[syslinux:master] dos: Use libinstaller option parser

syslinux-bot for Shao Miller shao.miller at yrdsb.edu.on.ca
Mon Jul 19 21:24:15 PDT 2010


Commit-ID:  c02184c7378991951ffe07add1ff368a8663c18b
Gitweb:     http://syslinux.zytor.com/commit/c02184c7378991951ffe07add1ff368a8663c18b
Author:     Shao Miller <shao.miller at yrdsb.edu.on.ca>
AuthorDate: Mon, 19 Jul 2010 23:21:57 -0400
Committer:  Shao Miller <shao.miller at yrdsb.edu.on.ca>
CommitDate: Mon, 19 Jul 2010 23:24:01 -0400

dos: Use libinstaller option parser

We will produce an error message if a user attempts
to use an option we don't implement.

Signed-off-by: Shao Miller <shao.miller at yrdsb.edu.on.ca>


---
 MCONFIG.local           |    1 -
 NEWS                    |    2 +-
 dos/syslinux.c          |   80 +++++++++++-----------------------------------
 libinstaller/syslxopt.c |    5 ++-
 win32/syslinux.c        |    2 -
 5 files changed, 23 insertions(+), 67 deletions(-)

diff --git a/MCONFIG.local b/MCONFIG.local
deleted file mode 100644
index f91fc16..0000000
--- a/MCONFIG.local
+++ /dev/null
@@ -1 +0,0 @@
-CFLAGS += -DDEBUG=1
diff --git a/NEWS b/NEWS
index dff79d9..88d1236 100644
--- a/NEWS
+++ b/NEWS
@@ -24,7 +24,7 @@ Changes in 4.02:
 	  full.
 	* Handle fallbacks from EDD to CHS, to deal with systems which
 	  announce EDD support but don't actually have it.
-	* SYSLINUX: the mtools and win32 installers now use the new
+	* SYSLINUX: the mtools, DOS and win32 installers now use the new
 	  command line options.
 
 Changes in 4.01:
diff --git a/dos/syslinux.c b/dos/syslinux.c
index 1e08659..b5fdfc5 100644
--- a/dos/syslinux.c
+++ b/dos/syslinux.c
@@ -32,7 +32,7 @@
 #include "syslxopt.h"
 #include "syslxint.h"
 
-const char *program = "syslinux";	/* Name of program */
+char *program = "syslinux.com";		/* Name of program */
 uint16_t dos_version;
 
 #ifdef DEBUG
@@ -587,22 +587,14 @@ int main(int argc, char *argv[])
     static unsigned char sectbuf[SECTOR_SIZE];
     int dev_fd, fd;
     static char ldlinux_name[] = "@:\\ldlinux.sys";
-    char **argp, *opt;
-    int force = 0;		/* -f (force) option */
     struct libfat_filesystem *fs;
     libfat_sector_t s, *secp;
     libfat_sector_t *sectors;
     int ldlinux_sectors;
     int32_t ldlinux_cluster;
     int nsectors;
-    const char *device = NULL, *bootsecfile = NULL;
     const char *errmsg;
     int i;
-    int writembr = 0;		/* -m (write MBR) option */
-    int set_active = 0;		/* -a (set partition active) option */
-    const char *subdir = NULL;
-    int stupid = 0;
-    int raid_mode = 0;
     int patch_sectors;
     unsigned char *dp;
 
@@ -610,54 +602,20 @@ int main(int argc, char *argv[])
     for (i = 0; i <= argc; i++)
 	dprintf("argv[%d] = %p = \"%s\"\n", i, argv[i], argv[i]);
 
-    (void)argc;			/* Unused */
-
     get_dos_version();
 
-    for (argp = argv + 1; *argp; argp++) {
-	if (**argp == '-') {
-	    opt = *argp + 1;
-	    if (!*opt)
-		usage(EX_USAGE, MODE_SYSLINUX_DOSWIN);
-
-	    while (*opt) {
-		switch (*opt) {
-		case 's':	/* Use "safe, slow and stupid" code */
-		    stupid = 1;
-		    break;
-		case 'r':	/* RAID mode */
-		    raid_mode = 1;
-		    break;
-		case 'f':	/* Force install */
-		    force = 1;
-		    break;
-		case 'm':	/* Write MBR */
-		    writembr = 1;
-		    break;
-		case 'a':	/* Set partition active */
-		    set_active = 1;
-		    break;
-		case 'd':
-		    if (argp[1])
-			subdir = *++argp;
-		    break;
-		default:
-		    usage(EX_USAGE, MODE_SYSLINUX_DOSWIN);
-		}
-		opt++;
-	    }
-	} else {
-	    if (bootsecfile)
-		usage(EX_USAGE, MODE_SYSLINUX_DOSWIN);
-	    else if (device)
-		bootsecfile = *argp;
-	    else
-		device = *argp;
-	}
-    }
+    argv[0] = program;
+    parse_options(argc, argv, MODE_SYSLINUX_DOSWIN);
 
