]> code.citadel.org Git - citadel.git/blobdiff - citadel/commands.c
Fixes for Cygwin (see ChangeLog)
[citadel.git] / citadel / commands.c
index 50bf0e7c6b8da9841c95afd3333b22786e653b24..e68c4436ca43c47f831b7e7f824b50410dcc685c 100644 (file)
 
 #include <signal.h>
 #include <errno.h>
+#include <stdarg.h>
 #include "citadel.h"
 #include "commands.h"
 #include "messages.h"
 #include "citadel_decls.h"
 #include "routines.h"
 #include "routines2.h"
+#ifndef HAVE_SNPRINTF
+#include "snprintf.h"
+#endif
 
 struct citcmd {
        struct citcmd *next;
@@ -124,6 +128,10 @@ void do_keepalive(void) {
        if ((now - idlet) < ((long)S_KEEPALIVE)) return;
        time(&idlet);
 
+       /* Do a space-backspace to keep socksified telnet sessions open */
+       printf(" %c", 8);
+       fflush(stdout);
+
        if (keepalives_enabled != KA_NO) {
                serv_puts("NOOP");
                if (keepalives_enabled == KA_YES) {
@@ -131,7 +139,7 @@ void do_keepalive(void) {
                        if (buf[3]=='*') {
                                express_msgs = 1;
                                if (ok_to_interrupt == 1) {
-                                       printf("\r                    \r");
+                                       printf("\r%64s\r", "");
                                        print_express();
                                        printf("%s%c ",room_name,
                                                room_prompt(room_flags));
@@ -193,6 +201,30 @@ int inkey(void) {          /* get a character from the keyboard, with   */
        return(a);
        }
 
+
+int yesno(void) { /* Returns 1 for yes, 0 for no */
+int a;
+       while (1) {
+               a=inkey(); a=tolower(a);
+               if (a=='y') { printf("Yes\n"); return(1); }
+               if (a=='n') { printf("No\n");  return(0); }
+               }
+       }
+
+int yesno_d(int d) /* Returns 1 for yes, 0 for no, arg is default value */
+       {
+int a;
+       while (1) {
+               a=inkey(); a=tolower(a);
+               if (a==13) a=(d ? 'y' : 'n');
+               if (a=='y') { printf("Yes\n"); return(1); }
+               if (a=='n') { printf("No\n");  return(0); }
+               }
+       }
+
+
+
+
 void getline(char *string, int lim)    /* Gets a line from the terminal */
                                /* Pointer to string buffer */
                        /* Maximum length - if negative, no-show */
@@ -244,6 +276,21 @@ void strprompt(char *prompt, char *str, int len)
        if (buf[0]!=0) strcpy(str,buf);
        }
 
+/*
+ * boolprompt()  -  prompt for a yes/no, print the existing value and
+ *                  allow the user to press return to keep it...
+ */
+int boolprompt(char *prompt, int prev_val) {
+       color(3);
+       printf("%s [", prompt);
+       color(1);
+       printf("%s", (prev_val ? "Yes" : "No"));
+       color(3);
+       printf("]: ");
+       color(7);
+       return(yesno_d(prev_val));
+       }
+
 /* 
  * intprompt()  -  like strprompt(), except for an integer
  *                 (note that it RETURNS the new value!)
@@ -254,7 +301,7 @@ int intprompt(char *prompt, int ival, int imin, int imax)
        int i;
        i = ival;
        do {
-               sprintf(buf,"%d",i);
+               snprintf(buf,sizeof buf,"%d",i);
                strprompt(prompt,buf,15);
                i=atoi(buf);
                if (i<imin) printf("*** Must be no less than %d.\n",imin);
@@ -314,16 +361,19 @@ void load_command_set(void) {
 
        ccfile = NULL;
        if (getenv("HOME") != NULL) {
-               sprintf(buf,"%s/.citadelrc",getenv("HOME"));
+               snprintf(buf,sizeof buf,"%s/.citadelrc",getenv("HOME"));
                ccfile = fopen(buf,"r");
                }
        if (ccfile==NULL) {
                ccfile = fopen("/usr/local/lib/citadel.rc","r");
                }
        if (ccfile==NULL) {
-               sprintf(buf,"%s/citadel.rc",BBSDIR);
+               snprintf(buf,sizeof buf,"%s/citadel.rc",BBSDIR);
                ccfile = fopen(buf,"r");
                }
+       if (ccfile==NULL) {
+               ccfile = fopen("./citadel.rc","r");
+               }
        if (ccfile==NULL) {
                perror("commands: cannot open citadel.rc");
                logoff(errno);
@@ -372,6 +422,8 @@ void load_command_set(void) {
                        rc_ansi_color = 1;
                if (!strncasecmp(&buf[11], "auto", 4)) 
                        rc_ansi_color = 2;      /* autodetect */
+               if (!strncasecmp(&buf[11], "user", 4)) 
+                       rc_ansi_color = 3;      /* user config */
                }
 
            if (!struncmp(buf,"username=",9))
@@ -538,6 +590,12 @@ int getcmd(char *argbuf)
        int this_lazy_cmd;
        struct citcmd *cptr;
 
+       /* Switch color support on or off if we're in user mode */
+       if (rc_ansi_color == 3) {
+               if (userflags & US_COLOR) enable_color = 1;
+               else enable_color = 0;
+               }
+
        /* if we're running in idiot mode, display a cute little menu */
        IFNEXPERT formout("mainmenu");
 
@@ -866,7 +924,6 @@ void color(int colornum)
 {
        if (enable_color) {
                printf("\033[3%dm", colornum);
-               /* printf("\033[1m"); */ /* uncomment for bold colours */
                fflush(stdout);
                }
        }
@@ -874,6 +931,7 @@ void color(int colornum)
 void cls(int colornum) {
        if (enable_color) {
                printf("\033[4%dm\033[2J\033[H", colornum);
+               printf("\033[0m"); /* change to 1 for bold colours */
                fflush(stdout);
                }
        }
@@ -903,32 +961,35 @@ void look_for_ansi(void) {
        else if (rc_ansi_color == 1) {
                enable_color = 1;
                }
+       else if (rc_ansi_color == 2) {
 
-       /* otherwise, do the auto-detect */
+               /* otherwise, do the auto-detect */
 
-       strcpy(abuf, "");
+               strcpy(abuf, "");
 
-       time(&now);
-       if ( (now - AnsiDetect) < 2 ) sleep(1);
-
-       do {
-               FD_ZERO(&rfds);
-               FD_SET(0,&rfds);
-               tv.tv_sec = 0;
-               tv.tv_usec = 1;
-
-               select(1, &rfds, NULL, NULL, &tv);
-               if (FD_ISSET(0, &rfds)) {
-                       abuf[strlen(abuf)+1] = 0;
-                       read(0, &abuf[strlen(abuf)], 1);
-                       }
+               time(&now);
+               if ( (now - AnsiDetect) < 2 ) sleep(1);
 
-               } while (FD_ISSET(0, &rfds));
+               do {
+                       FD_ZERO(&rfds);
+                       FD_SET(0,&rfds);
+                       tv.tv_sec = 0;
+                       tv.tv_usec = 1;
 
-       for (a=0; a<strlen(abuf); ++a) {
-               if ( (abuf[a] == 27) && (abuf[a+1] == '[')
-                  && (abuf[a+2] == '?') ) {
-                       enable_color = 1;
+                       select(1, &rfds, NULL, NULL, &tv);
+                       if (FD_ISSET(0, &rfds)) {
+                               abuf[strlen(abuf)+1] = 0;
+                               read(0, &abuf[strlen(abuf)], 1);
+                               }
+       
+                       } while (FD_ISSET(0, &rfds));
+       
+               for (a=0; a<strlen(abuf); ++a) {
+                       if ( (abuf[a] == 27) && (abuf[a+1] == '[')
+                       && (abuf[a+2] == '?') ) {
+                               enable_color = 1;
+                               }
                        }
                }
+
        }