From 8521d91eea4d77630d668ad269dc0634f4a426ff Mon Sep 17 00:00:00 2001 From: j8takagi Date: Tue, 12 Feb 2019 17:54:06 +0900 Subject: [PATCH] =?utf8?q?comet2monitor=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- monitor/help.monitor | 2 ++ monitor/load.monitor | 2 ++ monitor/quit.monitor | 1 + src/monitor.c | 16 ++++++++++------ 4 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 monitor/help.monitor create mode 100644 monitor/load.monitor create mode 100644 monitor/quit.monitor diff --git a/monitor/help.monitor b/monitor/help.monitor new file mode 100644 index 0000000..a7b15f7 --- /dev/null +++ b/monitor/help.monitor @@ -0,0 +1,2 @@ +? + diff --git a/monitor/load.monitor b/monitor/load.monitor new file mode 100644 index 0000000..656211a --- /dev/null +++ b/monitor/load.monitor @@ -0,0 +1,2 @@ +l as/sample/sum_10.o +d diff --git a/monitor/quit.monitor b/monitor/quit.monitor new file mode 100644 index 0000000..bca70f3 --- /dev/null +++ b/monitor/quit.monitor @@ -0,0 +1 @@ +q diff --git a/src/monitor.c b/src/monitor.c index a921e8d..a799f7c 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -340,7 +340,8 @@ void free_moncmdline(MONCMDLINE *moncmdl) void monitor() { - char *buf, *p; + char *buf = NULL; + int i; MONCMDLINE *moncmdl; MONCMDTYPE cmdtype = MONREPEAT; @@ -348,21 +349,24 @@ void monitor() fprintf(stdout, "- "); buf = malloc_chk(MONINSIZE + 1, "monitor.buf"); fgets(buf, MONINSIZE, stdin); - if((p = strchr(buf, '\n')) != NULL) { - p = '\0'; + fprintf(stdout, "%s", buf); + if(!buf[0]) { + cmdtype = MONQUIT; + } + if((i = strcspn(buf, "\n")) > 0 || buf[0] == '\n') { + buf[i] = '\0'; } if((moncmdl = monlinetok(buf)) != NULL) { cmdtype = monitorcmd(moncmdl->cmd, moncmdl->args); free_moncmdline(moncmdl); } - if(!buf[0] || cmdtype == MONQUIT) { - FREE(buf); + FREE(buf); + if(cmdtype == MONQUIT) { shutdown(); freebps(); free_cmdtable(HASH_CODE); freecerr(); exit(0); } - FREE(buf); } while(cmdtype == MONREPEAT); } -- 2.18.0