From 0a509c6152bae66fbd43f98beb38be593111a9a9 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 7 Dec 2013 23:51:09 -0500 Subject: [PATCH] examples/: check if sink_uri exists, add -f to force overwrite --- examples/parse_args.h | 9 ++++++++- examples/utils.c | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/parse_args.h b/examples/parse_args.h index 0198230b..d0386ccd 100644 --- a/examples/parse_args.h +++ b/examples/parse_args.h @@ -40,6 +40,8 @@ extern char_t * tempo_method; extern smpl_t silence_threshold; extern uint_t mix_input; +extern uint_t force_overwrite; + // functions defined in utils.c extern void examples_common_init (int argc, char **argv); extern void examples_common_del (void); @@ -78,6 +80,7 @@ usage (FILE * stream, int exit_code) " -s --silence select silence threshold\n" #ifdef PROG_HAS_OUTPUT " -m --mix-input mix input signal with output signal\n" + " -f --force-overwrite overwrite output file if\n" #endif #ifdef PROG_HAS_JACK " -j --jack use Jack\n" @@ -105,7 +108,7 @@ parse_args (int argc, char **argv) #ifdef PROG_HAS_PITCH "p:u:l:" #endif /* PROG_HAS_PITCH */ - "s:m"; + "s:mf"; int next_option; struct option long_options[] = { {"help", 0, NULL, 'h'}, @@ -131,6 +134,7 @@ parse_args (int argc, char **argv) #endif /* PROG_HAS_PITCH */ {"silence", 1, NULL, 's'}, {"mix-input", 0, NULL, 'm'}, + {"force-overwrite", 0, NULL, 'f'}, {NULL, 0, NULL, 0} }; prog_name = argv[0]; @@ -156,6 +160,9 @@ parse_args (int argc, char **argv) case 'o': sink_uri = optarg; break; + case 'f': /* force_overwrite flag */ + force_overwrite = 1; + break; case 'r': samplerate = atoi (optarg); break; diff --git a/examples/utils.c b/examples/utils.c index 2c4c90e2..f5c1d55f 100644 --- a/examples/utils.c +++ b/examples/utils.c @@ -53,6 +53,8 @@ char_t * tempo_method = "default"; smpl_t silence_threshold = -90.; uint_t mix_input = 0; +uint_t force_overwrite = 0; + // // internal memory stuff aubio_source_t *this_source = NULL; @@ -88,6 +90,12 @@ examples_common_init (int argc, char **argv) samplerate = aubio_source_get_samplerate(this_source); } if (sink_uri != NULL) { + uint_t sink_exists = (access(sink_uri, F_OK) == 0 ); + if (!force_overwrite && sink_exists) { + outmsg ("Output file %s already exists, use -f to overwrite.\n", + sink_uri); + exit (1); + } this_sink = new_aubio_sink ((char_t*)sink_uri, samplerate); if (this_sink == NULL) { outmsg ("Could not open output file %s\n", sink_uri); -- 2.11.0