home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / stubs / gen.c next >
Encoding:
C/C++ Source or Header  |  1995-11-19  |  1.1 KB  |  54 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6.  
  7. int
  8. main(int argc, char **argv)
  9. {
  10.   char buf[1000];
  11.   char fn[1000];
  12.   char cmd[1000];
  13.   int i;
  14.   FILE *stubs, *as, *oh;
  15.  
  16.   /* Remove all the old files */
  17.   for (i=0; ; i++)
  18.   {
  19.     sprintf(fn, "stub%04d.o", i);
  20.     if (access(fn, F_OK))
  21.       break;
  22.     remove(fn);
  23.   }
  24.   remove("makefile.oh");
  25.   oh = fopen("makefile.oh", "w");
  26.  
  27.   stubs = fopen(argv[1], "r");
  28.   i = 0;
  29.   while (fgets(buf, 1000, stubs))
  30.   {
  31.     if (strncmp(buf, "#define", 7))
  32.       continue;
  33.     sscanf(buf, "%*s %s", buf);
  34.     if (strncmp(buf, "__dj_include", 10) == 0)
  35.       continue;
  36.     sprintf(fn, "stub%04d.o", i);
  37.     i++;
  38.     printf("\r%s = %s    ", fn, buf);
  39.  
  40.     sprintf(cmd, "as -o %s", fn);
  41.     as = popen(cmd, "w");
  42.     fprintf(as, ".file \"%s.stub\"; .global _%s; _%s:; jmp ___%s\n",
  43.         buf, buf, buf, buf);
  44.     pclose(as);
  45.  
  46.     fprintf(oh, "&/%s\n", fn);
  47.   }
  48.   fclose(oh);
  49.   fclose(stubs);
  50.   printf("\n");
  51.  
  52.   return 0;
  53. }
  54.