diff --git a/edit/edit.c b/edit/edit.c
index ff2b2e7..9beb2c8 100644
a
|
b
|
|
44 | 44 | #include "../src/cmd.h" /* view_other_cmd() */ |
45 | 45 | #include "../src/user.h" /* user_menu_cmd() */ |
46 | 46 | #include "../src/wtools.h" /* query_dialog() */ |
| 47 | #include "../src/timefmt.h" /* time formatting */ |
47 | 48 | |
48 | 49 | |
49 | 50 | /* |
… |
… |
edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) |
2519 | 2520 | break; |
2520 | 2521 | |
2521 | 2522 | case CK_Date:{ |
2522 | | time_t t; |
2523 | | #ifdef HAVE_STRFTIME |
2524 | 2523 | char s[1024]; |
2525 | 2524 | /* fool gcc to prevent a Y2K warning */ |
2526 | 2525 | char time_format[] = "_c"; |
2527 | 2526 | time_format[0] = '%'; |
2528 | | #endif |
2529 | | time (&t); |
2530 | | #ifdef HAVE_STRFTIME |
2531 | | strftime (s, sizeof (s), time_format, localtime (&t)); |
| 2527 | |
| 2528 | FMT_LOCALTIME_CURRENT(s, sizeof(s), time_format); |
2532 | 2529 | edit_print_string (edit, s); |
2533 | | #else |
2534 | | edit_print_string (edit, ctime (&t)); |
2535 | | #endif |
2536 | 2530 | edit->force |= REDRAW_PAGE; |
2537 | 2531 | break; |
2538 | 2532 | } |
diff --git a/src/Makefile.am b/src/Makefile.am
index ccf0f8b..a4713a6 100644
a
|
b
|
SRCS = achown.c achown.h background.c background.h boxes.c boxes.h \ |
60 | 60 | popt.c poptconfig.c popt.h popthelp.c poptint.h poptparse.c \ |
61 | 61 | profile.c profile.h regex.c rxvt.c screen.c setup.c setup.h \ |
62 | 62 | slint.c subshell.c subshell.h textconf.c textconf.h \ |
63 | | tree.c tree.h treestore.c treestore.h tty.c tty.h user.c user.h \ |
64 | | util.c util.h utilunix.c view.c view.h vfsdummy.h widget.c \ |
| 63 | tree.c tree.h treestore.c treestore.h timefmt.h tty.c tty.h user.c \ |
| 64 | user.h util.c util.h utilunix.c view.c view.h vfsdummy.h widget.c \ |
65 | 65 | widget.h win.c win.h wtools.c wtools.h unixcompat.h \ |
66 | 66 | x11conn.h x11conn.c ecs.h ecs.c |
67 | 67 | |
diff --git a/src/timefmt.h b/src/timefmt.h
new file mode 100644
index 0000000..2b8d52f
-
|
+
|
|
| 1 | #ifndef __UTIL_TIMEFMT_H |
| 2 | #define __UTIL_TIMEFMT_H |
| 3 | |
| 4 | #include <sys/types.h> |
| 5 | |
| 6 | #define INVALID_TIME_TEXT "(invalid)" |
| 7 | |
| 8 | #ifdef HAVE_STRFTIME |
| 9 | |
| 10 | /* safe localtime formatting - strftime()-using version */ |
| 11 | #define FMT_LOCALTIME(buffer, bufsize, fmt, when) \ |
| 12 | { \ |
| 13 | struct tm *whentm; \ |
| 14 | whentm = localtime(&when); \ |
| 15 | if (whentm == NULL) \ |
| 16 | { \ |
| 17 | strncpy(buffer, INVALID_TIME_TEXT, bufsize); \ |
| 18 | buffer[bufsize-1] = 0; \ |
| 19 | } \ |
| 20 | else \ |
| 21 | { \ |
| 22 | strftime(buffer, bufsize, fmt, whentm); \ |
| 23 | } \ |
| 24 | } \ |
| 25 | |
| 26 | #else |
| 27 | |
| 28 | /* fallback when strftime/localtime not available */ |
| 29 | #define FMT_LOCALTIME(buffer,bufsize,fmt,when) \ |
| 30 | { \ |
| 31 | ctime_r(when,buffer); \ |
| 32 | } \ |
| 33 | |
| 34 | #endif |
| 35 | |
| 36 | #define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \ |
| 37 | { \ |
| 38 | time_t __current_time; \ |
| 39 | time(&__current_time); \ |
| 40 | FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \ |
| 41 | } |
| 42 | |
| 43 | #endif /* !__UTIL_H */ |
diff --git a/src/util.c b/src/util.c
index da6d1b2..2e4eabb 100644
a
|
b
|
|
41 | 41 | #include "cmd.h" /* guess_message_value */ |
42 | 42 | #include "mountlist.h" |
43 | 43 | #include "win.h" /* xterm_flag */ |
| 44 | #include "timefmt.h" |
44 | 45 | |
45 | 46 | #ifdef HAVE_CHARSET |
46 | 47 | #include "charsets.h" |
… |
… |
short-month-name sizes for different locales */ |
724 | 725 | size_t |
725 | 726 | i18n_checktimelength (void) |
726 | 727 | { |
727 | | size_t length, a, b; |
728 | | char buf [MAX_I18NTIMELENGTH + 1]; |
729 | 728 | time_t testtime = time (NULL); |
730 | | |
731 | | a = strftime (buf, sizeof(buf)-1, _("%b %e %H:%M"), localtime(&testtime)); |
732 | | b = strftime (buf, sizeof(buf)-1, _("%b %e %Y"), localtime(&testtime)); |
733 | | |
734 | | length = max (a, b); |
735 | | length = max (strlen (_("(invalid)")), length); |
736 | | |
| 729 | struct tm* lt = localtime(&testtime); |
| 730 | size_t length; |
| 731 | |
| 732 | if (lt == NULL) { |
| 733 | // huh, localtime() doesnt seem to work ... falling back to "(invalid)" |
| 734 | length = strlen(INVALID_TIME_TEXT); |
| 735 | } else { |
| 736 | char buf [MAX_I18NTIMELENGTH + 1]; |
| 737 | size_t a, b; |
| 738 | a = strftime (buf, sizeof(buf)-1, _("%b %e %H:%M"), lt); |
| 739 | b = strftime (buf, sizeof(buf)-1, _("%b %e %Y"), lt); |
| 740 | length = max (a, b); |
| 741 | } |
| 742 | |
737 | 743 | /* Don't handle big differences. Use standard value (email bug, please) */ |
738 | 744 | if ( length > MAX_I18NTIMELENGTH || length < MIN_I18NTIMELENGTH ) |
739 | | length = STD_I18NTIMELENGTH; |
| 745 | length = STD_I18NTIMELENGTH; |
740 | 746 | |
741 | 747 | return length; |
742 | 748 | } |
… |
… |
file_date (time_t when) |
773 | 779 | else |
774 | 780 | fmt = fmttime; |
775 | 781 | |
776 | | whentm = localtime(&when); |
777 | | if (whentm == NULL) |
778 | | g_snprintf (timebuf, i18n_timelength, "%s", _("(invalid)")); |
779 | | else |
780 | | strftime (timebuf, i18n_timelength, fmt, whentm); |
| 782 | FMT_LOCALTIME(timebuf, i18n_timelength, fmt, when); |
| 783 | |
781 | 784 | return timebuf; |
782 | 785 | } |
783 | 786 | |