diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-10-07 21:39:00 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-10-07 21:39:00 +0200 |
| commit | 4e2f5ec4bf2aec43f184674cfe9831d20e13e34a (patch) | |
| tree | 60ae9971d033f6865ea2b91a36e31c1ff0a88f7d | |
| parent | 15d5e19422c9b19cd452297ff0d333149c94e787 (diff) | |
| download | ttdaw-4e2f5ec4bf2aec43f184674cfe9831d20e13e34a.tar.gz | |
Added basic argument parsing and better Makefile
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | main.c | 43 |
2 files changed, 47 insertions, 2 deletions
@@ -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) @@ -1,7 +1,48 @@ #include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <getopt.h> + +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; } |
