Description: Add Big5 and UTF-8 output options for lunar.c
 Big5 support was added to 2.2-1 in 2002.
 .
 UTF-8 support was added to 2.2-3 at the request of LI Daobing in 2006,
 see Debian Bug#288170.  However, it could only print simplified Chinese
 in UTF-8 mode back then.
 .
 In 2013, two new options, -s and -t, were added to 2.2-4 so that the
 end-user may choose either simplified or traditional Chinese in UTF-8 mode.
Author: Anthony Fok <foka@debian.org>
Origin: vendor
Bug-Debian: http://bugs.debian.org/288170
Forwarded: not-needed
Last-Update: 2013-10-04
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/lunar.c
+++ b/lunar.c
@@ -112,6 +112,31 @@ static char *weekday[] = {
     "Thursday", "Friday", "Saturday"
 };
 
+static	char	*GanUTF8[] = {
+    "甲", "乙", "丙", "丁", "戊",
+    "己", "庚", "辛", "壬", "癸"
+};
+
+static	char	*ZhiUTF8[] = {
+    "子", "丑", "寅", "卯", "辰", "巳",
+    "午", "未", "申", "酉", "戌", "亥"
+};
+
+static	char   *ShengXiaoUTF8_hant[] = {
+    "鼠", "牛", "虎", "兔", "龍", "蛇",
+    "馬", "羊", "猴", "雞", "狗", "豬"
+};
+
+static	char   *ShengXiaoUTF8_hans[] = {
+    "鼠", "牛", "虎", "兔", "龙", "蛇",
+    "马", "羊", "猴", "鸡", "狗", "猪"
+};
+
+static char *weekdayUTF8[] = {
+    "日", "一", "二", "三",
+    "四", "五", "六"
+};
+
 static	char	*GanGB[] = {
     "", "", "", "", "",
     "", "", "", "", ""
@@ -132,6 +157,26 @@ static char *weekdayGB[] = {
     "", "", ""
 };
 
+static	char	*GanB5[] = {
+    "", "A", "", "B", "",
+    "v", "", "", "", ""
+};
+
+static	char	*ZhiB5[] = {
+    "l", "", "G", "f", "", "x",
+    "", "", "", "", "", ""
+};
+
+static	char   *ShengXiaoB5[] = {
+    "", "", "", "", "s", "D",
+    "", "", "U", "", "", ""
+};
+
+static char *weekdayB5[] = {
+    "", "@", "G", "T",
+    "|", "", ""
+};
+
 
 Date solar, lunar, gan, zhi, gan2, zhi2, lunar2;
 
@@ -140,8 +185,11 @@ int yday[Nyear];	/* number of lunar days
 int mday[Nmonth+1];	/* number of days in the months of the lunar year */
 int jieAlert;		/* if there is uncertainty in JieQi calculation */
 
-int	showHZ = 0;			/* output in hanzi */
+int	showHZ_GB = 0;			/* output in GB-encoded hanzi */
 int	showBM = 0;			/* output in bitmap */
+int	showHZ_UTF8 = 0;		/* output in UTF-8-encoded hanzi */
+int	showHZ_B5 = 0;			/* output in Big5-encoded hanzi */
+int	simplified = 0;			/* output in simplified Chinese */
 char	BMfile[] = "/usr/share/lunar/lunar.bitmap";	/* bit map file */
 char	GZBM[NBM][BMRow][BMCol];	/* the bitmap array */
 char	*progname;
@@ -153,7 +201,8 @@ int     make_yday(), make_mday(), GZcycl
 void	CalGZ();
 int	CmpDate(), JieDate();
 void    readBM(), display3();
-void	Report(), ReportE(), ReportBM(), ReportGB();
+void	Report(), ReportE(), ReportBM(), ReportGB(), ReportB5();
+void	ReportUTF8_hant(), ReportUTF8_hans();
 void	usage(), Error();
 
 
@@ -174,8 +223,45 @@ char *argv[];
 	{
 	    case 'i': inverse = 1; break;
 	    case 'l': if (inverse) leap=1; else usage(); break;
-	    case 'h': showHZ = 1; break;
-	    case 'b': showBM = 1; break;
+	    case 'g':
+	    case 'h': showHZ_GB = 1;
+		      showHZ_UTF8 = showHZ_B5 = 0;
+		      break;
+	    case 'b': showBM = 1;
+		      showHZ_UTF8 = showHZ_GB = showHZ_B5 = 0;
+		      break;
+	    case 'u': showHZ_UTF8 = 1;
+		      showHZ_B5 = showHZ_GB = 0;
+		      break;
+	    case '5': showHZ_B5 = 1;
+		      showHZ_UTF8 = showHZ_GB = 0;
+		      break;
+	    case 's': simplified = 1; break;
+	    case 't': simplified = 0; break;
+	    case '-':
+		if (!strcmp(argv[k], "--utf8"))
+		{
+		    showHZ_UTF8 = 1;
+		    showHZ_B5 = 0;
+		    showHZ_GB = 0;
+		}
+		else if (!strcmp(argv[k], "--big5"))
+		{
+		    showHZ_B5 = 1;
+		    showHZ_UTF8 = 0;
+		    showHZ_GB = 0;
+		}
+		else if (!strcmp(argv[k], "--gb"))
+		{
+		    showHZ_GB = 1;
+		    showHZ_UTF8 = 0;
+		    showHZ_B5 = 0;
+		}
+		else if (!strcmp(argv[k], "--help"))
+		    usage();
+		else
+		    usage();
+		break;
 	    default:  usage(); break;
 	}
     }
