ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/expandarg.c
Revision: 2.7
Committed: Fri Jun 27 06:53:21 2003 UTC (20 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.6: +7 -3 lines
Log Message:
Broke standard.h into rtio.h, rterror.h, rtmath.h, and rtmisc.h

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: expandarg.c,v 2.6 2003/05/13 17:58:32 greg Exp $";
3 #endif
4 /*
5 * Get additional command arguments from file or environment.
6 *
7 * External symbols declared in rtio.h
8 */
9
10 #include "copyright.h"
11
12 #include "rtio.h"
13
14 #include "rtmisc.h"
15
16 #include <errno.h>
17
18 #define MAXARGEXP 512 /* maximum argument expansion */
19
20 /* set the following to suit, -1 to disable */
21 int envexpchr = '$'; /* environment expansion character */
22 int filexpchr = '@'; /* file expansion character */
23
24
25 int
26 expandarg(acp, avp, n) /* expand list at argument n */
27 int *acp;
28 register char ***avp;
29 int n;
30 {
31 int ace;
32 char *ave[MAXARGEXP];
33 char **newav;
34 /* check argument */
35 if (n >= *acp)
36 return(0);
37 errno = 0;
38 if ((*avp)[n][0] == filexpchr) { /* file name */
39 ace = wordfile(ave, (*avp)[n]+1);
40 if (ace < 0)
41 return(-1); /* no such file */
42 } else if ((*avp)[n][0] == envexpchr) { /* env. variable */
43 ace = wordstring(ave, getenv((*avp)[n]+1));
44 if (ace < 0)
45 return(-1); /* no such variable */
46 } else /* regular argument */
47 return(0);
48 /* allocate new pointer list */
49 newav = (char **)bmalloc((*acp+ace)*sizeof(char *));
50 if (newav == NULL)
51 return(-1);
52 /* copy preceeding arguments */
53 bcopy((void *)*avp, (void *)newav, n*sizeof(char *));
54 /* copy expanded argument */
55 bcopy((void *)ave, (void *)(newav+n), ace*sizeof(char *));
56 /* copy trailing arguments + NULL */
57 bcopy((void *)(*avp+n+1), (void *)(newav+n+ace), (*acp-n)*sizeof(char *));
58 /* free old list */
59 bfree((char *)*avp, (*acp+1)*sizeof(char *));
60 /* assign new list */
61 *acp += ace-1;
62 *avp = newav;
63 return(1); /* return success */
64 }