*
* This version is the traditional command parser for room prompts.
*
+ * $Id$
+ *
*/
#include "sysdep.h"
#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;
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) {
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));
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 */
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!)
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);
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);
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))
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");
{
if (enable_color) {
printf("\033[3%dm", colornum);
- /* printf("\033[1m"); */ /* uncomment for bold colours */
fflush(stdout);
}
}
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);
}
}
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;
+ }
}
}
+
}