4 * This is simply a filter that converts Citadel binary message format
5 * to readable, formatted output.
7 * If the -q (quiet or qwk) flag is used, only the message text prints, and
8 * then it stops at the end of the first message it prints.
9 * This is used by the QWK reader for Citadel/UX during message format
22 #if TIME_WITH_SYS_TIME
23 # include <sys/time.h>
27 # include <sys/time.h>
38 int fpgetfield(FILE *fp, char *string);
39 int fmout(int width, FILE *fp);
44 * replacement strerror() for systems that don't have it
50 snprintf(buf, sizeof buf, "errno = %d",e);
55 int main(int argc, char **argv)
58 int a,b,e,mtype,aflag;
64 if (argc==2) if (!strcmp(argv[1],"-q")) qwk = 1;
66 if (argc==2) if (strcmp(argv[1],"-q")) {
67 fp = fopen(argv[1],"r");
69 fprintf(stderr,"%s: cannot open %s: %s\n",
70 argv[0],argv[1],strerror(errno));
80 mtype=getc(fp); aflag=getc(fp);
81 if (qwk == 0) printf(" ");
88 if (strlen(subject)!=0)
89 printf("Subject: %s\n",subject);
91 if (aflag!=1) fmout(80,fp);
92 else while(a=getc(fp), a>0) {
93 if (a==13) putc(10,stdout);
97 if ((b!='M')&&(b>0)) fpgetfield(fp,bbb);
98 if (b=='U') strcpy(subject,bbb);
100 if (b=='A') printf("from %s ",bbb);
101 if (b=='N') printf("@%s ",bbb);
102 if (b=='O') printf("in %s> ",bbb);
103 if (b=='R') printf("to %s ",bbb);
106 tm=(struct tm *)localtime(&now);
107 strcpy(bbb,asctime(tm)); bbb[strlen(bbb)-1]=0;
108 printf("%s ",&bbb[4]);
111 } while ((b!='M')&&(b>0));
112 if (qwk==0) printf("\n");
117 int fpgetfield(FILE *fp, char *string) /* level-2 break out next null-terminated string */
126 if (b<1) { string[a]=0; return(0); }
133 int fmout(int width, FILE *fp)
140 strcpy(aaa,""); old=255;
141 c=1; /* c is the current pos */
142 FMTA: old=real; a=getc(fp); real=a;
143 if (a<=0) goto FMTEND;
145 if ( ((a==13)||(a==10)) && (old!=13) && (old!=10) ) a=32;
146 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
148 if (a>126) goto FMTA;
151 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
152 { printf("\n%s",aaa); c=strlen(aaa); aaa[0]=0; }
153 b=strlen(aaa); aaa[b]=a; aaa[b+1]=0; }
154 if (a==32) { if ((strlen(aaa)+c)>(width-5)) {
158 printf("%s ",aaa); ++c; c=c+strlen(aaa);
159 strcpy(aaa,""); goto FMTA; }
160 if ((a==13)||(a==10)) {
161 printf("%s\n",aaa); c=1;
162 strcpy(aaa,""); goto FMTA; }
165 FMTEND: printf("\n");