diff --git a/src/homemade_speedstep.c b/src/homemade_speedstep.c index 34286e5..b507979 100644 --- a/src/homemade_speedstep.c +++ b/src/homemade_speedstep.c @@ -2,6 +2,7 @@ #include #include +#define VERSION "1.0" #define POLLING_TIME 1 #define CURGOV "/sys/devices/system/cpu/cpufreq/policy0/scaling_governor" #define FREQS "/sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies" @@ -105,8 +106,14 @@ int main(int argc, char** argv){ if (argc == 1 || comparestrings(argv[1], "-h") == 0 || comparestrings(argv[1], "--help") == 0){ fprintf(stderr, "usage: homemade_speedstep \n"); - fprintf(stderr, " homemade_speedstep [-h | --help]\n"); - fprintf(stderr, " -h | --help prints out this help message\n"); + fprintf(stderr, " homemade_speedstep [-h | --help | -v | --version]\n"); + fprintf(stderr, " -h | --help prints out this help message\n"); + fprintf(stderr, " -v | --version prints out version number\n"); + return 0; + } + if (comparestrings(argv[1], "-v") == 0 + || comparestrings(argv[1], "--version") == 0){ + fprintf(stderr, VERSION"\n"); return 0; } /* check for correct ammount of arguments */ @@ -139,12 +146,14 @@ int main(int argc, char** argv){ int stepc = countblanks(freqsfilec); /* create a char ** array with pointers to freq steps */ char ** steps = malloc(sizeof(char*) * stepc); - int index = 0; + int* index = malloc(sizeof(int*)); + *index = 0; int i; for(i = 0; i < stepc; i++){ - index = splitstr(steps, freqsfilec, index, i); + *index = splitstr(steps, freqsfilec, *index, i); } /* free memory and close file */ + free(index); free(freqsfilec); fclose(freqsfile); /* try to open scaling_maximum_frequency, exit on fail */ @@ -221,8 +230,8 @@ int main(int argc, char** argv){ timepassed = 0; } /* check if a minute passed without step changes and temp is below minmax average */ - if (timepassed > 60 && temperature <= (mintemp+maxtemp)/2 && curstep < stepc - 1){ - curstep++; + if (timepassed > 60 && temperature <= (mintemp+maxtemp)/2 && curstep > 0){ + curstep--; curmaxfile = fopen(MAXSPDPATH, "w"); if (curmaxfile == NULL){ fprintf(stderr, "error: couldn't open scaling_maximum_frequency\n");