comet2monitorの修正
[YACASL2.git] / src / monitor.c
index 831a47a..a799f7c 100644 (file)
@@ -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,8 +349,12 @@ void monitor()
         fprintf(stdout, "- ");
         buf = malloc_chk(MONINSIZE + 1, "monitor.buf");
         fgets(buf, MONINSIZE, stdin);
-        if((p = strchr(buf, '\n')) != NULL) {
-            strcpy(p, "");
+        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);