MOO-cows Mailing List Archive

[Prev][Next][Index][Thread]

Patch for 1.8.0 binary output




> Mar 10 00:38:00: *** STREAM_PRINTF: Unknown format directive: %X

encode_binary() uses "%02X" now to convert integers into uppercase hex
strings.  It's broken because stock 1.8.0's stream_printf doesn't
understand "%x" or "%X" directives, which are lowercase and uppercase
hexadecimal formats.

Here's a patch for streams.c.  You may need to apply it with:

  patch -l <streams.c.patch

because my emacs environment is fanatic about munging tab-vs-space.
Pavel, were you using some specific set of emacs or gnu indent
options?

BTW, for the truly lunatic fringe, I have a set of patches that adds
GNU realine to emergency mode.  I'm not going to fix them up right
unless enough other people care....

Jay Carlson
nop@nop.com    nop@ccs.neu.edu    nop@kagoona.mitre.org

Flat text is just *never* what you want.   ---stephen p spackman

streams.c.patch:

*** streams.c-180  Sun Mar 10 18:30:49 1996
--- streams.c	Sun Mar 10 18:28:57 1996
***************
*** 76,89 ****
  }
  
  static const char *
! itoa(int n, int radix)
  {
      if (n == 0)                 /* zero produces "" below. */
          return "0";
      else if (n == -2147483647 -1)       /* min. integer won't work below. */
          switch (radix) {
            case 10: return "-2147483648";
            case 8:  return "-17777777777";
            default:
              errlog("STREAM_PRINTF: Illegal radix %d!\n", radix);
              return "0";
--- 76,97 ----
  }
  
  static const char *
! fancy_itoa(int n, int radix, int uppercase)
  {
+     const char lowercase_digits[] = "0123456789abcdef";
+     const char uppercase_digits[] = "0123456789ABCDEF";
+     const char *digits = lowercase_digits;
+ 
+     if (uppercase)
+       digits = uppercase_digits;
+ 
      if (n == 0)                 /* zero produces "" below. */
          return "0";
      else if (n == -2147483647 -1)       /* min. integer won't work below. */
          switch (radix) {
            case 10: return "-2147483648";
            case 8:  return "-17777777777";
+           case 16: return uppercase ? "-7FFFFFFF" : "-7fffffff";
            default:
              errlog("STREAM_PRINTF: Illegal radix %d!\n", radix);
              return "0";
***************
*** 99,105 ****
          }
          *(ptr) = '\0';
          while (n != 0) {
!             *(--ptr) = '0' + n % radix;
              n /= radix;
          }
          if (neg)
--- 107,113 ----
          }
          *(ptr) = '\0';
          while (n != 0) {
!             *(--ptr) = digits[n % radix];
              n /= radix;
          }
          if (neg)
***************
*** 142,150 ****
                    case 's':
                      string = va_arg(args, char *);
                      break;
                    case 'o':
                    case 'd':
!                     string = itoa(va_arg(args, int), c == 'd' ? 10 : 8);
                      break;
                    case 'g':
                      sprintf(buffer, dbl_fmt(), va_arg(args, double));
--- 150,166 ----
                    case 's':
                      string = va_arg(args, char *);
                      break;
+                   case 'x':
+                     string = fancy_itoa(va_arg(args, int), 16, 0);
+                     break;
+                   case 'X':
+                     string = fancy_itoa(va_arg(args, int), 16, 1);
+                     break;
                    case 'o':
+                     string = fancy_itoa(va_arg(args, int), 8, 0);
+                     break;
                    case 'd':
!                     string = fancy_itoa(va_arg(args, int), 10, 0);
                      break;
                    case 'g':
                      sprintf(buffer, dbl_fmt(), va_arg(args, double));



Home | Subject Index | Thread Index