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