Mercurial > emacs
comparison src/editfns.c @ 21225:47e189a470d2
(Fformat): Handle padding before or after, for %s etc.
Treat 0 like a multibyte char in %c.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 20 Mar 1998 04:59:15 +0000 |
parents | ef954087e7b9 |
children | c8d0df2cbd3d |
comparison
equal
deleted
inserted
replaced
21224:1581abe1a67e | 21225:47e189a470d2 |
---|---|
2311 be a double. */ | 2311 be a double. */ |
2312 if (*format == 'e' || *format == 'f' || *format == 'g') | 2312 if (*format == 'e' || *format == 'f' || *format == 'g') |
2313 args[n] = Ffloat (args[n]); | 2313 args[n] = Ffloat (args[n]); |
2314 #endif | 2314 #endif |
2315 thissize = 30; | 2315 thissize = 30; |
2316 if (*format == 'c' && ! SINGLE_BYTE_CHAR_P (XINT (args[n]))) | 2316 if (*format == 'c' |
2317 && (! SINGLE_BYTE_CHAR_P (XINT (args[n])) | |
2318 || XINT (args[n]) == 0)) | |
2317 { | 2319 { |
2318 if (! multibyte) | 2320 if (! multibyte) |
2319 { | 2321 { |
2320 multibyte = 1; | 2322 multibyte = 1; |
2321 goto retry; | 2323 goto retry; |
2373 while (format != end) | 2375 while (format != end) |
2374 { | 2376 { |
2375 if (*format == '%') | 2377 if (*format == '%') |
2376 { | 2378 { |
2377 int minlen; | 2379 int minlen; |
2380 int negative = 0; | |
2378 unsigned char *this_format_start = format; | 2381 unsigned char *this_format_start = format; |
2379 | 2382 |
2380 format++; | 2383 format++; |
2381 | 2384 |
2382 /* Process a numeric arg and skip it. */ | 2385 /* Process a numeric arg and skip it. */ |
2383 minlen = atoi (format); | 2386 minlen = atoi (format); |
2384 if (minlen < 0) | 2387 if (minlen < 0) |
2385 minlen = - minlen; | 2388 minlen = - minlen, negative = 1; |
2386 | 2389 |
2387 while ((*format >= '0' && *format <= '9') | 2390 while ((*format >= '0' && *format <= '9') |
2388 || *format == '-' || *format == ' ' || *format == '.') | 2391 || *format == '-' || *format == ' ' || *format == '.') |
2389 format++; | 2392 format++; |
2390 | 2393 |
2397 | 2400 |
2398 ++n; | 2401 ++n; |
2399 | 2402 |
2400 if (STRINGP (args[n])) | 2403 if (STRINGP (args[n])) |
2401 { | 2404 { |
2402 int padding, nbytes, width; | 2405 int padding, nbytes; |
2406 int width = strwidth (XSTRING (args[n])->data, | |
2407 XSTRING (args[n])->size_byte); | |
2408 | |
2409 /* If spec requires it, pad on right with spaces. */ | |
2410 padding = minlen - width; | |
2411 if (! negative) | |
2412 while (padding-- > 0) | |
2413 { | |
2414 *p++ = ' '; | |
2415 nchars++; | |
2416 } | |
2403 | 2417 |
2404 nbytes = copy_text (XSTRING (args[n])->data, p, | 2418 nbytes = copy_text (XSTRING (args[n])->data, p, |
2405 XSTRING (args[n])->size_byte, | 2419 XSTRING (args[n])->size_byte, |
2406 STRING_MULTIBYTE (args[n]), multibyte); | 2420 STRING_MULTIBYTE (args[n]), multibyte); |
2407 width = strwidth (p, nbytes); | |
2408 p += nbytes; | 2421 p += nbytes; |
2409 nchars += XSTRING (args[n])->size; | 2422 nchars += XSTRING (args[n])->size; |
2410 | 2423 |
2411 /* If spec requires it, pad on right with spaces. */ | 2424 if (negative) |
2412 padding = minlen - width; | 2425 while (padding-- > 0) |
2413 while (padding-- > 0) | 2426 { |
2414 { | 2427 *p++ = ' '; |
2415 *p++ = ' '; | 2428 nchars++; |
2416 nchars++; | 2429 } |
2417 } | |
2418 } | 2430 } |
2419 else if (INTEGERP (args[n]) || FLOATP (args[n])) | 2431 else if (INTEGERP (args[n]) || FLOATP (args[n])) |
2420 { | 2432 { |
2421 int this_nchars; | 2433 int this_nchars; |
2422 | 2434 |