428
+ − 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) 1995 Free Software Foundation, Inc.
793
+ − 5 Copyright (C) 2001, 2002 Ben Wing.
428
+ − 6 Rewritten by mly to use varargs.h.
+ − 7 Rewritten from scratch by Ben Wing (February 1995) for Mule; expanded
+ − 8 to full printf spec.
1983
+ − 9 Support for bignums, ratios, and bigfloats added April 2004 by Jerry James.
428
+ − 10
+ − 11 This file is part of XEmacs.
+ − 12
+ − 13 XEmacs is free software; you can redistribute it and/or modify it
+ − 14 under the terms of the GNU General Public License as published by the
+ − 15 Free Software Foundation; either version 2, or (at your option) any
+ − 16 later version.
+ − 17
+ − 18 XEmacs is distributed in the hope that it will be useful, but WITHOUT
+ − 19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ − 20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ − 21 for more details.
+ − 22
+ − 23 You should have received a copy of the GNU General Public License
+ − 24 along with XEmacs; see the file COPYING. If not, write to
+ − 25 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ − 26 Boston, MA 02111-1307, USA. */
+ − 27
793
+ − 28 /* Synched up with: Rewritten by Ben Wing. Not in FSF. */
428
+ − 29
+ − 30 #include <config.h>
+ − 31 #include "lisp.h"
+ − 32
+ − 33 #include "buffer.h"
+ − 34 #include "lstream.h"
+ − 35
446
+ − 36 static const char * const valid_flags = "-+ #0";
1983
+ − 37 static const char * const valid_converters = "dic" "ouxX" "feEgG" "sS"
+ − 38 #if defined(HAVE_BIGNUM) || defined(HAVE_RATIO)
+ − 39 "npyY"
+ − 40 #endif
+ − 41 #ifdef HAVE_BIGFLOAT
+ − 42 "FhHkK"
+ − 43 #endif
+ − 44 ;
446
+ − 45 static const char * const int_converters = "dic";
+ − 46 static const char * const unsigned_int_converters = "ouxX";
+ − 47 static const char * const double_converters = "feEgG";
+ − 48 static const char * const string_converters = "sS";
1983
+ − 49 #if defined(HAVE_BIGNUM) || defined(HAVE_RATIO)
+ − 50 static const char * const bignum_converters = "npyY";
+ − 51 #endif
+ − 52 #ifdef HAVE_BIGFLOAT
+ − 53 static const char * const bigfloat_converters = "FhHkK";
+ − 54 #endif
428
+ − 55
+ − 56 typedef struct printf_spec printf_spec;
+ − 57 struct printf_spec
+ − 58 {
+ − 59 int argnum; /* which argument does this spec want? This is one-based:
+ − 60 The first argument given is numbered 1, the second
+ − 61 is 2, etc. This is to handle %##$x-type specs. */
+ − 62 int minwidth;
+ − 63 int precision;
+ − 64 unsigned int minus_flag:1;
+ − 65 unsigned int plus_flag:1;
+ − 66 unsigned int space_flag:1;
+ − 67 unsigned int number_flag:1;
+ − 68 unsigned int zero_flag:1;
+ − 69 unsigned int h_flag:1;
+ − 70 unsigned int l_flag:1;
+ − 71 unsigned int forwarding_precision:1;
+ − 72 char converter; /* converter character or 0 for dummy marker
+ − 73 indicating literal text at the end of the
+ − 74 specification */
+ − 75 Bytecount text_before; /* position of the first character of the
+ − 76 block of literal text before this spec */
+ − 77 Bytecount text_before_len; /* length of that text */
+ − 78 };
+ − 79
+ − 80 typedef union printf_arg printf_arg;
+ − 81 union printf_arg
+ − 82 {
+ − 83 long l;
+ − 84 unsigned long ul;
+ − 85 double d;
867
+ − 86 Ibyte *bp;
1983
+ − 87 Lisp_Object obj;
428
+ − 88 };
+ − 89
+ − 90 /* We maintain a list of all the % specs in the specification,
+ − 91 along with the offset and length of the block of literal text
+ − 92 before each spec. In addition, we have a "dummy" spec that
+ − 93 represents all the literal text at the end of the specification.
+ − 94 Its converter is 0. */
+ − 95
+ − 96 typedef struct
+ − 97 {
+ − 98 Dynarr_declare (struct printf_spec);
+ − 99 } printf_spec_dynarr;
+ − 100
+ − 101 typedef struct
+ − 102 {
+ − 103 Dynarr_declare (union printf_arg);
+ − 104 } printf_arg_dynarr;
+ − 105
448
+ − 106 /* Append STRING (of length LEN bytes) to STREAM.
+ − 107 MINLEN is the minimum field width.
+ − 108 If MINUS_FLAG is set, left-justify the string in its field;
+ − 109 otherwise, right-justify.
+ − 110 If ZERO_FLAG is set, pad with 0's; otherwise pad with spaces.
+ − 111 If MAXLEN is non-negative, the string is first truncated on the
+ − 112 right to that many characters.
428
+ − 113
+ − 114 Note that MINLEN and MAXLEN are Charcounts but LEN is a Bytecount. */
+ − 115
+ − 116 static void
867
+ − 117 doprnt_2 (Lisp_Object stream, const Ibyte *string, Bytecount len,
428
+ − 118 Charcount minlen, Charcount maxlen, int minus_flag, int zero_flag)
+ − 119 {
+ − 120 Lstream *lstr = XLSTREAM (stream);
448
+ − 121 Charcount cclen = bytecount_to_charcount (string, len);
+ − 122 int to_add = minlen - cclen;
428
+ − 123
+ − 124 /* Padding at beginning to right-justify ... */
448
+ − 125 if (!minus_flag)
+ − 126 while (to_add-- > 0)
+ − 127 Lstream_putc (lstr, zero_flag ? '0' : ' ');
428
+ − 128
448
+ − 129 if (0 <= maxlen && maxlen < cclen)
+ − 130 len = charcount_to_bytecount (string, maxlen);
428
+ − 131 Lstream_write (lstr, string, len);
+ − 132
+ − 133 /* Padding at end to left-justify ... */
448
+ − 134 if (minus_flag)
+ − 135 while (to_add-- > 0)
+ − 136 Lstream_putc (lstr, zero_flag ? '0' : ' ');
428
+ − 137 }
+ − 138
867
+ − 139 static const Ibyte *
+ − 140 parse_off_posnum (const Ibyte *start, const Ibyte *end, int *returned_num)
428
+ − 141 {
867
+ − 142 Ibyte arg_convert[100];
+ − 143 REGISTER Ibyte *arg_ptr = arg_convert;
428
+ − 144
+ − 145 *returned_num = -1;
+ − 146 while (start != end && isdigit (*start))
+ − 147 {
647
+ − 148 if (arg_ptr - arg_convert >= (int) sizeof (arg_convert) - 1)
+ − 149 syntax_error ("Format converter number too large", Qunbound);
428
+ − 150 *arg_ptr++ = *start++;
+ − 151 }
+ − 152 *arg_ptr = '\0';
+ − 153 if (arg_convert != arg_ptr)
+ − 154 *returned_num = atoi ((char *) arg_convert);
+ − 155 return start;
+ − 156 }
+ − 157
793
+ − 158 #define NEXT_ASCII_BYTE(ch) \
+ − 159 do { \
+ − 160 if (fmt == fmt_end) \
+ − 161 syntax_error ("Premature end of format string", Qunbound); \
+ − 162 ch = *fmt; \
+ − 163 if (ch >= 0200) \
+ − 164 syntax_error ("Non-ASCII character in format converter spec", \
+ − 165 Qunbound); \
+ − 166 fmt++; \
428
+ − 167 } while (0)
+ − 168
+ − 169 #define RESOLVE_FLAG_CONFLICTS(spec) \
+ − 170 do { \
+ − 171 if (spec.space_flag && spec.plus_flag) \
+ − 172 spec.space_flag = 0; \
+ − 173 if (spec.zero_flag && spec.space_flag) \
+ − 174 spec.zero_flag = 0; \
+ − 175 } while (0)
+ − 176
+ − 177 static printf_spec_dynarr *
867
+ − 178 parse_doprnt_spec (const Ibyte *format, Bytecount format_length)
428
+ − 179 {
867
+ − 180 const Ibyte *fmt = format;
+ − 181 const Ibyte *fmt_end = format + format_length;
428
+ − 182 printf_spec_dynarr *specs = Dynarr_new (printf_spec);
+ − 183 int prev_argnum = 0;
+ − 184
+ − 185 while (1)
+ − 186 {
+ − 187 struct printf_spec spec;
867
+ − 188 const Ibyte *text_end;
+ − 189 Ibyte ch;
428
+ − 190
+ − 191 xzero (spec);
+ − 192 if (fmt == fmt_end)
+ − 193 return specs;
867
+ − 194 text_end = (Ibyte *) memchr (fmt, '%', fmt_end - fmt);
428
+ − 195 if (!text_end)
+ − 196 text_end = fmt_end;
+ − 197 spec.text_before = fmt - format;
+ − 198 spec.text_before_len = text_end - fmt;
+ − 199 fmt = text_end;
+ − 200 if (fmt != fmt_end)
+ − 201 {
+ − 202 fmt++; /* skip over % */
+ − 203
+ − 204 /* A % is special -- no arg number. According to ANSI specs,
+ − 205 field width does not apply to %% conversion. */
+ − 206 if (fmt != fmt_end && *fmt == '%')
+ − 207 {
+ − 208 spec.converter = '%';
+ − 209 Dynarr_add (specs, spec);
+ − 210 fmt++;
+ − 211 continue;
+ − 212 }
+ − 213
+ − 214 /* Is there a field number specifier? */
+ − 215 {
867
+ − 216 const Ibyte *ptr;
428
+ − 217 int fieldspec;
+ − 218
+ − 219 ptr = parse_off_posnum (fmt, fmt_end, &fieldspec);
+ − 220 if (fieldspec > 0 && ptr != fmt_end && *ptr == '$')
+ − 221 {
+ − 222 /* There is a format specifier */
+ − 223 prev_argnum = fieldspec;
+ − 224 fmt = ptr + 1;
+ − 225 }
+ − 226 else
+ − 227 prev_argnum++;
+ − 228 spec.argnum = prev_argnum;
+ − 229 }
+ − 230
+ − 231 /* Parse off any flags */
+ − 232 NEXT_ASCII_BYTE (ch);
+ − 233 while (strchr (valid_flags, ch))
+ − 234 {
+ − 235 switch (ch)
+ − 236 {
446
+ − 237 case '-': spec.minus_flag = 1; break;
+ − 238 case '+': spec.plus_flag = 1; break;
+ − 239 case ' ': spec.space_flag = 1; break;
428
+ − 240 case '#': spec.number_flag = 1; break;
446
+ − 241 case '0': spec.zero_flag = 1; break;
2500
+ − 242 default: ABORT ();
428
+ − 243 }
+ − 244 NEXT_ASCII_BYTE (ch);
+ − 245 }
+ − 246
+ − 247 /* Parse off the minimum field width */
+ − 248 fmt--; /* back up */
+ − 249
+ − 250 /*
+ − 251 * * means the field width was passed as an argument.
+ − 252 * Mark the current spec as one that forwards its
+ − 253 * field width and flags to the next spec in the array.
+ − 254 * Then create a new spec and continue with the parsing.
+ − 255 */
+ − 256 if (fmt != fmt_end && *fmt == '*')
+ − 257 {
+ − 258 spec.converter = '*';
+ − 259 RESOLVE_FLAG_CONFLICTS(spec);
+ − 260 Dynarr_add (specs, spec);
+ − 261 xzero (spec);
+ − 262 spec.argnum = ++prev_argnum;
+ − 263 fmt++;
+ − 264 }
+ − 265 else
+ − 266 {
+ − 267 fmt = parse_off_posnum (fmt, fmt_end, &spec.minwidth);
+ − 268 if (spec.minwidth == -1)
+ − 269 spec.minwidth = 0;
+ − 270 }
+ − 271
+ − 272 /* Parse off any precision specified */
+ − 273 NEXT_ASCII_BYTE (ch);
+ − 274 if (ch == '.')
+ − 275 {
+ − 276 /*
+ − 277 * * means the precision was passed as an argument.
+ − 278 * Mark the current spec as one that forwards its
+ − 279 * fieldwidth, flags and precision to the next spec in
+ − 280 * the array. Then create a new spec and continue
+ − 281 * with the parse.
+ − 282 */
+ − 283 if (fmt != fmt_end && *fmt == '*')
+ − 284 {
+ − 285 spec.converter = '*';
+ − 286 spec.forwarding_precision = 1;
+ − 287 RESOLVE_FLAG_CONFLICTS(spec);
+ − 288 Dynarr_add (specs, spec);
+ − 289 xzero (spec);
+ − 290 spec.argnum = ++prev_argnum;
+ − 291 fmt++;
+ − 292 }
+ − 293 else
+ − 294 {
+ − 295 fmt = parse_off_posnum (fmt, fmt_end, &spec.precision);
+ − 296 if (spec.precision == -1)
+ − 297 spec.precision = 0;
+ − 298 }
+ − 299 NEXT_ASCII_BYTE (ch);
+ − 300 }
+ − 301 else
+ − 302 /* No precision specified */
+ − 303 spec.precision = -1;
+ − 304
+ − 305 /* Parse off h or l flag */
+ − 306 if (ch == 'h' || ch == 'l')
+ − 307 {
+ − 308 if (ch == 'h')
+ − 309 spec.h_flag = 1;
+ − 310 else
+ − 311 spec.l_flag = 1;
+ − 312 NEXT_ASCII_BYTE (ch);
+ − 313 }
+ − 314
+ − 315 if (!strchr (valid_converters, ch))
563
+ − 316 syntax_error ("Invalid converter character", make_char (ch));
428
+ − 317 spec.converter = ch;
+ − 318 }
+ − 319
+ − 320 RESOLVE_FLAG_CONFLICTS(spec);
+ − 321 Dynarr_add (specs, spec);
+ − 322 }
+ − 323
1204
+ − 324 RETURN_NOT_REACHED(specs); /* suppress compiler warning */
428
+ − 325 }
+ − 326
+ − 327 static int
+ − 328 get_args_needed (printf_spec_dynarr *specs)
+ − 329 {
+ − 330 int args_needed = 0;
+ − 331 REGISTER int i;
+ − 332
+ − 333 /* Figure out how many args are needed. This may be less than
+ − 334 the number of specs because a spec could be %% or could be
+ − 335 missing (literal text at end of format string) or there
+ − 336 could be specs where the field number is explicitly given.
+ − 337 We just look for the maximum argument number that's referenced. */
+ − 338
+ − 339 for (i = 0; i < Dynarr_length (specs); i++)
+ − 340 {
+ − 341 char ch = Dynarr_at (specs, i).converter;
+ − 342 if (ch && ch != '%')
+ − 343 {
+ − 344 int argnum = Dynarr_at (specs, i).argnum;
+ − 345 if (argnum > args_needed)
+ − 346 args_needed = argnum;
+ − 347 }
+ − 348 }
+ − 349
+ − 350 return args_needed;
+ − 351 }
+ − 352
+ − 353 static printf_arg_dynarr *
+ − 354 get_doprnt_args (printf_spec_dynarr *specs, va_list vargs)
+ − 355 {
+ − 356 printf_arg_dynarr *args = Dynarr_new (printf_arg);
+ − 357 union printf_arg arg;
+ − 358 REGISTER int i;
+ − 359 int args_needed = get_args_needed (specs);
+ − 360
+ − 361 xzero (arg);
+ − 362 for (i = 1; i <= args_needed; i++)
+ − 363 {
+ − 364 int j;
+ − 365 char ch;
+ − 366 struct printf_spec *spec = 0;
+ − 367
+ − 368 for (j = 0; j < Dynarr_length (specs); j++)
+ − 369 {
+ − 370 spec = Dynarr_atp (specs, j);
+ − 371 if (spec->argnum == i)
+ − 372 break;
+ − 373 }
+ − 374
+ − 375 if (j == Dynarr_length (specs))
1318
+ − 376 syntax_error ("No conversion spec for argument", make_int (i));
428
+ − 377
+ − 378 ch = spec->converter;
+ − 379
+ − 380 if (strchr (int_converters, ch))
+ − 381 {
446
+ − 382 if (spec->l_flag)
428
+ − 383 arg.l = va_arg (vargs, long);
+ − 384 else
446
+ − 385 /* int even if ch == 'c' or spec->h_flag:
+ − 386 "the type used in va_arg is supposed to match the
+ − 387 actual type **after default promotions**."
+ − 388 Hence we read an int, not a short, if spec->h_flag. */
+ − 389 arg.l = va_arg (vargs, int);
428
+ − 390 }
+ − 391 else if (strchr (unsigned_int_converters, ch))
+ − 392 {
446
+ − 393 if (spec->l_flag)
428
+ − 394 arg.ul = va_arg (vargs, unsigned long);
+ − 395 else
446
+ − 396 /* unsigned int even if ch == 'c' or spec->h_flag */
+ − 397 arg.ul = (unsigned long) va_arg (vargs, unsigned int);
428
+ − 398 }
+ − 399 else if (strchr (double_converters, ch))
+ − 400 arg.d = va_arg (vargs, double);
+ − 401 else if (strchr (string_converters, ch))
867
+ − 402 arg.bp = va_arg (vargs, Ibyte *);
1983
+ − 403 #if defined(HAVE_BIGNUM) || defined(HAVE_RATIO)
+ − 404 else if (strchr (bignum_converters, ch))
+ − 405 arg.obj = va_arg (vargs, Lisp_Object);
+ − 406 #endif
+ − 407 #ifdef HAVE_BIGFLOAT
+ − 408 else if (strchr (bigfloat_converters, ch))
+ − 409 arg.obj = va_arg (vargs, Lisp_Object);
+ − 410 #endif
2500
+ − 411 else ABORT ();
428
+ − 412
+ − 413 Dynarr_add (args, arg);
+ − 414 }
+ − 415
+ − 416 return args;
+ − 417 }
+ − 418
771
+ − 419 /* Most basic entry point into string formatting.
+ − 420
+ − 421 Generate output from a format-spec (either a Lisp string
+ − 422 FORMAT_RELOC, or a C string FORMAT_NONRELOC of length FORMAT_LENGTH
+ − 423 -- which *MUST NOT* come from Lisp string data, unless GC is
+ − 424 inhibited). Output goes to STREAM. Returns the number of bytes
+ − 425 stored into STREAM. Arguments are either C-type arguments in
+ − 426 va_list VARGS, or an array of Lisp objects in LARGS of size
+ − 427 NARGS. (Behavior is different in the two cases -- you either get
+ − 428 standard sprintf() behavior or `format' behavior.) */
428
+ − 429
+ − 430 static Bytecount
867
+ − 431 emacs_doprnt_1 (Lisp_Object stream, const Ibyte *format_nonreloc,
771
+ − 432 Bytecount format_length, Lisp_Object format_reloc,
+ − 433 int nargs, const Lisp_Object *largs, va_list vargs)
428
+ − 434 {
+ − 435 printf_spec_dynarr *specs = 0;
+ − 436 printf_arg_dynarr *args = 0;
+ − 437 REGISTER int i;
+ − 438 int init_byte_count = Lstream_byte_count (XLSTREAM (stream));
771
+ − 439 int count;
428
+ − 440
+ − 441 if (!NILP (format_reloc))
+ − 442 {
+ − 443 format_nonreloc = XSTRING_DATA (format_reloc);
+ − 444 format_length = XSTRING_LENGTH (format_reloc);
+ − 445 }
+ − 446 if (format_length < 0)
442
+ − 447 format_length = (Bytecount) strlen ((const char *) format_nonreloc);
428
+ − 448
+ − 449 specs = parse_doprnt_spec (format_nonreloc, format_length);
771
+ − 450 count = record_unwind_protect_freeing_dynarr (specs);
+ − 451
428
+ − 452 if (largs)
+ − 453 {
446
+ − 454 /* allow too many args for string, but not too few */
428
+ − 455 if (nargs < get_args_needed (specs))
563
+ − 456 signal_error_1 (Qwrong_number_of_arguments,
1318
+ − 457 list3 (Qformat,
+ − 458 make_int (nargs),
+ − 459 !NILP (format_reloc) ? format_reloc :
+ − 460 make_string (format_nonreloc, format_length)));
428
+ − 461 }
+ − 462 else
+ − 463 {
+ − 464 args = get_doprnt_args (specs, vargs);
771
+ − 465 record_unwind_protect_freeing_dynarr (args);
428
+ − 466 }
+ − 467
+ − 468 for (i = 0; i < Dynarr_length (specs); i++)
+ − 469 {
+ − 470 struct printf_spec *spec = Dynarr_atp (specs, i);
+ − 471 char ch;
+ − 472
+ − 473 /* Copy the text before */
+ − 474 if (!NILP (format_reloc)) /* refetch in case of GC below */
+ − 475 format_nonreloc = XSTRING_DATA (format_reloc);
446
+ − 476
771
+ − 477 doprnt_2 (stream, format_nonreloc + spec->text_before,
446
+ − 478 spec->text_before_len, 0, -1, 0, 0);
428
+ − 479
+ − 480 ch = spec->converter;
+ − 481
+ − 482 if (!ch)
+ − 483 continue;
+ − 484
+ − 485 if (ch == '%')
+ − 486 {
867
+ − 487 doprnt_2 (stream, (Ibyte *) &ch, 1, 0, -1, 0, 0);
428
+ − 488 continue;
+ − 489 }
+ − 490
+ − 491 /* The char '*' as converter means the field width, precision
+ − 492 was specified as an argument. Extract the data and forward
+ − 493 it to the next spec, to which it will apply. */
+ − 494 if (ch == '*')
+ − 495 {
+ − 496 struct printf_spec *nextspec = Dynarr_atp (specs, i + 1);
+ − 497 Lisp_Object obj = largs[spec->argnum - 1];
+ − 498
+ − 499 if (INTP (obj))
+ − 500 {
+ − 501 if (spec->forwarding_precision)
+ − 502 {
+ − 503 nextspec->precision = XINT (obj);
+ − 504 nextspec->minwidth = spec->minwidth;
+ − 505 }
+ − 506 else
+ − 507 {
+ − 508 nextspec->minwidth = XINT (obj);
446
+ − 509 if (XINT (obj) < 0)
428
+ − 510 {
+ − 511 spec->minus_flag = 1;
+ − 512 nextspec->minwidth = - nextspec->minwidth;
+ − 513 }
+ − 514 }
446
+ − 515 nextspec->minus_flag = spec->minus_flag;
+ − 516 nextspec->plus_flag = spec->plus_flag;
+ − 517 nextspec->space_flag = spec->space_flag;
428
+ − 518 nextspec->number_flag = spec->number_flag;
446
+ − 519 nextspec->zero_flag = spec->zero_flag;
428
+ − 520 }
+ − 521 continue;
+ − 522 }
+ − 523
+ − 524 if (largs && (spec->argnum < 1 || spec->argnum > nargs))
771
+ − 525 syntax_error ("Invalid repositioning argument",
+ − 526 make_int (spec->argnum));
428
+ − 527
+ − 528 else if (ch == 'S' || ch == 's')
+ − 529 {
867
+ − 530 Ibyte *string;
428
+ − 531 Bytecount string_len;
+ − 532
+ − 533 if (!largs)
+ − 534 {
+ − 535 string = Dynarr_at (args, spec->argnum - 1).bp;
771
+ − 536 #if 0
+ − 537 /* [[ error() can be called with null string arguments.
428
+ − 538 E.g., in fileio.c, the return value of strerror()
+ − 539 is never checked. We'll print (null), like some
+ − 540 printf implementations do. Would it be better (and safe)
+ − 541 to signal an error instead? Or should we just use the
771
+ − 542 empty string? -dkindred@cs.cmu.edu 8/1997 ]]
+ − 543 Do not hide bugs. --ben
428
+ − 544 */
+ − 545 if (!string)
867
+ − 546 string = (Ibyte *) "(null)";
771
+ − 547 #else
+ − 548 assert (string);
+ − 549 #endif
428
+ − 550 string_len = strlen ((char *) string);
+ − 551 }
+ − 552 else
+ − 553 {
+ − 554 Lisp_Object obj = largs[spec->argnum - 1];
793
+ − 555 Lisp_Object ls;
428
+ − 556
+ − 557 if (ch == 'S')
+ − 558 {
+ − 559 /* For `S', prin1 the argument and then treat like
+ − 560 a string. */
793
+ − 561 ls = Fprin1_to_string (obj, Qnil);
428
+ − 562 }
+ − 563 else if (STRINGP (obj))
793
+ − 564 ls = obj;
428
+ − 565 else if (SYMBOLP (obj))
+ − 566 ls = XSYMBOL (obj)->name;
+ − 567 else
+ − 568 {
+ − 569 /* convert to string using princ. */
793
+ − 570 ls = Fprin1_to_string (obj, Qt);
428
+ − 571 }
793
+ − 572 string = XSTRING_DATA (ls);
+ − 573 string_len = XSTRING_LENGTH (ls);
428
+ − 574 }
+ − 575
771
+ − 576 doprnt_2 (stream, string, string_len, spec->minwidth,
428
+ − 577 spec->precision, spec->minus_flag, spec->zero_flag);
+ − 578 }
+ − 579
+ − 580 else
+ − 581 {
+ − 582 /* Must be a number. */
+ − 583 union printf_arg arg;
+ − 584
+ − 585 if (!largs)
+ − 586 {
+ − 587 arg = Dynarr_at (args, spec->argnum - 1);
+ − 588 }
+ − 589 else
+ − 590 {
+ − 591 Lisp_Object obj = largs[spec->argnum - 1];
+ − 592 if (CHARP (obj))
+ − 593 obj = make_int (XCHAR (obj));
1983
+ − 594 #ifdef WITH_NUMBER_TYPES
+ − 595 if (!NUMBERP (obj))
+ − 596 #else
428
+ − 597 if (!INT_OR_FLOATP (obj))
1983
+ − 598 #endif
428
+ − 599 {
2267
+ − 600 /* WARNING! This MUST be big enough for the sprintf below */
2272
+ − 601 CIbyte msg[48];
+ − 602 sprintf (msg,
2267
+ − 603 "format specifier %%%c doesn't match argument type",
+ − 604 ch);
2272
+ − 605 syntax_error (msg, Qnil);
428
+ − 606 }
+ − 607 else if (strchr (double_converters, ch))
1983
+ − 608 {
+ − 609 #ifdef WITH_NUMBER_TYPES
+ − 610 if (INTP (obj) || FLOATP (obj))
+ − 611 arg.d = XFLOATINT (obj);
+ − 612 #ifdef HAVE_BIGNUM
+ − 613 else if (BIGNUMP (obj))
+ − 614 arg.d = bignum_to_double (XBIGNUM_DATA (obj));
+ − 615 #endif
+ − 616 #ifdef HAVE_RATIO
+ − 617 else if (RATIOP (obj))
+ − 618 arg.d = ratio_to_double (XRATIO_DATA (obj));
+ − 619 #endif
+ − 620 #ifdef HAVE_BIGFLOAT
+ − 621 else if (BIGFLOATP (obj))
+ − 622 {
+ − 623 arg.obj = obj;
+ − 624 switch (ch)
+ − 625 {
+ − 626 case 'f': ch = 'F'; break;
+ − 627 case 'e': ch = 'h'; break;
+ − 628 case 'E': ch = 'H'; break;
+ − 629 case 'g': ch = 'k'; break;
+ − 630 case 'G': ch = 'K'; break;
+ − 631 }
+ − 632 }
+ − 633 #endif
+ − 634 #else /* !WITH_NUMBER_TYPES */
+ − 635 arg.d = XFLOATINT (obj);
+ − 636 #endif /* WITH_NUMBER_TYPES */
+ − 637 }
428
+ − 638 else
+ − 639 {
446
+ − 640 if (FLOATP (obj))
+ − 641 obj = Ftruncate (obj);
1983
+ − 642 #ifdef HAVE_BIGFLOAT
+ − 643 else if (BIGFLOATP (obj))
+ − 644 {
+ − 645 #ifdef HAVE_BIGNUM
+ − 646 bignum_set_bigfloat (scratch_bignum,
+ − 647 XBIGFLOAT_DATA (obj));
+ − 648 if (strchr (unsigned_int_converters, ch) &&
+ − 649 bignum_sign (scratch_bignum) < 0)
+ − 650 dead_wrong_type_argument (Qnonnegativep, obj);
+ − 651 obj =
+ − 652 Fcanonicalize_number (make_bignum_bg (scratch_bignum));
+ − 653 #else /* !HAVE_BIGNUM */
+ − 654 obj = make_int (bigfloat_to_long (XBIGFLOAT_DATA (obj)));
+ − 655 #endif /* HAVE_BIGNUM */
+ − 656 }
+ − 657 #endif /* HAVE_BIGFLOAT */
+ − 658 #ifdef HAVE_RATIO
+ − 659 else if (RATIOP (obj))
+ − 660 {
+ − 661 arg.obj = obj;
+ − 662 switch (ch)
+ − 663 {
+ − 664 case 'i': case 'd': ch = 'n'; break;
+ − 665 case 'o': ch = 'p'; break;
+ − 666 case 'x': ch = 'y'; break;
+ − 667 case 'X': ch = 'Y'; break;
+ − 668 default: /* ch == 'u' */
+ − 669 if (strchr (unsigned_int_converters, ch) &&
+ − 670 ratio_sign (XRATIO_DATA (obj)) < 0)
+ − 671 dead_wrong_type_argument (Qnonnegativep, obj);
+ − 672 else
+ − 673 ch = 'n';
+ − 674 }
+ − 675 }
+ − 676 #endif
+ − 677 #ifdef HAVE_BIGNUM
+ − 678 if (BIGNUMP (obj))
+ − 679 {
+ − 680 arg.obj = obj;
+ − 681 switch (ch)
+ − 682 {
+ − 683 case 'i': case 'd': ch = 'n'; break;
+ − 684 case 'o': ch = 'p'; break;
+ − 685 case 'x': ch = 'y'; break;
+ − 686 case 'X': ch = 'Y'; break;
+ − 687 default: /* ch == 'u' */
+ − 688 if (strchr (unsigned_int_converters, ch) &&
+ − 689 bignum_sign (XBIGNUM_DATA (obj)) < 0)
+ − 690 dead_wrong_type_argument (Qnatnump, obj);
+ − 691 else
+ − 692 ch = 'n';
+ − 693 }
+ − 694 }
+ − 695 #endif
+ − 696 if (INTP (obj))
+ − 697 {
+ − 698 if (strchr (unsigned_int_converters, ch))
+ − 699 {
+ − 700 #ifdef HAVE_BIGNUM
+ − 701 if (XINT (obj) < 0)
+ − 702 dead_wrong_type_argument (Qnatnump, obj);
+ − 703 #endif
+ − 704 arg.ul = (unsigned long) XUINT (obj);
+ − 705 }
+ − 706 else
+ − 707 arg.l = XINT (obj);
+ − 708 }
428
+ − 709 }
+ − 710 }
+ − 711
+ − 712 if (ch == 'c')
+ − 713 {
867
+ − 714 Ichar a;
428
+ − 715 Bytecount charlen;
867
+ − 716 Ibyte charbuf[MAX_ICHAR_LEN];
428
+ − 717
867
+ − 718 a = (Ichar) arg.l;
428
+ − 719
867
+ − 720 if (!valid_ichar_p (a))
2267
+ − 721 {
+ − 722 /* WARNING! This MUST be big enough for the sprintf below */
2272
+ − 723 CIbyte msg[60];
+ − 724 sprintf (msg, "invalid character value %d to %%c spec",
2267
+ − 725 a);
2272
+ − 726 syntax_error (msg, Qnil);
2267
+ − 727 }
428
+ − 728
867
+ − 729 charlen = set_itext_ichar (charbuf, a);
771
+ − 730 doprnt_2 (stream, charbuf, charlen, spec->minwidth,
428
+ − 731 -1, spec->minus_flag, spec->zero_flag);
+ − 732 }
1983
+ − 733 #if defined(HAVE_BIGNUM) || defined(HAVE_RATIO)
+ − 734 else if (strchr (bignum_converters, ch))
+ − 735 {
+ − 736 #ifdef HAVE_BIGNUM
+ − 737 if (BIGNUMP (arg.obj))
+ − 738 {
1995
+ − 739 Ibyte *text_to_print =
+ − 740 (Ibyte *) bignum_to_string (XBIGNUM_DATA (arg.obj),
+ − 741 ch == 'n' ? 10 :
+ − 742 (ch == 'p' ? 8 : 16));
+ − 743 doprnt_2 (stream, text_to_print,
+ − 744 strlen ((const char *) text_to_print),
1983
+ − 745 spec->minwidth, -1, spec->minus_flag,
+ − 746 spec->zero_flag);
1995
+ − 747 xfree (text_to_print, Ibyte *);
1983
+ − 748 }
+ − 749 #endif
+ − 750 #ifdef HAVE_RATIO
+ − 751 if (RATIOP (arg.obj))
+ − 752 {
1995
+ − 753 Ibyte *text_to_print =
+ − 754 (Ibyte *) ratio_to_string (XRATIO_DATA (arg.obj),
+ − 755 ch == 'n' ? 10 :
+ − 756 (ch == 'p' ? 8 : 16));
+ − 757 doprnt_2 (stream, text_to_print,
+ − 758 strlen ((const char *) text_to_print),
1983
+ − 759 spec->minwidth, -1, spec->minus_flag,
+ − 760 spec->zero_flag);
1995
+ − 761 xfree (text_to_print, Ibyte *);
1983
+ − 762 }
+ − 763 #endif
+ − 764 }
+ − 765 #endif /* HAVE_BIGNUM || HAVE_RATIO */
+ − 766 #ifdef HAVE_BIGFLOAT
+ − 767 else if (strchr (bigfloat_converters, ch))
+ − 768 {
1995
+ − 769 Ibyte *text_to_print =
+ − 770 (Ibyte *) bigfloat_to_string (XBIGFLOAT_DATA (arg.obj), 10);
+ − 771 doprnt_2 (stream, text_to_print,
+ − 772 strlen ((const char *) text_to_print),
1983
+ − 773 spec->minwidth, -1, spec->minus_flag, spec->zero_flag);
1995
+ − 774 xfree (text_to_print, Ibyte *);
1983
+ − 775 }
+ − 776 #endif /* HAVE_BIGFLOAT */
428
+ − 777 else
+ − 778 {
3706
+ − 779 Ascbyte *text_to_print = alloca_array (char, 350);
+ − 780 Ascbyte constructed_spec[100];
+ − 781 Ascbyte *p = constructed_spec;
428
+ − 782
448
+ − 783 /* Mostly reconstruct the spec and use sprintf() to
428
+ − 784 format the string. */
+ − 785
446
+ − 786 *p++ = '%';
+ − 787 if (spec->plus_flag) *p++ = '+';
+ − 788 if (spec->space_flag) *p++ = ' ';
+ − 789 if (spec->number_flag) *p++ = '#';
448
+ − 790 if (spec->minus_flag) *p++ = '-';
+ − 791 if (spec->zero_flag) *p++ = '0';
446
+ − 792
448
+ − 793 if (spec->minwidth >= 0)
577
+ − 794 {
+ − 795 long_to_string (p, spec->minwidth);
+ − 796 p += strlen (p);
+ − 797 }
448
+ − 798 if (spec->precision >= 0)
428
+ − 799 {
446
+ − 800 *p++ = '.';
577
+ − 801 long_to_string (p, spec->precision);
+ − 802 p += strlen (p);
428
+ − 803 }
448
+ − 804
428
+ − 805 if (strchr (double_converters, ch))
442
+ − 806 {
446
+ − 807 *p++ = ch;
+ − 808 *p++ = '\0';
442
+ − 809 sprintf (text_to_print, constructed_spec, arg.d);
+ − 810 }
428
+ − 811 else
+ − 812 {
448
+ − 813 *p++ = 'l'; /* Always use longs with sprintf() */
+ − 814 *p++ = ch;
+ − 815 *p++ = '\0';
446
+ − 816
+ − 817 if (strchr (unsigned_int_converters, ch))
+ − 818 sprintf (text_to_print, constructed_spec, arg.ul);
+ − 819 else
428
+ − 820 sprintf (text_to_print, constructed_spec, arg.l);
+ − 821 }
+ − 822
867
+ − 823 doprnt_2 (stream, (Ibyte *) text_to_print,
448
+ − 824 strlen (text_to_print), 0, -1, 0, 0);
428
+ − 825 }
+ − 826 }
+ − 827 }
+ − 828
771
+ − 829 unbind_to (count);
428
+ − 830 return Lstream_byte_count (XLSTREAM (stream)) - init_byte_count;
+ − 831 }
+ − 832
771
+ − 833 /* Basic external entry point into string formatting. See
+ − 834 emacs_doprnt_1().
+ − 835 */
+ − 836
+ − 837 Bytecount
867
+ − 838 emacs_doprnt_va (Lisp_Object stream, const Ibyte *format_nonreloc,
771
+ − 839 Bytecount format_length, Lisp_Object format_reloc,
+ − 840 va_list vargs)
+ − 841 {
+ − 842 return emacs_doprnt_1 (stream, format_nonreloc, format_length,
+ − 843 format_reloc, 0, 0, vargs);
+ − 844 }
+ − 845
+ − 846 /* Basic external entry point into string formatting. See
+ − 847 emacs_doprnt_1().
+ − 848 */
+ − 849
+ − 850 Bytecount
867
+ − 851 emacs_doprnt (Lisp_Object stream, const Ibyte *format_nonreloc,
771
+ − 852 Bytecount format_length, Lisp_Object format_reloc,
+ − 853 int nargs, const Lisp_Object *largs, ...)
428
+ − 854 {
+ − 855 va_list vargs;
+ − 856 Bytecount val;
+ − 857 va_start (vargs, largs);
771
+ − 858 val = emacs_doprnt_1 (stream, format_nonreloc, format_length,
+ − 859 format_reloc, nargs, largs, vargs);
428
+ − 860 va_end (vargs);
+ − 861 return val;
+ − 862 }
+ − 863
771
+ − 864 /* Similar to `format' in that its arguments are Lisp objects rather than C
+ − 865 objects. (For the versions that take C objects, see the
+ − 866 emacs_[v]sprintf... functions below.) Accepts the format string as
+ − 867 either a C string (FORMAT_NONRELOC, which *MUST NOT* come from Lisp
+ − 868 string data, unless GC is inhibited) or a Lisp string (FORMAT_RELOC).
+ − 869 Return resulting formatted string as a Lisp string.
428
+ − 870
771
+ − 871 All arguments are GCPRO'd, including FORMAT_RELOC; this makes it OK to
+ − 872 pass newly created objects into this function (as often happens).
428
+ − 873
771
+ − 874 #### It shouldn't be necessary to specify the number of arguments.
+ − 875 This would require some rewriting of the doprnt() functions, though.
+ − 876 */
428
+ − 877
+ − 878 Lisp_Object
867
+ − 879 emacs_vsprintf_string_lisp (const CIbyte *format_nonreloc,
771
+ − 880 Lisp_Object format_reloc, int nargs,
+ − 881 const Lisp_Object *largs)
428
+ − 882 {
771
+ − 883 Lisp_Object stream;
428
+ − 884 Lisp_Object obj;
771
+ − 885 struct gcpro gcpro1, gcpro2;
+ − 886 GCPRO2 (largs[0], format_reloc);
+ − 887 gcpro1.nvars = nargs;
428
+ − 888
771
+ − 889 stream = make_resizing_buffer_output_stream ();
867
+ − 890 emacs_doprnt (stream, (Ibyte *) format_nonreloc, format_nonreloc ?
771
+ − 891 strlen (format_nonreloc) : 0,
+ − 892 format_reloc, nargs, largs);
428
+ − 893 Lstream_flush (XLSTREAM (stream));
+ − 894 obj = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
+ − 895 Lstream_byte_count (XLSTREAM (stream)));
771
+ − 896 Lstream_delete (XLSTREAM (stream));
428
+ − 897 UNGCPRO;
+ − 898 return obj;
+ − 899 }
+ − 900
771
+ − 901 /* Like emacs_vsprintf_string_lisp() but accepts its extra args directly
+ − 902 (using variable arguments), rather than as an array. */
+ − 903
428
+ − 904 Lisp_Object
867
+ − 905 emacs_sprintf_string_lisp (const CIbyte *format_nonreloc,
771
+ − 906 Lisp_Object format_reloc, int nargs, ...)
428
+ − 907 {
771
+ − 908 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
+ − 909 va_list va;
+ − 910 int i;
428
+ − 911 Lisp_Object obj;
+ − 912
771
+ − 913 va_start (va, nargs);
+ − 914 for (i = 0; i < nargs; i++)
+ − 915 args[i] = va_arg (va, Lisp_Object);
+ − 916 va_end (va);
+ − 917 obj = emacs_vsprintf_string_lisp (format_nonreloc, format_reloc, nargs,
+ − 918 args);
428
+ − 919 return obj;
+ − 920 }
+ − 921
771
+ − 922 /* Like emacs_vsprintf_string_lisp() but returns a malloc()ed memory block.
+ − 923 Return length out through LEN_OUT, if not null. */
+ − 924
867
+ − 925 Ibyte *
+ − 926 emacs_vsprintf_malloc_lisp (const CIbyte *format_nonreloc,
771
+ − 927 Lisp_Object format_reloc, int nargs,
+ − 928 const Lisp_Object *largs, Bytecount *len_out)
+ − 929 {
+ − 930 Lisp_Object stream;
867
+ − 931 Ibyte *retval;
771
+ − 932 Bytecount len;
+ − 933 struct gcpro gcpro1, gcpro2;
+ − 934
+ − 935 GCPRO2 (largs[0], format_reloc);
+ − 936 gcpro1.nvars = nargs;
+ − 937
+ − 938 stream = make_resizing_buffer_output_stream ();
867
+ − 939 emacs_doprnt (stream, (Ibyte *) format_nonreloc, format_nonreloc ?
771
+ − 940 strlen (format_nonreloc) : 0,
+ − 941 format_reloc, nargs, largs);
+ − 942 Lstream_flush (XLSTREAM (stream));
+ − 943 len = Lstream_byte_count (XLSTREAM (stream));
2367
+ − 944 retval = xnew_ibytes (len + 1);
771
+ − 945 memcpy (retval, resizing_buffer_stream_ptr (XLSTREAM (stream)), len);
+ − 946 retval[len] = '\0';
+ − 947 Lstream_delete (XLSTREAM (stream));
+ − 948
+ − 949 if (len_out)
+ − 950 *len_out = len;
+ − 951 UNGCPRO;
+ − 952 return retval;
+ − 953 }
+ − 954
+ − 955 /* Like emacs_sprintf_string_lisp() but returns a malloc()ed memory block.
+ − 956 Return length out through LEN_OUT, if not null. */
+ − 957
867
+ − 958 Ibyte *
+ − 959 emacs_sprintf_malloc_lisp (Bytecount *len_out, const CIbyte *format_nonreloc,
771
+ − 960 Lisp_Object format_reloc, int nargs, ...)
+ − 961 {
+ − 962 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
+ − 963 va_list va;
+ − 964 int i;
867
+ − 965 Ibyte *retval;
771
+ − 966
+ − 967 va_start (va, nargs);
+ − 968 for (i = 0; i < nargs; i++)
+ − 969 args[i] = va_arg (va, Lisp_Object);
+ − 970 va_end (va);
+ − 971 retval = emacs_vsprintf_malloc_lisp (format_nonreloc, format_reloc, nargs,
+ − 972 args, len_out);
+ − 973 return retval;
+ − 974 }
+ − 975
+ − 976 /* vsprintf()-like replacement. Returns a Lisp string. Data
+ − 977 from Lisp strings is OK because we explicitly inhibit GC. */
+ − 978
428
+ − 979 Lisp_Object
867
+ − 980 emacs_vsprintf_string (const CIbyte *format, va_list vargs)
428
+ − 981 {
771
+ − 982 Lisp_Object stream = make_resizing_buffer_output_stream ();
428
+ − 983 Lisp_Object obj;
771
+ − 984 int count = begin_gc_forbidden ();
428
+ − 985
867
+ − 986 emacs_doprnt_va (stream, (Ibyte *) format, strlen (format), Qnil,
771
+ − 987 vargs);
428
+ − 988 Lstream_flush (XLSTREAM (stream));
+ − 989 obj = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
+ − 990 Lstream_byte_count (XLSTREAM (stream)));
+ − 991 Lstream_delete (XLSTREAM (stream));
771
+ − 992 end_gc_forbidden (count);
428
+ − 993 return obj;
+ − 994 }
+ − 995
771
+ − 996 /* sprintf()-like replacement. Returns a Lisp string. Data
+ − 997 from Lisp strings is OK because we explicitly inhibit GC. */
+ − 998
428
+ − 999 Lisp_Object
867
+ − 1000 emacs_sprintf_string (const CIbyte *format, ...)
771
+ − 1001 {
+ − 1002 va_list vargs;
+ − 1003 Lisp_Object retval;
+ − 1004
+ − 1005 va_start (vargs, format);
+ − 1006 retval = emacs_vsprintf_string (format, vargs);
+ − 1007 va_end (vargs);
+ − 1008 return retval;
+ − 1009 }
+ − 1010
+ − 1011 /* vsprintf()-like replacement. Returns a malloc()ed memory block. Data
+ − 1012 from Lisp strings is OK because we explicitly inhibit GC. Return
+ − 1013 length out through LEN_OUT, if not null. */
+ − 1014
867
+ − 1015 Ibyte *
+ − 1016 emacs_vsprintf_malloc (const CIbyte *format, va_list vargs,
771
+ − 1017 Bytecount *len_out)
428
+ − 1018 {
771
+ − 1019 int count = begin_gc_forbidden ();
428
+ − 1020 Lisp_Object stream = make_resizing_buffer_output_stream ();
867
+ − 1021 Ibyte *retval;
771
+ − 1022 Bytecount len;
+ − 1023
867
+ − 1024 emacs_doprnt_va (stream, (Ibyte *) format, strlen (format), Qnil,
771
+ − 1025 vargs);
+ − 1026 Lstream_flush (XLSTREAM (stream));
+ − 1027 len = Lstream_byte_count (XLSTREAM (stream));
2367
+ − 1028 retval = xnew_ibytes (len + 1);
771
+ − 1029 memcpy (retval, resizing_buffer_stream_ptr (XLSTREAM (stream)), len);
+ − 1030 retval[len] = '\0';
+ − 1031 end_gc_forbidden (count);
+ − 1032 Lstream_delete (XLSTREAM (stream));
+ − 1033
+ − 1034 if (len_out)
+ − 1035 *len_out = len;
+ − 1036 return retval;
+ − 1037 }
+ − 1038
+ − 1039 /* sprintf()-like replacement. Returns a malloc()ed memory block. Data
+ − 1040 from Lisp strings is OK because we explicitly inhibit GC. Return length
+ − 1041 out through LEN_OUT, if not null. */
428
+ − 1042
867
+ − 1043 Ibyte *
+ − 1044 emacs_sprintf_malloc (Bytecount *len_out, const CIbyte *format, ...)
771
+ − 1045 {
+ − 1046 va_list vargs;
867
+ − 1047 Ibyte *retval;
771
+ − 1048
+ − 1049 va_start (vargs, format);
+ − 1050 retval = emacs_vsprintf_malloc (format, vargs, len_out);
428
+ − 1051 va_end (vargs);
771
+ − 1052 return retval;
+ − 1053 }
+ − 1054
+ − 1055 /* vsprintf() replacement. Writes output into OUTPUT, which better
+ − 1056 have enough space for the output. Data from Lisp strings is OK
+ − 1057 because we explicitly inhibit GC. */
+ − 1058
+ − 1059 Bytecount
867
+ − 1060 emacs_vsprintf (Ibyte *output, const CIbyte *format, va_list vargs)
771
+ − 1061 {
+ − 1062 Bytecount retval;
+ − 1063 int count = begin_gc_forbidden ();
+ − 1064 Lisp_Object stream = make_resizing_buffer_output_stream ();
+ − 1065 Bytecount len;
428
+ − 1066
867
+ − 1067 retval = emacs_doprnt_va (stream, (Ibyte *) format, strlen (format), Qnil,
771
+ − 1068 vargs);
428
+ − 1069 Lstream_flush (XLSTREAM (stream));
771
+ − 1070 len = Lstream_byte_count (XLSTREAM (stream));
+ − 1071 memcpy (output, resizing_buffer_stream_ptr (XLSTREAM (stream)), len);
+ − 1072 output[len] = '\0';
+ − 1073 end_gc_forbidden (count);
428
+ − 1074 Lstream_delete (XLSTREAM (stream));
771
+ − 1075
+ − 1076 return retval;
428
+ − 1077 }
771
+ − 1078
+ − 1079 /* sprintf() replacement. Writes output into OUTPUT, which better
+ − 1080 have enough space for the output. Data from Lisp strings is OK
+ − 1081 because we explicitly inhibit GC. */
+ − 1082
+ − 1083 Bytecount
867
+ − 1084 emacs_sprintf (Ibyte *output, const CIbyte *format, ...)
771
+ − 1085 {
+ − 1086 va_list vargs;
+ − 1087 Bytecount retval;
+ − 1088
+ − 1089 va_start (vargs, format);
+ − 1090 retval = emacs_vsprintf (output, format, vargs);
+ − 1091 va_end (vargs);
+ − 1092 return retval;
+ − 1093 }