sort: add -x hex sort feature back

. so unstack works again
This commit is contained in:
Ben Gras 2012-12-11 04:43:20 +01:00
parent f44fb1784b
commit e286ccc05b
4 changed files with 32 additions and 0 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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':

View file

@ -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 */