* Eliminated the whole SIGINT/SIGQUIT based handling of Ctrl-O and Ctrl-C
authorArt Cancro <ajc@citadel.org>
Sun, 9 Jul 2000 02:27:03 +0000 (02:27 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 9 Jul 2000 02:27:03 +0000 (02:27 +0000)
  keyboard interrupts.  Replaced with a non-blocking check for keyboard input
  which sets the global variable 'sigcaught' if either key was pressed.
  fmout() and pprintf() switch to 'drain mode' if sigcaught is set.
  This closes Bug #18.

citadel/ChangeLog
citadel/citadel.c
citadel/commands.c
citadel/commands.h
citadel/rooms.c
citadel/routines.c

index 6468f1811fcbba18f581b46571b198a48dd49c7f..ba958bdedb0011477b9e92fdbefa95f70b1efd8a 100644 (file)
@@ -1,4 +1,11 @@
  $Log$
+ Revision 572.12  2000/07/09 02:27:02  ajc
+ * Eliminated the whole SIGINT/SIGQUIT based handling of Ctrl-O and Ctrl-C
+   keyboard interrupts.  Replaced with a non-blocking check for keyboard input
+   which sets the global variable 'sigcaught' if either key was pressed.
+   fmout() and pprintf() switch to 'drain mode' if sigcaught is set.
+   This closes Bug #18.
+
  Revision 572.11  2000/07/06 20:26:36  ajc
  * updated .Help SUMMARY
 
@@ -1928,3 +1935,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
+
index 706558fee6b30f907a795e8a4938f76254315e1f..c4381db77412d4e868b4474826fc45fc2d946b6a 100644 (file)
@@ -127,19 +127,6 @@ void logoff(int code)
 
 
 
-/*
- * We handle "next" and "stop" much differently than in earlier versions.
- * The signal catching routine simply sets a flag and returns.
- */
-void sighandler(int which_sig)
-{
-       signal(SIGINT, SIG_IGN);
-       signal(SIGQUIT, SIG_IGN);
-       sigcaught = which_sig;
-       return;
-}
-
-
 /*
  * signal catching function for hangups...
  */
@@ -193,8 +180,6 @@ void userlist(char *patn)
                pprintf("%s\n", &buf[4]);
                return;
        }
-       sigcaught = 0;
-       sttybbs(SB_YES_INTR);
        pprintf("       User Name           Num  L  LastCall  Calls Posts\n");
        pprintf("------------------------- ----- - ---------- ----- -----\n");
        while (serv_gets(buf), strcmp(buf, "000")) {
@@ -215,7 +200,6 @@ void userlist(char *patn)
 
                }
        }
-       sttybbs(SB_NO_INTR);
        pprintf("\n");
 }
 
index 3a6fb8af6681f3a53cac56cc76cc2c4f61547f8f..ab656b07e9b4e636267443d48578a5a3de53a50b 100644 (file)
@@ -84,6 +84,33 @@ int enable_color = 0;                        /* nonzero for ANSI color */
 
 
 
