2022-04-15 11:11:49 +02:00
|
|
|
#include <libgen.h>
|
|
|
|
#include <stddef.h>
|
2022-01-12 19:09:37 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ksys.h>
|
|
|
|
|
|
|
|
#define ARGC_VALID 3
|
|
|
|
|
|
|
|
enum ARGV_FILE {
|
|
|
|
IN = 1,
|
|
|
|
OUT = 2
|
|
|
|
};
|
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
void show_help(void)
|
|
|
|
{
|
2022-01-12 19:09:37 +01:00
|
|
|
puts("Usage: defgen [lib.obj] [lib.def]");
|
|
|
|
}
|
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2022-01-12 19:09:37 +01:00
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
if (argc != ARGC_VALID) {
|
2022-01-12 19:09:37 +01:00
|
|
|
show_help();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
ksys_dll_t* obj_dll = _ksys_dlopen(argv[IN]);
|
2022-01-12 19:09:37 +01:00
|
|
|
FILE* outfile = fopen(argv[OUT], "w");
|
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
if (!obj_dll) {
|
2022-01-12 19:09:37 +01:00
|
|
|
printf("File '%s' not found!\n", argv[IN]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
if (!outfile) {
|
2022-01-12 19:09:37 +01:00
|
|
|
printf("Unable to create file:'%s'!\n", argv[OUT]);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(outfile, "LIBRARY %s\n\n", basename(argv[IN]));
|
|
|
|
fputs("EXPORTS\n", outfile);
|
2022-04-15 11:11:49 +02:00
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
while (obj_dll[i].func_name) {
|
|
|
|
fprintf(outfile, "%s\n", obj_dll[i].func_name);
|
2022-01-12 19:09:37 +01:00
|
|
|
i++;
|
|
|
|
}
|
2022-04-15 11:11:49 +02:00
|
|
|
fclose(outfile);
|
2022-01-12 19:09:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|