Wed Jan 23 21:32:32 2013 UTC ()
remove duplicated code, and try to cleanup parsing by using the shared code.
cd9660 needs a lot of work.


(christos)
diff -r1.36 -r1.37 src/usr.sbin/makefs/cd9660.c
diff -r1.36 -r1.37 src/usr.sbin/makefs/makefs.c
diff -r1.4 -r1.5 src/usr.sbin/makefs/chfs.c
diff -r1.4 -r1.5 src/usr.sbin/makefs/v7fs.c
diff -r1.50 -r1.51 src/usr.sbin/makefs/ffs.c
diff -r1.28 -r1.29 src/usr.sbin/makefs/makefs.h
diff -r1.1 -r1.2 src/usr.sbin/makefs/msdos.c

cvs diff -r1.36 -r1.37 src/usr.sbin/makefs/cd9660.c (expand / switch to context diff)
--- src/usr.sbin/makefs/cd9660.c 2013/01/23 20:46:39 1.36
+++ src/usr.sbin/makefs/cd9660.c 2013/01/23 21:32:32 1.37
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660.c,v 1.36 2013/01/23 20:46:39 christos Exp $	*/
+/*	$NetBSD: cd9660.c,v 1.37 2013/01/23 21:32:32 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.36 2013/01/23 20:46:39 christos Exp $");
+__RCSID("$NetBSD: cd9660.c,v 1.37 2013/01/23 21:32:32 christos Exp $");
 #endif  /* !__lint */
 
 #include <string.h>
@@ -424,7 +424,7 @@
 			warnx("Option `%s' doesn't contain a value", var);
 			rv = 0;
 		} else
-			rv = set_option(cd9660_options, var, val);
+			rv = set_option_var(cd9660_options, var, val);
 	}
 
 	if (var)

cvs diff -r1.36 -r1.37 src/usr.sbin/makefs/makefs.c (expand / switch to context diff)
--- src/usr.sbin/makefs/makefs.c 2013/01/23 20:46:39 1.36
+++ src/usr.sbin/makefs/makefs.c 2013/01/23 21:32:32 1.37
@@ -1,4 +1,4 @@
-/*	$NetBSD: makefs.c,v 1.36 2013/01/23 20:46:39 christos Exp $	*/
+/*	$NetBSD: makefs.c,v 1.37 2013/01/23 21:32:32 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.36 2013/01/23 20:46:39 christos Exp $");
+__RCSID("$NetBSD: makefs.c,v 1.37 2013/01/23 21:32:32 christos Exp $");
 #endif	/* !__lint */
 
 #include <assert.h>
@@ -300,9 +300,33 @@
 	/* NOTREACHED */
 }
 
+int
+set_option(const option_t *options, const char *option)
+{
+	char *var, *val;
+	int retval;
 
+	assert(option != NULL);
+
+	if ((var = strdup(option)) == NULL) {
+		err(EXIT_FAILURE, "Allocating memory for copy of option string");
+	}
+	retval = 0;
+	if ((val = strchr(var, '=')) == NULL) {
+		warnx("Option `%s' doesn't contain a value", var);
+		goto out;
+	}
+	*val++ = '\0';
+
+	retval = set_option_var(options, var, val);
+	
+out:
+	free(var);
+	return retval;
+}
+
 int
-set_option(const option_t *options, const char *var, const char *val)
+set_option_var(const option_t *options, const char *var, const char *val)
 {
 	char *s;
 	size_t i;

cvs diff -r1.4 -r1.5 src/usr.sbin/makefs/chfs.c (expand / switch to context diff)
--- src/usr.sbin/makefs/chfs.c 2013/01/23 20:46:39 1.4
+++ src/usr.sbin/makefs/chfs.c 2013/01/23 21:32:32 1.5
@@ -83,28 +83,10 @@
 		{ .name = NULL }
 	};
 
-	char *var, *val;
-	int retval;
-
 	assert(option != NULL);
 	assert(fsopts != NULL);
 
-	if ((var = strdup(option)) == NULL) {
-		err(EXIT_FAILURE, "Allocating memory for copy of option string");
-	}
-	retval = 0;
-
-	if ((val = strchr(var, '=')) == NULL) {
-		warnx("Option `%s' doesn't contain a value", var);
-		goto leave_chfs_parse_opts;
-	}
-	*val++ = '\0';
-
-	retval = set_option(chfs_options, var, val);
-	
-leave_chfs_parse_opts:
-	free(var);
-	return retval;
+	return set_option(chfs_options, option);
 }
 
 void

cvs diff -r1.4 -r1.5 src/usr.sbin/makefs/v7fs.c (expand / switch to context diff)
--- src/usr.sbin/makefs/v7fs.c 2013/01/23 20:46:39 1.4
+++ src/usr.sbin/makefs/v7fs.c 2013/01/23 21:32:32 1.5
@@ -1,4 +1,4 @@
-/*	$NetBSD: v7fs.c,v 1.4 2013/01/23 20:46:39 christos Exp $	*/
+/*	$NetBSD: v7fs.c,v 1.5 2013/01/23 21:32:32 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.4 2013/01/23 20:46:39 christos Exp $");
+__RCSID("$NetBSD: v7fs.c,v 1.5 2013/01/23 21:32:32 christos Exp $");
 #endif	/* !__lint */
 
 #include <stdio.h>
@@ -82,7 +82,7 @@
 		{ .name = NULL }
 	};
 
-	set_option(v7fs_options, option, "1");
+	set_option_var(v7fs_options, option, "1");
 
 	return 1;
 }

