home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol078 / clist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1984-04-29  |  2.4 KB  |  116 lines

  1. #include <b:bdscio.h>
  2.  
  3. /*   clist - list 'c' source files   */
  4.  
  5. #define eos '\0'
  6. #define std_err 4
  7. #define dev_lst 2
  8.  
  9. int n_flag, h_flag;
  10.  
  11. #include "cpybuf.c"
  12.  
  13. #include "cmpbuflc.c"
  14.  
  15. #include "instr.c"
  16.  
  17. #include "diagn.c"
  18.  
  19. #include "pagin8.c"
  20.  
  21. #include "incl.c"
  22.  
  23. #include "filenm.c"
  24.  
  25. #include "detab.c"
  26.  
  27. /*  check include - do possible include processing  */
  28. check_include (line)
  29. /******************/
  30.     char *line;
  31.     {
  32.     int n;
  33.     char file[20];
  34.     int list();
  35.     int abort;
  36.  
  37.     for ( ; isspace(*line) ; ++line);  /* skip leading spaces */
  38.     if (cmpbuflc (line, "#include ", 9))
  39.         {
  40.         n = get_name (line+9, file);
  41.         if (n == 0 || n > 20)
  42.             {
  43.             if (n > 20)
  44.                 abort = TRUE;
  45.             else
  46.                 abort = FALSE;
  47.             diagnostic (abort, "error in file name ",
  48.                         file, NULL);
  49.             }
  50.         else
  51.             {
  52.             if (cmpbuflc (&file[n-2], ".h", 2))  /* header file */
  53.                 {
  54.                 if (h_flag)
  55.                     include (file, &list);
  56.                 }
  57.             else
  58.                 if (n_flag)  /* non-header file */
  59.                     include (file, &list);
  60.             }
  61.         }
  62.     }  /* check_include */
  63.  
  64. /*  list - label and print lines of "file"  */
  65. list (file, iobuf)
  66. /*********/
  67.     char *file;
  68.     struct _buf *iobuf;
  69.     {
  70.     char *fgets();
  71.     char *buf, *line;
  72.     int line_number;
  73.     char *alloc();
  74.  
  75.     buf = alloc (170);
  76.     line = alloc (150);
  77.     line_number = 0;
  78.     strcpy (buf, file);
  79.     while (strlen(buf) < 17)
  80.         strcat (buf, " ");
  81.     while (fgets (line, iobuf))
  82.         {
  83.         sprintf (&buf[14], "%3d", ++line_number);
  84.         strcat (buf, ": ");
  85.         detab (line, buf+19);
  86.         paginate (buf);
  87.         if (n_flag || h_flag)
  88.             check_include (line);
  89.         }  /* while */
  90.     free (buf);
  91.     free (line);
  92.     } /* list */
  93.  
  94.  
  95. main (argc, argv)
  96. /***************/
  97.     int argc;
  98.     char **argv;
  99.     {
  100.     _allocp = NULL;
  101.     n_flag = TRUE;
  102.     h_flag = FALSE;
  103.     page = 0;
  104.     if (argc <= 1)
  105.         diagnostic (TRUE, 
  106.         "Usage A>clist file1 file2 ... filen <cr>\n", NULL);
  107.     --argc;
  108.     ++argv;
  109.     do {
  110.        title = *argv;
  111.        include (title, &list);
  112.        paginate (NULL);
  113.        }
  114.     while (++argv, --argc);
  115.     }
  116.