X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmonitor.c;h=a799f7cb8e661953ab712f4fe221135edd12a0b3;hb=c8fdd78cfb5ba3a2afcdbb95e69e49d1c0dc23ed;hp=831a47acc36578b5a5113512324c61395b77af6d;hpb=8365c3016d2564c0498d2dc21300b1bff57e929b;p=YACASL2.git diff --git a/src/monitor.c b/src/monitor.c index 831a47a..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,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);