File azan.c changed (mode: 100644) (index ea02f73..b2c7b75) |
1 |
|
/* See LICENSE file for copyright and license details. |
|
2 |
|
* |
|
|
1 |
|
/* |
|
2 |
|
* See LICENSE file for copyright and license details. |
3 |
3 |
* Azan is simple Muslim prayers notifier. |
* Azan is simple Muslim prayers notifier. |
4 |
|
* print next pray left duration. |
|
|
4 |
|
* print next prayer left duration or today's all prayers. |
5 |
5 |
*/ |
*/ |
6 |
6 |
|
|
7 |
7 |
#include <time.h> |
#include <time.h> |
|
9 |
9 |
#include <stdlib.h> |
#include <stdlib.h> |
10 |
10 |
#include <math.h> |
#include <math.h> |
11 |
11 |
#include <string.h> |
#include <string.h> |
|
12 |
|
#ifdef __linux__ |
12 |
13 |
#include <getopt.h> |
#include <getopt.h> |
13 |
|
#ifdef __unix__ |
|
|
14 |
|
#include <unistd.h> |
14 |
15 |
#include <sys/types.h> |
#include <sys/types.h> |
15 |
16 |
#include <sys/stat.h> |
#include <sys/stat.h> |
16 |
17 |
#endif |
#endif |
|
23 |
24 |
|
|
24 |
25 |
/* function declarations */ |
/* function declarations */ |
25 |
26 |
static void usage(void); |
static void usage(void); |
26 |
|
static char convert_prayer_int_to_char(int pray_numb); |
|
27 |
|
static char *convert_timet_to_str(time_t input_time); |
|
28 |
|
static char *convert_sec_double_to_min_hour(double input_seconds); |
|
29 |
|
static time_t convert_today_double_to_timet(double event_time, int day); |
|
|
27 |
|
static char convert_prayer_int_to_char(const int pray_numb); |
|
28 |
|
static char *convert_timet_to_str(const time_t input_time); |
|
29 |
|
static char *convert_sec_double_to_min_hour(const double input_seconds); |
|
30 |
|
static time_t convert_today_double_to_timet(const double event_time, const int day); |
30 |
31 |
static double convert_gregorian_to_julian(int year, int month, int day); |
static double convert_gregorian_to_julian(int year, int month, int day); |
31 |
32 |
static double convert_degrees_to_radians(const double x); |
static double convert_degrees_to_radians(const double x); |
32 |
33 |
static double convert_radians_to_degrees(const double x); |
static double convert_radians_to_degrees(const double x); |
33 |
34 |
static double T(const double alpha, const double D); |
static double T(const double alpha, const double D); |
34 |
35 |
static double A(const double t, const double D); |
static double A(const double t, const double D); |
35 |
36 |
static double normalize(const double x, const double N); |
static double normalize(const double x, const double N); |
36 |
|
static double get_equation_time(double jdn, double *D); |
|
37 |
|
static double get_sunrise(double dhuhr, double D); |
|
38 |
|
static double get_fajr(double duhr, double D); |
|
39 |
|
static double get_duhr(double EqT); |
|
40 |
|
static double get_asr(double duhr, double D); |
|
41 |
|
static double get_maghrib(double dhuhr, double D); |
|
42 |
|
static double get_isha(double duhr, double maghrib, double D); |
|
43 |
|
static int file_exist(char *filename); |
|
44 |
|
static int create_cache_file(time_t t, char *full_path); |
|
45 |
|
static time_t *read_azan_cache_file(char *azan_cache_file); |
|
46 |
|
static int print_next_prayer(time_t current_time, char *azan_cache_file); |
|
47 |
|
static int print_all_prayers(char *azan_cache_file); |
|
48 |
|
static char *get_cache_file_name(time_t t); |
|
|
37 |
|
static double get_equation_time(const double jdn, double *D); |
|
38 |
|
static double get_sunrise(const double dhuhr, const double D); |
|
39 |
|
static double get_fajr(const double duhr, const double D); |
|
40 |
|
static double get_duhr(const double EqT); |
|
41 |
|
static double get_asr(const double duhr, const double D); |
|
42 |
|
static double get_maghrib(double dhuhr, const double D); |
|
43 |
|
static double get_isha(const double duhr, const double maghrib, const double D); |
|
44 |
|
static int file_exist(const char *filename); |
|
45 |
|
static int create_cache_file(const time_t t, const char *full_path); |
|
46 |
|
static time_t *read_azan_cache_file(const char *azan_cache_file); |
|
47 |
|
static int print_next_prayer(const time_t current_time, const char *azan_cache_file); |
|
48 |
|
static int print_all_prayers(const char *azan_cache_file); |
|
49 |
|
static char *get_cache_file_name(const time_t t); |
49 |
50 |
|
|
50 |
51 |
/* function implementations */ |
/* function implementations */ |
51 |
52 |
static void |
static void |
|
... |
... |
usage(void) |
62 |
63 |
} |
} |
63 |
64 |
|
|
64 |
65 |
static char |
static char |
65 |
|
convert_prayer_int_to_char(int pray_numb) |
|
|
66 |
|
convert_prayer_int_to_char(const int pray_numb) |
66 |
67 |
{ |
{ |
67 |
68 |
char result; |
char result; |
68 |
69 |
switch (pray_numb) { |
switch (pray_numb) { |
|
... |
... |
convert_prayer_int_to_char(int pray_numb) |
91 |
92 |
} |
} |
92 |
93 |
|
|
93 |
94 |
static char |
static char |
94 |
|
*convert_timet_to_str(time_t input_time) |
|
|
95 |
|
*convert_timet_to_str(const time_t input_time) |
95 |
96 |
{ |
{ |
96 |
97 |
char *result; |
char *result; |
97 |
98 |
size_t result_size = (size_t)32; |
size_t result_size = (size_t)32; |
|
... |
... |
static char |
104 |
105 |
} |
} |
105 |
106 |
|
|
106 |
107 |
static char |
static char |
107 |
|
*convert_sec_double_to_min_hour(double input_seconds) |
|
|
108 |
|
*convert_sec_double_to_min_hour(const double input_seconds) |
108 |
109 |
{ |
{ |
109 |
110 |
char *result; |
char *result; |
110 |
111 |
size_t result_size = (size_t)32; |
size_t result_size = (size_t)32; |
|
... |
... |
static char |
122 |
123 |
} |
} |
123 |
124 |
|
|
124 |
125 |
static time_t |
static time_t |
125 |
|
convert_today_double_to_timet(double event_time, int day) |
|
|
126 |
|
convert_today_double_to_timet(const double event_time, const int day) |
126 |
127 |
{ |
{ |
127 |
128 |
/* Convert to hour min */ |
/* Convert to hour min */ |
128 |
|
double hours = floor(event_time); |
|
129 |
|
double minutes = round((event_time - hours) * 60.0); |
|
|
129 |
|
const double hours = floor(event_time); |
|
130 |
|
const double minutes = round((event_time - hours) * 60.0); |
130 |
131 |
|
|
131 |
132 |
time_t now ; |
time_t now ; |
132 |
133 |
time_t converted; |
time_t converted; |
|
... |
... |
convert_gregorian_to_julian(int year, int month, int day) |
149 |
150 |
year -= 1; |
year -= 1; |
150 |
151 |
month += 12; |
month += 12; |
151 |
152 |
} |
} |
152 |
|
double A = floor((double)year / 100); |
|
153 |
|
double B = 2 - A + floor(A / 4); |
|
154 |
|
double result = floor(365.25 * ((double)year + 4716)) + |
|
|
153 |
|
const double A = floor((double)year / 100); |
|
154 |
|
const double B = 2 - A + floor(A / 4); |
|
155 |
|
const double result = floor(365.25 * ((double)year + 4716)) + |
155 |
156 |
floor(30.6001 * ((double)month + 1)) + |
floor(30.6001 * ((double)month + 1)) + |
156 |
157 |
(double)day + B - 1524.5; |
(double)day + B - 1524.5; |
157 |
158 |
return result; |
return result; |
|
... |
... |
convert_radians_to_degrees(const double x) |
169 |
170 |
return ((x) * 180.0) / MI_PI; |
return ((x) * 180.0) / MI_PI; |
170 |
171 |
} |
} |
171 |
172 |
|
|
172 |
|
static double |
|
|
173 |
|
static const double |
173 |
174 |
T(const double alpha, const double D) |
T(const double alpha, const double D) |
174 |
175 |
{ |
{ |
175 |
|
double p1 = 1.0/15.0; |
|
176 |
|
double p2 = cos(convert_degrees_to_radians(latitude)) * |
|
|
176 |
|
const double p1 = 1.0/15.0; |
|
177 |
|
const double p2 = cos(convert_degrees_to_radians(latitude)) * |
177 |
178 |
cos(convert_degrees_to_radians(D)); |
cos(convert_degrees_to_radians(D)); |
178 |
|
double p3 = sin(convert_degrees_to_radians(latitude)) * |
|
|
179 |
|
const double p3 = sin(convert_degrees_to_radians(latitude)) * |
179 |
180 |
sin(convert_degrees_to_radians(D)); |
sin(convert_degrees_to_radians(D)); |
180 |
|
double p4 = -1.0 * sin(convert_degrees_to_radians(alpha)); |
|
181 |
|
double p5 = convert_radians_to_degrees(acos((p4 - p3) / p2)); |
|
182 |
|
double r = p1 * p5; |
|
|
181 |
|
const double p4 = -1.0 * sin(convert_degrees_to_radians(alpha)); |
|
182 |
|
const double p5 = convert_radians_to_degrees(acos((p4 - p3) / p2)); |
|
183 |
|
const double r = p1 * p5; |
183 |
184 |
return r; |
return r; |
184 |
185 |
} |
} |
185 |
186 |
|
|
186 |
|
static double |
|
|
187 |
|
static const double |
187 |
188 |
A(const double t, const double D) |
A(const double t, const double D) |
188 |
189 |
{ |
{ |
189 |
|
double p1 = 1.0/15.0; |
|
190 |
|
double p2 = cos(convert_degrees_to_radians(latitude))* |
|
191 |
|
cos(convert_degrees_to_radians(D)); |
|
192 |
|
double p3 = sin(convert_degrees_to_radians(latitude)) * |
|
193 |
|
sin(convert_degrees_to_radians(D)); |
|
194 |
|
double p4 = tan(convert_degrees_to_radians((latitude - D))); |
|
195 |
|
double p5 = atan2(1.0, (t + p4)); |
|
196 |
|
double p6 = sin(p5); |
|
197 |
|
double p7 = acos((p6 - p3) / p2); |
|
198 |
|
double r = p1 * convert_radians_to_degrees(p7); |
|
|
190 |
|
const double p1 = 1.0/15.0; |
|
191 |
|
const double p2 = cos(convert_degrees_to_radians(latitude))* |
|
192 |
|
cos(convert_degrees_to_radians(D)); |
|
193 |
|
const double p3 = sin(convert_degrees_to_radians(latitude)) * |
|
194 |
|
sin(convert_degrees_to_radians(D)); |
|
195 |
|
const double p4 = tan(convert_degrees_to_radians((latitude - D))); |
|
196 |
|
const double p5 = atan2(1.0, (t + p4)); |
|
197 |
|
const double p6 = sin(p5); |
|
198 |
|
const double p7 = acos((p6 - p3) / p2); |
|
199 |
|
const double r = p1 * convert_radians_to_degrees(p7); |
199 |
200 |
return r; |
return r; |
200 |
201 |
} |
} |
201 |
202 |
|
|
202 |
|
static double |
|
|
203 |
|
static const double |
203 |
204 |
normalize(const double x, const double N) |
normalize(const double x, const double N) |
204 |
205 |
{ |
{ |
205 |
|
double n; |
|
206 |
|
n = x - (N * floor( x / N )); |
|
|
206 |
|
const double n = x - (N * floor( x / N )); |
207 |
207 |
return n; |
return n; |
208 |
208 |
} |
} |
209 |
209 |
|
|
210 |
|
static double |
|
211 |
|
get_equation_time(double jdn, double *D) |
|
|
210 |
|
static const double |
|
211 |
|
get_equation_time(const double jdn, double *D) |
212 |
212 |
{ |
{ |
213 |
213 |
double d; /* Julian Day Number from 1 January 2000 */ |
double d; /* Julian Day Number from 1 January 2000 */ |
214 |
214 |
double g; /* Mean anomaly of the Sun */ |
double g; /* Mean anomaly of the Sun */ |
|
... |
... |
get_equation_time(double jdn, double *D) |
217 |
217 |
double e; /* The mean obliquity of the ecliptic */ |
double e; /* The mean obliquity of the ecliptic */ |
218 |
218 |
double RA; /* The Sun's right ascension */ |
double RA; /* The Sun's right ascension */ |
219 |
219 |
double EqT; /* The Equation of Time */ |
double EqT; /* The Equation of Time */ |
220 |
|
double offset = 2451545; |
|
|
220 |
|
const double offset = 2451545.0; |
221 |
221 |
|
|
222 |
|
FAIL_IF(jdn < offset, "[Error] Julian must be greader than offset."); |
|
|
222 |
|
FAIL_IF((int)jdn < (int)offset, "[Error] Julian must be greader than offset."); |
223 |
223 |
d = (jdn - offset); /* Remove the offset from jdn */ |
d = (jdn - offset); /* Remove the offset from jdn */ |
224 |
224 |
g = 357.529 + 0.98560028 * d; |
g = 357.529 + 0.98560028 * d; |
225 |
225 |
q = 280.459 + 0.98564736 * d; |
q = 280.459 + 0.98564736 * d; |
|
... |
... |
get_equation_time(double jdn, double *D) |
238 |
238 |
return EqT; |
return EqT; |
239 |
239 |
} |
} |
240 |
240 |
|
|
241 |
|
static double |
|
242 |
|
get_sunrise(double dhuhr, double D) |
|
|
241 |
|
static const double |
|
242 |
|
get_sunrise(const double dhuhr, const double D) |
243 |
243 |
{ |
{ |
244 |
244 |
return (dhuhr - T(0.8333 + 0.0347 * sqrt(altitude), D)); |
return (dhuhr - T(0.8333 + 0.0347 * sqrt(altitude), D)); |
245 |
245 |
} |
} |
246 |
246 |
|
|
247 |
|
static double |
|
248 |
|
get_fajr(double duhr, double D) |
|
|
247 |
|
static const double |
|
248 |
|
get_fajr(const double duhr, const double D) |
249 |
249 |
{ |
{ |
250 |
|
double fajr = duhr - T(fajr_angle, D); |
|
|
250 |
|
const double fajr = duhr - T(fajr_angle, D); |
251 |
251 |
return fajr; |
return fajr; |
252 |
252 |
} |
} |
253 |
253 |
|
|
254 |
|
static double |
|
255 |
|
get_duhr(double EqT) |
|
|
254 |
|
static const double |
|
255 |
|
get_duhr(const double EqT) |
256 |
256 |
{ |
{ |
257 |
|
static double duhr; |
|
|
257 |
|
double duhr; |
258 |
258 |
duhr = 12.0 + time_zone - longitude/15.0 - EqT; |
duhr = 12.0 + time_zone - longitude/15.0 - EqT; |
259 |
259 |
duhr = normalize(duhr, 24.0); |
duhr = normalize(duhr, 24.0); |
260 |
260 |
return duhr; |
return duhr; |
261 |
261 |
} |
} |
262 |
262 |
|
|
263 |
|
static double |
|
264 |
|
get_asr(double duhr, double D) |
|
|
263 |
|
static const double |
|
264 |
|
get_asr(const double duhr, const double D) |
265 |
265 |
{ |
{ |
266 |
266 |
double asr; |
double asr; |
267 |
267 |
if (use_major == 1){ |
if (use_major == 1){ |
|
... |
... |
get_asr(double duhr, double D) |
276 |
276 |
return asr; |
return asr; |
277 |
277 |
} |
} |
278 |
278 |
|
|
279 |
|
static double |
|
280 |
|
get_maghrib(double dhuhr, double D) |
|
|
279 |
|
static const double |
|
280 |
|
get_maghrib(const double dhuhr, const double D) |
281 |
281 |
{ |
{ |
282 |
282 |
return (dhuhr + T(0.8333 + 0.0347 * sqrt(altitude), D)); |
return (dhuhr + T(0.8333 + 0.0347 * sqrt(altitude), D)); |
283 |
283 |
} |
} |
284 |
284 |
|
|
285 |
|
static double |
|
286 |
|
get_isha(double duhr, double maghrib, double D) |
|
|
285 |
|
static const double |
|
286 |
|
get_isha(const double duhr, const double maghrib, const double D) |
287 |
287 |
{ |
{ |
288 |
|
double one_min = 60.0/3600.0; |
|
|
288 |
|
const double one_min = 60.0/3600.0; |
289 |
289 |
double isha; |
double isha; |
290 |
290 |
|
|
291 |
291 |
/* Umm Al-Qura */ |
/* Umm Al-Qura */ |
292 |
292 |
if (use_umm_al_qura == 1) { |
if (use_umm_al_qura == 1) { |
293 |
|
isha = maghrib + 90 * one_min; |
|
|
293 |
|
isha = maghrib + 90.0 * one_min; |
294 |
294 |
|
|
295 |
295 |
/* Ramadan Umm Al-Qura */ |
/* Ramadan Umm Al-Qura */ |
296 |
296 |
} else if (is_ramadan == 1){ |
} else if (is_ramadan == 1){ |
297 |
|
isha = maghrib + 120 * one_min; |
|
|
297 |
|
isha = maghrib + 120.0 * one_min; |
298 |
298 |
|
|
299 |
299 |
/* Use isha_angle */ |
/* Use isha_angle */ |
300 |
300 |
} else { |
} else { |
|
... |
... |
get_isha(double duhr, double maghrib, double D) |
306 |
306 |
} |
} |
307 |
307 |
|
|
308 |
308 |
static int |
static int |
309 |
|
file_exist(char *filename) |
|
|
309 |
|
file_exist(const char *filename) |
310 |
310 |
{ |
{ |
311 |
311 |
FILE *file; |
FILE *file; |
312 |
312 |
file = fopen(filename, "r"); |
file = fopen(filename, "r"); |
|
... |
... |
file_exist(char *filename) |
318 |
318 |
} |
} |
319 |
319 |
|
|
320 |
320 |
static int |
static int |
321 |
|
create_cache_file(time_t t, char *full_path) |
|
|
321 |
|
create_cache_file(const time_t t, const char *full_path) |
322 |
322 |
{ |
{ |
323 |
323 |
/* Current date time */ |
/* Current date time */ |
324 |
|
struct tm current_date = *localtime(&t); |
|
325 |
|
int day = current_date.tm_mday; |
|
326 |
|
int month = current_date.tm_mon + 1; |
|
327 |
|
int year = current_date.tm_year + 1900; |
|
|
324 |
|
const struct tm current_date = *localtime(&t); |
|
325 |
|
const int day = current_date.tm_mday; |
|
326 |
|
const int month = current_date.tm_mon + 1; |
|
327 |
|
const int year = current_date.tm_year + 1900; |
328 |
328 |
|
|
329 |
329 |
/* Create Cache File if doesn't exists'*/ |
/* Create Cache File if doesn't exists'*/ |
330 |
330 |
if (file_exist(full_path) < 0){ |
if (file_exist(full_path) < 0){ |
331 |
331 |
// FIXME: if dir with same name(must get file type filter) |
// FIXME: if dir with same name(must get file type filter) |
332 |
332 |
/* Equation of Time */ |
/* Equation of Time */ |
333 |
|
double julian_date = convert_gregorian_to_julian(year, month, day); |
|
|
333 |
|
const double julian_date = convert_gregorian_to_julian( |
|
334 |
|
year, month, day); |
334 |
335 |
double D = 0.0; |
double D = 0.0; |
335 |
|
double equation_of_time = get_equation_time(julian_date, &D); |
|
|
336 |
|
const double equation_of_time = get_equation_time(julian_date, &D); |
336 |
337 |
|
|
337 |
338 |
/* Today's Prayers time */ |
/* Today's Prayers time */ |
338 |
339 |
// FIXME 3 minutes less (duhr = 15 should be 18) |
// FIXME 3 minutes less (duhr = 15 should be 18) |
339 |
|
double duhr = get_duhr(equation_of_time); |
|
340 |
|
double sunrise = get_sunrise(duhr, D); |
|
|
340 |
|
const double duhr = get_duhr(equation_of_time); |
|
341 |
|
const double sunrise = get_sunrise(duhr, D); |
341 |
342 |
// TODO fajr sunrise |
// TODO fajr sunrise |
342 |
343 |
// fajr = get_fajr(true_noon, sunset_prev, sunrise, loc, &coord); |
// fajr = get_fajr(true_noon, sunset_prev, sunrise, loc, &coord); |
343 |
|
double fajr = get_fajr(duhr, D); |
|
344 |
|
double maghrib = get_maghrib(duhr, D); |
|
|
344 |
|
const double fajr = get_fajr(duhr, D); |
|
345 |
|
const double maghrib = get_maghrib(duhr, D); |
345 |
346 |
//TODO isha next sunrise |
//TODO isha next sunrise |
346 |
347 |
//isha = get_isha(true_noon, sunset, sunrise_next, loc, &coord); |
//isha = get_isha(true_noon, sunset, sunrise_next, loc, &coord); |
347 |
|
double isha = get_isha(duhr, maghrib, D); |
|
348 |
|
double asr = get_asr(duhr, D); |
|
349 |
|
|
|
|
348 |
|
const double isha = get_isha(duhr, maghrib, D); |
|
349 |
|
const double asr = get_asr(duhr, D); |
350 |
350 |
|
|
351 |
351 |
/* Convert prayer times to unix timestamp */ |
/* Convert prayer times to unix timestamp */ |
352 |
|
static time_t prayer_array[6]; |
|
|
352 |
|
time_t prayer_array[6]; |
353 |
353 |
prayer_array[0] = convert_today_double_to_timet(fajr, day); |
prayer_array[0] = convert_today_double_to_timet(fajr, day); |
354 |
354 |
prayer_array[1] = convert_today_double_to_timet(duhr, day); |
prayer_array[1] = convert_today_double_to_timet(duhr, day); |
355 |
355 |
prayer_array[2] = convert_today_double_to_timet(asr, day); |
prayer_array[2] = convert_today_double_to_timet(asr, day); |
|
... |
... |
create_cache_file(time_t t, char *full_path) |
379 |
379 |
} |
} |
380 |
380 |
|
|
381 |
381 |
static time_t |
static time_t |
382 |
|
*read_azan_cache_file(char *azan_cache_file) |
|
|
382 |
|
*read_azan_cache_file(const char *azan_cache_file) |
383 |
383 |
{ |
{ |
384 |
384 |
FILE *fp; |
FILE *fp; |
385 |
385 |
char buffer[128]; |
char buffer[128]; |
|
... |
... |
static time_t |
409 |
409 |
} |
} |
410 |
410 |
|
|
411 |
411 |
static int |
static int |
412 |
|
print_next_prayer(time_t current_time, char *azan_cache_file) |
|
|
412 |
|
print_next_prayer(const time_t current_time, const char *azan_cache_file) |
413 |
413 |
{ |
{ |
414 |
414 |
time_t *azan_array; |
time_t *azan_array; |
415 |
415 |
azan_array = read_azan_cache_file(azan_cache_file); |
azan_array = read_azan_cache_file(azan_cache_file); |
|
... |
... |
print_next_prayer(time_t current_time, char *azan_cache_file) |
432 |
432 |
} |
} |
433 |
433 |
|
|
434 |
434 |
static int |
static int |
435 |
|
print_all_prayers(char *azan_cache_file) |
|
|
435 |
|
print_all_prayers(const char *azan_cache_file) |
436 |
436 |
{ |
{ |
437 |
437 |
time_t *azan_array; |
time_t *azan_array; |
438 |
438 |
azan_array = read_azan_cache_file(azan_cache_file); |
azan_array = read_azan_cache_file(azan_cache_file); |
|
... |
... |
print_all_prayers(char *azan_cache_file) |
440 |
440 |
|
|
441 |
441 |
for (int i=0; i<5; i++) { |
for (int i=0; i<5; i++) { |
442 |
442 |
// convert_timet_to_str; |
// convert_timet_to_str; |
443 |
|
char prayer_first_letter = convert_prayer_int_to_char(i); |
|
|
443 |
|
const char prayer_first_letter = convert_prayer_int_to_char(i); |
444 |
444 |
char *prayer_time = convert_timet_to_str(azan_array[i]); |
char *prayer_time = convert_timet_to_str(azan_array[i]); |
445 |
445 |
printf("%c %s\n", prayer_first_letter, prayer_time); |
printf("%c %s\n", prayer_first_letter, prayer_time); |
446 |
446 |
free(prayer_time); |
free(prayer_time); |
|
... |
... |
print_all_prayers(char *azan_cache_file) |
451 |
451 |
} |
} |
452 |
452 |
|
|
453 |
453 |
static char |
static char |
454 |
|
*get_cache_file_name(time_t t) |
|
|
454 |
|
*get_cache_file_name(const time_t t) |
455 |
455 |
{ |
{ |
456 |
456 |
/* Current date time */ |
/* Current date time */ |
457 |
|
struct tm current_date = *localtime(&t); |
|
458 |
|
int day = current_date.tm_mday; |
|
459 |
|
int month = current_date.tm_mon + 1; |
|
460 |
|
int year = current_date.tm_year + 1900; |
|
|
457 |
|
const struct tm current_date = *localtime(&t); |
|
458 |
|
const int day = current_date.tm_mday; |
|
459 |
|
const int month = current_date.tm_mon + 1; |
|
460 |
|
const int year = current_date.tm_year + 1900; |
461 |
461 |
|
|
462 |
|
size_t max_file_name = (size_t)128; |
|
463 |
|
static char azan_cache_file[128]; |
|
|
462 |
|
const size_t max_file_name = (size_t)128; |
|
463 |
|
char azan_cache_file[128]; |
464 |
464 |
|
|
465 |
465 |
(void)snprintf(azan_cache_file, max_file_name, "azan_%.2i-%.2i-%i.txt", |
(void)snprintf(azan_cache_file, max_file_name, "azan_%.2i-%.2i-%i.txt", |
466 |
466 |
day, month, year); |
day, month, year); |
|
... |
... |
int |
478 |
478 |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
479 |
479 |
{ |
{ |
480 |
480 |
/* Handel Arguments */ |
/* Handel Arguments */ |
481 |
|
int c = getopt(argc, argv, "vah"); |
|
482 |
|
time_t t = time(NULL); |
|
|
481 |
|
const int c = getopt(argc, argv, "vah"); |
|
482 |
|
const time_t t = time(NULL); |
483 |
483 |
char *full_path = get_cache_file_name(t); |
char *full_path = get_cache_file_name(t); |
484 |
484 |
|
|
485 |
485 |
if (argc > 1) { |
if (argc > 1) { |