mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
[v0.99][X86] Add --full-cpu-name option
This commit is contained in:
@@ -24,6 +24,7 @@ struct args_struct {
|
|||||||
bool debug_flag;
|
bool debug_flag;
|
||||||
bool help_flag;
|
bool help_flag;
|
||||||
bool raw_flag;
|
bool raw_flag;
|
||||||
|
bool full_cpu_name_flag;
|
||||||
bool verbose_flag;
|
bool verbose_flag;
|
||||||
bool version_flag;
|
bool version_flag;
|
||||||
STYLE style;
|
STYLE style;
|
||||||
@@ -31,23 +32,25 @@ struct args_struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const char args_chr[] = {
|
const char args_chr[] = {
|
||||||
/* [ARG_CHAR_STYLE] = */ 's',
|
/* [ARG_CHAR_STYLE] = */ 's',
|
||||||
/* [ARG_CHAR_COLOR] = */ 'c',
|
/* [ARG_CHAR_COLOR] = */ 'c',
|
||||||
/* [ARG_CHAR_HELP] = */ 'h',
|
/* [ARG_CHAR_HELP] = */ 'h',
|
||||||
/* [ARG_CHAR_RAW] = */ 'r',
|
/* [ARG_CHAR_RAW] = */ 'r',
|
||||||
/* [ARG_CHAR_DEBUG] = */ 'd',
|
/* [ARG_CHAR_FULLCPUNAME] = */ 'F',
|
||||||
/* [ARG_CHAR_VERBOSE] = */ 'v',
|
/* [ARG_CHAR_DEBUG] = */ 'd',
|
||||||
/* [ARG_CHAR_VERSION] = */ 'V',
|
/* [ARG_CHAR_VERBOSE] = */ 'v',
|
||||||
|
/* [ARG_CHAR_VERSION] = */ 'V',
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *args_str[] = {
|
const char *args_str[] = {
|
||||||
/* [ARG_CHAR_STYLE] = */ "style",
|
/* [ARG_CHAR_STYLE] = */ "style",
|
||||||
/* [ARG_CHAR_COLOR] = */ "color",
|
/* [ARG_CHAR_COLOR] = */ "color",
|
||||||
/* [ARG_CHAR_HELP] = */ "help",
|
/* [ARG_CHAR_HELP] = */ "help",
|
||||||
/* [ARG_CHAR_RAW] = */ "raw",
|
/* [ARG_CHAR_RAW] = */ "raw",
|
||||||
/* [ARG_CHAR_DEBUG] = */ "debug",
|
/* [ARG_CHAR_FULLCPUNAME] = */ "full-cpu-name",
|
||||||
/* [ARG_CHAR_VERBOSE] = */ "verbose",
|
/* [ARG_CHAR_DEBUG] = */ "debug",
|
||||||
/* [ARG_CHAR_VERSION] = */ "version",
|
/* [ARG_CHAR_VERBOSE] = */ "verbose",
|
||||||
|
/* [ARG_CHAR_VERSION] = */ "version",
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct args_struct args;
|
static struct args_struct args;
|
||||||
@@ -76,6 +79,10 @@ bool show_raw() {
|
|||||||
return args.raw_flag;
|
return args.raw_flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool show_full_cpu_name() {
|
||||||
|
return args.full_cpu_name_flag;
|
||||||
|
}
|
||||||
|
|
||||||
bool verbose_enabled() {
|
bool verbose_enabled() {
|
||||||
return args.verbose_flag;
|
return args.verbose_flag;
|
||||||
}
|
}
|
||||||
@@ -172,9 +179,10 @@ char* build_short_options() {
|
|||||||
memset(str, 0, sizeof(char) * (len*2 + 1));
|
memset(str, 0, sizeof(char) * (len*2 + 1));
|
||||||
|
|
||||||
#ifdef ARCH_X86
|
#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_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
|
#else
|
||||||
sprintf(str, "%c:%c:%c%c%c%c",
|
sprintf(str, "%c:%c:%c%c%c%c",
|
||||||
c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP],
|
c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP],
|
||||||
@@ -191,6 +199,7 @@ bool parse_args(int argc, char* argv[]) {
|
|||||||
|
|
||||||
bool color_flag = false;
|
bool color_flag = false;
|
||||||
args.debug_flag = false;
|
args.debug_flag = false;
|
||||||
|
args.full_cpu_name_flag = false;
|
||||||
args.raw_flag = false;
|
args.raw_flag = false;
|
||||||
args.verbose_flag = false;
|
args.verbose_flag = false;
|
||||||
args.help_flag = false;
|
args.help_flag = false;
|
||||||
@@ -198,15 +207,16 @@ bool parse_args(int argc, char* argv[]) {
|
|||||||
args.colors = NULL;
|
args.colors = NULL;
|
||||||
|
|
||||||
const struct option long_options[] = {
|
const struct option long_options[] = {
|
||||||
{args_str[ARG_STYLE], required_argument, 0, args_chr[ARG_STYLE] },
|
{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_COLOR], required_argument, 0, args_chr[ARG_COLOR] },
|
||||||
{args_str[ARG_HELP], no_argument, 0, args_chr[ARG_HELP] },
|
{args_str[ARG_HELP], no_argument, 0, args_chr[ARG_HELP] },
|
||||||
#ifdef ARCH_X86
|
#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
|
#endif
|
||||||
{args_str[ARG_DEBUG], no_argument, 0, args_chr[ARG_DEBUG] },
|
{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_VERBOSE], no_argument, 0, args_chr[ARG_VERBOSE] },
|
||||||
{args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] },
|
{args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] },
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -240,6 +250,9 @@ bool parse_args(int argc, char* argv[]) {
|
|||||||
else if(opt == args_chr[ARG_HELP]) {
|
else if(opt == args_chr[ARG_HELP]) {
|
||||||
args.help_flag = true;
|
args.help_flag = true;
|
||||||
}
|
}
|
||||||
|
else if(opt == args_chr[ARG_FULLCPUNAME]) {
|
||||||
|
args.full_cpu_name_flag = true;
|
||||||
|
}
|
||||||
else if(opt == args_chr[ARG_RAW]) {
|
else if(opt == args_chr[ARG_RAW]) {
|
||||||
args.raw_flag = true;
|
args.raw_flag = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ enum {
|
|||||||
ARG_COLOR,
|
ARG_COLOR,
|
||||||
ARG_HELP,
|
ARG_HELP,
|
||||||
ARG_RAW,
|
ARG_RAW,
|
||||||
|
ARG_FULLCPUNAME,
|
||||||
ARG_DEBUG,
|
ARG_DEBUG,
|
||||||
ARG_VERBOSE,
|
ARG_VERBOSE,
|
||||||
ARG_VERSION
|
ARG_VERSION
|
||||||
@@ -37,6 +38,7 @@ extern const char *args_str[];
|
|||||||
int max_arg_str_length();
|
int max_arg_str_length();
|
||||||
bool parse_args(int argc, char* argv[]);
|
bool parse_args(int argc, char* argv[]);
|
||||||
bool show_help();
|
bool show_help();
|
||||||
|
bool show_full_cpu_name();
|
||||||
bool show_raw();
|
bool show_raw();
|
||||||
bool show_debug();
|
bool show_debug();
|
||||||
bool show_version();
|
bool show_version();
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ int64_t get_freq(struct frequency* freq) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ARCH_X86) || defined(ARCH_PPC)
|
#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;
|
return cpu->cpu_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ struct cpuInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if defined(ARCH_X86) || defined(ARCH_PPC)
|
#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);
|
char* get_str_sockets(struct topology* topo);
|
||||||
uint32_t get_nsockets(struct topology* topo);
|
uint32_t get_nsockets(struct topology* topo);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ void print_help(char *argv[]) {
|
|||||||
#endif
|
#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])), "");
|
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
|
#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])), "");
|
printf(" -%c, --%s %*s Prints raw cpuid data\n", c[ARG_RAW], t[ARG_RAW], (int) (max_len-strlen(t[ARG_RAW])), "");
|
||||||
#endif
|
#endif
|
||||||
printf(" -%c, --%s %*s Prints this help and exit\n", c[ARG_HELP], t[ARG_HELP], (int) (max_len-strlen(t[ARG_HELP])), "");
|
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);
|
print_debug(cpu);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(show_raw()) {
|
if(show_raw()) {
|
||||||
#ifdef ARCH_X86
|
#ifdef ARCH_X86
|
||||||
print_version();
|
print_version();
|
||||||
@@ -128,8 +129,8 @@ int main(int argc, char* argv[]) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if(print_cpufetch(cpu, get_style(), get_colors()))
|
if(print_cpufetch(cpu, get_style(), get_colors(), show_full_cpu_name()))
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
else
|
else
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|||||||
@@ -380,7 +380,7 @@ void print_ascii_generic(struct ascii* art, uint32_t la) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ARCH_X86
|
#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);
|
struct ascii* art = set_ascii(get_cpu_vendor(cpu), s);
|
||||||
if(art == NULL)
|
if(art == NULL)
|
||||||
return false;
|
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* max_frequency = get_str_freq(cpu->freq);
|
||||||
char* n_cores = get_str_topology(cpu, cpu->topo, false);
|
char* n_cores = get_str_topology(cpu, cpu->topo, false);
|
||||||
char* n_cores_dual = get_str_topology(cpu, cpu->topo, true);
|
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* avx = get_str_avx(cpu);
|
||||||
char* fma = get_str_fma(cpu);
|
char* fma = get_str_fma(cpu);
|
||||||
|
|
||||||
@@ -728,11 +728,11 @@ struct terminal* get_terminal_size() {
|
|||||||
return term;
|
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();
|
struct terminal* term = get_terminal_size();
|
||||||
|
|
||||||
#ifdef ARCH_X86
|
#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
|
#elif ARCH_PPC
|
||||||
return print_cpufetch_ppc(cpu, s, cs, term);
|
return print_cpufetch_ppc(cpu, s, cs, term);
|
||||||
#elif ARCH_ARM
|
#elif ARCH_ARM
|
||||||
|
|||||||
@@ -22,6 +22,6 @@ typedef int STYLE;
|
|||||||
void print_levels(struct cpuInfo* cpu);
|
void print_levels(struct cpuInfo* cpu);
|
||||||
#endif
|
#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
|
#endif
|
||||||
|
|||||||
@@ -360,7 +360,6 @@ struct cpuInfo* get_cpu_info() {
|
|||||||
|
|
||||||
if (cpu->maxExtendedLevels >= 0x80000004){
|
if (cpu->maxExtendedLevels >= 0x80000004){
|
||||||
cpu->cpu_name = get_str_cpu_name_internal();
|
cpu->cpu_name = get_str_cpu_name_internal();
|
||||||
if(cpu->cpu_vendor == CPU_VENDOR_INTEL) abbreviate_intel_cpu_name(&cpu->cpu_name);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cpu->cpu_name = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN) + 1));
|
cpu->cpu_name = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN) + 1));
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ char* get_str_sse(struct cpuInfo* cpu);
|
|||||||
char* get_str_fma(struct cpuInfo* cpu);
|
char* get_str_fma(struct cpuInfo* cpu);
|
||||||
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket);
|
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_debug(struct cpuInfo* cpu);
|
||||||
void print_raw(struct cpuInfo* cpu);
|
void print_raw(struct cpuInfo* cpu);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user