#include #include #include #include #include #include #include #include "util/versie.h" static void usage(FILE *f) { fprintf(f, "Gebruik: omg [-hV] [NAAM=WAARDE]... [COMMANDO]...\n" "\n" "TODO \n" "\n" " -h Toon deze hulptekst\n" " -V Toon versienummer\n"); } // Returns pointer to argument array containing the variables to set and the // command to execute and its arguments static char** parse_options(int argc, char **argv) { int opt; while ((opt = getopt(argc, argv, "hV")) != -1) { switch (opt) { case 'h': usage(stdout); exit(0); case 'V': drukkedoos_print_versie(stdout); exit(0); case '?': fprintf(stderr, "omg: Ongeldige optie: -%c\n", optopt); usage(stderr); exit(1); } } return argv + optind; } int entry_omg(int argc, char **argv) { char **args = parse_options(argc, argv); while (*args != NULL) { if (strchr(*args, '=') == NULL) { break; } char *name = strtok(*args, "="); char *value = strtok(NULL, "="); if (value == NULL) { fprintf(stderr, "omg: geen waarde gegeven voor sleutel '%s'\n", name); return 1; } errno = 0; if (setenv(name, value, true) == -1) { fprintf(stderr, "omg: kon omgeving niet aanpassen: %s\n", strerror(errno)); } args++; } if (*args == NULL) { while (*environ != NULL) { printf("%s\n", *environ); environ++; } return 0; } errno = 0; execvp(args[0], args); fprintf(stderr, "omg: kon proces niet starten: %s\n", strerror(errno)); return 1; }