3f579d3
diff -urN calendar-1.25.orig/calendar.h calendar-1.25/calendar.h
3f579d3
--- calendar-1.25.orig/calendar.h	2009-03-03 22:37:55.000000000 -0500
3f579d3
+++ calendar-1.25/calendar.h	2009-03-04 00:08:53.000000000 -0500
3f579d3
@@ -31,6 +31,8 @@
3f579d3
 
3f579d3
 #include <sys/uio.h>
3f579d3
 
3f579d3
+#include <iconv.h>
3f579d3
+
3f579d3
 extern struct passwd *pw;
3f579d3
 extern int doall;
3f579d3
 extern int bodun_always;
3f579d3
@@ -70,6 +72,7 @@
3f579d3
 	int (*getev)(int);
3f579d3
 };
3f579d3
 
3f579d3
+void     convprint(FILE *, iconv_t, char *);
3f579d3
 void	 cal(void);
3f579d3
 void	 closecal(FILE *);
3f579d3
 int	 getday(char *);
3f579d3
diff -urN calendar-1.25.orig/io.c calendar-1.25/io.c
3f579d3
--- calendar-1.25.orig/io.c	2009-03-03 22:37:55.000000000 -0500
3f579d3
+++ calendar-1.25/io.c	2009-03-04 00:11:21.000000000 -0500
3f579d3
@@ -61,10 +61,17 @@
3f579d3
 #include <string.h>
3f579d3
 #include <unistd.h>
3f579d3
 
3f579d3
+#include <langinfo.h>
3f579d3
+#include <iconv.h>
3f579d3
+
3f579d3
 #include "pathnames.h"
3f579d3
 #include "calendar.h"
3f579d3
 
3f579d3
 
3f579d3
+#define ICONV_TRANSLIT  "/" "/" "TRANSLIT"
3f579d3
+#define ICONV_FROMCODE  "UTF-8"
3f579d3
+#define ICONV_BUFSIZ    (128)
3f579d3
+
3f579d3
 struct iovec header[] = {
3f579d3
 	{ "From: ", 6 },
3f579d3
 	{ NULL, 0 },
3f579d3
@@ -76,6 +83,39 @@
3f579d3
 	{ "Auto-Submitted: auto-generated\n\n", 32 },
3f579d3
 };
3f579d3
 
3f579d3
+void
3f579d3
+convprint(FILE *fp, iconv_t ic, char *inputbuf)
3f579d3
+{
3f579d3
+    char *iconv_input;
3f579d3
+    char *iconv_output;
3f579d3
+    char outputbuf[ICONV_BUFSIZ];
3f579d3
+    size_t inputsz;
3f579d3
+    size_t outputsz;
3f579d3
+    size_t iconv_result;
3f579d3
+
3f579d3
+    iconv_input = inputbuf;
3f579d3
+    inputsz = strlen(inputbuf);
3f579d3
+
3f579d3
+    while (inputsz > 0)
3f579d3
+    {
3f579d3
+        iconv_output = outputbuf;
3f579d3
+        outputsz = sizeof(outputbuf) - 1;
3f579d3
+
3f579d3
+        iconv_result = iconv(
3f579d3
+                ic,
3f579d3
+                &iconv_input,
3f579d3
+                &inputsz,
3f579d3
+                &iconv_output,
3f579d3
+                &outputsz
3f579d3
+                );
3f579d3
+        if ((((size_t) -1) == iconv_result) && (E2BIG != errno))
3f579d3
+        {
3f579d3
+            return;
3f579d3
+        }
3f579d3
+        outputbuf[sizeof(outputbuf) - outputsz - 1] = '\0';
3f579d3
+        (void)fprintf(fp, "%s", outputbuf);
3f579d3
+    }
3f579d3
+}
3f579d3
 
3f579d3
 void
3f579d3
 cal(void)
3f579d3
@@ -86,6 +126,42 @@
3f579d3
 	struct match *m;
3f579d3
 	FILE *fp;
3f579d3
 