cvs diff -r1.50 -r1.51 src/usr.sbin/makefs/ffs.c (expand / switch to context diff)
--- src/usr.sbin/makefs/ffs.c 2013/01/23 20:46:39 1.50
+++ src/usr.sbin/makefs/ffs.c 2013/01/23 21:32:32 1.51
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs.c,v 1.50 2013/01/23 20:46:39 christos Exp $	*/
+/*	$NetBSD: ffs.c,v 1.51 2013/01/23 21:32:32 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.50 2013/01/23 20:46:39 christos Exp $");
+__RCSID("$NetBSD: ffs.c,v 1.51 2013/01/23 21:32:32 christos Exp $");
 #endif	/* !__lint */
 
 #include <sys/param.h>
@@ -186,6 +186,7 @@
 ffs_parse_opts(const char *option, fsinfo_t *fsopts)
 {
 	ffs_opt_t	*ffs_opts = fsopts->fs_specific;
+	char optimization[24];
 
 	option_t ffs_options[] = {
 	    { '\0', "bsize", &ffs_opts->bsize, OPT_INT32,
@@ -208,11 +209,14 @@
 	      1, INT_MAX, "max # of blocks per group" },
 	    { '\0', "version", &ffs_opts->version, OPT_INT32,
 	      1, 2, "UFS version" },
+	    { '\0', "optimization", optimization, OPT_STRARRAY,
+	      1, sizeof(optimization), "Optimization (time|space)" },
+	    { '\0', "label", ffs_opts->label, OPT_STRARRAY,
+	      1, sizeof(ffs_opts->label), "UFS label" },
 	    { .name = NULL }
 	};
 
-	char	*var, *val;
-	int	rv;
+	int	rv, i;
 
 	assert(option != NULL);
 	assert(fsopts != NULL);
@@ -221,36 +225,24 @@
 	if (debug & DEBUG_FS_PARSE_OPTS)
 		printf("ffs_parse_opts: got `%s'\n", option);
 
-	if ((var = strdup(option)) == NULL)
-		err(1, "Allocating memory for copy of option string");
-	rv = 0;
+	rv = set_option(ffs_options, option);
+	if (rv == 0)
+		return 0;
 
-	if ((val = strchr(var, '=')) == NULL) {
-		warnx("Option `%s' doesn't contain a value", var);
-		goto leave_ffs_parse_opts;
-	}
-	*val++ = '\0';
+	for (i = 0; ffs_options[i].name && (1 << i) != rv; i++)
+		continue;
 
-	if (strcmp(var, "optimization") == 0) {
-		if (strcmp(val, "time") == 0) {
+	if (strcmp(ffs_options[i].name, "optimization") == 0) {
+		if (strcmp(optimization, "time") == 0) {
 			ffs_opts->optimization = FS_OPTTIME;
-		} else if (strcmp(val, "space") == 0) {
+		} else if (strcmp(optimization, "space") == 0) {
 			ffs_opts->optimization = FS_OPTSPACE;
 		} else {
-			warnx("Invalid optimization `%s'", val);
-			goto leave_ffs_parse_opts;
+			warnx("Invalid optimization `%s'", optimization);
+			return 0;
 		}
-		rv = 1;
-	} else if (strcmp(var, "label") == 0) {
-		strlcpy(ffs_opts->label, val, sizeof(ffs_opts->label));
-		rv = 1;
-	} else
-		rv = set_option(ffs_options, var, val);
-
- leave_ffs_parse_opts:
-	if (var)
-		free(var);
-	return (rv);
+	}
+	return rv;
 }
 
 

cvs diff -r1.28 -r1.29 src/usr.sbin/makefs/makefs.h (expand / switch to context diff)
--- src/usr.sbin/makefs/makefs.h 2013/01/23 20:46:39 1.28
+++ src/usr.sbin/makefs/makefs.h 2013/01/23 21:32:32 1.29
@@ -1,4 +1,4 @@
-/*	$NetBSD: makefs.h,v 1.28 2013/01/23 20:46:39 christos Exp $	*/
+/*	$NetBSD: makefs.h,v 1.29 2013/01/23 21:32:32 christos Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -171,7 +171,8 @@
 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 *, const char *);
+int		set_option(const option_t *, const char *);
+int		set_option_var(const option_t *, const char *, const char *);
 fsnode *	walk_dir(const char *, const char *, fsnode *, fsnode *);
 void		free_fsnodes(fsnode *);
 

cvs diff -r1.1 -r1.2 src/usr.sbin/makefs/msdos.c (expand / switch to context diff)
--- src/usr.sbin/makefs/msdos.c 2013/01/23 20:46:39 1.1
+++ src/usr.sbin/makefs/msdos.c 2013/01/23 21:32:32 1.2
@@ -1,4 +1,4 @@
-/*	$NetBSD: msdos.c,v 1.1 2013/01/23 20:46:39 christos Exp $	*/
+/*	$NetBSD: msdos.c,v 1.2 2013/01/23 21:32:32 christos Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: msdos.c,v 1.1 2013/01/23 20:46:39 christos Exp $");
+__RCSID("$NetBSD: msdos.c,v 1.2 2013/01/23 21:32:32 christos Exp $");
 #endif	/* !__lint */
 
 #include <sys/param.h>
@@ -109,9 +109,7 @@
 	if (debug & DEBUG_FS_PARSE_OPTS)
 		printf("msdos_parse_opts: got `%s'\n", option);
 
-	set_option(msdos_options, option, "1");
-
-	return 1;
+	return set_option(msdos_options, option);
 }