1: /* $Header$ */
   2: 
   3: /*
   4:  * Author: Peter J. Nicklin
   5:  */
   6: 
   7: /*
   8:  * getcpd() loads a PATH struct with the attributes of the current working
   9:  * project directory. Don't bother getting  type or description (too slow
  10:  * at present). Returns -1 on error, 0 if a regular directory, or 1
  11:  * if a project directory.
  12:  */
  13: #include <stdio.h>
  14: #include "macro.h"
  15: #include "null.h"
  16: #include "path.h"
  17: #include "pdb.h"
  18: #include "pdbuf.h"
  19: #include "pld.h"
  20: #include "yesno.h"
  21: 
  22: getcpd(pb)
  23:     PATH *pb;           /* pathname buffer */
  24: {
  25:     char cwd[PATHSIZE];     /* current working directory */
  26:     char *cwp;          /* current working  project */
  27:     char *getcwp();         /* get current working project */
  28:     char *getwd();          /* get current working directory */
  29:     char *mkalias();        /* construct alias from pathname */
  30:     char *pbfndstring();        /* find string field */
  31:     char *pbgetkey();       /* get next key */
  32:     char *relpath;          /* relative pathname */
  33:     char *strcpy();         /* string copy */
  34:     char *xorpath();        /* remove subpathname */
  35:     int closepdb();         /* close database */
  36:     int pbcmpfield();       /* compare non-key fields */
  37:     int pbfndflag();        /* find flag field */
  38:     int pgetent();          /* load next entry into buffer */
  39:     PDB *pldp;          /* project link directory stream */
  40:     PDB *openpdb();         /* open database */
  41: 
  42:     pb->p_alias = pb->p_buf;
  43:     getwd(cwd);
  44:     if ((cwp = getcwp()) == NULL)
  45:         {
  46:         pb->p_mode = P_IFREG;
  47:         strcpy(pb->p_alias, mkalias(cwd));
  48:         pb->p_path = pb->p_alias + strlen(pb->p_alias) + 1;
  49:         strcpy(pb->p_path, cwd);
  50:         return(0);
  51:         }
  52:     if (EQUAL(cwd, cwp))        /* we are in project root directory */
  53:         relpath = CURDIR;
  54:     else
  55:         relpath = xorpath(cwp, cwd);
  56:     if ((pldp = openpdb(PLDNAME, cwp, "r")) == NULL)
  57:         return(-1);
  58:     while (pgetent(pldp) != EOF)
  59:         {
  60:         if (pbcmpfield(relpath, pbfndstring(PDIRPATH)) == 0)
  61:             {
  62:             if (pbfndflag(PROOTDIR) == YES)
  63:                 pb->p_mode = P_IFPROOT;
  64:             else
  65:                 pb->p_mode = P_IFPDIR;
  66:             pbgetkey(pb->p_alias);
  67:             pb->p_path = pb->p_alias + strlen(pb->p_alias) + 1;
  68:             strcpy(pb->p_path, cwd);
  69:             closepdb(pldp);
  70:             return(1);
  71:             }
  72:         }
  73:     closepdb(pldp);
  74:     pb->p_mode = P_IFREG;
  75:     strcpy(pb->p_path, cwd);
  76:     return(0);
  77: }

Defined functions

getcpd defined in line 22; never used
Last modified: 1985-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 727
Valid CSS Valid XHTML 1.0 Strict