diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-03 15:52:39 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-03 15:52:39 +0200 |
commit | a6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch) | |
tree | b88cc7a8457658d67e0321718556ac807f6bccf3 /src/printforward.c | |
parent | 00be7622c428f279872f84569f098ce16150f8a8 (diff) |
format files
Diffstat (limited to 'src/printforward.c')
-rw-r--r-- | src/printforward.c | 69 |
1 files changed, 30 insertions, 39 deletions
diff --git a/src/printforward.c b/src/printforward.c index 0ab7ad9..594ccad 100644 --- a/src/printforward.c +++ b/src/printforward.c @@ -1,43 +1,40 @@ #include <unistd.h> + #include "buffer.h" +#include "cdbread.h" #include "logmsg.h" #include "stralloc.h" -#include "cdbread.h" #define WHO "printmaillist" void badformat() { - logmsg(WHO,100,FATAL,"bad database format"); + logmsg(WHO, 100, FATAL, "bad database format"); } void nomem() { - logmsg(WHO,111,FATAL,"out of memory"); + logmsg(WHO, 111, FATAL, "out of memory"); } void getch(char *ch) { int r; - r = buffer_get(buffer_0small,ch,1); - if (r == -1) - logmsg(WHO,111,FATAL,"unable to read input"); - if (r == 0) - badformat(); + r = buffer_get(buffer_0small, ch, 1); + if (r == -1) logmsg(WHO, 111, FATAL, "unable to read input"); + if (r == 0) badformat(); } void out(char *ch) { - if (buffer_put(buffer_1small,ch,1) == -1) - logmsg(WHO,111,FATAL,"unable to write output"); + if (buffer_put(buffer_1small, ch, 1) == -1) logmsg(WHO, 111, FATAL, "unable to write output"); } void printbuf(char *buf) { - while (*buf) - out(buf++); + while (*buf) out(buf++); } -void printsafe(char *buf,int len) +void printsafe(char *buf, int len) { char ch; @@ -65,12 +62,10 @@ int main() int i; int j; - for (i = 0; i < 4; ++i) - getch(buf + i); + for (i = 0; i < 4; ++i) getch(buf + i); eod = cdb_unpack(buf); - for (i = 4; i < 2048; ++i) - getch(&ch); + for (i = 4; i < 2048; ++i) getch(&ch); pos = 2048; while (pos < eod) { @@ -80,33 +75,32 @@ int main() klen = cdb_unpack(buf); dlen = cdb_unpack(buf + 4); - if (!stralloc_copys(&key,"")) nomem(); + if (!stralloc_copys(&key, "")) nomem(); if (eod - pos < klen) badformat(); pos += klen; while (klen) { --klen; getch(&ch); - if (!stralloc_append(&key,&ch)) nomem(); + if (!stralloc_append(&key, &ch)) nomem(); } if (eod - pos < dlen) badformat(); pos += dlen; - if (!stralloc_copys(&data,"")) nomem(); + if (!stralloc_copys(&data, "")) nomem(); while (dlen) { --dlen; getch(&ch); - if (!stralloc_append(&data,&ch)) nomem(); + if (!stralloc_append(&data, &ch)) nomem(); } if (!key.len) badformat(); if (key.s[0] == '?') { - printsafe(key.s + 1,key.len - 1); + printsafe(key.s + 1, key.len - 1); printbuf(": ?"); - printsafe(data.s,data.len); + printsafe(data.s, data.len); printbuf(";\n"); - } - else if (key.s[0] == ':') { - printsafe(key.s + 1,key.len - 1); + } else if (key.s[0] == ':') { + printsafe(key.s + 1, key.len - 1); printbuf(":\n"); i = 0; @@ -114,29 +108,26 @@ int main() if (!data.s[j]) { if ((data.s[i] == '.') || (data.s[i] == '/')) { printbuf(", "); - printsafe(data.s + i,j - i); + printsafe(data.s + i, j - i); printbuf("\n"); - } - else if ((data.s[i] == '|') || (data.s[i] == '!')) { + } else if ((data.s[i] == '|') || (data.s[i] == '!')) { printbuf(", "); - printsafe(data.s + i,j - i); + printsafe(data.s + i, j - i); printbuf("\n"); - } - else if ((data.s[i] == '&') && (j - i < 900)) { + } else if ((data.s[i] == '&') && (j - i < 900)) { printbuf(", "); - printsafe(data.s + i,j - i); + printsafe(data.s + i, j - i); printbuf("\n"); - } - else badformat(); + } else + badformat(); i = j + 1; } if (i != j) badformat(); printbuf(";\n"); - } - else badformat(); + } else + badformat(); } - if (buffer_flush(buffer_1small) == -1) - logmsg(WHO,111,FATAL,"unable to write output"); + if (buffer_flush(buffer_1small) == -1) logmsg(WHO, 111, FATAL, "unable to write output"); _exit(0); } |