Fixed little bug in amd. Introduced feature to check version

This commit is contained in:
Dr-Noob
2018-06-24 00:17:50 +02:00
parent 8e56bc3801
commit 7cd4cb6dcb
5 changed files with 52 additions and 16 deletions

View File

@@ -22,6 +22,9 @@ Theoretical peak flops
\fB\-\-help\fR \fB\-\-help\fR
Prints help Prints help
.TP .TP
\fB\-\-version\fR
Prints cpufetch version
.TP
\fB\-\-style\fR \fB\-\-style\fR
Specify the color style of ascii logo Specify the color style of ascii logo
.SH BUGS .SH BUGS

View File

@@ -5,13 +5,16 @@
#define ARG_STR_STYLE "style" #define ARG_STR_STYLE "style"
#define ARG_STR_HELP "help" #define ARG_STR_HELP "help"
#define ARG_STR_VERSION "version"
#define ARG_CHAR_STYLE 's' #define ARG_CHAR_STYLE 's'
#define ARG_CHAR_HELP 'h' #define ARG_CHAR_HELP 'h'
#define ARG_CHAR_VERSION 'v'
#define STYLE_STR_1 "default" #define STYLE_STR_1 "default"
#define STYLE_STR_2 "dark" #define STYLE_STR_2 "dark"
struct args_struct { struct args_struct {
int help_flag; int help_flag;
int version_flag;
STYLE style; STYLE style;
}; };
@@ -36,6 +39,10 @@ int showHelp() {
return args.help_flag; return args.help_flag;
} }
int showVersion() {
return args.version_flag;
}
int parseArgs(int argc, char* argv[]) { int parseArgs(int argc, char* argv[]) {
int c; int c;
int digit_optind = 0; int digit_optind = 0;
@@ -46,8 +53,9 @@ int parseArgs(int argc, char* argv[]) {
args.style = STYLE_EMPTY; args.style = STYLE_EMPTY;
static struct option long_options[] = { static struct option long_options[] = {
{ARG_STR_STYLE, required_argument, 0, ARG_CHAR_STYLE}, {ARG_STR_STYLE, required_argument, 0, ARG_CHAR_STYLE },
{ARG_STR_HELP, no_argument, 0, ARG_CHAR_HELP }, {ARG_STR_HELP, no_argument, 0, ARG_CHAR_HELP },
{ARG_STR_VERSION, no_argument, 0, ARG_CHAR_VERSION },
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
@@ -72,6 +80,13 @@ int parseArgs(int argc, char* argv[]) {
} }
args.help_flag = BOOLEAN_TRUE; args.help_flag = BOOLEAN_TRUE;
} }
else if (c == ARG_CHAR_VERSION) {
if(args.version_flag) {
printf("ERROR: Version option specified more than once\n");
return BOOLEAN_FALSE;
}
args.version_flag = BOOLEAN_TRUE;
}
else if(c == '?') { else if(c == '?') {
printf("WARNING: Invalid options\n"); printf("WARNING: Invalid options\n");
args.help_flag = BOOLEAN_TRUE; args.help_flag = BOOLEAN_TRUE;
@@ -89,5 +104,10 @@ int parseArgs(int argc, char* argv[]) {
args.help_flag = BOOLEAN_TRUE; args.help_flag = BOOLEAN_TRUE;
} }
if((args.help_flag + args.version_flag + (args.style != STYLE_EMPTY)) > 1) {
printf("WARNING: You should specify just one option\n");
args.help_flag = BOOLEAN_TRUE;
}
return BOOLEAN_TRUE; return BOOLEAN_TRUE;
} }

View File

@@ -6,5 +6,6 @@
int parseArgs(int argc, char* argv[]); int parseArgs(int argc, char* argv[]);
STYLE getStyle(); STYLE getStyle();
int showHelp(); int showHelp();
int showVersion();
#endif #endif

View File

@@ -25,17 +25,23 @@ Peak FLOPS: 512 GFLOP/s(in simple precision)
***/ ***/
void help(int argc, char *argv[]) static const char* VERSION = "0.33";
{
printf("Usage: %s [--help] [--style STYLE]\n\ void help(int argc, char *argv[]) {
printf("Usage: %s [--version] [--help] [--style STYLE]\n\
Options: \n\ Options: \n\
--style Set logo style color\n\ --style Set logo style color\n\
default: Default style color\n\ default: Default style color\n\
dark: Dark style color\n\n\ dark: Dark style color\n\
--help Print this help and exit\n", --help Print this help and exit\n\
--version Print cpufetch version and exit\n",
argv[0]); argv[0]);
} }
void version() {
printf("cpufetch v%s\n",VERSION);
}
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if(!parseArgs(argc,argv)) if(!parseArgs(argc,argv))
return EXIT_FAILURE; return EXIT_FAILURE;
@@ -45,6 +51,11 @@ int main(int argc, char* argv[]) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if(showVersion()) {
version();
return EXIT_SUCCESS;
}
struct cpuInfo* cpu = getCPUInfo(); struct cpuInfo* cpu = getCPUInfo();
if(cpu == NULL) if(cpu == NULL)
return EXIT_FAILURE; return EXIT_FAILURE;

View File

@@ -179,13 +179,13 @@ void print_ascii_intel(struct ascii* art) {
} }
/*** PRINT ATTRIBUTE ***/ /*** PRINT ATTRIBUTE ***/
if(n>LINES_SPACE_UP-1 && n<NUMBER_OF_LINES-LINES_SPACE_DOWN)printf("%s%s%s%s"RESET"\n",art->color1,ATTRIBUTE_FIELDS[n-LINES_SPACE_UP],art->color2,art->atributes[n-LINES_SPACE_UP]); if(n>LINES_SPACE_UP-1 && n<NUMBER_OF_LINES-LINES_SPACE_DOWN)
printf("%s%s%s%s"RESET"\n",art->color1,ATTRIBUTE_FIELDS[n-LINES_SPACE_UP],art->color2,art->atributes[n-LINES_SPACE_UP]);
else printf("\n"); else printf("\n");
} }
} }
void print_ascii_amd(struct ascii* art) { void print_ascii_amd(struct ascii* art) {
int flag = BOOLEAN_FALSE;
for(int n=0;n<NUMBER_OF_LINES;n++) { for(int n=0;n<NUMBER_OF_LINES;n++) {
/*** PRINT ASCII-ART ***/ /*** PRINT ASCII-ART ***/
@@ -199,7 +199,8 @@ void print_ascii_amd(struct ascii* art) {
} }
/*** PRINT ATTRIBUTE ***/ /*** PRINT ATTRIBUTE ***/
if(n>2 && n<NUMBER_OF_LINES-4)printf("%s%s%s%s"RESET"\n",art->color1,ATTRIBUTE_FIELDS[n-3],art->color2,art->atributes[n-3]); if(n>LINES_SPACE_UP-1 && n<NUMBER_OF_LINES-LINES_SPACE_DOWN)
printf("%s%s%s%s"RESET"\n",art->color1,ATTRIBUTE_FIELDS[n-LINES_SPACE_UP],art->color2,art->atributes[n-LINES_SPACE_UP]);
else printf("\n"); else printf("\n");
} }