mirror of
https://github.com/mpv-player/mpv
synced 2025-04-26 05:09:29 +00:00
New suboption type: malloc'ed, zero terminated string
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@14539 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
ce701ae438
commit
ca8fc9929b
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user