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