home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / MAKELIST.C < prev    next >
C/C++ Source or Header  |  1994-04-17  |  2KB  |  89 lines

  1. #include "global.h"
  2.   
  3. static char include[] = "#include";
  4. static char nameline[1024];
  5. static int Recurse = FALSE;
  6. static int Tree = FALSE;
  7.   
  8. void
  9. scanfile( char *filename, int indent )
  10. {
  11.     FILE *fp;
  12.     char buf[512], *name_p, *end_p, *str_p;
  13.   
  14.     fp = fopen(filename,"r");
  15.     if(fp == NULL){
  16.         fprintf(stderr,"Cannot open %s\n",filename);
  17.         return;
  18.     }
  19.   
  20.     while(fgets(buf,512,fp) != NULL){
  21.         if(strncmp(buf,include,sizeof(include)-1) != 0)
  22.             continue;
  23.         if((name_p = strchr(buf,'\"')) == NULL)
  24.             continue;
  25.         name_p++;   /* skip quote */
  26.         if((end_p = strchr(name_p,'\"')) == NULL)
  27.             continue;
  28.         *end_p = '\0';
  29.         if( Tree ){
  30.             int i = 0;
  31.   
  32.             while( i++ < indent )
  33.                 printf("\t");
  34.         }
  35.   
  36.         if( ( str_p = strstr( nameline, name_p ) ) != NULL
  37.         && str_p[-1] == ' ' ){
  38.             if( Tree ){
  39.                 printf( "***\t%s\n", name_p );
  40.             }
  41.         } else {
  42.             if( Tree ){
  43.                 printf( "\t%s\n", name_p );
  44.             }
  45.             strcat( nameline, " " );
  46.             strcat( nameline, name_p );
  47.   
  48.             if( Recurse )
  49.                 scanfile( name_p, indent + 1 );
  50.         }
  51.     }
  52.     fclose(fp);
  53. }
  54.   
  55. main(argc,argv)
  56. int argc;
  57. char *argv[];
  58. {
  59.     char buf[10],*cp;
  60.     int c;
  61.   
  62.     while((c = getopt(argc,argv,"rt")) != EOF){
  63.         switch(c){
  64.             case 't':
  65.                 Tree = TRUE;
  66.             case 'r':
  67.                 Recurse = TRUE;
  68.                 break;
  69.         }
  70.     }
  71.   
  72.     for(;optind<argc;optind++){
  73.         nameline[0] = '\0';
  74.         if( Tree ) {
  75.             printf("%s\n",argv[optind]);
  76.         } else {
  77.             strcpy(buf,argv[optind]);
  78.             if((cp = strchr(buf,'.')) == NULL)
  79.                 continue;
  80.             *cp = '\0';
  81.             printf("%s.obj: %s",buf,argv[optind]);
  82.         }
  83.         scanfile( argv[optind], 0 );
  84.         if( !Tree )
  85.             printf( "%s\n", nameline );
  86.     }
  87.     return 0;
  88. }
  89.