Enlightenment CVS committal

Author  : sebastid
Project : e17
Module  : apps/e

Dir     : e17/apps/e/src/modules/temperature


Modified Files:
        e_mod_main.c e_mod_main.h 


Log Message:
E-codingstyle
Fix memleak

===================================================================
RCS file: 
/cvsroot/enlightenment/e17/apps/e/src/modules/temperature/e_mod_main.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -3 -r1.33 -r1.34
--- e_mod_main.c        15 Sep 2005 09:48:18 -0000      1.33
+++ e_mod_main.c        20 Sep 2005 18:16:33 -0000      1.34
@@ -135,7 +135,7 @@
    E_CONFIG_VAL(D, T, high, INT);
    E_CONFIG_LIST(D, T, faces, conf_face_edd);
    E_CONFIG_VAL(D, T, sensor_name, STR);
-   E_CONFIG_VAL(D,T,units,INT);
+   E_CONFIG_VAL(D, T, units, INT);
 
    e->conf = e_config_domain_load("module.temperature", conf_edd);
    if (!e->conf)
@@ -144,13 +144,13 @@
        e->conf->poll_time = 10.0;
        e->conf->low = 30;
        e->conf->high = 80;
-        e->conf->sensor_name = "temp1";
-       e->conf->units = celcius;
+       e->conf->sensor_name = "temp1";
+       e->conf->units = CELCIUS;
      }
    E_CONFIG_LIMIT(e->conf->poll_time, 0.5, 1000.0);
    E_CONFIG_LIMIT(e->conf->low, 0, 100);
    E_CONFIG_LIMIT(e->conf->high, 0, 220);
-   E_CONFIG_LIMIT(e->conf->units, 0, 1);
+   E_CONFIG_LIMIT(e->conf->units, CELCIUS, FAHRENHEIT);
 
    _temperature_config_menu_new(e);
    e->have_temp = -1;
