afify / azan (public) (License: MIT) (since 2020-03-08) (hash sha1)
azan is a simple muslim prayers notifier for unix-like systems.
List of commits:
Subject Hash Author Date (UTC)
[refactor] add util, default no cache 54c57bbfcb384c42e82d8b9525a7ead2a6147a77 Hassan Afify 2020-03-07 18:33:07
[fix] Makefile portable, usage function 8c669507ed7eeccb3c47a3f908aa35c17b6527a8 Hassan Afify 2020-02-16 17:15:19
[fix] remove get_sunrise, fix splint warnings 0559e8624c71fd4c018650161eb2642a661ee9ef Hassan Afify 2019-10-07 18:57:57
[fix] Makefile default configuration a22ddc6853b16d2f269c27502d800a3b869eb328 Hassan Afify 2019-10-05 14:37:25
[fix] functions declaration missing const fb80f2f8b529debddc4af21d5c5994e33deb19bd Hassan Afify 2019-10-05 14:34:49
[refactor] Change variables to const ef8b891737823e8d584fa975c4d561a63801b3e4 Hassan Afify 2019-10-04 18:45:07
[refactor] function declaration parameter name bed4911ed9c5be310e710f945ed68d65228adba5 Hassan Afify 2019-10-04 18:57:40
[delete] sent presentation file 8166502f5dbfcf52d859b95d2fc069a6043ca756 Hassan Afify 2019-10-05 10:34:04
[update] Makefile b29c34f1d2ea1a5d48e649d68595772f1fbbc374 Hassan Afify 2019-10-04 19:03:58
[refactor] function declaration parameter name 4db440d3a9a86ae56d8f3f0196831ad7d699f77f Hassan Afify 2019-10-04 18:57:40
[refactor] Change variables to const 04d742ebb7431167d2f35512612d54b4375ff5f7 Hassan Afify 2019-10-04 18:45:07
[style] pointer asterisk position c47adc6974d903abf5ec68b73a828d788bfc4605 Hassan Afify 2019-10-04 13:32:18
[fix] testing branch Makefile configuration b683a683b7c003b333536e6a0a6e5b18fb8ef74d Hassan Afify 2019-10-04 14:41:18
[style] pointer asterisk position 684a938929a553d2c54049482e56521ea1d759b7 Hassan Afify 2019-10-04 13:32:18
[fix] option -a bug e645d6b8e355187aff53e9d77e717656996be61b Hassan Afify 2019-10-02 15:52:10
[fix] update config.def.h d70664ff8899be4120339a2578aeb555100601ab Hassan Afify 2019-10-01 19:55:21
[refactor] remove azan.h, upgrade functions 8d457954d6afea2679ad40a0c4874ef967c0f8a2 Hassan Afify 2019-10-01 19:13:58
[fix] Remove send-notification feature 982a2f0cdcbae2d5d95b83e1f33cbf19c5fae0f0 Hassan Afify 2019-09-30 15:35:55
[doc] update README and man page, remove .github 9f329d7a6433208b32b17b33f17527e306208b5b Hassan Afify 2019-09-30 06:39:56
Update issue templates 03092fd9858d1f42bc0c6a06eeed834be3f34c2b Hassan Afify 2019-09-28 15:45:11
Commit 54c57bbfcb384c42e82d8b9525a7ead2a6147a77 - [refactor] add util, default no cache
* replace print_all, print_next functions
- create get_all_prayers function
- merge print functions to handel:
- cache & runtime
- all prayers & next prayer

