]> andersk Git - moira.git/commitdiff
Three bugfixes and a feature
authordanw <danw>
Sun, 17 Nov 1996 23:14:58 +0000 (23:14 +0000)
committerdanw <danw>
Sun, 17 Nov 1996 23:14:58 +0000 (23:14 +0000)
  - 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

index 29fd82104a93b512e94499734943027bce2ef4a7..597784f53949013fab135e196045fee444dc94da 100644 (file)
@@ -22,37 +22,89 @@ static char *rcsid_test_c = "$Header$";
 #include <string.h>
 #include <moira.h>
 #include <com_err.h>
+#include <setjmp.h>
+#include <signal.h>
+
+#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;
          }
This page took 0.05187 seconds and 5 git commands to generate.