X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmonitor.c;h=a799f7cb8e661953ab712f4fe221135edd12a0b3;hb=c8fdd78cfb5ba3a2afcdbb95e69e49d1c0dc23ed;hp=9fe71f59bd13aeda83eebc6c52ed865456653fe1;hpb=21b0a348f1e1660a3da0ebf0c4e7009a4ac11c71;p=YACASL2.git diff --git a/src/monitor.c b/src/monitor.c index 9fe71f5..a799f7c 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -132,7 +132,7 @@ MONARGS *monargstok(const char *str) } sepp = r + strcspn(r, " "); sepc = *sepp; - *sepp = '\0'; + strcpy(sepp, ""); args->argv[++(args->argc)-1] = strdup_chk(q, "args.argv[]"); q = r = sepp + 1; } while(sepc == ' '); @@ -146,7 +146,7 @@ MONCMDLINE *monlinetok(const char *line) long l; MONCMDLINE *moncmdl = NULL; - if(*line == '\n' || *line == '\0') { + if(!line[0] || line[0] == '\n') { return NULL; } p = tokens = strdup_chk(line, "tokens"); @@ -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) { - *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);