home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1 / HamRadio.cdr / misc / src0131 / mkdep.c < prev    next >
C/C++ Source or Header  |  1991-01-26  |  970b  |  47 lines

  1. /* Simple-minded program that generates dependencies for a makefile.
  2.  * Does not process #ifdefs, so some spurious dependencies may be
  3.  * generated.
  4.  *
  5.  * Copyright 1991 Phil Karn, KA9Q
  6.  */
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. char include[] = "#include";
  11. main(argc,argv)
  12. int argc;
  13. char *argv[];
  14. {
  15.     int i;
  16.     FILE *fp;
  17.     char buf[512],*cp,*cp1;
  18.  
  19.     for(i=1;i<argc;i++){
  20.         strcpy(buf,argv[i]);
  21.         if((cp = strchr(buf,'.')) == NULL)
  22.             continue;
  23.         *cp = '\0';
  24.         printf("%s.obj: %s",buf,argv[i]);
  25.         fp = fopen(argv[i],"r");
  26.         if(fp == NULL){
  27.             fprintf(stderr,"Cannot open %s\n",argv[i]);
  28.             continue;
  29.         }
  30.         while(fgets(buf,512,fp) != NULL){
  31.             if(strncmp(buf,include,sizeof(include)-1) != 0)
  32.                 continue;
  33.             if((cp = strchr(buf,'\"')) == NULL)
  34.                 continue;
  35.             cp++;
  36.             if((cp1 = strchr(cp,'\"')) == NULL)
  37.                 continue;
  38.             putchar(' ');
  39.             while(cp != cp1)
  40.                 putchar(*cp++);
  41.         }
  42.         putchar('\n');
  43.         fclose(fp);
  44.     }
  45.     return 0;
  46. }
  47.