summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-01-19 17:10:20 +0000
committerreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-01-19 17:10:20 +0000
commitca8fc9929bdc71e2192a8fdbcab2eb0c1fb6191c (patch)
treeeb22dec8700b3581b735ae10863416673aac0c70
parentce701ae4386237798ffe06447021481e8e8002fc (diff)
downloadmpv-ca8fc9929bdc71e2192a8fdbcab2eb0c1fb6191c.tar.bz2
mpv-ca8fc9929bdc71e2192a8fdbcab2eb0c1fb6191c.tar.xz
New suboption type: malloc'ed, zero terminated string
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@14539 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--libvo/vo_jpeg.c21
-rw-r--r--libvo/vo_md5sum.c12
-rw-r--r--libvo/vo_pnm.c22
-rw-r--r--libvo/vo_yuv4mpeg.c15
-rw-r--r--subopt-helper.c20
-rw-r--r--subopt-helper.h3
6 files changed, 35 insertions, 58 deletions
diff --git a/libvo/vo_jpeg.c b/libvo/vo_jpeg.c
index 6d1c097d1e..9fe73f425f 100644
--- a/libvo/vo_jpeg.c
+++ b/libvo/vo_jpeg.c
@@ -325,7 +325,6 @@ static int int_pos(int *mf)
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 @@ static uint32_t preinit(const char *arg)
(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 @@ static uint32_t preinit(const char *arg)
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);
diff --git a/libvo/vo_md5sum.c b/libvo/vo_md5sum.c
index d4a08414ee..35ce3a645e 100644
--- a/libvo/vo_md5sum.c
+++ b/libvo/vo_md5sum.c
@@ -103,9 +103,8 @@ void md5sum_write_error(void) {
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 @@ static uint32_t preinit(const char *arg)
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);
diff --git a/libvo/vo_pnm.c b/libvo/vo_pnm.c
index 40245c6c76..68d4866a08 100644
--- a/libvo/vo_pnm.c
+++ b/libvo/vo_pnm.c
@@ -130,16 +130,14 @@ static uint32_t preinit(const char *arg)
{
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 @@ static uint32_t preinit(const char *arg)
MSGTR_VO_ParsingSuboptions);
pnm_maxfiles = 1000;
+ pnm_outdir = strdup(".");
+ pnm_subdirs = NULL;
if (subopt_parse(arg, subopts) != 0) {
return -1;
@@ -163,20 +163,6 @@ static uint32_t preinit(const char *arg)
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;
diff --git a/libvo/vo_yuv4mpeg.c b/libvo/vo_yuv4mpeg.c
index 6463657d3f..10afcd1d6d 100644
--- a/libvo/vo_yuv4mpeg.c
+++ b/libvo/vo_yuv4mpeg.c
@@ -141,12 +141,12 @@ static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width,
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 void check_events(void)
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 @@ static uint32_t preinit(const char *arg)
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)
diff --git a/subopt-helper.c b/subopt-helper.c
index df2ceda639..1ffd5fe746 100644
--- a/subopt-helper.c
+++ b/subopt-helper.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include <assert.h>
#ifndef MPDEBUG
@@ -144,6 +145,23 @@ int subopt_parse( char const * const str, opt_t * opts )
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 @@ static char const * parse_str( char const * const str, strarg_t * const valp )
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;
diff --git a/subopt-helper.h b/subopt-helper.h
index 6479f3894e..5891b8c0c8 100644
--- a/subopt-helper.h
+++ b/subopt-helper.h
@@ -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 @@ int subopt_parse( char const * const str, opt_t * opts );
/*------------------ 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;