* 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,
*/
-#define REVISION "$Revision: 1.9 $"
+#define REVISION "$Revision: 1.10 $"
#include <unistd.h>
#include <stdio.h>
void print_table(unsigned short delivery);
-
static string cnames[128][15] =
{
{"NUL", "Null", (char *)NULL},
"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",
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;
}
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);
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++)
/* 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;
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)
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;
}
-.TH ascii 1
+.TH ascii 1 "" "Open Source"
.SH NAME
ascii -- report character aliases
.SH SYNOPSIS
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.
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).
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 <esr@snark.thyrsus.com> 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 <ioannis@debian.org> added command options and minor
-enhancements.
+enhancements.
+Brian J. Ginsbach <ginsbach@sgi.com> fixed several bugs and expanded the
+man page.