The following changes since commit 844e965443e08133a7a366a496d8cc52ef93ca48:
Merge commit 'syslinux-4.04-pre18' into elflink (2011-04-04 14:12:08
-0700)
are available in the git repository at:
git://git.zytor.com/users/mfleming/syslinux.git for-hpa/elflink/ldlinux
Matt Fleming (3):
ldlinux, cli: Do not assign 'comm_counter' unnecessarily
ldlinux: Move cmdline processing out of cli.c
ldlinux: Pass entire cmdline to execute()
com32/elflink/ldlinux/cli.c | 76 +++-----------------------------
com32/elflink/ldlinux/ldlinux.c | 87 +++++++++++++++++++++++++++--------
com32/elflink/ldlinux/readconfig.c | 2 +-
com32/elflink/modules/cli.h | 1 -
com32/elflink/modules/menu.h | 2 +
5 files changed, 76 insertions(+), 92 deletions(-)
diff --git a/com32/elflink/ldlinux/cli.c b/com32/elflink/ldlinux/cli.c
index 0884525..3026cac 100644
--- a/com32/elflink/ldlinux/cli.c
+++ b/com32/elflink/ldlinux/cli.c
@@ -141,8 +141,6 @@ const char *edit_cmdline(const char *input, int top /*, int
width */ ,
const char *ret;
int width = 0;
struct cli_command *comm_counter;
- comm_counter - list_entry(cli_history_head.next->prev,
typeof(*comm_counter), list);
if (!width) {
int height;
@@ -447,76 +445,14 @@ const char *edit_cmdline(const char *input, int top /*,
int width */ ,
}
printf("\033[?7h");
- return ret;
-}
-
-void process_command(const char *cmd, bool history)
-{
- char **argv = malloc((MAX_COMMAND_ARGS + 1) * sizeof(char *));
- char *temp_cmd = (char *)malloc(sizeof(char) * (strlen(cmd) + 1));
- int argc = 1, len_mn;
- char *crt_arg, *module_name;
-
- /* return if user only press enter */
- if (cmd[0] == '\0') {
- printf("\n");
- return;
- }
- printf("\n");
-
- if (history) {
- struct cli_command *comm;
- comm = malloc(sizeof(struct cli_command));
- comm->command = malloc(sizeof(char) * (strlen(cmd) + 1));
- strcpy(comm->command, cmd);
- list_add(&(comm->list), &cli_history_head);
- }
-
- // dprintf("raw cmd = %s", cmd);
- strcpy(temp_cmd, cmd);
- module_name = strtok((char *)cmd, COMMAND_DELIM);
- len_mn = strlen(module_name);
-
- if (!strcmp(module_name + len_mn - 4, ".c32")) {
- if (module_find(module_name) != NULL) {
- /* make module re-enterable */
- // dprintf("Module %s is already running");
- }
- do {
- argv[0] = module_name;
- crt_arg = strtok(NULL, COMMAND_DELIM);
- if (crt_arg != NULL && strlen(crt_arg) > 0) {
- argv[argc] = crt_arg;
- argc++;
- } else
- break;
- } while (argc < MAX_COMMAND_ARGS);
- argv[argc] = NULL;
- module_load_dependencies(module_name, MODULES_DEP);
- spawn_load(module_name, (const char **)argv);
- } else if (!strcmp(module_name + len_mn - 2, ".0")) {
- execute(cmd, KT_PXE);
- } else if (!strcmp(module_name + len_mn - 3, ".bs")) {
- } else if (!strcmp(module_name + len_mn - 4, ".img")) {
- execute(cmd, KT_FDIMAGE);
- } else if (!strcmp(module_name + len_mn - 4, ".bin")) {
- } else if (!strcmp(module_name + len_mn - 4, ".bss")) {
- execute(cmd, KT_BSS);
- } else if (!strcmp(module_name + len_mn - 4, ".com")
- || !strcmp(module_name + len_mn - 4, ".cbt")) {
- execute(cmd, KT_COMBOOT);
- } else if (!strcmp(module_name + len_mn - 4, ".cfg")
- || !strcmp(module_name + len_mn - 5, ".conf")
- || !strcmp(module_name + len_mn - 7, ".config")) {
- execute(module_name, KT_CONFIG);
- }
- /* use KT_KERNEL as default */
- else
- execute(temp_cmd, KT_KERNEL);
+ /* Add the command to the history */
+ comm_counter = malloc(sizeof(struct cli_command));
+ comm_counter->command = malloc(sizeof(char) * (strlen(ret) + 1));
+ strcpy(comm_counter->command, ret);
+ list_add(&(comm_counter->list), &cli_history_head);
- free(argv);
- free(temp_cmd);
+ return ret;
}
static int cli_init(void)
diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c
index ea889cc..839a28a 100644
--- a/com32/elflink/ldlinux/ldlinux.c
+++ b/com32/elflink/ldlinux/ldlinux.c
@@ -11,35 +11,61 @@
#include <sys/module.h>
-static void enter_cmdline(void)
+/*
+ * Attempt to load a kernel after deciding what type of image it is.
+ *
+ * We only return from this function if something went wrong loading
+ * the the kernel. If we return the caller should call enter_cmdline()
+ * so that the user can help us out.
+ */
+static void load_kernel(const char *kernel)
{
- const char *cmdline;
+ struct menu_entry *me;
+ enum kernel_type type;
+ const char *cmdline, *p;
+ int len;
- /* Enter endless command line prompt, should support "exit" */
- while (1) {
- cmdline = edit_cmdline("syslinux$", 1, NULL, cat_help_file);
- if (!cmdline)
- continue;
- /* feng: give up the aux check here */
- //aux = list_entry(cli_history_head.next, typeof(*aux), list);
- //if (strcmp(aux->command, cmdline)) {
- process_command(cmdline, true);
- //}
+ /* Virtual kernel? */
+ me = find_label(kernel);
+ if (me) {
+ /* XXX we don't handle LOCALBOOT yet */
+ execute(me->cmdline, KT_KERNEL);
+ /* We shouldn't return */
+ goto bad_kernel;
}
-}
-static void load_kernel(void)
-{
- enum kernel_type type;
- const char *cmdline;
+ if (!allowimplicit)
+ goto bad_implicit;
- if (defaultlevel == LEVEL_UI)
+ /* Find the end of the command */
+ while (*p && !my_isspace(*p))
+ p++;
+
+ len = p - kernel;
+ if (!strncmp(kernel + len - 4, ".c32", 4)) {
type = KT_COM32;
+ } else if (!strncmp(kernel + len - 2, ".0", 2)) {
+ type = KT_PXE;
+ } else if (!strncmp(kernel + len - 3, ".bs", 3)) {
+ type = KT_BOOT;
+ } else if (!strncmp(kernel + len - 4, ".img", 4)) {
+ type = KT_FDIMAGE;
+ } else if (!strncmp(kernel + len - 4, ".bin", 4)) {
+ type = KT_BOOT;
+ } else if (!strncmp(kernel + len - 4, ".bss", 4)) {
+ type = KT_BSS;
+ } else if (!strncmp(kernel + len - 4, ".com", 4) ||
+ !strncmp(kernel + len - 4, ".cbt", 4)) {
+ type = KT_COMBOOT;
+ }
+ /* use KT_KERNEL as default */
else
type = KT_KERNEL;
- execute(default_cmd, type);
+ execute(kernel, type);
+bad_implicit:
+bad_kernel:
/*
* If we fail to boot the kernel execute the "onerror" command
* line.
@@ -50,6 +76,27 @@ static void load_kernel(void)
}
}
+static void enter_cmdline(void)
+{
+ const char *cmdline;
+
+ /* Enter endless command line prompt, should support "exit" */
+ while (1) {
+ cmdline = edit_cmdline("syslinux$", 1, NULL, cat_help_file);
+ if (!cmdline)
+ continue;
+
+ /* return if user only press enter */
+ if (cmdline[0] == '\0') {
+ printf("\n");
+ continue;
+ }
+ printf("\n");
+
+ load_kernel(cmdline);
+ }
+}
+
static int ldlinux_main(int argc, char **argv)
{
openconsole(&dev_rawcon_r, &dev_ansiserial_w);
@@ -67,7 +114,7 @@ static int ldlinux_main(int argc, char **argv)
*/
if (defaultlevel || noescape) {
if (defaultlevel) {
- load_kernel(); /* Shouldn't return */
+ load_kernel(default_cmd); /* Shouldn't return */
} else {
printf("No DEFAULT or UI configuration directive found!\n");
diff --git a/com32/elflink/ldlinux/readconfig.c
b/com32/elflink/ldlinux/readconfig.c
index 66e84df..d78c015 100644
--- a/com32/elflink/ldlinux/readconfig.c
+++ b/com32/elflink/ldlinux/readconfig.c
@@ -432,7 +432,7 @@ void print_labels(const char *prefix, size_t len)
}
}
-static struct menu_entry *find_label(const char *str)
+struct menu_entry *find_label(const char *str)
{
const char *p;
struct menu_entry *me;
diff --git a/com32/elflink/modules/cli.h b/com32/elflink/modules/cli.h
index 4ae9caf..513c171 100644
--- a/com32/elflink/modules/cli.h
+++ b/com32/elflink/modules/cli.h
@@ -15,7 +15,6 @@ extern int mygetkey(clock_t timeout);
extern const char *edit_cmdline(const char *input, int top /*, int width */ ,
int (*pDraw_Menu) (int, int, int),
void (*show_fkey) (int));
-extern void process_command(const char *cmd, bool history);
extern struct menu *root_menu, *start_menu, *hide_menu, *menu_list,
*default_menu;
#endif
diff --git a/com32/elflink/modules/menu.h b/com32/elflink/modules/menu.h
index 8041fc9..e79fb3e 100644
--- a/com32/elflink/modules/menu.h
+++ b/com32/elflink/modules/menu.h
@@ -204,6 +204,8 @@ extern const int message_base_color;
extern const char *current_background;
void set_background(const char *new_background);
+extern struct menu_entry *find_label(const char *str);
+
/* execute.c */
void execute(const char *cmdline, enum kernel_type type);