mess822x 1.23
mess822x
Loading...
Searching...
No Matches
addrlist.c
Go to the documentation of this file.
1#include "buffer.h"
2#include "logmsg.h"
3#include "getln.h"
4#include "mess822.h"
5#include "exit.h"
6
7#define WHO "addrlist"
8
9static void nomem()
10{
11 logmsg(WHO,111,FATAL,"out of memory");
12}
13
14static void put(char *buf)
15{
16 char ch;
17
18 while ((ch = *buf)) {
19 if (ch == '\n') ch = 0;
20 buffer_put(buffer_1,&ch,1);
21 ++buf;
22 }
23}
24
25stralloc line = {0};
27
28stralloc addrlist = {0};
29stralloc quoted = {0};
30
31int main()
32{
33 int i;
34 int j;
35
36 for (;;) {
37 if (getln(buffer_0,&line,&match,'\n') == -1)
38 logmsg(WHO,111,FATAL,"unable to read input: ");
39 if (!line.len) break;
40 if (match) --line.len;
41
42 buffer_puts(buffer_1,"input {");
43 buffer_put(buffer_1,line.s,line.len);
44 buffer_puts(buffer_1,"}\n");
45
46 for (i = 0; i < line.len; ++i)
47 if (line.s[i] == 0)
48 line.s[i] = '\n';
49
50 if (!stralloc_0(&line)) nomem();
51
52 if (!mess822_addrlist(&addrlist,line.s)) nomem();
53
54 for (j = i = 0; j < addrlist.len; ++j)
55 if (!addrlist.s[j]) {
56 if (addrlist.s[i] == '(') {
57 buffer_puts(buffer_1,"comment {");
58 put(addrlist.s + i + 1);
59 buffer_puts(buffer_1,"}\n");
60 }
61 else if (addrlist.s[i] == '+') {
62 buffer_puts(buffer_1,"address {");
63 put(addrlist.s + i + 1);
64 buffer_puts(buffer_1,"}\n");
65 }
66 i = j + 1;
67 }
68
69 if (!mess822_quotelist(&quoted,&addrlist)) nomem();
70 buffer_puts(buffer_1,"rewrite {");
71 buffer_put(buffer_1,quoted.s,quoted.len);
72 buffer_puts(buffer_1,"}\n");
73
74 buffer_puts(buffer_1,"\n");
75 if (!match) break;
76 }
77
78 buffer_flush(buffer_1);
79 _exit(0);
80}
stralloc quoted
Definition: addrlist.c:29
stralloc line
Definition: addrlist.c:25
int match
Definition: addrlist.c:26
stralloc addrlist
Definition: addrlist.c:28
#define WHO
Definition: addrlist.c:7
int main()
Definition: addrlist.c:31
int mess822_addrlist(stralloc *, char *)
Definition: mess822_addr.c:119
int mess822_quotelist(stralloc *, stralloc *)