1: static char *rcsid = "$Header$";
   2: /*
   3:  * pd - change working project directory
   4:  *
   5:  * Author: Peter J. Nicklin
   6:  */
   7: #include <stdio.h>
   8: #include "macro.h"
   9: #include "null.h"
  10: #include "path.h"
  11: #include "pdb.h"
  12: #include "pld.h"
  13: #include "spms.h"
  14: #include "yesno.h"
  15: 
  16: char *PGN = "pd";           /* program name */
  17: 
  18: main(argc, argv)
  19:     int argc;
  20:     char **argv;
  21: {
  22:     extern int PPDEBUG;     /* project pathname debug flag */
  23:     char *alias;            /* project directory alias */
  24:     char *cmd;          /* change directory command pointer */
  25:     char *cwp;          /* current project regular pathname */
  26:     char dirdesc[DIRDESCSIZE];  /* project directory description */
  27:     char *getcwp();         /* get current project pathname */
  28:     char *pbgetstring();        /* get specified string field */
  29:     char *ppathname;        /* project pathname */
  30:     int dflag = NO;         /* print description flag */
  31:     int errpdb();           /* print database error message */
  32:     int pfndent();          /* find and load database entry */
  33:     int status = 0;         /* exit status */
  34:     int xppath();           /* expand project pathname */
  35:     PATH pathbuf;           /* pathname struct buffer */
  36:     PDB *openpdb();         /* open database */
  37:     PDB *pldp;          /* project link directory stream */
  38:     void nodir();           /* "can't find dir" fatal error call */
  39: 
  40:     cmd = "cd";
  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 'p':
  55:                     cmd = "pushd";
  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: pd [-d] pdirname");
  67: 
  68:     /* print the target directory */
  69:     ppathname = (argc < 1) ? CURPROJECT : *argv;
  70:     if (xppath(ppathname, &pathbuf) == -1)
  71:         nodir(ppathname);
  72:     else switch (pathbuf.p_mode & P_IFMT)
  73:         {
  74:         case P_IFNEW:
  75:             nodir(ppathname);
  76:             break;
  77:         case P_IFREG:
  78:             break;
  79:         case P_IFPDIR:
  80:         case P_IFHOME:
  81:         case P_IFPROOT:
  82:             /* change project if different (for cd only) */
  83:             if (*cmd == 'c' && (cwp = getcwp()) != NULL)
  84:                 if (!EQUAL(cwp, pathbuf.p_project))
  85:                     printf("setenv PROJECT %s;",
  86:                            pathbuf.p_project);
  87:             break;
  88:         }
  89:     printf("%s %s", cmd, pathbuf.p_path);
  90: 
  91:     /* print project directory description */
  92:     if (dflag == YES && (pathbuf.p_mode&P_IFMT) != P_IFREG)
  93:         {
  94:         if ((pathbuf.p_mode&P_IFMT) == P_IFPDIR)
  95:             alias = pathbuf.p_alias;
  96:         else
  97:             alias = CURPROJECT;
  98:         if ((pldp = openpdb(PLDNAME, pathbuf.p_project, "r")) == NULL)
  99:             exit(errpdb((PDB *) NULL));
 100:         if (pfndent(alias, pldp) == NO)
 101:             fatal("can't find %s alias in %s", alias, pldp->path);
 102:         if (*pbgetstring(PDIRDESC, dirdesc) != '\0')
 103:             fprintf(stderr, "%s\n", dirdesc);
 104:         }
 105:     exit(0);
 106: }
 107: 
 108: 
 109: 
 110: /*
 111:  * nodir() complains that it can't find the directory and calls exit(1).
 112:  */
 113: void
 114: nodir(ppathname)
 115:     char *ppathname;        /* project pathname */
 116: {
 117:     *PGN = '\0';
 118:     patherr(ppathname);
 119:     exit(1);
 120: }

Defined functions

main defined in line 18; never used
nodir defined in line 113; used 3 times

Defined variables

PGN defined in line 16; used 1 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: 912
Valid CSS Valid XHTML 1.0 Strict