comparison src/editfns.c @ 4019:0463aae99f4e

* editfns.c (Fformat): Since floats occupy two elements in the argument list passed to doprnt, we must use separate indices for the array of arguments passed to Fformat, and the array of arguments to be passed to doprnt.
author Jim Blandy <jimb@redhat.com>
date Wed, 07 Jul 1993 10:22:05 +0000
parents 301e2dca5fd7
children 03a4c3912c13
comparison
equal deleted inserted replaced
4018:43a30cb1b170 4019:0463aae99f4e
1392 } 1392 }
1393 } 1393 }
1394 1394
1395 { 1395 {
1396 register int nstrings = n + 1; 1396 register int nstrings = n + 1;
1397
1398 /* Allocate twice as many strings as we have %-escapes; floats occupy
1399 two slots, and we're not sure how many of those we have. */
1397 register unsigned char **strings 1400 register unsigned char **strings
1398 = (unsigned char **) alloca (nstrings * sizeof (unsigned char *)); 1401 = (unsigned char **) alloca (2 * nstrings * sizeof (unsigned char *));
1399 1402 int i;
1403
1404 i = 0;
1400 for (n = 0; n < nstrings; n++) 1405 for (n = 0; n < nstrings; n++)
1401 { 1406 {
1402 if (n >= nargs) 1407 if (n >= nargs)
1403 strings[n] = (unsigned char *) ""; 1408 strings[i++] = (unsigned char *) "";
1404 else if (XTYPE (args[n]) == Lisp_Int) 1409 else if (XTYPE (args[n]) == Lisp_Int)
1405 /* We checked above that the corresponding format effector 1410 /* We checked above that the corresponding format effector
1406 isn't %s, which would cause MPV. */ 1411 isn't %s, which would cause MPV. */
1407 strings[n] = (unsigned char *) XINT (args[n]); 1412 strings[i++] = (unsigned char *) XINT (args[n]);
1408 #ifdef LISP_FLOAT_TYPE 1413 #ifdef LISP_FLOAT_TYPE
1409 else if (XTYPE (args[n]) == Lisp_Float) 1414 else if (XTYPE (args[n]) == Lisp_Float)
1410 { 1415 {
1411 union { double d; int half[2]; } u; 1416 union { double d; int half[2]; } u;
1412 1417
1413 u.d = XFLOAT (args[n])->data; 1418 u.d = XFLOAT (args[n])->data;
1414 strings[n++] = (unsigned char *) u.half[0]; 1419 strings[i++] = (unsigned char *) u.half[0];
1415 strings[n] = (unsigned char *) u.half[1]; 1420 strings[i++] = (unsigned char *) u.half[1];
1416 } 1421 }
1417 #endif 1422 #endif
1418 else 1423 else
1419 strings[n] = XSTRING (args[n])->data; 1424 strings[i++] = XSTRING (args[n])->data;
1420 } 1425 }
1421 1426
1422 /* Format it in bigger and bigger buf's until it all fits. */ 1427 /* Format it in bigger and bigger buf's until it all fits. */
1423 while (1) 1428 while (1)
1424 { 1429 {
1425 buf = (char *) alloca (total + 1); 1430 buf = (char *) alloca (total + 1);
1426 buf[total - 1] = 0; 1431 buf[total - 1] = 0;
1427 1432
1428 length = doprnt (buf, total + 1, strings[0], end, nargs, strings + 1); 1433 length = doprnt (buf, total + 1, strings[0], end, i-1, strings + 1);
1429 if (buf[total - 1] == 0) 1434 if (buf[total - 1] == 0)
1430 break; 1435 break;
1431 1436
1432 total *= 2; 1437 total *= 2;
1433 } 1438 }