[v0.99] Add options: --logo-long --logo-short --logo-intel-new --logo-intel-old

This commit is contained in:
Dr-Noob
2021-08-19 11:40:00 +02:00
parent a302a4508c
commit c0935d1b4b
6 changed files with 138 additions and 52 deletions

View File

@@ -25,6 +25,10 @@ struct args_struct {
bool help_flag;
bool raw_flag;
bool full_cpu_name_flag;
bool logo_long;
bool logo_short;
bool logo_intel_new;
bool logo_intel_old;
bool verbose_flag;
bool version_flag;
STYLE style;
@@ -32,25 +36,33 @@ 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_FULLCPUNAME] = */ 'F',
/* [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_LOGO_LONG] = */ 1,
/* [ARG_CHAR_LOGO_SHORT] = */ 2,
/* [ARG_CHAR_LOGO_INTEL_NEW] = */ 3,
/* [ARG_CHAR_LOGO_INTEL_OLD] = */ 4,
/* [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_FULLCPUNAME] = */ "full-cpu-name",
/* [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_LOGO_LONG] = */ "logo-long",
/* [ARG_CHAR_LOGO_SHORT] = */ "logo-short",
/* [ARG_CHAR_LOGO_INTEL_NEW] = */ "logo-intel-new",
/* [ARG_CHAR_LOGO_INTEL_OLD] = */ "logo-intel-old",
/* [ARG_CHAR_DEBUG] = */ "debug",
/* [ARG_CHAR_VERBOSE] = */ "verbose",
/* [ARG_CHAR_VERSION] = */ "version",
};
static struct args_struct args;
@@ -83,6 +95,22 @@ bool show_full_cpu_name() {
return args.full_cpu_name_flag;
}
bool show_logo_long() {
return args.logo_long;
}
bool show_logo_short() {
return args.logo_short;
}
bool show_logo_intel_new() {
return args.logo_intel_new;
}
bool show_logo_intel_old() {
return args.logo_intel_old;
}
bool verbose_enabled() {
return args.verbose_flag;
}
@@ -179,14 +207,18 @@ char* build_short_options() {
memset(str, 0, sizeof(char) * (len*2 + 1));
#ifdef ARCH_X86
sprintf(str, "%c:%c:%c%c%c%c%c%c",
c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP], c[ARG_RAW],
c[ARG_FULLCPUNAME], c[ARG_DEBUG], c[ARG_VERBOSE],
c[ARG_VERSION]);
#else
sprintf(str, "%c:%c:%c%c%c%c",
sprintf(str, "%c:%c:%c%c%c%c%c%c%c%c%c%c",
c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP],
c[ARG_RAW], c[ARG_FULLCPUNAME],
c[ARG_LOGO_SHORT], c[ARG_LOGO_LONG],
c[ARG_LOGO_INTEL_NEW], c[ARG_LOGO_INTEL_OLD],
c[ARG_DEBUG], c[ARG_VERBOSE], c[ARG_VERSION]);
#else
sprintf(str, "%c:%c:%c%c%c%c%c%c",
c[ARG_STYLE], c[ARG_COLOR], c[ARG_HELP],
c[ARG_LOGO_SHORT], c[ARG_LOGO_LONG],
c[ARG_DEBUG], c[ARG_VERBOSE],
c[ARG_VERSION]);
#endif
return str;
@@ -202,21 +234,29 @@ bool parse_args(int argc, char* argv[]) {
args.full_cpu_name_flag = false;
args.raw_flag = false;
args.verbose_flag = false;
args.logo_long = false;
args.logo_short = false;
args.logo_intel_new = false;
args.logo_intel_old = false;
args.help_flag = false;
args.style = STYLE_EMPTY;
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_FULLCPUNAME], no_argument, 0, args_chr[ARG_FULLCPUNAME] },
{args_str[ARG_RAW], no_argument, 0, args_chr[ARG_RAW] },
{args_str[ARG_LOGO_INTEL_NEW], no_argument, 0, args_chr[ARG_LOGO_INTEL_NEW] },
{args_str[ARG_LOGO_INTEL_OLD], no_argument, 0, args_chr[ARG_LOGO_INTEL_OLD] },
{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_LOGO_SHORT], no_argument, 0, args_chr[ARG_LOGO_SHORT] },
{args_str[ARG_LOGO_LONG], no_argument, 0, args_chr[ARG_LOGO_LONG] },
{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}
};
@@ -253,6 +293,18 @@ bool parse_args(int argc, char* argv[]) {
else if(opt == args_chr[ARG_FULLCPUNAME]) {
args.full_cpu_name_flag = true;
}
else if(opt == args_chr[ARG_LOGO_SHORT]) {
args.logo_short = true;
}
else if(opt == args_chr[ARG_LOGO_LONG]) {
args.logo_long = true;
}
else if(opt == args_chr[ARG_LOGO_INTEL_NEW]) {
args.logo_intel_new = true;
}
else if(opt == args_chr[ARG_LOGO_INTEL_OLD]) {
args.logo_intel_old = true;
}
else if(opt == args_chr[ARG_RAW]) {
args.raw_flag = true;
}
@@ -284,5 +336,17 @@ bool parse_args(int argc, char* argv[]) {
args.help_flag = true;
}
if(args.logo_intel_new && args.logo_intel_old) {
printWarn("%s and %s cannot be specified together", args_str[ARG_LOGO_INTEL_NEW], args_str[ARG_LOGO_INTEL_OLD]);
args.logo_intel_new = false;
args.logo_intel_old = false;
}
if(args.logo_short && args.logo_long) {
printWarn("%s and %s cannot be specified together", args_str[ARG_LOGO_SHORT], args_str[ARG_LOGO_LONG]);
args.logo_short = false;
args.logo_long = false;
}
return true;
}

