Просмотр исходного кода

Rename the mem command to meminfo

terminal.c: is_cmd_meminfo() matches the whole word, the command process
is spawned as "meminfo", and the help entry (which also feeds Tab
completion) shows meminfo.  mem.c comment and the AGENTS.md command list
follow.

Verified on QEMU: `mem` now reports "command not found" and `meminfo`
prints the memory/E820 report; the USB keyboard regression still passes.
Johannes Zellner 1 месяц назад
Родитель
Сommit
0c3303026d
3 измененных файлов с 13 добавлено и 9 удалено
  1. 1 1
      AGENTS.md
  2. 1 1
      mem.c
  3. 11 7
      terminal.c

+ 1 - 1
AGENTS.md

@@ -162,7 +162,7 @@ make clean
 `cd [path]`, `ls [path]`, `cat <path>`, `save <path> <text>`, `rm <path>`,
 `cd [path]`, `ls [path]`, `cat <path>`, `save <path> <text>`, `rm <path>`,
 `mkdir <path>`, `rmdir <path>`, `hello`, `reboot`, `poweroff`, `run <name>|<file>`, `space`,
 `mkdir <path>`, `rmdir <path>`, `hello`, `reboot`, `poweroff`, `run <name>|<file>`, `space`,
 `prog`,
 `prog`,
-`clock`, `colors`, `display`, `cpuinfo`, `mouseinfo`, `lsusb`, `lspci [id]`, `peek <addr> [len]`, `poke <addr> <val>`, `storage`, `mem`, `format <device>`,
+`clock`, `colors`, `display`, `cpuinfo`, `mouseinfo`, `lsusb`, `lspci [id]`, `peek <addr> [len]`, `poke <addr> <val>`, `storage`, `meminfo`, `format <device>`,
 `ps`, `kill <pid>`, `help`, `clear`, `serial test|recv`, `kexec`, `dbg`.
 `ps`, `kill <pid>`, `help`, `clear`, `serial test|recv`, `kexec`, `dbg`.
 
 
 Network: `netinfo`, `netrecv`, `netsend`, `netip [a.b.c.d]`, `dhcp` (re-run the
 Network: `netinfo`, `netrecv`, `netsend`, `netip [a.b.c.d]`, `dhcp` (re-run the

+ 1 - 1
mem.c

@@ -1,4 +1,4 @@
-/* mem command: report total/free physical memory and the E820 map. */
+/* meminfo command: report total/free physical memory and the E820 map. */
 
 
 #include "io.h"
 #include "io.h"
 #include "mm.h"
 #include "mm.h"

+ 11 - 7
terminal.c

@@ -770,16 +770,20 @@ static int is_cmd_storage(const char *line, unsigned int line_len)
 	return (i == line_len);
 	return (i == line_len);
 }
 }
 
 
-static int is_cmd_mem(const char *line, unsigned int line_len)
+static int is_cmd_meminfo(const char *line, unsigned int line_len)
 {
 {
 	unsigned int i = 0;
 	unsigned int i = 0;
 	while (i < line_len && line[i] == ' ')
 	while (i < line_len && line[i] == ' ')
 		i++;
 		i++;
-	if (i + 3 > line_len)
+	if (i + 7 > line_len)
 		return 0;
 		return 0;
-	if (line[i] != 'm' || line[i+1] != 'e' || line[i+2] != 'm')
+	if (line[i] != 'm' || line[i+1] != 'e' || line[i+2] != 'm' ||
+	    line[i+3] != 'i' || line[i+4] != 'n' || line[i+5] != 'f' ||
+	    line[i+6] != 'o')
 		return 0;
 		return 0;
-	i += 3;
+	i += 7;
+	if (i < line_len && line[i] != ' ')
+		return 0;  /* "meminfo" must be a whole word */
 	while (i < line_len && line[i] == ' ')
 	while (i < line_len && line[i] == ' ')
 		i++;
 		i++;
 	return (i == line_len);
 	return (i == line_len);
@@ -817,7 +821,7 @@ static const char *const help_items[] = {
 	"cd [path]", "ls [path]", "cat <path>", "save <path> <text>",
 	"cd [path]", "ls [path]", "cat <path>", "save <path> <text>",
 	"rm <path>", "mkdir <path>", "rmdir <path>", "hello", "reboot",
 	"rm <path>", "mkdir <path>", "rmdir <path>", "hello", "reboot",
 	"poweroff", "run <name>|<file>", "space", "prog", "clock", "colors",
 	"poweroff", "run <name>|<file>", "space", "prog", "clock", "colors",
-	"display", "cpuinfo", "lsusb", "mouseinfo", "storage", "mem",
+	"display", "cpuinfo", "lsusb", "mouseinfo", "storage", "meminfo",
 	"format <device>", "lspci [id]", "peek <addr> [len]", "poke <addr> <val>",
 	"format <device>", "lspci [id]", "peek <addr> [len]", "poke <addr> <val>",
 	"netinfo",
 	"netinfo",
 	"netrecv", "netsend", "netip [a.b.c.d]", "netping <a.b.c.d>",
 	"netrecv", "netsend", "netip [a.b.c.d]", "netping <a.b.c.d>",
@@ -1702,8 +1706,8 @@ void term_run(struct term *t)
 						term_spawn(t, "ping", program_ping_main);
 						term_spawn(t, "ping", program_ping_main);
 					} else if (is_cmd_storage(t->line, t->line_len)) {
 					} else if (is_cmd_storage(t->line, t->line_len)) {
 						term_spawn(t, "storage", program_storage_main);
 						term_spawn(t, "storage", program_storage_main);
-					} else if (is_cmd_mem(t->line, t->line_len)) {
-						term_spawn(t, "mem", program_mem_main);
+					} else if (is_cmd_meminfo(t->line, t->line_len)) {
+						term_spawn(t, "meminfo", program_mem_main);
 					} else if (is_cmd_clock(t->line, t->line_len)) {
 					} else if (is_cmd_clock(t->line, t->line_len)) {
 						io_putstr("clock: not available in windowed mode yet\n");
 						io_putstr("clock: not available in windowed mode yet\n");
 					} else if (is_cmd_colors(t->line, t->line_len)) {
 					} else if (is_cmd_colors(t->line, t->line_len)) {