* clean main function
* remove duplicates
Author: Hassan Afify
Author date (UTC): 2020-03-07 18:33
Committer name: Hassan Afify
Committer date (UTC): 2020-03-07 18:33
Parent(s): 8c669507ed7eeccb3c47a3f908aa35c17b6527a8
Signing key: 4A65EF4E06D0E8BF
Tree: 5e70703ad159c7723665dc9dd87d2c3802a8db53
File Lines added Lines deleted
Makefile 1 1
README.md 3 3
azan.1 9 6
azan.c 170 157
config.def.h 9 9
util.c 50 0
util.h 10 0
File Makefile changed (mode: 100644) (index 0fb1560..4b1aa7b)
3 3
4 4 include config.mk include config.mk
5 5
6 SRC = azan.c
6 SRC = azan.c util.c
7 7 OBJ = ${SRC:.c=.o} OBJ = ${SRC:.c=.o}
8 8
9 9 all: options azan all: options azan
File README.md changed (mode: 100644) (index fec2900..22c9f6c)
... ... $ azan
18 18 Options Options
19 19 ------- -------
20 20 ```sh ```sh
21 $ azan [-vah]
21 $ azan [-vach]
22 22 $ man azan $ man azan
23 23 ``` ```
24 24
 
... ... and (re)compiling the source code.
30 30 Philosophy, Contribution & Code Style Philosophy, Contribution & Code Style
31 31 ------------------------------------- -------------------------------------
32 32 - [Contribution]. - [Contribution].
33 - <img src="https://suckless.org/logo.svg" width="13"/> [Philosophy].
34 - <img src="https://suckless.org/logo.svg" width="13"/> [Code Style].
33 - [Philosophy].
34 - [Code Style].
35 35
36 36 Ask Questions Ask Questions
37 37 ------------- -------------
File azan.1 changed (mode: 100644) (index 50de4aa..3bb84cb)
3 3 azan \- simple muslim prayer notifier azan \- simple muslim prayer notifier
4 4 .SH SYNOPSIS .SH SYNOPSIS
5 5 .B azan .B azan
6 .RB [ \-vah ]
6 .RB [ \-achv ]
7 7 .SH DESCRIPTION .SH DESCRIPTION
8 8 azan is a simple muslim prayers notifier for unix-like systems. Show prayers time. azan is a simple muslim prayers notifier for unix-like systems. Show prayers time.
9 9 .P .P
10 10 azan is used for status bars. azan is used for status bars.
11 11 .SH OPTIONS .SH OPTIONS
12 12 .TP .TP
13 .B \-v
14 prints version information to standard output, then exits.
15 .TP
16 13 .B \-a .B \-a
17 prints todays's prayers time.
14 print all prayers time.
15 .TP
16 .B \-c
17 use cache file.
18 18 .TP .TP
19 19 .B \-h .B \-h
20 prints usage help.
20 print usage help.
21 .TP
22 .B \-v
23 print version information to standard output, then exits.
21 24 .SH USAGE .SH USAGE
22 25 .TP .TP
23 26 .B azan .B azan
File azan.c changed (mode: 100644) (index 3160ed5..753baf6)
4 4 * print next prayer left duration or today's all prayers. * print next prayer left duration or today's all prayers.
5 5 */ */
6 6
7 #include <time.h>
7 #include <math.h>
8 8 #include <stdio.h> #include <stdio.h>
9 9 #include <stdlib.h> #include <stdlib.h>
10 #include <math.h>
11 10 #include <string.h> #include <string.h>
12 #include <getopt.h>
13 #if defined (__linux__) || (__OpenBSD__)
14 #include <unistd.h>
15 #include <sys/types.h>
16 11 #include <sys/stat.h> #include <sys/stat.h>
17 #endif
12 #include <sys/types.h>
13 #include <time.h>
14 #include <unistd.h>
18 15
19 16 #include "config.h" #include "config.h"
20
21 /* macros */
22 #define FAIL_IF(EXP, MSG) {if(EXP){printf("%s [LINE %d]\n", MSG, __LINE__);\
23 exit(EXIT_FAILURE);}}
17 #include "util.h"
24 18
25 19 /* function declarations */ /* function declarations */
26 20 static void usage(void); static void usage(void);
 
