+
+/* Read an integer in radix RADIX using READCHARFUN to read
+ characters. RADIX must be in the interval [2..36]; if it isn't, a
+ read error is signaled . Value is the integer read. Signals an
+ error if encountering invalid read syntax or if RADIX is out of
+ range. */
+
+static Lisp_Object
+read_integer (readcharfun, radix)
+ Lisp_Object readcharfun;
+ int radix;
+{
+ int ndigits = 0, invalid_p, c, sign = 0;
+ EMACS_INT number = 0;
+
+ if (radix < 2 || radix > 36)
+ invalid_p = 1;
+ else
+ {
+ number = ndigits = invalid_p = 0;
+ sign = 1;
+
+ c = READCHAR;
+ if (c == '-')
+ {
+ c = READCHAR;
+ sign = -1;
+ }
+ else if (c == '+')
+ c = READCHAR;
+
+ while (c >= 0)
+ {
+ int digit;
+
+ if (c >= '0' && c <= '9')
+ digit = c - '0';
+ else if (c >= 'a' && c <= 'z')
+ digit = c - 'a' + 10;
+ else if (c >= 'A' && c <= 'Z')
+ digit = c - 'A' + 10;
+ else
+ {
+ UNREAD (c);
+ break;
+ }
+
+ if (digit < 0 || digit >= radix)
+ invalid_p = 1;
+
+ number = radix * number + digit;
+ ++ndigits;
+ c = READCHAR;
+ }
+ }
+
+ if (ndigits == 0 || invalid_p)
+ {
+ char buf[50];
+ sprintf (buf, "integer, radix %d", radix);
+ Fsignal (Qinvalid_read_syntax, Fcons (build_string (buf), Qnil));
+ }
+
+ return make_number (sign * number);
+}
+
+
+/* Convert unibyte text in read_buffer to multibyte.
+
+ Initially, *P is a pointer after the end of the unibyte text, and
+ the pointer *END points after the end of read_buffer.
+
+ If read_buffer doesn't have enough room to hold the result
+ of the conversion, reallocate it and adjust *P and *END.
+
+ At the end, make *P point after the result of the conversion, and
+ return in *NCHARS the number of characters in the converted
+ text. */
+
+static void
+to_multibyte (p, end, nchars)
+ char **p, **end;
+ int *nchars;
+{
+ int nbytes;
+
+ parse_str_as_multibyte (read_buffer, *p - read_buffer, &nbytes, nchars);
+ if (read_buffer_size < 2 * nbytes)
+ {
+ int offset = *p - read_buffer;
+ read_buffer_size = 2 * max (read_buffer_size, nbytes);
+ read_buffer = (char *) xrealloc (read_buffer, read_buffer_size);
+ *p = read_buffer + offset;
+ *end = read_buffer + read_buffer_size;
+ }
+
+ if (nbytes != *nchars)
+ nbytes = str_as_multibyte (read_buffer, read_buffer_size,
+ *p - read_buffer, nchars);
+
+ *p = read_buffer + nbytes;
+}
+
+