+/*
+ * If an interesting key has been pressed, return its value, otherwise 0
+ */
+char was_a_key_pressed(void) {
+       fd_set rfds;
+       struct timeval tv;
+       int the_character;
+       int retval;
+
+       FD_ZERO(&rfds);
+       FD_SET(0, &rfds);
+       tv.tv_sec = 0;
+       tv.tv_usec = 0;
+       retval = select(1, &rfds, NULL, NULL, &tv); 
+
+       if (FD_ISSET(0, &rfds)) {
+               the_character = inkey();
+       }
+       else {
+               the_character = 0;
+       }
+       return(the_character);
+}
+
+
+
+
 
 /*
  * Check to see if we need to pause at the end of a screen.
@@ -93,6 +120,13 @@ int enable_color = 0;                       /* nonzero for ANSI color */
  */
 int checkpagin(int lp, int pagin, int height)
 {
+       int thekey;
+
+       if (sigcaught) return(lp);
+       thekey = was_a_key_pressed();
+       if ( (thekey == NEXT_KEY) || (thekey == STOP_KEY)) sigcaught = thekey;
+       if (sigcaught) return(lp);
+
        if (!pagin) return(0);
        if (lp>=(height-1)) {
                set_keepalives(KA_NO);
@@ -113,7 +147,13 @@ void pprintf(const char *format, ...) {
         va_list arg_ptr;
        static char buf[4096];  /* static for performance, change if needed */
        int i;
-  
+
+       /* If sigcaught is nonzero, a keypress has interrupted this and we
+        * should just drain output.
+        */
+       if (sigcaught) return;
+       /* Otherwise, start spewing... */ 
         va_start(arg_ptr, format);   
         vsprintf(buf, format, arg_ptr);   
         va_end(arg_ptr);   
@@ -790,6 +830,13 @@ int getcmd(char *argbuf)
        int this_lazy_cmd;
        struct citcmd *cptr;
 
+       /*
+        * Starting a new command now, so set sigcaught to 0.  This variable
+        * is set to nonzero (usually NEXT_KEY or STOP_KEY) if a command has
+        * been interrupted by a keypress.
+        */
+       sigcaught = 0;
+
        /* Switch color support on or off if we're in user mode */
        if (rc_ansi_color == 3) {
                if (userflags & US_COLOR)
@@ -921,8 +968,7 @@ int getcmd(char *argbuf)
 /*
  * set tty modes.  commands are:
  * 
- * 0 - set to bbs mode, intr/quit disabled
- * 1 - set to bbs mode, intr/quit enabled
+ * 01- set to bbs mode
  * 2 - save current settings for later restoral
  * 3 - restore saved settings
  */
@@ -944,17 +990,8 @@ void sttybbs(int cmd)
                live.c_oflag = OPOST | ONLCR;
                live.c_lflag = ISIG | NOFLSH;
 
-               if (cmd == SB_YES_INTR) {
-                       live.c_cc[VINTR] = NEXT_KEY;
-                       live.c_cc[VQUIT] = STOP_KEY;
-                       signal(SIGINT, *sighandler);
-                       signal(SIGQUIT, *sighandler);
-               } else {
-                       signal(SIGINT, SIG_IGN);
-                       signal(SIGQUIT, SIG_IGN);
-                       live.c_cc[VINTR] = (-1);
-                       live.c_cc[VQUIT] = (-1);
-               }
+               live.c_cc[VINTR] = (-1);
+               live.c_cc[VQUIT] = (-1);
 
                /* do we even need this stuff anymore? */
                /* live.c_line=0; */
@@ -1011,13 +1048,13 @@ void display_help(char *name)
 /*
  * fmout()  -  Citadel text formatter and paginator
  */
-int fmout(int width, FILE * fp, char pagin, int height, int starting_lp, char subst)
-                       /* screen width to use */
-                       /* file to read from, or NULL to read from server */
-                       /* nonzero if we should use the paginator */
-                       /* screen height to use */
-                       /* starting value for lines_printed, -1 for global */
-                       /* nonzero if we should use hypertext mode */
+int fmout(
+       int width,      /* screen width to use */
+       FILE *fp,       /* file to read from, or NULL to read from server */
+       char pagin,     /* nonzero if we should use the paginator */
+       int height,     /* screen height to use */
+       int starting_lp,/* starting value for lines_printed, -1 for global */
+       char subst)     /* nonzero if we should use hypertext mode */
 {
        int a, b, c, d, old;
        int real = (-1);
@@ -1035,13 +1072,7 @@ int fmout(int width, FILE * fp, char pagin, int height, int starting_lp, char su
        strcpy(buffer, "");
        c = 1;                  /* c is the current pos */
 
-       sigcaught = 0;
-       sttybbs(1);
-
 FMTA:  while ((eof_flag == 0) && (strlen(buffer) < 126)) {
-       
-               if (sigcaught)
-                       goto OOPS;
                if (fp != NULL) {       /* read from file */
                        if (feof(fp))
                                eof_flag = 1;
@@ -1129,17 +1160,18 @@ FMTA:   while ((eof_flag == 0) && (strlen(buffer) < 126)) {
                c = 1;
                ++lines_printed;
                lines_printed = checkpagin(lines_printed, pagin, height);
+               if (sigcaught) goto OOPS;
                strcpy(aaa, "");
                goto FMTA;
        }
        goto FMTA;
 
-       /* signal caught; drain the server */
-      OOPS:do {
+       /* keypress caught; drain the server */
+OOPS:  do {
                serv_gets(aaa);
        } while (strcmp(aaa, "000"));
 
-      FMTEND:printf("\n");
+FMTEND:        printf("\n");
        ++lines_printed;
        lines_printed = checkpagin(lines_printed, pagin, height);
        return (sigcaught);
index 1d47e0d5103e27477449afca8b63d11cbbf558db..26e8706389db1d0c5bcd95806ae753e46ffbb5da 100644 (file)
@@ -54,6 +54,7 @@ char keymenu(char *menuprompt, char *menustring);
 void async_ka_start(void);
 void async_ka_end(void);
 int checkpagin(int lp, int pagin, int height);
+char was_a_key_pressed(void);
 void pprintf(const char *format, ...);
 
 
index 0cd7a32a8e88dbd93af87863ad352d06b70e3abf..f46a4ee61f6429232e945dd8de76e1cc48f3aad9 100644 (file)
@@ -201,13 +201,10 @@ void listrms(char *variety)
                        }
                }
 
-       sigcaught = 0;
-       sttybbs(SB_YES_INTR);
        room_tree_list(NULL);
        room_tree_list(rl);
        color(DIM_WHITE);
-       sttybbs(SB_NO_INTR);
-       }
+}
 
 
 void list_other_floors(void) {
@@ -900,14 +897,11 @@ void whoknows(void) {
        if (buf[0]!='1') {
                pprintf("%s\n",&buf[5]);
                return;
-               }
-       sigcaught = 0;
-       sttybbs(SB_YES_INTR);
+       }
        while (serv_gets(buf), strncmp(buf,"000",3)) {
                if (sigcaught==0) pprintf("%s\n",buf);
-               }
-       sttybbs(SB_NO_INTR);
        }
+}
 
 
 void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
index 0997942175aed98ab87b1ad61e8a01d542a1847a..9b2db74e557a1c46fde5668bb9e5ccf643bc4504 100644 (file)
@@ -81,7 +81,7 @@ void hit_any_key(void) {              /* hit any key to continue */
        sttybbs(1);
        if (b==NEXT_KEY) sigcaught = SIGINT;
        if (b==STOP_KEY) sigcaught = SIGQUIT;
-       }
+}
 
 /*
  * change a user's access level