home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / util / makedepend / pr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-25  |  2.3 KB  |  102 lines

  1. /*
  2.  * $XConsortium: pr.c,v 1.14 91/07/25 11:51:15 rws Exp $
  3.  */
  4. #include "def.h"
  5.  
  6. extern struct    inclist    inclist[ MAXFILES ],
  7.             *inclistp;
  8. extern char    *objprefix;
  9. extern char    *objsuffix;
  10. extern int    width;
  11. extern boolean    printed;
  12. extern boolean    verbose;
  13. extern boolean    show_where_not;
  14.  
  15. add_include(file, file_red, include, dot, failOK)
  16.     struct inclist    *file, *file_red;
  17.     char    *include;
  18.     boolean    dot;
  19. {
  20.     register struct inclist    *newfile;
  21.     register struct filepointer    *content;
  22.  
  23.     /*
  24.      * First decide what the pathname of this include file really is.
  25.      */
  26.     newfile = inc_path(file->i_file, include, dot);
  27.     if (newfile == NULL) {
  28.         if (failOK)
  29.             return;
  30.         if (file != file_red)
  31.             warning("%s (reading %s): ",
  32.                 file_red->i_file, file->i_file);
  33.         else
  34.             warning("%s: ", file->i_file);
  35.         warning1("cannot find include file \"%s\"\n", include);
  36.         show_where_not = TRUE;
  37.         newfile = inc_path(file->i_file, include, dot);
  38.         show_where_not = FALSE;
  39.     }
  40.  
  41.     if (newfile) {
  42.         included_by(file, newfile);
  43.         if (!newfile->i_searched) {
  44.             newfile->i_searched = TRUE;
  45.             content = getfile(newfile->i_file);
  46.             find_includes(content, newfile, file_red, 0, failOK);
  47.             freefile(content);
  48.         }
  49.     }
  50. }
  51.  
  52. recursive_pr_include(head, file, base)
  53.     register struct inclist    *head;
  54.     register char    *file, *base;
  55. {
  56.     register int    i;
  57.  
  58.     if (head->i_marked)
  59.         return;
  60.     head->i_marked = TRUE;
  61.     if (head->i_file != file)
  62.         pr(head, file, base);
  63.     for (i=0; i<head->i_listlen; i++)
  64.         recursive_pr_include(head->i_list[ i ], file, base);
  65. }
  66.  
  67. pr(ip, file, base)
  68.     register struct inclist  *ip;
  69.     char    *file, *base;
  70. {
  71.     static char    *lastfile;
  72.     static int    current_len;
  73.     register int    len, i;
  74.     char    buf[ BUFSIZ ];
  75.  
  76.     printed = TRUE;
  77.     len = strlen(ip->i_file)+1;
  78.     if (current_len + len > width || file != lastfile) {
  79.         lastfile = file;
  80.         sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
  81.             ip->i_file);
  82.         len = current_len = strlen(buf);
  83.     }
  84.     else {
  85.         buf[0] = ' ';
  86.         strcpy(buf+1, ip->i_file);
  87.         current_len += len;
  88.     }
  89.     fwrite(buf, len, 1, stdout);
  90.  
  91.     /*
  92.      * If verbose is set, then print out what this file includes.
  93.      */
  94.     if (! verbose || ip->i_list == NULL || ip->i_notified)
  95.         return;
  96.     ip->i_notified = TRUE;
  97.     lastfile = NULL;
  98.     printf("\n# %s includes:", ip->i_file);
  99.     for (i=0; i<ip->i_listlen; i++)
  100.         printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
  101. }
  102.