@@ -317,7 +317,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->low = (10 + (30*(e->conf->units)));
+   e->conf->low = (10 + (30 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -328,7 +328,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->low = (20 + (40*(e->conf->units)));
+   e->conf->low = (20 + (40 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -339,7 +339,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->low = (30 + (50*(e->conf->units)));
+   e->conf->low = (30 + (50 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -350,7 +350,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->low = (40 + (60*(e->conf->units)));
+   e->conf->low = (40 + (60 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -361,7 +361,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->low = (50 + (70*(e->conf->units)));
+   e->conf->low = (50 + (70 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -372,7 +372,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->high = (20 + (40*(e->conf->units)));
+   e->conf->high = (20 + (40 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -383,7 +383,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->high = (30 + (50*(e->conf->units)));
+   e->conf->high = (30 + (50 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -394,7 +394,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->high = (40 + (60*(e->conf->units)));
+   e->conf->high = (40 + (60 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -405,7 +405,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->high = (50 + (70*(e->conf->units)));
+   e->conf->high = (50 + (70 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -416,7 +416,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->high = (60 + (80*(e->conf->units)));
+   e->conf->high = (60 + (80 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -427,7 +427,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->high = (70 + (90*(e->conf->units)));
+   e->conf->high = (70 + (90 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -438,7 +438,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->high = (80 + (100*(e->conf->units)));
+   e->conf->high = (80 + (100 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -449,7 +449,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->high = (90 + (120*(e->conf->units)));
+   e->conf->high = (90 + (120 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -460,7 +460,7 @@
    Temperature *e;
 
    e = data;
-   e->conf->high = (100 + (140*(e->conf->units)));
+   e->conf->high = (100 + (140 * e->conf->units));
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -504,7 +504,7 @@
    Temperature *e;
        
    e = data;   
-   e->conf->units = fahrenheit;
+   e->conf->units = FAHRENHEIT;
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -515,7 +515,7 @@
    Temperature *e;
 
    e = data;   
-   e->conf->units = celcius;
+   e->conf->units = CELCIUS;
    _temperature_cb_check(e);
    e_config_save_queue();
 }
@@ -526,35 +526,32 @@
    E_Menu *mn;
    E_Menu_Item *mi;
        
+   int i;
    char* unit_str[10];
    int unit_int[10];
        
-   if(e->conf->units == fahrenheit) 
-   {
-       int i;
+   if (e->conf->units == FAHRENHEIT) 
+     {
        char s[6];
-       
-       for(i=0; i < 10; ++i)
-        {
-          unit_int[i] = ((i+2)*20);
-          sprintf(s, "%u F", unit_int[i]);
-          unit_str[i] = calloc(strlen(s)+1, sizeof(char));
-          strcpy(unit_str[i], s);
-       }      
-   }
-   else if(e->conf->units == celcius)  
-   {
-       int i;
+
+       for (i = 0; i < 10; i++)
+         {
+            unit_int[i] = (i + 2) * 20;
+            sprintf(s, "%u F", unit_int[i]);
+            unit_str[i] = strdup(s);
+         }      
+     }
+   else if (e->conf->units == CELCIUS) 
+     {
        char s[6];
-       
-       for(i=0; i < 10; ++i)
-       {
-          unit_int[i] = ((i+1)*10);
-          sprintf(s, "%u C", unit_int[i]);
-          unit_str[i] = calloc(strlen(s)+1, sizeof(char));
-          strcpy(unit_str[i], s);
-       }
-   }
+
+       for (i = 0; i < 10; i++)
+         {
+            unit_int[i] = (i + 1) * 10;
+            sprintf(s, "%u C", unit_int[i]);
+            unit_str[i] = strdup(s);
+         }
+     }
    
    /* Low temperature */
    mn = e_menu_new();
@@ -663,6 +660,11 @@
    e_menu_item_callback_set(mi, _temperature_menu_high_100, e);
 
    e->config_menu_high = mn;
+
+   for (i = 0; i < 10; i++)
+     {
+       free(unit_str[i]);
+     }
 }
 
 static void
@@ -720,14 +722,14 @@
    e_menu_item_label_set(mi, _("Fahrenheit"));
    e_menu_item_radio_set(mi, 1);
    e_menu_item_radio_group_set(mi, 1);
-   if (e->conf->units == fahrenheit) e_menu_item_toggle_set(mi, 1);
+   if (e->conf->units == FAHRENHEIT) e_menu_item_toggle_set(mi, 1);
    e_menu_item_callback_set(mi, _temperature_menu_unit_fahrenheit, e);
 
    mi = e_menu_item_new(mn);
    e_menu_item_label_set(mi, _("Celcius"));
    e_menu_item_radio_set(mi, 1);
    e_menu_item_radio_group_set(mi, 1);
-   if (e->conf->units == celcius) e_menu_item_toggle_set(mi, 1);
+   if (e->conf->units == CELCIUS) e_menu_item_toggle_set(mi, 1);
    e_menu_item_callback_set(mi, _temperature_menu_unit_celcius, e);
    
    e->config_menu_unit = mn;
@@ -808,14 +810,6 @@
      }
 
    e->config_menu = mn;
-     
-/*   int i,j;
-   
-   for(i=0; i < 10; ++i)
-   {
-       free(unit_str[i]);
-   }
-*/
 }
 
 static Temperature_Face *
@@ -1075,8 +1069,8 @@
    if (therms) ecore_list_destroy(therms);
 #endif   
    
-   if(ef->conf->units == fahrenheit)
-       temp = (temp*9/5)+32;
+   if (ef->conf->units == FAHRENHEIT)
+       temp = (temp * 9.0 / 5.0) + 32;
    
    if (ret)
      {
@@ -1098,7 +1092,7 @@
                                    (double)(temp - ef->conf->low) /
                                    (double)(ef->conf->high - ef->conf->low));
                  
-            if(ef->conf->units == fahrenheit) 
+            if (ef->conf->units == FAHRENHEIT) 
                snprintf(buf, sizeof(buf), "%i°F", temp);
             else
                snprintf(buf, sizeof(buf), "%i°C", temp);               
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/apps/e/src/modules/temperature/e_mod_main.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- e_mod_main.h        15 Sep 2005 06:25:28 -0000      1.8
+++ e_mod_main.h        20 Sep 2005 18:16:33 -0000      1.9
@@ -9,7 +9,11 @@
 typedef struct _Temperature      Temperature;
 typedef struct _Temperature_Face Temperature_Face;
        
-typedef enum _unit {celcius=0, fahrenheit} unit;
+typedef enum _Unit
+{
+   CELCIUS,
+   FAHRENHEIT
+} Unit;
 
 struct _Config
 {
@@ -17,7 +21,7 @@
    int low, high;
    Evas_List *faces;
    char *sensor_name;
-   unit units;
+   Unit units;
 };
 
 struct _Config_Face




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to