Skip to content
This repository was archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Cleaned some code and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-oliviero committed Feb 1, 2023
1 parent 0cb0956 commit 9cd6640
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
ColumnLimit: 100
ColumnLimit: 0
MaxEmptyLinesToKeep: 1
PointerAlignment: Left
...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ uwufetch_*
*.o
*.so
*.a
*.dSYM
14 changes: 0 additions & 14 deletions config

This file was deleted.

23 changes: 6 additions & 17 deletions fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ CONSOLE_SCREEN_BUFFER_INFO csbi;

#ifdef __APPLE__
// buffers where data fetched from sysctl are stored
// CPU
#define CPUBUFFERLEN 128

char cpu_buffer[CPUBUFFERLEN];
Expand Down Expand Up @@ -161,8 +160,7 @@ void* get_ram(void* argp) {
"r"); // free alternative for openbsd
#endif
#else
// getting memory info from /proc/meminfo:
// https://github.com/KittyKatt/screenFetch/issues/386#issuecomment-249312716
// getting memory info from /proc/meminfo: https://github.com/KittyKatt/screenFetch/issues/386#issuecomment-249312716
meminfo = fopen("/proc/meminfo",
"r"); // popen("LANG=EN_us free -m 2> /dev/null", "r"); // get ram info with free
#endif
Expand All @@ -185,13 +183,10 @@ void* get_ram(void* argp) {
}
#ifndef __OPENBSD__
user_info->ram_total = memtotal / 1024;
user_info->ram_used = ((memtotal + shmem) - (memfree + buffers + cached + sreclaimable)) / 1024;
user_info->ram_used = ((memtotal + shmem) - (memfree + buffers + cached + sreclaimable)) / 1024;
#endif
}

