Commit ce079c85 authored by Harald Judt's avatar Harald Judt

Cleanup: Declare functions static.

parent 6e8ad2ce
......@@ -195,7 +195,7 @@ make_label(void)
}
gchar *
static gchar *
sanitize_location_name(const gchar *location_name)
{
gchar *pos, *pos2, sane[LOC_NAME_MAX_LEN * 4];
......
......@@ -37,7 +37,7 @@
g_ascii_strtod(value, NULL)))
gboolean
static gboolean
has_timeslice(xml_weather *data,
time_t start_t,
time_t end_t)
......@@ -220,7 +220,7 @@ is_night_time(xml_astro *astro)
* Evening: 20:00-02:00
* Night: 02:00-08:00
*/
void
static void
get_daytime_interval(struct tm *start_tm,
struct tm *end_tm,
daytime dt)
......@@ -311,7 +311,7 @@ time_calc_day(struct tm time_tm,
* times. Shift maximum prev_hours_limit hours into the past and
* next_hours_limit hours into the future.
*/
xml_time *
static xml_time *
find_timeslice(xml_weather *data,
struct tm start_tm,
struct tm end_tm,
......@@ -353,7 +353,7 @@ find_timeslice(xml_weather *data,
* Find the timeslice with the shortest interval near the given start
* and end times
*/
xml_time *
static xml_time *
find_shortest_timeslice(xml_weather *data,
struct tm start_tm,
struct tm end_tm,
......@@ -398,7 +398,7 @@ find_shortest_timeslice(xml_weather *data,
* Take point and interval data and generate one combined timeslice
* that provides all information needed to present a forecast.
*/
xml_time *
static xml_time *
make_combined_timeslice(xml_time *point,
xml_time *interval)
{
......
......@@ -56,6 +56,182 @@ my_timegm(struct tm *tm)
}
xml_time *
get_timeslice(xml_weather *data,
time_t start_t,
time_t end_t)
{
guint i;
for (i = 0; i < data->num_timeslices; i++) {
if (data->timeslice[i]->start == start_t &&
data->timeslice[i]->end == end_t)
return data->timeslice[i];
}
if (data->num_timeslices == MAX_TIMESLICE - 1)
return NULL;
data->timeslice[data->num_timeslices] = g_slice_new0(xml_time);
data->timeslice[data->num_timeslices]->start = start_t;
data->timeslice[data->num_timeslices]->end = end_t;
data->num_timeslices++;
return data->timeslice[data->num_timeslices - 1];
}
static time_t
parse_xml_timestring(gchar *ts,
gchar *format) {
time_t t;
struct tm tm;
memset(&t, 0, sizeof(time_t));
if (G_UNLIKELY(ts == NULL))
return t;
/* standard format */
if (format == NULL)
format = "%Y-%m-%dT%H:%M:%SZ";
/* strptime needs an initialized struct, or unpredictable
* behaviour might occur */
memset(&tm, 0, sizeof(struct tm));
tm.tm_isdst = -1;
if (G_UNLIKELY(strptime(ts, format, &tm) == NULL))
return t;
t = my_timegm(&tm);
return t;
}
static void
parse_location(xmlNode *cur_node,
xml_location *loc)
{
xmlNode *child_node;
g_free(loc->altitude);
loc->altitude = PROP(cur_node, "altitude");
g_free(loc->latitude);
loc->latitude = PROP(cur_node, "latitude");
g_free(loc->longitude);
loc->longitude = PROP(cur_node, "longitude");
for (child_node = cur_node->children; child_node;
child_node = child_node->next) {
if (NODE_IS_TYPE(child_node, "temperature")) {
g_free(loc->temperature_unit);
g_free(loc->temperature_value);
loc->temperature_unit = PROP(child_node, "unit");
loc->temperature_value = PROP(child_node, "value");
}
if (NODE_IS_TYPE(child_node, "windDirection")) {
g_free(loc->wind_dir_deg);
g_free(loc->wind_dir_name);
loc->wind_dir_deg = PROP(child_node, "deg");
loc->wind_dir_name = PROP(child_node, "name");
}
if (NODE_IS_TYPE(child_node, "windSpeed")) {
g_free(loc->wind_speed_mps);
g_free(loc->wind_speed_beaufort);
loc->wind_speed_mps = PROP(child_node, "mps");
loc->wind_speed_beaufort = PROP(child_node, "beaufort");
}
if (NODE_IS_TYPE(child_node, "humidity")) {
g_free(loc->humidity_unit);
g_free(loc->humidity_value);
loc->humidity_unit = PROP(child_node, "unit");
loc->humidity_value = PROP(child_node, "value");
}
if (NODE_IS_TYPE(child_node, "pressure")) {
g_free(loc->pressure_unit);
g_free(loc->pressure_value);
loc->pressure_unit = PROP(child_node, "unit");
loc->pressure_value = PROP(child_node, "value");
}
if (NODE_IS_TYPE(child_node, "cloudiness")) {
g_free(loc->clouds_percent[CLOUDS_PERC_CLOUDINESS]);
loc->clouds_percent[CLOUDS_PERC_CLOUDINESS] = PROP(child_node, "percent");
}
if (NODE_IS_TYPE(child_node, "fog")) {
g_free(loc->fog_percent);
loc->fog_percent = PROP(child_node, "percent");
}
if (NODE_IS_TYPE(child_node, "lowClouds")) {
g_free(loc->clouds_percent[CLOUDS_PERC_LOW]);
loc->clouds_percent[CLOUDS_PERC_LOW] = PROP(child_node, "percent");
}
if (NODE_IS_TYPE(child_node, "mediumClouds")) {
g_free(loc->clouds_percent[CLOUDS_PERC_MED]);
loc->clouds_percent[CLOUDS_PERC_MED] = PROP(child_node, "percent");
}
if (NODE_IS_TYPE(child_node, "highClouds")) {
g_free(loc->clouds_percent[CLOUDS_PERC_HIGH]);
loc->clouds_percent[CLOUDS_PERC_HIGH] = PROP(child_node, "percent");
}
if (NODE_IS_TYPE(child_node, "precipitation")) {
g_free(loc->precipitation_unit);
g_free(loc->precipitation_value);
loc->precipitation_unit = PROP(child_node, "unit");
loc->precipitation_value = PROP(child_node, "value");
}
if (NODE_IS_TYPE(child_node, "symbol")) {
g_free(loc->symbol);
loc->symbol = PROP(child_node, "id");
loc->symbol_id = strtol(PROP(child_node, "number"), NULL, 10);
}
}
}
static void
parse_time(xmlNode *cur_node,
xml_weather *data)
{
gchar *datatype, *from, *to;
time_t start_t, end_t;
xml_time *timeslice;
xmlNode *child_node;
datatype = PROP(cur_node, "datatype");
if (xmlStrcasecmp(datatype, "forecast")) {
xmlFree(datatype);
return;
}
xmlFree(datatype);
from = PROP(cur_node, "from");
start_t = parse_xml_timestring(from, NULL);
xmlFree(from);
to = PROP(cur_node, "to");
end_t = parse_xml_timestring(to, NULL);
xmlFree(to);
if (G_UNLIKELY(!start_t || !end_t))
return;
timeslice = get_timeslice(data, start_t, end_t);
if (G_UNLIKELY(!timeslice)) {
g_warning("no timeslice");
return;
}
for (child_node = cur_node->children; child_node;
child_node = child_node->next)
if (G_LIKELY(NODE_IS_TYPE(child_node, "location"))) {
if (timeslice->location == NULL)
timeslice->location = g_slice_new0(xml_location);
parse_location(child_node, timeslice->location);
}
}
xml_weather *
parse_weather(xmlNode *cur_node)
{
......@@ -91,33 +267,7 @@ parse_weather(xmlNode *cur_node)
}
time_t
parse_xml_timestring(gchar *ts, gchar *format) {
time_t t;
struct tm tm;
memset(&t, 0, sizeof(time_t));
if (G_UNLIKELY(ts == NULL))
return t;
/* standard format */
if (format == NULL)
format = "%Y-%m-%dT%H:%M:%SZ";
/* strptime needs an initialized struct, or unpredictable
* behaviour might occur */
memset(&tm, 0, sizeof(struct tm));
tm.tm_isdst = -1;
if (G_UNLIKELY(strptime(ts, format, &tm) == NULL))
return t;
t = my_timegm(&tm);
return t;
}
void
static void
parse_astro_location(xmlNode *cur_node,
xml_astro *astro)
{
......@@ -222,155 +372,6 @@ parse_astro(xmlNode *cur_node)
}
void
parse_time(xmlNode *cur_node,
xml_weather *data)
{
gchar *datatype, *from, *to;
time_t start_t, end_t;
xml_time *timeslice;
xmlNode *child_node;
datatype = PROP(cur_node, "datatype");
if (xmlStrcasecmp(datatype, "forecast")) {
xmlFree(datatype);
return;
}
xmlFree(datatype);
from = PROP(cur_node, "from");
start_t = parse_xml_timestring(from, NULL);
xmlFree(from);
to = PROP(cur_node, "to");
end_t = parse_xml_timestring(to, NULL);
xmlFree(to);
if (G_UNLIKELY(!start_t || !end_t))
return;
timeslice = get_timeslice(data, start_t, end_t);
if (G_UNLIKELY(!timeslice)) {
g_warning("no timeslice");
return;
}
for (child_node = cur_node->children; child_node;
child_node = child_node->next)
if (G_LIKELY(NODE_IS_TYPE(child_node, "location"))) {
if (timeslice->location == NULL)
timeslice->location = g_slice_new0(xml_location);
parse_location(child_node, timeslice->location);
}
}
xml_time *
get_timeslice(xml_weather *data,
time_t start_t,
time_t end_t)
{
guint i;
for (i = 0; i < data->num_timeslices; i++) {
if (data->timeslice[i]->start == start_t &&
data->timeslice[i]->end == end_t)
return data->timeslice[i];
}
if (data->num_timeslices == MAX_TIMESLICE - 1)
return NULL;
data->timeslice[data->num_timeslices] = g_slice_new0(xml_time);
data->timeslice[data->num_timeslices]->start = start_t;
data->timeslice[data->num_timeslices]->end = end_t;
data->num_timeslices++;
return data->timeslice[data->num_timeslices - 1];
}
void
parse_location(xmlNode *cur_node,
xml_location *loc)
{
xmlNode *child_node;
g_free(loc->altitude);
loc->altitude = PROP(cur_node, "altitude");
g_free(loc->latitude);
loc->latitude = PROP(cur_node, "latitude");
g_free(loc->longitude);
loc->longitude = PROP(cur_node, "longitude");
for (child_node = cur_node->children; child_node;
child_node = child_node->next) {
if (NODE_IS_TYPE(child_node, "temperature")) {
g_free(loc->temperature_unit);
g_free(loc->temperature_value);
loc->temperature_unit = PROP(child_node, "unit");
loc->temperature_value = PROP(child_node, "value");
}
if (NODE_IS_TYPE(child_node, "windDirection")) {
g_free(loc->wind_dir_deg);
g_free(loc->wind_dir_name);
loc->wind_dir_deg = PROP(child_node, "deg");
loc->wind_dir_name = PROP(child_node, "name");
}
if (NODE_IS_TYPE(child_node, "windSpeed")) {
g_free(loc->wind_speed_mps);
g_free(loc->wind_speed_beaufort);
loc->wind_speed_mps = PROP(child_node, "mps");
loc->wind_speed_beaufort = PROP(child_node, "beaufort");
}
if (NODE_IS_TYPE(child_node, "humidity")) {
g_free(loc->humidity_unit);
g_free(loc->humidity_value);
loc->humidity_unit = PROP(child_node, "unit");
loc->humidity_value = PROP(child_node, "value");
}
if (NODE_IS_TYPE(child_node, "pressure")) {
g_free(loc->pressure_unit);
g_free(loc->pressure_value);
loc->pressure_unit = PROP(child_node, "unit");
loc->pressure_value = PROP(child_node, "value");
}
if (NODE_IS_TYPE(child_node, "cloudiness")) {
g_free(loc->clouds_percent[CLOUDS_PERC_CLOUDINESS]);
loc->clouds_percent[CLOUDS_PERC_CLOUDINESS] = PROP(child_node, "percent");
}
if (NODE_IS_TYPE(child_node, "fog")) {
g_free(loc->fog_percent);
loc->fog_percent = PROP(child_node, "percent");
}
if (NODE_IS_TYPE(child_node, "lowClouds")) {
g_free(loc->clouds_percent[CLOUDS_PERC_LOW]);
loc->clouds_percent[CLOUDS_PERC_LOW] = PROP(child_node, "percent");
}
if (NODE_IS_TYPE(child_node, "mediumClouds")) {
g_free(loc->clouds_percent[CLOUDS_PERC_MED]);
loc->clouds_percent[CLOUDS_PERC_MED] = PROP(child_node, "percent");
}
if (NODE_IS_TYPE(child_node, "highClouds")) {
g_free(loc->clouds_percent[CLOUDS_PERC_HIGH]);
loc->clouds_percent[CLOUDS_PERC_HIGH] = PROP(child_node, "percent");
}
if (NODE_IS_TYPE(child_node, "precipitation")) {
g_free(loc->precipitation_unit);
g_free(loc->precipitation_value);
loc->precipitation_unit = PROP(child_node, "unit");
loc->precipitation_value = PROP(child_node, "value");
}
if (NODE_IS_TYPE(child_node, "symbol")) {
g_free(loc->symbol);
loc->symbol = PROP(child_node, "id");
loc->symbol_id = strtol(PROP(child_node, "number"), NULL, 10);
}
}
}
static void
xml_location_free(xml_location *loc)
{
......@@ -402,6 +403,7 @@ xml_location_free(xml_location *loc)
loc = NULL;
}
void
xml_time_free(xml_time *timeslice)
{
......@@ -430,6 +432,7 @@ xml_weather_free(xml_weather *data)
data = NULL;
}
void
xml_astro_free(xml_astro *astro)
{
......
......@@ -103,12 +103,6 @@ xml_weather *parse_weather(xmlNode *cur_node);
xml_astro *parse_astro(xmlNode *cur_node);
void parse_time(xmlNode *cur_node,
xml_weather *data);
void parse_location(xmlNode *cur_node,
xml_location *location);
xml_time *get_timeslice(xml_weather *data,
time_t start_t,
time_t end_t);
......
......@@ -484,7 +484,7 @@ create_summary_tab(xfceweather_data *data)
}
GtkWidget *
static GtkWidget *
add_forecast_cell(GtkWidget *widget,
GdkColor *color)
{
......@@ -502,7 +502,7 @@ add_forecast_cell(GtkWidget *widget,
}
GtkWidget *
static GtkWidget *
add_forecast_header(gchar *text,
gdouble angle,
GdkColor *color)
......
......@@ -879,7 +879,7 @@ xfceweather_create_options(XfcePanelPlugin *plugin,
}
gchar *
static gchar *
weather_get_tooltip_text(xfceweather_data *data)
{
xml_time *conditions;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment