diff --git a/Makefile b/Makefile index 3d2191a0ce266b7981cbc80b20cf6144cdd1f66a..9aebb9cafbae4438da158f902217b7432e8467de 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +CC := cc +CFLAGS := -Wall -Wextra -Wshadow -Wunused -Wswitch-enum -Wpedantic -Wundef +LDFLAGS := -lm -ldl -lpthread -lasound + ttdaw: main.c - $(CC) -Wall -o ttdaw main.c minisdl_audio.c -lm -ldl -lpthread -lasound -lm + $(CC) $(CFLAGS) -o ttdaw main.c minisdl_audio.c $(LDFLAGS) diff --git a/main.c b/main.c index 51bcdb694e6472feefe2fd1c8ec4b910af0691b7..4fc3d1ae00a7fb236540920d882dc2827a2f0451 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,48 @@ #include +#include +#include +#include + +void help(const char *argv0) { + printf("Usage: %s [options]\n" + "\nAvailable options:\n" + " -h,--help this help\n" + " -v,--version show version\n" + " -p,--port=client:port device port\n", + argv0); +} int main(int argc, char *argv[]) { - fprintf(stdout, "Oh, hi Mark!\n"); + const char short_options[] = "hvlp"; + const struct option long_options[] = { + {"help", 0, NULL, 'h'}, + {"version", 0, NULL, 'v'}, + {"list", 0, NULL, 'l'}, + {"port", 1, NULL, 'p'}, + {0}, + }; + + int c; + while ((c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + switch (c) { + case 'h': + help(argv[0]); + return 0; + case 'v': + fprintf(stdout, "Version\n"); + return 0; + case 'l': + fprintf(stdout, "List\n"); + return 0; + case 'p': + fprintf(stdout, "Port\n"); + return 0; + default: + fprintf(stdout, "No option provided\n"); + return 0; + } + } + return 0; }