[v0.99][X86] Add --full-cpu-name option

This commit is contained in:
Dr-Noob
2021-08-11 23:24:48 +02:00
parent 06a76d4c75
commit 6d79a96fa8
9 changed files with 54 additions and 34 deletions

View File

@@ -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;
@@ -35,6 +36,7 @@ const char args_chr[] = {
/* [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',
@@ -45,6 +47,7 @@ const char *args_str[] = {
/* [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",
@@ -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;
@@ -202,6 +211,7 @@ bool parse_args(int argc, char* argv[]) {
{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_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] },
@@ -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;
}

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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])), "");
@@ -129,7 +130,7 @@ int main(int argc, char* argv[]) {
#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;

View File

@@ -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

View File

@@ -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

View File

@@ -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));

View File

@@ -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);