... ... static const double get_maghrib(const double, const double);
42 36 static const double get_isha(const double, const double, const double); static const double get_isha(const double, const double, const double);
43 37 static int file_exist(const char*); static int file_exist(const char*);
44 38 static int create_cache_file(const time_t, const char*); static int create_cache_file(const time_t, const char*);
45 static time_t *read_azan_cache_file(const char*);
46 static int print_next_prayer(const time_t, const char*);
47 static int print_all_prayers(const char*);
48 39 static char *get_cache_file_name(const time_t); static char *get_cache_file_name(const time_t);
40 static time_t *read_azan_cache_file(const char*);
41 static time_t *get_all_prayers(const time_t);
42 static int print_p(const char, const char);
49 43
50 44 /* function implementations */ /* function implementations */
51 45 static void static void
 
... ... static char
91 85 { {
92 86 char *result; char *result;
93 87 size_t result_size = (size_t)32; size_t result_size = (size_t)32;
94 result = calloc(result_size, sizeof(char));
95 FAIL_IF(result == NULL, "[Error] allocating memory.");
88 result = ecalloc(result_size, sizeof(char));
96 89 struct tm new_time = *localtime(&input_time); struct tm new_time = *localtime(&input_time);
97 90 (void) snprintf(result, result_size, "%.2d:%.2d", (void) snprintf(result, result_size, "%.2d:%.2d",
98 91 new_time.tm_hour, new_time.tm_min); new_time.tm_hour, new_time.tm_min);
 
... ... static char
104 97 { {
105 98 char *result; char *result;
106 99 size_t result_size = (size_t)32; size_t result_size = (size_t)32;
107 result = calloc(result_size, sizeof(char));
108 FAIL_IF(result == NULL, "[Error] allocating memory.");
100 result = ecalloc(result_size, sizeof(char));
109 101 int hours,minutes; int hours,minutes;
110 102 int remaining_seconds; int remaining_seconds;
111 103 int seconds_in_hour = 60 * 60; int seconds_in_hour = 60 * 60;
 
... ... get_isha(const double duhr, const double maghrib, const double D)
285 277 } else if (is_ramadan == 1){ } else if (is_ramadan == 1){
286 278 isha = maghrib + 120.0 * one_min; isha = maghrib + 120.0 * one_min;
287 279
288 /* Use isha_angle */
280 /* Use isha_angle */
289 281 } else { } else {
290 282 isha = duhr + T(isha_angle, D); isha = duhr + T(isha_angle, D);
291 283 } }
 
... ... file_exist(const char *filename)
307 299 } }
308 300
309 301 static int static int
310 create_cache_file(const time_t t, const char *full_path)
302 create_cache_file(const time_t current_time, const char *full_path)
303 {
304 /* Create Cache File if doesn't exists'*/
305 if (file_exist(full_path) == 0){
306 return 0;
307 }
308
309 time_t *azan_array;
310 azan_array = get_all_prayers(current_time);
311 FAIL_IF(azan_array == NULL, "[Error] reading array.");
312
313 /* Create cache file */
314 FILE *fpointer;
315 fpointer = fopen(full_path, "w");
316 /* Change permission to read only*/
317 /* chmod(full_path, 00400); */
318 FAIL_IF(fpointer == NULL, "[Error] opening lp cache file.");
319
320 fprintf(fpointer, "%ld\n%ld\n%ld\n%ld\n%ld\n%ld",
321 (long)azan_array[0],
322 (long)azan_array[1],
323 (long)azan_array[2],
324 (long)azan_array[3],
325 (long)azan_array[4],
326 (long)azan_array[5]
327 );
328
329 (void)fclose(fpointer);
330 free(azan_array);
331 azan_array = NULL;
332 return 0;
333 }
334
335 static char
336 *get_cache_file_name(const time_t t)
311 337 { {
312 338 /* Current date time */ /* Current date time */
313 339 const struct tm current_date = *localtime(&t); const struct tm current_date = *localtime(&t);
 
... ... create_cache_file(const time_t t, const char *full_path)
315 341 const int month = current_date.tm_mon + 1; const int month = current_date.tm_mon + 1;
316 342 const int year = current_date.tm_year + 1900; const int year = current_date.tm_year + 1900;
317 343
318 /* Create Cache File if doesn't exists'*/
319 if (file_exist(full_path) < 0){
320
321 /* Equation of Time */
322 const double julian_date = convert_gregorian_to_julian(
323 year, month, day);
324 double D = 0.0;
325 const double equation_of_time = get_equation_time(julian_date, &D);
326
327 /* Today's Prayers time */
328 const double duhr = get_duhr(equation_of_time);
329 const double fajr = get_fajr(duhr, D);
330 const double maghrib = get_maghrib(duhr, D);
331 const double isha = get_isha(duhr, maghrib, D);
332 const double asr = get_asr(duhr, D);
333
334 /* Convert prayer times to unix timestamp */
335 time_t prayer_array[6];
336 prayer_array[0] = convert_today_double_to_timet(fajr, day);
337 prayer_array[1] = convert_today_double_to_timet(duhr, day);
338 prayer_array[2] = convert_today_double_to_timet(asr, day);
339 prayer_array[3] = convert_today_double_to_timet(maghrib, day);
340 prayer_array[4] = convert_today_double_to_timet(isha, day);
341 prayer_array[5] = convert_today_double_to_timet(fajr, day+1);
342
343 /* Create cache file */
344 FILE *fpointer;
345 fpointer = fopen(full_path, "w");
346 /* Change permission to read only*/
347 // chmod(full_path, 00400);
348 FAIL_IF(fpointer == NULL, "[Error] opening lp cache file.");
349
350 fprintf(fpointer, "%ld\n%ld\n%ld\n%ld\n%ld\n%ld",
351 (long)prayer_array[0],
352 (long)prayer_array[1],
353 (long)prayer_array[2],
354 (long)prayer_array[3],
355 (long)prayer_array[4],
356 (long)prayer_array[5]
357 );
358
359 (void)fclose(fpointer);
360 }
344 const size_t max_file_name = (size_t)128;
345 char azan_cache_file[128];
361 346
362 return 0;
347 (void)snprintf(azan_cache_file, max_file_name, "azan_%.2i-%.2i-%i.txt",
348 day, month, year);
349
350 char *full_path = ecalloc(max_file_name, sizeof(char));
351 strcpy(full_path, cache_dir);
352 strcat(full_path, "/");
353 strcat(full_path, azan_cache_file);
354
355 return full_path;
363 356 } }
364 357
365 358 static time_t static time_t
 