@@ -230,12 +316,16 @@ void usage()
     printf("Usage:\n\n");
     printf("Solar->Lunar:\t%s [-h] [-b] year month day [hour]\n", progname);
     printf("\t\t(in Solar Calendar, 24 hour clock)\n\n");
-    printf("Lunar->Solar:\t%s [-h] [-b] -i [-l] year month day [hour]\n",
+    printf("Lunar->Solar:\t%s [-u] [-h] [-b] -i [-l] year month day [hour]\n",
 	   progname);
     printf("\t\t(in Lunar Calendar, 24 hour clock)\n");
-    printf("\t\t-l means the month is a leap month (\"run4 yue4\")\n\n");
-    printf("\t\t-h means output in hanzi (GB)\n");
-    printf("\t\t-b means output in \"bitmap\"\n\n");
+    printf("\t\t-l  means the month is a leap month (\"run4 yue4\")\n\n");
+    printf("\t\t-u, --utf8  means output in hanzi (UTF-8)\n");
+    printf("\t\t        -s  selects simplified Chinese for UTF-8\n");
+    printf("\t\t        -t  selects traditional Chinese for UTF-8\n");
+    printf("\t\t-h, --gb    means output in hanzi (GB)\n");
+    printf("\t\t-5, --big5  means output in hanzi (Big5)\n\n");
+    printf("\t\t-b          means output in \"bitmap\"\n");
     printf("Date range: about %d years from the Solar Date %d.%d.%d\n", Nyear,
 	   SolarFirstDate.year, SolarFirstDate.month, SolarFirstDate.day);
     exit(1);
@@ -586,7 +676,16 @@ int year;
 
 void Report()
 {
-    if (showHZ)
+    if (showHZ_UTF8)
+    {
+	if (simplified)
+	    ReportUTF8_hans();
+	else
+	    ReportUTF8_hant();
+    }
+    else if (showHZ_B5)
+	ReportB5();
+    else if (showHZ_GB)
 	ReportGB();
     else if (showBM)
 	ReportBM();
@@ -595,6 +694,72 @@ void Report()
 }
 
 
+void ReportUTF8_hant()
+{
+    printf("%s%d%s%2d%s%2d%s%2d%s%s%s\n", "陽曆：　",
+	   solar.year, "年", solar.month, "月", solar.day,
+	   "日", solar.hour, "時　",
+	   "星期", weekdayUTF8[solar.weekday]);
+    printf("%s%d%s%s%2d%s%2d%s%s%s%s%s\n", "陰曆：　",
+	   lunar.year, "年", (lunar.leap? "閏":""),
+	   lunar.month, "月", lunar.day, "日",
+	   ZhiUTF8[zhi.hour], "時　",
+	   "生肖屬", ShengXiaoUTF8_hant[zhi.year]);
+    printf("%s%s%s%s%s%s%s%s%s%s%s%s%s\n", "干支：　",
+	   GanUTF8[gan.year], ZhiUTF8[zhi.year], "年　",
+	   GanUTF8[gan.month], ZhiUTF8[zhi.month], "月　",
+	   GanUTF8[gan.day], ZhiUTF8[zhi.day], "日　",
+	   GanUTF8[gan.hour], ZhiUTF8[zhi.hour], "時　");
+    printf("%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
+	   "用四柱神算推算之時辰八字：　",
+	   GanUTF8[gan2.year], ZhiUTF8[zhi2.year], "年　",
+	   GanUTF8[gan2.month], ZhiUTF8[zhi2.month], "月　",
+	   GanUTF8[gan2.day], ZhiUTF8[zhi2.day], "日　",
+	   GanUTF8[gan2.hour], ZhiUTF8[zhi2.hour], "時　");
+    if (jieAlert)
+    {
+	printf("* %s, %s\n", "是日為節",
+	       "月柱可能要修改");
+	if (lunar2.month==1)
+	    printf("* %s\n", "年柱亦可能要修改");
+	printf("* %s\n", "請查有節氣時間之萬年曆");
+    }
+}
+
+
+void ReportUTF8_hans()
+{
+    printf("%s%d%s%2d%s%2d%s%2d%s%s%s\n", "阳历：　",
+	   solar.year, "年", solar.month, "月", solar.day,
+	   "日", solar.hour, "时　",
+	   "星期", weekdayUTF8[solar.weekday]);
+    printf("%s%d%s%s%2d%s%2d%s%s%s%s%s\n", "阴历：　",
+	   lunar.year, "年", (lunar.leap? "闰":""),
+	   lunar.month, "月", lunar.day, "日",
+	   ZhiUTF8[zhi.hour], "时　",
+	   "生肖属", ShengXiaoUTF8_hans[zhi.year]);
+    printf("%s%s%s%s%s%s%s%s%s%s%s%s%s\n", "干支：　",
+	   GanUTF8[gan.year], ZhiUTF8[zhi.year], "年　",
+	   GanUTF8[gan.month], ZhiUTF8[zhi.month], "月　",
+	   GanUTF8[gan.day], ZhiUTF8[zhi.day], "日　",
+	   GanUTF8[gan.hour], ZhiUTF8[zhi.hour], "时　");
+    printf("%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
+	   "用四柱神算推算之时辰八字：　",
+	   GanUTF8[gan2.year], ZhiUTF8[zhi2.year], "年　",
+	   GanUTF8[gan2.month], ZhiUTF8[zhi2.month], "月　",
+	   GanUTF8[gan2.day], ZhiUTF8[zhi2.day], "日　",
+	   GanUTF8[gan2.hour], ZhiUTF8[zhi2.hour], "时　");
+    if (jieAlert)
+    {
+	printf("* %s, %s\n", "是日为节",
+	       "月柱可能要修改");
+	if (lunar2.month==1)
+	    printf("* %s\n", "年柱亦可能要修改");
+	printf("* %s\n", "请查有节气时间之万年历");
+    }
+}
+
+
 void ReportGB()
 {
     printf("%s%d%s%2d%s%2d%s%2d%s%s%s\n", "",
@@ -627,6 +792,39 @@ void ReportGB()
     }
 }
 
+
+void ReportB5()
+{
+    printf("%s%d%s%2d%s%2d%s%2d%s%s%s\n", "G@",
+	   solar.year, "~", solar.month, "", solar.day,
+	   "", solar.hour, "ɡ@",
+	   "P", weekdayB5[solar.weekday]);
+    printf("%s%d%s%s%2d%s%2d%s%s%s%s%s\n", "G@",
+	   lunar.year, "~", (lunar.leap? "|":""),
+	   lunar.month, "", lunar.day, "",
+	   ZhiB5[zhi.hour], "ɡ@",
+	   "ͨv", ShengXiaoB5[zhi.year]);
+    printf("%s%s%s%s%s%s%s%s%s%s%s%s%s\n", "zG@",
+	   GanB5[gan.year], ZhiB5[zhi.year], "~@",
+	   GanB5[gan.month], ZhiB5[zhi.month], "@",
+	   GanB5[gan.day], ZhiB5[zhi.day], "@",
+	   GanB5[gan.hour], ZhiB5[zhi.hour], "ɡ@");
+    printf("%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
+	   "Υ|W⤧ɨKrG@",
+	   GanB5[gan2.year], ZhiB5[zhi2.year], "~@",
+	   GanB5[gan2.month], ZhiB5[zhi2.month], "@",
+	   GanB5[gan2.day], ZhiB5[zhi2.day], "@",
+	   GanB5[gan2.hour], ZhiB5[zhi2.hour], "ɡ@");
+    if (jieAlert)
+    {
+	printf("* %s, %s\n", "O鬰`",
+	       "Winק");
+	if (lunar2.month==1)
+	    printf("* %s\n", "~Winק");
+	printf("* %s\n", "Ьd`ɶU~");
+    }
+}
+
 
 void ReportE()
 {
