home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / Languages / Python / python-14-src / PC / utils / makesrc.c next >
Encoding:
C/C++ Source or Header  |  1997-01-17  |  1.9 KB  |  68 lines

  1. #include <stdio.h>
  2. #include <direct.h>
  3. #include <string.h>
  4.  
  5. /* Copy files from source directories to ./src changing
  6. file names and #include names to 8x3 lower case */
  7.  
  8. char *usage = "You must be in the \"pc\" directory.\n";
  9. char *list[] = {"..\\Include", "..\\Modules", "..\\Objects", "..\\Parser", "..\\Python", ".", 0};
  10. main()
  11. {
  12.   DIR *dpath;
  13.   struct dirent *dir;
  14.   int len;
  15.   char **plist;
  16.   char *pt1, *pt2, *name;
  17.   char dest_path[256], src_path[256], buf256[256];
  18.   FILE *fpin, *fpout;
  19.  
  20.   for (plist = list; *plist; plist++){
  21.     if ((dpath = opendir(*plist)) == NULL){
  22.       printf(usage);
  23.       return 1;
  24.       }
  25.  
  26.     while (dir = readdir(dpath)){
  27.       name = dir->d_name;
  28.       len = strlen(name);
  29.       if (len > 2 && name[len - 2] == '.' &&
  30.             (name[len - 1] == 'c' || name[len - 1] == 'h')){
  31.         strcpy(buf256, name);
  32.         if (len > 10){
  33.           buf256[8] = '.';
  34.           buf256[9] = name[len - 1];
  35.           buf256[10] = 0;
  36.           }
  37.         strlwr(buf256);
  38.         strncpy(src_path, *plist, 256);
  39.         strncat(src_path, "\\", 256);
  40.         strncat(src_path, name, 256);
  41.         strncpy(dest_path, ".\\src\\", 256);
  42.         strncat(dest_path, buf256, 256);
  43.         printf("Copying %-30s to %s\n", src_path, dest_path);
  44.         fpin = fopen(src_path, "r");
  45.         fpout = fopen(dest_path, "w");
  46.         while (fgets(buf256, 256, fpin)){
  47.           if (!strncmp(buf256, "#include", 8)){
  48.             strlwr(buf256);
  49.             if ((pt1 = strstr(buf256, "\"")) &&
  50.                 (pt2 = strstr(buf256, ".")) &&
  51.                 (*(pt2 + 1) == 'h') &&
  52.                 (pt2 - pt1 > 9)){
  53.               for (pt1 += 9; *pt2; pt1++, pt2++)
  54.                 *pt1 = *pt2;
  55.               *pt1 = 0;
  56.               }
  57.             }
  58.           fputs(buf256, fpout);
  59.           }
  60.         fclose(fpin);
  61.         fclose(fpout);
  62.         }
  63.       }
  64.     closedir(dpath);
  65.     }
  66.   return 0;
  67.   }
  68.