X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Fmonitor.c;h=a799f7cb8e661953ab712f4fe221135edd12a0b3;hp=4278c6ae6ab0a2847c45f1892fbadc2813f1a57d;hb=8521d91eea4d77630d668ad269dc0634f4a426ff;hpb=2f0b91ab1a54973a084e1609b46a1432c8b8e334 diff --git a/src/monitor.c b/src/monitor.c index 4278c6a..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); @@ -359,7 +364,7 @@ void monitor() if(cmdtype == MONQUIT) { shutdown(); freebps(); - free_code_cmdtype(); + free_cmdtable(HASH_CODE); freecerr(); exit(0); }