From 3fb35f698ccf5d0e70c81f75a399b24ff20554c4 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Wed, 3 Nov 2004 20:48:45 +0000 Subject: [PATCH] Changed terminal i/o for the bbs --- ChangeLog | 17 + TODO | 2 + examples/txtfiles-en.tar | Bin 81920 -> 81920 bytes lang/dutch.txt | 2 +- lang/english.txt | 2 +- lang/french.txt | 2 +- lang/galego.txt | 2 +- lang/german.txt | 2 +- lang/germandu.txt | 2 +- lang/italian.txt | 2 +- lang/spanish.txt | 2 +- lib/mbselib.h | 14 +- lib/rawio.c | 160 +-- mbfido/mbfido.c | 2 +- mbmon/mutil.c | 16 +- mbsebbs/Makefile | 76 +- mbsebbs/bye.c | 40 +- mbsebbs/change.c | 988 ++++++++--------- mbsebbs/chat.c | 46 +- mbsebbs/dispfile.c | 309 +++--- mbsebbs/door.c | 30 +- mbsebbs/email.c | 1003 ++++++++--------- mbsebbs/file.c | 2212 +++++++++++++++++++------------------- mbsebbs/filesub.c | 508 +++++---- mbsebbs/fsedit.c | 108 +- mbsebbs/funcs.c | 31 +- mbsebbs/input.c | 583 ++++++---- mbsebbs/input.h | 7 + mbsebbs/language.c | 96 +- mbsebbs/lastcallers.c | 34 +- mbsebbs/lineedit.c | 827 +++++++------- mbsebbs/mail.c | 1222 +++++++++++---------- mbsebbs/mbnewusr.c | 36 +- mbsebbs/mbsebbs.c | 45 +- mbsebbs/menu.c | 28 +- mbsebbs/misc.c | 12 +- mbsebbs/morefile.c | 95 +- mbsebbs/newuser.c | 80 +- mbsebbs/offline.c | 384 +++---- mbsebbs/oneline.c | 581 +++++----- mbsebbs/openport.c | 162 +++ mbsebbs/openport.h | 11 + mbsebbs/page.c | 68 +- mbsebbs/pinfo.c | 153 +-- mbsebbs/pop3.c | 17 +- mbsebbs/signature.c | 57 +- mbsebbs/term.c | 67 +- mbsebbs/timecheck.c | 15 +- mbsebbs/timeout.c | 115 +- mbsebbs/timestats.c | 75 +- mbsebbs/ttyio.c | 594 ++++++++++ mbsebbs/ttyio.h | 115 ++ mbsebbs/user.c | 16 +- mbsebbs/userlist.c | 29 +- mbsebbs/whoson.c | 75 +- mbsetup/mutil.c | 16 +- script/editor.in | 8 +- 57 files changed, 6202 insertions(+), 4999 deletions(-) create mode 100644 mbsebbs/openport.c create mode 100644 mbsebbs/openport.h create mode 100644 mbsebbs/ttyio.c create mode 100644 mbsebbs/ttyio.h diff --git a/ChangeLog b/ChangeLog index 28d4728e..f4e60654 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,25 @@ $Id$ +!!!! DON'T USE, THIS VERSION HAS LOTS OF BUGS !!!! v0.71.0 27-Oct-2004 + mbsebbs: + In change handle the first character of the name is not + capitalized. + Changed layout of raw directory listing to support long + filenames. + Rewrote terminal i/o. + + mbnewusr: + Rewrote terminal i/o. + + lang: + Changed width of prompt 261. + + examples: + Fixed logo display. + v0.70.0 06-Jun-2004 - 26-Oct-2004. diff --git a/TODO b/TODO index ccf5852e..ad3afcc2 100644 --- a/TODO +++ b/TODO @@ -124,6 +124,8 @@ mbcico: N: Make workaround for binkp bug in Irex 2.24 upto 2.29 + U: See whathappens if we remove FLUSHOUT(), this may give troubles. + mbfile: L: Update <-touch> diff --git a/examples/txtfiles-en.tar b/examples/txtfiles-en.tar index c894fa43c55886740bf935cf62960dead6d8f66d..889bdaed1bec5b99d150be09a2a7663c8eef9fa5 100644 GIT binary patch delta 229 zcmZo@U~On%-Oy1ZYG`0+Vq|1&VrXd0U|?uuWN5~qU@*CmC1o>Xtpqc-bhM$hk*T$@ zL9W7Pm4>8w;zkTm9mYUCARXq0rcfQ*8RZ#wvGN+~C>ZD&8-q!s=_gbe1GxM$k=0{}&xH5C8= delta 230 zcmZo@U~On%-Oy1ZYG7_`W@c()Y-(c8U|?uuWNO5qU@*CmC1o>Xtpqc-m~^zEwUMc{ zu|e);m4>8w;)V={28IS^CPv1_#)cpr=7uIv9ore@8F#Vr8tEt)=oy%RNrUMpR2T!f zj1@BSON)vXOw6~ds50JRn*Lv%v0dC4(a/ein]: |Es sind keine Dateien zum Herunterladen markiert. |extra Minuten. |Du hast folgende Bereiche fuer den "Offline Reader" markiert: -|Dateiname Groesse Datum +|Dateiname Groesse Datum |Protokoll: Protokolldatei kann nicht geoeffnet werden. |Auswahl des bevorzugten Protokolls |Bitte Protokoll auswaehlen (frei lassen um abzubrechen): diff --git a/lang/italian.txt b/lang/italian.txt index 66434471..722d948b 100644 --- a/lang/italian.txt +++ b/lang/italian.txt @@ -259,7 +259,7 @@ SN|Nodo sconosciuto, continua lo stesso [s/N]: |Nessun file selezionato per il download. |minuti extra. |Hai selezionato le seguenti Conferenze: -|Filename Dimensione Data +|Filename Dimensione Data |Protocollo: Non posso aprire il file del protocollo. |Seleziona il tuo protocollo di trasferimento preferito |Seleziona Protocollo (Invio per uscire): diff --git a/lang/spanish.txt b/lang/spanish.txt index a4b0d4c9..d71ccabd 100644 --- a/lang/spanish.txt +++ b/lang/spanish.txt @@ -259,7 +259,7 @@ SN|Nodo desconocido. |No hay ficheros marcados. |minutos extra. |Has seleccionado las siguientes  reas: -|Fichero Tama¤o Fecha +|Fichero Tama¤o Fecha |Protocolo: No puedo abrir fichero de protocolos. |Elija el protocolo de transferencia predeterminado |Elija Protocolo (Enter para salir): diff --git a/lib/mbselib.h b/lib/mbselib.h index be28f6c6..d266106c 100644 --- a/lib/mbselib.h +++ b/lib/mbselib.h @@ -2240,13 +2240,13 @@ char *arcname(faddr *, unsigned short, int); /* * From rawio.c */ -void Setraw(void); /* Set raw mode */ -void Unsetraw(void); /* Unset raw mode */ -unsigned char Getone(void); /* Get one raw character */ -long Speed(void); /* Get (locked) tty speed */ -int Waitchar(unsigned char *, int); /* Wait n * 10mSec for char */ -int Escapechar(unsigned char *); /* Escape sequence test */ -unsigned char Readkey(void); /* Read a translated key */ +void mbse_Setraw(void); /* Set raw mode */ +void mbse_Unsetraw(void); /* Unset raw mode */ +unsigned char mbse_Getone(void); /* Get one raw character */ +long mbse_Speed(void); /* Get (locked) tty speed */ +int mbse_Waitchar(unsigned char *, int); /* Wait n * 10mSec for char */ +int mbse_Escapechar(unsigned char *); /* Escape sequence test */ +unsigned char mbse_Readkey(void); /* Read a translated key */ diff --git a/lib/rawio.c b/lib/rawio.c index ee43c625..28f616d5 100644 --- a/lib/rawio.c +++ b/lib/rawio.c @@ -38,7 +38,7 @@ int rawset = FALSE; /* * Sets raw mode and saves the terminal setup */ -void Setraw() +void mbse_Setraw() { int rc; @@ -72,7 +72,7 @@ void Setraw() /* * Unsets raw mode and returns state of terminal */ -void Unsetraw() +void mbse_Unsetraw() { int rc; @@ -95,21 +95,21 @@ void Unsetraw() * This function is used to get a single character from a user ie for a * menu option */ -unsigned char Getone() +unsigned char mbse_Getone() { - unsigned char c = 0; + unsigned char c = 0; - if ((ttyfd = open ("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - perror("open 8"); - exit(MBERR_TTYIO_ERROR); - } - Setraw(); + if ((ttyfd = open ("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { + perror("open 8"); + exit(MBERR_TTYIO_ERROR); + } + mbse_Setraw(); - c = Readkey(); + c = mbse_Readkey(); - Unsetraw(); - close(ttyfd); - return(c); + mbse_Unsetraw(); + close(ttyfd); + return(c); } @@ -117,7 +117,7 @@ unsigned char Getone() /* * Read the (locked) speed from the tty */ -long Speed(void) +long mbse_Speed(void) { speed_t mspeed; @@ -227,7 +227,7 @@ long Speed(void) /* * Wait for a character for a maximum of wtime * 10 mSec. */ -int Waitchar(unsigned char *ch, int wtime) +int mbse_Waitchar(unsigned char *ch, int wtime) { int i, rc = -1; @@ -242,56 +242,56 @@ int Waitchar(unsigned char *ch, int wtime) -int Escapechar(unsigned char *ch) +int mbse_Escapechar(unsigned char *ch) { - int rc; - unsigned char c; + int rc; + unsigned char c; - /* - * Escape character, if nothing follows within - * 50 mSec, the user really pressed . + /* + * Escape character, if nothing follows within + * 50 mSec, the user really pressed . + */ + if ((rc = mbse_Waitchar(ch, 5)) == -1) + return rc; + + if (*ch == '[') { + /* + * Start of CSI sequence. If nothing follows, + * return immediatly. */ - if ((rc = Waitchar(ch, 5)) == -1) - return rc; + if ((rc = mbse_Waitchar(ch, 5)) == -1) + return rc; - if (*ch == '[') { - /* - * Start of CSI sequence. If nothing follows, - * return immediatly. - */ - if ((rc = Waitchar(ch, 5)) == -1) - return rc; - - /* - * Test for the most important keys. Note - * that only the cursor movement keys are - * guaranteed to work with PC-clients. - */ - c = *ch; - if (c == 'A') - c = KEY_UP; - if (c == 'B') - c = KEY_DOWN; - if (c == 'C') - c = KEY_RIGHT; - if (c == 'D') - c = KEY_LEFT; - if ((c == '1') || (c == 'H') || (c == 0)) - c = KEY_HOME; - if ((c == '4') || (c == 'K') || (c == 101) || (c == 144)) - c = KEY_END; - if (c == '2') - c = KEY_INS; - if (c == '3') - c = KEY_DEL; - if (c == '5') - c = KEY_PGUP; - if (c == '6') - c = KEY_PGDN; - memcpy(ch, &c, sizeof(unsigned char)); - return rc; - } - return -1; + /* + * Test for the most important keys. Note + * that only the cursor movement keys are + * guaranteed to work with PC-clients. + */ + c = *ch; + if (c == 'A') + c = KEY_UP; + if (c == 'B') + c = KEY_DOWN; + if (c == 'C') + c = KEY_RIGHT; + if (c == 'D') + c = KEY_LEFT; + if ((c == '1') || (c == 'H') || (c == 0)) + c = KEY_HOME; + if ((c == '4') || (c == 'K') || (c == 101) || (c == 144)) + c = KEY_END; + if (c == '2') + c = KEY_INS; + if (c == '3') + c = KEY_DEL; + if (c == '5') + c = KEY_PGUP; + if (c == '6') + c = KEY_PGDN; + memcpy(ch, &c, sizeof(unsigned char)); + return rc; + } + return -1; } @@ -303,31 +303,31 @@ int Escapechar(unsigned char *ch) * If for example cursur keys are detected, this function returns * a translated value. */ -unsigned char Readkey(void) +unsigned char mbse_Readkey(void) { - unsigned char ch = 0; - int rc = -1; + unsigned char ch = 0; + int rc = -1; - while (rc == -1) { - rc = Waitchar(&ch, 5); + while (rc == -1) { + rc = mbse_Waitchar(&ch, 5); - /* - * If the character is not an Escape character, - * then this function is finished. - */ - if ((rc == 1) && (ch != KEY_ESCAPE)) - return ch; + /* + * If the character is not an Escape character, + * then this function is finished. + */ + if ((rc == 1) && (ch != KEY_ESCAPE)) + return ch; - if ((rc == 1) && (ch == KEY_ESCAPE)) { - rc = Escapechar(&ch); - if (rc == 1) - return ch; - else - return KEY_ESCAPE; - } + if ((rc == 1) && (ch == KEY_ESCAPE)) { + rc = mbse_Escapechar(&ch); + if (rc == 1) + return ch; + else + return KEY_ESCAPE; } + } - return(ch); + return(ch); } diff --git a/mbfido/mbfido.c b/mbfido/mbfido.c index 0a304ed5..9b522d57 100644 --- a/mbfido/mbfido.c +++ b/mbfido/mbfido.c @@ -611,7 +611,7 @@ int main(int argc, char **argv) mbse_colour(LIGHTGREEN, BLACK); printf("Are you sure to process all area lists [y/N] "); fflush(stdout); - x = Getone(); + x = mbse_Getone(); printf("\r \r"); fflush(stdout); if (toupper(x) != 'Y') diff --git a/mbmon/mutil.c b/mbmon/mutil.c index 50b3e5f6..2fa78fad 100644 --- a/mbmon/mutil.c +++ b/mbmon/mutil.c @@ -47,7 +47,7 @@ unsigned char readkey(int y, int x, int fg, int bg) perror("open /dev/tty"); exit(MBERR_TTYIO_ERROR); } - Setraw(); + mbse_Setraw(); i = 0; while (rc == -1) { @@ -56,12 +56,12 @@ unsigned char readkey(int y, int x, int fg, int bg) mbse_locate(y, x); fflush(stdout); - rc = Waitchar(&ch, 5); + rc = mbse_Waitchar(&ch, 5); if ((rc == 1) && (ch != KEY_ESCAPE)) break; if ((rc == 1) && (ch == KEY_ESCAPE)) - rc = Escapechar(&ch); + rc = mbse_Escapechar(&ch); if (rc == 1) break; @@ -69,7 +69,7 @@ unsigned char readkey(int y, int x, int fg, int bg) Nopper(); } - Unsetraw(); + mbse_Unsetraw(); close(ttyfd); return ch; @@ -90,15 +90,15 @@ unsigned char testkey(int y, int x) perror("open /dev/tty"); exit(MBERR_TTYIO_ERROR); } - Setraw(); + mbse_Setraw(); - rc = Waitchar(&ch, 50); + rc = mbse_Waitchar(&ch, 50); if (rc == 1) { if (ch == KEY_ESCAPE) - rc = Escapechar(&ch); + rc = mbse_Escapechar(&ch); } - Unsetraw(); + mbse_Unsetraw(); close(ttyfd); if (rc == 1) diff --git a/mbsebbs/Makefile b/mbsebbs/Makefile index 5c65e14d..bcb6ad16 100644 --- a/mbsebbs/Makefile +++ b/mbsebbs/Makefile @@ -7,7 +7,7 @@ include ../Makefile.global SRCS = signature.c filesub.c language.c mbtoberep.c \ msgutil.c oneline.c bbslist.c morefile.c \ email.c fsedit.c lineedit.c mblang.c mbuser.c page.c \ - bye.c funcs.c mail.c term.c \ + bye.c funcs.c mail.c term.c ttyio.c openport.c \ newuser.c pinfo.c timecheck.c change.c \ exitinfo.c mball.c mbsebbs.c menu.c pop3.c lastcallers.c \ timeout.c chat.c file.c mbstat.c misc.c \ @@ -16,7 +16,7 @@ SRCS = signature.c filesub.c language.c mbtoberep.c \ HDRS = signature.h filesub.h language.h mbsebbs.h misc.h offline.h \ timeout.h bbslist.h email.h fsedit.h lineedit.h \ mbstat.h msgutil.h oneline.h user.h bye.h morefile.h \ - funcs.h mail.h mbuser.h page.h term.h \ + funcs.h mail.h mbuser.h page.h term.h ttyio.h openport.h \ change.h exitinfo.h mball.h newuser.h \ pinfo.h chat.h file.h menu.h \ pop3.h timecheck.h mbnewusr.h input.h whoson.h \ @@ -26,10 +26,10 @@ MBSEBBS_OBJS = signature.o bbslist.o chat.o file.o funcs.o mail.o menu.o \ bye.o change.o mbsebbs.o timeout.o user.o timecheck.o \ exitinfo.o filesub.o lineedit.o offline.o language.o msgutil.o \ pop3.o email.o input.o whoson.o door.o dispfile.o userlist.o timestats.o \ - logentry.o morefile.o lastcallers.o term.o + logentry.o morefile.o lastcallers.o term.o ttyio.o openport.o MBSEBBS_LIBS = ../lib/libmbse.a ../lib/libmsgbase.a ../lib/libdbase.a ../lib/libmbinet.a ../lib/libnodelist.a -MBNEWUSR_OBJS = mbnewusr.o newuser.o language.o timeout.o dispfile.o oneline.o \ - timecheck.o input.o exitinfo.o funcs.o misc.o change.o door.o term.o \ +MBNEWUSR_OBJS = mbnewusr.o newuser.o language.o timeout.o dispfile.o oneline.o ttyio.o \ + timecheck.o input.o exitinfo.o funcs.o misc.o change.o door.o term.o openport.o \ filesub.o mail.o email.o msgutil.o pop3.o lineedit.o fsedit.o whoson.o MBNEWUSR_LIBS = ../lib/libmbse.a ../lib/libmsgbase.a ../lib/libdbase.a ../lib/libmbinet.a ../lib/libnodelist.a MBALL_OBJS = mball.o @@ -118,47 +118,49 @@ depend: # DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT # Dependencies generated by make depend -signature.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h signature.h funcs.h input.h language.h timeout.h term.h -filesub.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbsedb.h filesub.h funcs.h language.h input.h misc.h timeout.h exitinfo.h change.h term.h -language.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h language.h term.h +signature.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h signature.h funcs.h input.h language.h timeout.h term.h ttyio.h +filesub.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbsedb.h filesub.h funcs.h language.h input.h misc.h timeout.h exitinfo.h change.h term.h ttyio.h +language.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h language.h term.h ttyio.h mbtoberep.o: ../config.h ../lib/mbselib.h msgutil.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msgtext.h ../lib/msg.h oneline.h msgutil.h -oneline.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h oneline.h funcs.h input.h language.h term.h +oneline.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h oneline.h funcs.h input.h language.h term.h ttyio.h bbslist.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h bbslist.h funcs.h input.h language.h term.h -morefile.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h language.h morefile.h timeout.h -email.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msgtext.h ../lib/msg.h ../lib/mbinet.h exitinfo.h language.h mail.h timeout.h msgutil.h input.h email.h whoson.h term.h -fsedit.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h mail.h input.h language.h timeout.h pinfo.h fsedit.h term.h -lineedit.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h mail.h input.h language.h timeout.h lineedit.h term.h +morefile.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h language.h morefile.h timeout.h term.h ttyio.h +email.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msgtext.h ../lib/msg.h ../lib/mbinet.h exitinfo.h language.h mail.h timeout.h msgutil.h input.h email.h whoson.h term.h ttyio.h +fsedit.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h mail.h input.h language.h timeout.h pinfo.h fsedit.h term.h ttyio.h +lineedit.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h mail.h input.h language.h timeout.h lineedit.h term.h ttyio.h mblang.o: ../config.h ../lib/mbselib.h mbuser.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbuser.h -page.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h dispfile.h input.h chat.h page.h timeout.h mail.h language.h term.h -bye.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/nodelist.h dispfile.h misc.h language.h bye.h term.h -funcs.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msgtext.h ../lib/msg.h funcs.h -mail.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/nodelist.h ../lib/msgtext.h ../lib/msg.h mail.h funcs.h input.h language.h misc.h timeout.h oneline.h exitinfo.h lineedit.h fsedit.h filesub.h msgutil.h pop3.h email.h door.h whoson.h term.h -term.o: ../config.h ../lib/mbselib.h ../lib/users.h term.h -newuser.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h funcs.h input.h newuser.h language.h timeout.h change.h dispfile.h term.h -pinfo.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h pinfo.h input.h term.h -timecheck.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h timecheck.h funcs.h bye.h exitinfo.h language.h input.h term.h -change.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h change.h dispfile.h funcs.h input.h language.h misc.h timeout.h exitinfo.h bye.h term.h +page.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h dispfile.h input.h chat.h page.h timeout.h mail.h language.h term.h ttyio.h +bye.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/nodelist.h dispfile.h misc.h language.h bye.h term.h openport.h ttyio.h +funcs.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msgtext.h ../lib/msg.h funcs.h term.h ttyio.h +mail.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/nodelist.h ../lib/msgtext.h ../lib/msg.h mail.h funcs.h input.h language.h misc.h timeout.h oneline.h exitinfo.h lineedit.h fsedit.h filesub.h msgutil.h pop3.h email.h door.h whoson.h term.h ttyio.h openport.h +term.o: ../config.h ../lib/mbselib.h ../lib/users.h term.h ttyio.h +ttyio.o: ../config.h ../lib/mbselib.h ttyio.h +openport.o: ../config.h ../lib/mbselib.h ttyio.h openport.h +newuser.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h funcs.h input.h newuser.h language.h timeout.h change.h dispfile.h term.h ttyio.h openport.h +pinfo.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h pinfo.h input.h term.h ttyio.h +timecheck.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h timecheck.h funcs.h bye.h exitinfo.h language.h input.h term.h ttyio.h +change.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h change.h dispfile.h funcs.h input.h language.h misc.h timeout.h exitinfo.h bye.h term.h ttyio.h exitinfo.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h funcs.h input.h language.h oneline.h misc.h bye.h timeout.h timecheck.h exitinfo.h mball.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbsedb.h mball.h -mbsebbs.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msg.h mbsebbs.h user.h dispfile.h language.h menu.h misc.h bye.h timeout.h funcs.h term.h -menu.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h oneline.h mail.h bbslist.h change.h chat.h file.h funcs.h input.h misc.h timeout.h menu.h page.h pinfo.h bye.h timecheck.h whoson.h language.h offline.h email.h door.h dispfile.h userlist.h timestats.h logentry.h morefile.h lastcallers.h signature.h term.h -pop3.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbinet.h ../lib/msgtext.h ../lib/msg.h msgutil.h pop3.h term.h -lastcallers.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h language.h lastcallers.h term.h +mbsebbs.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msg.h mbsebbs.h user.h dispfile.h language.h menu.h misc.h bye.h timeout.h funcs.h term.h ttyio.h openport.h +menu.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h oneline.h mail.h bbslist.h change.h chat.h file.h funcs.h input.h misc.h timeout.h menu.h page.h pinfo.h bye.h timecheck.h whoson.h language.h offline.h email.h door.h dispfile.h userlist.h timestats.h logentry.h morefile.h lastcallers.h signature.h term.h ttyio.h +pop3.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbinet.h ../lib/msgtext.h ../lib/msg.h msgutil.h pop3.h term.h ttyio.h +lastcallers.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h language.h lastcallers.h term.h ttyio.h timeout.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msg.h timeout.h funcs.h bye.h filesub.h language.h term.h -chat.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h chat.h funcs.h input.h language.h misc.h whoson.h term.h -file.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbsedb.h filesub.h file.h funcs.h input.h language.h misc.h timeout.h exitinfo.h whoson.h change.h dispfile.h term.h +chat.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h chat.h funcs.h input.h language.h misc.h whoson.h term.h ttyio.h +file.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbsedb.h filesub.h file.h funcs.h input.h language.h misc.h timeout.h exitinfo.h whoson.h change.h dispfile.h term.h ttyio.h openport.h mbstat.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbstat.h -misc.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h funcs.h input.h language.h misc.h timeout.h exitinfo.h -offline.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/bluewave.h ../lib/msgtext.h ../lib/msg.h mail.h funcs.h input.h language.h file.h filesub.h exitinfo.h timeout.h msgutil.h pop3.h offline.h whoson.h term.h -user.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h timeout.h user.h dispfile.h funcs.h input.h misc.h bye.h file.h mail.h change.h menu.h exitinfo.h language.h offline.h email.h term.h -mbnewusr.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h mbnewusr.h funcs.h input.h language.h misc.h timeout.h newuser.h term.h -input.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h timeout.h language.h term.h -whoson.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h language.h exitinfo.h whoson.h term.h -door.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h language.h input.h timeout.h exitinfo.h whoson.h door.h term.h -dispfile.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msgtext.h ../lib/msg.h funcs.h language.h oneline.h misc.h timeout.h timecheck.h exitinfo.h mail.h email.h input.h dispfile.h filesub.h term.h -userlist.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h userlist.h language.h input.h timeout.h term.h +misc.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msg.h funcs.h input.h language.h misc.h timeout.h exitinfo.h ttyio.h term.h +offline.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/bluewave.h ../lib/msgtext.h ../lib/msg.h mail.h funcs.h input.h language.h file.h filesub.h exitinfo.h timeout.h msgutil.h pop3.h offline.h whoson.h term.h ttyio.h openport.h +user.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h timeout.h user.h dispfile.h funcs.h input.h misc.h bye.h file.h mail.h change.h menu.h exitinfo.h language.h offline.h email.h term.h ttyio.h +mbnewusr.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h mbnewusr.h funcs.h input.h language.h misc.h timeout.h newuser.h term.h ttyio.h openport.h +input.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h timeout.h language.h term.h ttyio.h +whoson.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h language.h exitinfo.h whoson.h term.h ttyio.h +door.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h language.h input.h timeout.h exitinfo.h whoson.h door.h term.h ttyio.h openport.h +dispfile.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msgtext.h ../lib/msg.h funcs.h language.h oneline.h misc.h timeout.h timecheck.h exitinfo.h mail.h email.h input.h dispfile.h filesub.h term.h ttyio.h +userlist.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h userlist.h language.h input.h timeout.h term.h ttyio.h timestats.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h timestats.h funcs.h language.h input.h exitinfo.h term.h logentry.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h logentry.h # End of generated dependencies diff --git a/mbsebbs/bye.c b/mbsebbs/bye.c index 0d77286e..daddf7c6 100644 --- a/mbsebbs/bye.c +++ b/mbsebbs/bye.c @@ -38,12 +38,14 @@ #include "language.h" #include "bye.h" #include "term.h" +#include "openport.h" +#include "ttyio.h" extern pid_t mypid; extern time_t t_start; extern char *StartTime; - +extern int hanged_up; int do_mailout = FALSE; @@ -54,6 +56,7 @@ void Good_Bye(int onsig) char *temp; long offset; time_t t_end; + int i; IsDoing("Hangup"); temp = calloc(PATH_MAX, sizeof(char)); @@ -63,7 +66,7 @@ void Good_Bye(int onsig) * Don't display goodbye screen on SIGHUP and idle timeout. * With idle timeout this will go into a loop. */ - if ((onsig != SIGHUP) && (onsig != SIGALRM) && (onsig != MBERR_TIMEOUT)) + if ((onsig != SIGHUP) && (onsig != SIGALRM) && (onsig != MBERR_TIMEOUT) && (hanged_up == 0)) DisplayFile((char *)"goodbye"); if (do_mailout) @@ -86,7 +89,7 @@ void Good_Bye(int onsig) usrconfig.iLastFileArea = iAreaNumber; /* If time expired, do not say say successful logoff */ - if (!iExpired) + if (!iExpired && !hanged_up) Syslog('+', "User successfully logged off BBS"); usrconfig.iLastMsgArea = iMsgAreaNumber; @@ -102,8 +105,24 @@ void Good_Bye(int onsig) } } + /* + * Flush all data to the user, wait 5 seconds to + * be sure the user received all data. + */ + if (! hanged_up) { + colour(LIGHTGRAY, BLACK); + sleep(4); + } + + for (i = 0; i < NSIG; i++) + signal(i, SIG_IGN); + + cookedport(); + hangup(); + t_end = time(NULL); Syslog(' ', "MBSEBBS finished in %s", t_elapsed(t_start, t_end)); + sleep(1); /* * Start shutting down this session @@ -117,16 +136,6 @@ void Good_Bye(int onsig) free(temp); unlink("taglist"); - /* - * Flush all data to the user, wait 5 seconds to - * be sure the user received all data. - */ - colour(LIGHTGRAY, BLACK); - fflush(stdout); - fflush(stdin); - sleep(5); - - Unsetraw(); Free_Language(); free(pTTY); if (StartTime) @@ -156,10 +165,11 @@ void Quick_Bye(int onsig) signal(i, SIG_DFL); colour(LIGHTGRAY, BLACK); - fflush(stdout); - fflush(stdin); sleep(3); + cookedport(); + hangup(); + free(pTTY); if (StartTime) free(StartTime); diff --git a/mbsebbs/change.c b/mbsebbs/change.c index cbb3206b..1e4b6c63 100644 --- a/mbsebbs/change.c +++ b/mbsebbs/change.c @@ -42,101 +42,109 @@ #include "exitinfo.h" #include "bye.h" #include "term.h" - +#include "ttyio.h" int Chg_Language(int NewMode) { - FILE *pLang; - int iLang, iFoundLang = FALSE; - char *temp; + FILE *pLang; + int iLang, iFoundLang = FALSE; + char *temp; - temp = calloc(PATH_MAX, sizeof(char)); + temp = calloc(PATH_MAX, sizeof(char)); - if (!NewMode) - ReadExitinfo(); + if (!NewMode) + ReadExitinfo(); - while(TRUE) { - sprintf(temp, "%s/etc/language.data", getenv("MBSE_ROOT")); - if(( pLang = fopen(temp, "r")) == NULL) { - WriteError("$Can't open %s", temp); - printf("\nFATAL: Can't open language file\n\n"); - Pause(); - free(temp); - return 0; - } - fread(&langhdr, sizeof(langhdr), 1, pLang); - - colour(CFG.HiliteF, CFG.HiliteB); - /* Select your preferred language */ - printf("\n%s\n\n", (char *) Language(378)); - - iLang = 6; - colour(9,0); - while (fread(&lang, langhdr.recsize, 1, pLang) == 1) - if (lang.Available) { - colour(13, 0); - printf("(%s)", lang.LangKey); - colour(8,0); - printf(" %c ", 46); - colour(3,0); - printf("%-29s ", lang.Name); - - iLang++; - if ((iLang % 2) == 0) - printf("\n"); - } - Enter(1); - - colour(CFG.HiliteF, CFG.HiliteB); - /* Select language: */ - printf("\n%s", (char *) Language(379)); - - fflush(stdout); - alarm_on(); - iLang = toupper(Getone()); - - printf("%c", iLang); - - fseek(pLang, langhdr.hdrsize, 0); - - while (fread(&lang, langhdr.recsize, 1, pLang) == 1) { - strcpy(lang.LangKey,tu(lang.LangKey)); - if ((lang.LangKey[0] == iLang) && (lang.Available)) { - strcpy(CFG.current_language, lang.Filename); - iFoundLang = TRUE; - break; - } - } - - fclose(pLang); - - if(!iFoundLang) { - Enter(2); - /* Invalid selection, please try again! */ - pout(10, 0, (char *) Language(265)); - Enter(2); - } else { - exitinfo.iLanguage = iLang; - strcpy(CFG.current_language, lang.Filename); - Free_Language(); - InitLanguage(); - - colour(10, 0); - /* Language now set to" */ - printf("\n\n%s%s\n\n", (char *) Language(380), lang.Name); - - if (!NewMode) { - Syslog('+', "Changed language to %s", lang.Name); - WriteExitinfo(); - Pause(); - } - break; - } + while(TRUE) { + sprintf(temp, "%s/etc/language.data", getenv("MBSE_ROOT")); + if(( pLang = fopen(temp, "r")) == NULL) { + WriteError("$Can't open %s", temp); + sprintf(temp, "\nFATAL: Can't open language file\n\n"); + PUTSTR(temp); + Pause(); + free(temp); + return 0; } + fread(&langhdr, sizeof(langhdr), 1, pLang); - free(temp); + colour(CFG.HiliteF, CFG.HiliteB); + /* Select your preferred language */ + sprintf(temp, "\r\n%s\r\n\r\n", (char *) Language(378)); + PUTSTR(temp); + + iLang = 6; + colour(9,0); + while (fread(&lang, langhdr.recsize, 1, pLang) == 1) + if (lang.Available) { + colour(13, 0); + sprintf(temp, "(%s)", lang.LangKey); + PUTSTR(temp); + colour(8,0); + sprintf(temp, " %c ", 46); + PUTSTR(temp); + colour(3,0); + sprintf(temp, "%-29s ", lang.Name); + PUTSTR(temp); + + iLang++; + if ((iLang % 2) == 0) { + PUTCHAR('\r'); + PUTCHAR('\n'); + } + } Enter(1); - return iLang; + + colour(CFG.HiliteF, CFG.HiliteB); + /* Select language: */ + sprintf(temp, "\n%s", (char *) Language(379)); + PUTSTR(temp); + + alarm_on(); + iLang = toupper(Readkey()); + + PUTCHAR(iLang); + + fseek(pLang, langhdr.hdrsize, 0); + + while (fread(&lang, langhdr.recsize, 1, pLang) == 1) { + strcpy(lang.LangKey,tu(lang.LangKey)); + if ((lang.LangKey[0] == iLang) && (lang.Available)) { + strcpy(CFG.current_language, lang.Filename); + iFoundLang = TRUE; + break; + } + } + + fclose(pLang); + + if(!iFoundLang) { + Enter(2); + /* Invalid selection, please try again! */ + pout(10, 0, (char *) Language(265)); + Enter(2); + } else { + exitinfo.iLanguage = iLang; + strcpy(CFG.current_language, lang.Filename); + Free_Language(); + InitLanguage(); + + colour(10, 0); + /* Language now set to" */ + sprintf(temp, "\r\n\r\n%s%s\r\n\r\n", (char *) Language(380), lang.Name); + PUTSTR(temp); + + if (!NewMode) { + Syslog('+', "Changed language to %s", lang.Name); + WriteExitinfo(); + Pause(); + } + break; + } + } + + free(temp); + Enter(1); + return iLang; } @@ -154,7 +162,6 @@ void Chg_Password() Enter(1); /* Old password: */ language(15, 0, 120); - fflush(stdout); colour(CFG.InputColourF, CFG.InputColourB); Getpass(temp1); @@ -163,7 +170,6 @@ void Chg_Password() Enter(1); /* New password: */ language(9, 0, 121); - fflush(stdout); colour(CFG.InputColourF, CFG.InputColourB); Getpass(temp1); if((strlen(temp1)) >= CFG.password_length) { @@ -171,7 +177,6 @@ void Chg_Password() /* Confirm new password: */ language(9, 0, 122); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); Getpass(temp2); if(( strcmp(temp1,temp2)) != 0) { /* Passwords do not match! */ @@ -179,14 +184,13 @@ void Chg_Password() language(12, 0, 123); Enter(1); } else { - fflush(stdout); - fflush(stdin); break; } } else { colour(12, 0); /* Your password must contain at least %d characters! Try again.*/ - printf("\n%s%d %s\n\n", (char *) Language(42), CFG.password_length, (char *) Language(43)); + sprintf(temp2, "\r\n%s%d %s\r\n\r\n", (char *) Language(42), CFG.password_length, (char *) Language(43)); + PUTSTR(temp2); } } @@ -275,8 +279,7 @@ void Chg_Handle() /* Enter a handle (Enter to Quit): */ pout(9, 0, (char *) Language(412)); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); - Getname(temp, 34); + GetstrC(temp, 34); if ((strcmp(temp, "")) == 0) { free(Handle); @@ -286,14 +289,14 @@ void Chg_Handle() strcpy(Handle, tlcap(temp)); if (CheckHandle(Handle) || CheckUnixNames(Handle)) { - pout(12, 0, (char *)"\nThat handle is already been used\n"); + pout(12, 0, (char *)"\r\nThat handle is already been used\r\n"); } else if (CheckName(Handle)) { - pout(12, 0, (char *)"\nThat name is already been used\n"); - } else if((strcmp(Handle, "sysop")) == 0) { - pout(12, 0, (char *)"\nYou cannot use Sysop as a handle\n"); + pout(12, 0, (char *)"\r\nThat name is already been used\r\n"); + } else if((strcasecmp(Handle, "sysop")) == 0) { + pout(12, 0, (char *)"\r\nYou cannot use Sysop as a handle\r\n"); } else if(strcmp(temp, "") != 0) { Setup(exitinfo.sHandle, temp); - pout(10, 0, (char *)"\nHandle Changed!\n\n"); + pout(10, 0, (char *)"\r\nHandle Changed!\r\n\r\n"); Syslog('+', "New handle \"%s\"", exitinfo.sHandle); break; } @@ -311,23 +314,23 @@ void Chg_Handle() */ void Chg_Hotkeys() { - ReadExitinfo(); - Enter(2); + ReadExitinfo(); + Enter(2); - if (exitinfo.HotKeys) { - exitinfo.HotKeys = FALSE; - /* Hotkeys are now OFF */ - pout(10, 0, (char *) Language(146)); - } else { - exitinfo.HotKeys = TRUE; - /* Hotkeys are now ON */ - pout(10, 0, (char *) Language(145)); - } + if (exitinfo.HotKeys) { + exitinfo.HotKeys = FALSE; + /* Hotkeys are now OFF */ + pout(10, 0, (char *) Language(146)); + } else { + exitinfo.HotKeys = TRUE; + /* Hotkeys are now ON */ + pout(10, 0, (char *) Language(145)); + } - Enter(2); - sleep(2); - Syslog('+', "Hotkeys changed to %s", exitinfo.HotKeys?"True":"False"); - WriteExitinfo(); + Enter(2); + sleep(2); + Syslog('+', "Hotkeys changed to %s", exitinfo.HotKeys?"True":"False"); + WriteExitinfo(); } @@ -337,23 +340,23 @@ void Chg_Hotkeys() */ void Chg_MailCheck() { - ReadExitinfo(); - Enter(2); + ReadExitinfo(); + Enter(2); - if (exitinfo.MailScan) { - exitinfo.MailScan = FALSE; - /* New Mail check is now OFF */ - pout(10, 0, (char *) Language(367)); - } else { - exitinfo.MailScan = TRUE; - /* New Mail check is now ON */ - pout(10, 0, (char *) Language(366)); - } + if (exitinfo.MailScan) { + exitinfo.MailScan = FALSE; + /* New Mail check is now OFF */ + pout(10, 0, (char *) Language(367)); + } else { + exitinfo.MailScan = TRUE; + /* New Mail check is now ON */ + pout(10, 0, (char *) Language(366)); + } - Enter(2); - sleep(2); - Syslog('+', "New Mail Check changed to %s", exitinfo.MailScan ?"True":"False"); - WriteExitinfo(); + Enter(2); + sleep(2); + Syslog('+', "New Mail Check changed to %s", exitinfo.MailScan ?"True":"False"); + WriteExitinfo(); } @@ -363,23 +366,23 @@ void Chg_MailCheck() */ void Chg_FileCheck() { - ReadExitinfo(); - Enter(2); + ReadExitinfo(); + Enter(2); - if (exitinfo.ieFILE) { - exitinfo.ieFILE = FALSE; - /* New Files check is now OFF */ - pout(10, 0, (char *) Language(371)); - } else { - exitinfo.ieFILE = TRUE; - /* New Files check is now ON */ - pout(10, 0, (char *) Language(370)); - } + if (exitinfo.ieFILE) { + exitinfo.ieFILE = FALSE; + /* New Files check is now OFF */ + pout(10, 0, (char *) Language(371)); + } else { + exitinfo.ieFILE = TRUE; + /* New Files check is now ON */ + pout(10, 0, (char *) Language(370)); + } - Enter(2); - sleep(2); - Syslog('+', "Check New Files changed to %s", exitinfo.ieFILE ?"True":"False"); - WriteExitinfo(); + Enter(2); + sleep(2); + Syslog('+', "Check New Files changed to %s", exitinfo.ieFILE ?"True":"False"); + WriteExitinfo(); } @@ -390,6 +393,7 @@ void Chg_FileCheck() void Chg_FsMsged() { int z; + char temp[81]; ReadExitinfo(); Enter(2); @@ -398,7 +402,8 @@ void Chg_FsMsged() pout(LIGHTMAGENTA, BLACK, (char *)Language(372)); /* Line/Fullscreen/External */ colour(LIGHTCYAN, BLACK); - printf(" %s ", Language(387 + (exitinfo.MsgEditor & 3))); + sprintf(temp, " %s ", Language(387 + (exitinfo.MsgEditor & 3))); + PUTSTR(temp); /* Editor */ pout(LIGHTMAGENTA, BLACK, (char *)Language(390)); Enter(1); @@ -409,9 +414,8 @@ void Chg_FsMsged() else /* Select: 1) Line editor, 2) Fullscreen editor */ pout(WHITE, BLACK, (char *)Language(438)); - fflush(stdout); alarm_on(); - z = toupper(Getone()); + z = toupper(Readkey()); if (z == Keystroke(373, 0)) { exitinfo.MsgEditor = LINEEDIT; @@ -430,7 +434,8 @@ void Chg_FsMsged() pout(LIGHTMAGENTA, BLACK, (char *)Language(372)); /* Line/Fullscreen/External */ colour(LIGHTCYAN, BLACK); - printf(" %s ", Language(387 + (exitinfo.MsgEditor & 3))); + sprintf(temp, " %s ", Language(387 + (exitinfo.MsgEditor & 3))); + PUTSTR(temp); /* Editor */ pout(LIGHTMAGENTA, BLACK, (char *)Language(390)); @@ -471,71 +476,70 @@ void Chg_FsMsgedKeys() */ void Chg_Disturb() { - ReadExitinfo(); - colour(10, 0); + ReadExitinfo(); + Enter(2); - if(exitinfo.DoNotDisturb) { - exitinfo.DoNotDisturb = FALSE; - /* Do not disturb turned OFF */ - printf("\n%s\n", (char *) Language(416)); - } else { - exitinfo.DoNotDisturb = TRUE; - /* Do not disturb turned ON */ - printf("\n%s\n", (char *) Language(417)); - } + if(exitinfo.DoNotDisturb) { + exitinfo.DoNotDisturb = FALSE; + /* Do not disturb turned OFF */ + pout(10, 0, (char *) Language(416)); + } else { + exitinfo.DoNotDisturb = TRUE; + /* Do not disturb turned ON */ + pout(10, 0, (char *) Language(417)); + } - Syslog('+', "Do not disturb now %s", exitinfo.DoNotDisturb?"True":"False"); - UserSilent(exitinfo.DoNotDisturb); - sleep(2); - WriteExitinfo(); + Enter(2); + Syslog('+', "Do not disturb now %s", exitinfo.DoNotDisturb?"True":"False"); + UserSilent(exitinfo.DoNotDisturb); + sleep(2); + WriteExitinfo(); } void Chg_Location() { - char temp[81]; + char temp[81]; - ReadExitinfo(); - Syslog('+', "Old location \"%s\"", exitinfo.sLocation); + ReadExitinfo(); + Syslog('+', "Old location \"%s\"", exitinfo.sLocation); - while (TRUE) { - /* Old Location: */ - Enter(1); - /* Old location: */ - pout(15, 0, (char *) Language(73)); - colour(9, 0); - printf("%s\n", exitinfo.sLocation); - Enter(1); - /* Please enter your location: */ - pout(14, 0, (char *) Language(49)); + while (TRUE) { + /* Old Location: */ + Enter(1); + /* Old location: */ + pout(15, 0, (char *) Language(73)); + pout(9, 0, exitinfo.sLocation); + Enter(2); + /* Please enter your location: */ + pout(14, 0, (char *) Language(49)); - if(CFG.iCapLocation) { - colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); - GetnameNE(temp, 24); - } else { - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp, 80); - } - - if((strcmp(temp, "")) == 0) - break; - - if(( strlen(temp)) < CFG.CityLen) { - Enter(1); - /* Please enter a longer location (min */ - colour(12, 0); - printf("%s%d)", (char *) Language(74), CFG.CityLen); - Enter(1); - } else { - Setup(exitinfo.sLocation,temp); - break; - } + colour(CFG.InputColourF, CFG.InputColourB); + if (CFG.iCapLocation) { + GetnameNE(temp, 24); + } else { + GetstrC(temp, 80); } - Syslog('+', "New location \"%s\"", exitinfo.sLocation); - WriteExitinfo(); + if((strcmp(temp, "")) == 0) + break; + + if(( strlen(temp)) < CFG.CityLen) { + Enter(1); + /* Please enter a longer location (min */ + colour(12, 0); + sprintf(temp, "%s%d)", (char *) Language(74), CFG.CityLen); + PUTSTR(temp); + Enter(1); + } else { + Setup(exitinfo.sLocation,temp); + break; + } + } + + Syslog('+', "New location \"%s\"", exitinfo.sLocation); + WriteExitinfo(); } @@ -556,10 +560,12 @@ void Chg_Address() pout(WHITE, BLACK, (char *) Language(476)); Enter(1); colour(LIGHTBLUE, BLACK); - printf("%s\n", exitinfo.address[0]); - printf("%s\n", exitinfo.address[1]); - printf("%s\n", exitinfo.address[2]); + PUTSTR(exitinfo.address[0]); Enter(1); + PUTSTR(exitinfo.address[1]); + Enter(1); + PUTSTR(exitinfo.address[2]); + Enter(2); /* Your address, maximum 3 lines (only visible for the sysop): */ pout(YELLOW, BLACK, (char *) Language(474)); Enter(1); @@ -568,7 +574,6 @@ void Chg_Address() colour(YELLOW, BLACK); printf("%d: ", i+1); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); alarm_on(); GetstrC(temp, 40); if (strcmp(temp, "")) @@ -597,145 +602,145 @@ void Chg_Address() */ void Chg_Graphics() { - ReadExitinfo(); - Enter(2); + ReadExitinfo(); + Enter(2); - if (exitinfo.GraphMode) { - exitinfo.GraphMode = FALSE; - /* Ansi Mode turned OFF */ - pout(15, 0, (char *) Language(76)); - } else { - exitinfo.GraphMode = TRUE; - /* Ansi Mode turned ON */ - pout(15, 0, (char *) Language(75)); - } + if (exitinfo.GraphMode) { + exitinfo.GraphMode = FALSE; + /* Ansi Mode turned OFF */ + pout(15, 0, (char *) Language(76)); + } else { + exitinfo.GraphMode = TRUE; + /* Ansi Mode turned ON */ + pout(15, 0, (char *) Language(75)); + } - Syslog('+', "Graphics mode now %s", exitinfo.GraphMode?"On":"Off"); - Enter(2); - TermInit(exitinfo.GraphMode, 80, exitinfo.iScreenLen); - WriteExitinfo(); - sleep(2); + Syslog('+', "Graphics mode now %s", exitinfo.GraphMode?"On":"Off"); + Enter(2); + TermInit(exitinfo.GraphMode, 80, exitinfo.iScreenLen); + WriteExitinfo(); + sleep(2); } void Chg_VoicePhone() { - char temp[81]; + char temp[81]; - ReadExitinfo(); - Syslog('+', "Old voice phone \"%s\"", exitinfo.sVoicePhone); + ReadExitinfo(); + Syslog('+', "Old voice phone \"%s\"", exitinfo.sVoicePhone); - while (TRUE) { - Enter(1); - /* Please enter you Voice Number */ - pout(10, 0, (char *) Language(45)); - Enter(1); - pout(10, 0, (char *)": "); - colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); - GetPhone(temp, 16); + while (TRUE) { + Enter(1); + /* Please enter you Voice Number */ + pout(10, 0, (char *) Language(45)); + Enter(1); + pout(10, 0, (char *)": "); + colour(CFG.InputColourF, CFG.InputColourB); + GetPhone(temp, 16); - if (strlen(temp) < 6) { - Enter(1); - /* Please enter a proper phone number */ - pout(12, 0, (char *) Language(47)); - Enter(1); - } else { - strcpy(exitinfo.sVoicePhone, temp); - break; - } + if (strlen(temp) < 6) { + Enter(1); + /* Please enter a proper phone number */ + pout(12, 0, (char *) Language(47)); + Enter(1); + } else { + strcpy(exitinfo.sVoicePhone, temp); + break; } + } - Syslog('+', "New voice phone \"%s\"", exitinfo.sVoicePhone); - WriteExitinfo(); + Syslog('+', "New voice phone \"%s\"", exitinfo.sVoicePhone); + WriteExitinfo(); } void Chg_DataPhone() { - char temp[81]; + char temp[81]; - ReadExitinfo(); - Syslog('+', "Old data phone \"%s\"", exitinfo.sDataPhone); + ReadExitinfo(); + Syslog('+', "Old data phone \"%s\"", exitinfo.sDataPhone); - while (1) { - Enter(1); - /* Please enter you Data Number */ - pout(10, 0, (char *) Language(48)); - Enter(1); - pout(10, 0, (char *)": "); - colour(CFG.InputColourF, CFG.InputColourB); - GetPhone(temp, 16); + while (1) { + Enter(1); + /* Please enter you Data Number */ + pout(10, 0, (char *) Language(48)); + Enter(1); + pout(10, 0, (char *)": "); + colour(CFG.InputColourF, CFG.InputColourB); + GetPhone(temp, 16); - if( strlen(temp) < 6) { - Enter(1); - /* Please enter a proper phone number */ - pout(12, 0, (char *) Language(47)); - Enter(1); - } else { - strcpy(exitinfo.sDataPhone, temp); - break; - } + if( strlen(temp) < 6) { + Enter(1); + /* Please enter a proper phone number */ + pout(12, 0, (char *) Language(47)); + Enter(1); + } else { + strcpy(exitinfo.sDataPhone, temp); + break; } + } - Syslog('+', "New data phone \"%s\"", exitinfo.sDataPhone); - WriteExitinfo(); + Syslog('+', "New data phone \"%s\"", exitinfo.sDataPhone); + WriteExitinfo(); } void Chg_News() { - ReadExitinfo(); + ReadExitinfo(); + Enter(2); - if (exitinfo.ieNEWS) { - exitinfo.ieNEWS = FALSE; - /* News bulletins turned OFF */ - printf("\n\n%s\n\n", (char *) Language(79)); - } else { - exitinfo.ieNEWS = TRUE; - /* News bulletins turned ON */ - printf("\n\n%s\n\n", (char *) Language(78)); - } + if (exitinfo.ieNEWS) { + exitinfo.ieNEWS = FALSE; + /* News bulletins turned OFF */ + pout(10, 0, (char *) Language(79)); + } else { + exitinfo.ieNEWS = TRUE; + /* News bulletins turned ON */ + pout(10, 0, (char *) Language(78)); + } - Syslog('+', "News bullentins now %s", exitinfo.ieNEWS?"True":"False"); - sleep(2); - WriteExitinfo(); + Enter(2); + Syslog('+', "News bullentins now %s", exitinfo.ieNEWS?"True":"False"); + sleep(2); + WriteExitinfo(); } void Chg_ScreenLen() { - char *temp; + char *temp; - ReadExitinfo(); - temp = calloc(81, sizeof(char)); - Syslog('+', "Old screenlen %d", exitinfo.iScreenLen); - fflush(stdin); + ReadExitinfo(); + temp = calloc(81, sizeof(char)); + Syslog('+', "Old screenlen %d", exitinfo.iScreenLen); - Enter(1); - /* Please enter your Screen Length? [24]: */ - pout(13, 0, (char *) Language(64)); - colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); - Getnum(temp, 2); + Enter(1); + /* Please enter your Screen Length? [24]: */ + pout(13, 0, (char *) Language(64)); + colour(CFG.InputColourF, CFG.InputColourB); + Getnum(temp, 2); - if((strcmp(temp, "")) == 0) { - exitinfo.iScreenLen = 24; - printf("\n%s\n\n", (char *) Language(80)); - } else { - exitinfo.iScreenLen = atoi(temp); - printf("\n%s%d\n\n", (char *) Language(81), exitinfo.iScreenLen); - } + if((strcmp(temp, "")) == 0) { + exitinfo.iScreenLen = 24; + sprintf(temp, "\r\n%s\r\n\r\n", (char *) Language(80)); + } else { + exitinfo.iScreenLen = atoi(temp); + sprintf(temp, "\r\n%s%d\r\n\r\n", (char *) Language(81), exitinfo.iScreenLen); + } + PUTSTR(temp); - TermInit(exitinfo.GraphMode, 80, exitinfo.iScreenLen); - Syslog('+', "New screenlen %d", exitinfo.iScreenLen); - WriteExitinfo(); - Pause(); - free(temp); + TermInit(exitinfo.GraphMode, 80, exitinfo.iScreenLen); + Syslog('+', "New screenlen %d", exitinfo.iScreenLen); + WriteExitinfo(); + Pause(); + free(temp); } @@ -745,89 +750,90 @@ void Chg_ScreenLen() */ int Test_DOB(char *DOB) { - int tyear, year, month, day; - char temp[40], temp1[40]; + int tyear, year, month, day; + char temp[40], temp1[40]; - /* - * If Ask Date of Birth is off, assume users age is - * zero, and this check is ok. - */ - if (!CFG.iDOB) { - UserAge = 0; - return TRUE; - } + /* + * If Ask Date of Birth is off, assume users age is + * zero, and this check is ok. + */ + if (!CFG.iDOB) { + UserAge = 0; + return TRUE; + } - /* - * First check length of string - */ - if (strlen(DOB) != 10) { - Syslog('!', "Date format length %d characters", strlen(DOB)); - /* Please enter the correct date format */ - language(14, 0, 83); - return FALSE; - } - /* - * Split the date into pieces - */ - strcpy(temp1, DOB); - strcpy(temp, strtok(temp1, "-")); - day = atoi(temp); - strcpy(temp, strtok(NULL, "-")); - month = atoi(temp); - strcpy(temp, strtok(NULL, "")); - year = atoi(temp); - tyear = l_date->tm_year + 1900; + /* + * First check length of string + */ + if (strlen(DOB) != 10) { + Syslog('!', "Date format length %d characters", strlen(DOB)); + /* Please enter the correct date format */ + language(14, 0, 83); + return FALSE; + } + + /* + * Split the date into pieces + */ + strcpy(temp1, DOB); + strcpy(temp, strtok(temp1, "-")); + day = atoi(temp); + strcpy(temp, strtok(NULL, "-")); + month = atoi(temp); + strcpy(temp, strtok(NULL, "")); + year = atoi(temp); + tyear = l_date->tm_year + 1900; - if (((tyear - year) < 10) || ((tyear - year) > 95)) { - Syslog('!', "DOB: Year error: %d", tyear - year); - return FALSE; - } - if ((month < 1) || (month > 12)) { - Syslog('!', "DOB: Month error: %d", month); - return FALSE; - } - if ((day < 1) || (day > 31)) { - Syslog('!', "DOB: Day error: %d", day); - return FALSE; - } + if (((tyear - year) < 10) || ((tyear - year) > 95)) { + Syslog('!', "DOB: Year error: %d", tyear - year); + return FALSE; + } + if ((month < 1) || (month > 12)) { + Syslog('!', "DOB: Month error: %d", month); + return FALSE; + } + if ((day < 1) || (day > 31)) { + Syslog('!', "DOB: Day error: %d", day); + return FALSE; + } - UserAge = tyear - year; - if ((l_date->tm_mon + 1) < month) - UserAge--; - if (((l_date->tm_mon + 1) == month) && (l_date->tm_mday < day)) - UserAge--; - Syslog('B', "DOB: Users age %d year", UserAge); - return TRUE; + UserAge = tyear - year; + if ((l_date->tm_mon + 1) < month) + UserAge--; + if (((l_date->tm_mon + 1) == month) && (l_date->tm_mday < day)) + UserAge--; + Syslog('B', "DOB: Users age %d year", UserAge); + return TRUE; } void Chg_DOB() { - char *temp; + char *temp; - if (!CFG.iDOB) - return; + if (!CFG.iDOB) + return; - temp = calloc(81, sizeof(char)); - ReadExitinfo(); - Syslog('+', "Old DOB %s", exitinfo.sDateOfBirth); + temp = calloc(81, sizeof(char)); + ReadExitinfo(); + Syslog('+', "Old DOB %s", exitinfo.sDateOfBirth); - while (TRUE) { - Enter(1); - /* Please enter your Date of Birth DD-MM-YYYY: */ - pout(3, 0, (char *) Language(56)); - colour(CFG.InputColourF, CFG.InputColourB); - GetDate(temp, 10); - if (Test_DOB(temp)) { - Setup(exitinfo.sDateOfBirth, temp); - break; - } + while (TRUE) { + Enter(1); + /* Please enter your Date of Birth DD-MM-YYYY: */ + pout(3, 0, (char *) Language(56)); + colour(CFG.InputColourF, CFG.InputColourB); + GetDate(temp, 10); + if (Test_DOB(temp)) { + Setup(exitinfo.sDateOfBirth, temp); + break; } + } - Syslog('+', "New DOB %s", exitinfo.sDateOfBirth); - WriteExitinfo(); - free(temp); + Syslog('+', "New DOB %s", exitinfo.sDateOfBirth); + WriteExitinfo(); + free(temp); } @@ -837,130 +843,137 @@ void Chg_DOB() */ void Chg_Protocol() { - FILE *pProtConfig; - int iProt, iFoundProt = FALSE; - int precno = 0; - char *temp; - char Prot[2]; + FILE *pProtConfig; + int iProt, iFoundProt = FALSE, precno = 0; + char *temp, Prot[2]; - temp = calloc(PATH_MAX, sizeof(char)); - ReadExitinfo(); - Syslog('+', "Old protocol %s", sProtName); + temp = calloc(PATH_MAX, sizeof(char)); + ReadExitinfo(); + Syslog('+', "Old protocol %s", sProtName); - while(TRUE) { - sprintf(temp, "%s/etc/protocol.data", getenv("MBSE_ROOT")); + while(TRUE) { + sprintf(temp, "%s/etc/protocol.data", getenv("MBSE_ROOT")); - if ((pProtConfig = fopen(temp, "r")) == NULL) { - WriteError("$Can't open %s", temp); - /* Protocol: Can't open protocol file. */ - printf("\n%s\n\n", (char *) Language(262)); - Pause(); - free(temp); - fclose(pProtConfig); - return; - } - fread(&PROThdr, sizeof(PROThdr), 1, pProtConfig); + if ((pProtConfig = fopen(temp, "r")) == NULL) { + WriteError("$Can't open %s", temp); + /* Protocol: Can't open protocol file. */ + Enter(1); + PUTSTR((char *) Language(262)); + Enter(2); + Pause(); + free(temp); + fclose(pProtConfig); + return; + } + fread(&PROThdr, sizeof(PROThdr), 1, pProtConfig); - colour(CFG.HiliteF, CFG.HiliteB); - /* Select your preferred protocol */ - printf("\n%s\n\n", (char *) Language(263)); + Enter(1); + /* Select your preferred protocol */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(263)); + Enter(2); - colour(9,0); - while (fread(&PROT, PROThdr.recsize, 1, pProtConfig) == 1) - if (PROT.Available && Access(exitinfo.Security, PROT.Level)) - printf("(%s) %-20s Efficiency %3d %%\n", PROT.ProtKey, PROT.ProtName, PROT.Efficiency); + colour(9,0); + while (fread(&PROT, PROThdr.recsize, 1, pProtConfig) == 1) { + if (PROT.Available && Access(exitinfo.Security, PROT.Level)) { + sprintf(temp, "(%s) %-20s Efficiency %3d %%\r\n", PROT.ProtKey, PROT.ProtName, PROT.Efficiency); + PUTSTR(temp); + } + } + + Enter(1); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(264)); - colour(CFG.HiliteF, CFG.HiliteB); - printf("\n%s", (char *) Language(264)); + alarm_on(); + iProt = toupper(Readkey()); - fflush(stdout); - alarm_on(); - iProt = toupper(Getone()); + PUTCHAR(iProt); + sprintf(Prot, "%c", iProt); - printf("%c", iProt); - sprintf(Prot, "%c", iProt); - - fseek(pProtConfig, PROThdr.hdrsize, 0); - while (fread(&PROT, PROThdr.recsize, 1, pProtConfig) == 1) { - if ((strncmp(PROT.ProtKey, Prot, 1) == 0) && - PROT.Available && Access(exitinfo.Security, PROT.Level)) { - strcpy(sProtName, PROT.ProtName); - strcpy(sProtUp, PROT.ProtUp); - strcpy(sProtDn, PROT.ProtDn); - strcpy(sProtAdvice, PROT.Advice); - uProtBatch = PROT.Batch; - uProtBidir = PROT.Bidir; - iProtEfficiency = PROT.Efficiency; - iFoundProt = TRUE; - } else - precno++; - } - - fclose(pProtConfig); - - if (iProt == 13) { - free(temp); - return; - } else - if (!iFoundProt) { - Enter(2); - pout(10, 0, (char *) Language(265)); - Enter(2); - /* Loop for new attempt */ - } else { - Setup(exitinfo.sProtocol, sProtName); - colour(10,0); - /* Protocol now set to: */ - printf("\n\n%s%s\n\n", (char *) Language(266), sProtName); - Pause(); - break; - } + fseek(pProtConfig, PROThdr.hdrsize, 0); + while (fread(&PROT, PROThdr.recsize, 1, pProtConfig) == 1) { + if ((strncmp(PROT.ProtKey, Prot, 1) == 0) && PROT.Available && Access(exitinfo.Security, PROT.Level)) { + strcpy(sProtName, PROT.ProtName); + strcpy(sProtUp, PROT.ProtUp); + strcpy(sProtDn, PROT.ProtDn); + strcpy(sProtAdvice, PROT.Advice); + uProtBatch = PROT.Batch; + uProtBidir = PROT.Bidir; + iProtEfficiency = PROT.Efficiency; + iFoundProt = TRUE; + } else + precno++; } - Syslog('+', "New protocol %s", sProtName); - WriteExitinfo(); - free(temp); + fclose(pProtConfig); + + if (iProt == 13) { + free(temp); + return; + } else { + if (!iFoundProt) { + Enter(2); + pout(10, 0, (char *) Language(265)); + Enter(2); + /* Loop for new attempt */ + } else { + Setup(exitinfo.sProtocol, sProtName); + Enter(1); + /* Protocol now set to: */ + pout(10, 0, (char *) Language(266)); + PUTSTR(sProtName); + Enter(2); + Pause(); + break; + } + } + } + + Syslog('+', "New protocol %s", sProtName); + WriteExitinfo(); + free(temp); } void Set_Protocol(char *Protocol) { - FILE *pProtConfig; - int precno = 0; - char *temp; + FILE *pProtConfig; + int precno = 0; + char *temp; - temp = calloc(PATH_MAX, sizeof(char)); + temp = calloc(PATH_MAX, sizeof(char)); - sprintf(temp, "%s/etc/protocol.data", getenv("MBSE_ROOT")); + sprintf(temp, "%s/etc/protocol.data", getenv("MBSE_ROOT")); - if(( pProtConfig = fopen(temp, "rb")) == NULL) { - WriteError("$Can't open %s", temp); - /* Protocol: Can't open protocol file. */ - printf("\n%s\n\n", (char *) Language(262)); - Pause(); - free(temp); - return; - } + if(( pProtConfig = fopen(temp, "rb")) == NULL) { + WriteError("$Can't open %s", temp); + Enter(1); + /* Protocol: Can't open protocol file. */ + pout(LIGHTRED, BLACK, (char *) Language(262)); + Enter(2); + Pause(); + free(temp); + return; + } - fread(&PROThdr, sizeof(PROThdr), 1, pProtConfig); + fread(&PROThdr, sizeof(PROThdr), 1, pProtConfig); - while (fread(&PROT, PROThdr.recsize, 1, pProtConfig) == 1) { - if ((strcmp(PROT.ProtName, Protocol)) == 0) { - tlf(sProtName); - strcpy(sProtName, PROT.ProtName); - strcpy(sProtUp, PROT.ProtUp); - strcpy(sProtDn, PROT.ProtDn); - strcpy(sProtAdvice, PROT.Advice); - uProtBatch = PROT.Batch; - uProtBidir = PROT.Bidir; - iProtEfficiency = PROT.Efficiency; - } else - precno++; - } + while (fread(&PROT, PROThdr.recsize, 1, pProtConfig) == 1) { + if ((strcmp(PROT.ProtName, Protocol)) == 0) { + tlf(sProtName); + strcpy(sProtName, PROT.ProtName); + strcpy(sProtUp, PROT.ProtUp); + strcpy(sProtDn, PROT.ProtDn); + strcpy(sProtAdvice, PROT.Advice); + uProtBatch = PROT.Batch; + uProtBidir = PROT.Bidir; + iProtEfficiency = PROT.Efficiency; + } else + precno++; + } - free(temp); - fclose(pProtConfig); + free(temp); + fclose(pProtConfig); } @@ -968,16 +981,19 @@ void Set_Protocol(char *Protocol) void Chg_OLR_ExtInfo() { ReadExitinfo(); + Enter(2); if (exitinfo.OL_ExtInfo) { exitinfo.OL_ExtInfo = FALSE; /* Offline Reader: Extended Info turned OFF */ - printf("\n\n%s\n\n", (char *) Language(16)); + pout(GREEN, BLACK, (char *) Language(16)); } else { exitinfo.OL_ExtInfo = TRUE; /* Offline Reader: Extended Info turned ON */ - printf("\n\n%s\n\n", (char *) Language(15)); + pout(GREEN, BLACK, (char *) Language(15)); } + + Enter(2); Syslog('+', "OLR Extended Info now %s", exitinfo.OL_ExtInfo?"True":"False"); sleep(2); WriteExitinfo(); @@ -998,25 +1014,28 @@ void Chg_Charset() Syslog('+', "Old character set %s", getchrs(exitinfo.Charset)); while(TRUE) { - colour(CFG.HiliteF, CFG.HiliteB); + Enter(1); /* Select your preferred character set */ - printf("\n%s\n\n", (char *) Language(23)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(23)); + Enter(2); colour(LIGHTBLUE, BLACK); for (i = (FTNC_NONE + 1); i <= FTNC_MAXCHARS; i++) { colour(LIGHTBLUE, BLACK); - printf("%2d ", i); + sprintf(temp, "%2d ", i); + PUTSTR(temp); colour(LIGHTCYAN, BLACK); - printf("%-9s ", getchrs(i)); + sprintf(temp, "%-9s ", getchrs(i)); + PUTSTR(temp); colour(LIGHTMAGENTA, BLACK); - printf("%s\n", getchrsdesc(i)); + sprintf(temp, "%s\r\n", getchrsdesc(i)); + PUTSTR(temp); } - colour(CFG.HiliteF, CFG.HiliteB); + Enter(1); /* Select character set (Enter to Quit): */ - printf("\n%s", (char *) Language(24)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(24)); - fflush(stdout); Getnum(temp, 2); if (((strcmp(temp, "")) == 0) && (exitinfo.Charset != FTNC_NONE)) { @@ -1030,10 +1049,13 @@ void Chg_Charset() exitinfo.Charset = i; Syslog('+', "New character set %s", getchrs(exitinfo.Charset)); WriteExitinfo(); - free(temp); + Enter(2); colour(LIGHTGREEN, BLACK); /* Character set now set to: */ - printf("\n\n%s%s\n\n", (char *) Language(25), getchrs(i)); + sprintf(temp, "%s%s", (char *) Language(25), getchrs(i)); + PUTSTR(temp); + free(temp); + Enter(2); Pause(); return; } diff --git a/mbsebbs/chat.c b/mbsebbs/chat.c index 76a1d562..162e7f4b 100644 --- a/mbsebbs/chat.c +++ b/mbsebbs/chat.c @@ -39,6 +39,7 @@ #include "misc.h" #include "whoson.h" #include "term.h" +#include "ttyio.h" int chat_with_sysop = FALSE; /* Global sysop chat flag */ @@ -63,21 +64,12 @@ unsigned char testkey(int y, int x) Nopper(); locate(y, x); - fflush(stdout); - - if ((ttyfd = open("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - perror("open /dev/tty"); - exit(MBERR_TTYIO_ERROR); - } - Setraw(); rc = Waitchar(&ch, 50); if (rc == 1) { if (ch == KEY_ESCAPE) rc = Escapechar(&ch); } - Unsetraw(); - close(ttyfd); if (rc == 1) return ch; else @@ -97,15 +89,15 @@ void Showline(int y, int x, char *msg) if (msg[0] == '<') { locate(y, x); colour(LIGHTCYAN, BLACK); - putchar('<'); + PUTCHAR('<'); colour(LIGHTBLUE, BLACK); for (i = 1; i < strlen(msg); i++) { if (msg[i] == '>') { colour(LIGHTCYAN, BLACK); - putchar(msg[i]); + PUTCHAR(msg[i]); colour(CYAN, BLACK); } else { - putchar(msg[i]); + PUTCHAR(msg[i]); } } } else if (msg[0] == '*') { @@ -142,7 +134,6 @@ void DispMsg(char *msg) } else { rpointer++; } - fflush(stdout); } @@ -152,7 +143,7 @@ void DispMsg(char *msg) */ void clrtoeol(void) { - fprintf(stdout, ANSI_CLREOL); + PUTSTR((char *)ANSI_CLREOL); } @@ -178,15 +169,14 @@ void Chat(char *username, char *channel) if (username && channel) { colour(LIGHTGREEN, BLACK); + PUTCHAR('\007'); /* *** Sysop is starting chat *** */ - printf("\007%s\n\r", (char *) Language(59)); - fflush(stdout); + pout(LIGHTGREEN, BLACK, (char *) Language(59)); + Enter(1); sleep(1); - printf("\007"); - fflush(stdout); + PUTCHAR('\007'); sleep(1); - printf("\007"); - fflush(stdout); + PUTCHAR('\007'); Syslog('+', "Sysop chat started"); chat_with_sysop = TRUE; } else { @@ -200,7 +190,8 @@ void Chat(char *username, char *channel) locate(1, 1); colour(WHITE, BLUE); clrtoeol(); - mvprintw(1, 2, "MBSE BBS Chat Server"); + sprintf(buf, "%-*s", 79, " MBSE BBS Chat Server"); + mvprintw(1, 1, buf); sprintf(buf, "CCON,3,%d,%s,0;", mypid, exitinfo.Name); Syslog('c', "> %s", buf); @@ -223,7 +214,8 @@ void Chat(char *username, char *channel) locate(exitinfo.iScreenLen - 2, 1); colour(WHITE, BLUE); clrtoeol(); - mvprintw(exitinfo.iScreenLen - 2, 2, "Chat, type \"/EXIT\" to exit"); + sprintf(buf, "%-*s", 79, " Chat, type \"/EXIT\" to exit or \"/HELP\" for help"); + mvprintw(exitinfo.iScreenLen - 2, 1, buf); colour(LIGHTGRAY, BLACK); mvprintw(exitinfo.iScreenLen - 1, 1, ">"); @@ -287,21 +279,19 @@ void Chat(char *username, char *channel) ch = testkey(exitinfo.iScreenLen -1, curpos + 2); if (isprint(ch)) { if (curpos < 77) { - putchar(ch); - fflush(stdout); + PUTCHAR(ch); sbuf[curpos] = ch; curpos++; } else { - putchar(7); - fflush(stdout); + PUTCHAR(7); } } else if ((ch == KEY_BACKSPACE) || (ch == KEY_RUBOUT) || (ch == KEY_DEL)) { if (curpos) { curpos--; sbuf[curpos] = '\0'; - printf("\b \b"); + BackErase(); } else { - putchar(7); + PUTCHAR(7); } } else if ((ch == '\r') && curpos) { sprintf(buf, "CPUT:2,%d,%s;", mypid, sbuf); diff --git a/mbsebbs/dispfile.c b/mbsebbs/dispfile.c index dc04bd5e..1bec7360 100644 --- a/mbsebbs/dispfile.c +++ b/mbsebbs/dispfile.c @@ -47,6 +47,7 @@ #include "dispfile.h" #include "filesub.h" #include "term.h" +#include "ttyio.h" /* @@ -55,28 +56,28 @@ int TotalUsers(void); int TotalUsers(void) { - FILE *pUsrConfig; - int ch = 0; - char *temp; - struct userhdr uhdr; - struct userrec u; + FILE *pUsrConfig; + int ch = 0; + char *temp; + struct userhdr uhdr; + struct userrec u; - temp = calloc(PATH_MAX, sizeof(char)); - sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT")); - if(( pUsrConfig = fopen(temp,"rb")) == NULL) - WriteError("ControlCodeK: Can't open users file %s for reading", temp); - else { - fread(&uhdr, sizeof(uhdr), 1, pUsrConfig); + temp = calloc(PATH_MAX, sizeof(char)); + sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT")); + if(( pUsrConfig = fopen(temp,"rb")) == NULL) + WriteError("ControlCodeK: Can't open users file %s for reading", temp); + else { + fread(&uhdr, sizeof(uhdr), 1, pUsrConfig); - while (fread(&u, uhdr.recsize, 1, pUsrConfig) == 1) - if ((!u.Deleted) && (strlen(u.sUserName) > 0)) - ch++; + while (fread(&u, uhdr.recsize, 1, pUsrConfig) == 1) + if ((!u.Deleted) && (strlen(u.sUserName) > 0)) + ch++; - fclose(pUsrConfig); - } - free(temp); + fclose(pUsrConfig); + } + free(temp); - return ch; + return ch; } @@ -100,8 +101,10 @@ void DisplayRules(void) if ((dp = opendir(CFG.rulesdir)) == NULL) { WriteError("$Can't open directory %s", CFG.rulesdir); + Enter(1); /* Can't open directory for listing: */ - printf("\n%s\n\n", (char *) Language(290)); + pout(LIGHTRED, BLACK, (char *) Language(290)); + Enter(2); Pause(); return; } @@ -138,9 +141,9 @@ void DisplayRules(void) } else { Syslog('+', "Display rules for %s failed, not found", msgs.Tag); Enter(1); - colour(LIGHTRED, BLACK); /* No rules found for this area */ - printf("\n%s\n\n", (char *) Language(13)); + pout(LIGHTRED, BLACK, (char *) Language(13)); + Enter(2); Pause(); } } @@ -155,9 +158,10 @@ void DisplayRules(void) */ int DisplayTextFile(char *filename) { - FILE *fp; - char *buf; - int i, x, c, z, lc = 0; + FILE *fp; + char *buf; + int i, x, z, lc = 0; + unsigned char c; if ((fp = fopen(filename, "r")) == NULL) { WriteError("$DisplayTextFile(%s) failed"); @@ -172,26 +176,23 @@ int DisplayTextFile(char *filename) i = strlen(buf); for (x = 0; x < i; x++) { - c = (*(buf + x)); + c = (*(buf + x) & 0xff); if (isprint(c)) - printf("%c", c); + PUTCHAR(c); } - printf("\n"); - fflush(stdout); + Enter(1); lc++; if ((lc >= exitinfo.iScreenLen) && (lc < 1000)) { lc = 0; /* More (Y/n/=) */ pout(CFG.MoreF, CFG.MoreB, (char *) Language(61)); - fflush(stdout); alarm_on(); - z = toupper(Getone()); + z = toupper(Readkey()); if (z == Keystroke(61, 1)) { - printf("\n"); - fflush(stdout); + Enter(1); fclose(fp); free(buf); return TRUE; @@ -211,10 +212,8 @@ int DisplayTextFile(char *filename) Enter(1); /* Press ENTER to continue */ language(CFG.MoreF, CFG.MoreB, 436); - fflush(stdout); - fflush(stdin); alarm_on(); - Getone(); + Readkey(); return TRUE; } @@ -228,11 +227,12 @@ int DisplayTextFile(char *filename) */ int DisplayFile(char *filename) { - FILE *pFileName; - long iSec = 0; - char *sFileName, *tmp, *tmp1, newfile[PATH_MAX]; - int i, x; - + FILE *pFileName; + long iSec = 0; + char *sFileName, *tmp, *tmp1, newfile[PATH_MAX]; + int i, x; + unsigned char c; + sFileName = calloc(16385, sizeof(char)); tmp = calloc(PATH_MAX, sizeof(char)); tmp1 = calloc(PATH_MAX, sizeof(char)); @@ -272,7 +272,8 @@ int DisplayFile(char *filename) i = fread(sFileName, sizeof(char), 16384, pFileName); for (x = 0; x < i; x++) { - switch(*(sFileName + x)) { + c = *(sFileName + x) & 0xff; + switch (c) { case '': ControlCodeU(sFileName[++x]); break; @@ -282,10 +283,8 @@ int DisplayFile(char *filename) case ' ': ControlCodeK(sFileName[++x]); break; - case '': fflush(stdout); - fflush(stdin); - alarm_on(); - Getone(); + case '': alarm_on(); + Readkey(); break; case '': /* @@ -306,16 +305,20 @@ int DisplayFile(char *filename) iSec = atoi(tmp1); while ((x <= i) && (*(sFileName + x) != '')) { if (exitinfo.Security.level >= iSec) - printf("%c", *(sFileName + x)); + PUTCHAR(*(sFileName + x)); x++; } break; - case '': fflush(stdout); - sleep(1); + case '': sleep(1); break; - default: printf("%c", *(sFileName + x)); + case '\n': Enter(1); /* Insert , we are in raw mode */ + break; + + case '\r': break; /* If the file has chars (DOS), eat them */ + + default: PUTCHAR(*(sFileName + x)); } /* switch */ } /* for */ @@ -338,10 +341,8 @@ int DisplayFileEnter(char *File) Enter(1); /* Press ENTER to continue */ language(13, 0, 436); - fflush(stdout); - fflush(stdin); alarm_on(); - Getone(); + Readkey(); return rc; } @@ -349,325 +350,333 @@ int DisplayFileEnter(char *File) void ControlCodeF(int ch) { - /* Update user info */ - ReadExitinfo(); + char temp[81]; + + /* Update user info */ + ReadExitinfo(); - switch (toupper(ch)) { + switch (toupper(ch)) { case '!': - printf(exitinfo.sProtocol); + sprintf(temp, "%s", exitinfo.sProtocol); break; case 'A': - printf("%ld", exitinfo.Uploads); + sprintf(temp, "%ld", exitinfo.Uploads); break; case 'B': - printf("%ld", exitinfo.Downloads); + sprintf(temp, "%ld", exitinfo.Downloads); break; case 'C': - printf("%lu", exitinfo.DownloadK); + sprintf(temp, "%lu", exitinfo.DownloadK); break; case 'D': - printf("%lu", exitinfo.UploadK); + sprintf(temp, "%lu", exitinfo.UploadK); break; case 'E': - printf("%lu", exitinfo.DownloadK + exitinfo.UploadK); + sprintf(temp, "%lu", exitinfo.DownloadK + exitinfo.UploadK); break; case 'F': - printf("%lu", LIMIT.DownK); + sprintf(temp, "%lu", LIMIT.DownK); break; case 'G': - printf("%d", exitinfo.iTransferTime); + sprintf(temp, "%d", exitinfo.iTransferTime); break; case 'H': - printf("%d", iAreaNumber); + sprintf(temp, "%d", iAreaNumber); break; case 'I': - printf(sAreaDesc); + sprintf(temp, "%s", sAreaDesc); break; case 'J': - printf("%u", LIMIT.DownF); + sprintf(temp, "%u", LIMIT.DownF); break; case 'K': - printf("%s", LIMIT.Description); + sprintf(temp, "%s", LIMIT.Description); break; default: - printf(" "); - } + sprintf(temp, " "); + } + PUTSTR(temp); } void ControlCodeU(int ch) { - /* - * Update user info - */ - TimeCheck(); - ReadExitinfo(); + char temp[81]; + + /* + * Update user info + */ + TimeCheck(); + ReadExitinfo(); - switch (toupper(ch)) { + switch (toupper(ch)) { case 'A': - printf("%s", exitinfo.sUserName); + sprintf(temp, "%s", exitinfo.sUserName); break; case 'B': - printf(exitinfo.sLocation); + sprintf(temp, "%s", exitinfo.sLocation); break; case 'C': - printf(exitinfo.sVoicePhone); + sprintf(temp, "%s", exitinfo.sVoicePhone); break; case 'D': - printf(exitinfo.sDataPhone); + sprintf(temp, "%s", exitinfo.sDataPhone); break; case 'E': - printf(LastLoginDate); + sprintf(temp, "%s", LastLoginDate); break; case 'F': - printf("%s %s", StrDateDMY(exitinfo.tFirstLoginDate), StrTimeHMS(exitinfo.tFirstLoginDate)); + sprintf(temp, "%s %s", StrDateDMY(exitinfo.tFirstLoginDate), StrTimeHMS(exitinfo.tFirstLoginDate)); break; case 'G': - printf(LastLoginTime); + sprintf(temp, "%s", LastLoginTime); break; case 'H': - printf("%d", exitinfo.Security.level); + sprintf(temp, "%d", exitinfo.Security.level); break; case 'I': - printf("%d", exitinfo.iTotalCalls); + sprintf(temp, "%d", exitinfo.iTotalCalls); break; case 'J': - printf("%d", exitinfo.iTimeUsed); + sprintf(temp, "%d", exitinfo.iTimeUsed); break; case 'K': - printf("%d", exitinfo.iConnectTime); + sprintf(temp, "%d", exitinfo.iConnectTime); break; case 'L': - printf("%d", exitinfo.iTimeLeft); + sprintf(temp, "%d", exitinfo.iTimeLeft); break; case 'M': - printf("%d", exitinfo.iScreenLen); + sprintf(temp, "%d", exitinfo.iScreenLen); break; case 'N': - printf(FirstName); + sprintf(temp, "%s", FirstName); break; case 'O': - printf(LastName); + sprintf(temp, "%s", LastName); break; case 'Q': - printf("%s", exitinfo.ieNEWS ? (char *) Language(147) : (char *) Language(148)); + sprintf(temp, "%s", exitinfo.ieNEWS ? (char *) Language(147) : (char *) Language(148)); break; case 'P': - printf("%s", exitinfo.GraphMode ? (char *) Language(147) : (char *) Language(148)); + sprintf(temp, "%s", exitinfo.GraphMode ? (char *) Language(147) : (char *) Language(148)); break; case 'R': - printf("%s", exitinfo.HotKeys ? (char *) Language(147) : (char *) Language(148)); + sprintf(temp, "%s", exitinfo.HotKeys ? (char *) Language(147) : (char *) Language(148)); break; case 'S': - printf("%d", exitinfo.iTimeUsed + exitinfo.iTimeLeft); + sprintf(temp, "%d", exitinfo.iTimeUsed + exitinfo.iTimeLeft); break; case 'T': - printf(exitinfo.sDateOfBirth); + sprintf(temp, "%s", exitinfo.sDateOfBirth); break; case 'U': - printf("%d", exitinfo.iPosted); + sprintf(temp, "%d", exitinfo.iPosted); break; case 'X': - printf(lang.Name); + sprintf(temp, "%s", lang.Name); break; case 'Y': - printf(exitinfo.sHandle); + sprintf(temp, "%s", exitinfo.sHandle); break; case 'Z': - printf("%s", exitinfo.DoNotDisturb ? (char *) Language(147) : (char *) Language(148)); + sprintf(temp, "%s", exitinfo.DoNotDisturb ? (char *) Language(147) : (char *) Language(148)); break; case '1': - printf("%s", exitinfo.MailScan ? (char *) Language(147) : (char *) Language(148)); + sprintf(temp, "%s", exitinfo.MailScan ? (char *) Language(147) : (char *) Language(148)); break; case '2': - printf("%s", exitinfo.ieFILE ? (char *) Language(147) : (char *) Language(148)); + sprintf(temp, "%s", exitinfo.ieFILE ? (char *) Language(147) : (char *) Language(148)); break; case '3': switch(exitinfo.MsgEditor) { - case LINEEDIT: printf(Language(387)); + case LINEEDIT: sprintf(temp, "%s", Language(387)); break; - case FSEDIT: printf(Language(388)); + case FSEDIT: sprintf(temp, "%s", Language(388)); break; - case EXTEDIT: printf(Language(389)); + case EXTEDIT: sprintf(temp, "%s", Language(389)); break; - default: printf("?"); + default: sprintf(temp, "?"); } break; case '4': - printf("%s", exitinfo.FSemacs ? (char *) Language(147) : (char *) Language(148)); + sprintf(temp, "%s", exitinfo.FSemacs ? (char *) Language(147) : (char *) Language(148)); break; case '5': - printf(exitinfo.address[0]); + sprintf(temp, "%s", exitinfo.address[0]); break; case '6': - printf(exitinfo.address[1]); + sprintf(temp, "%s", exitinfo.address[1]); break; case '7': - printf(exitinfo.address[2]); + sprintf(temp, "%s", exitinfo.address[2]); break; case '8': - printf("%s", exitinfo.OL_ExtInfo ? (char *) Language(147) : (char *) Language(148)); + sprintf(temp, "%s", exitinfo.OL_ExtInfo ? (char *) Language(147) : (char *) Language(148)); break; case '9': - printf("%s", getchrs(exitinfo.Charset)); + sprintf(temp, "%s", getchrs(exitinfo.Charset)); break; default: - printf(" "); - } + sprintf(temp, " "); + } + PUTSTR(temp); } void ControlCodeK(int ch) { - FILE *pCallerLog; - char sDataFile[PATH_MAX]; - lastread LR; + FILE *pCallerLog; + char sDataFile[PATH_MAX], temp[81]; + lastread LR; - switch (toupper(ch)) { + switch (toupper(ch)) { case 'A': - printf("%s", (char *) GetDateDMY()); + sprintf(temp, "%s", (char *) GetDateDMY()); break; case 'B': - printf("%s", (char *) GetLocalHMS()); + sprintf(temp, "%s", (char *) GetLocalHMS()); break; case 'C': - printf("%s", (char *) GLCdate()); + sprintf(temp, "%s", (char *) GLCdate()); break; case 'D': - printf("%s", (char *) GLCdateyy()); + sprintf(temp, "%s", (char *) GLCdateyy()); break; case 'E': - printf("%ld", Speed()); + sprintf(temp, "%ld", Speed()); break; case 'F': - printf("%s", LastCaller); + sprintf(temp, "%s", LastCaller); break; case 'G': - printf("%d", TotalUsers()); + sprintf(temp, "%d", TotalUsers()); break; case 'H': sprintf(sDataFile, "%s/etc/sysinfo.data", getenv("MBSE_ROOT")); if((pCallerLog = fopen(sDataFile, "rb")) != NULL) { - fread(&SYSINFO, sizeof(SYSINFO), 1, pCallerLog); - printf("%ld", SYSINFO.SystemCalls); - fclose(pCallerLog); + fread(&SYSINFO, sizeof(SYSINFO), 1, pCallerLog); + sprintf(temp, "%ld", SYSINFO.SystemCalls); + fclose(pCallerLog); } break; case 'I': - printf("%d", iMsgAreaNumber + 1); + sprintf(temp, "%d", iMsgAreaNumber + 1); break; case 'J': - printf(sMsgAreaDesc); + sprintf(temp, "%s", sMsgAreaDesc); break; case 'K': - printf("%s", Oneliner_Get()); + sprintf(temp, "%s", Oneliner_Get()); break; case 'L': SetMsgArea(iMsgAreaNumber); - printf("%ld", MsgBase.Total); + sprintf(temp, "%ld", MsgBase.Total); break; case 'M': LR.UserID = grecno; if (Msg_Open(sMsgAreaBase)) { - if (Msg_GetLastRead(&LR) == TRUE) { - if (LR.HighReadMsg > MsgBase.Highest) - LR.HighReadMsg = MsgBase.Highest; - printf("%ld", LR.HighReadMsg); - } else - printf("?"); - Msg_Close(); + if (Msg_GetLastRead(&LR) == TRUE) { + if (LR.HighReadMsg > MsgBase.Highest) + LR.HighReadMsg = MsgBase.Highest; + sprintf(temp, "%ld", LR.HighReadMsg); + } else + sprintf(temp, "?"); + Msg_Close(); } break; case 'N': - printf("%s", sMailbox); + sprintf(temp, "%s", sMailbox); break; case 'O': SetEmailArea(sMailbox); - printf("%ld", EmailBase.Total); + sprintf(temp, "%ld", EmailBase.Total); break; case 'P': sprintf(sDataFile, "%s/%s/%s", CFG.bbs_usersdir, exitinfo.Name, sMailbox); LR.UserID = grecno; if (Msg_Open(sDataFile)) { - if (Msg_GetLastRead(&LR) == TRUE) { - if (LR.HighReadMsg > EmailBase.Highest) - LR.HighReadMsg = EmailBase.Highest; - printf("%ld", LR.HighReadMsg); - } else - printf("?"); - Msg_Close(); + if (Msg_GetLastRead(&LR) == TRUE) { + if (LR.HighReadMsg > EmailBase.Highest) + LR.HighReadMsg = EmailBase.Highest; + sprintf(temp, "%ld", LR.HighReadMsg); + } else + sprintf(temp, "?"); + Msg_Close(); } break; case 'Q': - printf("%s %s", StrDateDMY(LastCallerTime), StrTimeHMS(LastCallerTime)); + sprintf(temp, "%s %s", StrDateDMY(LastCallerTime), StrTimeHMS(LastCallerTime)); break; default: - printf(" "); + sprintf(temp, " "); - } + } + + PUTSTR(temp); } diff --git a/mbsebbs/door.c b/mbsebbs/door.c index e21116de..4435c88d 100644 --- a/mbsebbs/door.c +++ b/mbsebbs/door.c @@ -39,6 +39,8 @@ #include "whoson.h" #include "door.h" #include "term.h" +#include "ttyio.h" +#include "openport.h" extern time_t t_start; @@ -128,9 +130,10 @@ void ExtDoor(char *Program, int NoDoorsys, int Y2Kdoorsys, int Comport, int NoSu strtok(NULL, ","); /* location */ if (strcmp(strtok(NULL, ","), menus.DoorName) == 0) { Syslog('+', "User tried single user door %s, but door is in use", menus.DoorName); - colour(LIGHTRED, BLACK); + Enter(1); /* The door is in use by another user, try again later */ - printf("\n%s\n\n", (char *) Language(20)); + pout(LIGHTRED, BLACK, (char *) Language(20)); + Enter(2); Pause(); free(temp1); free(String); @@ -149,14 +152,14 @@ void ExtDoor(char *Program, int NoDoorsys, int Y2Kdoorsys, int Comport, int NoSu } if ((strstr(Program, "/A")) != NULL) { + Enter(1); colour(3, 0); if ((String = strstr(Program, "/T=")) != NULL) { String1 = String + 3; - printf("\n%s", String1); + PUTSTR(String1); } else - printf("\nPlease enter filename: "); + PUTSTR((char *)"Please enter filename: "); - fflush(stdout); colour(CFG.InputColourF, CFG.InputColourB); GetstrC(temp1, 80); @@ -288,19 +291,32 @@ void ExtDoor(char *Program, int NoDoorsys, int Y2Kdoorsys, int Comport, int NoSu } clear(); - printf("Loading ...\n\n"); + PUTSTR((char *)"Loading ..."); + Enter(2); + + /* + * Put terminal back in cooked mode, prefered by some doors. + */ + cookedport(); + if (NoSuid) rc = exec_nosuid(Program); else rc = execute_str((char *)"/bin/sh", (char *)"-c", Program, NULL, NULL, NULL); + /* + * Restore raw mode if needed, some doors put the terminal + * back in cooked mode. + */ + rawport(); + Altime(0); alarm_off(); alarm_on(); Syslog('+', "Door end, rc=%d", rc); free(temp1); - printf("\n\n"); + Enter(2); if (!NoPrompt) Pause(); diff --git a/mbsebbs/email.c b/mbsebbs/email.c index d253bc7c..e83daca0 100644 --- a/mbsebbs/email.c +++ b/mbsebbs/email.c @@ -44,6 +44,8 @@ #include "email.h" #include "whoson.h" #include "term.h" +#include "ttyio.h" + extern unsigned long LastNum; extern int Kludges; @@ -66,13 +68,14 @@ int Save_Email(int); int HasNoEmail(void) { - if (exitinfo.Email) - return FALSE; + if (exitinfo.Email) + return FALSE; - colour(15, 0); - printf("\nYou have no e-mail access\n\n"); - sleep(3); - return TRUE; + Enter(1); + pout(WHITE, BLACK, (char *)"You have no e-mail access"); + Enter(2); + sleep(3); + return TRUE; } @@ -82,164 +85,166 @@ int HasNoEmail(void) */ void ShowEmailHdr(void) { - static char Buf1[35], Buf2[35], Buf3[81]; - struct tm *tm; + static char Buf1[35], Buf2[35], Buf3[81], temp[81]; + struct tm *tm; - Buf1[0] = '\0'; - Buf2[0] = '\0'; - Buf3[0] = '\0'; + Buf1[0] = '\0'; + Buf2[0] = '\0'; + Buf3[0] = '\0'; - clear(); - colour(1,7); - printf(" %-70s", sMailbox); + clear(); + sprintf(temp, " %-70s", sMailbox); + pout(1, 7, temp); - colour(4,7); - printf("#%-5lu\n", Msg.Id); + sprintf(temp, "#%-5lu", Msg.Id); + pout(4, 7, temp); + Enter(1); - /* Date : */ - pout(14, 0, (char *) Language(206)); - colour(10, 0); - tm = gmtime(&Msg.Written); - printf("%02d-%02d-%d %02d:%02d:%02d", tm->tm_mday, tm->tm_mon+1, + /* Date : */ + pout(14, 0, (char *) Language(206)); + tm = gmtime(&Msg.Written); + sprintf(temp, "%02d-%02d-%d %02d:%02d:%02d", tm->tm_mday, tm->tm_mon+1, tm->tm_year+1900, tm->tm_hour, tm->tm_min, tm->tm_sec); - colour(12, 0); - if (Msg.Local) printf(" Local"); - if (Msg.Intransit) printf(" Transit"); - if (Msg.Private) printf(" Priv."); - if (Msg.Received) printf(" Rcvd"); - if (Msg.Sent) printf(" Sent"); - if (Msg.KillSent) printf(" KillSent"); - if (Msg.ArchiveSent) printf(" ArchiveSent"); - if (Msg.Hold) printf(" Hold"); - if (Msg.Crash) printf(" Crash"); - if (Msg.Immediate) printf(" Imm."); - if (Msg.Direct) printf(" Dir"); - if (Msg.Gate) printf(" Gate"); - if (Msg.FileRequest) printf(" Freq"); - if (Msg.FileAttach) printf(" File"); - if (Msg.TruncFile) printf(" TruncFile"); - if (Msg.KillFile) printf(" KillFile"); - if (Msg.ReceiptRequest) printf(" RRQ"); - if (Msg.ConfirmRequest) printf(" CRQ"); - if (Msg.Orphan) printf(" Orphan"); - if (Msg.Encrypt) printf(" Crypt"); - if (Msg.Compressed) printf(" Comp"); - if (Msg.Escaped) printf(" 7bit"); - if (Msg.ForcePU) printf(" FPU"); - if (Msg.Localmail) printf(" Localmail"); - if (Msg.Netmail) printf(" Netmail"); - if (Msg.Echomail) printf(" Echomail"); - if (Msg.News) printf(" News"); - if (Msg.Email) printf(" E-mail"); - if (Msg.Nodisplay) printf(" Nodisp"); - if (Msg.Locked) printf(" LCK"); - if (Msg.Deleted) printf(" Del"); - printf("\n"); + pout(10, 0, temp); + colour(12, 0); + if (Msg.Local) PUTSTR((char *)" Local"); + if (Msg.Intransit) PUTSTR((char *)" Transit"); + if (Msg.Private) PUTSTR((char *)" Priv."); + if (Msg.Received) PUTSTR((char *)" Rcvd"); + if (Msg.Sent) PUTSTR((char *)" Sent"); + if (Msg.KillSent) PUTSTR((char *)" KillSent"); + if (Msg.ArchiveSent) PUTSTR((char *)" ArchiveSent"); + if (Msg.Hold) PUTSTR((char *)" Hold"); + if (Msg.Crash) PUTSTR((char *)" Crash"); + if (Msg.Immediate) PUTSTR((char *)" Imm."); + if (Msg.Direct) PUTSTR((char *)" Dir"); + if (Msg.Gate) PUTSTR((char *)" Gate"); + if (Msg.FileRequest) PUTSTR((char *)" Freq"); + if (Msg.FileAttach) PUTSTR((char *)" File"); + if (Msg.TruncFile) PUTSTR((char *)" TruncFile"); + if (Msg.KillFile) PUTSTR((char *)" KillFile"); + if (Msg.ReceiptRequest) PUTSTR((char *)" RRQ"); + if (Msg.ConfirmRequest) PUTSTR((char *)" CRQ"); + if (Msg.Orphan) PUTSTR((char *)" Orphan"); + if (Msg.Encrypt) PUTSTR((char *)" Crypt"); + if (Msg.Compressed) PUTSTR((char *)" Comp"); + if (Msg.Escaped) PUTSTR((char *)" 7bit"); + if (Msg.ForcePU) PUTSTR((char *)" FPU"); + if (Msg.Localmail) PUTSTR((char *)" Localmail"); + if (Msg.Netmail) PUTSTR((char *)" Netmail"); + if (Msg.Echomail) PUTSTR((char *)" Echomail"); + if (Msg.News) PUTSTR((char *)" News"); + if (Msg.Email) PUTSTR((char *)" E-mail"); + if (Msg.Nodisplay) PUTSTR((char *)" Nodisp"); + if (Msg.Locked) PUTSTR((char *)" LCK"); + if (Msg.Deleted) PUTSTR((char *)" Del"); + Enter(1); - /* From : */ - pout(14,0, (char *) Language(209)); - colour(10, 0); - printf("%s\n", Msg.From); + /* From : */ + pout(14,0, (char *) Language(209)); + pout(10, 0, Msg.From); + Enter(1); - /* To : */ - pout(14,0, (char *) Language(208)); - colour(10, 0); - printf("%s\n", Msg.To); + /* To : */ + pout(14,0, (char *) Language(208)); + pout(10, 0, Msg.To); + Enter(1); - /* Subject : */ - pout(14,0, (char *) Language(210)); - colour(10, 0); - printf("%s\n", Msg.Subject); - - colour(CFG.HiliteF, CFG.HiliteB); - colour(14, 1); - if (Msg.Reply) - sprintf(Buf1, "\"+\" %s %lu", (char *)Language(211), Msg.Reply); - if (Msg.Original) - sprintf(Buf2, " \"-\" %s %lu", (char *)Language(212), Msg.Original); - sprintf(Buf3, "%s%s ", Buf1, Buf2); - colour(14, 1); - printf("%78s \n", Buf3); + /* Subject : */ + pout(14,0, (char *) Language(210)); + pout(10, 0, Msg.Subject); + Enter(1); + + if (Msg.Reply) + sprintf(Buf1, "\"+\" %s %lu", (char *)Language(211), Msg.Reply); + if (Msg.Original) + sprintf(Buf2, " \"-\" %s %lu", (char *)Language(212), Msg.Original); + sprintf(Buf3, "%s%s ", Buf1, Buf2); + sprintf(temp, "%78s ", Buf3); + pout(14, 1, temp); + Enter(1); } - /* * Export a email to file in the users home directory. */ int Export_a_Email(unsigned long Num) { - char *p; + char *p, temp[21]; - LastNum = Num; - iLineCount = 7; - WhosDoingWhat(READ_POST, NULL); - Syslog('+', "Export email %d in area %s", Num, sMailbox); + LastNum = Num; + iLineCount = 7; + WhosDoingWhat(READ_POST, NULL); + Syslog('+', "Export email %d in area %s", Num, sMailbox); - /* - * The area data is already set, so we can do the next things - */ - if (EmailBase.Total == 0) { - colour(15, 0); - /* There are no messages in this area */ - printf("\n%s\n\n", (char *) Language(205)); - sleep(3); - return FALSE; - } + /* + * The area data is already set, so we can do the next things + */ + if (EmailBase.Total == 0) { + Enter(1); + /* There are no messages in this area */ + pout(WHITE, BLACK, (char *) Language(205)); + Enter(2); + sleep(3); + return FALSE; + } - if (!Msg_Open(sMailpath)) { - WriteError("Error open JAM base %s", sMailpath); - return FALSE; - } + if (!Msg_Open(sMailpath)) { + WriteError("Error open JAM base %s", sMailpath); + return FALSE; + } - if (!Msg_ReadHeader(Num)) { - perror(""); - colour(15, 0); - printf("\n%s\n\n", (char *)Language(77)); - Msg_Close(); - sleep(3); - return FALSE; - } - - /* - * Export the message text to the file in the users home/wrk directory. - * Create the filename as _.msg The message is - * written in M$DOS format. - */ - p = calloc(PATH_MAX, sizeof(char)); - sprintf(p, "%s/%s/wrk/%s_%lu.msg", CFG.bbs_usersdir, exitinfo.Name, sMailbox, Num); - if ((qf = fopen(p, "w")) != NULL) { - free(p); - p = NULL; - if (Msg_Read(Num, 80)) { - if ((p = (char *)MsgText_First()) != NULL) - do { - if (p[0] == '\001') { - if (Kludges) { - p[0] = 'a'; - fprintf(qf, "^%s\r\n", p); - } - } else - fprintf(qf, "%s\r\n", p); - } while ((p = (char *)MsgText_Next()) != NULL); - } - fclose(qf); - } else { - WriteError("$Can't open %s", p); - free(p); - } + if (!Msg_ReadHeader(Num)) { + Enter(1); + pout(WHITE, BLACK, (char *)Language(77)); Msg_Close(); + Enter(2); + sleep(3); + return FALSE; + } - /* - * Report the result. - */ - colour(CFG.TextColourF, CFG.TextColourB); - printf("\n\n%s", (char *) Language(46)); - colour(CFG.HiliteF, CFG.HiliteB); - printf("%s_%lu.msg\n\n", sMailbox, Num); - Pause(); - return TRUE; + /* + * Export the message text to the file in the users home/wrk directory. + * Create the filename as _.msg The message is + * written in M$DOS format. + */ + p = calloc(PATH_MAX, sizeof(char)); + sprintf(p, "%s/%s/wrk/%s_%lu.msg", CFG.bbs_usersdir, exitinfo.Name, sMailbox, Num); + if ((qf = fopen(p, "w")) != NULL) { + free(p); + p = NULL; + if (Msg_Read(Num, 80)) { + if ((p = (char *)MsgText_First()) != NULL) { + do { + if (p[0] == '\001') { + if (Kludges) { + p[0] = 'a'; + fprintf(qf, "^%s\r\n", p); + } + } else + fprintf(qf, "%s\r\n", p); + } while ((p = (char *)MsgText_Next()) != NULL); + } + } + fclose(qf); + } else { + WriteError("$Can't open %s", p); + free(p); + } + Msg_Close(); + + /* + * Report the result. + */ + Enter(2); + pout(CFG.TextColourF, CFG.TextColourB, (char *) Language(46)); + sprintf(temp, "%s_%lu.msg", sMailbox, Num); + pout(CFG.HiliteF, CFG.HiliteB, temp); + Enter(2); + Pause(); + return TRUE; } @@ -340,10 +345,11 @@ int Save_Email(int IsReply) Syslog('+', "Email (%ld) to \"%s\", \"%s\", in mailbox", Msg.Id, Msg.To, Msg.Subject); - colour(CFG.HiliteF, CFG.HiliteB); + Enter(1); /* Saving message to disk */ - printf("\n%s(%ld)\n\n", (char *) Language(202), Msg.Id); - fflush(stdout); + sprintf(temp, "%s(%ld)", (char *) Language(202), Msg.Id); + pout(CFG.HiliteF, CFG.HiliteB, temp); + Enter(2); sleep(2); /* @@ -365,145 +371,147 @@ int Save_Email(int IsReply) int Read_a_Email(unsigned long Num) { - char *p = NULL, *fn; - lastread LR; + char *p = NULL, *fn; + lastread LR; - LastNum = Num; - iLineCount = 7; - WhosDoingWhat(READ_POST, NULL); + LastNum = Num; + iLineCount = 7; + WhosDoingWhat(READ_POST, NULL); - /* - * The area data is already set, so we can do the next things - */ - if (EmailBase.Total == 0) { - colour(15, 0); - /* There are no messages in this area */ - printf("\n%s\n\n", (char *) Language(205)); - sleep(3); - return FALSE; + /* + * The area data is already set, so we can do the next things + */ + if (EmailBase.Total == 0) { + Enter(1); + /* There are no messages in this area */ + pout(WHITE, BLACK, (char *) Language(205)); + Enter(2); + sleep(3); + return FALSE; + } + + if (!Msg_Open(sMailpath)) { + WriteError("Error open JAM base %s", sMailpath); + return FALSE; + } + + if (!Msg_ReadHeader(Num)) { + Enter(1); + pout(WHITE, BLACK, (char *)Language(77)); + Enter(2); + Msg_Close(); + sleep(3); + return FALSE; + } + ShowEmailHdr(); + + /* + * Fill Quote file in case the user wants to reply. Note that line + * wrapping is set lower then normal message read, to create room + * for the Quote> strings at the start of each line. + */ + fn = calloc(PATH_MAX, sizeof(char)); + sprintf(fn, "%s/%s/.quote", CFG.bbs_usersdir, exitinfo.Name); + if ((qf = fopen(fn, "w")) != NULL) { + if (Msg_Read(Num, 75)) { + if ((p = (char *)MsgText_First()) != NULL) + do { + if (p[0] == '\001') { + /* + * While doing this, store the original Message-id in case + * a reply will be made. + */ + if (strncasecmp(p, "\001Message-id: ", 13) == 0) { + sprintf(Msg.Msgid, "%s", p+13); + Syslog('m', "Stored Msgid \"%s\"", Msg.Msgid); + } + if (Kludges) { + p[0] = 'a'; + fprintf(qf, "^%s\n", p); + } + } else + fprintf(qf, "%s\n", p); + } while ((p = (char *)MsgText_Next()) != NULL); } + fclose(qf); + } else { + WriteError("$Can't open %s", p); + } + free(fn); - if (!Msg_Open(sMailpath)) { - WriteError("Error open JAM base %s", sMailpath); - return FALSE; - } - - if (!Msg_ReadHeader(Num)) { - perror(""); - colour(15, 0); - printf("\n%s\n\n", (char *)Language(77)); - Msg_Close(); - sleep(3); - return FALSE; - } - ShowEmailHdr(); - - /* - * Fill Quote file in case the user wants to reply. Note that line - * wrapping is set lower then normal message read, to create room - * for the Quote> strings at the start of each line. - */ - fn = calloc(PATH_MAX, sizeof(char)); - sprintf(fn, "%s/%s/.quote", CFG.bbs_usersdir, exitinfo.Name); - if ((qf = fopen(fn, "w")) != NULL) { - if (Msg_Read(Num, 75)) { - if ((p = (char *)MsgText_First()) != NULL) - do { - if (p[0] == '\001') { - /* - * While doing this, store the original Message-id in case - * a reply will be made. - */ - if (strncasecmp(p, "\001Message-id: ", 13) == 0) { - sprintf(Msg.Msgid, "%s", p+13); - Syslog('m', "Stored Msgid \"%s\"", Msg.Msgid); - } - if (Kludges) { - p[0] = 'a'; - fprintf(qf, "^%s\n", p); - } - } else - fprintf(qf, "%s\n", p); - } while ((p = (char *)MsgText_Next()) != NULL); + /* + * Show message text + */ + colour(CFG.TextColourF, CFG.TextColourB); + if (Msg_Read(Num, 79)) { + if ((p = (char *)MsgText_First()) != NULL) { + do { + if (p[0] == '\001') { + if (Kludges) { + pout(LIGHTGRAY, BLACK, p); + Enter(1); + if (CheckLine(CFG.TextColourF, CFG.TextColourB, TRUE)) + break; + } + } else { + colour(CFG.TextColourF, CFG.TextColourB); + if (strchr(p, '>') != NULL) + if ((strlen(p) - strlen(strchr(p, '>'))) < 10) + colour(CFG.HiliteF, CFG.HiliteB); + PUTSTR(p); + Enter(1); + if (CheckLine(CFG.TextColourF, CFG.TextColourB, TRUE)) + break; } - fclose(qf); + } while ((p = (char *)MsgText_Next()) != NULL); + } + } + + /* + * Set the Received status on this message. + */ + if (!Msg.Received) { + Syslog('m', "Marking message received"); + Msg.Received = TRUE; + Msg.Read = time(NULL) - (gmt_offset((time_t)0) * 60); + if (Msg_Lock(30L)) { + Msg_WriteHeader(Num); + Msg_UnLock(); + } + } + + /* + * Update lastread pointer. + */ + if (Msg_Lock(30L)) { + LR.UserID = grecno; + p = xstrcpy(exitinfo.sUserName); + if (Msg_GetLastRead(&LR) == TRUE) { + LR.LastReadMsg = Num; + if (Num > LR.HighReadMsg) + LR.HighReadMsg = Num; + if (LR.HighReadMsg > EmailBase.Highest) + LR.HighReadMsg = EmailBase.Highest; + LR.UserCRC = StringCRC32(tl(p)); + if (!Msg_SetLastRead(LR)) + WriteError("Error update lastread"); } else { - WriteError("$Can't open %s", p); - } - free(fn); - - /* - * Show message text - */ - colour(CFG.TextColourF, CFG.TextColourB); - if (Msg_Read(Num, 79)) { - if ((p = (char *)MsgText_First()) != NULL) { - do { - if (p[0] == '\001') { - if (Kludges) { - colour(7, 0); - printf("%s\n", p); - if (CheckLine(CFG.TextColourF, CFG.TextColourB, TRUE)) - break; - } - } else { - colour(CFG.TextColourF, CFG.TextColourB); - if (strchr(p, '>') != NULL) - if ((strlen(p) - strlen(strchr(p, '>'))) < 10) - colour(CFG.HiliteF, CFG.HiliteB); - printf("%s\n", p); - if (CheckLine(CFG.TextColourF, CFG.TextColourB, TRUE)) - break; - } - } while ((p = (char *)MsgText_Next()) != NULL); - } - } - - /* - * Set the Received status on this message. - */ - if (!Msg.Received) { - Syslog('m', "Marking message received"); - Msg.Received = TRUE; - Msg.Read = time(NULL) - (gmt_offset((time_t)0) * 60); - if (Msg_Lock(30L)) { - Msg_WriteHeader(Num); - Msg_UnLock(); - } - } - - /* - * Update lastread pointer. - */ - if (Msg_Lock(30L)) { - LR.UserID = grecno; - p = xstrcpy(exitinfo.sUserName); - if (Msg_GetLastRead(&LR) == TRUE) { - LR.LastReadMsg = Num; - if (Num > LR.HighReadMsg) - LR.HighReadMsg = Num; - if (LR.HighReadMsg > EmailBase.Highest) - LR.HighReadMsg = EmailBase.Highest; - LR.UserCRC = StringCRC32(tl(p)); - if (!Msg_SetLastRead(LR)) - WriteError("Error update lastread"); - } else { - /* - * Append new lastread pointer - */ - LR.UserCRC = StringCRC32(tl(p)); - LR.UserID = grecno; - LR.LastReadMsg = Num; - LR.HighReadMsg = Num; - if (!Msg_NewLastRead(LR)) - WriteError("Can't append lastread"); - } - free(p); - Msg_UnLock(); + /* + * Append new lastread pointer + */ + LR.UserCRC = StringCRC32(tl(p)); + LR.UserID = grecno; + LR.LastReadMsg = Num; + LR.HighReadMsg = Num; + if (!Msg_NewLastRead(LR)) + WriteError("Can't append lastread"); } + free(p); + Msg_UnLock(); + } - Msg_Close(); - return TRUE; + Msg_Close(); + return TRUE; } @@ -513,73 +521,72 @@ int Read_a_Email(unsigned long Num) */ int EmailPanel(void) { - int input; + int input; - WhosDoingWhat(READ_POST, NULL); + WhosDoingWhat(READ_POST, NULL); - colour(15, 4); - /* (A)gain, (N)ext, (L)ast, (R)eply, (E)nter, (D)elete, (Q)uit, e(X)port */ - printf("%s", (char *) Language(214)); - if (exitinfo.Security.level >= CFG.sysop_access) - printf(", (!)"); - printf(": "); - fflush(stdout); - alarm_on(); - input = toupper(Getone()); + /* (A)gain, (N)ext, (L)ast, (R)eply, (E)nter, (D)elete, (Q)uit, e(X)port */ + pout(WHITE, RED, (char *) Language(214)); + if (exitinfo.Security.level >= CFG.sysop_access) + PUTSTR((char *)", (!)"); + PUTSTR((char *)": "); + alarm_on(); + input = toupper(Readkey()); - if (input == '!') { - if (exitinfo.Security.level >= CFG.sysop_access) { - if (Kludges) - Kludges = FALSE; - else - Kludges = TRUE; - Read_a_Email(LastNum); - } - } else if (input == Keystroke(214, 0)) { /* (A)gain */ - Read_a_Email(LastNum); - } else if (input == Keystroke(214, 4)) { /* (P)ost */ - Write_Email(); - Read_a_Email(LastNum); - } else if (input == Keystroke(214, 2)) { /* (L)ast */ - if (LastNum > EmailBase.Lowest) - LastNum--; - Read_a_Email(LastNum); - } else if (input == Keystroke(214, 3)) { /* (R)eply */ - Reply_Email(TRUE); - Read_a_Email(LastNum); - } else if (input == Keystroke(214, 5)) { /* (Q)uit */ - /* Quit */ - printf("%s\n", (char *) Language(189)); - return FALSE; - } else if (input == Keystroke(214, 7)) { /* e(X)port */ - Export_a_Email(LastNum); - Read_a_Email(LastNum); - } else if (input == '+') { - if (Msg.Reply) - LastNum = Msg.Reply; - Read_a_Email(LastNum); - } else if (input == '-') { - if (Msg.Original) - LastNum = Msg.Original; - Read_a_Email(LastNum); - } else if (input == Keystroke(214, 6)) { /* (D)elete */ -// Delete_EmailNum(LastNum); - if (LastNum < EmailBase.Highest) { - LastNum++; - Read_a_Email(LastNum); - } else { - return FALSE; - } - } else { - /* Next */ - pout(15, 0, (char *) Language(216)); - if (LastNum < EmailBase.Highest) - LastNum++; - else - return FALSE; - Read_a_Email(LastNum); + if (input == '!') { + if (exitinfo.Security.level >= CFG.sysop_access) { + if (Kludges) + Kludges = FALSE; + else + Kludges = TRUE; + Read_a_Email(LastNum); } - return TRUE; + } else if (input == Keystroke(214, 0)) { /* (A)gain */ + Read_a_Email(LastNum); + } else if (input == Keystroke(214, 4)) { /* (P)ost */ + Write_Email(); + Read_a_Email(LastNum); + } else if (input == Keystroke(214, 2)) { /* (L)ast */ + if (LastNum > EmailBase.Lowest) + LastNum--; + Read_a_Email(LastNum); + } else if (input == Keystroke(214, 3)) { /* (R)eply */ + Reply_Email(TRUE); + Read_a_Email(LastNum); + } else if (input == Keystroke(214, 5)) { /* (Q)uit */ + /* Quit */ + pout(WHITE, BLACK, (char *) Language(189)); + Enter(1); + return FALSE; + } else if (input == Keystroke(214, 7)) { /* e(X)port */ + Export_a_Email(LastNum); + Read_a_Email(LastNum); + } else if (input == '+') { + if (Msg.Reply) + LastNum = Msg.Reply; + Read_a_Email(LastNum); + } else if (input == '-') { + if (Msg.Original) + LastNum = Msg.Original; + Read_a_Email(LastNum); + } else if (input == Keystroke(214, 6)) { /* (D)elete */ +// Delete_EmailNum(LastNum); + if (LastNum < EmailBase.Highest) { + LastNum++; + Read_a_Email(LastNum); + } else { + return FALSE; + } + } else { + /* Next */ + pout(15, 0, (char *) Language(216)); + if (LastNum < EmailBase.Highest) + LastNum++; + else + return FALSE; + Read_a_Email(LastNum); + } + return TRUE; } @@ -589,57 +596,62 @@ int EmailPanel(void) */ void Read_Email(void) { - char *temp; - unsigned long Start; - lastread LR; + char *temp; + unsigned long Start; + lastread LR; - if (HasNoEmail()) - return; + if (HasNoEmail()) + return; - colour(CFG.TextColourF, CFG.TextColourB); - /* Message area \"%s\" contains %lu messages. */ - printf("\n%s\"%s\" %s%lu %s", (char *) Language(221), sMailbox, (char *) Language(222), EmailBase.Total, (char *) Language(223)); + Enter(1); + temp = calloc(128, sizeof(char)); + /* Message area \"%s\" contains %lu messages. */ + sprintf(temp, "\n%s\"%s\" %s%lu %s", (char *) Language(221), sMailbox, (char *) Language(222), + EmailBase.Total, (char *) Language(223)); + pout(CFG.TextColourF, CFG.TextColourB, temp); + /* + * Check for lastread pointer, suggest lastread number for start. + */ + Start = EmailBase.Lowest; + if (Msg_Open(sMailpath)) { + LR.UserID = grecno; + if (Msg_GetLastRead(&LR)) + Start = LR.HighReadMsg + 1; + else + Start = 1; + Msg_Close(); /* - * Check for lastread pointer, suggest lastread number for start. + * If we already have read the last message, the pointer is + * higher then HighMsgNum, we set it at HighMsgNum to prevent + * errors and read that message again. */ - Start = EmailBase.Lowest; - if (Msg_Open(sMailpath)) { - LR.UserID = grecno; - if (Msg_GetLastRead(&LR)) - Start = LR.HighReadMsg + 1; - else - Start = 1; - Msg_Close(); - /* - * If we already have read the last message, the pointer is - * higher then HighMsgNum, we set it at HighMsgNum to prevent - * errors and read that message again. - */ - if (Start > EmailBase.Highest) - Start = EmailBase.Highest; - } + if (Start > EmailBase.Highest) + Start = EmailBase.Highest; + } - colour(15, 0); - /* Please enter a message between */ - printf("\n%s(%lu - %lu)", (char *) Language(224), EmailBase.Lowest, EmailBase.Highest); - /* Message number [ */ - printf("\n%s%lu]: ", (char *) Language(225), Start); + Enter(1); + /* Please enter a message between */ + sprintf(temp, "%s(%lu - %lu)", (char *) Language(224), EmailBase.Lowest, EmailBase.Highest); + pout(WHITE, BLACK, temp); + Enter(1); + /* Message number [ */ + sprintf(temp, "%s%lu]: ", (char *) Language(225), Start); + PUTSTR(temp); - temp = calloc(128, sizeof(char)); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp, 80); - if ((strcmp(temp, "")) != 0) - Start = atoi(temp); - free(temp); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp, 80); + if ((strcmp(temp, "")) != 0) + Start = atoi(temp); + free(temp); - if (!Read_a_Email(Start)) - return; + if (!Read_a_Email(Start)) + return; - if (EmailBase.Total == 0) - return; + if (EmailBase.Total == 0) + return; - while(EmailPanel()) {} + while(EmailPanel()) {} } @@ -651,8 +663,8 @@ void Read_Email(void) void Reply_Email(int IsReply) { int i, j, x; - char to[65], from[65], subj[72], msgid[81], replyto[81], replyaddr[81], *tmp, *buf, qin[9]; - faddr *Dest = NULL; + char to[65], from[65], subj[72], msgid[81], replyto[81], replyaddr[81], *tmp, *buf, qin[9], temp[81]; + faddr *Dest = NULL; sprintf(from, "%s", Msg.To); sprintf(to, "%s", Msg.From); @@ -672,13 +684,15 @@ void Reply_Email(int IsReply) Line = 1; WhosDoingWhat(READ_POST, NULL); clear(); - colour(1,7); - printf(" %-71s", sMailbox); - colour(4,7); - printf("#%-5lu", EmailBase.Highest + 1); + sprintf(temp, " %-70s", sMailbox); + pout(BLUE, LIGHTGRAY, temp); + sprintf(temp, "#%-5lu", EmailBase.Highest + 1); + pout(RED, LIGHTGRAY, temp); + Enter(1); colour(CFG.HiliteF, CFG.HiliteB); sLine(); + Enter(1); for (i = 0; i < (TEXTBUFSIZE + 1); i++) Message[i] = (char *) calloc(MAX_LINE_LENGTH +1, sizeof(char)); @@ -690,7 +704,7 @@ void Reply_Email(int IsReply) sprintf(Msg.ReplyAddr, "%s", replyaddr); /* From : */ - pout(14, 0, (char *) Language(209)); + pout(YELLOW, BLACK, (char *) Language(209)); if (CFG.EmailMode != E_PRMISP) { /* * If not permanent connected to the internet, use fidonet.org style addressing. @@ -712,23 +726,21 @@ void Reply_Email(int IsReply) /* To : */ sprintf(Msg.To, "%s", to); - pout(14, 0, (char *) Language(208)); + pout(YELLOW, BLACK, (char *) Language(208)); pout(CFG.MsgInputColourF, CFG.MsgInputColourB, Msg.To); Enter(1); /* Enter to keep Subject. */ - pout(12, 0, (char *) Language(219)); + pout(LIGHTRED, BLACK, (char *) Language(219)); Enter(1); /* Subject : */ - pout(14, 0, (char *) Language(210)); + pout(YELLOW, BLACK, (char *) Language(210)); sprintf(Msg.Subject, "%s", subj); pout(CFG.MsgInputColourF, CFG.MsgInputColourB, Msg.Subject); x = strlen(subj); - fflush(stdout); colour(CFG.MsgInputColourF, CFG.MsgInputColourB); GetstrP(subj, 50, x); - fflush(stdout); if (strlen(subj)) strcpy(Msg.Subject, subj); @@ -816,13 +828,15 @@ void Write_Email(void) Msg_New(); + Enter(1); colour(9, 0); /* Posting message in area: */ - printf("\n%s\"%s\"\n", (char *) Language(156), "mailbox"); + pout(LIGHTBLUE, BLACK, (char *) Language(156)); + PUTSTR((char *)"\"mailbox\""); + Enter(2); - Enter(1); /* From : */ - pout(14, 0, (char *) Language(157)); + pout(YELLOW, BLACK, (char *) Language(157)); if (CFG.EmailMode != E_PRMISP) { /* * If not permanent connected to the internet, use fidonet.org style addressing. @@ -839,15 +853,14 @@ void Write_Email(void) break; } - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - printf("%s", Msg.From); + pout(CFG.MsgInputColourF, CFG.MsgInputColourB, Msg.From); Syslog('b', "Setting From: %s", Msg.From); - Enter(1); - /* To : */ - pout(14, 0, (char *) Language(158)); + /* To : */ + pout(YELLOW, BLACK, (char *) Language(158)); colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + alarm_on(); GetstrU(Msg.To, 63); if ((strcmp(Msg.To, "")) == 0) { @@ -859,20 +872,18 @@ void Write_Email(void) } /* Subject : */ - pout(14, 0, (char *) Language(161)); + pout(YELLOW, BLACK, (char *) Language(161)); colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - fflush(stdout); alarm_on(); GetstrP(Msg.Subject, 65, 0); if ((strcmp(Msg.Subject, "")) == 0) { Enter(1); /* Abort Message [y/N] ?: */ - pout(3, 0, (char *) Language(162)); - fflush(stdout); + pout(CYAN, BLACK, (char *) Language(162)); alarm_on(); - if (toupper(Getone()) == Keystroke(162, 0)) { + if (toupper(Readkey()) == Keystroke(162, 0)) { for (i = 0; i < (TEXTBUFSIZE + 1); i++) free(Message[i]); SetEmailArea(orgbox); @@ -898,124 +909,124 @@ void Write_Email(void) void QuickScan_Email(void) { - int FoundMsg = FALSE; - long i; + int FoundMsg = FALSE; + long i; + char temp[81]; - iLineCount = 2; - WhosDoingWhat(READ_POST, NULL); + iLineCount = 2; + WhosDoingWhat(READ_POST, NULL); - if (EmailBase.Total == 0) { - Enter(1); - /* There are no messages in this area. */ - pout(15, 0, (char *) Language(205)); - Enter(3); - sleep(3); - return; - } + if (EmailBase.Total == 0) { + Enter(1); + /* There are no messages in this area. */ + pout(WHITE, BLACK, (char *) Language(205)); + Enter(2); + sleep(3); + return; + } - clear(); - /* # From To Subject */ - poutCR(14, 1, (char *) Language(220)); + clear(); + /* # From To Subject */ + poutCR(YELLOW, BLUE, (char *) Language(220)); - if (Msg_Open(sMailpath)) { - for (i = EmailBase.Lowest; i <= EmailBase.Highest; i++) { - if (Msg_ReadHeader(i)) { + if (Msg_Open(sMailpath)) { + for (i = EmailBase.Lowest; i <= EmailBase.Highest; i++) { + if (Msg_ReadHeader(i)) { - colour(15, 0); - printf("%-6lu", Msg.Id); - colour(3, 0); - printf("%s ", padleft(Msg.From, 20, ' ')); + sprintf(temp, "%-6lu", Msg.Id); + pout(WHITE, BLACK, temp); + sprintf(temp, "%s ", padleft(Msg.From, 20, ' ')); + pout(CYAN, BLACK, temp); - colour(2, 0); - printf("%s ", padleft(Msg.To, 20, ' ')); - colour(5, 0); - printf("%s", padleft(Msg.Subject, 31, ' ')); - printf("\n"); - FoundMsg = TRUE; - if (LC(1)) - break; - } - } - Msg_Close(); - } - - if(!FoundMsg) { + sprintf(temp, "%s ", padleft(Msg.To, 20, ' ')); + pout(GREEN, BLACK, temp); + sprintf(temp, "%s", padleft(Msg.Subject, 31, ' ')); + pout(MAGENTA, BLACK, temp); Enter(1); - /* There are no messages in this area. */ - pout(10, 0, (char *) Language(205)); - Enter(2); - sleep(3); + FoundMsg = TRUE; + if (LC(1)) + break; + } } + Msg_Close(); + } - iLineCount = 2; - Pause(); + if(!FoundMsg) { + Enter(1); + /* There are no messages in this area. */ + pout(LIGHTGREEN, BLACK, (char *) Language(205)); + Enter(2); + sleep(3); + } + + iLineCount = 2; + Pause(); } void Trash_Email(void) { - if (HasNoEmail()) - return; + if (HasNoEmail()) + return; } void Choose_Mailbox(char *Option) { - char *temp; + char *temp; - if (HasNoEmail()) - return; + if (HasNoEmail()) + return; - if (strlen(Option)) { - if (!strcmp(Option, "M+")) { - if (!strcmp(sMailbox, "mailbox")) - SetEmailArea((char *)"archive"); - else if (!strcmp(sMailbox, "archive")) - SetEmailArea((char *)"trash"); - else if (!strcmp(sMailbox, "trash")) - SetEmailArea((char *)"mailbox"); - } - if (!strcmp(Option, "M-")) { - if (!strcmp(sMailbox, "mailbox")) - SetEmailArea((char *)"trash"); - else if (!strcmp(sMailbox, "trash")) - SetEmailArea((char *)"archive"); - else if (!strcmp(sMailbox, "archive")); - SetEmailArea((char *)"mailbox"); - } - Syslog('+', "Emailarea: %s", sMailbox); - return; + if (strlen(Option)) { + if (!strcmp(Option, "M+")) { + if (!strcmp(sMailbox, "mailbox")) + SetEmailArea((char *)"archive"); + else if (!strcmp(sMailbox, "archive")) + SetEmailArea((char *)"trash"); + else if (!strcmp(sMailbox, "trash")) + SetEmailArea((char *)"mailbox"); } - - clear(); - Enter(1); - /* Message areas */ - pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(231)); - Enter(2); - - pout(15, 0, (char *)" 1"); pout(9, 0, (char *)" . "); pout(3, 0, (char *) Language(467)); printf("\n"); - pout(15, 0, (char *)" 2"); pout(9, 0, (char *)" . "); pout(3, 0, (char *) Language(468)); printf("\n"); - pout(15, 0, (char *)" 3"); pout(9, 0, (char *)" . "); pout(3, 0, (char *) Language(469)); printf("\n"); - - pout(CFG.MoreF, CFG.MoreB, (char *) Language(470)); - colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); - temp = calloc(81, sizeof(char)); - GetstrC(temp, 7); - - switch (atoi(temp)) { - case 1: SetEmailArea((char *)"mailbox"); - break; - case 2: SetEmailArea((char *)"archive"); - break; - case 3: SetEmailArea((char *)"trash"); - break; + if (!strcmp(Option, "M-")) { + if (!strcmp(sMailbox, "mailbox")) + SetEmailArea((char *)"trash"); + else if (!strcmp(sMailbox, "trash")) + SetEmailArea((char *)"archive"); + else if (!strcmp(sMailbox, "archive")); + SetEmailArea((char *)"mailbox"); } - Syslog('+', "Emailarea: %s", sMailbox); - free(temp); + return; + } + + clear(); + Enter(1); + /* Message areas */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(231)); + Enter(2); + + pout(15, 0, (char *)" 1"); pout(9, 0, (char *)" . "); pout(3, 0, (char *) Language(467)); Enter(1); + pout(15, 0, (char *)" 2"); pout(9, 0, (char *)" . "); pout(3, 0, (char *) Language(468)); Enter(1); + pout(15, 0, (char *)" 3"); pout(9, 0, (char *)" . "); pout(3, 0, (char *) Language(469)); Enter(1); + + pout(CFG.MoreF, CFG.MoreB, (char *) Language(470)); + colour(CFG.InputColourF, CFG.InputColourB); + temp = calloc(81, sizeof(char)); + GetstrC(temp, 7); + + switch (atoi(temp)) { + case 1: SetEmailArea((char *)"mailbox"); + break; + case 2: SetEmailArea((char *)"archive"); + break; + case 3: SetEmailArea((char *)"trash"); + break; + } + + Syslog('+', "Emailarea: %s", sMailbox); + free(temp); } diff --git a/mbsebbs/file.c b/mbsebbs/file.c index ceebebf0..6263a136 100644 --- a/mbsebbs/file.c +++ b/mbsebbs/file.c @@ -45,6 +45,9 @@ #include "change.h" #include "dispfile.h" #include "term.h" +#include "ttyio.h" +#include "openport.h" + extern long arecno; /* File area number in xxxScan() functions */ @@ -82,10 +85,11 @@ int CheckFile(char *File, int iArea) */ void File_List() { - int FileCount = 0; - unsigned FileBytes = 0; - _Tag T; + int FileCount = 0; + unsigned FileBytes = 0; + _Tag T; struct _fdbarea *fdb_area = NULL; + char temp[81]; iLineCount = 0; WhosDoingWhat(FILELIST, NULL); @@ -93,9 +97,10 @@ void File_List() Syslog('+', "Listing File Area # %d", iAreaNumber); if (Access(exitinfo.Security, area.LTSec) == FALSE) { - colour(14, 0); + Enter(1); /* You don't have enough security to list this area */ - printf("\n%s\n", (char *) Language(236)); + pout(YELLOW, BLACK, (char *) Language(236)); + Enter(2); Pause(); return; } @@ -126,10 +131,12 @@ void File_List() return; } - if (fdb.Deleted) + if (fdb.Deleted) { /* D E L E T E D */ /* Uploaded by: */ - printf(" -- %-12s %s [%4ld] %s%s\n", fdb.Name, (char *) Language(239), + sprintf(temp, " -- %-12s %s [%4ld] %s%s\n", fdb.Name, (char *) Language(239), fdb.TimesDL, (char *) Language(238), fdb.Uploader); + PUTSTR(temp); + } FileCount++; /* Increase File Counter by 1 */ FileBytes += fdb.Size; /* Increase File Byte Count */ @@ -137,9 +144,11 @@ void File_List() Mark(); - colour(11,0); + Enter(1); /* Total Files: */ - printf("\n%s%d / %d bytes\n\n", (char *) Language(242), FileCount, FileBytes); + sprintf(temp, "%s%d / %d bytes", (char *) Language(242), FileCount, FileBytes); + pout(LIGHTCYAN, BLACK, temp); + Enter(2); iLineCount = 0; mbsedb_CloseFDB(fdb_area); @@ -156,10 +165,8 @@ void Download(void) DIR *dirp; struct dirent *dp; FILE *tf, *fd; - int i, err, Count = 0; - int OldArea; - char *symTo, *symFrom; - char *temp; + int i, err, Count = 0, OldArea; + char *symTo, *symFrom, *temp; long Size = 0, CostSize = 0; time_t ElapstimeStart, ElapstimeFin, iTime; long iTransfer = 0; @@ -173,22 +180,22 @@ void Download(void) execute_pth((char *)"rm", temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); sprintf(temp, "%s/%s/tag", CFG.bbs_usersdir, exitinfo.Name); CheckDir(temp); - free(temp); if ((tf = fopen("taglist", "r+")) == NULL) { Syslog('+', "Download command but no files marked"); /* No files marked for download. */ - pout(12, 0, (char *) Language(258)); + pout(LIGHTRED, BLACK, (char *) Language(258)); Enter(2); Pause(); + free(temp); return; } symTo = calloc(PATH_MAX, sizeof(char)); symFrom = calloc(PATH_MAX, sizeof(char)); - colour(13, 0); /* Checking your marked downloads, please wait... */ - printf("%s\n\n", (char *) Language(255)); + pout(LIGHTMAGENTA, BLACK, (char *) Language(255)); + Enter(2); ReadExitinfo(); while (fread(&Tag, sizeof(Tag), 1, tf) == 1) { @@ -211,9 +218,9 @@ void Download(void) if (strcmp(fdb.LName, Tag.LFile) == 0) { Syslog('b', "Found file %s in area %d", fdb.LName, Tag.Area); if (fdb.Deleted) { - pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(248)); /* Sorry that file is unavailable for download */ - printf("%s (%s)\n", (char *) Language(248), fdb.LName); + sprintf(temp, "%s (%s)", (char *) Language(248), fdb.LName); + poutCR(CFG.HiliteF, CFG.HiliteB, temp); Tag.Active = FALSE; Syslog('+', "File %s in area %d unavailable for download, deleted", fdb.LName, Tag.Area); } @@ -293,18 +300,20 @@ void Download(void) SetFileArea(OldArea); unlink("taglist"); /* No files marked for download */ - pout(12, 0, (char *) Language(258)); + pout(LIGHTRED, BLACK, (char *) Language(258)); Enter(2); Pause(); free(symTo); free(symFrom); + free(temp); Syslog('+', "No files left to download"); return; } - colour(14, 0); /* You have */ /* files( */ /* bytes) marked for download */ - printf("%s %d %s%ld %s\n\n", (char *) Language(249), Count, (char *) Language(280), Size, (char *) Language(281)); + sprintf(temp, "%s %d %s%ld %s", (char *) Language(249), Count, (char *) Language(280), Size, (char *) Language(281)); + pout(YELLOW, BLACK, temp); + Enter(2); /* * If user has no default protocol, make sure he has one. @@ -313,6 +322,7 @@ void Download(void) SetFileArea(OldArea); free(symTo); free(symFrom); + free(temp); return; } @@ -320,6 +330,7 @@ void Download(void) SetFileArea(OldArea); free(symTo); free(symFrom); + free(temp); return; } @@ -327,17 +338,16 @@ void Download(void) clear(); /* File(s) : */ - pout(14, 0, (char *) Language(349)); printf("%d\n", Count); + pout(YELLOW, BLACK, (char *) Language(349)); sprintf(temp, "%d", Count); PUTSTR(temp); Enter(1); /* Size : */ - pout( 3, 0, (char *) Language(350)); printf("%lu\n", Size); + pout( CYAN, BLACK, (char *) Language(350)); sprintf(temp, "%lu", Size); PUTSTR(temp); Enter(1); /* Protocol : */ - pout( 3, 0, (char *) Language(351)); printf("%s\n", sProtName); + pout( CYAN, BLACK, (char *) Language(351)); sprintf(temp, "%s", sProtName); PUTSTR(temp); Enter(1); Syslog('+', "Download tagged files start, protocol: %s", sProtName); - printf("%s\n\n", sProtAdvice); - fflush(stdout); - fflush(stdin); + PUTSTR(sProtAdvice); + Enter(2); /* * Wait a while before download @@ -353,7 +363,6 @@ void Download(void) alarm_set(((exitinfo.iTimeLeft + 10) * 60) - 10); Altime((exitinfo.iTimeLeft + 10) * 60); - temp = calloc(PATH_MAX, sizeof(char)); sprintf(temp, "%s/%s/tag", CFG.bbs_usersdir, exitinfo.Name); if ((dirp = opendir(temp)) == NULL) { WriteError("$Download: Can't open dir: %s", temp); @@ -374,10 +383,12 @@ void Download(void) } if (temp != NULL) { if ((err = execute_str(sProtDn, temp, NULL, NULL, NULL, NULL))) { - perror(""); - colour(CFG.HiliteF, CFG.HiliteB); - WriteError("Download error %d, prot: %s", err, sProtDn); + WriteError("$Download error %d, prot: %s", err, sProtDn); } + /* + * Restore rawport + */ + rawport(); free(temp); } else { WriteError("No filebatch created"); @@ -387,8 +398,6 @@ void Download(void) Altime(0); alarm_off(); alarm_on(); - fflush(stdout); - fflush(stdin); Home(); ElapstimeFin = time(NULL); @@ -404,10 +413,10 @@ void Download(void) * Checking the successfull sent files, they are missing from * the ./tag directory. Failed files are still there. */ - colour(11, 0); + PUTCHAR('\r'); /* Updating download counters, please wait ... */ - printf("\r%s\n\n", (char *) Language(352)); - fflush(stdout); + pout(LIGHTCYAN, BLACK, (char *) Language(352)); + Enter(2); Count = Size = 0; if ((tf = fopen("taglist", "r+")) != NULL) { @@ -459,7 +468,6 @@ void Download(void) iTransfer = Size / iTime; Syslog('+', "Download time %ld seconds (%lu cps), %d files", iTime, iTransfer, Count); - /* * Update the users record. */ @@ -491,70 +499,77 @@ void Download(void) */ void File_RawDir(char *OpData) { - DIR *dirp; - char *FileName, *temp; - int iFileCount = 0; - int LineCount = 2; - int iBytes = 0; - struct dirent *dp; - struct stat statfile; + DIR *dirp; + char *FileName, *temp, temp2[81]; + int iFileCount = 0, LineCount = 2, iBytes = 0; + struct dirent *dp; + struct stat statfile; - FileName = calloc(PATH_MAX, sizeof(char)); - temp = calloc(PATH_MAX, sizeof(char)); + FileName = calloc(PATH_MAX, sizeof(char)); + temp = calloc(PATH_MAX, sizeof(char)); - if((strcmp(OpData, "/F")) == 0) - strcpy(temp, sAreaPath); - else - strcpy(temp, OpData); + if ((strcmp(OpData, "/F")) == 0) + strcpy(temp, sAreaPath); + else + strcpy(temp, OpData); - if ((dirp = opendir(temp)) == NULL) { - clear(); - WriteError("$RawDir: Can't open dir: %s", temp); - printf("\nCan't open directory for raw listing!\n\n"); - Pause(); - } else { - clear(); - colour(CFG.HiliteF, CFG.HiliteB); - /* Filename Size Date */ - printf("%s\n", (char *) Language(261)); - fLine(42); + if ((dirp = opendir(temp)) == NULL) { + clear(); + WriteError("$RawDir: Can't open dir: %s", temp); + Enter(1); + pout(LIGHTRED, BLACK, (char *)"Can't open directory for raw listing!"); + Enter(2); + Pause(); + } else { + clear(); + /* Filename Size Date */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(261)); + Enter(1); + fLine(78); - while ((dp = readdir( dirp )) != NULL ) { - sprintf(FileName, "%s/%s", temp, dp->d_name); + while ((dp = readdir( dirp )) != NULL ) { + sprintf(FileName, "%s/%s", temp, dp->d_name); - if (*(dp->d_name) != '.') { - iFileCount++; - if (stat(FileName, &statfile) != 0) - printf("Can't stat file %s\n", FileName); - iBytes += statfile.st_size; + if (*(dp->d_name) != '.') { + iFileCount++; + if (stat(FileName, &statfile) != 0) { + pout(LIGHTRED, BLACK, (char *)"Can't stat file "); + PUTSTR(FileName); + } else { + iBytes += statfile.st_size; - colour(14,0); - printf("%-12s " , dp->d_name); + sprintf(temp2, "%-54s " , dp->d_name); + pout(YELLOW, BLACK, temp2); - colour(13,0); - printf("%-12ld", (long)(statfile.st_size)); + sprintf(temp2, "%-12ld", (long)(statfile.st_size)); + pout(LIGHTMAGENTA, BLACK, temp2); - colour(10,0); - printf("%-10s\n", StrDateDMY(statfile.st_mtime)); - - LineCount++; - if (LineCount == exitinfo.iScreenLen) { - Pause(); - LineCount = 0; - } - } + sprintf(temp2, "%-10s", StrDateDMY(statfile.st_mtime)); + pout(LIGHTGREEN, BLACK, temp2); } + Enter(1); - colour(CFG.HiliteF, CFG.HiliteB); - fLine(42); - /* Total Files: */ /* Bytes */ - printf("%s %d, %d %s\n\n", (char *) Language(242), iFileCount, iBytes, (char *) Language(354)); - - Pause(); - closedir(dirp); + LineCount++; + if (LineCount == exitinfo.iScreenLen) { + Pause(); + LineCount = 0; + } + } } - free(temp); - free(FileName); + + colour(CFG.HiliteF, CFG.HiliteB); + fLine(78); + /* Total Files: */ /* Bytes */ + sprintf(temp2, "%s %d, %d %s", (char *) Language(242), iFileCount, iBytes, (char *) Language(354)); + pout(LIGHTGREEN, BLACK, temp2); + Enter(2); + + Pause(); + closedir(dirp); + } + + free(temp); + free(FileName); } @@ -581,7 +596,7 @@ int KeywordScan() Enter(2); /* Enter keyword to use for Search: */ - pout(11, 0, (char *) Language(267)); + pout(LIGHTCYAN, BLACK, (char *) Language(267)); colour(CFG.InputColourF, CFG.InputColourB); GetstrC(Name, 80); @@ -602,7 +617,7 @@ int KeywordScan() clear(); /* File search by keyword */ - pout(15, 0, (char *) Language(268)); + pout(WHITE, BLACK, (char *) Language(268)); Enter(1); InitTag(); @@ -678,7 +693,7 @@ int KeywordScan() free(Name); free(tmpname); fclose(pAreas); - printf("\n"); + Enter(1); if (Count) Mark(); else @@ -710,11 +725,11 @@ int FilenameScan() Enter(2); /* Accepts wildcards such as : *.zip, *.gz, *.* */ - pout(15, 0, (char *) Language(269)); + pout(WHITE, BLACK, (char *) Language(269)); Enter(2); /* Enter filename to search for : */ - pout(11, 0, (char *) Language(271)); + pout(LIGHTCYAN, BLACK, (char *) Language(271)); colour(CFG.InputColourF, CFG.InputColourB); GetstrC(Name, 80); @@ -731,7 +746,7 @@ int FilenameScan() clear(); /* File Search by Filename */ - pout(15, 0, (char *) Language(272)); + pout(WHITE, BLACK, (char *) Language(272)); Enter(1); InitTag(); @@ -790,7 +805,7 @@ int FilenameScan() Syslog('+', "Found %d files", Count); fclose(pAreas); - printf("\n"); + Enter(1); if (Count) Mark(); else @@ -822,26 +837,26 @@ int NewfileScan(int AskStart) if (AskStart) { Enter(2); /* Search for new since your last call [Y/n]: */ - pout(11, 0, (char *) Language(273)); + pout(LIGHTCYAN, BLACK, (char *) Language(273)); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); - if (toupper(Getone()) == Keystroke(273, 1)) { + if (toupper(Readkey()) == Keystroke(273, 1)) { Enter(1); /* Enter new date to search for [DD-MM-YYYY]: */ - pout(2, 0, (char *) Language(274)); + pout(GREEN, BLACK, (char *) Language(274)); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); GetDate(temp, 10); - } else + } else { strcpy(temp, LastLoginDate); - } else + } + } else { strcpy(temp, LastLoginDate); + } Syslog('+', "NewfileScan() since %s", temp); clear(); /* File Search by Date */ - pout(15, 0, (char *) Language(275)); + pout(WHITE, BLACK, (char *) Language(275)); Enter(2); Date[0] = temp[6]; /* Swap the date around */ @@ -885,7 +900,7 @@ int NewfileScan(int AskStart) if (ifDate >= itDate) { if (!Found) { - printf("\n\n"); + Enter(2); if (iLC(2) == 1) { free(Date); free(temp); @@ -912,7 +927,6 @@ int NewfileScan(int AskStart) fclose(pAreas); return 1; } - } /* End of if */ } /* End of while */ @@ -922,7 +936,7 @@ int NewfileScan(int AskStart) * Add 2 blank lines after found files. */ if (Found) { - printf("\n\n"); + Enter(2); if (iLC(2) == 1) { free(Date); free(temp); @@ -935,13 +949,12 @@ int NewfileScan(int AskStart) } /* End of check new files scan */ arecno++; /* Go to next file area */ - } /* End of Main */ if (Count) Syslog('+', "Found %d new files", Count); fclose(pAreas); - printf("\n"); + Enter(1); if (Count) Mark(); else @@ -959,243 +972,240 @@ int NewfileScan(int AskStart) */ int Upload() { - char File[81], temp[81]; - int Area, x = 0; - int i, err; - unsigned long OldArea; - time_t ElapstimeStart, ElapstimeFin, iTime; - DIR *dirp; - struct dirent *dp; - struct stat statfile; - char *arc; + char File[81], temp[81]; + int Area, x = 0, err; + unsigned long OldArea; + time_t ElapstimeStart, ElapstimeFin, iTime; + DIR *dirp; + struct dirent *dp; + struct stat statfile; + char *arc; - WhosDoingWhat(UPLOAD, NULL); + WhosDoingWhat(UPLOAD, NULL); - /* - * Select default protocol if users hasn't any. - */ - if (!ForceProtocol()) - return 0; + /* + * Select default protocol if users hasn't any. + */ + if (!ForceProtocol()) + return 0; - Enter(1); - Area = OldArea = iAreaNumber; + Enter(1); + Area = OldArea = iAreaNumber; - /* - * If there is a special upload area for the current area - * then select it. - */ - if (area.Upload) - Area = area.Upload; - SetFileArea(Area); + /* + * If there is a special upload area for the current area + * then select it. + */ + if (area.Upload) + Area = area.Upload; + SetFileArea(Area); - /* - * Only ask for a filename for non-batching protocols, - * ie. the stone age Xmodem for example. - */ - if (!uProtBatch) { - /* Please enter file to upload: */ - pout(14, 0, (char *) Language(276)); + /* + * Only ask for a filename for non-batching protocols, + * ie. the stone age Xmodem for example. + */ + if (!uProtBatch) { + /* Please enter file to upload: */ + pout(YELLOW, BLACK, (char *) Language(276)); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(File, 80); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(File, 80); - if((strcmp(File, "")) == 0) - return 0; + if ((strcmp(File, "")) == 0) + return 0; - if (*(File) == '.' || *(File) == '*' || *(File) == ' ' || *(File) == '/') { - colour(CFG.HiliteF, CFG.HiliteB); - /* Illegal Filename! */ - printf("\n%s\n\n", (char *) Language(247)); - Pause(); - return 0; - } + if (*(File) == '.' || *(File) == '*' || *(File) == ' ' || *(File) == '/') { + Enter(1); + /* Illegal Filename! */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); + Pause(); + return 0; + } + + Strlen = strlen(File); + Strlen--; - Strlen = strlen(File); - Strlen--; - - if (*(File + Strlen) == '.' || *(File + Strlen) == '/' || *(File + Strlen) == ' ') { - colour(CFG.HiliteF, CFG.HiliteB); - /* Illegal Filename! */ - printf("\n%s\n\n", (char *) Language(247)); - Pause(); - return 0; - } - - if ((!strcmp(File, "files.bbs")) || (!strcmp(File, "00index")) || (strstr(File, (char *)".html"))) { - colour(CFG.HiliteF, CFG.HiliteB); - /* Illegal Filename! */ - printf("\n%s\n\n", (char *) Language(247)); - Syslog('!', "Attempted to upload %s", File); - Pause(); - return 0; - } - - for (i = 0; i < strlen(File); i++) - printf("%d ", File[i]); - - /* - * Check for a space or ; in filename being uploaded - */ - if (((strchr(File, 32)) != NULL) || ((strchr(File, ';')) != NULL)) { - colour(CFG.HiliteF, CFG.HiliteB); - /* Illegal Filename! */ - printf("\n%s\n\n", (char *) Language(247)); - Pause(); - return 0; - } - - /* MOET IN ALLE AREAS ZOEKEN */ - if (area.Dupes) { - x = CheckFile(File, Area); - if (x) { - Enter(1); - /* The file already exists on the system */ - pout(15, 3, (char *) Language(282)); - Enter(2); - SetFileArea(OldArea); - Pause(); - return 0; - } - } - SetFileArea(OldArea); + if (*(File + Strlen) == '.' || *(File + Strlen) == '/' || *(File + Strlen) == ' ') { + Enter(1); + /* Illegal Filename! */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); + Pause(); + return 0; } - SetFileArea(Area); - Syslog('+', "Upload area is %d %s", Area, area.Name); + if ((!strcmp(File, "files.bbs")) || (!strcmp(File, "00index")) || (strstr(File, (char *)".html"))) { + Enter(1); + /* Illegal Filename! */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); + Syslog('!', "Attempted to upload %s", File); + Pause(); + return 0; + } /* - * Check upload access for the real upload directory. + * Check for a space or ; in filename being uploaded */ - if (!Access(exitinfo.Security, area.UPSec)) { - colour(CFG.HiliteF, CFG.HiliteB); - /* You do not have enough access to upload to this area */ - printf("\n%s\n\n", (char *) Language(278)); + if (((strchr(File, 32)) != NULL) || ((strchr(File, ';')) != NULL)) { + Enter(1); + /* Illegal Filename! */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); + Pause(); + return 0; + } + + /* MOET IN ALLE AREAS ZOEKEN */ + if (area.Dupes) { + x = CheckFile(File, Area); + if (x) { + Enter(1); + /* The file already exists on the system */ + pout(WHITE, CYAN, (char *) Language(282)); + Enter(2); SetFileArea(OldArea); Pause(); return 0; + } } + SetFileArea(OldArea); + } - clear(); - colour(CFG.HiliteF, CFG.HiliteB); - /* Please start your upload now ...*/ - printf("\n\n%s, %s\n\n", sProtAdvice, (char *) Language(283)); - if (uProtBatch) - Syslog('+', "Upload using %s", sProtName); - else - Syslog('+', "Upload \"%s\" using %s", File, sProtName); + SetFileArea(Area); + Syslog('+', "Upload area is %d %s", Area, area.Name); - sprintf(temp, "%s/%s/upl", CFG.bbs_usersdir, exitinfo.Name); - if (chdir(temp)) { - WriteError("$Can't chdir to %s", temp); - SetFileArea(OldArea); - return 0; - } - - fflush(stdout); - fflush(stdin); - sleep(2); - ElapstimeStart = time(NULL); - - /* - * Get the file(s). Set the Client/Server time to 2 hours. - * This is not a nice solution, at least it works and prevents - * that the bbs will hang. - */ - Altime(7200); - alarm_set(7190); - if ((err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL))) { - /* - * Log any errors - */ - colour(CFG.HiliteF, CFG.HiliteB); - WriteError("$Upload error %d, prot: %s", err, sProtUp); - } - Altime(0); - alarm_off(); - alarm_on(); - printf("\n\n\n"); - fflush(stdout); - fflush(stdin); - ElapstimeFin = time(NULL); - - /* - * Get time from Before Upload and After Upload to get - * upload time, if the time is zero, it will be one. - */ - iTime = ElapstimeFin - ElapstimeStart; - if (!iTime) - iTime = 1; - - Syslog('b', "Transfer time %ld", iTime); - - if ((dirp = opendir(".")) == NULL) { - WriteError("$Upload: can't open ./upl"); - Home(); - SetFileArea(OldArea); - return 1; - } - - pout(CFG.UnderlineColourF, CFG.UnderlineColourB, (char *)"\n\nChecking your upload(s)\n\n"); - - while ((dp = readdir(dirp)) != NULL) { - - if (*(dp->d_name) != '.') { - stat(dp->d_name, &statfile); - Syslog('+', "Uploaded \"%s\", %ld bytes", dp->d_name, statfile.st_size); - - if ((arc = GetFileType(dp->d_name)) == NULL) { - /* - * If the filetype is unknown, it is probably - * a textfile or so. Import it direct. - */ - Syslog('b', "Unknown file type"); - if (!ScanDirect(dp->d_name)) - ImportFile(dp->d_name, Area, FALSE, iTime, statfile.st_size); - } else { - /* - * We figured out the type of the uploaded file. - */ - Syslog('b', "File type is %s", arc); - - /* - * MS-DOS executables are handled direct. - */ - if ((strcmp("EXE", arc) == 0) || (strcmp("COM", arc) == 0)) { - if (!ScanDirect(dp->d_name)) - ImportFile(dp->d_name, Area, FALSE, iTime, statfile.st_size); - } else { - switch(ScanArchive(dp->d_name, arc)) { - - case 0: - ImportFile(dp->d_name, Area, TRUE, iTime, statfile.st_size); - break; - - case 1: - break; - - case 2: - break; - - case 3: - /* - * No valid unarchiver found, just import after scanning, - * may catch macro viri. - */ - if (!ScanDirect(dp->d_name)) - ImportFile(dp->d_name, Area, FALSE, iTime, statfile.st_size); - break; - } - } - } - } - } - closedir(dirp); - - Home(); + /* + * Check upload access for the real upload directory. + */ + if (!Access(exitinfo.Security, area.UPSec)) { + Enter(1); + /* You do not have enough access to upload to this area */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(278)); + Enter(2); SetFileArea(OldArea); Pause(); + return 0; + } + + clear(); + Enter(2); + colour(CFG.HiliteF, CFG.HiliteB); + /* Please start your upload now ...*/ + pout(CFG.HiliteF, CFG.HiliteB, sProtAdvice); + PUTCHAR(' '); + PUTSTR((char *) Language(283)); + Enter(2); + + if (uProtBatch) + Syslog('+', "Upload using %s", sProtName); + else + Syslog('+', "Upload \"%s\" using %s", File, sProtName); + + sprintf(temp, "%s/%s/upl", CFG.bbs_usersdir, exitinfo.Name); + if (chdir(temp)) { + WriteError("$Can't chdir to %s", temp); + SetFileArea(OldArea); + return 0; + } + + sleep(2); + ElapstimeStart = time(NULL); + + /* + * Get the file(s). Set the Client/Server time to 2 hours. + * This is not a nice solution, at least it works and prevents + * that the bbs will hang. + */ + Altime(7200); + alarm_set(7190); + err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL); + rawport(); + + if (err) { + /* + * Log any errors + */ + WriteError("$Upload error %d, prot: %s", err, sProtUp); + } + Altime(0); + alarm_off(); + alarm_on(); + Enter(3); + ElapstimeFin = time(NULL); + + /* + * Get time from Before Upload and After Upload to get + * upload time, if the time is zero, it will be one. + */ + iTime = ElapstimeFin - ElapstimeStart; + if (!iTime) + iTime = 1; + + Syslog('b', "Transfer time %ld", iTime); + + if ((dirp = opendir(".")) == NULL) { + WriteError("$Upload: can't open ./upl"); + Home(); + SetFileArea(OldArea); return 1; + } + + Enter(2); + pout(CFG.UnderlineColourF, CFG.UnderlineColourB, (char *)"Checking your upload(s)"); + Enter(1); + + while ((dp = readdir(dirp)) != NULL) { + if (*(dp->d_name) != '.') { + stat(dp->d_name, &statfile); + Syslog('+', "Uploaded \"%s\", %ld bytes", dp->d_name, statfile.st_size); + + if ((arc = GetFileType(dp->d_name)) == NULL) { + /* + * If the filetype is unknown, it is probably + * a textfile or so. Import it direct. + */ + Syslog('b', "Unknown file type"); + if (!ScanDirect(dp->d_name)) + ImportFile(dp->d_name, Area, FALSE, iTime, statfile.st_size); + } else { + /* + * We figured out the type of the uploaded file. + */ + Syslog('b', "File type is %s", arc); + + /* + * MS-DOS executables are handled direct. + */ + if ((strcmp("EXE", arc) == 0) || (strcmp("COM", arc) == 0)) { + if (!ScanDirect(dp->d_name)) + ImportFile(dp->d_name, Area, FALSE, iTime, statfile.st_size); + } else { + switch (ScanArchive(dp->d_name, arc)) { + case 0: ImportFile(dp->d_name, Area, TRUE, iTime, statfile.st_size); + break; + case 1: break; + case 2: break; + case 3: /* + * No valid unarchiver found, just import after scanning, + * may catch macro viri. + */ + if (!ScanDirect(dp->d_name)) + ImportFile(dp->d_name, Area, FALSE, iTime, statfile.st_size); + break; + } + } + } + } + } + closedir(dirp); + + Home(); + SetFileArea(OldArea); + Pause(); + return 1; } @@ -1205,126 +1215,124 @@ int Upload() */ int DownloadDirect(char *Name, int Wait) { - int err, rc; - char *symTo, *symFrom; - long Size; - time_t ElapstimeStart, ElapstimeFin, iTime; - long iTransfer = 0; + int err, rc; + char *symTo, *symFrom, temp[81]; + long Size; + time_t ElapstimeStart, ElapstimeFin, iTime; + long iTransfer = 0; - if ((Size = file_size(Name)) == -1) { - WriteError("No file %s", Name); - colour(CFG.HiliteF, CFG.HiliteB); - printf("File not found\n\n"); - Pause(); - } + if ((Size = file_size(Name)) == -1) { + WriteError("No file %s", Name); + pout(CFG.HiliteF, CFG.HiliteB, (char *)"File not found"); + Enter(2); + Pause(); + } - /* - * Make a symlink to the users tmp dir. - */ - symTo = calloc(PATH_MAX, sizeof(char)); - symFrom = calloc(PATH_MAX, sizeof(char)); - sprintf(symFrom, "%s/%s/tmp%s", CFG.bbs_usersdir, exitinfo.Name, strrchr(Name, '/')); - sprintf(symTo, "%s", Name); + /* + * Make a symlink to the users tmp dir. + */ + symTo = calloc(PATH_MAX, sizeof(char)); + symFrom = calloc(PATH_MAX, sizeof(char)); + sprintf(symFrom, "%s/%s/tmp%s", CFG.bbs_usersdir, exitinfo.Name, strrchr(Name, '/')); + sprintf(symTo, "%s", Name); - if (symlink(symTo, symFrom)) { - WriteError("$Can't create symlink %s %s", symTo, symFrom); - free(symTo); - free(symFrom); - return FALSE; - } - - /* - * If user has no default protocol, make sure he has one. - */ - if (!ForceProtocol()) { - unlink(symFrom); - free(symTo); - free(symFrom); - return FALSE; - } - - WhosDoingWhat(DOWNLOAD, NULL); - ReadExitinfo(); - - clear(); - /* File(s) : */ - pout(14, 0, (char *) Language(349)); printf("%s\n", symFrom); - /* Size : */ - pout( 3, 0, (char *) Language(350)); printf("%lu\n", Size); - /* Protocol : */ - pout( 3, 0, (char *) Language(351)); printf("%s\n", sProtName); - - Syslog('+', "Download direct start %s", Name); - - printf("%s\n\n", sProtAdvice); - fflush(stdout); - fflush(stdin); - - /* - * Wait a while before download - */ - sleep(2); - ElapstimeStart = time(NULL); - - /* - * Transfer the file. Set the Client/Server time at the maximum - * time the user has plus 10 minutes. The overall timer 10 seconds - * less. - */ - alarm_set(((exitinfo.iTimeLeft + 10) * 60) - 10); - Altime((exitinfo.iTimeLeft + 10) * 60); - if ((err = execute_str(sProtDn, symFrom, NULL, NULL, NULL, NULL))) { - /* - * Only log the error, we might have sent some files - * instead of nothing. - */ - perror(""); - colour(CFG.HiliteF, CFG.HiliteB); - WriteError("Download error %d, prot: %s", err, sProtDn); - } - Altime(0); - alarm_off(); - alarm_on(); - fflush(stdout); - fflush(stdin); - ElapstimeFin = time(NULL); - - /* - * Get time from Before Download and After Download to get - * download time, if the time is zero, it will be one. - */ - iTime = ElapstimeFin - ElapstimeStart; - if (!iTime) - iTime = 1; - - if ((access(symFrom, R_OK)) != 0) { - - /* - * Work out transfer rate in seconds by dividing the - * Size of the File by the amount of time it took to download - * the file. - */ - iTransfer = Size / iTime; - Syslog('+', "Download ok, time %ld seconds (%lu cps)", iTime, iTransfer); - - /* - * Update the users record. The file is free, so only statistics. - */ - ReadExitinfo(); - exitinfo.Downloads++; /* Increase download counter */ - exitinfo.iTransferTime = iTransfer; - WriteExitinfo(); - rc = TRUE; - } else { - Syslog('+', "Download failed to sent file"); - unlink(symFrom); - rc = FALSE; - } - if (Wait) - Pause(); + if (symlink(symTo, symFrom)) { + WriteError("$Can't create symlink %s %s", symTo, symFrom); free(symTo); free(symFrom); - return rc; + return FALSE; + } + + /* + * If user has no default protocol, make sure he has one. + */ + if (!ForceProtocol()) { + unlink(symFrom); + free(symTo); + free(symFrom); + return FALSE; + } + + WhosDoingWhat(DOWNLOAD, NULL); + ReadExitinfo(); + + clear(); + /* File(s) : */ + pout(YELLOW, BLACK, (char *) Language(349)); sprintf(temp, "%s", symFrom); PUTSTR(temp); Enter(1); + /* Size : */ + pout( CYAN, BLACK, (char *) Language(350)); sprintf(temp, "%lu", Size); PUTSTR(temp); Enter(1); + /* Protocol : */ + pout( CYAN, BLACK, (char *) Language(351)); sprintf(temp, "%s", sProtName); PUTSTR(temp); Enter(1); + + Syslog('+', "Download direct start %s", Name); + + PUTSTR(sProtAdvice); + Enter(2); + + /* + * Wait a while before download + */ + sleep(2); + ElapstimeStart = time(NULL); + + /* + * Transfer the file. Set the Client/Server time at the maximum + * time the user has plus 10 minutes. The overall timer 10 seconds + * less. + */ + alarm_set(((exitinfo.iTimeLeft + 10) * 60) - 10); + Altime((exitinfo.iTimeLeft + 10) * 60); + err = execute_str(sProtDn, symFrom, NULL, NULL, NULL, NULL); + rawport(); + if (err) { + /* + * Only log the error, we might have sent some files + * instead of nothing. + */ + WriteError("$Download error %d, prot: %s", err, sProtDn); + } + + Altime(0); + alarm_off(); + alarm_on(); + ElapstimeFin = time(NULL); + + /* + * Get time from Before Download and After Download to get + * download time, if the time is zero, it will be one. + */ + iTime = ElapstimeFin - ElapstimeStart; + if (!iTime) + iTime = 1; + + if ((access(symFrom, R_OK)) != 0) { + + /* + * Work out transfer rate in seconds by dividing the + * Size of the File by the amount of time it took to download + * the file. + */ + iTransfer = Size / iTime; + Syslog('+', "Download ok, time %ld seconds (%lu cps)", iTime, iTransfer); + + /* + * Update the users record. The file is free, so only statistics. + */ + ReadExitinfo(); + exitinfo.Downloads++; /* Increase download counter */ + exitinfo.iTransferTime = iTransfer; + WriteExitinfo(); + rc = TRUE; + } else { + Syslog('+', "Download failed to sent file"); + unlink(symFrom); + rc = FALSE; + } + if (Wait) + Pause(); + free(symTo); + free(symFrom); + return rc; } @@ -1334,72 +1342,73 @@ int DownloadDirect(char *Name, int Wait) */ void List_Home() { - DIR *dirp; - char *FileName, *temp; - int iFileCount = 0; - int iBytes = 0; - struct dirent *dp; - struct stat statfile; + DIR *dirp; + char *FileName, *temp; + int iFileCount = 0, iBytes = 0; + struct dirent *dp; + struct stat statfile; - FileName = calloc(PATH_MAX, sizeof(char)); - temp = calloc(PATH_MAX, sizeof(char)); + FileName = calloc(PATH_MAX, sizeof(char)); + temp = calloc(PATH_MAX, sizeof(char)); - iLineCount = 2; - clear(); - sprintf(temp, "%s/%s/wrk", CFG.bbs_usersdir, exitinfo.Name); + iLineCount = 2; + clear(); + sprintf(temp, "%s/%s/wrk", CFG.bbs_usersdir, exitinfo.Name); - if ((dirp = opendir(temp)) == NULL) { - WriteError("$List_Home: Can't open dir: %s", temp); - /* Can't open directory for listing: */ - printf("\n%s\n\n", (char *) Language(290)); - Pause(); - } else { - colour(1, 7); - /* Home directory listing for */ - printf(" %s", (char *) Language(291)); - colour(4, 7); - printf("%-51s\n", exitinfo.sUserName); + if ((dirp = opendir(temp)) == NULL) { + WriteError("$List_Home: Can't open dir: %s", temp); + Enter(1); + /* Can't open directory for listing: */ + pout(LIGHTRED, BLACK, (char *) Language(290)); + Enter(2); + Pause(); + } else { + /* Home directory listing for */ + sprintf(temp, " %s", (char *) Language(291)); + pout(BLUE, LIGHTGRAY, temp); + sprintf(temp, "%-51s", exitinfo.sUserName); + pout(RED, LIGHTGRAY, temp); + Enter(1); - while ((dp = readdir( dirp )) != NULL ) { - sprintf(FileName, "%s/%s", temp, dp->d_name); - /* - * Check first letter of file for a ".", do not display hidden files - * This includes the current directory and parent directory . & .. - */ - if (*(dp->d_name) != '.') { - iFileCount++; - if(stat(FileName, &statfile) != 0) - WriteError("$Can't stat file %s",FileName); - iBytes += statfile.st_size; - - colour(14,0); - printf("%-20s", dp->d_name); - - colour(13,0); - printf("%-12ld", (long)(statfile.st_size)); - - colour(10,0); - printf("%s ", StrDateDMY(statfile.st_mtime)); - - colour(11,0); - printf("%s", StrTimeHMS(statfile.st_mtime)); - - printf("\n"); - } - if (iLC(1) == 1) - return; + while ((dp = readdir( dirp )) != NULL ) { + sprintf(temp, "%s/%s/wrk", CFG.bbs_usersdir, exitinfo.Name); + sprintf(FileName, "%s/%s", temp, dp->d_name); + /* + * Check first letter of file for a ".", do not display hidden files + * This includes the current directory and parent directory . & .. + */ + if (*(dp->d_name) != '.') { + iFileCount++; + if (stat(FileName, &statfile) != 0) { + WriteError("$Can't stat file %s",FileName); + } else { + iBytes += statfile.st_size; + sprintf(temp, "%-20s", dp->d_name); + pout(YELLOW, BLACK, temp); + sprintf(temp, "%-12ld", (long)(statfile.st_size)); + pout(LIGHTMAGENTA, BLACK, temp); + sprintf(temp, "%s ", StrDateDMY(statfile.st_mtime)); + pout(LIGHTGREEN, BLACK, temp); + sprintf(temp, "%s", StrTimeHMS(statfile.st_mtime)); + pout(LIGHTCYAN, BLACK, temp); + Enter(1); } - - colour(11,0); - /* Total Files: */ /* Bytes */ - printf("\n\n%s%d / %d %s\n", (char *) Language(242), iFileCount, iBytes, (char *) Language(354)); - - Pause(); - closedir(dirp); + } + if (iLC(1) == 1) + return; } - free(temp); - free(FileName); + Enter(2); + /* Total Files: */ /* Bytes */ + sprintf(temp, "%s%d / %d %s", (char *) Language(242), iFileCount, iBytes, (char *) Language(354)); + pout(LIGHTCYAN, BLACK, temp); + Enter(1); + Pause(); + closedir(dirp); + } + + free(temp); + free(FileName); } @@ -1409,69 +1418,67 @@ void List_Home() */ void Delete_Home() { - char *temp, *temp1; - int i; + char *temp, *temp1; + int i; - temp = calloc(PATH_MAX, sizeof(char)); - temp1 = calloc(PATH_MAX, sizeof(char)); + temp = calloc(PATH_MAX, sizeof(char)); + temp1 = calloc(PATH_MAX, sizeof(char)); - sprintf(temp, "%s/%s/wrk/", CFG.bbs_usersdir, exitinfo.Name); + sprintf(temp, "%s/%s/wrk/", CFG.bbs_usersdir, exitinfo.Name); - Enter(1); - /* Please enter filename to delete: */ - pout(9, 0, (char *) Language(292)); - colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); - GetstrC(temp1, 80); - - - if(strcmp(temp1, "") == 0) { - free(temp); - free(temp1); - return; - } - - if(temp1[0] == '.') { - Enter(1); - /* Sorry you may not delete hidden files ...*/ - pout(12, 0, (char *) Language(293)); - } else { - strcat(temp, temp1); - - if ((access(temp, R_OK)) == 0) { - colour(10, 0); - /* Delete file: */ /* Are you Sure? [Y/n]: */ - printf("\n%s %s, %s", (char *) Language(368), temp1, (char *) Language(369)); - fflush(stdout); - i = toupper(Getone()); - - if (i == Keystroke(369, 0) || i == 13) { - i = unlink(temp); - - if (i == -1) { - Enter(1); - /* Unable to delete file ... */ - pout(12, 0, (char *) Language(294)); - } else { - Syslog('+', "Delete %s from homedir", temp1); - } - } else { - Enter(2); - /* Aborting ... */ - pout(8, 0, (char *) Language(116)); - } - } else { - Enter(1); - /* Invalid filename, please try again ... */ - pout(12, 0, (char *) Language(295)); - } - - } + Enter(1); + /* Please enter filename to delete: */ + pout(9, 0, (char *) Language(292)); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp1, 80); + if (strcmp(temp1, "") == 0) { free(temp); free(temp1); - printf("\n"); - Pause(); + return; + } + + if (temp1[0] == '.') { + Enter(1); + /* Sorry you may not delete hidden files ...*/ + pout(12, 0, (char *) Language(293)); + } else { + strcat(temp, temp1); + + if ((access(temp, R_OK)) == 0) { + Enter(1); + /* Delete file: */ /* Are you Sure? [Y/n]: */ + sprintf(temp1, "%s %s, %s", (char *) Language(368), temp1, (char *) Language(369)); + pout(LIGHTGREEN, BLACK, temp1); + i = toupper(Readkey()); + + if (i == Keystroke(369, 0) || i == 13) { + i = unlink(temp); + + if (i == -1) { + Enter(1); + /* Unable to delete file ... */ + pout(LIGHTRED, BLACK, (char *) Language(294)); + } else { + Syslog('+', "Delete %s from homedir", temp1); + } + } else { + Enter(2); + /* Aborting ... */ + pout(DARKGRAY, BLACK, (char *) Language(116)); + } + } else { + Enter(1); + /* Invalid filename, please try again ... */ + pout(LIGHTRED, BLACK, (char *) Language(295)); + } + + } + + Enter(2); + free(temp); + free(temp1); + Pause(); } @@ -1482,62 +1489,64 @@ void Delete_Home() */ int Download_Home() { - char *temp, *File; - struct stat statfile; - int rc; + char *temp, *File; + struct stat statfile; + int rc; - File = calloc(PATH_MAX, sizeof(char)); - temp = calloc(PATH_MAX, sizeof(char)); + File = calloc(PATH_MAX, sizeof(char)); + temp = calloc(PATH_MAX, sizeof(char)); - WhosDoingWhat(DOWNLOAD, NULL); + WhosDoingWhat(DOWNLOAD, NULL); - colour(14,0); - /* Please enter filename: */ - printf("\n%s", (char *) Language(245)); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(File, 80); - - if(( strcmp(File, "")) == 0) { - colour(CFG.HiliteF, CFG.HiliteB); - /* No filename entered, Aborting. */ - printf("\n\n%s\n", (char *) Language(246)); - Pause(); - free(File); - free(temp); - return FALSE; - } - - if( *(File) == '/' || *(File) == ' ') { - colour(CFG.HiliteF, CFG.HiliteB); - /* Illegal Filename! */ - printf("\n%s\n\n", (char *) Language(247)); - Pause(); - free(File); - free(temp); - return FALSE; - } - - /* - * Get path for users home directory - */ - sprintf(temp, "%s/%s/wrk/%s", CFG.bbs_usersdir, exitinfo.Name, File); - - if (stat(temp, &statfile) != 0) { - Enter(1); - /* File does not exist, please try again ...*/ - pout(12, 0, (char *) Language(296)); - Enter(2); - Pause(); - free(File); - free(temp); - return FALSE; - } - - rc = DownloadDirect(temp, TRUE); + Enter(1); + /* Please enter filename: */ + pout(YELLOW, BLACK, (char *) Language(245)); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(File, 80); + if (( strcmp(File, "")) == 0) { + Enter(2); + /* No filename entered, Aborting. */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(246)); + Enter(2); + Pause(); free(File); free(temp); - return rc; + return FALSE; + } + + if (*(File) == '/' || *(File) == ' ') { + Enter(2); + /* Illegal Filename! */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); + Pause(); + free(File); + free(temp); + return FALSE; + } + + /* + * Get path for users home directory + */ + sprintf(temp, "%s/%s/wrk/%s", CFG.bbs_usersdir, exitinfo.Name, File); + + if (stat(temp, &statfile) != 0) { + Enter(2); + /* File does not exist, please try again ...*/ + pout(LIGHTRED, BLACK, (char *) Language(296)); + Enter(2); + Pause(); + free(File); + free(temp); + return FALSE; + } + + rc = DownloadDirect(temp, TRUE); + + free(File); + free(temp); + return rc; } @@ -1547,192 +1556,189 @@ int Download_Home() */ int Upload_Home() { - DIR *dirp; - struct dirent *dp; - char *File, *sFileName, *temp, *arc; - time_t ElapstimeStart, ElapstimeFin, iTime; - int err; - struct stat statfile; + DIR *dirp; + struct dirent *dp; + char *File, *sFileName, *temp, *arc; + time_t ElapstimeStart, ElapstimeFin, iTime; + int err; + struct stat statfile; - WhosDoingWhat(UPLOAD, NULL); - if (!ForceProtocol()) - return 0; + WhosDoingWhat(UPLOAD, NULL); + if (!ForceProtocol()) + return 0; - File = calloc(PATH_MAX, sizeof(char)); - sFileName = calloc(PATH_MAX, sizeof(char)); - temp = calloc(PATH_MAX, sizeof(char)); + File = calloc(PATH_MAX, sizeof(char)); + sFileName = calloc(PATH_MAX, sizeof(char)); + temp = calloc(PATH_MAX, sizeof(char)); - if (!uProtBatch) { + if (!uProtBatch) { - Enter(1); - /* Please enter file to upload: */ - pout(14, 0, (char *) Language(276)); + Enter(1); + /* Please enter file to upload: */ + pout(YELLOW, BLACK, (char *) Language(276)); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(File, 80); - - if((strcmp(File, "")) == 0) { - free(File); - free(sFileName); - free(temp); - return 0; - } - - if(File[0] == '.' || File[0] == '*' || File[0] == ' ') { - colour(CFG.HiliteF, CFG.HiliteB); - /* Illegal Filename! */ - printf("\n%s\n\n", (char *) Language(247)); - Pause(); - free(File); - free(sFileName); - free(temp); - return 0; - } - - Strlen = strlen(File); - Strlen--; - - if(File[Strlen] == '.' || File[Strlen] == '/' || File[Strlen] == ' ') { - colour(CFG.HiliteF, CFG.HiliteB); - /* Illegal Filename! */ - printf("\n%s\n\n", (char *) Language(247)); - Pause(); - free(File); - free(sFileName); - free(temp); - return 0; - } + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(File, 80); + if ((strcmp(File, "")) == 0) { + free(File); + free(sFileName); + free(temp); + return 0; } - clear(); - colour(CFG.HiliteF, CFG.HiliteB); - /* Please start your upload now ...*/ - printf("\n\n%s, %s\n\n", sProtAdvice, (char *) Language(283)); - if (uProtBatch) - Syslog('+', "Upload using %s", sProtName); - else - Syslog('+', "Upload \"%s\" using %s", File, sProtName); - - sprintf(temp, "%s/%s/upl", CFG.bbs_usersdir, exitinfo.Name); - if (chdir(temp)) { - WriteError("$Can't chdir to %s", temp); - free(File); - free(sFileName); - free(temp); - return 0; + if (File[0] == '.' || File[0] == '*' || File[0] == ' ') { + Enter(1); + /* Illegal Filename! */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); + Pause(); + free(File); + free(sFileName); + free(temp); + return 0; } - fflush(stdout); - fflush(stdin); - sleep(2); - ElapstimeStart = time(NULL); - - /* - * Get the file(s). Set the Client/Server time to 2 hours. - * This is not a nice solution, at least it works and prevents - * that the bbs will hang. - */ - Altime(7200); - alarm_set(7190); - if ((err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL))) { - /* - * Log any errors - */ - colour(CFG.HiliteF, CFG.HiliteB); - WriteError("$Upload error %d, prot: %s", err, sProtUp); + Strlen = strlen(File); + Strlen--; + + if (File[Strlen] == '.' || File[Strlen] == '/' || File[Strlen] == ' ') { + Enter(1); + /* Illegal Filename! */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); + Pause(); + free(File); + free(sFileName); + free(temp); + return 0; } - Altime(0); - alarm_off(); - alarm_on(); - printf("\n\n\n"); - fflush(stdout); - fflush(stdin); - ElapstimeFin = time(NULL); + } - /* - * Get time from Before Upload and After Upload to get - * upload time, if the time is zero, it will be one. - */ - iTime = ElapstimeFin - ElapstimeStart; - if (!iTime) - iTime = 1; + clear(); + Enter(2); + /* Please start your upload now ...*/ + sprintf(temp, "%s, %s", sProtAdvice, (char *) Language(283)); + pout(CFG.HiliteF, CFG.HiliteB, temp); + Enter(2); + if (uProtBatch) + Syslog('+', "Upload using %s", sProtName); + else + Syslog('+', "Upload \"%s\" using %s", File, sProtName); - Syslog('b', "Transfer time %ld", iTime); - - if ((dirp = opendir(".")) == NULL) { - WriteError("$Upload: can't open ./upl"); - Home(); - free(File); - free(sFileName); - free(temp); - return 1; - } - - Syslog('b', "Start checking uploaded files"); - pout(CFG.UnderlineColourF, CFG.UnderlineColourB, (char *)"\n\nChecking your upload(s)\n\n"); - - while ((dp = readdir(dirp)) != NULL) { - - if (*(dp->d_name) != '.') { - stat(dp->d_name, &statfile); - Syslog('+', "Uploaded \"%s\", %ld bytes", dp->d_name, statfile.st_size); - - if ((arc = GetFileType(dp->d_name)) == NULL) { - /* - * If the filetype is unknown, it is probably - * a textfile or so. Import it direct. - */ - Syslog('b', "Unknown file type"); - ImportHome(dp->d_name); - } else { - /* - * We figured out the type of the uploaded file. - */ - Syslog('b', "File type is %s", arc); - - /* - * MS-DOS executables are handled direct. - */ - if ((strcmp("EXE", arc) == 0) || (strcmp("COM", arc) == 0)) { - if (!ScanDirect(dp->d_name)) - ImportHome(dp->d_name); - } else { - switch(ScanArchive(dp->d_name, arc)) { - - case 0: - ImportHome(dp->d_name); - break; - - case 1: - break; - - case 2: - break; - - case 3: - /* - * No valid unarchiver found, just import - */ - ImportHome(dp->d_name); - break; - } - } - } - } - } - closedir(dirp); - Home(); - - ReadExitinfo(); - exitinfo.Uploads++; - WriteExitinfo(); - - Pause(); + sprintf(temp, "%s/%s/upl", CFG.bbs_usersdir, exitinfo.Name); + if (chdir(temp)) { + WriteError("$Can't chdir to %s", temp); free(File); free(sFileName); free(temp); + return 0; + } + + sleep(2); + ElapstimeStart = time(NULL); + + /* + * Get the file(s). Set the Client/Server time to 2 hours. + * This is not a nice solution, at least it works and prevents + * that the bbs will hang. + */ + Altime(7200); + alarm_set(7190); + err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL); + rawport(); + + if (err) { + /* + * Log any errors + */ + WriteError("$Upload error %d, prot: %s", err, sProtUp); + } + + Altime(0); + alarm_off(); + alarm_on(); + Enter(3); + ElapstimeFin = time(NULL); + + /* + * Get time from Before Upload and After Upload to get + * upload time, if the time is zero, it will be one. + */ + iTime = ElapstimeFin - ElapstimeStart; + if (!iTime) + iTime = 1; + + Syslog('b', "Transfer time %ld", iTime); + + if ((dirp = opendir(".")) == NULL) { + WriteError("$Upload: can't open ./upl"); + Home(); + free(File); + free(sFileName); + free(temp); return 1; + } + + Syslog('b', "Start checking uploaded files"); + Enter(2); + pout(CFG.UnderlineColourF, CFG.UnderlineColourB, (char *)"Checking your upload(s)"); + Enter(2); + + while ((dp = readdir(dirp)) != NULL) { + + if (*(dp->d_name) != '.') { + stat(dp->d_name, &statfile); + Syslog('+', "Uploaded \"%s\", %ld bytes", dp->d_name, statfile.st_size); + + if ((arc = GetFileType(dp->d_name)) == NULL) { + /* + * If the filetype is unknown, it is probably + * a textfile or so. Import it direct. + */ + Syslog('b', "Unknown file type"); + ImportHome(dp->d_name); + } else { + /* + * We figured out the type of the uploaded file. + */ + Syslog('b', "File type is %s", arc); + + /* + * MS-DOS executables are handled direct. + */ + if ((strcmp("EXE", arc) == 0) || (strcmp("COM", arc) == 0)) { + if (!ScanDirect(dp->d_name)) + ImportHome(dp->d_name); + } else { + switch(ScanArchive(dp->d_name, arc)) { + case 0: ImportHome(dp->d_name); + break; + case 1: break; + case 2: break; + case 3: /* + * No valid unarchiver found, just import + */ + ImportHome(dp->d_name); + break; + } + } + } + } + } + + closedir(dirp); + Home(); + + ReadExitinfo(); + exitinfo.Uploads++; + WriteExitinfo(); + + Pause(); + free(File); + free(sFileName); + free(temp); + return 1; } @@ -1742,211 +1748,206 @@ int Upload_Home() */ void FileArea_List(char *Option) { - FILE *pAreas; - int iAreaCount = 6, Recno = 1; - int iOldArea, iAreaNum = 0; - int iGotArea = FALSE; /* Flag to check if user typed in area */ - long offset; - char *temp; + FILE *pAreas; + int iAreaCount = 6, Recno = 1, iOldArea, iAreaNum = 0; + int iGotArea = FALSE; /* Flag to check if user typed in area */ + long offset; + char *temp; - /* - * Save old area, incase he picks a invalid area - */ - iOldArea = iAreaNumber; - if ((pAreas = OpenFareas(FALSE)) == NULL) - return; + /* + * Save old area, incase he picks a invalid area + */ + iOldArea = iAreaNumber; + if ((pAreas = OpenFareas(FALSE)) == NULL) + return; - /* - * Count howmany records there are - */ - fseek(pAreas, 0, SEEK_END); - iAreaNum = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize; + /* + * Count howmany records there are + */ + fseek(pAreas, 0, SEEK_END); + iAreaNum = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize; - /* - * If there are menu options, select area direct. - */ - if (strlen(Option) != 0) { + /* + * If there are menu options, select area direct. + */ + if (strlen(Option) != 0) { - if (strcmp(Option, "F+") == 0) - while(TRUE) { - iAreaNumber++; - if (iAreaNumber > iAreaNum) - iAreaNumber = 1; + if (strcmp(Option, "F+") == 0) { + while (TRUE) { + iAreaNumber++; + if (iAreaNumber > iAreaNum) + iAreaNumber = 1; - offset = areahdr.hdrsize + ((iAreaNumber - 1) * areahdr.recsize); - if (fseek(pAreas, offset, 0) != 0) { - printf("Can't move pointer here"); - } - - fread(&area, areahdr.recsize, 1, pAreas); - if ((Access(exitinfo.Security, area.LTSec)) && (area.Available) && (strlen(area.Password) == 0)) - break; - } - - if (strcmp(Option, "F-") == 0) - while(TRUE) { - iAreaNumber--; - if (iAreaNumber < 1) - iAreaNumber = iAreaNum; - - offset = areahdr.hdrsize + ((iAreaNumber - 1) * areahdr.recsize); - if (fseek(pAreas, offset, 0) != 0) { - printf("Can't move pointer here"); - } - - fread(&area, areahdr.recsize, 1, pAreas); - if ((Access(exitinfo.Security, area.LTSec)) && (area.Available) && (strlen(area.Password) == 0)) - break; - } - SetFileArea(iAreaNumber); - Syslog('+', "File area %lu %s", iAreaNumber, sAreaDesc); - fclose(pAreas); - return; - } - - /* - * Interactive mode - */ - clear(); - Enter(1); - /* File Areas */ - pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(298)); - Enter(2); - temp = calloc(81, sizeof(char)); - - fseek(pAreas, areahdr.hdrsize, 0); - - while (fread(&area, areahdr.recsize, 1, pAreas) == 1) { - - if ((Access(exitinfo.Security, area.LTSec)) && (area.Available)) { - area.Name[31] = '\0'; - - colour(15,0); - printf("%5d", Recno); - - colour(9,0); - printf(" %c ", 46); - - colour(3,0); - printf("%-31s", area.Name); - - iAreaCount++; - - if ((iAreaCount % 2) == 0) - printf("\n"); - else - printf(" "); + offset = areahdr.hdrsize + ((iAreaNumber - 1) * areahdr.recsize); + if (fseek(pAreas, offset, 0) != 0) { + printf("Can't move pointer here"); } - Recno++; - - if ((iAreaCount / 2) == exitinfo.iScreenLen) { - /* More (Y/n/=/Area #): */ - pout(CFG.MoreF, CFG.MoreB, (char *) Language(207)); - /* - * Ask user for Area or enter to continue - */ - colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); - GetstrC(temp, 7); - - if (toupper(*(temp)) == Keystroke(207, 1)) - break; - - if ((strcmp(temp, "")) != 0) { - iGotArea = TRUE; - break; - } - - iAreaCount = 2; - } - } - - /* - * If user type in area above during area listing - * don't ask for it again - */ - if (!iGotArea) { - Enter(1); - /* Select Area: */ - pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(232)); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp, 80); - } - - /* - * Check if user pressed ENTER - */ - if((strcmp(temp, "")) == 0) { - fclose(pAreas); - return; - } - - iAreaNumber = atoi(temp); - - /* - * Do a check in case user enters a negative value - */ - if (iAreaNumber < 1) - iAreaNumber = 1; - - offset = areahdr.hdrsize + ((iAreaNumber - 1) * areahdr.recsize); - if(fseek(pAreas, offset, 0) != 0) - printf("Can't move pointer there."); - else fread(&area, areahdr.recsize, 1, pAreas); - - /* - * Do a check if area is greater or less number than allowed, - * security access level, is oke, and the area is active. - */ - if (iAreaNumber > iAreaNum || iAreaNumber < 1 || - (Access(exitinfo.Security, area.LTSec) == FALSE) || - (strlen(area.Name) == 0)) { - Enter(1); - /* Invalid area specified - Please try again ...*/ - pout(12, 0, (char *) Language(233)); - Enter(2); - Pause(); - fclose(pAreas); - iAreaNumber = iOldArea; - SetFileArea(iAreaNumber); - free(temp); - return; + if ((Access(exitinfo.Security, area.LTSec)) && (area.Available) && (strlen(area.Password) == 0)) + break; + } } + + if (strcmp(Option, "F-") == 0) { + while (TRUE) { + iAreaNumber--; + if (iAreaNumber < 1) + iAreaNumber = iAreaNum; + offset = areahdr.hdrsize + ((iAreaNumber - 1) * areahdr.recsize); + if (fseek(pAreas, offset, 0) != 0) { + printf("Can't move pointer here"); + } + + fread(&area, areahdr.recsize, 1, pAreas); + if ((Access(exitinfo.Security, area.LTSec)) && (area.Available) && (strlen(area.Password) == 0)) + break; + } + } + SetFileArea(iAreaNumber); Syslog('+', "File area %lu %s", iAreaNumber, sAreaDesc); - - /* - * Check if file area has a password, if it does ask user for it - */ - if((strlen(area.Password)) > 2) { - Enter(2); - /* Please enter Area Password: */ - pout(15, 0, (char *) Language(299)); - fflush(stdout); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp, 20); - - if((strcmp(temp, area.Password)) != 0) { - Enter(1); - /* Password is incorrect */ - pout(15, 0, (char *) Language(234)); - Enter(2); - Syslog('!', "Incorrect File Area # %d password given: %s", iAreaNumber, temp); - SetFileArea(iOldArea); - } else { - Enter(1); - /* Password is correct */ - pout(15, 0, (char *) Language(235)); - Enter(2); - } - Pause(); - } - - free(temp); fclose(pAreas); + return; + } + + /* + * Interactive mode + */ + clear(); + Enter(1); + /* File Areas */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(298)); + Enter(2); + temp = calloc(81, sizeof(char)); + + fseek(pAreas, areahdr.hdrsize, 0); + + while (fread(&area, areahdr.recsize, 1, pAreas) == 1) { + + if ((Access(exitinfo.Security, area.LTSec)) && (area.Available)) { + area.Name[31] = '\0'; + sprintf(temp, "%5d", Recno); + pout(WHITE, BLACK, temp); + sprintf(temp, " %c ", 46); + pout(LIGHTBLUE, BLACK, temp); + sprintf(temp, "%-31s", area.Name); + pout(CYAN, BLACK, temp); + iAreaCount++; + + if ((iAreaCount % 2) == 0) { + Enter(1); + } else { + PUTCHAR(' '); + } + } + + Recno++; + + if ((iAreaCount / 2) == exitinfo.iScreenLen) { + /* More (Y/n/=/Area #): */ + pout(CFG.MoreF, CFG.MoreB, (char *) Language(207)); + /* + * Ask user for Area or enter to continue + */ + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp, 7); + + if (toupper(*(temp)) == Keystroke(207, 1)) + break; + + if ((strcmp(temp, "")) != 0) { + iGotArea = TRUE; + break; + } + + iAreaCount = 2; + } + } + + /* + * If user type in area above during area listing + * don't ask for it again + */ + if (!iGotArea) { + Enter(1); + /* Select Area: */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(232)); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp, 80); + } + + /* + * Check if user pressed ENTER + */ + if ((strcmp(temp, "")) == 0) { + fclose(pAreas); + return; + } + + iAreaNumber = atoi(temp); + + /* + * Do a check in case user enters a negative value + */ + if (iAreaNumber < 1) + iAreaNumber = 1; + + offset = areahdr.hdrsize + ((iAreaNumber - 1) * areahdr.recsize); + if (fseek(pAreas, offset, 0) != 0) + printf("Can't move pointer there."); + else + fread(&area, areahdr.recsize, 1, pAreas); + + /* + * Do a check if area is greater or less number than allowed, + * security access level, is oke, and the area is active. + */ + if (iAreaNumber > iAreaNum || iAreaNumber < 1 || + (Access(exitinfo.Security, area.LTSec) == FALSE) || + (strlen(area.Name) == 0)) { + Enter(1); + /* Invalid area specified - Please try again ...*/ + pout(LIGHTRED, BLACK, (char *) Language(233)); + Enter(2); + Pause(); + fclose(pAreas); + iAreaNumber = iOldArea; + SetFileArea(iAreaNumber); + free(temp); + return; + } + + SetFileArea(iAreaNumber); + Syslog('+', "File area %lu %s", iAreaNumber, sAreaDesc); + + /* + * Check if file area has a password, if it does ask user for it + */ + if ((strlen(area.Password)) > 2) { + Enter(2); + /* Please enter Area Password: */ + pout(WHITE, BLACK, (char *) Language(299)); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp, 20); + Enter(1); + + if ((strcmp(temp, area.Password)) != 0) { + /* Password is incorrect */ + pout(LIGHTRED, BLACK, (char *) Language(234)); + Syslog('!', "Incorrect File Area # %d password given: %s", iAreaNumber, temp); + SetFileArea(iOldArea); + } else { + /* Password is correct */ + pout(WHITE, BLACK, (char *) Language(235)); + } + Enter(2); + Pause(); + } + + free(temp); + fclose(pAreas); } @@ -1964,16 +1965,17 @@ void Copy_Home() temp1 = calloc(PATH_MAX, sizeof(char)); temp2 = calloc(PATH_MAX, sizeof(char)); - colour(14,0); + Enter(1); /* Please enter filename: */ - printf("\n%s", (char *) Language(245)); + pout(YELLOW, BLACK, (char *) Language(245)); colour(CFG.InputColourF, CFG.InputColourB); GetstrC(File, 80); + Enter(2); if ((strcmp(File, "")) == 0) { - colour(CFG.HiliteF, CFG.HiliteB); /* No filename entered, Aborting. */ - printf("\n\n%s\n", (char *) Language(246)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(246)); + Enter(2); Pause(); free(File); free(temp1); @@ -1982,9 +1984,9 @@ void Copy_Home() } if (*(File) == '/' || *(File) == ' ') { - colour(CFG.HiliteF, CFG.HiliteB); /* Illegal Filename! */ - printf("\n%s\n\n", (char *) Language(247)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); Pause(); free(File); free(temp1); @@ -1993,8 +1995,8 @@ void Copy_Home() } if (Access(exitinfo.Security, area.DLSec) == FALSE) { - colour(14, 0); - printf("\n%s\n", (char *) Language(236)); + pout(YELLOW, BLACK, (char *) Language(236)); + Enter(2); Pause(); free(File); free(temp1); @@ -2014,40 +2016,41 @@ void Copy_Home() Found = TRUE; if (((fdb.Size + Quota()) > (CFG.iQuota * 1048576))) { - colour(CFG.HiliteF, CFG.HiliteB); /* You have not enough diskspace free to copy this file */ - printf("%s\n", (char *) Language(279)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(279)); + Enter(1); Syslog('+', "Copy homedir, not enough quota"); } else { sprintf(temp1, "%s/%s", area.Path, fdb.LName); /* Use real longname here */ sprintf(temp2, "%s/%s/wrk/%s", CFG.bbs_usersdir, exitinfo.Name, File); colour(CFG.TextColourF, CFG.TextColourB); /* Start copy: */ - printf("%s%s ", (char *) Language(289), File); - fflush(stdout); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(289)); + PUTSTR(File); + PUTCHAR(' '); Syslog('b', "Copy from : %s", temp1); Syslog('b', "Copy to : %s", temp2); if ((err = file_cp(temp1, temp2))) { - colour(CFG.HiliteF, CFG.HiliteB); /* Failed! */ - printf("%s\n", (char *) Language(353)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(353)); WriteError("Copy %s to homedir failed, code %d", File, err); } else { /* Ok */ - printf("%s\n", (char *) Language(200)); + PUTSTR((char *) Language(200)); Syslog('+', "Copied %s from area %d to homedir", File, iAreaNumber); } + Enter(1); } } } mbsedb_CloseFDB(fdb_area); if (!Found) { - colour(CFG.HiliteF, CFG.HiliteB); /* File does not exist, please try again ... */ - printf("%s\n", (char *) Language(296)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(296)); + Enter(1); } Pause(); @@ -2063,115 +2066,114 @@ void Copy_Home() */ void EditTaglist() { - FILE *tf; - int i, x, Fg, Count; - char *temp; + FILE *tf; + int i, x, Fg, Count; + char *temp; - if ((tf = fopen("taglist", "r+")) == NULL) { - colour(CFG.HiliteF, CFG.HiliteB); - /* No files tagged. */ - printf("\n%s\n\n", (char *) Language(361)); - Pause(); - return; + if ((tf = fopen("taglist", "r+")) == NULL) { + Enter(1); + /* No files tagged. */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(361)); + Enter(2); + Pause(); + return; + } + + temp = calloc(81, sizeof(char)); + + while (TRUE) { + clear(); + fseek(tf, 0, SEEK_SET); + Count = 0; + /* # Area Active File Size Cost */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(355)); + Enter(1); + colour(LIGHTGREEN, BLACK); + fLine(48); + + while ((fread(&Tag, sizeof(Tag), 1, tf) == 1)) { + Count++; + + if (Tag.Active) + Fg = WHITE; + else + Fg = LIGHTGRAY; + + sprintf(temp, "%3d ", Count); + pout(Fg, BLACK, temp); + + Fg--; + sprintf(temp, "%5ld ", Tag.Area); + pout(Fg, BLACK, temp); + + Fg--; + if (Tag.Active) + /* Yes */ + sprintf(temp, "%-6s ", (char *) Language(356)); + else + /* No */ + sprintf(temp, "%-6s ", (char *) Language(357)); + pout(Fg, BLACK, temp); + + Fg--; + sprintf(temp, "%-12s", Tag.SFile); + pout(Fg, BLACK, temp); + + Fg--; + sprintf(temp, " %8ld", (long)(Tag.Size)); + pout(Fg, BLACK, temp); + + Fg--; + sprintf(temp, " %5d", Tag.Cost); + pout(Fg, BLACK, temp); + Enter(1); + } + colour(LIGHTGREEN, BLACK); + fLine(48); + + /* (T)oggle active, (E)rase all, (ENTER) to continue: */ + pout(WHITE, RED, (char *) Language(358)); + + i = toupper(Readkey()); + colour(CFG.CRColourF, CFG.CRColourB); + + if (i == Keystroke(358, 0)) { + Enter(2); + /* Enter file number, 1.. */ + sprintf(temp, "%s%d ", (char *) Language(359), Count); + PUTSTR(temp); + + GetstrC(temp, 5); + x = atoi(temp); + + if ((x > 0) && (x <= Count)) { + if (fseek(tf, (x - 1) * sizeof(Tag), SEEK_SET) == 0) { + if (fread(&Tag, sizeof(Tag), 1, tf) == 1) { + if (Tag.Active) + Tag.Active = FALSE; + else + Tag.Active = TRUE; + + fseek(tf,(x - 1) * sizeof(Tag), SEEK_SET); + fwrite(&Tag, sizeof(Tag), 1, tf); + } + } + } } - temp = calloc(81, sizeof(char)); - - while (TRUE) { - clear(); - fseek(tf, 0, SEEK_SET); - Count = 0; - colour(CFG.HiliteF, CFG.HiliteB); - /* # Area Active File Size Cost */ - printf("%s\n", (char *) Language(355)); - colour(10, 0); - fLine(48); - - while ((fread(&Tag, sizeof(Tag), 1, tf) == 1)) { - Count++; - - if (Tag.Active) - Fg = 15; - else - Fg = 7; - - colour(Fg, 0); - printf("%3d ", Count); - - Fg--; - colour(Fg, 0); - printf("%5ld ", Tag.Area); - - Fg--; - colour(Fg, 0); - if (Tag.Active) - /* Yes */ - printf("%-6s ", (char *) Language(356)); - else - /* No */ - printf("%-6s ", (char *) Language(357)); - - Fg--; - colour(Fg, 0); - printf("%-12s", Tag.SFile); - - Fg--; - colour(Fg, 0); - printf(" %8ld", (long)(Tag.Size)); - - Fg--; - colour(Fg, 0); - printf(" %5d\n", Tag.Cost); - } - colour(10, 0); - fLine(48); - - colour(15, 4); - /* (T)oggle active, (E)rase all, (ENTER) to continue: */ - printf("\n%s", (char *) Language(358)); - fflush(stdout); - fflush(stdin); - - i = toupper(Getone()); - colour(CFG.CRColourF, CFG.CRColourB); - - if (i == Keystroke(358, 0)) { - /* Enter file number, 1.. */ - printf("\n\n%s%d ", (char *) Language(359), Count); - fflush(stdout); - fflush(stdin); - - GetstrC(temp, 5); - x = atoi(temp); - - if ((x > 0) && (x <= Count)) { - if (fseek(tf, (x - 1) * sizeof(Tag), SEEK_SET) == 0) { - if (fread(&Tag, sizeof(Tag), 1, tf) == 1) { - if (Tag.Active) - Tag.Active = FALSE; - else - Tag.Active = TRUE; - - fseek(tf,(x - 1) * sizeof(Tag), SEEK_SET); - fwrite(&Tag, sizeof(Tag), 1, tf); - } - } - } - } - - if (i == Keystroke(358, 1)) { - fclose(tf); - unlink("taglist"); - free(temp); - return; - } - - if ((i == '\r') || (i == '\n')) { - fclose(tf); - free(temp); - return; - } + if (i == Keystroke(358, 1)) { + fclose(tf); + unlink("taglist"); + free(temp); + return; } + + if ((i == '\r') || (i == '\n')) { + fclose(tf); + free(temp); + return; + } + } } @@ -2191,9 +2193,10 @@ void ViewFile(char *name) Syslog('+', "ViewFile(%s)", printable(name, 0)); if (Access(exitinfo.Security, area.LTSec) == FALSE) { - colour(YELLOW, BLACK); + Enter(1); /* You don't have enough security to list this area */ - printf("\n%s\n", (char *) Language(236)); + pout(YELLOW, BLACK, (char *) Language(236)); + Enter(2); Pause(); return; } @@ -2215,9 +2218,10 @@ void ViewFile(char *name) } if (*(File) == '.' || *(File) == '*' || *(File) == ' ' || *(File) == '/') { - colour(CFG.HiliteF, CFG.HiliteB); + Enter(1); /* Illegal Filename! */ - printf("\n%s\n\n", (char *) Language(247)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); Pause(); free(File); return; @@ -2227,18 +2231,20 @@ void ViewFile(char *name) Strlen--; if (*(File + Strlen) == '.' || *(File + Strlen) == '/' || *(File + Strlen) == ' ') { - colour(CFG.HiliteF, CFG.HiliteB); + Enter(1); /* Illegal Filename! */ - printf("\n%s\n\n", (char *) Language(247)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); Pause(); free(File); return; } if ((!strcmp(File, "files.bbs")) || (!strcmp(File, "00index")) || (strstr(File, (char *)".html"))) { - colour(CFG.HiliteF, CFG.HiliteB); + Enter(1); /* Illegal Filename! */ - printf("\n%s\n\n", (char *) Language(247)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); Pause(); free(File); return; @@ -2262,9 +2268,10 @@ void ViewFile(char *name) mbsedb_CloseFDB(fdb_area); if (!found) { - colour(YELLOW, BLACK); + Enter(1); /* File does not exist, please try again ... */ - printf("\n%s\n\n", (char *) Language(296)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(296)); + Enter(2); free(File); Pause(); return; @@ -2292,9 +2299,10 @@ void ViewFile(char *name) if (!found || (strlen(archiver.varc) == 0)) { Syslog('+', "No archiver view for %s available", File); - colour(YELLOW, BLACK); + Enter(1); /* Archiver not available */ - printf("\n%s\n\n", Language(442)); + pout(CFG.HiliteF, CFG.HiliteB, Language(442)); + Enter(2); free(File); free(temp); Pause(); @@ -2329,7 +2337,9 @@ void ViewFile(char *name) } if (((count * 10) / total) < 8) { Syslog('+', "This is not a ASCII textfile"); - printf("\n%s\n\n", Language(17)); + Enter(1); + pout(CFG.HiliteF, CFG.HiliteB, Language(17)); + Enter(2); Pause(); free(File); return; diff --git a/mbsebbs/filesub.c b/mbsebbs/filesub.c index 962b3f9a..16572eb8 100644 --- a/mbsebbs/filesub.c +++ b/mbsebbs/filesub.c @@ -42,6 +42,7 @@ #include "exitinfo.h" #include "change.h" #include "term.h" +#include "ttyio.h" extern pid_t mypid; @@ -62,13 +63,13 @@ _Tag Tagbuf[100]; */ void InitTag() { - int i; + int i; - Tagnr = 0; + Tagnr = 0; - for (i = 0; i < 100; i++) { - memset(&Tagbuf[i], 0, sizeof(_Tag)); - } + for (i = 0; i < 100; i++) { + memset(&Tagbuf[i], 0, sizeof(_Tag)); + } } @@ -78,32 +79,32 @@ void InitTag() */ void SetTag(_Tag tag) { - if (Tagnr < 99) - Tagnr++; - else - Tagnr = 1; + if (Tagnr < 99) + Tagnr++; + else + Tagnr = 1; - Tagbuf[Tagnr] = tag; + Tagbuf[Tagnr] = tag; } int ForceProtocol() { + /* + * If user has no default protocol, make sure he has one. + */ + if (strcmp(sProtName, "") == 0) { + Chg_Protocol(); + /* - * If user has no default protocol, make sure he has one. + * If the user didn't pick a protocol, quit. */ if (strcmp(sProtName, "") == 0) { - Chg_Protocol(); - - /* - * If the user didn't pick a protocol, quit. - */ - if (strcmp(sProtName, "") == 0) { - return FALSE; - } + return FALSE; } - return TRUE; + } + return TRUE; } @@ -113,41 +114,29 @@ int ForceProtocol() */ void GetstrD(char *sStr, int iMaxlen) { - unsigned char ch = 0; - int iPos = 0; + unsigned char ch = 0; + int iPos = 0; - fflush(stdout); + strcpy(sStr, ""); - if ((ttyfd = open ("/dev/tty", O_RDWR)) < 0) { - perror("open 6"); - return; - } - Setraw(); - strcpy(sStr, ""); + alarm_on(); + while (ch != 13) { + ch = Readkey(); - alarm_on(); - while (ch != 13) { - ch = Readkey(); - - if (((ch == 8) || (ch == KEY_DEL) || (ch == 127)) && (iPos > 0)) { - printf("\b \b"); - fflush(stdout); - sStr[--iPos]='\0'; - } - - if (ch > 31 && ch < 127) { - if (iPos <= iMaxlen) { - iPos++; - sprintf(sStr, "%s%c", sStr, ch); - printf("%c", ch); - fflush(stdout); - } else - ch=07; - } + if (((ch == 8) || (ch == KEY_DEL) || (ch == 127)) && (iPos > 0)) { + BackErase(); + sStr[--iPos]='\0'; } - Unsetraw(); - close(ttyfd); + if (ch > 31 && ch < 127) { + if (iPos <= iMaxlen) { + iPos++; + sprintf(sStr, "%s%c", sStr, ch); + PUTCHAR(ch); + } else + PUTCHAR(7); + } + } } @@ -159,27 +148,28 @@ void GetstrD(char *sStr, int iMaxlen) */ FILE *OpenFareas(int Write) { - FILE *pAreas; - char *FileArea; + FILE *pAreas; + char *FileArea; - FileArea = calloc(PATH_MAX, sizeof(char)); - sprintf(FileArea, "%s/etc/fareas.data", getenv("MBSE_ROOT")); + FileArea = calloc(PATH_MAX, sizeof(char)); + sprintf(FileArea, "%s/etc/fareas.data", getenv("MBSE_ROOT")); - if (Write) - pAreas = fopen(FileArea, "r+"); - else - pAreas = fopen(FileArea, "r"); + if (Write) + pAreas = fopen(FileArea, "r+"); + else + pAreas = fopen(FileArea, "r"); - if (pAreas == NULL) { - WriteError("$Can't open FileBase %s", FileArea); - /* FATAL: Unable to open areas database */ - printf("%s\n\n", (char *) Language(243)); - sleep(2); - } else - fread(&areahdr, sizeof(areahdr), 1, pAreas); + if (pAreas == NULL) { + WriteError("$Can't open FileBase %s", FileArea); + /* FATAL: Unable to open areas database */ + pout(LIGHTRED, BLACK, (char *) Language(243)); + Enter(2); + sleep(2); + } else + fread(&areahdr, sizeof(areahdr), 1, pAreas); - free(FileArea); - return pAreas; + free(FileArea); + return pAreas; } @@ -189,17 +179,19 @@ FILE *OpenFareas(int Write) */ void Header() { - colour(4, 7); - printf(" Area "); + char temp[81]; + + pout(RED, LIGHTGRAY, (char *)" Area "); - colour(4, 7); - printf("%-5d ", iAreaNumber); + sprintf(temp, "%-5d ", iAreaNumber); + pout(RED, LIGHTGRAY, temp); - colour(1,7); - printf("%-65s\n", sAreaDesc); + sprintf(temp, "%-65s", sAreaDesc); + pout(BLUE, LIGHTGRAY, temp); + Enter(1); - colour(15,0); - fLine(79); + colour(15,0); + fLine(79); } @@ -209,20 +201,21 @@ void Header() */ void Sheader() { - colour(Hcolor, 0); - printf("\r %-4ld", arecno); + char temp[81]; - colour(9, 0); - printf(" ... "); + PUTCHAR('\r'); + sprintf(temp, " %-4ld", arecno); + pout(Hcolor, BLACK, temp); - colour(Hcolor, 0); - printf("%-44s", area.Name); - fflush(stdout); + pout(LIGHTBLUE, BLACK, (char *)" ... "); - if (Hcolor < 15) - Hcolor++; - else - Hcolor = 9; + sprintf(temp, "%-44s", area.Name); + pout(Hcolor, BLACK, temp); + + if (Hcolor < WHITE) + Hcolor++; + else + Hcolor = LIGHTBLUE; } @@ -232,16 +225,15 @@ void Sheader() */ void Blanker(int count) { - int i; + int i; - for (i = 0; i < count; i++) - printf("\b"); + for (i = 0; i < count; i++) + PUTCHAR('\b'); - for (i = 0; i < count; i++) - printf(" "); + for (i = 0; i < count; i++) + PUTCHAR(' '); - printf("\r"); - fflush(stdout); + PUTCHAR('\r'); } @@ -252,80 +244,77 @@ void Blanker(int count) */ void Mark() { - char *temp; - FILE *fp; - int i, Found; - int Count, Size; + char *temp; + FILE *fp; + int i, Found, Count, Size; - temp = calloc(81, sizeof(char)); + temp = calloc(81, sizeof(char)); - /* - * First count the already tagged files. - */ - Count = Size = 0; - if ((fp = fopen("taglist", "r")) != NULL) { - while (fread(&Tag, sizeof(Tag), 1, fp) == 1) { - if (Tag.Active) { - Count++; - Size += (Tag.Size / 1024); - } - } - fclose(fp); + /* + * First count the already tagged files. + */ + Count = Size = 0; + if ((fp = fopen("taglist", "r")) != NULL) { + while (fread(&Tag, sizeof(Tag), 1, fp) == 1) { + if (Tag.Active) { + Count++; + Size += (Tag.Size / 1024); + } } + fclose(fp); + } - colour(CFG.HiliteF, CFG.HiliteB); - /* Marked: */ - printf("%s%d, %dK; ", (char *) Language(360), Count, Size); + /* Marked: */ + sprintf(temp, "%s%d, %dK; ", (char *) Language(360), Count, Size); + pout(CFG.HiliteF, CFG.HiliteB, temp); - /* Mark file number of press to stop */ - printf("%s", (char *) Language(7)); + /* Mark file number of press to stop */ + PUTSTR((char *) Language(7)); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrD(temp, 10); - Blanker(strlen(Language(7)) + strlen(temp)); - - if (strlen(temp) == 0) { - free(temp); - return; - } - - i = atoi(temp); - - if ((i > 0) && (i < 100)) { - if ((Tagbuf[i].Area) && (strlen(Tagbuf[i].LFile))) { - if (Access(exitinfo.Security, area.DLSec)) { - if ((fp = fopen("taglist", "a+")) != NULL) { - - fseek(fp, 0, SEEK_SET); - Found = FALSE; - while (fread(&Tag, sizeof(Tag), 1, fp) == 1) - if ((Tag.Area == Tagbuf[i].Area) && (strcmp(Tag.LFile, Tagbuf[i].LFile) == 0)) { - Found = TRUE; - Syslog('b', "Tagbuf[i].File already tagged"); - } - - if (!Found) { - memset(&Tag, 0, sizeof(Tag)); - Tag = Tagbuf[i]; - Tag.Active = TRUE; - fwrite(&Tag, sizeof(Tag), 1, fp); - Syslog('+', "Tagged file %s from area %d", Tag.LFile, Tag.Area); - } - - fclose(fp); - } - } else { - colour(12, 0); - /* You do not have enough access to download from this area. */ - printf("%s", (char *) Language(244)); - fflush(stdout); - sleep(3); - Blanker(strlen(Language(244))); - } - } - } + colour(CFG.InputColourF, CFG.InputColourB); + GetstrD(temp, 10); + Blanker(strlen(Language(7)) + strlen(temp)); + if (strlen(temp) == 0) { free(temp); + return; + } + + i = atoi(temp); + + if ((i > 0) && (i < 100)) { + if ((Tagbuf[i].Area) && (strlen(Tagbuf[i].LFile))) { + if (Access(exitinfo.Security, area.DLSec)) { + if ((fp = fopen("taglist", "a+")) != NULL) { + + fseek(fp, 0, SEEK_SET); + Found = FALSE; + while (fread(&Tag, sizeof(Tag), 1, fp) == 1) + if ((Tag.Area == Tagbuf[i].Area) && (strcmp(Tag.LFile, Tagbuf[i].LFile) == 0)) { + Found = TRUE; + Syslog('b', "Tagbuf[i].File already tagged"); + } + + if (!Found) { + memset(&Tag, 0, sizeof(Tag)); + Tag = Tagbuf[i]; + Tag.Active = TRUE; + fwrite(&Tag, sizeof(Tag), 1, fp); + Syslog('+', "Tagged file %s from area %d", Tag.LFile, Tag.Area); + } + + fclose(fp); + } + } else { + /* You do not have enough access to download from this area. */ + pout(LIGHTRED, BLACK, (char *) Language(244)); + sleep(3); + Blanker(strlen(Language(244))); + } + } + } + + free(temp); } @@ -335,43 +324,42 @@ void Mark() */ int iLC(int Lines) { - int x, z; + int x, z; - x = strlen(Language(131)); - iLineCount += Lines; + x = strlen(Language(131)); + iLineCount += Lines; - if ((iLineCount >= exitinfo.iScreenLen) && (iLineCount < 1000)) { - iLineCount = 0; + if ((iLineCount >= exitinfo.iScreenLen) && (iLineCount < 1000)) { + iLineCount = 0; - while(TRUE) { - /* More (Y/n/=) M=Mark */ - pout(CFG.MoreF, CFG.MoreB, (char *) Language(131)); + while (TRUE) { + /* More (Y/n/=) M=Mark */ + pout(CFG.MoreF, CFG.MoreB, (char *) Language(131)); - fflush(stdout); - alarm_on(); - z = toupper(Getone()); - Blanker(x); + alarm_on(); + z = toupper(Readkey()); + Blanker(x); - if (z == Keystroke(131, 1)) { - printf("\n"); - return 1; - } + if (z == Keystroke(131, 1)) { + Enter(1); + return 1; + } - if (z == Keystroke(131, 2)) { - iLineCount = 1000; - return 0; - } + if (z == Keystroke(131, 2)) { + iLineCount = 9000; + return 0; + } - if ((z == Keystroke(131, 0)) || (z == '\r') || (z == '\n')) { - return 0; - } + if ((z == Keystroke(131, 0)) || (z == '\r') || (z == '\n')) { + return 0; + } - if (z == Keystroke(131, 3)) { - Mark(); - } - } + if (z == Keystroke(131, 3)) { + Mark(); + } } - return 0; + } + return 0; } @@ -381,30 +369,32 @@ int iLC(int Lines) */ int ShowOneFile() { - int y, z, fg, bg; + int y, z, fg, bg; + char temp[81]; if (!fdb.Deleted) { - colour(7, 0); - printf(" %02d ", Tagnr); + sprintf(temp, " %02d ", Tagnr); + pout(LIGHTGRAY, BLACK, temp); - colour(CFG.FilenameF, CFG.FilenameB); - printf("%-12s", fdb.Name); + sprintf(temp, "%-12s", fdb.Name); + pout(CFG.FilenameF, CFG.FilenameB, temp); - colour(CFG.FilesizeF, CFG.FilesizeB); - printf("%10lu ", (long)(fdb.Size)); + sprintf(temp, "%10lu ", (long)(fdb.Size)); + pout(CFG.FilesizeF, CFG.FilesizeB, temp); - colour(CFG.FiledateF, CFG.FiledateB); - printf("%-10s ", StrDateDMY(fdb.UploadDate)); + sprintf(temp, "%-10s ", StrDateDMY(fdb.UploadDate)); + pout(CFG.FiledateF, CFG.FiledateB, temp); - colour(12, 0); - printf("[%4ld] ", fdb.TimesDL); + sprintf(temp, "[%4ld] ", fdb.TimesDL); + pout(LIGHTRED, BLACK, temp); if ((strcmp(fdb.Uploader, "")) == 0) strcpy(fdb.Uploader, "SysOp"); - colour(CFG.HiliteF, CFG.HiliteB); - printf("%s%s\n", (char *) Language(238), fdb.Uploader); + sprintf(temp, "%s%s", (char *) Language(238), fdb.Uploader); + pout(CFG.HiliteF, CFG.HiliteB, temp); + Enter(1); if (iLC(1) == 1) return 1; @@ -420,12 +410,13 @@ int ShowOneFile() else fg = (int)fdb.Desc[z][3] - 48; bg = (int)fdb.Desc[z][2] - 48; - colour(fg, bg); - printf(" %s\n",fdb.Desc[z]+4); + sprintf(temp, " %s",fdb.Desc[z]+4); + pout(fg, bg, temp); } else { - colour(CFG.FiledescF, CFG.FiledescB); - printf(" %s\n",fdb.Desc[z]); + sprintf(temp, " %s",fdb.Desc[z]); + pout(CFG.FiledescF, CFG.FiledescB, temp); } + Enter(1); if (iLC(1) == 1) return 1; @@ -439,6 +430,8 @@ int ShowOneFile() int CheckBytesAvailable(long CostSize) { + char temp[81]; + if (LIMIT.DownK) { if ((exitinfo.DownloadKToday <= 0) || ((CostSize / 1024) > exitinfo.DownloadKToday)) { @@ -447,14 +440,14 @@ int CheckBytesAvailable(long CostSize) Enter(1); Syslog('+', "Not enough bytes to download %ld", CostSize); - colour(WHITE, BLACK); /* You must upload before you can download. */ pout(LIGHTRED, BLACK, (char *) Language(253)); Enter(2); - colour(YELLOW, BLACK); /* Kilobytes currently available: */ - printf("%s%lu Kbytes.\n\n", (char *) Language(254), exitinfo.DownloadKToday); + sprintf(temp, "%s%lu Kbytes.", (char *) Language(254), exitinfo.DownloadKToday); + pout(YELLOW, BLACK, temp); + Enter(2); Pause(); return FALSE; @@ -488,7 +481,7 @@ int ScanDirect(char *fn) { FILE *fp, *lp; int err, Found = FALSE; - char *temp, *temp1, *stdlog, *errlog, buf[256]; + char *temp, *temp1, *stdlog, *errlog, buf[256], msg[81]; temp = calloc(PATH_MAX, sizeof(char)); temp1 = calloc(PATH_MAX, sizeof(char)); @@ -506,10 +499,9 @@ int ScanDirect(char *fn) while (fread(&virscan, virscanhdr.recsize, 1, fp) == 1) { if (virscan.available) { - colour(CFG.TextColourF, CFG.TextColourB); /* Scanning */ /* with */ - printf("%s %s %s %s ", (char *) Language(132), fn, (char *) Language(133), virscan.comment); - fflush(stdout); + sprintf(msg, "%s %s %s %s ", (char *) Language(132), fn, (char *) Language(133), virscan.comment); + pout(CFG.TextColourF, CFG.TextColourB, msg); Altime(3600); err = execute_str(virscan.scanner, virscan.options, temp, (char *)"/dev/null", stdlog, errlog); @@ -535,17 +527,18 @@ int ScanDirect(char *fn) unlink(errlog); if (err != virscan.error) { WriteError("VIRUS ALERT: Result %d (%s)", err, virscan.comment); - colour(CFG.HiliteF, CFG.HiliteB); /* Possible VIRUS found! */ - printf("%s\n", (char *) Language(199)); + sprintf(msg, "%s", (char *) Language(199)); + pout(CFG.HiliteF, CFG.HiliteB, msg); Found = TRUE; } else { /* Ok */ - printf("%s\n", (char *) Language(200)); + sprintf(msg, "%s", (char *) Language(200)); + PUTSTR(msg); } + Enter(1); Altime(0); Nopper(); - fflush(stdout); } } fclose(fp); @@ -572,7 +565,7 @@ int ScanArchive(char *fn, char *ftype) { FILE *fp, *lp; int err = 0, Found = FALSE; - char *temp, *stdlog, *errlog, buf[256]; + char *temp, *stdlog, *errlog, buf[256], msg[81]; char *cwd = NULL; @@ -613,10 +606,9 @@ int ScanArchive(char *fn, char *ftype) return 1; } - colour(CFG.TextColourF, CFG.TextColourB); /* Unpacking archive */ - printf("%s %s ", (char *) Language(201), fn); - fflush(stdout); + sprintf(msg, "%s %s ", (char *) Language(201), fn); + pout(CFG.TextColourF, CFG.TextColourB, msg); if (!strlen(archiver.funarc)) { WriteError("No unarc command available"); @@ -627,17 +619,16 @@ int ScanArchive(char *fn, char *ftype) execute_pth((char *)"rm", (char *)"-r -f ./*", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); chdir(cwd); free(cwd); - colour(CFG.HiliteF, CFG.HiliteB); /* ERROR */ - printf("%s\n", (char *) Language(217)); - fflush(stdout); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(217)); + Enter(1); return 1; } } /* Ok */ - printf("%s\n", (char *) Language(200)); - fflush(stdout); + PUTSTR((char *) Language(200)); + Enter(1); sprintf(temp, "%s/etc/virscan.data", getenv("MBSE_ROOT")); @@ -646,10 +637,9 @@ int ScanArchive(char *fn, char *ftype) while (fread(&virscan, virscanhdr.recsize, 1, fp) == 1) { if (virscan.available) { - colour(CFG.TextColourF, CFG.TextColourB); /* Scanning */ /* with */ - printf("%s %s %s %s ", (char *) Language(132), fn, (char *) Language(133), virscan.comment); - fflush(stdout); + sprintf(msg, "%s %s %s %s ", (char *) Language(132), fn, (char *) Language(133), virscan.comment); + pout(CFG.TextColourF, CFG.TextColourB, msg); Altime(3600); err = execute_str(virscan.scanner, virscan.options, (char *)"*", (char *)"/dev/null", stdlog, errlog); @@ -675,15 +665,14 @@ int ScanArchive(char *fn, char *ftype) unlink(errlog); if (err != virscan.error) { WriteError("VIRUS ALERT: Result %d (%s)", err, virscan.comment); - colour(CFG.HiliteF, CFG.HiliteB); /* Possible VIRUS found! */ - printf("%s\n", (char *) Language(199)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(199)); Found = TRUE; } else { /* Ok */ - printf("%s\n", (char *) Language(200)); + PUTSTR((char *) Language(200)); } - fflush(stdout); + Enter(1); Altime(0); Nopper(); } @@ -792,7 +781,7 @@ char *GetFileType(char *fn) */ int ImportFile(char *fn, int Area, int fileid, time_t iTime, off_t Size) { - char *temp, *temp1; + char *temp, *temp1, msg[81]; temp = calloc(PATH_MAX, sizeof(char)); temp1 = calloc(PATH_MAX, sizeof(char)); @@ -817,7 +806,9 @@ int ImportFile(char *fn, int Area, int fileid, time_t iTime, off_t Size) exitinfo.UploadKToday += (Size / 1024); Syslog('b', "Uploads %d, Kb %d, Kb today %d", exitinfo.Uploads, exitinfo.UploadK, exitinfo.UploadKToday); /* You have */ /* extra download KBytes. */ - printf("%s %ld %s\n", (char *) Language(249), (long)(Size / 1024), (char *) Language(250)); + sprintf(msg, "%s %ld %s", (char *) Language(249), (long)(Size / 1024), (char *) Language(250)); + PUTSTR(msg); + Enter(1); exitinfo.DownloadKToday += (Size / 1024); Syslog('b', "DownloadKToday %d", exitinfo.DownloadKToday); @@ -825,7 +816,9 @@ int ImportFile(char *fn, int Area, int fileid, time_t iTime, off_t Size) iTime /= 60; /* Divide Seconds by 60 to give minutes */ /* You have */ /* extra minutes. */ - printf("%s %ld %s\n", (char *) Language(249), iTime, (char *) Language(259)); + sprintf(msg, "%s %ld %s", (char *) Language(249), iTime, (char *) Language(259)); + PUTSTR(msg); + Enter(1); exitinfo.iTimeLeft += iTime; WriteExitinfo(); @@ -852,7 +845,7 @@ int Addfile(char *File, int AreaNum, int fileid) { FILE *id, *pPrivate; int err = 1, iDesc = 1, iPrivate = FALSE, GotId = FALSE, lines, i, j; - char *Filename, *temp1, *idname = NULL, *Desc[26], *lname, temp[81]; + char *Filename, *temp1, *idname = NULL, *Desc[26], *lname, temp[81], msg[81]; struct stat statfile; struct _fdbarea *fdb_area = NULL; @@ -870,9 +863,12 @@ int Addfile(char *File, int AreaNum, int fileid) */ if (stat(Filename, &statfile) != 0) { + Enter(1); colour(10, 0); /* Upload was unsuccessful for: */ - printf("\n%s%s\n\n", (char *) Language(284), File); + sprintf(msg, "%s%s", (char *) Language(284), File); + pout(LIGHTGREEN, BLACK, msg); + Enter(2); mbsedb_CloseFDB(fdb_area); free(Filename); @@ -899,20 +895,17 @@ int Addfile(char *File, int AreaNum, int fileid) } if (area.PwdUP) { - colour(9,0); + Enter(1); /* Do you want to password protect your upload ? [y/N]: */ - printf("\n%s", (char *) Language(285)); - fflush(stdout); + pout(LIGHTBLUE, BLACK, (char *) Language(285)); - if (toupper(Getone()) == Keystroke(285, 0)) { - colour(10, 0); + if (toupper(Readkey()) == Keystroke(285, 0)) { + Enter(1); /* REMEMBER: Passwords are "CaSe SeNsITiVe!" */ - printf("\n%s\n", (char *) Language(286)); - colour(14,0); + pout(LIGHTGREEN, BLACK, (char *) Language(286)); + Enter(1); /* Password: */ - printf("%s", (char *) Language(8)); - fflush(stdout); - fflush(stdin); + pout(YELLOW, BLACK, (char *) Language(8)); GetstrC(fdb.Password, 20); } } @@ -994,10 +987,10 @@ int Addfile(char *File, int AreaNum, int fileid) } if (lines) { Syslog('+', "Using %d FILE_ID.DIZ lines for description", lines); - colour(CFG.TextColourF, CFG.TextColourB); /* Found FILE_ID.DIZ in */ - printf("%s %s\n", (char *) Language(257), File); - fflush(stdout); + sprintf(msg, "%s %s", (char *) Language(257), File); + pout(CFG.TextColourF, CFG.TextColourB, msg); + Enter(1); } else { Syslog('!', "No FILE_ID.DIZ lines left to use"); GotId = FALSE; @@ -1012,15 +1005,16 @@ int Addfile(char *File, int AreaNum, int fileid) for (i = 0; i < 26; i++) *(Desc + i) = (char *) calloc(49, sizeof(char)); - colour(12,0); + Enter(1); /* Please enter description of file */ - printf("\n%s %s\n\n", (char *) Language(287), File); - while (TRUE) { - colour(10,0); - printf("%2d> ", iDesc); - fflush(stdout); - colour(CFG.InputColourF, CFG.InputColourB); + sprintf(msg, "%s %s", (char *) Language(287), File); + pout(LIGHTRED, BLACK, msg); + Enter(2); + while (TRUE) { + sprintf(msg, "%2d> ", iDesc); + pout(LIGHTGREEN, BLACK, msg); + colour(CFG.InputColourF, CFG.InputColourB); GetstrC(*(Desc + iDesc), 47); if ((strcmp(*(Desc + iDesc), "")) == 0) @@ -1061,7 +1055,7 @@ int Addfile(char *File, int AreaNum, int fileid) Enter(1); /* Your upload time has been returned to you. Thank you for your upload! */ - pout(10, 0, (char *) Language(288)); + pout(LIGHTGREEN, BLACK, (char *) Language(288)); Enter(1); } diff --git a/mbsebbs/fsedit.c b/mbsebbs/fsedit.c index 96803064..bc438869 100644 --- a/mbsebbs/fsedit.c +++ b/mbsebbs/fsedit.c @@ -39,46 +39,54 @@ #include "pinfo.h" #include "fsedit.h" #include "term.h" +#include "ttyio.h" void Show_Ins(void) { locate(1, 70); colour(YELLOW, BLUE); - printf("%s", InsMode ? "INS": "OVR"); - fflush(stdout); + if (InsMode) + PUTSTR((char *)"INS"); + else + PUTSTR((char *)"OVR"); } void Top_Help() { + char temp[81]; + locate(1,1); colour(YELLOW, BLUE); - printf("%s", padleft((char *)"Press ESC for menu, other keys is edit text", 80, ' ')); + sprintf(temp, "%s", padleft((char *)"Press ESC for menu, other keys is edit text", 79, ' ')); + PUTSTR(temp); Show_Ins(); } void Top_Menu(void) { + char temp[81]; + locate(1,1); colour(WHITE, RED); - printf("%s", padleft((char *)"(A)bort (H)elp (S)ave - Any other key is continue edit", 80, ' ')); - fflush(stdout); + sprintf(temp, "%s", padleft((char *)"(A)bort (H)elp (S)ave - Any other key is continue edit", 79, ' ')); + PUTSTR(temp); } void Ls(int a, int y) { locate(y, 10); - printf("%c ", a ? 179 : '|'); + PUTCHAR(a ? 179 : '|'); } void Rs(int a) { colour(LIGHTGREEN, BLUE); - printf("%c", a ? 179 : '|'); + PUTCHAR(a ? 179 : '|'); } @@ -87,8 +95,8 @@ void Ws(int a, int y) int i; Ls(a, y); - for (i = 0; i < 57; i++) - printf(" "); + for (i = 0; i < 58; i++) + PUTCHAR(' '); Rs(a); } @@ -97,7 +105,7 @@ void Hl(int a, int y, char *txt) { Ls(a, y); colour(WHITE, BLUE); - printf("%s", padleft(txt, 57, ' ')); + PUTSTR(padleft(txt, 58, ' ')); Rs(a); } @@ -112,16 +120,16 @@ void Full_Help(void) /* Top row */ locate(1, 10); - printf("%c", a ? 213 : '+'); + PUTCHAR(a ? 213 : '+'); for (i = 0; i < 58; i++) - printf("%c", a ? 205 : '='); - printf("%c", a ? 184 : '+'); + PUTCHAR(a ? 205 : '='); + PUTCHAR(a ? 184 : '+'); Ws(a, 2); Ls(a, 3); colour(YELLOW, BLUE); - printf("%s", padleft((char *)" Editor Help", 57, ' ')); + PUTSTR(padleft((char *)" Editor Help", 58, ' ')); Rs(a); Ws(a, 4); @@ -138,26 +146,24 @@ void Full_Help(void) Ws(a, 15); locate(16,10); - printf("%c", a ? 212 : '+'); + PUTCHAR(a ? 212 : '+'); for (i = 0; i < 58; i++) - printf("%c", a ? 205 : '='); - printf("%c", a ? 190 : '+'); - fflush(stdout); + PUTCHAR(a ? 205 : '='); + PUTCHAR(a ? 190 : '+'); } + void Setcursor(void) { CurRow = Row + TopVisible - 1; locate(Row + 1, Col); - fflush(stdout); } void Beep(void) { - printf("\007"); - fflush(stdout); + PUTCHAR('\007'); } @@ -177,7 +183,7 @@ void Refresh(void) if ((i >= TopVisible) && (i < (TopVisible + exitinfo.iScreenLen -1))) { locate(j, 1); j++; - printf("%s", Message[i]); + PUTSTR(Message[i]); } } Setcursor(); @@ -195,12 +201,11 @@ void GetstrLC(char *sStr, int iMaxlen) while (ch != 13) { - fflush(stdout); ch = Readkey(); if ((ch == 8) || (ch == KEY_DEL) || (ch == 127)) { if (iPos > 0) { - printf("\b \b"); + BackErase(); sStr[--iPos] = '\0'; } else { Beep(); @@ -211,14 +216,14 @@ void GetstrLC(char *sStr, int iMaxlen) if (iPos <= iMaxlen) { iPos++; sprintf(sStr, "%s%c", sStr, ch); - printf("%c", ch); + PUTCHAR(ch); } else { Beep(); } } } - printf("\n"); + Enter(1); } @@ -403,12 +408,6 @@ int Fs_Edit() Syslog('b', "FSEDIT: Entering FullScreen editor"); clear(); - fflush(stdout); - if ((ttyfd = open("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - WriteError("$Can't open tty"); - return FALSE; - } - Setraw(); InsMode = TRUE; TopVisible = 1; Col = 1; @@ -521,9 +520,10 @@ int Fs_Edit() Setcursor(); for (i = Col; i <= strlen(Message[CurRow]); i++) { Message[CurRow][i-1] = Message[CurRow][i]; - printf("%c", Message[CurRow][i]); + PUTCHAR(Message[CurRow][i]); } - printf(" \b"); + PUTCHAR(' '); + PUTCHAR('\b'); Message[CurRow][i-1] = '\0'; Setcursor(); } else if (((strlen(Message[CurRow]) + strlen(Message[CurRow+1]) < 75) @@ -572,8 +572,7 @@ int Fs_Edit() } else { if (Col == strlen(Message[CurRow]) + 1) { /* BS at end of line */ - printf("\b \b"); - fflush(stdout); + BackErase(); Col--; Message[CurRow][Col-1] = '\0'; Changed = TRUE; @@ -583,9 +582,10 @@ int Fs_Edit() Setcursor(); for (i = Col; i <= strlen(Message[CurRow]); i++) { Message[CurRow][i-1] = Message[CurRow][i]; - printf("%c", Message[CurRow][i]); + PUTCHAR(Message[CurRow][i]); } - printf(" \b"); + PUTCHAR(' '); + PUTCHAR('\b'); Message[CurRow][strlen(Message[CurRow])] = '\0'; Setcursor(); Changed = TRUE; @@ -617,16 +617,17 @@ int Fs_Edit() tmpname = calloc(PATH_MAX, sizeof(char)); filname = calloc(PATH_MAX, sizeof(char)); - colour(14, 0); + Enter(1); /* Please enter filename: */ - printf("\n%s", (char *) Language(245)); + pout(YELLOW, BLACK, (char *) Language(245)); colour(CFG.InputColourF, CFG.InputColourB); GetstrLC(filname, 80); if ((strcmp(filname, "") == 0)) { - colour(CFG.HiliteF, CFG.HiliteB); + Enter(2); /* No filename entered, aborting */ - printf("\n\n%s\n", (char *) Language(246)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(246)); + Enter(1); Pause(); free(filname); free(tmpname); @@ -635,9 +636,10 @@ int Fs_Edit() } if (*(filname) == '/' || *(filname) == ' ') { - colour(CFG.HiliteF, CFG.HiliteB); + Enter(2); /* Illegal filename */ - printf("\n\n%s\n", (char *) Language(247)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(1); Pause(); free(tmpname); free(filname); @@ -648,9 +650,10 @@ int Fs_Edit() sprintf(tmpname, "%s/%s/wrk/%s", CFG.bbs_usersdir, exitinfo.Name, filname); if ((fd = fopen(tmpname, "r")) == NULL) { WriteError("$Can't open %s", tmpname); - colour(CFG.HiliteF, CFG.HiliteB); + Enter(2); /* File does not exist, please try again */ - printf("\n\n%s\n", (char *) Language(296)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(296)); + Enter(1); Pause(); } else { while ((fgets(filname, 80, fd)) != NULL) { @@ -692,10 +695,7 @@ int Fs_Edit() ch = toupper(Readkey()); if (ch == 'A' || ch == 'S') { Syslog('b', "FSEDIT: %s message (%c)", (ch == 'S' && Changed) ? "Saving" : "Aborting", ch); - Unsetraw(); - close(ttyfd); clear(); - fflush(stdout); if (ch == 'S' && Changed) { Syslog('+', "FSEDIT: Message will be saved"); return TRUE; @@ -732,8 +732,7 @@ int Fs_Edit() Refresh(); } else { Col++; - printf("%c", ch); - fflush(stdout); + PUTCHAR(ch); } Changed = TRUE; } else { @@ -763,14 +762,13 @@ int Fs_Edit() Refresh(); } else { locate(Row + 1, 1); - printf(Message[CurRow]); + PUTSTR(Message[CurRow]); Setcursor(); } Changed = TRUE; } else { Message[CurRow][Col-1] = ch; - printf("%c", ch); - fflush(stdout); + PUTCHAR(ch); Col++; Changed = TRUE; } @@ -780,8 +778,6 @@ int Fs_Edit() } WriteError("FsEdit(): Impossible to be here"); - Unsetraw(); - close(ttyfd); return FALSE; } diff --git a/mbsebbs/funcs.c b/mbsebbs/funcs.c index 12491046..47d2eb4a 100644 --- a/mbsebbs/funcs.c +++ b/mbsebbs/funcs.c @@ -35,6 +35,8 @@ #include "../lib/msgtext.h" #include "../lib/msg.h" #include "funcs.h" +#include "term.h" +#include "ttyio.h" extern pid_t mypid; /* Original pid */ @@ -54,20 +56,23 @@ void UserSilent(int flag) */ int CheckStatus() { - static char buf[81]; + static char buf[81], msg[81]; - sprintf(buf, "SBBS:0;"); - if (socket_send(buf) == 0) { - strcpy(buf, socket_receive()); - if (strncmp(buf, "100:2,0", 7) == 0) - return TRUE; - if ((strncmp(buf, "100:2,2", 7) == 0) && (!ttyinfo.honor_zmh)) - return TRUE; - buf[strlen(buf) -1] = '\0'; - printf("\n\n\007*** %s ***\n\n\n", buf+8); - fflush(stdout); - } - return FALSE; + sprintf(buf, "SBBS:0;"); + if (socket_send(buf) == 0) { + strcpy(buf, socket_receive()); + if (strncmp(buf, "100:2,0", 7) == 0) + return TRUE; + if ((strncmp(buf, "100:2,2", 7) == 0) && (!ttyinfo.honor_zmh)) + return TRUE; + buf[strlen(buf) -1] = '\0'; + Enter(2); + PUTCHAR('\007'); + sprintf(msg, "*** %s ***", buf+8); + PUTSTR(msg); + Enter(3); + } + return FALSE; } diff --git a/mbsebbs/input.c b/mbsebbs/input.c index b6735404..fa41450e 100644 --- a/mbsebbs/input.c +++ b/mbsebbs/input.c @@ -36,6 +36,243 @@ #include "timeout.h" #include "language.h" #include "term.h" +#include "ttyio.h" + + + + +/* + * Wait for a character for a maximum of wtime * 10 mSec. + */ +int Waitchar(unsigned char *ch, int wtime) +{ + int i, rc = TIMEOUT; + + for (i = 0; i < wtime; i++) { + rc = GETCHAR(0); +// Syslog('t', "Waitchar(): after GETCHAR() tty_status = %d, rc = %d", tty_status, rc); + if (tty_status == STAT_SUCCESS) { +// Syslog('t', "Waitchar(): return %d", rc); + memcpy(ch, &rc, sizeof(unsigned char)); + return 1; + } + if (tty_status != STAT_TIMEOUT) { + Syslog('t', "Waitchar(): error rc=%d", rc); + return rc; + } + msleep(10); + } + // Syslog('t', "Waitchar() timeout returns %d", rc); + return rc; +} + + + +int Escapechar(unsigned char *ch) +{ + int rc; + unsigned char c; + + /* + * Escape character, if nothing follows within + * 50 mSec, the user really pressed . + */ + if ((rc = Waitchar(ch, 5)) == TIMEOUT) + return rc; + + if (*ch == '[') { + /* + * Start of CSI sequence. If nothing follows, + * return immediatly. + */ + if ((rc = Waitchar(ch, 5)) == TIMEOUT) + return rc; + + /* + * Test for the most important keys. Note + * that only the cursor movement keys are + * guaranteed to work with PC-clients. + */ + c = *ch; + if (c == 'A') + c = KEY_UP; + if (c == 'B') + c = KEY_DOWN; + if (c == 'C') + c = KEY_RIGHT; + if (c == 'D') + c = KEY_LEFT; + if ((c == '1') || (c == 'H') || (c == 0)) + c = KEY_HOME; + if ((c == '4') || (c == 'K') || (c == 101) || (c == 144)) + c = KEY_END; + if (c == '2') + c = KEY_INS; + if (c == '3') + c = KEY_DEL; + if (c == '5') + c = KEY_PGUP; + if (c == '6') + c = KEY_PGDN; + memcpy(ch, &c, sizeof(unsigned char)); + return rc; + } + + return -1; +} + + + +/* + * This next function will detect the grey keys on the keyboard for + * VT100, VT220, Xterm, PC-ANSI, and Linux console. Works with + * several terminals on serial lines (tested 1200 bps). + * If for example cursur keys are detected, this function returns + * a translated value. + */ +unsigned char Readkey(void) +{ + unsigned char ch = 0; + int rc = TIMEOUT; + + Syslog('t', "Readkey()"); + while (rc == TIMEOUT) { + rc = Waitchar(&ch, 5); +// Syslog('t', "rc = %d, ch = %d", rc, ch); + + /* + * If the character is not an Escape character, + * then this function is finished. + */ + if ((rc == 1) && (ch != KEY_ESCAPE)) { + Syslog('t', "Readkey() returns %d", ch); + return ch; + } + + if ((rc == 1) && (ch == KEY_ESCAPE)) { + rc = Escapechar(&ch); + if (rc == 1) { + Syslog('t', "Readkey() returns %d", ch); + return ch; + } else { + Syslog('t', "Readkey() returns %d", KEY_ESCAPE); + return KEY_ESCAPE; + } + } + } + Syslog('t', "Readkey() returns %d", rc); + return rc; +} + + + +/* + * Read the (locked) speed from the tty + */ +long Speed(void) +{ + speed_t mspeed; + + mspeed = cfgetospeed(&tbufs); +#ifdef CBAUD + switch (mspeed & CBAUD) { +#else + switch (mspeed) { +#endif + case B0: return 0; +#if defined(B50) + case B50: return 50; +#endif +#if defined(B75) + case B75: return 75; +#endif +#if defined(B110) + case B110: return 110; +#endif +#if defined(B134) + case B134: return 134; +#endif +#if defined(B150) + case B150: return 150; +#endif +#if defined(B200) + case B200: return 200; +#endif +#if defined(B300) + case B300: return 300; +#endif +#if defined(B600) + case B600: return 600; +#endif +#if defined(B1200) + case B1200: return 1200; +#endif +#if defined(B1800) + case B1800: return 1800; +#endif +#if defined(B2400) + case B2400: return 2400; +#endif +#if defined(B4800) + case B4800: return 4800; +#endif +#if defined(B9600) + case B9600: return 9600; +#endif +#if defined(B19200) + case B19200: return 19200; +#endif +#if defined(B38400) + case B38400: return 38400; +#endif +#if defined(B57600) + case B57600: return 57600; +#endif +#if defined(B115200) + case B115200: return 115200; +#endif +#if defined(B230400) + case B230400: return 203400; +#endif +#if defined(B460800) + case B460800: return 460800; +#endif +#if defined(B500000) + case B500000: return 500000; +#endif +#if defined(B576000) + case B576000: return 576000; +#endif +#if defined(B921600) + case B921600: return 921600; +#endif +#if defined(B1000000) + case B1000000: return 1000000; +#endif +#if defined(B1152000) + case B1152000: return 1152000; +#endif +#if defined(B1500000) + case B1500000: return 1500000; +#endif +#if defined(B2000000) + case B2000000: return 2000000; +#endif +#if defined(B2500000) + case B2500000: return 2500000; +#endif +#if defined(B3000000) + case B3000000: return 3000000; +#endif +#if defined(B3500000) + case B3500000: return 3500000; +#endif +#if defined(B4000000) + case B4000000: return 4000000; +#endif + default: return 9600; + } +} @@ -56,6 +293,16 @@ int traduce(char *ch) } + +void BackErase(void) +{ + PUTCHAR('\b'); + PUTCHAR(' '); + PUTCHAR('\b'); +} + + + /* * Get a character string with cursor position */ @@ -64,40 +311,34 @@ void GetstrP(char *sStr, int iMaxLen, int Position) unsigned char ch = 0; int iPos = Position; - if ((ttyfd = open("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - perror("open 1"); - return; - } - Setraw(); - + FLUSHIN(); alarm_on(); while (ch != KEY_ENTER) { - fflush(stdout); ch = Readkey(); if ((ch == KEY_BACKSPACE) || (ch == KEY_DEL) || (ch == KEY_RUBOUT)) { if (iPos > 0) { - printf("\b \b"); + BackErase(); sStr[--iPos] = '\0'; } else - putchar('\007'); + PUTCHAR('\007'); } if ((ch > 31 && ch < 127) || traduce(&ch)) { if (iPos <= iMaxLen) { iPos++; sprintf(sStr, "%s%c", sStr, ch); - printf("%c", ch); - } else - putchar('\007'); + PUTCHAR(ch); + } else { + PUTCHAR('\007'); + } } } - Unsetraw(); - close(ttyfd); - printf("\n"); + PUTCHAR('\r'); + PUTCHAR('\n'); } @@ -110,42 +351,34 @@ void GetstrC(char *sStr, int iMaxlen) unsigned char ch = 0; int iPos = 0; - fflush(stdout); - if ((ttyfd = open ("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - perror("open 6"); - return; - } - Setraw(); - + FLUSHIN(); strcpy(sStr, ""); alarm_on(); while (ch != 13) { - fflush(stdout); ch = Readkey(); if ((ch == 8) || (ch == KEY_DEL) || (ch == 127)) { if (iPos > 0) { - printf("\b \b"); + BackErase(); sStr[--iPos] = '\0'; } else - putchar('\007'); + PUTCHAR('\007'); } if ((ch > 31) && (ch < 127) && (ch != ',')) { if (iPos <= iMaxlen) { iPos++; sprintf(sStr, "%s%c", sStr, ch); - printf("%c", ch); + PUTCHAR(ch); } else - putchar('\007'); + PUTCHAR('\007'); } } - Unsetraw(); - close(ttyfd); - printf("\n"); + PUTCHAR('\r'); + PUTCHAR('\n'); } @@ -158,42 +391,34 @@ void GetstrU(char *sStr, int iMaxlen) unsigned char ch = 0; int iPos = 0; - fflush(stdout); - if ((ttyfd = open ("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - perror("open 6"); - return; - } - Setraw(); - + FLUSHIN(); strcpy(sStr, ""); alarm_on(); while (ch != 13) { - fflush(stdout); ch = Readkey(); if ((ch == 8) || (ch == KEY_DEL) || (ch == 127)) { if (iPos > 0) { - printf("\b \b"); + BackErase(); sStr[--iPos] = '\0'; } else - putchar('\007'); + PUTCHAR('\007'); } if (isalnum(ch) || (ch == '@') || (ch == '.') || (ch == '-') || (ch == '_')) { if (iPos <= iMaxlen) { iPos++; sprintf(sStr, "%s%c", sStr, ch); - printf("%c", ch); + PUTCHAR(ch); } else - putchar('\007'); + PUTCHAR('\007'); } } - Unsetraw(); - close(ttyfd); - printf("\n"); + PUTCHAR('\r'); + PUTCHAR('\n'); } @@ -203,46 +428,38 @@ void GetstrU(char *sStr, int iMaxlen) */ void GetPhone(char *sStr, int iMaxlen) { - unsigned char ch = 0; - int iPos = 0; + unsigned char ch = 0; + int iPos = 0; - fflush(stdout); + FLUSHIN(); + + strcpy(sStr, ""); + alarm_on(); - if ((ttyfd = open ("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - perror("open 5"); - return; - } - Setraw(); + while (ch != 13) { - strcpy(sStr, ""); - alarm_on(); + ch = Readkey(); - while (ch != 13) { - - fflush(stdout); - ch = Readkey(); - - if ((ch == 8) || (ch == KEY_DEL) || (ch == 127)) { - if (iPos > 0) { - printf("\b \b"); - sStr[--iPos]='\0'; - } else - putchar('\007'); - } - - if ((ch >= '0' && ch <= '9') || (ch == '-') || (ch == '+')) { - if (iPos <= iMaxlen) { - iPos++; - sprintf(sStr, "%s%c", sStr, ch); - printf("%c", ch); - } else - putchar('\007'); - } + if ((ch == 8) || (ch == KEY_DEL) || (ch == 127)) { + if (iPos > 0) { + BackErase(); + sStr[--iPos]='\0'; + } else + PUTCHAR('\007'); } - Unsetraw(); - close(ttyfd); - printf("\n"); + if ((ch >= '0' && ch <= '9') || (ch == '-') || (ch == '+')) { + if (iPos <= iMaxlen) { + iPos++; + sprintf(sStr, "%s%c", sStr, ch); + PUTCHAR(ch); + } else + PUTCHAR('\007'); + } + } + + PUTCHAR('\r'); + PUTCHAR('\n'); } @@ -252,48 +469,39 @@ void GetPhone(char *sStr, int iMaxlen) */ void Getnum(char *sStr, int iMaxlen) { - unsigned char ch = 0; - int iPos = 0; + unsigned char ch = 0; + int iPos = 0; - fflush(stdout); + FLUSHIN(); - if ((ttyfd = open ("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - perror("open 5"); - return; - } - Setraw(); + strcpy(sStr, ""); + alarm_on(); - strcpy(sStr, ""); - alarm_on(); + while (ch != 13) { - while (ch != 13) { + ch = Readkey(); - fflush(stdout); - ch = Readkey(); - - if ((ch == 8) || (ch == KEY_DEL) || (ch == 127)) { - if (iPos > 0) { - printf("\b \b"); - sStr[--iPos]='\0'; - } else - putchar('\007'); - } - - if ((ch >= '0' && ch <= '9') || (ch == '-') || (ch == ' ') \ - || (ch == ',') || (ch == '.')) { - - if (iPos <= iMaxlen) { - iPos++; - sprintf(sStr, "%s%c", sStr, ch); - printf("%c", ch); - } else - putchar('\007'); - } + if ((ch == 8) || (ch == KEY_DEL) || (ch == 127)) { + if (iPos > 0) { + BackErase(); + sStr[--iPos]='\0'; + } else + PUTCHAR('\007'); } - Unsetraw(); - close(ttyfd); - printf("\n"); + if ((ch >= '0' && ch <= '9') || (ch == '-') || (ch == ' ') || (ch == ',') || (ch == '.')) { + + if (iPos <= iMaxlen) { + iPos++; + sprintf(sStr, "%s%c", sStr, ch); + PUTCHAR(ch); + } else + PUTCHAR('\007'); + } + } + + PUTCHAR('\r'); + PUTCHAR('\n'); } @@ -304,57 +512,48 @@ void Getnum(char *sStr, int iMaxlen) */ void GetDate(char *sStr, int iMaxlen) { - unsigned char ch = 0; - int iPos = 0; + unsigned char ch = 0; + int iPos = 0; - fflush(stdout); + FLUSHIN(); + strcpy(sStr, ""); - strcpy(sStr, ""); + alarm_on(); + while (ch != 13) { - if ((ttyfd = open ("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - perror("open 4"); - return; - } - Setraw(); + ch = Readkey(); - alarm_on(); - while (ch != 13) { + if ((ch == 8) || (ch == KEY_DEL) || (ch == 127)) { + if (iPos > 0) + BackErase(); + else + PUTCHAR('\007'); - fflush(stdout); - ch = Readkey(); + if (iPos == 3 || iPos == 6) { + BackErase(); + --iPos; + } - if ((ch == 8) || (ch == KEY_DEL) || (ch == 127)) { - if (iPos > 0) - printf("\b \b"); - else - putchar('\007'); - - if (iPos == 3 || iPos == 6) { - printf("\b \b"); - --iPos; - } - - sStr[--iPos]='\0'; - } - - if (ch >= '0' && ch <= '9') { - if (iPos < iMaxlen) { - iPos++; - sprintf(sStr, "%s%c", sStr, ch); - printf("%c", ch); - if (iPos == 2 || iPos == 5) { - printf("-"); - sprintf(sStr, "%s-", sStr); - iPos++; - } - } else - putchar('\007'); - } + sStr[--iPos]='\0'; } - Unsetraw(); - close(ttyfd); - printf("\n"); + if (ch >= '0' && ch <= '9') { + if (iPos < iMaxlen) { + iPos++; + sprintf(sStr, "%s%c", sStr, ch); + PUTCHAR(ch); + if (iPos == 2 || iPos == 5) { + PUTCHAR('-'); + sprintf(sStr, "%s-", sStr); + iPos++; + } + } else + PUTCHAR('\007'); + } + } + + PUTCHAR('\r'); + PUTCHAR('\n'); } @@ -371,11 +570,6 @@ void Getname(char *sStr, int iMaxlen) strcpy(sStr, ""); - if ((ttyfd = open ("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - perror("open 2"); - return; - } - Setraw(); alarm_on(); while (ch != 13) { @@ -418,8 +612,6 @@ void Getname(char *sStr, int iMaxlen) } } - Unsetraw(); - close(ttyfd); printf("\n"); } @@ -438,11 +630,6 @@ void GetnameNE(char *sStr, int iMaxlen) strcpy(sStr, ""); - if ((ttyfd = open ("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - perror("open 2"); - return; - } - Setraw(); alarm_on(); while (ch != 13) { @@ -485,8 +672,6 @@ void GetnameNE(char *sStr, int iMaxlen) } } - Unsetraw(); - close(ttyfd); printf("\n"); } @@ -504,17 +689,6 @@ void Getpass(char *theword) int counter = 0; char password[Max_passlen+1]; - /* - * Open the device that we want to read the password from, you can't use - * stdin as this might change in a pipe - */ - if ((ttyfd = open ("/dev/tty", O_RDWR)) < 0) { - perror("open 7"); - ExitClient(MBERR_TTYIO_ERROR); - } - - /* Set Raw mode so that the characters don't echo */ - Setraw(); alarm_on(); /* @@ -543,8 +717,6 @@ void Getpass(char *theword) printf("%c", CFG.iPasswd_Char); } } - Unsetraw(); /* Go normal */ - close(ttyfd); password[counter] = '\0'; /* Make sure the string has a NULL at the end*/ strcpy(theword,password); @@ -554,33 +726,30 @@ void Getpass(char *theword) void Pause() { - int i, x; - char *string; + int i, x; + char *string; - string = malloc(81); + string = malloc(81); - /* Press (Enter) to continue: */ - sprintf(string, "\r%s", (char *) Language(375)); - colour(CFG.CRColourF, CFG.CRColourB); - printf(string); - - do { - fflush(stdout); - fflush(stdin); - alarm_on(); - i = Getone(); - } while ((i != '\r') && (i != '\n')); + /* Press (Enter) to continue: */ + sprintf(string, "\r%s", (char *) Language(375)); + colour(CFG.CRColourF, CFG.CRColourB); + PUTSTR(string); + + do { + alarm_on(); + i = Readkey(); + } while ((i != '\r') && (i != '\n')); - x = strlen(string); - for(i = 0; i < x; i++) - printf("\b"); - for(i = 0; i < x; i++) - printf(" "); - for(i = 0; i < x; i++) - printf("\b"); - fflush(stdout); + x = strlen(string); + for(i = 0; i < x; i++) + PUTCHAR('\b'); + for(i = 0; i < x; i++) + PUTCHAR(' '); + for(i = 0; i < x; i++) + PUTCHAR('\b'); - free(string); + free(string); } diff --git a/mbsebbs/input.h b/mbsebbs/input.h index d589faaa..36807c37 100644 --- a/mbsebbs/input.h +++ b/mbsebbs/input.h @@ -4,6 +4,13 @@ #define _INPUT_H +long Speed(void); /* Get (locked) tty speed */ +int Waitchar(unsigned char *, int); /* Wait n* 10mSec for char */ +int Escapechar(unsigned char *); /* Escape sequence test */ +unsigned char Readkey(void); /* Read a translated key */ + + +void BackErase(void); /* Send backspace with erase */ void GetstrU(char *, int); /* Get string, forbid spaces */ void GetstrP(char *, int, int); /* Get string with cursor position */ void GetstrC(char *, int); /* Get string, length, clear string */ diff --git a/mbsebbs/language.c b/mbsebbs/language.c index d86f9c40..cb675dc6 100644 --- a/mbsebbs/language.c +++ b/mbsebbs/language.c @@ -35,7 +35,7 @@ #include "input.h" #include "language.h" #include "term.h" - +#include "ttyio.h" /* @@ -84,30 +84,32 @@ int Keystroke(int lRecord, int Pos) */ void Set_Language(int iLanguage) { - FILE *pLang; - char *temp; + FILE *pLang; + char *temp; - temp = calloc(PATH_MAX, sizeof(char)); - sprintf(temp, "%s/etc/language.data", getenv("MBSE_ROOT")); - - if ((pLang = fopen(temp, "rb")) == NULL) { - WriteError("Language: Can't open file: %s", temp); - printf("\nLanguage: Can't open language file\n\n"); - free(temp); - Pause(); - return; - } - - fread(&langhdr, sizeof(langhdr), 1, pLang); - while (fread(&lang, langhdr.recsize, 1, pLang) == 1) { - if ((lang.LangKey[0] == iLanguage) && (lang.Available)) { - strcpy(CFG.current_language, lang.Filename); - break; - } - } + temp = calloc(PATH_MAX, sizeof(char)); + sprintf(temp, "%s/etc/language.data", getenv("MBSE_ROOT")); + if ((pLang = fopen(temp, "rb")) == NULL) { + WriteError("Language: Can't open file: %s", temp); + Enter(1); + PUTSTR((char *)"Language: Can't open language file"); + Enter(2); free(temp); - fclose(pLang); + Pause(); + return; + } + + fread(&langhdr, sizeof(langhdr), 1, pLang); + while (fread(&lang, langhdr.recsize, 1, pLang) == 1) { + if ((lang.LangKey[0] == iLanguage) && (lang.Available)) { + strcpy(CFG.current_language, lang.Filename); + break; + } + } + + free(temp); + fclose(pLang); } @@ -118,34 +120,36 @@ void Set_Language(int iLanguage) */ void InitLanguage() { - FILE *pLang; - int iLang = 0; - char *temp; + FILE *pLang; + int iLang = 0; + char *temp; - temp = calloc(PATH_MAX, sizeof(char)); + temp = calloc(PATH_MAX, sizeof(char)); - sprintf(temp, "%s/etc/%s", getenv("MBSE_ROOT"), CFG.current_language); - if ((pLang = fopen(temp, "rb")) == NULL) { - WriteError("$FATAL: Can't open %s", temp); - ExitClient(MBERR_INIT_ERROR); + sprintf(temp, "%s/etc/%s", getenv("MBSE_ROOT"), CFG.current_language); + if ((pLang = fopen(temp, "rb")) == NULL) { + WriteError("$FATAL: Can't open %s", temp); + ExitClient(MBERR_INIT_ERROR); + } + + while (fread(&ldata, sizeof(ldata), 1, pLang) == 1) { + *(mLanguage + iLang) = (char *) calloc(strlen(ldata.sString) + 1, sizeof(char)); + *(mKeystroke + iLang) = (char *) calloc(strlen(ldata.sKey) + 1, sizeof(char)); + strcpy(mLanguage[iLang], ldata.sString); + strcpy(mKeystroke[iLang], ldata.sKey); + iLang++; + + if (iLang >= LANG) { + Enter(1); + PUTSTR((char *)"FATAL: Language file has to many lines in it"); + Enter(2); + ExitClient(MBERR_INIT_ERROR); } + } - while (fread(&ldata, sizeof(ldata), 1, pLang) == 1) { - *(mLanguage + iLang) = (char *) calloc(strlen(ldata.sString) + 1, sizeof(char)); - *(mKeystroke + iLang) = (char *) calloc(strlen(ldata.sKey) + 1, sizeof(char)); - strcpy(mLanguage[iLang], ldata.sString); - strcpy(mKeystroke[iLang], ldata.sKey); - iLang++; - - if(iLang >= LANG) { - printf("FATAL: Language file has to many lines in it"); - ExitClient(MBERR_INIT_ERROR); - } - } - - fclose(pLang); - Syslog('b', "%d language lines read (%s)", iLang, CFG.current_language); - free(temp); + fclose(pLang); + Syslog('b', "%d language lines read (%s)", iLang, CFG.current_language); + free(temp); } diff --git a/mbsebbs/lastcallers.c b/mbsebbs/lastcallers.c index 4a535a11..2dc7ee6f 100644 --- a/mbsebbs/lastcallers.c +++ b/mbsebbs/lastcallers.c @@ -36,6 +36,7 @@ #include "language.h" #include "lastcallers.h" #include "term.h" +#include "ttyio.h" /* @@ -86,7 +87,7 @@ void LastCallers(char *OpData) colour(LIGHTRED, BLACK); Center(Underline); - printf("\n"); + Enter(1); /* # User Name Device timeOn Calls Location */ pout(LIGHTGREEN, BLACK, (char *) Language(85)); @@ -100,31 +101,34 @@ void LastCallers(char *OpData) count++; colour(WHITE, BLACK); - printf("%-5d", count); + sprintf(Heading, "%-5d", count); + PUTSTR(Heading); colour(LIGHTCYAN, BLACK); if ((strcasecmp(OpData, "/H")) == 0) { if ((strcmp(lcall.Handle, "") != 0 && *(lcall.Handle) != ' ')) - printf("%-20s", lcall.Handle); + sprintf(Heading, "%-20s", lcall.Handle); else - printf("%-20s", lcall.UserName); + sprintf(Heading, "%-20s", lcall.UserName); } else if (strcasecmp(OpData, "/U") == 0) { - printf("%-20s", lcall.Name); + sprintf(Heading, "%-20s", lcall.Name); } else { - printf("%-20s", lcall.UserName); + sprintf(Heading, "%-20s", lcall.UserName); } + PUTSTR(Heading); - colour(LIGHTBLUE, BLACK); - printf("%-8s", lcall.Device); + sprintf(Heading, "%-8s", lcall.Device); + pout(LIGHTBLUE, BLACK, Heading); - colour(LIGHTMAGENTA, BLACK); - printf("%-8s", lcall.TimeOn); + sprintf(Heading, "%-8s", lcall.TimeOn); + pout(LIGHTMAGENTA, BLACK, Heading); - colour(YELLOW, BLACK); - printf("%-7d", lcall.Calls); + sprintf(Heading, "%-7d", lcall.Calls); + pout(YELLOW, BLACK, Heading); - colour(LIGHTRED, BLACK); - printf("%-32s\n", lcall.Location); + sprintf(Heading, "%-32s", lcall.Location); + pout(LIGHTRED, BLACK, Heading); + Enter(1); LineCount++; if (LineCount == exitinfo.iScreenLen) { @@ -138,7 +142,7 @@ void LastCallers(char *OpData) fLine(79); fclose(pLC); - printf("\n"); + Enter(1); Pause(); } free(sFileName); diff --git a/mbsebbs/lineedit.c b/mbsebbs/lineedit.c index 170f1091..d1221bc4 100644 --- a/mbsebbs/lineedit.c +++ b/mbsebbs/lineedit.c @@ -38,6 +38,7 @@ #include "timeout.h" #include "lineedit.h" #include "term.h" +#include "ttyio.h" extern int Line; @@ -60,516 +61,516 @@ void Line_Edit_Center(void); /* Center a line */ void Line_Edit_Append() { - if((Line - 1) == TEXTBUFSIZE) { - Enter(1); - /* Maximum message length exceeded */ - pout(3, 0, (char *) Language(166)); - Enter(1); - return; - } - - while (TRUE) { - colour(10, 0); - printf("%-2d : ", Line); - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - fflush(stdout); - alarm_on(); - GetstrP(Message[Line], 72, 0); - - if((strcmp(Message[Line], "")) == 0) - return; - - Line++; - if((Line - 1) == TEXTBUFSIZE) { - Enter(1); - /* Maximum message length exceeded */ - pout(12, 0, (char *) Language(166)); - Enter(1); - return; - } + char msg[41]; + + if ((Line - 1) == TEXTBUFSIZE) { + Enter(1); + /* Maximum message length exceeded */ + pout(CYAN, BLACK, (char *) Language(166)); + Enter(1); + return; + } + + while (TRUE) { + sprintf(msg, "%-2d : ", Line); + pout(LIGHTGREEN, BLACK, msg); + colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + alarm_on(); + GetstrP(Message[Line], 72, 0); + + if ((strcmp(Message[Line], "")) == 0) + return; + + Line++; + if ((Line - 1) == TEXTBUFSIZE) { + Enter(1); + /* Maximum message length exceeded */ + pout(LIGHTRED, BLACK, (char *) Language(166)); + Enter(1); + return; } + } } void Line_Edit_Delete() { - int i, start, end = 0, total; - int Loop; - char temp[81]; + int i, start, end = 0, total, Loop; + char temp[81]; - while (TRUE) { - colour(10, 0); - /* Delete starting at line */ - printf("\n\n%s#(1 - %d): ", (char *) Language(176), (Line - 1) ); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp, 80); - if((strcmp(temp, "")) == 0) { - /* Aborted. */ - pout(15, 0, (char *) Language(177)); - Enter(1); - return; - } + while (TRUE) { + Enter(2); + /* Delete starting at line */ + sprintf(temp, "%s#(1 - %d): ", (char *) Language(176), (Line - 1) ); + pout(LIGHTGREEN, BLACK, temp); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp, 80); + if ((strcmp(temp, "")) == 0) { + /* Aborted. */ + pout(WHITE, BLACK, (char *) Language(177)); + Enter(1); + return; + } - start = atoi(temp); - colour(10, 0); - if(start > (Line - 1) ) - /* Please enter a number in the range of */ - printf("\n%s(1 - %d)", (char *) Language(178), (Line - 1) ); - else - break; + start = atoi(temp); + if (start > (Line - 1)) { + Enter(1); + /* Please enter a number in the range of */ + sprintf(temp, "%s(1 - %d)", (char *) Language(178), (Line - 1) ); + pout(LIGHTGREEN, BLACK, temp); + } else + break; + } + + while (TRUE) { + /* Delete ending at line */ + sprintf(temp, "%s# (1 - %d): ", (char *) Language(179), (Line - 1) ); + pout(LIGHTGREEN, BLACK, temp); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp, 80); + if ((strcmp(temp, "")) == 0) { + /* Aborted. */ + pout(WHITE, BLACK, (char *) Language(176)); + Enter(1); + return; } - while (TRUE) { - colour(10, 0); - /* Delete ending at line */ - printf("%s# (1 - %d): ", (char *) Language(179), (Line - 1) ); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp, 80); - if((strcmp(temp, "")) == 0) { - /* Aborted. */ - pout(15, 0, (char *) Language(176)); - Enter(1); - return; - } + end = atoi(temp); - end = atoi(temp); + if(end > (Line - 1)) { + Enter(1); + /* Please enter a number in the range of */ + sprintf(temp, "%s(1 - %d)", (char *) Language(179), (Line - 1) ); + pout(LIGHTGREEN, BLACK, temp); + Enter(2); + } else + break; + } - colour(10, 0); - if(end > (Line - 1)) - /* Please enter a number in the range of */ - printf("\n%s(1 - %d)\n\n", (char *) Language(179), (Line - 1) ); - else - break; + /* Get total by minusing the end line from the start line */ + /* and + 1 will give you total lines between start and end */ + total = (end - start) + 1; - } + /* Define loop by minusing total lines from end which will */ + /* do a loop for only the amount of lines left after the */ + /* end line */ + Loop = Line - end++; - /* Get total by minusing the end line from the start line */ - /* and + 1 will give you total lines between start and end */ - total = (end - start) + 1; + /* Minus the total amount of deleted lines from the current */ + /* amount of lines to keep track of how many lines you are */ + /* working with */ + Line -= total; - /* Define loop by minusing total lines from end which will */ - /* do a loop for only the amount of lines left after the */ - /* end line */ - Loop = Line - end++; + /* Do loop to copy the current message over the deleted lines */ - /* Minus the total amount of deleted lines from the current */ - /* amount of lines to keep track of how many lines you are */ - /* working with */ - Line -= total; - - /* Do loop to copy the current message over the deleted lines */ - - for (i = 0; i < Loop; i++) - strcpy(*(Message + start++), *(Message + end++)); + for (i = 0; i < Loop; i++) + strcpy(*(Message + start++), *(Message + end++)); } void Line_Edit_Edit() { - int j, edit; - char temp[81]; + int j, edit; + char temp[81]; + while (TRUE) { while (TRUE) { - while (TRUE) { - colour(10, 0); - /* Enter line # to edit */ - printf("\n%s(1 - %d): ", (char *) Language(181), (Line - 1) ); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp, 80); - if((strcmp(temp, "")) == 0) - return; + Enter(1); + /* Enter line # to edit */ + sprintf(temp, "%s(1 - %d): ", (char *) Language(181), (Line - 1) ); + pout(LIGHTGREEN, BLACK, temp); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp, 80); + if ((strcmp(temp, "")) == 0) + return; - edit = atoi(temp); + edit = atoi(temp); - colour(10, 0); - if(edit > Line) - /* Please enter a number in the range of */ - printf("\n%s(1 - %d) ", (char *) Language(178), (Line - 1) ); - else - break; - } - - colour(10, 0); - printf("\n%d : ", edit); - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - printf("%s", Message[edit]); - fflush(stdout); - j = strlen(Message[edit]); - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - alarm_on(); - GetstrP(Message[edit], 81, j); + if (edit > Line) { + Enter(1); + /* Please enter a number in the range of */ + sprintf(temp, "%s(1 - %d) ", (char *) Language(178), (Line - 1) ); + pout(LIGHTGREEN, BLACK, temp); + } else + break; } + + Enter(1); + sprintf(temp, "%d : ", edit); + pout(LIGHTGREEN, BLACK, temp); + colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + PUTSTR(Message[edit]); + j = strlen(Message[edit]); + colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + alarm_on(); + GetstrP(Message[edit], 80, j); + } } void Line_Edit_Insert() { - int i, j, start, end = 0, total; - char temp[81]; + int i, j, start, end = 0, total; + char temp[81]; - if((Line - 1) == TEXTBUFSIZE) { - Enter(1); - /* Maximum message length exceeded */ - pout(3, 0, (char *) Language(166)); - Enter(1); - return; - } + if ((Line - 1) == TEXTBUFSIZE) { + Enter(1); + /* Maximum message length exceeded */ + pout(CYAN, BLACK, (char *) Language(166)); + Enter(1); + return; + } - while (TRUE) { - colour(10, 0); - /* Enter line # to insert text before */ - printf("\n\n%s(1 - %d): ", (char *) Language(183), (Line - 1)); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp, 80); - if((strcmp(temp, "")) == 0) { - /* Aborted. */ - pout(15, 0, (char *) Language(177)); - return; - } - - start = atoi(temp); - - colour(10, 0); - if(start > (Line - 1)) - /* Please enter a number in the range of */ - printf("\n%s(1 - %d)", (char *) Language(178), (Line - 1)); - else - break; - } - - j = start; - colour(10, 0); - printf("\n%-2d : ", start); - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + while (TRUE) { + Enter(2); + /* Enter line # to insert text before */ + sprintf(temp, "%s(1 - %d): ", (char *) Language(183), (Line - 1)); + pout(LIGHTGREEN, BLACK, temp); + colour(CFG.InputColourF, CFG.InputColourB); GetstrC(temp, 80); - - if((strcmp(temp, "")) == 0) - return; - - total = Line - start; - end = Line; - Line++; - start = Line; - - for (i = 0; i < total + 1; i++) { - strcpy(Message[start], Message[end]); - start--; - end--; + if ((strcmp(temp, "")) == 0) { + /* Aborted. */ + pout(WHITE, BLACK, (char *) Language(177)); + return; } - strcpy(Message[j], temp); + start = atoi(temp); + + if (start > (Line - 1)) { + Enter(1); + /* Please enter a number in the range of */ + sprintf(temp, "%s(1 - %d)", (char *) Language(178), (Line - 1)); + pout(LIGHTGREEN, BLACK, temp); + } else + break; + } + + Enter(1); + j = start; + sprintf(temp, "%-2d : ", start); + pout(LIGHTGREEN, BLACK, temp); + colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + GetstrC(temp, 80); + + if ((strcmp(temp, "")) == 0) + return; + + total = Line - start; + end = Line; + Line++; + start = Line; + + for (i = 0; i < total + 1; i++) { + strcpy(Message[start], Message[end]); + start--; + end--; + } + + strcpy(Message[j], temp); } void Line_Edit_Replace() { - int edit; - char temp[81]; + int edit; + char temp[81]; + while (TRUE) { while (TRUE) { - while (TRUE) { - colour(10, 0); - /* Enter line # to replace */ - printf("\n\n%s(1 - %d): ", (char *) Language(185), (Line - 1) ); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp, 80); - if((strcmp(temp, "")) == 0) - return; + Enter(2); + /* Enter line # to replace */ + sprintf(temp, "%s(1 - %d): ", (char *) Language(185), (Line - 1) ); + pout(LIGHTGREEN, BLACK, temp); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp, 80); + if ((strcmp(temp, "")) == 0) + return; - edit = atoi(temp); - - colour(10, 0); - if(edit > Line) - /* Please enter a number in the range of */ - printf("\n%s(1 - %d) ", (char *) Language(178), (Line - 1)); - else - break; - } + edit = atoi(temp); + if (edit > Line) { Enter(1); - /* Line reads: */ - pout(15, 0, (char *) Language(186)); - Enter(1); - - colour(10, 0); - printf("%d : ", edit); - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - printf("%s\n\n", Message[edit]); - - colour(10, 0); - printf("%d : ", edit); - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - GetstrC(temp, 80); - if((strcmp(temp, "")) == 0) { - Enter(1); - /* Unchanged. */ - pout(15, 0, (char *) Language(187)); - Enter(1); - } else - strcpy(Message[edit], temp); - - Enter(1); - /* Line now reads: */ - pout(15, 0, (char *) Language(188)); - Enter(1); - - colour(10, 0); - printf("%d : ", edit); - - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - printf("%s", Message[edit]); + /* Please enter a number in the range of */ + sprintf(temp, "%s(1 - %d) ", (char *) Language(178), (Line - 1)); + pout(LIGHTGREEN, BLACK, temp); + } else + break; } + + Enter(1); + /* Line reads: */ + pout(WHITE, BLACK, (char *) Language(186)); + Enter(1); + + sprintf(temp, "%d : ", edit); + pout(LIGHTGREEN, BLACK, temp); + colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + PUTSTR(Message[edit]); + Enter(2); + + sprintf(temp, "%d : ", edit); + pout(LIGHTGREEN, BLACK, temp); + colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + GetstrC(temp, 80); + if ((strcmp(temp, "")) == 0) { + Enter(1); + /* Unchanged. */ + pout(WHITE, BLACK, (char *) Language(187)); + Enter(1); + } else + strcpy(Message[edit], temp); + + Enter(1); + /* Line now reads: */ + pout(WHITE, BLACK, (char *) Language(188)); + Enter(1); + + sprintf(temp, "%d : ", edit); + pout(LIGHTGREEN, BLACK, temp); + + colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + PUTSTR(Message[edit]); + } } void Line_Edit_Text() { - int edit; - char temp[81]; - char temp1[81]; + int edit; + char temp[81], temp1[81]; + while (TRUE) { while (TRUE) { - while (TRUE) { - colour(10, 0); - /* Enter line # to edit */ - printf("\n\n%s(1 - %d): ", (char *) Language(194), (Line - 1)); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp, 80); - if((strcmp(temp, "")) == 0) - return; + Enter(2); + /* Enter line # to edit */ + sprintf(temp, "%s(1 - %d): ", (char *) Language(194), (Line - 1)); + pout(LIGHTGREEN, BLACK, temp); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp, 80); + if ((strcmp(temp, "")) == 0) + return; - edit = atoi(temp); - - colour(10, 0); - if(edit > Line) - /* Please enter a number in the range of */ - printf("\n%s(1 - %d) ", (char *) Language(178), (Line - 1) ); - else - break; - } + edit = atoi(temp); + if (edit > Line) { Enter(1); - /* Line reads: */ - pout(15, 0, (char *) Language(186)); - Enter(1); - colour(10, 0); - printf("%d : ", edit); - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - printf("%s\n\n", Message[edit]); - - /* Text to replace: */ - pout(10, 0, (char *) Language(195)); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp, 80); - /* Replacement text: */ - pout(10, 0, (char *) Language(196)); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp1, 80); - - strreplace(Message[edit], temp, temp1); - - Enter(1); - /* Line now reads: */ - pout(15, 0, (char *) Language(197)); - Enter(1); - colour(10, 0); - printf("%d : ", edit); - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - printf("%s", Message[edit]); + /* Please enter a number in the range of */ + sprintf(temp, "%s(1 - %d) ", (char *) Language(178), (Line - 1) ); + pout(LIGHTGREEN, BLACK, temp); + } else + break; } + + Enter(1); + /* Line reads: */ + pout(WHITE, BLACK, (char *) Language(186)); + Enter(1); + sprintf(temp, "%d : ", edit); + pout(LIGHTGREEN, BLACK, temp); + colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + PUTSTR(Message[edit]); + Enter(2); + + /* Text to replace: */ + pout(LIGHTGREEN, BLACK, (char *) Language(195)); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp, 80); + /* Replacement text: */ + pout(LIGHTGREEN, BLACK, (char *) Language(196)); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp1, 80); + + strreplace(Message[edit], temp, temp1); + + Enter(1); + /* Line now reads: */ + pout(WHITE, BLACK, (char *) Language(197)); + Enter(1); + sprintf(temp, "%d : ", edit); + pout(LIGHTGREEN, BLACK, temp); + colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + PUTSTR(Message[edit]); + } } void Line_Edit_Center() { - int i, j, z, center; - int maxlen = 78; - char *CEnter; - char temp[81]; + int i, j, z, center, maxlen = 78; + char *CEnter, temp[81]; - colour(15, 0); - /* Enter line # to center */ - printf("\n\n%s(1 - %d): ", (char *) Language(203), (Line - 1)); - fflush(stdout); - GetstrC(temp, 80); - if((strcmp(temp, "")) == 0) - return; + Enter(2); + /* Enter line # to center */ + sprintf(temp, "%s(1 - %d): ", (char *) Language(203), (Line - 1)); + pout(WHITE, BLACK, temp); + GetstrC(temp, 80); + if ((strcmp(temp, "")) == 0) + return; - CEnter = calloc(81, sizeof(char)); - center = atoi(temp); - j = strlen(Message[center]); - if (j >= maxlen) - /* Line is maximum length and cannot be centered */ - printf("\n%s\n", (char *) Language(204)); - else { - z = 35 - (j / 2); + CEnter = calloc(81, sizeof(char)); + center = atoi(temp); + j = strlen(Message[center]); + if (j >= maxlen) { + Enter(1); + /* Line is maximum length and cannot be centered */ + pout(LIGHTGREEN, BLACK, (char *) Language(204)); + Enter(1); + } else { + z = 35 - (j / 2); - for(i = 0; i < z; i++) - strcat(CEnter," "); - strcat(CEnter, Message[center]); - strcpy(Message[center], CEnter); - } + for (i = 0; i < z; i++) + strcat(CEnter," "); + strcat(CEnter, Message[center]); + strcpy(Message[center], CEnter); + } - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - printf("\n%s\n", Message[center]); - free(CEnter); + Enter(1); + colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + PUTSTR(Message[center]); + Enter(1); + free(CEnter); } int Line_Edit() { - int i, j; + int i, j; + char msg[81]; - clear(); - colour(12, 0); - /* Begin your message now, Blank line to end */ - Center((char *) Language(164)); - /* Maximum of TEXTBUFSIZE lines, 73 chars per line */ - Center((char *) Language(165)); - colour(14, 0); - printf(" ("); - for (i = 0; i < 74; i++) - printf("-"); - printf(")\n"); + clear(); + colour(LIGHTRED, BLACK); + /* Begin your message now, Blank line to end */ + Center((char *) Language(164)); + /* Maximum of TEXTBUFSIZE lines, 73 chars per line */ + Center((char *) Language(165)); + colour(YELLOW, BLACK); + PUTSTR((char *)" ("); + for (i = 0; i < 74; i++) + PUTSTR((char *)"-"); + PUTSTR((char *)")"); + Enter(1); - Line_Edit_Append(); + Line_Edit_Append(); - while (TRUE) { - colour(14, 0); - /* Functions available: (Current Message: */ - printf("\n%s%d ", (char *) Language(167), (Line - 1)); - /* Lines) */ - printf("%s\n\n", (char *) Language(168)); - colour(11, 0); - /* L - List message S - Save message C - Continue message */ - printf("%s\n", (char *) Language(169)); + while (TRUE) { + Enter(1); + /* Functions available: (Current Message: */ /* Lines) */ + sprintf(msg, "%s%d %s", (char *) Language(167), (Line - 1), (char *) Language(168)); + pout(YELLOW, BLACK, msg); + Enter(2); - /* Q - Quit message D - Delete line I - Insert line */ - printf("%s\n", (char *) Language(170)); + /* L - List message S - Save message C - Continue message */ + pout(LIGHTCYAN, BLACK, (char *) Language(169)); + Enter(1); - /* T - Text edit E - Edit line R - Replace line */ - printf("%s\n", (char *) Language(171)); + /* Q - Quit message D - Delete line I - Insert line */ + pout(LIGHTCYAN, BLACK, (char *) Language(170)); + Enter(1); - /* Z - Center line */ - printf("%s\n", (char *) Language(172)); + /* T - Text edit E - Edit line R - Replace line */ + pout(LIGHTCYAN, BLACK, (char *) Language(171)); + Enter(1); - colour(15, 0); - printf("\n%s [", (char *) Language(173)); - for (i = 0; i < 10; i++) - putchar(Keystroke(172, i)); - printf("]: "); - fflush(stdout); + /* Z - Center line */ + pout(LIGHTCYAN, BLACK, (char *) Language(172)); + Enter(2); - alarm_on(); - j = toupper(Getone()); + sprintf(msg, "%s [", (char *) Language(173)); + pout(WHITE, BLACK, msg); + for (i = 0; i < 10; i++) + PUTCHAR(Keystroke(172, i)); + PUTSTR((char *)"]: "); - if (j == Keystroke(172, 2)) { - /* Continue */ - pout(15, 0, (char *) Language(174)); - Enter(1); - Line_Edit_Append(); - } else + alarm_on(); + j = toupper(Readkey()); - if (j == Keystroke(172, 4)) { - /* Delete */ - pout(15, 0, (char *) Language(175)); - Enter(1); - Line_Edit_Delete(); - } else + if (j == Keystroke(172, 2)) { + /* Continue */ + pout(WHITE, BLACK, (char *) Language(174)); + Enter(1); + Line_Edit_Append(); + } else if (j == Keystroke(172, 4)) { + /* Delete */ + pout(WHITE, BLACK, (char *) Language(175)); + Enter(1); + Line_Edit_Delete(); + } else if (j == Keystroke(172, 7)) { + /* Edit */ + pout(WHITE, BLACK, (char *) Language(180)); + Enter(1); + Line_Edit_Edit(); + } else if (j == Keystroke(172, 5)) { + /* Insert */ + pout(WHITE, BLACK, (char *) Language(182)); + Enter(1); + Line_Edit_Insert(); + } else if (j == Keystroke(172, 0)) { + pout(WHITE, BLACK, (char *) Language(184)); + Enter(2); - if (j == Keystroke(172, 7)) { - /* Edit */ - pout(15, 0, (char *) Language(180)); - Enter(1); - Line_Edit_Edit(); - } else + for (i = 1; i < Line; i++) { + sprintf(msg, "%d: ", i); + pout(LIGHTGREEN, BLACK, msg); + colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + PUTSTR(Message[i]); + Enter(1); + } + } else if (j == Keystroke(172, 8)) { + /* Replace */ + pout(WHITE, BLACK, (char *) Language(362)); + Enter(1); + Line_Edit_Replace(); + } else if (j == Keystroke(172, 3)) { + /* Quit */ + pout(WHITE, BLACK, (char *) Language(189)); + Enter(2); - if (j == Keystroke(172, 5)) { - /* Insert */ - pout(15, 0, (char *) Language(182)); - Enter(1); - Line_Edit_Insert(); - } else + /* Are you sure [y/N] */ + PUTSTR((char *) Language(190)); + alarm_on(); - if (j == Keystroke(172, 0)) { - pout(15, 0, (char *) Language(184)); - Enter(2); + if (toupper(Readkey()) == Keystroke(190, 0)) { + /* Yes */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(356)); + Enter(1); + /* Message aborted. */ + pout(WHITE, BLACK, (char *) Language(191)); + Enter(2); - for(i = 1; i < Line; i++) { - colour(10, 0); - printf("%d: ", i); - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - printf("%s\n", Message[i]); - } - } else + sleep(1); + return FALSE; + } - if (j == Keystroke(172, 8)) { - /* Replace */ - pout(15, 0, (char *) Language(362)); - Enter(1); - Line_Edit_Replace(); - } else + /* No */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(192)); + Enter(1); + } else if (j == Keystroke(172, 6)) { + /* Text Edit */ + pout(WHITE, BLACK, (char *) Language(193)); + Line_Edit_Text(); + } else if (j == Keystroke(172, 1)) { + /* Save */ + pout(WHITE, BLACK, (char *) Language(198)); + Enter(1); - if (j == Keystroke(172, 3)) { - /* Quit */ - pout(15, 0, (char *) Language(189)); - Enter(2); - - /* Are you sure [y/N] */ - printf("%s", (char *) Language(190)); - fflush(stdout); - alarm_on(); - - if (toupper(Getone()) == Keystroke(190, 0)) { - /* Yes */ - pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(356)); - Enter(1); - /* Message aborted. */ - pout(15, 0, (char *) Language(191)); - Enter(2); - - fflush(stdout); - sleep(1); - return FALSE; - } - - colour(CFG.HiliteF, CFG.HiliteB); - /* No */ - printf("%s\n", (char *) Language(192)); - } else - - if (j == Keystroke(172, 6)) { - /* Text Edit */ - pout(15, 0, (char *) Language(193)); - Line_Edit_Text(); - } else - - if (j == Keystroke(172, 1)) { - /* Save */ - pout(15, 0, (char *) Language(198)); - Enter(1); - fflush(stdout); - - if (Line > 1) - return TRUE; + if (Line > 1) + return TRUE; - return FALSE; - } else - - if (j == Keystroke(172, 9)) { - /* Center */ - pout(15, 0, (char *) Language(376)); - Enter(1); - Line_Edit_Center(); - } + return FALSE; + } else if (j == Keystroke(172, 9)) { + /* Center */ + pout(WHITE, BLACK, (char *) Language(376)); + Enter(1); + Line_Edit_Center(); } + } } diff --git a/mbsebbs/mail.c b/mbsebbs/mail.c index 0fbca0a1..76f5ed8a 100644 --- a/mbsebbs/mail.c +++ b/mbsebbs/mail.c @@ -59,6 +59,9 @@ #include "door.h" #include "whoson.h" #include "term.h" +#include "ttyio.h" +#include "openport.h" + /* @@ -105,12 +108,11 @@ int LC(int Lines) iLineCount = 1; pout(CFG.MoreF, CFG.MoreB, (char *) Language(61)); - fflush(stdout); alarm_on(); - z = toupper(Getone()); + z = toupper(Readkey()); if (z == Keystroke(61, 1)) { - printf("\n"); + Enter(1); return(1); } @@ -134,7 +136,6 @@ int Post_Allowed(void) if (msgs.MsgKinds == RONLY) { /* Message area is Readonly */ pout(LIGHTRED, BLACK, (char *) Language(437)); - fflush(stdout); sleep(3); return FALSE; } @@ -163,16 +164,14 @@ int Alias_Option(void) /* YN|) to post this message [Y/n]: */ pout(CYAN, BLACK, (char *)Language(478)); colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - fflush(stdout); alarm_on(); - if (toupper(Getone()) == Keystroke(478, 1)) { + if (toupper(Readkey()) == Keystroke(478, 1)) { rc = FALSE; - printf("%c", Keystroke(478, 1)); + PUTCHAR(Keystroke(478, 1)); } else { - printf("%c", Keystroke(478, 0)); + PUTCHAR(Keystroke(478, 0)); } Enter(2); - fflush(stdout); return rc; } @@ -199,26 +198,23 @@ int Crash_Option(faddr *Dest) /* Crash [y/N]: */ pout(CYAN, BLACK, (char *)Language(461)); colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - fflush(stdout); alarm_on(); - if (toupper(Getone()) == Keystroke(461, 0)) { + if (toupper(Readkey()) == Keystroke(461, 0)) { rc = 1; - printf("%c", Keystroke(461, 0)); + PUTCHAR(Keystroke(461, 0)); } else - printf("%c", Keystroke(461, 1)); + PUTCHAR(Keystroke(461, 1)); } else { /* Warning: node is not CM, send Immediate [y/N]: */ pout(CYAN, BLACK, (char *)Language(462)); colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - fflush(stdout); alarm_on(); - if (toupper(Getone()) == Keystroke(462, 0)) { + if (toupper(Readkey()) == Keystroke(462, 0)) { rc = 2; - printf("%c", Keystroke(462, 0)); + PUTCHAR(Keystroke(462, 0)); } else - printf("%c", Keystroke(462, 1)); + PUTCHAR(Keystroke(462, 1)); } - fflush(stdout); if (Nlent->addr.domain) free(Nlent->addr.domain); @@ -250,15 +246,13 @@ int IsPrivate(void) Enter(1); /* Private [y/N]: */ pout(CYAN, BLACK, (char *) Language(163)); - fflush(stdout); alarm_on(); - if (toupper(Getone()) == Keystroke(163, 0)) { + if (toupper(Readkey()) == Keystroke(163, 0)) { rc = TRUE; - printf("%c", Keystroke(163, 0)); + PUTCHAR(Keystroke(163, 0)); } else { - printf("%c", Keystroke(163, 1)); + PUTCHAR(Keystroke(163, 1)); } - fflush(stdout); } /* @@ -275,77 +269,73 @@ int IsPrivate(void) void Check_Attach(void); void Check_Attach(void) { - char *Attach, *dospath; - struct stat sb; + char *Attach, *dospath, msg[81]; + struct stat sb; - /* - * This is a dangerous option! Every file on the system to which the - * bbs has read access and is in the range of paths translatable by - * Unix to DOS can be attached to the netmail. - */ - if ((msgs.Type == NETMAIL) && (exitinfo.Security.level >= CFG.iAttachLevel)) { + /* + * This is a dangerous option! Every file on the system to which the + * bbs has read access and is in the range of paths translatable by + * Unix to DOS can be attached to the netmail. + */ + if ((msgs.Type == NETMAIL) && (exitinfo.Security.level >= CFG.iAttachLevel)) { - Attach = calloc(PATH_MAX, sizeof(char)); - while (TRUE) { + Attach = calloc(PATH_MAX, sizeof(char)); + while (TRUE) { + Enter(1); + /* Attach file [y/N]: */ + pout(CYAN, BLACK, (char *)Language(463)); + alarm_on(); + if (toupper(Readkey()) == Keystroke(463, 0)) { + + PUTCHAR(Keystroke(463, 0)); + Enter(1); + /* Please enter filename: */ + pout(YELLOW, BLACK, (char *)Language(245)); + colour(CFG.MsgInputColourF, CFG.MsgInputColourB); + alarm_on(); + sprintf(Attach, "%s/", CFG.uxpath); + PUTSTR(Attach); + GetstrP(Attach, 71, strlen(Attach)); + if (strcmp(Attach, "") == 0) + break; + + if ((stat(Attach, &sb) == 0) && (S_ISREG(sb.st_mode))) { + dospath = xstrcpy(Unix2Dos(Attach)); + if (strncasecmp(Attach, CFG.uxpath, strlen(CFG.uxpath)) == 0) { + Syslog('+', "FileAttach \"%s\"", Attach); + if (strlen(CFG.dospath)) + strcpy(Msg.Subject, dospath); + else + sprintf(Msg.Subject, "%s", Attach); + Msg.FileAttach = TRUE; Enter(1); - /* Attach file [y/N]: */ - pout(CYAN, BLACK, (char *)Language(463)); - fflush(stdout); - alarm_on(); - if (toupper(Getone()) == Keystroke(463, 0)) { - - printf("%c", Keystroke(463, 0)); - Enter(1); - /* Please enter filename: */ - pout(YELLOW, BLACK, (char *)Language(245)); - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - fflush(stdout); - alarm_on(); - sprintf(Attach, "%s/", CFG.uxpath); - printf("%s", Attach); - fflush(stdout); - GetstrP(Attach, 71, strlen(Attach)); - if (strcmp(Attach, "") == 0) - break; - - if ((stat(Attach, &sb) == 0) && (S_ISREG(sb.st_mode))) { - dospath = xstrcpy(Unix2Dos(Attach)); - if (strncasecmp(Attach, CFG.uxpath, strlen(CFG.uxpath)) == 0) { - Syslog('+', "FileAttach \"%s\"", Attach); - if (strlen(CFG.dospath)) - strcpy(Msg.Subject, dospath); - else - sprintf(Msg.Subject, "%s", Attach); - Msg.FileAttach = TRUE; - Enter(1); - colour(11, 0); - /* File */ /* will be attached */ - printf("%s %s %s", (char *)Language(464), Msg.Subject, Language(465)); - Enter(1); - fflush(stdout); - sleep(2); - break; - } else { - Enter(1); - colour(10, 0); - /* File not within */ - printf("%s \"%s\"", Language(466), CFG.uxpath); - Enter(1); - Pause(); - } - } else { - Enter(1); - /* File does not exist, please try again ... */ - pout(10, 0, (char *)Language(296)); - Enter(1); - Pause(); - } - } else { - break; - } /* if attach */ - } /* while true */ - free(Attach); - } + /* File */ /* will be attached */ + sprintf(msg, "%s %s %s", (char *)Language(464), Msg.Subject, Language(465)); + pout(LIGHTCYAN, BLACK, msg); + Enter(1); + sleep(2); + break; + } else { + Enter(1); + /* File not within */ + sprintf(msg, "%s \"%s\"", Language(466), CFG.uxpath); + pout(LIGHTGREEN, BLACK, msg); + Enter(1); + Pause(); + } + } else { + Enter(1); + /* File does not exist, please try again ... */ + pout(LIGHTGREEN, BLACK, (char *)Language(296)); + Enter(1); + Pause(); + } + } else { + break; + } /* if attach */ + } /* while true */ + free(Attach); + } } @@ -401,7 +391,7 @@ int Edit_Msg() void Post_Msg() { int i, x, cc; - char *FidoNode; + char *FidoNode, msg[81]; faddr *Dest = NULL; node *Nlent = NULL; unsigned short point; @@ -420,9 +410,11 @@ void Post_Msg() Msg_New(); - colour(LIGHTBLUE, BLACK); + Enter(1); /* Posting message in area: */ - printf("\n%s\"%s\"\n", (char *) Language(156), sMsgAreaDesc); + sprintf(msg, "%s\"%s\"", (char *) Language(156), sMsgAreaDesc); + pout(LIGHTBLUE, BLACK, msg); + Enter(1); if (Alias_Option()) { /* @@ -518,19 +510,18 @@ void Post_Msg() colour(YELLOW, BLACK); if (point) - printf("Boss : "); + PUTSTR((char *)"Boss : "); else - printf("Node : "); + PUTSTR((char *)"Node : "); Dest->point = point; - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - printf("%s in %s", Nlent->name, Nlent->location); + sprintf(msg, "%s in %s", Nlent->name, Nlent->location); + pout(CFG.MsgInputColourF, CFG.MsgInputColourB, msg); /* " Is this correct [y/N]: " */ pout(YELLOW, BLACK, (char *)Language(21)); colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - fflush(stdout); alarm_on(); - if (toupper(Getone()) == Keystroke(21, 0)) { + if (toupper(Readkey()) == Keystroke(21, 0)) { Enter(1); sprintf(Msg.ToAddress, "%s", ascfnode(Dest, 0x1f)); x = TRUE; @@ -543,12 +534,11 @@ void Post_Msg() } } else { Dest->point = point; - printf("\r"); + PUTCHAR('\r'); /* Node not known, continue anayway [y/N]: */ pout(CYAN, BLACK, (char *) Language(241)); - fflush(stdout); alarm_on(); - if (toupper(Getone()) == Keystroke(241, 0)) { + if (toupper(Readkey()) == Keystroke(241, 0)) { x = TRUE; Syslog('+', "Node %s not found, forced continue", FidoNode); } @@ -562,7 +552,7 @@ void Post_Msg() } if(!x) { - printf("\r"); + PUTCHAR('\r'); /* User not found. Try again, or (Enter) to quit */ pout(CYAN, BLACK, (char *) Language(160)); } else @@ -574,7 +564,6 @@ void Post_Msg() /* Subject : */ pout(YELLOW, BLACK, (char *) Language(161)); colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - fflush(stdout); alarm_on(); GetstrP(Msg.Subject, 65, 0); @@ -582,10 +571,9 @@ void Post_Msg() Enter(1); /* Abort Message [y/N] ?: */ pout(CYAN, BLACK, (char *) Language(162)); - fflush(stdout); alarm_on(); - if (toupper(Getone()) == Keystroke(162, 0)) { + if (toupper(Readkey()) == Keystroke(162, 0)) { for(i = 0; i < (TEXTBUFSIZE + 1); i++) free(Message[i]); tidy_faddr(Dest); @@ -603,8 +591,7 @@ void Post_Msg() Check_Attach(); if (Edit_Msg()) { - printf("\n"); - fflush(stdout); + Enter(1); if (msgs.Type == NETMAIL) { /* * Check for Carbon Copy lines, process them if present. @@ -647,8 +634,7 @@ void Post_Msg() } else { Save_Msg(FALSE, Dest); } - printf("\n"); - fflush(stdout); + Enter(1); sleep(3); } @@ -667,7 +653,7 @@ int Save_CC(int IsReply, char *ccline) { faddr *Dest = NULL; int i, j, x, rc = FALSE; - char *p, *username; + char *p, *username, msg[81]; unsigned short point; node *Nlent; @@ -685,9 +671,10 @@ int Save_CC(int IsReply, char *ccline) Syslog('b', "i=%d, j=%d", i, j); if (j <= i) { Syslog('+', "Could not parse %s", printable(ccline, 0)); - colour(LIGHTRED, BLACK); /* Could not parse */ - printf("%s \"%s\"\n", Language(22), printable(ccline, 0)); + sprintf(msg, "%s \"%s\"", Language(22), printable(ccline, 0)); + pout(LIGHTRED, BLACK, msg); + Enter(1); Pause(); return FALSE; } @@ -701,26 +688,30 @@ int Save_CC(int IsReply, char *ccline) if (strlen(username) == 0) { Syslog('+', "Could not extract username from %s", printable(ccline, 0)); - colour(LIGHTRED, BLACK); /* Could not parse */ - printf("%s \"%s\"\n", Language(22), printable(ccline, 0)); + sprintf(msg, "%s \"%s\"", Language(22), printable(ccline, 0)); + pout(LIGHTRED, BLACK, msg); + Enter(1); Pause(); return FALSE; } if ((Dest = parsefnode(ccline + j)) == NULL) { Syslog('+', "Could not extract address from %s", printable(ccline, 0)); - colour(LIGHTRED, BLACK); /* Could not parse */ - printf("%s \"%s\"\n", Language(22), printable(ccline, 0)); + sprintf(msg, "%s \"%s\"", Language(22), printable(ccline, 0)); + pout(LIGHTRED, BLACK, msg); + Enter(1); Pause(); return FALSE; } Dest->name = tlcap(printable(username, 0)); Syslog('b', "Dest %s", ascfnode(Dest, 0xff)); - colour(LIGHTMAGENTA, BLACK); - printf("\nConfirm CC to %s\n", ascfnode(Dest, 0xff)); + Enter(1); + sprintf(msg, "Confirm CC to %s", ascfnode(Dest, 0xff)); + pout(LIGHTMAGENTA, BLACK, msg); + Enter(1); x = FALSE; point = Dest->point; @@ -728,19 +719,18 @@ int Save_CC(int IsReply, char *ccline) if (((Nlent = getnlent(Dest)) != NULL) && (Nlent->addr.zone)) { colour(YELLOW, BLACK); if (point) - printf("Boss : "); + PUTSTR((char *)"Boss : "); else - printf("Node : "); + PUTSTR((char *)"Node : "); Dest->point = point; - colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - printf("%s in %s", Nlent->name, Nlent->location); + sprintf(msg, "%s in %s", Nlent->name, Nlent->location); + pout(CFG.MsgInputColourF, CFG.MsgInputColourB, msg); /* " Is this correct [y/N]: " */ pout(YELLOW, BLACK, (char *)Language(21)); colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - fflush(stdout); alarm_on(); - if (toupper(Getone()) == Keystroke(21, 0)) { + if (toupper(Readkey()) == Keystroke(21, 0)) { Enter(1); sprintf(Msg.ToAddress, "%s", ascfnode(Dest, 0x1f)); x = TRUE; @@ -753,20 +743,18 @@ int Save_CC(int IsReply, char *ccline) } } else { Dest->point = point; - printf("\n"); + Enter(1); /* Node not known, continue anayway [y/N]: */ pout(CYAN, BLACK, (char *) Language(241)); - fflush(stdout); alarm_on(); - if (toupper(Getone()) == Keystroke(241, 0)) { + if (toupper(Readkey()) == Keystroke(241, 0)) { x = TRUE; Syslog('+', "Node %s not found, forced continue", ascfnode(Dest, 0x0f)); } } if (x) { - printf("\n"); - fflush(stdout); + Enter(1); rc = Save_Msg(IsReply, Dest); } @@ -836,10 +824,10 @@ int Save_Msg(int IsReply, faddr *Dest) Syslog('+', "Msg (%ld) to \"%s\", \"%s\", in %ld", Msg.Id, Msg.To, Msg.Subject, iMsgAreaNumber + 1); - colour(CFG.HiliteF, CFG.HiliteB); /* Saving message to disk */ - printf("%s(%ld)\n", (char *) Language(202), Msg.Id); - fflush(stdout); + sprintf(temp, "%s(%ld)", (char *) Language(202), Msg.Id); + pout(CFG.HiliteF, CFG.HiliteB, temp); + Enter(1); msgs.LastPosted = time(NULL); msgs.Posted.total++; @@ -903,106 +891,111 @@ int Save_Msg(int IsReply, faddr *Dest) */ void ShowMsgHdr() { - static char Buf1[35], Buf2[35], Buf3[81]; - struct tm *tm; - time_t now; - int color; + static char Buf1[35], Buf2[35], Buf3[81]; + char msg[81]; + struct tm *tm; + time_t now; + int color; - Buf1[0] = '\0'; - Buf2[0] = '\0'; - Buf3[0] = '\0'; + Buf1[0] = '\0'; + Buf2[0] = '\0'; + Buf3[0] = '\0'; - clear(); - colour(BLUE, LIGHTGRAY); - printf(" %-70s", sMsgAreaDesc); + clear(); + sprintf(msg, " %-70s", sMsgAreaDesc); + pout(BLUE, LIGHTGRAY, msg); - colour(RED, LIGHTGRAY); - printf("#%-5lu\n", Msg.Id); + sprintf(msg, "#%-5lu", Msg.Id); + pout(RED, LIGHTGRAY, msg); + Enter(1); - /* Date : */ - pout(YELLOW, BLACK, (char *) Language(206)); - colour(GREEN, BLACK); - /* Use intermediate variable to prevent SIGBUS on Sparc's */ - now = Msg.Written; - tm = gmtime(&now); - printf("%02d-%02d-%d %02d:%02d:%02d", tm->tm_mday, tm->tm_mon+1, + /* Date : */ + pout(YELLOW, BLACK, (char *) Language(206)); + colour(GREEN, BLACK); + /* Use intermediate variable to prevent SIGBUS on Sparc's */ + now = Msg.Written; + tm = gmtime(&now); + sprintf(msg, "%02d-%02d-%d %02d:%02d:%02d", tm->tm_mday, tm->tm_mon+1, tm->tm_year+1900, tm->tm_hour, tm->tm_min, tm->tm_sec); - colour(LIGHTRED, BLACK); - if (Msg.Local) printf(" Local"); - if (Msg.Intransit) printf(" Transit"); - if (Msg.Private) printf(" Priv."); - if (Msg.Received) printf(" Rcvd"); - if (Msg.Sent) printf(" Sent"); - if (Msg.KillSent) printf(" KillSent"); - if (Msg.ArchiveSent) printf(" ArchiveSent"); - if (Msg.Hold) printf(" Hold"); - if (Msg.Crash) printf(" Crash"); - if (Msg.Immediate) printf(" Imm."); - if (Msg.Direct) printf(" Dir"); - if (Msg.Gate) printf(" Gate"); - if (Msg.FileRequest) printf(" Freq"); - if (Msg.FileAttach) printf(" File"); - if (Msg.TruncFile) printf(" TruncFile"); - if (Msg.KillFile) printf(" KillFile"); - if (Msg.ReceiptRequest) printf(" RRQ"); - if (Msg.ConfirmRequest) printf(" CRQ"); - if (Msg.Orphan) printf(" Orphan"); - if (Msg.Encrypt) printf(" Crypt"); - if (Msg.Compressed) printf(" Comp"); - if (Msg.Escaped) printf(" 7bit"); - if (Msg.ForcePU) printf(" FPU"); - if (Msg.Localmail) printf(" Localmail"); - if (Msg.Netmail) printf(" Netmail"); - if (Msg.Echomail) printf(" Echomail"); - if (Msg.News) printf(" News"); - if (Msg.Email) printf(" E-mail"); - if (Msg.Nodisplay) printf(" Nodisp"); - if (Msg.Locked) printf(" LCK"); - if (Msg.Deleted) printf(" Del"); - printf("\n"); + PUTSTR(msg); - /* From : */ - pout(YELLOW, BLACK, (char *) Language(209)); - if (IsMe(Msg.From)) - color = LIGHTGREEN; - else - color = GREEN; - colour(color++, BLACK); - printf("%s ", Msg.From); - if (iMsgAreaType != LOCALMAIL) { - colour(color, BLACK); - printf("(%s)", Msg.FromAddress); - } - printf("\n"); + colour(LIGHTRED, BLACK); + if (Msg.Local) PUTSTR((char *)" Local"); + if (Msg.Intransit) PUTSTR((char *)" Transit"); + if (Msg.Private) PUTSTR((char *)" Priv."); + if (Msg.Received) PUTSTR((char *)" Rcvd"); + if (Msg.Sent) PUTSTR((char *)" Sent"); + if (Msg.KillSent) PUTSTR((char *)" KillSent"); + if (Msg.ArchiveSent) PUTSTR((char *)" ArchiveSent"); + if (Msg.Hold) PUTSTR((char *)" Hold"); + if (Msg.Crash) PUTSTR((char *)" Crash"); + if (Msg.Immediate) PUTSTR((char *)" Imm."); + if (Msg.Direct) PUTSTR((char *)" Dir"); + if (Msg.Gate) PUTSTR((char *)" Gate"); + if (Msg.FileRequest) PUTSTR((char *)" Freq"); + if (Msg.FileAttach) PUTSTR((char *)" File"); + if (Msg.TruncFile) PUTSTR((char *)" TruncFile"); + if (Msg.KillFile) PUTSTR((char *)" KillFile"); + if (Msg.ReceiptRequest) PUTSTR((char *)" RRQ"); + if (Msg.ConfirmRequest) PUTSTR((char *)" CRQ"); + if (Msg.Orphan) PUTSTR((char *)" Orphan"); + if (Msg.Encrypt) PUTSTR((char *)" Crypt"); + if (Msg.Compressed) PUTSTR((char *)" Comp"); + if (Msg.Escaped) PUTSTR((char *)" 7bit"); + if (Msg.ForcePU) PUTSTR((char *)" FPU"); + if (Msg.Localmail) PUTSTR((char *)" Localmail"); + if (Msg.Netmail) PUTSTR((char *)" Netmail"); + if (Msg.Echomail) PUTSTR((char *)" Echomail"); + if (Msg.News) PUTSTR((char *)" News"); + if (Msg.Email) PUTSTR((char *)" E-mail"); + if (Msg.Nodisplay) PUTSTR((char *)" Nodisp"); + if (Msg.Locked) PUTSTR((char *)" LCK"); + if (Msg.Deleted) PUTSTR((char *)" Del"); + Enter(1); - /* To : */ - pout(YELLOW, BLACK, (char *) Language(208)); - if (IsMe(Msg.To)) - color = LIGHTGREEN; - else - color = GREEN; - colour(color++, BLACK); - printf("%s ", Msg.To); - if (iMsgAreaType == NETMAIL) { - colour(color, BLACK); - printf("(%s)", Msg.ToAddress); - } - printf("\n"); + /* From : */ + pout(YELLOW, BLACK, (char *) Language(209)); + if (IsMe(Msg.From)) + color = LIGHTGREEN; + else + color = GREEN; + colour(color++, BLACK); + PUTSTR(Msg.From); + if (iMsgAreaType != LOCALMAIL) { + sprintf(msg, " (%s)", Msg.FromAddress); + pout(color, BLACK, msg); + } + Enter(1); - /* Subject : */ - pout(YELLOW, BLACK, (char *) Language(210)); - colour(GREEN, BLACK); - printf("%s\n", Msg.Subject); + /* To : */ + pout(YELLOW, BLACK, (char *) Language(208)); + if (IsMe(Msg.To)) + color = LIGHTGREEN; + else + color = GREEN; + colour(color++, BLACK); + PUTSTR(Msg.To); + if (iMsgAreaType == NETMAIL) { + sprintf(msg, " (%s)", Msg.ToAddress); + pout(color, BLACK, msg); + } + Enter(1); - colour(CFG.HiliteF, CFG.HiliteB); - colour(YELLOW, BLUE); - if (Msg.Reply) - sprintf(Buf1, "\"+\" %s %lu", (char *)Language(211), Msg.Reply); - if (Msg.Original) - sprintf(Buf2, " \"-\" %s %lu", (char *)Language(212), Msg.Original); - sprintf(Buf3, "%s%s ", Buf1, Buf2); - colour(YELLOW, BLUE); - printf("%78s \n", Buf3); + /* Subject : */ + pout(YELLOW, BLACK, (char *) Language(210)); + pout(GREEN, BLACK, Msg.Subject); + Enter(1); + + colour(CFG.HiliteF, CFG.HiliteB); + colour(YELLOW, BLUE); + if (Msg.Reply) + sprintf(Buf1, "\"+\" %s %lu", (char *)Language(211), Msg.Reply); + if (Msg.Original) + sprintf(Buf2, " \"-\" %s %lu", (char *)Language(212), Msg.Original); + sprintf(Buf3, "%s%s ", Buf1, Buf2); + sprintf(msg, "%77s ", Buf3); + pout(YELLOW, BLUE, msg); + Enter(1); } @@ -1012,7 +1005,7 @@ void ShowMsgHdr() */ int Export_a_Msg(unsigned long Num) { - char *p; + char *p, msg[81]; int ShowMsg = TRUE, z, homedir = TRUE; LastNum = Num; @@ -1028,15 +1021,14 @@ int Export_a_Msg(unsigned long Num) /* Export to (H)ome or (R)ules directory: */ pout(WHITE, RED, (char *) Language(11)); colour(CFG.MsgInputColourF, CFG.MsgInputColourB); - fflush(stdout); alarm_on(); - z = toupper(Getone()); + z = toupper(Readkey()); if (z == Keystroke(11, 0)) { - printf("%c", Keystroke(478, 0)); + PUTCHAR(Keystroke(478, 0)); break; } if (z == Keystroke(11, 1)) { - printf("%c", Keystroke(478, 1)); + PUTCHAR(Keystroke(478, 1)); homedir = FALSE; break; } @@ -1049,9 +1041,10 @@ int Export_a_Msg(unsigned long Num) * The area data is already set, so we can do the next things */ if (MsgBase.Total == 0) { - colour(WHITE, BLACK); + Enter(1); /* There are no messages in this area */ - printf("\n%s\n\n", (char *) Language(205)); + pout(WHITE, BLACK, (char *) Language(205)); + Enter(2); Syslog('+', "No messages in area"); sleep(3); return FALSE; @@ -1063,10 +1056,10 @@ int Export_a_Msg(unsigned long Num) } if (!Msg_ReadHeader(Num)) { - perror(""); - colour(WHITE, BLACK); + Enter(1); /* Message doesn't exist */ - printf("\n%s\n\n", (char *)Language(77)); + pout(WHITE, BLACK, (char *)Language(77)); + Enter(2); Msg_Close(); sleep(3); return FALSE; @@ -1081,8 +1074,10 @@ int Export_a_Msg(unsigned long Num) } if (!ShowMsg) { + Enter(1); /* Private message, not owner */ - printf("\n%s\n\n", (char *) Language(82)); + pout(WHITE, BLACK, (char *) Language(82)); + Enter(2); Msg_Close(); sleep(3); return FALSE; @@ -1136,18 +1131,18 @@ int Export_a_Msg(unsigned long Num) /* * Report the result. */ - colour(CFG.TextColourF, CFG.TextColourB); + Enter(2); if (homedir) { /* Message exported to your private directory as: */ - printf("\n\n%s", (char *) Language(46)); - colour(CFG.HiliteF, CFG.HiliteB); - printf("%d_%lu.msg\n\n", iMsgAreaNumber + 1, Num); + pout(CFG.TextColourF, CFG.TextColourB, (char *) Language(46)); + sprintf(msg, "%d_%lu.msg", iMsgAreaNumber + 1, Num); + pout(CFG.HiliteF, CFG.HiliteB, msg); } else { /* Message exported to rules directory as */ - printf("\n\n%s", (char *) Language(12)); - colour(CFG.HiliteF, CFG.HiliteB); - printf("%s\n\n", msgs.Tag); + pout(CFG.TextColourF, CFG.TextColourB, (char *) Language(12)); + pout(CFG.HiliteF, CFG.HiliteB, msgs.Tag); } + Enter(2); Pause(); return TRUE; } @@ -1172,9 +1167,10 @@ int Read_a_Msg(unsigned long Num, int UpdateLR) * The area data is already set, so we can do the next things */ if (MsgBase.Total == 0) { - colour(WHITE, BLACK); + Enter(1); /* There are no messages in this area */ - printf("\n%s\n\n", (char *) Language(205)); + pout(WHITE, BLACK, (char *) Language(205)); + Enter(2); sleep(3); return FALSE; } @@ -1185,9 +1181,9 @@ int Read_a_Msg(unsigned long Num, int UpdateLR) } if (!Msg_ReadHeader(Num)) { - perror(""); - colour(WHITE, BLACK); - printf("\n%s\n\n", (char *)Language(77)); + Enter(1); + pout(WHITE, BLACK, (char *)Language(77)); + Enter(2); Msg_Close(); sleep(3); return FALSE; @@ -1201,7 +1197,9 @@ int Read_a_Msg(unsigned long Num, int UpdateLR) ShowMsg = TRUE; } if (!ShowMsg) { - printf("\n%s\n\n", (char *) Language(82)); + Enter(1); + pout(WHITE, BLACK, (char *) Language(82)); + Enter(2); Msg_Close(); sleep(3); return FALSE; @@ -1272,8 +1270,8 @@ int Read_a_Msg(unsigned long Num, int UpdateLR) do { if ((p[0] == '\001') || (!strncmp(p, "SEEN-BY:", 8)) || (!strncmp(p, "AREA:", 5))) { if (Kludges) { - colour(7, 0); - printf("%s\n", p); + pout(LIGHTGRAY, BLACK, p); + Enter(1); if (CheckLine(CFG.TextColourF, CFG.TextColourB, FALSE)) break; } @@ -1287,11 +1285,12 @@ int Read_a_Msg(unsigned long Num, int UpdateLR) * Try to translate character sets */ for (i = 0; i < strlen(p); i++) { - printf("%s", charset_map_c(p[i], FALSE)); + PUTSTR(charset_map_c(p[i], FALSE)); } - printf("\n"); + Enter(1); } else { - printf("%s\n", p); + PUTSTR(p); + Enter(1); } if (CheckLine(CFG.TextColourF, CFG.TextColourB, FALSE)) @@ -1313,7 +1312,6 @@ int Read_a_Msg(unsigned long Num, int UpdateLR) */ if ((!Msg.Received) && (strlen(Msg.To) > 0) && ((strcasecmp(Msg.To, exitinfo.sUserName) == 0) || (strcasecmp(exitinfo.sHandle, Msg.To) == 0))) { - Syslog('m', "Marking message received"); Msg.Received = TRUE; Msg.Read = time(NULL) - (gmt_offset((time_t)0) * 60); if (Msg_Lock(30L)) { @@ -1363,55 +1361,59 @@ int Read_a_Msg(unsigned long Num, int UpdateLR) */ void Read_Msgs() { - char *temp; - unsigned long Start; - lastread LR; + char *temp; + unsigned long Start; + lastread LR; - colour(CFG.TextColourF, CFG.TextColourB); + temp = calloc(81, sizeof(char)); + Enter(1); /* Message area \"%s\" contains %lu messages. */ - printf("\n%s\"%s\" %s%lu %s", (char *) Language(221), sMsgAreaDesc, + sprintf(temp, "%s\"%s\" %s%lu %s", (char *) Language(221), sMsgAreaDesc, (char *) Language(222), MsgBase.Total, (char *) Language(223)); + pout(CFG.TextColourF, CFG.TextColourB, temp); + /* + * Check for lastread pointer, suggest lastread number for start. + */ + Start = MsgBase.Lowest; + if (Msg_Open(sMsgAreaBase)) { + LR.UserID = grecno; + if (Msg_GetLastRead(&LR)) + Start = LR.HighReadMsg + 1; + else + Start = 1; + Msg_Close(); /* - * Check for lastread pointer, suggest lastread number for start. + * If we already have read the last message, the pointer is + * higher then HighMsgNum, we set it at HighMsgNum to prevent + * errors and read that message again. */ - Start = MsgBase.Lowest; - if (Msg_Open(sMsgAreaBase)) { - LR.UserID = grecno; - if (Msg_GetLastRead(&LR)) - Start = LR.HighReadMsg + 1; - else - Start = 1; - Msg_Close(); - /* - * If we already have read the last message, the pointer is - * higher then HighMsgNum, we set it at HighMsgNum to prevent - * errors and read that message again. - */ - if (Start > MsgBase.Highest) - Start = MsgBase.Highest; - } + if (Start > MsgBase.Highest) + Start = MsgBase.Highest; + } - colour(WHITE, BLACK); - /* Please enter a message between */ - printf("\n%s(%lu - %lu)", (char *) Language(224), MsgBase.Lowest, MsgBase.Highest); - /* Message number [ */ - printf("\n%s%lu]: ", (char *) Language(225), Start); + Enter(1); + /* Please enter a message between */ + sprintf(temp, "%s(%lu - %lu)", (char *) Language(224), MsgBase.Lowest, MsgBase.Highest); + pout(WHITE, BLACK, temp); + Enter(1); + /* Message number [ */ + sprintf(temp, "%s%lu]: ", (char *) Language(225), Start); + PUTSTR(temp); - temp = calloc(81, sizeof(char)); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(temp, 80); - if ((strcmp(temp, "")) != 0) - Start = atoi(temp); - free(temp); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp, 80); + if ((strcmp(temp, "")) != 0) + Start = atoi(temp); + free(temp); - if (!Read_a_Msg(Start, TRUE)) - return; + if (!Read_a_Msg(Start, TRUE)) + return; - if (MsgBase.Total == 0) - return; + if (MsgBase.Total == 0) + return; - while(ReadPanel()) {} + while(ReadPanel()) {} } @@ -1425,7 +1427,6 @@ int ReadPanel() WhosDoingWhat(READ_POST, NULL); - colour(WHITE, RED); /* * The writer of the message, sysops, and who has sysop rights to the message area * are allowed to delete messages. @@ -1433,19 +1434,18 @@ int ReadPanel() if ((msgs.UsrDelete && IsMe(Msg.From)) || (exitinfo.Security.level >= CFG.sysop_access) || Access(exitinfo.Security, msgs.SYSec)) { /* (A)gain, (N)ext, (L)ast, (R)eply, (E)nter, (D)elete, (Q)uit, e(X)port */ - printf("%s", (char *) Language(214)); + pout(WHITE, RED, (char *) Language(214)); } else { /* (A)gain, (N)ext, (L)ast, (R)eply, (E)nter, (Q)uit, e(X)port */ - printf("%s", (char *) Language(215)); + pout(WHITE, RED, (char *) Language(215)); } if ((exitinfo.Security.level >= CFG.sysop_access) || Access(exitinfo.Security, msgs.SYSec)) - printf(", (!)"); + PUTSTR((char *)", (!)"); - printf(": "); + PUTSTR((char *)": "); - fflush(stdout); alarm_on(); - input = toupper(Getone()); + input = toupper(Readkey()); if (input == '!') { /* ! Toggle kludges display */ if ((exitinfo.Security.level >= CFG.sysop_access) || Access(exitinfo.Security, msgs.SYSec)) { @@ -1474,7 +1474,8 @@ int ReadPanel() } else if (input == Keystroke(214, 5)) { /* (Q)uit */ /* Quit */ - printf("%s\n", (char *) Language(189)); + pout(WHITE, BLACK, (char *) Language(189)); + Enter(1); return FALSE; } else if (input == Keystroke(214, 7)) { /* e(X)port */ @@ -1528,7 +1529,7 @@ int ReadPanel() void Reply_Msg(int IsReply) { int i, j, x, cc; - char to[65], from[65], subj[73], msgid[81], replyto[81], replyaddr[81], *tmp, *buf, qin[6]; + char to[65], from[65], subj[73], msgid[81], replyto[81], replyaddr[81], *tmp, *buf, qin[6], msg[81]; faddr *Dest = NULL; if (!Post_Allowed()) @@ -1563,10 +1564,11 @@ void Reply_Msg(int IsReply) x = 0; WhosDoingWhat(READ_POST, NULL); clear(); - colour(BLUE, LIGHTGRAY); - printf(" %-71s", sMsgAreaDesc); - colour(RED, LIGHTGRAY); - printf("#%-5lu", MsgBase.Highest + 1); + sprintf(msg, " %-71s", sMsgAreaDesc); + pout(BLUE, LIGHTGRAY, msg); + sprintf(msg, "#%-5lu", MsgBase.Highest + 1); + pout(RED, LIGHTGRAY, msg); + Enter(1); colour(CFG.HiliteF, CFG.HiliteB); sLine(); @@ -1621,10 +1623,8 @@ void Reply_Msg(int IsReply) pout(CFG.MsgInputColourF, CFG.MsgInputColourB, Msg.Subject); x = strlen(subj); - fflush(stdout); colour(CFG.MsgInputColourF, CFG.MsgInputColourB); GetstrP(subj, 50, x); - fflush(stdout); if (strlen(subj)) strcpy(Msg.Subject, subj); @@ -1644,9 +1644,8 @@ void Reply_Msg(int IsReply) case -1:printf("\r"); /* Node not known, continue anayway [y/N]: */ pout(CYAN, BLACK, (char *) Language(241)); - fflush(stdout); alarm_on(); - if (toupper(Getone()) == Keystroke(241, 0)) { + if (toupper(Readkey()) == Keystroke(241, 0)) { Syslog('+', "Node not found, forced continue"); } else { for (i = 0; i < (TEXTBUFSIZE + 1); i++) @@ -1703,8 +1702,7 @@ void Reply_Msg(int IsReply) } if (Edit_Msg()) { - printf("\n"); - fflush(stdout); + Enter(1); if (msgs.Type == NETMAIL) { /* * Check for Carbon Copy lines, process them if present. @@ -1747,8 +1745,7 @@ void Reply_Msg(int IsReply) } else { Save_Msg(IsReply, Dest); } - printf("\n"); - fflush(stdout); + Enter(1); sleep(3); } @@ -1760,33 +1757,33 @@ void Reply_Msg(int IsReply) int IsMe(char *Name) { - char *p, *q; - int i, rc = FALSE; + char *p, *q; + int i, rc = FALSE; - if (strlen(Name) == 0) - return FALSE; + if (strlen(Name) == 0) + return FALSE; - if (strcasecmp(Name, exitinfo.sUserName) == 0) - rc = TRUE; + if (strcasecmp(Name, exitinfo.sUserName) == 0) + rc = TRUE; - if (strcasecmp(Name, exitinfo.sHandle) == 0) - rc = TRUE; + if (strcasecmp(Name, exitinfo.sHandle) == 0) + rc = TRUE; - q = xstrcpy(Name); - if (strstr(q, (char *)"@")) { - p = strtok(q, "@"); - for (i = 0; i < strlen(p); i++) - if (p[i] == '_') - p[i] = ' '; - if (strcasecmp(p, exitinfo.sUserName) == 0) - rc = TRUE; - if (strcasecmp(p, exitinfo.sHandle) == 0) - rc = TRUE; - if (strcasecmp(p, exitinfo.Name) == 0) - rc = TRUE; - } - free(q); - return rc ; + q = xstrcpy(Name); + if (strstr(q, (char *)"@")) { + p = strtok(q, "@"); + for (i = 0; i < strlen(p); i++) + if (p[i] == '_') + p[i] = ' '; + if (strcasecmp(p, exitinfo.sUserName) == 0) + rc = TRUE; + if (strcasecmp(p, exitinfo.sHandle) == 0) + rc = TRUE; + if (strcasecmp(p, exitinfo.Name) == 0) + rc = TRUE; + } + free(q); + return rc ; } @@ -1795,6 +1792,7 @@ void QuickScan_Msgs() { int FoundMsg = FALSE; long i; + char msg[81]; iLineCount = 2; WhosDoingWhat(READ_POST, NULL); @@ -1817,23 +1815,22 @@ void QuickScan_Msgs() if (Msg_ReadHeader(i) && ((msgs.Type != NETMAIL) || ((msgs.Type == NETMAIL) && ((IsMe(Msg.From)) || (IsMe(Msg.To)))))) { - colour(WHITE, BLACK); - printf("%-6lu", Msg.Id); + sprintf(msg, "%-6lu", Msg.Id); + pout(WHITE, BLACK, msg); + sprintf(msg, "%s ", padleft(Msg.From, 20, ' ')); if (IsMe(Msg.From)) - colour(LIGHTCYAN, BLACK); + pout(LIGHTCYAN, BLACK, msg); else - colour(CYAN, BLACK); - printf("%s ", padleft(Msg.From, 20, ' ')); + pout(CYAN, BLACK, msg); + sprintf(msg, "%s ", padleft(Msg.To, 20, ' ')); if (IsMe(Msg.To)) - colour(LIGHTGREEN, BLACK); + pout(LIGHTGREEN, BLACK, msg); else - colour(GREEN, BLACK); - printf("%s ", padleft(Msg.To, 20, ' ')); - colour(MAGENTA, BLACK); - printf("%s", padleft(Msg.Subject, 31, ' ')); - printf("\n"); - fflush(stdout); + pout(GREEN, BLACK, msg); + sprintf(msg, "%s", padleft(Msg.Subject, 31, ' ')); + pout(MAGENTA, BLACK, msg); + Enter(1); FoundMsg = TRUE; if (LC(1)) break; @@ -1870,23 +1867,26 @@ void Delete_Msg() * The area data is already set, so we can do the next things */ if (MsgBase.Total == 0) { - colour(WHITE, BLACK); + Enter(1); /* There are no messages in this area */ - printf("\n%s\n\n", (char *) Language(205)); + pout(WHITE, BLACK, (char *) Language(205)); + Enter(2); sleep(3); return; } - colour(CFG.TextColourF, CFG.TextColourB); - /* Message area \"%s\" contains %lu messages. */ - printf("\n%s\"%s\" %s%lu %s", (char *) Language(221), sMsgAreaDesc, - (char *) Language(222), MsgBase.Total, (char *) Language(223)); - - colour(WHITE, BLACK); - /* Please enter a message between */ - printf("\n%s(%lu - %lu): ", (char *) Language(224), MsgBase.Lowest, MsgBase.Highest); - temp = calloc(81, sizeof(char)); + Enter(1); + /* Message area \"%s\" contains %lu messages. */ + sprintf(temp, "%s\"%s\" %s%lu %s", (char *) Language(221), sMsgAreaDesc, + (char *) Language(222), MsgBase.Total, (char *) Language(223)); + pout(CFG.TextColourF, CFG.TextColourB, temp); + + Enter(1); + /* Please enter a message between */ + sprintf(temp, "%s(%lu - %lu): ", (char *) Language(224), MsgBase.Lowest, MsgBase.Highest); + pout(WHITE, BLACK, temp); + colour(CFG.InputColourF, CFG.InputColourB); GetstrC(temp, 10); if ((strcmp(temp, "")) != 0) @@ -1899,10 +1899,10 @@ void Delete_Msg() } if (!Msg_ReadHeader(Msgnum)) { - perror(""); - colour(WHITE, BLACK); + Enter(1); /* Message doesn't exist */ - printf("\n%s\n\n", (char *)Language(77)); + pout(WHITE, BLACK, (char *)Language(77)); + Enter(2); Msg_Close(); sleep(3); return; @@ -1916,8 +1916,9 @@ void Delete_Msg() Access(exitinfo.Security, msgs.SYSec)) { Delete_MsgNum(Msgnum); } else { - colour(LIGHTRED, BLACK); - printf("\n%s\n\n", (char *)Language(14)); + Enter(1); + pout(LIGHTRED, BLACK, (char *)Language(14)); + Enter(2); } sleep(3); @@ -1931,45 +1932,35 @@ void Delete_Msg() */ int CheckLine(int FG, int BG, int Email) { - int i, x, z; + int x, z; - x = strlen(Language(61)); - iLineCount++; + x = strlen(Language(61)); + iLineCount++; - if ((iLineCount >= (exitinfo.iScreenLen -1)) && (iLineCount < 1000)) { - iLineCount = 7; + if ((iLineCount >= (exitinfo.iScreenLen -1)) && (iLineCount < 1000)) { + iLineCount = 7; - DoNop(); - pout(CFG.MoreF, CFG.MoreB, (char *) Language(61)); + DoNop(); + pout(CFG.MoreF, CFG.MoreB, (char *) Language(61)); - fflush(stdout); - alarm_on(); - z = tolower(Getone()); + alarm_on(); + z = tolower(Readkey()); - for (i = 0; i < x; i++) - putchar('\b'); - for (i = 0; i < x; i++) - putchar(' '); - for (i = 0; i < x; i++) - putchar('\b'); - fflush(stdout); + Blanker(x); - switch(z) { - - case 'n': - printf("\n"); + switch(z) { + case 'n': Enter(1); return TRUE; break; - case '=': - iLineCount = 1000; - } - if (Email) - ShowEmailHdr(); - else - ShowMsgHdr(); - colour(FG, BG); + case '=': iLineCount = 1000; } - return FALSE; + if (Email) + ShowEmailHdr(); + else + ShowMsgHdr(); + colour(FG, BG); + } + return FALSE; } @@ -1984,7 +1975,7 @@ void MsgArea_List(char *Option) int iGotArea = FALSE; /* Flag to check if user typed in area */ int iCheckNew = FALSE; /* Flag to check for new mail in area */ long offset; - char *temp; + char *temp, msg[81]; lastread LR; temp = calloc(PATH_MAX, sizeof(char)); @@ -2161,8 +2152,8 @@ void MsgArea_List(char *Option) if ((Access(exitinfo.Security, msgs.RDSec)) && (msgs.Active)) { msgs.Name[31] = '\0'; - colour(WHITE, BLACK); - printf("%5d", Recno + 1); + sprintf(msg, "%5d", Recno + 1); + pout(WHITE, BLACK, msg); colour(LIGHTBLUE, BLACK); /* Check for New Mail if N was put on option data */ @@ -2176,25 +2167,25 @@ void MsgArea_List(char *Option) if (MsgBase.Highest > LR.HighReadMsg ) { pout(YELLOW, BLACK, (char *)" * "); } else { - printf(" . "); + PUTSTR((char *)" . "); } Msg_Close(); } else { - printf(" . "); + PUTSTR((char *)" . "); } } else { - printf(" . "); + PUTSTR((char *)" . "); } - colour(CYAN, BLACK); - printf("%-31s", msgs.Name); + sprintf(msg, "%-31s", msgs.Name); + pout(CYAN, BLACK, msg); iAreaCount++; if ((iAreaCount % 2) == 0) - printf("\n"); + Enter(1); else - printf(" "); + PUTCHAR(' '); } Recno++; @@ -2206,7 +2197,6 @@ void MsgArea_List(char *Option) * Ask user for Area or enter to continue */ colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); GetstrC(temp, 7); if (toupper(temp[0]) == Keystroke(207, 1)) @@ -2286,7 +2276,6 @@ void MsgArea_List(char *Option) Enter(2); /* Please enter Area Password: */ pout(WHITE, BLACK, (char *) Language(233)); - fflush(stdout); colour(CFG.InputColourF, CFG.InputColourB); GetstrC(temp, 20); @@ -2340,46 +2329,45 @@ void Delete_MsgNum(unsigned long MsgNum) */ int CheckUser(char *To) { - FILE *pUsrConfig; - int Found = FALSE; - char *temp; - long offset; - unsigned long Crc; + FILE *pUsrConfig; + int Found = FALSE; + char *temp; + long offset; + unsigned long Crc; - temp = calloc(PATH_MAX, sizeof(char)); - sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT")); - if ((pUsrConfig = fopen(temp,"rb")) == NULL) { - perror(""); - WriteError("Can't open file %s for reading", temp); - Pause(); - free(temp); - return FALSE; - } + temp = calloc(PATH_MAX, sizeof(char)); + sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT")); + if ((pUsrConfig = fopen(temp,"rb")) == NULL) { + WriteError("$Can't open file %s for reading", temp); + Pause(); free(temp); - fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig); - Crc = StringCRC32(tl(To)); + return FALSE; + } + free(temp); + fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig); + Crc = StringCRC32(tl(To)); - while (fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig) == 1) { - if (StringCRC32(tl(usrconfig.sUserName)) == Crc) { - Found = TRUE; - break; - } + while (fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig) == 1) { + if (StringCRC32(tl(usrconfig.sUserName)) == Crc) { + Found = TRUE; + break; } + } - if (!Found) - Syslog('!', "User attempted to mail unknown user: %s", tlcap(To)); + if (!Found) + Syslog('!', "User attempted to mail unknown user: %s", tlcap(To)); - /* - * Restore users record - */ - offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize); - if (fseek(pUsrConfig, offset, 0) != 0) - printf("Can't move pointer there."); - else - fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig); - fclose(pUsrConfig); + /* + * Restore users record + */ + offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize); + if (fseek(pUsrConfig, offset, 0) != 0) + WriteError("$Can't move pointer there."); + else + fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig); + fclose(pUsrConfig); - return Found; + return Found; } @@ -2391,7 +2379,7 @@ void CheckMail() { FILE *pMsgArea, *Tmp; int x, Found = 0, Color, Count = 0, Reading, OldMsgArea; - char *temp, *sFileName; + char *temp, *sFileName, msg[81]; unsigned long i, Start; typedef struct _Mailrec { long Area; @@ -2409,7 +2397,6 @@ void CheckMail() language(LIGHTGREEN, BLACK, 150); Enter(2); Color = LIGHTBLUE; - fflush(stdout); /* * Open temporary file @@ -2426,8 +2413,8 @@ void CheckMail() if (exitinfo.Email && strlen(exitinfo.Password)) { check_popmail(exitinfo.Name, exitinfo.Password); colour(Color++, BLACK); - printf("\re-mail Private e-mail mailbox"); - fflush(stdout); + PUTCHAR('\r'); + PUTSTR((char *)"e-mail Private e-mail mailbox"); Count = 0; sprintf(temp, "%s/%s/mailbox", CFG.bbs_usersdir, exitinfo.Name); SetEmailArea((char *)"mailbox"); @@ -2448,7 +2435,7 @@ void CheckMail() * Only check the received status of the email. The mail * may not be direct addressed to this user (aliases database) * but if it is in his mailbox it is always for the user. - * FIXME: mail writte by the user is shown as new too. + * FIXME: mail written by the user is shown as new too. */ if (!Msg.Received) { /* @@ -2465,9 +2452,11 @@ void CheckMail() Msg_Close(); } if (Count) { - colour(CFG.TextColourF, CFG.TextColourB); + Enter(2); /* messages in */ - printf("\n\n%d %s private e-mail mailbox\n\n", Count, (char *)Language(213)); + sprintf(temp, "%d %s private e-mail mailbox", Count, (char *)Language(213)); + pout(CFG.TextColourF, CFG.TextColourB, temp); + Enter(2); Syslog('m', " %d messages in private e-mail mailbox", Count); } } @@ -2493,13 +2482,13 @@ void CheckMail() if ((msgs.Active) && (exitinfo.Security.level >= msgs.RDSec.level)) { SetMsgArea(iMsgAreaNumber); sprintf(temp, "%d", iMsgAreaNumber + 1); - colour(Color, 0); if (Color < WHITE) Color++; else Color = LIGHTBLUE; - printf("\r%6s %-40s", temp, sMsgAreaDesc); - fflush(stdout); + PUTCHAR('\r'); + sprintf(msg, "%6s %-40s", temp, sMsgAreaDesc); + pout(Color, BLACK, msg); Count = 0; /* * Refresh timers @@ -2536,9 +2525,11 @@ void CheckMail() Msg_Close(); } if (Count) { - colour(CFG.TextColourF, CFG.TextColourB); + Enter(2); /* messages in */ - printf("\n\n%d %s %s\n\n", Count, (char *)Language(213), sMsgAreaDesc); + sprintf(msg, "%d %s %s", Count, (char *)Language(213), sMsgAreaDesc); + pout(CFG.TextColourF, CFG.TextColourB, msg); + Enter(2); Syslog('m', " %d messages in %s", Count, sMsgAreaDesc); } } @@ -2546,21 +2537,20 @@ void CheckMail() } fclose(pMsgArea); - putchar('\r'); + PUTCHAR('\r'); for (i = 0; i < 48; i++) - putchar(' '); - putchar('\r'); + PUTCHAR(' '); + PUTCHAR('\r'); if (Found) { - colour(YELLOW, BLACK); + Enter(1); /* You have messages, read your mail now? [Y/n]: */ - printf("\n%s%d %s", (char *) Language(142), Found, (char *) Language(143)); + sprintf(msg, "%s%d %s", (char *) Language(142), Found, (char *) Language(143)); + pout(YELLOW, BLACK, msg); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); - fflush(stdin); alarm_on(); - if (toupper(Getone()) != Keystroke(143,1)) { + if (toupper(Readkey()) != Keystroke(143,1)) { rewind(Tmp); Reading = TRUE; @@ -2576,10 +2566,8 @@ void CheckMail() } /* (R)eply, (N)ext, (Q)uit */ pout(CFG.CRColourF, CFG.CRColourB, (char *)Language(218)); - fflush(stdout); - fflush(stdin); alarm_on(); - x = toupper(Getone()); + x = toupper(Readkey()); if (x == Keystroke(218, 0)) { Syslog('m', " Reply!"); @@ -2594,7 +2582,7 @@ void CheckMail() iMsgAreaNumber = OldMsgArea; fclose(Tmp); SetMsgArea(OldMsgArea); - printf("\n\n"); + Enter(2); free(temp); free(sFileName); return; @@ -2610,7 +2598,7 @@ void CheckMail() iMsgAreaNumber = OldMsgArea; fclose(Tmp); SetMsgArea(OldMsgArea); - printf("\n\n"); + Enter(2); free(temp); free(sFileName); } @@ -2622,125 +2610,118 @@ void CheckMail() */ void MailStatus() { - FILE *pMsgArea; - int Count = 0; - int OldMsgArea; - char temp[81]; - char *sFileName; - unsigned long i; + FILE *pMsgArea; + int Count = 0; + int OldMsgArea; + char temp[81], msg[81]; + char *sFileName; + unsigned long i; - sFileName = calloc(PATH_MAX, sizeof(char)); - OldMsgArea = iMsgAreaNumber; - iMsgAreaNumber = 0; - clear(); - colour(YELLOW, BLUE); - /* Area Type Description Messages Personal */ - printf("%-79s", (char *)Language(226)); - Enter(1); - iLineCount = 2; - fflush(stdout); + sFileName = calloc(PATH_MAX, sizeof(char)); + OldMsgArea = iMsgAreaNumber; + iMsgAreaNumber = 0; + clear(); + /* Area Type Description Messages Personal */ + sprintf(msg, "%-79s", (char *)Language(226)); + pout(YELLOW, BLUE, msg); + Enter(1); + iLineCount = 2; - if (exitinfo.Email) { - sprintf(temp, "%s", sMailbox); - for (i = 0; i < 3; i++) { - switch (i) { - case 0: SetEmailArea((char *)"mailbox"); - break; - case 1: SetEmailArea((char *)"archive"); - break; - case 2: SetEmailArea((char *)"trash"); - break; - } - colour(LIGHTRED, BLACK); - printf(" Email"); - colour(LIGHTCYAN, BLACK); - printf(" %-40s", Language(467 + i)); - colour(YELLOW, BLACK); - if (EmailBase.Highest) - printf(" %8lu", EmailBase.Highest - EmailBase.Lowest + 1); - else - printf(" 0"); - colour(LIGHTBLUE, BLACK); - if (EmailBase.Highest) - printf(" %8lu\n", EmailBase.Highest - EmailBase.Lowest + 1); - else - printf(" 0\n"); - } - iLineCount = 5; - SetEmailArea(temp); + if (exitinfo.Email) { + sprintf(temp, "%s", sMailbox); + for (i = 0; i < 3; i++) { + switch (i) { + case 0: SetEmailArea((char *)"mailbox"); + break; + case 1: SetEmailArea((char *)"archive"); + break; + case 2: SetEmailArea((char *)"trash"); + break; + } + pout(LIGHTRED, BLACK, (char *)" Email"); + sprintf(msg, " %-40s", Language(467 + i)); + pout(LIGHTCYAN, BLACK, msg); + if (EmailBase.Highest) + sprintf(msg, " %8lu", EmailBase.Highest - EmailBase.Lowest + 1); + else + sprintf(msg, " 0"); + pout(YELLOW, BLACK, msg); + if (EmailBase.Highest) + sprintf(msg, " %8lu", EmailBase.Highest - EmailBase.Lowest + 1); + else + sprintf(msg, " 0"); + pout(LIGHTBLUE, BLACK, msg); + Enter(1); } + iLineCount = 5; + SetEmailArea(temp); + } - /* - * Open the message base configuration - */ - sprintf(sFileName,"%s/etc/mareas.data", getenv("MBSE_ROOT")); - if((pMsgArea = fopen(sFileName, "r+")) == NULL) { - WriteError("Can't open file: %s", sFileName); - free(sFileName); - return; - } - fread(&msgshdr, sizeof(msgshdr), 1, pMsgArea); - - /* - * Check all areas one by one - */ - while (fread(&msgs, msgshdr.recsize, 1, pMsgArea) == 1) { - fseek(pMsgArea, msgshdr.syssize, SEEK_CUR); - if ((msgs.Active) && (exitinfo.Security.level >= msgs.RDSec.level)) { - SetMsgArea(iMsgAreaNumber); - sprintf(temp, "%d", iMsgAreaNumber + 1); - colour(WHITE, BLACK); - printf("%5s", temp); - colour(LIGHTRED, BLACK); - switch(msgs.Type) { - case LOCALMAIL: - printf(" Local"); - break; - - case NETMAIL: - printf(" Net "); - break; - - case LIST: - case ECHOMAIL: - printf(" Echo "); - break; - - case NEWS: - printf(" News "); - break; - } - colour(LIGHTCYAN, BLACK); - printf(" %-40s", sMsgAreaDesc); - Count = 0; - - if (Msg_Open(sMsgAreaBase)) { - for (i = MsgBase.Lowest; i <= MsgBase.Highest; i++) { - if (Msg_ReadHeader(i)) { - if (IsMe(Msg.To) || IsMe(Msg.From)) - Count++; - } - } - Msg_Close(); - } else - WriteError("Error open JAM %s", sMsgAreaBase); - colour(YELLOW, BLACK); - if (MsgBase.Highest) - printf(" %8lu", MsgBase.Highest - MsgBase.Lowest + 1); - else - printf(" 0"); - colour(LIGHTBLUE, BLACK); - printf(" %8d\n", Count); - if (LC(1)) - break; - } - iMsgAreaNumber++; - } - - fclose(pMsgArea); - SetMsgArea(OldMsgArea); + /* + * Open the message base configuration + */ + sprintf(sFileName,"%s/etc/mareas.data", getenv("MBSE_ROOT")); + if((pMsgArea = fopen(sFileName, "r+")) == NULL) { + WriteError("Can't open file: %s", sFileName); free(sFileName); - Pause(); + return; + } + fread(&msgshdr, sizeof(msgshdr), 1, pMsgArea); + + /* + * Check all areas one by one + */ + while (fread(&msgs, msgshdr.recsize, 1, pMsgArea) == 1) { + fseek(pMsgArea, msgshdr.syssize, SEEK_CUR); + if ((msgs.Active) && (exitinfo.Security.level >= msgs.RDSec.level)) { + SetMsgArea(iMsgAreaNumber); + sprintf(temp, "%d", iMsgAreaNumber + 1); + sprintf(msg, "%5s", temp); + pout(WHITE, BLACK, msg); + colour(LIGHTRED, BLACK); + switch(msgs.Type) { + case LOCALMAIL: PUTSTR((char *)" Local"); + break; + case NETMAIL: PUTSTR((char *)" Net "); + break; + case LIST: + case ECHOMAIL: PUTSTR((char *)" Echo "); + break; + case NEWS: PUTSTR((char *)" News "); + break; + } + sprintf(msg, " %-40s", sMsgAreaDesc); + pout(LIGHTCYAN, BLACK, msg); + Count = 0; + + if (Msg_Open(sMsgAreaBase)) { + for (i = MsgBase.Lowest; i <= MsgBase.Highest; i++) { + if (Msg_ReadHeader(i)) { + if (IsMe(Msg.To) || IsMe(Msg.From)) + Count++; + } + } + Msg_Close(); + } else + WriteError("Error open JAM %s", sMsgAreaBase); + if (MsgBase.Highest) + sprintf(msg, " %8lu", MsgBase.Highest - MsgBase.Lowest + 1); + else + sprintf(msg, " 0"); + pout(YELLOW, BLACK, msg); + sprintf(msg, " %8d", Count); + pout(LIGHTBLUE, BLACK, msg); + Enter(1); + if (LC(1)) + break; + } + iMsgAreaNumber++; + } + + fclose(pMsgArea); + SetMsgArea(OldMsgArea); + free(sFileName); + Pause(); } @@ -2750,49 +2731,49 @@ void MailStatus() */ void SetMsgArea(unsigned long AreaNum) { - FILE *pMsgArea; - long offset; - char *sFileName; + FILE *pMsgArea; + long offset; + char *sFileName; - sFileName = calloc(PATH_MAX, sizeof(char)); - sprintf(sFileName,"%s/etc/mareas.data", getenv("MBSE_ROOT")); - memset(&msgs, 0, sizeof(msgs)); + sFileName = calloc(PATH_MAX, sizeof(char)); + sprintf(sFileName,"%s/etc/mareas.data", getenv("MBSE_ROOT")); + memset(&msgs, 0, sizeof(msgs)); - if((pMsgArea = fopen(sFileName, "r")) == NULL) { - WriteError("$Can't open file: %s", sFileName); - free(sFileName); - return; - } - - fread(&msgshdr, sizeof(msgshdr), 1, pMsgArea); - offset = msgshdr.hdrsize + (AreaNum * (msgshdr.recsize + msgshdr.syssize)); - if(fseek(pMsgArea, offset, 0) != 0) { - WriteError("$Can't move pointer in %s",sFileName); - free(sFileName); - return; - } - - fread(&msgs, msgshdr.recsize, 1, pMsgArea); - strcpy(sMsgAreaDesc, msgs.Name); - strcpy(sMsgAreaBase, msgs.Base); - iMsgAreaNumber = AreaNum; - iMsgAreaType = msgs.Type; - - fclose(pMsgArea); - - /* - * Get information from the message base - */ - - if (Msg_Open(sMsgAreaBase)) { - - MsgBase.Lowest = Msg_Lowest(); - MsgBase.Highest = Msg_Highest(); - MsgBase.Total = Msg_Number(); - Msg_Close(); - } else - WriteError("Error open JAM %s", sMsgAreaBase); + if ((pMsgArea = fopen(sFileName, "r")) == NULL) { + WriteError("$Can't open file: %s", sFileName); free(sFileName); + return; + } + + fread(&msgshdr, sizeof(msgshdr), 1, pMsgArea); + offset = msgshdr.hdrsize + (AreaNum * (msgshdr.recsize + msgshdr.syssize)); + if (fseek(pMsgArea, offset, 0) != 0) { + WriteError("$Can't move pointer in %s",sFileName); + free(sFileName); + return; + } + + fread(&msgs, msgshdr.recsize, 1, pMsgArea); + strcpy(sMsgAreaDesc, msgs.Name); + strcpy(sMsgAreaBase, msgs.Base); + iMsgAreaNumber = AreaNum; + iMsgAreaType = msgs.Type; + + fclose(pMsgArea); + + /* + * Get information from the message base + */ + + if (Msg_Open(sMsgAreaBase)) { + + MsgBase.Lowest = Msg_Lowest(); + MsgBase.Highest = Msg_Highest(); + MsgBase.Total = Msg_Number(); + Msg_Close(); + } else + WriteError("Error open JAM %s", sMsgAreaBase); + free(sFileName); } @@ -2839,6 +2820,9 @@ int Ext_Edit() fclose(fd); stat( tmpname, &st1 ); ExtDoor(CFG.externaleditor,FALSE,TRUE,TRUE,FALSE,TRUE, FALSE, (char *)"Write message"); + if (rawport() != 0) { + WriteError("Unable to set raw mode"); + } stat( tmpname, &st2 ); } diff --git a/mbsebbs/mbnewusr.c b/mbsebbs/mbnewusr.c index 2748b2c1..22521774 100644 --- a/mbsebbs/mbnewusr.c +++ b/mbsebbs/mbnewusr.c @@ -40,7 +40,8 @@ #include "timeout.h" #include "newuser.h" #include "term.h" - +#include "ttyio.h" +#include "openport.h" extern int do_quiet; /* Logging quiet flag */ @@ -52,10 +53,9 @@ int main(int argc, char **argv) { char *p, *tty, temp[PATH_MAX]; FILE *pTty; - int i; + int i, rc = 0; struct passwd *pw; - printf("\n\nLoading MBSE BBS New User Registration ...\n\n"); pTTY = calloc(15, sizeof(char)); tty = ttyname(1); @@ -105,6 +105,15 @@ int main(int argc, char **argv) Syslog(' ', " "); Syslog(' ', "MBNEWUSR v%s", VERSION); + if ((rc = rawport()) != 0) { + WriteError("Unable to set raw mode"); + Fast_Bye(MBERR_OK);; + } + + Enter(2); + PUTSTR((char *)"Loading MBSE BBS New User Registration ..."); + Enter(2); + if ((p = getenv("CONNECT")) != NULL) Syslog('+', "CONNECT %s", p); if ((p = getenv("CALLER_ID")) != NULL) @@ -137,7 +146,7 @@ int main(int argc, char **argv) * Trap signals */ for (i = 0; i < NSIG; i++) { - if ((i == SIGHUP) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || (i == SIGKILL)) + if ((i == SIGHUP) || (i == SIGPIPE) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) signal(i, (void (*))die); else if (i == SIGCHLD) signal(i, SIG_DFL); @@ -160,10 +169,10 @@ int main(int argc, char **argv) Fast_Bye(MBERR_OK); } - colour(YELLOW, BLACK); - printf("MBSE BBS v%s (Release: %s) on %s/%s\n", VERSION, ReleaseDate, OsName(), OsCPU()); - colour(WHITE, BLACK); - printf("%s\n\n", COPYRIGHT); + sprintf(temp, "MBSE BBS v%s (Release: %s) on %s/%s", VERSION, ReleaseDate, OsName(), OsCPU()); + poutCR(YELLOW, BLACK, temp); + pout(WHITE, BLACK, (char *)COPYRIGHT); + Enter(2); /* * Check if this port is available. @@ -183,7 +192,8 @@ int main(int argc, char **argv) if ((strcmp(ttyinfo.tty, pTTY) != 0) || (!ttyinfo.available)) { Syslog('+', "No BBS allowed on port \"%s\"", pTTY); - printf("No BBS on this port allowed!\n\n"); + PUTSTR((char *)"No BBS on this port allowed!"); + Enter(2); Fast_Bye(MBERR_OK); } @@ -192,10 +202,12 @@ int main(int argc, char **argv) */ if (CFG.iConnectString) { /* Connected on port */ - colour(CYAN, BLACK); - printf("%s\"%s\" ", (char *) Language(348), ttyinfo.comment); + sprintf(temp, "%s\"%s\" ", (char *) Language(348), ttyinfo.comment); + pout(CYAN, BLACK, temp); /* on */ - printf("%s %s\n", (char *) Language(135), ctime(<ime)); + sprintf(temp, "%s %s", (char *) Language(135), ctime(<ime)); + PUTSTR(temp); + Enter(1); } } diff --git a/mbsebbs/mbsebbs.c b/mbsebbs/mbsebbs.c index d3ca2b4b..2eef9525 100644 --- a/mbsebbs/mbsebbs.c +++ b/mbsebbs/mbsebbs.c @@ -43,6 +43,8 @@ #include "timeout.h" #include "funcs.h" #include "term.h" +#include "ttyio.h" +#include "openport.h" #include #include @@ -57,10 +59,9 @@ int main(int argc, char **argv) { FILE *pTty; char *p, *tty, temp[PATH_MAX]; - int i; + int i, rc; struct stat sb; - printf("Loading MBSE BBS ...\n"); pTTY = calloc(15, sizeof(char)); tty = ttyname(1); @@ -73,7 +74,7 @@ int main(int argc, char **argv) } else if (getenv("USER") != NULL) { strcpy(sUnixName, getenv("USER")); } else { - WriteError("No username in environment"); + fprintf(stderr, "No username in environment\n"); Quick_Bye(MBERR_OK); } @@ -104,10 +105,18 @@ int main(int argc, char **argv) InitClient(sUnixName, (char *)"mbsebbs", (char *)"Unknown", CFG.logfile, CFG.bbs_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog); IsDoing("Loging in"); - Syslog(' ', " "); Syslog(' ', "MBSEBBS v%s", VERSION); + if ((rc = rawport()) != 0) { + WriteError("Unable to set raw mode"); + Quick_Bye(MBERR_OK);; + } + + PUTSTR((char *)"Loading MBSE BBS ..."); + PUTCHAR('\r'); + PUTCHAR('\n'); + if ((p = getenv("CONNECT")) != NULL) Syslog('+', "CONNECT %s", p); if ((p = getenv("CALLER_ID")) != NULL) @@ -142,8 +151,8 @@ int main(int argc, char **argv) /* * Trap signals */ - for(i = 0; i < NSIG; i++) { - if ((i == SIGHUP) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) + for (i = 0; i < NSIG; i++) { + if ((i == SIGHUP) || (i == SIGPIPE) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) signal(i, (void (*))die); else if (i == SIGCHLD) signal(i, SIG_DFL); @@ -156,7 +165,7 @@ int main(int argc, char **argv) * is in color, the user will see color no mather what. */ TermInit(1, 80, 24); - + /* * Now it's time to check if the bbs is open. If not, we * log the user off. @@ -170,10 +179,10 @@ int main(int argc, char **argv) clear(); DisplayLogo(); - colour(YELLOW, BLACK); - printf("MBSE BBS v%s (Release: %s) on %s/%s\n", VERSION, ReleaseDate, OsName(), OsCPU()); - colour(WHITE, BLACK); - printf("%s\n\n", COPYRIGHT); + sprintf(temp, "MBSE BBS v%s (Release: %s) on %s/%s", VERSION, ReleaseDate, OsName(), OsCPU()); + poutCR(YELLOW, BLACK, temp); + pout(WHITE, BLACK, (char *)COPYRIGHT); + Enter(2); /* * Check users homedirectory, some *nix systems let users in if no @@ -181,7 +190,8 @@ int main(int argc, char **argv) */ sprintf(temp, "%s/%s", CFG.bbs_usersdir, sUnixName); if (stat(temp, &sb)) { - printf("No homedirectory\n\n"); + sprintf(temp, "No homedirectory\r\n\r\n"); + PUTSTR(temp); WriteError("homedirectory %s doesn't exist", temp); Quick_Bye(MBERR_OK); } @@ -204,7 +214,8 @@ int main(int argc, char **argv) if ((strcmp(ttyinfo.tty, pTTY) != 0) || (!ttyinfo.available)) { Syslog('+', "No BBS allowed on port \"%s\"", pTTY); - printf("No BBS on this port allowed!\n\n"); + sprintf(temp, "No BBS on this port allowed!\r\n\r\n"); + PUTSTR(temp); Free_Language(); Quick_Bye(MBERR_OK); } @@ -214,10 +225,12 @@ int main(int argc, char **argv) */ if (CFG.iConnectString) { /* Connected on port */ - colour(CYAN, BLACK); - printf("%s\"%s\" ", (char *) Language(348), ttyinfo.comment); + sprintf(temp, "%s\"%s\" ", (char *) Language(348), ttyinfo.comment); + pout(CYAN, BLACK, temp); /* on */ - printf("%s %s\n", (char *) Language(135), ctime(<ime)); + sprintf(temp, "%s %s", (char *) Language(135), ctime(<ime)); + PUTSTR(temp); + Enter(1); } } diff --git a/mbsebbs/menu.c b/mbsebbs/menu.c index 058906bc..bed5bccc 100644 --- a/mbsebbs/menu.c +++ b/mbsebbs/menu.c @@ -60,6 +60,7 @@ #include "lastcallers.h" #include "signature.h" #include "term.h" +#include "ttyio.h" extern pid_t mypid; @@ -90,7 +91,7 @@ void menu() { FILE *pMenuFile; int iFoundKey = FALSE, Key, IsANSI; - char *Input, *sMenuPathFileName, buf[81]; + char temp[81], *Input, *sMenuPathFileName, buf[81]; Input = calloc(PATH_MAX, sizeof(char)); sMenuPathFileName = calloc(PATH_MAX, sizeof(char)); @@ -127,7 +128,8 @@ void menu() */ if (MenuError == 10) { WriteError("FATAL ERROR: Too many menu errors"); - printf("Too many menu errors, notifying Sysop\n\n"); + sprintf(temp, "Too many menu errors, notifying Sysop\r\n\r\n"); + PUTSTR(temp); sleep(3); die(MBERR_CONFIG_ERROR); } @@ -179,7 +181,9 @@ void menu() if (IsSema((char *)"upsdown")) { fclose(pMenuFile); Syslog('+', "Kicking user out, upsdown semafore detected"); - printf("System power failure, closing the bbs\n\n"); + sprintf(temp, "System power failure, closing the bbs"); + PUTSTR(temp); + Enter(2); sleep(3); Good_Bye(MBERR_OK); } @@ -205,10 +209,9 @@ void menu() alarm_on(); if (exitinfo.HotKeys) { - fflush(stdout); - Key = Getone(); + Key = Readkey(); sprintf(Input, "%c", Key); - printf("\n"); + Enter(1); } else { colour(CFG.InputColourF, CFG.InputColourB); GetstrC(Input, 80); @@ -381,7 +384,8 @@ void DoMenu(int Type) for (i = 0; i < strlen(menus.OptionalData); i++) if (*(menus.OptionalData + i) == '@') *(menus.OptionalData + i) = '\n'; - printf("%s\n", menus.OptionalData); + sprintf(temp, "%s\r\n", menus.OptionalData); + PUTSTR(temp); } break; @@ -743,7 +747,7 @@ void DisplayMenu(void) if ( ( dpos + 1 ) == maxdpos ) { skipCRLF=1; } else { - printf("%c",menus.Display[ dpos ]); + PUTCHAR(menus.Display[ dpos ]); } break; @@ -751,7 +755,7 @@ void DisplayMenu(void) escaped = 1; } else { escaped = 0; - printf("%c",menus.Display[ dpos ]); + PUTCHAR(menus.Display[ dpos ]); } break; @@ -767,17 +771,17 @@ void DisplayMenu(void) } } else { escaped=0; - printf("%c",menus.Display[ dpos ]); + PUTCHAR(menus.Display[ dpos ]); } break; default: /* all other characters */ - printf("%c",menus.Display[ dpos ]); + PUTCHAR(menus.Display[ dpos ]); } } if ( !skipCRLF ) { - printf("\n"); + Enter(1); } } diff --git a/mbsebbs/misc.c b/mbsebbs/misc.c index d4bbd0d6..6fc0670c 100644 --- a/mbsebbs/misc.c +++ b/mbsebbs/misc.c @@ -32,12 +32,15 @@ #include "../lib/mbselib.h" #include "../lib/mbse.h" #include "../lib/users.h" +#include "../lib/msg.h" #include "funcs.h" #include "input.h" #include "language.h" #include "misc.h" #include "timeout.h" #include "exitinfo.h" +#include "ttyio.h" +#include "term.h" extern char *StartTime; /* Time user logged in */ @@ -113,14 +116,17 @@ void DisplayLogo() char *sString, *temp; temp = calloc(PATH_MAX, sizeof(char)); - sString = calloc(81, sizeof(char)); + sString = calloc(1024, sizeof(char)); sprintf(temp, "%s/%s", CFG.bbs_txtfiles, CFG.welcome_logo); if ((pLogo = fopen(temp,"rb")) == NULL) WriteError("$DisplayLogo: Can't open %s", temp); else { - while (fgets(sString, 80, pLogo) != NULL) - printf("%s", sString); + while (Fgets(sString, 1023, pLogo) != NULL) { +// Striplf(sString); + PUTSTR(sString); + Enter(1); + } fclose(pLogo); } free(sString); diff --git a/mbsebbs/morefile.c b/mbsebbs/morefile.c index d6605481..5e09040d 100644 --- a/mbsebbs/morefile.c +++ b/mbsebbs/morefile.c @@ -36,62 +36,61 @@ #include "language.h" #include "morefile.h" #include "timeout.h" - +#include "term.h" +#include "ttyio.h" int MoreFile(char *filename) { - char Buf[81]; - static FILE *fptr; - int lines; - int input; - int ignore = FALSE; - int maxlines; + char Buf[81]; + static FILE *fptr; + int lines, input, ignore = FALSE, maxlines; - maxlines = lines = exitinfo.iScreenLen - 2; + maxlines = lines = exitinfo.iScreenLen - 2; - if ((fptr = fopen(filename,"r")) == NULL) { - printf("%s%s\n", (char *) Language(72), filename); + if ((fptr = fopen(filename,"r")) == NULL) { + sprintf(Buf, "%s%s", (char *) Language(72), filename); + pout(LIGHTRED, BLACK, Buf); + Enter(2); + return(0); + } + + Enter(1); + + while (fgets(Buf,80,fptr) != NULL) { + if ((lines != 0) || (ignore)) { + lines--; + PUTSTR(Buf); + } + + if (strlen(Buf) == 0) { + fclose(fptr); + return(0); + } + if (lines == 0) { + /* More (Y/n/=) */ + sprintf(Buf, " %sY\x08", (char *) Language(61)); + PUTSTR(Buf); + alarm_on(); + input = toupper(getchar()); + + if ((input == Keystroke(61, 0)) || (input == '\r')) + lines = maxlines; + + if (input == Keystroke(61, 1)) { + fclose(fptr); return(0); + } + + if (input == Keystroke(61, 2)) + ignore = TRUE; + else + lines = maxlines; } - - printf("\n"); - - while (fgets(Buf,80,fptr) != NULL) { - if ((lines != 0) || (ignore)) { - lines--; - printf("%s",Buf); - } - - if (strlen(Buf) == 0) { - fclose(fptr); - return(0); - } - if (lines == 0) { - fflush(stdin); - /* More (Y/n/=) */ - printf(" %sY\x08", (char *) Language(61)); - fflush(stdout); - alarm_on(); - input = toupper(getchar()); - - if ((input == Keystroke(61, 0)) || (input == '\r')) - lines = maxlines; - - if (input == Keystroke(61, 1)) { - fclose(fptr); - return(0); - } - - if (input == Keystroke(61, 2)) - ignore = TRUE; - else - lines = maxlines; - } - } - Pause(); - fclose(fptr); - return 1; + } + Pause(); + fclose(fptr); + return 1; } diff --git a/mbsebbs/newuser.c b/mbsebbs/newuser.c index d0b3ad02..2fb84438 100644 --- a/mbsebbs/newuser.c +++ b/mbsebbs/newuser.c @@ -41,6 +41,9 @@ #include "change.h" #include "dispfile.h" #include "term.h" +#include "ttyio.h" +#include "openport.h" + /* @@ -105,7 +108,6 @@ int newuser() /* Please enter your First and Last name: */ language(CYAN, BLACK, 0); - fflush(stdout); alarm_on(); Getname(temp, 35); strcpy(FullName, tlcap(temp)); @@ -148,14 +150,12 @@ int newuser() Enter(1); /* Please enter new password : */ language(LIGHTCYAN, BLACK, 39); - fflush(stdout); alarm_on(); Getpass(temp1); if ((x = strlen(temp1)) >= CFG.password_length) { Enter(1); /* Please enter password again : */ language(LIGHTCYAN, BLACK, 40); - fflush(stdout); alarm_on(); Getpass(temp2); if ((i = strcmp(temp1,temp2)) != 0) { @@ -171,7 +171,8 @@ int newuser() Enter(2); /* Your password must contain at least */ language(LIGHTRED, BLACK, 42); - printf("%d ", CFG.password_length); + sprintf(temp, "%d ", CFG.password_length); + PUTSTR(temp); /* characters! Try again. */ language(WHITE, BLACK, 43); Enter(1); @@ -218,7 +219,6 @@ int newuser() pout(LIGHTGREEN, BLACK, (char *)": "); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); alarm_on(); GetPhone(temp, 16); @@ -269,7 +269,7 @@ int newuser() } /* End of if Statement */ if (!CFG.iDataPhone) - printf("\n"); + Enter(1); if (CFG.iLocation) { while (TRUE) { @@ -279,7 +279,6 @@ int newuser() colour(CFG.InputColourF, CFG.InputColourB); alarm_on(); if (CFG.iCapLocation) { /* Cap Location is turned on, Capitalise first letter */ - fflush(stdout); GetnameNE(temp, 24); } else GetstrC(temp, 80); @@ -289,7 +288,8 @@ int newuser() /* Please enter a longer location */ language(LIGHTRED, BLACK, 50); Enter(1); - printf("%s%d)", (char *) Language(74), CFG.CityLen); + sprintf(temp, "%s%d)", (char *) Language(74), CFG.CityLen); + PUTSTR(temp); Enter(1); } else { strcpy(usrconfig.sLocation, temp); @@ -306,10 +306,9 @@ int newuser() language(LIGHTMAGENTA, BLACK, 474); Enter(1); for (i = 0; i < 3; i++) { - colour(YELLOW, BLACK); - printf("%d: ", i+1); + sprintf(temp, "%d: ", i+1); + pout(YELLOW, BLACK, temp); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); alarm_on(); GetstrC(usrconfig.address[i], 40); } @@ -328,7 +327,6 @@ int newuser() /* Enter a handle (Enter to Quit): */ language(LIGHTRED, BLACK, 412); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); alarm_on(); Getname(temp, 34); @@ -356,9 +354,8 @@ int newuser() /* What is your sex? (M)ale or (F)emale: */ language(LIGHTBLUE, BLACK, 51); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); alarm_on(); - i = toupper(Getone()); + i = toupper(Readkey()); if (i == Keystroke(51, 0)) { /* Male */ @@ -388,7 +385,6 @@ int newuser() /* Please enter your Date of Birth DD-MM-YYYY: */ pout(CYAN, BLACK, (char *) Language(56)); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); alarm_on(); GetDate(temp, 10); @@ -454,7 +450,6 @@ int newuser() /* Please enter your Screen Length [24]: */ pout(LIGHTMAGENTA, BLACK, (char *) Language(64)); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); alarm_on(); Getnum(temp, 3); @@ -572,15 +567,16 @@ int newuser() /* Login Name : */ pout(LIGHTBLUE, BLACK, (char *) Language(68)); colour(CYAN, BLACK); - printf("%s (%s)\n", UnixName, FullName); + sprintf(temp, "%s (%s)", UnixName, FullName); + PUTSTR(temp); + Enter(1); /* Password : */ pout(LIGHTBLUE, BLACK, (char *) Language(69)); pout(CYAN, BLACK, (char *)"<"); /* not displayed */ pout(WHITE, BLACK, (char *) Language(70)); - pout(CYAN, BLACK, (char *)">\n\n"); - fflush(stdout); - fflush(stdin); + pout(CYAN, BLACK, (char *)">"); + Enter(2); if (CFG.iVoicePhone && TelephoneScan(Phone1, FullName)) Syslog('!', "Duplicate phone numbers found"); @@ -597,8 +593,7 @@ int newuser() Syslog('+', "Completed new-user procedure"); /* New user registration completed. */ - pout(LIGHTGREEN, BLACK, (char *) Language(71)); - Enter(1); + poutCR(LIGHTGREEN, BLACK, (char *) Language(71)); /* You need to login again with the name: */ pout(LIGHTRED, BLACK, (char *) Language(5)); pout(YELLOW, BLACK, UnixName); @@ -606,7 +601,7 @@ int newuser() alarm_on(); Pause(); alarm_off(); - printf("\n"); + Enter(1); return 0; } @@ -615,7 +610,7 @@ int newuser() void Fast_Bye(int onsig) { char *temp; - time_t t_end; + time_t t_end; t_end = time(NULL); Syslog(' ', "MBNEWUSR finished in %s", t_elapsed(t_start, t_end)); @@ -627,10 +622,11 @@ void Fast_Bye(int onsig) free(temp); colour(LIGHTGRAY, BLACK); - fflush(stdout); - fflush(stdin); sleep(3); + cookedport(); + hangup(); + Free_Language(); free(pTTY); exit(MBERR_OK); @@ -661,24 +657,22 @@ char *NameGen(char *FidoName) Syslog('+', "NameGen(%s)", FidoName); while ((strcmp(sUserName, "") == 0) || (CheckUnixNames(sUserName)) || (strlen(sUserName) < 3)) { - colour(LIGHTRED, BLACK); - printf("\n%s\n\n", (char *) Language(381)); - colour(WHITE, BLACK); + Enter(1); + pout(LIGHTRED, BLACK, (char *) Language(381)); + Enter(2); /* Please enter a login name (Maximum 8 characters) */ - printf("\n%s\n", (char *) Language(383)); + poutCR(WHITE, BLACK, (char *) Language(383)); /* ie. John Doe, login = jdoe */ - printf("%s\n", (char *) Language(384)); - colour(LIGHTGREEN, BLACK); + poutCR(WHITE, BLACK, (char *) Language(384)); + /* login > */ - printf("%s", (char *) Language(385)); - fflush(stdout); - fflush(stdin); + pout(LIGHTGREEN, BLACK, (char *) Language(385)); GetstrU(sUserName, 7); if (CheckUnixNames(sUserName)) { + Enter(1); /* That login name already exists, please choose another one. */ - colour(LIGHTRED, BLACK); - printf("\n%s\n", (char *) Language(386)); + poutCR(LIGHTRED, BLACK, (char *) Language(386)); Syslog('+', "Users tried to use \"%s\" as Unix name", MBSE_SS(sUserName)); } } @@ -705,8 +699,6 @@ char *NameCreate(char *Name, char *Comment, char *Password) */ sprintf(progname, "%s/bin/mbuseradd", getenv("MBSE_ROOT")); sprintf(gidstr, "%d", getgid()); - fflush(stdout); - fflush(stdin); args[0] = progname; args[1] = gidstr; args[2] = Name; @@ -729,8 +721,6 @@ char *NameCreate(char *Name, char *Comment, char *Password) args[2] = Name; args[3] = Password; args[4] = NULL; - fflush(stdout); - fflush(stdin); if ((err = execute(args, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"))) { WriteError("Failed to set unix password"); @@ -738,9 +728,9 @@ char *NameCreate(char *Name, char *Comment, char *Password) ExitClient(MBERR_GENERAL); } - colour(YELLOW, BLACK); + Enter(1); /* Your "Unix Account" is created, you may use it the next time you call */ - printf("\n%s\n", (char *) Language(382)); + poutCR(YELLOW, BLACK, (char *) Language(382)); Syslog('+', "Created Unix account %s for %s", Name, Comment); free(progname); @@ -770,7 +760,9 @@ int BadNames(char *Username) strcpy(String, tl(String)); Striplf(String); if ((strstr(User, String)) != NULL) { - printf("\nSorry that name is not acceptable on this system\n"); + Enter(1); + pout(LIGHTRED, BLACK, (char *)"Sorry that name is not acceptable on this system"); + Enter(1); Syslog('+', "User tried username \"%s\", found in %s", Username, temp); iFoundName = TRUE; break; diff --git a/mbsebbs/offline.c b/mbsebbs/offline.c index 6fd64259..91f0321c 100644 --- a/mbsebbs/offline.c +++ b/mbsebbs/offline.c @@ -48,6 +48,9 @@ #include "offline.h" #include "whoson.h" #include "term.h" +#include "ttyio.h" +#include "openport.h" + long Total, TotalPersonal, Current, Personal; @@ -100,7 +103,6 @@ void AddArc(char *Temp, char *Pktname) execute_str((char *)archiver.marc, Pktname, Temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); unlink(Temp); printf("."); - fflush(stdout); } @@ -140,14 +142,12 @@ void UpdateLR(msg_high *mhl, FILE *mf) char *p; msg_high *tmp; - colour(YELLOW, BLACK); /* Updating lastread pointer */ - printf("%s\n", (char *)Language(449)); + poutCR(YELLOW, BLACK, (char *)Language(449)); colour(LIGHTMAGENTA, BLACK); for (tmp = mhl; tmp; tmp = tmp->next) { - printf("."); - fflush(stdout); + PUTCHAR('.'); fseek(mf, ((tmp->Area -1) * (msgshdr.recsize + msgshdr.syssize)) + msgshdr.hdrsize, SEEK_SET); fread(&msgs, msgshdr.recsize, 1, mf); if (Msg_Open(msgs.Base)) { @@ -224,7 +224,7 @@ void OLR_TagArea() { char *Msgname, *Tagname; FILE *ma, *tf; - char *buf; + char *buf, msg[81]; long total, Offset, Area; int lines, input, ignore = FALSE, maxlines; @@ -238,22 +238,20 @@ void OLR_TagArea() sprintf(Tagname, "%s/%s/.olrtags", CFG.bbs_usersdir, exitinfo.Name); clear(); - colour(YELLOW, BLACK); /* Tag Offline Reader message areas */ - printf("%s\n", (char *)Language(66)); + poutCR(YELLOW, BLACK, (char *)Language(66)); do { - colour(WHITE, BLACK); + Enter(1); /* Enter the name of the conference, or ? for a list: */ - printf("\n%s", (char *)Language(228)); + pout(WHITE, BLACK, (char *)Language(228)); colour(CFG.InputColourF, CFG.InputColourB); GetstrC(buf, 20); if (buf[0] == '?') { maxlines = lines = exitinfo.iScreenLen - 1; - colour(LIGHTCYAN, BLACK); /* Conference Area Msgs Description */ - printf("%s\n", (char *)Language(229)); + poutCR(LIGHTCYAN, BLACK, (char *)Language(229)); if ((ma = fopen(Msgname, "r")) != NULL) { fread(&msgshdr, sizeof(msgshdr), 1, ma); Area = 0; @@ -267,21 +265,20 @@ void OLR_TagArea() Msg_Close(); } else total = 0; - colour(CYAN, BLACK); if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && (!olrtagrec.Tagged) && strlen(msgs.QWKname)) { if ( (lines != 0) || (ignore) ) { lines--; - printf("%-20.20s %-5ld %-5ld %s\n", msgs.QWKname, Area, total, msgs.Name); + sprintf(msg, "%-20.20s %-5ld %-5ld %s", msgs.QWKname, Area, total, msgs.Name); + poutCR(CYAN, BLACK, msg); } if (lines == 0) { - fflush(stdin); - colour(WHITE, BLACK); /* More (Y/n/=) */ - printf("%s%c\x08", (char *) Language(61),Keystroke(61,0)); - fflush(stdout); + sprintf(msg, "%s%c\x08", (char *) Language(61),Keystroke(61,0)); + pout(WHITE, BLACK, msg); alarm_on(); - input = toupper(Getone()); - printf("%c\r",input); + input = toupper(Readkey()); + PUTCHAR(input); + PUTCHAR('\r'); if ((input == Keystroke(61, 0)) || (input == '\r')) lines = maxlines; @@ -366,7 +363,7 @@ void OLR_TagArea() */ void OLR_UntagArea() { - char *Msgname, *Tagname, *buf; + char *Msgname, *Tagname, *buf, msg[81]; FILE *ma, *tf; long total, Offset, Area; int lines, input, ignore = FALSE, maxlines; @@ -381,22 +378,20 @@ void OLR_UntagArea() sprintf(Tagname, "%s/%s/.olrtags", CFG.bbs_usersdir, exitinfo.Name); clear(); - colour(YELLOW, BLACK); /* Untag Offline Reader message areas */ - printf("%s\n", (char *)Language(256)); + poutCR(YELLOW, BLACK, (char *)Language(256)); do { - colour(WHITE, BLACK); + Enter(1); /* Enter the name of the conference, or ? for a list: */ - printf("\n%s", (char *)Language(228)); + pout(WHITE, BLACK, (char *)Language(228)); colour(CFG.InputColourF, CFG.InputColourB); GetstrC(buf, 20); if (buf[0] == '?') { maxlines = lines = exitinfo.iScreenLen - 1; - colour(LIGHTCYAN, BLACK); /* Conference Area Msgs Description */ - printf("%s\n", (char *)Language(229)); + poutCR(LIGHTCYAN, BLACK, (char *)Language(229)); if ((ma = fopen(Msgname, "r")) != NULL) { fread(&msgshdr, sizeof(msgshdr), 1, ma); Area = 0; @@ -410,21 +405,20 @@ void OLR_UntagArea() Msg_Close(); } else total = 0; - colour(CYAN, BLACK); if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && olrtagrec.Tagged && strlen(msgs.QWKname)) { if ( (lines != 0) || (ignore) ) { lines--; - printf("%-20.20s %-5ld %-5ld %s\n", msgs.QWKname, Area, total, msgs.Name); + sprintf(msg, "%-20.20s %-5ld %-5ld %s", msgs.QWKname, Area, total, msgs.Name); + poutCR(CYAN, BLACK, msg); } if (lines == 0) { - fflush(stdin); - colour(WHITE, BLACK); /* More (Y/n/=) */ - printf("%s%c\x08", (char *) Language(61),Keystroke(61,0)); - fflush(stdout); + sprintf(msg, "%s%c\x08", (char *) Language(61),Keystroke(61,0)); + pout(WHITE, BLACK, msg); alarm_on(); - input = toupper(Getone()); - printf("%c\r",input); + input = toupper(Readkey()); + PUTCHAR(input); + PUTCHAR('\r'); if ((input == Keystroke(61, 0)) || (input == '\r')) lines = maxlines; @@ -485,7 +479,7 @@ void OLR_UntagArea() fread(&olrtagrec, sizeof(olrtagrec), 1, tf); if (olrtagrec.Tagged) { if (msgs.OLR_Forced) { - printf("Area cannot be switched off\n"); + poutCR(LIGHTRED, BLACK, (char *)"Area cannot be switched off"); } else { olrtagrec.Tagged = FALSE; fseek(tf, - sizeof(olrtagrec), SEEK_CUR); @@ -523,11 +517,12 @@ void New_Hdr() /* New or deleted mail areas at */ sprintf(temp, "%s%s", (char *) Language(364), CFG.bbs_name); Center(temp); - free(temp); - printf("\n"); + Enter(1); colour(WHITE, BLUE); /* Area State Type Description */ - printf("%-79s\n", (char *) Language(365)); + sprintf(temp, "%-79s", (char *) Language(365)); + poutCR(WHITE, BLUE, temp); + free(temp); } @@ -535,21 +530,25 @@ void New_Hdr() void New_Area(long); void New_Area(long Area) { - colour(LIGHTCYAN, BLACK); + char msg[81]; + /* New */ - printf("%4ld %s", Area, (char *)Language(391)); + sprintf(msg, "%4ld %s", Area, (char *)Language(391)); + pout(LIGHTCYAN, BLACK, msg); + switch (msgs.Type) { - case LOCALMAIL: printf(Language(392)); /* Local */ + case LOCALMAIL: PUTSTR((char *)Language(392)); /* Local */ break; - case NETMAIL: printf(Language(393)); /* Netmail */ + case NETMAIL: PUTSTR((char *)Language(393)); /* Netmail */ break; case LIST: - case ECHOMAIL: printf(Language(394)); /* Echomail */ + case ECHOMAIL: PUTSTR((char *)Language(394)); /* Echomail */ break; - case NEWS: printf(Language(395)); /* News */ + case NEWS: PUTSTR((char *)Language(395)); /* News */ break; } - printf("%s\n", msgs.Name); + PUTSTR(msgs.Name); + Enter(1); } @@ -557,9 +556,11 @@ void New_Area(long Area) void Old_Area(long); void Old_Area(long Area) { - colour(LIGHTRED, BLACK); + char msg[81]; + /* Del */ - printf("%4ld %s\n", Area, (char *)Language(397)); + sprintf(msg, "%4ld %s", Area, (char *)Language(397)); + poutCR(LIGHTRED, BLACK, msg); } @@ -710,7 +711,7 @@ void OLR_SyncTags() */ void OLR_ViewTags() { - char *Tagname, *Msgname; + char *Tagname, *Msgname, msg[81]; FILE *tf, *ma; long total, Area = 0; int lines, input, ignore = FALSE, maxlines; @@ -739,14 +740,12 @@ void OLR_ViewTags() fread(&msgshdr, sizeof(msgshdr), 1, ma); clear(); - colour(YELLOW, BLACK); /* You have selected the following Conference(s): */ - printf ("%s\n", (char *)Language(260)); - colour(LIGHTCYAN, BLACK); + poutCR(YELLOW, BLACK, (char *)Language(260)); + Enter(1); /* Conference Area Msgs Description */ - printf ("\n%s\n", (char *)Language(229)); + poutCR(LIGHTCYAN, BLACK, (char *)Language(229)); colour(CYAN, BLACK); - fflush(stdout); maxlines = lines = exitinfo.iScreenLen - 1; while (fread(&msgs, msgshdr.recsize, 1, ma) == 1) { @@ -762,17 +761,18 @@ void OLR_ViewTags() total = 0; if ( (lines != 0) || (ignore) ) { lines--; - printf("%-20.20s %-5ld %-5ld %s\n", msgs.QWKname, Area, total, msgs.Name); + sprintf(msg, "%-20.20s %-5ld %-5ld %s", msgs.QWKname, Area, total, msgs.Name); + PUTSTR(msg); + Enter(1); } if (lines == 0) { - fflush(stdin); - colour(WHITE, BLACK); /* More (Y/n/=) */ - printf("%s%c\x08", (char *) Language(61),Keystroke(61,0)); - fflush(stdout); + sprintf(msg, "%s%c\x08", (char *) Language(61),Keystroke(61,0)); + pout(WHITE, BLACK, msg); alarm_on(); - input = toupper(Getone()); - printf("%c\r",input); + input = toupper(Readkey()); + PUTCHAR(input); + PUTCHAR('\r'); if ((input == Keystroke(61, 0)) || (input == '\r')) lines = maxlines; @@ -785,7 +785,6 @@ void OLR_ViewTags() lines = maxlines; colour(CYAN, BLACK); } - fflush(stdout); } } @@ -805,16 +804,15 @@ int OLR_Prescan() { unsigned short RetVal = FALSE, Areas; unsigned long Number; - char *Temp; + char *Temp, msg[81]; FILE *mf, *tf; int x; WhosDoingWhat(OLR, NULL); clear(); - colour(LIGHTMAGENTA, BLACK); /* Offline Reader Download */ - printf("%s\n\n", (char *)Language(277)); - fflush(stdout); + pout(LIGHTMAGENTA, BLACK, (char *)Language(277)); + Enter(2); if (exitinfo.Email) check_popmail(exitinfo.Name, exitinfo.Password); @@ -828,9 +826,10 @@ int OLR_Prescan() tf = fopen(Temp, "r"); Total = TotalPersonal = Areas = 0; + Enter(1); colour(WHITE, BLUE); /* Forum Description Msgs. Pers. */ - printf("\n%s\n", (char *)Language(297)); + poutCR(WHITE, BLUE, (char *)Language(297)); while (fread(&msgs, msgshdr.recsize, 1, mf) == 1) { fseek(mf, msgshdr.syssize, SEEK_CUR); @@ -840,9 +839,8 @@ int OLR_Prescan() if (Msg_Open(msgs.Base)) { Areas++; Current = Personal = 0; - colour(LIGHTCYAN, BLACK); - printf("%-20.20s %-41.41s ", msgs.QWKname, msgs.Name); - fflush(stdout); + sprintf(msg, "%-20.20s %-41.41s ", msgs.QWKname, msgs.Name); + pout(LIGHTCYAN, BLACK, msg); memset(&LR, 0, sizeof(LR)); LR.UserID = grecno; @@ -867,9 +865,8 @@ int OLR_Prescan() } while (Msg_Next(&Number)); } - colour(LIGHTGREEN, BLACK); - printf("%5lu %5lu\n", Current, Personal); - fflush(stdout); + sprintf(msg, "%5lu %5lu", Current, Personal); + poutCR(LIGHTGREEN, BLACK, msg); Msg_Close(); } } @@ -877,27 +874,30 @@ int OLR_Prescan() Syslog('+', "OLR Prescan: %u Areas, %lu Messages", Areas, Total); - colour(LIGHTBLUE, BLACK); + Enter(1); /* Total messages found: */ - printf("\n%s %lu\n\n", (char *)Language(338), Total); + sprintf(msg, "%s %lu", (char *)Language(338), Total); + pout(LIGHTBLUE, BLACK, msg); + Enter(2); + if (Total == 0L) { - colour(YELLOW, BLACK); /* No messages found to download! */ - printf("%s\n\007", (char *)Language(374)); + poutCR(YELLOW, BLACK, (char *)Language(374)); + PUTCHAR('\007'); Pause(); } else { if (CFG.OLR_MaxMsgs != 0 && Total > CFG.OLR_MaxMsgs) { /* Too much messages. Only the first will be packed! */ - printf("%s %d %s\n\n\007", (char *)Language(377), CFG.OLR_MaxMsgs, (char *)Language(411)); + sprintf(msg, "%s %d %s", (char *)Language(377), CFG.OLR_MaxMsgs, (char *)Language(411)); + PUTCHAR('\007'); + Enter(2); Total = CFG.OLR_MaxMsgs; } - colour(CFG.HiliteF, CFG.HiliteB); /* Do you want to download these messages [Y/n]? */ - printf("%s", (char *)Language(425)); - fflush(stdout); + pout(CFG.HiliteF, CFG.HiliteB, (char *)Language(425)); alarm_on(); - x = toupper(Getone()); + x = toupper(Readkey()); if (x != Keystroke(425, 1)) { RetVal = TRUE; @@ -922,13 +922,16 @@ int OLR_Prescan() */ void DrawBar(char *Pktname) { - colour(YELLOW, BLACK); + char msg[81]; + + Enter(1); /* Preparing packet */ - printf("\n%s %s...\n\n", (char *)Language(445), Pktname); - colour(LIGHTGREEN, BLACK); - printf("0%% 10%% 20%% 30%% 40%% 50%% 60%% 70%% 80%% 90%% 100%%\n"); - printf("|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\r"); - fflush(stdout); + sprintf(msg, "%s %s...", (char *)Language(445), Pktname); + pout(YELLOW, BLACK, msg); + Enter(2); + poutCR(LIGHTGREEN, BLACK, (char *)"0%% 10%% 20%% 30%% 40%% 50%% 60%% 70%% 80%% 90%% 100%%"); + PUTSTR((char *)"|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|"); + PUTCHAR('\r'); } @@ -937,7 +940,8 @@ void OLR_RestrictDate() { WhosDoingWhat(OLR, NULL); - printf("Not Yet Implemented\n"); + PUTSTR((char *)"Not Yet Implemented"); + Enter(1); Pause(); } @@ -1006,13 +1010,14 @@ USHORT TOffline::TooOld (ULONG Restrict, class TMsgBase *Msg) */ void OLR_Upload(void) { - char *File, *temp, *Arc, Dirpath[PATH_MAX], Filename[81]; + char *File, *temp, *Arc, Dirpath[PATH_MAX], Filename[81], msg[81]; time_t ElapstimeStart, ElapstimeFin, iTime; int err, Strlen, RetVal = FALSE; FILE *fp; if (strlen(CFG.bbsid) == 0) { - printf("System configuration error, inform sysop\n"); + PUTSTR((char *)"System configuration error, inform sysop"); + Enter(1); WriteError("Config OLR bbsid not configured"); Pause(); return; @@ -1020,9 +1025,8 @@ void OLR_Upload(void) WhosDoingWhat(OLR, NULL); clear(); - colour(LIGHTMAGENTA, BLACK); /* Offline Reader Upload */ - printf("%s\n", (char *)Language(439)); + poutCR(LIGHTMAGENTA, BLACK, (char *)Language(439)); if (!ForceProtocol()) return; @@ -1044,9 +1048,10 @@ void OLR_Upload(void) return; if (File[0] == '.' || File[0] == '*' || File[0] == ' ') { - colour(CFG.HiliteF, CFG.HiliteB); + Enter(1); /* Illegal filename! */ - printf("\n%s\n\n", (char *) Language(247)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); Pause(); return; } @@ -1055,26 +1060,30 @@ void OLR_Upload(void) Strlen--; if (File[Strlen] == '.' || File[Strlen] == '/' || File[Strlen] == ' ') { - colour(CFG.HiliteF, CFG.HiliteB); + Enter(1); /* Illegal Filename! */ - printf("\n%s\n\n", (char *) Language(247)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); Pause(); return; } if (strncasecmp(File, CFG.bbsid, strlen(CFG.bbsid))) { - colour(CFG.HiliteF, CFG.HiliteB); + Enter(1); /* Illegal filename! */ - printf("\n%s\n\n", (char *) Language(247)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247)); + Enter(2); Pause(); return; } Syslog('+', "Filename accepted"); } - colour(CFG.HiliteF, CFG.HiliteB); + Enter(1); /* Please start your upload now */ - printf("\n%s, %s\n\n", sProtAdvice, (char *) Language(283)); + sprintf(msg, "%s, %s", sProtAdvice, (char *) Language(283)); + pout(CFG.HiliteF, CFG.HiliteB, msg); + Enter(2); if (uProtBatch) Syslog('+', "Upload using %s", sProtName); else @@ -1087,8 +1096,6 @@ void OLR_Upload(void) return; } - fflush(stdout); - fflush(stdin); sleep(2); ElapstimeStart = time(NULL); @@ -1097,16 +1104,18 @@ void OLR_Upload(void) */ Altime(7200); alarm_set(7190); - if ((err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL))) { - colour(CFG.HiliteF, CFG.HiliteB); + err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL); + if (rawport() != 0) { + WriteError("Unable to set raw mode"); + } + if (err) { WriteError("$Upload error %d, prot: %s", err, sProtUp); } Altime(0); alarm_off(); alarm_on(); - printf("\n"); - fflush(stdout); - fflush(stdin); + + Enter(1); ElapstimeFin = time(NULL); /* @@ -1136,7 +1145,8 @@ void OLR_Upload(void) if (RetVal == FALSE) { WriteError("Invalid OLR packed received"); /* Invalid packet received */ - printf("%s\n\n", (char *)Language(440)); + pout(LIGHTRED, BLACK, (char *)Language(440)); + Enter(2); sleep(2); return; } @@ -1146,7 +1156,7 @@ void OLR_Upload(void) if ((Arc = GetFileType(File)) == NULL) { /* Unknown compression type */ - printf("%s\n", (char *)Language(441)); + poutCR(LIGHTRED, BLACK, (char *)Language(441)); Syslog('+', "Unknown compression type"); Pause(); return; @@ -1169,7 +1179,7 @@ void OLR_Upload(void) if (strcmp(Arc, archiver.name) || (!archiver.available)) { Syslog('+', "Archiver %s not available", Arc); /* Archiver not available */ - printf("%s\n", (char *)Language(442)); + poutCR(LIGHTRED, BLACK, (char *)Language(442)); Pause(); return; } @@ -1178,24 +1188,27 @@ void OLR_Upload(void) colour(CFG.TextColourF, CFG.TextColourB); /* Unpacking archive */ - printf("%s ", (char *) Language(201)); - fflush(stdout); + pout(CFG.TextColourF, CFG.TextColourB, (char *) Language(201)); + PUTCHAR(' '); sprintf(temp, "%s %s", archiver.funarc, File); Syslog('m', "Unarc %s", temp); colour(CFG.HiliteF, CFG.HiliteB); - if ((err = execute_str(archiver.funarc, File, NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"))) { + err = execute_str(archiver.funarc, File, NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); + if (rawport() != 0) { + WriteError("Unable to set raw mode"); + } + if (err) { WriteError("$Failed %s", temp); /* ERROR */ - printf("%s\n", (char *) Language(217)); - fflush(stdout); + poutCR(LIGHTRED, BLACK, (char *) Language(217)); Pause(); return; } /* Ok */ - printf("%s\n", (char *) Language(200)); - fflush(stdout); + PUTSTR((char *) Language(200)); + Enter(1); unlink(File); /* @@ -1244,7 +1257,7 @@ void OLR_Upload(void) WriteError("OLR_Upload: Garbage in mailpacket, clean directory!"); /* Unknown type mailpacket */ - printf("%s\n", (char *)Language(443)); + poutCR(LIGHTRED, BLACK, (char *)Language(443)); Pause(); free(File); free(temp); @@ -1281,7 +1294,8 @@ void OLR_DownBW() msg_high *mhl = NULL; if (strlen(CFG.bbsid) == 0) { - printf("System configuration error, inform sysop\n"); + PUTSTR((char *)"System configuration error, inform sysop"); + Enter(1); WriteError("Config OLR bbsid not configured"); Pause(); return; @@ -1292,9 +1306,8 @@ void OLR_DownBW() Total = TotalPersonal = 0; clear(); - colour(LIGHTBLUE, BLACK); /* BlueWave Offline download */ - printf("%s\n", (char *)Language(444)); + poutCR(LIGHTBLUE, BLACK, (char *)Language(444)); Work = calloc(PATH_MAX, sizeof(char)); Temp = calloc(PATH_MAX, sizeof(char)); @@ -1476,14 +1489,17 @@ void OLR_DownBW() if (Total) { /* Packing with */ - printf("\n%s ", (char *)Language(446)); + Enter(1); + PUTSTR((char *)Language(446)); + PUTCHAR(' '); sprintf(Temp, "%s/etc/archiver.data", getenv("MBSE_ROOT")); if ((af = fopen(Temp, "r")) != NULL) { fread(&archiverhdr, sizeof(archiverhdr), 1, af); while (fread(&archiver, archiverhdr.recsize, 1, af) == 1) { if (archiver.available && (!strcmp(archiver.name, exitinfo.Archiver))) { Syslog('+', "Archiver %s", archiver.comment); - printf("%s ", archiver.comment); + PUTSTR(archiver.comment); + PUTCHAR(' '); sprintf(Temp, "%s/%s.DAT", Work, CFG.bbsid); AddArc(Temp, Pktname); alarm_on(); @@ -1503,15 +1519,15 @@ void OLR_DownBW() } } - colour(CFG.HiliteF, CFG.HiliteB); if (rc == FALSE) { Syslog('+', "BlueWave download failed"); /* Download failed */ - printf("%s", (char *)Language(447)); + poutCR(CFG.HiliteF, CFG.HiliteB, (char *)Language(447)); } else { Syslog('+', "BlueWave download successfull"); + PUTCHAR('\r'); /* Download successfull */ - printf("\r%s\n", (char *)Language(448)); + poutCR(CFG.HiliteF, CFG.HiliteB, (char *)Language(448)); if (mhl != NULL) UpdateLR(mhl, mf); @@ -1522,7 +1538,7 @@ void OLR_DownBW() free(Temp); free(Work); - printf("\n\n"); + Enter(2); Pause(); } @@ -1543,9 +1559,8 @@ void BlueWave_Fetch() time_t now; struct tm *tm; - colour(LIGHTBLUE, BLACK); /* Processing BlueWave reply packet */ - printf("%s\n", (char *)Language(450)); + poutCR(LIGHTBLUE, BLACK, (char *)Language(450)); temp = calloc(PATH_MAX, sizeof(char)); b = calloc(256, sizeof(char)); buffer = b; @@ -1568,7 +1583,7 @@ void BlueWave_Fetch() fclose(up); free(temp); /* ERROR in packet */ - printf("%s\n", (char *)Language(451)); + poutCR(LIGHTRED, BLACK, (char *)Language(451)); Pause(); return; } @@ -1581,15 +1596,14 @@ void BlueWave_Fetch() colour(CFG.TextColourF, CFG.TextColourB); /* Import messages */ - printf("%s ", (char *)Language(452)); + pout(CFG.TextColourF, CFG.TextColourB, (char *)Language(452)); + PUTCHAR(' '); colour(CFG.HiliteF, CFG.HiliteB); - fflush(stdout); i = 0; memset(&Upr, 0, sizeof(UPL_REC)); while (fread(&Upr, Uph.upl_rec_len, 1, up) == 1) { - printf("."); - fflush(stdout); + PUTCHAR('.'); Syslog('m', " From : %s", Upr.from); Syslog('m', " To : %s", Upr.to); Syslog('m', " Subj : %s", Upr.subj); @@ -1692,8 +1706,10 @@ void BlueWave_Fetch() Close_Msgbase(msgs.Base); } } else { + Enter(1); /* No Write access to area */ - printf("\n%s %s\n", (char *)Language(453), msgs.Name); + sprintf(temp, "%s %s", (char *)Language(453), msgs.Name); + poutCR(LIGHTRED, BLACK, temp); WriteError("No Write Access to area %s", msgs.Name); } } @@ -1701,17 +1717,16 @@ void BlueWave_Fetch() } memset(&Upr, 0, sizeof(UPL_REC)); } - printf("\n"); - colour(CFG.TextColourF, CFG.TextColourB); + Enter(1); if (i) { /* Messages imported */ - printf("%d %s\n", i, (char *)Language(454)); + sprintf(temp, "%d %s", i, (char *)Language(454)); + poutCR(CFG.TextColourF, CFG.TextColourB, temp); ReadExitinfo(); exitinfo.iPosted += i; WriteExitinfo(); do_mailout = TRUE; } - fflush(stdout); fclose(up); sprintf(temp, "%s/%s", Dirpath, Filename); unlink(temp); @@ -1731,9 +1746,8 @@ void BlueWave_Fetch() iol = fopen(temp, "r"); } if (iol != NULL) { - colour(LIGHTBLUE, BLACK); /* Processing Offline Configuration */ - printf("%s\n", (char *)Language(455)); + poutCR(LIGHTBLUE, BLACK, (char *)Language(455)); Syslog('+', "Processing BlueWave v3 configuration file \"%s\"", Filename); OLC_head = FALSE; @@ -1869,9 +1883,9 @@ void BlueWave_Fetch() fclose(iol); sprintf(temp, "%s/%s", Dirpath, Filename); unlink(temp); - colour(CYAN, BLACK); /* Message areas selected */ - printf("%d %s\n", i, (char *)Language(456)); + sprintf(temp, "%d %s", i, (char *)Language(456)); + poutCR(CYAN, BLACK, temp); Syslog('+', " %d active message areas.", i); } @@ -1891,12 +1905,11 @@ void BlueWave_Fetch() while (fread(&Req, sizeof(REQ_REC), 1, tp) == 1) { Syslog('m', " File %s", Req.filename); - colour(CFG.TextColourF, CFG.TextColourB); - printf("%-12s ", Req.filename); + sprintf(temp, "%-12s ", Req.filename); + pout(CFG.TextColourF, CFG.TextColourB, temp); colour(CFG.HiliteF, CFG.HiliteB); - fflush(stdout); - printf("\n"); + Enter(1); } fclose(tp); @@ -1915,7 +1928,7 @@ void BlueWave_Fetch() unsigned long BlueWave_PackArea(unsigned long ulLast, long Area) { FILE *fdm, *fdfti, *fdmix; - char *Temp, *Text; + char *Temp, *Text, msg[81]; unsigned long Number; MIX_REC Mix; FTI_REC Fti; @@ -1998,9 +2011,8 @@ unsigned long BlueWave_PackArea(unsigned long ulLast, long Area) if (BarWidth != (unsigned short)((Total * 61L) / TotalPack)) { BarWidth = (unsigned short)((Total * 61L) / TotalPack); - colour(CYAN, BLACK); - printf("\r%.*s", BarWidth, "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"); - fflush(stdout); + sprintf(msg, "\r%.*s", BarWidth, "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"); + pout(CYAN, BLACK, msg); } } while (Msg_Next(&Number)); } @@ -2044,7 +2056,7 @@ void OLR_DownQWK(void) msg_high *tmp, *mhl = NULL; if (strlen(CFG.bbsid) == 0) { - printf("System configuration error, inform sysop\n"); + poutCR(LIGHTRED, BLACK, (char *)"System configuration error, inform sysop"); WriteError("Config OLR bbsid not configured"); Pause(); return; @@ -2055,9 +2067,8 @@ void OLR_DownQWK(void) Total = TotalPersonal = 0L; clear(); - colour(LIGHTBLUE, BLACK); /* QWK Offline Download */ - printf("%s\n", (char *)Language(458)); + poutCR(LIGHTBLUE, BLACK, (char *)Language(458)); Work = calloc(PATH_MAX, sizeof(char)); Temp = calloc(PATH_MAX, sizeof(char)); @@ -2199,15 +2210,18 @@ void OLR_DownQWK(void) fclose(tf); if (Total) { + Enter(1); /* Packing with */ - printf("\n%s ", (char *)Language(446)); + PUTSTR((char *)Language(446)); + PUTCHAR(' '); sprintf(Temp, "%s/etc/archiver.data", getenv("MBSE_ROOT")); if ((af = fopen(Temp, "r")) != NULL) { fread(&archiverhdr, sizeof(archiverhdr), 1, af); while (fread(&archiver, archiverhdr.recsize, 1, af) == 1) { if (archiver.available && (!strcmp(archiver.name, exitinfo.Archiver))) { Syslog('+', "Archiver %s", archiver.comment); - printf("%s ", archiver.comment); + PUTSTR(archiver.comment); + PUTCHAR(' '); sprintf(Temp, "%s/CONTROL.DAT", Work); AddArc(Temp, Pktname); alarm_on(); @@ -2237,15 +2251,15 @@ void OLR_DownQWK(void) } } - colour(CFG.HiliteF, CFG.HiliteB); if (rc == FALSE) { Syslog('+', "QWK download failed"); /* Download failed */ - printf("%s", (char *)Language(447)); + pout(CFG.HiliteF, CFG.HiliteB, (char *)Language(447)); } else { Syslog('+', "QWK download successfull"); + PUTCHAR('\r'); /* Download successfull */ - printf("\r%s\n", (char *)Language(448)); + poutCR(CFG.HiliteF, CFG.HiliteB, (char *)Language(448)); if (mhl != NULL) UpdateLR(mhl, mf); @@ -2255,7 +2269,7 @@ void OLR_DownQWK(void) free(Temp); free(Work); - printf("\n\n"); + Enter(2); Pause(); } @@ -2274,9 +2288,8 @@ void QWK_Fetch() fidoaddr dest; int HasTear; - colour(LIGHTBLUE, BLACK); /* Processing BlueWave reply packet */ - printf("%s\n", (char *)Language(459)); + poutCR(LIGHTBLUE, BLACK, (char *)Language(459)); temp = calloc(PATH_MAX, sizeof(char)); otemp = calloc(PATH_MAX, sizeof(char)); nWidth = 78; @@ -2298,7 +2311,7 @@ void QWK_Fetch() fclose(up); unlink(temp); /* ERROR in packet */ - printf("%s\n", (char *)Language(451)); + poutCR(LIGHTRED, BLACK, (char *)Language(451)); free(temp); free(otemp); Pause(); @@ -2509,17 +2522,16 @@ void QWK_Fetch() fclose(up); } - printf("\n"); - colour(CFG.TextColourF, CFG.TextColourB); + Enter(1); if (nPosted) { /* Messages imported */ - printf("%d %s\n", nPosted, (char *)Language(454)); + sprintf(temp, "%d %s", nPosted, (char *)Language(454)); + poutCR(CFG.TextColourF, CFG.TextColourB, temp); ReadExitinfo(); exitinfo.iPosted += nPosted; WriteExitinfo(); do_mailout = TRUE; } - fflush(stdout); sprintf(temp, "%s/%s", Dirpath, Filename); Syslog('m', "Unlink %s rc=%d", temp, unlink(temp)); free(temp); @@ -2575,7 +2587,7 @@ unsigned long QWK_PackArea(unsigned long ulLast, long Area) { FILE *fdm, *fdi, *fdp; float out, in; - char *Work, *Temp, *Text; + char *Work, *Temp, *Text, msg[81]; unsigned long Number, Pos, Size, Blocks; int Pack = FALSE; struct tm *tp; @@ -2695,9 +2707,9 @@ unsigned long QWK_PackArea(unsigned long ulLast, long Area) if (BarWidth != (unsigned short)((Total * 61L) / TotalPack)) { BarWidth = (unsigned short)((Total * 61L) / TotalPack); - colour(CYAN, BLACK); - printf("\r%.*s", BarWidth, "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"); - fflush(stdout); + PUTCHAR('\r'); + sprintf(msg, "%.*s", BarWidth, "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"); + pout(CYAN, BLACK, msg); } } } while (Msg_Next(&Number)); @@ -2754,7 +2766,7 @@ void OLR_DownASCII(void) msg_high *tmp, *mhl = NULL; if (strlen(CFG.bbsid) == 0) { - printf("System configuration error, inform sysop\n"); + poutCR(LIGHTRED, BLACK, (char *)"System configuration error, inform sysop"); WriteError("Config OLR bbsid not configured"); Pause(); return; @@ -2765,9 +2777,8 @@ void OLR_DownASCII(void) Total = TotalPersonal = 0L; clear(); - colour(LIGHTBLUE, BLACK); /* ASCII Offline Download */ - printf("%s\n", (char *)Language(460)); + poutCR(LIGHTBLUE, BLACK, (char *)Language(460)); Work = calloc(PATH_MAX, sizeof(char)); Temp = calloc(PATH_MAX, sizeof(char)); @@ -2829,15 +2840,18 @@ void OLR_DownASCII(void) } if (Total) { + Enter(1); /* Packing with */ - printf("\n%s ", (char *)Language(446)); + PUTSTR((char *)Language(446)); + PUTCHAR(' '); sprintf(Temp, "%s/etc/archiver.data", getenv("MBSE_ROOT")); if ((af = fopen(Temp, "r")) != NULL) { fread(&archiverhdr, sizeof(archiverhdr), 1, af); while (fread(&archiver, archiverhdr.recsize, 1, af) == 1) { if (archiver.available && (!strcmp(archiver.name, exitinfo.Archiver))) { Syslog('+', "Archiver %s", archiver.comment); - printf("%s ", archiver.comment); + PUTSTR(archiver.comment); + PUTCHAR(' '); alarm_on(); for (tmp = mhl; tmp; tmp = tmp->next) { @@ -2853,15 +2867,15 @@ void OLR_DownASCII(void) } } - colour(CFG.HiliteF, CFG.HiliteB); if (rc == FALSE) { Syslog('+', "ASCII download failed"); /* Download failed */ - printf("%s", (char *)Language(447)); + pout(CFG.HiliteF, CFG.HiliteB, (char *)Language(447)); } else { Syslog('+', "ASCII download successfull"); + PUTCHAR('\r'); /* Download successfull */ - printf("\r%s\n", (char *)Language(448)); + poutCR(CFG.HiliteF, CFG.HiliteB, (char *)Language(448)); if (mhl != NULL) UpdateLR(mhl, mf); @@ -2870,7 +2884,7 @@ void OLR_DownASCII(void) tidy_high(&mhl); free(Temp); free(Work); - printf("\n\n"); + Enter(2); Pause(); } @@ -2882,7 +2896,7 @@ void OLR_DownASCII(void) unsigned long ASCII_PackArea(unsigned long ulLast, long Area) { FILE *fp; - char *Work, *Temp, *Text; + char *Work, *Temp, *Text, msg[81]; unsigned long Number; int Pack = FALSE; struct tm *tp; @@ -2938,9 +2952,9 @@ unsigned long ASCII_PackArea(unsigned long ulLast, long Area) if (BarWidth != (unsigned short)((Total * 61L) / TotalPack)) { BarWidth = (unsigned short)((Total * 61L) / TotalPack); - colour(CYAN, BLACK); - printf("\r%.*s", BarWidth, "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"); - fflush(stdout); + PUTCHAR('\r'); + sprintf(msg, "%.*s", BarWidth, "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"); + pout(CYAN, BLACK, msg); } } } while (Msg_Next(&Number)); diff --git a/mbsebbs/oneline.c b/mbsebbs/oneline.c index 868ab967..821febf9 100644 --- a/mbsebbs/oneline.c +++ b/mbsebbs/oneline.c @@ -37,6 +37,7 @@ #include "input.h" #include "language.h" #include "term.h" +#include "ttyio.h" char sOneliner[81]; @@ -71,66 +72,64 @@ void Oneliner_Check() void Oneliner_Add() { - FILE *pOneline; - char *sFileName; - int x; - char temp[81]; + FILE *pOneline; + char *sFileName; + int x; + char temp[81]; - Oneliner_Check(); + Oneliner_Check(); - sFileName = calloc(128, sizeof(char)); - sprintf(sFileName,"%s/etc/oneline.data", getenv("MBSE_ROOT")); + sFileName = calloc(PATH_MAX, sizeof(char)); + sprintf(sFileName,"%s/etc/oneline.data", getenv("MBSE_ROOT")); - if((pOneline = fopen(sFileName, "a+")) == NULL) { - WriteError("Can't open file: %s", sFileName); - return; - } - free(sFileName); + if ((pOneline = fopen(sFileName, "a+")) == NULL) { + WriteError("Can't open file: %s", sFileName); + return; + } + free(sFileName); - memset(&ol, 0, sizeof(ol)); - clear(); - /* MBSE BBS Oneliners will randomly appear on the main menu. */ - poutCR(15, 0, Language(341)); - Enter(1); + memset(&ol, 0, sizeof(ol)); + clear(); + /* MBSE BBS Oneliners will randomly appear on the main menu. */ + poutCR(WHITE, BLACK, Language(341)); + Enter(1); - /* Obscene or libellous oneliners will be deleted!! */ - poutCR(15, 1, Language(342)); - Enter(1); + /* Obscene or libellous oneliners will be deleted!! */ + poutCR(WHITE, BLUE, Language(342)); + Enter(1); - /* Please enter your oneliner below. You have 75 characters.*/ - pout(12, 0, Language(343)); - Enter(1); - pout(15, 0, (char *)"> "); - colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); - GetstrC(temp, 75); + /* Please enter your oneliner below. You have 75 characters.*/ + poutCR(LIGHTRED, BLACK, Language(343)); + pout(WHITE, BLACK, (char *)"> "); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(temp, 75); - if((strcmp(temp, "")) == 0) { - fclose(pOneline); - return; - } else { - x = strlen(temp); - if(x >= 78) - temp[78] = '\0'; - - strcpy(ol.Oneline, temp); - } - - Enter(1); - /* Oneliner added */ - pout(3, 0, Language(344)); - Enter(2); - Pause(); - - Syslog('!', "User added oneliner:"); - Syslog('!', ol.Oneline); - - sprintf(ol.UserName,"%s", exitinfo.sUserName); - sprintf(ol.DateOfEntry,"%02d-%02d-%04d",l_date->tm_mday,l_date->tm_mon+1,l_date->tm_year+1900); - ol.Available = TRUE; - - fwrite(&ol, sizeof(ol), 1, pOneline); + if ((strcmp(temp, "")) == 0) { fclose(pOneline); + return; + } else { + x = strlen(temp); + if (x >= 78) + temp[78] = '\0'; + + strcpy(ol.Oneline, temp); + } + + Enter(1); + /* Oneliner added */ + pout(CYAN, BLACK, Language(344)); + Enter(2); + Pause(); + + Syslog('!', "User added oneliner:"); + Syslog('!', ol.Oneline); + + sprintf(ol.UserName,"%s", exitinfo.sUserName); + sprintf(ol.DateOfEntry,"%02d-%02d-%04d",l_date->tm_mday,l_date->tm_mon+1,l_date->tm_year+1900); + ol.Available = TRUE; + + fwrite(&ol, sizeof(ol), 1, pOneline); + fclose(pOneline); } @@ -141,43 +140,43 @@ void Oneliner_Add() */ void Oneliner_Print() { - int i, x, z; - int Strlen; - int Maxlen = 80; - char sNewOneliner[81] = ""; + int i, x, z, Strlen, Maxlen = 80; + char sNewOneliner[81] = ""; - /* - * Select a new colour - */ - if (iColour < 8) - iColour = 8; + /* + * Select a new colour + */ + if (iColour < 8) + iColour = 8; + else + if (iColour == 15) + iColour = 8; else - if (iColour == 15) - iColour = 8; - else - iColour++; + iColour++; - /* - * Get a random oneliner - */ - strcpy(sOneliner, Oneliner_Get()); + /* + * Get a random oneliner + */ + strcpy(sOneliner, Oneliner_Get()); - /* - * Now display it on screen - */ - Strlen = strlen(sOneliner); + /* + * Now display it on screen + */ + Strlen = strlen(sOneliner); - if(Strlen == Maxlen) - printf("%s\n", sOneliner); - else { - x = Maxlen - Strlen; - z = x / 2; - for(i = 0; i < z; i++) - strcat(sNewOneliner," "); - strcat(sNewOneliner, sOneliner); - colour(iColour, 0); - printf("%s\n", sNewOneliner); - } + if (Strlen == Maxlen) { + PUTSTR(sOneliner); + Enter(1); + } else { + x = Maxlen - Strlen; + z = x / 2; + for(i = 0; i < z; i++) + strcat(sNewOneliner," "); + strcat(sNewOneliner, sOneliner); + colour(iColour, 0); + PUTSTR(sNewOneliner); + Enter(1); + } } @@ -187,57 +186,56 @@ void Oneliner_Print() */ char *Oneliner_Get() { - FILE *pOneline; - int i, j, in, id; - int recno = 0; - long offset; - int nrecno; - char *sFileName; - static char temp[81]; + FILE *pOneline; + int i, j, in, id, recno = 0; + long offset; + int nrecno; + char *sFileName; + static char temp[81]; - /* - * Get a random oneliner - */ - sFileName = calloc(128, sizeof(char)); - sprintf(sFileName,"%s/etc/oneline.data", getenv("MBSE_ROOT")); + /* + * Get a random oneliner + */ + sFileName = calloc(128, sizeof(char)); + sprintf(sFileName,"%s/etc/oneline.data", getenv("MBSE_ROOT")); - if((pOneline = fopen(sFileName, "r+")) == NULL) { - WriteError("Can't open file: %s", sFileName); - return '\0'; - } - fread(&olhdr, sizeof(olhdr), 1, pOneline); + if ((pOneline = fopen(sFileName, "r+")) == NULL) { + WriteError("Can't open file: %s", sFileName); + return '\0'; + } + fread(&olhdr, sizeof(olhdr), 1, pOneline); - while (fread(&ol, olhdr.recsize, 1, pOneline) == 1) { - recno++; - } - nrecno = recno; - fseek(pOneline, olhdr.hdrsize, 0); + while (fread(&ol, olhdr.recsize, 1, pOneline) == 1) { + recno++; + } + nrecno = recno; + fseek(pOneline, olhdr.hdrsize, 0); - /* - * Generate random record number - */ - while (TRUE) { - in = nrecno; - id = getpid(); + /* + * Generate random record number + */ + while (TRUE) { + in = nrecno; + id = getpid(); - i = rand(); - j = i % id; - if ((j <= in)) - break; - } + i = rand(); + j = i % id; + if ((j <= in)) + break; + } - offset = olhdr.hdrsize + (j * olhdr.recsize); - if (fseek(pOneline, offset, 0) != 0) { - WriteError("Can't move pointer in %s", sFileName); - return '\0'; - } + offset = olhdr.hdrsize + (j * olhdr.recsize); + if (fseek(pOneline, offset, 0) != 0) { + WriteError("Can't move pointer in %s", sFileName); + return '\0'; + } - fread(&ol, olhdr.recsize, 1, pOneline); - memset(&temp, 0, sizeof(temp)); - strcpy(temp, ol.Oneline); - fclose(pOneline); - free(sFileName); - return temp; + fread(&ol, olhdr.recsize, 1, pOneline); + memset(&temp, 0, sizeof(temp)); + strcpy(temp, ol.Oneline); + fclose(pOneline); + free(sFileName); + return temp; } @@ -247,203 +245,200 @@ char *Oneliner_Get() */ void Oneliner_List() { - FILE *pOneline; - int recno = 0; - int Colour = 1; - char *sFileName; + FILE *pOneline; + int recno = 0, Colour = 1; + char *sFileName, msg[81]; - clear(); - sFileName = calloc(128, sizeof(char)); - sprintf(sFileName,"%s/etc/oneline.data", getenv("MBSE_ROOT")); + clear(); + sFileName = calloc(PATH_MAX, sizeof(char)); + sprintf(sFileName,"%s/etc/oneline.data", getenv("MBSE_ROOT")); - if((pOneline = fopen(sFileName, "r+")) == NULL) { - WriteError("Can't open file: %s", sFileName); - return; - } - fread(&olhdr, sizeof(olhdr), 1, pOneline); + if ((pOneline = fopen(sFileName, "r+")) == NULL) { + WriteError("Can't open file: %s", sFileName); + return; + } + fread(&olhdr, sizeof(olhdr), 1, pOneline); - if((SYSOP == TRUE) || (exitinfo.Security.level >= CFG.sysop_access)) { - /* # A Date User Description */ - pout(10, 0, Language(345)); - Enter(1); + if ((SYSOP == TRUE) || (exitinfo.Security.level >= CFG.sysop_access)) { + /* # A Date User Description */ + pout(LIGHTGREEN, BLACK, Language(345)); + } else { + /* # Description */ + pout(LIGHTGREEN, BLACK, Language(346)); + } + Enter(1); + colour(GREEN, BLACK); + sLine(); + + while (fread(&ol, olhdr.recsize, 1, pOneline) == 1) { + if ((SYSOP == TRUE) || (exitinfo.Security.level >= CFG.sysop_access)) { + sprintf(msg, "%2d", recno); + pout(WHITE, BLACK, msg); + + sprintf(msg, "%2d ", ol.Available); + pout(LIGHTBLUE, BLACK, msg); + + pout(LIGHTCYAN, BLACK, ol.DateOfEntry); + + sprintf(msg, "%-15s ", ol.UserName); + pout(CYAN, BLACK, msg); + + sprintf(msg, "%-.48s", ol.Oneline); + poutCR(Colour, BLACK, msg); } else { - /* # Description */ - pout(10, 0, Language(346)); - Enter(1); + sprintf(msg, "%2d ", recno); + pout(WHITE, BLACK, msg); + sprintf(msg, "%-.76s", ol.Oneline); + poutCR(Colour, BLACK, msg); } - colour(2, 0); - sLine(); - while (fread(&ol, olhdr.recsize, 1, pOneline) == 1) { - if((SYSOP == TRUE) || (exitinfo.Security.level >= CFG.sysop_access)) { - colour(15, 0); - printf("%2d", recno); - - colour(9, 0); - printf("%2d ", ol.Available); - - colour(11, 0); - printf("%s ", ol.DateOfEntry); - - colour(3, 0); - printf("%-15s ", ol.UserName); - - colour(Colour, 0); - printf("%-.48s\n", ol.Oneline); - } else { - colour(15, 0); - printf("%2d ", recno); - colour(Colour, 0); - printf("%-.76s\n", ol.Oneline); - } - - recno++; - Colour++; - if(Colour >= 16) - Colour = 1; - } - fclose(pOneline); - printf("\n"); - Pause(); - free(sFileName); + recno++; + Colour++; + if (Colour >= 16) + Colour = 1; + } + fclose(pOneline); + Enter(1); + Pause(); + free(sFileName); } void Oneliner_Show() { - FILE *pOneline; - int recno = 0; - long offset; - char *sFileName; + FILE *pOneline; + int recno = 0; + long offset; + char *sFileName, msg[11]; - sFileName = calloc(128, sizeof(char)); - sprintf(sFileName,"%s/etc/oneline.data", getenv("MBSE_ROOT")); + sFileName = calloc(PATH_MAX, sizeof(char)); + sprintf(sFileName,"%s/etc/oneline.data", getenv("MBSE_ROOT")); - if((pOneline = fopen(sFileName, "r+")) == NULL) { - WriteError("Can't open file: %s", sFileName); - return; - } - fread(&olhdr, sizeof(olhdr), 1, pOneline); + if ((pOneline = fopen(sFileName, "r+")) == NULL) { + WriteError("Can't open file: %s", sFileName); + return; + } + fread(&olhdr, sizeof(olhdr), 1, pOneline); - Enter(1); - /* Please enter number to list: */ - pout(15, 0, Language(347)); - colour(CFG.InputColourF, CFG.InputColourB); - scanf("%d", &recno); + Enter(1); + /* Please enter number to list: */ + pout(WHITE, BLACK, Language(347)); + colour(CFG.InputColourF, CFG.InputColourB); + scanf("%d", &recno); - offset = olhdr.hdrsize + (recno * olhdr.recsize); - if (fseek(pOneline, offset, 0) != 0) - WriteError("Can't move pointer in %s",sFileName); + offset = olhdr.hdrsize + (recno * olhdr.recsize); + if (fseek(pOneline, offset, 0) != 0) + WriteError("Can't move pointer in %s",sFileName); - fread(&ol, olhdr.recsize, 1, pOneline); + fread(&ol, olhdr.recsize, 1, pOneline); - colour(15, 0); - printf("\n%d ", recno); - colour(12, 0); - printf("%s\n\n", ol.Oneline); + Enter(1); + sprintf(msg, "%d ", recno); + pout(WHITE, BLACK, msg); + pout(LIGHTRED, BLACK, ol.Oneline); + Enter(2); - Pause(); - fclose(pOneline); - free(sFileName); + Pause(); + fclose(pOneline); + free(sFileName); } void Oneliner_Delete() { - FILE *pOneline; - int recno = 0; - long offset; - int nrecno = 0; - char srecno[7]; - char *sFileName; - char stemp[50]; - char sUser[35]; + FILE *pOneline; + int recno = 0, nrecno = 0; + long offset; + char srecno[7], *sFileName, stemp[50], sUser[36], msg[81]; - sFileName = calloc(128, sizeof(char)); - sprintf(sFileName,"%s/etc/oneline.data", getenv("MBSE_ROOT")); + sFileName = calloc(PATH_MAX, sizeof(char)); + sprintf(sFileName,"%s/etc/oneline.data", getenv("MBSE_ROOT")); - if((pOneline = fopen(sFileName, "r+")) == NULL) { - WriteError("Can't open file: %s", sFileName); - return; + if ((pOneline = fopen(sFileName, "r+")) == NULL) { + WriteError("Can't open file: %s", sFileName); + return; + } + fread(&olhdr, sizeof(olhdr), 1, pOneline); + + Enter(1); + /* Please enter number to delete: */ + pout(WHITE, BLACK, Language(331)); + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(srecno, 6); + + if ((strcmp(srecno,"")) == 0) { + fclose(pOneline); + return; + } + + recno = atoi(srecno); + + nrecno = recno; + recno = 0; + + while (fread(&ol, olhdr.recsize, 1, pOneline) == 1) { + recno++; + } + + if (nrecno >= recno) { + Enter(1); + /* Record does not exist */ + pout(LIGHTRED, BLACK, Language(319)); + Enter(2); + fclose(pOneline); + Pause(); + } else { + offset = olhdr.hdrsize + (nrecno * olhdr.recsize); + if (fseek(pOneline, offset, 0) != 0) { + WriteError("Can't move pointer in %s",sFileName); + } + + fread(&ol, olhdr.recsize, 1, pOneline); + + /* Convert Record Int to string, so we can print to logfiles */ + sprintf(stemp,"%d", nrecno); + + /* Print UserName to String, so we can compare for deletion */ + sprintf(sUser,"%s", exitinfo.sUserName); + + if ((strcmp(sUser, ol.UserName)) != 0) { + if ((!SYSOP) && (exitinfo.Security.level < CFG.sysop_access)) { + Enter(1); + /* Record *//* does not belong to you.*/ + sprintf(msg, "%s%s %s", (char *) Language(332), stemp, (char *) Language(333)); + pout(LIGHTRED, BLACK, msg); + Enter(2); + Syslog('!', "User tried to delete somebody else's record: %s", stemp); + Pause(); + fclose(pOneline); + return; + } } - fread(&olhdr, sizeof(olhdr), 1, pOneline); Enter(1); - /* Please enter number to delete: */ - pout(15, 0, Language(331)); - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(srecno, 6); - - if((strcmp(srecno,"")) == 0) { - fclose(pOneline); - return; - } - - recno = atoi(srecno); - - nrecno = recno; - recno = 0; - - while (fread(&ol, olhdr.recsize, 1, pOneline) == 1) { - recno++; - } - - if(nrecno >= recno) { - Enter(1); - /* Record does not exist */ - pout(12, 0, Language(319)); - Enter(2); - fclose(pOneline); - Pause(); + if ((ol.Available ) == FALSE) { + /* Record: %d already marked for deletion */ + sprintf(msg, "%s%d %s", (char *) Language(332), nrecno, (char *) Language(334)); + pout(LIGHTRED, BLACK, msg); + Syslog('!', "User tried to mark an already marked record: %s", stemp); } else { - offset = olhdr.hdrsize + (nrecno * olhdr.recsize); - if (fseek(pOneline, offset, 0) != 0) { - WriteError("Can't move pointer in %s",sFileName); - } - - fread(&ol, olhdr.recsize, 1, pOneline); - - /* Convert Record Int to string, so we can print to logfiles */ - sprintf(stemp,"%d", nrecno); - - /* Print UserName to String, so we can compare for deletion */ - sprintf(sUser,"%s", exitinfo.sUserName); - - if((strcmp(sUser, ol.UserName)) != 0) { - if((!SYSOP) && (exitinfo.Security.level < CFG.sysop_access)) { - colour(12, 0); - /* Record *//* does not belong to you.*/ - printf("\n%s%s %s\n\n", (char *) Language(332), stemp, (char *) Language(333)); - Syslog('!', "User tried to delete somebody else's record: %s", stemp); - Pause(); - fclose(pOneline); - return; - } - } - - if ((ol.Available ) == FALSE) { - colour(12, 0); - /* Record: %d already marked for deletion */ - printf("\n%s%d %s\n\n", (char *) Language(332), nrecno, (char *) Language(334)); - Syslog('!', "User tried to mark an already marked record: %s", stemp); - Pause(); - } else { - ol.Available = FALSE; - colour(10, 0); - /* Record *//* marked for deletion */ - printf("\n%s%d %s\n\n", (char *) Language(332), nrecno, (char *) Language(334)); - Syslog('+', "User marked oneliner record for deletion: %s", stemp); - Pause(); - } - - if (fseek(pOneline, offset, 0) != 0) - WriteError("Can't move pointer in %s",sFileName); - fwrite(&ol, olhdr.recsize, 1, pOneline); + ol.Available = FALSE; + /* Record *//* marked for deletion */ + sprintf(msg, "%s%d %s", (char *) Language(332), nrecno, (char *) Language(334)); + pout(LIGHTGREEN, BLACK, msg); + Syslog('+', "User marked oneliner record for deletion: %s", stemp); } - fclose(pOneline); - free(sFileName); + Enter(2); + Pause(); + + if (fseek(pOneline, offset, 0) != 0) + WriteError("Can't move pointer in %s",sFileName); + fwrite(&ol, olhdr.recsize, 1, pOneline); + } + fclose(pOneline); + free(sFileName); } diff --git a/mbsebbs/openport.c b/mbsebbs/openport.c new file mode 100644 index 00000000..4a8a9f7a --- /dev/null +++ b/mbsebbs/openport.c @@ -0,0 +1,162 @@ +/***************************************************************************** + * + * $Id$ + * + ***************************************************************************** + * Copyright (C) 1997-2004 + * + * Michiel Broek FIDO: 2:280/2802 + * Beekmansbos 10 + * 1971 BV IJmuiden + * the Netherlands + * + * This file is part of MBSE BBS. + * + * This BBS is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * MBSE BBS is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MBSE BBS; see the file COPYING. If not, write to the Free + * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + *****************************************************************************/ + +#include "../config.h" +#include "../lib/mbselib.h" +#include "ttyio.h" +#include "openport.h" + + +int hanged_up = 0; + +static struct termios savetios; +static struct termios tios; + + + +/* + * Set port to local, hangup using DTR drop. + */ +void hangup(void) +{ + struct termios Tios; + tcflag_t cflag; + speed_t ispeed, ospeed; + int rc; + + Syslog('t', "Setting port local"); + + if (isatty(0)) { + if ((rc = tcgetattr(0,&Tios))) { + WriteError("$tcgetattr(0,save) return %d",rc); + return; + } + Syslog('+', "Lowering DTR to hangup"); + + cflag = Tios.c_cflag | CLOCAL; + + ispeed = cfgetispeed(&tios); + ospeed = cfgetospeed(&tios); + cfsetispeed(&Tios,0); + cfsetospeed(&Tios,0); + if ((rc = tcsetattr(0,TCSADRAIN,&Tios))) + WriteError("$tcsetattr(0,TCSADRAIN,hangup) return %d",rc); + + sleep(1); /* as far as I notice, DTR goes back high on next op. */ + + Tios.c_cflag = cflag; + cfsetispeed(&Tios,ispeed); + cfsetospeed(&Tios,ospeed); + if ((rc = tcsetattr(0,TCSADRAIN,&Tios))) + Syslog('t', "$tcsetattr(0,TCSADRAIN,clocal) return %d",rc); + } else { + Syslog('t', "Not at a tty"); + } + + return; +} + + + +/* + * Put the current opened tty in raw mode. + */ +int rawport(void) +{ + int rc = 0; + + Syslog('t', "rawport()"); + tty_status = 0; + + Syslog('t', "ttyname 0 %s", ttyname(0)); + Syslog('t', "ttyname 1 %s", ttyname(1)); + Syslog('t', "fd = %d", fileno(stdin)); + Syslog('t', "fd = %d", fileno(stdout)); + Syslog('t', "fd = %d", fileno(stderr)); + + if (isatty(0)) { + if ((rc = tcgetattr(0,&savetios))) { + WriteError("$tcgetattr(0,save) return %d",rc); + return rc; + } + + tios = savetios; + tios.c_iflag &= ~(INLCR | ICRNL | ISTRIP | IXON ); /* IUCLC removed for FreeBSD */ + /* + * Map CRNL modes strip control characters and flow control + */ + tios.c_oflag &= ~OPOST; /* Don't do ouput character translation */ + tios.c_lflag &= ~(ICANON | ECHO); /* No canonical input and no echo */ + tios.c_cc[VMIN] = 1; /* Receive 1 character at a time */ + tios.c_cc[VTIME] = 0; /* No time limit per character */ + + if ((rc = tcsetattr(0,TCSADRAIN,&tios))) + WriteError("$tcsetattr(0,TCSADRAIN,raw) return %d",rc); + + } else { + Syslog('t', "not at a tty"); + } + return rc; +} + + + +int cookedport(void) +{ + int rc = 0; + + Syslog('t', "cookedport()"); + if (isatty(0)) { + if ((rc = tcsetattr(0,TCSAFLUSH,&savetios))) + Syslog('t', "$tcsetattr(0,TCSAFLUSH,save) return %d", rc); + } + + return rc; +} + + + +void sendbrk(void) +{ + Syslog('t', "Send break"); + + if (isatty(0)) { +#if (defined(TIOCSBRK)) + Syslog('t', "TIOCSBRK"); + ioctl(0, TIOCSBRK, 0L); +#elif (defined(TCSBRK)) + Syslog('t', "TCSBRK"); + ioctl(0, TCSBRK, 0L); +#else /* any ideas about BSD? */ + ; +#endif + } +} + + diff --git a/mbsebbs/openport.h b/mbsebbs/openport.h new file mode 100644 index 00000000..cd351ab8 --- /dev/null +++ b/mbsebbs/openport.h @@ -0,0 +1,11 @@ +#ifndef _OPENPORT_H +#define _OPENPORT_H + +/* $Id$ */ + +void hangup(void); +int rawport(void); +int cookedport(void); +void sendbrk(void); + +#endif diff --git a/mbsebbs/page.c b/mbsebbs/page.c index 76a79fab..3613c267 100644 --- a/mbsebbs/page.c +++ b/mbsebbs/page.c @@ -41,6 +41,7 @@ #include "mail.h" #include "language.h" #include "term.h" +#include "ttyio.h" extern pid_t mypid; @@ -65,33 +66,34 @@ void Page_Sysop(char *String) if (CFG.iAskReason) { locate(6, 0); colour(BLUE, BLACK); - printf("%c", 213); + PUTCHAR(213); for (i = 0; i < 78; i++) - printf("%c", 205); - printf("%c\n", 184); + PUTCHAR(205); + PUTCHAR(184); + Enter(1); colour(LIGHTGRAY, BLACK); for (i = 0; i < 78; i++) - printf("%c", 250); - printf("\n"); + PUTCHAR(250); + Enter(1); colour(BLUE, BLACK); - printf("%c", 212); + PUTCHAR(212); for (i = 0; i < 78; i++) - printf("%c", 205); - printf("%c\n", 190); + PUTCHAR(205); + PUTCHAR(190); + Enter(1); locate(7, 2); - colour(LIGHTGRAY, BLACK); - fflush(stdout); GetPageStr(temp, 76); colour(BLUE, BLACK); - printf("%c", 212); + PUTCHAR(212); for (i = 0; i < 78; i++) - printf("%c", 205); - printf("%c\n", 190); + PUTCHAR(205); + PUTCHAR(190); + Enter(1); if ((strcmp(temp, "")) == 0) return; @@ -102,7 +104,6 @@ void Page_Sysop(char *String) sprintf(Reason, "User want's to chat"); } - CFG.iMaxPageTimes--; if (CFG.iMaxPageTimes <= 0) { @@ -129,7 +130,7 @@ void Page_Sysop(char *String) pout(WHITE, BLACK, (char *)"["); colour(BLUE, BLACK); for (i = 0; i < CFG.iPageLength; i++) - printf("%c", 176); + PUTCHAR(176); pout(WHITE, BLACK, (char *)"]"); locate(16, ((80 - CFG.iPageLength) / 2 - 2) + 1); @@ -168,8 +169,7 @@ void Page_Sysop(char *String) * Check for other errors */ if (strcmp(buf, "100:1,3;") == 0) { - colour(LIGHTRED, BLACK); - printf("Internal system error, the sysop is informed"); + pout(LIGHTRED, BLACK, (char *)"Internal system error, the sysop is informed"); Enter(2); Syslog('!', "Got error on page sysop command"); Pause(); @@ -183,8 +183,7 @@ void Page_Sysop(char *String) */ colour(LIGHTBLUE, BLACK); for (i = 0; i < CFG.iPageLength; i++) { - printf("%c", 219); - fflush(stdout); + PUTCHAR(219); sleep(1); sprintf(buf, "CISC:1,%d", mypid); @@ -214,7 +213,7 @@ void Page_Sysop(char *String) } PageReason(); - printf("\n\n\n"); + Enter(3); Pause(); if (strlen(Reason)) SysopComment(Reason); @@ -235,12 +234,6 @@ void GetPageStr(char *sStr, int iMaxlen) unsigned char ch = 0; int iPos = 0; - if ((ttyfd = open ("/dev/tty", O_RDWR)) < 0) { - perror("open 6"); - return; - } - Setraw(); - strcpy(sStr, ""); alarm_on(); @@ -248,8 +241,9 @@ void GetPageStr(char *sStr, int iMaxlen) ch = Readkey(); if (((ch == 8) || (ch == KEY_DEL) || (ch == 127)) && (iPos > 0)) { - printf("\b%c\b", 250); - fflush(stdout); + PUTCHAR('\b'); + PUTCHAR(250); + PUTCHAR('\b'); sStr[--iPos]='\0'; } @@ -257,16 +251,14 @@ void GetPageStr(char *sStr, int iMaxlen) if (iPos <= iMaxlen) { iPos++; sprintf(sStr, "%s%c", sStr, ch); - printf("%c", ch); + PUTCHAR(ch); fflush(stdout); } else ch=13; } } - Unsetraw(); - close(ttyfd); - printf("\n"); + Enter(1); } @@ -309,9 +301,9 @@ void PageReason() if (Lines == j) { Striplf(String); locate(18, ((78 - strlen(String) ) / 2)); - pout(15, 0, (char *)"["); - pout(9, 0, String); - pout(15, 0, (char *)"]"); + pout(WHITE, BLACK, (char *)"["); + pout(LIGHTBLUE, BLACK, String); + pout(WHITE, BLACK, (char *)"]"); iFoundString = TRUE; } @@ -323,9 +315,9 @@ void PageReason() /* Sysop currently is not available ... please leave a comment */ sprintf(String, "%s", (char *) Language(155)); locate(18, ((78 - strlen(String) ) / 2)); - pout(15, 0, (char *)"["); - pout(9, 0, String); - pout(15, 0, (char *)"]"); + pout(WHITE, BLACK, (char *)"["); + pout(LIGHTBLUE, BLACK, String); + pout(WHITE, BLACK, (char *)"]"); } free(temp); diff --git a/mbsebbs/pinfo.c b/mbsebbs/pinfo.c index b91f0073..0f7da39b 100644 --- a/mbsebbs/pinfo.c +++ b/mbsebbs/pinfo.c @@ -35,31 +35,33 @@ #include "pinfo.h" #include "input.h" #include "term.h" +#include "ttyio.h" void ls(int a) { - printf("%c ", a ? 179 : '|'); + PUTCHAR(a ? 179 : '|'); } void rs(int a) { - colour(8, 0); - printf("%c\n", a ? 179 : '|'); + colour(DARKGRAY, BLACK); + PUTCHAR(a ? 179 : '|'); + Enter(1); } void wl(int a) { - int i; + int i; - ls(a); - for(i = 0; i < 76; i++) - printf(" "); - rs(a); + ls(a); + for(i = 0; i < 76; i++) + PUTCHAR(' '); + rs(a); } @@ -69,80 +71,81 @@ void wl(int a) */ void cr(void) { - int a, i; - char *string, *temp; + int a, i; + char *string, *temp; - a = exitinfo.GraphMode; + a = exitinfo.GraphMode; - string = calloc(81, sizeof(char)); - temp = calloc(81, sizeof(char)); + string = calloc(81, sizeof(char)); + temp = calloc(81, sizeof(char)); - clear(); - colour(8, 0); + clear(); + colour(DARKGRAY, BLACK); - /* Print top row */ - printf("%c", a ? 213 : '+'); - for(i = 0; i < 77; i++) - printf("%c", a ? 205 : '='); - printf("%c\n", a ? 184 : '+'); + /* Print top row */ + PUTCHAR(a ? 213 : '+'); + for (i = 0; i < 76; i++) + PUTCHAR(a ? 205 : '='); + PUTCHAR(a ? 184 : '+'); + Enter(1); - wl(a); - ls(a); - sprintf(temp, "MBSE Bulletin Board System %s (%s-%s)", VERSION, OsName(), OsCPU()); - pout(14, 0, padleft(temp, 76, ' ')); - rs(a); - wl(a); - ls(a); - sprintf(temp, "%s", COPYRIGHT); - pout(11, 0, padleft(temp, 76, ' ')); - rs(a); - wl(a); - ls(a); - sprintf(temp, "Compiled on %s at %s", __DATE__, __TIME__); - pout(14, 0, padleft(temp, 76, ' ')); - rs(a); - wl(a); - ls(a); - pout(11, 0, (char *)"MBSE has been written and designed by Michiel Broek. Many others have given "); - rs(a); - ls(a); - pout(11, 0, (char *)"valuable time in the form of new ideas and suggestions on how to make MBSE "); - rs(a); - ls(a); - pout(11, 0, (char *)"BBS a better BBS "); - rs(a); - wl(a); - ls(a); - pout(15, 0, (char *)"Available from http://www.mbse.dds.nl or 2:280/2802 "); - rs(a); - wl(a); - ls(a); - pout(12, 0, (char *)"JAM(mbp) - Copyright 1993 Joaquim Homrighausen, Andrew Milner, "); - rs(a); - ls(a); - pout(12, 0, (char *)" Mats Birch, Mats Wallin. "); - rs(a); - ls(a); - pout(12, 0, (char *)" ALL RIGHTS RESERVED. "); - rs(a); - wl(a); - ls(a); - pout(9, 0, (char *)"This is free software; released under the terms of the GNU General Public "); - rs(a); - ls(a); - pout(9, 0, (char *)"License as published by the Free Software Foundation. "); - rs(a); - wl(a); + wl(a); + ls(a); + sprintf(temp, "MBSE Bulletin Board System %s (%s-%s)", VERSION, OsName(), OsCPU()); + pout(YELLOW, BLACK, padleft(temp, 76, ' ')); + rs(a); + wl(a); + ls(a); + sprintf(temp, "%s", COPYRIGHT); + pout(LIGHTCYAN, BLACK, padleft(temp, 76, ' ')); + rs(a); + wl(a); + ls(a); + sprintf(temp, "Compiled on %s at %s", __DATE__, __TIME__); + pout(LIGHTRED, BLACK, padleft(temp, 76, ' ')); + rs(a); + wl(a); + ls(a); + pout(LIGHTCYAN, BLACK, (char *)"MBSE has been written and designed by Michiel Broek. Many others have given "); + rs(a); + ls(a); + pout(LIGHTCYAN, BLACK, (char *)"valuable time in the form of new ideas and suggestions on how to make MBSE "); + rs(a); + ls(a); + pout(LIGHTCYAN, BLACK, (char *)"BBS a better BBS "); + rs(a); + wl(a); + ls(a); + pout(WHITE, BLACK, (char *)"Available from http://www.mbse.dds.nl or 2:280/2802 "); + rs(a); + wl(a); + ls(a); + pout(LIGHTRED, BLACK, (char *)"JAM(mbp) - Copyright 1993 Joaquim Homrighausen, Andrew Milner, "); + rs(a); + ls(a); + pout(LIGHTRED, BLACK, (char *)" Mats Birch, Mats Wallin. "); + rs(a); + ls(a); + pout(LIGHTRED, BLACK, (char *)" ALL RIGHTS RESERVED. "); + rs(a); + wl(a); + ls(a); + pout(LIGHTBLUE, BLACK, (char *)"This is free software; released under the terms of the GNU General Public "); + rs(a); + ls(a); + pout(LIGHTBLUE, BLACK, (char *)"License as published by the Free Software Foundation. "); + rs(a); + wl(a); - printf("%c", a ? 212 : '+'); - for(i = 0; i < 77; i++) - printf("%c", a ? 205 : '='); - printf("%c", a ? 190 : '+'); + PUTCHAR(a ? 212 : '+'); + for (i = 0; i < 76; i++) + PUTCHAR(a ? 205 : '='); + PUTCHAR(a ? 190 : '+'); - free(string); - free(temp); - printf("\n"); - Pause(); + free(string); + free(temp); + Enter(1); + Pause(); } diff --git a/mbsebbs/pop3.c b/mbsebbs/pop3.c index 8ad5c752..0e3770f3 100644 --- a/mbsebbs/pop3.c +++ b/mbsebbs/pop3.c @@ -38,15 +38,14 @@ #include "msgutil.h" #include "pop3.h" #include "term.h" +#include "ttyio.h" void error_popmail(char *); void error_popmail(char *umsg) { pop3_close(); - colour(LIGHTRED, BLACK); - printf("%s\r\n", umsg); - fflush(stdout); + poutCR(LIGHTRED, BLACK, umsg); } @@ -185,9 +184,9 @@ void check_popmail(char *user, char *pass) /* * Show progress */ - colour(color, BLACK); - printf("\rFetching message %02d/%02d, total %d bytes", msgnum, tmsgs, size); - fflush(stdout); + PUTCHAR('\r'); + sprintf(temp, "Fetching message %02d/%02d, total %d bytes", msgnum, tmsgs, size); + pout(color, BLACK, temp); if (color < WHITE) color++; else @@ -197,16 +196,16 @@ void check_popmail(char *user, char *pass) fclose(tp); } } - fflush(stdout); } pop3_cmd((char *)"QUIT\r\n"); pop3_close(); if (tmsgs) { + PUTCHAR('\r'); colour(LIGHTMAGENTA, BLACK); - printf("\r \r"); - fflush(stdout); + pout(LIGHTMAGENTA, BLACK, (char *)" "); + PUTCHAR('\r'); } } diff --git a/mbsebbs/signature.c b/mbsebbs/signature.c index 64b0a8da..99925817 100644 --- a/mbsebbs/signature.c +++ b/mbsebbs/signature.c @@ -38,6 +38,7 @@ #include "language.h" #include "timeout.h" #include "term.h" +#include "ttyio.h" #define MAXSIGLINES 4 @@ -83,8 +84,9 @@ void toprow(void) pout(YELLOW, BLACK, (char *)" Ơ"); for (i = 0; i < LENSIGLINES; i++) - printf("Í"); - printf("¸\n"); + PUTCHAR('Í'); + PUTCHAR('¸'); + Enter(1); } @@ -96,8 +98,9 @@ void botrow(void) pout(YELLOW, BLACK, (char *)" Ô"); for (i = 0; i < LENSIGLINES; i++) - printf("Í"); - printf("¾\n"); + PUTCHAR('Í'); + PUTCHAR('¾'); + Enter(1); } @@ -139,11 +142,9 @@ int loadsignature(void) toprow(); for (i = 0; i < MAXSIGLINES; i++) { - colour(LIGHTRED, BLACK); - printf("%d:", i+1); - colour(CFG.MoreF, CFG.MoreB); - printf("%s\n", sLiNE[i]); - fflush(stdout); + sprintf(temp, "%d:", i+1); + pout(LIGHTRED, BLACK, temp); + poutCR(CFG.MoreF, CFG.MoreB, sLiNE[i]); } botrow(); @@ -176,10 +177,9 @@ int editsignature(void) /* Select: */ pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(115)); - fflush(stdout); alarm_on(); - i = toupper(Getone()); + i = toupper(Readkey()); Enter(1); if (i == Keystroke(114, 3)) { @@ -191,9 +191,10 @@ int editsignature(void) return TRUE; } else if (i == Keystroke(114, 2)) { + Enter(1); /* Edit which line: */ - colour(CFG.HiliteF, CFG.HiliteB); - printf("\n %s", (char *) Language(118)); + sprintf(temp, " %s", (char *) Language(118)); + pout(CFG.HiliteF, CFG.HiliteB, temp); colour(CFG.InputColourF, CFG.InputColourB); GetstrC(temp, 3); @@ -202,27 +203,25 @@ int editsignature(void) i = atoi(temp); if ((i < 1) || (i > MAXSIGLINES)) { + Enter(1); /* Line does not exist. */ - printf("%s\n", (char *) Language(119)); + poutCR(LIGHTRED, BLACK, (char *) Language(119)); break; } x = strlen(sLiNE[i-1]); - colour(LIGHTRED, BLACK); - printf("%d:", i); - colour(CFG.InputColourF, CFG.InputColourB); - printf("%s", sLiNE[i-1]); - fflush(stdout); + sprintf(temp, "%d:", i); + pout(LIGHTRED, BLACK, temp); + pout(CFG.InputColourF, CFG.InputColourB, sLiNE[i-1]); GetstrP(sLiNE[i-1], LENSIGLINES-1, x); } else if (i == Keystroke(114, 0)) { /* List lines */ toprow(); for (i = 0; i < MAXSIGLINES; i++) { - colour(LIGHTRED, BLACK); - printf("%d:", i+1); - colour(CFG.MoreF, CFG.MoreB); - printf("%s\n", sLiNE[i]); + sprintf(temp, "%d:", i+1); + pout(LIGHTRED, BLACK, temp); + poutCR(CFG.MoreF, CFG.MoreB, sLiNE[i]); } botrow(); @@ -251,9 +250,9 @@ int editsignature(void) return TRUE; } else if (i == Keystroke(114, 1)) { + Enter(1); /* Edit which line: */ - colour(CFG.HiliteF, CFG.HiliteB); - printf("\n%s", (char *) Language(118)); + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(118)); colour(CFG.InputColourF, CFG.InputColourB); GetstrC(temp, 3); @@ -263,15 +262,17 @@ int editsignature(void) i = atoi(temp); if ((i < 1) || (i > MAXSIGLINES)) { + Enter(1); /* Line does not exist. */ - printf("\n%s", (char *) Language(119)); + poutCR(LIGHTRED, BLACK, (char *) Language(119)); break; } Enter(1); /* Line reads: */ poutCR(CFG.MoreF, CFG.MoreB, (char *) Language(186)); - printf("%d:%s\n", i, sLiNE[i-1]); + sprintf(temp, "%d:%s", i, sLiNE[i-1]); + poutCR(CFG.MoreF, CFG.MoreB, temp); Enter(1); /* Text to replace: */ @@ -292,7 +293,7 @@ int editsignature(void) strreplace(sLiNE[i-1], temp, temp1); } else - printf("\n"); + Enter(1); } free(temp); diff --git a/mbsebbs/term.c b/mbsebbs/term.c index dc1f0e95..71cdd904 100644 --- a/mbsebbs/term.c +++ b/mbsebbs/term.c @@ -33,6 +33,7 @@ #include "../lib/mbselib.h" #include "../lib/users.h" #include "term.h" +#include "ttyio.h" int termmode; /* 0 = tty, 1 = ANSI */ @@ -56,9 +57,10 @@ void Enter(int num) { int i; - for (i = 0; i < num; i++) - fprintf(stdout, "\n"); - fflush(stdout); + for (i = 0; i < num; i++) { + PUTCHAR('\r'); + PUTCHAR('\n'); + } } @@ -67,8 +69,7 @@ void Enter(int num) void pout(int fg, int bg, char *Str) { colour(fg, bg); - fprintf(stdout, Str); - fflush(stdout); + PUTSTR(Str); } @@ -84,9 +85,9 @@ void poutCenter(int fg, int bg, char *Str) void poutCR(int fg, int bg, char *Str) { colour(fg, bg); - fputs(Str, stdout); - fprintf(stdout, "\n"); - fflush(stdout); + PUTSTR(Str); + PUTCHAR('\r'); + PUTCHAR('\n'); } @@ -96,19 +97,21 @@ void poutCR(int fg, int bg, char *Str) */ void colour(int fg, int bg) { + char temp[61]; + if (termmode == 1) { int att=0, fore=37, back=40; if (fg<0 || fg>31 || bg<0 || bg>7) { - fprintf(stdout, "ANSI: Illegal colour specified: %i, %i\n", fg, bg); - fflush(stdout); + sprintf(temp, "ANSI: Illegal colour specified: %i, %i\n", fg, bg); + PUTSTR(temp); return; } - fprintf(stdout, "["); + PUTSTR((char *)"["); if ( fg > WHITE) { - fprintf(stdout, "5;"); + PUTSTR((char *)"5;"); fg-= 16; } if (fg > LIGHTGRAY) { @@ -134,8 +137,8 @@ void colour(int fg, int bg) else if (bg == LIGHTGRAY) back=47; else back=40; - fprintf(stdout, "%d;%d;%dm", att, fore, back); - fflush(stdout); + sprintf(temp, "%d;%d;%dm", att, fore, back); + PUTSTR(temp); } } @@ -152,17 +155,17 @@ void Center(char *string) Strlen = strlen(string); if (Strlen == Maxlen) - fprintf(stdout, "%s\n", string); + PUTSTR(string); else { x = Maxlen - Strlen; z = x / 2; for (i = 0; i < z; i++) strcat(Str, " "); strcat(Str, string); - fprintf(stdout, "%s\n", Str); + PUTSTR(Str); } - - fflush(stdout); + PUTCHAR('\r'); + PUTCHAR('\n'); free(Str); } @@ -172,9 +175,8 @@ void clear() { if (termmode == 1) { colour(LIGHTGRAY, BLACK); - fprintf(stdout, ANSI_HOME); - fprintf(stdout, ANSI_CLEAR); - fflush(stdout); + PUTSTR((char *)ANSI_HOME); + PUTSTR((char *)ANSI_CLEAR); } else Enter(1); } @@ -186,14 +188,15 @@ void clear() */ void locate(int y, int x) { + char temp[61]; + if (termmode > 0) { if (y > termy || x > termx) { - fprintf(stdout, "ANSI: Invalid screen coordinates: %i, %i\n", y, x); - fflush(stdout); - return; + sprintf(temp, "ANSI: Invalid screen coordinates: %i, %i\n", y, x); + } else { + sprintf(temp, "\x1B[%i;%iH", y, x); } - fprintf(stdout, "\x1B[%i;%iH", y, x); - fflush(stdout); + PUTSTR(temp); } } @@ -205,19 +208,18 @@ void fLine(int Len) if (termmode == 0) for (x = 0; x < Len; x++) - fprintf(stdout, "-"); + PUTCHAR('-'); if (termmode == 1) for (x = 0; x < Len; x++) - fprintf(stdout, "%c", 196); + PUTCHAR(196); - fprintf(stdout, " \n"); - fflush(stdout); + PUTCHAR('\r'); + PUTCHAR('\n'); } - void sLine() { fLine(termx -1); @@ -240,9 +242,8 @@ void mvprintw(int y, int x, const char *format, ...) va_end(va_ptr); locate(y, x); - fprintf(stdout, outputstr); + PUTSTR(outputstr); free(outputstr); - fflush(stdout); } diff --git a/mbsebbs/timecheck.c b/mbsebbs/timecheck.c index e736fba9..6f2a8a04 100644 --- a/mbsebbs/timecheck.c +++ b/mbsebbs/timecheck.c @@ -39,6 +39,7 @@ #include "language.h" #include "input.h" #include "term.h" +#include "ttyio.h" extern pid_t mypid; /* Pid of this program */ @@ -53,7 +54,7 @@ void Check_PM(void); void Check_PM(void) { static char buf[200]; - char resp[128]; + char resp[128], msg[81]; sprintf(buf, "CIPM:1,%d;", mypid); if (socket_send(buf) == 0) { @@ -64,12 +65,17 @@ void Check_PM(void) strncpy(resp, strtok(buf, ":"), 5); /* Should be 100 */ strncpy(resp, strtok(NULL, ","), 3); /* Should be 2 */ strncpy(resp, strtok(NULL, ","), 36); /* From Name */ + + Enter(2); + PUTCHAR('\007'); colour(CYAN, BLACK); /* ** Message ** from */ - printf("\n\n\007%s %s:\n", (char *)Language(434), resp); + sprintf(msg, "%s %s:", (char *)Language(434), resp); + poutCR(CYAN, BLACK, msg); strncpy(resp, strtok(NULL, "\0"), 80); /* The real message */ resp[strlen(resp)-1] = '\0'; - printf("%s\n", resp); + PUTSTR(resp); + Enter(1); Pause(); } } @@ -110,7 +116,8 @@ void TimeCheck(void) } if (exitinfo.iTimeLeft <= 0) { - printf("\n%s\n", (char *) Language(130)); + Enter(1); + poutCR(YELLOW, BLACK, (char *) Language(130)); sleep(3); Syslog('!', "Users time limit exceeded ... user disconnected!"); iExpired = TRUE; diff --git a/mbsebbs/timeout.c b/mbsebbs/timeout.c index ee26fbe1..d67b0c9c 100644 --- a/mbsebbs/timeout.c +++ b/mbsebbs/timeout.c @@ -41,93 +41,96 @@ #include "term.h" -extern int e_pid; /* Pid of external program */ - +extern int e_pid; /* Pid of external program */ +extern int hanged_up; /* Hanged up status */ void die(int onsig) { - /* - * First check if there is a child running, if so, kill it. - */ - if (e_pid) { - if ((kill(e_pid, SIGTERM)) == 0) - Syslog('+', "SIGTERM to pid %d succeeded", e_pid); - else { - if ((kill(e_pid, SIGKILL)) == 0) - Syslog('+', "SIGKILL to pid %d succeeded", e_pid); - else - WriteError("Failed to kill pid %d", e_pid); - } - - /* - * In case the child had the tty in raw mode, reset the tty - */ - execute_pth((char *)"stty", (char *)"sane", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); - } - - if (MsgBase.Locked) - Msg_UnLock(); - if (MsgBase.Open) - Msg_Close(); - - Home(); + if (onsig <= NSIG) signal(onsig, SIG_IGN); - if (onsig) - if (onsig == SIGHUP) { - Syslog('+', "Lost Carrier"); - } else if (onsig == SIGALRM) { - Syslog('+', "User inactivity timeout"); - } else { - if (onsig <= NSIG) - WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]); - else - WriteError("Terminated with error %d", onsig); - } - else - Syslog(' ', "Terminated by user"); - - if (onsig == SIGSEGV) { - Syslog('+', "Last msg area %s", msgs.Name); + + /* + * First check if there is a child running, if so, kill it. + */ + if (e_pid) { + if ((kill(e_pid, SIGTERM)) == 0) + Syslog('+', "SIGTERM to pid %d succeeded", e_pid); + else { + if ((kill(e_pid, SIGKILL)) == 0) + Syslog('+', "SIGKILL to pid %d succeeded", e_pid); + else + WriteError("Failed to kill pid %d", e_pid); } + } - Good_Bye(onsig); + if (MsgBase.Locked) + Msg_UnLock(); + if (MsgBase.Open) + Msg_Close(); + + Home(); + if (onsig) { + if (onsig == SIGHUP) { + hanged_up = 1; + Syslog('+', "Lost Carrier"); + } else if (onsig == SIGPIPE) { + hanged_up = 1; + Syslog('+', "Broken Pipe"); + } else if (onsig == SIGALRM) { + Syslog('+', "User inactivity timeout"); + } else { + if (onsig <= NSIG) + WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]); + else + WriteError("Terminated with error %d", onsig); + } + } else { + Syslog(' ', "Terminated by user"); + } + + if (onsig == SIGSEGV) { + Syslog('+', "Last msg area %s", msgs.Name); + } + + Good_Bye(onsig); } void alarm_sig() { - colour(LIGHTRED, BLACK); - /* Autologout: idletime reached.*/ - printf("\r\n%s\r\n", (char *) Language(410)); + Enter(2); + /* Autologout: idletime reached.*/ + pout(LIGHTRED, BLACK, (char *) Language(410)); + Enter(2); - Syslog('!', "Autologout: idletime reached"); - die(SIGALRM); + Syslog('!', "Autologout: idletime reached"); + die(SIGALRM); } void alarm_set(int val) { - signal(SIGALRM, (void (*))alarm_sig); - alarm(val); - Syslog('S', "Alarm set for %d seconds", val); + signal(SIGALRM, (void (*))alarm_sig); + alarm(val); + Syslog('S', "Alarm set for %d seconds", val); } void alarm_on() { - alarm_set(60 * CFG.idleout); + alarm_set(60 * CFG.idleout); } void alarm_off() { - alarm(0); - signal(SIGALRM, SIG_IGN); - Syslog('S', "Alarm is off"); + alarm(0); + signal(SIGALRM, SIG_IGN); + Syslog('S', "Alarm is off"); } diff --git a/mbsebbs/timestats.c b/mbsebbs/timestats.c index 3a4ac460..c7038344 100644 --- a/mbsebbs/timestats.c +++ b/mbsebbs/timestats.c @@ -42,49 +42,56 @@ void TimeStats() { - char Logdate[15]; + char Logdate[21], msg[81]; - Time_Now = time(NULL); - l_date = localtime(&Time_Now); - sprintf(Logdate,"%02d-%s %02d:%02d:%02d", l_date->tm_mday, GetMonth(l_date->tm_mon+1), + Time_Now = time(NULL); + l_date = localtime(&Time_Now); + sprintf(Logdate, "%02d-%s %02d:%02d:%02d", l_date->tm_mday, GetMonth(l_date->tm_mon+1), l_date->tm_hour, l_date->tm_min, l_date->tm_sec); - clear(); - ReadExitinfo(); + clear(); + ReadExitinfo(); - colour(15, 0); - /* TIME STATISTICS for */ - printf("\n%s%s ", (char *) Language(134), exitinfo.sUserName); - /* on */ - printf("%s %s\n", (char *) Language(135), Logdate); + Enter(1); + /* TIME STATISTICS for */ + sprintf(msg, "%s%s ", (char *) Language(134), exitinfo.sUserName); + pout(WHITE, BLACK, msg); + /* on */ + sprintf(msg, "%s %s", (char *) Language(135), Logdate); + poutCR(WHITE, BLACK, msg); - colour(12, 0); - fLine(79); + colour(LIGHTRED, BLACK); + fLine(79); - printf("\n"); + Enter(1); - colour(10, 0); + /* Current Time */ + sprintf(msg, "%s %s", (char *) Language(136), (char *) GetLocalHMS()); + poutCR(LIGHTGREEN, BLACK, msg); - /* Current Time */ - printf("%s %s\n", (char *) Language(136), (char *) GetLocalHMS()); + /* Current Date */ + sprintf(msg, "%s %s", (char *) Language(137), (char *) GLCdateyy()); + poutCR(LIGHTGREEN, BLACK, msg); + Enter(1); - /* Current Date */ - printf("%s %s\n\n", (char *) Language(137), (char *) GLCdateyy()); - - /* Connect time */ - printf("%s %d %s\n", (char *) Language(138), exitinfo.iConnectTime, (char *) Language(471)); - - /* Time used today */ - printf("%s %d %s\n", (char *) Language(139), exitinfo.iTimeUsed, (char *) Language(471)); - - /* Time remaining today */ - printf("%s %d %s\n", (char *) Language(140), exitinfo.iTimeLeft, (char *) Language(471)); - - /* Daily time limit */ - printf("%s %d %s\n", (char *) Language(141), exitinfo.iTimeUsed + exitinfo.iTimeLeft, (char *) Language(471)); - - printf("\n"); - Pause(); + /* Connect time */ + sprintf(msg, "%s %d %s", (char *) Language(138), exitinfo.iConnectTime, (char *) Language(471)); + poutCR(LIGHTGREEN, BLACK, msg); + + /* Time used today */ + sprintf(msg, "%s %d %s", (char *) Language(139), exitinfo.iTimeUsed, (char *) Language(471)); + poutCR(LIGHTGREEN, BLACK, msg); + + /* Time remaining today */ + sprintf(msg, "%s %d %s", (char *) Language(140), exitinfo.iTimeLeft, (char *) Language(471)); + poutCR(LIGHTGREEN, BLACK, msg); + + /* Daily time limit */ + sprintf(msg, "%s %d %s", (char *) Language(141), exitinfo.iTimeUsed + exitinfo.iTimeLeft, (char *) Language(471)); + poutCR(LIGHTGREEN, BLACK, msg); + + Enter(1); + Pause(); } diff --git a/mbsebbs/ttyio.c b/mbsebbs/ttyio.c new file mode 100644 index 00000000..1c92f961 --- /dev/null +++ b/mbsebbs/ttyio.c @@ -0,0 +1,594 @@ +/***************************************************************************** + * + * $Id$ + * Purpose ...............: tty I/O for mbsebbs and mbnewusr + * + ***************************************************************************** + * Copyright (C) 1997-2004 + * + * Michiel Broek FIDO: 2:280/2802 + * Beekmansbos 10 + * 1971 BV IJmuiden + * the Netherlands + * + * This file is part of MBSE BBS. + * + * This BBS is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * MBSE BBS is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MBSE BBS; see the file COPYING. If not, write to the Free + * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + *****************************************************************************/ + +#include "../config.h" +#include "../lib/mbselib.h" +#include "ttyio.h" + + +extern int hanged_up; +extern char *inetaddr; + +#define TT_BUFSIZ 1024 +#define NUMTIMERS 3 + + +int tty_status = 0; +int f_flags; +static char buffer[TT_BUFSIZ]; +static char *next; +static int left = 0; + + +static time_t timer[NUMTIMERS]; + +char *ttystat[]= {(char *)"Ok", + (char *)"Error", + (char *)"TimeOut", + (char *)"EOF", + (char *)"Hangup", + (char *)"Empty", + (char *)"UnCompress"}; + +int tty_resettimer(int tno); +void tty_resettimers(void); +int tty_settimer(int,int); +int tty_expired(int); +int tty_running(int); + +#define RESETTIMER(x) tty_resettimer(x) +#define RESETTIMERS() tty_resettimers() +#define SETTIMER(x,y) tty_settimer(x,y) +#define EXPIRED(x) tty_expired(x) +#define RUNNING(x) tty_running(x) + + + +/* + * timer functions + */ +int tty_resettimer(int tno) +{ + if (tno >= NUMTIMERS) { + errno = EINVAL; + WriteError("ttyio: invalid timer No for resettimer(%d)", tno); + return -1; + } + + timer[tno] = (time_t) 0; + return 0; +} + + + +void tty_resettimers(void) +{ + int i; + + for (i = 0; i < NUMTIMERS; i++) + timer[i] = (time_t)0; +} + + + +int tty_settimer(int tno, int interval) +{ + if (tno >= NUMTIMERS) { + errno = EINVAL; + WriteError("ttyio: invalid timer No for settimer(%d)", tno); + return -1; + } + + timer[tno]=time((time_t*)NULL)+interval; + return 0; +} + + + +int tty_expired(int tno) +{ + time_t now; + + if (tno >= NUMTIMERS) { + errno = EINVAL; + WriteError("ttyio: invalid timer No for expired(%d)", tno); + return -1; + } + + /* + * Check if timer is running + */ + if (timer[tno] == (time_t) 0) + return 0; + + now = time(NULL); + return (now >= timer[tno]); +} + + + +int tty_running(int tno) +{ + if (tno > NUMTIMERS) { + errno = EINVAL; + WriteError("ttyio: invalid timer for tty_running(%d)", tno); + return -1; + } + + /* + * check if timer is running + */ + if (timer[tno] == (time_t) 0) + return 0; + else + return 1; +} + + + +/* + * private r/w functions + */ +static int tty_read(char *buf, int size, int tot) +{ + time_t timeout, now; + int i, rc; + fd_set readfds, writefds, exceptfds; + struct timeval seltimer; + + if (size == 0) + return 0; + tty_status = 0; + + now = time(NULL); + timeout = (time_t)300; /* maximum of 5 minutes */ + + for (i = 0; i < NUMTIMERS; i++) { + if (timer[i]) { + if (now >= timer[i]) { + tty_status=STAT_TIMEOUT; + Syslog('!', "tty_read: timer %d already expired, return", i); + return -tty_status; + } else { + if (timeout > (timer[i]-now)) + timeout=timer[i]-now; + } + } + } + if ((tot != -1) && (timeout > tot)) + timeout=tot; + + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_ZERO(&exceptfds); + FD_SET(0,&readfds); + FD_SET(0,&exceptfds); + seltimer.tv_sec=timeout; + seltimer.tv_usec=0; + + rc = select(1,&readfds,&writefds,&exceptfds,&seltimer); + + if (rc < 0) { + if (hanged_up) { + tty_status=STAT_HANGUP; + WriteError("tty_read: hanged_up flag"); + } else { + WriteError("$tty_read: select for read failed"); + tty_status = STAT_ERROR; + } + } else if (rc == 0) { + tty_status = STAT_TIMEOUT; + } else { /* rc > 0 */ + if (FD_ISSET(0,&exceptfds)) { + Syslog('!', "$tty_read: exeption error"); + tty_status = STAT_ERROR; + } + } + + if (tty_status) { + return -tty_status; + } + + if (!FD_ISSET(0,&readfds)) { + WriteError("tty_read: Cannot be: select returned but read fd not set"); + tty_status = STAT_ERROR; + return -tty_status; + } + + rc = read(0,buf,size); + + if (rc <= 0) { + Syslog('t', "tty_read: return %d",rc); + if (hanged_up || (errno == EPIPE) || (errno == ECONNRESET)) { + tty_status = STAT_HANGUP; + WriteError("tty_read: hanged_up flag"); + } else { + tty_status = STAT_ERROR; + Syslog('!', "tty_read: error flag"); + } + rc=-tty_status; + } + + return rc; +} + + + +int tty_write(char *buf, int size) +{ + int result; + + tty_status=0; + result = write(1, buf, size); + + if (result != size) { + if (hanged_up || (errno == EPIPE) || (errno == ECONNRESET)) { + tty_status = STAT_HANGUP; + WriteError("tty_write: hanged_up flag"); + } else { + tty_status=STAT_ERROR; + Syslog('!', "tty_write: error flag"); + } + } + if (tty_status) + Syslog('t', "tty_write: error %s", ttystat[tty_status]); + + return -tty_status; +} + + + +/* public r/w functions */ + +/* + * Check if there is data available on stdin. + */ +int tty_check(void) +{ + int rc; + + // try to read available (timeout = 0) data if we have no data in + // our buffer + + if (!left) { + rc = tty_read(buffer, TT_BUFSIZ, 0); + if (rc > 0) { + left = rc; + } + } + + return (left > 0); +} + + + +int tty_putcheck(int size) +{ + fd_set set; + struct timeval timeout; + + /* + * Initialize the file descriptor set. + */ + FD_ZERO(&set); + FD_SET(1, &set); + + /* + * Initialize the timeout data structure. + */ + timeout.tv_sec = 0; + timeout.tv_usec = 0; + + /* + * `select' returns 0 if timeout, 1 if input available, -1 if error. + */ + return select(FD_SETSIZE, NULL, &set, NULL, &timeout); +} + + + +int tty_waitputget(int tot) +{ + int i, rc; + time_t timeout, now; + fd_set readfds, writefds, exceptfds; + struct timeval seltimer; + + tty_status=0; + now = time(NULL); + timeout=(time_t)300; /* maximum of 5 minutes */ + + for (i = 0; i < NUMTIMERS; i++) { + if (timer[i]) { + if (now >= timer[i]) { + tty_status = STAT_TIMEOUT; + WriteError("tty_waitputget: timer %d already expired, return",i); + return -tty_status; + } else { + if (timeout > (timer[i]-now)) + timeout = timer[i]-now; + } + } + } + if ((tot != -1) && (timeout > tot)) + timeout=tot; + Syslog('t', "tty_waitputget: timeout=%d",timeout); + + /* + * Initialize the file descriptor set. + */ + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_ZERO(&exceptfds); + + FD_SET(0, &readfds); + FD_SET(1, &writefds); + FD_SET(0, &exceptfds); + FD_SET(1, &exceptfds); + + /* + * Initialize the timeout data structure. + */ + seltimer.tv_sec = timeout; + seltimer.tv_usec = 0; + + /* + * `select' returns 0 if timeout, 1 if input available, -1 if error. + */ + rc = select(FD_SETSIZE, &readfds, &writefds, &exceptfds, &seltimer); + + if (rc < 0) { + if (hanged_up) { + tty_status=STAT_HANGUP; + WriteError("tty_waitputget: hanged_up flag"); + } else { + WriteError("$tty_waitputget: select failed"); + tty_status=STAT_ERROR; + } + } else if (rc == 0) { + tty_status=STAT_TIMEOUT; + } else { + /* rc > 0 */ + if ((FD_ISSET(0,&exceptfds)) || (FD_ISSET(1,&exceptfds))) { + WriteError("$tty_waitputget: exeption error"); + tty_status=STAT_ERROR; + } + } + + if (tty_status) { + Syslog('t', "tty_waitputget: return after select status %s",ttystat[tty_status]); + return -tty_status; + } + + rc = 0; + + if (FD_ISSET(0,&readfds)) + rc |= 1; + + if (FD_ISSET(1,&writefds)) + rc |= 2; + + return rc; +} + + + +/* + * Discard all available input characters + */ +void tty_flushin(void) +{ + tcflush(0, TCIFLUSH); +} + + + +/* + * Discard all available characters in output buffer. + */ +void tty_flushout(void) +{ + tcflush(1, TCOFLUSH); +} + + + +int tty_ungetc(int c) +{ + if (next == buffer) { + if (left >= TT_BUFSIZ) { + return -1; + } + + next = buffer + TT_BUFSIZ - left; + memcpy(next, buffer, left); + } + + next--; + *next = c; + left++; + + return 0; +} + + + +int tty_getc(int tot) +{ + if (!left) { + left=tty_read(buffer,TT_BUFSIZ,tot); + next=buffer; + } + + if (left <= 0) { + left=0; + return -tty_status; + } else { + left--; + return (*next++)&0xff; + } +} + + + +int tty_get(char *buf, int size, int tot) +{ + int result=0; + + if (left >= size) { + memcpy(buf,next,size); + next += size; + left -= size; + return 0; + } + + if (left > 0) { + memcpy(buf,next,left); + buf += left; + next += left; + size -= left; + left=0; + } + + while ((result=tty_read(buf,size,tot)) > 0) { + buf += result; + size -= result; + } + + return result; +} + + + +int tty_putc(int c) +{ + char buf = c; + + return tty_write(&buf,1); +} + + + +int tty_put(char *buf, int size) +{ + return tty_write(buf,size); +} + + + +int tty_putget(char **obuf, int *osize, char **ibuf, int *isize) +{ + time_t timeout, now; + int i, rc; + fd_set readfds, writefds, exceptfds; + struct timeval seltimer; + + tty_status = 0; + now = time(NULL); + timeout = (time_t)300; /* maximum of 5 minutes */ + + for (i = 0; i < NUMTIMERS; i++) { + if (timer[i]) { + if (now >= timer[i]) { + tty_status = STAT_TIMEOUT; + WriteError("tty_putget: timer %d already expired, return",i); + return -tty_status; + } else { + if (timeout > (timer[i]-now)) + timeout=timer[i]-now; + } + } + } + + Syslog('t', "tty_putget: timeout=%d",timeout); + + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_ZERO(&exceptfds); + FD_SET(0,&readfds); + FD_SET(1,&writefds); + FD_SET(0,&exceptfds); + FD_SET(1,&exceptfds); + seltimer.tv_sec=timeout; + seltimer.tv_usec=0; + + rc=select(2,&readfds,&writefds,&exceptfds,&seltimer); + if (rc < 0) { + if (hanged_up) { + tty_status=STAT_HANGUP; + WriteError("tty_putget: hanged_up flag"); + } else { + WriteError("$tty_putget: select failed"); + tty_status=STAT_ERROR; + } + } else if (rc == 0) { + tty_status=STAT_TIMEOUT; + } else { + /* rc > 0 */ + if ((FD_ISSET(0,&exceptfds)) || (FD_ISSET(1,&exceptfds))) { + WriteError("$tty_putget: exeption error"); + tty_status=STAT_ERROR; + } + } + + if (tty_status) { + Syslog('t', "tty_putget: return after select status %s",ttystat[tty_status]); + return -tty_status; + } + + if (FD_ISSET(0,&readfds) && *isize) { + rc = read(0, *ibuf, *isize); + if (rc < 0) { + WriteError("$tty_putget: read failed"); + tty_status=STAT_ERROR; + } else { + (*ibuf)+=rc; + (*isize)-=rc; + } + } + + if (FD_ISSET(1,&writefds) && *osize) { + rc=write(1, *obuf, *osize); + if (rc < 0) { + WriteError("$tty_putget: write failed"); + tty_status=STAT_ERROR; + } else { + (*obuf)+=rc; + (*osize)-=rc; + } + } + + if (tty_status) + return -tty_status; + else + return ((*isize == 0) | ((*osize == 0) << 1)); +} + + diff --git a/mbsebbs/ttyio.h b/mbsebbs/ttyio.h new file mode 100644 index 00000000..164dc5d6 --- /dev/null +++ b/mbsebbs/ttyio.h @@ -0,0 +1,115 @@ +/* $Id */ + +#ifndef TTYIO_H +#define TTYIO_H + +#define TIMERNO_BRAIN 0 /* BRAIN timerno */ +#define TIMERNO_RX 1 /* Receiver timerno */ +#define TIMERNO_TX 2 /* Transmitter timerno */ + +#define RESETTIMER(x) tty_resettimer(x) +#define RESETTIMERS() tty_resettimers() +#define SETTIMER(x,y) tty_settimer(x,y) +#define EXPIRED(x) tty_expired(x) +#define RUNNING(x) tty_running(x) + +#define TCHECK() tty_check() +#define PUTCHECK(x) tty_putcheck(x) +#define WAITPUTGET(x) tty_waitputget(x) +#define FLUSHOUT() tty_flushout() +#define FLUSHIN() tty_flushin() +#define PUTCHAR(x) tty_putc(x) +#define PUT(x,y) tty_put(x,y) +#define PUTSTR(x) tty_put(x,strlen(x)) +#define GETCHAR(x) tty_getc(x) +#define UNGETCHAR(x) tty_ungetc(x) +#define GET(x,y,z) tty_get(x,y,z) +#define PUTGET(a,b,x,y) tty_putget(a,b,x,y) +#define STATUS tty_status + +#define STAT_SUCCESS 0 +#define STAT_ERROR 1 +#define STAT_TIMEOUT 2 +#define STAT_EOFILE 3 +#define STAT_HANGUP 4 +#define STAT_EMPTY 5 +#define STAT_UNCOMP 6 + +#define SUCCESS (STATUS == 0) +#define TERROR (-STAT_ERROR) +#define TIMEOUT (-STAT_TIMEOUT) +#define EOFILE (-STAT_EOFILE) +#define HANGUP (-STAT_HANGUP) +#define EMPTY (-STAT_EMPTY) + +#define GET_COMPLETE(x) (x & 1) +#define PUT_COMPLETE(x) (x & 2) + +#ifndef NUL +#define NUL 0x00 +#endif +#define SOH 0x01 +#define STX 0x02 +#define ETX 0x03 +#define EOT 0x04 +#define ENQ 0x05 +#define ACK 0x06 +#define BEL 0x07 +#define BS 0x08 +#define HT 0x09 +#define LF 0x0a +#define VT 0x0b +#ifndef FF +#define FF 0x0c +#endif +#ifndef CR +#define CR 0x0d +#endif +#define SO 0x0e +#define SI 0x0f +#define DLE 0x10 +#ifndef XON +#define XON 0x11 +#endif +#define DC1 0x11 +#define DC2 0x12 +#ifndef XOFF +#define XOFF 0x13 +#endif +#define DC3 0x13 +#define DC4 0x14 +#define NAK 0x15 +#define SYN 0x16 +#define ETB 0x17 +#define CAN 0x18 +#define EM 0x19 +#define SUB 0x1a +#ifndef ESC +#define ESC 0x1b +#endif +#define RS 0x1e +#define US 0x1f +#define TSYNC 0xae +#define YOOHOO 0xf1 + +extern int tty_status; + +extern int tty_resettimer(int tno); +extern void tty_resettimers(void); +extern int tty_settimer(int,int); +extern int tty_expired(int); +extern int tty_running(int); +extern int tty_check(void); +extern int tty_waitputget(int); +extern int tty_ungetc(int); +extern int tty_getc(int); +extern int tty_get(char*,int,int); +extern int tty_putcheck(int); +extern int tty_putc(int); +extern int tty_put(char*,int); +extern int tty_putget(char**,int*,char**,int*); +extern void tty_flushout(void); +extern void tty_flushin(void); +extern void sendbrk(void); + +#endif diff --git a/mbsebbs/user.c b/mbsebbs/user.c index cb0c684b..16a07059 100644 --- a/mbsebbs/user.c +++ b/mbsebbs/user.c @@ -50,6 +50,7 @@ #include "offline.h" #include "email.h" #include "term.h" +#include "ttyio.h" extern int sock; @@ -184,7 +185,8 @@ void user() * This should not happen. */ WriteError("$Can't open %s", temp); - printf("Can't open userfile, run \"newuser\" first"); + PUTSTR((char *)"Can't open userfile, run \"newuser\" first"); + Enter(1); ExitClient(MBERR_OK); } @@ -199,11 +201,14 @@ void user() if (!FoundName) { fclose(pUsrConfig); - printf("Unknown username: %s\n", sUnixName); + sprintf(temp, "Unknown username: %s\r\n", sUnixName); + PUTSTR(temp); /* FATAL ERROR: You are not in the BBS users file.*/ - printf("%s\n", (char *) Language(389)); + sprintf(temp, "%s\r\n", (char *) Language(389)); + PUTSTR(temp); /* Please run 'newuser' to create an account */ - printf("%s\n", (char *) Language(390)); + sprintf(temp, "%s\r\n", (char *) Language(390)); + PUTSTR(temp); Syslog('?', "FATAL: Could not find user in BBS users file."); Syslog('?', " and system is using unix accounts\n"); Free_Language(); @@ -285,7 +290,8 @@ void user() if (CFG.max_logins && (logins > CFG.max_logins)) { Syslog('+', "User logins %d, allowed %d, disconnecting", logins, CFG.max_logins); colour(LIGHTRED, BLACK); - printf("%s %d %s\n", (char *) Language(18), CFG.max_logins, (char *) Language(19)); + sprintf(temp, "%s %d %s\r\n", (char *) Language(18), CFG.max_logins, (char *) Language(19)); + PUTSTR(temp); Quick_Bye(MBERR_INIT_ERROR); } diff --git a/mbsebbs/userlist.c b/mbsebbs/userlist.c index b6e98c28..3d6613b8 100644 --- a/mbsebbs/userlist.c +++ b/mbsebbs/userlist.c @@ -37,13 +37,14 @@ #include "input.h" #include "timeout.h" #include "term.h" +#include "ttyio.h" void UserList(char *OpData) { FILE *pUsrConfig; int LineCount = 2, iFoundName = FALSE, iNameCount = 0; - char *Name, *sTemp, *User, *temp; + char *Name, *sTemp, *User, *temp, msg[81]; struct userhdr uhdr; struct userrec u; @@ -93,16 +94,18 @@ void UserList(char *OpData) if ((!u.Hidden) && (!u.Deleted)) { if ((strcasecmp(OpData, "/H")) == 0) { if ((strcmp(u.sHandle, "") != 0 && *(u.sHandle) != ' ')) - printf("%-25s", u.sHandle); + sprintf(msg, "%-25s", u.sHandle); else - printf("%-25s", u.sUserName); + sprintf(msg, "%-25s", u.sUserName); } else if (strcasecmp(OpData, "/U") == 0) { - printf("%-25s", u.Name); + sprintf(msg, "%-25s", u.Name); } else { - printf("%-25s", u.sUserName); + sprintf(msg, "%-25s", u.sUserName); } + PUTSTR(msg); - printf("%-30s%-14s%-11d", u.sLocation, StrDateDMY(u.tLastLoginDate), u.iTotalCalls); + sprintf(msg, "%-30s%-14s%-10d", u.sLocation, StrDateDMY(u.tLastLoginDate), u.iTotalCalls); + PUTSTR(msg); iFoundName = TRUE; LineCount++; iNameCount++; @@ -112,16 +115,18 @@ void UserList(char *OpData) } else if ((!u.Hidden) && (!u.Deleted) && (strlen(u.sUserName) > 0)) { if ((strcmp(OpData, "/H")) == 0) { if ((strcasecmp(u.sHandle, "") != 0 && *(u.sHandle) != ' ')) - printf("%-25s", u.sHandle); + sprintf(msg, "%-25s", u.sHandle); else - printf("%-25s", u.sUserName); + sprintf(msg, "%-25s", u.sUserName); } else if (strcasecmp(OpData, "/U") == 0) { - printf("%-25s", u.Name); + sprintf(msg, "%-25s", u.Name); } else { - printf("%-25s", u.sUserName); + sprintf(msg, "%-25s", u.sUserName); } - - printf("%-30s%-14s%-11d", u.sLocation, StrDateDMY(u.tLastLoginDate), u.iTotalCalls); + PUTSTR(msg); + + sprintf(msg, "%-30s%-14s%-10d", u.sLocation, StrDateDMY(u.tLastLoginDate), u.iTotalCalls); + PUTSTR(msg); iFoundName = TRUE; LineCount++; iNameCount++; diff --git a/mbsebbs/whoson.c b/mbsebbs/whoson.c index 0fe7ca3d..7ebcf116 100644 --- a/mbsebbs/whoson.c +++ b/mbsebbs/whoson.c @@ -37,6 +37,7 @@ #include "exitinfo.h" #include "whoson.h" #include "term.h" +#include "ttyio.h" extern int LC_Download, LC_Upload, LC_Read, LC_Chat, LC_Olr, LC_Door; @@ -50,7 +51,7 @@ extern int LC_Download, LC_Upload, LC_Read, LC_Chat, LC_Olr, LC_Door; void WhosOn(char *OpData) { char buf[128], *Heading, *Underline, *cnt, *isdoing, *location, *device; - char *fullname, *temp; + char *fullname, *temp, msg[81]; int i, x, Start = TRUE; FILE *fp; struct userhdr ushdr; @@ -73,7 +74,7 @@ void WhosOn(char *OpData) sprintf(Underline, "%s%c", Underline, exitinfo.GraphMode ? 196 : 45); colour(LIGHTRED, BLACK); Center(Underline); - printf("\n"); + Enter(1); /* Name Device Status Location */ pout(LIGHTGREEN, BLACK, (char *) Language(415)); @@ -126,51 +127,51 @@ void WhosOn(char *OpData) } free(temp); } - colour(LIGHTCYAN, BLACK); - printf("%-30s", fullname); + sprintf(msg, "%-30s", fullname); + pout(LIGHTCYAN, BLACK, msg); free(fullname); - colour(LIGHTBLUE, BLACK); - printf("%-9s", device); + sprintf(msg, "%-9s", device); + pout(LIGHTBLUE, BLACK, msg); free(device); + strtok(NULL, ","); location = xstrcpy(strtok(NULL, ",")); isdoing = xstrcpy(strtok(NULL, ",")); - colour(WHITE, BLACK); if (strstr(isdoing, "Browsing")) /* Browseng */ - printf("%-15s", (char *) Language(418)); + sprintf(msg, "%-15s", (char *) Language(418)); else if (strstr(isdoing, "Downloading")) /* Downloading */ - printf("%-15s", (char *) Language(419)); + sprintf(msg, "%-15s", (char *) Language(419)); else if (strstr(isdoing, "Uploading")) /* Uploading */ - printf("%-15s", (char *) Language(420)); + sprintf(msg, "%-15s", (char *) Language(420)); else if (strstr(isdoing, "Read")) /* Msg Section */ - printf("%-15s", (char *) Language(421)); + sprintf(msg, "%-15s", (char *) Language(421)); else if (strstr(isdoing, "External")) /* External Door */ - printf("%-15s", (char *) Language(422)); + sprintf(msg, "%-15s", (char *) Language(422)); else if (strstr(isdoing, "Chat")) /* Chatting */ - printf("%-15s", (char *) Language(423)); + sprintf(msg, "%-15s", (char *) Language(423)); else if (strstr(isdoing, "Files")) /* Listing Files */ - printf("%-15s", (char *) Language(424)); + sprintf(msg, "%-15s", (char *) Language(424)); else if (strstr(isdoing, "Time")) /* Banking Door */ - printf("%-15s", (char *) Language(426)); + sprintf(msg, "%-15s", (char *) Language(426)); else if (strstr(isdoing, "Safe")) /* Safe Door */ - printf("%-15s", (char *) Language(427)); + sprintf(msg, "%-15s", (char *) Language(427)); else if (strstr(isdoing, "Whoson")) /* WhosOn List */ - printf("%-15s", (char *) Language(428)); + sprintf(msg, "%-15s", (char *) Language(428)); else if (strstr(isdoing, "Offline")) /* Offline Reader */ - printf("%-15s", (char *) Language(429)); + sprintf(msg, "%-15s", (char *) Language(429)); else { /* * This is default when nothing matches, with doors this @@ -178,11 +179,13 @@ void WhosOn(char *OpData) */ if (strlen(isdoing) > 15) isdoing[15] = '\0'; - printf("%-15s", isdoing); + sprintf(msg, "%-15s", isdoing); } + pout(WHITE, BLACK, msg); - colour(LIGHTRED, BLACK); - printf("%-25s\n", location); + sprintf(msg, "%-25s", location); + pout(LIGHTRED, BLACK, msg); + Enter(1); free(location); free(isdoing); } @@ -194,8 +197,7 @@ void WhosOn(char *OpData) free(Underline); free(Heading); - - printf("\n"); + Enter(1); } @@ -277,20 +279,19 @@ void SendOnlineMsg(char *OpData) /* Please enter username to send message to: */ pout(CYAN, BLACK, (char *) Language(430)); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); GetstrC(User, 35); if (!strcmp(User, "")) { free(User); free(String); return; } + temp = calloc(PATH_MAX, sizeof(char)); /* * If we were displaying handles or real names, then lookup the * users unix name to send to mbtask. */ if ((strcasecmp(OpData, "/H") == 0) || (strlen(OpData) == 0)) { - temp = calloc(PATH_MAX, sizeof(char)); sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT")); if ((fp = fopen(temp, "rb")) != NULL) { fread(&ushdr, sizeof(ushdr), 1, fp); @@ -307,14 +308,13 @@ void SendOnlineMsg(char *OpData) } fclose(fp); } - free(temp); } /* Please enter message to send (Max 76 Characters) */ pout(LIGHTGREEN, BLACK, (char *)Language(433)); - pout(LIGHTGREEN, BLACK, (char *)"\n> "); + Enter(1); + pout(LIGHTGREEN, BLACK, (char *)"> "); colour(CFG.InputColourF, CFG.InputColourB); - fflush(stdout); GetstrC(String, 76); if ((strcmp(String, "")) != 0) { @@ -330,24 +330,33 @@ void SendOnlineMsg(char *OpData) strcpy(buf, socket_receive()); if (strncmp(buf, "100:1,3;", 8) == 0) { + Enter(1); /* Sorry, there is no user on */ - printf("\n%s %s\n\n", (char *) Language(431), User); + sprintf(temp, "%s %s", (char *) Language(431), User); + PUTSTR(temp); + Enter(1); } if (strncmp(buf, "100:1,2;", 8) == 0) { - printf("\nNo more room in users message buffer\n\n"); + Enter(1); + PUTSTR((char *)"No more room in users message buffer"); + Enter(2); } if (strncmp(buf, "100:1,1;", 8) == 0) { - colour(LIGHTRED, BLACK); + Enter(1); /* doesn't wish to be disturbed */ - printf("\n%s %s\n", User, (char *) Language(432)); + sprintf(temp, "%s %s", User, (char *) Language(432)); + pout(LIGHTRED, BLACK, temp); + Enter(1); } if (strncmp(buf, "100:0;", 6) == 0) { - printf("Message Sent!\n"); + PUTSTR((char *)"Message Sent!"); + Enter(1); Syslog('+', "Online msg to %s: \"%s\"", User, String); } } } + free(temp); free(User); free(String); Pause(); diff --git a/mbsetup/mutil.c b/mbsetup/mutil.c index 6737237c..80769bf5 100644 --- a/mbsetup/mutil.c +++ b/mbsetup/mutil.c @@ -47,7 +47,7 @@ unsigned char readkey(int y, int x, int fg, int bg) perror("open 9"); exit(MBERR_TTYIO_ERROR); } - Setraw(); + mbse_Setraw(); i = 0; while (rc == -1) { @@ -56,12 +56,12 @@ unsigned char readkey(int y, int x, int fg, int bg) mbse_locate(y, x); fflush(stdout); - rc = Waitchar(&ch, 5); + rc = mbse_Waitchar(&ch, 5); if ((rc == 1) && (ch != KEY_ESCAPE)) break; if ((rc == 1) && (ch == KEY_ESCAPE)) - rc = Escapechar(&ch); + rc = mbse_Escapechar(&ch); if (rc == 1) break; @@ -69,7 +69,7 @@ unsigned char readkey(int y, int x, int fg, int bg) Nopper(); } - Unsetraw(); + mbse_Unsetraw(); close(ttyfd); return ch; @@ -89,15 +89,15 @@ unsigned char testkey(int y, int x) perror("open 9"); exit(MBERR_TTYIO_ERROR); } - Setraw(); + mbse_Setraw(); - rc = Waitchar(&ch, 100); + rc = mbse_Waitchar(&ch, 100); if (rc == 1) { if (ch == KEY_ESCAPE) - rc = Escapechar(&ch); + rc = mbse_Escapechar(&ch); } - Unsetraw(); + mbse_Unsetraw(); close(ttyfd); if (rc == 1) diff --git a/script/editor.in b/script/editor.in index 7da43f8c..65083e6f 100644 --- a/script/editor.in +++ b/script/editor.in @@ -88,10 +88,10 @@ alarma $TIME $EDITOR & ## Draw header and call editor clear echo -e " -$LANGAREA: $AREANUM $AREA -\n$LANGFROM: $MSGFROM $MSGFROMADDR -\n$LANGTO: $MSGTO $MSGTOADDR -\n$LANGRE: $MSGSUBJECT +$LANGAREA: $AREANUM $AREA +\n$LANGFROM: $MSGFROM $MSGFROMADDR +\n$LANGTO: $MSGTO $MSGTOADDR +\n$LANGRE: $MSGSUBJECT \n" $EDITOR $PARAM ## kill alarm