1: static char *rcsid = "$Header$";
2: /*
3: * pwp - path to working project
4: *
5: * Author: Peter J. Nicklin
6: */
7: #include <pwd.h>
8: #include <stdio.h>
9: #include "macro.h"
10: #include "null.h"
11: #include "path.h"
12: #include "pdb.h"
13: #include "pdbuf.h"
14: #include "pld.h"
15: #include "spms.h"
16: #include "yesno.h"
17:
18: #define PASSWDFILE "/etc/passwd"
19:
20: char *PGN = "pwp"; /* program name */
21:
22: main(argc, argv)
23: int argc;
24: char **argv;
25: {
26: extern int PPDEBUG; /* project pathname debug flag */
27: char alias[ALIASSIZE]; /* project alias */
28: char *cwp; /* current working project */
29: char *getcwp(); /* get current working project */
30: char *gethdir(); /* get home directory pathname */
31: char lastcwp[PATHSIZE]; /* last current working project */
32: char *pbfndstring(); /* find string field */
33: char *pbgetkey(); /* get next key */
34: char ppathname[PPATHSIZE]; /* project pathname */
35: char *ppptr = &ppathname[(sizeof ppathname)-1];
36: /* project pathname pointer */
37: char *prepend(); /* prepend projectname to pathname */
38: char *relpath; /* relative pathname */
39: char *strcpy(); /* string copy */
40: char *xorpath(); /* remove subpathname */
41: int chproject(); /* change working project */
42: int closepdb(); /* close database */
43: int errpdb(); /* print database error message */
44: int lflag = NO; /* long format flag */
45: int pbcmpfield(); /* compare non-key fields */
46: int pbfndflag(); /* find flag field */
47: int pgetent(); /* load next entry into buffer */
48: int status = 0; /* exit status */
49: PDB *pldp; /* project link directory stream */
50: PDB *openpdb(); /* open database */
51: struct passwd *getpwdir(); /* get password file entry for dir */
52: struct passwd *pw; /* password entry pointer */
53:
54: {
55: register char *s; /* option pointer */
56: while (--argc > 0 && **++argv == '-')
57: {
58: for (s = argv[0]+1; *s != '\0'; s++)
59: switch (*s)
60: {
61: case 'D':
62: PPDEBUG = YES;
63: break;
64: case 'l':
65: lflag = YES;
66: break;
67: default:
68: warn("bad option -%c", *s);
69: status = 1;
70: goto endfor;
71: }
72: endfor: continue;
73: }
74: }
75: if (status == 1 || argc > 0)
76: fatal("usage: pwp [-l]");
77:
78: if ((cwp = getcwp()) == NULL)
79: fatal("no project environment");
80: if (lflag == YES)
81: printf("%s\n", cwp);
82: else {
83: for (;;)
84: {
85: strcpy(lastcwp, cwp);
86: chproject(PARENTPROJECT);
87: cwp = getcwp();
88: chdir(cwp);
89: if (EQUAL(cwp, lastcwp))
90: break; /* reached home directory */
91: relpath = xorpath(cwp, lastcwp);
92: if ((pldp = openpdb(PLDNAME, CURDIR, "r")) == NULL)
93: exit(errpdb((PDB *) NULL));
94: while (pgetent(pldp) != EOF)
95: {
96: if (pbfndflag(PROOTDIR) == NO)
97: continue;
98: if (pbcmpfield(relpath, pbfndstring(PDIRPATH)) == 0)
99: break;
100: }
101: ppptr = prepend(PPATHSEP, prepend(pbgetkey(alias), ppptr));
102: closepdb(pldp);
103: }
104: if (!EQUAL(cwp, gethdir(CNULL)))
105: if ((pw = getpwdir(cwp)) == NULL)
106: {
107: warn("can't find %s home directory in %s", cwp,
108: PASSWDFILE);
109: }
110: else {
111: ppptr = prepend(USERPROJECT, prepend(pw->pw_name, ppptr));
112: }
113: printf("%s\n", (*ppptr == '\0') ? ROOTPROJECT : ppptr);
114: }
115: exit(0);
116: }
117:
118:
119:
120: /*
121: * prepend() tacks a project alias onto the front of a project pathname.
122: */
123: static char *
124: prepend(alias, ppathname)
125: register char *alias;
126: register char *ppathname;
127: {
128: register int i; /* alias name size counter */
129:
130: for (i = 0; *alias != '\0'; i++, alias++)
131: continue;
132: while (i-- > 0)
133: *--ppathname = *--alias;
134: return(ppathname);
135: }
Defined functions
main
defined in line
22;
never used
Defined variables
PGN
defined in line
20;
never used
rcsid
defined in line
1;
never used
Defined macros