/* * TREE * * build tree */#include <D2:\include\stdio.h>#include "D:tree.h"#define local staticextern char word[40];struct s_unit *dtree;struct s_unit *unit;local *types[] ={  ".C", ".M65", ".OBJ", ".COM", 0};local typev[] ={  c_msc, c_C, c_M65, c_OBJ, c_COM};local char m_nob[] = " cannot build\n";local char buf[40], buf2[13];local char entry[23];local char erred;/* make unit data */local struct s_unit *mkunit (){  struct s_unit *u;  char *p, *q;  int i;  u = pmalloc(sizeof(struct s_unit));  strcpy(u->name, word);  u->source = NULL;  p = strchr(word, '.');  u->type = typev[inlist(types, p)];  filname(buf, word);  p = strchr(buf, ':');  if (q = strrchr(p, '\\')) p = q;  if (q = strrchr(p, '>' )) p = q;  strcpy(buf2, ++p);  *p = 0;  p = u->time;  if (dirent(buf, buf2, entry) < 0)  {    u->nil = 1;    for (i=0; i<6; i++)      *p++ = 0;  }  else  {    u->nil = 0;    *p++ = entry[19];    *p++ = entry[18];    *p++ = entry[17];    *p++ = entry[20];    *p++ = entry[21];    *p   = entry[22];  }  return u;}/* find unit */local struct s_unit *findunit (u)struct s_unit *u;{  struct s_dep *d;  struct s_unit *u2;  if (!strcmp(u->name, word))  {    return u;  }  else  {    d = u->source;    while (d)    {      if (u2 = findunit(d->dep))        return u2;      d = d->next;    }  }  return NULL;}/* add unit to tree */int addunit (){  struct s_unit *u;  if (dtree == NULL)  {    dtree = unit = mkunit();  }  else    unit = findunit(dtree);  if (unit) return 0;  putstr(stdout, 2,     word, " unrelated\n");  return 1;}/* add dependent to previous unit */int adddep (){  struct s_dep *d, *d2, *new;  struct s_unit *u;  char ts, td, s;  new = pmalloc(sizeof(struct s_dep));  if (!(new->dep = u = mkunit()))    return 1;  new->next = NULL;  if (d = unit->source)  {    while (d2 = d->next) d = d2;    d->next = new;  }  else  {    unit->source = new;  }  if (!(td=unit->type))  {    fputs(unit->name, stdout);    fputs(     m_nob, stdout);    return 1;  }  s  = td + (ts = u->type);  if (  (ts > td)     || (s!=2 && s!=3 && s!=6 && s!=12)     || (ts==0 && td!=2))  {    putstr(stdout, 4,      unit->name, "->", u->name , m_nob    );    return 1;  }  return 0;}