[Xfce4-commits] <xfce4-weather-plugin:master> Reformat source code: weather-translate

Harald Judt noreply at xfce.org
Thu Jul 26 16:12:11 CEST 2012


Updating branch refs/heads/master
         to 833dd0b6ec8b21e52b9f9223847e1765edc3c33c (commit)
       from d06db6157cdd49ee7116f5f75108143143fd0f32 (commit)

commit 833dd0b6ec8b21e52b9f9223847e1765edc3c33c
Author: Harald Judt <h.judt at gmx.at>
Date:   Thu Jul 26 16:10:30 2012 +0200

    Reformat source code: weather-translate

 panel-plugin/weather-translate.c |  283 +++++++++++++++++++-------------------
 panel-plugin/weather-translate.h |   13 +-
 2 files changed, 149 insertions(+), 147 deletions(-)

diff --git a/panel-plugin/weather-translate.c b/panel-plugin/weather-translate.c
index 7024afd..8ed986e 100644
--- a/panel-plugin/weather-translate.c
+++ b/panel-plugin/weather-translate.c
@@ -27,198 +27,197 @@
 #include "weather.h"
 #include "weather-translate.h"
 
-#define DAY_LOC_N  (sizeof(gchar) * 100)
+#define DAY_LOC_N (sizeof(gchar) * 100)
 
 
 static const gchar *wdirs[] = {
-  N_("S"),
-  N_("SSW"),
-  N_("SW"),
-  N_("WSW"),
-  N_("W"),
-  N_("WNW"),
-  N_("NW"),
-  N_("NNW"),
-  N_("N"),
-  N_("NNE"),
-  N_("NE"),
-  N_("ENE"),
-  N_("E"),
-  N_("ESE"),
-  N_("SE"),
-  N_("SSE"),
-  N_("CALM"),
-  NULL
+    N_("S"),
+    N_("SSW"),
+    N_("SW"),
+    N_("WSW"),
+    N_("W"),
+    N_("WNW"),
+    N_("NW"),
+    N_("NNW"),
+    N_("N"),
+    N_("NNE"),
+    N_("NE"),
+    N_("ENE"),
+    N_("E"),
+    N_("ESE"),
+    N_("SE"),
+    N_("SSE"),
+    N_("CALM"),
+    NULL
 };
 
 
 static const gchar *
