I just want to point out that the one you wrote broken, and the fixed one won't work for anonix (or the fix will do nothing).
according to them it's not broken:
- No internationalization. A large amount of GNU bloat is caused by this, and
with English continuing to dominate, the ANONIX initial planning group decided
against explicitly adding code for this, instead opting to let those few who
need it translate themselves.
I don't want to fix it, I have my own working from gnu.
your gnu one can't do
cal 1 340282366920938463463374607431768211456, while this one can (and supports localization):
/* Copyright (c) 2008 Anonymous
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that you grant this
* same permission to anyone you distribute it to without any additional
* restrictions.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <gmp.h>
#include <langinfo.h>
#include <libintl.h>
int main(int argc, char **argv){
mpz_t year, tmp1, tmp2, tmp3, tmp4;
unsigned long day_of_week;
uintmax_t month = 0, month_min = 1, month_max = 12;
int_fast8_t month_days = 0;
const int_fast8_t months_days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
30, 31 };
time_t t = time(NULL);
char weekday[13] = {0}, weekdays[65] = {0}, month_name[LINE_MAX] = {0},
cal_head[LINE_MAX] = {0};
struct tm *time_struct = localtime(&t);
textdomain("cal");
setlocale(LC_ALL, "");
bind_textdomain_codeset("cal", nl_langinfo(CODESET));
mpz_init(year);
switch(argc){
case 1:
mpz_set_ui(year, time_struct->tm_year + 1900);
month_min = month_max = time_struct->tm_mon + 1;
break;
case 2:
mpz_set_str(year, argv[1], 10);
break;
default:
month_min = month_max = strtoumax(argv[1], NULL, 10);
mpz_set_str(year, argv[2], 10);
}
if(mpz_sgn(year) < 1 || !month_min || month_min > 12){
fputs(gettext(
"learn to use cal, you idiot: http://opengroup.org/susv3xcu/cal.html\n"),
stderr);
abort();
}
for(int i = 0; i < 7; ++i){
time_struct->tm_wday = i;
strftime(weekday, 13, "%a", time_struct);
strncat(weekdays, weekday, 12);
strcat(weekdays, " ");
}
for(int month = month_min; month <= month_max; ++month){
time_struct->tm_mon = month - 1;
strftime(month_name, LINE_MAX, "%B", time_struct);
for(int i = (27 - snprintf(cal_head, LINE_MAX, "%s %s", month_name,
mpz_get_str(NULL, 10, year))) / 2; i > 0; --i) putchar(' ');
puts(cal_head);
puts(weekdays);
if(!mpz_cmp_ui(year, 1752) && month == 9){
puts(" 1 2 14 15 16");
puts(" 17 18 19 20 21 22 23");
puts(" 24 25 26 27 28 29 30");
}else{
month_days = months_days[month - 1];
mpz_init(tmp1);
mpz_init(tmp2);
mpz_init(tmp3);
mpz_init(tmp4);
if(mpz_cmp_ui(year, 1752) > 0 || (!mpz_cmp_ui(year, 1752) && month > 9)){
/* Gregorian */
if(month == 2 && mpz_divisible_ui_p(year, 4) && !mpz_divisible_ui_p(year,
100) || mpz_divisible_ui_p(year, 400)) month_days = 29;
mpz_add_ui(tmp4, year, 4800 - (14 - month) / 12);
mpz_tdiv_q_ui(tmp1, tmp4, 4);
mpz_tdiv_q_ui(tmp2, tmp4, 100);
mpz_tdiv_q_ui(tmp3, tmp4, 400);
mpz_mul_ui(tmp4, tmp4, 365);
mpz_add(tmp4, tmp4, tmp1);
mpz_sub(tmp4, tmp4, tmp2);
mpz_add(tmp4, tmp4, tmp3);
mpz_add_ui(tmp4, tmp4, (153 * (month + 12 * ((14 - month) / 12) - 3) + 2) /
5);
mpz_sub_ui(tmp4, tmp4, 32043);
day_of_week = mpz_tdiv_ui(tmp4, 7);
}else{
/* Julian */
if(month == 2 && mpz_divisible_ui_p(year, 4))
month_days = 29;
mpz_add_ui(tmp2, year, 4800 - (14 - month) / 12);
mpz_tdiv_q_ui(tmp1, tmp2, 4);
mpz_mul_ui(tmp2, tmp2, 365);
mpz_add(tmp2, tmp2, tmp1);
mpz_add_ui(tmp2, tmp2, (153 * (month + 12 * ((14 - month) / 12) - 3) + 2) /
5);
mpz_sub_ui(tmp2, tmp2, 32081);
day_of_week = mpz_tdiv_ui(tmp2, 7);
}
mpz_clear(tmp1);
mpz_clear(tmp2);
mpz_clear(tmp3);
mpz_clear(tmp4);
for(int i = 0; i < day_of_week; ++i) fputs(" ", stdout);
for(int i = 1; i <= month_days; ++i){
printf("% 3u", i);
++day_of_week;
putchar((day_of_week %= 7) ? ' ' : '\n');
}
}
putchar('\n');
}
mpz_clear(year);
return 0;
}
and here's a localization file for it:
# icelandic localization for cal
# Copyright (C) 2008 anonymous
# This file is distributed under the same license as the cal package.
#
msgid ""
msgstr ""
"Project-Id-Version: cal 1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2008-12-18 12:28-0000\n"
"PO-Revision-Date: 2008-12-18 10:29-0500\n"
"Last-Translator: anonymous\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language-Team: Icelandic\n"
msgid "learn to use cal, you idiot: http://opengroup.org/susv3xcu/cal.html\n"
msgstr ""
"lærðu að nota cal, þú fábjáni: http://opengroup.org/susv3xcu/cal.html\n"