1: static char *rcsid = "$Header$";
   2: /*
   3:  * chproject - change current project
   4:  *
   5:  * Author: Peter J. Nicklin
   6:  */
   7: #include <stdio.h>
   8: #include "bin.h"
   9: #include "macro.h"
  10: #include "path.h"
  11: #include "pdb.h"
  12: #include "pld.h"
  13: #include "spms.h"
  14: #include "system.h"
  15: #include "yesno.h"
  16: 
  17: char *PGN;              /* program name */
  18: int CSHELL = 0;             /* C shell command interpreter flag */
  19: 
  20: main(argc, argv)
  21:     int argc;
  22:     char **argv;
  23: {
  24:     extern int PPDEBUG;     /* project pathname debug flag */
  25:     char *getcwp();         /* get current working project */
  26:     char *getshell();       /* get command shell pathname */
  27:     char *pathtail();       /* remove pathname head */
  28:     int chproject();        /* change project */
  29:     int dflag = NO;         /* project description flag */
  30:     int fflag = YES;        /* execute PROJECTRC file */
  31:     int status = 0;         /* exit status */
  32:     void mustchdir();       /* must change directory */
  33:     void printPROJECT();        /* print PROJECT value */
  34:     void printcd();         /* print "cd" command */
  35:     void printdesc();       /* print project description */
  36:     void printrc();         /* print PROJECTRC execution request */
  37: 
  38:     PGN = pathtail(*argv);
  39:     if (EQUAL(pathtail(getshell()), pathtail(CSH))) CSHELL++;
  40: 
  41:     {
  42:     register char *s;       /* option pointer */
  43:     while (--argc > 0 && **++argv == '-')
  44:         {
  45:         for (s = argv[0]+1; *s != '\0'; s++)
  46:             switch (*s)
  47:                 {
  48:                 case 'D':
  49:                     PPDEBUG = YES;
  50:                     break;
  51:                 case 'd':
  52:                     dflag = YES;
  53:                     break;
  54:                 case 'f':
  55:                     fflag = NO;
  56:                     break;
  57:                 default:
  58:                     warn("bad option -%c", *s);
  59:                     status = 1;
  60:                     goto endfor;
  61:                 }
  62:         endfor: continue;
  63:         }
  64:     }
  65:     if (status == 1 || argc != 1)
  66:         fatal("usage: chproject [-df] projectname");
  67:     if (chproject(*argv) == NO)
  68:         exit(1);
  69:     mustchdir(getcwp());
  70:     printcd(getcwp());
  71:     printPROJECT();
  72:     if (fflag == YES && FILEXIST(PROJECTRC))
  73:         printrc();
  74:     if (dflag == YES) printdesc();
  75:     exit(0);
  76: }
  77: 
  78: 
  79: 
  80: /*
  81:  * mustchdir() must change current working directory or die.
  82:  */
  83: void
  84: mustchdir(pathname)
  85:     char *pathname;         /* destination directory */
  86: {
  87:     if (!CHDIR(pathname))
  88:         fatal("permission denied");
  89: }
  90: 
  91: 
  92: 
  93: /*
  94:  * printPROJECT prints PROJECT environment variable value.
  95:  */
  96: void
  97: printPROJECT()
  98: {
  99:     char *getcwp();         /* get current working project */
 100: 
 101:     if (CSHELL)
 102:         printf("; setenv PROJECT ");
 103:     else
 104:         printf("; export PROJECT; PROJECT=");
 105: 
 106:        printf("%s", getcwp());
 107: }
 108: 
 109: 
 110: 
 111: /*
 112:  * printcd() prints the "cd" change directory command.
 113:  */
 114: void
 115: printcd(pathname)
 116:     char *pathname;         /* pathname of destination directory */
 117: {
 118:     printf("cd %s", pathname);
 119: }
 120: 
 121: 
 122: 
 123: /*
 124:  * printrc() prints the PROJECTRC project initialization file execution
 125:  * request.
 126:  */
 127: void
 128: printrc()
 129: {
 130:     if (CSHELL)
 131:         printf("; source %s", PROJECTRC);
 132:     else
 133:         printf("; . %s", PROJECTRC);
 134: }
 135: 
 136: 
 137: 
 138: /*
 139:  * printdesc() prints project description.
 140:  */
 141: void
 142: printdesc()
 143: {
 144:     char dirdesc[DIRDESCSIZE];  /* project directory description */
 145:     char *pbgetstring();        /* get specified string field */
 146:     int errpdb();           /* print database error message */
 147:     int pfndent();          /* find and load database entry */
 148:     PDB *openpdb();         /* open database */
 149:     PDB *pldp;          /* project link directory stream */
 150: 
 151:     if ((pldp = openpdb(PLDNAME, CURDIR, "r")) == NULL)
 152:         exit(errpdb((PDB *) NULL));
 153:     if (pfndent(CURPROJECT, pldp) == NO)
 154:         fatal("can't find %s alias in %s", CURPROJECT, pldp->path);
 155:     if (*pbgetstring(PDIRDESC, dirdesc) != '\0')
 156:         fprintf(stderr, "%s\n", dirdesc);
 157: }

Defined functions

main defined in line 20; never used
mustchdir defined in line 83; used 2 times
printPROJECT defined in line 96; used 2 times
printcd defined in line 114; used 2 times
printdesc defined in line 141; used 2 times
printrc defined in line 127; used 2 times

Defined variables

CSHELL defined in line 18; used 3 times
PGN defined in line 17; used 1 times
  • in line 38
rcsid defined in line 1; never used
Last modified: 1985-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1161
Valid CSS Valid XHTML 1.0 Strict