diff options
-rw-r--r-- | Makefile | 19 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | TODO.md | 5 | ||||
-rw-r--r-- | bat_tray/bat_tray.c | 11 | ||||
-rw-r--r-- | freq_tray/getfreq.c | 5 | ||||
-rw-r--r-- | freq_tray/getgov.c | 1 | ||||
-rw-r--r-- | tray.c | 13 | ||||
-rw-r--r-- | trayfreq.c | 8 | ||||
-rw-r--r-- | trayfreq_set/trayfreq_set.c | 67 |
9 files changed, 74 insertions, 57 deletions
@@ -42,28 +42,33 @@ trayfreq_set_SOURCES = trayfreq_set/trayfreq_set.c \ ######################################################################## # Make entire suite -all: trayfreq trayfreq-set +all: trayfreq-en trayfreq-fr trayfreq-set-en trayfreq-set-fr ######################################################################## - ######################################################################## # Make trayfreq-set program for setting governors -trayfreq-set: - $(CC) -o trayfreq-set $(trayfreq_set_SOURCES) $(trayfreq_set_CFLAGS) $(trayfreq_set_LDFLAGS) +trayfreq-set-en: + $(CC) -o trayfreq-set-en $(trayfreq_set_SOURCES) $(trayfreq_set_CFLAGS) $(trayfreq_set_LDFLAGS) + +trayfreq-set-fr: + $(CC) -o trayfreq-set-fr $(trayfreq_set_SOURCES) $(trayfreq_set_CFLAGS) $(trayfreq_set_LDFLAGS) -DLANG_FR ######################################################################## ######################################################################## # Make main trayfreq system tray program -trayfreq: - $(CC) -o trayfreq $(trayfreq_SOURCES) $(trayfreq_CFLAGS) $(trayfreq_LDFLAGS) +trayfreq-en: + $(CC) -o trayfreq-en $(trayfreq_SOURCES) $(trayfreq_CFLAGS) $(trayfreq_LDFLAGS) + +trayfreq-fr: + $(CC) -o trayfreq-fr $(trayfreq_SOURCES) $(trayfreq_CFLAGS) $(trayfreq_LDFLAGS) -DLANG_FR ######################################################################## ######################################################################## # Remove generated files clean: - rm -f trayfreq trayfreq-set + rm -f trayfreq-en trayfreq-set-en trayfreq-fr trayfreq-set-fr ######################################################################## @@ -1,5 +1,5 @@ What? -=== +===== The official trayfreq (see AUTHORS) was abandoned in 2009 and stopped working with modern, up-to-date Linux systems. This is a fork which is designed to work on newer Archlinux systems, however it shouldn't be limited to Arch. @@ -1,4 +1,5 @@ To do -==== +===== -* Hmm. Nothing. This can't be right... +* Receive feedback on French translation +* Clean up `trayfreq-set`'s `main()` diff --git a/bat_tray/bat_tray.c b/bat_tray/bat_tray.c index 9f6adfb..38c85bc 100644 --- a/bat_tray/bat_tray.c +++ b/bat_tray/bat_tray.c @@ -16,6 +16,8 @@ * <http://www.gnu.org/licenses/>. * ************************************************************************/ + +#include "../strings.h" #include "bat_tray.h" #include "../common.h" @@ -26,7 +28,6 @@ static GtkStatusIcon* tray; - int _BAT_NUM; char CHARGE_VALUE_PATH[512]; char CHARGE_STATE_PATH[512]; @@ -52,18 +53,18 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean switch(get_battery_state()) { case STATE_DISCHARGING: - sprintf(msg, "Discharging (%i%% left)", get_bat_percent()); + sprintf(msg, S_BAT_TRAY_C_BATTERY_DISCHARGING, get_bat_percent()); break; case STATE_CHARGING: - sprintf(msg, "Charging (%i%%)", get_bat_percent()); + sprintf(msg, S_BAT_TRAY_C_BATTERY_CHARGING, get_bat_percent()); break; case STATE_CHARGED: - sprintf(msg, "Fully charged"); + sprintf(msg, S_BAT_TRAY_C_BATTERY_FULL); break; default: - sprintf(msg, "Unknown status"); + sprintf(msg, S_BAT_TRAY_C_BATTERY_UNKNOWN); break; } diff --git a/freq_tray/getfreq.c b/freq_tray/getfreq.c index 5ac3948..7ac2181 100644 --- a/freq_tray/getfreq.c +++ b/freq_tray/getfreq.c @@ -16,6 +16,7 @@ * <http://www.gnu.org/licenses/>. * ************************************************************************/ +#include "string.h" #include "getfreq.h" #include "getcore.h" #include "math.h" @@ -37,7 +38,7 @@ void gf_init() int j = 0; for(i = 0; i < gc_number(); ++i) { - memset(freq_string, '\0', 500); + memset(freq_string, 0, 500); // Get available governor freqs. If no governor, try next cpu if (gf_available(i, freq_string, 500) == -1) @@ -49,7 +50,7 @@ void gf_init() gchar* end_of_curr = g_strstr_len(curr, strlen(curr), " "); while(end_of_curr) { - memset(AVAILABLE_FREQUENCIES[i][j], '\0', 13); + memset(AVAILABLE_FREQUENCIES[i][j], 0, 13); memmove(AVAILABLE_FREQUENCIES[i][j], curr, end_of_curr - curr); curr = end_of_curr+1; diff --git a/freq_tray/getgov.c b/freq_tray/getgov.c index cbb571c..8fe44a5 100644 --- a/freq_tray/getgov.c +++ b/freq_tray/getgov.c @@ -16,6 +16,7 @@ * <http://www.gnu.org/licenses/>. * ************************************************************************/ +#include "string.h" #include "getgov.h" #include "getcore.h" @@ -16,6 +16,7 @@ * <http://www.gnu.org/licenses/>. * ************************************************************************/ +#include "strings.h" #include "tray.h" #include "widget_manager.h" #include "freq_tray/getfreq.h" @@ -130,7 +131,7 @@ static void tray_generate_menu() gtk_menu_append(menu, seperator); /* append the governors*/ - for(i = 0; i < gg_number(); ++i) + for(i = 0; i < gg_number(); i++) { if(g_strcmp0(gg_gov(0, i), "userspace") == 0) continue; @@ -156,8 +157,8 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean gchar label[20]; int i = 0; - memset(msg, '\0', 500); - memset(current_governer, '\0', 20); + memset(msg, 0, 500); + memset(current_governer, 0, 20); // Change governor based on battery state battery is discharging if ( get_battery_state() == STATE_DISCHARGING ) @@ -179,13 +180,13 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean } gg_current(0, current_governer, 20); - sprintf(msg, "%sGovernor: %s\n", msg, current_governer); + sprintf(msg+strlen(msg), S_TRAY_C_GOVERNOR, current_governer); for(i = 0; i < gc_number(); ++i) { - memset(label, '\0', 20); + memset(label, 0, 20); gf_get_frequency_label(gf_current(i), label); - sprintf(msg, "%sCPU%i: %s%s", msg, i, label, i == gc_number()-1 ? "" : "\n"); + sprintf(msg+strlen(msg), S_TRAY_C_CPU, i, label, i == gc_number()-1 ? "" : "\n"); } tray_set_tooltip(msg); @@ -16,6 +16,8 @@ * <http://www.gnu.org/licenses/>. * ************************************************************************/ +#include "strings.h" + #include "widget_manager.h" #include "tray.h" #include "bat_tray/bat_tray.h" @@ -39,8 +41,6 @@ void config_init() gboolean home_config_exists; config.key_file = NULL; - printf("Battery governor: %s",_DEFAULT_BAT_GOV); - config.file_name = g_strconcat(getenv("HOME"), "/.trayfreq.config", NULL); // Check if ~/.trayfreq.config exists @@ -62,7 +62,7 @@ void config_init() if(!success) { - g_warning("Failed to open config files!\n"); + g_warning(S_TRAYFREQ_C_CONFIG_FILE_ERROR); return; } @@ -105,7 +105,7 @@ int main(int argc, char** argv) if(!gtk_init_check(&argc, &argv)) { - g_error("Cannot initialize gtk: gtk_init_check returned FALSE.\nBailing."); + g_error(S_TRAYFREQ_C_GTK_ERROR); return 1; } diff --git a/trayfreq_set/trayfreq_set.c b/trayfreq_set/trayfreq_set.c index 75b37f0..9318403 100644 --- a/trayfreq_set/trayfreq_set.c +++ b/trayfreq_set/trayfreq_set.c @@ -20,30 +20,43 @@ #include <stdlib.h> #include <string.h> +#include "../strings.h" #include "../freq_tray/getfreq.h" #include "../freq_tray/getcore.h" -#define ERRMSG "FAILED: Couldn't open %s for writing\n" +char file_path[100]; -void set_freq_max(char* freq, char* core) + +void prepare_path(const char* file, const char* core) +{ + // Sanatise core to make sure there's not monkey business going on -- it's only an integer + int core_i = atoi(core); + + sprintf(file_path, "/sys/devices/system/cpu/cpu%d/cpufreq/%s", core_i, file); +} + +void file_open_error() +{ + printf(S_TRAYFREQ_SET_C_FILE_OPEN_ERROR, file_path); +} + +void set_freq_max(const char* freq, const char* core) { - char file_path[100]; - sprintf(file_path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_max_freq", core); + prepare_path("scaling_max_freq",core); FILE* fd = fopen(file_path, "w"); if (fd) { fprintf(fd, freq); fclose(fd); } else { - printf(ERRMSG,file_path); + file_open_error(); } } void set_freq_min(char* freq, char* core) { - char file_path[100]; - sprintf(file_path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_min_freq", core); + prepare_path("scaling_min_freq",core); FILE* fd = fopen(file_path, "w"); if (fd) @@ -51,14 +64,13 @@ void set_freq_min(char* freq, char* core) fprintf(fd, freq); fclose(fd); } else { - printf(ERRMSG,file_path); + file_open_error(); } } static void set_speed(char* freq, char* core) { - char file_path[100]; - sprintf(file_path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_setspeed", core); + prepare_path("scaling_setspeed",core); FILE* fd = fopen(file_path, "w"); if (fd) @@ -66,14 +78,13 @@ static void set_speed(char* freq, char* core) fprintf(fd, freq); fclose(fd); } else { - printf(ERRMSG,file_path); + file_open_error(); } } void set_gov(char* gov, char* core) { - char file_path[100]; - sprintf(file_path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_governor", core); + prepare_path("scaling_governor",core); FILE* fd = fopen(file_path, "w"); if (fd) @@ -81,7 +92,7 @@ void set_gov(char* gov, char* core) fprintf(fd, gov); fclose(fd); } else { - printf(ERRMSG,file_path); + file_open_error(); } } @@ -98,47 +109,43 @@ int main(int argc, char *argv[]) if(!argv[1]) { - printf("Use -g to set the governor or -f to set the frequency.\n"); - } - else if(strcmp(argv[1], "-g") == 0) - { + printf(S_TRAYFREQ_SET_C_NO_ARGS); + } else if(strcmp(argv[1], "-g") == 0) { if(!argv[2]) - printf("Pass the governor to set after the -g.\n"); + printf(S_TRAYFREQ_SET_C_SET_GOVERNOR_ARG); else { if(!argv[3]) - printf("Use -c to set the core.\n"); + printf(S_TRAYFREQ_SET_C_SET_CORE_ARG); else if(strcmp(argv[3], "-c") == 0) { if(!argv[4]) - printf("Pass the core to set after the -c.\n"); + printf(S_TRAYFREQ_SET_C_SET_CORE_ARG); else set_gov(argv[2], argv[4]); } else - printf("Use -c to set the core.\n"); + printf(S_TRAYFREQ_SET_C_SET_CORE_ARG); } - } - else if(strcmp(argv[1], "-f") == 0) - { + } else if(strcmp(argv[1], "-f") == 0) { if(!argv[2]) { - printf("Pass the frequency to set after the -f.\n"); + printf(S_TRAYFREQ_SET_C_SET_FREQUENCY_ARG); } else { if(!argv[3]) { - printf("Use -c to set the core.\n"); + printf(S_TRAYFREQ_SET_C_SET_CORE_ARG); } else if(strcmp(argv[3], "-c") == 0) { if(!argv[4]) - printf("Pass the core to set after the -c.\n"); + printf(S_TRAYFREQ_SET_C_SET_CORE_ARG); else set_freq(argv[2], argv[4]); } else { - printf("Use -c to set the core.\n"); + printf(S_TRAYFREQ_SET_C_SET_CORE_ARG); } } } else { - printf("Use -g to set the governor or -f to set the frequency.\n"); + printf(S_TRAYFREQ_SET_C_NO_ARGS); } return 0; }
\ No newline at end of file |