/* * MAKE * * write chain */#include <D2:\include\stdio.h>#include "D:tree.h"#define local staticextern char *m_nopen;extern char runtime[], library[];extern char outfile[];extern struct s_unit *dtree;extern FILE *output;local char *ext;local char  m_lnkerr[] = "link file error\n"   ,  m_outerr[] = "output file error\n" ,  newline[]  = "\n"                  ,  fnbuf[40]  = "D:"                  ;local char worktodo = 0;local FILE *lf;/* print action */local make (ud)struct s_unit *ud;{  struct s_unit *us;  struct s_dep *d;  FILE *out2;  char ts, *sep, *size;  worktodo = 1;  ts = (      us = (d = ud->source)->dep  )->type;  switch (ts)  {  case c_M65:    if (us->source) break;  case c_C:    (*ext)++;    break;  case c_OBJ:    strcat(fnbuf, ud->name);    *((char *)strchr(fnbuf, '.')) = 0;    strcat(fnbuf, ".LNK");    if ((lf=fopen(fnbuf, "w")) == NULL)      fputs(m_lnkerr, stdout);    putstr(lf, 2, runtime, newline);  }  switch (ts)  {  case c_C:    putstr(output, 2,      "X CC65 ", us->name    );    break;  case c_M65:    fputs("X RA65 -O ", output);    if (!strchr(ud->name, ':'))    {      fputs("D:", output);    }    fputs(ud->name, output);    fputc(     ' ', output);  case c_OBJ:    if (ts == c_M65)    {      out2 = output;      sep  = " ";    }    else    {      out2 = lf;      sep  = newline;    }    for (; d; d=d->next)    {      putstr(out2, 2,        d->dep->name, sep      );    }  }  switch (ts)  {  case c_M65:    if (us->source)    {      fputs(newline, output);      break;    }  case c_C:    size = (ts==c_M65) ? "0 " : "11 ";    putstr(output, 6,      " >>2:ERRORS\nCHECK ", size,      outfile, "\n-", outfile, newline    );    fclose(output);    output = fopen(outfile, "w");    if (output == NULL)      fputs(m_outerr, stdout);    break;  case c_OBJ:    putstr(output, 5,      "X LINK65 -O ", ud->name,      " @", fnbuf, "\n"    );    putstr(lf, 2,      library, newline    );    fclose(lf);  }}/* traverse, checking units */local int traverse (u)struct s_unit *u;{  struct s_dep *d;  struct s_unit *v;  int t, rc;  if (!(d=u->source))  {    if (u->nil)    {      fputs(u->name, stdout);      fputs(m_nopen, stdout);      return -1;    }    return 0;  }  for (t=0; d; d=d->next)  {    if ((v=d->dep)->nil)    {      bcopy(u->time, v->time, 6);    }    if ((rc=traverse(v)) < 0)    {      return -1;    }    else    {      if (rc) t = 1;    }    if (      memcmp(u->time, v->time, 6) < 0    ) t = 1;  }  if (t) make(u);  return t;}/* generate batch-file chain */chain (){  ext = outfile + 10;  if (traverse(dtree) < 0) return -1;  return worktodo;}