aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid <dbphillipsnz@gmail.com>2014-09-28 15:49:52 +1300
committerDavid <dbphillipsnz@gmail.com>2014-09-28 15:49:52 +1300
commit22428b4d31bfbad0462fe13719698232452f4149 (patch)
treed52cc14b3c5c7eb192c15b7ba85666bc2686dc86
parent45f116b0562951775af0d6833229b22b49bc0397 (diff)
downloadparamano-22428b4d31bfbad0462fe13719698232452f4149.tar.xz
Code tidy
-rw-r--r--Makefile14
-rw-r--r--TODO.md1
-rw-r--r--bat_tray.c10
-rw-r--r--common.c6
-rw-r--r--common.h5
-rw-r--r--config_file.c3
-rw-r--r--config_file.h2
-rw-r--r--defaults.c4
-rw-r--r--defaults.h3
-rw-r--r--getcore.c11
-rw-r--r--getcore.h4
-rw-r--r--getfreq.c19
-rw-r--r--getfreq.h16
-rw-r--r--getgov.c16
-rw-r--r--getgov.h12
-rw-r--r--paramano.c18
-rw-r--r--paramano.h20
-rw-r--r--paramano_set.c14
-rw-r--r--paramano_set_interface.c7
-rw-r--r--reload.c6
-rw-r--r--reload.h1
-rw-r--r--tray.c61
-rw-r--r--tray.h2
23 files changed, 84 insertions, 171 deletions
diff --git a/Makefile b/Makefile
index c0cc1aa..b701f43 100644
--- a/Makefile
+++ b/Makefile
@@ -41,8 +41,8 @@ DEPS = bat_tray.h \
getcore.h \
getfreq.h \
getgov.h \
- reload.h \
paramano.h \
+ reload.h \
tray.h \
paramano_set_interface.h
@@ -55,6 +55,18 @@ CFLAGS = -I/usr/include/gtk-2.0 \
-I/usr/include/glib-2.0 \
-I/usr/lib/glib-2.0/include \
-Wall \
+ -Wclobbered \
+ -Wempty-body \
+ -Wignored-qualifiers \
+ -Wmissing-field-initializers \
+ -Wmissing-parameter-type \
+ -Woverride-init \
+ -Wsign-compare \
+ -Wtype-limits \
+ -Wuninitialized \
+ -Wunused-but-set-parameter \
+ -Wdouble-promotion \
+ -Werror \
-D_=gettext
LDFLAGS = -lgtk-3 \
diff --git a/TODO.md b/TODO.md
index 0fa3d73..0bbffff 100644
--- a/TODO.md
+++ b/TODO.md
@@ -3,3 +3,4 @@ To do
* Disable open_file wrapper when compiling without debug flag
* Get rid of various magic numbers
+* Make tooltip strings cached
diff --git a/bat_tray.c b/bat_tray.c
index 888be69..aacbccb 100644
--- a/bat_tray.c
+++ b/bat_tray.c
@@ -17,17 +17,9 @@
************************************************************************/
-#include "bat_tray.h"
-
-#include <gtk/gtk.h>
-#include <libintl.h>
-#include <stdio.h>
-#include "common.h"
-#include "defaults.h"
-
+#include "paramano.h"
static GtkStatusIcon* tray;
-
int bat_num; // Shortcoming: we only detect one battery
char *CHARGE_VALUE_PATH, *CHARGE_STATE_PATH;
diff --git a/common.c b/common.c
index 2a802d8..0c8a2fe 100644
--- a/common.c
+++ b/common.c
@@ -16,11 +16,7 @@
* <http://www.gnu.org/licenses/>. *
************************************************************************/
-#include "common.h"
-
-#include <stdio.h> /* fopen, fgets, printf */
-#include <stdlib.h> /* atoi */
-#include <string.h> /* lots of functions */
+#include "paramano.h"
/***********************************************************************
* Return integer value from first line in file
diff --git a/common.h b/common.h
index 06dd072..6d55d46 100644
--- a/common.h
+++ b/common.h
@@ -19,13 +19,10 @@
#ifndef COMMON_H
#define COMMON_H
-#include <stdbool.h>
-#include <stdio.h>
-
int get_int_value_from_file(const char* filename);
int get_int(const char* string);
bool file_has_line(const char *filename, const char *line);
-FILE* check_for_file(char* path);
+FILE *check_for_file(char* path);
// <ew> Stringification of line number
#define STRING2(x) #x
diff --git a/config_file.c b/config_file.c
index 33dd512..b085c4c 100644
--- a/config_file.c
+++ b/config_file.c
@@ -16,8 +16,7 @@
* <http://www.gnu.org/licenses/>. *
************************************************************************/
-#include "config_file.h"
-#include "common.h"
+#include "paramano.h"
gboolean config_open(struct config_file* config_file)
{
diff --git a/config_file.h b/config_file.h
index e4d8696..61ef74b 100644
--- a/config_file.h
+++ b/config_file.h
@@ -19,8 +19,6 @@
#ifndef CONFIG_FILE_H
#define CONFIG_FILE_H
-#include <glib.h>
-
struct config_file
{
GKeyFile* key_file;
diff --git a/defaults.c b/defaults.c
index 42496e7..3b90014 100644
--- a/defaults.c
+++ b/defaults.c
@@ -16,9 +16,7 @@
* <http://www.gnu.org/licenses/>. *
************************************************************************/
-#include "defaults.h"
-
-#include <stdio.h>
+#include "paramano.h"
char* DEFAULT_GOV;
char* DEFAULT_FREQ;
diff --git a/defaults.h b/defaults.h
index ae4a1bc..c4bd176 100644
--- a/defaults.h
+++ b/defaults.h
@@ -19,9 +19,6 @@
#ifndef DEFAULTS_H
#define DEFAULTS_H
-#include <stdbool.h> /* boolean types */
-#include <stdlib.h> /* NULL */
-
char* DEFAULT_GOV;
char* DEFAULT_FREQ;
char* DEFAULT_PROG;
diff --git a/getcore.c b/getcore.c
index 9b21e76..9fb9600 100644
--- a/getcore.c
+++ b/getcore.c
@@ -16,14 +16,7 @@
* <http://www.gnu.org/licenses/>. *
************************************************************************/
-#include "getcore.h"
-
-#include "common.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <unistd.h>
+#include "paramano.h"
unsigned int cores;
@@ -59,7 +52,7 @@ void gc_init()
/***********************************************************************
* Return number of cores
**********************************************************************/
-int gc_number()
+unsigned int gc_number()
{
return cores;
}
diff --git a/getcore.h b/getcore.h
index 3324669..5e6cbb9 100644
--- a/getcore.h
+++ b/getcore.h
@@ -19,7 +19,7 @@
#ifndef GETCORE_H
#define GETCORE_H
-void gc_init();
-int gc_number();
+void gc_init();
+unsigned int gc_number();
#endif
diff --git a/getfreq.c b/getfreq.c
index bae86cf..ac989fd 100644
--- a/getfreq.c
+++ b/getfreq.c
@@ -16,14 +16,7 @@
* <http://www.gnu.org/licenses/>. *
************************************************************************/
-#include "getfreq.h"
-#include "getcore.h"
-#include "common.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <glib.h>
+#include "paramano.h"
#define MAX_CORES 1000
#define MAX_FREQS 50
@@ -139,13 +132,13 @@ char* gf_get_frequency_label(int freq)
{
char *string;
if(freq >= 1000000000) // >= 1 billion KHz (1 THz) This, ladies and gentlement, is future-proofing ;)
- asprintf(&string, "%.2f THz", (float)freq/1000000000 );
+ asprintf(&string, "%.2f THz", (double)freq/1000000000 );
else if(freq >= 1000000) // >= 1 million KHz (1 GHz)
- asprintf(&string, "%.2f GHz", (float)freq/1000000 );
+ asprintf(&string, "%.2f GHz", (double)freq/1000000 );
else if (freq >= 1000) // >= 1 thousand KHz (1 MHz)
- asprintf(&string, "%.2f MHz", (float)freq/1000 );
+ asprintf(&string, "%.2f MHz", (double)freq/1000 );
else // < 1000 KHz (1 MHz)
- asprintf(&string, "%.2f KHz", (float)freq);
+ asprintf(&string, "%.2f KHz", (double)freq);
debug("Prepared freq label '%s' for freq %d\n",string,freq);
@@ -171,7 +164,7 @@ int gf_freqi(int core, int index)
/***********************************************************************
* Return total number of frequencies
**********************************************************************/
-int gf_number()
+unsigned int gf_number()
{
return total_freqs;
}
diff --git a/getfreq.h b/getfreq.h
index 6699cd5..17b5242 100644
--- a/getfreq.h
+++ b/getfreq.h
@@ -19,15 +19,13 @@
#ifndef GETFREQ_H
#define GETFREQ_H
-#include <stdbool.h>
-
-void gf_init();
-int gf_current(int core);
-int gf_available(int core, char* out, int size);
-char* gf_get_frequency_label(int freq);
-char* gf_freqa(int core, int index);
-int gf_freqi(int core, int index);
-int gf_number();
+void gf_init();
+int gf_current(int core);
+int gf_available(int core, char* out, int size);
+char* gf_get_frequency_label(int freq);
+char* gf_freqa(int core, int index);
+int gf_freqi(int core, int index);
+unsigned int gf_number();
#endif
diff --git a/getgov.c b/getgov.c
index c6dec99..cff7329 100644
--- a/getgov.c
+++ b/getgov.c
@@ -16,15 +16,7 @@
* <http://www.gnu.org/licenses/>. *
************************************************************************/
-#include "string.h"
-#include "getgov.h"
-#include "getcore.h"
-#include "common.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <glib.h>
+#include "paramano.h"
/* [CORE][GOVERNOR NUMBER] */
char governors[999][50][13];
@@ -36,9 +28,9 @@ int total_governors;
void gg_init()
{
gchar gov_string[500];
- int i = 0;
+ unsigned int i = 0;
total_governors = 0;
- for (i = 0; i < gc_number(); ++i)
+ for (i = 0; i < gc_number(); i++)
{
memset(gov_string, '\0', sizeof(gov_string) );
gg_available(i, gov_string, sizeof(gov_string) );
@@ -120,7 +112,7 @@ char* gg_gov(int core, int index)
/***********************************************************************
* Return total number of governors
**********************************************************************/
-int gg_number()
+unsigned int gg_number()
{
return total_governors;
}
diff --git a/getgov.h b/getgov.h
index 25c6e89..131f164 100644
--- a/getgov.h
+++ b/getgov.h
@@ -19,12 +19,10 @@
#ifndef GETGOV_H
#define GETGOV_H
-#include <stdbool.h>
-
-void gg_init();
-bool gg_current(int core, char* out, int size);
-bool gg_available(int core, char* out, int size);
-char* gg_gov(int core, int index);
-int gg_number();
+void gg_init();
+bool gg_current(int core, char* out, int size);
+bool gg_available(int core, char* out, int size);
+char* gg_gov(int core, int index);
+unsigned int gg_number();
#endif
diff --git a/paramano.c b/paramano.c
index 8489e12..84a6996 100644
--- a/paramano.c
+++ b/paramano.c
@@ -18,24 +18,6 @@
#include "paramano.h"
-#include "tray.h"
-#include "bat_tray.h"
-#include "getfreq.h"
-#include "getcore.h"
-#include "getgov.h"
-#include "config_file.h"
-#include "reload.h"
-#include "defaults.h"
-#include "common.h"
-
-#include <gtk/gtk.h>
-#include <unistd.h> // getuid, getgid
-#include <stdio.h> // printf, FILE, fopen, etc
-#include <string.h> // strlen
-
-#include <libintl.h> // gettext
-#include <locale.h> // LC_ALL etc
-
/***********************************************************************
* Main
diff --git a/paramano.h b/paramano.h
index 1a54455..5bdaebe 100644
--- a/paramano.h
+++ b/paramano.h
@@ -19,6 +19,26 @@
#ifndef PARAMANO_H
#define PARAMANO_H
+#include <gtk/gtk.h>
+#include <unistd.h> // getuid, getgid
+#include <stdio.h> // printf, FILE, fopen, etc
+#include <stdlib.h> // free etc
+#include <stdbool.h> // boolean types
+#include <string.h> // strlen
+#include <libintl.h> // gettext
+#include <locale.h> // LC_ALL etc
+
+#include "tray.h"
+#include "bat_tray.h"
+#include "getfreq.h"
+#include "getcore.h"
+#include "getgov.h"
+#include "config_file.h"
+#include "reload.h"
+#include "defaults.h"
+#include "common.h"
+#include "paramano_set_interface.h"
+
void config_init();
#endif
diff --git a/paramano_set.c b/paramano_set.c
index b235454..4a0ba2d 100644
--- a/paramano_set.c
+++ b/paramano_set.c
@@ -17,16 +17,7 @@
************************************************************************/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <libintl.h>
-#include <locale.h>
-
-#include "getfreq.h"
-#include "getcore.h"
-#include "common.h"
+#include "paramano.h"
#define FILE_PATH_STRING_SIZE 100
@@ -117,9 +108,6 @@ int main(int argc, char *argv[])
debug("Set gettext up\n");
- gc_init();
- gf_init();
-
argument_summary args;
memset(&args, 0, sizeof(args));
diff --git a/paramano_set_interface.c b/paramano_set_interface.c
index fe4e2dc..2806253 100644
--- a/paramano_set_interface.c
+++ b/paramano_set_interface.c
@@ -16,12 +16,7 @@
* <http://www.gnu.org/licenses/>. *
************************************************************************/
-#include "paramano_set_interface.h"
-
-#include "common.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
+#include "paramano.h"
void si_gov(char* gov, int core)
{
diff --git a/reload.c b/reload.c
index aeac1f0..517762c 100644
--- a/reload.c
+++ b/reload.c
@@ -16,13 +16,7 @@
* <http://www.gnu.org/licenses/>. *
************************************************************************/
-#include "reload.h"
-#include "bat_tray.h"
-#include "tray.h"
#include "paramano.h"
-#include "defaults.h"
-#include "common.h"
-#include <stdio.h>
/***********************************************************************
diff --git a/reload.h b/reload.h
index e5a5e49..030147e 100644
--- a/reload.h
+++ b/reload.h
@@ -20,4 +20,5 @@
#define RELOAD_H
void reload_config();
+
#endif
diff --git a/tray.c b/tray.c
index 34803e7..9b8bdfe 100644
--- a/tray.c
+++ b/tray.c
@@ -16,28 +16,10 @@
* <http://www.gnu.org/licenses/>. *
************************************************************************/
-#include "tray.h"
+#include "paramano.h"
-#include "getfreq.h"
-#include "getcore.h"
-#include "getgov.h"
-#include "paramano_set_interface.h"
-#include "bat_tray.h"
-#include "defaults.h"
-#include "common.h"
-
-#include <glib.h>
-#include <gtk/gtk.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <libintl.h>
-
-
-//#define TOOLTIP_TEXT_SIZE 500
GtkStatusIcon* tray;
-//char tooltip_text[TOOLTIP_TEXT_SIZE];
GtkWidget* menu;
GSList* menu_items;
@@ -54,8 +36,8 @@ static void freq_menu_item_toggled(GtkCheckMenuItem* item, gpointer data)
{
checked_menu_item = GTK_WIDGET(item);
gint freq = GPOINTER_TO_INT(data);
- int i = 0;
- for(i = 0; i < gc_number(); ++i)
+ unsigned int i = 0;
+ for(i = 0; i < gc_number(); i++)
si_freq(freq, i);
}
}
@@ -71,8 +53,8 @@ static void gov_menu_item_toggled(GtkCheckMenuItem* item, gpointer data)
{
checked_menu_item = GTK_WIDGET(item);
char* gov = (char*)data;
- int i = 0;
- for(i = 0; i < gc_number(); ++i)
+ unsigned int i = 0;
+ for(i = 0; i < gc_number(); i++)
si_gov(gov, i);
}
}
@@ -129,7 +111,7 @@ static void tray_generate_menu()
gg_init();
char *label;
- int i = 0;
+ unsigned int i = 0;
char current_governor[20];
memset(current_governor, '\0', sizeof(current_governor) );
@@ -138,7 +120,7 @@ static void tray_generate_menu()
gint current_frequency = gf_current(0);
// Add available frequencies
- for(i = 0; i < gf_number(); ++i)
+ for(i = 0; i < gf_number(); i++)
{
label = gf_get_frequency_label(gf_freqi(0, i));
debug("Got freq label '%s', i=%d\n",label,i);
@@ -202,7 +184,7 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean
{
char *msg, *label;
char current_governor[20]; // TO DO
- int i = 0;
+ unsigned int i = 0;
memset(current_governor, '\0', sizeof(current_governor) );
@@ -210,7 +192,7 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean
asprintf(&msg, _("Governor: %s\n"), current_governor);
- for(i = 0; i < gc_number(); ++i)
+ for(i = 0; i < gc_number(); i++)
{
debug("Adding CPU%d's frequency\n",i);
label = gf_get_frequency_label(gf_current(i));
@@ -243,14 +225,14 @@ static void popup_menu(GtkStatusIcon* statuc_icon,guint button,guint activate_ti
**********************************************************************/
static gboolean update_icon(gpointer user_data)
{
- int i;
+ unsigned int i;
switch ( get_battery_state() )
{
case STATE_DISCHARGING:
debug("Discharging\n");
if(DEFAULT_BAT_GOV)
{
- for(i = 0; i < gc_number(); ++i)
+ for(i = 0; i < gc_number(); i++)
si_gov(DEFAULT_BAT_GOV, i);
}
break;
@@ -260,7 +242,7 @@ static gboolean update_icon(gpointer user_data)
debug("Charging/Full\n");
if(DEFAULT_AC_GOV)
{
- for(i = 0; i < gc_number(); ++i)
+ for(i = 0; i < gc_number(); i++)
si_gov(DEFAULT_AC_GOV, i);
}
@@ -279,20 +261,20 @@ static gboolean update_icon(gpointer user_data)
void tray_set_defaults()
{
// Set defaults
- int i = 0;
+ unsigned int i = 0;
if(DEFAULT_GOV)
{
- for(i = 0; i < gc_number(); ++i)
+ for(i = 0; i < gc_number(); i++)
si_gov(DEFAULT_GOV, i);
} else {
- for(i = 0; i < gc_number(); ++i)
+ for(i = 0; i < gc_number(); i++)
si_gov("ondemand", i);
}
if(DEFAULT_FREQ)
{
- for(i = 0; i < gc_number(); ++i)
+ for(i = 0; i < gc_number(); i++)
si_freq(atoi(DEFAULT_FREQ), i);
}
@@ -321,17 +303,6 @@ void tray_init()
tray_init_menu();
}
-
-/***********************************************************************
- * Set the tooltip message
- **********************************************************************/
-void tray_set_tooltip(const char* msg)
-{
- debug("Setting up toolip var with text '%s'\n",msg);
- //memset(tooltip_text, '\0', TOOLTIP_TEXT_SIZE);
- //memmove(tooltip_text, msg, strlen(msg));
-}
-
/**********************************************************************
* Set icon based on current freq/governor
**********************************************************************/
diff --git a/tray.h b/tray.h
index 4958734..87e377d 100644
--- a/tray.h
+++ b/tray.h
@@ -19,8 +19,6 @@
#ifndef TRAY_H
#define TRAY_H
-#include <stdbool.h>
-
void tray_set_defaults();
void tray_init();
void tray_set_tooltip(const char* msg);