]> code.citadel.org Git - citadel.git/commitdiff
* Full-screen curses support for Citadel text client
authorMichael Hampton <io_error@uncensored.citadel.org>
Sat, 19 Jan 2002 09:59:10 +0000 (09:59 +0000)
committerMichael Hampton <io_error@uncensored.citadel.org>
Sat, 19 Jan 2002 09:59:10 +0000 (09:59 +0000)
19 files changed:
citadel/ChangeLog
citadel/Makefile.in
citadel/acconfig.h
citadel/citadel.c
citadel/citadel.rc
citadel/citadel_decls.h
citadel/client_chat.c
citadel/client_crypto.c
citadel/commands.c
citadel/configure.ac
citadel/ipc_c_tcp.c
citadel/md5.c
citadel/messages.c
citadel/rooms.c
citadel/routines.c
citadel/routines2.c
citadel/screen.c [new file with mode: 0644]
citadel/screen.h [new file with mode: 0644]
citadel/tools.c

index 8ad1af481a729b864fbe7e2a40b6745edc9aec92..c2531b6e0e2310dc558e81dff95b69b45d90de2c 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 590.72  2002/01/19 09:59:08  error
+ * Full-screen curses support for Citadel text client
+
  Revision 590.71  2002/01/17 20:11:05  nbryant
  remove lock.c/lock.h; don't need them for what i was planning after all
 
@@ -3188,3 +3191,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
+
index 41d068a6b736c92b8ca5b4c637cb09ea3884e58d..f6bf6be2e5708c82718bbff9a829e94b1eff9f1d 100644 (file)
@@ -86,7 +86,7 @@ SOURCES=aidepost.c citadel.c citmail.c citserver.c client_chat.c \
        client_crypto.c commands.c config.c control.c $(DATABASE) \
        dynloader.c file_ops.c housekeeping.c ipc_c_tcp.c locate_host.c \
        logging.c messages.c msgbase.c msgform.c \
-       netsetup.c policy.c readlog.c migratenet.c \
+       netsetup.c policy.c readlog.c migratenet.c screen.c \
        room_ops.c rooms.c routines.c routines2.c serv_chat.c serv_crypto.c \
        serv_info.c serv_test.c setup.c snprintf.c stats.c serv_vcard.c \
        support.c sysdep.c tools.c user_ops.c userlist.c serv_expire.c \
@@ -114,14 +114,14 @@ serv_modules: $(SERV_MODULES)
 #
 
 citadel$(EXEEXT): ipc_c_tcp$(CX) citadel$(CX) rooms$(CX) routines$(CX) \
-       routines2$(CX) messages$(CX)  \
+       routines2$(CX) messages$(CX) screen$(CX) \
        client_passwords$(CX) md5$(CX) client_crypto$(CX) \
        commands$(CX) client_chat$(CX) serv_info$(CX) tools$(CX) $(LIBOBJS)
        $(CC) ipc_c_tcp$(CX) citadel$(CX) rooms$(CX) routines$(CX) \
-       routines2$(CX) messages$(CX) \
+       routines2$(CX) messages$(CX) screen$(CX) \
        commands$(CX) client_chat$(CX) serv_info$(CX) tools$(CX) \
        client_passwords$(CX) md5$(CX) client_crypto$(CX) \
-       $(LIBOBJS) $(LDFLAGS) -o citadel $(NETLIBS) $(SSL_LIBS) $(CLIENT_PTLIBS)
+       $(LIBOBJS) $(LDFLAGS) -o citadel $(CURSES) $(NETLIBS) $(SSL_LIBS) $(CLIENT_PTLIBS)
 
 .c.o:
        $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) -c $<
index 958d43d11f0d6f23d526cf4888e51941025cb7e1..a3d6e0d856153a1916ca10c4d97805dfe8159ff4 100644 (file)
@@ -24,3 +24,6 @@
 
 /* Define if you have OpenSSL. */
 #undef HAVE_OPENSSL
+
+/* Define if curses implementation has vw_printw */
+#undef VW_PRINTW_IN_CURSES
index c9de2c8716aa230921381f607c2cef2fb96f5b38..5340ffc72456a1a836bb79cdca0aa594ba5cb362 100644 (file)
@@ -51,6 +51,7 @@
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
+#include "screen.h"
 
 #include "md5.h"
 
@@ -128,6 +129,8 @@ void logoff(int code)
  * now clean up various things
  */
 
+       screen_delete();
+
        unlink(temp);
        unlink(temp2);
        nukedir(tempdir);
@@ -177,7 +180,7 @@ void formout(char *name)
        serv_puts(cmd);
        serv_gets(cmd);
        if (cmd[0] != '1') {
-               printf("%s\n", &cmd[4]);
+               scr_printf("%s\n", &cmd[4]);
                return;
        }
        fmout(screenwidth, NULL,
@@ -343,7 +346,7 @@ void dotgoto(char *towhere, int display_name)
                        express_msgs = 1;
        }
        if (!strncmp(aaa, "54", 2)) {
-               printf("Wrong password.\n");
+               scr_printf("Wrong password.\n");
                return;
        }
        /*
@@ -373,7 +376,7 @@ void dotgoto(char *towhere, int display_name)
                                }
                        }
                if (strlen(bbb) == 0) {
-                       printf("No room '%s'.\n", towhere);
+                       scr_printf("No room '%s'.\n", towhere);
                        return;
                }
                snprintf(aaa, sizeof aaa, "GOTO %s", bbb);
@@ -383,7 +386,7 @@ void dotgoto(char *towhere, int display_name)
                        express_msgs = 1;
        }
        if (aaa[0] != '2') {
-               printf("%s\n", aaa);
+               scr_printf("%s\n", aaa);
                return;
        }
        extract(room_name, &aaa[4], 0);
@@ -397,23 +400,23 @@ void dotgoto(char *towhere, int display_name)
        if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
                if (floorlist[(int) curr_floor][0] == 0)
                        load_floorlist();
-               printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
+               scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
        }
        if (display_name == 1) {
                color(BRIGHT_WHITE);
-               printf("%s ", room_name);
+               scr_printf("%s ", room_name);
                color(DIM_WHITE);
-               printf("- ");
+               scr_printf("- ");
        }
        if (display_name != 2) {
                color(BRIGHT_YELLOW);
-               printf("%d ", extract_int(&aaa[4], 1));
+               scr_printf("%d ", extract_int(&aaa[4], 1));
                color(DIM_WHITE);
-               printf("new of ");
+               scr_printf("new of ");
                color(BRIGHT_YELLOW);
-               printf("%d ", extract_int(&aaa[4], 2));
+               scr_printf("%d ", extract_int(&aaa[4], 2));
                color(DIM_WHITE);
-               printf("messages.\n");
+               scr_printf("messages.\n");
        }
        highest_msg_read = extract_int(&aaa[4], 6);
        maxmsgnum = extract_int(&aaa[4], 5);
@@ -430,7 +433,7 @@ void dotgoto(char *towhere, int display_name)
                newmailcount = extract_int(&aaa[4], 9);
                if ((oldmailcount >= 0) && (newmailcount > oldmailcount)) {
                        color(BRIGHT_RED);
-                       printf("*** You have new mail\n");
+                       scr_printf("*** You have new mail\n");
                        color(DIM_WHITE);
                }
                oldmailcount = newmailcount;
@@ -507,13 +510,13 @@ void forget_all_rooms_on(int ffloor)
        char buf[SIZ];
        struct march *flist, *fptr;
 
-       printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
-       fflush(stdout);
+       scr_printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
+       scr_flush();
        snprintf(buf, sizeof buf, "LKRA %d", ffloor);
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0] != '1') {
-               printf("%-72s\n", &buf[4]);
+               scr_printf("%-72s\n", &buf[4]);
                return;
        }
        flist = NULL;
@@ -535,7 +538,7 @@ void forget_all_rooms_on(int ffloor)
                flist = flist->next;
                free(fptr);
        }
-       printf("%-72s\r", "");
+       scr_printf("%-72s\r", "");
 }
 
 
@@ -593,7 +596,7 @@ void gotofloor(char *towhere, int mode)
                                tofloor = a;
        }
        if (tofloor < 0) {
-               printf("No floor '%s'.\n", towhere);
+               scr_printf("No floor '%s'.\n", towhere);
                return;
        }
        for (mptr = march; mptr != NULL; mptr = mptr->next) {
@@ -614,7 +617,7 @@ void gotofloor(char *towhere, int mode)
        if (strlen(targ) > 0) {
                gf_toroom(targ, mode);
        } else {
-               printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
+               scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
        }
 }
 
@@ -626,12 +629,12 @@ void forget_this_floor(void)
 {
 
        if (curr_floor == 0) {
-               printf("Can't forget this floor.\n");
+               scr_printf("Can't forget this floor.\n");
                return;
        }
        if (floorlist[0][0] == 0)
                load_floorlist();
-       printf("Are you sure you want to forget all rooms on %s? ",
+       scr_printf("Are you sure you want to forget all rooms on %s? ",
               &floorlist[(int) curr_floor][0]);
        if (yesno() == 0)
                return;
@@ -642,6 +645,7 @@ void forget_this_floor(void)
 
 /* 
  * Figure out the physical screen dimensions, if we can
+ * WARNING:  this is now called from a signal handler!
  */
 void check_screen_dims(void)
 {
@@ -653,6 +657,9 @@ void check_screen_dims(void)
                unsigned short ypixels;         /* pixels */
        } xwinsz;
 
+       if (scr_set_windowsize())
+               return;
+
        if (have_xterm) {       /* dynamically size screen if on an xterm */
                if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
                        if (xwinsz.height)
@@ -710,11 +717,11 @@ int set_password(void)
                snprintf(buf, sizeof buf, "SETP %s", pass1);
                serv_puts(buf);
                serv_gets(buf);
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                offer_to_remember_password(hostbuf, portbuf, fullname, pass1);
                return (0);
        } else {
-               printf("*** They don't match... try again.\n");
+               scr_printf("*** They don't match... try again.\n");
                return (1);
        }
 }
@@ -887,10 +894,10 @@ int main(int argc, char **argv)
        
        /* Permissions sanity check - don't run citadel setuid/setgid */
        if (getuid() != geteuid()) {
-               fprintf(stderr, "Please do not run citadel setuid!\n");
+               err_printf("Please do not run citadel setuid!\n");
                logoff(3);
        } else if (getgid() != getegid()) {
-               fprintf(stderr, "Please do not run citadel setgid!\n");
+               err_printf("Please do not run citadel setgid!\n");
                logoff(3);
        }
 
@@ -902,6 +909,7 @@ int main(int argc, char **argv)
        signal(SIGCONT, catch_sigcont);         /* Catch SIGCONT so we can reset terminal */
 
        arg_encrypt = RC_DEFAULT;
+       arg_screen = RC_DEFAULT;
 
        /* 
         * Handle command line options as if we were called like /bin/login
@@ -920,6 +928,14 @@ int main(int argc, char **argv)
                        arg_encrypt = RC_YES;
                        argc = shift(argc, argv, a, 1);
                }
+               if (!strcmp(argv[a], "-s")) {
+                       arg_screen = RC_NO;
+                       argc = shift(argc, argv, a, 1);
+               }
+               if (!strcmp(argv[a], "-S")) {
+                       arg_screen = RC_YES;
+                       argc = shift(argc, argv, a, 1);
+               }
                if (!strcmp(argv[a], "-p")) {
                        struct stat st;
                
@@ -947,7 +963,7 @@ int main(int argc, char **argv)
                                        logoff(3);
                                }
                                /*
-                               printf("Privileges changed to uid %d gid %d\n",
+                               scr_printf("Privileges changed to uid %d gid %d\n",
                                                getuid(), getgid());
                                */
                        }
@@ -955,15 +971,15 @@ int main(int argc, char **argv)
                }
        }
 
-       printf("Attaching to server... \r");
-       fflush(stdout);
-       attach_to_server(argc, argv, hostbuf, portbuf);
+       screen_new();
 
-       send_ansi_detect();
+       sln_printf("Attaching to server... \r");
+       sln_flush();
+       attach_to_server(argc, argv, hostbuf, portbuf);
 
        serv_gets(aaa);
        if (aaa[0] != '2') {
-               printf("%s\n", &aaa[4]);
+               scr_printf("%s\n", &aaa[4]);
                logoff(atoi(aaa));
        }
 
@@ -991,24 +1007,20 @@ int main(int argc, char **argv)
 
        get_serv_info(telnet_client_host);
 
-       look_for_ansi();
-       cls(0);
-       color(7);
-
        if (!starttls()) {
-               printf("Session will not be encrypted.\n");
+               sln_printf("Session will not be encrypted.\n");
        }
 
-       printf("%-24s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode,
+       scr_printf("%-24s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode,
                serv_info.serv_bbs_city);
 
        screenwidth = 80;       /* default screen dimensions */
        screenheight = 24;
        
-       printf(" pause    next    stop\n");
-       printf(" ctrl-s  ctrl-o  ctrl-c\n\n");
+       scr_printf(" pause    next    stop\n");
+       scr_printf(" ctrl-s  ctrl-o  ctrl-c\n\n");
        formout("hello");       /* print the opening greeting */
-       printf("\n");
+       scr_printf("\n");
 
 GSTA:  /* See if we have a username and password on disk */
        if (rc_remember_passwords) {
@@ -1049,7 +1061,7 @@ GSTA:     /* See if we have a username and password on disk */
                }
                strproc(fullname);
                if (!strcasecmp(fullname, "new")) {     /* just in case */
-                       printf("Please enter the name you wish to log in with.\n");
+                       scr_printf("Please enter the name you wish to log in with.\n");
                }
        } while (
                        (!strcasecmp(fullname, "bbs"))
@@ -1092,13 +1104,13 @@ GSTA:   /* See if we have a username and password on disk */
                                        fullname, password);
                goto PWOK;
        }
-       printf("<< wrong password >>\n");
+       scr_printf("<< wrong password >>\n");
        if (strlen(rc_password) > 0)
                logoff(0);
        goto GSTA;
 
 NEWUSR:        if (strlen(rc_password) == 0) {
-               printf("No record. Enter as new user? ");
+               scr_printf("No record. Enter as new user? ");
                if (yesno() == 0)
                        goto GSTA;
        }
@@ -1106,7 +1118,7 @@ NEWUSR:   if (strlen(rc_password) == 0) {
        serv_puts(aaa);
        serv_gets(aaa);
        if (aaa[0] != '2') {
-               printf("%s\n", aaa);
+               scr_printf("%s\n", aaa);
                goto GSTA;
        }
        load_user_info(&aaa[4]);
@@ -1125,15 +1137,15 @@ PWOK:
                        enable_color = 0;
        }
 
