4 * This file contains functions which implement parts of the
5 * text-mode user interface.
16 #include <sys/types.h>
18 #if TIME_WITH_SYS_TIME
19 # include <sys/time.h>
23 # include <sys/time.h>
35 #ifdef HAVE_SYS_SELECT_H
36 #include <sys/select.h>
39 #ifdef THREADED_CLIENT
49 #include "citadel_decls.h"
51 #include "routines2.h"
54 #include "client_chat.h"
67 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
71 char rc_exp_cmd[1024];
72 int rc_allow_attachments;
73 int rc_display_message_numbers;
74 int rc_force_mail_prompts;
75 int rc_remember_passwords;
78 char urls[MAXURLS][SIZ];
82 int next_lazy_cmd = 5;
84 int lines_printed = 0; /* line count for paginator */
85 extern int screenwidth, screenheight;
88 struct citcmd *cmdlist = NULL;
91 /* these variables are local to this module */
92 char keepalives_enabled = KA_YES; /* send NOOPs to server when idle */
93 int ok_to_interrupt = 0; /* print express msgs asynchronously */
94 time_t AnsiDetect; /* when did we send the detect code? */
95 int enable_color = 0; /* nonzero for ANSI color */
101 * If an interesting key has been pressed, return its value, otherwise 0
103 char was_a_key_pressed(void) {
113 retval = select(1, &rfds, NULL, NULL, &tv);
115 /* Careful! Disable keepalives during keyboard polling; we're probably
116 * in the middle of a data transfer from the server, in which case
117 * sending a NOOP would throw the client protocol out of sync.
119 if (FD_ISSET(0, &rfds)) {
120 set_keepalives(KA_NO);
121 the_character = inkey();
122 set_keepalives(KA_YES);
127 return(the_character);
135 * Check to see if we need to pause at the end of a screen.
136 * If we do, we have to disable server keepalives during the pause because
137 * we are probably in the middle of a server operation and the NOOP command
138 * would confuse everything.
140 int checkpagin(int lp, int pagin, int height)
144 if (sigcaught) return(lp);
145 thekey = was_a_key_pressed();
146 if (thekey == 'q' || thekey == 'Q' || thekey == 's' || thekey == 'S')
148 if (thekey == 'n' || thekey == 'N')
150 if ( (thekey == NEXT_KEY) || (thekey == STOP_KEY)) sigcaught = thekey;
151 if (sigcaught) return(lp);
153 if (!pagin) return(0);
154 if (lp>=(height-1)) {
155 set_keepalives(KA_NO);
157 set_keepalives(KA_YES);
167 * pprintf() ... paginated version of printf()
169 void pprintf(const char *format, ...) {
171 static char buf[4096]; /* static for performance, change if needed */
174 /* If sigcaught is nonzero, a keypress has interrupted this and we
175 * should just drain output.
177 if (sigcaught) return;
179 /* Otherwise, start spewing... */
180 va_start(arg_ptr, format);
181 vsprintf(buf, format, arg_ptr);
184 for (i=0; i<strlen(buf); ++i) {
188 lines_printed = checkpagin(lines_printed,
189 (userflags & US_PAGINATOR),
198 * print_express() - print express messages if there are any
200 void print_express(void)
210 if (express_msgs == 0)
216 if (strlen(rc_exp_cmd) == 0) {
221 while (express_msgs != 0) {
227 express_msgs = extract_int(&buf[4], 0);
228 timestamp = extract_long(&buf[4], 1);
229 flags = extract_int(&buf[4], 2);
230 extract(sender, &buf[4], 3);
231 extract(node, &buf[4], 4);
232 strcpy(last_paged, sender);
234 stamp = localtime(×tamp);
236 /* If the page is a Logoff Request, honor it. */
242 if (strlen(rc_exp_cmd) > 0) {
243 outpipe = popen(rc_exp_cmd, "w");
244 if (outpipe != NULL) {
245 /* Header derived from flags */
248 "Please log off now, as requested ");
250 fprintf(outpipe, "Broadcast message ");
252 fprintf(outpipe, "Chat request ");
254 fprintf(outpipe, "Message ");
255 /* Timestamp. Can this be improved? */
256 if (stamp->tm_hour == 0 || stamp->tm_hour == 12)
257 fprintf(outpipe, "at 12:%02d%cm",
259 stamp->tm_hour ? 'p' : 'a');
260 else if (stamp->tm_hour > 12) /* pm */
261 fprintf(outpipe, "at %d:%02dpm",
265 fprintf(outpipe, "at %d:%02dam",
266 stamp->tm_hour, stamp->tm_min);
267 fprintf(outpipe, " from %s", sender);
268 if (strncmp(serv_info.serv_nodename, node, 32))
269 fprintf(outpipe, " @%s", node);
270 fprintf(outpipe, ":\n");
271 while (serv_gets(buf), strcmp(buf, "000")) {
272 fprintf(outpipe, "%s\n", buf);
275 if (express_msgs == 0)
280 /* fall back to built-in express message display */
284 /* Header derived from flags */
286 scr_printf("Please log off now, as requested ");
288 scr_printf("Broadcast message ");
290 scr_printf("Chat request ");
292 scr_printf("Message ");
294 /* Timestamp. Can this be improved? */
295 if (stamp->tm_hour == 0 || stamp->tm_hour == 12)/* 12am/12pm */
296 scr_printf("at 12:%02d%cm", stamp->tm_min,
297 stamp->tm_hour ? 'p' : 'a');
298 else if (stamp->tm_hour > 12) /* pm */
299 scr_printf("at %d:%02dpm",
300 stamp->tm_hour - 12, stamp->tm_min);
302 scr_printf("at %d:%02dam", stamp->tm_hour, stamp->tm_min);
305 scr_printf(" from %s", sender);
307 /* Remote node, if any */
308 if (strncmp(serv_info.serv_nodename, node, 32))
309 scr_printf(" @%s", node);
313 fmout(screenwidth, NULL, 1, screenheight, -1, 0);
315 scr_printf("\n---\n");
322 void set_keepalives(int s)
324 keepalives_enabled = (char) s;
328 * This loop handles the "keepalive" messages sent to the server when idling.
331 static time_t idlet = 0;
332 static void really_do_keepalive(void) {
336 if (keepalives_enabled == KA_YES) {
341 if (ok_to_interrupt == 1) {
342 scr_printf("\r%64s\r", "");
344 scr_printf("%s%c ", room_name,
345 room_prompt(room_flags));
352 /* threaded nonblocking keepalive stuff starts here. I'm going for a simple
353 encapsulated interface; in theory there should be no need to touch these
354 globals outside of the async_ka_* functions. */
356 #ifdef THREADED_CLIENT
357 static pthread_t ka_thr_handle;
358 static int ka_thr_active = 0;
359 static int async_ka_enabled = 0;
361 static void *ka_thread(void *arg)
363 really_do_keepalive();
364 pthread_detach(ka_thr_handle);
369 /* start up a thread to handle a keepalive in the background */
370 static void async_ka_exec(void)
372 if (!ka_thr_active) {
374 if (pthread_create(&ka_thr_handle, NULL, ka_thread, NULL)) {
375 perror("pthread_create");
380 #endif /* THREADED_CLIENT */
382 static void do_keepalive(void)
387 if ((now - idlet) < ((long) S_KEEPALIVE))
390 /* Do a space-backspace to keep telnet sessions from idling out */
391 scr_printf(" %c", 8);
394 #ifdef THREADED_CLIENT
395 if (async_ka_enabled)
399 really_do_keepalive();
403 /* Now the actual async-keepalve API that we expose to higher levels:
404 async_ka_start() and async_ka_end(). These do nothing when we don't have
405 threading enabled, so we avoid sprinkling ifdef's throughout the code. */
407 /* wait for a background keepalive to complete. this must be done before
408 attempting any further server requests! */
409 void async_ka_end(void)
411 #ifdef THREADED_CLIENT
413 pthread_join(ka_thr_handle, NULL);
419 /* tell do_keepalive() that keepalives are asynchronous. */
420 void async_ka_start(void)
422 #ifdef THREADED_CLIENT
429 { /* get a character from the keyboard, with */
430 int a; /* the watchdog timer in effect if necessary */
433 time_t start_time, now;
441 /* This loop waits for keyboard input. If the keepalive
442 * timer expires, it sends a keepalive to the server if
443 * necessary and then waits again.
450 tv.tv_sec = S_KEEPALIVE;
454 select(1, &rfds, NULL, NULL, &tv);
455 } while (!FD_ISSET(0, &rfds));
460 /* At this point, there's input, so fetch it.
461 * (There's a hole in the bucket...)
470 if (((a != 4) && (a != 10) && (a != 8) && (a != NEXT_KEY) && (a != STOP_KEY))
471 && ((a < 32) || (a > 126)))
479 { /* Returns 1 for yes, 0 for no */
495 /* Returns 1 for yes, 0 for no, arg is default value */
518 /* Gets a line from the terminal */
519 /* string == Pointer to string buffer */
520 /* lim == Maximum length - if negative, no-show */
521 void getline(char *string, int lim)
535 if ((a == 8) && (strlen(string) == 0))
537 if ((a != 10) && (a != 8) && (strlen(string) == lim))
539 if ((a == 8) && (string[0] != 0)) {
540 string[strlen(string) - 1] = 0;
565 * strprompt() - prompt for a string, print the existing value and
566 * allow the user to press return to keep it...
568 void strprompt(char *prompt, char *str, int len)
573 scr_printf("%s ", prompt);
576 color(BRIGHT_MAGENTA);
577 scr_printf("%s", str);
590 * boolprompt() - prompt for a yes/no, print the existing value and
591 * allow the user to press return to keep it...
593 int boolprompt(char *prompt, int prev_val)
598 scr_printf("%s ", prompt);
601 color(BRIGHT_MAGENTA);
602 scr_printf("%s", (prev_val ? "Yes" : "No"));
606 r = (yesno_d(prev_val));
612 * intprompt() - like strprompt(), except for an integer
613 * (note that it RETURNS the new value!)
615 int intprompt(char *prompt, int ival, int imin, int imax)
623 snprintf(buf, sizeof buf, "%d", i);
624 strprompt(prompt, buf, 15);
626 for (p=0; p<strlen(buf); ++p) {
627 if ( (!isdigit(buf[p]))
628 && ( (buf[p]!='-') || (p!=0) ) )
632 scr_printf("*** Must be no less than %d.\n", imin);
634 scr_printf("*** Must be no more than %d.\n", imax);
635 } while ((i < imin) || (i > imax));
640 * newprompt() - prompt for a string with no existing value
641 * (clears out string buffer first)
643 void newprompt(char *prompt, char *str, int len)
645 color(BRIGHT_MAGENTA);
646 scr_printf("%s", prompt);
654 { /* returns a lower case value */
663 * parse the citadel.rc file
665 void load_command_set(void)
670 struct citcmd *lastcmd = NULL;
675 /* first, set up some defaults for non-required variables */
677 strcpy(editor_path, "");
678 strcpy(printcmd, "");
679 strcpy(rc_username, "");
680 strcpy(rc_password, "");
683 rc_allow_attachments = 0;
684 rc_remember_passwords = 0;
685 strcpy(rc_exp_cmd, "");
686 rc_display_message_numbers = 0;
687 rc_force_mail_prompts = 0;
689 strcpy(rc_url_cmd, "");
690 rc_encrypt = RC_DEFAULT;
691 rc_screen = RC_DEFAULT;
692 rc_alt_semantics = 0;
694 /* now try to open the citadel.rc file */
697 if (getenv("HOME") != NULL) {
698 snprintf(buf, sizeof buf, "%s/.citadelrc", getenv("HOME"));
699 ccfile = fopen(buf, "r");
701 if (ccfile == NULL) {
702 ccfile = fopen("/usr/local/lib/citadel.rc", "r");
704 if (ccfile == NULL) {
705 snprintf(buf, sizeof buf, "%s/citadel.rc", BBSDIR);
706 ccfile = fopen(buf, "r");
708 if (ccfile == NULL) {
709 ccfile = fopen("./citadel.rc", "r");
711 if (ccfile == NULL) {
712 perror("commands: cannot open citadel.rc");
715 while (fgets(buf, sizeof buf, ccfile) != NULL) {
716 while ((strlen(buf) > 0) ? (isspace(buf[strlen(buf) - 1])) : 0)
717 buf[strlen(buf) - 1] = 0;
719 if (!strncasecmp(buf, "encrypt=", 8)) {
720 if (!strcasecmp(&buf[8], "yes"))
722 else if (!strcasecmp(&buf[8], "no"))
724 else if (!strcasecmp(&buf[8], "default"))
725 rc_encrypt = RC_DEFAULT;
728 if (!strncasecmp(buf, "fullscreen=", 11)) {
729 if (!strcasecmp(&buf[11], "yes"))
731 else if (!strcasecmp(&buf[11], "no"))
735 if (!strncasecmp(buf, "editor=", 7))
736 strcpy(editor_path, &buf[7]);
738 if (!strncasecmp(buf, "printcmd=", 9))
739 strcpy(printcmd, &buf[9]);
741 if (!strncasecmp(buf, "expcmd=", 7))
742 strcpy(rc_exp_cmd, &buf[7]);
744 if (!strncasecmp(buf, "local_screen_dimensions=", 24))
745 have_xterm = (char) atoi(&buf[24]);
747 if (!strncasecmp(buf, "use_floors=", 11)) {
748 if (!strcasecmp(&buf[11], "yes"))
749 rc_floor_mode = RC_YES;
750 if (!strcasecmp(&buf[11], "no"))
751 rc_floor_mode = RC_NO;
752 if (!strcasecmp(&buf[11], "default"))
753 rc_floor_mode = RC_DEFAULT;
755 if (!strncasecmp(buf, "beep=", 5)) {
756 rc_exp_beep = atoi(&buf[5]);
758 if (!strncasecmp(buf, "allow_attachments=", 18)) {
759 rc_allow_attachments = atoi(&buf[18]);
761 if (!strncasecmp(buf, "remember_passwords=", 19)) {
762 rc_remember_passwords = atoi(&buf[19]);
764 if (!strncasecmp(buf, "display_message_numbers=", 24)) {
765 rc_display_message_numbers = atoi(&buf[24]);
767 if (!strncasecmp(buf, "force_mail_prompts=", 19)) {
768 rc_force_mail_prompts = atoi(&buf[19]);
770 if (!strncasecmp(buf, "ansi_color=", 11)) {
771 if (!strncasecmp(&buf[11], "on", 2))
773 if (!strncasecmp(&buf[11], "auto", 4))
774 rc_ansi_color = 2; /* autodetect */
775 if (!strncasecmp(&buf[11], "user", 4))
776 rc_ansi_color = 3; /* user config */
778 if (!strncasecmp(buf, "username=", 9))
779 strcpy(rc_username, &buf[9]);
781 if (!strncasecmp(buf, "password=", 9))
782 strcpy(rc_password, &buf[9]);
784 if (!strncasecmp(buf, "urlcmd=", 7))
785 strcpy(rc_url_cmd, &buf[7]);
787 if (!strncasecmp(buf, "alternate_semantics=", 20)) {
788 if (!strncasecmp(&buf[11], "yes", 3))
789 rc_alt_semantics = 1;
790 if (!strncasecmp(&buf[11], "no", 2))
791 rc_alt_semantics = 0;
793 if (!strncasecmp(buf, "cmd=", 4)) {
794 strcpy(buf, &buf[4]);
796 cptr = (struct citcmd *) malloc(sizeof(struct citcmd));
798 cptr->c_cmdnum = atoi(buf);
799 for (d = strlen(buf); d >= 0; --d)
802 strcpy(buf, &buf[b + 1]);
804 cptr->c_axlevel = atoi(buf);
805 for (d = strlen(buf); d >= 0; --d)
808 strcpy(buf, &buf[b + 1]);
810 for (a = 0; a < 5; ++a)
811 cptr->c_keys[a][0] = 0;
815 buf[strlen(buf) + 1] = 0;
816 while (strlen(buf) > 0) {
818 for (d = strlen(buf); d >= 0; --d)
821 strncpy(cptr->c_keys[a], buf, b);
822 cptr->c_keys[a][b] = 0;
824 strcpy(buf, &buf[b + 1]);
834 lastcmd->next = cptr;
844 * return the key associated with a command
846 char keycmd(char *cmdstr)
850 for (a = 0; a < strlen(cmdstr); ++a)
851 if (cmdstr[a] == '&')
852 return (tolower(cmdstr[a + 1]));
858 * Output the string from a key command without the ampersand
859 * "mode" should be set to 0 for normal or 1 for <C>ommand key highlighting
861 char *cmd_expand(char *strbuf, int mode)
869 for (a = 0; a < strlen(exp); ++a) {
870 if (strbuf[a] == '&') {
873 strcpy(&exp[a], &exp[a + 1]);
877 strcpy(buf, &exp[a + 2]);
883 if (!strncmp(&exp[a], "^r", 2)) {
885 strcpy(&exp[a], room_name);
886 strcat(exp, &buf[a + 2]);
888 if (!strncmp(&exp[a], "^c", 2)) {
890 strcpy(&exp[a + 1], &exp[a + 2]);
900 * Comparison function to determine if entered commands match a
901 * command loaded from the config file.
903 int cmdmatch(char *cmdbuf, struct citcmd *cptr, int ncomp)
914 for (a = 0; a < ncomp; ++a) {
915 if ((tolower(cmdbuf[a]) != keycmd(cptr->c_keys[a]))
916 || (cptr->c_axlevel > cmdax))
924 * This function returns 1 if a given command requires a string input
926 int requires_string(struct citcmd *cptr, int ncomp)
931 strcpy(buf, cptr->c_keys[ncomp - 1]);
932 for (a = 0; a < strlen(buf); ++a) {
941 * Input a command at the main prompt.
942 * This function returns an integer command number. If the command prompts
943 * for a string then it is placed in the supplied buffer.
945 int getcmd(char *argbuf)
957 * Starting a new command now, so set sigcaught to 0. This variable
958 * is set to nonzero (usually NEXT_KEY or STOP_KEY) if a command has
959 * been interrupted by a keypress.
963 /* Switch color support on or off if we're in user mode */
964 if (rc_ansi_color == 3) {
965 if (userflags & US_COLOR)
970 /* if we're running in idiot mode, display a cute little menu */
971 IFNEXPERT formout("mainmenu");
973 print_express(); /* print express messages if there are any */
976 for (a = 0; a < 5; ++a)
978 /* now the room prompt... */
981 scr_printf("\n%s", room_name);
983 scr_printf("%c ", room_prompt(room_flags));
990 /* Handle the backspace key, but only if there's something
991 * to backspace over...
993 if ((ch == 8) && (cmdpos > 0)) {
994 back(cmdspaces[cmdpos - 1] + 1);
998 /* Spacebar invokes "lazy traversal" commands */
999 if ((ch == 32) && (cmdpos == 0)) {
1000 this_lazy_cmd = next_lazy_cmd;
1001 if (this_lazy_cmd == 13)
1003 if (this_lazy_cmd == 5)
1005 for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
1006 if (cptr->c_cmdnum == this_lazy_cmd) {
1007 for (a = 0; a < 5; ++a)
1008 if (cptr->c_keys[a][0] != 0)
1009 scr_printf("%s ", cmd_expand(
1010 cptr->c_keys[a], 0));
1012 return (this_lazy_cmd);
1016 return (this_lazy_cmd);
1018 /* Otherwise, process the command */
1019 cmdbuf[cmdpos] = tolower(ch);
1021 for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
1022 if (cmdmatch(cmdbuf, cptr, cmdpos + 1)) {
1024 scr_printf("%s", cmd_expand(cptr->c_keys[cmdpos], 0));
1025 cmdspaces[cmdpos] = strlen(
1026 cmd_expand(cptr->c_keys[cmdpos], 0));
1028 if ((cptr->c_keys[cmdpos + 1]) != 0)
1034 for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
1035 if (cmdmatch(cmdbuf, cptr, 5)) {
1036 /* We've found our command. */
1037 if (requires_string(cptr, cmdpos)) {
1038 getline(argbuf, 32);
1043 /* If this command is one that changes rooms,
1044 * then the next lazy-command (space bar)
1045 * should be "read new" instead of "goto"
1047 if ((cptr->c_cmdnum == 5)
1048 || (cptr->c_cmdnum == 6)
1049 || (cptr->c_cmdnum == 47)
1050 || (cptr->c_cmdnum == 52)
1051 || (cptr->c_cmdnum == 16)
1052 || (cptr->c_cmdnum == 20))
1055 return (cptr->c_cmdnum);
1061 pprintf("\rOne of ... \n");
1062 for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
1063 if (cmdmatch(cmdbuf, cptr, cmdpos)) {
1064 for (a = 0; a < 5; ++a) {
1065 pprintf("%s ", cmd_expand(cptr->c_keys[a], 1));
1071 pprintf("\n%s%c ", room_name, room_prompt(room_flags));
1073 for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
1074 if ((got == 0) && (cmdmatch(cmdbuf, cptr, cmdpos))) {
1075 for (a = 0; a < cmdpos; ++a) {
1077 cmd_expand(cptr->c_keys[a], 0));
1092 * set tty modes. commands are:
1094 * 01- set to bbs mode
1095 * 2 - save current settings for later restoral
1096 * 3 - restore saved settings
1098 #ifdef HAVE_TERMIOS_H
1099 void sttybbs(int cmd)
1100 { /* SysV version of sttybbs() */
1101 struct termios live;
1102 static struct termios saved_settings;
1103 static int last_cmd = 0;
1110 if ((cmd == 0) || (cmd == 1)) {
1111 tcgetattr(0, &live);
1112 live.c_iflag = ISTRIP | IXON | IXANY;
1113 live.c_oflag = OPOST | ONLCR;
1114 live.c_lflag = ISIG | NOFLSH;
1116 live.c_cc[VINTR] = (-1);
1117 live.c_cc[VQUIT] = (-1);
1120 live.c_cc[VMIN] = 0;
1121 live.c_cc[VTIME] = 0;
1124 /* do we even need this stuff anymore? */
1125 /* live.c_line=0; */
1126 live.c_cc[VERASE] = 8;
1127 live.c_cc[VKILL] = 24;
1128 live.c_cc[VEOF] = 1;
1129 live.c_cc[VEOL] = 255;
1130 live.c_cc[VEOL2] = 0;
1131 live.c_cc[VSTART] = 0;
1132 tcsetattr(0, TCSADRAIN, &live);
1135 tcgetattr(0, &saved_settings);
1138 tcsetattr(0, TCSADRAIN, &saved_settings);
1142 void sttybbs(int cmd)
1143 { /* BSD version of sttybbs() */
1145 static struct sgttyb saved_settings;
1146 static int last_cmd = 0;
1153 if ((cmd == 0) || (cmd == 1)) {
1155 live.sg_flags |= CBREAK;
1156 live.sg_flags |= CRMOD;
1157 live.sg_flags |= NL1;
1158 live.sg_flags &= ~ECHO;
1160 live.sg_flags |= NOFLSH;
1164 gtty(0, &saved_settings);
1167 stty(0, &saved_settings);
1174 * display_help() - help file viewer
1176 void display_help(char *name)
1183 * fmout() - Citadel text formatter and paginator
1186 int width, /* screen width to use */
1187 FILE *fp, /* file to read from, or NULL to read from server */
1188 char pagin, /* nonzero if we should use the paginator */
1189 int height, /* screen height to use */
1190 int starting_lp,/* starting value for lines_printed, -1 for global */
1191 char subst) /* nonzero if we should use hypertext mode */
1193 int a, b, c, d, old;
1199 num_urls = 0; /* Start with a clean slate of embedded URL's */
1201 if (starting_lp >= 0) {
1202 lines_printed = starting_lp;
1207 c = 1; /* c is the current pos */
1209 FMTA: while ((eof_flag == 0) && (strlen(buffer) < 126)) {
1210 if (fp != NULL) { /* read from file */
1213 if (eof_flag == 0) {
1215 buffer[strlen(buffer) + 1] = 0;
1216 buffer[strlen(buffer)] = a;
1218 } else { /* read from server */
1220 serv_gets(&buffer[d]);
1221 while ((!isspace(buffer[d])) && (isspace(buffer[strlen(buffer) - 1])))
1222 buffer[strlen(buffer) - 1] = 0;
1223 if (!strcmp(&buffer[d], "000")) {
1226 while (isspace(buffer[strlen(buffer) - 1]))
1227 buffer[strlen(buffer) - 1] = 0;
1235 if ( (!strncasecmp(buffer, "http://", 7))
1236 || (!strncasecmp(buffer, "ftp://", 6)) ) {
1237 safestrncpy(urls[num_urls], buffer, (SIZ-1));
1238 for (a=0; a<strlen(urls[num_urls]); ++a) {
1239 b = urls[num_urls][a];
1240 if ( (b==' ') || (b==')') || (b=='>') || (b==10)
1241 || (b==13) || (b==9) || (b=='\"') )
1242 urls[num_urls][a] = 0;
1247 buffer[strlen(buffer) + 1] = 0;
1249 strcpy(buffer, &buffer[1]);
1256 if (((a == 13) || (a == 10)) && (old != 13) && (old != 10))
1258 if (((old == 13) || (old == 10)) && (isspace(real))) {
1261 lines_printed = checkpagin(lines_printed, pagin, height);
1268 if (((strlen(aaa) + c) > (width - 5)) && (strlen(aaa) > (width - 5))) {
1269 scr_printf("\n%s", aaa);
1273 lines_printed = checkpagin(lines_printed, pagin, height);
1280 if ((strlen(aaa) + c) > (width - 5)) {
1284 lines_printed = checkpagin(lines_printed, pagin, height);
1286 scr_printf("%s ", aaa);
1288 c = c + strlen(aaa);
1292 if ((a == 13) || (a == 10)) {
1293 scr_printf("%s\n", aaa);
1296 lines_printed = checkpagin(lines_printed, pagin, height);
1297 if (sigcaught) goto OOPS;
1303 /* keypress caught; drain the server */
1306 } while (strcmp(aaa, "000"));
1308 FMTEND: scr_printf("\n");
1310 lines_printed = checkpagin(lines_printed, pagin, height);
1316 * support ANSI color if defined
1318 void color(int colornum)
1320 static int is_bold = 0;
1321 static int hold_color, current_color;
1323 if (colornum == COLOR_PUSH) {
1324 hold_color = current_color;
1328 if (colornum == COLOR_POP) {
1333 current_color = colornum;
1335 #ifdef HAVE_CURSES_H
1336 if (scr_color(colornum))
1339 /* When switching to dim white, actually output an 'original
1340 * pair' sequence -- this looks better on black-on-white
1343 if (colornum == DIM_WHITE)
1344 printf("\033[39;49m");
1346 printf("\033[3%d;40m", (colornum & 7));
1348 if ((colornum >= 8) && (is_bold == 0)) {
1351 } else if ((colornum < 8) && (is_bold == 1)) {
1359 void cls(int colornum)
1362 printf("\033[4%dm\033[2J\033[H\033[0m", colornum);
1369 * Detect whether ANSI color is available (answerback)
1371 void send_ansi_detect(void)
1373 if (rc_ansi_color == 2) {
1380 void look_for_ansi(void)
1388 if (rc_ansi_color == 0) {
1390 } else if (rc_ansi_color == 1) {
1392 } else if (rc_ansi_color == 2) {
1394 /* otherwise, do the auto-detect */
1399 if ((now - AnsiDetect) < 2)
1408 select(1, &rfds, NULL, NULL, &tv);
1409 if (FD_ISSET(0, &rfds)) {
1410 abuf[strlen(abuf) + 1] = 0;
1411 read(0, &abuf[strlen(abuf)], 1);
1413 } while (FD_ISSET(0, &rfds));
1415 for (a = 0; a < strlen(abuf); ++a) {
1416 if ((abuf[a] == 27) && (abuf[a + 1] == '[')
1417 && (abuf[a + 2] == '?')) {
1426 * Display key options (highlight hotkeys inside angle brackets)
1428 void keyopt(char *buf) {
1432 for (i=0; i<strlen(buf); ++i) {
1435 color(BRIGHT_MAGENTA);
1449 * Present a key-menu line choice type of thing
1451 char keymenu(char *menuprompt, char *menustring) {
1457 int display_prompt = 1;
1459 choices = num_tokens(menustring, '|');
1461 if (menuprompt != NULL) do_prompt = 1;
1462 if (menuprompt != NULL) if (strlen(menuprompt)==0) do_prompt = 0;
1465 if (display_prompt) {
1467 scr_printf("%s ", menuprompt);
1470 for (i=0; i<choices; ++i) {
1471 extract(buf, menustring, i);
1481 if ( (do_prompt) && (ch=='?') ) {
1482 scr_printf("\rOne of... ");
1484 for (i=0; i<choices; ++i) {
1485 extract(buf, menustring, i);
1494 for (i=0; i<choices; ++i) {
1495 extract(buf, menustring, i);
1496 for (c=1; c<strlen(buf); ++c) {
1497 if ( (ch == tolower(buf[c]))
1499 && (buf[c+1]=='>') ) {
1500 for (a=0; a<strlen(buf); ++a) {
1501 if ( (a!=(c-1)) && (a!=(c+1))) {