home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gle / gle / addtype.c < prev    next >
C/C++ Source or Header  |  1992-11-29  |  2KB  |  96 lines

  1. /* This program reads a C file and adds type's to function prototypes. e.g.
  2. int xyz(int x);
  3.     becomes
  4. int xyz(int x);
  5. */
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <ctype.h>
  10.  
  11. #define true 1
  12. #define false 0
  13.  
  14. /*--------------------------------------------------------------------------*/
  15. main(int argc, char *argv[])
  16. {
  17.   int i;
  18.   char buff[90];
  19.   for (i=1;i<argc;i++) {
  20.     do_file(argv[i]);
  21.     printf("Just done {%s} Continue?",argv[i]);
  22.   }
  23. }
  24. do_file(char *inname)
  25. {
  26.     FILE *fin,*fout;
  27.     char inbuff[3200];
  28.     char outname[100],outbak[100];
  29.     int sl,i,j,k;
  30.     char *s;
  31.  
  32.     strcpy(outname,inname);
  33.  
  34.     fout = fopen("addtype.tmp","w");
  35.     if (fout==NULL) perror("open error2 "), exit(1);
  36.     fin = fopen(inname,"r");
  37.     if (fin == NULL) { perror("Unable to open file") ;  exit(2); }
  38.     if (fout == NULL) { perror("Unable to open file") ;  exit(2); }
  39.     for (;!feof(fin);) {
  40.             inbuff[0] = 0;
  41.         if (fgets(inbuff,32000,fin)==NULL) break;
  42.         do_line(inbuff);
  43.         fputs(inbuff,fout);
  44.     }
  45.     fclose(fin);
  46.     fclose(fout);
  47.     strcpy(outbak,outname);
  48.     strcat(outbak,".bak");
  49.     rename(outname,outbak);
  50.     rename("addtype.tmp",outname);
  51. }
  52. do_line(char *ss)
  53. {
  54.     int bk=0;
  55.     static char buff[200];
  56.     char *s;
  57.     s = ss;
  58.     if (!isalpha(*s)) return;
  59.     s++;
  60.     for (;*s!=NULL;s++) {
  61.         if (*s=='(') goto search_right;
  62.         if (isspace(*s)) return;
  63.     }
  64.     return;
  65. search_right:
  66.     for (;*s!=NULL;s++) {
  67.         if (*s=='(') bk++;
  68.         if (*s==')') if (bk==1) {
  69.             if (*(++s)==';') goto add_int;
  70.             else return;
  71.         } else bk--;
  72.     }
  73.     return;
  74. add_int:
  75.     strcpy(buff,"int ");
  76.     strcat(buff,ss);
  77.     strcpy(ss,buff);
  78.     printf("%s",buff);
  79. }
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.