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