summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2005-10-03 18:38:20 +0000
committerJean Delvare <jdelvare@suse.de>2005-10-03 18:38:20 +0000
commit901f5e3bfe854649764103600db4dff7135484ca (patch)
tree570107d56a65fda1ffb6b0d6f2fe8406f594d075
parent65364b35522401a5a4071239f68eb727ca92cfba (diff)
downloaddmidecode-git-901f5e3bfe854649764103600db4dff7135484ca.tar.gz
Move the command line handling of vpddecode to a separate source file.
-rw-r--r--Makefile9
-rw-r--r--vpddecode.c62
-rw-r--r--vpdopt.c84
-rw-r--r--vpdopt.h34
4 files changed, 125 insertions, 64 deletions
diff --git a/Makefile b/Makefile
index ac2d714..652a560 100644
--- a/Makefile
+++ b/Makefile
@@ -49,8 +49,8 @@ biosdecode : biosdecode.o util.o
ownership : ownership.o util.o
$(CC) $(LDFLAGS) ownership.o util.o -o $@
-vpddecode : vpddecode.o util.o
- $(CC) $(LDFLAGS) vpddecode.o util.o -o $@
+vpddecode : vpddecode.o vpdopt.o util.o
+ $(CC) $(LDFLAGS) vpddecode.o vpdopt.o util.o -o $@
#
# Objects
@@ -69,7 +69,10 @@ biosdecode.o : biosdecode.c version.h types.h util.h config.h
ownership.o : ownership.c version.h types.h util.h config.h
$(CC) $(CFLAGS) -c $< -o $@
-vpddecode.o : vpddecode.c version.h types.h util.h config.h
+vpddecode.o : vpddecode.c version.h types.h util.h config.h vpdopt.h
+ $(CC) $(CFLAGS) -c $< -o $@
+
+vpdopt.o : vpdopt.c config.h vpdopt.h
$(CC) $(CFLAGS) -c $< -o $@
util.o : util.c types.h util.h config.h
diff --git a/vpddecode.c b/vpddecode.c
index 06c5118..6be50a5 100644
--- a/vpddecode.c
+++ b/vpddecode.c
@@ -37,24 +37,12 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <getopt.h>
#include "version.h"
#include "config.h"
#include "types.h"
#include "util.h"
-
-/* Options are global */
-struct opt
-{
- const char* devmem;
- unsigned int flags;
-};
-static struct opt opt;
-
-#define FLAG_VERSION (1<<0)
-#define FLAG_HELP (1<<1)
-#define FLAG_DUMP (1<<2)
+#include "vpdopt.h"
static const char *product_name(const char *id)
{
@@ -299,54 +287,6 @@ static int decode(const u8 *p)
return 1;
}
-/* Return -1 on error, 0 on success */
-static int parse_command_line(int argc, char * const argv[])
-{
- int option;
- const char *optstring = "d:huV";
- struct option longopts[]={
- { "dev-mem", required_argument, NULL, 'd' },
- { "help", no_argument, NULL, 'h' },
- { "dump", no_argument, NULL, 'u' },
- { "version", no_argument, NULL, 'V' },
- { 0, 0, 0, 0 }
- };
-
- while((option=getopt_long(argc, argv, optstring, longopts, NULL))!=-1)
- switch(option)
- {
- case 'd':
- opt.devmem=optarg;
- break;
- case 'h':
- opt.flags|=FLAG_HELP;
- break;
- case 'u':
- opt.flags|=FLAG_DUMP;
- break;
- case 'V':
- opt.flags|=FLAG_VERSION;
- break;
- case '?':
- return -1;
- }
-
- return 0;
-}
-
-static void print_help(void)
-{
- static const char *help=
- "Usage: vpddecode [OPTIONS]\n"
- "Options are:\n"
- " -d, --dev-mem FILE Read memory from device FILE (default: " DEFAULT_MEM_DEV ")\n"
- " -h, --help Display this help text and exit\n"
- " -u, --dump Do not decode the VPD records\n"
- " -V, --version Display the version and exit\n";
-
- printf("%s", help);
-}
-
int main(int argc, char * const argv[])
{
u8 *buf;
diff --git a/vpdopt.c b/vpdopt.c
new file mode 100644
index 0000000..932cd59
--- /dev/null
+++ b/vpdopt.c
@@ -0,0 +1,84 @@
+/*
+ * Command line handling of vpddecode
+ * This file is part of the dmidecode project.
+ *
+ * (C) 2005 Jean Delvare <khali@linux-fr.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+
+#include "config.h"
+#include "vpdopt.h"
+
+
+/* Options are global */
+struct opt opt;
+
+
+/*
+ * Command line options handling
+ */
+
+/* Return -1 on error, 0 on success */
+int parse_command_line(int argc, char * const argv[])
+{
+ int option;
+ const char *optstring = "d:huV";
+ struct option longopts[]={
+ { "dev-mem", required_argument, NULL, 'd' },
+ { "help", no_argument, NULL, 'h' },
+ { "dump", no_argument, NULL, 'u' },
+ { "version", no_argument, NULL, 'V' },
+ { 0, 0, 0, 0 }
+ };
+
+ while((option=getopt_long(argc, argv, optstring, longopts, NULL))!=-1)
+ switch(option)
+ {
+ case 'd':
+ opt.devmem=optarg;
+ break;
+ case 'h':
+ opt.flags|=FLAG_HELP;
+ break;
+ case 'u':
+ opt.flags|=FLAG_DUMP;
+ break;
+ case 'V':
+ opt.flags|=FLAG_VERSION;
+ break;
+ case '?':
+ return -1;
+ }
+
+ return 0;
+}
+
+void print_help(void)
+{
+ static const char *help=
+ "Usage: vpddecode [OPTIONS]\n"
+ "Options are:\n"
+ " -d, --dev-mem FILE Read memory from device FILE (default: " DEFAULT_MEM_DEV ")\n"
+ " -h, --help Display this help text and exit\n"
+ " -u, --dump Do not decode the VPD records\n"
+ " -V, --version Display the version and exit\n";
+
+ printf("%s", help);
+}
diff --git a/vpdopt.h b/vpdopt.h
new file mode 100644
index 0000000..6cb59ee
--- /dev/null
+++ b/vpdopt.h
@@ -0,0 +1,34 @@
+/*
+ * Command line handling of vpddecode
+ * This file is part of the dmidecode project.
+ *
+ * (C) 2005 Jean Delvare <khali@linux-fr.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+struct opt
+{
+ const char* devmem;
+ unsigned int flags;
+};
+extern struct opt opt;
+
+#define FLAG_VERSION (1<<0)
+#define FLAG_HELP (1<<1)
+#define FLAG_DUMP (1<<2)
+
+int parse_command_line(int argc, char * const argv[]);
+void print_help(void);