[FFmpeg-devel] [PATCH 2/3] Make parse_preset_line() account for the preset line parsed, improve feedback.
Stefano Sabatini
stefano.sabatini-lala
Sat Nov 6 15:02:51 CET 2010
---
cmdutils.c | 6 ++++--
cmdutils.h | 4 +++-
ffmpeg.c | 7 ++++---
ffserver.c | 8 +++++---
4 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/cmdutils.c b/cmdutils.c
index 40a77b1..76bf736 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -779,13 +779,14 @@ FILE *get_preset_file(char *filename, size_t filename_size,
}
int parse_preset_line(FILE *preset_file, char *preset_filename,
- char *line, int line_size,
+ char *line, int line_size, int *line_count,
char *key, int key_size, char *val, int val_size)
{
char tmp[1000], tmp2[1000];
while (!feof(preset_file)) {
int e = fscanf(preset_file, "%999[^\n]\n", tmp) - 1;
+ (*line_count)++;
if (line[0] == '#' && !e)
continue;
snprintf(line, line_size, "%s", tmp);
@@ -793,7 +794,8 @@ int parse_preset_line(FILE *preset_file, char *preset_filename,
snprintf(key, key_size, "%s", tmp);
snprintf(val, val_size, "%s", tmp2);
if (e) {
- fprintf(stderr, "%s: Invalid syntax: '%s'\n", preset_filename, line);
+ fprintf(stderr, "%s:%d: Invalid syntax: '%s'\n",
+ preset_filename, *line_count, line);
return AVERROR(EINVAL);
}
return 0;
diff --git a/cmdutils.h b/cmdutils.h
index 2a9bc3c..94ab7a9 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -287,13 +287,15 @@ FILE *get_preset_file(char *filename, size_t filename_size,
* Lines starting with '#' are considered comment, and skipped.
*
* @param line buffer where to put the parsed line, with size given by line_size
+ * @param line_count pointer to an int which will be updated with the number of the
+ * parsed line (starting from 1)
* @param key buffer where to put the parsed key, with size given by key_size
* @param val buffer where to put the parsed value, with size given by val_size
* @return 0 in case of successfull parsing, AVERROR(EINVAL) in case
* of parsing error or AVERROR(EOF) when the file is terminated
*/
int parse_preset_line(FILE *preset_file, char *preset_filename,
- char *line, int line_size,
+ char *line, int line_size, int *line_count,
char *key, int key_size, char *val, int val_size);
#if CONFIG_AVFILTER
diff --git a/ffmpeg.c b/ffmpeg.c
index 1cd6260..8c3c342 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -4029,7 +4029,7 @@ static int opt_bsf(const char *opt, const char *arg)
static int opt_preset(const char *opt, const char *arg)
{
FILE *f=NULL;
- int ret;
+ int ret, line_count = 0;
char filename[1000], tmp[1000], tmp2[1000], line[1000];
char *codec_name = *opt == 'v' ? video_codec_name :
*opt == 'a' ? audio_codec_name :
@@ -4040,7 +4040,7 @@ static int opt_preset(const char *opt, const char *arg)
ffmpeg_exit(1);
}
- while (!(ret = parse_preset_line(f, filename, line, sizeof(line),
+ while (!(ret = parse_preset_line(f, filename, line, sizeof(line), &line_count,
tmp, sizeof(tmp), tmp2, sizeof(tmp2)))) {
if(!strcmp(tmp, "acodec")){
opt_audio_codec(tmp2);
@@ -4049,7 +4049,8 @@ static int opt_preset(const char *opt, const char *arg)
}else if(!strcmp(tmp, "scodec")){
opt_subtitle_codec(tmp2);
}else if(opt_default(tmp, tmp2) < 0){
- fprintf(stderr, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
+ fprintf(stderr, "%s:%d: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
+ filename, line_count, line, tmp, tmp2);
ffmpeg_exit(1);
}
}
diff --git a/ffserver.c b/ffserver.c
index 602d8e3..56a6595 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -3972,7 +3972,7 @@ static int ffserver_opt_preset(const char *arg,
{
FILE *f=NULL;
char filename[1000], tmp[1000], tmp2[1000], line[1000];
- int ret = 0;
+ int ret = 0, line_count = 0;
AVCodec *codec = avcodec_find_encoder(avctx->codec_id);
if (!(f = get_preset_file(filename, sizeof(filename), arg, 0,
@@ -3981,7 +3981,8 @@ static int ffserver_opt_preset(const char *arg,
return 1;
}
- while (!(ret = parse_preset_line(f, filename, line, sizeof(line),
+ while (!(ret = parse_preset_line(f, filename,
+ line, sizeof(line), &line_count,
tmp, sizeof(tmp), tmp2, sizeof(tmp2)))) {
if(!strcmp(tmp, "acodec")){
*audio_id = opt_audio_codec(tmp2);
@@ -3990,7 +3991,8 @@ static int ffserver_opt_preset(const char *arg,
}else if(!strcmp(tmp, "scodec")){
/* opt_subtitle_codec(tmp2); */
}else if(ffserver_opt_default(tmp, tmp2, avctx, type) < 0){
- fprintf(stderr, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
+ fprintf(stderr, "%s:%d: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
+ filename, line_count, line, tmp, tmp2);
ret = 1;
break;
}
--
1.7.1
More information about the ffmpeg-devel
mailing list