From 86a1552530f2b5e8dc6a6981d2b576658e9ebf29 Mon Sep 17 00:00:00 2001 From: celso Date: Fri, 11 Nov 2022 21:31:00 -0300 Subject: [PATCH] added argc check and help message --- src/homemade_speedstep.c | 41 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/homemade_speedstep.c b/src/homemade_speedstep.c index d28ad30..e8ef509 100644 --- a/src/homemade_speedstep.c +++ b/src/homemade_speedstep.c @@ -27,13 +27,50 @@ int getfilec(FILE *file, char arr[]){ return i; } -int main(){ +int powerof(int base, int exponent){ + int i, result; + if (exponent==0){ + return result=1; + } + result=base; + for(i=0; i=0){ + result+=((int)number[length-1]-'0')*(powerof(10,j)); + j++; + length--; + } + return result; +} + +int main(int argc, char** argv){ + if (argc == 1 || comparestrings(argv[1], "-h") == 0 + || comparestrings(argv[1], "--help") == 0){ + printf("usage: homemade_speedstep \n"); + printf(" homemade_speedstep [-h | --help]\n"); + printf(" -h | --help prints out this help message\n"); + return 0; + } + if (argc!=3){ + printf("error: wrong ammount of arguments given\n"); + printf(" see homemade_speedstep --help\n"); + return 1; + } char gov[20]; FILE *govfile = fopen(CURGOV, "r"); getfilec(govfile, gov); if (comparestrings(gov, "userspace\n") != 0){ printf("error: userspace governor not set\n"); - return 1; + fclose(govfile); + return 2; } FILE *freqsfile = fopen(FREQS, "r"); FILE *curmaxfile = fopen(MAXSPDPATH, "r");