diff --git a/src/common/global.c b/src/common/global.c index 826b66d..2ed88ba 100644 --- a/src/common/global.c +++ b/src/common/global.c @@ -20,6 +20,37 @@ #endif +#ifdef ARCH_X86 + static const char* ARCH_STR = "x86_64 build"; + #include "../x86/cpuid.h" +#elif ARCH_PPC + static const char* ARCH_STR = "PowerPC build"; + #include "../ppc/ppc.h" +#elif ARCH_ARM + static const char* ARCH_STR = "ARM build"; + #include "../arm/midr.h" +#endif + +#ifdef __linux__ + #ifdef __ANDROID__ + static const char* OS_STR = "Android"; + #else + static const char* OS_STR = "Linux"; + #endif +#elif __FreeBSD__ + static const char* OS_STR = "FreeBSD"; +#elif _WIN32 + static const char* OS_STR = "Windows"; +#elif defined __APPLE__ || __MACH__ + static const char* OS_STR = "macOS"; +#else + static const char* OS_STR = "Unknown OS"; +#endif + +#ifndef GIT_FULL_VERSION + static const char* VERSION = "1.03"; +#endif + enum { LOG_LEVEL_NORMAL, LOG_LEVEL_VERBOSE @@ -47,6 +78,8 @@ void printErr(const char *fmt, ...) { vsnprintf(buffer,buffer_size, fmt, args); va_end(args); fprintf(stderr,RED "[ERROR]: "RESET "%s\n",buffer); + fprintf(stderr,"[VERSION]: "); + print_version(stderr); } void printBug(const char *fmt, ...) { @@ -57,6 +90,8 @@ void printBug(const char *fmt, ...) { vsnprintf(buffer,buffer_size, fmt, args); va_end(args); fprintf(stderr,RED "[ERROR]: "RESET "%s\n",buffer); + fprintf(stderr,"[VERSION]: "); + print_version(stderr); #if defined(ARCH_X86) || defined(ARCH_PPC) fprintf(stderr, "Please, create a new issue with this error message, the output of 'cpufetch' and 'cpufetch --debug' on https://github.com/Dr-Noob/cpufetch/issues\n"); #elif ARCH_ARM @@ -123,3 +158,10 @@ void* erealloc(void *ptr, size_t size) { return newptr; } +void print_version(FILE *restrict stream) { +#ifdef GIT_FULL_VERSION + fprintf(stream, "cpufetch %s (%s %s)\n", GIT_FULL_VERSION, OS_STR, ARCH_STR); +#else + fprintf(stream, "cpufetch v%s (%s %s)\n", VERSION, OS_STR, ARCH_STR); +#endif +} diff --git a/src/common/global.h b/src/common/global.h index 4b61c4e..5a9e399 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -17,5 +17,6 @@ char *strremove(char *str, const char *sub); void* emalloc(size_t size); void* ecalloc(size_t nmemb, size_t size); void* erealloc(void *ptr, size_t size); +void print_version(FILE *restrict stream); #endif diff --git a/src/common/main.c b/src/common/main.c index 25117be..6f2900f 100644 --- a/src/common/main.c +++ b/src/common/main.c @@ -6,37 +6,6 @@ #include "printer.h" #include "global.h" -#ifdef ARCH_X86 - static const char* ARCH_STR = "x86_64 build"; - #include "../x86/cpuid.h" -#elif ARCH_PPC - static const char* ARCH_STR = "PowerPC build"; - #include "../ppc/ppc.h" -#elif ARCH_ARM - static const char* ARCH_STR = "ARM build"; - #include "../arm/midr.h" -#endif - -#ifdef __linux__ - #ifdef __ANDROID__ - static const char* OS_STR = "Android"; - #else - static const char* OS_STR = "Linux"; - #endif -#elif __FreeBSD__ - static const char* OS_STR = "FreeBSD"; -#elif _WIN32 - static const char* OS_STR = "Windows"; -#elif defined __APPLE__ || __MACH__ - static const char* OS_STR = "macOS"; -#else - static const char* OS_STR = "Unknown OS"; -#endif - -#ifndef GIT_FULL_VERSION - static const char* VERSION = "1.03"; -#endif - void print_help(char *argv[]) { const char **t = args_str; const char *c = args_chr; @@ -108,14 +77,6 @@ void print_help(char *argv[]) { printf(" To correctly measure peak performance, see: https://github.com/Dr-Noob/peakperf\n"); } -void print_version() { -#ifdef GIT_FULL_VERSION - printf("cpufetch %s (%s %s)\n", GIT_FULL_VERSION, OS_STR, ARCH_STR); -#else - printf("cpufetch v%s (%s %s)\n", VERSION, OS_STR, ARCH_STR); -#endif -} - int main(int argc, char* argv[]) { if(!parse_args(argc,argv)) return EXIT_FAILURE; @@ -126,7 +87,7 @@ int main(int argc, char* argv[]) { } if(show_version()) { - print_version(); + print_version(stdout); return EXIT_SUCCESS; } @@ -137,7 +98,7 @@ int main(int argc, char* argv[]) { return EXIT_FAILURE; if(show_debug()) { - print_version(); + print_version(stdout); print_debug(cpu); return EXIT_SUCCESS; } @@ -145,7 +106,7 @@ int main(int argc, char* argv[]) { // TODO: This should be moved to the end of args.c if(show_raw()) { #ifdef ARCH_X86 - print_version(); + print_version(stdout); print_raw(cpu); return EXIT_SUCCESS; #else