2024-07-09 19:33:45 +00:00
|
|
|
#!/bin/sh
|
|
|
|
cat > mutils.c << EOF
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2024-09-30 13:11:43 +00:00
|
|
|
#include <libgen.h>
|
2024-07-09 19:33:45 +00:00
|
|
|
|
|
|
|
$(for i in $(ls src); do
|
|
|
|
f=$(basename $i .c)
|
|
|
|
echo "int "$f"_main(int argc, char **argv);"
|
|
|
|
done)
|
|
|
|
|
|
|
|
struct cmd {
|
|
|
|
int (*func)(int argc, char **argv);
|
|
|
|
const char *str;
|
|
|
|
} cmds[] = {
|
2024-07-13 11:43:49 +00:00
|
|
|
$(for i in $(ls src); do
|
|
|
|
f=$(basename $i .c)
|
2024-07-09 19:33:45 +00:00
|
|
|
|
2024-07-13 11:43:49 +00:00
|
|
|
#EDIT SOURCES
|
|
|
|
cat src/$i | sed "s/main(/"$f"_main(/g" > bin/$i
|
2024-07-09 19:33:45 +00:00
|
|
|
|
2024-07-13 11:43:49 +00:00
|
|
|
#FILL STRUCTURE
|
|
|
|
echo -e "\t{"$f"_main, \"$f\"},"
|
|
|
|
done)
|
2024-07-09 19:33:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2024-09-30 13:11:43 +00:00
|
|
|
char *prog = basename(argv[0]);
|
2024-07-09 19:33:45 +00:00
|
|
|
|
2024-09-30 13:11:43 +00:00
|
|
|
if (argc == 1 && !strcmp(prog, "mutils")) {
|
2024-07-09 19:33:45 +00:00
|
|
|
for (size_t i = 0; i < sizeof(cmds) / sizeof(struct cmd); i++)
|
2024-09-30 13:11:43 +00:00
|
|
|
printf("%s ", cmds[i].str);
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strcmp(prog, "mutils")) {
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
|
|
|
|
prog = argv[0];
|
2024-07-09 19:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < sizeof(cmds) / sizeof(struct cmd); i++)
|
2024-09-30 13:11:43 +00:00
|
|
|
if (!strcmp(prog, cmds[i].str))
|
|
|
|
return cmds[i].func(argc, argv);
|
2024-07-09 19:33:45 +00:00
|
|
|
|
2024-09-30 13:11:43 +00:00
|
|
|
fprintf(stderr, "mutils: unknown applet %s\n", prog);
|
2024-07-09 19:33:45 +00:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2024-10-26 12:05:11 +00:00
|
|
|
echo $CFLAGS | xargs $CC -D_BOX -Iconfigs -Ilibmu mutils.c obj/*.o bin/*.c -o mutils
|
2024-09-01 13:43:41 +00:00
|
|
|
echo $CFLAGS | xargs $CC -Iconfigs scripts/musuid.c -o musuid
|