#!/bin/sh cat > mutils.c << EOF #include #include #include $(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[] = { $(for i in $(ls src); do f=$(basename $i .c) #EDIT SOURCES cat src/$i | sed "s/main(/"$f"_main(/g" > bin/$i #FILL STRUCTURE echo -e "\t{"$f"_main, \"$f\"}," done) }; int main(int argc, char **argv) { char *prog = basename(argv[0]); if (argc == 1 && !strcmp(prog, "mutils")) { for (size_t i = 0; i < sizeof(cmds) / sizeof(struct cmd); i++) printf("%s ", cmds[i].str); putchar('\n'); return 0; } else if (!strcmp(prog, "mutils")) { argv++; argc--; prog = argv[0]; } for (size_t i = 0; i < sizeof(cmds) / sizeof(struct cmd); i++) if (!strcmp(prog, cmds[i].str)) return cmds[i].func(argc, argv); fprintf(stderr, "mutils: unknown applet %s\n", prog); } EOF echo $CFLAGS | xargs $CC -D_BOX -Iconfigs -Ilibmu mutils.c obj/*.o bin/*.c -o mutils echo $CFLAGS | xargs $CC -Iconfigs scripts/musuid.c -o musuid