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/columnt.c | |
parent | 00be7622c428f279872f84569f098ce16150f8a8 (diff) |
format files
Diffstat (limited to 'src/columnt.c')
-rw-r--r-- | src/columnt.c | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/src/columnt.c b/src/columnt.c index 9e4cf0e..638c078 100644 --- a/src/columnt.c +++ b/src/columnt.c @@ -1,21 +1,31 @@ #include <unistd.h> + #include "alloc.h" -#include "logmsg.h" #include "buffer.h" -#include "stralloc.h" #include "exit.h" +#include "logmsg.h" #include "readclose.h" +#include "stralloc.h" #define WHO "columnt" #define BSIZE 4096 char outbuf[BSIZE]; -buffer bo = BUFFER_INIT(write,1,outbuf,sizeof(outbuf)); +buffer bo = BUFFER_INIT(write, 1, outbuf, sizeof(outbuf)); -void nomem() { logmsg(WHO,111,FATAL,"out of memory"); } -void die_read() { logmsg(WHO,110,ERROR,"unable to read input: "); } -void die_write() { logmsg(WHO,110,ERROR,"unable to write output: "); } +void nomem() +{ + logmsg(WHO, 111, FATAL, "out of memory"); +} +void die_read() +{ + logmsg(WHO, 110, ERROR, "unable to read input: "); +} +void die_write() +{ + logmsg(WHO, 110, ERROR, "unable to write output: "); +} stralloc file = {0}; int *width; @@ -28,15 +38,15 @@ void nothing() void printline() { - if (buffer_put(&bo,"\n",1) == -1) die_write(); + if (buffer_put(&bo, "\n", 1) == -1) die_write(); } -void maxfield_check(int fieldnum,char *buf,int len) +void maxfield_check(int fieldnum, char *buf, int len) { if (fieldnum > maxfield) maxfield = fieldnum; } -void width_check(int fieldnum,char *buf,int len) +void width_check(int fieldnum, char *buf, int len) { if (len > width[fieldnum]) width[fieldnum] = len; } @@ -45,24 +55,23 @@ void width_init() { int i; - width = (int *) alloc((maxfield + 1) * sizeof(int)); + width = (int *)alloc((maxfield + 1) * sizeof(int)); if (!width) nomem(); - for (i = 0; i <= maxfield; ++i) - width[i] = 0; + for (i = 0; i <= maxfield; ++i) width[i] = 0; } -void printfield(int fieldnum,char *buf,int len) +void printfield(int fieldnum, char *buf, int len) { int i; if (fieldnum < maxfield) for (i = len; i < width[fieldnum]; ++i) - if (buffer_put(&bo," ",1) == -1) die_write(); + if (buffer_put(&bo, " ", 1) == -1) die_write(); - if (buffer_put(&bo,buf,len) == -1) die_write(); + if (buffer_put(&bo, buf, len) == -1) die_write(); if (fieldnum < maxfield) - if (buffer_put(&bo," ",2) == -1) die_write(); + if (buffer_put(&bo, " ", 2) == -1) die_write(); } void split(void (*dofield)(), void (*doline)()) @@ -80,7 +89,7 @@ void split(void (*dofield)(), void (*doline)()) if (i == j) break; fieldpos = i; while ((file.s[i] != ' ') && (file.s[i] != '\t') && (file.s[i] != '\n')) ++i; - dofield(fieldnum++,file.s + fieldpos,i - fieldpos); + dofield(fieldnum++, file.s + fieldpos, i - fieldpos); } doline(); i = j + 1; @@ -89,15 +98,15 @@ void split(void (*dofield)(), void (*doline)()) int main() { - if (readclose_append(0,&file,BSIZE) == -1) die_read(); + if (readclose_append(0, &file, BSIZE) == -1) die_read(); if (!file.len) _exit(0); if (file.s[file.len - 1] != '\n') - if (!stralloc_append(&file,"\n")) nomem(); + if (!stralloc_append(&file, "\n")) nomem(); - split(maxfield_check,nothing); + split(maxfield_check, nothing); width_init(); - split(width_check,nothing); - split(printfield,printline); + split(width_check, nothing); + split(printfield, printline); if (buffer_flush(&bo) == -1) die_write(); _exit(0); |