*
* This version is the traditional command parser for room prompts.
*
+ * $Id$
+ *
*/
#include "sysdep.h"
#include <sys/types.h>
#include <sys/time.h>
-#ifdef POSIX_TERMIO
+#ifdef HAVE_TERMIOS_H
#include <termios.h>
#else
#include <sgtty.h>
#endif
-#ifdef NEED_SELECT_H
+#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#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;
#define IFNEXPERT if ((userflags&US_EXPERT)==0)
-extern unsigned room_flags;
-extern char room_name[];
-extern struct CtdlServInfo serv_info;
-extern char axlevel;
-extern char is_room_aide;
-extern unsigned userflags;
-extern char sigcaught;
-extern char editor_path[];
-extern char printcmd[];
-extern char have_xterm;
-extern char rc_username[];
-extern char rc_password[];
-extern char rc_floor_mode;
-char rc_exp_beep;
+int rc_exp_beep;
char rc_exp_cmd[256];
-extern int lines_printed;
-extern char express_msgs;
+int rc_allow_attachments;
+int rc_display_message_numbers;
+int rc_force_mail_prompts;
+int rc_ansi_color;
char *gl_string;
+int next_lazy_cmd = 5;
struct citcmd *cmdlist = NULL;
-void sighandler();
-void logoff();
-int struncmp();
-void formout();
-int room_prompt();
-void back();
-int checkpagin();
-void color();
-
/* these variables are local to this module */
char keepalives_enabled = KA_YES; /* send NOOPs to server when idle */
/*
* print_express() - print express messages if there are any
*/
-void print_express() {
+void print_express(void) {
char buf[256];
FILE *outpipe;
}
-void set_keepalives(s)
-int s; {
+void set_keepalives(int s)
+{
keepalives_enabled = (char)s;
}
/*
* This loop handles the "keepalive" messages sent to the server when idling.
*/
-void do_keepalive() {
+void do_keepalive(void) {
char buf[256];
- static long idlet = 0L;
- long now;
+ static time_t idlet = 0;
+ time_t now;
time(&now);
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));
}
-int inkey() { /* get a character from the keyboard, with */
+int inkey(void) { /* get a character from the keyboard, with */
int a; /* the watchdog timer in effect if necessary */
fd_set rfds;
struct timeval tv;
- long start_time, now;
+ time_t start_time, now;
char inbuf[2];
time(&start_time);
return(a);
}
-void getline(string,lim) /* Gets a line from the terminal */
-char string[]; /* Pointer to string buffer */
-int lim; /* Maximum length - if negative, no-show */
+
+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 */
{
int a,b;
char flag = 0;
* strprompt() - prompt for a string, print the existing value and
* allow the user to press return to keep it...
*/
-void strprompt(prompt,str,len)
-char *prompt;
-char *str;
-int len; {
+void strprompt(char *prompt, char *str, int len)
+{
char buf[128];
print_express();
color(3);
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 intprompt(prompt,ival,imin,imax)
-char *prompt;
-int ival;
-int imin;
-int imax; {
+int intprompt(char *prompt, int ival, int imin, int imax)
+{
char buf[16];
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);
* newprompt() - prompt for a string with no existing value
* (clears out string buffer first)
*/
-void newprompt(prompt,str,len)
-char *prompt;
-char *str;
-int len; {
+void newprompt(char *prompt, char *str, int len)
+{
color(3);
printf("%s",prompt);
color(2);
}
-int lkey() { /* returns a lower case value */
+int lkey(void) { /* returns a lower case value */
int a;
a=inkey();
if (isupper(a)) a=tolower(a);
/*
* parse the citadel.rc file
*/
-void load_command_set() {
+void load_command_set(void) {
FILE *ccfile;
char buf[256];
struct citcmd *cptr;
+ struct citcmd *lastcmd = NULL;
int a,d;
int b = 0;
strcpy(rc_password,"");
rc_floor_mode = 0;
rc_exp_beep = 1;
+ rc_allow_attachments = 0;
strcpy(rc_exp_cmd, "");
+ rc_display_message_numbers = 0;
+ rc_force_mail_prompts = 0;
+ rc_ansi_color = 0;
/* now try to open the citadel.rc file */
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_exp_beep = atoi(&buf[5]);
}
+ if (!struncmp(buf,"allow_attachments=", 18)) {
+ rc_allow_attachments = atoi(&buf[18]);
+ }
+
+ if (!struncmp(buf,"display_message_numbers=", 24)) {
+ rc_display_message_numbers = atoi(&buf[24]);
+ }
+
+ if (!struncmp(buf,"force_mail_prompts=", 19)) {
+ rc_force_mail_prompts = atoi(&buf[19]);
+ }
+
+ if (!struncmp(buf,"ansi_color=", 11)) {
+ if (!strncasecmp(&buf[11], "on", 2))
+ 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))
strcpy(rc_username,&buf[9]);
++a;
}
- cptr->next = cmdlist;
- cmdlist = cptr;
-
+ cptr->next = NULL;
+ if (cmdlist == NULL) cmdlist = cptr;
+ else lastcmd->next = cptr;
+ lastcmd = cptr;
}
}
fclose(ccfile);
/*
* return the key associated with a command
*/
-char keycmd(cmdstr)
-char cmdstr[]; {
+char keycmd(char *cmdstr)
+{
int a;
for (a=0; a<strlen(cmdstr); ++a)
* Output the string from a key command without the ampersand
* "mode" should be set to 0 for normal or 1 for <C>ommand key highlighting
*/
-char *cmd_expand(strbuf,mode)
-char strbuf[];
-int mode; {
+char *cmd_expand(char *strbuf, int mode)
+{
int a;
static char exp[64];
char buf[256];
* Comparison function to determine if entered commands match a
* command loaded from the config file.
*/
-int cmdmatch(cmdbuf,cptr,ncomp)
-char cmdbuf[];
-struct citcmd *cptr;
-int ncomp; {
+int cmdmatch(char *cmdbuf, struct citcmd *cptr, int ncomp)
+{
int a;
int cmdax;
/*
* This function returns 1 if a given command requires a string input
*/
-int requires_string(cptr,ncomp)
-struct citcmd *cptr;
-int ncomp; {
+int requires_string(struct citcmd *cptr, int ncomp)
+{
int a;
char buf[64];
* This function returns an integer command number. If the command prompts
* for a string then it is placed in the supplied buffer.
*/
-int getcmd(argbuf)
-char *argbuf; {
+int getcmd(char *argbuf)
+{
char cmdbuf[5];
int cmdspaces[5];
int cmdpos;
int ch;
int a;
int got;
+ 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");
ch = inkey();
ok_to_interrupt = 0;
+ /* Handle the backspace key, but only if there's something
+ * to backspace over...
+ */
if ( (ch == 8) && (cmdpos > 0) ) {
back(cmdspaces[cmdpos-1] + 1);
cmdbuf[cmdpos] = 0;
--cmdpos;
}
+ /* Spacebar invokes "lazy traversal" commands */
+ if ( (ch == 32) && (cmdpos == 0) ) {
+ this_lazy_cmd = next_lazy_cmd;
+ if (this_lazy_cmd == 13) next_lazy_cmd = 5;
+ if (this_lazy_cmd == 5) next_lazy_cmd = 13;
+ for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
+ if (cptr->c_cmdnum == this_lazy_cmd) {
+ for (a=0; a<5; ++a)
+ if (cptr->c_keys[a][0] != 0)
+ printf("%s ", cmd_expand(
+ cptr->c_keys[a], 0));
+ printf("\n");
+ return(this_lazy_cmd);
+ }
+ }
+ printf("\n");
+ return(this_lazy_cmd);
+ }
+
+ /* Otherwise, process the command */
cmdbuf[cmdpos] = tolower(ch);
for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
if (cmdmatch(cmdbuf,cptr,5)) {
+ /* We've found our command. */
if (requires_string(cptr,cmdpos)) {
getline(argbuf,32);
}
else {
printf("\n");
}
+
+ /* If this command is one that changes rooms,
+ * then the next lazy-command (space bar)
+ * should be "read new" instead of "goto"
+ */
+ if ((cptr->c_cmdnum==5)
+ ||(cptr->c_cmdnum==6)
+ ||(cptr->c_cmdnum==47)
+ ||(cptr->c_cmdnum==52)
+ ||(cptr->c_cmdnum==16)
+ ||(cptr->c_cmdnum==20))
+ next_lazy_cmd = 13;
+
return(cptr->c_cmdnum);
+
}
}
* 2 - save current settings for later restoral
* 3 - restore saved settings
*/
-#ifdef POSIX_TERMIO
-void sttybbs(cmd) /* SysV version of sttybbs() */
-int cmd; {
+#ifdef HAVE_TERMIOS_H
+void sttybbs(int cmd) /* SysV version of sttybbs() */
+ {
struct termios live;
static struct termios saved_settings;
+ static int last_cmd = 0;
+
+ if (cmd == SB_LAST)
+ cmd = last_cmd;
+ else
+ last_cmd = cmd;
if ( (cmd == 0) || (cmd == 1) ) {
tcgetattr(0,&live);
live.c_iflag=ISTRIP|IXON|IXANY;
live.c_oflag=OPOST|ONLCR;
- live.c_lflag=NOFLSH;
- if (cmd==1) live.c_lflag=ISIG|NOFLSH;
+ live.c_lflag=ISIG|NOFLSH;
if (cmd==SB_YES_INTR) {
live.c_cc[VINTR]=NEXT_KEY;
}
}
#else
-void sttybbs(cmd) /* BSD version of sttybbs() */
-int cmd; {
+void sttybbs(int cmd) /* BSD version of sttybbs() */
+{
struct sgttyb live;
static struct sgttyb saved_settings;
/*
* display_help() - help file viewer
*/
-void display_help(name)
-char name[]; {
+void display_help(char *name)
+{
formout(name);
}
/*
* fmout() - Citadel text formatter and paginator
*/
-int fmout(width,fp,pagin,height,starting_lp,subst)
-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 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 a,b,c,d,old;
int real = (-1);
/*
* support ANSI color if defined
*/
-void color(colornum)
-int colornum; {
-
-#ifdef ANSI_COLOR
+void color(int colornum)
+{
if (enable_color) {
- fflush(stdout);
- printf("%c[3%dm%c[1m", 27, colornum, 27);
+ printf("\033[3%dm", colornum);
fflush(stdout);
}
-#endif
}
-void cls() {
-#ifdef ANSI_COLOR
- fflush(stdout);
- printf("%c[2J%c[H", 27, 27);
- fflush(stdout);
-#endif
+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);
+ }
}
/*
* Detect whether ANSI color is available (answerback)
*/
-void send_ansi_detect() {
-#ifdef ANSI_COLOR
- printf("%c[c", 27);
- fflush(stdout);
- time(&AnsiDetect);
-#endif
+void send_ansi_detect(void) {
+ if (rc_ansi_color == 2) {
+ printf("\033[c");
+ fflush(stdout);
+ time(&AnsiDetect);
+ }
}
-void look_for_ansi() {
-#ifdef ANSI_COLOR
+void look_for_ansi(void) {
fd_set rfds;
struct timeval tv;
char abuf[512];
time_t now;
int a;
- strcpy(abuf, "");
+ if (rc_ansi_color == 0) {
+ enable_color = 0;
+ }
+ else if (rc_ansi_color == 1) {
+ enable_color = 1;
+ }
+ else if (rc_ansi_color == 2) {
- time(&now);
- if ( (now - AnsiDetect) < 2 ) sleep(1);
+ /* otherwise, do the auto-detect */
- 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);
- }
+ strcpy(abuf, "");
- } while (FD_ISSET(0, &rfds));
+ time(&now);
+ if ( (now - AnsiDetect) < 2 ) sleep(1);
- for (a=0; a<strlen(abuf); ++a) {
- if ( (abuf[a] == 27) && (abuf[a+1] == '[')
- && (abuf[a+2] == '?') ) {
- enable_color = 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);
+ }
+
+ } 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;
+ }
}
}
-#endif
+
}