Fix coding style
It was about damn time. Consistency is very important in such a big codebase.
This commit is contained in:
73
cut.c
73
cut.c
@@ -3,6 +3,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "text.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -30,21 +31,21 @@ insert(Range *r)
|
||||
{
|
||||
Range *l, *p, *t;
|
||||
|
||||
for(p = NULL, l = list; l; p = l, l = l->next) {
|
||||
if(r->max && r->max + 1 < l->min) {
|
||||
for (p = NULL, l = list; l; p = l, l = l->next) {
|
||||
if (r->max && r->max + 1 < l->min) {
|
||||
r->next = l;
|
||||
break;
|
||||
} else if(!l->max || r->min < l->max + 2) {
|
||||
} else if (!l->max || r->min < l->max + 2) {
|
||||
l->min = MIN(r->min, l->min);
|
||||
for(p = l, t = l->next; t; p = t, t = t->next)
|
||||
if(r->max && r->max + 1 < t->min)
|
||||
for (p = l, t = l->next; t; p = t, t = t->next)
|
||||
if (r->max && r->max + 1 < t->min)
|
||||
break;
|
||||
l->max = (p->max && r->max) ? MAX(p->max, r->max) : 0;
|
||||
l->next = t;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(p)
|
||||
if (p)
|
||||
p->next = r;
|
||||
else
|
||||
list = r;
|
||||
@@ -57,19 +58,19 @@ parselist(char *str)
|
||||
size_t n = 1;
|
||||
Range *r;
|
||||
|
||||
for(s = str; *s; s++) {
|
||||
if(*s == ' ')
|
||||
for (s = str; *s; s++) {
|
||||
if (*s == ' ')
|
||||
*s = ',';
|
||||
if(*s == ',')
|
||||
if (*s == ',')
|
||||
n++;
|
||||
}
|
||||
if(!(r = malloc(n * sizeof(Range))))
|
||||
if (!(r = malloc(n * sizeof(Range))))
|
||||
eprintf("malloc:");
|
||||
for(s = str; n; n--, s++) {
|
||||
for (s = str; n; n--, s++) {
|
||||
r->min = (*s == '-') ? 1 : strtoul(s, &s, 10);
|
||||
r->max = (*s == '-') ? strtoul(s + 1, &s, 10) : r->min;
|
||||
r->next = NULL;
|
||||
if(!r->min || (r->max && r->max < r->min) || (*s && *s != ','))
|
||||
if (!r->min || (r->max && r->max < r->min) || (*s && *s != ','))
|
||||
eprintf("cut: bad list value\n");
|
||||
insert(r++);
|
||||
}
|
||||
@@ -79,7 +80,7 @@ static void
|
||||
freelist(void) {
|
||||
Range *l = list, *next;
|
||||
|
||||
while(l) {
|
||||
while (l) {
|
||||
next = l->next;
|
||||
free(l);
|
||||
l->next = NULL;
|
||||
@@ -93,21 +94,21 @@ seek(const char *s, size_t pos, size_t *prev, size_t count)
|
||||
const char *t;
|
||||
size_t n = pos - *prev;
|
||||
|
||||
if(mode == 'b') {
|
||||
if((t = memchr(s, 0, n)))
|
||||
if (mode == 'b') {
|
||||
if ((t = memchr(s, 0, n)))
|
||||
return t - s;
|
||||
if(nflag)
|
||||
while(n && !UTF8_POINT(s[n]))
|
||||
if (nflag)
|
||||
while (n && !UTF8_POINT(s[n]))
|
||||
n--;
|
||||
*prev += n;
|
||||
return n;
|
||||
} else if(mode == 'c') {
|
||||
for(n++, t = s; *t; t++)
|
||||
if(UTF8_POINT(*t) && !--n)
|
||||
} else if (mode == 'c') {
|
||||
for (n++, t = s; *t; t++)
|
||||
if (UTF8_POINT(*t) && !--n)
|
||||
break;
|
||||
} else {
|
||||
for(t = (count < 2) ? s : s + 1; n && *t; t++)
|
||||
if(*t == delim && !--n && count)
|
||||
for (t = (count < 2) ? s : s + 1; n && *t; t++)
|
||||
if (*t == delim && !--n && count)
|
||||
break;
|
||||
}
|
||||
*prev = pos;
|
||||
@@ -122,24 +123,24 @@ cut(FILE *fp)
|
||||
ssize_t len;
|
||||
Range *r;
|
||||
|
||||
while((len = agetline(&buf, &size, fp)) != -1) {
|
||||
if(len && buf[len - 1] == '\n')
|
||||
while ((len = agetline(&buf, &size, fp)) != -1) {
|
||||
if (len && buf[len - 1] == '\n')
|
||||
buf[len - 1] = '\0';
|
||||
if(mode == 'f' && !strchr(buf, delim)) {
|
||||
if(!sflag)
|
||||
if (mode == 'f' && !strchr(buf, delim)) {
|
||||
if (!sflag)
|
||||
puts(buf);
|
||||
continue;
|
||||
}
|
||||
for(i = 0, p = 1, s = buf, r = list; r; r = r->next, s += n) {
|
||||
for (i = 0, p = 1, s = buf, r = list; r; r = r->next, s += n) {
|
||||
s += seek(s, r->min, &p, i++);
|
||||
if(!*s)
|
||||
if (!*s)
|
||||
break;
|
||||
if(!r->max) {
|
||||
if (!r->max) {
|
||||
fputs(s, stdout);
|
||||
break;
|
||||
}
|
||||
n = seek(s, r->max + 1, &p, i++);
|
||||
if(fwrite(s, 1, n, stdout) != n)
|
||||
if (fwrite(s, 1, n, stdout) != n)
|
||||
eprintf("write error:");
|
||||
}
|
||||
putchar('\n');
|
||||
@@ -172,22 +173,22 @@ main(int argc, char *argv[])
|
||||
usage();
|
||||
} ARGEND;
|
||||
|
||||
if(!mode)
|
||||
if (!mode)
|
||||
usage();
|
||||
if(!argc)
|
||||
if (!argc)
|
||||
cut(stdin);
|
||||
else {
|
||||
for(; argc--; argv++) {
|
||||
if(strcmp(*argv, "-"))
|
||||
for (; argc--; argv++) {
|
||||
if (strcmp(*argv, "-"))
|
||||
fp = fopen(*argv, "r");
|
||||
else
|
||||
fp = stdin;
|
||||
if(!fp) {
|
||||
if (!fp) {
|
||||
weprintf("fopen %s:", *argv);
|
||||
continue;
|
||||
}
|
||||
cut(fp);
|
||||
if(fp != stdin)
|
||||
if (fp != stdin)
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user