diff --git a/src/args.c b/src/args.c index e787704..6f99581 100644 --- a/src/args.c +++ b/src/args.c @@ -9,26 +9,30 @@ #define ARG_STR_COLOR "color" #define ARG_STR_HELP "help" #define ARG_STR_LEVELS "levels" +#define ARG_STR_VERBOSE "verbose" #define ARG_STR_VERSION "version" #define ARG_CHAR_STYLE 's' #define ARG_CHAR_COLOR 'c' #define ARG_CHAR_HELP 'h' #define ARG_CHAR_LEVELS 'l' +#define ARG_CHAR_VERBOSE 'v' #define ARG_CHAR_VERSION 'v' #define STYLE_STR_1 "fancy" #define STYLE_STR_2 "retro" +#define STYLE_STR_3 "legacy" struct args_struct { bool levels_flag; bool help_flag; + bool verbose_flag; bool version_flag; STYLE style; struct colors* colors; }; -static const char* SYTLES_STR_LIST[STYLES_COUNT] = { STYLE_STR_1, STYLE_STR_2 }; +static const char* SYTLES_STR_LIST[STYLES_COUNT] = { STYLE_STR_1, STYLE_STR_2, STYLE_STR_3 }; static struct args_struct args; STYLE get_style() { @@ -52,7 +56,7 @@ bool show_levels() { } bool verbose_enabled() { - return false; + return args.verbose_flag; } STYLE parse_style(char* style) { @@ -96,7 +100,7 @@ bool parse_color(char* optarg, struct colors** cs) { return false; } - /* + //TODO: Refactor c1->R c2->R ... to c[i]->R if((*c1)->R < 0 || (*c1)->R > 255) { printErr("Red in color 1 is invalid. Must be in range (0, 255)"); return false; @@ -120,7 +124,7 @@ bool parse_color(char* optarg, struct colors** cs) { if((*c2)->B < 0 || (*c2)->B > 255) { printErr("Blue in color 2 is invalid. Must be in range (0, 255)"); return false; - }*/ + } return true; } @@ -133,6 +137,7 @@ bool parse_args(int argc, char* argv[]) { bool color_flag = false; args.levels_flag = false; + args.verbose_flag = false; args.help_flag = false; args.style = STYLE_EMPTY; args.colors = NULL; @@ -142,11 +147,12 @@ bool parse_args(int argc, char* argv[]) { {ARG_STR_COLOR, required_argument, 0, ARG_CHAR_COLOR }, {ARG_STR_HELP, no_argument, 0, ARG_CHAR_HELP }, {ARG_STR_LEVELS, no_argument, 0, ARG_CHAR_LEVELS }, + {ARG_STR_VERBOSE, no_argument, 0, ARG_CHAR_VERBOSE }, {ARG_STR_VERSION, no_argument, 0, ARG_CHAR_VERSION }, {0, 0, 0, 0} }; - c = getopt_long(argc, argv,"",long_options, &option_index); + c = getopt_long(argc, argv, "", long_options, &option_index); while (c != -1) { if(c == ARG_CHAR_COLOR) { @@ -178,6 +184,13 @@ bool parse_args(int argc, char* argv[]) { } args.help_flag = true; } + else if(c == ARG_CHAR_VERBOSE) { + if(args.verbose_flag) { + printErr("Verbose option specified more than once"); + return false; + } + args.verbose_flag = true; + } else if(c == ARG_CHAR_LEVELS) { if(args.levels_flag) { printErr("Levels option specified more than once"); diff --git a/src/cpuid.c b/src/cpuid.c index 8163a5e..0f928f0 100644 --- a/src/cpuid.c +++ b/src/cpuid.c @@ -288,7 +288,7 @@ struct topology* get_topology_info(struct cpuInfo* cpu) { topo->total_cores = topo->logical_cores; // fallback } #endif - + switch(cpu->cpu_vendor) { case VENDOR_INTEL: if (cpu->maxLevels >= 0x00000004) { diff --git a/src/main.c b/src/main.c index fbaa1d7..a0424ca 100644 --- a/src/main.c +++ b/src/main.c @@ -6,10 +6,10 @@ #include "cpuid.h" #include "global.h" -static const char* VERSION = "0.57"; +static const char* VERSION = "0.59"; void print_help(char *argv[]) { - printf("Usage: %s [--version] [--help] [--levels] [--style fancy|retro] [--color 'R,G,B:R,G,B:R,G,B:R,G,B']\n\ + printf("Usage: %s [--version] [--help] [--levels] [--style fancy|retro|legacy] [--color 'R,G,B:R,G,B:R,G,B:R,G,B']\n\ Options: \n\ --color Set text color. 4 colors (in RGB format) must be specified in the form: R,G,B:R,G,B:...\n\ These colors correspond to the ASCII art color (2 colors) and for the text colors (next 2)\n\ @@ -17,6 +17,7 @@ Options: \n\ --style Set the style of the ASCII art:\n\ * fancy \n\ * retro \n\ + * legacy \n\ --help Prints this help and exit\n\ --levels Prints CPU model and cpuid levels (debug purposes)\n\ --version Prints cpufetch version and exit\n", diff --git a/src/printer.c b/src/printer.c index 76d8db6..b89d366 100644 --- a/src/printer.c +++ b/src/printer.c @@ -147,23 +147,23 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style, struct colors* cs) { } art->ascii_chars[1] = '#'; - #ifdef _WIN32 - strcpy(art->color1_ascii,COL_NONE); - strcpy(art->color2_ascii,COL_NONE); - strcpy(art->color1_text,COL_NONE); - strcpy(art->color2_text,COL_NONE); - art->reset[0] = '\0'; - #else + // If style is emtpy, set the default style + if(style == STYLE_EMPTY) { + #ifdef _WIN32 + style = STYLE_LEGACY; + #else + style = STYLE_FANCY; + #endif + } + switch(style) { - case STYLE_EMPTY: - #ifdef _WIN32 - strcpy(art->color1_ascii,COL_NONE); - strcpy(art->color2_ascii,COL_NONE); - strcpy(art->color1_text,COL_NONE); - strcpy(art->color2_text,COL_NONE); - art->reset[0] = '\0'; - break; - #endif + case STYLE_LEGACY: + strcpy(art->color1_ascii,COL_NONE); + strcpy(art->color2_ascii,COL_NONE); + strcpy(art->color1_text,COL_NONE); + strcpy(art->color2_text,COL_NONE); + art->reset[0] = '\0'; + break; case STYLE_FANCY: if(cs != NULL) { COL_FANCY_1 = rgb_to_ansi(cs->c1, true, true); @@ -207,7 +207,6 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style, struct colors* cs) { printBug("Found invalid style (%d)",style); return NULL; } - #endif char tmp[NUMBER_OF_LINES*LINE_SIZE]; if(cpuVendor == VENDOR_INTEL) strcpy(tmp, INTEL_ASCII); diff --git a/src/printer.h b/src/printer.h index 0bea06e..34ae3b7 100644 --- a/src/printer.h +++ b/src/printer.h @@ -6,12 +6,13 @@ typedef int STYLE; #include "args.h" #include "cpuid.h" -#define STYLES_COUNT 2 +#define STYLES_COUNT 3 #define STYLE_INVALID -2 #define STYLE_EMPTY -1 #define STYLE_FANCY 0 #define STYLE_RETRO 1 +#define STYLE_LEGACY 2 bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* freq, struct topology* topo, STYLE s, struct colors* cs);