]> thyrsus.com Git - ascii.git/commitdiff
Bug fixes stimulated by Christian von Roques <roques@pond.sub.org>
authorEric S. Raymond <esr@thyrsus.com>
Thu, 12 Oct 1995 18:48:50 +0000 (18:48 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 12 Oct 1995 18:48:50 +0000 (18:48 +0000)
ascii.c

diff --git a/ascii.c b/ascii.c
index 260dce32a5826ebf3db962cd69471c65e757cadd..86e3e1651ea38c29822cbb7f1a1bee25e866707e 100644 (file)
--- a/ascii.c
+++ b/ascii.c
@@ -3,6 +3,8 @@
  *
  * by Eric S. Raymond <esr@snark.uu.net>, 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);
     }