3f579d3
+        char *langinfo_coding;
3f579d3
+        char *iconv_coding;
3f579d3
+        iconv_t ic;
3f579d3
+        int use_iconv;
3f579d3
+
3f579d3
+        use_iconv = 1;
3f579d3
+        iconv_coding = NULL;
3f579d3
+        ic = (iconv_t) -1;
3f579d3
+        (void)setlocale(LC_ALL, "");
3f579d3
+        langinfo_coding = nl_langinfo(CODESET);
3f579d3
+        if ((NULL == langinfo_coding) || ('\0' == *langinfo_coding))
3f579d3
+        {
3f579d3
+            use_iconv = 0;
3f579d3
+        }
3f579d3
+        else
3f579d3
+        {
3f579d3
+            iconv_coding = malloc(
3f579d3
+                    strlen(langinfo_coding) + sizeof(ICONV_TRANSLIT)
3f579d3
+                    );
3f579d3
+        }
3f579d3
+
3f579d3
+        if (NULL == iconv_coding)
3f579d3
+        {
3f579d3
+            use_iconv = 0;
3f579d3
+        }
3f579d3
+        else
3f579d3
+        {
3f579d3
+            sprintf(iconv_coding, "%s%s", langinfo_coding, ICONV_TRANSLIT);
3f579d3
+            ic = iconv_open(iconv_coding, ICONV_FROMCODE);
3f579d3
+        }
3f579d3
+
3f579d3
+        if (((iconv_t) -1) == ic)
3f579d3
+        {
3f579d3
+            use_iconv = 0;
3f579d3
+        }
3f579d3
+
3f579d3
 	events = NULL;
3f579d3
 	cur_evt = NULL;
3f579d3
 	if ((fp = opencal()) == NULL)
3f579d3
@@ -101,6 +177,14 @@
3f579d3
 		if (buf[0] == '\0')
3f579d3
 			continue;
3f579d3
 		if (strncmp(buf, "LANG=", 5) == 0) {
3f579d3
+                        if (use_iconv)
3f579d3
+                        {
3f579d3
+                            char *coding_start = strchr(buf, '.');
3f579d3
+                            if (NULL != coding_start)
3f579d3
+                            {
3f579d3
+                                strcpy(coding_start, ".UTF-8");
3f579d3
+                            }
3f579d3
+                        }
3f579d3
 			(void) setlocale(LC_ALL, buf + 5);
3f579d3
 			setnnames();
3f579d3
 			if (!strcmp(buf + 5, "ru_RU.KOI8-R") ||
3f579d3
@@ -215,8 +299,17 @@
3f579d3
 	}
3f579d3
 	tmp = events;
3f579d3
 	while (tmp) {
3f579d3
+            if (use_iconv)
3f579d3
+            {
3f579d3
+                convprint(fp, ic, tmp->print_date);
3f579d3
+                convprint(fp, ic, *(tmp->desc));
3f579d3
+                (void)fputc((int) '\n', fp);
3f579d3
+            }
3f579d3
+            else
3f579d3
+            {
3f579d3
 		(void)fprintf(fp, "%s%s\n", tmp->print_date, *(tmp->desc));
3f579d3
-		tmp = tmp->next;
3f579d3
+            }
3f579d3
+            tmp = tmp->next;
3f579d3
 	}
3f579d3
 	tmp = events;
3f579d3
 	while (tmp) {
3f579d3
@@ -226,6 +319,17 @@
3f579d3
 		tmp = tmp->next;
3f579d3
 		free(events);
3f579d3
 	}
3f579d3
+
3f579d3
+        if (NULL != iconv_coding)
3f579d3
+        {
3f579d3
+            free(iconv_coding);
3f579d3
+        }
3f579d3
+
3f579d3
+        if (((iconv_t) -1) != ic)
3f579d3
+        {
3f579d3
+            iconv_close(ic);
3f579d3
+        }
3f579d3
+
3f579d3
 	closecal(fp);
3f579d3
 }
3f579d3