ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/expandarg.c
Revision: 2.1
Committed: Sat Oct 17 08:41:37 1992 UTC (31 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 greg 2.1 /* Copyright (c) 1992 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Get additional command arguments from file or environment.
9     */
10    
11     #include "standard.h"
12    
13     #define MAXARGEXP 512 /* maximum argument expansion */
14    
15     /* set the following to suit, -1 to disable */
16     int envexpchr = '$'; /* environment expansion character */
17     int filexpchr = '^'; /* file expansion character */
18    
19    
20     expandarg(acp, avp, n) /* expand list at argument n */
21     int *acp;
22     register char ***avp;
23     int n;
24     {
25     int ace;
26     char *ave[MAXARGEXP];
27     char **newav;
28     /* check argument */
29     errno = 0;
30     if ((*avp)[n][0] == filexpchr) { /* file name */
31     ace = wordfile(ave, (*avp)[n]+1);
32     if (ace < 0)
33     return(-1); /* no such file */
34     } else if ((*avp)[n][0] == envexpchr) { /* env. variable */
35     ace = wordstring(ave, getenv((*avp)[n]+1));
36     if (ace < 0)
37     return(-1); /* no such variable */
38     } else /* regular argument */
39     return(0);
40     /* allocate new pointer list */
41     newav = (char **)bmalloc((*acp+ace)*sizeof(char *));
42     if (newav == NULL)
43     return(-1);
44     /* copy preceeding arguments */
45     bcopy((char *)*avp, (char *)newav, n*sizeof(char *));
46     /* copy expanded argument */
47     bcopy((char *)ave, (char *)(newav+n), ace*sizeof(char *));
48     /* copy trailing arguments + NULL */
49     bcopy((char *)(*avp+n+1), (char *)(newav+n+ace), (*acp-n)*sizeof(char *));
50     /* free old list */
51     bfree((char *)*avp, (*acp+1)*sizeof(char *));
52     /* assign new list */
53     *acp += ace-1;
54     *avp = newav;
55     return(1); /* return success */
56     }