#include #include #include char usage[] = "unicode { [-t] hex hex ... | hexmin-hexmax ... | [-n] char ... }"; char hex[] = "0123456789abcdefABCDEF"; int numout = 0; int text = 0; char *err; Biobuf bout; char *range(char*[]); char *nums(char*[]); char *chars(char*[]); void main(int argc, char *argv[]) { ARGBEGIN{ case 'n': numout = 1; break; case 't': text = 1; break; }ARGEND Binit(&bout, 1, OWRITE); if(argc == 0){ fprint(2, "usage: %s\n", usage); exits("usage"); } if(!numout && utfrune(argv[0], '-')) exits(range(argv)); if(numout || strchr(hex, argv[0][0])==0) exits(nums(argv)); exits(chars(argv)); } char* range(char *argv[]) { char *q; long min, max; int i; while(*argv){ q = *argv; if(strchr(hex, q[0]) == 0){ err: fprint(2, "unicode: bad range %s\n", *argv); return "bad range"; } min = strtoul(q, &q, 16); if(min<0 || min>0xFFFF || *q!='-') goto err; q++; if(strchr(hex, *q) == 0) goto err; max = strtoul(q, &q, 16); if(max<0 || max>0xFFFF || max0xFFFF || *q!=0) goto err; Bprint(&bout, "%C", m); if(!text) Bprint(&bout, "\n"); argv++; } return 0; }