home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / asmutl / make-ds.lbr / FILE.CQ / FILE.C
Encoding:
C/C++ Source or Header  |  1986-09-05  |  3.3 KB  |  161 lines

  1. /* File FILE.C BDS-C Ver 1.2 30May85 */
  2. #include <bdscio.h>
  3. #include "make.h"
  4.  
  5.  
  6. /*
  7.  * Return file-node for 'fname'.
  8.  * If it doesn't exist, then create one.
  9.  */
  10. FILENODE *filenode(fname)
  11. char *fname;
  12. {
  13.     FILENODE *f, *afnode(), *gfile();
  14.  
  15.     if((f = gfile(fname)) == NULL)
  16.         f = afnode(fname);
  17.     return f;
  18. }
  19.  
  20.  
  21. /*
  22.  * Add a dependency to the node 'fnd'.
  23.  * 'fnd' will depend on 'fname'.
  24.  */
  25. addfile(fnd, fname)
  26. FILENODE *fnd;
  27. char *fname;
  28. {
  29.     NODE *n;
  30.     FILENODE *f;
  31.  
  32.     if(fnd == NULL)            /* punt if no root file */
  33.     {
  34.         printf("No current root, can't add dependency '%s'\n",fname);
  35.         return;
  36.     }
  37.  
  38.     f = filenode(fname);
  39.     if((n = /*(NODE *)*/alloc(sizeof *n)) == NULL) allerr();
  40.     n->nnext = fnd->fnode;
  41.     fnd->fnode = n;
  42.     n->nfile = f;
  43. }
  44.  
  45.  
  46. /*
  47.  * Add a line of method-text to the node 'fnode'.
  48.  */
  49. addmeth(fnode, methtext)
  50. FILENODE *fnode;
  51. char *methtext;
  52. {
  53.     int len;
  54.     char *new;
  55.  
  56.     if(fnode == NULL || methtext == NULL) return;
  57.  
  58.     len = strlen(methtext) + 2;
  59.     if(fnode->fmake == NULL)
  60.     {
  61.         if((fnode->fmake = /*(char *)*/alloc(1)) == NULL) allerr();
  62.         *(fnode->fmake) = 0;
  63.     }
  64.     len += strlen(fnode->fmake);
  65.  
  66. /* Lattice C and BDS-C doesn't have 'realloc()', so this kludges around it: */
  67.     if((new = /*(char *)*/alloc(len)) == NULL) allerr();
  68.     strcpy(new, fnode->fmake);
  69.     free(fnode->fmake);
  70.     fnode->fmake = new;
  71.  
  72.     strcat(fnode->fmake, methtext);
  73.     len = strlen(fnode->fmake);
  74.     if(len && fnode->fmake[len - 1] != '\n')
  75.         strcat(fnode->fmake, "\n");
  76. }
  77.  
  78.  
  79. /*
  80.  * Get a filenode for the file called 'fn'.
  81.  * Returns NULL if the node doesn't exist.
  82.  */
  83. FILENODE *gfile(fn)
  84. char *fn;
  85. {
  86.     FILENODE *f;
  87.  
  88.     for(f = froot; f != NULL; f = f->fnext)
  89.         if(strcieq(fn, f->fname)) return f;
  90.     return NULL;
  91. }
  92.  
  93.  
  94. /*
  95.  * Alloc space for a new file node.
  96.  */
  97. FILENODE *afnode(name)
  98. char *name;
  99. {
  100.     FILENODE *f;
  101.  
  102.     for(f=froot; f; f=f->fnext)
  103.         if(strcieq(name, f->fname)) return f;
  104.  
  105.     if((f = /*(FILENODE *)*/alloc(sizeof *f)) == NULL) allerr();
  106.     if((f->fname = /*(char *)*/alloc(strlen(name)+1)) == NULL) allerr();
  107.     strcpy(f->fname, name);
  108.     f->fmake = NULL;
  109.     f->fnode = NULL;
  110.     f->fdate = NULL;
  111.     f->fflag = 0;
  112.  
  113.     f->fnext = froot;
  114.     froot = f;
  115.     return f;
  116. }
  117.  
  118.  
  119. /*
  120.  * Print dependency tree.
  121.  */
  122. prtree()
  123. {
  124.     FILENODE *f;
  125.     NODE *n;
  126.      int reltime,cnt;
  127.  
  128.     for(f = froot; f != NULL; f = f->fnext)
  129.     {
  130. /* v 1.1 4/30 fix for rel time, & pretty-print dates  */
  131.         printf("%s%s%s ",
  132.             f->fname,
  133.             (f->fflag & ROOTP) ? " (root)" : "",
  134.             (f->fflag & REBUILT) ? " (rebuilt)" : "");
  135.         for (cnt= 14 - strlen(f->fname); cnt; cnt--)
  136.             putchar(' ');
  137.         printf("(%02.2x/%02.2x/%02.2x ",
  138.             (f->fdate != NULL) ? (f->fdate)->d_s[1] : 0,
  139.             (f->fdate != NULL) ? (f->fdate)->d_s[2] : 0,
  140.             (f->fdate != NULL) ? (f->fdate)->d_s[0] : 0);
  141.  
  142.         if ( !(((f->fdate)->d_s[3])&0x80))
  143.             printf("%02.2x:%02.2x)\n",
  144.             (f->fdate != NULL) ? (f->fdate)->d_s[3] : 0,
  145.             (f->fdate != NULL) ? (f->fdate)->d_s[4] : 0);
  146.         else {
  147.             reltime = (f->fdate != NULL) ? 
  148.                 256*( (f->fdate->d_s[3])&0x7f) +
  149.                     (f->fdate)->d_s[4] : 0;
  150.             printf("+%04.4d)\n",reltime);
  151.             }
  152.         if(f->fmake != NULL)
  153.             printf("%s", f->fmake);
  154.         for(n = f->fnode; n != NULL; n = n->nnext)
  155.             printf("\t%s\n", (n->nfile)->fname);
  156.         puts("");
  157.     }
  158. }
  159. rtree()
  160. {
  161.     FIL