View File

@@ -25,6 +25,10 @@ enum {
ARG_HELP,
ARG_RAW,
ARG_FULLCPUNAME,
ARG_LOGO_LONG,
ARG_LOGO_SHORT,
ARG_LOGO_INTEL_NEW,
ARG_LOGO_INTEL_OLD,
ARG_DEBUG,
ARG_VERBOSE,
ARG_VERSION
@@ -39,6 +43,10 @@ int max_arg_str_length();
bool parse_args(int argc, char* argv[]);
bool show_help();
bool show_full_cpu_name();
bool show_logo_long();
bool show_logo_short();
bool show_logo_intel_new();
bool show_logo_intel_old();
bool show_raw();
bool show_debug();
bool show_version();

View File

@@ -51,8 +51,12 @@ void print_help(char *argv[]) {
#elif ARCH_ARM
printf(" -%c, --%s %*s Prints main ID register values for all cores (debug purposes)\n", c[ARG_DEBUG], t[ARG_DEBUG], (int) (max_len-strlen(t[ARG_DEBUG])), "");
#endif
printf(" --%s %*s Shows the short version of the logo\n", t[ARG_LOGO_SHORT], (int) (max_len-strlen(t[ARG_LOGO_SHORT])), "");
printf(" --%s %*s Shows the long version of the logo\n", t[ARG_LOGO_LONG], (int) (max_len-strlen(t[ARG_LOGO_LONG])), "");
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(" --%s %*s Show the old Intel logo\n", t[ARG_LOGO_INTEL_OLD], (int) (max_len-strlen(t[ARG_LOGO_INTEL_OLD])), "");
printf(" --%s %*s Show the new Intel logo\n", t[ARG_LOGO_INTEL_NEW], (int) (max_len-strlen(t[ARG_LOGO_INTEL_NEW])), "");
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

View File

@@ -257,37 +257,42 @@ void replace_bgbyfg_color(struct ascii_logo* logo) {
}
}
struct ascii_logo* choose_ascii_art_fits(struct ascii_logo* logo_iffits, struct ascii_logo* logo_ifdoesnt, struct terminal* term, int lf) {
if(term != NULL && ascii_fits_screen(term->w, *logo_iffits, lf)) {
return logo_iffits;
}
else {
return logo_ifdoesnt;
}
}
void choose_ascii_art(struct ascii* art, struct color** cs, struct terminal* term, int lf) {
// 1. Choose logo
#ifdef ARCH_X86
if(art->vendor == CPU_VENDOR_INTEL) {
if(art->new_intel_logo) {
if(term != NULL && ascii_fits_screen(term->w, logo_intel_l_new, lf))
art->art = &logo_intel_l_new;
else
art->art = &logo_intel_new;
if(show_logo_long()) art->art = &logo_intel_l_new;
else if(show_logo_short()) art->art = &logo_intel_new;
else art->art = choose_ascii_art_fits(&logo_intel_l_new, &logo_intel_new, term, lf);
}
else {
if(term != NULL && ascii_fits_screen(term->w, logo_intel_l, lf))
art->art = &logo_intel_l;
else
art->art = &logo_intel;
if(show_logo_long()) art->art = &logo_intel_l;
else if(show_logo_short()) art->art = &logo_intel;
else art->art = choose_ascii_art_fits(&logo_intel_l, &logo_intel, term, lf);
}
}
else if(art->vendor == CPU_VENDOR_AMD) {
if(term != NULL && ascii_fits_screen(term->w, logo_amd_l, lf))
art->art = &logo_amd_l;
else
art->art = &logo_amd;
if(show_logo_long()) art->art = &logo_amd_l;
else if(show_logo_short()) art->art = &logo_amd;
else art->art = choose_ascii_art_fits(&logo_amd_l, &logo_amd, term, lf);
}
else {
art->art = &logo_unknown;
}
#elif ARCH_PPC
if(term != NULL && ascii_fits_screen(term->w, logo_ibm_l, lf))
art->art = &logo_ibm_l;
else
art->art = &logo_ibm;
if(show_logo_long()) art->art = &logo_ibm_l;
else if(show_logo_short()) art->art = &logo_ibm;
else art->art = choose_ascii_art_fits(&logo_ibm_l, &logo_ibm, term, lf);
#elif ARCH_ARM
if(art->vendor == SOC_VENDOR_SNAPDRAGON)
art->art = &logo_snapd;
@@ -302,10 +307,9 @@ void choose_ascii_art(struct ascii* art, struct color** cs, struct terminal* ter
else if(art->vendor == SOC_VENDOR_APPLE)
art->art = &logo_apple;
else {
if(term != NULL && ascii_fits_screen(term->w, logo_arm_l, lf))
art->art = &logo_arm_l;
else
art->art = &logo_arm;
if(show_logo_long()) art->art = &logo_arm_l;
else if(show_logo_short()) art->art = &logo_arm;
else art->art = choose_ascii_art_fits(&logo_arm_l, &logo_arm, term, lf);
}
#endif
@@ -432,6 +436,12 @@ void print_ascii_generic(struct ascii* art, uint32_t la, int32_t text_space, con
#endif
#ifdef ARCH_X86
bool choose_new_intel_logo(struct cpuInfo* cpu) {
if(show_logo_intel_new()) return true;
if(show_logo_intel_old()) return false;
return choose_new_intel_logo_uarch(cpu);
}
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)

View File

@@ -399,7 +399,7 @@ int get_number_of_vpus(struct cpuInfo* cpu) {
}
}
bool choose_new_intel_logo(struct cpuInfo* cpu) {
bool choose_new_intel_logo_uarch(struct cpuInfo* cpu) {
switch(cpu->arch->uarch) {
case UARCH_ROCKET_LAKE:
// TODO: case UARCH_TIGER_LAKE: missing?

View File

@@ -11,7 +11,7 @@ struct uarch* get_uarch_from_cpuid(struct cpuInfo* cpu, uint32_t ef, uint32_t f,
bool vpus_are_AVX512(struct cpuInfo* cpu);
bool is_knights_landing(struct cpuInfo* cpu);
int get_number_of_vpus(struct cpuInfo* cpu);
bool choose_new_intel_logo(struct cpuInfo* cpu);
bool choose_new_intel_logo_uarch(struct cpuInfo* cpu);
char* get_str_uarch(struct cpuInfo* cpu);
char* get_str_process(struct cpuInfo* cpu);
void free_uarch_struct(struct uarch* arch);