Adding upstream version 4.00~pre61+dfsg.
[syslinux-debian/hramrach.git] / com32 / hdt / hdt-cli-hdt.c
blobf4854e3707ddbd25f7b51323e71ae34652734175
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 Pierre-Alexandre Meyer - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
12 * conditions:
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * -----------------------------------------------------------------------
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <syslinux/config.h>
33 #include <syslinux/reboot.h>
35 #include "hdt-menu.h"
36 #include "hdt-cli.h"
37 #include "hdt-common.h"
39 /**
40 * cli_clear_screen - clear (erase) the entire screen
41 **/
42 static void cli_clear_screen(int argc __unused, char **argv __unused,
43 struct s_hardware *hardware __unused)
45 clear_screen();
48 /**
49 * main_show_modes - show availables modes
50 **/
51 static void main_show_modes(int argc __unused, char **argv __unused,
52 struct s_hardware *hardware __unused)
54 int i = 0;
56 reset_more_printf();
57 printf("Available modes:\n");
58 while (list_modes[i]) {
59 printf("%s ", list_modes[i]->name);
60 i++;
62 printf("\n");
65 /**
66 * cli_set_mode - set the mode of the cli, in the cli
68 * The mode number must be supplied in argv, position 0.
69 **/
70 static void cli_set_mode(int argc, char **argv, struct s_hardware *hardware)
72 cli_mode_t new_mode;
74 reset_more_printf();
75 if (argc <= 0) {
76 more_printf("Which mode?\n");
77 return;
81 * Note! argv[0] is a string representing the mode, we need the
82 * equivalent cli_mode_t to pass it to set_mode.
84 new_mode = mode_s_to_mode_t(argv[0]);
85 set_mode(new_mode, hardware);
88 /**
89 * do_exit - shared helper to exit a mode
90 **/
91 static void do_exit(int argc __unused, char **argv __unused,
92 struct s_hardware *hardware)
94 int new_mode = HDT_MODE;
96 switch (hdt_cli.mode) {
97 case HDT_MODE:
98 new_mode = EXIT_MODE;
99 break;
100 default:
101 new_mode = HDT_MODE;
102 break;
105 dprintf("CLI DEBUG: Switching from mode %d to mode %d\n", hdt_cli.mode,
106 new_mode);
107 set_mode(new_mode, hardware);
111 * show_cli_help - shared helper to show available commands
113 static void show_cli_help(int argc __unused, char **argv __unused,
114 struct s_hardware *hardware __unused)
116 int j = 0;
117 struct cli_mode_descr *current_mode;
118 struct cli_callback_descr *associated_module = NULL;
120 find_cli_mode_descr(hdt_cli.mode, &current_mode);
122 printf("Available commands are:\n");
124 /* List first default modules of the mode */
125 if (current_mode->default_modules && current_mode->default_modules->modules) {
126 while (current_mode->default_modules->modules[j].name) {
127 printf("%s ", current_mode->default_modules->modules[j].name);
128 j++;
130 printf("\n");
133 /* List secondly the show modules of the mode */
134 if (current_mode->show_modules && current_mode->show_modules->modules) {
135 printf("\nshow commands:\n");
136 j = 0;
137 while (current_mode->show_modules->modules[j].name) {
138 printf("%s ", current_mode->show_modules->modules[j].name);
139 j++;
141 printf("\n");
144 /* List thirdly the set modules of the mode */
145 if (current_mode->set_modules && current_mode->set_modules->modules) {
146 printf("\nset commands:\n");
147 j = 0;
148 while (current_mode->set_modules->modules[j].name) {
149 printf("%s ", current_mode->set_modules->modules[j].name);
150 j++;
152 printf("\n");
155 /* List finally the default modules of the hdt mode */
156 if (current_mode->mode != hdt_mode.mode &&
157 hdt_mode.default_modules && hdt_mode.default_modules->modules) {
158 j = 0;
159 while (hdt_mode.default_modules->modules[j].name) {
161 * Any default command that is present in hdt mode but
162 * not in the current mode is available. A default
163 * command can be redefined in the current mode though.
164 * This next call test this use case: if it is
165 * overwritten, do not print it again.
167 find_cli_callback_descr(hdt_mode.default_modules->modules[j].name,
168 current_mode->default_modules,
169 &associated_module);
170 if (associated_module == NULL)
171 printf("%s ", hdt_mode.default_modules->modules[j].name);
172 j++;
174 printf("\n");
177 printf("\n");
178 main_show_modes(argc, argv, hardware);
182 * show_cli_help - shared helper to show available commands
184 static void goto_menu(int argc __unused, char **argv __unused,
185 struct s_hardware *hardware)
187 char version_string[256];
188 snprintf(version_string, sizeof version_string, "%s %s (%s)",
189 PRODUCT_NAME, VERSION, CODENAME);
190 start_menu_mode(hardware, version_string);
191 return;
195 * main_show_summary - give an overview of the system
197 void main_show_summary(int argc __unused, char **argv __unused,
198 struct s_hardware *hardware)
200 detect_pci(hardware); /* pxe is detected in the pci */
201 detect_dmi(hardware);
202 cpu_detect(hardware);
203 detect_memory(hardware);
204 reset_more_printf();
205 clear_screen();
206 main_show_cpu(argc, argv, hardware);
207 if (hardware->is_dmi_valid) {
208 more_printf("System\n");
209 more_printf(" Manufacturer : %s\n", hardware->dmi.system.manufacturer);
210 more_printf(" Product Name : %s\n", hardware->dmi.system.product_name);
211 more_printf(" Serial : %s\n", hardware->dmi.system.serial);
212 more_printf("Bios\n");
213 more_printf(" Version : %s\n", hardware->dmi.bios.version);
214 more_printf(" Release : %s\n", hardware->dmi.bios.release_date);
215 more_printf("Memory Size : %lu MB (%lu KB)\n",
216 (hardware->detected_memory_size + (1 << 9)) >> 10,
217 hardware->detected_memory_size);
219 main_show_pci(argc, argv, hardware);
221 if (hardware->is_pxe_valid)
222 main_show_pxe(argc, argv, hardware);
224 main_show_kernel(argc, argv, hardware);
227 void main_show_hdt(int argc __unused, char **argv __unused,
228 struct s_hardware *hardware __unused)
230 reset_more_printf();
231 more_printf("HDT\n");
232 more_printf(" Product : %s\n", PRODUCT_NAME);
233 more_printf(" Version : %s (%s)\n", VERSION, CODENAME);
234 more_printf(" Website : %s\n", WEBSITE_URL);
235 more_printf(" Mailing List : %s\n", CONTACT);
236 more_printf(" Project Leader : %s\n", AUTHOR);
237 more_printf(" Core Developer : %s\n", CORE_DEVELOPER);
238 char *contributors[NB_CONTRIBUTORS] = CONTRIBUTORS;
239 for (int c = 0; c < NB_CONTRIBUTORS; c++) {
240 more_printf(" Contributor : %s\n", contributors[c]);
245 * do_reboot - reboot the system
247 static void do_reboot(int argc __unused, char **argv __unused,
248 struct s_hardware *hardware)
250 (void) hardware;
251 /* Let's call the internal rebooting call */
252 syslinux_reboot(1);
255 /* Default hdt mode */
256 struct cli_callback_descr list_hdt_default_modules[] = {
258 .name = CLI_CLEAR,
259 .exec = cli_clear_screen,
262 .name = CLI_EXIT,
263 .exec = do_exit,
266 .name = CLI_HELP,
267 .exec = show_cli_help,
270 .name = CLI_MENU,
271 .exec = goto_menu,
274 .name = CLI_REBOOT,
275 .exec = do_reboot,
278 .name = CLI_HISTORY,
279 .exec = print_history,
282 .name = NULL,
283 .exec = NULL},
286 struct cli_callback_descr list_hdt_show_modules[] = {
288 .name = CLI_SUMMARY,
289 .exec = main_show_summary,
292 .name = CLI_PCI,
293 .exec = main_show_pci,
296 .name = CLI_DMI,
297 .exec = main_show_dmi,
300 .name = CLI_CPU,
301 .exec = main_show_cpu,
304 .name = CLI_DISK,
305 .exec = disks_summary,
308 .name = CLI_PXE,
309 .exec = main_show_pxe,
312 .name = CLI_SYSLINUX,
313 .exec = main_show_syslinux,
316 .name = CLI_KERNEL,
317 .exec = main_show_kernel,
320 .name = CLI_VESA,
321 .exec = main_show_vesa,
324 .name = CLI_HDT,
325 .exec = main_show_hdt,
328 .name = CLI_VPD,
329 .exec = main_show_vpd,
332 .name = CLI_MEMORY,
333 .exec = show_dmi_memory_modules,
336 .name = "modes",
337 .exec = main_show_modes,
340 .name = NULL,
341 .exec = NULL,
345 struct cli_callback_descr list_hdt_set_modules[] = {
347 .name = CLI_MODE,
348 .exec = cli_set_mode,
351 .name = NULL,
352 .exec = NULL,
356 struct cli_module_descr hdt_default_modules = {
357 .modules = list_hdt_default_modules,
360 struct cli_module_descr hdt_show_modules = {
361 .modules = list_hdt_show_modules,
362 .default_callback = main_show_summary,
365 struct cli_module_descr hdt_set_modules = {
366 .modules = list_hdt_set_modules,
369 struct cli_mode_descr hdt_mode = {
370 .mode = HDT_MODE,
371 .name = CLI_HDT,
372 .default_modules = &hdt_default_modules,
373 .show_modules = &hdt_show_modules,
374 .set_modules = &hdt_set_modules,