Subversion Repositories Kolibri OS

Rev

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

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <limits.h>
  5.  
  6. int main(int argc, char** argv) {
  7.     if(argc!=3){
  8.         printf("Usage: LoadGen <symbols.txt> <loader_dir>\n");
  9.         return 0;
  10.     }
  11.     argv[2][strlen(argv[1])-2]='\0';
  12.     FILE* symbols_txt = fopen(argv[1], "r");
  13.     if(!symbols_txt){
  14.         fprintf(stderr, "File '%s' not found!\n", argv[1]);
  15.             return -1;
  16.     }
  17.     char line[256];
  18.     while(fgets(line, 256, symbols_txt)) {
  19.         if(line[0]!='!'){
  20.             if(line[strlen(line)-1]=='\n'){
  21.                 line[strlen(line)-1]='\0';
  22.             }
  23.             char asm_name[PATH_MAX];
  24.             sprintf(asm_name, "%s/%s.asm", argv[2], line);
  25.             FILE *out = fopen(asm_name, "wb");
  26.             if(!out){
  27.                 fprintf(stderr, "Error! File '%s' not created!\n", asm_name);
  28.                 return -1;
  29.             }else{
  30.                 printf("File '%s' created successfully!\n", asm_name);
  31.             }
  32.  
  33.             fprintf(out, "format ELF\n");
  34.             fprintf(out, "include \"__lib__.inc\"\n");
  35.             fprintf(out, "fun      equ __func@%s\n", line);
  36.             fprintf(out, "fun_str  equ '%s'\n", line);
  37.             fprintf(out, "section '.text'\n");
  38.             fprintf(out, "fun_name db fun_str, 0\n");
  39.             fprintf(out, "section '.data'\n");
  40.             fprintf(out, "extrn lib_name\n");
  41.             fprintf(out, "public fun as fun_str\n");
  42.             fprintf(out, "fun dd fun_name\n");
  43.             fprintf(out, "lib dd lib_name\n");
  44.  
  45.             fclose(out);
  46.         }
  47.     }
  48. }
  49.