diff options
| author | Paul Eggert | 2011-04-06 20:49:25 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-04-06 20:49:25 -0700 |
| commit | ea6c7ae6bf4e43c7c31babf76600d2ee008f4e19 (patch) | |
| tree | a05e7cdc4dd7bd17b111b12efb9cfadd8387e458 /src | |
| parent | 5fdb398c4b75b0c834aff7132f90b0ce5317a25a (diff) | |
| download | emacs-ea6c7ae6bf4e43c7c31babf76600d2ee008f4e19.tar.gz emacs-ea6c7ae6bf4e43c7c31babf76600d2ee008f4e19.zip | |
Remove the doprnt implementation, as Emacs now uses vsnprintf.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/Makefile.in | 2 | ||||
| -rw-r--r-- | src/deps.mk | 1 | ||||
| -rw-r--r-- | src/doprnt.c | 279 | ||||
| -rw-r--r-- | src/lisp.h | 4 |
5 files changed, 8 insertions, 284 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c1bea6b4cc7..a98c4e72ba1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,11 @@ | |||
| 1 | 2011-04-07 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-04-07 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | Remove the doprnt implementation, as Emacs now uses vsnprintf. | ||
| 4 | * doprnt.c: Remove. | ||
| 5 | * lisp.h (doprnt): Remove. | ||
| 6 | * Makefile.in (base_obj): Remove doprnt.o. | ||
| 7 | * deps.mk (doprnt.o): Remove. | ||
| 8 | |||
| 3 | error: Print 32- and 64-bit integers portably (Bug#8435). | 9 | error: Print 32- and 64-bit integers portably (Bug#8435). |
| 4 | Without this change, on typical 64-bit hosts error ("...%d...", N) | 10 | Without this change, on typical 64-bit hosts error ("...%d...", N) |
| 5 | was used to print both 32- and 64-bit integers N, which relied on | 11 | was used to print both 32- and 64-bit integers N, which relied on |
diff --git a/src/Makefile.in b/src/Makefile.in index e1195968f7f..154d6abba4e 100644 --- a/src/Makefile.in +++ b/src/Makefile.in | |||
| @@ -354,7 +354,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \ | |||
| 354 | syntax.o $(UNEXEC_OBJ) bytecode.o \ | 354 | syntax.o $(UNEXEC_OBJ) bytecode.o \ |
| 355 | process.o gnutls.o callproc.o \ | 355 | process.o gnutls.o callproc.o \ |
| 356 | region-cache.o sound.o atimer.o \ | 356 | region-cache.o sound.o atimer.o \ |
| 357 | doprnt.o intervals.o textprop.o composite.o xml.o \ | 357 | intervals.o textprop.o composite.o xml.o \ |
| 358 | $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) | 358 | $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) |
| 359 | obj = $(base_obj) $(NS_OBJC_OBJ) | 359 | obj = $(base_obj) $(NS_OBJC_OBJ) |
| 360 | 360 | ||
diff --git a/src/deps.mk b/src/deps.mk index be5d3694fca..2df1577ef78 100644 --- a/src/deps.mk +++ b/src/deps.mk | |||
| @@ -82,7 +82,6 @@ dispnew.o: dispnew.c systime.h commands.h process.h frame.h coding.h \ | |||
| 82 | # doc.o's dependency on buildobj.h is in src/Makefile.in. | 82 | # doc.o's dependency on buildobj.h is in src/Makefile.in. |
| 83 | doc.o: doc.c lisp.h $(config_h) buffer.h keyboard.h keymap.h \ | 83 | doc.o: doc.c lisp.h $(config_h) buffer.h keyboard.h keymap.h \ |
| 84 | character.h systime.h coding.h composite.h ../lib/unistd.h globals.h | 84 | character.h systime.h coding.h composite.h ../lib/unistd.h globals.h |
| 85 | doprnt.o: doprnt.c character.h lisp.h globals.h ../lib/unistd.h $(config_h) | ||
| 86 | dosfns.o: buffer.h termchar.h termhooks.h frame.h blockinput.h window.h \ | 85 | dosfns.o: buffer.h termchar.h termhooks.h frame.h blockinput.h window.h \ |
| 87 | msdos.h dosfns.h dispextern.h charset.h coding.h atimer.h systime.h \ | 86 | msdos.h dosfns.h dispextern.h charset.h coding.h atimer.h systime.h \ |
| 88 | lisp.h $(config_h) | 87 | lisp.h $(config_h) |
diff --git a/src/doprnt.c b/src/doprnt.c deleted file mode 100644 index 36eb272caae..00000000000 --- a/src/doprnt.c +++ /dev/null | |||
| @@ -1,279 +0,0 @@ | |||
| 1 | /* Output like sprintf to a buffer of specified size. | ||
| 2 | Also takes args differently: pass one pointer to an array of strings | ||
| 3 | in addition to the format string which is separate. | ||
| 4 | Copyright (C) 1985, 2001-2011 Free Software Foundation, Inc. | ||
| 5 | |||
| 6 | This file is part of GNU Emacs. | ||
| 7 | |||
| 8 | GNU Emacs is free software: you can redistribute it and/or modify | ||
| 9 | it under the terms of the GNU General Public License as published by | ||
| 10 | the Free Software Foundation, either version 3 of the License, or | ||
| 11 | (at your option) any later version. | ||
| 12 | |||
| 13 | GNU Emacs is distributed in the hope that it will be useful, | ||
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | GNU General Public License for more details. | ||
| 17 | |||
| 18 | You should have received a copy of the GNU General Public License | ||
| 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 20 | |||
| 21 | |||
| 22 | #include <config.h> | ||
| 23 | #include <stdio.h> | ||
| 24 | #include <ctype.h> | ||
| 25 | #include <setjmp.h> | ||
| 26 | |||
| 27 | #ifdef STDC_HEADERS | ||
| 28 | #include <float.h> | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #include <unistd.h> | ||
| 32 | |||
| 33 | #include "lisp.h" | ||
| 34 | |||
| 35 | /* Since we use the macro CHAR_HEAD_P, we have to include this, but | ||
| 36 | don't have to include others because CHAR_HEAD_P does not contains | ||
| 37 | another macro. */ | ||
| 38 | #include "character.h" | ||
| 39 | |||
| 40 | #ifndef DBL_MAX_10_EXP | ||
| 41 | #define DBL_MAX_10_EXP 308 /* IEEE double */ | ||
| 42 | #endif | ||
| 43 | |||
| 44 | /* Generate output from a format-spec FORMAT, | ||
| 45 | terminated at position FORMAT_END. | ||
| 46 | Output goes in BUFFER, which has room for BUFSIZE chars. | ||
| 47 | If the output does not fit, truncate it to fit. | ||
| 48 | Returns the number of bytes stored into BUFFER. | ||
| 49 | ARGS points to the vector of arguments, and NARGS says how many. | ||
| 50 | A double counts as two arguments. | ||
| 51 | String arguments are passed as C strings. | ||
| 52 | Integers are passed as C integers. */ | ||
| 53 | |||
| 54 | EMACS_INT | ||
| 55 | doprnt (char *buffer, register int bufsize, const char *format, | ||
| 56 | const char *format_end, va_list ap) | ||
| 57 | { | ||
| 58 | const char *fmt = format; /* Pointer into format string */ | ||
| 59 | register char *bufptr = buffer; /* Pointer into output buffer.. */ | ||
| 60 | |||
| 61 | /* Use this for sprintf unless we need something really big. */ | ||
| 62 | char tembuf[DBL_MAX_10_EXP + 100]; | ||
| 63 | |||
| 64 | /* Size of sprintf_buffer. */ | ||
| 65 | unsigned size_allocated = sizeof (tembuf); | ||
| 66 | |||
| 67 | /* Buffer to use for sprintf. Either tembuf or same as BIG_BUFFER. */ | ||
| 68 | char *sprintf_buffer = tembuf; | ||
| 69 | |||
| 70 | /* Buffer we have got with malloc. */ | ||
| 71 | char *big_buffer = 0; | ||
| 72 | |||
| 73 | register int tem; | ||
| 74 | char *string; | ||
| 75 | char fixed_buffer[20]; /* Default buffer for small formatting. */ | ||
| 76 | char *fmtcpy; | ||
| 77 | int minlen; | ||
| 78 | char charbuf[MAX_MULTIBYTE_LENGTH + 1]; /* Used for %c. */ | ||
| 79 | |||
| 80 | if (format_end == 0) | ||
| 81 | format_end = format + strlen (format); | ||
| 82 | |||
| 83 | if ((format_end - format + 1) < sizeof (fixed_buffer)) | ||
| 84 | fmtcpy = fixed_buffer; | ||
| 85 | else | ||
| 86 | fmtcpy = (char *) alloca (format_end - format + 1); | ||
| 87 | |||
| 88 | bufsize--; | ||
| 89 | |||
| 90 | /* Loop until end of format string or buffer full. */ | ||
| 91 | while (fmt != format_end && bufsize > 0) | ||
| 92 | { | ||
| 93 | if (*fmt == '%') /* Check for a '%' character */ | ||
| 94 | { | ||
| 95 | unsigned size_bound = 0; | ||
| 96 | EMACS_INT width; /* Columns occupied by STRING. */ | ||
| 97 | |||
| 98 | fmt++; | ||
| 99 | /* Copy this one %-spec into fmtcpy. */ | ||
| 100 | string = fmtcpy; | ||
| 101 | *string++ = '%'; | ||
| 102 | while (1) | ||
| 103 | { | ||
| 104 | *string++ = *fmt; | ||
| 105 | if ('0' <= *fmt && *fmt <= '9') | ||
| 106 | { | ||
| 107 | /* Get an idea of how much space we might need. | ||
| 108 | This might be a field width or a precision; e.g. | ||
| 109 | %1.1000f and %1000.1f both might need 1000+ bytes. | ||
| 110 | Parse the width or precision, checking for overflow. */ | ||
| 111 | unsigned n = *fmt - '0'; | ||
| 112 | while ('0' <= fmt[1] && fmt[1] <= '9') | ||
| 113 | { | ||
| 114 | if (n * 10 + fmt[1] - '0' < n) | ||
| 115 | error ("Format width or precision too large"); | ||
| 116 | n = n * 10 + fmt[1] - '0'; | ||
| 117 | *string++ = *++fmt; | ||
| 118 | } | ||
| 119 | |||
| 120 | if (size_bound < n) | ||
| 121 | size_bound = n; | ||
| 122 | } | ||
| 123 | else if (*fmt == '-' || *fmt == ' ' || *fmt == '.' || *fmt == '+') | ||
| 124 | ; | ||
| 125 | else | ||
| 126 | break; | ||
| 127 | fmt++; | ||
| 128 | } | ||
| 129 | *string = 0; | ||
| 130 | |||
| 131 | /* Make the size bound large enough to handle floating point formats | ||
| 132 | with large numbers. */ | ||
| 133 | if (size_bound + DBL_MAX_10_EXP + 50 < size_bound) | ||
| 134 | error ("Format width or precision too large"); | ||
| 135 | size_bound += DBL_MAX_10_EXP + 50; | ||
| 136 | |||
| 137 | /* Make sure we have that much. */ | ||
| 138 | if (size_bound > size_allocated) | ||
| 139 | { | ||
| 140 | if (big_buffer) | ||
| 141 | big_buffer = (char *) xrealloc (big_buffer, size_bound); | ||
| 142 | else | ||
| 143 | big_buffer = (char *) xmalloc (size_bound); | ||
| 144 | sprintf_buffer = big_buffer; | ||
| 145 | size_allocated = size_bound; | ||
| 146 | } | ||
| 147 | minlen = 0; | ||
| 148 | switch (*fmt++) | ||
| 149 | { | ||
| 150 | default: | ||
| 151 | error ("Invalid format operation %%%c", fmt[-1]); | ||
| 152 | |||
| 153 | /* case 'b': */ | ||
| 154 | case 'd': | ||
| 155 | case 'o': | ||
| 156 | case 'x': | ||
| 157 | if (sizeof (int) == sizeof (EMACS_INT)) | ||
| 158 | ; | ||
| 159 | else if (sizeof (long) == sizeof (EMACS_INT)) | ||
| 160 | /* Insert an `l' the right place. */ | ||
| 161 | string[1] = string[0], | ||
| 162 | string[0] = string[-1], | ||
| 163 | string[-1] = 'l', | ||
| 164 | string++; | ||
| 165 | else | ||
| 166 | abort (); | ||
| 167 | sprintf (sprintf_buffer, fmtcpy, va_arg(ap, char *)); | ||
| 168 | /* Now copy into final output, truncating as nec. */ | ||
| 169 | string = sprintf_buffer; | ||
| 170 | goto doit; | ||
| 171 | |||
| 172 | case 'f': | ||
| 173 | case 'e': | ||
| 174 | case 'g': | ||
| 175 | { | ||
| 176 | double d = va_arg(ap, double); | ||
| 177 | sprintf (sprintf_buffer, fmtcpy, d); | ||
| 178 | /* Now copy into final output, truncating as nec. */ | ||
| 179 | string = sprintf_buffer; | ||
| 180 | goto doit; | ||
| 181 | } | ||
| 182 | |||
| 183 | case 'S': | ||
| 184 | string[-1] = 's'; | ||
| 185 | case 's': | ||
| 186 | if (fmtcpy[1] != 's') | ||
| 187 | minlen = atoi (&fmtcpy[1]); | ||
| 188 | string = va_arg (ap, char *); | ||
| 189 | tem = strlen (string); | ||
| 190 | width = strwidth (string, tem); | ||
| 191 | goto doit1; | ||
| 192 | |||
| 193 | /* Copy string into final output, truncating if no room. */ | ||
| 194 | doit: | ||
| 195 | /* Coming here means STRING contains ASCII only. */ | ||
| 196 | width = tem = strlen (string); | ||
| 197 | doit1: | ||
| 198 | /* We have already calculated: | ||
| 199 | TEM -- length of STRING, | ||
| 200 | WIDTH -- columns occupied by STRING when displayed, and | ||
| 201 | MINLEN -- minimum columns of the output. */ | ||
| 202 | if (minlen > 0) | ||
| 203 | { | ||
| 204 | while (minlen > width && bufsize > 0) | ||
| 205 | { | ||
| 206 | *bufptr++ = ' '; | ||
| 207 | bufsize--; | ||
| 208 | minlen--; | ||
| 209 | } | ||
| 210 | minlen = 0; | ||
| 211 | } | ||
| 212 | if (tem > bufsize) | ||
| 213 | { | ||
| 214 | /* Truncate the string at character boundary. */ | ||
| 215 | tem = bufsize; | ||
| 216 | while (!CHAR_HEAD_P (string[tem - 1])) tem--; | ||
| 217 | memcpy (bufptr, string, tem); | ||
| 218 | /* We must calculate WIDTH again. */ | ||
| 219 | width = strwidth (bufptr, tem); | ||
| 220 | } | ||
| 221 | else | ||
| 222 | memcpy (bufptr, string, tem); | ||
| 223 | bufptr += tem; | ||
| 224 | bufsize -= tem; | ||
| 225 | if (minlen < 0) | ||
| 226 | { | ||
| 227 | while (minlen < - width && bufsize > 0) | ||
| 228 | { | ||
| 229 | *bufptr++ = ' '; | ||
| 230 | bufsize--; | ||
| 231 | minlen++; | ||
| 232 | } | ||
| 233 | minlen = 0; | ||
| 234 | } | ||
| 235 | continue; | ||
| 236 | |||
| 237 | case 'c': | ||
| 238 | { | ||
| 239 | /* Sometimes for %c we pass a char, which would widen | ||
| 240 | to int. Sometimes we pass XFASTINT() or XINT() | ||
| 241 | values, which would be EMACS_INT. Let's hope that | ||
| 242 | both are passed the same way, otherwise we'll need | ||
| 243 | to rewrite callers. */ | ||
| 244 | EMACS_INT chr = va_arg(ap, EMACS_INT); | ||
| 245 | tem = CHAR_STRING ((int) chr, (unsigned char *) charbuf); | ||
| 246 | string = charbuf; | ||
| 247 | string[tem] = 0; | ||
| 248 | width = strwidth (string, tem); | ||
| 249 | if (fmtcpy[1] != 'c') | ||
| 250 | minlen = atoi (&fmtcpy[1]); | ||
| 251 | goto doit1; | ||
| 252 | } | ||
| 253 | |||
| 254 | case '%': | ||
| 255 | fmt--; /* Drop thru and this % will be treated as normal */ | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 259 | { | ||
| 260 | /* Just some character; Copy it if the whole multi-byte form | ||
| 261 | fit in the buffer. */ | ||
| 262 | char *save_bufptr = bufptr; | ||
| 263 | |||
| 264 | do { *bufptr++ = *fmt++; } | ||
| 265 | while (--bufsize > 0 && !CHAR_HEAD_P (*fmt)); | ||
| 266 | if (!CHAR_HEAD_P (*fmt)) | ||
| 267 | { | ||
| 268 | bufptr = save_bufptr; | ||
| 269 | break; | ||
| 270 | } | ||
| 271 | } | ||
| 272 | }; | ||
| 273 | |||
| 274 | /* If we had to malloc something, free it. */ | ||
| 275 | xfree (big_buffer); | ||
| 276 | |||
| 277 | *bufptr = 0; /* Make sure our string end with a '\0' */ | ||
| 278 | return bufptr - buffer; | ||
| 279 | } | ||
diff --git a/src/lisp.h b/src/lisp.h index 7999fb42d5f..a6933e70288 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -2782,9 +2782,7 @@ extern Lisp_Object internal_with_output_to_temp_buffer | |||
| 2782 | extern void float_to_string (char *, double); | 2782 | extern void float_to_string (char *, double); |
| 2783 | extern void syms_of_print (void); | 2783 | extern void syms_of_print (void); |
| 2784 | 2784 | ||
| 2785 | /* Defined in doprnt.c */ | 2785 | /* Defined in lread.c. */ |
| 2786 | extern EMACS_INT doprnt (char *, int, const char *, const char *, va_list); | ||
| 2787 | |||
| 2788 | extern Lisp_Object Qvariable_documentation, Qstandard_input; | 2786 | extern Lisp_Object Qvariable_documentation, Qstandard_input; |
| 2789 | extern Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction; | 2787 | extern Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction; |
| 2790 | extern Lisp_Object initial_obarray; | 2788 | extern Lisp_Object initial_obarray; |