From 6d79a96fa8dfcbb0a1da435a11c5b35c3479529d Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Wed, 11 Aug 2021 23:24:48 +0200 Subject: [PATCH] [v0.99][X86] Add --full-cpu-name option --- src/common/args.c | 59 +++++++++++++++++++++++++++----------------- src/common/args.h | 2 ++ src/common/cpu.c | 5 +++- src/common/cpu.h | 2 +- src/common/main.c | 7 +++--- src/common/printer.c | 8 +++--- src/common/printer.h | 2 +- src/x86/cpuid.c | 1 - src/x86/cpuid.h | 2 ++ 9 files changed, 54 insertions(+), 34 deletions(-) diff --git a/src/common/args.c b/src/common/args.c index 3860741..5779334 100644 --- a/src/common/args.c +++ b/src/common/args.c @@ -24,6 +24,7 @@ struct args_struct { bool debug_flag; bool help_flag; bool raw_flag; + bool full_cpu_name_flag; bool verbose_flag; bool version_flag; STYLE style; @@ -31,23 +32,25 @@ struct args_struct { }; const char args_chr[] = { - /* [ARG_CHAR_STYLE] = */ 's', - /* [ARG_CHAR_COLOR] = */ 'c', - /* [ARG_CHAR_HELP] = */ 'h', - /* [ARG_CHAR_RAW] = */ 'r', - /* [ARG_CHAR_DEBUG] = */ 'd', - /* [ARG_CHAR_VERBOSE] = */ 'v', - /* [ARG_CHAR_VERSION] = */ 'V', + /* [ARG_CHAR_STYLE] = */ 's', + /* [ARG_CHAR_COLOR] = */ 'c', + /* [ARG_CHAR_HELP] = */ 'h', + /* [ARG_CHAR_RAW] = */ 'r', + /* [ARG_CHAR_FULLCPUNAME] = */ 'F', + /* [ARG_CHAR_DEBUG] = */ 'd', + /* [ARG_CHAR_VERBOSE] = */ 'v', + /* [ARG_CHAR_VERSION] = */ 'V', }; const char *args_str[] = { - /* [ARG_CHAR_STYLE] = */ "style", - /* [ARG_CHAR_COLOR] = */ "color", - /* [ARG_CHAR_HELP] = */ "help", - /* [ARG_CHAR_RAW] = */ "raw", - /* [ARG_CHAR_DEBUG] = */ "debug", - /* [ARG_CHAR_VERBOSE] = */ "verbose", - /* [ARG_CHAR_VERSION] = */ "version", + /* [ARG_CHAR_STYLE] = */ "style", + /* [ARG_CHAR_COLOR] = */ "color", + /* [ARG_CHAR_HELP] = */ "help", + /* [ARG_CHAR_RAW] = */ "raw", + /* [ARG_CHAR_FULLCPUNAME] = */ "full-cpu-name", + /* [ARG_CHAR_DEBUG] = */ "debug", + /* [ARG_CHAR_VERBOSE] = */ "verbose", + /* [ARG_CHAR_VERSION] = */ "version", }; static struct args_struct args; @@ -76,6 +79,10 @@ bool show_raw() { return args.raw_flag; } +bool show_full_cpu_name() { + return args.full_cpu_name_flag; +} + bool verbose_enabled() { return args.verbose_flag; } @@ -172,9 +179,10 @@ char* build_short_options() { memset(str, 0, sizeof(char) * (len*2 + 1)); #ifdef ARCH_X86 - sprintf(str, "%c:%c:%c%c%c%c%c", + sprintf(str, "%c:%c:%c%c%c%c%c%c", c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP], c[ARG_RAW], - c[ARG_DEBUG], c[ARG_VERBOSE], c[ARG_VERSION]); + c[ARG_FULLCPUNAME], c[ARG_DEBUG], c[ARG_VERBOSE], + c[ARG_VERSION]); #else sprintf(str, "%c:%c:%c%c%c%c", c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP], @@ -191,6 +199,7 @@ bool parse_args(int argc, char* argv[]) { bool color_flag = false; args.debug_flag = false; + args.full_cpu_name_flag = false; args.raw_flag = false; args.verbose_flag = false; args.help_flag = false; @@ -198,15 +207,16 @@ bool parse_args(int argc, char* argv[]) { args.colors = NULL; const struct option long_options[] = { - {args_str[ARG_STYLE], required_argument, 0, args_chr[ARG_STYLE] }, - {args_str[ARG_COLOR], required_argument, 0, args_chr[ARG_COLOR] }, - {args_str[ARG_HELP], no_argument, 0, args_chr[ARG_HELP] }, + {args_str[ARG_STYLE], required_argument, 0, args_chr[ARG_STYLE] }, + {args_str[ARG_COLOR], required_argument, 0, args_chr[ARG_COLOR] }, + {args_str[ARG_HELP], no_argument, 0, args_chr[ARG_HELP] }, #ifdef ARCH_X86 - {args_str[ARG_RAW], no_argument, 0, args_chr[ARG_RAW] }, + {args_str[ARG_FULLCPUNAME], no_argument, 0, args_chr[ARG_FULLCPUNAME] }, + {args_str[ARG_RAW], no_argument, 0, args_chr[ARG_RAW] }, #endif - {args_str[ARG_DEBUG], no_argument, 0, args_chr[ARG_DEBUG] }, - {args_str[ARG_VERBOSE], no_argument, 0, args_chr[ARG_VERBOSE] }, - {args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] }, + {args_str[ARG_DEBUG], no_argument, 0, args_chr[ARG_DEBUG] }, + {args_str[ARG_VERBOSE], no_argument, 0, args_chr[ARG_VERBOSE] }, + {args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] }, {0, 0, 0, 0} }; @@ -240,6 +250,9 @@ bool parse_args(int argc, char* argv[]) { else if(opt == args_chr[ARG_HELP]) { args.help_flag = true; } + else if(opt == args_chr[ARG_FULLCPUNAME]) { + args.full_cpu_name_flag = true; + } else if(opt == args_chr[ARG_RAW]) { args.raw_flag = true; } diff --git a/src/common/args.h b/src/common/args.h index 0d6f270..f48578a 100644 --- a/src/common/args.h +++ b/src/common/args.h @@ -24,6 +24,7 @@ enum { ARG_COLOR, ARG_HELP, ARG_RAW, + ARG_FULLCPUNAME, ARG_DEBUG, ARG_VERBOSE, ARG_VERSION @@ -37,6 +38,7 @@ extern const char *args_str[]; int max_arg_str_length(); bool parse_args(int argc, char* argv[]); bool show_help(); +bool show_full_cpu_name(); bool show_raw(); bool show_debug(); bool show_version(); diff --git a/src/common/cpu.c b/src/common/cpu.c index 4ddc768..a1f6a42 100644 --- a/src/common/cpu.c +++ b/src/common/cpu.c @@ -33,7 +33,10 @@ int64_t get_freq(struct frequency* freq) { } #if defined(ARCH_X86) || defined(ARCH_PPC) -char* get_str_cpu_name(struct cpuInfo* cpu) { +char* get_str_cpu_name(struct cpuInfo* cpu, bool fcpuname) { + if(cpu->cpu_vendor == CPU_VENDOR_INTEL && !fcpuname) { + abbreviate_intel_cpu_name(&cpu->cpu_name); + } return cpu->cpu_name; } diff --git a/src/common/cpu.h b/src/common/cpu.h index a0ab4f9..fea607f 100644 --- a/src/common/cpu.h +++ b/src/common/cpu.h @@ -147,7 +147,7 @@ struct cpuInfo { }; #if defined(ARCH_X86) || defined(ARCH_PPC) -char* get_str_cpu_name(struct cpuInfo* cpu); +char* get_str_cpu_name(struct cpuInfo* cpu, bool fcpuname); char* get_str_sockets(struct topology* topo); uint32_t get_nsockets(struct topology* topo); #endif diff --git a/src/common/main.c b/src/common/main.c index c83651a..dc235b0 100644 --- a/src/common/main.c +++ b/src/common/main.c @@ -53,6 +53,7 @@ void print_help(char *argv[]) { #endif printf(" -%c, --%s %*s Prints extra information (if available) about how cpufetch tried fetching information\n", c[ARG_VERBOSE], t[ARG_VERBOSE], (int) (max_len-strlen(t[ARG_VERBOSE])), ""); #ifdef ARCH_X86 + printf(" -%c, --%s %*s Show the full CPU name (do not abbreviate it)\n", c[ARG_FULLCPUNAME], t[ARG_FULLCPUNAME], (int) (max_len-strlen(t[ARG_FULLCPUNAME])), ""); printf(" -%c, --%s %*s Prints raw cpuid data\n", c[ARG_RAW], t[ARG_RAW], (int) (max_len-strlen(t[ARG_RAW])), ""); #endif printf(" -%c, --%s %*s Prints this help and exit\n", c[ARG_HELP], t[ARG_HELP], (int) (max_len-strlen(t[ARG_HELP])), ""); @@ -117,7 +118,7 @@ int main(int argc, char* argv[]) { print_debug(cpu); return EXIT_SUCCESS; } - + if(show_raw()) { #ifdef ARCH_X86 print_version(); @@ -128,8 +129,8 @@ int main(int argc, char* argv[]) { return EXIT_FAILURE; #endif } - - if(print_cpufetch(cpu, get_style(), get_colors())) + + if(print_cpufetch(cpu, get_style(), get_colors(), show_full_cpu_name())) return EXIT_SUCCESS; else return EXIT_FAILURE; diff --git a/src/common/printer.c b/src/common/printer.c index 2c4e4b6..8f75063 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -380,7 +380,7 @@ void print_ascii_generic(struct ascii* art, uint32_t la) { #endif #ifdef ARCH_X86 -bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct terminal* term) { +bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct terminal* term, bool fcpuname) { struct ascii* art = set_ascii(get_cpu_vendor(cpu), s); if(art == NULL) return false; @@ -391,7 +391,7 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct char* max_frequency = get_str_freq(cpu->freq); char* n_cores = get_str_topology(cpu, cpu->topo, false); char* n_cores_dual = get_str_topology(cpu, cpu->topo, true); - char* cpu_name = get_str_cpu_name(cpu); + char* cpu_name = get_str_cpu_name(cpu, fcpuname); char* avx = get_str_avx(cpu); char* fma = get_str_fma(cpu); @@ -728,11 +728,11 @@ struct terminal* get_terminal_size() { return term; } -bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs) { +bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs, bool show_full_cpu_name) { struct terminal* term = get_terminal_size(); #ifdef ARCH_X86 - return print_cpufetch_x86(cpu, s, cs, term); + return print_cpufetch_x86(cpu, s, cs, term, show_full_cpu_name); #elif ARCH_PPC return print_cpufetch_ppc(cpu, s, cs, term); #elif ARCH_ARM diff --git a/src/common/printer.h b/src/common/printer.h index f7159a4..6bcf675 100644 --- a/src/common/printer.h +++ b/src/common/printer.h @@ -22,6 +22,6 @@ typedef int STYLE; void print_levels(struct cpuInfo* cpu); #endif -bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs); +bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs, bool fcpuname); #endif diff --git a/src/x86/cpuid.c b/src/x86/cpuid.c index 2831d5e..dab8027 100644 --- a/src/x86/cpuid.c +++ b/src/x86/cpuid.c @@ -360,7 +360,6 @@ struct cpuInfo* get_cpu_info() { if (cpu->maxExtendedLevels >= 0x80000004){ cpu->cpu_name = get_str_cpu_name_internal(); - if(cpu->cpu_vendor == CPU_VENDOR_INTEL) abbreviate_intel_cpu_name(&cpu->cpu_name); } else { cpu->cpu_name = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN) + 1)); diff --git a/src/x86/cpuid.h b/src/x86/cpuid.h index 3dc6202..89a559a 100644 --- a/src/x86/cpuid.h +++ b/src/x86/cpuid.h @@ -13,6 +13,8 @@ char* get_str_sse(struct cpuInfo* cpu); char* get_str_fma(struct cpuInfo* cpu); char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket); +void abbreviate_intel_cpu_name(char** name); + void print_debug(struct cpuInfo* cpu); void print_raw(struct cpuInfo* cpu);