... ... static time_t
370 363
371 364 time_t *pray_times_array; /* the returned array */ time_t *pray_times_array; /* the returned array */
372 365 size_t pray_times_array_size = (size_t)6; size_t pray_times_array_size = (size_t)6;
373 pray_times_array = calloc(pray_times_array_size, sizeof(time_t));
374 FAIL_IF(pray_times_array == NULL, "[Error] allocating memory.");
366 pray_times_array = ecalloc(pray_times_array_size, sizeof(time_t));
375 367 char *tmp_pray[6]; /* string array hold temp values for checking */ char *tmp_pray[6]; /* string array hold temp values for checking */
376 368
377 /* To fix splint warning Returned storage not completely defined */
378 pray_times_array[0] = 0;
379
380 /* Read the cache file */
369 /* Read the cache file */
381 370 fp = fopen(azan_cache_file,"r"); fp = fopen(azan_cache_file,"r");
382 371 FAIL_IF(fp == NULL, "[Error] opening azan cache file."); FAIL_IF(fp == NULL, "[Error] opening azan cache file.");
383 372
 
... ... static time_t
395 384 return pray_times_array; return pray_times_array;
396 385 } }
397 386
398 static int
399 print_next_prayer(const time_t current_time, const char *azan_cache_file)
387 static time_t
388 *get_all_prayers(const time_t t)
400 389 { {
401 time_t *azan_array;
402 azan_array = read_azan_cache_file(azan_cache_file);
403 FAIL_IF(azan_array == NULL, "[Error] reading array.");
390 time_t *prayer_array; /* the returned array */
391 size_t prayer_array_size= (size_t)6;
392 prayer_array = ecalloc(prayer_array_size, sizeof(time_t));
404 393
405 for (int i=0; i<6; i++) {
406 if (azan_array[i] > current_time){
407 double left_seconds = difftime(azan_array[i], current_time);
408 char prayer_first_letter = convert_prayer_int_to_char(i);
409 char *left_duration = convert_sec_double_to_min_hour(left_seconds);
410 printf("%c %s\n", prayer_first_letter, left_duration);
411 free(left_duration);
412 break; /* Print first prayer only */
413 }
414 }
394 /* Current date time */
395 const struct tm current_date = *localtime(&t);
396 const int day = current_date.tm_mday;
397 const int month = current_date.tm_mon + 1;
398 const int year = current_date.tm_year + 1900;
415 399
416 free(azan_array);
417 azan_array = NULL;
418 return 0;
400 /* Equation of Time */
401 const double julian_date = convert_gregorian_to_julian(
402 year, month, day);
403 double D = 0.0;
404 const double equation_of_time = get_equation_time(julian_date, &D);
405
406 /* Today's Prayers time */
407 const double duhr = get_duhr(equation_of_time);
408 const double fajr = get_fajr(duhr, D);
409 const double maghrib = get_maghrib(duhr, D);
410 const double isha = get_isha(duhr, maghrib, D);
411 const double asr = get_asr(duhr, D);
412
413 /* Convert prayer times to unix timestamp */
414 /* time_t prayer_array[6]; */
415 prayer_array[0] = convert_today_double_to_timet(fajr, day);
416 prayer_array[1] = convert_today_double_to_timet(duhr, day);
417 prayer_array[2] = convert_today_double_to_timet(asr, day);
418 prayer_array[3] = convert_today_double_to_timet(maghrib, day);
419 prayer_array[4] = convert_today_double_to_timet(isha, day);
420 prayer_array[5] = convert_today_double_to_timet(fajr, day+1);
421
422 /* printf("%ld\n%ld\n%ld\n%ld\n%ld\n%ld\n",
423 // (long)prayer_array[0],
424 // (long)prayer_array[1],
425 // (long)prayer_array[2],
426 // (long)prayer_array[3],
427 // (long)prayer_array[4],
428 // (long)prayer_array[5]
429 );
430 */
431
432 FAIL_IF(prayer_array == NULL, "[Error] pray_times_array is NULL.");
433 return prayer_array;
419 434 } }
420 435
421 436 static int static int
422 print_all_prayers(const char *azan_cache_file)
437 print_p(const char print_m, const char cache_m)
423 438 { {
439 /*
440 * print_m: [n] next prayer, [a] all prayers
441 * cache_m: [r] runtime, [c] use cache file
442 */
443
444 const time_t current_time = time(NULL);
424 445 time_t *azan_array; time_t *azan_array;
425 azan_array = read_azan_cache_file(azan_cache_file);
426 FAIL_IF(azan_array == NULL, "[Error] reading array.");
446 char *prayer_time;
447 char *left_duration;
448 char *azan_cache_file;
449 char prayer_first_letter;
450 double left_seconds;
451
452 switch (cache_m) {
453 case 'r': /* runtime, no caching */
454 azan_array = get_all_prayers(current_time);
455 FAIL_IF(azan_array == NULL, "[Error] reading array.");
456 break;
457
458 case 'c': /* use cache file */
459 /* Create cache file if not exists */
460 azan_cache_file = get_cache_file_name(current_time);
461 FAIL_IF(create_cache_file(current_time, azan_cache_file) < 0,
462 "[Error] creating Cache File.");
463 azan_array = read_azan_cache_file(azan_cache_file);
464 FAIL_IF(azan_array == NULL, "[Error] reading array.");
465 free(azan_cache_file);
466 azan_cache_file = NULL;
467 break;
468 }
427 469
428 for (int i=0; i<5; i++) {
429 // convert_timet_to_str;
430 const char prayer_first_letter = convert_prayer_int_to_char(i);
431 char *prayer_time = convert_timet_to_str(azan_array[i]);
432 printf("%c %s\n", prayer_first_letter, prayer_time);
433 free(prayer_time);
470 switch (print_m) {
471 case 'a': /* print all prayers time */
472 for (int i=0; i<5; i++) {
473 prayer_first_letter = convert_prayer_int_to_char(i);
474 prayer_time = convert_timet_to_str(azan_array[i]);
475 printf("%c %s\n", prayer_first_letter, prayer_time);
476 free(prayer_time);
477 prayer_time = NULL;
478 }
479 break;
480 case 'n': /* print next prayer left duration */
481 for (int i=0; i<6; i++) {
482 if (azan_array[i] > current_time){
483 left_seconds = difftime(azan_array[i], current_time);
484 prayer_first_letter = convert_prayer_int_to_char(i);
485 left_duration = convert_sec_double_to_min_hour(left_seconds);
486 printf("%c %s\n", prayer_first_letter, left_duration);
487 free(left_duration);
488 left_duration = NULL;
489 break; /* Print first prayer only */
490 }
491 }
492 break;
434 493 } }
435 494
436 495 free(azan_array); free(azan_array);
496 azan_array = NULL;
437 497 return 0; return 0;
438 }
439
440 static char
441 *get_cache_file_name(const time_t t)
442 {
443 /* Current date time */
444 const struct tm current_date = *localtime(&t);
445 const int day = current_date.tm_mday;
446 const int month = current_date.tm_mon + 1;
447 const int year = current_date.tm_year + 1900;
448
449 const size_t max_file_name = (size_t)128;
450 char azan_cache_file[128];
451
452 (void)snprintf(azan_cache_file, max_file_name, "azan_%.2i-%.2i-%i.txt",
453 day, month, year);
454 498
455 char *full_path = calloc(max_file_name, sizeof(char));
456 FAIL_IF(full_path == NULL,"[Error] reading array.");
457 strcpy(full_path, cache_dir);
458 strcat(full_path, "/");
459 strcat(full_path, azan_cache_file);
460
461 return full_path;
462 499 } }
463 500
464 501 int int
465 502 main(int argc, char *argv[]) main(int argc, char *argv[])
466 503 { {
467 /* Handel Arguments */
468 const int c = getopt(argc, argv, "vah");
469 const time_t t = time(NULL);
470 char *full_path = get_cache_file_name(t);
471
472 if (argc > 1) {
473 switch (c) {
474 case 'v':
504 if (argc == 1) {
505 FAIL_IF(print_p('n', 'r') < 0, "Error Calculating.\n");
506
507 } else if (argc > 1) {
508 if (strcmp("-v", argv[1]) == 0){
475 509 (void)puts("azan-"VERSION); (void)puts("azan-"VERSION);
476 break;
477 case 'a':
478 FAIL_IF(create_cache_file(t, full_path) < 0,
479 "[Error] Creating Cache File.");
480 FAIL_IF(print_all_prayers(full_path) < 0,
481 "[Error] print_all_prayers().");
482 break;
483 case 'h':
484 usage();
485 break;
486 default:
510
511 } else if (strcmp("-h", argv[1]) == 0){
487 512 usage(); usage();
488 }
489 513
490 /* No Argument */
491 } else {
514 } else if (strcmp("-a", argv[1]) == 0){
515 FAIL_IF(print_p('a', 'r') < 0, "Error Calculating.\n");
492 516
493 /* Create cache file if not exists */
494 if (create_cache_file(t, full_path) < 0) {
495 printf("Error Creating Cache File\n");
496 free(full_path);
497 full_path = NULL;
498 return -1;
499 }
517 } else if (strcmp("-c", argv[1]) == 0){
518 FAIL_IF(print_p('n', 'c') < 0, "Error Reading Cache File\n");
500 519
501 /* Read cache file */
502 if (print_next_prayer(t, full_path) < 0){
503 printf("Error Reading Cache File\n");
504 free(full_path);
505 full_path = NULL;
506 return -1;
520 } else if (strcmp("-ca", argv[1]) == 0 || strcmp("-ac", argv[1]) == 0){
521 FAIL_IF(print_p('a', 'c') < 0, "[Error] print_all_prayers().");
507 522 } }
508 523 } }
509 free(full_path);
510 full_path = NULL;
511 524 return 0; return 0;
512 525 } }
File config.def.h changed (mode: 100644) (index 58a8aa8..6c31702)
... ... static const double altitude = 0.0;
18 18 static const int use_umm_al_qura = 1; static const int use_umm_al_qura = 1;
19 19 static const int is_ramadan = 0; static const int is_ramadan = 0;
20 20 static const double fajr_angle = 18.0; static const double fajr_angle = 18.0;
21 static const double isha_angle = 18.0;
21 static const double isha_angle = 17.0; /* used if use_umm_al_qura = 0 */
22 22
23 23 /* Asr */ /* Asr */
24 static const int use_major = 1;
24 static const int use_major = 1; /* use hanafi if 0 */
25 25
26 26 /* /*
27 Muslim World League 18 17
28 Islamic Society of North America (ISNA) 15 15
29 Egyptian General Authority of Survey 19.5 17.5
30 Umm al-Qura University, Makkah 18.5 90 min after Maghrib 120 Ramadan
31 University of Islamic Sciences, Karachi 18 18
32 Institute of Geophysics, University of Tehran 17.7 14*
33 Shia Ithna Ashari, Leva Research Institute, Qum 16 14
27 Muslim World League 18 17
28 Umm al-Qura University, Makkah 18.5 90 min after Maghrib (120 Ramadan)
29 Egyptian General Authority of Survey 19.5 17.5
30 Islamic Society of North America (ISNA) 15 15
31 University of Islamic Sciences, Karachi 18 18
32 Institute of Geophysics, University of Tehran 17.7 14*
33 Shia Ithna Ashari, Leva Research Institute, Qum 16 14
34 34 */ */
35 35
36 36 #endif /* CONFIG_H */ #endif /* CONFIG_H */
File util.c added (mode: 100644) (index 0000000..105a863)
1 /* See LICENSE file for copyright and license details. */
2 #include <stdarg.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 #include "util.h"
8
9 void *
10 ecalloc(size_t nmemb, size_t size)
11 {
12 void *p;
13
14 if (!(p = calloc(nmemb, size)))
15 die("calloc:");
16 return p;
17
18
19 // void *p;
20 // p = calloc(nmemb, size);
21 // if (p == NULL){
22 // die("calloc:");
23 // exit(EXIT_FAILURE);
24 // }
25 // return p;
26
27
28
29
30
31 }
32
33 void
34 die(const char *fmt, ...)
35 {
36 va_list ap;
37
38 va_start(ap, fmt);
39 (void)vfprintf(stderr, fmt, ap);
40 va_end(ap);
41
42 if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
43 (void)fputc(' ', stderr);
44 perror(NULL);
45 } else {
46 (void)fputc('\n', stderr);
47 }
48
49 exit(EXIT_FAILURE);
50 }
File util.h added (mode: 100644) (index 0000000..2653353)
1 /* See LICENSE file for copyright and license details. */
2
3 #define MAX(A, B) ((A) > (B) ? (A) : (B))
4 #define MIN(A, B) ((A) < (B) ? (A) : (B))
5 #define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B))
6 #define FAIL_IF(EXP, MSG) {if(EXP){fprintf(stderr, "[\033[31mFAILED %d\033[0m] %s\n", __LINE__, MSG);exit(EXIT_FAILURE);}}
7 #define WARN(EXP, MSG) {if(EXP){printf("[\033[33mWARN %d\033[0m] %s\n", __LINE__, MSG);return -1;}}
8
9 void die(const char *fmt, ...);
10 void *ecalloc(size_t nmemb, size_t size);
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/afify/azan

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/afify/azan

Clone this repository using git:
git clone git://git.rocketgit.com/user/afify/azan

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main