|
0 |
/* hcal.c http://libhdate.sourceforge.net
|
|
1 |
* Hebrew calendar (part of package libhdate)
|
|
2 |
*
|
|
3 |
* compile:
|
|
4 |
* gcc `pkg-config --libs --cflags libhdate` hcal.c -o hcal
|
|
5 |
*
|
|
6 |
* Copyright: 2011-2012 (c) Boruch Baum, 2004-2010 (c) Yaacov Zamir
|
|
7 |
*
|
|
8 |
* This program is free software: you can redistribute it and/or modify
|
|
9 |
* it under the terms of the GNU General Public License as published by
|
|
10 |
* the Free Software Foundation, either version 3 of the License, or
|
|
11 |
* (at your option) any later version.
|
|
12 |
*
|
|
13 |
* This program is distributed in the hope that it will be useful,
|
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 |
* GNU General Public License for more details.
|
|
17 |
*
|
|
18 |
* You should have received a copy of the GNU General Public License
|
|
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include <stdio.h> // For printf
|
|
23 |
#include <hdate.h> // For hebrew date
|
|
24 |
//#include "../../src/hdate.h"
|
|
25 |
#include <stdlib.h> // For atoi, malloc
|
|
26 |
#include <locale.h> // For setlocale
|
|
27 |
#include <getopt.h> // For getopt_long
|
|
28 |
#include <string.h> // For strlen, mempcpy
|
|
29 |
#include <time.h> // For time, tzset
|
|
30 |
//#include <wchar.h> // for unicode character operations
|
|
31 |
|
|
32 |
#define FALSE 0
|
|
33 |
#define TRUE -1
|
|
34 |
#define SHABBAT 7
|
|
35 |
|
|
36 |
#define HDATE_STRING_SHORT 1
|
|
37 |
|
|
38 |
// for opt.menu[MAX_MENU_ITEMS]
|
|
39 |
#define MAX_MENU_ITEMS 10
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
// for colorization
|
|
44 |
#define CODE_REVERSE_VIDEO "%c[7m", 27
|
|
45 |
#define CODE_RESTORE_VIDEO "%c[m", 27
|
|
46 |
#define CODE_BLACK "%c[30m", 27
|
|
47 |
#define CODE_LIGHT_RED "%c[31m", 27
|
|
48 |
#define CODE_LIGHT_GREEN "%c[32m", 27
|
|
49 |
#define CODE_LIGHT_BROWN "%c[33m", 27
|
|
50 |
#define CODE_DARK_BLUE "%c[34m", 27
|
|
51 |
#define CODE_LIGHT_PURPLE "%c[35m", 27
|
|
52 |
#define CODE_LIGHT_AQUA "%c[36m", 27
|
|
53 |
#define CODE_LIGHT_GREY "%c[37m", 27
|
|
54 |
#define CODE_BOLD_GREY "%c[1;30m", 27
|
|
55 |
#define CODE_BOLD_RED "%c[1;31m", 27
|
|
56 |
#define CODE_BOLD_GREEN "%c[1;32m", 27
|
|
57 |
#define CODE_BOLD_YELLOW "%c[1;33m", 27
|
|
58 |
#define CODE_BOLD_BLUE "%c[1;34m", 27
|
|
59 |
#define CODE_BOLD_PURPLE "%c[1;35m", 27
|
|
60 |
#define CODE_BOLD_AQUA "%c[1;36m", 27
|
|
61 |
#define CODE_BOLD_WHITE "%c[1;37m", 27
|
|
62 |
#define ELEMENT_WEEKDAY_G 1
|
|
63 |
#define ELEMENT_WEEKDAY_H 2
|
|
64 |
#define ELEMENT_SHABBAT_DAY 3
|
|
65 |
#define ELEMENT_HOLIDAY_DAY 4
|
|
66 |
#define ELEMENT_HOLIDAY_FLAG 5
|
|
67 |
#define ELEMENT_SHABBAT_NAME 6
|
|
68 |
#define ELEMENT_WEEKDAY_NAMES 7
|
|
69 |
#define ELEMENT_MONTH_G 8
|
|
70 |
#define ELEMENT_MONTH_H 9
|
|
71 |
#define ELEMENT_SHABBAT_TIMES 10
|
|
72 |
#define ELEMENT_PARASHA 11
|
|
73 |
#define ELEMENT_THIS_SHABBAT_TIMES 12
|
|
74 |
#define ELEMENT_THIS_PARASHA 13
|
|
75 |
#define ELEMENT_HOLIDAY_NAME 14
|
|
76 |
#define ELEMENT_TODAY_HOLIDAY_DAY 15
|
|
77 |
#define ELEMENT_TODAY_HOLIDAY_NAME 16
|
|
78 |
|
|
79 |
/**************************************************
|
|
80 |
* functions to support hcal and hdate
|
|
81 |
**************************************************/
|
|
82 |
#include "./local_functions.c"
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
static char holiday_flag[] = { '/', '+', '*', '~', '!', '@', '#', '$', '%', '^' };
|
|
87 |
/* Holiday types: (reference hdate_holyday.c)
|
|
88 |
/ - 0 - Regular day
|
|
89 |
+ - 1 - Yom tov (plus yom kippor)
|
|
90 |
* - 2 - Erev yom kippur
|
|
91 |
~ - 3 - Hol hamoed
|
|
92 |
! - 4 - Hanuka and purim
|
|
93 |
@ - 5 - Tzomot
|
|
94 |
# - 6 - Independance day and Yom yerushalaim
|
|
95 |
$ - 7 - Lag baomer ,Tu beav, Tu beshvat
|
|
96 |
% - 8 - Tzahal and Holocaust memorial days
|
|
97 |
^ - 9 - National days
|
|
98 |
*/
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
typedef struct {
|
|
103 |
int html;
|
|
104 |
int external_css;
|
|
105 |
int diaspora;
|
|
106 |
int parasha;
|
|
107 |
int shabbat;
|
|
108 |
int candles;
|
|
109 |
int havdalah;
|
|
110 |
int no_reverse;
|
|
111 |
int three_month;
|
|
112 |
int colorize;
|
|
113 |
int footnote;
|
|
114 |
int jd_today_g;
|
|
115 |
int jd_today_h;
|
|
116 |
int force_hebrew;
|
|
117 |
int force_israel;
|
|
118 |
int not_sunset_aware;
|
|
119 |
int quiet_alerts;
|
|
120 |
int bidi;
|
|
121 |
double lat;
|
|
122 |
double lon;
|
|
123 |
int tz;
|
|
124 |
int menu;
|
|
125 |
char* menu_item[MAX_MENU_ITEMS];
|
|
126 |
} option_list;
|
|
127 |
|
|
128 |
typedef struct {
|
|
129 |
int g_month_1;
|
|
130 |
int g_year_1;
|
|
131 |
int g_month_2;
|
|
132 |
int g_year_2;
|
|
133 |
int h_month_1;
|
|
134 |
int h_year_1;
|
|
135 |
int h_month_2;
|
|
136 |
int h_year_2;
|
|
137 |
} header_info;
|
|
138 |
|
|
139 |
|
|
140 |
const char* hcal_config_file_text = N_("\
|
|
141 |
# configuration file for hcal - Hebrew calendar program\n\
|
|
142 |
# part of package libhdate\n\
|
|
143 |
#\n# Should you mangle this file and wish to restore its default content,\n\
|
|
144 |
# rename or delete this file and run hcal; hcal will automatically\n\
|
|
145 |
# regenerate the default content.\n#\n\
|
|
146 |
# Your system administrator can set system-wide defaults for hcal by\n\
|
|
147 |
# modifying file <not yet implemented>.\n\
|
|
148 |
# You may override all defaults by changing the contents of this file.\n\
|
|
149 |
#\n\
|
|
150 |
# Version information\n\
|
|
151 |
# This may be used by updates to hcal to determine how to parse the file\n\
|
|
152 |
# and whether additional information and options should be appended to\n\
|
|
153 |
# the end of this file.\n\
|
|
154 |
VERSION=2.00\n\
|
|
155 |
# Location awareness\n\
|
|
156 |
# hcal wants to accurately highlight the current Hebrew day, including\n\
|
|
157 |
# during the hours between sunset and secular midnight. If you don't\n\
|
|
158 |
# provide it with latitude, longitude, and time zone information, hcal\n\
|
|
159 |
# will try to guess the information, based upon your system timezone,\n\
|
|
160 |
# and its (limited, and maybe biased) of the dominant Jewish community\n\
|
|
161 |
# in that timezone. When hcal is forced to guess, it alerts the user\n\
|
|
162 |
# with a message that includes the guessed location.\n\
|
|
163 |
# hcal's guesses will also affect its default behaviour for output of\n\
|
|
164 |
# Shabbat times, parshiot, and choice of Israel/diaspora hoidays\n\
|
|
165 |
#SUNSET_AWARE=TRUE\n\
|
|
166 |
# LATITUDE and LONGITUDE may be in decimal format or in the form\n\
|
|
167 |
# degrees[:minutes[:seconds]] with the characters :'\" as possible\n\
|
|
168 |
# delimiters. Use negative values to indicate South and West, or\n\
|
|
169 |
# use the abbreviated compass directions N, S, E, W.\n\
|
|
170 |
#LATITUDE=\n\
|
|
171 |
#LONGITUDE=\n\
|
|
172 |
# TIMEZONE may may be in decimal format or in the form degrees[:minutes]\n\
|
|
173 |
# with the characters :'\" as possible delimiters.\n\
|
|
174 |
#TIMEZONE=\n\n\
|
|
175 |
# Israel and the diaspora\n\
|
|
176 |
# If hcal guesses that you're not in Israel, the DIASPORA option will be\n\
|
|
177 |
# set true. This will affect holiday and parasha output. FORCE_ISRAEL\n\
|
|
178 |
# forces hcal to display calendar information for Israel, using hcal's\n\
|
|
179 |
# default coordinates foe Israel, or coordinates that you provide that\n\
|
|
180 |
# seem legitmately within Israel.\n\
|
|
181 |
# Thus, if you are living in Sao Paolo, and will be visiting Israel for\n\
|
|
182 |
# Sukkot, set BOTH flags true in order to see holiday information for\n\
|
|
183 |
# a non-resident vistor to Israel. The command line options for these\n\
|
|
184 |
# features are --israel, -I, --diaspora, -d.\n\
|
|
185 |
#FORCE_DIASPORA=FALSE;\n\
|
|
186 |
#FORCE_ISRAEL=FALSE;\n\n\
|
|
187 |
# Shabbat related\n\
|
|
188 |
# Setting SHABBAT_INFO true will output parshiot and Shabbat times.\n\
|
|
189 |
# The command line options for these features are -p (--parasha), and\n\
|
|
190 |
# -s (--shabbat). The CANDLE_LIGHTING field can accept a value of 18 - 90 (minutes\n\
|
|
191 |
# before sunset). The HAVDALAH field can accept a value of 20 - 90\n\
|
|
192 |
# (minutes after sunset).\n\
|
|
193 |
#PARASHA_NAMES=FALSE\n\
|
|
194 |
#SHABBAT_INFO=FALSE\n\
|
|
195 |
#CANDLE_LIGHTING=FALSE\n\
|
|
196 |
#HAVDALAH=FALSE\n\n\
|
|
197 |
# Holiday identification\n\
|
|
198 |
# hcal flags holidays by replacing the gregorian/Hebrew date separator\n\
|
|
199 |
# with assorted unhelpful cryptic symbols. Setting FOOTNOTES to true\n\
|
|
200 |
# will have hcal output after the month's calendar, a list of the month's\n\
|
|
201 |
# holidays along with the days on which they occur.\n\
|
|
202 |
#FOOTNOTE=FALSE\n\n\
|
|
203 |
# Output in hebrew characters\n\
|
|
204 |
# hcal defaults to output all information in your default language, so\n\
|
|
205 |
# if your default language is Hebrew, you're all set. Otherwise, you can\n\
|
|
206 |
# set FORCE_HEBREW to true to output Hebrew information in Hebrew, while\n\
|
|
207 |
# still outputting gregorian information in your default language. To\n\
|
|
208 |
# output ALL information in Hebrew, run something like this:\n\
|
|
209 |
# LC_TEMP=LC_ALL; LC_ALL=\"he_IL.UTF-8\"; hcal; LC_ALL=$LC_TEMP\n\
|
|
210 |
# If setting FORCE_HEBREW to true results in 'garbage' or non-Hebrew\n\
|
|
211 |
# output, you need to install a terminal font that includes the Hebrew\n\
|
|
212 |
# character set (hint: unicode).\n\
|
|
213 |
# The command line option for FORCE_HEBREW is either --hebrew or -H\n\
|
|
214 |
#FORCE_HEBREW=FALSE\n\n\
|
|
215 |
# The FORCE_HEBREW option outputs data that is 'correct' and 'logical'.\n\
|
|
216 |
# Unfortunately, the world can not be depended upon to be either. Most\n\
|
|
217 |
# Xwindow applications will display the data fine with FORCE_HEBREW; most\n\
|
|
218 |
# xterm implementations will not. (in fact, the only xterm clone I know\n\
|
|
219 |
# of that comes close is mlterm). If using FORCE_HEBREW results in\n\
|
|
220 |
# Hebrew characters being displayed in reverse, set OUTPUT_BIDI to true.\n\
|
|
221 |
# This will reverse the order of the Hebrew characters, so they will\n\
|
|
222 |
# display 'visual'ly correct; however, such output will not be suitable\n\
|
|
223 |
# for piping or pasting to many other applications. Setting OUTPUT_BIDI\n\
|
|
224 |
# automatically forces hebrew.\n\
|
|
225 |
# The command line option for OUTPUT_BIDI is either --bidi, --visual, or -b\n\
|
|
226 |
#OUTPUT_BIDI=FALSE\n\n\
|
|
227 |
# Display enhancements\n\
|
|
228 |
# hcal defaults to display the current day in reverse video\n\
|
|
229 |
# The command line option for this feature is --no-reverse\n\
|
|
230 |
#SUPPRESS_REVERSE_VIDEO=FALSE;\n\
|
|
231 |
# hcal can display its output \"calming, muted tones\". Note that piping\n\
|
|
232 |
# colorized output may yield unexpected results.\n\
|
|
233 |
#COLORIZE=FALSE\n\n\
|
|
234 |
# HTML OUTPUT\n\
|
|
235 |
#OUTPUT_HTML=FALSE\n\
|
|
236 |
#USE_EXTERNAL_CSS_FILE=\"pathto/foo/bar\"\n\n\
|
|
237 |
# Suppress alerts and warnings\n\
|
|
238 |
# hcal alerts the user via STDERR when it guesses the user's location.\n\
|
|
239 |
#QUIET_ALERTS=FALSE\n\n\
|
|
240 |
# Three month display\n\
|
|
241 |
# hcal can display a previous, current and next month side-by-side. hcal\n\
|
|
242 |
# can also display a calendar for an entire year in four rows of three\n\
|
|
243 |
# months each. Note that this will display properly only if your console\n\
|
|
244 |
# is set for at least 127 columns. Note also that setting this option to\n\
|
|
245 |
# will cause options FOOTNOTES, SHABBAT, and PARASHA_NAMES to false.\n\
|
|
246 |
#THREE_MONTH=FALSE\n\n\
|
|
247 |
# User-defined menus\n\
|
|
248 |
# You may specify here command-line strings to optionally be parsed\n\
|
|
249 |
# by hcal at execution time. To do so, use the command line option -m\n\
|
|
250 |
# (--menu). hcal will process first the settings of this config file,\n\
|
|
251 |
# then the other settings of your command line, and then will prompt\n\
|
|
252 |
# you for which menu item you would like to select. hcal will process\n\
|
|
253 |
# your menu selection as if it were a new command line, further modifying\n\
|
|
254 |
# all the prior settings.\n\
|
|
255 |
# Only the first ten \"MENU=\" entries will be read. Each line will be\n\
|
|
256 |
# truncated at one hundred characters\n\
|
|
257 |
#MENU= -l -23.55 -L -46.61 -z -3 # parents in Sao Paolo\n\
|
|
258 |
#MENU= -l 32 -L 34 -z 2 # son in bnei brak\n\
|
|
259 |
#MENU= -fbc -l 43.71 -L -79.43 -z -5 # me in Toronto\n\
|
|
260 |
#MENU= -l 22.26 -L 114.15 -z 8 # supplier in Hong Kong\n\
|
|
261 |
");
|
|
262 |
|
|
263 |
|
|
264 |
/**************************************************
|
|
265 |
* print version
|
|
266 |
*************************************************/
|
|
267 |
int print_version ()
|
|
268 |
{
|
|
269 |
printf ("%s\n", N_("hcal - Hebrew calendar\nversion 1.6"));
|
|
270 |
return 0;
|
|
271 |
}
|
|
272 |
|
|
273 |
/**************************************************
|
|
274 |
* print usage
|
|
275 |
*************************************************/
|
|
276 |
void print_usage_hcal ()
|
|
277 |
{
|
|
278 |
printf ("%s\n",
|
|
279 |
N_("Usage: hcal [options] [coordinates timezone] ] [[month] year]\n\
|
|
280 |
coordinates: -l [NS]yy[.xxx] -L [EW]xx[.xxx]\n\
|
|
281 |
-l [NS]yy[:mm[:ss]] -L [EW]xx[:mm[:ss]]\n\
|
|
282 |
timezone: -z nn[( .nn | :mm )]\n\
|
|
283 |
Try \'hcal --help\' for more information"));
|
|
284 |
}
|
|
285 |
|
|
286 |
/**************************************************
|
|
287 |
* print help
|
|
288 |
*************************************************/
|
|
289 |
void print_help ()
|
|
290 |
{
|
|
291 |
print_usage_hcal();
|
|
292 |
printf ("%s\n",
|
|
293 |
N_("Hebrew calendar\nOPTIONS:\n\
|
|
294 |
-1 --one-month over-ride config file setting if you had set\n\
|
|
295 |
option --three-month as a default there\n\
|
|
296 |
-3 --three-month displays previous/next months\n\
|
|
297 |
side by side. requires 127 columns\n\
|
|
298 |
-b --bidi prints hebrew in reverse (visual)\n\
|
|
299 |
--visual\n\
|
|
300 |
--no-bidi over-ride config file setting if you had set\n\
|
|
301 |
--no-visual option -bidi as a default there\n\
|
|
302 |
-c --colorize displays in calming, muted tones\n\
|
|
303 |
--no-color over-ride a --colorize setting in your config file\n\
|
|
304 |
-d --diaspora use diaspora reading and holidays.\n\
|
|
305 |
-f --footnote print descriptive notes of holidays\n\
|
|
306 |
--no-footnote over-ride a footnote setting in your config file\n\
|
|
307 |
-h --html output in html format to stdout\n\
|
|
308 |
-H --hebrew print hebrew information in Hebrew\n\
|
|
309 |
-i use external css file \"./hcal.css\".\n\
|
|
310 |
-I --israel override a diaspora default\n\
|
|
311 |
--no-reverse do not highlight today's date\n\
|
|
312 |
-m --menu prompt user-defined menu from config file\n\
|
|
313 |
-p --parasha print week's parasha on each calendar row\n\
|
|
314 |
-q --quiet-alerts suppress warning messages\n\
|
|
315 |
-s --shabbat print Shabbat times and parshiot\n\
|
|
316 |
--candles modify default minhag of 20 minutes. (17<n<91)\n\
|
|
317 |
--havdalah modify default minhag of 3 stars. (19<n<91 minutes)\n\
|
|
318 |
-z --timezone nn timezone, +/-UTC\n\
|
|
319 |
-l --latitude yy latitude yy degrees. Negative values are South\n\
|
|
320 |
-L --longitude xx longitude xx degrees. Negative values are West\n\n\
|
|
321 |
All options can be made default in the config file, or menu-ized for\n\
|
|
322 |
easy selection."));
|
|
323 |
}
|
|
324 |
|
|
325 |
|
|
326 |
/**************************************************
|
|
327 |
* HTML - print css section
|
|
328 |
*************************************************/
|
|
329 |
int print_css (const int external_css)
|
|
330 |
{
|
|
331 |
if (external_css) printf ("\n\t@import \"hcal.css\";\n");
|
|
332 |
else
|
|
333 |
{
|
|
334 |
printf ("\nbody.hebrew { direction: rtl;}\n\
|
|
335 |
img { margin:0; padding: 0; vertical-align: middle; border: 0;}\n\
|
|
336 |
p {}\n\
|
|
337 |
table.main { width: 90%%; table-layout: fixed; font-size: 14pt; border: solid #aaaaaa; }\n\
|
|
338 |
table.day { width: 100%%; height: 100%%; table-layout: fixed; font-size: 14pt; }\n\
|
|
339 |
th.gmonth { font-size: 30pt; font-weight: bold }\n\
|
|
340 |
th.gyear { font-size: 30pt; font-weight: bold}\n\
|
|
341 |
th.hmonth { font-size: 30pt; font-weight: bold}\n\
|
|
342 |
th.hyear {font-size: 30pt; font-weight: bold }\n\
|
|
343 |
th.week { background-color: #aaaaaa; text-align: center; }\n\
|
|
344 |
td.gday { font-size: 30pt; vertical-align: top; }\n\
|
|
345 |
td.hday { font-size: 12pt; vertical-align: top; }\n\
|
|
346 |
td.sat { border: solid #777777; }\n\
|
|
347 |
td.regular { border: solid #aaaaaa; }\n\
|
|
348 |
td.holiday { color: #990000; border: solid #888888; }\n\
|
|
349 |
td.out_of_month { color: #dddddd; border: solid #dddddd; }\n\
|
|
350 |
tr.line1 { height: 30%%; }\n\
|
|
351 |
tr.line2 { height: 50%%; font-size: 30pt; }\n\
|
|
352 |
tr.line3 { height: 20%%; font-size: 12pt; vertical-align: bottom; }\n\
|
|
353 |
span.today { }\n\
|
|
354 |
span.gmonth { font-size: 24pt; }\n\
|
|
355 |
span.gyear { font-size: 24pt; }\n\
|
|
356 |
span.hmonth { font-size: 24pt; }\n\
|
|
357 |
span.hyear { font-size: 24pt; }\n\
|
|
358 |
span.holiday_name { }\n");
|
|
359 |
}
|
|
360 |
|
|
361 |
return 0;
|
|
362 |
}
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
/**************************************************
|
|
367 |
* HTML - print header
|
|
368 |
*************************************************/
|
|
369 |
int print_header_html ( const int external_css, const int force_hebrew)
|
|
370 |
{
|
|
371 |
printf ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\"http://www.w3.org/TR/html4/strict.dtd\">\n\
|
|
372 |
<html>\n\
|
|
373 |
<head>\n\
|
|
374 |
<meta name=\"generator\" content=\"hcal (libhdate)\">\n\
|
|
375 |
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n\
|
|
376 |
<style title=\"Normal\" type=\"text/css\" media=\"all\">");
|
|
377 |
|
|
378 |
print_css (external_css);
|
|
379 |
|
|
380 |
printf ("</style>\n");
|
|
381 |
|
|
382 |
/* some alternative css styles */
|
|
383 |
printf ("\n\
|
|
384 |
<link rel=\"alternate stylesheet\" title=\"High contrast\" type=\"text/css\" media=\"screen\" href=\"high_contrast.css\">\n\
|
|
385 |
<link rel=\"alternate stylesheet\" title=\"Colorful\" type=\"text/css\" media=\"screen\" href=\"colorful.css\">\n\
|
|
386 |
<link rel=\"alternate stylesheet\" title=\"Print\" type=\"text/css\" media=\"all\" href=\"print.css\">\n");
|
|
387 |
|
|
388 |
if ( (force_hebrew) || (hdate_is_hebrew_locale()) )
|
|
389 |
printf ("<title>Hebrew Calendar</title>\n</head>\n<body class=\"hebrew\"><center>\n");
|
|
390 |
else
|
|
391 |
printf ("<title>Hebrew Calendar</title>\n</head>\n<body><center>\n");
|
|
392 |
|
|
393 |
return 0;
|
|
394 |
}
|
|
395 |
|
|
396 |
|
|
397 |
|
|
398 |
/**************************************************
|
|
399 |
* HTML - print footer
|
|
400 |
*************************************************/
|
|
401 |
int print_html_footer ()
|
|
402 |
{
|
|
403 |
printf ("<!-- <p>\n\
|
|
404 |
<a href=\"http://validator.w3.org/check/referer\">\n<img \
|
|
405 |
src=\"http://www.w3.org/Icons/valid-html401\"\n\
|
|
406 |
alt=\"Valid HTML 4.01!\" height=\"31\" width=\"88\" />\n</a>\n");
|
|
407 |
printf ("<a href=\"http://jigsaw.w3.org/css-validator\">\n\
|
|
408 |
<img src=\"http://www.w3.org/Icons/valid-css\" alt=\"Valid CSS!\">\n\
|
|
409 |
</a>\n</p> -->\n");
|
|
410 |
|
|
411 |
printf ("</body></html>\n");
|
|
412 |
|
|
413 |
return 0;
|
|
414 |
}
|
|
415 |
|
|
416 |
|
|
417 |
/**************************************************
|
|
418 |
* Print HTML header - month line
|
|
419 |
*************************************************/
|
|
420 |
void print_header_month_line_html( const header_info header)
|
|
421 |
{
|
|
422 |
|
|
423 |
// TODO - fix bug ellul xxxx - tishrei xxxx+1
|
|
424 |
// char *h_year_1;
|
|
425 |
// h_year_1 = malloc(HEBREW_NUMBER_BUFFER_SIZE);
|
|
426 |
// char h_year_1[HEBREW_NUMBER_BUFFER_SIZE + 1];
|
|
427 |
char *h_year_1 = NULL;
|
|
428 |
|
|
429 |
/**************************************************
|
|
430 |
* Print Gregorian month and year
|
|
431 |
**************************************************/
|
|
432 |
printf ("<table width=90%%><tr><td align=left><span class=\"gmonth\">%s <span class=\"gyear\">%d</span></td>\n",
|
|
433 |
hdate_string( HDATE_STRING_GMONTH, header.g_month_1, HDATE_STRING_LONG, HDATE_STRING_LOCAL),
|
|
434 |
header.g_year_1);
|
|
435 |
|
|
436 |
h_year_1 = hdate_string(HDATE_STRING_INT, header.h_year_1, HDATE_STRING_LONG, HDATE_STRING_HEBREW);
|
|
437 |
/**************************************************
|
|
438 |
* Print Hebrew month and year
|
|
439 |
**************************************************/
|
|
440 |
printf ("<td align=right><span class=\"hmonth\">");
|
|
441 |
if (header.h_month_1 != header.h_month_2)
|
|
442 |
{
|
|
443 |
printf ("%s-",
|
|
444 |
hdate_string( HDATE_STRING_HMONTH , header.h_month_1, HDATE_STRING_LONG, HDATE_STRING_LOCAL));
|
|
445 |
}
|
|
446 |
printf ("%s ", hdate_string( HDATE_STRING_HMONTH , header.h_month_2, HDATE_STRING_LONG, HDATE_STRING_LOCAL));
|
|
447 |
printf ("</span>\n");
|
|
448 |
printf ("<span class=\"hyear\">%s</span></td></tr></table>\n", h_year_1);
|
|
449 |
|
|
450 |
printf ("<span class=\"month_table\">\n<table class=main>\n");
|
|
451 |
|
|
452 |
|
|
453 |
if (h_year_1 != NULL) free(h_year_1);
|
|
454 |
}
|
|
455 |
|
|
456 |
|
|
457 |
/**************************************************
|
|
458 |
* HTML - print column headings for days of weeks
|
|
459 |
**************************************************/
|
|
460 |
void print_header_dow_line_html()
|
|
461 |
{
|
|
462 |
int j;
|
|
463 |
|
|
464 |
for (j = 1; j < 8; j++)
|
|
465 |
printf ("<th class=\"week\">%3s</th>",
|
|
466 |
hdate_string( HDATE_STRING_DOW, j, TRUE, FALSE));
|
|
467 |
}
|
|
468 |
|
|
469 |
|
|
470 |
|
|
471 |
/**************************************************
|
|
472 |
* end HTML functions
|
|
473 |
*************************************************/
|
|
474 |
|
|
475 |
|
|
476 |
/*************************************************
|
|
477 |
* Display data in a more pleasing visual manner
|
|
478 |
*************************************************/
|
|
479 |
void colorize_element ( const int element )
|
|
480 |
{
|
|
481 |
switch (element) {
|
|
482 |
case ELEMENT_WEEKDAY_G: printf(CODE_LIGHT_GREY); break;
|
|
483 |
case ELEMENT_WEEKDAY_H: printf(CODE_LIGHT_BROWN); break;
|
|
484 |
case ELEMENT_MONTH_G: printf(CODE_LIGHT_GREY); break;
|
|
485 |
case ELEMENT_MONTH_H: printf(CODE_LIGHT_BROWN); break;
|
|
486 |
case ELEMENT_WEEKDAY_NAMES: printf(CODE_LIGHT_GREEN); break;
|
|
487 |
case ELEMENT_SHABBAT_NAME: printf(CODE_LIGHT_AQUA); break;
|
|
488 |
case ELEMENT_SHABBAT_DAY: printf(CODE_LIGHT_AQUA); break;
|
|
489 |
case ELEMENT_HOLIDAY_DAY: printf(CODE_LIGHT_AQUA); break;
|
|
490 |
case ELEMENT_SHABBAT_TIMES: printf(CODE_LIGHT_PURPLE); break;
|
|
491 |
case ELEMENT_PARASHA: printf(CODE_LIGHT_GREEN); break;
|
|
492 |
case ELEMENT_THIS_SHABBAT_TIMES: printf(CODE_LIGHT_GREEN); break;
|
|
493 |
case ELEMENT_THIS_PARASHA: printf(CODE_LIGHT_GREEN); break;
|
|
494 |
case ELEMENT_HOLIDAY_NAME: printf(CODE_LIGHT_GREY); break;
|
|
495 |
case ELEMENT_TODAY_HOLIDAY_DAY: printf(CODE_LIGHT_GREEN); break;
|
|
496 |
case ELEMENT_TODAY_HOLIDAY_NAME: printf(CODE_LIGHT_GREEN); break;
|
|
497 |
}
|
|
498 |
/* switch (element) {
|
|
499 |
case ELEMENT_WEEKDAY_G: printf(CODE_LIGHT_GREY); break;
|
|
500 |
case ELEMENT_WEEKDAY_H: printf(CODE_LIGHT_AQUA); break;
|
|
501 |
case ELEMENT_MONTH_G: printf(CODE_LIGHT_GREY); break;
|
|
502 |
case ELEMENT_MONTH_H: printf(CODE_LIGHT_AQUA); break;
|
|
503 |
case ELEMENT_WEEKDAY_NAMES: printf(CODE_LIGHT_GREEN); break;
|
|
504 |
case ELEMENT_SHABBAT_NAME: printf(CODE_BOLD_BLUE); break;
|
|
505 |
case ELEMENT_SHABBAT_DAY: printf(CODE_BOLD_BLUE); break;
|
|
506 |
case ELEMENT_HOLIDAY_DAY: printf(CODE_BOLD_BLUE); break;
|
|
507 |
case ELEMENT_SHABBAT_TIMES: printf(CODE_LIGHT_BROWN); break;
|
|
508 |
case ELEMENT_PARASHA: printf(CODE_LIGHT_GREEN); break;
|
|
509 |
case ELEMENT_THIS_SHABBAT_TIMES: printf(CODE_LIGHT_GREEN); break;
|
|
510 |
case ELEMENT_THIS_PARASHA: printf(CODE_LIGHT_GREEN); break;
|
|
511 |
case ELEMENT_HOLIDAY_NAME: printf(CODE_LIGHT_GREY); break;
|
|
512 |
case ELEMENT_TODAY_HOLIDAY_DAY: printf(CODE_LIGHT_GREEN); break;
|
|
513 |
case ELEMENT_TODAY_HOLIDAY_NAME: printf(CODE_LIGHT_GREEN); break;
|
|
514 |
*/
|
|
515 |
}
|
|
516 |
|
|
517 |
|
|
518 |
|
|
519 |
/**************************************************
|
|
520 |
* print header - month line to stdout
|
|
521 |
*************************************************/
|
|
522 |
void print_header_month_line_stdout( const header_info header, const int colorize, const int force_hebrew, const int visual_bidi )
|
|
523 |
{
|
|
524 |
char *g_month, *h1_month, *h2_month;
|
|
525 |
char *h1_year = NULL;
|
|
526 |
char *h2_year = NULL;
|
|
527 |
size_t g_month_len, g_year_len, h1_month_len, h2_month_len, h1_year_len, h2_year_len;
|
|
528 |
|
|
529 |
|
|
530 |
char *hebrew_buffer, *hebrew_buffer_next;
|
|
531 |
size_t hebrew_buffer_len, literals_len;
|
|
532 |
|
|
533 |
int j;
|
|
534 |
size_t padding = 0;
|
|
535 |
|
|
536 |
|
|
537 |
/**************************************************
|
|
538 |
* Print Gregorian month and year
|
|
539 |
*************************************************/
|
|
540 |
g_month = hdate_string( HDATE_STRING_GMONTH, header.g_month_1, HDATE_STRING_LONG, HDATE_STRING_LOCAL);
|
|
541 |
if (colorize) colorize_element(ELEMENT_MONTH_G);
|
|
542 |
printf ("%s %d", g_month, header.g_year_1);
|
|
543 |
if (colorize) printf(CODE_RESTORE_VIDEO);
|
|
544 |
|
|
545 |
/**************************************************
|
|
546 |
* Print Hebrew month and year
|
|
547 |
*
|
|
548 |
* because we want this printed right-justified on
|
|
549 |
* the same line, we need to calculate how many
|
|
550 |
* spaces to pad.
|
|
551 |
*
|
|
552 |
* because of the possible user option --bidi, we
|
|
553 |
* need to buffer the entire Hebrew text in order
|
|
554 |
* reverse its sequence for 'visual' display.
|
|
555 |
*
|
|
556 |
* This all requires collecting the data first
|
|
557 |
* and determining each's length.
|
|
558 |
*************************************************/
|
|
559 |
|
|
560 |
#define CALENDAR_WIDTH 41
|
|
561 |
#define DASH_WIDTH 3 // includes surrounding spaces
|
|
562 |
#define SPACE_WIDTH 1
|
|
563 |
|
|
564 |
|
|
565 |
/*************************************************
|
|
566 |
* padding info for gregorian date
|
|
567 |
*************************************************/
|
|
568 |
g_month_len = strlen(g_month);
|
|
569 |
g_year_len = 4;
|
|
570 |
switch (header.g_year_1)
|
|
571 |
{
|
|
572 |
case 1-9: g_year_len = 1; break;
|
|
573 |
case 10-99: g_year_len = 2; break;
|
|
574 |
case 100-999: g_year_len = 3; break;
|
|
575 |
}
|
|
576 |
|
|
577 |
|
|
578 |
/**************************************************
|
|
579 |
* collect padding info for Hebrew date
|
|
580 |
*************************************************/
|
|
581 |
h1_month = hdate_string( HDATE_STRING_HMONTH , header.h_month_1, HDATE_STRING_LONG, force_hebrew);
|
|
582 |
h1_year = hdate_string( HDATE_STRING_INT, header.h_year_1, HDATE_STRING_SHORT, force_hebrew);
|
|
583 |
//printf("\nh1_month = %s; h1_year = %s, in-year = %d\n",h1_month,h1_year, header.h_year_1);exit(0);
|
|
584 |
|
|
585 |
h1_month_len = strlen(h1_month);
|
|
586 |
h1_year_len = strlen(h1_year);
|
|
587 |
// DEBUG - printf("\nh1 year value = %d, h1 year string = %s, string length = %d\n",header.h_year_1, h1_year, h1_year_len);
|
|
588 |
// DEBUG - int ii; for (ii=0; ii<h1_year_len; ii++) printf("%x ",h1_year[ii]);
|
|
589 |
|
|
590 |
if (header.h_year_1 != header.h_year_2)
|
|
591 |
{
|
|
592 |
|
|
593 |
h2_month = hdate_string( HDATE_STRING_HMONTH , header.h_month_2, HDATE_STRING_LONG, force_hebrew);
|
|
594 |
h2_year = hdate_string(HDATE_STRING_INT, header.h_year_2, HDATE_STRING_LONG,force_hebrew);
|
|
595 |
|
|
596 |
h2_month_len = strlen(h2_month);
|
|
597 |
h2_year_len = strlen(h2_year);
|
|
598 |
literals_len = SPACE_WIDTH + DASH_WIDTH + SPACE_WIDTH;
|
|
599 |
|
|
600 |
hebrew_buffer_len = h1_month_len + h1_year_len + h2_month_len
|
|
601 |
+ h2_year_len + literals_len;
|
|
602 |
|
|
603 |
// printf("\nlength values = %d %d %d %d %d %d\n",h1_month_len , h1_year_len , DASH_WIDTH, h2_month_len, SPACE_WIDTH , h2_year_len);
|
|
604 |
hebrew_buffer = malloc(hebrew_buffer_len+1);
|
|
605 |
hebrew_buffer_next = mempcpy(hebrew_buffer, h1_month, h1_month_len);
|
|
606 |
hebrew_buffer_next = mempcpy(hebrew_buffer_next, " ", SPACE_WIDTH);
|
|
607 |
hebrew_buffer_next = mempcpy(hebrew_buffer_next, h1_year, h1_year_len);
|
|
608 |
hebrew_buffer_next = mempcpy(hebrew_buffer_next, " - ", DASH_WIDTH);
|
|
609 |
hebrew_buffer_next = mempcpy(hebrew_buffer_next, h2_month, h2_month_len);
|
|
610 |
hebrew_buffer_next = mempcpy(hebrew_buffer_next, " ", SPACE_WIDTH);
|
|
611 |
hebrew_buffer_next = mempcpy(hebrew_buffer_next, h2_year, h2_year_len);
|
|
612 |
hebrew_buffer[hebrew_buffer_len]='\0';
|
|
613 |
|
|
614 |
// printf("\nbuffer length = %d\nbuffer contents = %s\n",hebrew_buffer_len, hebrew_buffer); exit(0);
|
|
615 |
// free(hebrew_buffer);
|
|
616 |
}
|
|
617 |
else if (header.h_month_1 != header.h_month_2)
|
|
618 |
{
|
|
619 |
h2_month = hdate_string( HDATE_STRING_HMONTH , header.h_month_2, HDATE_STRING_LONG, force_hebrew);
|
|
620 |
h2_month_len = strlen(h2_month);
|
|
621 |
literals_len = DASH_WIDTH + SPACE_WIDTH;
|
|
622 |
|
|
623 |
hebrew_buffer_len = h1_month_len + h2_month_len + h1_year_len + literals_len;
|
|
624 |
hebrew_buffer = malloc(hebrew_buffer_len+1);
|
|
625 |
hebrew_buffer_next = mempcpy(hebrew_buffer, h1_month, h1_month_len);
|
|
626 |
hebrew_buffer_next = mempcpy(hebrew_buffer_next, " - ", DASH_WIDTH);
|
|
627 |
hebrew_buffer_next = mempcpy(hebrew_buffer_next, h2_month, h2_month_len);
|
|
628 |
hebrew_buffer_next = mempcpy(hebrew_buffer_next, " ", SPACE_WIDTH);
|
|
629 |
hebrew_buffer_next = mempcpy(hebrew_buffer_next, h1_year, h1_year_len);
|
|
630 |
hebrew_buffer[hebrew_buffer_len]='\0';
|
|
631 |
}
|
|
632 |
else
|
|
633 |
{
|
|
634 |
h2_month_len = 0;
|
|
635 |
h2_year_len = 0;
|
|
636 |
literals_len = SPACE_WIDTH;
|
|
637 |
|
|
638 |
hebrew_buffer_len = h1_month_len + h1_year_len + literals_len;
|
|
639 |
|
|
640 |
hebrew_buffer = malloc(hebrew_buffer_len+1);
|
|
641 |
hebrew_buffer_next = mempcpy(hebrew_buffer, h1_month, h1_month_len);
|
|
642 |
hebrew_buffer_next = mempcpy(hebrew_buffer_next, " ", SPACE_WIDTH);
|
|
643 |
hebrew_buffer_next = mempcpy(hebrew_buffer_next, h1_year, h1_year_len);
|
|
644 |
hebrew_buffer[hebrew_buffer_len]='\0';
|
|
645 |
}
|
|
646 |
|
|
647 |
if (!force_hebrew)
|
|
648 |
padding = CALENDAR_WIDTH - g_month_len - g_year_len - hebrew_buffer_len ;
|
|
649 |
else
|
|
650 |
padding = CALENDAR_WIDTH - g_month_len - g_year_len - (hebrew_buffer_len/2) - literals_len +1;
|
|
651 |
|
|
652 |
|
|
653 |
|
|
654 |
/**************************************************
|
|
655 |
* print padding
|
|
656 |
*************************************************/
|
|
657 |
for (j = 1; j < (int)padding; j++) printf(" ");
|
|
658 |
|
|
659 |
|
|
660 |
/**************************************************
|
|
661 |
* Print Hebrew month and year
|
|
662 |
*************************************************/
|
|
663 |
if (colorize) colorize_element(ELEMENT_MONTH_H);
|
|
664 |
if (visual_bidi) revstr(hebrew_buffer, hebrew_buffer_len);
|
|
665 |
printf ("%s", hebrew_buffer);
|
|
666 |
if (colorize) printf(CODE_RESTORE_VIDEO);
|
|
667 |
|
|
668 |
|
|
669 |
/**************************************************
|
|
670 |
* free allocated memory
|
|
671 |
*************************************************/
|
|
672 |
if (h1_year != NULL) free(h1_year);
|
|
673 |
// if (header.h_year_1 != header.h_year_2) free(h2_year);
|
|
674 |
if (h2_year != NULL) free(h2_year);
|
|
675 |
free(hebrew_buffer);
|
|
676 |
}
|
|
677 |
|
|
678 |
|
|
679 |
/**************************************************
|
|
680 |
* print column headings for days of weeks
|
|
681 |
**************************************************/
|
|
682 |
void print_header_dow_line_stdout( const int colorize )
|
|
683 |
{
|
|
684 |
int column;
|
|
685 |
|
|
686 |
void print_dow_column( int column )
|
|
687 |
{
|
|
688 |
if (hdate_is_hebrew_locale())
|
|
689 |
{ /* Hebrew heading is a single charcter per day */
|
|
690 |
printf ("%s%s%s", " ",
|
|
691 |
hdate_string( HDATE_STRING_DOW, column, HDATE_STRING_SHORT, HDATE_STRING_HEBREW),
|
|
692 |
" ");
|
|
693 |
}
|
|
694 |
else
|
|
695 |
{ /* presume three character heading */
|
|
696 |
printf ("%s%3s", " ",
|
|
697 |
hdate_string( HDATE_STRING_DOW, column, HDATE_STRING_SHORT, HDATE_STRING_LOCAL));
|
|
698 |
}
|
|
699 |
|
|
700 |
if (column != 7) printf (" ");
|
|
701 |
}
|
|
702 |
|
|
703 |
if (colorize) colorize_element(ELEMENT_WEEKDAY_NAMES);
|
|
704 |
for (column = 1; column < 7; column++) print_dow_column(column);
|
|
705 |
if (colorize) colorize_element(ELEMENT_SHABBAT_NAME);
|
|
706 |
print_dow_column(7);
|
|
707 |
if (colorize) printf(CODE_RESTORE_VIDEO);
|
|
708 |
}
|
|
709 |
|
|
710 |
|
|
711 |
|
|
712 |
/**************************************************
|
|
713 |
* calculate start/end month/year for a calendar
|
|
714 |
**************************************************/
|
|
715 |
header_info calculate_calendar_start_end (const int month, const int year)
|
|
716 |
{
|
|
717 |
hdate_struct h;
|
|
718 |
header_info header;
|
|
719 |
|
|
720 |
hdate_set_gdate (&h, 1, month, year);
|
|
721 |
header.g_month_1 = h.gd_mon;
|
|
722 |
header.g_year_1 = h.gd_year;
|
|
723 |
header.h_month_1 = h.hd_mon;
|
|
724 |
header.h_year_1 = h.hd_year;
|
|
725 |
|
|
726 |
|
|
727 |
hdate_set_jd ( &h, hdate_gdate_to_jd ( 1, month % 12 + 1, ((month==12) ? year+1 : year) ) - 1 );
|
|
728 |
header.g_month_2 = h.gd_mon;
|
|
729 |
header.g_year_2 = h.gd_year;
|
|
730 |
header.h_month_2 = h.hd_mon;
|
|
731 |
header.h_year_2 = h.hd_year;
|
|
732 |
|
|
733 |
return header;
|
|
734 |
}
|
|
735 |
|
|
736 |
|
|
737 |
/**************************************************
|
|
738 |
* print header - year and month
|
|
739 |
*************************************************/
|
|
740 |
int print_header ( const int month, const int year, const option_list opt)
|
|
741 |
{
|
|
742 |
header_info previous_month, current_month, next_month;
|
|
743 |
|
|
744 |
|
|
745 |
/**********************************************************
|
|
746 |
* Preliminary - set dates for begining and end of calendar
|
|
747 |
**********************************************************/
|
|
748 |
current_month = calculate_calendar_start_end(month, year);
|
|
749 |
if (opt.three_month)
|
|
750 |
{
|
|
751 |
previous_month = calculate_calendar_start_end(
|
|
752 |
(month==1 ? 12 : month-1), (month==1 ? year-1 : year) );
|
|
753 |
next_month = calculate_calendar_start_end(
|
|
754 |
(month==12 ? 1 : month+1), (month==12 ? year+1: year) );
|
|
755 |
}
|
|
756 |
|
|
757 |
/**************************************************
|
|
758 |
* HTML output - month header line
|
|
759 |
*************************************************/
|
|
760 |
if (opt.html) print_header_month_line_html(current_month);
|
|
761 |
|
|
762 |
|
|
763 |
/**************************************************
|
|
764 |
* STDOUT output - month header line
|
|
765 |
*************************************************/
|
|
766 |
else
|
|
767 |
{
|
|
768 |
if (opt.three_month)
|
|
769 |
{
|
|
770 |
print_header_month_line_stdout(previous_month, opt.colorize, opt.force_hebrew, opt.bidi);
|
|
771 |
printf(" ");
|
|
772 |
}
|
|
773 |
|
|
774 |
print_header_month_line_stdout(current_month, opt.colorize, opt.force_hebrew, opt.bidi);
|
|
775 |
|
|
776 |
if (opt.three_month)
|
|
777 |
{
|
|
778 |
printf(" ");
|
|
779 |
print_header_month_line_stdout(next_month, opt.colorize, opt.force_hebrew, opt.bidi);
|
|
780 |
}
|
|
781 |
}
|
|
782 |
|
|
783 |
/**************************************************
|
|
784 |
* terminate line
|
|
785 |
**************************************************/
|
|
786 |
if (opt.html) printf ("</tr>\n");
|
|
787 |
else printf ("\n");
|
|
788 |
|
|
789 |
|
|
790 |
/**************************************************
|
|
791 |
* print column headings for days of weeks
|
|
792 |
**************************************************/
|
|
793 |
if (opt.html) print_header_dow_line_html();
|
|
794 |
else
|
|
795 |
{
|
|
796 |
if (opt.three_month)
|
|
797 |
{
|
|
798 |
print_header_dow_line_stdout(opt.colorize);
|
|
799 |
printf(" ");
|
|
800 |
}
|
|
801 |
print_header_dow_line_stdout(opt.colorize);
|
|
802 |
if (opt.three_month)
|
|
803 |
{
|
|
804 |
printf(" ");
|
|
805 |
print_header_dow_line_stdout(opt.colorize);
|
|
806 |
}
|
|
807 |
}
|
|
808 |
|
|
809 |
/**************************************************
|
|
810 |
* terminate line
|
|
811 |
**************************************************/
|
|
812 |
if (opt.html) printf ("</tr>\n");
|
|
813 |
else printf ("\n");
|
|
814 |
|
|
815 |
return 0;
|
|
816 |
}
|
|
817 |
|
|
818 |
|
|
819 |
/**************************************************
|
|
820 |
* print HTML calendar entry (ie. a single day)
|
|
821 |
*************************************************/
|
|
822 |
void print_day_html ( const hdate_struct h, const int month, const option_list opt)
|
|
823 |
{
|
|
824 |
|
|
825 |
int holiday_type;
|
|
826 |
// char *hd_day;
|
|
827 |
// hd_day = malloc(HEBREW_NUMBER_BUFFER_SIZE);
|
|
828 |
// char hd_day_buffer[HEBREW_NUMBER_BUFFER_SIZE + 1];
|
|
829 |
char *hd_day_str = NULL;
|
|
830 |
|
|
831 |
holiday_type = hdate_get_holyday_type(hdate_get_holyday(&h, opt.diaspora));
|
|
832 |
|
|
833 |
|
|
834 |
if (h.gd_mon != month) printf ("<td class=\"out_of_month\">");
|
|
835 |
else if (h.hd_dw == SHABBAT) printf ("<td class=\"sat\">");
|
|
836 |
else if (holiday_type) printf ("<td class=\"holiday\">");
|
|
837 |
else printf ("<td class=\"regular\">");
|
|
838 |
|
|
839 |
/* Print a day */
|
|
840 |
hd_day_str = hdate_string(HDATE_STRING_INT, h.hd_day, HDATE_STRING_LONG,opt.force_hebrew);
|
|
841 |
printf ("<table class=day><tr class=line1><td class=\"gday\">%2d</td>\n\
|
|
842 |
<td class=\"hday\">%3s %s</td></tr><tr class=line2><td> </td></tr>",
|
|
843 |
h.gd_day,
|
|
844 |
hd_day_str,
|
|
845 |
hdate_string( HDATE_STRING_HMONTH , h.hd_mon, HDATE_STRING_LONG, opt.force_hebrew));
|
|
846 |
if (holiday_type) printf ("<tr class=line3><td class=\"holiday_name\">%s</td></tr>",
|
|
847 |
hdate_string( HDATE_STRING_HOLIDAY,
|
|
848 |
hdate_get_holyday (&h, opt.diaspora),
|
|
849 |
HDATE_STRING_SHORT, HDATE_STRING_LOCAL)
|
|
850 |
);
|
|
851 |
else printf ("<tr class=line3><td class=\"holiday_name\"> </td></tr>");
|
|
852 |
|
|
853 |
printf ("</table></td>\n");
|
|
854 |
|
|
855 |
if (hd_day_str != NULL) free(hd_day_str);
|
|
856 |
}
|
|
857 |
|
|
858 |
|
|
859 |
/*************************************************
|
|
860 |
* print stdout calendar entry (ie. a single day)
|
|
861 |
*************************************************/
|
|
862 |
void print_day ( const hdate_struct h, const int month, const option_list opt)
|
|
863 |
{
|
|
864 |
|
|
865 |
// for forcing Hebrew printing of Hebrew data
|
|
866 |
//char *language;
|
|
867 |
|
|
868 |
// char *hd_day_buffer[HEBREW_NUMBER_BUFFER_SIZE + 1];
|
|
869 |
// hd_day_buffer = malloc(HEBREW_NUMBER_BUFFER_SIZE + 1);
|
|
870 |
char *hd_day_str = NULL;
|
|
871 |
|
|
872 |
size_t hd_day_buffer_str_len;
|
|
873 |
|
|
874 |
int holiday_type;
|
|
875 |
holiday_type = hdate_get_holyday_type(hdate_get_holyday(&h, opt.diaspora));
|
|
876 |
|
|
877 |
/**************************************************
|
|
878 |
* out of month - needs padding
|
|
879 |
*************************************************/
|
|
880 |
if (h.gd_mon != month) printf(" ");
|
|
881 |
|
|
882 |
|
|
883 |
/**************************************************
|
|
884 |
* in month - print the data
|
|
885 |
*************************************************/
|
|
886 |
else
|
|
887 |
{
|
|
888 |
/*************************************************
|
|
889 |
* Gregorian date entry - color prefix
|
|
890 |
*************************************************/
|
|
891 |
if (h.hd_jd == opt.jd_today_g)
|
|
892 |
printf (CODE_REVERSE_VIDEO);
|
|
893 |
else if (opt.colorize)
|
|
894 |
{
|
|
895 |
if (h.hd_dw==7) colorize_element(ELEMENT_SHABBAT_DAY);
|
|
896 |
else if (holiday_type) colorize_element(ELEMENT_HOLIDAY_DAY);
|
|
897 |
else colorize_element(ELEMENT_WEEKDAY_G);
|
|
898 |
}
|
|
899 |
|
|
900 |
/*************************************************
|
|
901 |
* Gregorian date entry - the day of the month
|
|
902 |
*************************************************/
|
|
903 |
// this next line is necessary to align numbers
|
|
904 |
// correctly with bidi (tested using mlterm)
|
|
905 |
if ( (h.gd_day < 10) && (hdate_is_hebrew_locale()) )
|
|
906 |
printf ("%d ", h.gd_day);
|
|
907 |
else printf ("%2d", h.gd_day);
|
|
908 |
|
|
909 |
/*************************************************
|
|
910 |
* Gregorian date entry - color cleanup
|
|
911 |
*************************************************/
|
|
912 |
if ((h.hd_jd == opt.jd_today_g) || (opt.colorize))
|
|
913 |
printf (CODE_RESTORE_VIDEO);
|
|
914 |
|
|
915 |
|
|
916 |
/*************************************************
|
|
917 |
* holiday flag
|
|
918 |
*************************************************/
|
|
919 |
printf ("%c", holiday_flag[holiday_type]);
|
|
920 |
|
|
921 |
|
|
922 |
/*************************************************
|
|
923 |
* Hebrew date entry - color prefix
|
|
924 |
*************************************************/
|
|
925 |
if (h.hd_jd == opt.jd_today_h)
|
|
926 |
printf (CODE_REVERSE_VIDEO);
|
|
927 |
else if (opt.colorize)
|
|
928 |
{
|
|
929 |
if (h.hd_dw==7) colorize_element(ELEMENT_SHABBAT_DAY);
|
|
930 |
else if (holiday_type) colorize_element(ELEMENT_HOLIDAY_DAY);
|
|
931 |
else colorize_element(ELEMENT_WEEKDAY_H);
|
|
932 |
}
|
|
933 |
|
|
934 |
|
|
935 |
/*************************************************
|
|
936 |
* Hebrew date entry - day of the month
|
|
937 |
*************************************************/
|
|
938 |
hd_day_str = hdate_string(HDATE_STRING_INT, h.hd_day,HDATE_STRING_SHORT,opt.force_hebrew);
|
|
939 |
if (opt.bidi)
|
|
940 |
{
|
|
941 |
hd_day_buffer_str_len = (size_t) strlen(hd_day_str);
|
|
942 |
if ( hd_day_buffer_str_len > HEBREW_NUMBER_BUFFER_SIZE)
|
|
943 |
hd_day_buffer_str_len = HEBREW_NUMBER_BUFFER_SIZE - 1;
|
|
944 |
revstr(hd_day_str, hd_day_buffer_str_len);
|
|
945 |
}
|
|
946 |
if ( ( (opt.force_hebrew) || (hdate_is_hebrew_locale()) ) &&
|
|
947 |
( (h.hd_day < 11) || (h.hd_day == 20) || (h.hd_day == 30) ) )
|
|
948 |
{ // need to pad Hebrew dates 1-10, 20, 30
|
|
949 |
printf ("%s%s"," ",hd_day_str);
|
|
950 |
}
|
|
951 |
else printf ("%2s", hd_day_str);
|
|
952 |
|
|
953 |
/*************************************************
|
|
954 |
* Hebrew date entry - color cleanup
|
|
955 |
*************************************************/
|
|
956 |
if ((h.hd_jd == opt.jd_today_h) || (opt.colorize))
|
|
957 |
printf (CODE_RESTORE_VIDEO);
|
|
958 |
|
|
959 |
}
|
|
960 |
|
|
961 |
if (hd_day_str != NULL) free(hd_day_str);
|
|
962 |
}
|
|
963 |
|
|
964 |
|
|
965 |
/*************************************************
|
|
966 |
* print a calendar week's entry (ie. seven columns)
|
|
967 |
*************************************************/
|
|
968 |
void print_week( int jd, const int month, const option_list opt)
|
|
969 |
{
|
|
970 |
#define long_parasha_name 0
|
|
971 |
|
|
972 |
hdate_struct h;
|
|
973 |
|
|
974 |
int calendar_column;
|
|
975 |
|
|
976 |
// for opt.shabbat
|
|
977 |
int sun_hour, first_light, talit, sunrise;
|
|
978 |
int midday, sunset, first_stars, three_stars;
|
|
979 |
int this_week;
|
|
980 |
hdate_struct yom_shishi;
|
|
981 |
|
|
982 |
// for opt.parasha
|
|
983 |
int shabbat_name;
|
|
984 |
char *shabbat_name_str, *shabbat_name_buffer;
|
|
985 |
size_t shabbat_name_str_len;
|
|
986 |
|
|
987 |
|
|
988 |
// for forcing Hebrew printing of Hebrew data
|
|
989 |
//char *language;
|
|
990 |
|
|
991 |
|
|
992 |
/**************************************************
|
|
993 |
* for each column of calendar
|
|
994 |
*************************************************/
|
|
995 |
for (calendar_column = 0; calendar_column < 7; calendar_column++)
|
|
996 |
{
|
|
997 |
|
|
998 |
/**************************************************
|
|
999 |
* Get this day's information
|
|
1000 |
*************************************************/
|
|
1001 |
hdate_set_jd (&h, jd);
|
|
1002 |
if ( ((opt.shabbat) || (opt.parasha)) && (calendar_column == 5) )
|
|
1003 |
yom_shishi = h;
|
|
1004 |
|
|
1005 |
|
|
1006 |
/**************************************************
|
|
1007 |
* HTML calendar option
|
|
1008 |
*************************************************/
|
|
1009 |
if (opt.html) print_day_html ( h, month, opt );
|
|
1010 |
|
|
1011 |
|
|
1012 |
|
|
1013 |
/**************************************************
|
|
1014 |
* non-HTML calendar option
|
|
1015 |
*************************************************/
|
|
1016 |
else print_day ( h, month, opt);
|
|
1017 |
|
|
1018 |
|
|
1019 |
/**************************************************
|
|
1020 |
* space between days of week
|
|
1021 |
*************************************************/
|
|
1022 |
if (calendar_column != 6) printf (" ");
|
|
1023 |
|
|
1024 |
/**************************************************
|
|
1025 |
* advance to next day of week
|
|
1026 |
*************************************************/
|
|
1027 |
jd++;
|
|
1028 |
}
|
|
1029 |
|
|
1030 |
/**************************************************
|
|
1031 |
* print end of calendar line
|
|
1032 |
*************************************************/
|
|
1033 |
if ((!opt.html) && ( (h.gd_mon == month) || (h.gd_day < SHABBAT) ) )
|
|
1034 |
{
|
|
1035 |
|
|
1036 |
/********************************************************
|
|
1037 |
* determine whether this line gets special highlighting
|
|
1038 |
********************************************************/
|
|
1039 |
if ((opt.colorize)
|
|
1040 |
&& ((opt.shabbat) || (opt.parasha))
|
|
1041 |
&& ((jd - 1) > opt.jd_today_h)
|
|
1042 |
&& (((jd - 1) - opt.jd_today_h) < 7) )
|
|
1043 |
this_week = TRUE;
|
|
1044 |
else this_week = FALSE;
|
|
1045 |
|
|
1046 |
/*************************************************
|
|
1047 |
* print shabbat times
|
|
1048 |
*************************************************/
|
|
1049 |
if (opt.shabbat)
|
|
1050 |
{
|
|
1051 |
// candlelighting times
|
|
1052 |
/// note: compiler incorrectly issued warnings:
|
|
1053 |
/// "may be used uninitialized in this function [-Wmaybe-uninitialized]"
|
|
1054 |
/// The initialization occurs above (~line 1005) "yom_shishi = h"
|
|
1055 |
hdate_get_utc_sun_time (yom_shishi.gd_day, yom_shishi.gd_mon, yom_shishi.gd_year,
|
|
1056 |
opt.lat, opt.lon, &sunrise, &sunset);
|
|
1057 |
|
|
1058 |
// FIXME - allow for further minhag variation
|
|
1059 |
if (opt.candles != 1) sunset = sunset - opt.candles + opt.tz;
|
|
1060 |
else sunset = sunset + opt.tz - DEFAULT_CANDLES_MINUTES;
|
|
1061 |
|
|
1062 |
if (opt.colorize)
|
|
1063 |
{
|
|
1064 |
if (this_week) colorize_element(ELEMENT_THIS_SHABBAT_TIMES);
|
|
1065 |
else colorize_element(ELEMENT_SHABBAT_TIMES);
|
|
1066 |
}
|
|
1067 |
printf (" %02d:%02d", sunset / 60, sunset % 60);
|
|
1068 |
if (opt.colorize) printf (CODE_RESTORE_VIDEO);
|
|
1069 |
|
|
1070 |
printf(" - ");
|
|
1071 |
|
|
1072 |
// motzay shabat time
|
|
1073 |
hdate_get_utc_sun_time_full (h.gd_day, h.gd_mon, h.gd_year, opt.lat,
|
|
1074 |
opt.lon, &sun_hour, &first_light, &talit,
|
|
1075 |
&sunrise, &midday, &sunset,
|
|
1076 |
&first_stars, &three_stars);
|
|
1077 |
|
|
1078 |
// FIXME - allow for further minhag variation
|
|
1079 |
if (opt.havdalah != 1) three_stars = sunset + opt.havdalah + opt.tz;
|
|
1080 |
else three_stars = three_stars + opt.tz;
|
|
1081 |
|
|
1082 |
if (opt.colorize)
|
|
1083 |
{
|
|
1084 |
if (this_week) colorize_element(ELEMENT_THIS_SHABBAT_TIMES);
|
|
1085 |
else colorize_element(ELEMENT_SHABBAT_TIMES);
|
|
1086 |
}
|
|
1087 |
printf ("%02d:%02d", three_stars / 60, three_stars % 60);
|
|
1088 |
if (opt.colorize) printf (CODE_RESTORE_VIDEO);
|
|
1089 |
}
|
|
1090 |
|
|
1091 |
|
|
1092 |
/*************************************************
|
|
1093 |
* print shabbat name
|
|
1094 |
*************************************************/
|
|
1095 |
if (opt.parasha)
|
|
1096 |
{
|
|
1097 |
|
|
1098 |
/*************************************************
|
|
1099 |
* print shabbat name - force-hebrew setup
|
|
1100 |
*************************************************/
|
|
1101 |
// BUG - this isn't thread-safe
|
|
1102 |
/*if (opt.force_hebrew)
|
|
1103 |
{
|
|
1104 |
language=getenv("LANGUAGE");
|
|
1105 |
setenv("LANGUAGE", "he_IL.UTF-8", 1);
|
|
1106 |
}*/
|
|
1107 |
|
|
1108 |
|
|
1109 |
shabbat_name = hdate_get_parasha (&h, opt.diaspora);
|
|
1110 |
if (shabbat_name) shabbat_name_str =
|
|
1111 |
hdate_string( HDATE_STRING_PARASHA, shabbat_name,
|
|
1112 |
HDATE_STRING_SHORT, opt.force_hebrew);
|
|
1113 |
else
|
|
1114 |
{
|
|
1115 |
shabbat_name = hdate_get_holyday(&h, opt.diaspora);
|
|
1116 |
if (shabbat_name) shabbat_name_str =
|
|
1117 |
hdate_string( HDATE_STRING_HOLIDAY,
|
|
1118 |
shabbat_name,
|
|
1119 |
HDATE_STRING_SHORT, opt.force_hebrew);
|
|
1120 |
}
|
|
1121 |
if (shabbat_name)
|
|
1122 |
{
|
|
1123 |
if (opt.colorize)
|
|
1124 |
{
|
|
1125 |
if (this_week) colorize_element(ELEMENT_THIS_PARASHA);
|
|
1126 |
else colorize_element(ELEMENT_PARASHA);
|
|
1127 |
}
|
|
1128 |
if (opt.bidi)
|
|
1129 |
{
|
|
1130 |
shabbat_name_str_len = strlen(shabbat_name_str);
|
|
1131 |
shabbat_name_buffer = malloc(shabbat_name_str_len+1);
|
|
1132 |
memcpy(shabbat_name_buffer, shabbat_name_str, shabbat_name_str_len);
|
|
1133 |
shabbat_name_buffer[shabbat_name_str_len] = '\0';
|
|
1134 |
revstr(shabbat_name_buffer, shabbat_name_str_len);
|
|
1135 |
|
|
1136 |
// padding - FIXME - spaces are single-byte, while
|
|
1137 |
// the Hebrew characters are two bytes
|
|
1138 |
const int margin_max = 15;
|
|
1139 |
printf("%*s%s", (int)(margin_max - shabbat_name_str_len/2)," ", shabbat_name_buffer);
|
|
1140 |
|
|
1141 |
free(shabbat_name_buffer);
|
|
1142 |
}
|
|
1143 |
else printf(" %s", shabbat_name_str);
|
|
1144 |
//if (opt.force_hebrew) setenv("LANGUAGE", language, 1);
|
|
1145 |
if (opt.colorize) printf (CODE_RESTORE_VIDEO);
|
|
1146 |
}
|
|
1147 |
}
|
|
1148 |
}
|
|
1149 |
}
|
|
1150 |
|
|
1151 |
|
|
1152 |
|
|
1153 |
|
|
1154 |
/**************************************************
|
|
1155 |
* print month table
|
|
1156 |
*************************************************/
|
|
1157 |
int print_calendar ( const int current_month, const int current_year, const option_list opt)
|
|
1158 |
{
|
|
1159 |
hdate_struct h;
|
|
1160 |
int calendar_line;
|
|
1161 |
int max_calendar_lines = 4;
|
|
1162 |
/// the initializations on next line aren't truly necessary, but they do
|
|
1163 |
/// suppress warning "may be used uninitialized in this function [-Wmaybe-uninitialized]"
|
|
1164 |
int previous_month = 1, next_month = 1;
|
|
1165 |
int previous_year, next_year;
|
|
1166 |
/// the initializations on next line aren't truly necessary, but they do
|
|
1167 |
/// suppress warning "may be used uninitialized in this function [-Wmaybe-uninitialized]"
|
|
1168 |
int jd_current_month, jd_previous_month = 1, jd_next_month = 1;
|
|
1169 |
|
|
1170 |
void how_many_calendar_lines( int month, int start_dow )
|
|
1171 |
{
|
|
1172 |
switch (month)
|
|
1173 |
{
|
|
1174 |
case 4:
|
|
1175 |
case 6:
|
|
1176 |
case 9:
|
|
1177 |
case 11: if (start_dow == 7) max_calendar_lines = 6;
|
|
1178 |
else if (max_calendar_lines == 4) max_calendar_lines = 5;
|
|
1179 |
break;
|
|
1180 |
case 1:
|
|
1181 |
case 3:
|
|
1182 |
case 5:
|
|
1183 |
case 7:
|
|
1184 |
case 8:
|
|
1185 |
case 10:
|
|
1186 |
case 12: if (start_dow > 5) max_calendar_lines = 6;
|
|
1187 |
else if (max_calendar_lines == 4) max_calendar_lines = 5;
|
|
1188 |
break;
|
|
1189 |
case 2: if (start_dow > 1 && max_calendar_lines == 4) max_calendar_lines = 5;
|
|
1190 |
break;
|
|
1191 |
}
|
|
1192 |
}
|
|
1193 |
|
|
1194 |
/*********************************************************
|
|
1195 |
* Preliminaries:
|
|
1196 |
* - Find the first sunday(s) of each calendar
|
|
1197 |
* - Find number of calendar lines
|
|
1198 |
*********************************************************/
|
|
1199 |
hdate_set_gdate (&h, 1, current_month, current_year);
|
|
1200 |
jd_current_month = h.hd_jd - h.hd_dw + 1;
|
|
1201 |
how_many_calendar_lines( h.gd_mon, h.hd_dw );
|
|
1202 |
|
|
1203 |
/*********************************************************
|
|
1204 |
* three months, side-by-side
|
|
1205 |
*********************************************************/
|
|
1206 |
if (opt.three_month)
|
|
1207 |
{
|
|
1208 |
/*********************************************************
|
|
1209 |
* previous month
|
|
1210 |
*********************************************************/
|
|
1211 |
if (current_month == 1)
|
|
1212 |
{
|
|
1213 |
previous_month = 12;
|
|
1214 |
previous_year = current_year - 1;
|
|
1215 |
}
|
|
1216 |
else
|
|
1217 |
{
|
|
1218 |
previous_month = current_month - 1;
|
|
1219 |
previous_year = current_year;
|
|
1220 |
}
|
|
1221 |
hdate_set_gdate (&h, 1, previous_month, previous_year);
|
|
1222 |
jd_previous_month = h.hd_jd - h.hd_dw + 1;
|
|
1223 |
how_many_calendar_lines( h.gd_mon, h.hd_dw );
|
|
1224 |
|
|
1225 |
/*********************************************************
|
|
1226 |
* next month
|
|
1227 |
*********************************************************/
|
|
1228 |
if (current_month == 12)
|
|
1229 |
{
|
|
1230 |
next_month = 1;
|
|
1231 |
next_year = current_year + 1;
|
|
1232 |
}
|
|
1233 |
else
|
|
1234 |
{
|
|
1235 |
next_month = current_month + 1;
|
|
1236 |
next_year = current_year;
|
|
1237 |
}
|
|
1238 |
hdate_set_gdate (&h, 1, next_month, next_year);
|
|
1239 |
jd_next_month = h.hd_jd - h.hd_dw + 1;
|
|
1240 |
how_many_calendar_lines( h.gd_mon, h.hd_dw );
|
|
1241 |
}
|
|
1242 |
|
|
1243 |
|
|
1244 |
|
|
1245 |
/**************************************************
|
|
1246 |
* maximum six lines of calendar
|
|
1247 |
**************************************************/
|
|
1248 |
for (calendar_line = 0; calendar_line < max_calendar_lines; calendar_line++)
|
|
1249 |
{
|
|
1250 |
if (opt.html) printf ("<tr>\n");
|
|
1251 |
|
|
1252 |
if (opt.three_month)
|
|
1253 |
{
|
|
1254 |
print_week(jd_previous_month, previous_month, opt);
|
|
1255 |
jd_previous_month = jd_previous_month + 7;
|
|
1256 |
printf(" ");
|
|
1257 |
}
|
|
1258 |
|
|
1259 |
print_week(jd_current_month, current_month, opt);
|
|
1260 |
jd_current_month = jd_current_month + 7;
|
|
1261 |
|
|
1262 |
|
|
1263 |
if (opt.three_month)
|
|
1264 |
{
|
|
1265 |
printf(" ");
|
|
1266 |
print_week(jd_next_month, next_month, opt);
|
|
1267 |
jd_next_month = jd_next_month + 7;
|
|
1268 |
}
|
|
1269 |
|
|
1270 |
if (opt.html) printf ("</tr>\n");
|
|
1271 |
else printf ("\n");
|
|
1272 |
}
|
|
1273 |
|
|
1274 |
|
|
1275 |
/**************************************************
|
|
1276 |
* print end of calendar
|
|
1277 |
*************************************************/
|
|
1278 |
if (opt.html) printf ("</table>\n</span>");
|
|
1279 |
|
|
1280 |
return 0;
|
|
1281 |
}
|
|
1282 |
|
|
1283 |
|
|
1284 |
|
|
1285 |
|
|
1286 |
|
|
1287 |
|
|
1288 |
/****************************************************
|
|
1289 |
* print month header, month table, month footnotes
|
|
1290 |
****************************************************/
|
|
1291 |
int print_month ( const int month, const int year, const option_list opt)
|
|
1292 |
{
|
|
1293 |
hdate_struct h;
|
|
1294 |
|
|
1295 |
// following are for opt.footnote
|
|
1296 |
int jd_counter, holiday;
|
|
1297 |
//char *language; // for forcing Hebrew printing of footnote
|
|
1298 |
|
|
1299 |
|
|
1300 |
/* check if hebrew year (year > 3000) */
|
|
1301 |
if (year > 3000) hdate_set_hdate (&h, 1, month, year);
|
|
1302 |
else hdate_set_gdate (&h, 1, month, year);
|
|
1303 |
|
|
1304 |
|
|
1305 |
print_header (h.gd_mon, h.gd_year, opt);
|
|
1306 |
print_calendar (h.gd_mon, h.gd_year, opt);
|
|
1307 |
printf("\n");
|
|
1308 |
|
|
1309 |
|
|
1310 |
/****************************************************
|
|
1311 |
* print footnotes
|
|
1312 |
****************************************************/
|
|
1313 |
if (opt.footnote)
|
|
1314 |
{
|
|
1315 |
jd_counter = h.hd_jd;
|
|
1316 |
while ( month == h.gd_mon )
|
|
1317 |
{
|
|
1318 |
holiday = hdate_get_holyday(&h, opt.diaspora);
|
|
1319 |
if (holiday)
|
|
1320 |
{
|
|
1321 |
print_day ( h, month, opt);
|
|
1322 |
/*if (opt.force_hebrew)
|
|
1323 |
{
|
|
1324 |
// BUG - this isn't thread-safe
|
|
1325 |
// --- and it may no longer be nexessary anywhere
|
|
1326 |
// in the code now that I've embedded Hebrew
|
|
1327 |
language=getenv("LANGUAGE");
|
|
1328 |
setenv("LANGUAGE", "he_IL.UTF-8", 1);
|
|
1329 |
}*/
|
|
1330 |
if (opt.colorize)
|
|
1331 |
{
|
|
1332 |
if (opt.jd_today_h == h.hd_jd) colorize_element(ELEMENT_TODAY_HOLIDAY_NAME);
|
|
1333 |
else colorize_element(ELEMENT_HOLIDAY_NAME);
|
|
1334 |
}
|
|
1335 |
|
|
1336 |
if (opt.bidi)
|
|
1337 |
{
|
|
1338 |
char *holiday_str, *holiday_buffer;
|
|
1339 |
size_t holiday_str_len;
|
|
1340 |
holiday_str = hdate_string( HDATE_STRING_HOLIDAY,
|
|
1341 |
holiday,
|
|
1342 |
HDATE_STRING_LONG,
|
|
1343 |
opt.force_hebrew);
|
|
1344 |
|
|
1345 |
holiday_str_len = strlen(holiday_str);
|
|
1346 |
holiday_buffer = malloc(holiday_str_len+1);
|
|
1347 |
memcpy(holiday_buffer, holiday_str, holiday_str_len);
|
|
1348 |
holiday_buffer[holiday_str_len] = '\0';
|
|
1349 |
revstr(holiday_buffer, holiday_str_len);
|
|
1350 |
|
|
1351 |
// padding - FIXME - spaces are single-byte, while
|
|
1352 |
// the Hebrew characters are two bytes
|
|
1353 |
const int margin_max = 16; // 15 fails because of jabotinsky in july
|
|
1354 |
printf("%*s%s\n", (int)(margin_max - holiday_str_len/2)," ", holiday_buffer);
|
|
1355 |
|
|
1356 |
free(holiday_buffer);
|
|
1357 |
}
|
|
1358 |
else printf (" %s\n",
|
|
1359 |
hdate_string( HDATE_STRING_HOLIDAY,
|
|
1360 |
holiday,
|
|
1361 |
HDATE_STRING_LONG,
|
|
1362 |
opt.force_hebrew));
|
|
1363 |
|
|
1364 |
if (opt.colorize) printf (CODE_RESTORE_VIDEO);
|
|
1365 |
//if (opt.force_hebrew) setenv("LANGUAGE", language, 1);
|
|
1366 |
}
|
|
1367 |
jd_counter++;
|
|
1368 |
hdate_set_jd (&h, jd_counter);
|
|
1369 |
}
|
|
1370 |
}
|
|
1371 |
return 0;
|
|
1372 |
}
|
|
1373 |
|
|
1374 |
|
|
1375 |
/****************************************************
|
|
1376 |
* read and parse config file
|
|
1377 |
****************************************************/
|
|
1378 |
void read_config_file( FILE *config_file,
|
|
1379 |
option_list *opt,
|
|
1380 |
double* latitude,
|
|
1381 |
int* opt_latitude,
|
|
1382 |
double* longitude,
|
|
1383 |
int* opt_longitude,
|
|
1384 |
int* tz )
|
|
1385 |
|
|
1386 |
{
|
|
1387 |
char *input_string;
|
|
1388 |
size_t input_str_len = 100; // WARNING: if you change this value
|
|
1389 |
// you will still have to also
|
|
1390 |
// change a matching value below
|
|
1391 |
// in the statement that includes:
|
|
1392 |
// match_count = sscanf(input_string
|
|
1393 |
char *input_key = "";
|
|
1394 |
char *input_value = "";
|
|
1395 |
int line_count = 0;
|
|
1396 |
int menu_item = 0;
|
|
1397 |
size_t menu_len = 0;
|
|
1398 |
int match_count;
|
|
1399 |
int end_of_input_file = FALSE;
|
|
1400 |
int i;
|
|
1401 |
const int num_of_keys = 20;
|
|
1402 |
const char* key_list[] = { "SUNSET_AWARE", // 0
|
|
1403 |
"LATITUDE",
|
|
1404 |
"LONGITUDE", // 2
|
|
1405 |
"TIMEZONE",
|
|
1406 |
"DIASPORA", // 4
|
|
1407 |
"FORCE_ISRAEL",
|
|
1408 |
"PARASHA_NAMES", // 6
|
|
1409 |
"SHABBAT_INFO",
|
|
1410 |
"FOOTNOTES", // 8
|
|
1411 |
"FORCE_HEBREW",
|
|
1412 |
"OUTPUT_BIDI", //10
|
|
1413 |
"SUPPRESS_REVERSE_VIDEO",
|
|
1414 |
"COLORIZE", //12
|
|
1415 |
"OUTPUT_HTML",
|
|
1416 |
"USE_EXTERNAL_CSS_FILE",
|
|
1417 |
"QUIET_ALERTS",
|
|
1418 |
"THREE_MONTH", //16
|
|
1419 |
"MENU",
|
|
1420 |
"CANDLE_LIGHTING", //18
|
|
1421 |
"HAVDALAH"
|
|
1422 |
};
|
|
1423 |
|
|
1424 |
input_string = malloc(input_str_len+1);
|
|
1425 |
input_key = malloc(input_str_len+1);
|
|
1426 |
input_value = malloc(input_str_len+1);
|
|
1427 |
while ( end_of_input_file!=TRUE )
|
|
1428 |
{
|
|
1429 |
end_of_input_file = getline(&input_string, &input_str_len, config_file);
|
|
1430 |
if ( end_of_input_file!=TRUE )
|
|
1431 |
{
|
|
1432 |
errno = 0;
|
|
1433 |
// The '100' in the next statement is inelegant; it is meant to
|
|
1434 |
// be the value of input_str_len. Alternatively, don't malloc
|
|
1435 |
// input_value above, use the 'a' specifier here, and free(input_value)
|
|
1436 |
// at the end of every successful read and evaluation
|
|
1437 |
match_count = sscanf(input_string,"%[A-Z_]=%100[^\n]",input_key,input_value);
|
|
1438 |
line_count++;
|
|
1439 |
if (errno != 0) error(0,errno,"scan error at line %d", line_count);
|
|
1440 |
// DEBUG - printf("line number = %d, matches made = %d, key = %s, value = %s, string = %s",
|
|
1441 |
// line_count, match_count, input_key, input_value, input_string);
|
|
1442 |
if (match_count ==2)
|
|
1443 |
{
|
|
1444 |
for (i=0; i<num_of_keys; i++)
|
|
1445 |
{
|
|
1446 |
if (strcmp(input_key, key_list[i]) == 0)
|
|
1447 |
{
|
|
1448 |
// DEBUG - printf("match found!, %s = %s, index = %d\n",input_key,key_list[i],i);
|
|
1449 |
switch(i)
|
|
1450 |
{
|
|
1451 |
|
|
1452 |
case 0:if (strcmp(input_value,"FALSE") == 0) opt->not_sunset_aware = 1;
|
|
1453 |
else if (strcmp(input_value,"TRUE") == 0) opt->not_sunset_aware = 0;
|
|
1454 |
break;
|
|
1455 |
case 1:
|
|
1456 |
parse_coordinate(1, input_value, latitude, opt_latitude);
|
|
1457 |
break;
|
|
1458 |
case 2:
|
|
1459 |
parse_coordinate(2, input_value, longitude, opt_longitude);
|
|
1460 |
break;
|
|
1461 |
case 3:
|
|
1462 |
parse_timezone(input_value, tz);
|
|
1463 |
break;
|
|
1464 |
case 4:if (strcmp(input_value,"FALSE") == 0) opt->diaspora = 0;
|
|
1465 |
else if (strcmp(input_value,"TRUE") == 0) opt->diaspora = 1;
|
|
1466 |
break;
|
|
1467 |
case 5:if (strcmp(input_value,"FALSE") == 0) opt->force_israel = 0;
|
|
1468 |
else if (strcmp(input_value,"TRUE") == 0) opt->force_israel = 1;
|
|
1469 |
break;
|
|
1470 |
case 6:if (strcmp(input_value,"FALSE") == 0) opt->parasha = 0;
|
|
1471 |
else if (strcmp(input_value,"TRUE") == 0) opt->parasha = 1;
|
|
1472 |
break;
|
|
1473 |
case 7:if (strcmp(input_value,"FALSE") == 0) opt->shabbat = 0;
|
|
1474 |
else if (strcmp(input_value,"TRUE") == 0)
|
|
1475 |
{
|
|
1476 |
opt->shabbat = 1;
|
|
1477 |
opt->parasha = 1;
|
|
1478 |
}
|
|
1479 |
break;
|
|
1480 |
case 8:if (strcmp(input_value,"FALSE") == 0) opt->footnote = 0;
|
|
1481 |
else if (strcmp(input_value,"TRUE") == 0) opt->footnote = 1;
|
|
1482 |
break;
|
|
1483 |
case 9:if (strcmp(input_value,"FALSE") == 0) opt->force_hebrew = 0;
|
|
1484 |
else if (strcmp(input_value,"TRUE") == 0) opt->force_hebrew = 1;
|
|
1485 |
break;
|
|
1486 |
case 10:if (strcmp(input_value,"FALSE") == 0) opt->bidi = 0;
|
|
1487 |
else if (strcmp(input_value,"TRUE") == 0)
|
|
1488 |
{
|
|
1489 |
opt->bidi = 1;
|
|
1490 |
opt->force_hebrew = 1;
|
|
1491 |
}
|
|
1492 |
break;
|
|
1493 |
case 11:if (strcmp(input_value,"FALSE") == 0) opt->no_reverse = 0;
|
|
1494 |
else if (strcmp(input_value,"TRUE") == 0) opt->no_reverse = 1;
|
|
1495 |
break;
|
|
1496 |
case 12:if (strcmp(input_value,"FALSE") == 0) opt->colorize = 0;
|
|
1497 |
else if (strcmp(input_value,"TRUE") == 0) opt->colorize = 1;
|
|
1498 |
break;
|
|
1499 |
case 13:if (strcmp(input_value,"FALSE") == 0) opt->html = 0;
|
|
1500 |
else if (strcmp(input_value,"TRUE") == 0) opt->html = 1;
|
|
1501 |
break;
|
|
1502 |
case 14:if (strcmp(input_value,"FALSE") == 0) opt->external_css = 0;
|
|
1503 |
else if (strcmp(input_value,"TRUE") == 0) opt->external_css = 1;
|
|
1504 |
break;
|
|
1505 |
case 15:if (strcmp(input_value,"FALSE") == 0) opt->quiet_alerts = 0;
|
|
1506 |
else if (strcmp(input_value,"TRUE") == 0) opt->quiet_alerts = 1;
|
|
1507 |
break;
|
|
1508 |
case 16:if (strcmp(input_value,"FALSE") == 0) opt->three_month = 0;
|
|
1509 |
else if (strcmp(input_value,"TRUE") == 0) opt->three_month = 1;
|
|
1510 |
break;
|
|
1511 |
|
|
1512 |
// MENU
|
|
1513 |
case 17:if (menu_item < MAX_MENU_ITEMS)
|
|
1514 |
{
|
|
1515 |
menu_len = strlen(input_value);
|
|
1516 |
opt->menu_item[menu_item] = malloc(menu_len+1);
|
|
1517 |
memcpy(opt->menu_item[menu_item], input_value,menu_len);
|
|
1518 |
menu_item++;
|
|
1519 |
}
|
|
1520 |
break;
|
|
1521 |
// CANDLE_LIGHTING
|
|
1522 |
case 18:if (strcmp(input_value,"FALSE") == 0) opt->candles = 0;
|
|
1523 |
else if (strcmp(input_value,"TRUE") == 0) opt->candles = 1;
|
|
1524 |
else if (fnmatch( "[[:digit:]]?([[:digit:]])", input_value, FNM_EXTMATCH) == 0)
|
|
1525 |
{
|
|
1526 |
opt->candles = atoi(input_value);
|
|
1527 |
if (opt->candles < MIN_CANDLES_MINUTES) opt->candles = MIN_CANDLES_MINUTES;
|
|
1528 |
else if (opt->candles > MAX_CANDLES_MINUTES) opt->candles = MAX_CANDLES_MINUTES;
|
|
1529 |
}
|
|
1530 |
break;
|
|
1531 |
|
|
1532 |
// HAVDALAH
|
|
1533 |
case 19:if (strcmp(input_value,"FALSE") == 0) opt->havdalah = 0;
|
|
1534 |
else if (strcmp(input_value,"TRUE") == 0) opt->havdalah = 1;
|
|
1535 |
else if (fnmatch( "[[:digit:]]?([[:digit:]])", input_value, FNM_EXTMATCH) == 0)
|
|
1536 |
{
|
|
1537 |
opt->havdalah = atoi(input_value);
|
|
1538 |
if (opt->havdalah < MIN_MOTZASH_MINUTES) opt->havdalah = MIN_MOTZASH_MINUTES;
|
|
1539 |
else if (opt->havdalah > MAX_MOTZASH_MINUTES) opt->havdalah = MAX_MOTZASH_MINUTES;
|
|
1540 |
}
|
|
1541 |
break;
|
|
1542 |
|
|
1543 |
} // end of switch(i)
|
|
1544 |
break; // if found a match don't continue for loop
|
|
1545 |
}
|
|
1546 |
}
|
|
1547 |
}
|
|
1548 |
}
|
|
1549 |
}
|
|
1550 |
free(input_string);
|
|
1551 |
free(input_key);
|
|
1552 |
free(input_value);
|
|
1553 |
return;
|
|
1554 |
}
|
|
1555 |
|
|
1556 |
|
|
1557 |
/****************************************************
|
|
1558 |
* exit elegantly
|
|
1559 |
****************************************************/
|
|
1560 |
void exit_main( option_list *opt, const int exit_code)
|
|
1561 |
{
|
|
1562 |
int i;
|
|
1563 |
for (i=0; i<MAX_MENU_ITEMS; i++)
|
|
1564 |
{
|
|
1565 |
if (opt->menu_item[i] == NULL) break;
|
|
1566 |
free(opt->menu_item[i]);
|
|
1567 |
}
|
|
1568 |
exit (exit_code);
|
|
1569 |
}
|
|
1570 |
|
|
1571 |
|
|
1572 |
/****************************************************
|
|
1573 |
* parse a command-line or a config-file menu line
|
|
1574 |
*
|
|
1575 |
* It was appropriate to make this a function, outside
|
|
1576 |
* of main, because of its dual use and dual reference
|
|
1577 |
****************************************************/
|
|
1578 |
int hcal_parser( const int switch_arg, option_list *opt,
|
|
1579 |
double *lat, int *opt_latitude,
|
|
1580 |
double *lon, int *opt_Longitude,
|
|
1581 |
int *tz, int long_option_index)
|
|
1582 |
|
|
1583 |
{
|
|
1584 |
int error_detected = 0;
|
|
1585 |
|
|
1586 |
switch (switch_arg)
|
|
1587 |
{
|
|
1588 |
|
|
1589 |
case 0: /* long options */
|
|
1590 |
switch (long_option_index)
|
|
1591 |
{
|
|
1592 |
/* --version */ case 0: print_version (); exit_main(opt, 0); break;
|
|
1593 |
/* --help */ case 1: print_help (); exit_main(opt, 0); break;
|
|
1594 |
/* --no-reverse */ case 2: opt->no_reverse = 1; break;
|
|
1595 |
/* --html */ case 3: break;
|
|
1596 |
/* --parasha */ case 4: break;
|
|
1597 |
/* --shabbat */ case 5: break;
|
|
1598 |
/* --three-month*/ case 6: break;
|
|
1599 |
/* --colorize */ case 7: break;
|
|
1600 |
/* --footnote */ case 8: break;
|
|
1601 |
/* --hebrew */ case 9: break;
|
|
1602 |
/* --israel */ case 10:break;
|
|
1603 |
/* --latitude */ case 11:break;
|
|
1604 |
/* --longitude */ case 12:break;
|
|
1605 |
/* --timezone */ case 13:break;
|
|
1606 |
/* --not-sunset-aware */ case 14: opt->not_sunset_aware = 1; break;
|
|
1607 |
/* --quiet-alerts*/ case 15: break;
|
|
1608 |
/* --visual */ case 16:
|
|
1609 |
/* --bidi */ case 17: break;
|
|
1610 |
/* --one-month */ case 18: break;
|
|
1611 |
/* --no-visual */ case 19:
|
|
1612 |
/* --no-bidi */ case 20: opt->bidi = 0; opt->force_hebrew = 0; break;
|
|
1613 |
/* --no-color */ case 21: opt->colorize = 0; break;
|
|
1614 |
/* --no-footnote*/ case 22: opt->footnote = 0; break;
|
|
1615 |
/* --menu */ case 23: break;
|
|
1616 |
/* --candles */ case 24:
|
|
1617 |
if ( (optarg == NULL) && (opt->candles == 0) )opt->candles = 1;
|
|
1618 |
else
|
|
1619 |
{
|
|
1620 |
if (fnmatch( "[[:digit:]]?([[:digit:]])", optarg, FNM_EXTMATCH) == 0)
|
|
1621 |
{
|
|
1622 |
opt->candles = atoi(optarg);
|
|
1623 |
if ( (opt->candles >= MIN_CANDLES_MINUTES) &&
|
|
1624 |
(opt->candles <= MAX_CANDLES_MINUTES) ) break;
|
|
1625 |
}
|
|
1626 |
print_parm_error("--candles");
|
|
1627 |
error_detected++;
|
|
1628 |
}
|
|
1629 |
break;
|
|
1630 |
/* --havdalah */ case 25:
|
|
1631 |
if ( (optarg == NULL) && (opt->havdalah == 0) ) opt->havdalah = 1;
|
|
1632 |
else
|
|
1633 |
{
|
|
1634 |
if (fnmatch( "[[:digit:]]?([[:digit:]])", optarg, FNM_EXTMATCH) == 0)
|
|
1635 |
{
|
|
1636 |
opt->havdalah = atoi(optarg);
|
|
1637 |
if ( (opt->havdalah >= MIN_MOTZASH_MINUTES) &&
|
|
1638 |
(opt->havdalah <= MAX_MOTZASH_MINUTES) ) break;
|
|
1639 |
}
|
|
1640 |
print_parm_error("--havdalah");
|
|
1641 |
error_detected++;
|
|
1642 |
}
|
|
1643 |
break;
|
|
1644 |
|
|
1645 |
} // end switch for long_options
|
|
1646 |
break;
|
|
1647 |
|
|
1648 |
|
|
1649 |
case '1': opt->three_month = 0; break;
|
|
1650 |
case '3': opt->three_month = 1; break;
|
|
1651 |
case 'b': opt->bidi = 1; opt->force_hebrew = 1; break;
|
|
1652 |
case 'c': opt->colorize = 1; break;
|
|
1653 |
case 'd': opt->diaspora = 1; break;
|
|
1654 |
case 'f': opt->footnote = 1; break;
|
|
1655 |
case 'h': opt->html = 1; break;
|
|
1656 |
case 'H': opt->force_hebrew = 1; break;
|
|
1657 |
case 'I': opt->force_israel = 1; break;
|
|
1658 |
case 'i': opt->external_css = 1; break;
|
|
1659 |
case 'm': opt->menu = 1; break;
|
|
1660 |
case 'p': opt->parasha = 1; break;
|
|
1661 |
case 'q': opt->quiet_alerts = 1; break;
|
|
1662 |
case 'l':
|
|
1663 |
error_detected = error_detected + parse_coordinate(1, optarg, lat, opt_latitude);
|
|
1664 |
break;
|
|
1665 |
case 'L':
|
|
1666 |
error_detected = error_detected + parse_coordinate(2, optarg, lon, opt_Longitude);
|
|
1667 |
break;
|
|
1668 |
case 's':
|
|
1669 |
opt->shabbat = 1;
|
|
1670 |
opt->parasha = 1;
|
|
1671 |
if (opt->candles == 0) opt->candles = 1;
|
|
1672 |
if (opt->havdalah == 0) opt->havdalah = 1;
|
|
1673 |
break;
|
|
1674 |
case 'z':
|
|
1675 |
error_detected = error_detected + parse_timezone(optarg, tz);
|
|
1676 |
break;
|
|
1677 |
case '?':
|
|
1678 |
// FIXME if (strchr(short_options,optopt)!=NULL)
|
|
1679 |
print_parm_missing_error((char*) &optopt);
|
|
1680 |
error_detected = TRUE;
|
|
1681 |
break;
|
|
1682 |
default: print_usage_hcal (); exit_main(opt, 0); break;
|
|
1683 |
}
|
|
1684 |
return error_detected;
|
|
1685 |
}
|
|
1686 |
|
|
1687 |
/**************************************************
|
|
1688 |
***************************************************
|
|
1689 |
***************************************************
|
|
1690 |
* main
|
|
1691 |
***************************************************
|
|
1692 |
***************************************************
|
|
1693 |
**************************************************/
|
|
1694 |
int main (int argc, char *argv[])
|
|
1695 |
{
|
|
1696 |
|
|
1697 |
/* date */
|
|
1698 |
int month, year;
|
|
1699 |
|
|
1700 |
double lat = BAD_COORDINATE; /* set to this value for error handling */
|
|
1701 |
double lon = BAD_COORDINATE; /* set to this value for error handling */
|
|
1702 |
int tz = BAD_TIMEZONE; /* -z option Time Zone, default to system local time */
|
|
1703 |
|
|
1704 |
int opt_latitude = 0; /* -l option latitude */
|
|
1705 |
int opt_Longitude = 0; /* -L option longitude */
|
|
1706 |
|
|
1707 |
int error_detected = FALSE; /* exit after reporting ALL bad parms */
|
|
1708 |
|
|
1709 |
|
|
1710 |
option_list opt;
|
|
1711 |
opt.bidi = 0; // visual bidi, implies --force-hebrew
|
|
1712 |
opt.html = 0; // -h html format flag
|
|
1713 |
opt.diaspora = 0; // -d Diaspora holidays
|
|
1714 |
opt.external_css = 0; // -i External css file
|
|
1715 |
opt.parasha = 0; // -p print parasha alongside calendar
|
|
1716 |
opt.shabbat = 0; // -c print candle-lighting alongside calendar
|
|
1717 |
opt.candles = 0;
|
|
1718 |
opt.havdalah = 0;
|
|
1719 |
opt.no_reverse = 0; // don't highlight today in reverse video
|
|
1720 |
opt.three_month = 0; // print previous and next months also
|
|
1721 |
opt.colorize = 0; // display calendar in muted, more pleasing tones
|
|
1722 |
opt.footnote = 0; // display description of month's holidays
|
|
1723 |
opt.force_hebrew = 0; // force display of Hebrew data in Hebrew
|
|
1724 |
opt.force_israel = 0; // override diaspora-awareness
|
|
1725 |
opt.not_sunset_aware = 0; // override sunset-awareness
|
|
1726 |
opt.quiet_alerts = 0;
|
|
1727 |
|
|
1728 |
opt.lat = BAD_COORDINATE;
|
|
1729 |
opt.lon = BAD_COORDINATE;
|
|
1730 |
opt.tz = BAD_TIMEZONE;
|
|
1731 |
|
|
1732 |
opt.menu = 0; // -m print menus for user-selection
|
|
1733 |
int i;
|
|
1734 |
for (i=0; i<MAX_MENU_ITEMS; i++) opt.menu_item[i] = NULL;
|
|
1735 |
|
|
1736 |
|
|
1737 |
// support for getopt short options
|
|
1738 |
static char * short_options = "13bcdfhHiImpqsl:L:z:";
|
|
1739 |
|
|
1740 |
/* support for long options */
|
|
1741 |
int long_option_index = 0;
|
|
1742 |
int c;
|
|
1743 |
static struct option long_options[] = {
|
|
1744 |
// name, has_arg, flag, val
|
|
1745 |
{"version", 0, 0, 0},
|
|
1746 |
{"help", 0, 0, 0},
|
|
1747 |
{"no-reverse", 0, 0, 0},
|
|
1748 |
{"html", 0, 0, 'h'},
|
|
1749 |
{"parasha", 0, 0, 'p'},
|
|
1750 |
{"shabbat", 0, 0, 's'},
|
|
1751 |
{"three-month", 0, 0, '3'},
|
|
1752 |
{"colorize", 0, 0, 'c'},
|
|
1753 |
{"footnote",0,0,'f'},
|
|
1754 |
{"hebrew",0,0,'H'},
|
|
1755 |
{"israel",0,0,'I'},
|
|
1756 |
{"latitude", 1, 0, 'l'},
|
|
1757 |
{"longitude", 1, 0, 'L'},
|
|
1758 |
{"timezone", 1, 0, 'z'},
|
|
1759 |
{"not-sunset-aware", 0, 0, 0},
|
|
1760 |
{"quiet-alerts",0,0,'q'},
|
|
1761 |
{"bidi",0,0,'b'},
|
|
1762 |
{"visual",0,0,'b'},
|
|
1763 |
{"one-month",0,0,'1'},
|
|
1764 |
{"no-bidi",0,0,0},
|
|
1765 |
{"no-visual",0,0,0},
|
|
1766 |
{"no-color",0,0,0},
|
|
1767 |
{"no-footnote",0,0,0},
|
|
1768 |
{"menu",0,0,'m'},
|
|
1769 |
{"candles",2,0,0},
|
|
1770 |
{"havdalah",2,0,0},
|
|
1771 |
{0, 0, 0, 0}
|
|
1772 |
};
|
|
1773 |
|
|
1774 |
/* hdate struct */
|
|
1775 |
hdate_struct h;
|
|
1776 |
|
|
1777 |
// for config file user-defined menus
|
|
1778 |
size_t menu_len = 0;
|
|
1779 |
int menu_index;
|
|
1780 |
char *menuptr, *optptr;
|
|
1781 |
|
|
1782 |
/************************************************************
|
|
1783 |
* init locale
|
|
1784 |
*
|
|
1785 |
* I'm not sure why this had to be done. Per an answer on
|
|
1786 |
* stackoverflow (not yet check out by me):
|
|
1787 |
*
|
|
1788 |
* "At program startup, you should call setlocale():
|
|
1789 |
* setlocale(LC_CTYPE, "");
|
|
1790 |
* This will cause the wide character functions to use the
|
|
1791 |
* appropriate character set defined by the environment - eg.
|
|
1792 |
* on Unix-like systems, the LANG environment variable. For
|
|
1793 |
* example, this means that if your LANG variable is set to a
|
|
1794 |
* UTF8 locale, the wide character functions will handle input
|
|
1795 |
* and output in UTF8. (This is how the POSIX wc utility is
|
|
1796 |
* specified to work). You can then use the wide-character
|
|
1797 |
* versions of all the standard functions. However, if you
|
|
1798 |
* really do want to count characters rather than bytes, and
|
|
1799 |
* can assume that your text files are encoded in UTF-8, then
|
|
1800 |
* the easiest approach is to count all bytes that are not
|
|
1801 |
* trail bytes (i.e., in the range 0x80 to 0xBF)."
|
|
1802 |
*
|
|
1803 |
* Note: the code sets LC_ALL instead of LC_CTYPE; and the
|
|
1804 |
* code does not use wide_char functions ...
|
|
1805 |
************************************************************/
|
|
1806 |
setlocale (LC_ALL, "");
|
|
1807 |
|
|
1808 |
/************************************************************
|
|
1809 |
* parse config file
|
|
1810 |
************************************************************/
|
|
1811 |
FILE *config_file = get_config_file("/hcal", "/hcalrc", hcal_config_file_text);
|
|
1812 |
if (config_file != NULL)
|
|
1813 |
{
|
|
1814 |
read_config_file(config_file, &opt, &lat, &opt_latitude, &lon, &opt_Longitude, &tz);
|