3 * see copyright.doc for copyright information
5 * This is simply a filter that converts Citadel binary message format
6 * to readable, formatted output.
8 * If the -q (quiet or qwk) flag is used, only the message text prints, and
9 * then it stops at the end of the first message it prints.
10 * This is used by the QWK reader for Citadel/UX during message format
27 int fpgetfield(FILE *fp, char *string);
28 int fmout(int width, FILE *fp);
33 * replacement strerror() for systems that don't have it
39 sprintf(buf,"errno = %d",e);
44 int main(int argc, char **argv)
47 int a,b,e,mtype,aflag;
53 if (argc==2) if (!strcmp(argv[1],"-q")) qwk = 1;
55 if (argc==2) if (strcmp(argv[1],"-q")) {
56 fp = fopen(argv[1],"r");
58 fprintf(stderr,"%s: cannot open %s: %s\n",
59 argv[0],argv[1],strerror(errno));
69 mtype=getc(fp); aflag=getc(fp);
70 if (qwk == 0) printf(" ");
77 if (strlen(subject)!=0)
78 printf("Subject: %s\n",subject);
80 if (aflag!=1) fmout(80,fp);
81 else while(a=getc(fp), a>0) {
82 if (a==13) putc(10,stdout);
86 if ((b!='M')&&(b>0)) fpgetfield(fp,bbb);
87 if (b=='U') strcpy(subject,bbb);
89 if (b=='A') printf("from %s ",bbb);
90 if (b=='N') printf("@%s ",bbb);
91 if (b=='O') printf("in %s> ",bbb);
92 if (b=='R') printf("to %s ",bbb);
95 tm=(struct tm *)localtime(&now);
96 strcpy(bbb,asctime(tm)); bbb[strlen(bbb)-1]=0;
97 printf("%s ",&bbb[4]);
100 } while ((b!='M')&&(b>0));
101 if (qwk==0) printf("\n");
106 int fpgetfield(FILE *fp, char *string) /* level-2 break out next null-terminated string */
115 if (b<1) { string[a]=0; return(0); }
122 int fmout(int width, FILE *fp)
129 strcpy(aaa,""); old=255;
130 c=1; /* c is the current pos */
131 FMTA: old=real; a=getc(fp); real=a;
132 if (a<=0) goto FMTEND;
134 if ( ((a==13)||(a==10)) && (old!=13) && (old!=10) ) a=32;
135 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
137 if (a>126) goto FMTA;
140 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
141 { printf("\n%s",aaa); c=strlen(aaa); aaa[0]=0; }
142 b=strlen(aaa); aaa[b]=a; aaa[b+1]=0; }
143 if (a==32) { if ((strlen(aaa)+c)>(width-5)) {
147 printf("%s ",aaa); ++c; c=c+strlen(aaa);
148 strcpy(aaa,""); goto FMTA; }
149 if ((a==13)||(a==10)) {
150 printf("%s\n",aaa); c=1;
151 strcpy(aaa,""); goto FMTA; }
154 FMTEND: printf("\n");