home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / CPM3 / CPMMAKE.ARK / CHECK.C < prev    next >
C/C++ Source or Header  |  1986-08-31  |  2KB  |  107 lines

  1. /*
  2.  *    Check structures for make.
  3.  */
  4.  
  5. #include "c:stdio.h"
  6. #include "h.h"
  7.  
  8.  
  9. /*
  10.  *    Prints out the structures as defined in memory.  Good for check
  11.  *    that you make file does what you want (and for debugging make).
  12.  */
  13. void
  14. prt()
  15. {
  16.     register struct name *        np;
  17.     register struct depend *    dp;
  18.     register struct line *        lp;
  19.     register struct cmd *        cp;
  20.     register struct macro *        mp;
  21.  
  22.  
  23.     for (mp = macrohead; mp; mp = mp->m_next)
  24.         fprintf(stderr, "%s = %s\n", mp->m_name, mp->m_val);
  25.  
  26.     fputc('\n', stderr);
  27.  
  28.     for (np = namehead.n_next; np; np = np->n_next)
  29.     {
  30.         fprintf(stderr, "%s:\n", np->n_name);
  31.         for (lp = np->n_line; lp; lp = lp->l_next)
  32.         {
  33.             fputc(':', stderr);
  34.             for (dp = lp->l_dep; dp; dp = dp->d_next)
  35.                 fprintf(stderr, " %s", dp->d_name->n_name);
  36.             fputc('\n', stderr);
  37.  
  38.             for (cp = lp->l_cmd; cp; cp = cp->c_next)
  39.                 fprintf(stderr, "-\t%s\n", cp->c_cmd);
  40.             fputc('\n', stderr);
  41.         }
  42.         fputc('\n', stderr);
  43.     }
  44. }
  45.  
  46.  
  47. /*
  48.  *    Recursive routine that does the actual checking.
  49.  */
  50. void
  51. check(np)
  52. struct name *        np;
  53. {
  54.     register struct depend *    dp;
  55.     register struct line *        lp;
  56.  
  57.  
  58.     if (np->n_flag & N_MARK)
  59.         fatal("Circular dependency from %s", np->n_name);
  60.  
  61.     np->n_flag |= N_MARK;
  62.  
  63.     for (lp = np->n_line; lp; lp = lp->l_next)
  64.         for (dp = lp->l_dep; dp; dp = dp->d_next)
  65.             check(dp->d_name);
  66.  
  67.     np->n_flag &= ~N_MARK;
  68. }
  69.  
  70.  
  71. /*
  72.  *    Look for circular dependancies.
  73.  *    ie.
  74.  *        a: b
  75.  *        b: a
  76.  *    is a circular dep
  77.  */
  78. void
  79. circh()
  80. {
  81.     register struct name *    np;
  82.  
  83.  
  84.     for (np = namehead.n_next; np; np = np->n_next)
  85.         check(np);
  86. }
  87.  
  88.  
  89. /*
  90.  *    Check the target .PRECIOUS, and mark its dependentd as precious
  91.  */
  92. void
  93. precious()
  94. {
  95.     register struct depend *    dp;
  96.     register struct line *        lp;
  97.     register struct name *        np;
  98.  
  99.  
  100.     if (!((np = newname(".PRECIOUS"))->n_flag & N_TARG))
  101.         return;
  102.  
  103.     for (lp = np->n_line; lp; lp = lp->l_next)
  104.         for (dp = lp->l_dep; dp; dp = dp->d_next)
  105.             dp->d_name->n_flag |= N_PREC;
  106. }
  107.