From: Eric S. Raymond Date: Tue, 15 Dec 1998 19:26:35 +0000 (+0000) Subject: Update to 2.4. X-Git-Tag: 2-4~2 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=b2426831c893dd6a7a28fd117fd04f8faa49a696;p=ascii.git Update to 2.4. --- diff --git a/Makefile b/Makefile index 6ad611d..795db6b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # Note: When the version changes, you also have to change # the RPM spec file and LSM -V=2.3 +V=2.4 CFLAGS = -O diff --git a/ascii.c b/ascii.c index 934fae3..3cf1a5f 100644 --- a/ascii.c +++ b/ascii.c @@ -9,6 +9,7 @@ * v2.1 August 1997 -- merge in changes by Ioannis Tambouras. * v2.2 November 1997 -- merge in more changes by Ioannis Tambouras. * v2.3 November 1997 -- incorporated Colin Plumb's splash-screen idea. + * v2.4 December 1998 -- additions by Brian Ginsbach. * * Tries to interpret arguments as names or aliases of ascii characters * and dumps out *all* the aliases of each. Accepts literal characters, @@ -25,7 +26,7 @@ */ -#define REVISION "$Revision: 1.9 $" +#define REVISION "$Revision: 1.10 $" #include #include @@ -41,7 +42,6 @@ enum { decimal, hex, octal } mode; void print_table(unsigned short delivery); - static string cnames[128][15] = { {"NUL", "Null", (char *)NULL}, @@ -97,7 +97,7 @@ static string cnames[128][15] = "Amper", "And", (char *)NULL}, {"'", "Apostrophe", "Single Quote", "Close Quote", "Prime", - "Tick", "Pop", "Spark", "Prime", "Glitch", + "Tick", "Pop", "Spark", "Glitch", "# See ` and \" for matching names.", (char *)NULL}, {"(", "Open Parenthesis", @@ -359,8 +359,8 @@ int ch; char **ptr = &cnames[ch][0]; if (terse) { - printf("%d/%d %d 0x%02X 0o%o %s\n", - ch / 16, ch % 16, ch, ch, ch, btoa(ch)); + (void) printf("%d/%d %d 0x%02X 0o%o %s\n", + ch / 16, ch % 16, ch, ch, ch, btoa(ch)); return; } @@ -411,7 +411,8 @@ int ch; if (**ptr == '#') commentary = *ptr; else - (void) printf("%s%s ", *ptr, ptr[1] ? "," : ""); + (void) printf("%s%s ", *ptr, + (ptr[1] && *ptr[1] != '#') ? "," : ""); (void) putchar('\n'); if (commentary) (void) printf("Note: %s\n", commentary+2); @@ -457,9 +458,9 @@ char *str; if (len == 2 || len == 3) { /* first check for standard mnemonics */ - if (strcmp(str, "DEL") == 0) + if (stricmp(str, "DEL") == 0) { speak(0x7f); return; } - if (strcmp(str, "BL") == 0) + if (stricmp(str, "BL") == 0) { speak(' '); return; } else if (isalpha(str[0])) for (ch = 0; ch <= 32; ch++) @@ -470,7 +471,7 @@ char *str; /* OK, now try to interpret the string as a numeric */ if (len > 1 && len < 9) { - int hval, dval, oval, bval; + int hval, dval, oval, bval, spoken = 0; dval = oval = hval = bval = -1; @@ -484,19 +485,23 @@ char *str; if (len <= 9 && strspn(str, "01") == len) bval = atob(str); - /* accept 0xnn, \xnn and xnn forms for hex */ + /* accept 0xnn, \xnn, xnn and nnh forms for hex */ if (hval == -1) if ((str[0]=='0'||str[0]=='\\') && tolower(str[1]) == 'x') (void) sscanf(str + 2, "%x", &hval); else if (tolower(str[0]) == 'x') (void) sscanf(str + 1, "%x", &hval); + else if (tolower(str[len - 1]) == 'h') + (void) sscanf(str, "%x", &hval); - /* accept 0onn, \onnn and onnn forms for octal */ + /* accept 0onn, \onnn, onnn and \nnn forms for octal */ if (oval == -1) if ((str[0]=='0'||str[0]=='\\') && tolower(str[1]) == 'o') (void) sscanf(str + 2, "%o", &oval); else if (tolower(str[0]) == 'o') (void) sscanf(str + 1, "%o", &oval); + else if (str[0] == '\\' && strspn(str + 1, "0123456789") == len - 1) + (void) sscanf(str + 1, "%o", &oval); /* accept 0dnnn, \dnnn and dnnn forms for decimal */ if (dval == -1) @@ -513,15 +518,17 @@ char *str; bval = atob(str + 1); /* OK, now output all values */ - if (hval > -1) + if (hval > -1 && hval < 256) speak(hval & 0xff); - if (dval > -1) + if (dval > -1 && dval < 256) speak(dval & 0xff); - if (oval > -1) + if (oval > -1 && oval < 256) speak(oval & 0xff); - if (bval > -1) + if (bval > -1 && bval < 256) speak(bval & 0xff); - if (hval > 1 || dval > -1 || oval > -1 || bval > -1) + if (hval > -1 || dval > -1 || oval > -1 || bval > -1) + return; + if (hval < 256 || dval < 256 || oval < 256 || bval < 256) return; } diff --git a/ascii.spec b/ascii.spec index aef3c72..a688794 100644 --- a/ascii.spec +++ b/ascii.spec @@ -1,8 +1,8 @@ Description: interactive ASCII name and synonym chart Name: ascii -Version: 2.3 +Version: 2.4 Release: 1 -Source: locke.ccil.org:/pub/esr/ascii-2.2.tar.gz +Source: locke.ccil.org:/pub/esr/ascii-2.4.tar.gz Copyright: distributable Group: Utilities/Text diff --git a/ascii.xml b/ascii.xml index 4424700..c8d925d 100644 --- a/ascii.xml +++ b/ascii.xml @@ -1,4 +1,4 @@ -.TH ascii 1 +.TH ascii 1 "" "Open Source" .SH NAME ascii -- report character aliases .SH SYNOPSIS @@ -21,7 +21,7 @@ Ascii table in hex. Ascii table in octal. .TP .B \-h, -? -Show summary of options. +Show summary of options and a simple ASCII table. .TP .B \-v Show version of program. @@ -30,13 +30,13 @@ Characters in the ASCII set can have many aliases, depending on context. A character's possible names include: .TP 3 * -Its bit pattern +Its bit pattern (binary representation). .TP 3 * Its hex, decimal and octal representations. .TP 3 * -Its teletype mnemonic and caret-notation form (for control chars) +Its teletype mnemonic and caret-notation form (for control chars). .TP 3 * Its backlash-escape form in C (for some control chars). @@ -54,26 +54,95 @@ Its ISO/ECMA code table reference. Slang and other names in wide use for it among hackers. .P This utility accepts command-line strings and tries to interpret them as -one of the above. When it finds a value, it prints \fIall\fR of the names -of the character. If an argument could be interpreted in two or more +one of the above. +When it finds a value, it prints \fIall\fR of the names +of the character. +The constructs in the following list can be used to +specify character values. +If an argument could be interpreted in two or more ways, names for all the different characters it might be are dumped. +.TP 12 +.I character +Any character not described by one of the following conventions +represents the character itself. +.TP +.BI ^ character +A caret followed by a character. +.TP +.BI \e \|character +A backslash followed by certain special characters (abfnrtv). +.TP +.I mnemonic +An ASCII teletype mnemonic. +.TP +.I hexadecimal +A hexadecimal (hex) sequence consists of one or two case-insensitive hex digit +characters (01234567890abcdef). +To ensure hex interpretation use +.IB hex h , +.BI 0x hex, +.BI x hex +or +.BI \e\|x hex. +.TP +.I decimal +A decimal sequence consists of one, two or three decimal digit +characters (0123456789). +To ensure decimal interpretation use +.BI \e0d decimal, +.BI d decimal, +or +.BI \e\|d decimal. +.TP +.I octal +An octal sequence consists of one, two or three octal digit +characters (01234567). +To ensure octal interpretation use +.BI \e \|octal, +.BI 0o octal, +.BI o octal, +or +.BI \e\|o octal. +.TP +.I bit pattern +A bit pattern (binary) sequence consists of one to eight binary digit +characters (01). +To ensure bit interpretation use +.BI 0b bit\ pattern, +.BI b bit\ pattern +or +.BI \e\|b bit\ pattern. +.TP +.IR ISO / ECMA\ code +A ISO/ECMA code sequence consists of one or two decimal digit characters, +a slash, and one or two decimal digit characters. +.TP +.I name +An official ASCII or slang name. .P -This utility is particularly handy for interpreting cc(1)'s ugly -octal `invalid-character' messages, or when coding anything to do with serial -communications. As a side effect it serves as a handy base-converter -for random 8-bit values. +The slang names recognized and printed out are from a rather comprehensive +list that appeared on USENET in early 1990. +Mnemonics recognized and printed include the official ASCII set, +some official ISO names (where those differ) +and a few common-use alternatives (such as NL for LF). +All comparisons are +case-insensitive, and dashes are mapped to spaces. +Any unrecognized arguments or out of range values are silently ignored. .P For correct results, be careful to stringize or quote shell metacharacters in arguments (especially backslash). .P -The slang names recognized and printed out are from a rather comprehensive -list that appeared on USENET in early 1990. Mnemonics recognized and printed -include the official ASCII set, some official ISO names (where those differ) -and a few common-use alternatives (such as NL for LF). All comparisons are -case-insensitive, and dashes are mapped to spaces. +This utility is particularly handy for interpreting cc(1)'s ugly +octal `invalid-character' messages, or when coding anything to do with serial +communications. +As a side effect it serves as a handy base-converter +for random 8-bit values. .SH AUTHOR Eric S. Raymond November 1990 (home page at -http://www.ccil.org/~esr/home.html). Reproduce, use, +http://www.ccil.org/~esr/home.html). +Reproduce, use, and modify as you like as long as you don't remove this authorship notice. Ioannis E. Tambouras added command options and minor -enhancements. +enhancements. +Brian J. Ginsbach fixed several bugs and expanded the +man page.