File azan.c changed (mode: 100644) (index 51156dc..bed1c2a) |
... |
... |
create_cache_file(time_t t, char* full_path) |
325 |
325 |
|
|
326 |
326 |
/* Create Cache File if doesn't exists'*/ |
/* Create Cache File if doesn't exists'*/ |
327 |
327 |
if (file_exist(full_path) < 0){ |
if (file_exist(full_path) < 0){ |
|
328 |
|
// FIXME: if dir with same name(must get file type filter) |
328 |
329 |
/* Equation of Time */ |
/* Equation of Time */ |
329 |
330 |
double julian_date = convert_gregorian_to_julian(year, month, day); |
double julian_date = convert_gregorian_to_julian(year, month, day); |
330 |
331 |
double D = 0; |
double D = 0; |
331 |
332 |
double equation_of_time = get_equation_time(julian_date, &D); |
double equation_of_time = get_equation_time(julian_date, &D); |
332 |
333 |
|
|
333 |
334 |
/* Today's Prayers time */ |
/* Today's Prayers time */ |
334 |
|
// FIXME 3 minutes less (duhr = 15 should be 18) |
|
|
335 |
|
// FIXME 3 minutes less (duhr = 15 should be 18) |
335 |
336 |
double duhr = get_duhr(time_zone, longitude, equation_of_time); |
double duhr = get_duhr(time_zone, longitude, equation_of_time); |
336 |
337 |
double sunrise = get_sunrise(duhr, latitude, altitude, D); |
double sunrise = get_sunrise(duhr, latitude, altitude, D); |
337 |
|
// TODO fajr sunrise |
|
338 |
|
// fajr = get_fajr(true_noon, sunset_prev, sunrise, loc, &coord); |
|
|
338 |
|
// TODO fajr sunrise |
|
339 |
|
// fajr = get_fajr(true_noon, sunset_prev, sunrise, loc, &coord); |
339 |
340 |
double fajr = get_fajr(duhr, latitude, D, fajr_angle); |
double fajr = get_fajr(duhr, latitude, D, fajr_angle); |
340 |
341 |
double maghrib = get_maghrib(duhr, latitude, altitude, D); |
double maghrib = get_maghrib(duhr, latitude, altitude, D); |
341 |
342 |
//TODO isha next sunrise |
//TODO isha next sunrise |
|
... |
... |
create_cache_file(time_t t, char* full_path) |
345 |
346 |
|
|
346 |
347 |
|
|
347 |
348 |
/* Convert prayer times to unix timestamp */ |
/* Convert prayer times to unix timestamp */ |
348 |
|
static time_t prayer_array[6]; |
|
349 |
|
prayer_array[0] = convert_today_double_to_timet(fajr, day); |
|
350 |
|
prayer_array[1] = convert_today_double_to_timet(duhr, day); |
|
351 |
|
prayer_array[2] = convert_today_double_to_timet(asr, day); |
|
352 |
|
prayer_array[3] = convert_today_double_to_timet(maghrib, day); |
|
353 |
|
prayer_array[4] = convert_today_double_to_timet(isha, day); |
|
354 |
|
prayer_array[5] = convert_today_double_to_timet(fajr, day+1); |
|
355 |
|
|
|
356 |
|
/* Create cache dir if not exists*/ |
|
357 |
|
(void)mkdir(full_path, 0700); |
|
358 |
|
|
|
359 |
|
/* Create cache file */ |
|
360 |
|
FILE* fpointer; |
|
361 |
|
fpointer = fopen(full_path, "w"); |
|
362 |
|
chmod(full_path, 00400); /* Change permission to read only*/ |
|
363 |
|
// (void)puts(full_path); |
|
364 |
|
|
|
365 |
|
if (fpointer == NULL) { |
|
366 |
|
printf("[Error] opening lp cache file.\n"); |
|
367 |
|
exit(EXIT_FAILURE); |
|
368 |
|
} |
|
|
349 |
|
static time_t prayer_array[6]; |
|
350 |
|
prayer_array[0] = convert_today_double_to_timet(fajr, day); |
|
351 |
|
prayer_array[1] = convert_today_double_to_timet(duhr, day); |
|
352 |
|
prayer_array[2] = convert_today_double_to_timet(asr, day); |
|
353 |
|
prayer_array[3] = convert_today_double_to_timet(maghrib, day); |
|
354 |
|
prayer_array[4] = convert_today_double_to_timet(isha, day); |
|
355 |
|
prayer_array[5] = convert_today_double_to_timet(fajr, day+1); |
|
356 |
|
|
|
357 |
|
/* Create cache dir if not exists*/ |
|
358 |
|
char* cache_dir = get_cache_dir(); |
|
359 |
|
(void)mkdir(cache_dir, 0700); |
|
360 |
|
|
|
361 |
|
/* Create cache file */ |
|
362 |
|
FILE* fpointer; |
|
363 |
|
fpointer = fopen(full_path, "w"); |
|
364 |
|
chmod(full_path, 00400); /* Change permission to read only*/ |
|
365 |
|
if (fpointer == NULL) { |
|
366 |
|
printf("[Error] opening lp cache file.\n"); |
|
367 |
|
exit(EXIT_FAILURE); |
|
368 |
|
} |
369 |
369 |
|
|
370 |
370 |
fprintf(fpointer, "%ld\n%ld\n%ld\n%ld\n%ld\n%ld", |
fprintf(fpointer, "%ld\n%ld\n%ld\n%ld\n%ld\n%ld", |
371 |
371 |
(long)prayer_array[0], |
(long)prayer_array[0], |
|
... |
... |
create_cache_file(time_t t, char* full_path) |
376 |
376 |
(long)prayer_array[5] |
(long)prayer_array[5] |
377 |
377 |
); |
); |
378 |
378 |
|
|
379 |
|
(void)fclose(fpointer); |
|
|
379 |
|
(void)fclose(fpointer); |
380 |
380 |
} |
} |
381 |
381 |
|
|
382 |
382 |
return 0; |
return 0; |
|
... |
... |
print_next_prayer(time_t current_time, char* azan_cache_file) |
440 |
440 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
441 |
441 |
} |
} |
442 |
442 |
|
|
443 |
|
for (int i=0; i<5; i++) { |
|
|
443 |
|
for (int i=0; i<6; i++) { |
444 |
444 |
if (azan_array[i] > current_time){ |
if (azan_array[i] > current_time){ |
445 |
445 |
double left_seconds = difftime(azan_array[i], current_time); |
double left_seconds = difftime(azan_array[i], current_time); |
446 |
446 |
char prayer_first_letter = conv_prayer_int_to_char(i); |
char prayer_first_letter = conv_prayer_int_to_char(i); |
|
... |
... |
conv_prayer_int_to_char(int pray_numb) |
507 |
507 |
return result; |
return result; |
508 |
508 |
} |
} |
509 |
509 |
|
|
|
510 |
|
static char* |
|
511 |
|
get_cache_dir(void) |
|
512 |
|
{ |
|
513 |
|
size_t max_dir_name = 128; |
|
514 |
|
char* user_home = getenv("HOME"); |
|
515 |
|
char* cache_dir; |
|
516 |
|
cache_dir = calloc(128, sizeof(char)); |
|
517 |
|
|
|
518 |
|
if (user_home == NULL) { |
|
519 |
|
printf("Error, allocating memory [ Line %d ]\n", __LINE__); |
|
520 |
|
exit(EXIT_FAILURE); |
|
521 |
|
} |
|
522 |
|
(void)snprintf(cache_dir, max_dir_name, "%s/.cache/azan", user_home); |
|
523 |
|
|
|
524 |
|
return cache_dir; |
|
525 |
|
} |
|
526 |
|
|
510 |
527 |
static char* |
static char* |
511 |
528 |
get_cache_file_name(time_t t) |
get_cache_file_name(time_t t) |
512 |
529 |
{ |
{ |
|
... |
... |
get_cache_file_name(time_t t) |
517 |
534 |
int year = current_date.tm_year + 1900; |
int year = current_date.tm_year + 1900; |
518 |
535 |
|
|
519 |
536 |
size_t max_file_name = 128; |
size_t max_file_name = 128; |
520 |
|
static char cache_dir[128]; |
|
|
537 |
|
char* cache_dir = get_cache_dir(); |
521 |
538 |
static char azan_cache_file[128]; |
static char azan_cache_file[128]; |
522 |
539 |
|
|
523 |
|
/* Get Home dir */ |
|
524 |
|
char* user_home = getenv("HOME"); |
|
525 |
|
if (user_home == NULL) { |
|
526 |
|
printf("Error, allocating memory [ Line %d ]\n", __LINE__); |
|
527 |
|
exit(EXIT_FAILURE); |
|
528 |
|
} |
|
529 |
|
(void)snprintf(cache_dir, max_file_name, "%s/.cache/azan", user_home); |
|
530 |
540 |
(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", |
531 |
541 |
day, month, year); |
day, month, year); |
532 |
542 |
|
|
|
... |
... |
main(int argc, char *argv[]) |
583 |
593 |
if (argc > 1) { |
if (argc > 1) { |
584 |
594 |
switch (c) { |
switch (c) { |
585 |
595 |
case 'v': |
case 'v': |
586 |
|
puts("azan-"VERSION); |
|
|
596 |
|
(void)puts("azan-"VERSION); |
587 |
597 |
break; |
break; |
588 |
598 |
case 'n': |
case 'n': |
589 |
599 |
send_notification(full_path); |
send_notification(full_path); |