From: Ben Gras Date: Tue, 11 Dec 2012 03:43:20 +0000 (+0100) Subject: sort: add -x hex sort feature back X-Git-Tag: v3.2.1~156 X-Git-Url: http://zhaoyanbai.com/repos/%24relpath%24tabs.css?a=commitdiff_plain;h=e286ccc05bef1fbad5a00f4f3bd99c764daf92fe;p=minix.git sort: add -x hex sort feature back . so unstack works again --- diff --git a/usr.bin/sort/fields.c b/usr.bin/sort/fields.c index 9533b1c70..94cb23ca5 100644 --- a/usr.bin/sort/fields.c +++ b/usr.bin/sort/fields.c @@ -82,6 +82,10 @@ static u_char *enterfield(u_char *, const u_char *, struct field *, int); static u_char *number(u_char *, const u_char *, u_char *, u_char *, int); static u_char *length(u_char *, const u_char *, u_char *, u_char *, int); +#ifdef __minix +static u_char *numhex(u_char *, const u_char *, u_char *, u_char *, int); +#endif + #define DECIMAL_POINT '.' /* @@ -205,6 +209,10 @@ enterfield(u_char *tablepos, const u_char *endkey, struct field *cur_fld, return length(tablepos, endkey, start, end, flags); if (flags & N) return number(tablepos, endkey, start, end, flags); +#ifdef __minix + if (flags & X) + return numhex(tablepos, endkey, start, end, flags); +#endif /* Bound check space - assuming nothing is skipped */ if (tablepos + (end - start) + 1 >= endkey) @@ -375,3 +383,18 @@ length(u_char *pos, const u_char *bufend, u_char *line, u_char *lineend, l = snprintf((char *)buf, sizeof(buf), "%td", lineend - line); return number(pos, bufend, buf, buf + l, flag); } + +#ifdef __minix +static u_char * +numhex(u_char *pos, const u_char *bufend, u_char *line, u_char *lineend, + int flag) +{ + u_char buf[32]; + int64_t n = 0; + int l; + SKIP_BLANKS(line); + sscanf((const char *) pos, "%lx", &n); + l = snprintf((char *)buf, sizeof(buf), "%lld", n); + return number(pos, bufend, buf, buf + l, flag); +} +#endif diff --git a/usr.bin/sort/init.c b/usr.bin/sort/init.c index 0ef34b339..8884d0b40 100644 --- a/usr.bin/sort/init.c +++ b/usr.bin/sort/init.c @@ -233,6 +233,9 @@ optval(int desc, int tcolflag) case 'i': return I; case 'l': return L; case 'n': return N; +#ifdef __minix + case 'x': return X; +#endif case 'r': return R; default: return 0; } diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c index a0d4f5f20..5f026daca 100644 --- a/usr.bin/sort/sort.c +++ b/usr.bin/sort/sort.c @@ -170,6 +170,9 @@ main(int argc, char *argv[]) debug_flags |= 1 << (optarg[i] & 31); break; case 'd': case 'f': case 'i': case 'n': case 'l': +#ifdef __minix + case 'x': +#endif fldtab[0].flags |= optval(ch, 0); break; case 'H': diff --git a/usr.bin/sort/sort.h b/usr.bin/sort/sort.h index 677fd4522..cac59b0ee 100644 --- a/usr.bin/sort/sort.h +++ b/usr.bin/sort/sort.h @@ -86,6 +86,9 @@ #define BI 0x20 /* ignore blanks in icol */ #define BT 0x40 /* ignore blanks in tcol */ #define L 0x80 /* Sort by field length */ +#ifdef __minix +#define X 0x100 /* Field is a hex number */ +#endif /* masks for delimiters: blanks, fields, and termination. */ #define BLANK 1 /* ' ', '\t'; '\n' if -R is invoked */