--- sort.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/sort.c b/sort.c index 63b9509..5af81d2 100644 --- a/sort.c +++ b/sort.c _AT_@ -30,11 +30,13 @@ static char *next_nonblank(char *); static char *next_blank(char *); static int parse_keydef(struct keydef *, char *); static char *skip_columns(char *, size_t); +static char *end_column(char *); static char *columns(char *, const struct keydef *); static bool rflag = false; static bool uflag = false; static bool nflag = false; +static bool bflag = false; static void usage(void) _AT_@ -59,6 +61,9 @@ main(int argc, char *argv[]) case 'u': uflag = true; break; + case 'b': + bflag = true; + break; case 'k': addkeydef(EARGF(usage())); break; _AT_@ -169,7 +174,7 @@ parse_keydef(struct keydef *kd, char *s) kd->start_char = strtoul(rest+1, &rest, 10); if(*rest == ',') { kd->end_column = strtoul(rest+1, &rest, 10); - if(kd->end_column < kd->start_column) + if(kd->end_column && kd->end_column < kd->start_column) enprintf(2, ",%u is too small\n", kd->end_column); if(*rest == '.') kd->end_char = strtoul(rest+1, &rest, 10); _AT_@ -201,29 +206,45 @@ skip_columns(char *s, size_t n) size_t i; for(i = 0; i < n; i++) { - if(i != 0) + if(bflag) { + if(i != 0) + s = next_blank(s); + s = next_nonblank(s); + } else { + if(i == 0) + continue; + s = next_nonblank(s); s = next_blank(s); - s = next_nonblank(s); + } } return s; } static char * +end_column(char *s) +{ + if(bflag) + return next_blank(s); + else + return next_blank(next_nonblank(s)); +} + +static char * columns(char *line, const struct keydef *kd) { char *start, *end; char *res; start = skip_columns(line, kd->start_column); - start += MIN(kd->start_char, next_blank(start) - start) - 1; + start += MIN(kd->start_char, end_column(start) - start) - 1; if(kd->end_column) { end = skip_columns(line, kd->end_column); if(kd->end_char) - end += MIN(kd->end_char, next_blank(end) - end); + end += MIN(kd->end_char, end_column(end) - end); else - end = next_blank(end); + end = end_column(end); } else { end = line + strlen(line); } -- 1.8.5.1 --/04w6evG8XlLl3ft Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0007-sort-simplify-skip_columns.patch"Received on Mon Sep 17 2001 - 00:00:00 CEST
This archive was generated by hypermail 2.3.0 : Sat May 03 2014 - 21:36:07 CEST