ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/expandarg.c
Revision: 2.3
Committed: Fri Jul 16 12:40:37 1993 UTC (30 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +1 -1 lines
Log Message:
change file expansion character from '^' to '@'

File Contents

# Content
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 if (n >= *acp)
30 return(0);
31 errno = 0;
32 if ((*avp)[n][0] == filexpchr) { /* file name */
33 ace = wordfile(ave, (*avp)[n]+1);
34 if (ace < 0)
35 return(-1); /* no such file */
36 } else if ((*avp)[n][0] == envexpchr) { /* env. variable */
37 ace = wordstring(ave, getenv((*avp)[n]+1));
38 if (ace < 0)
39 return(-1); /* no such variable */
40 } else /* regular argument */
41 return(0);
42 /* allocate new pointer list */
43 newav = (char **)bmalloc((*acp+ace)*sizeof(char *));
44 if (newav == NULL)
45 return(-1);
46 /* copy preceeding arguments */
47 bcopy((char *)*avp, (char *)newav, n*sizeof(char *));
48 /* copy expanded argument */
49 bcopy((char *)ave, (char *)(newav+n), ace*sizeof(char *));
50 /* copy trailing arguments + NULL */
51 bcopy((char *)(*avp+n+1), (char *)(newav+n+ace), (*acp-n)*sizeof(char *));
52 /* free old list */
53 bfree((char *)*avp, (*acp+1)*sizeof(char *));
54 /* assign new list */
55 *acp += ace-1;
56 *avp = newav;
57 return(1); /* return success */
58 }