Mercurial > mplayer.hg
changeset 14538:00c3c4111017
New suboption type: malloc'ed, zero terminated string
author | reimar |
---|---|
date | Wed, 19 Jan 2005 17:10:20 +0000 |
parents | f832c3ec3e4b |
children | de08cc60fd7e |
files | libvo/vo_jpeg.c libvo/vo_md5sum.c libvo/vo_pnm.c libvo/vo_yuv4mpeg.c subopt-helper.c subopt-helper.h |
diffstat | 6 files changed, 35 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/libvo/vo_jpeg.c Wed Jan 19 17:03:59 2005 +0000 +++ b/libvo/vo_jpeg.c Wed Jan 19 17:10:20 2005 +0000 @@ -325,7 +325,6 @@ static uint32_t preinit(const char *arg) { - strarg_t outdir = {0, NULL}, subdirs = {0, NULL}; opt_t subopts[] = { {"progressive", OPT_ARG_BOOL, &jpeg_progressive_mode, NULL}, {"baseline", OPT_ARG_BOOL, &jpeg_baseline, NULL}, @@ -335,8 +334,8 @@ (opt_test_f)int_zero_hundred}, {"quality", OPT_ARG_INT, &jpeg_quality, (opt_test_f)int_zero_hundred}, - {"outdir", OPT_ARG_STR, &outdir, NULL}, - {"subdirs", OPT_ARG_STR, &subdirs, NULL}, + {"outdir", OPT_ARG_MSTRZ, &jpeg_outdir, NULL}, + {"subdirs", OPT_ARG_MSTRZ, &jpeg_subdirs, NULL}, {"maxfiles", OPT_ARG_INT, &jpeg_maxfiles, (opt_test_f)int_pos}, {NULL} }; @@ -351,25 +350,13 @@ jpeg_smooth = 0; jpeg_quality = 75; jpeg_maxfiles = 1000; + jpeg_outdir = strdup("."); + jpeg_subdirs = NULL; if (subopt_parse(arg, subopts) != 0) { return -1; } - if (outdir.len) { - jpeg_outdir = malloc(outdir.len + 1); - memcpy(jpeg_outdir, outdir.str, outdir.len); - jpeg_outdir[outdir.len] = '\0'; - } else { - jpeg_outdir = strdup("."); - } - - if (subdirs.len) { - jpeg_subdirs = malloc(subdirs.len + 1); - memcpy(jpeg_subdirs, subdirs.str, subdirs.len); - jpeg_subdirs[subdirs.len] = '\0'; - } - if (jpeg_progressive_mode) info_message = MSGTR_VO_JPEG_ProgressiveJPEG; else info_message = MSGTR_VO_JPEG_NoProgressiveJPEG; mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, info_message);
--- a/libvo/vo_md5sum.c Wed Jan 19 17:03:59 2005 +0000 +++ b/libvo/vo_md5sum.c Wed Jan 19 17:10:20 2005 +0000 @@ -103,9 +103,8 @@ static uint32_t preinit(const char *arg) { - strarg_t outfile = {0, NULL}; opt_t subopts[] = { - {"outfile", OPT_ARG_STR, &outfile, NULL}, + {"outfile", OPT_ARG_MSTRZ, &md5sum_outfile, NULL}, {NULL} }; @@ -114,18 +113,11 @@ mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, MSGTR_VO_ParsingSuboptions); + md5sum_outfile = strdup("md5sums"); if (subopt_parse(arg, subopts) != 0) { return -1; } - if (outfile.len) { - md5sum_outfile = malloc(outfile.len + 1); - memcpy(md5sum_outfile, outfile.str, outfile.len); - md5sum_outfile[outfile.len] = '\0'; - } else { - md5sum_outfile = strdup("md5sums"); - } - mp_msg(MSGT_VO, MSGL_V, "%s: outfile --> %s\n", info.short_name, md5sum_outfile);
--- a/libvo/vo_pnm.c Wed Jan 19 17:03:59 2005 +0000 +++ b/libvo/vo_pnm.c Wed Jan 19 17:10:20 2005 +0000 @@ -130,16 +130,14 @@ { int ppm_type = 0, pgm_type = 0, pgmyuv_type = 0, raw_mode = 0, ascii_mode = 0; - strarg_t outdir = {0, NULL}, - subdirs = {0, NULL}; opt_t subopts[] = { {"ppm", OPT_ARG_BOOL, &ppm_type, NULL}, {"pgm", OPT_ARG_BOOL, &pgm_type, NULL}, {"pgmyuv", OPT_ARG_BOOL, &pgmyuv_type, NULL}, {"raw", OPT_ARG_BOOL, &raw_mode, NULL}, {"ascii", OPT_ARG_BOOL, &ascii_mode, NULL}, - {"outdir", OPT_ARG_STR, &outdir, NULL}, - {"subdirs", OPT_ARG_STR, &subdirs, NULL}, + {"outdir", OPT_ARG_MSTRZ, &pnm_outdir, NULL}, + {"subdirs", OPT_ARG_MSTRZ, &pnm_subdirs, NULL}, {"maxfiles", OPT_ARG_INT, &pnm_maxfiles, (opt_test_f)int_pos}, {NULL} }; @@ -149,6 +147,8 @@ MSGTR_VO_ParsingSuboptions); pnm_maxfiles = 1000; + pnm_outdir = strdup("."); + pnm_subdirs = NULL; if (subopt_parse(arg, subopts) != 0) { return -1; @@ -163,20 +163,6 @@ if (ascii_mode) pnm_mode = PNM_ASCII_MODE; if (raw_mode) pnm_mode = PNM_RAW_MODE; - if (outdir.len) { - pnm_outdir = malloc(outdir.len + 1); - memcpy(pnm_outdir, outdir.str, outdir.len); - pnm_outdir[outdir.len] = '\0'; - } else { - pnm_outdir = strdup("."); - } - - if (subdirs.len) { - pnm_subdirs = malloc(subdirs.len + 1); - memcpy(pnm_subdirs, subdirs.str, subdirs.len); - pnm_subdirs[subdirs.len] = '\0'; - } - switch (pnm_mode) { case PNM_ASCII_MODE: info_message = MSGTR_VO_PNM_ASCIIMode;
--- a/libvo/vo_yuv4mpeg.c Wed Jan 19 17:03:59 2005 +0000 +++ b/libvo/vo_yuv4mpeg.c Wed Jan 19 17:10:20 2005 +0000 @@ -141,12 +141,12 @@ write_bytes = image_width * image_height * 3 / 2; image = malloc(write_bytes); - yuv_out = fopen(yuv_filename ? yuv_filename : "stream.yuv", "wb"); + yuv_out = fopen(yuv_filename, "wb"); if (!yuv_out || image == 0) { mp_msg(MSGT_VO,MSGL_FATAL, MSGTR_VO_YUV4MPEG_OutFileOpenError, - yuv_filename ? yuv_filename : "stream.yuv"); + yuv_filename); return -1; } image_y = image; @@ -496,17 +496,16 @@ static uint32_t preinit(const char *arg) { int il, il_bf; - strarg_t file; opt_t subopts[] = { {"interlaced", OPT_ARG_BOOL, &il, NULL}, {"interlaced_bf", OPT_ARG_BOOL, &il_bf, NULL}, - {"file", OPT_ARG_STR, &file, NULL}, + {"file", OPT_ARG_MSTRZ, &yuv_filename, NULL}, {NULL} }; il = 0; il_bf = 0; - file.len = 0; + yuv_filename = strdup("stream.yuv"); if (subopt_parse(arg, subopts) != 0) { mp_msg(MSGT_VO, MSGL_FATAL, MSGTR_VO_YUV4MPEG_UnknownSubDev, arg); return -1; @@ -517,12 +516,6 @@ config_interlace = Y4M_ILACE_TOP_FIRST; if (il_bf) config_interlace = Y4M_ILACE_BOTTOM_FIRST; - yuv_filename = NULL; - if (file.len > 0) { - yuv_filename = malloc(file.len + 1); - memcpy(yuv_filename, file.str, file.len); - yuv_filename[file.len] = 0; - } /* Inform user which output mode is used */ switch (config_interlace)
--- a/subopt-helper.c Wed Jan 19 17:03:59 2005 +0000 +++ b/subopt-helper.c Wed Jan 19 17:10:20 2005 +0000 @@ -22,6 +22,7 @@ #include <stdlib.h> #include <string.h> +#include <limits.h> #include <assert.h> #ifndef MPDEBUG @@ -144,6 +145,23 @@ last = parse_str( &str[parse_pos], (strarg_t *)opts[idx].valp ); break; + case OPT_ARG_MSTRZ: + { + char **valp = opts[idx].valp; + strarg_t tmp; + tmp.str = NULL; + tmp.len = 0; + last = parse_str( &str[parse_pos], &tmp ); + if (*valp) + free(*valp); + *valp = NULL; + if (tmp.str && tmp.len > 0) { + *valp = malloc(tmp.len + 1); + memcpy(*valp, tmp.str, tmp.len); + *valp[tmp.len] = 0; + } + break; + } default: assert( 0 && "Arg type of suboption doesn't exist!" ); last = NULL; // break parsing! @@ -237,7 +255,7 @@ match = &str[strlen(str)]; // empty string or too long - if ((match == str) || (match - str > 255)) + if ((match == str) || (match - str > INT_MAX)) return NULL; valp->len = match - str;
--- a/subopt-helper.h Wed Jan 19 17:03:59 2005 +0000 +++ b/subopt-helper.h Wed Jan 19 17:10:20 2005 +0000 @@ -12,6 +12,7 @@ #define OPT_ARG_BOOL 0 #define OPT_ARG_INT 1 #define OPT_ARG_STR 2 +#define OPT_ARG_MSTRZ 3 ///< A malloced, zero terminated string, use free()! typedef int (*opt_test_f)(void *); @@ -34,7 +35,7 @@ /*------------------ arg specific types and declaration -------------------*/ typedef struct strarg_s { - unsigned char len; ///< length of the string determined by the parser + int len; ///< length of the string determined by the parser char const * str; ///< pointer to position inside the parse string } strarg_t;