| 1 | #include "substdio.h" |
| 2 | #include "subfd.h" |
| 3 | #include "strerr.h" |
| 4 | #include "stralloc.h" |
| 5 | #include "getln.h" |
| 6 | |
| 7 | #define FATAL "printmaillist: fatal: " |
| 8 | |
| 9 | void badformat() |
| 10 | { |
| 11 | strerr_die2x(100,FATAL,"bad mailing list format"); |
| 12 | } |
| 13 | |
| 14 | stralloc line = {0}; |
| 15 | int match; |
| 16 | |
| 17 | void main() |
| 18 | { |
| 19 | for (;;) { |
| 20 | if (getln(subfdinsmall,&line,&match,'\0') == -1) |
| 21 | strerr_die2sys(111,FATAL,"unable to read input: "); |
| 22 | if (!match) { |
| 23 | if (line.len) |
| 24 | badformat(); |
| 25 | if (substdio_flush(subfdoutsmall) == -1) |
| 26 | strerr_die2sys(111,FATAL,"unable to write output: "); |
| 27 | _exit(0); |
| 28 | } |
| 29 | |
| 30 | if (line.s[str_chr(line.s,'\n')]) badformat(); |
| 31 | if (line.s[line.len - 1] == ' ') badformat(); |
| 32 | if (line.s[line.len - 1] == '\t') badformat(); |
| 33 | |
| 34 | if ((line.s[0] == '.') || (line.s[0] == '/')) { |
| 35 | if (substdio_puts(subfdoutsmall,line.s) == -1) |
| 36 | strerr_die2sys(111,FATAL,"unable to write output: "); |
| 37 | if (substdio_puts(subfdoutsmall,"\n") == -1) |
| 38 | strerr_die2sys(111,FATAL,"unable to write output: "); |
| 39 | continue; |
| 40 | } |
| 41 | if (line.s[0] == '&') { |
| 42 | if (line.len > 900) badformat(); |
| 43 | if (substdio_puts(subfdoutsmall,line.s) == -1) |
| 44 | strerr_die2sys(111,FATAL,"unable to write output: "); |
| 45 | if (substdio_puts(subfdoutsmall,"\n") == -1) |
| 46 | strerr_die2sys(111,FATAL,"unable to write output: "); |
| 47 | continue; |
| 48 | } |
| 49 | |
| 50 | badformat(); |
| 51 | } |
| 52 | } |