-translate_str (const gchar **loc_strings,
-               const gchar  *str)
+translate_str(const gchar **loc_strings,
+              const gchar *str)
 {
-  gint  loc_string_len, str_len;
-  guint i;
+    gint loc_string_len, str_len;
+    guint i;
 
-  if (str == NULL)
-    return "?";
+    if (str == NULL)
+        return "?";
 
-  str_len = strlen (str);
+    str_len = strlen(str);
 
-  if (str_len < 1)
-    return "?";
+    if (str_len < 1)
+        return "?";
 
-  for (i = 0; loc_strings[i] != NULL; i++)
-    {
-      loc_string_len = strlen (loc_strings[i]);
+    for (i = 0; loc_strings[i] != NULL; i++) {
+        loc_string_len = strlen(loc_strings[i]);
 
-      if (str_len != loc_string_len)
-        continue;
+        if (str_len != loc_string_len)
+            continue;
 
-      if (str[0] != loc_strings[i][0])
-        continue;
+        if (str[0] != loc_strings[i][0])
+            continue;
 
-      if (!g_ascii_strncasecmp (loc_strings[i], str, str_len))
-        return _(loc_strings[i]);
+        if (!g_ascii_strncasecmp(loc_strings[i], str, str_len))
+            return _(loc_strings[i]);
     }
 
-  return str;
+    return str;
 }
 
 
 typedef struct {
-	gint id;
-	gchar *symbol;
-	gchar *desc;
-	gchar *night_desc;
+    gint id;
+    gchar *symbol;
+    gchar *desc;
+    gchar *night_desc;
 } SymbolToDesc;
+
 static const SymbolToDesc symbol_to_desc[] = {
-	{ 1, "SUN",                 N_("Sunny"),                     N_("Clear")		},
-	{ 2, "LIGHTCLOUD",          N_("Lightly cloudy"),            N_("Lightly cloudy")	},
-	{ 3, "PARTLYCLOUD",         N_("Partly cloudy"),             N_("Partly cloudy")	},
-	{ 4, "CLOUD",               N_("Cloudy"),                    N_("Cloudy")		},
-	{ 5, "LIGHTRAINSUN",	    N_("Sunny, rain showers"),       N_("Clear, rain showers") },
-	{ 6, "LIGHTRAINTHUNDERSUN", N_("Sunny, rain showers with thunder"),
-	                            N_("Clear, rain showers with thunder") },
-	{ 7, "SLEETSUN",            N_("Sunny, sleet"),              N_("Clear, sleet") },
-	{ 8, "SNOWSUN",             N_("Sunny, snow"),               N_("Clear, snow") },
-	{ 9, "LIGHTRAIN",           N_("Rain showers"),              N_("Rain showers") },
-	{ 10,"RAIN",                N_("Rain"),                      N_("Rain") },
-	{ 11,"RAINTHUNDER",         N_("Rain with thunder"),         N_("Rain with thunder") },
-	{ 12,"SLEET",               N_("Sleet"),                     N_("Sleet") },
-	{ 13,"SNOW",                N_("Snow"),                      N_("Snow") },
-	{ 14,"SNOWTHUNDER",         N_("Snow with thunder"),         N_("Snow with thunder") },
-	{ 15,"FOG",                 N_("Fog"),                       N_("Fog") },
-	{ 16,"SUN",                 N_("Sunny"),                     N_("Clear") },
-	{ 17,"LIGHTCLOUD",          N_("Lightly cloudy"),            N_("Lightly cloudy") },
-	{ 18,"LIGHTRAINSUN",        N_("Sunny, rain showers"),       N_("Clear, rain showers") },
-	{ 19,"SNOWSUN",             N_("Sunny, Snow"),               N_("Clear, Snow") },
-	{ 20,"SLEETSUNTHUNDER",     N_("Sunny, Sleet and thunder"),  N_("Clear, sleet and thunder") },
-	{ 21,"SNOWSUNTHUNDER",      N_("Sunny, Snow and thunder"),   N_("Clear, snow and thunder") },
-	{ 22,"LIGHTRAINTHUNDER",    N_("Rain showers with thunder"), N_("Rain showers with thunder") },
-	{ 23,"SLEETTHUNDER",        N_("Sleet and thunder"),         N_("Sleet and thunder") },
+    { 1, "SUN",                 N_("Sunny"),                     N_("Clear")		},
+    { 2, "LIGHTCLOUD",          N_("Lightly cloudy"),            N_("Lightly cloudy")	},
+    { 3, "PARTLYCLOUD",         N_("Partly cloudy"),             N_("Partly cloudy")	},
+    { 4, "CLOUD",               N_("Cloudy"),                    N_("Cloudy")		},
+    { 5, "LIGHTRAINSUN",        N_("Sunny, rain showers"),       N_("Clear, rain showers") },
+    { 6, "LIGHTRAINTHUNDERSUN", N_("Sunny, rain showers with thunder"),
+      N_("Clear, rain showers with thunder") },
+    { 7, "SLEETSUN",            N_("Sunny, sleet"),              N_("Clear, sleet") },
+    { 8, "SNOWSUN",             N_("Sunny, snow"),               N_("Clear, snow") },
+    { 9, "LIGHTRAIN",           N_("Rain showers"),              N_("Rain showers") },
+    { 10,"RAIN",                N_("Rain"),                      N_("Rain") },
+    { 11,"RAINTHUNDER",         N_("Rain with thunder"),         N_("Rain with thunder") },
+    { 12,"SLEET",               N_("Sleet"),                     N_("Sleet") },
+    { 13,"SNOW",                N_("Snow"),                      N_("Snow") },
+    { 14,"SNOWTHUNDER",         N_("Snow with thunder"),         N_("Snow with thunder") },
+    { 15,"FOG",                 N_("Fog"),                       N_("Fog") },
+    { 16,"SUN",                 N_("Sunny"),                     N_("Clear") },
+    { 17,"LIGHTCLOUD",          N_("Lightly cloudy"),            N_("Lightly cloudy") },
+    { 18,"LIGHTRAINSUN",        N_("Sunny, rain showers"),       N_("Clear, rain showers") },
+    { 19,"SNOWSUN",             N_("Sunny, Snow"),               N_("Clear, Snow") },
+    { 20,"SLEETSUNTHUNDER",     N_("Sunny, Sleet and thunder"),  N_("Clear, sleet and thunder") },
+    { 21,"SNOWSUNTHUNDER",      N_("Sunny, Snow and thunder"),   N_("Clear, snow and thunder") },
+    { 22,"LIGHTRAINTHUNDER",    N_("Rain showers with thunder"), N_("Rain showers with thunder") },
+    { 23,"SLEETTHUNDER",        N_("Sleet and thunder"),         N_("Sleet and thunder") },
 };
-#define NUM_SYMBOLS (sizeof(symbol_to_desc)/sizeof(symbol_to_desc[0]))
+
+#define NUM_SYMBOLS (sizeof(symbol_to_desc) / sizeof(symbol_to_desc[0]))
 
 
 const gchar *
-translate_desc (const gchar *desc, gboolean nighttime)
+translate_desc(const gchar *desc,
+               gboolean nighttime)
 {
-  int i;
-  for (i = 0; i < NUM_SYMBOLS; i++) {
-    if (!strcmp(desc, symbol_to_desc[i].symbol))
-      if (nighttime)
-        return _(symbol_to_desc[i].night_desc);
-      else
-        return _(symbol_to_desc[i].desc);
-  }
-  return desc;
+    int i;
+    for (i = 0; i < NUM_SYMBOLS; i++) {
+        if (!strcmp(desc, symbol_to_desc[i].symbol))
+            if (nighttime)
+                return _(symbol_to_desc[i].night_desc);
+            else
+                return _(symbol_to_desc[i].desc);
+    }
+    return desc;
 }
 
 
 gchar *
-translate_day (gint weekday)
+translate_day(gint weekday)
 {
-  struct tm    time_tm;
-  gchar       *day_loc;
-  int          len;
+    struct tm time_tm;
+    gchar *day_loc;
+    int len;
 
-  if (weekday < 0 || weekday > 6)
-    return NULL;
+    if (weekday < 0 || weekday > 6)
+        return NULL;
 
-  time_tm.tm_wday = weekday;
+    time_tm.tm_wday = weekday;
 
-  day_loc = g_malloc (DAY_LOC_N);
+    day_loc = g_malloc(DAY_LOC_N);
 
-  len = strftime (day_loc, DAY_LOC_N, "%A", &time_tm);
-  day_loc[len] = 0;
-  if (!g_utf8_validate(day_loc, -1, NULL)) {
-    gchar *utf8 = g_locale_to_utf8(day_loc, -1, NULL, NULL, NULL);
-    g_free(day_loc);
-    day_loc = utf8;
-  }
+    len = strftime(day_loc, DAY_LOC_N, "%A", &time_tm);
+    day_loc[len] = 0;
+    if (!g_utf8_validate(day_loc, -1, NULL)) {
+        gchar *utf8 = g_locale_to_utf8(day_loc, -1, NULL, NULL, NULL);
+        g_free(day_loc);
+        day_loc = utf8;
+    }
 
-  return day_loc;
+    return day_loc;
 }
 
 
 gchar *
-translate_wind_direction (const gchar *wdir)
+translate_wind_direction(const gchar *wdir)
 {
-  gint   wdir_len;
-  guint  i;
-  gchar *wdir_loc, *tmp;
-  gchar  wdir_i[2];
-
-  if (wdir == NULL || (wdir_len = strlen (wdir)) < 1)
-    return NULL;
-
-  if (strchr (wdir, '/'))        /* N/A */
-    return NULL;
-
-  /*
-   * If the direction code can be translated, then translated the
-   * whole code so that it can be correctly translated in CJK (and
-   * possibly Finnish).  If not, use the old behaviour where
-   * individual direction codes are successively translated.
-   */
-  if (g_ascii_strcasecmp (wdir, _(wdir)) != 0)
-    wdir_loc = g_strdup (_(wdir));
-  else
-    {
-      wdir_loc = g_strdup ("");
-      for (i = 0; i < strlen (wdir); i++)
-        {
-          wdir_i[0] = wdir[i];
-          wdir_i[1] = '\0';
-
-          tmp = g_strdup_printf ("%s%s", wdir_loc,
-                                 translate_str (wdirs, wdir_i));
-          g_free (wdir_loc);
-          wdir_loc = tmp;
+    gint wdir_len;
+    guint i;
+    gchar *wdir_loc, *tmp, wdir_i[2];
+
+    if (wdir == NULL || (wdir_len = strlen(wdir)) < 1)
+        return NULL;
+
+    if (strchr(wdir, '/'))        /* N/A */
+        return NULL;
+
+    /*
+     * If the direction can be translated, then translate the whole
+     * code so that it can be correctly translated to CJK (and
+     * possibly Finnish). If not, use the old behaviour where
+     * individual direction codes are successively translated.
+     */
+    if (g_ascii_strcasecmp(wdir, _(wdir)) != 0)
+        wdir_loc = g_strdup(_(wdir));
+    else {
+        wdir_loc = g_strdup("");
+        for (i = 0; i < strlen(wdir); i++) {
+            wdir_i[0] = wdir[i];
+            wdir_i[1] = '\0';
+
+            tmp = g_strdup_printf("%s%s", wdir_loc,
+                                  translate_str(wdirs, wdir_i));
+            g_free(wdir_loc);
+            wdir_loc = tmp;
         }
 
     }
 
-  return wdir_loc;
+    return wdir_loc;
 }
 
 
-/* calm or a number */
+/* Return "calm", "N/A" or a number */
 gchar *
-translate_wind_speed (xml_time    *timeslice,
-                      const gchar *wspeed,
-                      unit_systems unit_system)
+translate_wind_speed(xml_time *timeslice,
+                     const gchar *wspeed,
+                     unit_systems unit_system)
 {
-  gchar *wspeed_loc;
-
-  if (g_ascii_strcasecmp (wspeed, "calm") == 0)
-    wspeed_loc = g_strdup (_("calm"));
-  else if (g_ascii_strcasecmp (wspeed, "N/A") == 0)
-    wspeed_loc = g_strdup (_("N/A"));
-  else {
-    wspeed_loc =
-      g_strdup_printf ("%s %s", wspeed, get_unit (unit_system, WIND_SPEED));
-  }
-
-  return wspeed_loc;
+    gchar *wspeed_loc;
+
+    if (g_ascii_strcasecmp(wspeed, "calm") == 0)
+        wspeed_loc = g_strdup(_("calm"));
+    else if (g_ascii_strcasecmp(wspeed, "N/A") == 0)
+        wspeed_loc = g_strdup(_("N/A"));
+    else {
+        wspeed_loc =
+            g_strdup_printf("%s %s", wspeed, get_unit(unit_system, WIND_SPEED));
+    }
+
+    return wspeed_loc;
 }
diff --git a/panel-plugin/weather-translate.h b/panel-plugin/weather-translate.h
index e1703bd..6dd2b6f 100644
--- a/panel-plugin/weather-translate.h
+++ b/panel-plugin/weather-translate.h
@@ -1,5 +1,5 @@
 /*  Copyright (c) 2003-2007 Xfce Development Team
- * 
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
@@ -23,14 +23,17 @@
 
 G_BEGIN_DECLS
 
-const gchar *translate_desc (const gchar *, gboolean);
+const gchar *translate_desc(const gchar *desc,
+                            gboolean nighttime);
 
 /* these return a newly allocated string, that should be freed */
-gchar *translate_day (gint);
+gchar *translate_day(gint weekday);
 
-gchar *translate_wind_direction (const gchar *);
+gchar *translate_wind_direction(const gchar *wdir);
 
-gchar *translate_wind_speed (xml_time *, const gchar *, unit_systems);
+gchar *translate_wind_speed(xml_time *timeslice,
+                            const gchar *wspeed,
+                            unit_systems unit_system);
 
 G_END_DECLS
 


More information about the Xfce4-commits mailing list