Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. // export_table_gen
  2. // Copyright (C) maxcodehack and turbocat2001, 2021
  3.  
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. int main(int argc, char** argv) {
  8.         if (argc != 3) {
  9.                 printf("Usage: %s <symbols.txt> <exports.c>\n", argv[0]);
  10.                 return 0;
  11.         }
  12.         FILE *input, *output;
  13.         if ((input = fopen(argv[1], "r")) == NULL)
  14.         {
  15.                 printf("error: file \"%s\" not found\n", argv[1]);
  16.                 return 1;
  17.         }
  18.         char buf[10000];
  19.         // Head
  20.         strcpy(buf, \
  21.                         "#include <stdio.h>\n" \
  22.                         "#include <string.h>\n" \
  23.                         "#include <stdlib.h>\n" \
  24.                         "#include <time.h>\n" \
  25.                         "#include <sys/dirent.h>\n" \
  26.                         "#include <sys/ksys.h>\n\n" \
  27.                         "#include <math.h>\n\n" \
  28.                         "#include <setjmp.h>\n\n" \
  29.                         "ksys_coff_etable_t EXPORTS[] = {\n");
  30.        
  31.         // Generate
  32.         char symbol[256];
  33.         while(fscanf(input, "%s", symbol) != EOF) {
  34.                 if(symbol[0]!='!'){
  35.                         char temp[256];
  36.                         sprintf(temp, "{\"%s\", &%s},\n", symbol, symbol);
  37.                         strcat(buf, temp);
  38.                 }
  39.         }
  40.         strcat(buf, "NULL,\n};");
  41.         fclose(input);
  42.        
  43.         // Output generated
  44.         output = fopen(argv[2], "w");
  45.         if (output == NULL)
  46.         {
  47.                 printf("Unable to write to file: '%s'!\n", argv[2]);
  48.                 return 1;
  49.         }
  50.  
  51.         fputs(buf, output);
  52.         fclose(output);
  53.        
  54.         printf("Done, check %s!\n", argv[2]);
  55.        
  56.         return 0;
  57. }
  58.