Implemented RTS/CTS handshaking (-C/--rtscts vs. -x/--xonxoff)
[mdsms.git] / manfmt.c
1 #include "config.h"
2 #ifndef lint
3 static char rcsid[] ATTR_UNUSED = "$Id$";
4 #endif
5
6 #ifdef HAVE_STDIO_H
7 #include <stdio.h>
8 #endif
9 #ifdef HAVE_STDLIB_H
10 #include <stdlib.h>
11 #endif
12 #ifdef HAVE_STRING_H
13 #include <string.h>
14 #endif
15 #ifdef HAVE_LIMITS_H
16 #include <limits.h>
17 #endif
18
19 static char buf[LINE_MAX];
20
21 int main(void)
22 {
23 char *s,*s2,*d;
24 char f;
25
26         while (fgets(buf,sizeof(buf),stdin)) {
27                 if (*buf=='#') continue;
28                 for (s=buf;*s==' ';s++);
29                 if (*s=='\n' || !*s) continue;
30                 f=0;
31                 for (d=s=buf;*s;s++) {
32                         if (*s=='\t') {
33                                 if ((f=!f)) {
34 /*fprintf(stderr,"DURING TURN-ON:%s",s);*/
35                                         while (s[1]==' ') s++;
36                                         if (s[1]=='"') s++;
37                                         }
38                                 else {
39 /*fprintf(stderr,"DURING TURN-OFF:%s",s);*/
40                                         while (d>buf && (d[-1]=='"' || d[-1]==' ')) d--;
41                                         }
42                                 continue;
43                                 }
44                         s2=s;
45                         if (*s=='~' ) *s='"';
46                         else if (f && s[0]=='"' && s[1]==' ') {
47                                 while (*++s==' ');
48                                 if (*s=='"') continue;
49                                 s=s2;
50                                 }
51                         *d++=*s;
52                         }
53                 *d='\0';
54                 fputs(buf,stdout);
55                 }
56         return(EXIT_SUCCESS);
57 }