Back to index

radiance  4R0+20100331
Defines | Functions | Variables
expandarg.c File Reference
#include "copyright.h"
#include <errno.h>
#include <string.h>
#include "rtio.h"
#include "rtmisc.h"

Go to the source code of this file.

Defines

#define MAXARGEXP   4096 /* maximum argument expansion */

Functions

int expandarg (int *acp, char ***avp, int n)

Variables

static const char RCSid [] = "$Id: expandarg.c,v 2.9 2008/05/17 02:49:41 greg Exp $"
int envexpchr = '$'
int filexpchr = '@'

Define Documentation

#define MAXARGEXP   4096 /* maximum argument expansion */

Definition at line 19 of file expandarg.c.


Function Documentation

int expandarg ( int *  acp,
char ***  avp,
int  n 
)

Definition at line 27 of file expandarg.c.

{
       int    ace;
       char   *ave[MAXARGEXP];
       char   **newav;
                                   /* check argument */
       if (n >= *acp)
              return(0);
       errno = 0;    
       if ((*avp)[n][0] == filexpchr) {          /* file name */
              ace = wordfile(ave, (*avp)[n]+1);
              if (ace < 0)
                     return(-1);   /* no such file */
       } else if ((*avp)[n][0] == envexpchr) {          /* env. variable */
              ace = wordstring(ave, getenv((*avp)[n]+1));
              if (ace < 0)
                     return(-1);   /* no such variable */
       } else                                    /* regular argument */
              return(0);
                                   /* allocate new pointer list */
       newav = (char **)bmalloc((*acp+ace)*sizeof(char *));
       if (newav == NULL)
              return(-1);
                                   /* copy preceeding arguments */
       memcpy((void *)newav, (void *)*avp, n*sizeof(char *));
                                   /* copy expanded argument */
       memcpy((void *)(newav+n), (void *)ave, ace*sizeof(char *));
                                   /* copy trailing arguments + NULL */
       memcpy((void *)(newav+n+ace), (void *)(*avp+n+1), (*acp-n)*sizeof(char *));
                                   /* free old list */
       bfree((char *)*avp, (*acp+1)*sizeof(char *));
                                   /* assign new list */
       *acp += ace-1;
       *avp = newav;
       return(1);                  /* return success */
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int envexpchr = '$'

Definition at line 22 of file expandarg.c.

int filexpchr = '@'

Definition at line 23 of file expandarg.c.

const char RCSid[] = "$Id: expandarg.c,v 2.9 2008/05/17 02:49:41 greg Exp $" [static]

Definition at line 2 of file expandarg.c.