93
94
static const char *
94
my_tgetstr(char *s, char *ss) {
95
my_tgetstr(char *s __attribute__ ((__unused__)), char *ss) {
95
96
const char* ret = tigetstr(ss);
96
97
if (!ret || ret==(char*)-1)
102
103
#elif defined(HAVE_LIBTERMCAP)
120
121
static const char *
121
my_tgetstr(char *s, char *ss) {
122
my_tgetstr(char *s, char *ss __attribute__ ((__unused__))) {
122
123
const char* ret = tgetstr(s, &strbuf);
129
130
#else /* ! (HAVE_LIBTERMCAP || HAVE_LIBNCURSES || HAVE_LIBNCURSESW) */
252
253
void monthly(int, int, int);
253
254
void monthly3(int, int, int);
254
255
void trim_trailing_spaces(char *);
256
static void __attribute__ ((__noreturn__)) usage(FILE * out);
256
257
void headers_init(void);
262
263
int ch, day, month, year, yflag;
263
264
int num_months = NUM_MONTHS;
266
static const struct option longopts[] = {
267
{"one", no_argument, NULL, '1'},
268
{"three", no_argument, NULL, '3'},
269
{"sunday", no_argument, NULL, 's'},
270
{"monday", no_argument, NULL, 'm'},
271
{"julian", no_argument, NULL, 'j'},
272
{"year", no_argument, NULL, 'y'},
273
{"version", no_argument, NULL, 'V'},
274
{"help", no_argument, NULL, 'h'},
265
278
setlocale(LC_ALL, "");
266
279
bindtextdomain(PACKAGE, LOCALEDIR);
267
280
textdomain(PACKAGE);
290
303
* This is needed to support first_weekday=2 and first_workday=1 for
291
304
* the rare case where working days span across 2 weeks.
292
305
* This shell script shows the combinations and calculations involved:
294
for LANG in en_US ru_RU fr_FR csb_PL POSIX; do
295
printf "%s:\t%s + %s -1 = " $LANG $(locale week-1stday first_weekday)
296
date -d"$(locale week-1stday) +$(($(locale first_weekday)-1))day" +%w
299
en_US: 19971130 + 1 -1 = 0 #0 = sunday
300
ru_RU: 19971130 + 2 -1 = 1
301
fr_FR: 19971201 + 1 -1 = 1
302
csb_PL: 19971201 + 2 -1 = 2
303
POSIX: 19971201 + 7 -1 = 0
307
* for LANG in en_US ru_RU fr_FR csb_PL POSIX; do
308
* printf "%s:\t%s + %s -1 = " $LANG $(locale week-1stday first_weekday)
309
* date -d"$(locale week-1stday) +$(($(locale first_weekday)-1))day" +%w
312
* en_US: 19971130 + 1 -1 = 0 #0 = sunday
313
* ru_RU: 19971130 + 2 -1 = 1
314
* fr_FR: 19971201 + 1 -1 = 1
315
* csb_PL: 19971201 + 2 -1 = 2
316
* POSIX: 19971201 + 7 -1 = 0
317
while ((ch = getopt(argc, argv, "13mjsyV")) != -1)
330
while ((ch = getopt_long(argc, argv, "13mjsyVh", longopts, NULL)) != -1)
320
333
num_months = 1; /* default */
351
366
day = month = year = 0;
354
if ((day = atoi(*argv++)) < 1 || day > 31)
355
errx(1, _("illegal day value: use 1-%d"), 31);
369
day = strtol_or_err(*argv++, _("illegal day value"));
370
if (day < 1 || 31 < day)
371
errx(EXIT_FAILURE, _("illegal day value: use 1-%d"), 31);
356
372
/* FALLTHROUGH */
358
if ((month = atoi(*argv++)) < 1 || month > 12)
359
errx(1, _("illegal month value: use 1-12"));
374
month = strtol_or_err(*argv++, _("illegal month value: use 1-12"));
375
if (month < 1 || 12 < month)
376
errx(EXIT_FAILURE, _("illegal month value: use 1-12"));
360
377
/* FALLTHROUGH */
362
if ((year = atoi(*argv)) < 1 || year > 9999)
363
errx(1, _("illegal year value: use 1-9999"));
379
year = strtol_or_err(*argv++, _("illegal year value: use 1-9999"));
380
if (year < 1 || 9999 < year)
381
errx(EXIT_FAILURE, _("illegal year value: use 1-9999"));
365
383
int dm = days_in_month[leap_year(year)][month];
367
errx(1, _("illegal day value: use 1-%d"), dm);
385
errx(EXIT_FAILURE, _("illegal day value: use 1-%d"), dm);
368
386
day = day_in_year(day, month, year);
369
387
} else if ((local_time->tm_year + 1900) == year) {
370
388
day = local_time->tm_yday + 1;
400
418
void headers_init(void)
403
char *cur_dh = day_headings, *cur_j_dh = j_day_headings;
405
strcpy(day_headings,"");
406
strcpy(j_day_headings,"");
408
for(i = 0 ; i < 7 ; i++ ) {
410
wd = (i + weekstart) % 7;
413
strcat(cur_dh++, " ");
414
space_left = sizeof(day_headings) - (cur_dh - day_headings);
417
cur_dh += center_str(nl_langinfo(ABDAY_1+wd), cur_dh, space_left, 2);
420
strcat(cur_j_dh++, " ");
421
space_left = sizeof(j_day_headings) - (cur_j_dh - j_day_headings);
424
cur_j_dh += center_str(nl_langinfo(ABDAY_1+wd), cur_j_dh, space_left, 3);
427
for (i = 0; i < 12; i++)
428
full_month[i] = nl_langinfo(MON_1+i);
421
char *cur_dh = day_headings, *cur_j_dh = j_day_headings;
423
strcpy(day_headings, "");
424
strcpy(j_day_headings, "");
426
for (i = 0; i < 7; i++) {
428
wd = (i + weekstart) % 7;
431
strcat(cur_dh++, " ");
433
sizeof(day_headings) - (cur_dh - day_headings);
437
center_str(nl_langinfo(ABDAY_1 + wd), cur_dh,
441
strcat(cur_j_dh++, " ");
443
sizeof(j_day_headings) - (cur_j_dh - j_day_headings);
447
center_str(nl_langinfo(ABDAY_1 + wd), cur_j_dh,
451
for (i = 0; i < 12; i++)
452
full_month[i] = nl_langinfo(MON_1 + i);
506
530
do_monthly(day, month, year, &out_curm);
507
531
do_monthly(day, next_month, next_year, &out_next);
509
width = (julian ? J_WEEK_LEN : WEEK_LEN) -1;
533
width = (julian ? J_WEEK_LEN : WEEK_LEN) -1;
510
534
for (i = 0; i < 2; i++)
511
535
printf("%s %s %s\n", out_prev.s[i], out_curm.s[i], out_next.s[i]);
512
536
for (i = 2; i < FMT_ST_LINES; i++) {
514
538
w1 = w2 = w3 = width;
516
540
#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) || defined(HAVE_LIBTERMCAP)
517
/* adjust width to allow for non printable characters */
518
w1 += (out_prev.s[i] == Hrow ? Slen : 0);
519
w2 += (out_curm.s[i] == Hrow ? Slen : 0);
520
w3 += (out_next.s[i] == Hrow ? Slen : 0);
541
/* adjust width to allow for non printable characters */
542
w1 += (out_prev.s[i] == Hrow ? Slen : 0);
543
w2 += (out_curm.s[i] == Hrow ? Slen : 0);
544
w3 += (out_next.s[i] == Hrow ? Slen : 0);
522
546
snprintf(lineout, sizeof(lineout), "%-*s %-*s %-*s\n",
523
547
w1, out_prev.s[i],
757
781
printf("%*s", separate, "");
784
static void __attribute__ ((__noreturn__)) usage(FILE * out)
764
fprintf(stderr, _("usage: %s [-13smjyV] [[[day] month] year]\n"),
786
fputs(_("\nUsage:\n"), out);
788
_(" %s [options] [[[day] month] year]\n"),
765
789
program_invocation_short_name);
791
fputs(_("\nOptions:\n"), out);
792
fputs(_(" -1, --one show only current month (default)\n"
793
" -3, --three show previous, current and next month\n"
794
" -s, --sunday Sunday as first day of week\n"
795
" -m, --monday Monday as first day of week\n"
796
" -j, --julian output Julian dates\n"
797
" -y, --year show whole current year\n"
798
" -V, --version display version information and exit\n"
799
" -h, --help display this help text and exit\n\n"), out);
801
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);