From a6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 15:52:39 +0200 Subject: format files --- src/qmail-qread.c | 189 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 120 insertions(+), 69 deletions(-) (limited to 'src/qmail-qread.c') diff --git a/src/qmail-qread.c b/src/qmail-qread.c index 888c14a..039af0c 100644 --- a/src/qmail-qread.c +++ b/src/qmail-qread.c @@ -1,43 +1,61 @@ -#include -#include #include -#include "stralloc.h" +#include +#include + +#include "error.h" +#include "exit.h" #include "fmt.h" -#include "str.h" #include "getln.h" -#include "fmtqfn.h" -#include "readsubdir.h" -#include "auto_qmail.h" #include "open.h" -#include "datetime.h" +#include "str.h" +#include "stralloc.h" + +#include "auto_qmail.h" #include "date822fmt.h" -#include "error.h" -#include "exit.h" +#include "datetime.h" +#include "fmtqfn.h" +#include "readsubdir.h" readsubdir rs; -void die(int n) { buffer_flush(buffer_1); _exit(n); } +void die(int n) +{ + buffer_flush(buffer_1); + _exit(n); +} -void warn(char *s1,char *s2) +void warn(char *s1, char *s2) { - char *x; - x = error_str(errno); - buffer_puts(buffer_1,s1); - buffer_puts(buffer_1,s2); - buffer_puts(buffer_1,": "); - buffer_puts(buffer_1,x); - buffer_puts(buffer_1,"\n"); + char *x; + x = error_str(errno); + buffer_puts(buffer_1, s1); + buffer_puts(buffer_1, s2); + buffer_puts(buffer_1, ": "); + buffer_puts(buffer_1, x); + buffer_puts(buffer_1, "\n"); } -void die_nomem() { buffer_puts(buffer_1,"fatal: out of memory\n"); die(111); } -void die_chdir() { warn("fatal: unable to chdir",""); die(110); } -void die_opendir(fn) char *fn; { warn("fatal: unable to opendir ",fn); die(110); } +void die_nomem() +{ + buffer_puts(buffer_1, "fatal: out of memory\n"); + die(111); +} +void die_chdir() +{ + warn("fatal: unable to chdir", ""); + die(110); +} +void die_opendir(fn) char *fn; +{ + warn("fatal: unable to opendir ", fn); + die(110); +} void err(unsigned long id) { - char foo[FMT_ULONG]; - foo[fmt_ulong(foo,id)] = 0; - warn("warning: trouble with #",foo); + char foo[FMT_ULONG]; + foo[fmt_ulong(foo, id)] = 0; + warn("warning: trouble with #", foo); } char fnmess[FMTQFN]; @@ -61,40 +79,64 @@ unsigned int fmtstats(char *s) unsigned int i; len = 0; - datetime_tai(&dt,qtime); - i = date822fmt(s,&dt) - 7/*XXX*/; len += i; if (s) s += i; - i = fmt_str(s," GMT #"); len += i; if (s) s += i; - i = fmt_ulong(s,id); len += i; if (s) s += i; - i = fmt_str(s," "); len += i; if (s) s += i; - i = fmt_ulong(s,size); len += i; if (s) s += i; - i = fmt_str(s," <"); len += i; if (s) s += i; - i = fmt_str(s,sender.s + 1); len += i; if (s) s += i; - i = fmt_str(s,"> "); len += i; if (s) s += i; + datetime_tai(&dt, qtime); + i = date822fmt(s, &dt) - 7 /*XXX*/; + len += i; + if (s) s += i; + i = fmt_str(s, " GMT #"); + len += i; + if (s) s += i; + i = fmt_ulong(s, id); + len += i; + if (s) s += i; + i = fmt_str(s, " "); + len += i; + if (s) s += i; + i = fmt_ulong(s, size); + len += i; + if (s) s += i; + i = fmt_str(s, " <"); + len += i; + if (s) s += i; + i = fmt_str(s, sender.s + 1); + len += i; + if (s) s += i; + i = fmt_str(s, "> "); + len += i; + if (s) s += i; if (flagbounce) { - i = fmt_str(s," bouncing"); len += i; if (s) s += i; + i = fmt_str(s, " bouncing"); + len += i; + if (s) s += i; } - return len; + return len; } stralloc stats = {0}; -void out(char *s,unsigned int n) +void out(char *s, unsigned int n) { while (n > 0) { - buffer_put(buffer_1,((*s >= 32) && (*s <= 126)) ? s : "_",1); + buffer_put(buffer_1, ((*s >= 32) && (*s <= 126)) ? s : "_", 1); --n; ++s; } } -void outs(char *s) { out(s,str_len(s)); } -void outok(char *s) { buffer_puts(buffer_1,s); } +void outs(char *s) +{ + out(s, str_len(s)); +} +void outok(char *s) +{ + buffer_puts(buffer_1, s); +} void putstats() { - if (!stralloc_ready(&stats,fmtstats(FMT_LEN))) die_nomem(); + if (!stralloc_ready(&stats, fmtstats(FMT_LEN))) die_nomem(); stats.len = fmtstats(stats.s); - out(stats.s,stats.len); + out(stats.s, stats.len); outok("\n"); } @@ -111,25 +153,35 @@ int main() if (chdir(auto_qmail) == -1) die_chdir(); if (chdir("queue") == -1) die_chdir(); - readsubdir_init(&rs,"info",die_opendir); + readsubdir_init(&rs, "info", die_opendir); - while ((x = readsubdir_next(&rs,&id))) + while ((x = readsubdir_next(&rs, &id))) if (x > 0) { - fmtqfn(fnmess,"mess/",id,1); - fmtqfn(fninfo,"info/",id,1); - fmtqfn(fnlocal,"local/",id,1); - fmtqfn(fnremote,"remote/",id,1); - fmtqfn(fnbounce,"bounce/",id,0); - - if (stat(fnmess,&st) == -1) { err(id); continue; } + fmtqfn(fnmess, "mess/", id, 1); + fmtqfn(fninfo, "info/", id, 1); + fmtqfn(fnlocal, "local/", id, 1); + fmtqfn(fnremote, "remote/", id, 1); + fmtqfn(fnbounce, "bounce/", id, 0); + + if (stat(fnmess, &st) == -1) { + err(id); + continue; + } size = st.st_size; - flagbounce = !stat(fnbounce,&st); + flagbounce = !stat(fnbounce, &st); fd = open_read(fninfo); - if (fd == -1) { err(id); continue; } - buffer_init(&b,read,fd,inbuf,sizeof(inbuf)); - if (getln(&b,&sender,&match,0) == -1) die_nomem(); - if (fstat(fd,&st) == -1) { close(fd); err(id); continue; } + if (fd == -1) { + err(id); + continue; + } + buffer_init(&b, read, fd, inbuf, sizeof(inbuf)); + if (getln(&b, &sender, &match, 0) == -1) die_nomem(); + if (fstat(fd, &st) == -1) { + close(fd); + err(id); + continue; + } close(fd); qtime = st.st_mtime; @@ -141,22 +193,21 @@ int main() if (errno != ENOENT) err(id); } else { for (;;) { - if (getln(&b,&line,&match,0) == -1) die_nomem(); - if (!match) break; - switch (line.s[0]) { - case 'D': - outok(" done"); - case 'T': - outok(channel ? "\tremote\t" : "\tlocal\t"); - outs(line.s + 1); - outok("\n"); - break; - } + if (getln(&b, &line, &match, 0) == -1) die_nomem(); + if (!match) break; + switch (line.s[0]) { + case 'D': outok(" done"); + case 'T': + outok(channel ? "\tremote\t" : "\tlocal\t"); + outs(line.s + 1); + outok("\n"); + break; + } } close(fd); } - } - } + } + } die(0); } -- cgit v1.2.3