-       printf("%s\nAccess level: %d (%s)\n"
+       scr_printf("%s\nAccess level: %d (%s)\n"
                "User #%ld / Login #%d",
                fullname, axlevel, axdefs[(int) axlevel],
                usernum, timescalled);
        if (lastcall > 0L) {
-               printf(" / Last login: %s\n",
+               scr_printf(" / Last login: %s\n",
                        asctime(localtime(&lastcall)) );
        }
-       printf("\n");
+       scr_printf("\n");
 
        serv_puts("CHEK");
        serv_gets(aaa);
@@ -1142,16 +1154,16 @@ PWOK:
                if (b > 0) {
                        color(BRIGHT_RED);
                        if (b == 1)
-                               printf("*** You have a new private message in Mail>\n");
+                               scr_printf("*** You have a new private message in Mail>\n");
                        if (b > 1)
-                               printf("*** You have %d new private messages in Mail>\n", b);
+                               scr_printf("*** You have %d new private messages in Mail>\n", b);
                        color(DIM_WHITE);
                }
                if ((axlevel >= 6) && (extract_int(&aaa[4], 2) > 0)) {
-                       printf("*** Users need validation\n");
+                       scr_printf("*** Users need validation\n");
                }
                if (extract_int(&aaa[4], 1) > 0) {
-                       printf("*** Please register.\n");
+                       scr_printf("*** Please register.\n");
                        formout("register");
                        entregis();
                }
@@ -1229,7 +1241,7 @@ PWOK:
                                serv_puts(bbb);
                                serv_gets(aaa);
                                if (strncmp("200", aaa, 3))
-                                       printf("\n%s\n", aaa);
+                                       scr_printf("\n%s\n", aaa);
                                else
                                        entmsg(0, 0);
                                break;
@@ -1382,7 +1394,7 @@ PWOK:
                                serv_puts(bbb);
                                serv_gets(aaa);
                                if (strncmp("200", aaa, 3))
-                                       printf("\n%s\n", aaa);
+                                       scr_printf("\n%s\n", aaa);
                                break;
                        case 76:
                                enternew("hostname", aaa, 25);
@@ -1390,7 +1402,7 @@ PWOK:
                                serv_puts(bbb);
                                serv_gets(aaa);
                                if (strncmp("200", aaa, 3))
-                                       printf("\n%s\n", aaa);
+                                       scr_printf("\n%s\n", aaa);
                                break;
                        case 77:
                                enternew("username", aaa, 32);
@@ -1398,7 +1410,7 @@ PWOK:
                                serv_puts(bbb);
                                serv_gets(aaa);
                                if (strncmp("200", aaa, 3))
-                                       printf("\n%s\n", aaa);
+                                       scr_printf("\n%s\n", aaa);
                                break;
 
                        case 35:
@@ -1417,7 +1429,7 @@ PWOK:
                                break;
 
                        case 15:
-                               printf("Are you sure (y/n)? ");
+                               scr_printf("Are you sure (y/n)? ");
                                if (yesno() == 1) {
                                        updatels();
                                        a = 0;
@@ -1426,12 +1438,12 @@ PWOK:
                                break;
 
                        case 85:
-                               printf("All users will be disconnected!  "
+                               scr_printf("All users will be disconnected!  "
                                        "Really terminate the server? ");
                                if (yesno() == 1) {
                                        serv_puts("DOWN");
                                        serv_gets(aaa);
-                                       printf("%s\n", &aaa[4]);
+                                       scr_printf("%s\n", &aaa[4]);
                                        if (aaa[0]=='2') {
                                                updatels();
                                                a = 0;
@@ -1441,19 +1453,19 @@ PWOK:
                                break;
 
                        case 86:
-                               printf("Do you really want to schedule a "
+                               scr_printf("Do you really want to schedule a "
                                        "server shutdown? ");
                                if (yesno() == 1) {
                                        serv_puts("SCDN 1");
                                        serv_gets(aaa);
                                        if (aaa[0]=='2') {
                                                if (atoi(&aaa[4])) {
-                                                       printf(
+                                                       scr_printf(
 "The Citadel server will terminate when all users are logged off.\n"
                                                                );
                                                }
                                                else {
-                                                       printf(
+                                                       scr_printf(
 "The Citadel server will not terminate.\n"
                                                                );
                                                }
@@ -1487,14 +1499,16 @@ PWOK:
 
                        case 2:
                                if (server_is_local) {
+                                       screen_reset();
                                        sttybbs(SB_RESTORE);
                                        snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
                                                 "exec ./subsystem %ld %d %d", fullname,
                                          usernum, screenwidth, axlevel);
                                        ka_system(aaa);
                                        sttybbs(SB_NO_INTR);
+                                       screen_set();
                                } else {
-                                       printf("*** Can't run doors when server is not local.\n");
+                                       scr_printf("*** Can't run doors when server is not local.\n");
                                }
                                break;
 
@@ -1574,12 +1588,12 @@ PWOK:
 
                        case 8:
                                knrooms(floor_mode);
-                               printf("\n");
+                               scr_printf("\n");
                                break;
 
                        case 68:
                                knrooms(2);
-                               printf("\n");
+                               scr_printf("\n");
                                break;
 
                        case 69:
@@ -1592,7 +1606,7 @@ PWOK:
 
                        case 19:
                                listzrooms();
-                               printf("\n");
+                               scr_printf("\n");
                                break;
 
                        case 51:
@@ -1614,16 +1628,18 @@ PWOK:
                        }       /* end switch */
        } while (termn8 == 0);
 
-TERMN8:        printf("%s logged out.\n", fullname);
+TERMN8:        scr_printf("%s logged out.\n", fullname);
        while (march != NULL) {
                remove_march(march->march_name, 0);
        }
        if (mcmd == 30) {
-               printf("\n\nType 'off' to disconnect, or next user...\n");
+               sln_printf("\n\nType 'off' to disconnect, or next user...\n");
        }
        snprintf(aaa, sizeof aaa, "LOUT");
        serv_puts(aaa);
        serv_gets(aaa);
+       screen_delete();
+       sttybbs(SB_RESTORE);
        if ((mcmd == 29) || (mcmd == 15)) {
                formout("goodbye");
                logoff(0);
index 8f8478bfd9e20015b0e4a0f383ef6b81566e7b4d..849b43b98fbf7bab732324a3f0f67da5a0867a8f 100644 (file)
 # systems on the same machine as the client.
 encrypt=default
 
+# Set FULLSCREN to yes to (attempt to) use full-screen curses mode.
+# This mode presents a status line and a few other niceties.  Some
+# people might not like this, so you can turn it off here or with the
+# -s command line option.  The default is to use full screen if the
+# terminal supports it.
+#fullscreen=yes
+
 # Set EDITOR to the name of an external editor to be used for entering
 # messages.  If you want the external editor to be used by default, be sure
 # to reflect this in the command set below.
@@ -117,7 +124,7 @@ remember_passwords=0
 # systems, where many messages may be posted while reading.  Users
 # accustomed to D.O.C. or its variants will want to set this option.
 #
-alternate_semantics=no
+alternate_semantics=yes
 
 
 # COMMAND SET CONFIGURATION
index 6a63a3c643fb6d23cf45bfb139fb4cddccdc8587..59c10af0c710648d1005e57e7cc6e3d2e3891d4b 100644 (file)
@@ -15,6 +15,8 @@ extern char rc_password[32];
 extern char rc_floor_mode;
 extern char rc_encrypt;                        /* from the citadel.rc file */
 extern char arg_encrypt;               /* from the command line */
+extern char rc_screen;
+extern char arg_screen;
 extern char rc_alt_semantics;
 extern char express_msgs;
 void logoff(int code);
index 268d47d558516382aa4f1bd2b5813d596f2331fa..57b0ba2aa09456c2bef52a6d33c12a6bcf82a99e 100644 (file)
@@ -44,6 +44,7 @@
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
+#include "screen.h"
 
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 
@@ -74,17 +75,17 @@ void chatmode(void)
        serv_puts("CHAT");
        serv_gets(buf);
        if (buf[0] != '8') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
-       printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
+       scr_printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
        set_keepalives(KA_NO);
        last_transmit = time(NULL);
 
        strcpy(buf, "");
        strcpy(wbuf, "");
        color(BRIGHT_YELLOW);
-       printf("> ");
+       scr_printf("> ");
        send_complete_line = 0;
        recv_complete_line = 0;
 
@@ -115,7 +116,7 @@ void chatmode(void)
                        } else if ((ch == 8) || (ch == 127)) {
                                if (strlen(wbuf) > 0) {
                                        wbuf[strlen(wbuf) - 1] = 0;
-                                       printf("%c %c", 8, 8);
+                                       scr_printf("%c %c", 8, 8);
                                }
                        } else {
                                putc(ch, stdout);
@@ -150,12 +151,12 @@ void chatmode(void)
                        }
                }
                if (recv_complete_line) {
-                       printf("\r%79s\r", "");
+                       scr_printf("\r%79s\r", "");
                        if (!strcmp(buf, "000")) {
                                color(BRIGHT_WHITE);
-                               printf("Exiting chat mode\n");
+                               scr_printf("Exiting chat mode\n");
 
-                               fflush(stdout);
+                               scr_flush();
                                set_keepalives(KA_YES);
 
 
@@ -177,7 +178,7 @@ void chatmode(void)
                                extract(c_text, buf, 1);
                                if (num_parms(buf) > 2) {
                                        extract(c_room, buf, 2);
-                                       printf("Got room %s\n", c_room);
+                                       scr_printf("Got room %s\n", c_room);
                                }
                                if (strcasecmp(c_text, "NOOP")) {
                                        if (!strcmp(c_user, fullname)) {
@@ -200,15 +201,15 @@ void chatmode(void)
                                        while (strlen(buf) < 79)
                                                strcat(buf, " ");
                                        if (strcmp(c_user, last_user)) {
-                                               printf("\r%79s\n", "");
+                                               scr_printf("\r%79s\n", "");
                                                strcpy(last_user, c_user);
                                        }
-                                       printf("\r%s\n", buf);
+                                       scr_printf("\r%s\n", buf);
                                        fflush(stdout);
                                }
                        }
                        color(BRIGHT_YELLOW);
-                       printf("> %s", wbuf);
+                       scr_printf("> %s", wbuf);
                        recv_complete_line = 0;
                        strcpy(buf, "");
                }
@@ -244,7 +245,7 @@ void page_user()
                if (!strncmp(buf, "200", 3)) {
                        strcpy(last_paged, touser);
                }
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
        /* new server -- use extended paging */
@@ -253,11 +254,11 @@ void page_user()
                serv_puts(buf);
                serv_gets(buf);
                if (buf[0] != '2') {
-                       printf("%s\n", &buf[4]);
+                       scr_printf("%s\n", &buf[4]);
                        return;
                }
                if (client_make_message(temp, touser, 0, 0, 0) != 0) {
-                       printf("No message sent.\n");
+                       scr_printf("No message sent.\n");
                        return;
                }
                pagefp = fopen(temp, "r");
@@ -273,9 +274,9 @@ void page_user()
                        }
                        fclose(pagefp);
                        serv_puts("000");
-                       printf("Message sent.\n");
+                       scr_printf("Message sent.\n");
                } else {
-                       printf("%s\n", &buf[4]);
+                       scr_printf("%s\n", &buf[4]);
                }
        }
 }
@@ -291,7 +292,7 @@ void quiet_mode(void)
        serv_puts("DEXP 2");
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
        qstate = atoi(&buf[4]);
@@ -303,13 +304,13 @@ void quiet_mode(void)
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
        qstate = atoi(&buf[4]);
        if (qstate) {
-               printf("Quiet mode enabled (no other users may page you)\n");
+               scr_printf("Quiet mode enabled (no other users may page you)\n");
        } else {
-               printf("Quiet mode disabled (other users may page you)\n");
+               scr_printf("Quiet mode disabled (other users may page you)\n");
        }
 }
index 5b1aba58396ebb5372833423b8b5090290a51963..73b58658b8773916503ee56f6b05b1a3f9f6301b 100644 (file)
@@ -13,6 +13,7 @@
 #include <sys/types.h>
 #include "citadel.h"
 #include "client_crypto.h"
+#include "screen.h"
 
 #ifdef HAVE_OPENSSL
 SSL *ssl;
@@ -42,7 +43,7 @@ void serv_read_ssl(char *buf, int bytes)
        while (len < bytes) {
                if (SSL_want_read(ssl)) {
                        if ((SSL_write(ssl, junk, 0)) < 1) {
-                               fprintf(stderr, "SSL_write in serv_read:\n");
+                               err_printf("SSL_write in serv_read:\n");
                                ERR_print_errors_fp(stderr);
                        }
                }
@@ -62,7 +63,7 @@ void serv_read_ssl(char *buf, int bytes)
                                serv_read(&buf[len], bytes - len);
                                return;
                        }
-                       fprintf(stderr, "SSL_read in serv_read:\n");
+                       err_printf("SSL_read in serv_read:\n");
                        ERR_print_errors_fp(stderr);
                        connection_died();
                        return;
@@ -84,7 +85,7 @@ void serv_write_ssl(char *buf, int nbytes)
        while (bytes_written < nbytes) {
                if (SSL_want_write(ssl)) {
                        if ((SSL_read(ssl, junk, 0)) < 1) {
-                               fprintf(stderr, "SSL_read in serv_write:\n");
+                               err_printf("SSL_read in serv_write:\n");
                                ERR_print_errors_fp(stderr);
                        }
                }
@@ -106,7 +107,7 @@ void serv_write_ssl(char *buf, int nbytes)
                                                nbytes - bytes_written);
                                return;
                        }
-                       fprintf(stderr, "SSL_write in serv_write:\n");
+                       err_printf("SSL_write in serv_write:\n");
                        ERR_print_errors_fp(stderr);
                        connection_died();
                        return;
@@ -162,13 +163,13 @@ int starttls(void)
        ssl_method = SSLv23_client_method();
        ssl_ctx = SSL_CTX_new(ssl_method);
        if (!ssl_ctx) {
-               fprintf(stderr, "SSL_CTX_new failed: %s\n",
+               err_printf("SSL_CTX_new failed: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                return 0;
        }
        /* Any reasonable cipher we can get */
        if (!(SSL_CTX_set_cipher_list(ssl_ctx, CIT_CIPHERS))) {
-               fprintf(stderr, "No ciphers available for encryption\n");
+               err_printf("No ciphers available for encryption\n");
                SSL_CTX_free(ssl_ctx);
                ssl_ctx = NULL;
                return 0;
@@ -178,17 +179,17 @@ int starttls(void)
        /* Load DH parameters into the context */
        dh = DH_new();
        if (!dh) {
-               fprintf(stderr, "Can't allocate a DH object: %s\n",
+               err_printf("Can't allocate a DH object: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                return 0;
        }
        if (!(BN_hex2bn(&(dh->p), DH_P))) {
-               fprintf(stderr, "Can't assign DH_P: %s\n",
+               err_printf("Can't assign DH_P: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                return 0;
        }
        if (!(BN_hex2bn(&(dh->g), DH_G))) {
-               fprintf(stderr, "Can't assign DH_G: %s\n",
+               err_printf("Can't assign DH_G: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                return 0;
        }
@@ -221,7 +222,7 @@ int starttls(void)
        /* New SSL object */
        ssl = SSL_new(ssl_ctx);
        if (!ssl) {
-               fprintf(stderr, "SSL_new failed: %s\n",
+               err_printf("SSL_new failed: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                SSL_CTX_free(ssl_ctx);
                ssl_ctx = NULL;
@@ -232,13 +233,13 @@ int starttls(void)
        SSL_set_session_id_context(ssl, "Citadel/UX SID", 14);
 #endif
        if (!RAND_status()) {
-               fprintf(stderr, "PRNG not properly seeded\n");
+               err_printf("PRNG not properly seeded\n");
                return 0;
        }
 
        /* Associate network connection with SSL object */
        if (SSL_set_fd(ssl, serv_sock) < 1) {
-               fprintf(stderr, "SSL_set_fd failed: %s\n",
+               err_printf("SSL_set_fd failed: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                SSL_CTX_free(ssl_ctx);
                ssl_ctx = NULL;
@@ -247,20 +248,20 @@ int starttls(void)
                return 0;
        }
 
-       printf("Requesting encryption...\r");
-       fflush(stdout);
+       sln_printf("Requesting encryption...\r");
+       sln_flush();
 
        /* Ready to start SSL/TLS */
        serv_puts("STLS");
        serv_gets(buf);
        if (buf[0] != '2') {
-               fprintf(stderr, "Server can't start TLS: %s\n", &buf[4]);
+               err_printf("Server can't start TLS: %s\n", &buf[4]);
                return 0;
        }
 
        /* Do SSL/TLS handshake */
        if ((a = SSL_connect(ssl)) < 1) {
-               fprintf(stderr, "SSL_connect failed: %s\n",
+               err_printf("SSL_connect failed: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                SSL_CTX_free(ssl_ctx);
                ssl_ctx = NULL;
@@ -273,7 +274,7 @@ int starttls(void)
                int bits, alg_bits;
 
                bits = SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &alg_bits);
-               printf("Encrypting with %s cipher %s (%d of %d bits)\n",
+               sln_printf("Encrypting with %s cipher %s (%d of %d bits)\n",
                                SSL_CIPHER_get_version(SSL_get_current_cipher(ssl)),
                                SSL_CIPHER_get_name(SSL_get_current_cipher(ssl)),
                                bits, alg_bits);
index 95fa992c9cb1160dc33d8f99da6643610c2a7860..8ae1978a08ee2e3aee62efa0a2d7e4c76a338fc6 100644 (file)
@@ -55,6 +55,7 @@
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
+#include "screen.h"
 
 struct citcmd {
        struct citcmd *next;
@@ -181,7 +182,7 @@ void pprintf(const char *format, ...) {
         va_end(arg_ptr);   
 
        for (i=0; i<strlen(buf); ++i) {
-               putc(buf[i], stdout);
+               scr_putc(buf[i]);
                if (buf[i]==10) {
                        ++lines_printed;
                        lines_printed = checkpagin(lines_printed,
@@ -210,11 +211,11 @@ void print_express(void)
                return;
 
        if (rc_exp_beep) {
-               putc(7, stdout);
+               scr_putc(7);
        }
        if (strlen(rc_exp_cmd) == 0) {
                color(BRIGHT_RED);
-               printf("\r---");
+               scr_printf("\r---");
        }
        
        while (express_msgs != 0) {
@@ -277,41 +278,41 @@ void print_express(void)
                        }
                }
                /* fall back to built-in express message display */
-               printf("\n");
+               scr_printf("\n");
                lines_printed++;
 
                /* Header derived from flags */
                if (flags & 2)
-                       printf("Please log off now, as requested ");
+                       scr_printf("Please log off now, as requested ");
                else if (flags & 1)
-                       printf("Broadcast message ");
+                       scr_printf("Broadcast message ");
                else if (flags & 4)
-                       printf("Chat request ");
+                       scr_printf("Chat request ");
                else
-                       printf("Message ");
+                       scr_printf("Message ");
        
                /* Timestamp.  Can this be improved? */
                if (stamp->tm_hour == 0 || stamp->tm_hour == 12)/* 12am/12pm */
-                       printf("at 12:%02d%cm", stamp->tm_min, 
+                       scr_printf("at 12:%02d%cm", stamp->tm_min, 
                                stamp->tm_hour ? 'p' : 'a');
                else if (stamp->tm_hour > 12)                   /* pm */
-                       printf("at %d:%02dpm",
+                       scr_printf("at %d:%02dpm",
                                stamp->tm_hour - 12, stamp->tm_min);
                else                                            /* am */
-                       printf("at %d:%02dam", stamp->tm_hour, stamp->tm_min);
+                       scr_printf("at %d:%02dam", stamp->tm_hour, stamp->tm_min);
                
                /* Sender */
-               printf(" from %s", sender);
+               scr_printf(" from %s", sender);
        
                /* Remote node, if any */
                if (strncmp(serv_info.serv_nodename, node, 32))
-                       printf(" @%s", node);
+                       scr_printf(" @%s", node);
        
-               printf(":\n");
+               scr_printf(":\n");
                lines_printed++;
                fmout(screenwidth, NULL, 1, screenheight, -1, 0);
        }
-       printf("\n---\n");
+       scr_printf("\n---\n");
        color(BRIGHT_WHITE);
 
 
@@ -338,11 +339,11 @@ static void really_do_keepalive(void) {
                if (buf[3] == '*') {
                        express_msgs = 1;
                        if (ok_to_interrupt == 1) {
-                               printf("\r%64s\r", "");
+                               scr_printf("\r%64s\r", "");
                                print_express();
-                               printf("%s%c ", room_name,
+                               scr_printf("%s%c ", room_name,
                                       room_prompt(room_flags));
-                               fflush(stdout);
+                               scr_flush();
                        }
                }
        }
@@ -387,8 +388,8 @@ static void do_keepalive(void)
                return;
 
        /* Do a space-backspace to keep telnet sessions from idling out */
-       printf(" %c", 8);
-       fflush(stdout);
+       scr_printf(" %c", 8);
+       scr_flush();
 
 #ifdef THREADED_CLIENT
        if (async_ka_enabled)
@@ -430,9 +431,8 @@ int inkey(void)
        fd_set rfds;
        struct timeval tv;
        time_t start_time, now;
-       char inbuf[2];
 
-       fflush(stdout);
+       scr_flush();
        lines_printed = 0;
        time(&start_time);
 
@@ -460,15 +460,14 @@ int inkey(void)
                /* At this point, there's input, so fetch it.
                 * (There's a hole in the bucket...)
                 */
-               read(0, inbuf, 1);
-               a = inbuf[0];
+               a = scr_getc();
                if (a == 127)
                        a = 8;
                if (a > 126)
                        a = 0;
-               if (a == 10)
-                       a = 13;
-               if (((a != 4) && (a != 13) && (a != 8) && (a != NEXT_KEY) && (a != STOP_KEY))
+               if (a == 13)
+                       a = 10;
+               if (((a != 4) && (a != 10) && (a != 8) && (a != NEXT_KEY) && (a != STOP_KEY))
                    && ((a < 32) || (a > 126)))
                        a = 0;
        } while (a == 0);
@@ -483,11 +482,11 @@ int yesno(void)
                a = inkey();
                a = tolower(a);
                if (a == 'y') {
-                       printf("Yes\n");
+                       scr_printf("Yes\n");
                        return (1);
                }
                if (a == 'n') {
-                       printf("No\n");
+                       scr_printf("No\n");
                        return (0);
                }
        }
@@ -500,14 +499,14 @@ int yesno_d(int d)
        while (1) {
                a = inkey();
                a = tolower(a);
-               if (a == 13)
+               if (a == 10)
                        a = (d ? 'y' : 'n');
                if (a == 'y') {
-                       printf("Yes\n");
+                       scr_printf("Yes\n");
                        return (1);
                }
                if (a == 'n') {
-                       printf("No\n");
+                       scr_printf("No\n");
                        return (0);
                }
        }
@@ -535,18 +534,17 @@ void getline(char *string, int lim)
        a = (a & 127);
        if ((a == 8) && (strlen(string) == 0))
                goto GLA;
-       if ((a != 13) && (a != 8) && (strlen(string) == lim))
+       if ((a != 10) && (a != 8) && (strlen(string) == lim))
                goto GLA;
        if ((a == 8) && (string[0] != 0)) {
                string[strlen(string) - 1] = 0;
-               putc(8, stdout);
-               putc(32, stdout);
-               putc(8, stdout);
+               scr_putc(8);
+               scr_putc(32);
+               scr_putc(8);
                goto GLA;
        }
-       if ((a == 13) || (a == 10)) {
-               putc(13, stdout);
-               putc(10, stdout);
+       if ((a == 10)) {
+               scr_putc(10);
                async_ka_end();
                return;
        }
@@ -556,9 +554,9 @@ void getline(char *string, int lim)
        string[b] = a;
        string[b + 1] = 0;
        if (flag == 0)
-               putc(a, stdout);
+               scr_putc(a);
        if (flag == 1)
-               putc('*', stdout);
+               scr_putc('*');
        goto GLA;
 }
 
@@ -572,15 +570,15 @@ void strprompt(char *prompt, char *str, int len)
        char buf[128];
        print_express();
        color(DIM_WHITE);
-       printf("%s ", prompt);
+       scr_printf("%s ", prompt);
        color(DIM_MAGENTA);
-       printf("[");
+       scr_printf("[");
        color(BRIGHT_MAGENTA);
-       printf("%s", str);
+       scr_printf("%s", str);
        color(DIM_MAGENTA);
-       printf("]");
+       scr_printf("]");
        color(DIM_WHITE);
-       printf(": ");
+       scr_printf(": ");
        color(BRIGHT_CYAN);
        getline(buf, len);
        if (buf[0] != 0)
@@ -597,13 +595,13 @@ int boolprompt(char *prompt, int prev_val)
        int r;
 
        color(DIM_WHITE);
-       printf("%s ", prompt);
+       scr_printf("%s ", prompt);
        color(DIM_MAGENTA);
-       printf(" [");
+       scr_printf(" [");
        color(BRIGHT_MAGENTA);
-       printf("%s", (prev_val ? "Yes" : "No"));
+       scr_printf("%s", (prev_val ? "Yes" : "No"));
        color(DIM_MAGENTA);
-       printf("]: ");
+       scr_printf("]: ");
        color(BRIGHT_CYAN);
        r = (yesno_d(prev_val));
        color(DIM_WHITE);
@@ -631,9 +629,9 @@ int intprompt(char *prompt, int ival, int imin, int imax)
                                i = imin - 1;
                }
                if (i < imin)
-                       printf("*** Must be no less than %d.\n", imin);
+                       scr_printf("*** Must be no less than %d.\n", imin);
                if (i > imax)
-                       printf("*** Must be no more than %d.\n", imax);
+                       scr_printf("*** Must be no more than %d.\n", imax);
        } while ((i < imin) || (i > imax));
        return (i);
 }
@@ -645,7 +643,7 @@ int intprompt(char *prompt, int ival, int imin, int imax)
 void newprompt(char *prompt, char *str, int len)
 {
        color(BRIGHT_MAGENTA);
-       printf("%s", prompt);
+       scr_printf("%s", prompt);
        color(DIM_MAGENTA);
        getline(str, len);
        color(DIM_WHITE);
@@ -690,6 +688,7 @@ void load_command_set(void)
        rc_ansi_color = 0;
        strcpy(rc_url_cmd, "");
        rc_encrypt = RC_DEFAULT;
+       rc_screen = RC_DEFAULT;
        rc_alt_semantics = 0;
 
        /* now try to open the citadel.rc file */
@@ -726,6 +725,13 @@ void load_command_set(void)
                                rc_encrypt = RC_DEFAULT;
                }
 
+               if (!strncasecmp(buf, "fullscreen=", 11)) {
+                       if (!strcasecmp(&buf[11], "yes"))
+                               rc_screen = RC_YES;
+                       else if (!strcasecmp(&buf[11], "no"))
+                               rc_screen = RC_NO;
+               }
+
                if (!strncasecmp(buf, "editor=", 7))
                        strcpy(editor_path, &buf[7]);
 
@@ -972,10 +978,10 @@ int getcmd(char *argbuf)
        /* now the room prompt... */
        ok_to_interrupt = 1;
        color(BRIGHT_WHITE);
-       printf("\n%s", room_name);
+       scr_printf("\n%s", room_name);
        color(DIM_WHITE);
-       printf("%c ", room_prompt(room_flags));
-       fflush(stdout);
+       scr_printf("%c ", room_prompt(room_flags));
+       scr_flush();
 
        while (1) {
                ch = inkey();
@@ -1000,13 +1006,13 @@ int getcmd(char *argbuf)
                                if (cptr->c_cmdnum == this_lazy_cmd) {
                                        for (a = 0; a < 5; ++a)
                                                if (cptr->c_keys[a][0] != 0)
-                                                       printf("%s ", cmd_expand(
+                                                       scr_printf("%s ", cmd_expand(
                                                                                        cptr->c_keys[a], 0));
-                                       printf("\n");
+                                       scr_printf("\n");
                                        return (this_lazy_cmd);
                                }
                        }
-                       printf("\n");
+                       scr_printf("\n");
                        return (this_lazy_cmd);
                }
                /* Otherwise, process the command */
@@ -1015,12 +1021,12 @@ int getcmd(char *argbuf)
                for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
                        if (cmdmatch(cmdbuf, cptr, cmdpos + 1)) {
 
-                               printf("%s", cmd_expand(cptr->c_keys[cmdpos], 0));
+                               scr_printf("%s", cmd_expand(cptr->c_keys[cmdpos], 0));
                                cmdspaces[cmdpos] = strlen(
                                    cmd_expand(cptr->c_keys[cmdpos], 0));
                                if (cmdpos < 4)
                                        if ((cptr->c_keys[cmdpos + 1]) != 0)
-                                               putc(' ', stdout);
+                                               scr_putc(' ');
                                ++cmdpos;
                        }
                }
@@ -1031,7 +1037,7 @@ int getcmd(char *argbuf)
                                if (requires_string(cptr, cmdpos)) {
                                        getline(argbuf, 32);
                                } else {
-                                       printf("\n");
+                                       scr_printf("\n");
                                }
 
                                /* If this command is one that changes rooms,
@@ -1137,6 +1143,12 @@ void sttybbs(int cmd)
 {                              /* BSD version of sttybbs() */
        struct sgttyb live;
        static struct sgttyb saved_settings;
+       static int last_cmd = 0;
+
+       if (cmd == SB_LAST)
+               cmd = last_cmd;
+       else
+               last_cmd = cmd;
 
        if ((cmd == 0) || (cmd == 1)) {
                gtty(0, &live);
@@ -1244,7 +1256,7 @@ FMTA:     while ((eof_flag == 0) && (strlen(buffer) < 126)) {
        if (((a == 13) || (a == 10)) && (old != 13) && (old != 10))
                a = 32;
        if (((old == 13) || (old == 10)) && (isspace(real))) {
-               printf("\n");
+               scr_printf("\n");
                ++lines_printed;
                lines_printed = checkpagin(lines_printed, pagin, height);
                c = 1;
@@ -1254,7 +1266,7 @@ FMTA:     while ((eof_flag == 0) && (strlen(buffer) < 126)) {
 
        if (a > 32) {
                if (((strlen(aaa) + c) > (width - 5)) && (strlen(aaa) > (width - 5))) {
-                       printf("\n%s", aaa);
+                       scr_printf("\n%s", aaa);
                        c = strlen(aaa);
                        aaa[0] = 0;
                        ++lines_printed;
@@ -1267,18 +1279,18 @@ FMTA:   while ((eof_flag == 0) && (strlen(buffer) < 126)) {
        if (a == 32) {
                if ((strlen(aaa) + c) > (width - 5)) {
                        c = 1;
-                       printf("\n");
+                       scr_printf("\n");
                        ++lines_printed;
                        lines_printed = checkpagin(lines_printed, pagin, height);
                }
-               printf("%s ", aaa);
+               scr_printf("%s ", aaa);
                ++c;
                c = c + strlen(aaa);
                strcpy(aaa, "");
                goto FMTA;
        }
        if ((a == 13) || (a == 10)) {
-               printf("%s\n", aaa);
+               scr_printf("%s\n", aaa);
                c = 1;
                ++lines_printed;
                lines_printed = checkpagin(lines_printed, pagin, height);
@@ -1293,7 +1305,7 @@ OOPS:     do {
                serv_gets(aaa);
        } while (strcmp(aaa, "000"));
 
-FMTEND:        printf("\n");
+FMTEND:        scr_printf("\n");
        ++lines_printed;
        lines_printed = checkpagin(lines_printed, pagin, height);
        return (sigcaught);
@@ -1320,6 +1332,10 @@ void color(int colornum)
 
        current_color = colornum;
        if (enable_color) {
+#ifdef HAVE_CURSES_H
+               if (scr_color(colornum))
+                       return;
+#endif
                /* When switching to dim white, actually output an 'original
                 * pair' sequence -- this looks better on black-on-white
                 * terminals.
@@ -1336,7 +1352,7 @@ void color(int colornum)
                        printf("\033[0m");
                        is_bold = 0;
                }
-               fflush(stdout);
+               scr_flush();
        }
 }
 
@@ -1344,7 +1360,7 @@ void cls(int colornum)
 {
        if (enable_color) {
                printf("\033[4%dm\033[2J\033[H\033[0m", colornum);
-               fflush(stdout);
+               scr_flush();
        }
 }
 
@@ -1356,7 +1372,7 @@ void send_ansi_detect(void)
 {
        if (rc_ansi_color == 2) {
                printf("\033[c");
-               fflush(stdout);
+               scr_flush();
                time(&AnsiDetect);
        }
 }
@@ -1415,13 +1431,13 @@ void keyopt(char *buf) {
        color(DIM_WHITE);
        for (i=0; i<strlen(buf); ++i) {
                if (buf[i]=='<') {
-                       putc(buf[i], stdout);
+                       scr_putc(buf[i]);
                        color(BRIGHT_MAGENTA);
                } else {
                        if (buf[i]=='>') {
                                color(DIM_WHITE);
                        }
-                       putc(buf[i], stdout);
+                       scr_putc(buf[i]);
                }
        }
        color(DIM_WHITE);
@@ -1448,30 +1464,30 @@ char keymenu(char *menuprompt, char *menustring) {
        while (1) {
                if (display_prompt) {
                        if (do_prompt) {
-                               printf("%s ", menuprompt);
+                               scr_printf("%s ", menuprompt);
                        } 
                        else {
                                for (i=0; i<choices; ++i) {
                                        extract(buf, menustring, i);
                                        keyopt(buf);
-                                       printf(" ");
+                                       scr_printf(" ");
                                }
                        }
-                       printf(" -> ");
+                       scr_printf(" -> ");
                        display_prompt = 0;
                }
                ch = lkey();
        
                if ( (do_prompt) && (ch=='?') ) {
-                       printf("\rOne of...                               ");
-                       printf("                                      \n");
+                       scr_printf("\rOne of...                               ");
+                       scr_printf("                                      \n");
                        for (i=0; i<choices; ++i) {
                                extract(buf, menustring, i);
-                               printf("   ");
+                               scr_printf("   ");
                                keyopt(buf);
-                               printf("\n");
+                               scr_printf("\n");
                        }
-                       printf("\n");
+                       scr_printf("\n");
                        display_prompt = 1;
                }
 
@@ -1483,10 +1499,10 @@ char keymenu(char *menuprompt, char *menustring) {
                                   && (buf[c+1]=='>') ) {
                                        for (a=0; a<strlen(buf); ++a) {
                                                if ( (a!=(c-1)) && (a!=(c+1))) {
-                                                       putc(buf[a], stdout);
+                                                       scr_putc(buf[a]);
                                                }
                                        }
-                                       printf("\n\n");
+                                       scr_printf("\n\n");
                                        return ch;
                                }
                        }
index 59326f42754387b8b24a919c4b6d03297cf31b9f..ec7f25b0111adc86946f26ac143a8c7617182121 100644 (file)
@@ -224,6 +224,8 @@ AC_SEARCH_LIBS(tgetent, [curses termcap])
 AC_SEARCH_LIBS(initscr, [curses ncurses])
 CURSES=$LIBS
 LIBS=$save_LIBS
+SCURS=`echo $CURSES | sed -e s/-l//`
+AC_CHECK_LIB($SCURS, vw_printw, AC_DEFINE(VW_PRINTW_IN_CURSES))
 
 dnl Check for libpthread(s) if we're not using Digital UNIX or FreeBSD. (On
 dnl which the -pthread flag takes care of this.)
index a5a086daaa0a35835a632b3f3c8204517a013aff..263f50e3ef0b327b575c5064c90e83e2971f2148 100644 (file)
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
+#ifdef CIT_CLIENT
+#include "screen.h"
+#else
+int err_printf(char *fmt, ...);
+int err_printf(char *fmt, ...)
+{
+       va_list ap;
+       int retval;
+       va_start(ap, fmt);
+       retval = fprintf(stderr, fmt, ap);
+       va_end(ap);
+       return retval;
+}
+#endif
 
 /*
  * If server_is_local is set to nonzero, the client assumes that it is running
@@ -62,8 +76,7 @@ extern int ssl_is_connected;
 
 
 void connection_died(void) {
-       fprintf(stderr, "\r"
-                       "Your connection to this Citadel server is broken.\n"
+       err_printf("\rYour connection to this Citadel server is broken.\n"
                        "Please re-connect and log in again.\n");
        logoff(3);
 }
@@ -71,7 +84,7 @@ void connection_died(void) {
 
 void timeout(int signum)
 {
-       printf("\rConnection timed out.\n");
+       err_printf("\rConnection timed out.\n");
        logoff(3);
 }
 
@@ -101,12 +114,12 @@ static int connectsock(char *host, char *service, char *protocol, int defaultPor
        if (phe) {
                memcpy(&sin.sin_addr, phe->h_addr, phe->h_length);
        } else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) {
-               fprintf(stderr, "Can't get %s host entry: %s\n",
+               err_printf("Can't get %s host entry: %s\n",
                        host, strerror(errno));
                logoff(3);
        }
        if ((ppe = getprotobyname(protocol)) == 0) {
-               fprintf(stderr, "Can't get %s protocol entry: %s\n",
+               err_printf("Can't get %s protocol entry: %s\n",
                        protocol, strerror(errno));
                logoff(3);
        }
@@ -118,14 +131,14 @@ static int connectsock(char *host, char *service, char *protocol, int defaultPor
 
        s = socket(PF_INET, type, ppe->p_proto);
        if (s < 0) {
-               fprintf(stderr, "Can't create socket: %s\n", strerror(errno));
+               err_printf("Can't create socket: %s\n", strerror(errno));
                logoff(3);
        }
        signal(SIGALRM, timeout);
        alarm(30);
 
        if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
-               fprintf(stderr, "can't connect to %s.%s: %s\n",
+               err_printf("can't connect to %s.%s: %s\n",
                        host, service, strerror(errno));
                logoff(3);
        }
@@ -146,14 +159,12 @@ int uds_connectsock(char *sockpath)
 
        s = socket(AF_UNIX, SOCK_STREAM, 0);
        if (s < 0) {
-               fprintf(stderr, "Can't create socket: %s\n",
-                       strerror(errno));
+               err_printf("Can't create socket: %s\n", strerror(errno));
                logoff(3);
        }
 
        if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-               fprintf(stderr, "can't connect: %s\n",
-                       strerror(errno));
+               err_printf("can't connect: %s\n", strerror(errno));
                logoff(3);
        }
 
@@ -246,7 +257,7 @@ void serv_gets(char *buf)
  */
 void serv_puts(char *buf)
 {
-       /* printf("< %s\n", buf); */
+       /* err_printf("< %s\n", buf); */
        serv_write(buf, strlen(buf));
        serv_write("\n", 1);
 }
@@ -274,8 +285,8 @@ void attach_to_server(int argc, char **argv, char *hostbuf, char *portbuf)
                        strcpy(citport, argv[a]);
                }
                else {
-                       fprintf(stderr,"%s: usage: ",argv[0]);
-                       fprintf(stderr,"%s [host] [port] ",argv[0]);
+                       err_printf("%s: usage: ",argv[0]);
+                       err_printf("%s [host] [port] ",argv[0]);
                        logoff(2);
                }
        }
index c0ba96afad0341f1e0c24828565888616f076b53..218989038ab458aa0844b655fd3ba8b1c6293f3a 100644 (file)
@@ -343,9 +343,9 @@ char *make_apop_string(char *realpass, char *nonce, char *buffer)
    int i;
    
    MD5Init(&ctx);
-//   printf("MD5@@: Adding nonce: %s\n", nonce);
+//   scr_printf("MD5@@: Adding nonce: %s\n", nonce);
    MD5Update(&ctx, (u_char*)nonce, strlen(nonce));
-//   printf("MD5@@: Adding password %s\n", realpass);
+//   scr_printf("MD5@@: Adding password %s\n", realpass);
    MD5Update(&ctx, (u_char*)realpass, strlen(realpass));
    MD5Final(rawdigest, &ctx);
    for (i=0; i<MD5_DIGEST_LEN; i++)
@@ -354,7 +354,7 @@ char *make_apop_string(char *realpass, char *nonce, char *buffer)
       buffer[i*2] = tolower(buffer[i*2]);
       buffer[(i*2)+1] = tolower(buffer[(i*2)+1]);
    }
-//   printf("MD5@@: Result is %s\n", buffer);
+//   scr_printf("MD5@@: Result is %s\n", buffer);
    return buffer;
 }
 
index d18b2307fcd616de12afc2d249486ddc973a2e16..8bfc7a20e349f03ac5244140e4da5f94566248b7 100644 (file)
@@ -39,6 +39,7 @@
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
+#include "screen.h"
 
 #define MAXWORDBUF SIZ
 #define MAXMSGS 512
@@ -255,7 +256,7 @@ void citedit(FILE * fp)
        /******* new ***********/
                if ((a > 32) && (a < 127) && (prev == 13)) {
                        add_word(textlist, "\n");
-                       printf(" ");
+                       scr_printf(" ");
                }
        /***********************/
 
@@ -267,12 +268,12 @@ void citedit(FILE * fp)
                if (a == 8) {
                        if (strlen(wordbuf) > 0) {
                                wordbuf[strlen(wordbuf) - 1] = 0;
-                               putc(8, stdout);
-                               putc(32, stdout);
-                               putc(8, stdout);
+                               scr_putc(8);
+                               scr_putc(32);
+                               scr_putc(8);
                        }
                } else if (a == 13) {
-                       printf("\n");
+                       scr_printf("\n");
                        if (strlen(wordbuf) == 0)
                                finished = 1;
                        else {
@@ -289,7 +290,7 @@ void citedit(FILE * fp)
                                strcpy(wordbuf, "");
                        }
                } else {
-                       putc(a, stdout);
+                       scr_putc(a);
                        wordbuf[strlen(wordbuf) + 1] = 0;
                        wordbuf[strlen(wordbuf)] = a;
                }
@@ -309,15 +310,15 @@ void citedit(FILE * fp)
                                                b = 0;
                                        }
                                for (b = 0; b < strlen(wordbuf); ++b) {
-                                       putc(8, stdout);
-                                       putc(32, stdout);
-                                       putc(8, stdout);
+                                       scr_putc(8);
+                                       scr_putc(32);
+                                       scr_putc(8);
                                }
-                               printf("\n%s", wordbuf);
+                               scr_printf("\n%s", wordbuf);
                        } else {
                                add_word(textlist, wordbuf);
                                strcpy(wordbuf, "");
-                               printf("\n");
+                               scr_printf("\n");
                        }
                }
                prev = a;
@@ -362,7 +363,7 @@ int read_message(
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0] != '1') {
-               printf("*** msg #%ld: %s\n", num, buf);
+               err_printf("*** msg #%ld: %s\n", num, buf);
                ++lines_printed;
                lines_printed =
                    checkpagin(lines_printed, pagin, screenheight);
@@ -376,10 +377,10 @@ int read_message(
        strcpy(node, "");
        strcpy(rfca, "");
 
-       printf("\n");
+       scr_printf("\n");
        ++lines_printed;
        lines_printed = checkpagin(lines_printed, pagin, screenheight);
-       printf(" ");
+       scr_printf(" ");
        if (pagin == 1) {
                color(BRIGHT_CYAN);
        }
@@ -387,7 +388,7 @@ int read_message(
        if (pagin == 2) {
                while (serv_gets(buf), strcmp(buf, "000")) {
                        if (buf[4] == '=') {
-                               printf("%s\n", buf);
+                               scr_printf("%s\n", buf);
                                ++lines_printed;
                                lines_printed =
                                    checkpagin(lines_printed,
@@ -411,17 +412,17 @@ int read_message(
                if ((!strncasecmp(buf, "msgn=", 5))
                    && (rc_display_message_numbers)) {
                        color(DIM_WHITE);
-                       printf("[");
+                       scr_printf("[");
                        color(BRIGHT_WHITE);
-                       printf("#%s", &buf[5]);
+                       scr_printf("#%s", &buf[5]);
                        color(DIM_WHITE);
-                       printf("] ");
+                       scr_printf("] ");
                }
                if (!strncasecmp(buf, "from=", 5)) {
                        color(DIM_WHITE);
-                       printf("from ");
+                       scr_printf("from ");
                        color(BRIGHT_CYAN);
-                       printf("%s ", &buf[5]);
+                       scr_printf("%s ", &buf[5]);
                }
                if (!strncasecmp(buf, "subj=", 5))
                        strcpy(m_subject, &buf[5]);
@@ -429,29 +430,29 @@ int read_message(
                if (!strncasecmp(buf, "rfca=", 5)) {
                        safestrncpy(rfca, &buf[5], sizeof(rfca) - 5);
                        color(DIM_WHITE);
-                       printf("<");
+                       scr_printf("<");
                        color(BRIGHT_BLUE);
-                       printf("%s", &buf[5]);
+                       scr_printf("%s", &buf[5]);
                        color(DIM_WHITE);
-                       printf("> ");
+                       scr_printf("> ");
                }
                if ((!strncasecmp(buf, "hnod=", 5))
                    && (strcasecmp(&buf[5], serv_info.serv_humannode))
                    && (strlen(rfca) == 0)) {
                        color(DIM_WHITE);
-                       printf("(");
+                       scr_printf("(");
                        color(BRIGHT_WHITE);
-                       printf("%s", &buf[5]);
+                       scr_printf("%s", &buf[5]);
                        color(DIM_WHITE);
-                       printf(") ");
+                       scr_printf(") ");
                }
                if ((!strncasecmp(buf, "room=", 5))
                    && (strcasecmp(&buf[5], room_name))
                    && (strlen(rfca) == 0)) {
                        color(DIM_WHITE);
-                       printf("in ");
+                       scr_printf("in ");
                        color(BRIGHT_MAGENTA);
-                       printf("%s> ", &buf[5]);
+                       scr_printf("%s> ", &buf[5]);
                }
 
                if (!strncasecmp(buf, "node=", 5)) {
@@ -465,33 +466,33 @@ int read_message(
                        {
                                if (strlen(rfca) == 0) {
                                        color(DIM_WHITE);
-                                       printf("@");
+                                       scr_printf("@");
                                        color(BRIGHT_YELLOW);
-                                       printf("%s ", &buf[5]);
+                                       scr_printf("%s ", &buf[5]);
                                }
                        }
                }
 
                if (!strncasecmp(buf, "rcpt=", 5)) {
                        color(DIM_WHITE);
-                       printf("to ");
+                       scr_printf("to ");
                        color(BRIGHT_CYAN);
-                       printf("%s ", &buf[5]);
+                       scr_printf("%s ", &buf[5]);
                }
                if (!strncasecmp(buf, "time=", 5)) {
                        fmt_date(now, atol(&buf[5]), 0);
-                       printf("%s ", now);
+                       scr_printf("%s ", now);
                }
        }
 
        if (nhdr == 1) {
                if (!is_room_aide) {
-                       printf(" ****");
+                       scr_printf(" ****");
                } else {
-                       printf(" %s", from);
+                       scr_printf(" %s", from);
                }
        }
-       printf("\n");
+       scr_printf("\n");
 
        if (strlen(rfca) > 0) {
                strcpy(reply_to, rfca);
@@ -506,7 +507,7 @@ int read_message(
        lines_printed = checkpagin(lines_printed, pagin, screenheight);
 
        if (strlen(m_subject) > 0) {
-               printf("Subject: %s\n", m_subject);
+               scr_printf("Subject: %s\n", m_subject);
                ++lines_printed;
                lines_printed =
                    checkpagin(lines_printed, pagin, screenheight);
@@ -518,7 +519,7 @@ int read_message(
        } else {
                while (serv_gets(buf), strcmp(buf, "000")) {
                        if (sigcaught == 0) {
-                               printf("%s\n", buf);
+                               scr_printf("%s\n", buf);
                                lines_printed = lines_printed + 1 +
                                    (strlen(buf) / screenwidth);
                                lines_printed =
@@ -528,7 +529,8 @@ int read_message(
                }
                fr = sigcaught;
        }
-       printf("\n");
+       scr_printf("\n");
+       scr_flush();
        ++lines_printed;
        lines_printed = checkpagin(lines_printed, pagin, screenheight);
 
@@ -553,12 +555,12 @@ void replace_string(char *filename, long int startpos)
        int substitutions = 0;
        long msglen = 0L;
 
-       printf("Enter text to be replaced:\n: ");
+       scr_printf("Enter text to be replaced:\n: ");
        getline(srch_str, 128);
        if (strlen(srch_str) == 0)
                return;
 
-       printf("Enter text to replace it with:\n: ");
+       scr_printf("Enter text to replace it with:\n: ");
        getline(rplc_str, 128);
 
        fp = fopen(filename, "r+");
@@ -594,7 +596,7 @@ void replace_string(char *filename, long int startpos)
        wpos = ftell(fp);
        fclose(fp);
        truncate(filename, wpos);
-       printf("<R>eplace made %d substitution(s).\n\n", substitutions);
+       scr_printf("<R>eplace made %d substitution(s).\n\n", substitutions);
 }
 
 /*
@@ -615,7 +617,7 @@ int client_make_message(char *filename,     /* temporary file name */
 
        if (mode == 2)
                if (strlen(editor_path) == 0) {
-                       printf
+                       err_printf
                            ("*** No editor available, using built-in editor\n");
                        mode = 0;
                }
@@ -634,12 +636,12 @@ int client_make_message(char *filename,   /* temporary file name */
                                " to %s", recipient);
                }
        }
-       printf("%s\n", header);
+       scr_printf("%s\n", header);
 
        beg = 0L;
 
        if (mode == 1) {
-               printf("(Press ctrl-d when finished)\n");
+               scr_printf("(Press ctrl-d when finished)\n");
        }
 
        if (mode == 0) {
@@ -651,7 +653,7 @@ int client_make_message(char *filename,     /* temporary file name */
                } else {
                        fp = fopen(filename, "w");
                        if (fp == NULL) {
-                               printf("*** Error opening temp file!\n"
+                               err_printf("*** Error opening temp file!\n"
                                        "    %s: %s\n",
                                        filename, strerror(errno));
                        return(1);
@@ -665,7 +667,7 @@ ME1:        switch (mode) {
        case 0:
                fp = fopen(filename, "r+");
                if (fp == NULL) {
-                       printf("*** Error opening temp file!\n"
+                       err_printf("*** Error opening temp file!\n"
                                "    %s: %s\n",
                                filename, strerror(errno));
                        return(1);
@@ -677,7 +679,7 @@ ME1:        switch (mode) {
        case 1:
                fp = fopen(filename, "a");
                if (fp == NULL) {
-                       printf("*** Error opening temp file!\n"
+                       err_printf("*** Error opening temp file!\n"
                                "    %s: %s\n",
                                filename, strerror(errno));
                        return(1);
@@ -690,10 +692,10 @@ ME1:      switch (mode) {
                                a = 10;
                        if (a != 4) {
                                putc(a, fp);
-                               putc(a, stdout);
+                               scr_putc(a);
                        }
                        if (a == 10)
-                               putc(13, stdout);
+                               scr_putc(10);
                } while (a != 4);
                fclose(fp);
                break;
@@ -704,6 +706,7 @@ ME1:        switch (mode) {
                cksum = file_checksum(filename);
                if (editor_pid == 0) {
                        chmod(filename, 0600);
+                       screen_reset();
                        sttybbs(SB_RESTORE);
                        setenv("WINDOW_TITLE", header, 1);
                        execlp(editor_path, editor_path, filename, NULL);
@@ -716,12 +719,13 @@ ME1:      switch (mode) {
                        } while ((b != editor_pid) && (b >= 0));
                editor_pid = (-1);
                sttybbs(0);
+               screen_set();
                break;
        }
 
 MECR:  if (mode == 2) {
                if (file_checksum(filename) == cksum) {
-                       printf("*** Aborted message.\n");
+                       err_printf("*** Aborted message.\n");
                        e_ex_code = 1;
                }
                if (e_ex_code == 0)
@@ -740,10 +744,10 @@ MECR:     if (mode == 2) {
        if (b == 's')
                goto MEFIN;
        if (b == 'p') {
-               printf(" %s from %s", datestr, fullname);
+               scr_printf(" %s from %s", datestr, fullname);
                if (strlen(recipient) > 0)
-                       printf(" to %s", recipient);
-               printf("\n");
+                       scr_printf(" to %s", recipient);
+               scr_printf("\n");
                fp = fopen(filename, "r");
                if (fp != NULL) {
                        fmout(screenwidth, fp,
@@ -764,7 +768,7 @@ MECR:       if (mode == 2) {
 
 MEFIN: return (0);
 
-MEABT: printf("Are you sure? ");
+MEABT: scr_printf("Are you sure? ");
        if (yesno() == 0) {
                goto ME1;
        }
@@ -816,16 +820,16 @@ void transmit_message(FILE *fp)
                }
 
                if ((time(NULL) - lasttick) > 2L) {
-                       printf(" %3ld%% completed\r",
+                       scr_printf(" %3ld%% completed\r",
                               ((ftell(fp) * 100L) / msglen));
-                       fflush(stdout);
+                       scr_flush();
                        lasttick = time(NULL);
                }
 
        }
        serv_puts(buf);
-       printf("                \r");
-       fflush(stdout);
+       scr_printf("                \r");
+       scr_flush();
 }
 
 
@@ -859,7 +863,7 @@ int entmsg(int is_reply,    /* nonzero if this was a <R>eply command */
        serv_gets(cmd);
 
        if ((strncmp(cmd, "570", 3)) && (strncmp(cmd, "200", 3))) {
-               printf("%s\n", &cmd[4]);
+               scr_printf("%s\n", &cmd[4]);
                return (1);
        }
 
@@ -882,7 +886,7 @@ int entmsg(int is_reply,    /* nonzero if this was a <R>eply command */
                        if (is_reply) {
                                strcpy(buf, reply_to);
                        } else {
-                               printf("Enter recipient: ");
+                               scr_printf("Enter recipient: ");
                                getline(buf, (SIZ-100) );
                                if (strlen(buf) == 0)
                                        return (1);
@@ -893,7 +897,7 @@ int entmsg(int is_reply,    /* nonzero if this was a <R>eply command */
 
        b = 0;
        if (room_flags & QR_ANONOPT) {
-               printf("Anonymous (Y/N)? ");
+               scr_printf("Anonymous (Y/N)? ");
                if (yesno() == 1)
                        b = 1;
        }
@@ -904,7 +908,7 @@ int entmsg(int is_reply,    /* nonzero if this was a <R>eply command */
                serv_puts(cmd);
                serv_gets(cmd);
                if (cmd[0] != '2') {
-                       printf("%s\n", &cmd[4]);
+                       scr_printf("%s\n", &cmd[4]);
                        return (1);
                }
        }
@@ -916,7 +920,7 @@ int entmsg(int is_reply,    /* nonzero if this was a <R>eply command */
        serv_puts("MSGS LAST|1");
        serv_gets(cmd);
        if (cmd[0] != '1') {
-               printf("%s\n", &cmd[5]);
+               scr_printf("%s\n", &cmd[5]);
        } else {
                while (serv_gets(cmd), strcmp(cmd, "000")) {
                        msg_arr[num_msgs++] = atol(cmd);
@@ -935,7 +939,7 @@ int entmsg(int is_reply,    /* nonzero if this was a <R>eply command */
        unlink(temp);
 
        if (fp == NULL) {
-               printf("*** Internal error while trying to save message!\n"
+               err_printf("*** Internal error while trying to save message!\n"
                        "    %s: %s\n",
                        temp, strerror(errno));
                return(errno);
@@ -946,7 +950,7 @@ int entmsg(int is_reply,    /* nonzero if this was a <R>eply command */
        serv_puts(cmd);
        serv_gets(cmd);
        if (cmd[0] != '4') {
-               printf("%s\n", &cmd[4]);
+               scr_printf("%s\n", &cmd[4]);
                return (1);
        }
 
@@ -960,7 +964,7 @@ int entmsg(int is_reply,    /* nonzero if this was a <R>eply command */
        serv_puts("MSGS NEW");
        serv_gets(cmd);
        if (cmd[0] != '1') {
-               printf("%s\n", &cmd[5]);
+               scr_printf("%s\n", &cmd[5]);
        } else {
                while (serv_gets(cmd), strcmp(cmd, "000")) {
                        msg_arr[num_msgs++] = atol(cmd);
@@ -986,11 +990,11 @@ int entmsg(int is_reply,  /* nonzero if this was a <R>eply command */
        }
 
        if (b == 1) {
-               printf("*** 1 additional message has been entered "
+               scr_printf("*** 1 additional message has been entered "
                        "in this room by another user.\n");
        }
        else if (b > 1) {
-               printf("*** %d additional messages have been entered "
+               scr_printf("*** %d additional messages have been entered "
                        "in this room by other users.\n", b);
        }
 
@@ -1016,12 +1020,12 @@ void process_quote(void)
        line = 0;
        fgets(buf, 128, qfile);
        while (fgets(buf, 128, qfile) != NULL) {
-               printf("%2d %s", ++line, buf);
+               scr_printf("%2d %s", ++line, buf);
        }
-       printf("Begin quoting at [ 1] : ");
+       scr_printf("Begin quoting at [ 1] : ");
        getline(buf, 3);
        qstart = (buf[0] == 0) ? (1) : atoi(buf);
-       printf("  End quoting at [%d] : ", line);
+       scr_printf("  End quoting at [%d] : ", line);
        getline(buf, 3);
        qend = (buf[0] == 0) ? (line) : atoi(buf);
        rewind(qfile);
@@ -1049,12 +1053,12 @@ void list_urls()
        char cmd[SIZ];
 
        if (num_urls == 0) {
-               printf("There were no URL's in the previous message.\n\n");
+               scr_printf("There were no URL's in the previous message.\n\n");
                return;
        }
 
        for (i = 0; i < num_urls; ++i) {
-               printf("%3d %s\n", i + 1, urls[i]);
+               scr_printf("%3d %s\n", i + 1, urls[i]);
        }
 
        if ((i = num_urls) != 1)
@@ -1062,7 +1066,7 @@ void list_urls()
 
        sprintf(cmd, rc_url_cmd, urls[i - 1]);
        system(cmd);
-       printf("\n");
+       scr_printf("\n");
 }
 
 /*
@@ -1111,7 +1115,7 @@ void readmsgs(
        serv_puts(cmd);
        serv_gets(cmd);
        if (cmd[0] != '1') {
-               printf("%s\n", &cmd[5]);
+               scr_printf("%s\n", &cmd[5]);
        } else {
                while (serv_gets(cmd), strcmp(cmd, "000")) {
                        if (num_msgs == MAXMSGS) {
@@ -1125,10 +1129,10 @@ void readmsgs(
 
        if (num_msgs == 0) {
                if (c == 3) return;
-               printf("*** There are no ");
-               if (c == 1) printf("new ");
-               if (c == 2) printf("old ");
-               printf("messages in this room.\n");
+               scr_printf("*** There are no ");
+               if (c == 1) scr_printf("new ");
+               if (c == 2) scr_printf("old ");
+               scr_printf("messages in this room.\n");
                return;
        }
 
@@ -1166,7 +1170,7 @@ RAGAIN:           pagin = ((arcflag == 0)
                if ((quotflag) || (arcflag)) {
                        screenwidth = hold_sw;
                }
-RMSGREAD:      fflush(stdout);
+RMSGREAD:      scr_flush();
                highest_msg_read = msg_arr[a];
                if (quotflag) {
                        freopen("/dev/tty", "r+", stdout);
@@ -1181,9 +1185,11 @@ RMSGREAD:        fflush(stdout);
                        f = fork();
                        if (f == 0) {
                                freopen(prtfile, "r", stdin);
+                               screen_reset();
                                sttybbs(SB_RESTORE);
                                ka_system(printcmd);
                                sttybbs(SB_NO_INTR);
+                               screen_set();
                                unlink(prtfile);
                                exit(0);
                        }
@@ -1191,7 +1197,7 @@ RMSGREAD: fflush(stdout);
                                do {
                                        g = wait(NULL);
                                } while ((g != f) && (g >= 0));
-                       printf("Message printed.\n");
+                       scr_printf("Message printed.\n");
                }
                if (rc_alt_semantics && c == 1) {
                        char buf[SIZ];
@@ -1208,11 +1214,11 @@ RMSGREAD:       fflush(stdout);
                        e = 'n';
                } else {
                        color(DIM_WHITE);
-                       printf("(");
+                       scr_printf("(");
                        color(BRIGHT_WHITE);
-                       printf("%d", num_msgs - a - 1);
+                       scr_printf("%d", num_msgs - a - 1);
                        color(DIM_WHITE);
-                       printf(") ");
+                       scr_printf(") ");
 
                        keyopt("<B>ack <A>gain <Q>uote <R>eply <N>ext <S>top m<Y> next ");
                        if (rc_url_cmd[0] && num_urls)
@@ -1252,97 +1258,95 @@ RMSGREAD:       fflush(stdout);
                                 && (e != 'u') && (e != 'c') && (e != 'y'));
                        switch (e) {
                        case 's':
-                               printf("Stop\r");
+                               scr_printf("Stop");
                                break;
                        case 'a':
-                               printf("Again\r");
+                               scr_printf("Again");
                                break;
                        case 'd':
-                               printf("Delete\r");
+                               scr_printf("Delete");
                                break;
                        case 'm':
-                               printf("Move\r");
+                               scr_printf("Move");
                                break;
                        case 'c':
-                               printf("Copy\r");
+                               scr_printf("Copy");
                                break;
                        case 'n':
-                               printf("Next\r");
+                               scr_printf("Next");
                                break;
                        case 'p':
-                               printf("Print\r");
+                               scr_printf("Print");
                                break;
                        case 'q':
-                               printf("Quote\r");
+                               scr_printf("Quote");
                                break;
                        case 'b':
-                               printf("Back\r");
+                               scr_printf("Back");
                                break;
                        case 'h':
-                               printf("Header\r");
+                               scr_printf("Header");
                                break;
                        case 'r':
-                               printf("Reply\r");
+                               scr_printf("Reply");
                                break;
                        case 'f':
-                               printf("File\r");
+                               scr_printf("File");
                                break;
                        case 'u':
-                               printf("URL's\r");
+                               scr_printf("URL's");
                                break;
                        case 'y':
-                               printf("mY next\r");
+                               scr_printf("mY next");
                                break;
                        case '?':
-                               printf("? <help>\r");
+                               scr_printf("? <help>");
                                break;
                        }
                        if (userflags & US_DISAPPEAR)
-                               printf("\r%79s\r", "");
+                               scr_printf("\r%79s\r", "");
                        else
-                               printf("\n");
-                       fflush(stdout);
+                               scr_printf("\n");
+                       scr_flush();
                }
                switch (e) {
                case '?':
-                       printf("Options available here:\n");
-                       printf(" ?  Help (prints this message)\n");
-                       printf(" S  Stop reading immediately\n");
-                       printf(" A  Again (repeats last message)\n");
-                       printf(" N  Next (continue with next message)\n");
-                       printf(" Y  My Next (continue with next message you authored)\n");
-                       printf(" B  Back (go back to previous message)\n");
+                       scr_printf("Options available here:\n"
+                               " ?  Help (prints this message)\n"
+                               " S  Stop reading immediately\n"
+                               " A  Again (repeats last message)\n"
+                               " N  Next (continue with next message)\n"
+                               " Y  My Next (continue with next message you authored)\n"
+                               " B  Back (go back to previous message)\n");
                        if ((is_room_aide)
                            || (room_flags & QR_MAILBOX)) {
-                               printf(" D  Delete this message\n");
-                               printf
-                                   (" M  Move message to another room\n");
+                               scr_printf(" D  Delete this message\n"
+                                       " M  Move message to another room\n");
                        }
-                       printf(" C  Copy message to another room\n");
+                       scr_printf(" C  Copy message to another room\n");
                        if (strlen(printcmd) > 0)
-                               printf(" P  Print this message\n");
-                       printf
-                           (" Q  Quote portions of this message for your next post\n");
-                       printf
-                           (" H  Headers (display message headers only)\n");
+                               scr_printf(" P  Print this message\n");
+                       scr_printf(
+                               " Q  Quote portions of this message for your next post\n"
+                               " H  Headers (display message headers only)\n");
                        if (is_mail)
-                               printf(" R  Reply to this message\n");
+                               scr_printf(" R  Reply to this message\n");
                        if (rc_allow_attachments)
-                               printf
+                               scr_printf
                                    (" F  (save attachments to a file)\n");
                        if (strlen(rc_url_cmd) > 0)
-                               printf(" U  (list URL's for display)\n");
-                       printf("\n");
+                               scr_printf(" U  (list URL's for display)\n");
+                       scr_printf("\n");
                        goto RMSGREAD;
                case 'p':
-                       fflush(stdout);
+                       scr_flush();
                        freopen(prtfile, "w", stdout);
                        arcflag = 1;
                        hold_color = enable_color;
                        enable_color = 0;
                        goto RAGAIN;
                case 'q':
-                       fflush(stdout);
+                       scr_flush();
                        freopen(temp2, "w", stdout);
                        quotflag = 1;
                        hold_color = enable_color;
@@ -1365,7 +1369,7 @@ RMSGREAD: fflush(stdout);
                                        (e == 'c' ? 1 : 0));
                                serv_puts(cmd);
                                serv_gets(cmd);
-                               printf("%s\n", &cmd[4]);
+                               scr_printf("%s\n", &cmd[4]);
                                if (cmd[0] == '2')
                                        msg_arr[a] = 0L;
                        } else {
@@ -1387,16 +1391,16 @@ RMSGREAD:       fflush(stdout);
                                                       extract_int(&cmd[4],
                                                                   0));
                        } else {
-                               printf("%s\n", &cmd[4]);
+                               scr_printf("%s\n", &cmd[4]);
                        }
                        goto RMSGREAD;
                case 'd':
-                       printf("*** Delete this message? ");
+                       scr_printf("*** Delete this message? ");
                        if (yesno() == 1) {
                                sprintf(cmd, "DELE %ld", msg_arr[a]);
                                serv_puts(cmd);
                                serv_gets(cmd);
-                               printf("%s\n", &cmd[4]);
+                               scr_printf("%s\n", &cmd[4]);
                                if (cmd[0] == '2')
                                        msg_arr[a] = 0L;
                        } else {
@@ -1478,7 +1482,7 @@ void check_message_base(void)
 {
        char buf[SIZ];
 
-       printf
+       scr_printf
            ("Please read the documentation before running this command.\n"
            "Having done so, do you still want to check the message base? ");
        if (yesno() == 0)
@@ -1487,11 +1491,11 @@ void check_message_base(void)
        serv_puts("FSCK");
        serv_gets(buf);
        if (buf[0] != '1') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
 
        while (serv_gets(buf), strcmp(buf, "000")) {
-               printf("%s\n", buf);
+               scr_printf("%s\n", buf);
        }
 }
index 78d75041da9c11fdf3fe9810333165b54672941a..55bc1c5ed802c7b76d1f65fc6746edc550e21bf6 100644 (file)
@@ -27,6 +27,7 @@
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
+#include "screen.h"
 
 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
 
@@ -355,10 +356,10 @@ int select_floor(int rfloor)
                                        newfloor = a;
                        }
                        if (newfloor < 0) {
-                               printf("\n One of:\n");
+                               scr_printf("\n One of:\n");
                                for (a = 0; a < 128; ++a) {
                                        if (floorlist[a][0] != 0) {
-                                               printf("%s\n",
+                                               scr_printf("%s\n",
                                                       &floorlist[a][0]);
                                        }
                                }
@@ -393,7 +394,7 @@ void editthisroom(void)
        serv_puts("GETR");
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
 
@@ -503,7 +504,7 @@ void editthisroom(void)
                        serv_puts(buf);
                        serv_gets(buf);
                        if (buf[0] != '2')
-                               printf("%s\n", &buf[4]);
+                               scr_printf("%s\n", &buf[4]);
                }
        } while (buf[0] != '2');
 
@@ -517,11 +518,11 @@ void editthisroom(void)
                sprintf(buf, "%d", expire_mode);
                strprompt("Message expire policy (? for list)", buf, 1);
                if (buf[0] == '?') {
-                       printf("\n");
-                       printf("0. Use the default for this floor\n");
-                       printf("1. Never automatically expire messages\n");
-                       printf("2. Expire by message count\n");
-                       printf("3. Expire by message age\n");
+                       scr_printf("\n"
+                               "0. Use the default for this floor\n"
+                               "1. Never automatically expire messages\n"
+                               "2. Expire by message count\n"
+                               "3. Expire by message age\n");
                }
        } while ((buf[0] < 48) || (buf[0] > 51));
        expire_mode = buf[0] - 48;
@@ -540,14 +541,14 @@ void editthisroom(void)
        }
 
        /* Give 'em a chance to change their minds */
-       printf("Save changes (y/n)? ");
+       scr_printf("Save changes (y/n)? ");
 
        if (yesno() == 1) {
                snprintf(buf, sizeof buf, "SETA %s", raide);
                serv_puts(buf);
                serv_gets(buf);
                if (buf[0] != '2') {
-                       printf("%s\n", &buf[4]);
+                       scr_printf("%s\n", &buf[4]);
                }
 
                snprintf(buf, sizeof buf, "SPEX room|%d|%d",
@@ -560,7 +561,7 @@ void editthisroom(void)
                         rorder);
                serv_puts(buf);
                serv_gets(buf);
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                if (buf[0] == '2')
                        dotgoto(rname, 2);
        }
@@ -580,14 +581,14 @@ void ungoto(void)
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
        sprintf(buf, "SLRP %ld", uglsn);
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
        }
        safestrncpy(buf, ugname, sizeof buf);
        strcpy(ugname, "");
@@ -616,8 +617,8 @@ void download_to_local_disk(char *supplied_filename, long total_bytes)
                newprompt("Filename: ", filename, 250);
        }
 
-       printf("Enter the name of the directory to save '%s'\n", filename);
-       printf("to, or press return for the current directory.\n");
+       scr_printf("Enter the name of the directory to save '%s'\n"
+               "to, or press return for the current directory.\n", filename);
        newprompt("Directory: ", dbuf, sizeof dbuf);
        if (strlen(dbuf) == 0)
                strcpy(dbuf, ".");
@@ -626,12 +627,12 @@ void download_to_local_disk(char *supplied_filename, long total_bytes)
 
        savefp = fopen(dbuf, "w");
        if (savefp == NULL) {
-               printf("Cannot open '%s': %s\n", dbuf, strerror(errno));
+               scr_printf("Cannot open '%s': %s\n", dbuf, strerror(errno));
                /* close the download file at the server */
                serv_puts("CLOS");
                serv_gets(buf);
                if (buf[0] != '2') {
-                       printf("%s\n", &buf[4]);
+                       scr_printf("%s\n", &buf[4]);
                }
                return;
        }
@@ -643,7 +644,7 @@ void download_to_local_disk(char *supplied_filename, long total_bytes)
                serv_puts(buf);
                serv_gets(buf);
                if (buf[0] != '6') {
-                       printf("%s\n", &buf[4]);
+                       scr_printf("%s\n", &buf[4]);
                        return;
                }
                packet = extract_int(&buf[4], 0);
@@ -658,7 +659,7 @@ void download_to_local_disk(char *supplied_filename, long total_bytes)
        serv_puts("CLOS");
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
        }
        return;
 }
@@ -684,7 +685,7 @@ void download(int proto)
        int broken = 0;
 
        if ((room_flags & QR_DOWNLOAD) == 0) {
-               printf("*** You cannot download from this room.\n");
+               scr_printf("*** You cannot download from this room.\n");
                return;
        }
 
@@ -694,7 +695,7 @@ void download(int proto)
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
        total_bytes = extract_long(&buf[4], 0);
@@ -706,7 +707,7 @@ void download(int proto)
        }
 
        /* Meta-download for public clients */
-       printf("Fetching file from Citadel server...\n");
+       scr_printf("Fetching file from Citadel server...\n");
        mkdir(tempdir, 0700);
        snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
        tpipe = fopen(tempname, "wb");
@@ -718,7 +719,7 @@ void download(int proto)
                serv_puts(buf);
                serv_gets(buf);
                if (buf[0] != '6') {
-                       printf("%s\n", &buf[4]);
+                       scr_printf("%s\n", &buf[4]);
                }
                packet = extract_int(&buf[4], 0);
                serv_read(dbuf, packet);
@@ -734,7 +735,7 @@ void download(int proto)
        serv_puts("CLOS");
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
        }
 
        if (proto == 0) {
@@ -751,13 +752,15 @@ void download(int proto)
        else
                sprintf(transmit_cmd, "exec cat %s", tempname);
 
+       screen_reset();
        sttybbs(SB_RESTORE);
        system(transmit_cmd);
        sttybbs(SB_NO_INTR);
+       screen_set();
 
        /* clean up the temporary directory */
        nukedir(tempdir);
-       putc(7, stdout);
+       scr_putc(7);
 }
 
 
@@ -810,7 +813,7 @@ void invite(void)
 
        /*
         * if ((room_flags & QR_PRIVATE)==0) {
-        *         printf("This is not a private room.\n");
+        *         scr_printf("This is not a private room.\n");
         *         return;
         * }
         */
@@ -822,7 +825,7 @@ void invite(void)
        snprintf(bbb, sizeof bbb, "INVT %s", aaa);
        serv_puts(bbb);
        serv_gets(bbb);
-       printf("%s\n", &bbb[4]);
+       scr_printf("%s\n", &bbb[4]);
 }
 
 
@@ -841,7 +844,7 @@ void kickout(void)
        snprintf(cmd, sizeof cmd, "KICK %s", username);
        serv_puts(cmd);
        serv_gets(cmd);
-       printf("%s\n", &cmd[4]);
+       scr_printf("%s\n", &cmd[4]);
 }
 
 
@@ -855,17 +858,17 @@ void killroom(void)
        serv_puts("KILL 0");
        serv_gets(aaa);
        if (aaa[0] != '2') {
-               printf("%s\n", &aaa[4]);
+               scr_printf("%s\n", &aaa[4]);
                return;
        }
 
-       printf("Are you sure you want to kill this room? ");
+       scr_printf("Are you sure you want to kill this room? ");
        if (yesno() == 0)
                return;
 
        serv_puts("KILL 1");
        serv_gets(aaa);
-       printf("%s\n", &aaa[4]);
+       scr_printf("%s\n", &aaa[4]);
        if (aaa[0] != '2')
                return;
        dotgoto("_BASEROOM_", 0);
@@ -875,14 +878,14 @@ void forget(void)
 {                              /* forget the current room */
        char cmd[SIZ];
 
-       printf("Are you sure you want to forget this room? ");
+       scr_printf("Are you sure you want to forget this room? ");
        if (yesno() == 0)
                return;
 
        serv_puts("FORG");
        serv_gets(cmd);
        if (cmd[0] != '2') {
-               printf("%s\n", &cmd[4]);
+               scr_printf("%s\n", &cmd[4]);
                return;
        }
 
@@ -907,7 +910,7 @@ void entroom(void)
        serv_gets(cmd);
 
        if (cmd[0] != '2') {
-               printf("%s\n", &cmd[4]);
+               scr_printf("%s\n", &cmd[4]);
                return;
        }
 
@@ -925,20 +928,20 @@ void entroom(void)
 
        IFNEXPERT formout("roomaccess");
        do {
-               printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
+               scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
                       "<3>Passworded room\n<4>Invitation-only room\n"
-                      "<5>Personal room\n");
-               printf("Enter room type: ");
+                      "<5>Personal room\n"
+                       "Enter room type: ");
                do {
                        b = inkey();
                } while (((b < '1') || (b > '5')) && (b != '?'));
                if (b == '?') {
-                       printf("?\n");
+                       scr_printf("?\n");
                        formout("roomaccess");
                }
        } while ((b < '1') || (b > '5'));
        b = b - 48;
-       printf("%d\n", b);
+       scr_printf("%d\n", b);
        new_room_type = b - 1;
        if (new_room_type == 2) {
                newprompt("Enter a room password: ", new_room_pass, 9);
@@ -949,18 +952,18 @@ void entroom(void)
                strcpy(new_room_pass, "");
        }
 
-       printf("\042%s\042, a", new_room_name);
+       scr_printf("\042%s\042, a", new_room_name);
        if (b == 1)
-               printf(" public room.");
+               scr_printf(" public room.");
        if (b == 2)
-               printf(" guess-name room.");
+               scr_printf(" guess-name room.");
        if (b == 3)
-               printf(" passworded room, password: %s", new_room_pass);
+               scr_printf(" passworded room, password: %s", new_room_pass);
        if (b == 4)
-               printf("n invitation-only room.");
+               scr_printf("n invitation-only room.");
        if (b == 5)
-               printf(" personal room.");
-       printf("\nInstall it? (y/n) : ");
+               scr_printf(" personal room.");
+       scr_printf("\nInstall it? (y/n) : ");
        if (yesno() == 0) {
                return;
        }
@@ -970,7 +973,7 @@ void entroom(void)
        serv_puts(cmd);
        serv_gets(cmd);
        if (cmd[0] != '2') {
-               printf("%s\n", &cmd[4]);
+               scr_printf("%s\n", &cmd[4]);
                return;
        }
 
@@ -1024,7 +1027,7 @@ void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
 
 
        if (strlen(editor_path) == 0) {
-               printf("Do you wish to re-enter %s? ", desc);
+               scr_printf("Do you wish to re-enter %s? ", desc);
                if (yesno() == 0)
                        return;
        }
@@ -1035,7 +1038,7 @@ void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
        serv_puts(check_cmd);
        serv_gets(cmd);
        if (cmd[0] != '2') {
-               printf("%s\n", &cmd[4]);
+               scr_printf("%s\n", &cmd[4]);
                return;
        }
 
@@ -1058,6 +1061,7 @@ void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
                editor_pid = fork();
                if (editor_pid == 0) {
                        chmod(temp, 0600);
+                       screen_reset();
                        sttybbs(SB_RESTORE);
                        execlp(editor_path, editor_path, temp, NULL);
                        exit(1);
@@ -1068,25 +1072,26 @@ void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
                                b = wait(&editor_exit);
                        } while ((b != editor_pid) && (b >= 0));
                editor_pid = (-1);
-               printf("Executed %s\n", editor_path);
+               scr_printf("Executed %s\n", editor_path);
                sttybbs(0);
+               screen_set();
        } else {
-               printf("Entering %s.  ", desc);
-               printf("Press return twice when finished.\n");
+               scr_printf("Entering %s.  "
+                       "Press return twice when finished.\n", desc);
                fp = fopen(temp, "r+");
                citedit(fp);
                fclose(fp);
        }
 
        if (file_checksum(temp) == cksum) {
-               printf("*** Aborted.\n");
+               scr_printf("*** Aborted.\n");
        }
 
        else {
                serv_puts(write_cmd);
                serv_gets(cmd);
                if (cmd[0] != '4') {
-                       printf("%s\n", &cmd[4]);
+                       scr_printf("%s\n", &cmd[4]);
                        return;
                }
 
@@ -1128,7 +1133,7 @@ void create_floor(void)
        serv_puts("CFLR xx|0");
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
 
@@ -1137,9 +1142,9 @@ void create_floor(void)
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0] == '2') {
-               printf("Floor has been created.\n");
+               scr_printf("Floor has been created.\n");
        } else {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
        }
 
        load_floorlist();
@@ -1176,11 +1181,11 @@ void edit_floor(void)
                    ("Floor default essage expire policy (? for list)",
                     buf, 1);
                if (buf[0] == '?') {
-                       printf("\n");
-                       printf("0. Use the system default\n");
-                       printf("1. Never automatically expire messages\n");
-                       printf("2. Expire by message count\n");
-                       printf("3. Expire by message age\n");
+                       scr_printf("\n"
+                               "0. Use the system default\n"
+                               "1. Never automatically expire messages\n"
+                               "2. Expire by message count\n"
+                               "3. Expire by message age\n");
                }
        } while ((buf[0] < 48) || (buf[0] > 51));
        expire_mode = buf[0] - 48;
@@ -1208,7 +1213,7 @@ void edit_floor(void)
                 &floorlist[(int) curr_floor][0]);
        serv_puts(buf);
        serv_gets(buf);
-       printf("%s\n", &buf[4]);
+       scr_printf("%s\n", &buf[4]);
        load_floorlist();
 }
 
@@ -1226,7 +1231,7 @@ void kill_floor(void)
        load_floorlist();
        do {
                floornum_to_delete = (-1);
-               printf("(Press return to abort)\n");
+               scr_printf("(Press return to abort)\n");
                newprompt("Delete which floor? ", buf, 255);
                if (strlen(buf) == 0)
                        return;
@@ -1234,15 +1239,15 @@ void kill_floor(void)
                        if (!strcasecmp(&floorlist[a][0], buf))
                                floornum_to_delete = a;
                if (floornum_to_delete < 0) {
-                       printf("No such floor.  Select one of:\n");
+                       scr_printf("No such floor.  Select one of:\n");
                        for (a = 0; a < 128; ++a)
                                if (floorlist[a][0] != 0)
-                                       printf("%s\n", &floorlist[a][0]);
+                                       scr_printf("%s\n", &floorlist[a][0]);
                }
        } while (floornum_to_delete < 0);
        sprintf(buf, "KFLR %d|1", floornum_to_delete);
        serv_puts(buf);
        serv_gets(buf);
-       printf("%s\n", &buf[4]);
+       scr_printf("%s\n", &buf[4]);
        load_floorlist();
 }
index 65383d9e5d292e802aa444339cbe589d1d0b0a19..3a3d901b8640e2d2b5401ac74d9e0c26a9e0fefd 100644 (file)
 #  include <time.h>
 # endif
 #endif
-
+#ifdef HAVE_LIMITS_H
 #include <limits.h>
+#endif
 #ifdef HAVE_UTMP_H
 #include <utmp.h>
 #endif
 #ifdef HAVE_UTMPX_H
 #include <utmpx.h>
 #endif
+#include "screen.h"
 
 #ifndef HAVE_GETUTLINE
 struct utmp *getutline(struct utmp *ut);
@@ -73,7 +75,7 @@ void back(int spaces) /* Destructive backspace */
             {
        int a;
        for (a=1; a<=spaces; ++a) {
-               putc(8,stdout); putc(32,stdout); putc(8,stdout);
+               scr_putc(8); scr_putc(32); scr_putc(8);
                }
        }
 
@@ -82,13 +84,13 @@ void hit_any_key(void) {            /* hit any key to continue */
 
        color(COLOR_PUSH);
        color(DIM_RED);
-       printf("%s\r",serv_info.serv_moreprompt);
+       scr_printf("%s\r",serv_info.serv_moreprompt);
        color(COLOR_POP);
        sttybbs(0);
        b=inkey();
        for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
-               putc(' ',stdout);
-       putc(13,stdout);
+               scr_putc(' ');
+       scr_putc(13);
        sttybbs(1);
        if (b == 'q' || b == 'Q' || b == 's' || b == 'S')
                b = STOP_KEY;
@@ -119,7 +121,7 @@ void edituser(void)
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0]!='2') {
-               printf("%s\n",&buf[4]);
+               scr_printf("%s\n",&buf[4]);
                return;
                }
        extract(who, &buf[4], 0);
@@ -149,7 +151,7 @@ void edituser(void)
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0]!='2') {
-               printf("%s\n",&buf[4]);
+               scr_printf("%s\n",&buf[4]);
                }
        }
 
@@ -161,13 +163,13 @@ int set_attr(int sval, char *prompt, unsigned int sbit)
 
        temp = sval;
        color(DIM_WHITE);
-       printf("%45s ", prompt);
+       scr_printf("%45s ", prompt);
        color(DIM_MAGENTA);
-       printf("[");
+       scr_printf("[");
        color(BRIGHT_MAGENTA);
-       printf("%3s", ((temp&sbit) ? "Yes":"No"));
+       scr_printf("%3s", ((temp&sbit) ? "Yes":"No"));
        color(DIM_MAGENTA);
-       printf("]? ");
+       scr_printf("]? ");
        color(BRIGHT_CYAN);
        a=yesno_d(temp&sbit);
        color(DIM_WHITE);
@@ -189,7 +191,7 @@ void enter_config(int mode)
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0]!='2') {
-               printf("%s\n",&buf[4]);
+               scr_printf("%s\n",&buf[4]);
                return;
                }
 
@@ -232,29 +234,29 @@ void enter_config(int mode)
        if (mode==2) {
         if (flags & US_EXPERT) {
                flags = (flags ^ US_EXPERT);
-               printf("Expert mode now OFF\n");
+               scr_printf("Expert mode now OFF\n");
                }
         else {
                flags = (flags | US_EXPERT);
-               printf("Expert mode now ON\n");
+               scr_printf("Expert mode now ON\n");
                }
         }
 
        if (mode==3) {
         if (flags & US_FLOORS) {
                flags = (flags ^ US_FLOORS);
-               printf("Floor mode now OFF\n");
+               scr_printf("Floor mode now OFF\n");
                }
         else {
                flags = (flags | US_FLOORS);
-               printf("Floor mode now ON\n");
+               scr_printf("Floor mode now ON\n");
                }
         }
 
        sprintf(buf,"SETU %d|%d|%d|%d",width,height,flags,filter);
        serv_puts(buf);
        serv_gets(buf);
-       if (buf[0]!='2') printf("%s\n",&buf[4]);
+       if (buf[0]!='2') scr_printf("%s\n",&buf[4]);
        userflags = flags;
 }
 
@@ -295,8 +297,8 @@ int pattern(char *search, char *patn)       /* Searches for patn in search string */
 
 void interr(int errnum)        /* display internal error as defined in errmsgs */
             {
-       printf("*** INTERNAL ERROR %d\n",errnum);
-       printf("(Press any key to continue)\n");
+       scr_printf("*** INTERNAL ERROR %d\n"
+               "(Press any key to continue)\n", errnum);
        inkey();
        logoff(errnum);
 }
@@ -346,7 +348,7 @@ void strproc(char *string)
  */
 char *strerror(int e)
 {
-       static char buf[32];
+       static char buf[128];
 
        sprintf(buf,"errno = %d",e);
        return(buf);
@@ -360,21 +362,21 @@ void progress(long int curr, long int cmax)
        long a;
 
        if (curr==0) {
-               printf(".......................................");
-               printf(".......................................\r");
-               fflush(stdout);
+               scr_printf(".......................................");
+               scr_printf(".......................................\r");
+               scr_flush();
                dots_printed = 0;
                }
        else if (curr==cmax) {
-               printf("\r%79s\n","");
+               scr_printf("\r%79s\n","");
                }
        else {
                a=(curr * 100) / cmax;
                a=a*78; a=a/100;
                while (dots_printed < a) {
-                       printf("*");
+                       scr_printf("*");
                        ++dots_printed;
-                       fflush(stdout);
+                       scr_flush();
                        }
                }
        }
@@ -469,11 +471,11 @@ void misc_server_cmd(char *cmd) {
 
        serv_puts(cmd);
        serv_gets(buf);
-       printf("%s\n",buf);
+       scr_printf("%s\n",buf);
        if (buf[0]=='1') {
                set_keepalives(KA_NO);
                while (serv_gets(buf), strcmp(buf,"000")) {
-                       printf("%s\n",buf);
+                       scr_printf("%s\n",buf);
                        }
                set_keepalives(KA_YES);
                return;
index 77b03c7150d0c6ed6530f86064f6ffab3f1de1ca..01d591d4e4c368c89dc23a6410ebc076fc30fdee 100644 (file)
@@ -42,6 +42,7 @@
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
+#include "screen.h"
 
 void interr(int errnum);
 void strprompt(char *prompt, char *str, int len);
@@ -67,7 +68,7 @@ int eopen(char *name, int mode)
        int ret;
        ret = open(name, mode);
        if (ret < 0) {
-               fprintf(stderr, "Cannot open file '%s', mode=%d, errno=%d\n",
+               err_printf("Cannot open file '%s', mode=%d, errno=%d\n",
                        name, mode, errno);
                interr(errno);
        }
@@ -148,7 +149,7 @@ void entregis(void)
        serv_puts("REGI");
        serv_gets(buf);
        if (buf[0] != '4') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
        serv_puts(tmpname);
@@ -160,7 +161,7 @@ void entregis(void)
        serv_puts(tmpemail);
        serv_puts(tmpcountry);
        serv_puts("000");
-       printf("\n");
+       scr_printf("\n");
 }
 
 void updatels(void)
@@ -169,7 +170,7 @@ void updatels(void)
 
        if (rc_alt_semantics) {
                if (maxmsgnum == highest_msg_read == 0) {
-                       /* fprintf(stderr, "maxmsgnum == highest_msg_read == 0\n"); */
+                       /* err_printf("maxmsgnum == highest_msg_read == 0\n"); */
                        return;
                }
                snprintf(buf, sizeof(buf), "SLRP %ld",
@@ -181,7 +182,7 @@ void updatels(void)
        }
        serv_gets(buf);
        if (buf[0] != '2')
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
 }
 
 /*
@@ -195,7 +196,7 @@ void updatelsa(void)
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0] != '2')
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
 }
 
 
@@ -226,7 +227,7 @@ void do_upload(int fd)
                                bytes_expected = atoi(&buf[4]);
                                serv_write(tbuf, bytes_expected);
                        } else {
-                               printf("%s\n", &buf[4]);
+                               scr_printf("%s\n", &buf[4]);
                        }
                }
                transmitted_bytes = transmitted_bytes + (long) bytes_to_send;
@@ -237,7 +238,7 @@ void do_upload(int fd)
        close(fd);
        serv_puts("UCLS 1");
        serv_gets(buf);
-       printf("%s\n", &buf[4]);
+       scr_printf("%s\n", &buf[4]);
 }
 
 
@@ -254,16 +255,16 @@ void cli_upload(void)
        int fd;
 
        if ((room_flags & QR_UPLOAD) == 0) {
-               printf("*** You cannot upload to this room.\n");
+               scr_printf("*** You cannot upload to this room.\n");
                return;
        }
        newprompt("File to be uploaded: ", flnm, 55);
        fd = open(flnm, O_RDONLY);
        if (fd < 0) {
-               printf("Cannot open '%s': %s\n", flnm, strerror(errno));
+               scr_printf("Cannot open '%s': %s\n", flnm, strerror(errno));
                return;
        }
-       printf("Enter a description of this file:\n");
+       scr_printf("Enter a description of this file:\n");
        newprompt(": ", desc, 75);
 
        /* keep generating filenames in hope of finding a unique one */
@@ -280,7 +281,7 @@ void cli_upload(void)
                serv_puts(tbuf);
                serv_gets(buf);
                if (buf[0] != '2')
-                       printf("%s\n", &buf[4]);
+                       scr_printf("%s\n", &buf[4]);
                ++a;
        } while (buf[0] != '2');
 
@@ -302,20 +303,20 @@ void cli_image_upload(char *keyname)
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
        newprompt("Image file to be uploaded: ", flnm, 55);
        fd = open(flnm, O_RDONLY);
        if (fd < 0) {
-               printf("Cannot open '%s': %s\n", flnm, strerror(errno));
+               scr_printf("Cannot open '%s': %s\n", flnm, strerror(errno));
                return;
        }
        sprintf(buf, "UIMG 1|%s", keyname);
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
        do_upload(fd);
@@ -337,7 +338,7 @@ void upload(int c)
        int fd;
 
        if ((room_flags & QR_UPLOAD) == 0) {
-               printf("*** You cannot upload to this room.\n");
+               scr_printf("*** You cannot upload to this room.\n");
                return;
        }
        /* we don't need a filename when receiving batch y/z modem */
@@ -356,7 +357,7 @@ void upload(int c)
 
        /* create a temporary directory... */
        if (mkdir(tempdir, 0700) != 0) {
-               printf("*** Could not create temporary directory %s: %s\n",
+               scr_printf("*** Could not create temporary directory %s: %s\n",
                       tempdir, strerror(errno));
                return;
        }
@@ -367,30 +368,32 @@ void upload(int c)
                switch (c) {
                case 0:
                        sttybbs(0);
-                       printf("Receiving %s - press Ctrl-D to end.\n", flnm);
+                       scr_printf("Receiving %s - press Ctrl-D to end.\n", flnm);
                        fp = fopen(flnm, "w");
                        do {
                                b = inkey();
                                if (b == 13) {
                                        b = 10;
-                                       printf("\r");
                                }
                                if (b != 4) {
-                                       printf("%c", b);
+                                       scr_printf("%c", b);
                                        putc(b, fp);
                                }
                        } while (b != 4);
                        fclose(fp);
                        exit(0);
                case 1:
+                       screen_reset();
                        sttybbs(3);
                        execlp("rx", "rx", flnm, NULL);
                        exit(1);
                case 2:
+                       screen_reset();
                        sttybbs(3);
                        execlp("rb", "rb", NULL);
                        exit(1);
                case 3:
+                       screen_reset();
                        sttybbs(3);
                        execlp("rz", "rz", NULL);
                        exit(1);
@@ -400,13 +403,14 @@ void upload(int c)
                        b = ka_wait(&a);
                } while ((b != xfer_pid) && (b != (-1)));
        sttybbs(0);
+       screen_set();
 
        if (a != 0) {
-               printf("\r*** Transfer unsuccessful.\n");
+               scr_printf("\r*** Transfer unsuccessful.\n");
                nukedir(tempdir);
                return;
        }
-       printf("\r*** Transfer successful.  Sending file(s) to server...\n");
+       scr_printf("\r*** Transfer successful.  Sending file(s) to server...\n");
        sprintf(buf, "cd %s; ls", tempdir);
        lsfp = popen(buf, "r");
        if (lsfp != NULL) {
@@ -439,7 +443,7 @@ void upload(int c)
                                close(fd);
                                serv_puts("UCLS 1");
                                serv_gets(buf);
-                               printf("%s\n", &buf[4]);
+                               scr_printf("%s\n", &buf[4]);
                        }
                }
                pclose(lsfp);
@@ -466,31 +470,31 @@ void val_user(char *user, int do_validate)
                        serv_gets(buf);
                        ++a;
                        if (a == 1)
-                               printf("User #%s - %s  ", buf, &cmd[4]);
+                               scr_printf("User #%s - %s  ", buf, &cmd[4]);
                        if (a == 2)
-                               printf("PW: %s\n", buf);
+                               scr_printf("PW: %s\n", buf);
                        if (a == 3)
-                               printf("%s\n", buf);
+                               scr_printf("%s\n", buf);
                        if (a == 4)
-                               printf("%s\n", buf);
+                               scr_printf("%s\n", buf);
                        if (a == 5)
-                               printf("%s, ", buf);
+                               scr_printf("%s, ", buf);
                        if (a == 6)
-                               printf("%s ", buf);
+                               scr_printf("%s ", buf);
                        if (a == 7)
-                               printf("%s\n", buf);
+                               scr_printf("%s\n", buf);
                        if (a == 8)
-                               printf("%s\n", buf);
+                               scr_printf("%s\n", buf);
                        if (a == 9)
                                ax = atoi(buf);
                        if (a == 10)
-                               printf("%s\n", buf);
+                               scr_printf("%s\n", buf);
                        if (a == 11)
-                               printf("%s\n", buf);
+                               scr_printf("%s\n", buf);
                } while (strcmp(buf, "000"));
-               printf("Current access level: %d (%s)\n", ax, axdefs[ax]);
+               scr_printf("Current access level: %d (%s)\n", ax, axdefs[ax]);
        } else {
-               printf("%-30s\n%s\n", user, &cmd[4]);
+               scr_printf("%-30s\n%s\n", user, &cmd[4]);
        }
 
        if (do_validate) {
@@ -500,9 +504,9 @@ void val_user(char *user, int do_validate)
                serv_puts(cmd);
                serv_gets(cmd);
                if (cmd[0] != '2')
-                       printf("%s\n", &cmd[4]);
+                       scr_printf("%s\n", &cmd[4]);
        }
-       printf("\n");
+       scr_printf("\n");
 }
 
 
@@ -518,7 +522,7 @@ void validate(void)
                if (cmd[0] != '3')
                        finished = 1;
                if (cmd[0] == '2')
-                       printf("%s\n", &cmd[4]);
+                       scr_printf("%s\n", &cmd[4]);
                if (cmd[0] == '3') {
                        extract(buf, cmd, 0);
                        val_user(&buf[4], 1);
@@ -531,17 +535,19 @@ void subshell(void)
        int a, b;
        a = fork();
        if (a == 0) {
+               screen_reset();
                sttybbs(SB_RESTORE);
                signal(SIGINT, SIG_DFL);
                signal(SIGQUIT, SIG_DFL);
                execlp(getenv("SHELL"), getenv("SHELL"), NULL);
-               printf("Could not open a shell: %s\n", strerror(errno));
+               err_printf("Could not open a shell: %s\n", strerror(errno));
                exit(errno);
        }
        do {
                b = ka_wait(NULL);
        } while ((a != b) && (a != (-1)));
        sttybbs(0);
+       screen_set();
 }
 
 /*
@@ -558,7 +564,7 @@ void deletefile(void)
        sprintf(cmd, "DELF %s", filename);
        serv_puts(cmd);
        serv_gets(cmd);
-       printf("%s\n", &cmd[4]);
+       err_printf("%s\n", &cmd[4]);
 }
 
 /*
@@ -575,7 +581,7 @@ void netsendfile(void)
        sprintf(cmd, "NETF %s|%s", filename, destsys);
        serv_puts(cmd);
        serv_gets(cmd);
-       printf("%s\n", &cmd[4]);
+       err_printf("%s\n", &cmd[4]);
        return;
 }
 
@@ -596,7 +602,7 @@ void movefile(void)
        sprintf(cmd, "MOVF %s|%s", filename, newroom);
        serv_puts(cmd);
        serv_gets(cmd);
-       printf("%s\n", &cmd[4]);
+       err_printf("%s\n", &cmd[4]);
 }
 
 
@@ -766,10 +772,10 @@ void do_system_configuration(void)
                strprompt("System default message expire policy (? for list)",
                          buf, 1);
                if (buf[0] == '?') {
-                       printf("\n");
-                       printf("1. Never automatically expire messages\n");
-                       printf("2. Expire by message count\n");
-                       printf("3. Expire by message age\n");
+                       scr_printf("\n"
+                               "1. Never automatically expire messages\n"
+                               "2. Expire by message count\n"
+                               "3. Expire by message age\n");
                }
        } while ((buf[0] < 49) || (buf[0] > 51));
        expire_mode = buf[0] - 48;
@@ -786,7 +792,7 @@ void do_system_configuration(void)
                expire_value = atol(buf);
        }
        /* Save it */
-       printf("Save this configuration? ");
+       scr_printf("Save this configuration? ");
        if (yesno()) {
                serv_puts("CONF set");
                serv_gets(buf);
@@ -852,24 +858,20 @@ void do_internet_configuration(void) {
        }
 
        do {
-               printf("\n");
+               scr_printf("\n");
                color(BRIGHT_WHITE);
-               printf("### ");
-               printf("                   Host or domain                  ");
-               printf("   Record type      \n");
+               scr_printf("###                    Host or domain                     Record type      \n");
                color(DIM_WHITE);
-               printf("--- ");
-               printf("-------------------------------------------------- ");
-               printf("--------------------\n");
+               scr_printf("--- -------------------------------------------------- --------------------\n");
                for (i=0; i<num_recs; ++i) {
                color(DIM_WHITE);
-               printf("%3d ", i+1);
+               scr_printf("%3d ", i+1);
                extract(buf, recs[i], 0);
                color(BRIGHT_CYAN);
-               printf("%-50s ", buf);
+               scr_printf("%-50s ", buf);
                extract(buf, recs[i], 1);
                color(BRIGHT_MAGENTA);
-               printf("%-20s\n", buf);
+               scr_printf("%-20s\n", buf);
                color(DIM_WHITE);
                }
 
@@ -907,7 +909,7 @@ void do_internet_configuration(void) {
                                        serv_puts("000");
                                }
                                else {
-                                       printf("%s\n", &buf[4]);
+                                       scr_printf("%s\n", &buf[4]);
                                }
                                quitting = 1;
                                break;
@@ -945,8 +947,8 @@ void network_config_management(char *entrytype, char *comment) {
        FILE *changefp;
 
        if (strlen(editor_path) == 0) {
-               printf("You must have an external editor configured in order"
-                       " to use this function.\n");
+               scr_printf("You must have an external editor configured in"
+                       " order to use this function.\n");
                return;
        }
 
@@ -955,7 +957,7 @@ void network_config_management(char *entrytype, char *comment) {
 
        tempfp = fopen(filename, "w");
        if (tempfp == NULL) {
-               printf("Cannot open %s: %s\n", filename, strerror(errno));
+               err_printf("Cannot open %s: %s\n", filename, strerror(errno));
                return;
        }
 
@@ -982,6 +984,7 @@ void network_config_management(char *entrytype, char *comment) {
        cksum = file_checksum(filename);
        if (editor_pid == 0) {
                chmod(filename, 0600);
+               screen_reset();
                sttybbs(SB_RESTORE);
                setenv("WINDOW_TITLE", "Network configuration", 1);
                execlp(editor_path, editor_path, filename, NULL);
@@ -994,10 +997,11 @@ void network_config_management(char *entrytype, char *comment) {
                } while ((b != editor_pid) && (b >= 0));
        editor_pid = (-1);
        sttybbs(0);
+       screen_set();
        }
 
        if (file_checksum(filename) == cksum) {
-               printf("*** Not saving changes.\n");
+               err_printf("*** Not saving changes.\n");
                e_ex_code = 1;
        }
 
@@ -1073,34 +1077,34 @@ void do_ignet_configuration(void) {
        }
 
        do {
-               printf("\n");
+               scr_printf("\n");
                color(BRIGHT_WHITE);
-               printf( "### "
+               scr_printf(     "### "
                        "   Node          "
                        "  Secret           "
                        "          Host or IP             "
                        "Port#\n");
                color(DIM_WHITE);
-               printf( "--- "
+               scr_printf(     "--- "
                        "---------------- "
                        "------------------ "
                        "-------------------------------- "
                        "-----\n");
                for (i=0; i<num_recs; ++i) {
                color(DIM_WHITE);
-               printf("%3d ", i+1);
+               scr_printf("%3d ", i+1);
                extract(buf, recs[i], 0);
                color(BRIGHT_CYAN);
-               printf("%-16s ", buf);
+               scr_printf("%-16s ", buf);
                extract(buf, recs[i], 1);
                color(BRIGHT_MAGENTA);
-               printf("%-18s ", buf);
+               scr_printf("%-18s ", buf);
                extract(buf, recs[i], 2);
                color(BRIGHT_CYAN);
-               printf("%-32s ", buf);
+               scr_printf("%-32s ", buf);
                extract(buf, recs[i], 3);
                color(BRIGHT_MAGENTA);
-               printf("%-3s\n", buf);
+               scr_printf("%-3s\n", buf);
                color(DIM_WHITE);
                }
 
@@ -1143,7 +1147,7 @@ void do_ignet_configuration(void) {
                                        serv_puts("000");
                                }
                                else {
-                                       printf("%s\n", &buf[4]);
+                                       scr_printf("%s\n", &buf[4]);
                                }
                                quitting = 1;
                                break;
diff --git a/citadel/screen.c b/citadel/screen.c
new file mode 100644 (file)
index 0000000..7d930f4
--- /dev/null
@@ -0,0 +1,349 @@
+/* $Id$ */
+
+/*
+ * Handle full-screen curses stuff
+ */
+
+#include "sysdep.h"
+#ifdef HAVE_CURSES_H
+#include <curses.h>
+#endif
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <sys/types.h>
+#ifdef VW_PRINTW_IN_CURSES
+#define _vwprintw vw_printw
+#else
+/* Ancient curses implementations, this needs testing. Anybody got XENIX? */
+#define _vwprintw vwprintw
+#endif
+#include "citadel.h"
+#include "commands.h"
+#include "screen.h"
+
+#ifdef HAVE_CURSES_H
+static SCREEN *myscreen = NULL;
+static WINDOW *mainwindow = NULL;
+static WINDOW *statuswindow = NULL;
+
+char rc_screen;
+char arg_screen;
+
+extern int screenheight;
+extern int screenwidth;
+extern void check_screen_dims(void);
+#endif
+
+
+/*
+ * Initialize the screen.  If newterm() fails, myscreen will be NULL and
+ * further handlers will assume we should be in line mode.
+ */
+void screen_new(void)
+{
+#ifdef HAVE_CURSES_H
+       if (arg_screen != RC_NO && rc_screen != RC_NO)
+               myscreen = newterm(NULL, stdout, stdin);
+       if (myscreen) {
+               cbreak();
+               noecho();
+               nonl();
+               intrflush(stdscr, FALSE);
+               keypad(stdscr, TRUE);
+       } else
+#endif /* HAVE_CURSES_H */
+       {
+               send_ansi_detect();
+               look_for_ansi();
+               cls(0);
+               color(1+DIM_WHITE);
+       }
+#ifdef HAVE_CURSES_H
+       if (myscreen) {
+               /* Setup all our colors */
+               start_color();
+               init_pair(1+DIM_BLACK, COLOR_BLACK, COLOR_BLACK);
+               init_pair(1+DIM_RED, COLOR_RED, COLOR_BLACK);
+               init_pair(1+DIM_GREEN, COLOR_GREEN, COLOR_BLACK);
+               init_pair(1+DIM_YELLOW, COLOR_YELLOW, COLOR_BLACK);
+               init_pair(1+DIM_BLUE, COLOR_BLUE, COLOR_BLACK);
+               init_pair(1+DIM_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
+               init_pair(1+DIM_CYAN, COLOR_CYAN, COLOR_BLACK);
+               init_pair(1+DIM_WHITE, COLOR_WHITE, COLOR_BLACK);
+               init_pair(17, COLOR_WHITE, COLOR_BLUE);
+       }
+#endif /* HAVE_CURSES_H */
+       screen_set();
+       windows_new();
+}
+
+
+/*
+ * Kill the screen completely (used at exit).  It is safe to call this
+ * function more than once.
+ */
+void screen_delete(void)
+{
+       windows_delete();
+       screen_reset();
+#ifdef HAVE_CURSES_H
+       if (myscreen)
+               delscreen(myscreen);
+       myscreen = NULL;
+#endif
+}
+
+
+/*
+ * Set screen/IO parameters, e.g. at start of program or return from external
+ * program run.
+ */
+int screen_set(void)
+{
+#ifdef HAVE_CURSES_H
+       if (myscreen) {
+               set_term(myscreen);
+               wrefresh(curscr);
+               return 1;
+       }
+#endif /* HAVE_CURSES_H */
+       return 0;
+}
+
+
+/*
+ * Reset screen/IO parameters, e.g. at exit or fork of external program.
+ */
+int screen_reset(void)
+{
+#ifdef HAVE_CURSES_H
+       if (myscreen) {
+               endwin();
+               return 1;
+       }
+#endif /* HAVE_CURSES_H */
+       return 0;
+}
+
+
+/*
+ * scr_printf() outputs to the main window (or screen if not in curses)
+ */
+int scr_printf(char *fmt, ...)
+{
+       va_list ap;
+       register int retval;
+
+       va_start(ap, fmt);
+#ifdef HAVE_CURSES_H
+       if (mainwindow) {
+               retval = _vwprintw(mainwindow, fmt, ap);
+               /*
+               if (fmt[strlen(fmt) - 1] == '\n')
+                       wrefresh(mainwindow);
+               */
+       } else
+#endif
+               retval = vprintf(fmt, ap);
+       va_end(ap);
+       return retval;
+}
+
+
+/*
+ * err_printf() outputs to error status window (or stderr if not in curses)
+ */
+int err_printf(char *fmt, ...)
+{
+       va_list ap;
+       register int retval;
+
+       va_start(ap, fmt);
+#ifdef HAVE_CURSES_H
+       if (mainwindow) {               /* FIXME: direct to error window */
+               retval = _vwprintw(mainwindow, fmt, ap);
+               if (fmt[strlen(fmt) - 1] == '\n')
+                       wrefresh(mainwindow);
+       } else
+#endif
+               retval = vfprintf(stderr, fmt, ap);
+       va_end(ap);
+       return retval;
+}
+
+
+/*
+ * sln_printf() outputs to error status window (or stderr if not in curses)
+ */
+int sln_printf(char *fmt, ...)
+{
+       va_list ap;
+       register int retval;
+
+       va_start(ap, fmt);
+#ifdef HAVE_CURSES_H
+       if (statuswindow) {
+               retval = _vwprintw(statuswindow, fmt, ap);
+               if (fmt[strlen(fmt) - 1] == '\n')
+                       wrefresh(mainwindow);
+       } else
+#endif
+               retval = vprintf(fmt, ap);
+       va_end(ap);
+       return retval;
+}
+
+
+int scr_getc(void)
+{
+#ifdef HAVE_CURSES_H
+       if (mainwindow)
+               return wgetch(mainwindow);
+#endif
+       return getchar();
+}
+
+
+/*
+ * scr_putc() outputs a single character
+ */
+int scr_putc(int c)
+{
+#ifdef HAVE_CURSES_H
+       if (mainwindow)
+               return ((waddch(mainwindow, c) == OK) ? c : EOF);
+#endif
+       return putc(c, stdout);
+}
+
+
+/*
+ * scr_color() sets the window color for mainwindow
+ */
+int scr_color(int colornum)
+{
+#ifdef HAVE_CURSES_H
+       if (mainwindow) {
+               wcolor_set(mainwindow, 1 + (colornum & 7), NULL);
+               if (colornum & 8) {
+                       wattron(mainwindow, A_BOLD);
+               } else {
+                       wattroff(mainwindow, A_BOLD);
+               }
+               return 1;
+       }
+#endif
+       return 0;
+}
+
+
+void scr_flush(void)
+{
+#ifdef HAVE_CURSES_H
+       if (mainwindow)
+               wrefresh(mainwindow);
+       else
+#endif
+               fflush(stdout);
+}
+
+
+void err_flush(void)
+{
+#ifdef HAVE_CURSES_H
+       if (mainwindow)         /* FIXME: error status window needed */
+               wrefresh(mainwindow);
+       else
+#endif
+               fflush(stderr);
+}
+
+
+void sln_flush(void)
+{
+#ifdef HAVE_CURSES_H
+       if (statuswindow)
+               wrefresh(statuswindow);
+       else
+#endif
+               fflush(stdout);
+}
+
+
+int scr_set_windowsize(void)
+{
+#ifdef HAVE_CURSES_H
+       int y, x;
+
+       if (mainwindow) {
+               getmaxyx(mainwindow, y, x);
+               screenheight = y;
+               screenwidth = x;
+               return 1;
+       }
+#endif /* HAVE_CURSES_H */
+       return 0;
+}
+
+
+/*
+ * scr_winch() handles window size changes from SIGWINCH
+ * resizes all our windows for us
+ */
+RETSIGTYPE scr_winch(void)
+{
+#ifdef HAVE_CURSES_H
+       /* FIXME: not implemented */
+#endif
+       check_screen_dims();
+}
+
+
+/*
+ * Initialize the window(s) we will be using.
+ */
+void windows_new(void)
+{
+#ifdef HAVE_CURSES_H
+       register int x, y;
+
+       if (myscreen) {
+               getmaxyx(stdscr, y, x);
+               mainwindow = newwin(y - 1, x, 0, 0);
+               screenwidth = x;
+               screenheight = y - 1;
+               immedok(mainwindow, FALSE);
+               leaveok(mainwindow, FALSE);
+               scrollok(mainwindow, TRUE);
+               statuswindow = newwin(1, x, y - 1, 0);
+               wbkgdset(statuswindow, COLOR_PAIR(17));
+               werase(statuswindow);
+               immedok(statuswindow, TRUE);
+               leaveok(statuswindow, FALSE);
+               scrollok(statuswindow, FALSE);
+               wrefresh(statuswindow);
+       }
+#else /* HAVE_CURSES_H */
+
+#endif /* HAVE_CURSES_H */
+}
+
+
+/*
+ * Deinitialize the window(s) we were using (at exit).
+ */
+void windows_delete(void)
+{
+#ifdef HAVE_CURSES_H
+       if (mainwindow)
+               delwin(mainwindow);
+       mainwindow = NULL;
+       if (statuswindow)
+               delwin(statuswindow);
+       statuswindow = NULL;
+#else /* HAVE_CURSES_H */
+
+#endif /* HAVE_CURSES_H */
+}
diff --git a/citadel/screen.h b/citadel/screen.h
new file mode 100644 (file)
index 0000000..0eb69ad
--- /dev/null
@@ -0,0 +1,18 @@
+/* $Id$ */
+
+void screen_new(void);
+void screen_delete(void);
+int screen_set(void);
+int screen_reset(void);
+int scr_printf(char *fmt, ...);
+int err_printf(char *fmt, ...);
+int sln_printf(char *fmt, ...);
+int scr_getc(void);
+int scr_putc(int c);
+int scr_color(int colornum);
+void scr_flush(void);
+void err_flush(void);
+void sln_flush(void);
+int scr_set_windowsize(void);
+void windows_new(void);
+void windows_delete(void);
index 1fd5c1f0e00b0f11ca0323815d152de66304a9c4..24c34ab5d965f4c106345ae58338c4c92d8331ee 100644 (file)
 #include "tools.h"
 #include "citadel.h"
 
+#ifdef CIT_CLIENT
+#include "screen.h"
+#else
+extern int err_printf(char *fmt, ...);
+#endif
+
 #define TRUE  1
 #define FALSE 0
 
@@ -39,7 +45,7 @@ static byte dtable[256];            /* base64 encode / decode table */
 char *safestrncpy(char *dest, const char *src, size_t n)
 {
        if (dest == NULL || src == NULL) {
-               fprintf(stderr, "safestrncpy: NULL argument\n");
+               err_printf("safestrncpy: NULL argument\n");
                abort();
        }
        strncpy(dest, src, n);