Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/cal.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/coreutils/cal.c
r1765 r2725 5 5 * See original copyright at the end of this file 6 6 * 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 9 … … 17 17 * Major size reduction... over 50% (>1.5k) on i386. 18 18 */ 19 20 19 #include "libbb.h" 20 #include "unicode.h" 21 21 22 22 /* We often use "unsigned" intead of "int", it's easier to div on most CPUs */ … … 41 41 }; 42 42 43 static unsigned julian; 43 /* Set to 0 or 1 in main */ 44 #define julian ((unsigned)option_mask32) 44 45 45 46 /* leap year -- account for Gregorian reformation in 1752 */ … … 76 77 #define HEAD_SEP 2 /* spaces between day headings */ 77 78 78 int cal_main(int argc, char **argv); 79 int cal_main(int argc, char **argv) 80 { 81 struct tm *local_time; 79 int cal_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 80 int cal_main(int argc UNUSED_PARAM, char **argv) 81 { 82 82 struct tm zero_tm; 83 83 time_t now; 84 84 unsigned month, year, flags, i; 85 85 char *month_names[12]; 86 char day_headings[28]; /* 28 for julian, 21 for nonjulian */ 86 /* normal heading: */ 87 /* "Su Mo Tu We Th Fr Sa" */ 88 /* -j heading: */ 89 /* " Su Mo Tu We Th Fr Sa" */ 90 char day_headings[ENABLE_UNICODE_SUPPORT ? 28 * 6 : 28]; 91 IF_UNICODE_SUPPORT(char *hp = day_headings;) 87 92 char buf[40]; 88 93 94 init_unicode(); 95 89 96 flags = getopt32(argv, "jy"); 90 julian = flags & 1; 97 /* This sets julian = flags & 1: */ 98 option_mask32 &= 1; 91 99 month = 0; 92 100 argv += optind; 93 argc -= optind; 94 95 if (argc > 2) { 96 bb_show_usage(); 97 } 98 99 if (!argc) { 101 102 if (!argv[0]) { 103 struct tm *ptm; 104 100 105 time(&now); 101 local_time= localtime(&now);102 year = local_time->tm_year + 1900;103 if (!(flags & 2)) { 104 month = local_time->tm_mon + 1;106 ptm = localtime(&now); 107 year = ptm->tm_year + 1900; 108 if (!(flags & 2)) { /* no -y */ 109 month = ptm->tm_mon + 1; 105 110 } 106 111 } else { 107 if (argc == 2) { 108 month = xatou_range(*argv++, 1, 12); 112 if (argv[1]) { 113 if (argv[2]) { 114 bb_show_usage(); 115 } 116 if (!(flags & 2)) { /* no -y */ 117 month = xatou_range(*argv, 1, 12); 118 } 119 argv++; 109 120 } 110 121 year = xatou_range(*argv, 1, 9999); … … 116 127 do { 117 128 zero_tm.tm_mon = i; 129 /* full month name according to locale */ 118 130 strftime(buf, sizeof(buf), "%B", &zero_tm); 119 131 month_names[i] = xstrdup(buf); … … 121 133 if (i < 7) { 122 134 zero_tm.tm_wday = i; 135 /* abbreviated weekday name according to locale */ 123 136 strftime(buf, sizeof(buf), "%a", &zero_tm); 137 #if ENABLE_UNICODE_SUPPORT 138 if (julian) 139 *hp++ = ' '; 140 { 141 char *two_wchars = unicode_conv_to_printable_fixedwidth(NULL, buf, 2); 142 strcpy(hp, two_wchars); 143 free(two_wchars); 144 } 145 hp += strlen(hp); 146 *hp++ = ' '; 147 #else 124 148 strncpy(day_headings + i * (3+julian) + julian, buf, 2); 149 #endif 125 150 } 126 151 } while (++i < 12); 152 IF_UNICODE_SUPPORT(hp[-1] = '\0';) 127 153 128 154 if (month) { … … 146 172 char lineout[80]; 147 173 148 sprintf(lineout, "% d", year);174 sprintf(lineout, "%u", year); 149 175 center(lineout, 150 176 (WEEK_LEN * 3 + HEAD_SEP * 2) … … 168 194 printf("%*s%s", HEAD_SEP, "", day_headings); 169 195 } 170 putchar('\n');196 bb_putchar('\n'); 171 197 for (row = 0; row < (6*7); row += 7) { 172 198 for (which_cal = 0; which_cal < 3-julian; which_cal++) { … … 180 206 } 181 207 182 fflush_stdout_and_exit( 0);208 fflush_stdout_and_exit(EXIT_SUCCESS); 183 209 } 184 210 … … 261 287 while (p != s) { 262 288 --p; 263 if (! (isspace)(*p)) { /* We want the function... not the inline. */289 if (!isspace(*p)) { 264 290 p[1] = '\0'; 265 291 break;
Note:
See TracChangeset
for help on using the changeset viewer.