home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / stub / stub2inc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-28  |  1.8 KB  |  71 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. static FILE *
  7. sfopen(const char *c, const char *m)
  8. {
  9.   FILE *rv = fopen(c, m);
  10.   if (rv == 0)
  11.   {
  12.     fprintf(stderr, "Error: cannot open file %s in mode %s\n", c, m);
  13.     exit(1);
  14.   }
  15.   return rv;
  16. }
  17.  
  18. int
  19. main(int argc, char **argv)
  20. {
  21.   char buf[1000];
  22.   char name[1000], type[1000];
  23.   int addr, tag=0;
  24.   FILE *inf = sfopen(argv[1], "r");
  25.   FILE *sf = sfopen(argv[2], "r");
  26.   FILE *outf = sfopen(argv[3], "w");
  27.   fprintf(outf, "/* Generated by stub2inf - DO NOT EDIT */\n");
  28.   fprintf(outf, "#ifndef __dj_include_stub_h__\n#define __dj_include_stub_h__\n\n");
  29.   while (1)
  30.   {
  31.     if (fgets(buf, 1000, inf) == 0)
  32.       break;
  33.     if (strstr(buf, "by Value"))
  34.       tag = 1;
  35.     if (strstr(buf, "by Name"))
  36.       tag = 0;
  37.     name[0] = 0;
  38.     sscanf(buf, "0000:%x %s", &addr, name);
  39.     if (strncmp(name, "stubinfo", 8) == 0 && tag)
  40.     {
  41.       strupr(name);
  42.       fprintf(outf, "#define %s %#x\n", name, addr);
  43.     }
  44.   }
  45.   fprintf(outf, "#ifndef __ASSEMBLER__\n");
  46.   fprintf(outf, "typedef struct {\n");
  47.   while (1)
  48.   {
  49.     if (fgets(buf, 1000, sf) == 0)
  50.       break;
  51.     if (strncmp(buf, "stubinfo_end", 12) == 0)
  52.       break;
  53.     if (strncmp(buf, "stubinfo_", 9) != 0)
  54.       continue;
  55.     name[0] = 0;
  56.     sscanf(buf, "%[^:]: ; %[^\n]", name, type);
  57.     if (strncmp(type, "char", 4) == 0)
  58.       fprintf(outf, "  char %s%s;\n", name+9, type+5);
  59.     else
  60.       fprintf(outf, "  %s %s;\n", type, name+9);
  61.   }
  62.   fprintf(outf, "} _GO32_StubInfo;\n");
  63.   fprintf(outf, "extern _GO32_StubInfo *_stubinfo;\n");
  64.   fprintf(outf, "#endif\n");
  65.   fprintf(outf, "\n#endif /* __dj_include_stub_h__ */\n");
  66.   fclose(inf);
  67.   fclose(sf);
  68.   fclose(outf);
  69.   return 0;
  70. }
  71.