diff options
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | TODO.md | 1 | ||||
-rw-r--r-- | bat_tray.c | 10 | ||||
-rw-r--r-- | common.c | 6 | ||||
-rw-r--r-- | common.h | 5 | ||||
-rw-r--r-- | config_file.c | 3 | ||||
-rw-r--r-- | config_file.h | 2 | ||||
-rw-r--r-- | defaults.c | 4 | ||||
-rw-r--r-- | defaults.h | 3 | ||||
-rw-r--r-- | getcore.c | 11 | ||||
-rw-r--r-- | getcore.h | 4 | ||||
-rw-r--r-- | getfreq.c | 19 | ||||
-rw-r--r-- | getfreq.h | 16 | ||||
-rw-r--r-- | getgov.c | 16 | ||||
-rw-r--r-- | getgov.h | 12 | ||||
-rw-r--r-- | paramano.c | 18 | ||||
-rw-r--r-- | paramano.h | 20 | ||||
-rw-r--r-- | paramano_set.c | 14 | ||||
-rw-r--r-- | paramano_set_interface.c | 7 | ||||
-rw-r--r-- | reload.c | 6 | ||||
-rw-r--r-- | reload.h | 1 | ||||
-rw-r--r-- | tray.c | 61 | ||||
-rw-r--r-- | tray.h | 2 |
23 files changed, 84 insertions, 171 deletions
@@ -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 \ @@ -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 @@ -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; @@ -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 @@ -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; @@ -16,9 +16,7 @@ * <http://www.gnu.org/licenses/>. * ************************************************************************/ -#include "defaults.h" - -#include <stdio.h> +#include "paramano.h" char* DEFAULT_GOV; char* DEFAULT_FREQ; @@ -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; @@ -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; } @@ -19,7 +19,7 @@ #ifndef GETCORE_H #define GETCORE_H -void gc_init(); -int gc_number(); +void gc_init(); +unsigned int gc_number(); #endif @@ -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; } @@ -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 @@ -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; } @@ -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 @@ -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 @@ -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) { @@ -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> /*********************************************************************** @@ -20,4 +20,5 @@ #define RELOAD_H void reload_config(); + #endif @@ -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 **********************************************************************/ @@ -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); |