1: static char *rcsid = "$Header$";
   2: /*
   3:  * pexec - execute command over project hierarchy
   4:  *
   5:  * Author: Peter J. Nicklin
   6:  */
   7: #include "bin.h"
   8: #include "macro.h"
   9: #include "getarg.h"
  10: #include "null.h"
  11: #include "path.h"
  12: #include "pdtyp.h"
  13: #include "slist.h"
  14: #include "spms.h"
  15: #include "yesno.h"
  16: 
  17: char *COMMAND;              /* command string to be executed */
  18: char *PGN = "pexec";            /* program name */
  19: char *SHELLNAME;            /* name of command shell */
  20: char *SHELLPATH;            /* pathname of command shell */
  21: int CSHELL = 0;             /* use csh or sh? */
  22: int CSHRC = NO;             /* execute .cshrc if csh shell */
  23: int DEBUG = NO;             /* print pexec debugging info */
  24: int ERRSTATUS = 1;          /* pexec error status */
  25: int EXECUTE = YES;          /* execute command? */
  26: int IGNORE_BAD_EXIT = NO;       /* exit if command doesn't return 0 */
  27: int NOQUERY;                /* query user about quitting? */
  28: int PRINT_HEADING = YES;        /* print headings for project dirs */
  29: int PVINDEX;                /* environ index for PROJECT variable */
  30: PDTYP PDIRTYP;              /* project directory type labels list */
  31: SLIST *ENVLIST;             /* project environment variable list */
  32: 
  33: main(argc, argv)
  34:     int argc;
  35:     char **argv;
  36: {
  37:     extern int PPDEBUG;     /* project pathname debug flag */
  38:     char *argvtos();        /* convert cmd args to string */
  39:     char *getcwp();         /* get current working project */
  40:     char *getshell();       /* get command shell pathname */
  41:     char *pathtail();       /* remove pathname head */
  42:     char *ppathname = CURPROJECT;   /* project pathname */
  43:     int atoi();         /* string to integer conversion */
  44:     int build_pdset();      /* create set of project dirs */
  45:     int ch_dir();           /* change current working directory */
  46:     int check_pdset();      /* check ordering of set of proj dirs */
  47:     int exec_pdset();       /* execute cmds in set of proj dirs */
  48:     int execcmd();          /* execute command in directory */
  49:     int getpvindex();       /* get PROJECT env. variable index */
  50:     int pdtparse();         /* parse boolean type label expr */
  51:     int status = 0;         /* exit status */
  52:     int xppath();           /* expand project pathname */
  53:     PATH pathbuf;           /* pathname struct buffer */
  54:     SLIST *slinit();        /* initialize list */
  55:     void debug_pdset();     /* print dirs + types after sorting */
  56:     void init_pdset();      /* initialize set of project dirs */
  57:     void print_title();     /* print project directory title */
  58:     void sort_pdset();      /* sort set of project dirs */
  59: 
  60:     {
  61:     register char *s;       /* option pointer */
  62:     while (--argc > 0 && **++argv == '-')
  63:         {
  64:         for (s = argv[0]+1; *s != '\0'; s++)
  65:             switch (*s)
  66:                 {
  67:                 case '?':
  68:                     NOQUERY++;
  69:                     break;
  70:                 case 'D':
  71:                     DEBUG = YES;
  72:                     PPDEBUG = YES;
  73:                     break;
  74:                 case 'P':
  75:                     ppathname = GETARG(s);
  76:                     if (*ppathname == '\0')
  77:                         {
  78:                         warn("missing project name");
  79:                         status = 1;
  80:                         }
  81:                     goto endfor;
  82:                 case 'T':
  83:                     if (pdtparse(GETARG(s), &PDIRTYP) == NO)
  84:                         status = 1;
  85:                     goto endfor;
  86:                 case 'X':
  87:                     ERRSTATUS = atoi(GETARG(s));
  88:                     goto endfor;
  89:                 case 'c':
  90:                     CSHRC = YES;
  91:                     break;
  92:                 case 'i':
  93:                     IGNORE_BAD_EXIT = YES;
  94:                     break;
  95:                 case 'q':
  96:                     PRINT_HEADING = NO;
  97:                     break;
  98:                 case 'x':
  99:                     EXECUTE = NO;
 100:                     break;
 101:                 default:
 102:                     warn("bad option -%c", *s);
 103:                     status = 1;
 104:                     goto endfor;
 105:                 }
 106:         endfor: continue;
 107:         }
 108:     }
 109:     if (status == 1 || argc < 1)
 110:         {
 111:         warn("usage: pexec [-?ciqx] [-P pdirname] [-T typexpr] command");
 112:         pxexit();
 113:         }
 114:     /*
 115: 	 * The PROJECT environment variable must exist because
 116: 	 * it has to be modified before each command execution.
 117: 	 */
 118:     if ((PVINDEX = getpvindex()) < 0)
 119:         {
 120:         warn("no project environment");
 121:         pxexit();
 122:         }
 123: 
 124:     if ((COMMAND = argvtos(argc, argv)) == NULL)
 125:         pxexit();
 126:     SHELLPATH = getshell();
 127:     SHELLNAME = pathtail(SHELLPATH);
 128:     if (EQUAL(SHELLNAME, pathtail(CSH)))
 129:         CSHELL++;
 130: 
 131:     /* convert project pathname to regular pathname */
 132:     if (xppath(ppathname, &pathbuf) == -1)
 133:         {
 134:         patherr(ppathname);
 135:         pxexit();
 136:         }
 137:     else switch (pathbuf.p_mode & P_IFMT)
 138:         {
 139:         case P_IFNEW:
 140:         case P_IFREG:
 141:             warn("%s: no such project or project directory", ppathname);
 142:             pxexit();
 143:         case P_IFPDIR:
 144:             IGNORE_BAD_EXIT = NO;
 145:             if (PRINT_HEADING == YES)
 146:                 print_title(ppathname);
 147:             ch_dir(pathbuf.p_path);
 148:             if (EXECUTE == YES)
 149:                 status |= execcmd(pathbuf.p_project);
 150:             break;
 151:         case P_IFHOME:
 152:         case P_IFPROOT:
 153:             if (PDIRTYP.pfxsize == 0)
 154:                 status |= execproject(ppathname, pathbuf.p_path);
 155:             else    {
 156:                 ENVLIST = slinit();
 157:                 init_pdset();
 158:                 if (build_pdset(ppathname, pathbuf.p_path) != 0)
 159:                     pxexit();
 160:                 sort_pdset();
 161:                 if (DEBUG == YES)
 162:                     debug_pdset();
 163:                 if (check_pdset() != 0)
 164:                     pxexit();
 165:                 status |= exec_pdset();
 166:                 }
 167:             break;
 168:         }
 169:     exit(status);
 170: }

Defined functions

main defined in line 33; never used

Defined variables

COMMAND defined in line 17; used 1 times
CSHELL defined in line 21; used 1 times
CSHRC defined in line 22; used 1 times
  • in line 90
DEBUG defined in line 23; used 2 times
ERRSTATUS defined in line 24; used 1 times
  • in line 87
EXECUTE defined in line 25; used 2 times
IGNORE_BAD_EXIT defined in line 26; used 2 times
NOQUERY defined in line 27; used 1 times
  • in line 68
PGN defined in line 18; used 1 times
PRINT_HEADING defined in line 28; used 2 times
PVINDEX defined in line 29; used 1 times
SHELLNAME defined in line 19; used 2 times
SHELLPATH defined in line 20; used 2 times
rcsid defined in line 1; never used
Last modified: 1985-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1360
Valid CSS Valid XHTML 1.0 Strict