home *** CD-ROM | disk | FTP | other *** search
- /*
- * SHOWMAIL.C - Display messages
- *
- * Msged/Q message editor for QuickBBS Copyright 1990 by P.J. Muller
- *
- */
-
- #include <stdio.h>
- #include <io.h>
- #include <time.h>
- #include <string.h>
- #include <dos.h>
-
- #include "msged.h"
- #include "screen.h"
- #include "qmsgbase.h"
-
- #ifdef SHOWMEM
- #include <alloc.h>
- #endif
-
- LINE *top = NULL, *bottom = NULL;
-
- extern LINE *anchorpt; /* from editmail.c */
-
- static void up(void);
- static void down(void);
- static void pgdown(void);
- static void pgup(void);
- extern void putl(LINE *l);
- static int zeller(int day, int month, int year);
- #if defined(SHOWMEM) && (defined(__SMALL__) || defined(__MEDIUM__))
- static BOOLEAN ptrok(void);
- #endif
-
- int showmsg(m)
- MSG m;
- {
- int command;
-
- showheader(m);
-
- #ifdef SHOWMEM
- gotoxy(50,6);
- #if defined(__SMALL__) || defined(__MEDIUM__)
- { BOOLEAN ok = ptrok();
- if (!ok) fputc('\b', stderr);
- bprintf("left:%6u %s", coreleft(), ok ? "Ok " : "BAD");
- } /* island */
- #else
- bprintf("left:%8lu", (long)coreleft());
- #endif
- #endif
-
- refresh(msgbuf.first, 1);
-
- for (;;) {
- gotoxy(1,maxy);
- video_update();
- switch (command = getkey()) {
-
- case PGUP:
- if (msgbuf.first != NULL)
- pgup();
- break;
-
- case UP:
- if (msgbuf.first != NULL)
- up();
- break;
-
- case SPACE:
- case PGDN:
- if (msgbuf.first != NULL)
- pgdown();
- break;
-
- case DOWN:
- if (msgbuf.first != NULL)
- down();
- break;
-
- default:
- return (command);
- }
- }
- }
-
- void showheader(MSG m)
- {
- int num, of;
-
- set_color(co_info);
-
- clrwnd(1, 1, maxx, 6);
-
- gotoxy(1, 1);
-
- num = boardmsg(CurBoard, m.header.msgnum);
- of = countmsg(CurBoard);
- bprintf("%03d/%03d %s", num, of,
- timedate(m.header.posttime, m.header.postdate,!techie));
-
- gotoxy(1, 2);
- bputs("From: ");
- set_color(co_normal);
- bputs(m.header.from);
- set_color(co_info);
-
- if ((arealist[area].netmail) || (techie)) {
- bputs(" of ");
-
- set_color(co_normal);
- bputs(formaddr(m.from,Z_A|N_A|P_O|D_O|A_INT));
- }
-
- gotoxy(1, 3);
-
- set_color(co_info);
- bputs("To: ");
-
- if (strnicmp(username,m.header.to,strlen(username)) == 0)
- set_color(co_hilite);
- else set_color(co_normal);
-
- bputs(m.header.to);
- set_color(co_info);
-
- if ((arealist[area].netmail) || (techie)) {
- bputs(" of ");
-
- set_color(co_normal);
- bputs(formaddr(m.to,Z_A|N_A|P_O|D_O|A_INT));
- }
-
- gotoxy(1, 4);
-
- set_color(co_info);
- if (m.header.bits.is_file)
- bputs("Files: ");
- else
- bputs("Subj: ");
-
- set_color(co_normal);
- bputs(m.header.subj);
-
- gotoxy(1, 5);
-
- set_color(co_info);
- bputs("Attr: ");
- set_color(co_normal);
- bputs(bits2ascii(m.header.bits,techie));
-
- gotoxy(1, 6);
- { int c; for (c=1; c < maxx; c++) bputc('_'); }
- gotoxy(1, 6);
- set_color(co_hilite);
- bprintf("%s ", arealist[area].description);
- if (curmsg(CurBoard) == lastreadmsg(CurBoard))
- bputs("(highest read) ");
- set_color(co_info);
- if (num == of) {
- bputs("(last) ");
- }
-
- { char s[30];
- int margin = maxx;
-
- if (m.header.up) {
- sprintf(s, " \032 %d", m.header.up);
- margin -= strlen(s);
- gotoxy(margin, 6);
- set_color(co_hilite);
- bputs(s);
- }
- sprintf(s, " #%d", m.header.msgnum);
- margin -= strlen(s);
- gotoxy(margin, 6);
- set_color(co_info);
- bputs(s);
-
- if (m.header.reply) {
- sprintf(s, " %d \033", m.header.reply);
- margin -= strlen(s);
- gotoxy(margin, 6);
- set_color(co_hilite);
- bputs(s);
- }
- }
- set_color(co_normal);
-
- } /* showheader */
-
- char *bits2ascii(MSGBITS bits, BOOLEAN detailed)
- {
- static char buf[100];
-
- buf[0] = EOS;
-
- #define add(z,s) if ((bits.z) && (strlen(buf) < 80)) strcat(buf,s);
-
- add(is_priv, "private ");
- add(is_file, "f/a ");
- add(is_kill, "kill/sent ");
- add(is_crash, "crash ");
- add(is_rcvd, "recvd ");
- add(is_sent, "sent ");
- add(is_local, "local ");
-
- if (detailed) {
- add(is_del, "*del* ");
- add(is_transit, "nettr ");
- add(is_netm, "netmail ");
- add(is_echotr, "echotr ");
- add(is_reqrec, "reqrec ");
- add(is_audreq, "audreq ");
- add(is_retrec, "retrec ");
- } /* if */
-
- #undef add
-
- return buf;
- } /* bits2ascii */
-
- void up()
- {
- int i = 1;
-
- while (top->prev) {
- top = top->prev;
- if (shownotes || (*(top->text) != '\01')) {
- scrolldown(1, 7, maxx, maxy, 1);
- gotoxy(1, 7);
- putl(top);
- break;
- }
- }
-
- for (bottom = top;
- (bottom->next != NULL) && (i < (maxy - 6));
- bottom = bottom->next)
- if ((*(bottom->text) != '\01') || shownotes)
- i++;
- }
-
- void down()
- {
- int i = 1;
-
- while (bottom->next) {
- bottom = bottom->next;
- if (shownotes || (*(bottom->text) != '\01')) {
- scrollup(1, 7, maxx, maxy, 1);
- gotoxy(1, maxy);
- putl(bottom);
- break;
- }
- }
-
- for (top = bottom; (top->prev != NULL) && (i < (maxy - 6)); top = top->prev)
- if ((*(top->text) != '\01') || shownotes)
- i++;
- }
-
- void pgup()
- {
- int i = 0;
-
- if ((top->prev == NULL) || ((*(top->prev->text) == 1) && !shownotes))
- return;
-
- for (bottom = top; (top->prev != NULL) && (i < (maxy - 6)); top = top->prev)
- if ((*(top->text) != '\01') || shownotes)
- i++;
-
- refresh(top, 1);
- }
-
- void pgdown()
- {
- int i = 1;
-
- if ((bottom->next == NULL) || ((*(bottom->next->text) == 1) && !shownotes))
- return;
-
- clrwnd(1, 7, maxx, maxy);
-
- for (top = bottom; (bottom->next != NULL) && (i < (maxy - 6)); bottom = bottom->next) {
- if ((*(bottom->text) != '\01') || shownotes) {
- gotoxy(1, 6 + i++);
- putl(bottom);
- }
- }
- if ((*(bottom->text) != '\01') || shownotes) {
- gotoxy(1, 6 + i);
- putl(bottom);
- }
- }
-
- void refresh(LINE * c, int y)
- {
- int i = y;
-
- top = bottom = c;
- clrwnd(1, (i + 6), maxx, maxy);
-
- if ((top == NULL) || (top->text == NULL))
- return;
-
- while ((top != NULL) && ((*top->text == '\01') && !shownotes))
- top = top->next;
-
- if (top == NULL)
- return;
-
- for (bottom = top; (bottom->next != NULL) && (i < (maxy - 6)); bottom = bottom->next) {
- if ((*(bottom->text) != '\01') || shownotes) {
- gotoxy(1, 6 + i++);
- putl(bottom);
- }
- }
-
- if ((*(bottom->text) != '\01') || shownotes) {
- gotoxy(1, 6 + i);
- putl(bottom);
- }
- } /* refresh */
-
- #ifdef TEXTDATE
- static int diffdate(struct date *d2, struct date *d1)
- {
- struct time tim;
- long day1,day2;
-
- memset(&tim,0,sizeof tim);
- day1 = dostounix(d1,&tim);
- day2 = dostounix(d2,&tim);
-
- day1 /= 60L*60*24;
- day2 /= 60L*60*24;
-
- return day2-day1;
- } /* diffdate */
- #endif
-
- /*
- * Format the time and date for the screen
- * Return pointer to static area
- * Longform also has 'shortcuts', like "yesterday"
- */
-
- char *timedate(char *t, char *d, BOOLEAN longform)
- {
- static char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
- static char *days[7] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
- static char *longdays[7] = {"Sunday","Monday","Tuesday","Wednesday",
- "Thursday","Friday","Saturday"};
- static char buf[35];
- int day, mon, year, hour, min, weekday;
-
- sscanf(t, "%d:%d", &hour, &min);
- sscanf(d, "%d-%d-%d", &mon, &day, &year);
-
- weekday = zeller(day, mon, year);
-
- year = ((year < 80) ? year+2000 : year+1900);
-
- if (longform) {
- #ifdef TEXTDATE
- char text[30];
-
- struct date now,then;
- int numdays;
-
- getdate(&now);
- then.da_year = year; then.da_day = day; then.da_mon = mon;
- numdays = diffdate(&now,&then);
-
- switch (numdays) {
- case -1:
- strcpy(text," (Tommorrow)");
- break;
- case 0:
- strcpy(text," (Today)");
- break;
- case 1:
- strcpy(text," (Yesterday)");
- break;
-
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- sprintf(text, " (Last %s)", longdays[weekday]);
- break;
-
- default:
- text[0] = EOS;
- break;
- } /* switch */
- #endif
-
- sprintf(buf,"%3.3s %02d %3.3s %-4d %2d:%02d%c%s",
- days[weekday], day, months[mon-1], year,
- (hour%12) ? hour%12 : 12, min, (hour >= 12) ? 'p' : 'a',
- #ifdef TEXTDATE
- text
- #else
- ""
- #endif
- );
-
- } else {
- sprintf(buf,"%02d %3.3s %-4d %02d:%02d", day,
- months[mon-1], year, hour, min);
- } /* else */
-
- return(buf);
- } /* timedate */
-
- /*
- * day from 1-31, month from 1-12, year from 80
- * Returns 0 for Sunday, etc.
- */
-
- static int zeller(int day, int month, int year)
- {
- int age;
-
- age = (year < 80) ? 20 : 19;
- if ((month -= 2) <= 0) {
- month += 12;
- year--;
- } /* if */
-
- return(((26*month-2)/10 + day + year + year/4 + age/4 - 2*age) % 7);
- } /* zeller */
-
- /*
- * Check for bad pointer references in Turbo C
- */
-
- #if defined(SHOWMEM) && (defined(__SMALL__) || defined(__MEDIUM__))
- static BOOLEAN ptrok()
- {
- BYTE *s = 0;
- int sum = 0;
-
- while (s < (BYTE *)0x2f)
- sum += *s++;
-
- return(sum == 0x0D37);
-
- } /* ptrok */
- #endif
-
- char *formaddr(ADDRESS a, int mask)
- {
- static char buf[200];
- char temp[200];
-
- buf[0] = EOS;
-
- #ifdef INTERNETHACK
- if (mask & A_INT) {
- if (a.point != 0) {
- sprintf(temp, "p%d.", a.point);
- strcat(buf, temp);
- }
- sprintf(temp, "f%d.n%d.z%d.fidonet.org (", a.node, a.net, a.zone);
- strcat(buf, temp);
- }
- #endif
- if ((mask & Z_A) || ((mask & Z_O) && (a.zone != 0))) {
- sprintf(temp,"%d:",a.zone);
- strcat(buf,temp);
- } /* if */
- if ((mask & N_A) || ((mask & N_O) && (a.net != 0))) {
- sprintf(temp,"%d/%d",a.net,a.node);
- strcat(buf,temp);
- } /* if */
- if ((mask & P_A) || ((mask & P_O) && (a.point != 0))) {
- sprintf(temp,".%d",a.point);
- strcat(buf,temp);
- } /* if */
- if (((mask & D_A) || (mask & D_O)) && (a.domain != NULL)) {
- sprintf(temp,"@%s",a.domain);
- strcat(buf,temp);
- } /* if */
- #ifdef INTERNETHACK
- if (mask & A_INT) {
- strcat(buf, ")");
- }
- #endif
-
- return buf;
- } /* formaddr */