/* Enter the command-line interface. HEAP is used for the command-line buffer. Return only if FOREVER is nonzero and get_cmdline returns nonzero (ESC is pushed). */ void enter_cmdline (char *heap, int forever) { /* Initialize the data and print a message. */ init_cmdline (); grub_setjmp (restart_cmdline_env); init_page (); #ifdef SUPPORT_DISKLESS print_network_configuration (); grub_putchar ('\n'); #endif print_cmdline_message (forever); while (1) { struct builtin *builtin; char *arg; *heap = 0; print_error (); errnum = ERR_NONE; /* Get the command-line with the minimal BASH-like interface. */ if (get_cmdline (PACKAGE "> ", heap, 2048, 0, 1)) return; /* If there was no command, grab a new one. */ if (! heap[0]) continue; /* Find a builtin. */ builtin = find_command (heap); if (! builtin) continue; /* If BUILTIN cannot be run in the command-line, skip it. */ if (! (builtin->flags & BUILTIN_CMDLINE)) { errnum = ERR_UNRECOGNIZED; continue; } /* Invalidate the cache, because the user may exchange removable disks. */ buf_drive = -1; /* Start to count lines, only if the internal pager is in use. */ if (use_pager) count_lines = 0; /* Run BUILTIN->FUNC. */ arg = skip_to (1, heap); (builtin->func) (arg, BUILTIN_CMDLINE); /* Finish the line count. */ count_lines = -1; } }
/* Enter the command-line interface. HEAP is used for the command-line buffer. Return only if FOREVER is nonzero and get_cmdline returns nonzero (ESC is pushed). */ void enter_cmdline (char *heap, int forever) { if (! debug) debug++; //grub_setjmp (restart_cmdline_env); /* Initialize the data and print a message. */ current_drive = GRUB_INVALID_DRIVE; count_lines = -1; kernel_type = KERNEL_TYPE_NONE; errnum = 0; errorcheck = 1; /* errorcheck on */ init_page (); grub_putchar ('\n'); #ifdef SUPPORT_DISKLESS print_network_configuration (); grub_putchar ('\n'); #endif print_cmdline_message (forever); while (1) { struct builtin *builtin; char *arg; grub_error_t errnum_old; errnum_old = errnum; *heap = 0; if (errnum && errorcheck) print_error (); errnum = ERR_NONE; /* Get the command-line with the minimal BASH-like interface. */ prompt = PACKAGE "> "; maxlen = 2048; echo_char = 0; readline = 1; if (get_cmdline (heap)) { kernel_type = KERNEL_TYPE_NONE; return; } /* If there was no command, grab a new one. */ if (! heap[0]) continue; /* Find a builtin. */ builtin = find_command (heap); if (! builtin) continue; /* If BUILTIN cannot be run in the command-line, skip it. */ if (! (builtin->flags & BUILTIN_CMDLINE)) { errnum = ERR_UNRECOGNIZED; continue; } /* Invalidate the cache, because the user may exchange removable disks. */ buf_drive = -1; /* Start to count lines, only if the internal pager is in use. */ if (use_pager) count_lines = 0; if ((builtin->func) == errnum_func || (builtin->func) == checkrange_func) errnum = errnum_old; /* find && and || */ for (arg = skip_to (0, heap); *arg != 0; arg = skip_to (0, arg)) { struct builtin *builtin1; int ret; char *arg1; arg1 = arg; if (*arg == '&' && arg[1] == '&' && (arg[2] == ' ' || arg[2] == '\t')) { /* handle the AND operator */ arg = skip_to (0, arg); builtin1 = find_command (arg); if (! builtin1 || ! (builtin1->flags & BUILTIN_CMDLINE)) { errnum = ERR_UNRECOGNIZED; goto next; } *arg1 = 0; ret = (builtin->func) (skip_to (1, heap), BUILTIN_CMDLINE); *arg1 = '&'; if (ret) { arg = skip_to (1, arg); if ((builtin1->func) != errnum_func && (builtin1->func) != checkrange_func) errnum = 0; (builtin1->func) (arg, BUILTIN_CMDLINE); } else errnum = 0; goto next; } else if (*arg == '|' && arg[1] == '|' && (arg[2] == ' ' || arg[2] == '\t')) { /* handle the OR operator */ arg = skip_to (0, arg); builtin1 = find_command (arg); if (! builtin1 || ! (builtin1->flags & BUILTIN_CMDLINE)) { errnum = ERR_UNRECOGNIZED; goto next; } *arg1 = 0; ret = (builtin->func) (skip_to (1, heap), BUILTIN_CMDLINE); *arg1 = '|'; if (! ret) { arg = skip_to (1, arg); if ((builtin1->func) != errnum_func && (builtin1->func) != checkrange_func) errnum = 0; (builtin1->func) (arg, BUILTIN_CMDLINE); } else errnum = 0; goto next; } } /* Run BUILTIN->FUNC. */ arg = (builtin->func) == commandline_func ? heap : skip_to (1, heap); (builtin->func) (arg, BUILTIN_CMDLINE); next: /* Finish the line count. */ count_lines = -1; } }