Started porting to openbsd, indented some code

This commit is contained in:
adri 2022-06-24 14:24:03 +02:00
parent 3ce863a90a
commit efa5970da0
2 changed files with 49 additions and 35 deletions

View file

@ -28,6 +28,13 @@ else ifeq ($(PLATFORM), FreeBSD)
LIBDIR = lib LIBDIR = lib
ETC_DIR = /etc ETC_DIR = /etc
MANDIR = share/man/man1 MANDIR = share/man/man1
else ifeq ($(PLATFORM), BSD)
CFLAGS += -D__OPENBSD__
CFLAGS_DEBUG += -D__OPENBSD__
PREFIX = bin
LIBDIR = lib
ETC_DIR = /etc
MANDIR = share/man/man1
else ifeq ($(PLATFORM), windows32) else ifeq ($(PLATFORM), windows32)
CC = gcc CC = gcc
PREFIX = "C:\Program Files" PREFIX = "C:\Program Files"

View file

@ -30,12 +30,19 @@
#include <unistd.h> #include <unistd.h>
#if defined(__APPLE__) || defined(__FREEBSD__) #if defined(__APPLE__) || defined(__FREEBSD__)
#include <sys/sysctl.h> #include <sys/sysctl.h>
#if defined(__OPENBSD__)
#include <sys/time.h>
#else
#include <time.h> #include <time.h>
#endif // defined(__OPENBSD__)
#else // defined(__APPLE__) || defined(__FREEBSD__) #else // defined(__APPLE__) || defined(__FREEBSD__)
#ifdef __FREEBSD__ #ifdef __FREEBSD__
#else // defined(__FREEBSD__) || defined(_WIN32) #else // defined(__FREEBSD__) || defined(_WIN32)
#ifndef _WIN32 #ifndef _WIN32
#ifndef __OPENBSD__
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#else // __OPENBSD__
#endif // __OPENBSD__
#else // _WIN32 #else // _WIN32
#include <sysinfoapi.h> #include <sysinfoapi.h>
#endif // _WIN32 #endif // _WIN32
@ -553,7 +560,7 @@ void write_cache(struct info* user_info) {
fprintf(stderr, "Failed to write to %s!", cache_file); fprintf(stderr, "Failed to write to %s!", cache_file);
return; return;
} }
// writing all info to the cache file // writing all info to the cache file
#ifdef __APPLE__ #ifdef __APPLE__
user_info->uptime = uptime_apple(); user_info->uptime = uptime_apple();
#else #else
@ -617,10 +624,10 @@ int read_cache(struct info* user_info) {
} }
/* /*
This replaces all terms in a string with another term. This replaces all terms in a string with another term.
replace("Hello World!", "World", "everyone") replace("Hello World!", "World", "everyone")
This returns "Hello everyone!". This returns "Hello everyone!".
*/ */
void replace(char* original, char* search, char* replacer) { void replace(char* original, char* search, char* replacer) {
char* ch; char* ch;
char buffer[1024]; char buffer[1024];
@ -635,10 +642,10 @@ void replace(char* original, char* search, char* replacer) {
} }
/* /*
This replaces all terms in a string with another term, case insensitive This replaces all terms in a string with another term, case insensitive
replace("Hello wOrLd!", "WoRlD", "everyone") replace("Hello wOrLd!", "WoRlD", "everyone")
This returns "Hello everyone!". This returns "Hello everyone!".
*/ */
void replace_ignorecase(char* original, char* search, char* replacer) { void replace_ignorecase(char* original, char* search, char* replacer) {
char* ch; char* ch;
char buffer[1024]; char buffer[1024];
@ -915,7 +922,7 @@ struct info get_info()
struct info user_info = {0}; struct info user_info = {0};
char buffer[256]; // line buffer char buffer[256]; // line buffer
// get terminal width used to truncate long names // get terminal width used to truncate long names
#ifndef _WIN32 #ifndef _WIN32
ioctl(STDOUT_FILENO, TIOCGWINSZ, &user_info.win); ioctl(STDOUT_FILENO, TIOCGWINSZ, &user_info.win);
user_info.target_width = user_info.win.ws_col - 30; user_info.target_width = user_info.win.ws_col - 30;
@ -1109,7 +1116,7 @@ struct info get_info()
#endif // _WIN32 #endif // _WIN32
truncate_str(user_info.cpu_model, user_info.target_width); truncate_str(user_info.cpu_model, user_info.target_width);
// system resources // system resources
#ifndef _WIN32 #ifndef _WIN32
uname(&user_info.sys_var); uname(&user_info.sys_var);
#endif // _WIN32 #endif // _WIN32
@ -1143,7 +1150,7 @@ struct info get_info()
if (kernel_fp) pclose(kernel_fp); if (kernel_fp) pclose(kernel_fp);
#endif // _WIN32 #endif // _WIN32
// ram // ram
#ifndef __APPLE__ #ifndef __APPLE__
#ifdef _WIN32 #ifdef _WIN32
FILE* mem_used_fp = popen("wmic os get freevirtualmemory", "r"); // free memory FILE* mem_used_fp = popen("wmic os get freevirtualmemory", "r"); // free memory
@ -1271,7 +1278,7 @@ struct info get_info()
truncate_str(user_info.gpu_model[i], user_info.target_width); truncate_str(user_info.gpu_model[i], user_info.target_width);
} }
// Resolution // Resolution
#ifndef _WIN32 #ifndef _WIN32
FILE* resolution = popen("xwininfo -root 2> /dev/null | grep -E 'Width|Height'", "r"); FILE* resolution = popen("xwininfo -root 2> /dev/null | grep -E 'Width|Height'", "r");
while (fgets(buffer, sizeof(buffer), resolution)) { while (fgets(buffer, sizeof(buffer), resolution)) {
@ -1281,7 +1288,7 @@ struct info get_info()
#endif #endif
if (strcmp(user_info.os_name, "windows")) MOVE_CURSOR = "\033[21C"; // to print windows logo on not windows systems if (strcmp(user_info.os_name, "windows")) MOVE_CURSOR = "\033[21C"; // to print windows logo on not windows systems
// package count // package count
#ifdef _WIN32 #ifdef _WIN32
user_info.pkgs = pkgman(&user_info, config_flags); user_info.pkgs = pkgman(&user_info, config_flags);
#else // _WIN32 #else // _WIN32
@ -1297,8 +1304,8 @@ struct info get_info()
} }
/* prints distribution list /* prints distribution list
distributions are listed by distribution branch distributions are listed by distribution branch
to make the output easier to understand by the user.*/ to make the output easier to understand by the user.*/
void list(char* arg) { void list(char* arg) {
printf("%s -d <options>\n" printf("%s -d <options>\n"
" Available distributions:\n" " Available distributions:\n"