Module Name:    src
Committed By:   christos
Date:           Wed Jan 23 21:32:32 UTC 2013

Modified Files:
        src/usr.sbin/makefs: cd9660.c chfs.c ffs.c makefs.c makefs.h msdos.c
            v7fs.c

Log Message:
remove duplicated code, and try to cleanup parsing by using the shared code.
cd9660 needs a lot of work.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/usr.sbin/makefs/cd9660.c \
    src/usr.sbin/makefs/makefs.c
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/makefs/chfs.c \
    src/usr.sbin/makefs/v7fs.c
cvs rdiff -u -r1.50 -r1.51 src/usr.sbin/makefs/ffs.c
cvs rdiff -u -r1.28 -r1.29 src/usr.sbin/makefs/makefs.h
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/makefs/msdos.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/makefs/cd9660.c
diff -u src/usr.sbin/makefs/cd9660.c:1.36 src/usr.sbin/makefs/cd9660.c:1.37
--- src/usr.sbin/makefs/cd9660.c:1.36	Wed Jan 23 15:46:39 2013
+++ src/usr.sbin/makefs/cd9660.c	Wed Jan 23 16:32:32 2013
@@ -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 @@ cd9660_parse_opts(const char *option, fs
 			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)
Index: src/usr.sbin/makefs/makefs.c
diff -u src/usr.sbin/makefs/makefs.c:1.36 src/usr.sbin/makefs/makefs.c:1.37
--- src/usr.sbin/makefs/makefs.c:1.36	Wed Jan 23 15:46:39 2013
+++ src/usr.sbin/makefs/makefs.c	Wed Jan 23 16:32:32 2013
@@ -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 @@ main(int argc, char *argv[])
 	/* 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;

Index: src/usr.sbin/makefs/chfs.c
diff -u src/usr.sbin/makefs/chfs.c:1.4 src/usr.sbin/makefs/chfs.c:1.5
--- src/usr.sbin/makefs/chfs.c:1.4	Wed Jan 23 15:46:39 2013
+++ src/usr.sbin/makefs/chfs.c	Wed Jan 23 16:32:32 2013
@@ -83,28 +83,10 @@ chfs_parse_opts(const char *option, fsin
 		{ .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
Index: src/usr.sbin/makefs/v7fs.c
diff -u src/usr.sbin/makefs/v7fs.c:1.4 src/usr.sbin/makefs/v7fs.c:1.5
--- src/usr.sbin/makefs/v7fs.c:1.4	Wed Jan 23 15:46:39 2013
+++ src/usr.sbin/makefs/v7fs.c	Wed Jan 23 16:32:32 2013
@@ -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 @@ v7fs_parse_opts(const char *option, fsin
 		{ .name = NULL }
 	};
 
-	set_option(v7fs_options, option, "1");
+	set_option_var(v7fs_options, option, "1");
 
 	return 1;
 }

Index: src/usr.sbin/makefs/ffs.c
diff -u src/usr.sbin/makefs/ffs.c:1.50 src/usr.sbin/makefs/ffs.c:1.51
--- src/usr.sbin/makefs/ffs.c:1.50	Wed Jan 23 15:46:39 2013
+++ src/usr.sbin/makefs/ffs.c	Wed Jan 23 16:32:32 2013
@@ -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 @@ int
 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 @@ ffs_parse_opts(const char *option, fsinf
 	      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 @@ ffs_parse_opts(const char *option, fsinf
 	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;
-
-	if ((val = strchr(var, '=')) == NULL) {
-		warnx("Option `%s' doesn't contain a value", var);
-		goto leave_ffs_parse_opts;
-	}
-	*val++ = '\0';
+	rv = set_option(ffs_options, option);
+	if (rv == 0)
+		return 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;
 }
 
 

Index: src/usr.sbin/makefs/makefs.h
diff -u src/usr.sbin/makefs/makefs.h:1.28 src/usr.sbin/makefs/makefs.h:1.29
--- src/usr.sbin/makefs/makefs.h:1.28	Wed Jan 23 15:46:39 2013
+++ src/usr.sbin/makefs/makefs.h	Wed Jan 23 16:32:32 2013
@@ -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 @@ 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 *, 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 *);
 

Index: src/usr.sbin/makefs/msdos.c
diff -u src/usr.sbin/makefs/msdos.c:1.1 src/usr.sbin/makefs/msdos.c:1.2
--- src/usr.sbin/makefs/msdos.c:1.1	Wed Jan 23 15:46:39 2013
+++ src/usr.sbin/makefs/msdos.c	Wed Jan 23 16:32:32 2013
@@ -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 @@ ALLOPTS
 	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);
 }
 
 

Reply via email to