home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 216.lha / PdMake / check.c < prev    next >
C/C++ Source or Header  |  1996-02-15  |  2KB  |  101 lines

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