ncal.c (204849) | ncal.c (204908) |
---|---|
1/*- 2 * Copyright (c) 1997 Wolfgang Helbig 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#ifndef lint 28static const char rcsid[] = | 1/*- 2 * Copyright (c) 1997 Wolfgang Helbig 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#ifndef lint 28static const char rcsid[] = |
29 "$FreeBSD: head/usr.bin/ncal/ncal.c 204849 2010-03-07 21:54:28Z edwin $"; | 29 "$FreeBSD: head/usr.bin/ncal/ncal.c 204908 2010-03-09 06:43:35Z edwin $"; |
30#endif /* not lint */ 31 32#include <calendar.h> 33#include <ctype.h> 34#include <err.h> 35#include <langinfo.h> 36#include <locale.h> 37#include <stdio.h> --- 17 unchanged lines hidden (view full) --- 55#define MAX_WIDTH 64 56 57typedef struct date date; 58 59struct monthlines { 60 wchar_t name[MAX_WIDTH + 1]; 61 char lines[7][MAX_WIDTH + 1]; 62 char weeks[MAX_WIDTH + 1]; | 30#endif /* not lint */ 31 32#include <calendar.h> 33#include <ctype.h> 34#include <err.h> 35#include <langinfo.h> 36#include <locale.h> 37#include <stdio.h> --- 17 unchanged lines hidden (view full) --- 55#define MAX_WIDTH 64 56 57typedef struct date date; 58 59struct monthlines { 60 wchar_t name[MAX_WIDTH + 1]; 61 char lines[7][MAX_WIDTH + 1]; 62 char weeks[MAX_WIDTH + 1]; |
63 unsigned int linelen[7]; | 63 unsigned int extralen[7]; |
64}; 65 66struct weekdays { 67 wchar_t names[7][4]; 68}; 69 70/* The switches from Julian to Gregorian in some countries */ 71static struct djswitch { --- 213 unchanged lines hidden (view full) --- 285 usage(); 286 flag_easter = 1; 287 break; 288 case 'j': 289 flag_julian_day = 1; 290 break; 291 case 'm': 292 flag_month = optarg; | 64}; 65 66struct weekdays { 67 wchar_t names[7][4]; 68}; 69 70/* The switches from Julian to Gregorian in some countries */ 71static struct djswitch { --- 213 unchanged lines hidden (view full) --- 285 usage(); 286 flag_easter = 1; 287 break; 288 case 'j': 289 flag_julian_day = 1; 290 break; 291 case 'm': 292 flag_month = optarg; |
293 before = 0; 294 after = 0; |
|
293 break; 294 case 'o': 295 if (flag_backward) 296 usage(); 297 flag_orthodox = 1; 298 flag_easter = 1; 299 break; 300 case 'p': --- 30 unchanged lines hidden (view full) --- 331 argc -= optind; 332 argv += optind; 333 334 switch (argc) { 335 case 2: 336 if (flag_easter) 337 usage(); 338 flag_month = *argv++; | 295 break; 296 case 'o': 297 if (flag_backward) 298 usage(); 299 flag_orthodox = 1; 300 flag_easter = 1; 301 break; 302 case 'p': --- 30 unchanged lines hidden (view full) --- 333 argc -= optind; 334 argv += optind; 335 336 switch (argc) { 337 case 2: 338 if (flag_easter) 339 usage(); 340 flag_month = *argv++; |
341 before = 0; 342 after = 0; 343 m = strtol(flag_month, NULL, 10); |
|
339 /* FALLTHROUGH */ 340 case 1: 341 y = atoi(*argv++); 342 if (y < 1 || y > 9999) 343 errx(EX_USAGE, "year %d not in range 1..9999", y); | 344 /* FALLTHROUGH */ 345 case 1: 346 y = atoi(*argv++); 347 if (y < 1 || y > 9999) 348 errx(EX_USAGE, "year %d not in range 1..9999", y); |
344 before = 0; 345 after = 11; 346 m = 1; | 349 if (before == -1 && after == -1) { 350 before = 0; 351 after = 11; 352 m = 1; 353 } |
347 break; 348 case 0: 349 { 350 time_t t; 351 struct tm *tm; 352 353 t = time(NULL); 354 tm = localtime(&t); --- 110 unchanged lines hidden (view full) --- 465 memset(&tm, 0, sizeof(tm)); 466 tm.tm_year = dt.y - 1900; 467 tm.tm_mon = dt.m - 1; 468 tm.tm_mday = dt.d; 469 strftime(buf, sizeof(buf), d_first ? "%e %B %Y" : "%B %e %Y", &tm); 470 printf("%s\n", buf); 471} 472 | 354 break; 355 case 0: 356 { 357 time_t t; 358 struct tm *tm; 359 360 t = time(NULL); 361 tm = localtime(&t); --- 110 unchanged lines hidden (view full) --- 472 memset(&tm, 0, sizeof(tm)); 473 tm.tm_year = dt.y - 1900; 474 tm.tm_mon = dt.m - 1; 475 tm.tm_mday = dt.d; 476 strftime(buf, sizeof(buf), d_first ? "%e %B %Y" : "%B %e %Y", &tm); 477 printf("%s\n", buf); 478} 479 |
473#define MW(mw, ms, ml) \ 474 strlen(ms) > (ml) ? (mw) + 9 : (mw) | 480#define MW(mw, me) ((mw) + me) |
475#define DECREASEMONTH(m, y) \ 476 if (--m == 0) { \ 477 m = 12; \ 478 y--; \ 479 } 480#define INCREASEMONTH(m, y) \ 481 if (++(m) == 13) { \ 482 (m) = 1; \ --- 76 unchanged lines hidden (view full) --- 559 wdss, wds.names[1], wdss, wds.names[2], 560 wdss, wds.names[3], wdss, wds.names[4], 561 wdss, wds.names[5]); 562 } 563 printf("\n"); 564 565 for (i = 0; i != 6; i++) { 566 for (j = 0; j < count; j++) | 481#define DECREASEMONTH(m, y) \ 482 if (--m == 0) { \ 483 m = 12; \ 484 y--; \ 485 } 486#define INCREASEMONTH(m, y) \ 487 if (++(m) == 13) { \ 488 (m) = 1; \ --- 76 unchanged lines hidden (view full) --- 565 wdss, wds.names[1], wdss, wds.names[2], 566 wdss, wds.names[3], wdss, wds.names[4], 567 wdss, wds.names[5]); 568 } 569 printf("\n"); 570 571 for (i = 0; i != 6; i++) { 572 for (j = 0; j < count; j++) |
567 printf("%-*s ", mw, year[j].lines[i]+1); | 573 printf("%-*s ", 574 MW(mw, year[j].extralen[i]), 575 year[j].lines[i]+1); |
568 printf("\n"); 569 } 570 571 m += mpl; 572 } 573} 574 575void --- 60 unchanged lines hidden (view full) --- 636 637 for (i = 0; i != 7; i++) { 638 /* Week day */ 639 wprintf(L"%.2ls", wds.names[i]); 640 641 /* Full months */ 642 for (j = 0; j < count; j++) 643 printf("%-*s", | 576 printf("\n"); 577 } 578 579 m += mpl; 580 } 581} 582 583void --- 60 unchanged lines hidden (view full) --- 644 645 for (i = 0; i != 7; i++) { 646 /* Week day */ 647 wprintf(L"%.2ls", wds.names[i]); 648 649 /* Full months */ 650 for (j = 0; j < count; j++) 651 printf("%-*s", |
644 MW(mw, year[j].lines[i], 645 year[j].linelen[i]), year[j].lines[i]); | 652 MW(mw, year[j].extralen[i]), 653 year[j].lines[i]); |
646 printf("\n"); 647 } 648 649 if (flag_weeks) { 650 printf(" "); 651 for (i = 0; i < count; i++) 652 printf("%-*s", mw, year[i].weeks); 653 printf("\n"); --- 74 unchanged lines hidden (view full) --- 728 ds + dt.d * dw, dw, &l); 729 else 730 memcpy(mlines->lines[i] + k + l, 731 ds + dt.d * dw, dw); 732 } else 733 memcpy(mlines->lines[i] + k + l, " ", dw); 734 } 735 mlines->lines[i][k + l] = '\0'; | 654 printf("\n"); 655 } 656 657 if (flag_weeks) { 658 printf(" "); 659 for (i = 0; i < count; i++) 660 printf("%-*s", mw, year[i].weeks); 661 printf("\n"); --- 74 unchanged lines hidden (view full) --- 736 ds + dt.d * dw, dw, &l); 737 else 738 memcpy(mlines->lines[i] + k + l, 739 ds + dt.d * dw, dw); 740 } else 741 memcpy(mlines->lines[i] + k + l, " ", dw); 742 } 743 mlines->lines[i][k + l] = '\0'; |
736 mlines->linelen[i] = k; | 744 mlines->extralen[i] = l; |
737 } 738 739 /* fill the weeknumbers */ 740 if (flag_weeks) { 741 for (j = firstm, k = 0; j < last; k += dw, j += 7) 742 if (j <= nswitch) 743 memset(mlines->weeks + k, ' ', dw); 744 else --- 90 unchanged lines hidden (view full) --- 835 ds + dt.d * dw, dw); 836 } else 837 memcpy(mlines->lines[i] + k + l, " ", dw); 838 } 839 if (k == 0) 840 mlines->lines[i][1] = '\0'; 841 else 842 mlines->lines[i][k + l] = '\0'; | 745 } 746 747 /* fill the weeknumbers */ 748 if (flag_weeks) { 749 for (j = firstm, k = 0; j < last; k += dw, j += 7) 750 if (j <= nswitch) 751 memset(mlines->weeks + k, ' ', dw); 752 else --- 90 unchanged lines hidden (view full) --- 843 ds + dt.d * dw, dw); 844 } else 845 memcpy(mlines->lines[i] + k + l, " ", dw); 846 } 847 if (k == 0) 848 mlines->lines[i][1] = '\0'; 849 else 850 mlines->lines[i][k + l] = '\0'; |
851 mlines->extralen[i] = l; |
|
843 } 844} 845 846/* Put the local names of weekdays into the wds */ 847void 848mkweekdays(struct weekdays *wds) 849{ 850 int i, len, width = 0; --- 222 unchanged lines hidden --- | 852 } 853} 854 855/* Put the local names of weekdays into the wds */ 856void 857mkweekdays(struct weekdays *wds) 858{ 859 int i, len, width = 0; --- 222 unchanged lines hidden --- |