home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
b
/
bmh02src.zip
/
SHOW.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-16
|
3KB
|
114 lines
/*
show.c : Copyright Paul Healy, EI9GL, 1992.
911227 : Added this header
920620 : Version 0.1
- doesn't remember current folder
- doesn't support listing of a subrange
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "buffer.h"
#include "rc.h"
#include "misc.h"
#include "help.h"
#include "pager.h"
#include "current.h"
#ifdef BMH
#define main show_main
#endif
static int started_page = 0;
static int
showmsg(FILE *fp, int i, char **start, char **end)
{
char line[256];
if (!started_page) {
started_page = 1;
page_setup();
}
sprintf(line, "(Message %s:%d)", currentfolder(NULL), i); /* no \n ?? */
(void) page_puts(line);
while (getstring(start, end, line, sizeof(line)) != NULL) {
if (strncmp(line, "From ", 5) == 0) {
fflush(fp);
return 1; /* have hit next message */
}
else if (fp == stdout)
(void) page_puts(line); /* need to move to the next msg anyway */
else {
if (line[0] != '\0') /* fputs returns EOF on being asked to */
/* write an empty string... */
if ( fputs(line, fp) == EOF ) {
fprintf(stderr, "showmsg: error writing message # %d\n", i);
return -1;
}
if ( fputc('\n', fp) == EOF) {
fprintf(stderr, "showmsg: error writing message # %d\n", i);
return -1;
}
}
}
return 0;
}
static void
readmsgs(FILE *fp, char *p, char *end, int argc, char *argv[], int msg)
{
char s[256];
int i = 0;
while (1) {
while ( *p!='F' )
p++;
if ( (p==end) && (refill(&p, &end) != 0) )
break;
else { /* may have found a From */
if (*(p-1) != '\n') {
p++;
continue;
}
getstring(&p, &end, s, sizeof(s));
if (strncmp(s, "From ", 5) == 0) {
i++;
while(wanted(i, argc, argv, msg) == 1)
if (showmsg(fp, i, &p, &end) == 0)
return ; /* eof */
else
i++;
}
}
}
}
int
main(int argc, char *argv[])
{
char *p, *end, *s;
int msg;
dohelp(argc, argv, "show [+folder] <msg 1> ... <msg n>");
if (setupbm()==-1)
return -1;
if (getcurrent(argc, argv, &s, &msg) == -1)
return -1;
if (loadmail("show", s, &p, &end) == -1)
return -1;
started_page = 0;
readmsgs(stdout, p, end, argc, argv, msg);
return lastmsg(argc, argv);
}