Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/cal.c


Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/coreutils/cal.c

    r1765 r2725  
    55 * See original copyright at the end of this file
    66 *
    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.
    88 */
    99
     
    1717 * Major size reduction... over 50% (>1.5k) on i386.
    1818 */
    19 
    2019#include "libbb.h"
     20#include "unicode.h"
    2121
    2222/* We often use "unsigned" intead of "int", it's easier to div on most CPUs */
     
    4141};
    4242
    43 static unsigned julian;
     43/* Set to 0 or 1 in main */
     44#define julian ((unsigned)option_mask32)
    4445
    4546/* leap year -- account for Gregorian reformation in 1752 */
     
    7677#define HEAD_SEP    2       /* spaces between day headings */
    7778
    78 int cal_main(int argc, char **argv);
    79 int cal_main(int argc, char **argv)
    80 {
    81     struct tm *local_time;
     79int cal_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     80int cal_main(int argc UNUSED_PARAM, char **argv)
     81{
    8282    struct tm zero_tm;
    8383    time_t now;
    8484    unsigned month, year, flags, i;
    8585    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;)
    8792    char buf[40];
    8893
     94    init_unicode();
     95
    8996    flags = getopt32(argv, "jy");
    90     julian = flags & 1;
     97    /* This sets julian = flags & 1: */
     98    option_mask32 &= 1;
    9199    month = 0;
    92100    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
    100105        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;
    105110        }
    106111    } 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++;
    109120        }
    110121        year = xatou_range(*argv, 1, 9999);
     
    116127    do {
    117128        zero_tm.tm_mon = i;
     129        /* full month name according to locale */
    118130        strftime(buf, sizeof(buf), "%B", &zero_tm);
    119131        month_names[i] = xstrdup(buf);
     
    121133        if (i < 7) {
    122134            zero_tm.tm_wday = i;
     135            /* abbreviated weekday name according to locale */
    123136            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
    124148            strncpy(day_headings + i * (3+julian) + julian, buf, 2);
     149#endif
    125150        }
    126151    } while (++i < 12);
     152    IF_UNICODE_SUPPORT(hp[-1] = '\0';)
    127153
    128154    if (month) {
     
    146172        char lineout[80];
    147173
    148         sprintf(lineout, "%d", year);
     174        sprintf(lineout, "%u", year);
    149175        center(lineout,
    150176               (WEEK_LEN * 3 + HEAD_SEP * 2)
     
    168194                printf("%*s%s", HEAD_SEP, "", day_headings);
    169195            }
    170             putchar('\n');
     196            bb_putchar('\n');
    171197            for (row = 0; row < (6*7); row += 7) {
    172198                for (which_cal = 0; which_cal < 3-julian; which_cal++) {
     
    180206    }
    181207
    182     fflush_stdout_and_exit(0);
     208    fflush_stdout_and_exit(EXIT_SUCCESS);
    183209}
    184210
     
    261287    while (p != s) {
    262288        --p;
    263         if (!(isspace)(*p)) {   /* We want the function... not the inline. */
     289        if (!isspace(*p)) {
    264290            p[1] = '\0';
    265291            break;
Note: See TracChangeset for help on using the changeset viewer.