From f281aa291c7e53c7dcb18e9606c36a649475f24c Mon Sep 17 00:00:00 2001 From: danw Date: Sun, 17 Nov 1996 23:14:58 +0000 Subject: [PATCH] Three bugfixes and a feature - blank lines no longer give: Unknown request "" - ^C just cancels the current line instead of killing the program - \\ is now valid in quoted strings (along with \nnn and \") - If you define USE_READLINE and tell it where to find includes and libraries, it will build in support for gnu readline. This isn't enabled by default, but I'm going to rebuild them with it, and it will be easily configurable in the future autoconfiscated version of the source tree. --- clients/mrtest/mrtest.c | 66 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/clients/mrtest/mrtest.c b/clients/mrtest/mrtest.c index 29fd8210..597784f5 100644 --- a/clients/mrtest/mrtest.c +++ b/clients/mrtest/mrtest.c @@ -22,37 +22,89 @@ static char *rcsid_test_c = "$Header$"; #include #include #include +#include +#include + +#ifdef USE_READLINE +#include "readline.h" +#endif int recursion = 0; extern int errno; extern int sending_version_no; int count, quit=0; char *whoami; +jmp_buf jb; #define MAXARGS 20 +void discard_input(int, int, struct sigcontext *); +char *mr_gets(char *, char *, size_t); + main(argc, argv) int argc; char **argv; { int status; char cmdbuf[BUFSIZ]; +#ifdef POSIX + struct sigaction action; +#endif whoami = argv[0]; initialize_sms_error_table(); initialize_krb_error_table(); +#ifdef POSIX + action.sa_handler = discard_input; + action.sa_flags = 0; + sigemptyset(&action.sa_mask); + sigaction(SIGINT, &action, NULL); +#else + signal(SIGINT, discard_input); +#endif + setjmp(jb); + while(!quit) { - printf("moira: "); - fflush(stdout); - if(!fgets(cmdbuf,BUFSIZ,stdin)) break; + if(!mr_gets("moira: ",cmdbuf,BUFSIZ)) break; execute_line(cmdbuf); } mr_disconnect(); exit(0); } +void discard_input(int sig, int code, struct sigcontext *scp) +{ + putc('\n', stdout); + longjmp(jb, 1); +} + +char *mr_gets(char *prompt, char *buf, size_t len) +{ + char *in; +#ifdef USE_READLINE + if(isatty(0)) { + in=readline(prompt); + + if (!in) return NULL; + if (*in) { + add_history(in); + strncpy(buf, in, len-1); + buf[len]=0; + } + + return buf; + } +#endif + printf("%s", prompt); + fflush(stdout); + in=fgets(buf, len, stdin); + if(!in) return in; + if(strchr(buf,'\n')) *(strchr(buf,'\n'))=0; + return buf; +} + execute_line(cmdbuf) char *cmdbuf; { @@ -99,7 +151,9 @@ parse(buf, argv) { char *p; int argc, num; - + + if(!*buf) return 0; + for(p=buf, argc=0, argv[0]=buf; *p && *p!='\n'; p++) { if(*p=='"') { char *d=p++; @@ -110,10 +164,10 @@ parse(buf, argv) return 0; } if(*p=='\\') { - if(*++p!='"' && (*p<'0' || *p>'9')) { + if(*++p!='"' && (*p<'0' || *p>'9') && (*p!='\\')) { fprintf(stderr, "moira: Bad use of \\\n"); return 0; - } else if (*p!='"') { + } else if (*p>='0' && *p<='9') { num=(*p-'0')*64 + (*++p-'0')*8 + (*++p-'0'); *p=num; } -- 2.45.2