added argc check and help message

This commit is contained in:
celso 2022-11-11 21:31:00 -03:00
parent a380465707
commit 86a1552530
1 changed files with 39 additions and 2 deletions

View File

@ -27,13 +27,50 @@ int getfilec(FILE *file, char arr[]){
return i; 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<exponent-1; i++){
result*=base;
}
return result;
}
int stringtoint(char number[], int length){
int j, result;
result=0;
j=0;
while(length-1>=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 <max temp> <min temp>\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]; char gov[20];
FILE *govfile = fopen(CURGOV, "r"); FILE *govfile = fopen(CURGOV, "r");
getfilec(govfile, gov); getfilec(govfile, gov);
if (comparestrings(gov, "userspace\n") != 0){ if (comparestrings(gov, "userspace\n") != 0){
printf("error: userspace governor not set\n"); printf("error: userspace governor not set\n");
return 1; fclose(govfile);
return 2;
} }
FILE *freqsfile = fopen(FREQS, "r"); FILE *freqsfile = fopen(FREQS, "r");
FILE *curmaxfile = fopen(MAXSPDPATH, "r"); FILE *curmaxfile = fopen(MAXSPDPATH, "r");