From: Eric S. Raymond Date: Thu, 12 Oct 1995 18:48:50 +0000 (+0000) Subject: Bug fixes stimulated by Christian von Roques X-Git-Tag: 2-1~13 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=c593bd80dd769f7de5611bd8649310b37c76583c;p=ascii.git Bug fixes stimulated by Christian von Roques --- diff --git a/ascii.c b/ascii.c index 260dce3..86e3e16 100644 --- a/ascii.c +++ b/ascii.c @@ -3,6 +3,8 @@ * * by Eric S. Raymond , v1.0 March 1990 * v1.1 November 1990 -- revised `slang' from the 2.2 pronunciation guide + * v1.2 March 1995 -- Fixed a core-dump bug + * v1.3 October 1995 -- Fixed a bug that shows up only under ELF. * * Tries to interpret arguments as names or aliases of ascii characters * and dumps out *all* the aliases of each. Accepts literal characters, @@ -10,7 +12,8 @@ * characters, numbers in hex/decimal/octal/binary, English names. * * The slang names used are selected from the 2.2 version of the USENET ascii - * pronunciation guide. + * pronunciation guide. Some additional ones were merged in from the Jargon + * File. * * Reproduce, use, and modify this as you like, as long as you don't * remove the authorship notice and clearly mark your changes. Send me @@ -55,7 +58,7 @@ static string cnames[128][15] = {"GS", "Group Separator", (char *)NULL}, {"RS", "Record Separator", (char *)NULL}, {"US", "Group Separator", (char *)NULL}, - {"SP", "BL", "Space", "Blank", (char *)NULL}, + {" ", "SP", "Space", "Blank", (char *)NULL}, {"!", "Exclamation Point", "Bang", "Excl", "Wow", "Factorial", "Shriek", "Pling", "Smash", "Cuss", (char *)NULL}, @@ -267,25 +270,20 @@ static char *btoa(val) int i; static char rep[BITSPERCHAR + 1]; - if (val == 0) - rp = "0"; - else - { - int dcount; - - /* write out external representation if requested */ - *(rp = rep + BITSPERCHAR) = '\0'; - for (dcount = 0; val && dcount <= BITSPERCHAR; dcount++) - { - *--rp = ((val & 1) ? '1' : '0'); - val /= 2; - } - - while (dcount++ <= BITSPERCHAR) - *--rp = '0'; - } - - return(rep); + /* write out external representation at least one char */ + *(rp = rep + BITSPERCHAR) = '\0'; + do { + *--rp = (val & 1) + '0'; /* Is '1' == '0' + 1 in EBCDIC? */ + val /= 2; + } while + (val && rp > rep); + +#ifndef SHORT_BINARY_REPRESENTATION + while (rp > rep) + *--rp = '0'; +#endif + + return(rp); } static void speak(ch) @@ -389,8 +387,10 @@ char *str; /* first check for standard mnemonics */ if (strcmp(str, "DEL") == 0) speak(0x7f); + if (strcmp(str, "BL") == 0) + speak(' '); else if (isalpha(str[0])) - for (ch = 0; ch < 32; ch++) + for (ch = 0; ch <= 32; ch++) if (!stricmp(str,cnames[ch][0]) || !strcmp(str,cnames[ch][1])) speak(ch); }