Added cpuinfo to freebsd port
This commit is contained in:
parent
60586d38a9
commit
9b43d4df0d
1 changed files with 49 additions and 18 deletions
45
uwufetch.c
45
uwufetch.c
|
@ -23,8 +23,10 @@
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#else
|
#else
|
||||||
|
#ifndef __FREEBSD__
|
||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
@ -65,8 +67,10 @@ struct package_manager
|
||||||
};
|
};
|
||||||
struct utsname sys_var;
|
struct utsname sys_var;
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
|
#ifdef __linux__
|
||||||
struct sysinfo sys;
|
struct sysinfo sys;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
struct winsize win;
|
struct winsize win;
|
||||||
|
|
||||||
int iscygwin = 0;
|
int iscygwin = 0;
|
||||||
|
@ -152,7 +156,11 @@ int main(int argc, char *argv[])
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
parse_config();
|
parse_config();
|
||||||
if ((argc == 1 && ascii_image_flag == 0) || (argc > 1 && ascii_image_flag == 0))
|
if ((argc == 1 && ascii_image_flag == 0) || (argc > 1 && ascii_image_flag == 0))
|
||||||
|
{
|
||||||
|
printf("\n"); // print a new line
|
||||||
|
printf("\033[1A"); // go up one line if possible
|
||||||
print_ascii();
|
print_ascii();
|
||||||
|
}
|
||||||
else if (ascii_image_flag == 1)
|
else if (ascii_image_flag == 1)
|
||||||
print_image();
|
print_image();
|
||||||
uwu_kernel();
|
uwu_kernel();
|
||||||
|
@ -338,7 +346,9 @@ void print_info()
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
uptime = uptime_mac();
|
uptime = uptime_mac();
|
||||||
#else
|
#else
|
||||||
|
#ifndef __FREEBSD__
|
||||||
uptime = sys.uptime;
|
uptime = sys.uptime;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
switch (uptime)
|
switch (uptime)
|
||||||
{
|
{
|
||||||
|
@ -370,7 +380,11 @@ void get_info()
|
||||||
|
|
||||||
// os version, cpu and board info
|
// os version, cpu and board info
|
||||||
FILE *os_release = fopen("/etc/os-release", "r");
|
FILE *os_release = fopen("/etc/os-release", "r");
|
||||||
|
#ifndef __FREEBSD__
|
||||||
FILE *cpuinfo = fopen("/proc/cpuinfo", "r");
|
FILE *cpuinfo = fopen("/proc/cpuinfo", "r");
|
||||||
|
#else
|
||||||
|
FILE *cpuinfo = popen("sysctl -a | egrep -i 'hw.model'", "r");
|
||||||
|
#endif
|
||||||
FILE *host_model_info = fopen("/sys/devices/virtual/dmi/id/product_version", "r");
|
FILE *host_model_info = fopen("/sys/devices/virtual/dmi/id/product_version", "r");
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
iscygwin = 1;
|
iscygwin = 1;
|
||||||
|
@ -392,8 +406,13 @@ void get_info()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), cpuinfo))
|
while (fgets(line, sizeof(line), cpuinfo))
|
||||||
|
#ifdef __FREEBSD__
|
||||||
|
if (sscanf(line, "hw.model: %[^\n]", cpu_model))
|
||||||
|
#else
|
||||||
if (sscanf(line, "model name : %[^\n]", cpu_model))
|
if (sscanf(line, "model name : %[^\n]", cpu_model))
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
sprintf(user, "%s", getenv("USER"));
|
sprintf(user, "%s", getenv("USER"));
|
||||||
if (iscygwin == 0)
|
if (iscygwin == 0)
|
||||||
|
@ -418,9 +437,11 @@ void get_info()
|
||||||
while (fgets(line, sizeof(line), host_model_info))
|
while (fgets(line, sizeof(line), host_model_info))
|
||||||
if (sscanf(line, "%[^\n]", host_model))
|
if (sscanf(line, "%[^\n]", host_model))
|
||||||
break;
|
break;
|
||||||
|
#ifndef __FREEBSD__
|
||||||
while (fgets(line, sizeof(line), cpuinfo))
|
while (fgets(line, sizeof(line), cpuinfo))
|
||||||
if (sscanf(line, "Hardware : %[^\n]", cpu_model))
|
if (sscanf(line, "Hardware : %[^\n]", cpu_model))
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (library) // macOS
|
else if (library) // macOS
|
||||||
{
|
{
|
||||||
|
@ -435,7 +456,9 @@ void get_info()
|
||||||
else
|
else
|
||||||
sprintf(version_name, "unknown");
|
sprintf(version_name, "unknown");
|
||||||
}
|
}
|
||||||
|
#ifndef __FREEBSD__
|
||||||
fclose(cpuinfo);
|
fclose(cpuinfo);
|
||||||
|
#endif
|
||||||
gethostname(host, 256);
|
gethostname(host, 256);
|
||||||
sscanf(getenv("SHELL"), "%s", shell);
|
sscanf(getenv("SHELL"), "%s", shell);
|
||||||
if (strlen(shell) > 16)
|
if (strlen(shell) > 16)
|
||||||
|
@ -447,7 +470,9 @@ void get_info()
|
||||||
// system resources
|
// system resources
|
||||||
uname(&sys_var);
|
uname(&sys_var);
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
|
#ifndef __FREEBSD__
|
||||||
sysinfo(&sys); // somehow this function has to be called again in print_info()
|
sysinfo(&sys); // somehow this function has to be called again in print_info()
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
truncate_name(sys_var.release);
|
truncate_name(sys_var.release);
|
||||||
|
@ -893,7 +918,7 @@ void usage(char *arg)
|
||||||
|
|
||||||
void uwu_kernel()
|
void uwu_kernel()
|
||||||
{
|
{
|
||||||
#define KERNEL_TO_UWU(str, original, uwufied) \
|
#define KERNEL_TO_UWU(str, original, uwufied) \
|
||||||
if (strcmp(str, original) == 0) \
|
if (strcmp(str, original) == 0) \
|
||||||
sprintf(str, "%s", uwufied)
|
sprintf(str, "%s", uwufied)
|
||||||
|
|
||||||
|
@ -902,12 +927,14 @@ void uwu_kernel()
|
||||||
char splitted[16][128] = {};
|
char splitted[16][128] = {};
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while((token = strsep(&temp_kernel, " "))) {
|
while ((token = strsep(&temp_kernel, " ")))
|
||||||
|
{
|
||||||
strcpy(splitted[count], token);
|
strcpy(splitted[count], token);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
strcpy(kernel, "");
|
strcpy(kernel, "");
|
||||||
for(int i = 0;i < 16;i++) {
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
|
||||||
// kernel name
|
// kernel name
|
||||||
KERNEL_TO_UWU(splitted[i], "Linux", "Linuwu");
|
KERNEL_TO_UWU(splitted[i], "Linux", "Linuwu");
|
||||||
|
@ -946,10 +973,11 @@ void uwu_kernel()
|
||||||
// Windows
|
// Windows
|
||||||
KERNEL_TO_UWU(splitted[i], "windows", "WinyandOwOws");
|
KERNEL_TO_UWU(splitted[i], "windows", "WinyandOwOws");
|
||||||
|
|
||||||
if(i != 0) strcat(kernel, " ");
|
if (i != 0)
|
||||||
|
strcat(kernel, " ");
|
||||||
strcat(kernel, splitted[i]);
|
strcat(kernel, splitted[i]);
|
||||||
}
|
}
|
||||||
#undef KERNEL_TO_UWU
|
#undef KERNEL_TO_UWU
|
||||||
}
|
}
|
||||||
|
|
||||||
void uwu_name()
|
void uwu_name()
|
||||||
|
@ -1008,8 +1036,11 @@ void uwu_name()
|
||||||
|
|
||||||
void truncate_name(char *name)
|
void truncate_name(char *name)
|
||||||
{
|
{
|
||||||
for (int i = target_width; i < 256; i++)
|
char arr[target_width];
|
||||||
name[i] = '\0';
|
|
||||||
|
for (int i = 0; i < target_width; i++)
|
||||||
|
arr[i] = name[i];
|
||||||
|
name = arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove square brackets (for gpu names)
|
// remove square brackets (for gpu names)
|
||||||
|
|
Loading…
Reference in a new issue