diff --git a/cpufetch.8 b/cpufetch.8 index f5c2d72..df0f381 100644 --- a/cpufetch.8 +++ b/cpufetch.8 @@ -22,6 +22,9 @@ Theoretical peak flops \fB\-\-help\fR Prints help .TP +\fB\-\-version\fR +Prints cpufetch version +.TP \fB\-\-style\fR Specify the color style of ascii logo .SH BUGS diff --git a/src/args.c b/src/args.c index db67784..9e693f5 100644 --- a/src/args.c +++ b/src/args.c @@ -3,15 +3,18 @@ #include #include "args.h" -#define ARG_STR_STYLE "style" -#define ARG_STR_HELP "help" -#define ARG_CHAR_STYLE 's' -#define ARG_CHAR_HELP 'h' +#define ARG_STR_STYLE "style" +#define ARG_STR_HELP "help" +#define ARG_STR_VERSION "version" +#define ARG_CHAR_STYLE 's' +#define ARG_CHAR_HELP 'h' +#define ARG_CHAR_VERSION 'v' #define STYLE_STR_1 "default" #define STYLE_STR_2 "dark" struct args_struct { int help_flag; + int version_flag; STYLE style; }; @@ -36,6 +39,10 @@ int showHelp() { return args.help_flag; } +int showVersion() { + return args.version_flag; +} + int parseArgs(int argc, char* argv[]) { int c; int digit_optind = 0; @@ -46,8 +53,9 @@ int parseArgs(int argc, char* argv[]) { args.style = STYLE_EMPTY; static struct option long_options[] = { - {ARG_STR_STYLE, required_argument, 0, ARG_CHAR_STYLE}, - {ARG_STR_HELP, no_argument, 0, ARG_CHAR_HELP }, + {ARG_STR_STYLE, required_argument, 0, ARG_CHAR_STYLE }, + {ARG_STR_HELP, no_argument, 0, ARG_CHAR_HELP }, + {ARG_STR_VERSION, no_argument, 0, ARG_CHAR_VERSION }, {0, 0, 0, 0} }; @@ -72,6 +80,13 @@ int parseArgs(int argc, char* argv[]) { } 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 == '?') { printf("WARNING: Invalid options\n"); args.help_flag = BOOLEAN_TRUE; @@ -89,5 +104,10 @@ int parseArgs(int argc, char* argv[]) { 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; } diff --git a/src/args.h b/src/args.h index 1f1e02a..414ba2e 100644 --- a/src/args.h +++ b/src/args.h @@ -6,5 +6,6 @@ int parseArgs(int argc, char* argv[]); STYLE getStyle(); int showHelp(); +int showVersion(); #endif diff --git a/src/main.c b/src/main.c index 9a0d2f9..b43a604 100644 --- a/src/main.c +++ b/src/main.c @@ -25,17 +25,23 @@ Peak FLOPS: 512 GFLOP/s(in simple precision) ***/ -void help(int argc, char *argv[]) -{ - printf("Usage: %s [--help] [--style STYLE]\n\ +static const char* VERSION = "0.33"; + +void help(int argc, char *argv[]) { + printf("Usage: %s [--version] [--help] [--style STYLE]\n\ Options: \n\ - --style Set logo style color\n\ - default: Default style color\n\ - dark: Dark style color\n\n\ - --help Print this help and exit\n", + --style Set logo style color\n\ + default: Default style color\n\ + dark: Dark style color\n\ + --help Print this help and exit\n\ + --version Print cpufetch version and exit\n", argv[0]); } +void version() { + printf("cpufetch v%s\n",VERSION); +} + int main(int argc, char* argv[]) { if(!parseArgs(argc,argv)) return EXIT_FAILURE; @@ -45,6 +51,11 @@ int main(int argc, char* argv[]) { return EXIT_SUCCESS; } + if(showVersion()) { + version(); + return EXIT_SUCCESS; + } + struct cpuInfo* cpu = getCPUInfo(); if(cpu == NULL) return EXIT_FAILURE; diff --git a/src/printer.c b/src/printer.c index ef00a96..05011d2 100644 --- a/src/printer.c +++ b/src/printer.c @@ -179,13 +179,13 @@ void print_ascii_intel(struct ascii* art) { } /*** PRINT ATTRIBUTE ***/ - if(n>LINES_SPACE_UP-1 && ncolor1,ATTRIBUTE_FIELDS[n-LINES_SPACE_UP],art->color2,art->atributes[n-LINES_SPACE_UP]); + if(n>LINES_SPACE_UP-1 && ncolor1,ATTRIBUTE_FIELDS[n-LINES_SPACE_UP],art->color2,art->atributes[n-LINES_SPACE_UP]); else printf("\n"); } } void print_ascii_amd(struct ascii* art) { - int flag = BOOLEAN_FALSE; for(int n=0;n2 && ncolor1,ATTRIBUTE_FIELDS[n-3],art->color2,art->atributes[n-3]); + if(n>LINES_SPACE_UP-1 && ncolor1,ATTRIBUTE_FIELDS[n-LINES_SPACE_UP],art->color2,art->atributes[n-LINES_SPACE_UP]); else printf("\n"); }