-    if (!device)
+    if (!opt.device)
 	usage(EX_USAGE, MODE_SYSLINUX_DOSWIN);
+    if (opt.sectors || opt.heads || opt.reset_adv || opt.set_once
+	|| (opt.update_only > 0) || opt.menu_save || opt.offset) {
+	fprintf(stderr,
+		"At least one specified option not yet implemented"
+		" for this installer.\n");
+	exit(1);
+    }
 
     /*
      * Create an ADV in memory... this should be smarter.
@@ -667,8 +625,8 @@ int main(int argc, char *argv[])
     /*
      * Figure out which drive we're talking to
      */
-    dev_fd = (device[0] & ~0x20) - 0x40;
-    if (dev_fd < 1 || dev_fd > 26 || device[1] != ':' || device[2])
+    dev_fd = (opt.device[0] & ~0x20) - 0x40;
+    if (dev_fd < 1 || dev_fd > 26 || opt.device[1] != ':' || opt.device[2])
 	usage(EX_USAGE, MODE_SYSLINUX_DOSWIN);
 
     set_lock_device(dev_fd);
@@ -721,7 +679,7 @@ int main(int argc, char *argv[])
     /*
      * If requested, move ldlinux.sys
      */
-    if (subdir) {
+    if (opt.directory) {
 	char new_ldlinux_name[160];
 	char *cp = new_ldlinux_name + 3;
 	const char *sd;
@@ -731,7 +689,7 @@ int main(int argc, char *argv[])
 	new_ldlinux_name[1] = ':';
 	new_ldlinux_name[2] = '\\';
 
-	for (sd = subdir; *sd; sd++) {
+	for (sd = opt.directory; *sd; sd++) {
 	    char c = *sd;
 
 	    if (c == '/' || c == '\\') {
@@ -764,7 +722,7 @@ int main(int argc, char *argv[])
     /*
      * Patch ldlinux.sys and the boot sector
      */
-    i = syslinux_patch(sectors, nsectors, stupid, raid_mode, subdir, NULL);
+    i = syslinux_patch(sectors, nsectors, opt.stupid_mode, opt.raid_mode, opt.directory, NULL);
     patch_sectors = (i + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
 
     /*
@@ -781,7 +739,7 @@ int main(int argc, char *argv[])
     /*
      * Muck with the MBR, if desired, while we hold the lock
      */
-    adjust_mbr(dev_fd, writembr, set_active);
+    adjust_mbr(dev_fd, opt.install_mbr, opt.activate_partition);
 
     /*
      * To finish up, write the boot sector
@@ -794,9 +752,9 @@ int main(int argc, char *argv[])
     syslinux_make_bootsect(sectbuf);
 
     /* Write new boot sector */
-    if (bootsecfile) {
+    if (opt.bootsecfile) {
 	unlock_device(0);
-	fd = creat(bootsecfile, 0x20);	/* ARCHIVE */
+	fd = creat(opt.bootsecfile, 0x20);	/* ARCHIVE */
 	write_file(fd, sectbuf, SECTOR_SIZE);
 	close(fd);
     } else {
diff --git a/libinstaller/syslxopt.c b/libinstaller/syslxopt.c
index eb00dbd..18a6baa 100644
--- a/libinstaller/syslxopt.c
+++ b/libinstaller/syslxopt.c
@@ -93,7 +93,8 @@ void __attribute__ ((noreturn)) usage(int rv, enum syslinux_mode mode)
     case MODE_SYSLINUX_DOSWIN:
 	/* For fs installation under Windows (syslinux.exe) */
 	fprintf(stderr,
-	    "Usage: %s [options] <drive>: [bootsecfile]\n",
+	    "Usage: %s [options] <drive>: [bootsecfile]\n"
+	    "  --directory  -d  Directory for installation target\n",
 	    program);
 	break;
     }
@@ -123,7 +124,7 @@ void __attribute__ ((noreturn)) usage(int rv, enum syslinux_mode mode)
 	    "  which includes zipdisks and LS-120 superfloppies.\n"
 	    "\n"
 	    "  The -z option is useful for USB devices which are considered\n"
-	    "  hard disks by some BIOSes and zipdrives by other BIOSes.\n");
+	    "  hard disks by some BIOSes and zipdrives by other BIOSes.");
 
     exit(rv);
 }
diff --git a/win32/syslinux.c b/win32/syslinux.c
index 9459385..1f95e84 100755
--- a/win32/syslinux.c
+++ b/win32/syslinux.c
@@ -252,8 +252,6 @@ int main(int argc, char *argv[])
     uint32_t ldlinux_cluster;
     int nsectors;
 
-    (void)argc;
-
     if (!checkver()) {
 	fprintf(stderr,
 		"You need to be running at least Windows NT; use syslinux.com instead.\n");



More information about the Syslinux-commits mailing list