home *** CD-ROM | disk | FTP | other *** search
- /* File FILE.C BDS-C Ver 1.2 30May85 */
- #include <bdscio.h>
- #include "make.h"
-
-
- /*
- * Return file-node for 'fname'.
- * If it doesn't exist, then create one.
- */
- FILENODE *filenode(fname)
- char *fname;
- {
- FILENODE *f, *afnode(), *gfile();
-
- if((f = gfile(fname)) == NULL)
- f = afnode(fname);
- return f;
- }
-
-
- /*
- * Add a dependency to the node 'fnd'.
- * 'fnd' will depend on 'fname'.
- */
- addfile(fnd, fname)
- FILENODE *fnd;
- char *fname;
- {
- NODE *n;
- FILENODE *f;
-
- if(fnd == NULL) /* punt if no root file */
- {
- printf("No current root, can't add dependency '%s'\n",fname);
- return;
- }
-
- f = filenode(fname);
- if((n = /*(NODE *)*/alloc(sizeof *n)) == NULL) allerr();
- n->nnext = fnd->fnode;
- fnd->fnode = n;
- n->nfile = f;
- }
-
-
- /*
- * Add a line of method-text to the node 'fnode'.
- */
- addmeth(fnode, methtext)
- FILENODE *fnode;
- char *methtext;
- {
- int len;
- char *new;
-
- if(fnode == NULL || methtext == NULL) return;
-
- len = strlen(methtext) + 2;
- if(fnode->fmake == NULL)
- {
- if((fnode->fmake = /*(char *)*/alloc(1)) == NULL) allerr();
- *(fnode->fmake) = 0;
- }
- len += strlen(fnode->fmake);
-
- /* Lattice C and BDS-C doesn't have 'realloc()', so this kludges around it: */
- if((new = /*(char *)*/alloc(len)) == NULL) allerr();
- strcpy(new, fnode->fmake);
- free(fnode->fmake);
- fnode->fmake = new;
-
- strcat(fnode->fmake, methtext);
- len = strlen(fnode->fmake);
- if(len && fnode->fmake[len - 1] != '\n')
- strcat(fnode->fmake, "\n");
- }
-
-
- /*
- * Get a filenode for the file called 'fn'.
- * Returns NULL if the node doesn't exist.
- */
- FILENODE *gfile(fn)
- char *fn;
- {
- FILENODE *f;
-
- for(f = froot; f != NULL; f = f->fnext)
- if(strcieq(fn, f->fname)) return f;
- return NULL;
- }
-
-
- /*
- * Alloc space for a new file node.
- */
- FILENODE *afnode(name)
- char *name;
- {
- FILENODE *f;
-
- for(f=froot; f; f=f->fnext)
- if(strcieq(name, f->fname)) return f;
-
- if((f = /*(FILENODE *)*/alloc(sizeof *f)) == NULL) allerr();
- if((f->fname = /*(char *)*/alloc(strlen(name)+1)) == NULL) allerr();
- strcpy(f->fname, name);
- f->fmake = NULL;
- f->fnode = NULL;
- f->fdate = NULL;
- f->fflag = 0;
-
- f->fnext = froot;
- froot = f;
- return f;
- }
-
-
- /*
- * Print dependency tree.
- */
- prtree()
- {
- FILENODE *f;
- NODE *n;
- int reltime,cnt;
-
- for(f = froot; f != NULL; f = f->fnext)
- {
- /* v 1.1 4/30 fix for rel time, & pretty-print dates */
- printf("%s%s%s ",
- f->fname,
- (f->fflag & ROOTP) ? " (root)" : "",
- (f->fflag & REBUILT) ? " (rebuilt)" : "");
- for (cnt= 14 - strlen(f->fname); cnt; cnt--)
- putchar(' ');
- printf("(%02.2x/%02.2x/%02.2x ",
- (f->fdate != NULL) ? (f->fdate)->d_s[1] : 0,
- (f->fdate != NULL) ? (f->fdate)->d_s[2] : 0,
- (f->fdate != NULL) ? (f->fdate)->d_s[0] : 0);
-
- if ( !(((f->fdate)->d_s[3])&0x80))
- printf("%02.2x:%02.2x)\n",
- (f->fdate != NULL) ? (f->fdate)->d_s[3] : 0,
- (f->fdate != NULL) ? (f->fdate)->d_s[4] : 0);
- else {
- reltime = (f->fdate != NULL) ?
- 256*( (f->fdate->d_s[3])&0x7f) +
- (f->fdate)->d_s[4] : 0;
- printf("+%04.4d)\n",reltime);
- }
- if(f->fmake != NULL)
- printf("%s", f->fmake);
- for(n = f->fnode; n != NULL; n = n->nnext)
- printf("\t%s\n", (n->nfile)->fname);
- puts("");
- }
- }
- rtree()
- {
- FIL