From 5161b3794383b0b0a789714fef3de99b0fdf0abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Fri, 22 Mar 2019 11:58:19 +0100 Subject: [PATCH] Added argument parameters. --- Makefile | 19 +++++++++++++- README | 5 ++-- src/args.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 9 +++++++ 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 src/args.h diff --git a/Makefile b/Makefile index fc5dfbb..1e23790 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,25 @@ +# Copyright (C) 2019 Ortega Froysa, Nicolás +# Author: Ortega Froysa, Nicolás +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + CC=gcc DEBUG=0 INCFLAGS=`pkg-config jack --cflags` LDFLAGS=`pkg-config jack --libs` -lreadline CFLAGS=$(INCFLAGS) -std=c99 -Wall -Wextra -Wfatal-errors -Werror +HDRS=src/args.h OBJS=src/main.o ifeq ($(DEBUG),1) @@ -11,7 +28,7 @@ else CFLAGS+=-O2 -DNDEBUG endif -%.o:%.c +%.o:%.c $(HDRS) $(CC) -c -o $@ $< $(CFLAGS) saus: $(OBJS) diff --git a/README b/README index bcf9803..bc4440b 100644 --- a/README +++ b/README @@ -1,8 +1,8 @@ ============ *** SAUS *** ============ -Scripted AUdio Software is a command-line tool for real-time audio -scripted filtering via JACK audio inputs. The user writes scripts which +Scripted AUdio Software is a command-line tool for real-time scripted +audio filtering via JACK audio inputs. The user writes scripts which modify the frequency and amplitude of the sound waves coming from the JACK input. @@ -13,6 +13,7 @@ To build the project you will require the following dependencies: * GNU Make * C99 compatible compiler * JACK2 + * GNU Readline ## Compiling To compile the project simply run the `make' command in the root diff --git a/src/args.h b/src/args.h new file mode 100644 index 0000000..a93fb76 --- /dev/null +++ b/src/args.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2019 Ortega Froysa, Nicolás + * Author: Ortega Froysa, Nicolás + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +const char *argp_program_version = "SAUS v1.0"; +const char *argp_program_bug_address = ""; + +static char doc[] = "saus -- a command-line tool for real-time " + "scripted audio filtering."; + +static char args_doc[] = "[-v] -f FILE | -l FILE"; + +static struct argp_option options[] = { + { "verbose", 'v', 0, 0, "Make output verbose", 0 }, + { "file", 'f', "FILE", 0, "Script file", 0 }, + { "playlist", 'l', "FILE", 0, "Playlist of script files", 0 }, + { 0 } +}; + +struct arguments { + int verbose; + char *script_file; + char *playlist_file; +}; + +static error_t parse_opt(int key, char *arg, struct argp_state *state) { + struct arguments *arguments = state->input; + + switch(key) + { + case 'v': + arguments->verbose = 1; + break; + case 'f': + arguments->script_file = arg; + break; + case 'l': + arguments->playlist_file = arg; + break; + /*case ARGP_KEY_ARG: + if(state->arg_num > 2) + argp_usage(state); + break; + case ARGP_KEY_END: + if(state->arg_num < 1) + argp_usage(state); + break;*/ + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 }; diff --git a/src/main.c b/src/main.c index 4fe4013..166a067 100644 --- a/src/main.c +++ b/src/main.c @@ -16,8 +16,17 @@ * along with this program. If not, see . */ +#include "args.h" + #include +#include int main(int argc, char *argv[]) { + struct arguments arguments; + arguments.verbose = 0; + arguments.script_file = NULL; + arguments.playlist_file = NULL; + + argp_parse(&argp, argc, argv, 0, 0, &arguments); return 0; }