Browse code

Add option -n to exit if output file exists.

Carl Eugen Hoyos authored on 2011/11/25 05:42:42
Showing 4 changed files
... ...
@@ -119,6 +119,7 @@ static int intra_dc_precision = 8;
119 119
 static int qp_hist = 0;
120 120
 
121 121
 static int file_overwrite = 0;
122
+static int no_file_overwrite = 0;
122 123
 static int do_benchmark = 0;
123 124
 static int do_hex_dump = 0;
124 125
 static int do_pkt_dump = 0;
... ...
@@ -3016,11 +3017,11 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
3016 3016
 
3017 3017
 static void assert_file_overwrite(const char *filename)
3018 3018
 {
3019
-    if (!file_overwrite &&
3019
+    if ((!file_overwrite || no_file_overwrite) &&
3020 3020
         (strchr(filename, ':') == NULL || filename[1] == ':' ||
3021 3021
          av_strstart(filename, "file:", NULL))) {
3022 3022
         if (avio_check(filename, 0) == 0) {
3023
-            if (!using_stdin) {
3023
+            if (!using_stdin && (!no_file_overwrite || file_overwrite)) {
3024 3024
                 fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
3025 3025
                 fflush(stderr);
3026 3026
                 if (!read_yesno()) {
... ...
@@ -4268,6 +4269,7 @@ static const OptionDef options[] = {
4268 4268
     { "f", HAS_ARG | OPT_STRING | OPT_OFFSET, {.off = OFFSET(format)}, "force format", "fmt" },
4269 4269
     { "i", HAS_ARG | OPT_FUNC2, {(void*)opt_input_file}, "input file name", "filename" },
4270 4270
     { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
4271
+    { "n", OPT_BOOL, {(void*)&no_file_overwrite}, "do not overwrite output files" },
4271 4272
     { "c", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
4272 4273
     { "codec", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
4273 4274
     { "pre", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(presets)}, "preset name", "preset" },
... ...
@@ -113,6 +113,9 @@ input file name
113 113
 @item -y (@emph{global})
114 114
 Overwrite output files without asking.
115 115
 
116
+@item -n (@emph{global})
117
+Do not overwrite output files but exit if file exists.
118
+
116 119
 @item -c[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream})
117 120
 @itemx -codec[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream})
118 121
 Select an encoder (when used before an output file) or a decoder (when used
... ...
@@ -94,6 +94,9 @@ input file name
94 94
 @item -y (@emph{global})
95 95
 Overwrite output files without asking.
96 96
 
97
+@item -n (@emph{global})
98
+Do not overwrite output files but exit if file exists.
99
+
97 100
 @item -c[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream})
98 101
 @itemx -codec[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream})
99 102
 Select an encoder (when used before an output file) or a decoder (when used
... ...
@@ -131,6 +131,7 @@ static const char *audio_codec_name    = NULL;
131 131
 static const char *subtitle_codec_name = NULL;
132 132
 
133 133
 static int file_overwrite = 0;
134
+static int no_file_overwrite = 0;
134 135
 static int do_benchmark = 0;
135 136
 static int do_hex_dump = 0;
136 137
 static int do_pkt_dump = 0;
... ...
@@ -3247,11 +3248,11 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
3247 3247
 
3248 3248
 static void assert_file_overwrite(const char *filename)
3249 3249
 {
3250
-    if (!file_overwrite &&
3250
+    if ((!file_overwrite || no_file_overwrite) &&
3251 3251
         (strchr(filename, ':') == NULL || filename[1] == ':' ||
3252 3252
          av_strstart(filename, "file:", NULL))) {
3253 3253
         if (avio_check(filename, 0) == 0) {
3254
-            if (!using_stdin) {
3254
+            if (!using_stdin && (!no_file_overwrite || file_overwrite)) {
3255 3255
                 fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
3256 3256
                 fflush(stderr);
3257 3257
                 term_exit();
... ...
@@ -4619,6 +4620,7 @@ static const OptionDef options[] = {
4619 4619
     { "f", HAS_ARG | OPT_STRING | OPT_OFFSET, {.off = OFFSET(format)}, "force format", "fmt" },
4620 4620
     { "i", HAS_ARG | OPT_FUNC2, {(void*)opt_input_file}, "input file name", "filename" },
4621 4621
     { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
4622
+    { "n", OPT_BOOL, {(void*)&no_file_overwrite}, "do not overwrite output files" },
4622 4623
     { "c", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
4623 4624
     { "codec", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
4624 4625
     { "pre", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(presets)}, "preset name", "preset" },