Description: Fix FTBFS with clang instead of GCC
Author: Alexander Ovchinnikov <sanek23994@gmail.com>
Bug-Debian: http://bugs.debian.org/758453
--- a/examples/hcal/hcal.c
+++ b/examples/hcal/hcal.c
@@ -677,13 +677,6 @@ void print_header_month_line_stdout( con
}
-/**************************************************
-* print column headings for days of weeks
-**************************************************/
-void print_header_dow_line_stdout( const int colorize )
-{
- int column;
-
void print_dow_column( int column )
{
if (hdate_is_hebrew_locale())
@@ -701,6 +694,13 @@ void print_header_dow_line_stdout( const
if (column != 7) printf (" ");
}
+/**************************************************
+* print column headings for days of weeks
+**************************************************/
+void print_header_dow_line_stdout( const int colorize )
+{
+ int column;
+
if (colorize) colorize_element(ELEMENT_WEEKDAY_NAMES);
for (column = 1; column < 7; column++) print_dow_column(column);
if (colorize) colorize_element(ELEMENT_SHABBAT_NAME);
@@ -1152,31 +1152,15 @@ void print_week( int jd, const int month
-/**************************************************
-* print month table
-*************************************************/
-int print_calendar ( const int current_month, const int current_year, const option_list opt)
-{
- hdate_struct h;
- int calendar_line;
- int max_calendar_lines = 4;
- /// the initializations on next line aren't truly necessary, but they do
- /// suppress warning "may be used uninitialized in this function [-Wmaybe-uninitialized]"
- int previous_month = 1, next_month = 1;
- int previous_year, next_year;
- /// the initializations on next line aren't truly necessary, but they do
- /// suppress warning "may be used uninitialized in this function [-Wmaybe-uninitialized]"
- int jd_current_month, jd_previous_month = 1, jd_next_month = 1;
-
- void how_many_calendar_lines( int month, int start_dow )
+void how_many_calendar_lines( int month, int start_dow, int *max_calendar_lines )
{
switch (month)
{
case 4:
case 6:
case 9:
- case 11: if (start_dow == 7) max_calendar_lines = 6;
- else if (max_calendar_lines == 4) max_calendar_lines = 5;
+ case 11: if (start_dow == 7) *max_calendar_lines = 6;
+ else if (*max_calendar_lines == 4) *max_calendar_lines = 5;
break;
case 1:
case 3:
@@ -1184,14 +1168,30 @@ int print_calendar ( const int current_m
case 7:
case 8:
case 10:
- case 12: if (start_dow > 5) max_calendar_lines = 6;
- else if (max_calendar_lines == 4) max_calendar_lines = 5;
+ case 12: if (start_dow > 5) *max_calendar_lines = 6;
+ else if (*max_calendar_lines == 4) *max_calendar_lines = 5;
break;
- case 2: if (start_dow > 1 && max_calendar_lines == 4) max_calendar_lines = 5;
+ case 2: if (start_dow > 1 && *max_calendar_lines == 4) *max_calendar_lines = 5;
break;
}
}
+/**************************************************
+* print month table
+*************************************************/
+int print_calendar ( const int current_month, const int current_year, const option_list opt)
+{
+ hdate_struct h;
+ int calendar_line;
+ int max_calendar_lines = 4;
+ /// the initializations on next line aren't truly necessary, but they do
+ /// suppress warning "may be used uninitialized in this function [-Wmaybe-uninitialized]"
+ int previous_month = 1, next_month = 1;
+ int previous_year, next_year;
+ /// the initializations on next line aren't truly necessary, but they do
+ /// suppress warning "may be used uninitialized in this function [-Wmaybe-uninitialized]"
+ int jd_current_month, jd_previous_month = 1, jd_next_month = 1;
+
/*********************************************************
* Preliminaries:
* - Find the first sunday(s) of each calendar
@@ -1199,7 +1199,7 @@ int print_calendar ( const int current_m
*********************************************************/
hdate_set_gdate (&h, 1, current_month, current_year);
jd_current_month = h.hd_jd - h.hd_dw + 1;
- how_many_calendar_lines( h.gd_mon, h.hd_dw );
+ how_many_calendar_lines( h.gd_mon, h.hd_dw, &max_calendar_lines );
/*********************************************************
* three months, side-by-side
@@ -1221,7 +1221,7 @@ int print_calendar ( const int current_m
}
hdate_set_gdate (&h, 1, previous_month, previous_year);
jd_previous_month = h.hd_jd - h.hd_dw + 1;
- how_many_calendar_lines( h.gd_mon, h.hd_dw );
+ how_many_calendar_lines( h.gd_mon, h.hd_dw, &max_calendar_lines );
/*********************************************************
* next month
@@ -1238,7 +1238,7 @@ int print_calendar ( const int current_m
}
hdate_set_gdate (&h, 1, next_month, next_year);
jd_next_month = h.hd_jd - h.hd_dw + 1;
- how_many_calendar_lines( h.gd_mon, h.hd_dw );
+ how_many_calendar_lines( h.gd_mon, h.hd_dw, &max_calendar_lines );
}
--- a/examples/hcal/local_functions.c
+++ b/examples/hcal/local_functions.c
@@ -645,62 +645,50 @@ file. Attempting to create a config file
}
-/************************************************************
-* Open config file, or create one
-* - returns filepointer or NULL
-* - if file does not exist, attempt to create it
-************************************************************/
-FILE* get_config_file( const char* config_dir_name,
- const char* config_file_name,
- const char* default_config_file_text )
-{
- size_t path_len;
-
- char* config_home_path_name = "";
- char* config_sub_path_name = "";
-
- char* config_dir_path;
- char* config_file_path;
-
- FILE* config_file;
/************************************************************
* sub-function to get_config_file: create_config_file
************************************************************/
- void create_config_file()
+ void create_config_file(FILE** config_file, char* config_file_path,
+ const char* default_config_file_text, const char* config_file_name)
{
- config_file = fopen(config_file_path, "a");
- if (config_file == NULL)
+ *config_file = fopen(config_file_path, "a");
+ if (*config_file == NULL)
{
error(0, errno, "%s: %s", N_("failure attempting to create config file"), config_file_path);
return;
}
- fprintf(config_file, "%s", default_config_file_text);
+ fprintf(*config_file, "%s", default_config_file_text);
error(0,0,"%s: %s",N_("config file created"), config_file_path);
- if (fclose(config_file) != 0) error(0,errno,"%s %s",N_("failure closing"),config_file_name);
+ if (fclose(*config_file) != 0) error(0,errno,"%s %s",N_("failure closing"),config_file_name);
}
/************************************************************
* sub-function to get_config_file: open_config_file
************************************************************/
- int open_config_file()
+ int open_config_file(FILE** config_file, char* config_file_path,
+ size_t *path_len, const char* config_home_path_name,
+ const char* config_sub_path_name, const char* config_dir_name,
+ const char* default_config_file_text, const char* config_file_name)
{
- config_file = fopen(config_file_path, "r");
- if (config_file == NULL)
+ char* config_dir_path;
+
+ *config_file = fopen(config_file_path, "r");
+ if (*config_file == NULL)
{
if (errno != ENOENT) return FALSE;
// maybe replace all this with a single line asprintf()
- path_len = strlen(config_home_path_name)
+ *path_len = strlen(config_home_path_name)
+ strlen(config_sub_path_name)
+ strlen(config_dir_name) +1;
- if (path_len < 1) return FALSE;
- config_dir_path = malloc(path_len);
+ if (*path_len < 1) return FALSE;
+ config_dir_path = malloc(*path_len);
if (config_dir_path == NULL)
{
error(0,errno,"%s",N_("memory allocation failure"));
return FALSE;
}
- snprintf(config_dir_path, path_len, "%s%s%s",
+ snprintf(config_dir_path, *path_len, "%s%s%s",
config_home_path_name, config_sub_path_name,
config_dir_name);
@@ -711,13 +699,30 @@ FILE* get_config_file( const char* confi
return FALSE;
}
greetings_to_version_16();
- create_config_file();
+ create_config_file(config_file, config_file_path, default_config_file_text, config_file_name);
free(config_dir_path);
return FALSE;
}
return TRUE;
}
+/************************************************************
+* Open config file, or create one
+* - returns filepointer or NULL
+* - if file does not exist, attempt to create it
+************************************************************/
+FILE* get_config_file( const char* config_dir_name,
+ const char* config_file_name,
+ const char* default_config_file_text )
+{
+ size_t path_len;
+
+ char* config_home_path_name = "";
+ char* config_sub_path_name = "";
+
+ char* config_file_path;
+
+ FILE* config_file;
/************************************************************
* main part of function get_config_file
@@ -749,7 +754,9 @@ FILE* get_config_file( const char* confi
config_home_path_name, config_sub_path_name,
config_dir_name, config_file_name);
- if (open_config_file() == TRUE)
+ if (open_config_file(&config_file, config_file_path, &path_len, config_home_path_name,
+ config_sub_path_name, config_dir_name,
+ default_config_file_text, config_file_name) == TRUE)
{
free(config_file_path);
return config_file;