From 9c37eddad24eb7e9bbc9aae723b3a992ec5b4c97 Mon Sep 17 00:00:00 2001 From: cbdev Date: Thu, 5 Dec 2019 19:31:14 +0100 Subject: Unify midi parsing/deparsing code --- midimonster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'midimonster.c') diff --git a/midimonster.c b/midimonster.c index eb64974..e6c0842 100644 --- a/midimonster.c +++ b/midimonster.c @@ -224,7 +224,7 @@ static void event_free(){ } static int usage(char* fn){ - fprintf(stderr, "MIDIMonster v0.2\n"); + fprintf(stderr, "MIDIMonster v0.3\n"); fprintf(stderr, "Usage:\n"); fprintf(stderr, "\t%s \n", fn); return EXIT_FAILURE; -- cgit v1.2.3 From e517dbe783e65fdd1c80f5c917f8f924e2adfe8d Mon Sep 17 00:00:00 2001 From: cbdev Date: Tue, 10 Dec 2019 23:28:02 +0100 Subject: Implement rudimentary argument parsing --- Makefile | 8 +++++++- midimonster.c | 27 ++++++++++++++++++++++++--- midimonster.h | 5 +++++ 3 files changed, 36 insertions(+), 4 deletions(-) (limited to 'midimonster.c') diff --git a/Makefile b/Makefile index 8dab638..5183fa5 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,19 @@ PREFIX ?= /usr PLUGIN_INSTALL = $(PREFIX)/lib/midimonster EXAMPLES ?= $(PREFIX)/share/midimonster SYSTEM := $(shell uname -s) +GITVERSION = $(shell git describe) +# Default compilation CFLAGS CFLAGS ?= -g -Wall -Wpedantic +#CFLAGS += -DDEBUG # Hide all non-API symbols for export CFLAGS += -fvisibility=hidden -#CFLAGS += -DDEBUG midimonster: LDLIBS = -ldl +# Replace version string with current git-describe if possible +ifneq "$(GITVERSION)" "" +midimonster: CFLAGS += "-DMIDIMONSTER_VERSION=\"$(GITVERSION)\"" +endif # Work around strange linker passing convention differences in Linux and OSX ifeq ($(SYSTEM),Linux) diff --git a/midimonster.c b/midimonster.c index e6c0842..67614d4 100644 --- a/midimonster.c +++ b/midimonster.c @@ -223,8 +223,12 @@ static void event_free(){ } } +static void version(){ + fprintf(stderr, "MIDIMonster %s\n", MIDIMONSTER_VERSION); +} + static int usage(char* fn){ - fprintf(stderr, "MIDIMonster v0.3\n"); + version(); fprintf(stderr, "Usage:\n"); fprintf(stderr, "\t%s \n", fn); return EXIT_FAILURE; @@ -263,6 +267,21 @@ static int platform_initialize(){ return 0; } +static int args_parse(int argc, char** argv, char** cfg_file){ + size_t u; + for(u = 1; u < argc; u++){ + if(!strcmp(argv[u], "-v") || !strcmp(argv[u], "--version")){ + version(); + return 1; + } + + //if nothing else matches, it's probably the configuration file + *cfg_file = argv[u]; + } + + return 0; +} + int main(int argc, char** argv){ fd_set all_fds, read_fds; event_collection* secondary = NULL; @@ -271,8 +290,10 @@ int main(int argc, char** argv){ managed_fd* signaled_fds = NULL; int rv = EXIT_FAILURE, error, maxfd = -1; char* cfg_file = DEFAULT_CFG; - if(argc > 1){ - cfg_file = argv[1]; + + //parse commandline arguments + if(args_parse(argc, argv, &cfg_file)){ + return EXIT_FAILURE; } if(platform_initialize()){ diff --git a/midimonster.h b/midimonster.h index 5ce0c73..677eeee 100644 --- a/midimonster.h +++ b/midimonster.h @@ -5,6 +5,11 @@ #include #include +/* Core version unless set by the build process */ +#ifndef MIDIMONSTER_VERSION + #define MIDIMONSTER_VERSION "v0.3-dist" +#endif + /* API call attributes and visibilities */ #ifndef MM_API #ifdef _WIN32 -- cgit v1.2.3 From 21bf7ec86e9319864c403d479b8267b2eb0efb6f Mon Sep 17 00:00:00 2001 From: Spacelord Date: Wed, 18 Dec 2019 09:03:46 +0100 Subject: Change --version output to stdout --- midimonster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'midimonster.c') diff --git a/midimonster.c b/midimonster.c index 67614d4..48c6fe9 100644 --- a/midimonster.c +++ b/midimonster.c @@ -224,7 +224,7 @@ static void event_free(){ } static void version(){ - fprintf(stderr, "MIDIMonster %s\n", MIDIMONSTER_VERSION); + fprintf(stdout, "MIDIMonster %s\n", MIDIMONSTER_VERSION); } static int usage(char* fn){ -- cgit v1.2.3 From 886c8e299454176446cce82f151b85a82b26aa06 Mon Sep 17 00:00:00 2001 From: cbdev Date: Wed, 18 Dec 2019 22:23:34 +0100 Subject: Fix evdev division by zero --- TODO | 3 ++- backends/evdev.c | 3 +++ midimonster.c | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'midimonster.c') diff --git a/TODO b/TODO index 6ee649f..a5b5e7c 100644 --- a/TODO +++ b/TODO @@ -4,5 +4,6 @@ Optimize core channel search (store backend offset) udp backends may ignore MTU mm_managed_fd.impl is not freed currently (and is heaped most of the time anyway) -> documentation installer: implement an upgrade mode (check for newer versions in the repo) -evdev.c:321 divides by zero with relaxis make event collectors threadsafe to stop marshalling data... +collect & check backend API version +introduce backend logging macro diff --git a/backends/evdev.c b/backends/evdev.c index 659dc77..193b28b 100644 --- a/backends/evdev.c +++ b/backends/evdev.c @@ -208,6 +208,9 @@ static int evdev_configure_instance(instance* inst, char* option, char* value) { data->relative_axis[data->relative_axes].max *= -1; data->relative_axis[data->relative_axes].inverted = 1; } + else if(data->relative_axis[data->relative_axes].max == 0){ + fprintf(stderr, "Relative axis configuration for %s.%s has invalid range\n", inst->name, option + 8); + } data->relative_axis[data->relative_axes].current = strtoul(next_token, NULL, 0); if(data->relative_axis[data->relative_axes].code < 0){ fprintf(stderr, "Failed to configure relative axis extents for %s.%s\n", inst->name, option + 8); diff --git a/midimonster.c b/midimonster.c index 48c6fe9..2ec165b 100644 --- a/midimonster.c +++ b/midimonster.c @@ -224,7 +224,7 @@ static void event_free(){ } static void version(){ - fprintf(stdout, "MIDIMonster %s\n", MIDIMONSTER_VERSION); + printf("MIDIMonster %s\n", MIDIMONSTER_VERSION); } static int usage(char* fn){ -- cgit v1.2.3