// while (fgets(buffer, buf_sz, meminfo)) // old way to get ram usage that uses the "free" command
// // free command prints like this: "Mem:" total used free shared buff/cache available
// sscanf(buffer, "Mem: %d %d", &user_info->ram_total, &user_info->ram_used);
fclose(meminfo);
#endif
#else // if __APPLE__
Expand Down Expand Up @@ -306,9 +301,7 @@ void* get_pkg(void* argp) { // this is just a function that returns the total of
struct package_manager pkgmans[] = {
{"apt list --installed 2> /dev/null | wc -l", "(apt)"},
{"apk info 2> /dev/null | wc -l", "(apk)"},
// {"dnf list installed 2> /dev/null | wc -l", "(dnf)"}, // according to
// https://stackoverflow.com/questions/48570019/advantages-of-dnf-vs-rpm-on-fedora, dnf and
// rpm return the same number of packages
// {"dnf list installed 2> /dev/null | wc -l", "(dnf)"}, // according to https://stackoverflow.com/questions/48570019/advantages-of-dnf-vs-rpm-on-fedora, dnf and rpm return the same number of packages
{"qlist -I 2> /dev/null | wc -l", "(emerge)"},
{"flatpak list 2> /dev/null | wc -l", "(flatpak)"},
{"snap list 2> /dev/null | wc -l", "(snap)"},
Expand Down Expand Up @@ -342,9 +335,7 @@ void* get_pkg(void* argp) { // this is just a function that returns the total of
#ifndef __APPLE__
FILE* fp = popen(current->command_string, "r"); // trying current package manager
#else
system(current->command_string); // writes to a temporary file: for some reason popen() does
// not
// intercept the stdout, so i have to read from a temporary file
system(current->command_string); // writes to a temporary file: for some reason popen() does not intercept the stdout, so i have to read from a temporary file
FILE* fp = fopen("/tmp/uwufetch_brew_tmp", "r");
#endif
unsigned int pkg_count = 0;
Expand Down Expand Up @@ -530,8 +521,7 @@ void get_info(struct flags flags, struct info* user_info) {
#else
FILE* cpuinfo = popen("sysctl hw.model", "r"); // cpu name command for freebsd
#endif
// trying to get some kind of information about the name of the computer (hopefully a product
// full name)
// trying to get some kind of information about the name of the computer (hopefully a product full name)
if (os_release) { // get normal vars if os_release exists
if (flags.os) {
while (fgets(buffer, sizeof(buffer), os_release) &&
Expand All @@ -543,8 +533,7 @@ void get_info(struct flags flags, struct info* user_info) {
if (user_info->os_name[os_name_len - 1] == '\"') {
user_info->os_name[os_name_len - 1] = '\0';
}
/* trying to detect amogos because in its os-release file ID value is just "debian",
will be removed when amogos will have an os-release file with ID=amogos */
// trying to detect amogos because in its os-release file ID value is just "debian", will be removed when amogos will have an os-release file with ID=amogos
if (strcmp(user_info->os_name, "debian") == 0 ||
strcmp(user_info->os_name, "raspbian") == 0) {
DIR* amogos_plymouth = opendir("/usr/share/plymouth/themes/amogos");
Expand Down
57 changes: 15 additions & 42 deletions uwufetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ void print_image(struct info* user_info) {
" for more info.\n\n",
RED);
#else
// unfortunately, the iOS stdlib does not have
// system();
// because it reports that it is not available under iOS during compilation
// unfortunately, the iOS stdlib does not have system(); because it reports that it is not available under iOS during compilation
printf("\033[0E\033[3C%s\n"
" There was an\n"
" error: images\n"
Expand All @@ -178,11 +176,7 @@ void print_image(struct info* user_info) {
#endif
}

/*
This replaces all terms in a string with another term.
replace("Hello World!", "World", "everyone")
This returns "Hello everyone!".
*/
// Replaces all terms in a string with another term.
void replace(char* original, char* search, char* replacer) {
char* ch;
char buffer[1024];
Expand All @@ -196,11 +190,7 @@ void replace(char* original, char* search, char* replacer) {
}
}

/*
This replaces all terms in a string with another term, case insensitive
replace("Hello wOrLd!", "WoRlD", "everyone")
This returns "Hello everyone!".
*/
// Replaces all terms in a string with another term, case insensitive
void replace_ignorecase(char* original, char* search, char* replacer) {
char* ch;
char buffer[1024];
Expand All @@ -217,8 +207,7 @@ void replace_ignorecase(char* original, char* search, char* replacer) {
}

#ifdef _WIN32
// windows sucks and hasn't a strstep, so I copied one from
// https://stackoverflow.com/questions/8512958/is-there-a-windows-variant-of-strsep-function
// windows sucks and hasn't a strstep, so I copied one from https://stackoverflow.com/questions/8512958/is-there-a-windows-variant-of-strsep-function
char* strsep(char** stringp, const char* delim) {
char* start = *stringp;
char* p;
Expand All @@ -241,6 +230,7 @@ void uwu_name(struct info* user_info) {
// linux
STRING_TO_UWU("alpine", "Nyalpine");
else STRING_TO_UWU("amogos", "AmogOwOS");
else STRING_TO_UWU("android", "Nyandroid");
else STRING_TO_UWU("arch", "Nyarch Linuwu");
else STRING_TO_UWU("arcolinux", "ArcOwO Linuwu");
else STRING_TO_UWU("artix", "Nyartix Linuwu");
Expand Down Expand Up @@ -269,9 +259,6 @@ void uwu_name(struct info* user_info) {
else STRING_TO_UWU("ubuntu", "Uwuntu");
else STRING_TO_UWU("void", "OwOid");
else STRING_TO_UWU("xerolinux", "xuwulinux");
else STRING_TO_UWU("android",
"Nyandroid"); // android at the end because it could be not
// considered as an actual distribution of gnu/linux

// BSD
else STRING_TO_UWU("freebsd", "FweeBSD");
Expand Down Expand Up @@ -309,6 +296,7 @@ void uwu_kernel(char* kernel) {
else KERNEL_TO_UWU(splitted[i], "linux", "linuwu");
else KERNEL_TO_UWU(splitted[i], "alpine", "Nyalpine");
else KERNEL_TO_UWU(splitted[i], "amogos", "AmogOwOS");
else KERNEL_TO_UWU(splitted[i], "android", "Nyandroid");
else KERNEL_TO_UWU(splitted[i], "arch", "Nyarch Linuwu");
else KERNEL_TO_UWU(splitted[i], "artix", "Nyartix Linuwu");
else KERNEL_TO_UWU(splitted[i], "debian", "Debinyan");
Expand All @@ -335,9 +323,6 @@ void uwu_kernel(char* kernel) {
else KERNEL_TO_UWU(splitted[i], "ubuntu", "Uwuntu");
else KERNEL_TO_UWU(splitted[i], "void", "OwOid");
else KERNEL_TO_UWU(splitted[i], "xerolinux", "xuwulinux");
else KERNEL_TO_UWU(splitted[i], "android",
"Nyandroid"); // android at the end because it could be not considered
// as an actual distribution of gnu/linux

// BSD
else KERNEL_TO_UWU(splitted[i], "freebsd", "FweeBSD");
Expand All @@ -360,9 +345,7 @@ void uwu_kernel(char* kernel) {
void uwu_hw(char* hwname) {
#define HW_TO_UWU(original, uwuified) replace_ignorecase(hwname, original, uwuified);
HW_TO_UWU("lenovo", "LenOwO")
HW_TO_UWU("cpu",
"CC\bPUwU"); // for some reasons this caused a segfault, using a \b
// (backspace) char fixes it
HW_TO_UWU("cpu", "CC\bPUwU"); // for some reasons this caused a segfault, using a \b (backspace) char fixes it
HW_TO_UWU("gpu", "GG\bPUwU")
HW_TO_UWU("graphics", "Gwaphics")
HW_TO_UWU("corporation", "COwOpowation")
Expand Down Expand Up @@ -507,12 +490,6 @@ void write_cache(struct info* user_info) {
for (int i = 0; user_info->gpu_model[i][0]; i++) // writing gpu names to file
fprintf(cache_fp, "gpu=%s\n", user_info->gpu_model[i]);

#ifdef __APPLE__
/* char brew_command[2048];
sprintf(brew_command, "ls $(brew --cellar) | wc -l | awk -F' ' '{print \"
\x1b[34mw w \x1b[0m\x1b[1mPKGS\x1b[0m \"$1 \" (brew)\"}'
> %s", cache_file); system(brew_command); */
#endif
fclose(cache_fp);
return;
}
Expand Down Expand Up @@ -550,8 +527,7 @@ void print_ascii(struct info* user_info) {
printf("\n");
FILE* file;
char ascii_file[1024];
// First tries to get ascii art file from local directory. Useful for
// debugging
// First tries to get ascii art file from local directory. Useful for debugging
sprintf(ascii_file, "./res/ascii/%s.txt", user_info->os_name);
file = fopen(ascii_file, "r");
if (!file) { // if the file does not exist in the local directory, open it
Expand Down Expand Up @@ -597,8 +573,7 @@ void print_ascii(struct info* user_info) {
replace(buffer, "{BACKGROUND_WHITE}", "\e[0;47m");
printf("%s", buffer); // print the line after setting the color
}
// Always set color to NORMAL, so there's no need to do this in every ascii
// file.
// Always set color to NORMAL, so there's no need to do this in every ascii file.
printf(NORMAL);
fclose(file);
}
Expand All @@ -622,12 +597,11 @@ void list(char* arg) {
" %sOther/spare distributions:\n"
" %salpine, %sfemboyos, %sgentoo, %sslackware, %ssolus, %svoid, "
"opensuse-leap, android, %sgnu, guix, %swindows, %sunknown\n\n",
arg, BLUE, NORMAL, BLUE, MAGENTA, GREEN, BLUE, // Arch based colors
RED, YELLOW, NORMAL, RED, GREEN, BLUE, RED, YELLOW, // Debian based colors
RED, NORMAL, RED, YELLOW, GREEN, YELLOW, RED, PINK, BLUE, WHITE, // BSD/Apple colors
RED, NORMAL, BLUE, GREEN, // RHEL colors
NORMAL, BLUE, RED, PINK, MAGENTA, WHITE, GREEN, YELLOW, BLUE,
WHITE); // Other/spare distributions colors
arg, BLUE, NORMAL, BLUE, MAGENTA, GREEN, BLUE, // Arch based colors
RED, YELLOW, NORMAL, RED, GREEN, BLUE, RED, YELLOW, // Debian based colors
RED, NORMAL, RED, YELLOW, GREEN, YELLOW, RED, PINK, BLUE, WHITE, // BSD/Apple colors
RED, NORMAL, BLUE, GREEN, // RHEL colors
NORMAL, BLUE, RED, PINK, MAGENTA, WHITE, GREEN, YELLOW, BLUE, WHITE); // Other/spare distributions colors
}

// prints the usage
Expand Down Expand Up @@ -661,8 +635,7 @@ void usage(char* arg) {
NORMAL);
}

// the main function is on the bottom of the file to avoid double function
// declarations
// the main function is on the bottom of the file to avoid double function declarations
int main(int argc, char* argv[]) {
struct user_config user_config_file;
struct info user_info = {0};
Expand Down
20 changes: 0 additions & 20 deletions uwufetch.dSYM/Contents/Info.plist

This file was deleted.

0 comments on commit 9cd6640

Please sign in to comment.