make everything use the generic options parser.

This commit is contained in:
christos 2013-01-29 15:52:25 +00:00
parent b73bbcbf2e
commit 50d02345aa
7 changed files with 166 additions and 129 deletions

@ -1,4 +1,4 @@
/* $NetBSD: cd9660.c,v 1.40 2013/01/29 01:05:57 christos Exp $ */
/* $NetBSD: cd9660.c,v 1.41 2013/01/29 15:52:25 christos Exp $ */
/*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@ -103,7 +103,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: cd9660.c,v 1.40 2013/01/29 01:05:57 christos Exp $");
__RCSID("$NetBSD: cd9660.c,v 1.41 2013/01/29 15:52:25 christos Exp $");
#endif /* !__lint */
#include <string.h>
@ -264,36 +264,65 @@ cd9660_prep_opts(fsinfo_t *fsopts)
iso9660_disk *diskStructure = ecalloc(1, sizeof(*diskStructure));
const option_t cd9660_options[] = {
{ 'h', "help", &diskStructure->displayHelp,
OPT_INT32, 0, 1, "Show help message" },
{ 'l', "isolevel", &diskStructure->isoLevel,
OPT_INT32, 1, 3, "ISO Level" },
{ 'S', "follow-symlinks", &diskStructure->follow_sym_links,
OPT_INT32, 0, 1, "Resolve symlinks in pathnames" },
{ 'v', "verbose", &diskStructure->verbose_level,
OPT_INT32, 0, 2, "Turns on verbose output" },
{ 'L', "Label", diskStructure->primaryDescriptor.volume_id,
OPT_STRARRAY, 1,
sizeof(diskStructure->primaryDescriptor.volume_id),
"Disk Label" },
{ 'R', "rockridge", &diskStructure->rock_ridge_enabled,
OPT_INT32, 0, 1, "Enable Rock-Ridge extensions" },
{ 'A', "archimedes", &diskStructure->archimedes_enabled,
OPT_INT32, 0, 1, "Enable Archimedes structure" },
{ '\0', "chrp-boot", &diskStructure->chrp_boot,
{ 'C', "chrp-boot", &diskStructure->chrp_boot,
OPT_INT32, 0, 1, "Enable CHRP boot" },
{ 'K', "keep-bad-images", &diskStructure->keep_bad_images,
OPT_INT32, 0, 1, "Keep bad images" },
{ '\0', "allow-deep-trees", &diskStructure->allow_deep_trees,
{ 'D', "allow-deep-trees", &diskStructure->allow_deep_trees,
OPT_INT32, 0, 1, "Allow trees more than 8 levels" },
{ '\0', "allow-max-name", &diskStructure->allow_max_name,
{ 'a', "allow-max-name", &diskStructure->allow_max_name,
OPT_INT32, 0, 1, "Allow 37 char filenames (unimplemented)" },
{ '\0', "allow-illegal-chars",
{ 'i', "allow-illegal-chars",
&diskStructure->allow_illegal_chars,
OPT_INT32, 0, 1, "Allow illegal characters in filenames" },
{ '\0', "allow-lowercase", &diskStructure->allow_lowercase,
OPT_INT32, 0, 1, "Allow lowercase characters in filenames" },
{ '\0', "allow-multidot", &diskStructure->allow_multidot,
{ 'D', "allow-multidot", &diskStructure->allow_multidot,
OPT_INT32, 0, 1, "Allow multiple periods in filenames" },
{ '\0', "omit-trailing-period",
{ 'o', "omit-trailing-period",
&diskStructure->omit_trailing_period,
OPT_INT32, 0, 1, "Omit trailing periods in filenames" },
{ '\0', "allow-lowercase", &diskStructure->allow_lowercase,
OPT_INT32, 0, 1, "Allow lowercase characters in filenames" },
{ '\0', "archimedes", &diskStructure->archimedes_enabled,
OPT_INT32, 0, 1, "Enable Archimedes structure" },
{ '\0', "no-trailing-padding",
&diskStructure->include_padding_areas,
OPT_INT32, 0, 1, "Include padding areas" },
{ 'A', "applicationid", NULL, OPT_STRBUF, 0, 0,
"Application Identifier" },
{ 'P', "publisher", NULL, OPT_STRBUF, 0, 0,
"Publisher Identifier" },
{ 'p', "preparer", NULL, OPT_STRBUF, 0, 0,
"Preparer Identifier" },
{ 'L', "label", NULL, OPT_STRBUF, 0, 0,
"Disk Label" },
{ 'V', "volumeid", NULL, OPT_STRBUF, 0, 0,
"Volume Set Identifier" },
{ 'B', "bootimage", NULL, OPT_STRBUF, 0, 0,
"Boot image parameter" },
{ 'G', "generic-bootimage", NULL, OPT_STRBUF, 0, 0,
"Generic boot image parameter" },
{ '\0', "bootimagedir", NULL, OPT_STRBUF, 0, 0,
"Boot image directory" },
{ '\0', "no-emul-boot", NULL, OPT_STRBUF, 0, 0,
"No boot emulation" },
{ '\0', "no-boot", NULL, OPT_STRBUF, 0, 0,
"No boot support" },
{ '\0', "hard-disk-boot", NULL, OPT_STRBUF, 0, 0,
"Boot from hard disk" },
{ '\0', "boot-load-segment", NULL, OPT_STRBUF, 0, 0,
"Boot load segment" },
{ .name = NULL }
};
@ -344,101 +373,105 @@ cd9660_arguments_set_string(const char *val, const char *fieldtitle, int length,
int
cd9660_parse_opts(const char *option, fsinfo_t *fsopts)
{
char *var, *val;
int rv;
int rv, i;
iso9660_disk *diskStructure = fsopts->fs_specific;
if (cd9660_defaults_set == 0)
cd9660_set_defaults(diskStructure);
option_t *cd9660_options = fsopts->fs_options;
char buf[1024];
const char *name, *desc;
assert(option != NULL);
if (debug & DEBUG_FS_PARSE_OPTS)
printf("cd9660_parse_opts: got `%s'\n", option);
var = estrdup(option);
rv = 1;
i = set_option(cd9660_options, option, buf, sizeof(buf));
if (i == -1)
return 0;
val = strchr(var, '=');
if (val != NULL)
*val++ = '\0';
if (cd9660_options[i].name == NULL)
abort();
/* First handle options with no parameters */
if (strcmp(var, "h") == 0) {
diskStructure->displayHelp = 1;
rv = 1;
} else if (CD9660_IS_COMMAND_ARG_DUAL(var, "S", "follow-symlinks")) {
/* this is not handled yet */
diskStructure->follow_sym_links = 1;
rv = 1;
} else if (CD9660_IS_COMMAND_ARG_DUAL(var, "L", "label")) {
rv = cd9660_arguments_set_string(val, "Disk Label", 32, 'd',
diskStructure->primaryDescriptor.volume_id);
} else if (CD9660_IS_COMMAND_ARG_DUAL(var, "A", "applicationid")) {
rv = cd9660_arguments_set_string(val, "Application Identifier", 128, 'a',
diskStructure->primaryDescriptor.application_id);
} else if(CD9660_IS_COMMAND_ARG_DUAL(var, "P", "publisher")) {
rv = cd9660_arguments_set_string(val, "Publisher Identifier",
128, 'a', diskStructure->primaryDescriptor.publisher_id);
} else if (CD9660_IS_COMMAND_ARG_DUAL(var, "p", "preparer")) {
rv = cd9660_arguments_set_string(val, "Preparer Identifier",
128, 'a', diskStructure->primaryDescriptor.preparer_id);
} else if (CD9660_IS_COMMAND_ARG_DUAL(var, "V", "volumeid")) {
rv = cd9660_arguments_set_string(val, "Volume Set Identifier",
128, 'a', diskStructure->primaryDescriptor.volume_set_id);
name = cd9660_options[i].name;
desc = cd9660_options[i].desc;
switch (cd9660_options[i].letter) {
case 'h':
case 'S':
rv = 0; /* this is not handled yet */
break;
case 'L':
rv = cd9660_arguments_set_string(buf, desc, 32, 'd',
diskStructure->primaryDescriptor.volume_id);
break;
case 'A':
rv = cd9660_arguments_set_string(buf, desc, 128, 'a',
diskStructure->primaryDescriptor.application_id);
break;
case 'P':
rv = cd9660_arguments_set_string(buf, desc, 128, 'a',
diskStructure->primaryDescriptor.publisher_id);
break;
case 'p':
rv = cd9660_arguments_set_string(buf, desc, 128, 'a',
diskStructure->primaryDescriptor.preparer_id);
break;
case 'V':
rv = cd9660_arguments_set_string(buf, desc, 128, 'a',
diskStructure->primaryDescriptor.volume_set_id);
break;
/* Boot options */
} else if (CD9660_IS_COMMAND_ARG_DUAL(var, "B", "bootimage")) {
if (val == NULL)
warnx("error: The Boot Image parameter requires a valid boot information string");
else
rv = cd9660_add_boot_disk(diskStructure, val);
} else if (CD9660_IS_COMMAND_ARG(var, "bootimagedir")) {
/*
* XXXfvdl this is unused.
*/
if (val == NULL)
errx(1, "error: The Boot Image Directory parameter"
" requires a directory name\n");
else {
diskStructure->boot_image_directory =
emalloc(strlen(val) + 1);
/* BIG TODO: Add the max length function here */
cd9660_arguments_set_string(val, "Boot Image Directory",
12 , 'd', diskStructure->boot_image_directory);
}
} else if (CD9660_IS_COMMAND_ARG_DUAL(var, "G", "generic-bootimage")) {
if (val == NULL)
warnx("error: The Boot Image parameter requires a valid boot information string");
else
rv = cd9660_add_generic_bootimage(diskStructure, val);
} else if (CD9660_IS_COMMAND_ARG(var, "no-trailing-padding"))
diskStructure->include_padding_areas = 0;
/* RRIP */
else if (CD9660_IS_COMMAND_ARG(var, "no-emul-boot") ||
CD9660_IS_COMMAND_ARG(var, "no-boot") ||
CD9660_IS_COMMAND_ARG(var, "hard-disk-boot")) {
cd9660_eltorito_add_boot_option(diskStructure, var, 0);
/* End of flag variables */
} else if (CD9660_IS_COMMAND_ARG(var, "boot-load-segment")) {
if (val == NULL) {
warnx("Option `%s' doesn't contain a value", var);
rv = 0;
} else {
cd9660_eltorito_add_boot_option(diskStructure, var,
val);
}
} else {
if (val == NULL) {
warnx("Option `%s' doesn't contain a value", var);
case 'B':
if (buf[0] == '\0') {
warnx("The Boot Image parameter requires a valid boot"
" information string");
rv = 0;
} else
rv = set_option_var(fsopts->fs_options, var, val) != -1;
rv = cd9660_add_boot_disk(diskStructure, buf);
break;
case 'G':
if (buf[0] == '\0') {
warnx("The Generic Boot Image parameter requires a"
" valid boot information string");
rv = 0;
} else
rv = cd9660_add_generic_bootimage(diskStructure, buf);
break;
default:
if (strcmp(name, "bootimagedir") == 0) {
/*
* XXXfvdl this is unused.
*/
if (buf[0] == '\0') {
warnx("The Boot Image Directory parameter"
" requires a directory name\n");
rv = 0;
} else {
diskStructure->boot_image_directory =
emalloc(strlen(buf) + 1);
/* BIG TODO: Add the max length function here */
rv = cd9660_arguments_set_string(buf, desc, 12,
'd', diskStructure->boot_image_directory);
}
} else if (strcmp(name, "no-emul-boot") == 0 ||
strcmp(name, "no-boot") == 0 ||
strcmp(name, "hard-disk-boot") == 0) {
/* RRIP */
cd9660_eltorito_add_boot_option(diskStructure, name, 0);
rv = 1;
} else if (strcmp(name, "boot-load-segment") == 0) {
if (buf[0] == '\0') {
warnx("Option `%s' doesn't contain a value",
name);
rv = 0;
} else {
cd9660_eltorito_add_boot_option(diskStructure,
name, buf);
rv = 1;
}
} else
rv = 1;
}
if (var)
free(var);
return (rv);
return rv;
}
/*

@ -1,4 +1,4 @@
/* $NetBSD: cd9660.h,v 1.19 2013/01/28 21:03:27 christos Exp $ */
/* $NetBSD: cd9660.h,v 1.20 2013/01/29 15:52:25 christos Exp $ */
/*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@ -121,12 +121,6 @@ typedef struct {
#define CD9660_MEM_ALLOC_ERROR(_F) \
err(EXIT_FAILURE, "%s, %s l. %d", _F, __FILE__, __LINE__)
#define CD9660_IS_COMMAND_ARG_DUAL(var,short,long)\
(strcmp((var),(short)) == 0) || (strcmp((var),(long))==0)
#define CD9660_IS_COMMAND_ARG(var,arg)\
(strcmp((var),(arg)) == 0)
#define CD9660_TYPE_FILE 0x01
#define CD9660_TYPE_DIR 0x02
#define CD9660_TYPE_DOT 0x04

@ -91,7 +91,7 @@ chfs_parse_opts(const char *option, fsinfo_t *fsopts)
assert(option != NULL);
assert(fsopts != NULL);
return set_option(fsopts->fs_options, option) != -1;
return set_option(fsopts->fs_options, option, NULL, 0) != -1;
}
void

@ -1,4 +1,4 @@
/* $NetBSD: ffs.c,v 1.56 2013/01/28 21:03:27 christos Exp $ */
/* $NetBSD: ffs.c,v 1.57 2013/01/29 15:52:25 christos Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@ -71,7 +71,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: ffs.c,v 1.56 2013/01/28 21:03:27 christos Exp $");
__RCSID("$NetBSD: ffs.c,v 1.57 2013/01/29 15:52:25 christos Exp $");
#endif /* !__lint */
#include <sys/param.h>
@ -152,8 +152,6 @@ static void *ffs_build_dinode2(struct ufs2_dinode *, dirbuf_t *, fsnode *,
int sectorsize; /* XXX: for buf.c::getblk() */
static char optimization[24]; /* XXX: allocate */
/* publically visible functions */
void
ffs_prep_opts(fsinfo_t *fsopts)
@ -181,8 +179,8 @@ ffs_prep_opts(fsinfo_t *fsopts)
1, INT_MAX, "max # of blocks per group" },
{ 'v', "version", &ffs_opts->version, OPT_INT32,
1, 2, "UFS version" },
{ 'o', "optimization", optimization, OPT_STRARRAY,
1, sizeof(optimization), "Optimization (time|space)" },
{ 'o', "optimization", NULL, OPT_STRBUF,
0, 0, "Optimization (time|space)" },
{ 'l', "label", ffs_opts->label, OPT_STRARRAY,
1, sizeof(ffs_opts->label), "UFS label" },
{ .name = NULL }
@ -216,6 +214,7 @@ ffs_parse_opts(const char *option, fsinfo_t *fsopts)
{
ffs_opt_t *ffs_opts = fsopts->fs_specific;
option_t *ffs_options = fsopts->fs_options;
char buf[1024];
int rv;
@ -226,22 +225,26 @@ ffs_parse_opts(const char *option, fsinfo_t *fsopts)
if (debug & DEBUG_FS_PARSE_OPTS)
printf("ffs_parse_opts: got `%s'\n", option);
rv = set_option(ffs_options, option);
rv = set_option(ffs_options, option, buf, sizeof(buf));
if (rv == -1)
return 0;
if (ffs_options[rv].name == NULL)
abort();
if (strcmp(ffs_options[rv].name, "optimization") == 0) {
if (strcmp(optimization, "time") == 0) {
switch (ffs_options[rv].letter) {
case 'o':
if (strcmp(buf, "time") == 0) {
ffs_opts->optimization = FS_OPTTIME;
} else if (strcmp(optimization, "space") == 0) {
} else if (strcmp(buf, "space") == 0) {
ffs_opts->optimization = FS_OPTSPACE;
} else {
warnx("Invalid optimization `%s'", optimization);
warnx("Invalid optimization `%s'", buf);
return 0;
}
break;
default:
break;
}
return 1;
}

@ -1,4 +1,4 @@
/* $NetBSD: makefs.c,v 1.43 2013/01/29 14:09:48 christos Exp $ */
/* $NetBSD: makefs.c,v 1.44 2013/01/29 15:52:25 christos Exp $ */
/*
* Copyright (c) 2001-2003 Wasabi Systems, Inc.
@ -41,7 +41,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: makefs.c,v 1.43 2013/01/29 14:09:48 christos Exp $");
__RCSID("$NetBSD: makefs.c,v 1.44 2013/01/29 15:52:25 christos Exp $");
#endif /* !__lint */
#include <assert.h>
@ -302,7 +302,7 @@ main(int argc, char *argv[])
}
int
set_option(const option_t *options, const char *option)
set_option(const option_t *options, const char *option, char *buf, size_t len)
{
char *var, *val;
int retval;
@ -315,13 +315,14 @@ set_option(const option_t *options, const char *option)
*val++ = '\0';
break;
}
retval = set_option_var(options, var, val);
retval = set_option_var(options, var, val, buf, len);
free(var);
return retval;
}
int
set_option_var(const option_t *options, const char *var, const char *val)
set_option_var(const option_t *options, const char *var, const char *val,
char *buf, size_t len)
{
char *s;
size_t i;
@ -354,7 +355,11 @@ set_option_var(const option_t *options, const char *var, const char *val)
err(1, NULL);
*(char **)options[i].value = s;
break;
case OPT_STRBUF:
if (buf == NULL)
abort();
strlcpy(buf, val, len);
break;
case OPT_INT64:
NUM(64);
case OPT_INT32:

@ -1,4 +1,4 @@
/* $NetBSD: makefs.h,v 1.30 2013/01/28 21:03:27 christos Exp $ */
/* $NetBSD: makefs.h,v 1.31 2013/01/29 15:52:25 christos Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@ -118,6 +118,7 @@ typedef struct _fsnode {
typedef enum {
OPT_STRARRAY,
OPT_STRPTR,
OPT_STRBUF,
OPT_BOOL,
OPT_INT8,
OPT_INT16,
@ -173,8 +174,9 @@ typedef struct {
void apply_specfile(const char *, const char *, fsnode *, int);
void dump_fsnodes(fsnode *);
const char * inode_type(mode_t);
int set_option(const option_t *, const char *);
int set_option_var(const option_t *, const char *, const char *);
int set_option(const option_t *, const char *, char *, size_t);
int set_option_var(const option_t *, const char *, const char *,
char *, size_t);
fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *);
void free_fsnodes(fsnode *);
option_t * copy_opts(const option_t *);

@ -1,4 +1,4 @@
/* $NetBSD: v7fs.c,v 1.7 2013/01/28 21:03:27 christos Exp $ */
/* $NetBSD: v7fs.c,v 1.8 2013/01/29 15:52:25 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: v7fs.c,v 1.7 2013/01/28 21:03:27 christos Exp $");
__RCSID("$NetBSD: v7fs.c,v 1.8 2013/01/29 15:52:25 christos Exp $");
#endif /* !__lint */
#include <stdio.h>
@ -85,7 +85,7 @@ int
v7fs_parse_opts(const char *option, fsinfo_t *fsopts)
{
return set_option_var(fsopts->fs_options, option, "1") != -1;
return set_option_var(fsopts->fs_options, option, "1", NULL, 0) != -1;
}
void