mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
Add --levels option
This commit is contained in:
32
src/args.c
32
src/args.c
@@ -5,24 +5,27 @@
|
|||||||
|
|
||||||
#define ARG_STR_STYLE "style"
|
#define ARG_STR_STYLE "style"
|
||||||
#define ARG_STR_HELP "help"
|
#define ARG_STR_HELP "help"
|
||||||
|
#define ARG_STR_LEVELS "levels"
|
||||||
#define ARG_STR_VERSION "version"
|
#define ARG_STR_VERSION "version"
|
||||||
#define ARG_CHAR_STYLE 's'
|
#define ARG_CHAR_STYLE 's'
|
||||||
#define ARG_CHAR_HELP 'h'
|
#define ARG_CHAR_HELP 'h'
|
||||||
|
#define ARG_CHAR_LEVELS 'l'
|
||||||
#define ARG_CHAR_VERSION 'v'
|
#define ARG_CHAR_VERSION 'v'
|
||||||
#define STYLE_STR_1 "default"
|
#define STYLE_STR_1 "default"
|
||||||
#define STYLE_STR_2 "dark"
|
#define STYLE_STR_2 "dark"
|
||||||
#define STYLE_STR_3 "none"
|
#define STYLE_STR_3 "none"
|
||||||
|
|
||||||
struct args_struct {
|
struct args_struct {
|
||||||
int help_flag;
|
bool levels_flag;
|
||||||
int version_flag;
|
bool help_flag;
|
||||||
|
bool version_flag;
|
||||||
STYLE style;
|
STYLE style;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* SYTLES_STR_LIST[STYLES_COUNT] = { STYLE_STR_1, STYLE_STR_2, STYLE_STR_3 };
|
static const char* SYTLES_STR_LIST[STYLES_COUNT] = { STYLE_STR_1, STYLE_STR_2, STYLE_STR_3 };
|
||||||
static struct args_struct args;
|
static struct args_struct args;
|
||||||
|
|
||||||
STYLE parseStyle(char* style) {
|
STYLE parse_style(char* style) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(i != STYLES_COUNT && strcmp(SYTLES_STR_LIST[i],style) != 0)
|
while(i != STYLES_COUNT && strcmp(SYTLES_STR_LIST[i],style) != 0)
|
||||||
i++;
|
i++;
|
||||||
@@ -32,34 +35,40 @@ STYLE parseStyle(char* style) {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
STYLE getStyle() {
|
STYLE get_style() {
|
||||||
return args.style;
|
return args.style;
|
||||||
}
|
}
|
||||||
|
|
||||||
int showHelp() {
|
bool show_help() {
|
||||||
return args.help_flag;
|
return args.help_flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
int showVersion() {
|
bool show_version() {
|
||||||
return args.version_flag;
|
return args.version_flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool show_levels() {
|
||||||
|
return args.levels_flag;
|
||||||
|
}
|
||||||
|
|
||||||
bool verbose_enabled() {
|
bool verbose_enabled() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parseArgs(int argc, char* argv[]) {
|
bool parse_args(int argc, char* argv[]) {
|
||||||
int c;
|
int c;
|
||||||
int digit_optind = 0;
|
int digit_optind = 0;
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
|
|
||||||
|
args.levels_flag = false;
|
||||||
args.help_flag = false;
|
args.help_flag = false;
|
||||||
args.style = STYLE_EMPTY;
|
args.style = STYLE_EMPTY;
|
||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{ARG_STR_STYLE, required_argument, 0, ARG_CHAR_STYLE },
|
{ARG_STR_STYLE, required_argument, 0, ARG_CHAR_STYLE },
|
||||||
{ARG_STR_HELP, no_argument, 0, ARG_CHAR_HELP },
|
{ARG_STR_HELP, no_argument, 0, ARG_CHAR_HELP },
|
||||||
|
{ARG_STR_LEVELS, no_argument, 0, ARG_CHAR_LEVELS },
|
||||||
{ARG_STR_VERSION, no_argument, 0, ARG_CHAR_VERSION },
|
{ARG_STR_VERSION, no_argument, 0, ARG_CHAR_VERSION },
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
@@ -72,7 +81,7 @@ bool parseArgs(int argc, char* argv[]) {
|
|||||||
printf("ERROR: Style option specified more than once\n");
|
printf("ERROR: Style option specified more than once\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
args.style = parseStyle(optarg);
|
args.style = parse_style(optarg);
|
||||||
if(args.style == STYLE_INVALID) {
|
if(args.style == STYLE_INVALID) {
|
||||||
printf("ERROR: Invalid style '%s'\n",optarg);
|
printf("ERROR: Invalid style '%s'\n",optarg);
|
||||||
return false;
|
return false;
|
||||||
@@ -85,6 +94,13 @@ bool parseArgs(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
args.help_flag = true;
|
args.help_flag = true;
|
||||||
}
|
}
|
||||||
|
else if(c == ARG_CHAR_LEVELS) {
|
||||||
|
if(args.levels_flag) {
|
||||||
|
printf("ERROR: Levels option specified more than once\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.levels_flag = true;
|
||||||
|
}
|
||||||
else if (c == ARG_CHAR_VERSION) {
|
else if (c == ARG_CHAR_VERSION) {
|
||||||
if(args.version_flag) {
|
if(args.version_flag) {
|
||||||
printf("ERROR: Version option specified more than once\n");
|
printf("ERROR: Version option specified more than once\n");
|
||||||
|
|||||||
@@ -4,10 +4,11 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "printer.h"
|
#include "printer.h"
|
||||||
|
|
||||||
bool parseArgs(int argc, char* argv[]);
|
bool parse_args(int argc, char* argv[]);
|
||||||
STYLE getStyle();
|
STYLE get_style();
|
||||||
int showHelp();
|
bool show_help();
|
||||||
int showVersion();
|
bool show_levels();
|
||||||
|
bool show_version();
|
||||||
bool verbose_enabled();
|
bool verbose_enabled();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
23
src/main.c
23
src/main.c
@@ -25,7 +25,7 @@ Peak FLOPS: 512 GFLOP/s(in simple precision)
|
|||||||
|
|
||||||
***/
|
***/
|
||||||
|
|
||||||
static const char* VERSION = "0.47";
|
static const char* VERSION = "0.48";
|
||||||
|
|
||||||
void print_help(int argc, char *argv[]) {
|
void print_help(int argc, char *argv[]) {
|
||||||
printf("Usage: %s [--version] [--help] [--style STYLE]\n\
|
printf("Usage: %s [--version] [--help] [--style STYLE]\n\
|
||||||
@@ -34,8 +34,9 @@ Options: \n\
|
|||||||
default: Default style color\n\
|
default: Default style color\n\
|
||||||
dark: Dark style color\n\
|
dark: Dark style color\n\
|
||||||
none: Don't use colors\n\
|
none: Don't use colors\n\
|
||||||
--help Print this help and exit\n\
|
--help Prints this help and exit\n\
|
||||||
--version Print cpufetch version and exit\n",
|
--levels Prints CPU model and cpuid levels (debug purposes)\n\
|
||||||
|
--version Prints cpufetch version and exit\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,15 +45,15 @@ void print_version() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
if(!parseArgs(argc,argv))
|
if(!parse_args(argc,argv))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
if(showHelp()) {
|
if(show_help()) {
|
||||||
print_help(argc, argv);
|
print_help(argc, argv);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(showVersion()) {
|
if(show_version()) {
|
||||||
print_version();
|
print_version();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -62,6 +63,13 @@ int main(int argc, char* argv[]) {
|
|||||||
struct cpuInfo* cpu = get_cpu_info();
|
struct cpuInfo* cpu = get_cpu_info();
|
||||||
if(cpu == NULL)
|
if(cpu == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
char* cpuName = get_str_cpu_name();
|
||||||
|
|
||||||
|
if(show_levels()) {
|
||||||
|
print_version();
|
||||||
|
print_levels(cpu, cpuName);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
struct cache* cach = get_cache_info(cpu);
|
struct cache* cach = get_cache_info(cpu);
|
||||||
if(cach == NULL)
|
if(cach == NULL)
|
||||||
@@ -75,11 +83,10 @@ int main(int argc, char* argv[]) {
|
|||||||
if(topo == NULL)
|
if(topo == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
struct ascii* art = set_ascii(get_cpu_vendor(cpu),getStyle());
|
struct ascii* art = set_ascii(get_cpu_vendor(cpu),get_style());
|
||||||
if(art == NULL)
|
if(art == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
char* cpuName = get_str_cpu_name();
|
|
||||||
char* maxFrequency = get_str_freq(freq);
|
char* maxFrequency = get_str_freq(freq);
|
||||||
char* nCores = get_str_topology(topo);
|
char* nCores = get_str_topology(topo);
|
||||||
char* avx = get_str_avx(cpu);
|
char* avx = get_str_avx(cpu);
|
||||||
|
|||||||
@@ -659,6 +659,12 @@ char* get_str_freq(struct frequency* freq) {
|
|||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_levels(struct cpuInfo* cpu, char* cpu_name) {
|
||||||
|
printf("%s\n", cpu_name);
|
||||||
|
printf("- Max standart level: 0x%.8X\n", cpu->maxLevels);
|
||||||
|
printf("- Max extended level: 0x%.8X\n", cpu->maxExtendedLevels);
|
||||||
|
}
|
||||||
|
|
||||||
void free_cache_struct(struct cache* cach) {
|
void free_cache_struct(struct cache* cach) {
|
||||||
free(cach);
|
free(cach);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ char* get_str_topology(struct topology* topo);
|
|||||||
|
|
||||||
char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq);
|
char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq);
|
||||||
|
|
||||||
|
void print_levels(struct cpuInfo* cpu, char* cpu_name);
|
||||||
|
|
||||||
void free_cpuinfo_struct(struct cpuInfo* cpu);
|
void free_cpuinfo_struct(struct cpuInfo* cpu);
|
||||||
void free_cache_struct(struct cache* cach);
|
void free_cache_struct(struct cache* cach);
|
||||||
void free_freq_struct(struct frequency* freq);
|
void free_freq_struct(struct frequency* freq);
|
||||||
|
|||||||
Reference in New Issue
Block a user