Subversion Repositories Kolibri OS

Rev

Rev 9620 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <libgen.h>
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <sys/ksys.h>
  7.  
  8. #define ARGC_VALID 3
  9.  
  10. enum ARGV_FILE {
  11.     IN = 1,
  12.     OUT = 2
  13. };
  14.  
  15. void show_help(void)
  16. {
  17.     puts("Usage: defgen [lib.obj] [lib.def]");
  18. }
  19.  
  20. int main(int argc, char** argv)
  21. {
  22.  
  23.     if (argc != ARGC_VALID) {
  24.         show_help();
  25.         return 0;
  26.     }
  27.  
  28.     ksys_dll_t* obj_dll = _ksys_dlopen(argv[IN]);
  29.     FILE* outfile = fopen(argv[OUT], "w");
  30.  
  31.     if (!obj_dll) {
  32.         printf("File '%s' not found!\n", argv[IN]);
  33.         return 1;
  34.     }
  35.  
  36.     if (!outfile) {
  37.         printf("Unable to create file:'%s'!\n", argv[OUT]);
  38.         return 2;
  39.     }
  40.  
  41.     fprintf(outfile, "LIBRARY %s\n\n", basename(argv[IN]));
  42.     fputs("EXPORTS\n", outfile);
  43.  
  44.     int i = 0;
  45.     while (obj_dll[i].func_name) {
  46.         fprintf(outfile, "%s\n", obj_dll[i].func_name);
  47.         i++;
  48.     }
  49.     fclose(outfile);
  50.     return 0;
  51. }
  52.