add swizzling unit to interface. -s2 swizzles 2-byte units, -s8 swizzles 8-byte units. any value from 1 to 8 is legal. -s1 is allowed but nilpotent. Reference: /n/sources/patch/maybe/xd-swizz Date: Thu Aug 1 18:42:38 CES 2013 Signed-off-by: quanstro@quanstro.net --- /sys/man/1/xd Thu Aug 1 18:40:59 2013 +++ /sys/man/1/xd Thu Aug 1 18:40:58 2013 @@ -79,8 +79,12 @@ .B -u (Unbuffered) Flush the output buffer after each 16-byte sequence. .TP -.B -s -Reverse (swab) the order of bytes in each group of 4 before printing. +.BI -s " n" +Reverse (swab) the order of bytes in each group of +.I n +before printing. By default +.I n +is 4. Legal values range from 1 to 8. .TP .B -r Print repeating groups of identical 16-byte sequences as the first group --- /sys/src/cmd/xd.c Thu Aug 1 18:41:02 2013 +++ /sys/src/cmd/xd.c Thu Aug 1 18:41:00 2013 @@ -25,7 +25,7 @@ typedef void fmtfn(char *); struct Arg { - int chartype; /* TNone, TAscii, TRunes */ + int chartype; /* TNone, TAscii, TRunes */ int loglen; /* 0==1, 1==2, 2==4, 3==8 */ int base; /* 0==8, 1==10, 2==16 */ fmtfn *fn; /* function to call with data */ @@ -87,8 +87,10 @@ continue; } if(argv[0][0] == 's'){ - swizzle = 1; + swizzle = 4; if(argv[0][1]) + swizzle = atoi(argv[0]+1); + if(swizzle <= 0 || swizzle > 8) goto Usage; continue; } @@ -160,7 +162,7 @@ break; default: Usage: - fprint(2, "usage: xd [-u] [-r] [-s] [-a{odx}] [-c|{b1w2l4v8}{odx}] ... file ...\n"); + fprint(2, "usage: xd [-u] [-r] [-s[n]] [-a{odx}] [-c|-R|{b1w2l4v8}{odx}] ... file ...\n"); exits("usage"); } argv[0]++; @@ -282,26 +284,28 @@ return 0; } +uchar order[] = {7, 6, 5, 4, 3, 2, 1, 0}; + void swizz(void) { - uchar *p, *q; - int i; + uchar *p, *q, *t; + int i, j, n; uchar swdata[16]; p = data; q = swdata; + t = order + (8-swizzle); for(i=0; i<16; i++) *q++ = *p++; p = data; q = swdata; - for(i=0; i<4; i++){ - p[0] = q[3]; - p[1] = q[2]; - p[2] = q[1]; - p[3] = q[0]; - p += 4; - q += 4; + n = 16/swizzle; + for(i=0; i