summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-03-02 22:20:08 -0800
committerH. Peter Anvin <hpa@zytor.com>2008-03-02 22:20:08 -0800
commit763bb1f82a4519bdf240fd5d43f7e776c0d5206f (patch)
treee9c71e85dcb864e99b41e8081c19ce5555875309
parente8004fc8eec23ad151fda3664f7abac1a7391373 (diff)
downloadsyslinux-763bb1f82a4519bdf240fd5d43f7e776c0d5206f.tar.gz
simple menu: break off execute() into its own source file
Break off execute() into its own source file, with the intent of being able to re-use it for a CLI module.
-rw-r--r--com32/menu/Makefile2
-rw-r--r--com32/menu/execute.c70
-rw-r--r--com32/menu/menu.h3
-rw-r--r--com32/menu/menumain.c55
4 files changed, 74 insertions, 56 deletions
diff --git a/com32/menu/Makefile b/com32/menu/Makefile
index d844ef5d..b898ce08 100644
--- a/com32/menu/Makefile
+++ b/com32/menu/Makefile
@@ -54,7 +54,7 @@ MODULES = menu.c32 vesamenu.c32
TESTFILES =
COMMONOBJS = menumain.o readconfig.o passwd.o printmsg.o colors.o \
- background.o refstr.o
+ background.o refstr.o execute.o
all: $(MODULES) $(TESTFILES)
diff --git a/com32/menu/execute.c b/com32/menu/execute.c
new file mode 100644
index 00000000..ace0e571
--- /dev/null
+++ b/com32/menu/execute.c
@@ -0,0 +1,70 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
+ *
+ * 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, Inc., 51 Franklin St, Fifth Floor,
+ * Boston MA 02110-1301, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include <stdlib.h>
+#include <string.h>
+#include <com32.h>
+#include "menu.h"
+
+void execute(const char *cmdline, enum kernel_type type)
+{
+ com32sys_t ireg;
+ const char *p, * const *pp;
+ char *q = __com32.cs_bounce;
+ const char *kernel, *args;
+
+ memset(&ireg, 0, sizeof ireg);
+
+ kernel = q;
+ p = cmdline;
+ while ( *p && !my_isspace(*p) ) {
+ *q++ = *p++;
+ }
+ *q++ = '\0';
+
+ args = q;
+ while ( *p && my_isspace(*p) )
+ p++;
+
+ strcpy(q, p);
+
+ if (kernel[0] == '.' && type == KT_NONE) {
+ /* It might be a type specifier */
+ enum kernel_type type = KT_NONE;
+ for (pp = kernel_types; *pp; pp++, type++) {
+ if (!strcmp(kernel+1, *pp)) {
+ execute(p, type); /* Strip the type specifier and retry */
+ }
+ }
+ }
+
+ if (type == KT_LOCALBOOT) {
+ ireg.eax.w[0] = 0x0014; /* Local boot */
+ ireg.edx.w[0] = strtoul(kernel, NULL, 0);
+ } else {
+ if (type < KT_KERNEL)
+ type = KT_KERNEL;
+
+ ireg.eax.w[0] = 0x0016; /* Run kernel image */
+ ireg.esi.w[0] = OFFS(kernel);
+ ireg.ds = SEG(kernel);
+ ireg.ebx.w[0] = OFFS(args);
+ ireg.es = SEG(args);
+ ireg.edx.l = type-KT_KERNEL;
+ /* ireg.ecx.l = 0; */ /* We do ipappend "manually" */
+ }
+
+ __intcall(0x22, &ireg, NULL);
+
+ /* If this returns, something went bad; return to menu */
+}
+
diff --git a/com32/menu/menu.h b/com32/menu/menu.h
index b8c28687..3cb127e2 100644
--- a/com32/menu/menu.h
+++ b/com32/menu/menu.h
@@ -214,4 +214,7 @@ extern const int message_base_color;
extern const char *current_background;
void set_background(const char *new_background);
+/* execute.c */
+void execute(const char *cmdline, enum kernel_type type);
+
#endif /* MENU_H */
diff --git a/com32/menu/menumain.c b/com32/menu/menumain.c
index 59ba32ad..ac1f9439 100644
--- a/com32/menu/menumain.c
+++ b/com32/menu/menumain.c
@@ -1017,61 +1017,6 @@ run_menu(void)
return cmdline;
}
-
-static void
-execute(const char *cmdline, enum kernel_type type)
-{
- com32sys_t ireg;
- const char *p, * const *pp;
- char *q = __com32.cs_bounce;
- const char *kernel, *args;
-
- memset(&ireg, 0, sizeof ireg);
-
- kernel = q;
- p = cmdline;
- while ( *p && !my_isspace(*p) ) {
- *q++ = *p++;
- }
- *q++ = '\0';
-
- args = q;
- while ( *p && my_isspace(*p) )
- p++;
-
- strcpy(q, p);
-
- if (kernel[0] == '.' && type == KT_NONE) {
- /* It might be a type specifier */
- enum kernel_type type = KT_NONE;
- for (pp = kernel_types; *pp; pp++, type++) {
- if (!strcmp(kernel+1, *pp)) {
- execute(p, type); /* Strip the type specifier and retry */
- }
- }
- }
-
- if (type == KT_LOCALBOOT) {
- ireg.eax.w[0] = 0x0014; /* Local boot */
- ireg.edx.w[0] = strtoul(kernel, NULL, 0);
- } else {
- if (type < KT_KERNEL)
- type = KT_KERNEL;
-
- ireg.eax.w[0] = 0x0016; /* Run kernel image */
- ireg.esi.w[0] = OFFS(kernel);
- ireg.ds = SEG(kernel);
- ireg.ebx.w[0] = OFFS(args);
- ireg.es = SEG(args);
- ireg.edx.l = type-KT_KERNEL;
- /* ireg.ecx.l = 0; */ /* We do ipappend "manually" */
- }
-
- __intcall(0x22, &ireg, NULL);
-
- /* If this returns, something went bad; return to menu */
-}
-
int menu_main(int argc, char *argv[])
{
const char *cmdline;