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
33 * replacement strerror() for systems that don't have it
39 sprintf(buf,"errno = %d",e);
48 int a,b,e,mtype,aflag;
54 if (argc==2) if (!strcmp(argv[1],"-q")) qwk = 1;
56 if (argc==2) if (strcmp(argv[1],"-q")) {
57 fp = fopen(argv[1],"r");
59 fprintf(stderr,"%s: cannot open %s: %s\n",
60 argv[0],argv[1],strerror(errno));
70 mtype=getc(fp); aflag=getc(fp);
71 if (qwk == 0) printf(" ");
78 if (strlen(subject)!=0)
79 printf("Subject: %s\n",subject);
81 if (aflag!=1) fmout(80,fp);
82 else while(a=getc(fp), a>0) {
83 if (a==13) putc(10,stdout);
87 if ((b!='M')&&(b>0)) fpgetfield(fp,bbb);
88 if (b=='U') strcpy(subject,bbb);
90 if (b=='A') printf("from %s ",bbb);
91 if (b=='N') printf("@%s ",bbb);
92 if (b=='O') printf("in %s> ",bbb);
93 if (b=='R') printf("to %s ",bbb);
96 tm=(struct tm *)localtime(&now);
97 strcpy(bbb,asctime(tm)); bbb[strlen(bbb)-1]=0;
98 printf("%s ",&bbb[4]);
101 } while ((b!='M')&&(b>0));
102 if (qwk==0) printf("\n");
107 int fpgetfield(fp,string) /* level-2 break out next null-terminated string */
116 if (b<1) { string[a]=0; return(0); }
132 strcpy(aaa,""); old=255;
133 c=1; /* c is the current pos */
134 FMTA: old=real; a=getc(fp); real=a;
135 if (a<=0) goto FMTEND;
137 if ( ((a==13)||(a==10)) && (old!=13) && (old!=10) ) a=32;
138 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
140 if (a>126) goto FMTA;
143 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
144 { printf("\n%s",aaa); c=strlen(aaa); aaa[0]=0; }
145 b=strlen(aaa); aaa[b]=a; aaa[b+1]=0; }
146 if (a==32) { if ((strlen(aaa)+c)>(width-5)) {
150 printf("%s ",aaa); ++c; c=c+strlen(aaa);
151 strcpy(aaa,""); goto FMTA; }
152 if ((a==13)||(a==10)) {
153 printf("%s\n",aaa); c=1;
154 strcpy(aaa,""); goto FMTA; }
157 FMTEND: printf("\n");