diff options
| author | Paul Eggert | 1997-07-14 22:36:07 +0000 |
|---|---|---|
| committer | Paul Eggert | 1997-07-14 22:36:07 +0000 |
| commit | 1b65a66c5d71799e883c481642ef0f6f313cfc5a (patch) | |
| tree | 31489af3e8d9c0b13cf11d63ce9384a6570f8b6a /src | |
| parent | 6ca5cfd1e8684b734308dc9c5a0b2046e65cca04 (diff) | |
| download | emacs-1b65a66c5d71799e883c481642ef0f6f313cfc5a.tar.gz emacs-1b65a66c5d71799e883c481642ef0f6f313cfc5a.zip | |
automatically generated from GPLed version
Diffstat (limited to 'src')
| -rw-r--r-- | src/strftime.c | 70 |
1 files changed, 52 insertions, 18 deletions
diff --git a/src/strftime.c b/src/strftime.c index 1850410ec73..f51cd3d5bf9 100644 --- a/src/strftime.c +++ b/src/strftime.c | |||
| @@ -33,7 +33,6 @@ | |||
| 33 | # define HAVE_TZSET 1 | 33 | # define HAVE_TZSET 1 |
| 34 | # define MULTIBYTE_IS_FORMAT_SAFE 1 | 34 | # define MULTIBYTE_IS_FORMAT_SAFE 1 |
| 35 | # define STDC_HEADERS 1 | 35 | # define STDC_HEADERS 1 |
| 36 | # include <ansidecl.h> | ||
| 37 | # include "../locale/localeinfo.h" | 36 | # include "../locale/localeinfo.h" |
| 38 | #endif | 37 | #endif |
| 39 | 38 | ||
| @@ -83,7 +82,9 @@ extern char *tzname[]; | |||
| 83 | # include <stdlib.h> | 82 | # include <stdlib.h> |
| 84 | # include <string.h> | 83 | # include <string.h> |
| 85 | #else | 84 | #else |
| 86 | # define memcpy(d, s, n) bcopy ((s), (d), (n)) | 85 | # ifndef HAVE_MEMCPY |
| 86 | # define memcpy(d, s, n) bcopy ((s), (d), (n)) | ||
| 87 | # endif | ||
| 87 | #endif | 88 | #endif |
| 88 | 89 | ||
| 89 | #ifndef __P | 90 | #ifndef __P |
| @@ -140,7 +141,7 @@ extern int __tz_compute __P ((time_t timer, const struct tm *tm)); | |||
| 140 | # if ! HAVE_LOCALTIME_R | 141 | # if ! HAVE_LOCALTIME_R |
| 141 | # if ! HAVE_TM_GMTOFF | 142 | # if ! HAVE_TM_GMTOFF |
| 142 | /* Approximate gmtime_r as best we can in its absence. */ | 143 | /* Approximate gmtime_r as best we can in its absence. */ |
| 143 | # define gmtime_r my_gmtime_r | 144 | # define gmtime_r my_gmtime_r |
| 144 | static struct tm *gmtime_r __P ((const time_t *, struct tm *)); | 145 | static struct tm *gmtime_r __P ((const time_t *, struct tm *)); |
| 145 | static struct tm * | 146 | static struct tm * |
| 146 | gmtime_r (t, tp) | 147 | gmtime_r (t, tp) |
| @@ -156,7 +157,7 @@ gmtime_r (t, tp) | |||
| 156 | # endif /* ! HAVE_TM_GMTOFF */ | 157 | # endif /* ! HAVE_TM_GMTOFF */ |
| 157 | 158 | ||
| 158 | /* Approximate localtime_r as best we can in its absence. */ | 159 | /* Approximate localtime_r as best we can in its absence. */ |
| 159 | # define localtime_r my_localtime_r | 160 | # define localtime_r my_ftime_localtime_r |
| 160 | static struct tm *localtime_r __P ((const time_t *, struct tm *)); | 161 | static struct tm *localtime_r __P ((const time_t *, struct tm *)); |
| 161 | static struct tm * | 162 | static struct tm * |
| 162 | localtime_r (t, tp) | 163 | localtime_r (t, tp) |
| @@ -173,13 +174,15 @@ localtime_r (t, tp) | |||
| 173 | #endif /* ! defined (_LIBC) */ | 174 | #endif /* ! defined (_LIBC) */ |
| 174 | 175 | ||
| 175 | 176 | ||
| 176 | #if !defined (memset) && !defined (HAVE_MEMSET) && !defined (_LIBC) | 177 | #if !defined memset && !defined HAVE_MEMSET && !defined _LIBC |
| 177 | /* Some systems lack the `memset' function and we don't want to | 178 | /* Some systems lack the `memset' function and we don't want to |
| 178 | introduce additional dependencies. */ | 179 | introduce additional dependencies. */ |
| 179 | /* The SGI compiler reportedly barfs on the trailing null | 180 | /* The SGI compiler reportedly barfs on the trailing null |
| 180 | if we use a string constant as the initializer. 28 June 1997, rms. */ | 181 | if we use a string constant as the initializer. 28 June 1997, rms. */ |
| 181 | static const char spaces[16] = { ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '} /* " "*/ ; | 182 | static const char spaces[16] = /* " " */ |
| 182 | static const char zeroes[16] = { '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'} /*"0000000000000000"*/; | 183 | { ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' }; |
| 184 | static const char zeroes[16] = /* "0000000000000000" */ | ||
| 185 | { '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' }; | ||
| 183 | 186 | ||
| 184 | # define memset_space(P, Len) \ | 187 | # define memset_space(P, Len) \ |
| 185 | do { \ | 188 | do { \ |
| @@ -213,7 +216,7 @@ static const char zeroes[16] = { '0','0','0','0','0','0','0','0','0','0','0','0' | |||
| 213 | # define memset_zero(P, Len) (memset ((P), '0', (Len)), (P) += (Len)) | 216 | # define memset_zero(P, Len) (memset ((P), '0', (Len)), (P) += (Len)) |
| 214 | #endif | 217 | #endif |
| 215 | 218 | ||
| 216 | #define add(n, f) \ | 219 | #define add(n, f) \ |
| 217 | do \ | 220 | do \ |
| 218 | { \ | 221 | { \ |
| 219 | int _n = (n); \ | 222 | int _n = (n); \ |
| @@ -236,7 +239,7 @@ static const char zeroes[16] = { '0','0','0','0','0','0','0','0','0','0','0','0' | |||
| 236 | i += _incr; \ | 239 | i += _incr; \ |
| 237 | } while (0) | 240 | } while (0) |
| 238 | 241 | ||
| 239 | #define cpy(n, s) \ | 242 | #define cpy(n, s) \ |
| 240 | add ((n), \ | 243 | add ((n), \ |
| 241 | if (to_lowcase) \ | 244 | if (to_lowcase) \ |
| 242 | memcpy_lowcase (p, (s), _n); \ | 245 | memcpy_lowcase (p, (s), _n); \ |
| @@ -286,9 +289,11 @@ memcpy_uppcase (dest, src, len) | |||
| 286 | return dest; | 289 | return dest; |
| 287 | } | 290 | } |
| 288 | 291 | ||
| 292 | |||
| 289 | #if ! HAVE_TM_GMTOFF | 293 | #if ! HAVE_TM_GMTOFF |
| 290 | /* Yield the difference between *A and *B, | 294 | /* Yield the difference between *A and *B, |
| 291 | measured in seconds, ignoring leap seconds. */ | 295 | measured in seconds, ignoring leap seconds. */ |
| 296 | # define tm_diff ftime_tm_diff | ||
| 292 | static int tm_diff __P ((const struct tm *, const struct tm *)); | 297 | static int tm_diff __P ((const struct tm *, const struct tm *)); |
| 293 | static int | 298 | static int |
| 294 | tm_diff (a, b) | 299 | tm_diff (a, b) |
| @@ -421,15 +426,13 @@ strftime (s, maxsize, format, tp) | |||
| 421 | const char *f; | 426 | const char *f; |
| 422 | 427 | ||
| 423 | zone = NULL; | 428 | zone = NULL; |
| 424 | #if !defined _LIBC && HAVE_TM_ZONE | 429 | #if HAVE_TM_ZONE |
| 425 | /* XXX We have some problems here. First, the string pointed to by | 430 | /* The POSIX test suite assumes that setting |
| 426 | tm_zone is dynamically allocated while loading the zone data. But | ||
| 427 | when another zone is loaded since the information in TP were | ||
| 428 | computed this would be a stale pointer. | ||
| 429 | The second problem is the POSIX test suite which assumes setting | ||
| 430 | the environment variable TZ to a new value before calling strftime() | 431 | the environment variable TZ to a new value before calling strftime() |
| 431 | will influence the result (the %Z format) even if the information in | 432 | will influence the result (the %Z format) even if the information in |
| 432 | TP is computed with a totally different time zone. --drepper@gnu */ | 433 | TP is computed with a totally different time zone. |
| 434 | This is bogus: though POSIX allows bad behavior like this, | ||
| 435 | POSIX does not require it. Do the right thing instead. */ | ||
| 433 | zone = (const char *) tp->tm_zone; | 436 | zone = (const char *) tp->tm_zone; |
| 434 | #endif | 437 | #endif |
| 435 | #if HAVE_TZNAME | 438 | #if HAVE_TZNAME |
| @@ -468,6 +471,7 @@ strftime (s, maxsize, format, tp) | |||
| 468 | int width = -1; | 471 | int width = -1; |
| 469 | int to_lowcase = 0; | 472 | int to_lowcase = 0; |
| 470 | int to_uppcase = 0; | 473 | int to_uppcase = 0; |
| 474 | int change_case = 0; | ||
| 471 | 475 | ||
| 472 | #if DO_MULTIBYTE | 476 | #if DO_MULTIBYTE |
| 473 | 477 | ||
| @@ -559,6 +563,9 @@ strftime (s, maxsize, format, tp) | |||
| 559 | case '^': | 563 | case '^': |
| 560 | to_uppcase = 1; | 564 | to_uppcase = 1; |
| 561 | continue; | 565 | continue; |
| 566 | case '#': | ||
| 567 | change_case = 1; | ||
| 568 | continue; | ||
| 562 | 569 | ||
| 563 | default: | 570 | default: |
| 564 | break; | 571 | break; |
| @@ -596,9 +603,11 @@ strftime (s, maxsize, format, tp) | |||
| 596 | switch (*f) | 603 | switch (*f) |
| 597 | { | 604 | { |
| 598 | #define DO_NUMBER(d, v) \ | 605 | #define DO_NUMBER(d, v) \ |
| 599 | digits = d; number_value = v; goto do_number | 606 | digits = width == -1 ? d : width; \ |
| 607 | number_value = v; goto do_number | ||
| 600 | #define DO_NUMBER_SPACEPAD(d, v) \ | 608 | #define DO_NUMBER_SPACEPAD(d, v) \ |
| 601 | digits = d; number_value = v; goto do_number_spacepad | 609 | digits = width == -1 ? d : width; \ |
| 610 | number_value = v; goto do_number_spacepad | ||
| 602 | 611 | ||
| 603 | case '%': | 612 | case '%': |
| 604 | if (modifier != 0) | 613 | if (modifier != 0) |
| @@ -609,12 +618,22 @@ strftime (s, maxsize, format, tp) | |||
| 609 | case 'a': | 618 | case 'a': |
| 610 | if (modifier != 0) | 619 | if (modifier != 0) |
| 611 | goto bad_format; | 620 | goto bad_format; |
| 621 | if (change_case) | ||
| 622 | { | ||
| 623 | to_uppcase = 1; | ||
| 624 | to_lowcase = 0; | ||
| 625 | } | ||
| 612 | cpy (aw_len, a_wkday); | 626 | cpy (aw_len, a_wkday); |
| 613 | break; | 627 | break; |
| 614 | 628 | ||
| 615 | case 'A': | 629 | case 'A': |
| 616 | if (modifier != 0) | 630 | if (modifier != 0) |
| 617 | goto bad_format; | 631 | goto bad_format; |
| 632 | if (change_case) | ||
| 633 | { | ||
| 634 | to_uppcase = 1; | ||
| 635 | to_lowcase = 0; | ||
| 636 | } | ||
| 618 | cpy (wkday_len, f_wkday); | 637 | cpy (wkday_len, f_wkday); |
| 619 | break; | 638 | break; |
| 620 | 639 | ||
| @@ -628,6 +647,11 @@ strftime (s, maxsize, format, tp) | |||
| 628 | case 'B': | 647 | case 'B': |
| 629 | if (modifier != 0) | 648 | if (modifier != 0) |
| 630 | goto bad_format; | 649 | goto bad_format; |
| 650 | if (change_case) | ||
| 651 | { | ||
| 652 | to_uppcase = 1; | ||
| 653 | to_lowcase = 0; | ||
| 654 | } | ||
| 631 | cpy (month_len, f_month); | 655 | cpy (month_len, f_month); |
| 632 | break; | 656 | break; |
| 633 | 657 | ||
| @@ -828,6 +852,11 @@ strftime (s, maxsize, format, tp) | |||
| 828 | /* FALLTHROUGH */ | 852 | /* FALLTHROUGH */ |
| 829 | 853 | ||
| 830 | case 'p': | 854 | case 'p': |
| 855 | if (change_case) | ||
| 856 | { | ||
| 857 | to_uppcase = 0; | ||
| 858 | to_lowcase = 1; | ||
| 859 | } | ||
| 831 | cpy (ap_len, ampm); | 860 | cpy (ap_len, ampm); |
| 832 | break; | 861 | break; |
| 833 | 862 | ||
| @@ -1000,6 +1029,11 @@ strftime (s, maxsize, format, tp) | |||
| 1000 | DO_NUMBER (2, (tp->tm_year % 100 + 100) % 100); | 1029 | DO_NUMBER (2, (tp->tm_year % 100 + 100) % 100); |
| 1001 | 1030 | ||
| 1002 | case 'Z': | 1031 | case 'Z': |
| 1032 | if (change_case) | ||
| 1033 | { | ||
| 1034 | to_uppcase = 0; | ||
| 1035 | to_lowcase = 1; | ||
| 1036 | } | ||
| 1003 | cpy (zonelen, zone); | 1037 | cpy (zonelen, zone); |
| 1004 | break; | 1038 | break; |
| 1005 | 1039 | ||