project structure refactoring

This commit is contained in:
Linus Dierheimer
2021-04-09 14:07:05 +02:00
parent 0649b6e755
commit 53c781aa21
29 changed files with 701 additions and 650 deletions
+18 -23
View File
@@ -19,10 +19,11 @@ execute_process(
set(PROJECT_VERSION "r${GIT_REV_LIST}.${GIT_REV_PARSE}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAFS} -Wall -O3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAFS} -Wall -Wextra -O3")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-O3")
if(BUILD_TESTS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -pipe -fno-plt")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -mtune=native -pipe -fno-plt -Wconversion -Wpedantic")
endif(BUILD_TESTS)
configure_file(src/fastfetch_config.h.in fastfetch_config.h)
@@ -49,14 +50,23 @@ include_directories(
${GLIB2_INCLUDE_DIRS}
)
link_libraries(
${CMAKE_DL_LIBS}
Threads::Threads
)
set(SRCS
src/common.c
src/logo.c
src/util/FFstrbuf.c
src/helpers/calculatePlasma.c
src/helpers/calculateGtk.c
src/helpers/calculateTerminal.c
src/helpers/calculateWM.c
src/common/init.c
src/common/threading.c
src/common/io.c
src/common/logo.c
src/common/format.c
src/common/parsing.c
src/common/calculatePlasma.c
src/common/calculateGtk.c
src/common/calculateTerminal.c
src/common/calculateWM.c
src/modules/break.c
src/modules/custom.c
src/modules/title.c
@@ -91,11 +101,6 @@ add_executable(fastfetch
${SRCS}
)
target_link_libraries(fastfetch
${CMAKE_DL_LIBS}
Threads::Threads
)
add_executable(flashfetch
src/flashfetch.c
${SRCS}
@@ -105,19 +110,9 @@ target_compile_definitions(flashfetch PUBLIC
FASTFETCH_BUILD_FLASHFETCH
)
target_link_libraries(flashfetch
${CMAKE_DL_LIBS}
Threads::Threads
)
if(BUILD_TESTS)
add_executable(fastfetch-test-performance
tests/performance.c
${SRCS}
)
target_link_libraries(fastfetch-test-performance
${CMAKE_DL_LIBS}
Threads::Threads
)
endif(BUILD_TESTS)
-571
View File
@@ -1,571 +0,0 @@
#include "fastfetch.h"
#include <malloc.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <pthread.h>
void ffInitState(FFstate* state)
{
state->current_row = 0;
state->passwd = getpwuid(getuid());
uname(&state->utsname);
sysinfo(&state->sysinfo);
}
void ffDefaultConfig(FFconfig* config)
{
ffStrbufInit(&config->color);
config->logo_spacing = 4;
ffStrbufInitS(&config->seperator, ": ");
config->offsetx = 0;
config->titleLength = 20; // This is overwritten by ffPrintTitle
config->colorLogo = true;
config->showErrors = false;
config->recache = false;
config->cacheSave = true;
config->printRemainingLogo = true;
//Since most of these properties are unlikely to be used at once, give them minimal heap space (the \0 character)
ffStrbufInitA(&config->osFormat, 1);
ffStrbufInitA(&config->osKey, 1);
ffStrbufInitA(&config->hostFormat, 1);
ffStrbufInitA(&config->hostKey, 1);
ffStrbufInitA(&config->kernelFormat, 1);
ffStrbufInitA(&config->kernelKey, 1);
ffStrbufInitA(&config->uptimeFormat, 1);
ffStrbufInitA(&config->uptimeKey, 1);
ffStrbufInitA(&config->packagesFormat, 1);
ffStrbufInitA(&config->packagesKey, 1);
ffStrbufInitA(&config->shellFormat, 1);
ffStrbufInitA(&config->shellKey, 1);
ffStrbufInitA(&config->resolutionFormat, 1);
ffStrbufInitA(&config->resolutionKey, 1);
ffStrbufInitA(&config->deFormat, 1);
ffStrbufInitA(&config->deKey, 1);
ffStrbufInitA(&config->wmFormat, 1);
ffStrbufInitA(&config->wmKey, 1);
ffStrbufInitA(&config->wmThemeFormat, 1);
ffStrbufInitA(&config->wmThemeKey, 1);
ffStrbufInitA(&config->themeFormat, 1);
ffStrbufInitA(&config->themeKey, 1);
ffStrbufInitA(&config->iconsFormat, 1);
ffStrbufInitA(&config->iconsKey, 1);
ffStrbufInitA(&config->fontFormat, 1);
ffStrbufInitA(&config->fontKey, 1);
ffStrbufInitA(&config->terminalFormat, 1);
ffStrbufInitA(&config->terminalKey, 1);
ffStrbufInitA(&config->termFontFormat, 1);
ffStrbufInitA(&config->termFontKey, 1);
ffStrbufInitA(&config->cpuFormat, 1);
ffStrbufInitA(&config->cpuKey, 1);
ffStrbufInitA(&config->gpuFormat, 1);
ffStrbufInitA(&config->gpuKey, 1);
ffStrbufInitA(&config->memoryFormat, 1);
ffStrbufInitA(&config->memoryKey, 1);
ffStrbufInitA(&config->diskFormat, 1);
ffStrbufInitA(&config->diskKey, 1);
ffStrbufInitA(&config->batteryFormat, 1);
ffStrbufInitA(&config->batteryKey, 1);
ffStrbufInitA(&config->localeFormat, 1);
ffStrbufInitA(&config->localeKey, 1);
ffStrbufInitA(&config->libPCI, 1);
ffStrbufInitA(&config->libX11, 1);
ffStrbufInitA(&config->libXrandr, 1);
ffStrbufInitA(&config->libDConf, 1);
ffStrbufInitA(&config->diskFolders, 1);
}
static inline void* calculatePlasmaThreadMain(void* instance)
{
ffCalculatePlasma((FFinstance*)instance, NULL, NULL, NULL);
return NULL;
}
static inline void* calculateGTK2ThreadMain(void* instance)
{
ffCalculateGTK2((FFinstance*)instance, NULL, NULL, NULL);
return NULL;
}
static inline void* calculateGTK3ThreadMain(void* instance)
{
ffCalculateGTK3((FFinstance*)instance, NULL, NULL, NULL);
return NULL;
}
static inline void* calculateGTK4ThreadMain(void* instance)
{
ffCalculateGTK4((FFinstance*)instance, NULL, NULL, NULL);
return NULL;
}
static inline void* calculateWMThreadMain(void* instance)
{
ffCalculateWM((FFinstance*)instance, NULL, NULL, NULL);
return NULL;
}
static inline void* calculateTerminalThreadMain(void* instance)
{
ffCalculateTerminal((FFinstance*)instance, NULL, NULL, NULL);
return NULL;
}
void ffStartCalculationThreads(FFinstance* instance)
{
pthread_t wmThread;
pthread_create(&wmThread, NULL, calculateWMThreadMain, instance);
pthread_detach(wmThread);
pthread_t gtk2Thread;
pthread_create(&gtk2Thread, NULL, calculateGTK2ThreadMain, instance);
pthread_detach(gtk2Thread);
pthread_t gtk3Thread;
pthread_create(&gtk3Thread, NULL, calculateGTK3ThreadMain, instance);
pthread_detach(gtk3Thread);
pthread_t gtk4Thread;
pthread_create(&gtk4Thread, NULL, calculateGTK4ThreadMain, instance);
pthread_detach(gtk4Thread);
pthread_t terminalThread;
pthread_create(&terminalThread, NULL, calculateTerminalThreadMain, instance);
pthread_detach(terminalThread);
pthread_t plasmaThread;
pthread_create(&plasmaThread, NULL, calculatePlasmaThreadMain, instance);
pthread_detach(plasmaThread);
}
static void ffCleanup(FFinstance* instance)
{
// Place for cleaning up
// I dont destroy the global strbufs, because the OS is typically faster doing it after the program terminates
// This eliminates one function call per strbuf + setting things like length to 0
}
void ffFinish(FFinstance* instance)
{
if(instance->config.printRemainingLogo)
ffPrintRemainingLogo(instance);
ffCleanup(instance);
}
void ffPrintKey(FFinstance* instance, FFstrbuf* customKey, const char* defKey)
{
fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
ffStrbufWriteTo(&instance->config.color, stdout);
if(customKey == NULL || customKey->length == 0)
fputs(defKey, stdout);
else
ffStrbufWriteTo(customKey, stdout);
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
ffStrbufWriteTo(&instance->config.seperator, stdout);
}
void ffPrintLogoAndKey(FFinstance* instance, FFstrbuf* customKey, const char* defKey)
{
ffPrintLogoLine(instance);
ffPrintKey(instance, customKey, defKey);
}
void ffPrintError(FFinstance* instance, FFstrbuf* customKey, const char* defKey, const char* message, ...)
{
if(!instance->config.showErrors)
return;
ffPrintLogoAndKey(instance, customKey, defKey);
va_list arguments;
va_start(arguments, message);
printf(FASTFETCH_TEXT_MODIFIER_ERROR);
vprintf(message, arguments);
puts(FASTFETCH_TEXT_MODIFIER_RESET);
va_end(arguments);
}
static const FFstrbuf* getCacheDir(FFinstance* instance)
{
static FFstrbuf cacheDir;
static bool init = false;
if(init)
return &cacheDir;
ffStrbufInitAS(&cacheDir, 64, getenv("XDG_CACHE_HOME"));
if(cacheDir.length == 0)
{
ffStrbufSetS(&cacheDir, instance->state.passwd->pw_dir);
ffStrbufAppendS(&cacheDir, "/.cache/");
}
mkdir(cacheDir.chars, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a cache folder but whow knews
ffStrbufAppendS(&cacheDir, "fastfetch/");
mkdir(cacheDir.chars, S_IRWXU | S_IRGRP | S_IROTH);
init = true;
return &cacheDir;
}
bool ffPrintCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* defKey)
{
if(instance->config.recache)
return false;
FFstrbuf cacheFile;
ffStrbufInitA(&cacheFile, 128);
ffStrbufAppend(&cacheFile, getCacheDir(instance));
ffStrbufAppendS(&cacheFile, defKey);
FFstrbuf value;
ffStrbufInitA(&value, 128);
ffGetFileContent(cacheFile.chars, &value);
ffStrbufDestroy(&cacheFile);
if(value.length == 0)
{
ffStrbufDestroy(&value);
return false;
}
ffPrintLogoAndKey(instance, customKey, defKey);
ffStrbufPutTo(&value, stdout);
ffStrbufDestroy(&value);
return true;
}
void ffPrintAndSaveCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* defKey, FFstrbuf* value)
{
if(value->length == 0)
return;
ffPrintLogoAndKey(instance, customKey, defKey);
ffStrbufPutTo(value, stdout);
if(!instance->config.cacheSave)
return;
FFstrbuf cacheFile;
ffStrbufInit(&cacheFile);
ffStrbufAppend(&cacheFile, getCacheDir(instance));
ffStrbufAppendS(&cacheFile, defKey);
int fd = open(cacheFile.chars, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if(fd == -1)
return;
bool failed = write(fd, value->chars, value->length) != value->length;
close(fd);
if(failed)
unlink(cacheFile.chars);
ffStrbufDestroy(&cacheFile);
}
void ffParsePropFile(const char* fileName, const char* regex, char* buffer)
{
buffer[0] = '\0'; //If an error occures, this is the indicator
char* line = NULL;
size_t len = 0;
FILE* file = fopen(fileName, "r");
if(file == NULL)
return; // handle errors in higher functions
while (getline(&line, &len, file) != -1)
{
if (sscanf(line, regex, buffer) > 0)
break;
}
fclose(file);
if(line != NULL)
free(line);
}
void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const char* regex, char* buffer)
{
FFstrbuf absolutePath;
ffStrbufInitA(&absolutePath, 64);
ffStrbufAppendS(&absolutePath, instance->state.passwd->pw_dir);
ffStrbufAppendC(&absolutePath, '/');
ffStrbufAppendS(&absolutePath, relativeFile);
ffParsePropFile(absolutePath.chars, regex, buffer);
ffStrbufDestroy(&absolutePath);
}
void ffAppendFileContent(const char* fileName, FFstrbuf* buffer)
{
int fd = open(fileName, O_RDONLY);
if(fd == -1)
return;
ssize_t readed;
while((readed = read(fd, buffer->chars + buffer->length, buffer->allocated - buffer->length)) == (buffer->allocated - buffer->length))
{
buffer->length += readed;
ffStrbufEnsureCapacity(buffer, buffer->allocated * 2);
}
if(readed >= 0)
buffer->length += readed;
ffStrbufTrimRight(buffer, '\n');
ffStrbufTrimRight(buffer, ' ');
close(fd);
}
void ffGetFileContent(const char* fileName, FFstrbuf* buffer)
{
ffStrbufClear(buffer);
ffAppendFileContent(fileName, buffer);
}
void ffParseFormatStringV(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, va_list argp)
{
FFformatarg arguments[numArgs];
for(uint32_t i = 0; i < numArgs; i++)
arguments[i] = (FFformatarg) va_arg(argp, FFformatarg);
uint32_t argCounter = 1; //First arg is 1 in fomat string
for(uint32_t i = 0; i < formatstr->length; ++i)
{
if(formatstr->chars[i] != '{')
{
ffStrbufAppendC(buffer, formatstr->chars[i]);
continue;
}
if(i == formatstr->length - 1)
{
ffStrbufAppendC(buffer, '{');
continue; //This will always stop the loop
}
++i;
if(formatstr->chars[i] == '{')
{
ffStrbufAppendC(buffer, '{');
continue;
}
uint32_t argIndex;
if(formatstr->chars[i] == '}')
{
if(argCounter > numArgs)
{
ffStrbufAppendS(buffer, "{}");
continue;
}
argIndex = argCounter++;
}
else
{
FFstrbuf argnumstr;
ffStrbufInit(&argnumstr);
while(formatstr->chars[i] != '}' && i < formatstr->length)
ffStrbufAppendC(&argnumstr, formatstr->chars[i++]);
if(
argnumstr.length == 0 ||
ffStrbufGetC(&argnumstr, 0) == '-' ||
sscanf(argnumstr.chars, "%u", &argIndex) != 1 ||
argIndex > numArgs
) {
ffStrbufAppendC(buffer, '{');
ffStrbufAppend(buffer, &argnumstr);
if(formatstr->chars[i] == '}') // We dont have a closing { when ending because whole format string is over
ffStrbufAppendC(buffer, '}');
ffStrbufDestroy(&argnumstr);
continue;
}
ffStrbufDestroy(&argnumstr);
}
if(argIndex == 0)
argIndex = 1;
FFformatarg arg = arguments[argIndex - 1];
if(arg.type == FF_FORMAT_ARG_TYPE_INT)
ffStrbufAppendF(buffer, "%i", *(int*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_UINT)
ffStrbufAppendF(buffer, "%u", *(uint32_t*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_UINT8)
ffStrbufAppendF(buffer, "%u", *(uint8_t*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_STRING)
ffStrbufAppendF(buffer, "%s", (const char*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_STRBUF)
ffStrbufAppend(buffer, (FFstrbuf*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_DOUBLE)
ffStrbufAppendF(buffer, "%g", *(double*)arg.value);
else
{
fprintf(stderr, "Error: format string \"%s\" argument is not implemented\n", formatstr->chars);
ffStrbufDestroy(buffer);
exit(806);
}
}
ffStrbufTrimRight(buffer, ' ');
}
void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, ...)
{
va_list argp;
va_start(argp, numArgs);
ffParseFormatStringV(buffer, formatstr, numArgs, argp);
va_end(argp);
}
void ffPrintFormatString(FFinstance* instance, FFstrbuf* customKey, const char* defKey, FFstrbuf* formatstr, uint32_t numArgs, ...)
{
FFstrbuf buffer;
ffStrbufInitA(&buffer, 256);
va_list argp;
va_start(argp, numArgs);
ffParseFormatStringV(&buffer, formatstr, numArgs, argp);
va_end(argp);
if(buffer.length > 0)
{
ffPrintLogoAndKey(instance, customKey, defKey);
ffStrbufPutTo(&buffer, stdout);
}
ffStrbufDestroy(&buffer);
}
void ffFormatGtkPretty(FFstrbuf* buffer, FFstrbuf* gtk2, FFstrbuf* gtk3, FFstrbuf* gtk4)
{
if(gtk2->length > 0 && gtk3->length > 0 && gtk4->length > 0)
{
if((ffStrbufIgnCaseComp(gtk2, gtk3) == 0) && (ffStrbufIgnCaseComp(gtk2, gtk4) == 0))
{
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK2/3/4]");
}
else if(ffStrbufIgnCaseComp(gtk2, gtk3) == 0)
{
ffStrbufAppend(buffer, gtk3);
ffStrbufAppendS(buffer, " [GTK2/3], ");
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK4]");
}
else if(ffStrbufIgnCaseComp(gtk3, gtk4) == 0)
{
ffStrbufAppend(buffer, gtk2);
ffStrbufAppendS(buffer, " [GTK2], ");
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK3/4]");
}
else
{
ffStrbufAppend(buffer, gtk2);
ffStrbufAppendS(buffer, " [GTK2], ");
ffStrbufAppend(buffer, gtk3);
ffStrbufAppendS(buffer, " [GTK3], ");
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK4]");
}
}
else if(gtk2->length > 0 && gtk3->length > 0)
{
if(ffStrbufIgnCaseComp(gtk2, gtk3) == 0)
{
ffStrbufAppend(buffer, gtk3);
ffStrbufAppendS(buffer, " [GTK2/3]");
}
else
{
ffStrbufAppend(buffer, gtk2);
ffStrbufAppendS(buffer, " [GTK2], ");
ffStrbufAppend(buffer, gtk3);
ffStrbufAppendS(buffer, " [GTK3]");
}
}
else if(gtk3->length > 0 && gtk4->length > 0)
{
if(ffStrbufIgnCaseComp(gtk3, gtk4) == 0)
{
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK3/4]");
}
else
{
ffStrbufAppend(buffer, gtk3);
ffStrbufAppendS(buffer, " [GTK3], ");
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK4]");
}
}
else if(gtk2->length > 0)
{
ffStrbufAppend(buffer, gtk2);
ffStrbufAppendS(buffer, " [GTK2]");
}
else if(gtk3->length > 0)
{
ffStrbufAppend(buffer, gtk3);
ffStrbufAppendS(buffer, " [GTK3]");
}
else if(gtk4->length > 0)
{
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK4]");
}
}
void ffParseFont(const char* font, FFstrbuf* name, double* size)
{
ffStrbufEnsureCapacity(name, 32);
int scanned = sscanf(font, "%[^,], %lf", name->chars, size);
ffStrbufRecalculateLength(name);
if(scanned < 2)
*size = 0.0;
if(scanned == 0)
ffStrbufSetS(name, font);
}
void ffFontPretty(FFstrbuf* buffer, const FFstrbuf* name, double size)
{
ffStrbufAppend(buffer, name);
if(size > 0)
{
ffStrbufAppendS(buffer, " (");
ffStrbufAppendF(buffer, "%g", size);
ffStrbufAppendS(buffer, "pt)");
}
}
@@ -1,8 +1,8 @@
#include "fastfetch.h"
#include "dconf/client/dconf-client.h"
#include "dlfcn.h"
#include <dlfcn.h>
#include <pthread.h>
#include <dconf/client/dconf-client.h>
static inline bool allPropertiesSet(FFstrbuf* themeNamePtr, FFstrbuf* iconsNamePtr, FFstrbuf* fontNamePtr)
{
@@ -1,5 +1,7 @@
#include "fastfetch.h"
#include <string.h>
#include <unistd.h>
#include <pthread.h>
static void getTerminalName(FFinstance* instance, const char* pid, FFstrbuf* exeName, FFstrbuf* processName, FFstrbuf* error)
@@ -5,6 +5,8 @@
void ffCalculateWM(FFinstance* instance, FFstrbuf** prettyNamePtr, FFstrbuf** processNamePtr, FFstrbuf** errorPtr)
{
UNUSED(instance);
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static FFstrbuf prettyName;
+125
View File
@@ -0,0 +1,125 @@
#include "fastfetch.h"
void ffParseFormatStringV(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, va_list argp)
{
FFformatarg arguments[numArgs];
for(uint32_t i = 0; i < numArgs; i++)
arguments[i] = (FFformatarg) va_arg(argp, FFformatarg);
uint32_t argCounter = 1; //First arg is 1 in fomat string
for(uint32_t i = 0; i < formatstr->length; ++i)
{
if(formatstr->chars[i] != '{')
{
ffStrbufAppendC(buffer, formatstr->chars[i]);
continue;
}
if(i == formatstr->length - 1)
{
ffStrbufAppendC(buffer, '{');
continue; //This will always stop the loop
}
++i;
if(formatstr->chars[i] == '{')
{
ffStrbufAppendC(buffer, '{');
continue;
}
uint32_t argIndex;
if(formatstr->chars[i] == '}')
{
if(argCounter > numArgs)
{
ffStrbufAppendS(buffer, "{}");
continue;
}
argIndex = argCounter++;
}
else
{
FFstrbuf argnumstr;
ffStrbufInit(&argnumstr);
while(formatstr->chars[i] != '}' && i < formatstr->length)
ffStrbufAppendC(&argnumstr, formatstr->chars[i++]);
if(
argnumstr.length == 0 ||
ffStrbufGetC(&argnumstr, 0) == '-' ||
sscanf(argnumstr.chars, "%u", &argIndex) != 1 ||
argIndex > numArgs
) {
ffStrbufAppendC(buffer, '{');
ffStrbufAppend(buffer, &argnumstr);
if(formatstr->chars[i] == '}') // We dont have a closing { when ending because whole format string is over
ffStrbufAppendC(buffer, '}');
ffStrbufDestroy(&argnumstr);
continue;
}
ffStrbufDestroy(&argnumstr);
}
if(argIndex == 0)
argIndex = 1;
FFformatarg arg = arguments[argIndex - 1];
if(arg.type == FF_FORMAT_ARG_TYPE_INT)
ffStrbufAppendF(buffer, "%i", *(int*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_UINT)
ffStrbufAppendF(buffer, "%u", *(uint32_t*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_UINT8)
ffStrbufAppendF(buffer, "%u", *(uint8_t*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_STRING)
ffStrbufAppendF(buffer, "%s", (const char*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_STRBUF)
ffStrbufAppend(buffer, (FFstrbuf*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_DOUBLE)
ffStrbufAppendF(buffer, "%g", *(double*)arg.value);
else
{
fprintf(stderr, "Error: format string \"%s\" argument is not implemented\n", formatstr->chars);
ffStrbufDestroy(buffer);
exit(806);
}
}
ffStrbufTrimRight(buffer, ' ');
}
void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, ...)
{
va_list argp;
va_start(argp, numArgs);
ffParseFormatStringV(buffer, formatstr, numArgs, argp);
va_end(argp);
}
void ffPrintFormatString(FFinstance* instance, FFstrbuf* customKey, const char* defKey, FFstrbuf* formatstr, uint32_t numArgs, ...)
{
FFstrbuf buffer;
ffStrbufInitA(&buffer, 256);
va_list argp;
va_start(argp, numArgs);
ffParseFormatStringV(&buffer, formatstr, numArgs, argp);
va_end(argp);
if(buffer.length > 0)
{
ffPrintLogoAndKey(instance, customKey, defKey);
ffStrbufPutTo(&buffer, stdout);
}
ffStrbufDestroy(&buffer);
}
+98
View File
@@ -0,0 +1,98 @@
#include "fastfetch.h"
#include <unistd.h>
static void initState(FFstate* state)
{
state->current_row = 0;
state->passwd = getpwuid(getuid());
uname(&state->utsname);
sysinfo(&state->sysinfo);
}
static void defaultConfig(FFconfig* config)
{
ffStrbufInit(&config->color);
config->logo_spacing = 4;
ffStrbufInitS(&config->seperator, ": ");
config->offsetx = 0;
config->titleLength = 20; // This is overwritten by ffPrintTitle
config->colorLogo = true;
config->showErrors = false;
config->recache = false;
config->cacheSave = true;
config->printRemainingLogo = true;
//Since most of these properties are unlikely to be used at once, give them minimal heap space (the \0 character)
ffStrbufInitA(&config->osFormat, 1);
ffStrbufInitA(&config->osKey, 1);
ffStrbufInitA(&config->hostFormat, 1);
ffStrbufInitA(&config->hostKey, 1);
ffStrbufInitA(&config->kernelFormat, 1);
ffStrbufInitA(&config->kernelKey, 1);
ffStrbufInitA(&config->uptimeFormat, 1);
ffStrbufInitA(&config->uptimeKey, 1);
ffStrbufInitA(&config->packagesFormat, 1);
ffStrbufInitA(&config->packagesKey, 1);
ffStrbufInitA(&config->shellFormat, 1);
ffStrbufInitA(&config->shellKey, 1);
ffStrbufInitA(&config->resolutionFormat, 1);
ffStrbufInitA(&config->resolutionKey, 1);
ffStrbufInitA(&config->deFormat, 1);
ffStrbufInitA(&config->deKey, 1);
ffStrbufInitA(&config->wmFormat, 1);
ffStrbufInitA(&config->wmKey, 1);
ffStrbufInitA(&config->wmThemeFormat, 1);
ffStrbufInitA(&config->wmThemeKey, 1);
ffStrbufInitA(&config->themeFormat, 1);
ffStrbufInitA(&config->themeKey, 1);
ffStrbufInitA(&config->iconsFormat, 1);
ffStrbufInitA(&config->iconsKey, 1);
ffStrbufInitA(&config->fontFormat, 1);
ffStrbufInitA(&config->fontKey, 1);
ffStrbufInitA(&config->terminalFormat, 1);
ffStrbufInitA(&config->terminalKey, 1);
ffStrbufInitA(&config->termFontFormat, 1);
ffStrbufInitA(&config->termFontKey, 1);
ffStrbufInitA(&config->cpuFormat, 1);
ffStrbufInitA(&config->cpuKey, 1);
ffStrbufInitA(&config->gpuFormat, 1);
ffStrbufInitA(&config->gpuKey, 1);
ffStrbufInitA(&config->memoryFormat, 1);
ffStrbufInitA(&config->memoryKey, 1);
ffStrbufInitA(&config->diskFormat, 1);
ffStrbufInitA(&config->diskKey, 1);
ffStrbufInitA(&config->batteryFormat, 1);
ffStrbufInitA(&config->batteryKey, 1);
ffStrbufInitA(&config->localeFormat, 1);
ffStrbufInitA(&config->localeKey, 1);
ffStrbufInitA(&config->libPCI, 1);
ffStrbufInitA(&config->libX11, 1);
ffStrbufInitA(&config->libXrandr, 1);
ffStrbufInitA(&config->libDConf, 1);
ffStrbufInitA(&config->diskFolders, 1);
}
void ffInitInstance(FFinstance* instance)
{
initState(&instance->state);
defaultConfig(&instance->config);
}
static void ffCleanup(FFinstance* instance)
{
UNUSED(instance);
// Place for cleaning up
// I dont destroy the global strbufs, because the OS is typically faster doing it after the program terminates
// This eliminates one function call per strbuf + setting things like length to 0
}
void ffFinish(FFinstance* instance)
{
if(instance->config.printRemainingLogo)
ffPrintRemainingLogo(instance);
ffCleanup(instance);
}
+185
View File
@@ -0,0 +1,185 @@
#include "fastfetch.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
void ffPrintKey(FFinstance* instance, FFstrbuf* customKey, const char* defKey)
{
fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
ffStrbufWriteTo(&instance->config.color, stdout);
if(customKey == NULL || customKey->length == 0)
fputs(defKey, stdout);
else
ffStrbufWriteTo(customKey, stdout);
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
ffStrbufWriteTo(&instance->config.seperator, stdout);
}
void ffPrintLogoAndKey(FFinstance* instance, FFstrbuf* customKey, const char* defKey)
{
ffPrintLogoLine(instance);
ffPrintKey(instance, customKey, defKey);
}
void ffPrintError(FFinstance* instance, FFstrbuf* customKey, const char* defKey, const char* message, ...)
{
if(!instance->config.showErrors)
return;
ffPrintLogoAndKey(instance, customKey, defKey);
va_list arguments;
va_start(arguments, message);
printf(FASTFETCH_TEXT_MODIFIER_ERROR);
vprintf(message, arguments);
puts(FASTFETCH_TEXT_MODIFIER_RESET);
va_end(arguments);
}
void ffParsePropFile(const char* fileName, const char* regex, char* buffer)
{
buffer[0] = '\0'; //If an error occures, this is the indicator
char* line = NULL;
size_t len = 0;
FILE* file = fopen(fileName, "r");
if(file == NULL)
return; // handle errors in higher functions
while (getline(&line, &len, file) != -1)
{
if (sscanf(line, regex, buffer) > 0)
break;
}
fclose(file);
if(line != NULL)
free(line);
}
void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const char* regex, char* buffer)
{
FFstrbuf absolutePath;
ffStrbufInitA(&absolutePath, 64);
ffStrbufAppendS(&absolutePath, instance->state.passwd->pw_dir);
ffStrbufAppendC(&absolutePath, '/');
ffStrbufAppendS(&absolutePath, relativeFile);
ffParsePropFile(absolutePath.chars, regex, buffer);
ffStrbufDestroy(&absolutePath);
}
void ffAppendFileContent(const char* fileName, FFstrbuf* buffer)
{
int fd = open(fileName, O_RDONLY);
if(fd == -1)
return;
ssize_t readed;
while((readed = read(fd, buffer->chars + buffer->length, buffer->allocated - buffer->length)) == (buffer->allocated - buffer->length))
{
buffer->length += (uint32_t) readed;
ffStrbufEnsureCapacity(buffer, buffer->allocated * 2);
}
if(readed >= 0)
buffer->length += (uint32_t) readed;
ffStrbufTrimRight(buffer, '\n');
ffStrbufTrimRight(buffer, ' ');
close(fd);
}
void ffGetFileContent(const char* fileName, FFstrbuf* buffer)
{
ffStrbufClear(buffer);
ffAppendFileContent(fileName, buffer);
}
static const FFstrbuf* getCacheDir(FFinstance* instance)
{
static FFstrbuf cacheDir;
static bool init = false;
if(init)
return &cacheDir;
ffStrbufInitAS(&cacheDir, 64, getenv("XDG_CACHE_HOME"));
if(cacheDir.length == 0)
{
ffStrbufSetS(&cacheDir, instance->state.passwd->pw_dir);
ffStrbufAppendS(&cacheDir, "/.cache/");
}
mkdir(cacheDir.chars, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a cache folder but whow knews
ffStrbufAppendS(&cacheDir, "fastfetch/");
mkdir(cacheDir.chars, S_IRWXU | S_IRGRP | S_IROTH);
init = true;
return &cacheDir;
}
bool ffPrintCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* defKey)
{
if(instance->config.recache)
return false;
FFstrbuf cacheFile;
ffStrbufInitA(&cacheFile, 128);
ffStrbufAppend(&cacheFile, getCacheDir(instance));
ffStrbufAppendS(&cacheFile, defKey);
FFstrbuf value;
ffStrbufInitA(&value, 128);
ffGetFileContent(cacheFile.chars, &value);
ffStrbufDestroy(&cacheFile);
if(value.length == 0)
{
ffStrbufDestroy(&value);
return false;
}
ffPrintLogoAndKey(instance, customKey, defKey);
ffStrbufPutTo(&value, stdout);
ffStrbufDestroy(&value);
return true;
}
void ffPrintAndSaveCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* defKey, FFstrbuf* value)
{
if(value->length == 0)
return;
ffPrintLogoAndKey(instance, customKey, defKey);
ffStrbufPutTo(value, stdout);
if(!instance->config.cacheSave)
return;
FFstrbuf cacheFile;
ffStrbufInit(&cacheFile);
ffStrbufAppend(&cacheFile, getCacheDir(instance));
ffStrbufAppendS(&cacheFile, defKey);
int fd = open(cacheFile.chars, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if(fd == -1)
return;
bool failed = write(fd, value->chars, value->length) != value->length;
close(fd);
if(failed)
unlink(cacheFile.chars);
ffStrbufDestroy(&cacheFile);
}
+2
View File
@@ -1,5 +1,7 @@
#include "fastfetch.h"
#include <string.h>
static void loadUnknownLogo(FFlogo* logo)
{
logo->width = 23;
+108
View File
@@ -0,0 +1,108 @@
#include "fastfetch.h"
void ffGetGtkPretty(FFstrbuf* buffer, FFstrbuf* gtk2, FFstrbuf* gtk3, FFstrbuf* gtk4)
{
if(gtk2->length > 0 && gtk3->length > 0 && gtk4->length > 0)
{
if((ffStrbufIgnCaseComp(gtk2, gtk3) == 0) && (ffStrbufIgnCaseComp(gtk2, gtk4) == 0))
{
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK2/3/4]");
}
else if(ffStrbufIgnCaseComp(gtk2, gtk3) == 0)
{
ffStrbufAppend(buffer, gtk3);
ffStrbufAppendS(buffer, " [GTK2/3], ");
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK4]");
}
else if(ffStrbufIgnCaseComp(gtk3, gtk4) == 0)
{
ffStrbufAppend(buffer, gtk2);
ffStrbufAppendS(buffer, " [GTK2], ");
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK3/4]");
}
else
{
ffStrbufAppend(buffer, gtk2);
ffStrbufAppendS(buffer, " [GTK2], ");
ffStrbufAppend(buffer, gtk3);
ffStrbufAppendS(buffer, " [GTK3], ");
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK4]");
}
}
else if(gtk2->length > 0 && gtk3->length > 0)
{
if(ffStrbufIgnCaseComp(gtk2, gtk3) == 0)
{
ffStrbufAppend(buffer, gtk3);
ffStrbufAppendS(buffer, " [GTK2/3]");
}
else
{
ffStrbufAppend(buffer, gtk2);
ffStrbufAppendS(buffer, " [GTK2], ");
ffStrbufAppend(buffer, gtk3);
ffStrbufAppendS(buffer, " [GTK3]");
}
}
else if(gtk3->length > 0 && gtk4->length > 0)
{
if(ffStrbufIgnCaseComp(gtk3, gtk4) == 0)
{
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK3/4]");
}
else
{
ffStrbufAppend(buffer, gtk3);
ffStrbufAppendS(buffer, " [GTK3], ");
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK4]");
}
}
else if(gtk2->length > 0)
{
ffStrbufAppend(buffer, gtk2);
ffStrbufAppendS(buffer, " [GTK2]");
}
else if(gtk3->length > 0)
{
ffStrbufAppend(buffer, gtk3);
ffStrbufAppendS(buffer, " [GTK3]");
}
else if(gtk4->length > 0)
{
ffStrbufAppend(buffer, gtk4);
ffStrbufAppendS(buffer, " [GTK4]");
}
}
void ffGetFont(const char* font, FFstrbuf* name, double* size)
{
ffStrbufEnsureCapacity(name, 32);
int scanned = sscanf(font, "%[^,], %lf", name->chars, size);
ffStrbufRecalculateLength(name);
if(scanned < 2)
*size = 0.0;
if(scanned == 0)
ffStrbufSetS(name, font);
}
void ffGetFontPretty(FFstrbuf* buffer, const FFstrbuf* name, double size)
{
ffStrbufAppend(buffer, name);
if(size > 0)
{
ffStrbufAppendS(buffer, " (");
ffStrbufAppendF(buffer, "%g", size);
ffStrbufAppendS(buffer, "pt)");
}
}
+75
View File
@@ -0,0 +1,75 @@
#include "fastfetch.h"
#include <pthread.h>
static inline void* calculatePlasmaThreadMain(void* instance)
{
ffCalculatePlasma((FFinstance*)instance, NULL, NULL, NULL);
return NULL;
}
static inline void* calculateGTK2ThreadMain(void* instance)
{
ffCalculateGTK2((FFinstance*)instance, NULL, NULL, NULL);
return NULL;
}
static inline void* calculateGTK3ThreadMain(void* instance)
{
ffCalculateGTK3((FFinstance*)instance, NULL, NULL, NULL);
return NULL;
}
static inline void* calculateGTK4ThreadMain(void* instance)
{
ffCalculateGTK4((FFinstance*)instance, NULL, NULL, NULL);
return NULL;
}
static inline void* calculateWMThreadMain(void* instance)
{
ffCalculateWM((FFinstance*)instance, NULL, NULL, NULL);
return NULL;
}
static inline void* calculateTerminalThreadMain(void* instance)
{
ffCalculateTerminal((FFinstance*)instance, NULL, NULL, NULL);
return NULL;
}
static inline void* startThreadsThreadMain(void* instance)
{
pthread_t wmThread;
pthread_create(&wmThread, NULL, calculateWMThreadMain, instance);
pthread_detach(wmThread);
pthread_t gtk2Thread;
pthread_create(&gtk2Thread, NULL, calculateGTK2ThreadMain, instance);
pthread_detach(gtk2Thread);
pthread_t gtk3Thread;
pthread_create(&gtk3Thread, NULL, calculateGTK3ThreadMain, instance);
pthread_detach(gtk3Thread);
pthread_t gtk4Thread;
pthread_create(&gtk4Thread, NULL, calculateGTK4ThreadMain, instance);
pthread_detach(gtk4Thread);
pthread_t terminalThread;
pthread_create(&terminalThread, NULL, calculateTerminalThreadMain, instance);
pthread_detach(terminalThread);
pthread_t plasmaThread;
pthread_create(&plasmaThread, NULL, calculatePlasmaThreadMain, instance);
pthread_detach(plasmaThread);
return NULL;
}
void ffStartCalculationThreads(FFinstance* instance)
{
pthread_t startThreadsThread;
pthread_create(&startThreadsThread, NULL, startThreadsThreadMain, instance);
pthread_detach(startThreadsThread);
}
+2 -3
View File
@@ -2,8 +2,8 @@
#include "fastfetch_config.h"
#include "util/FFvaluestore.h"
#include <string.h>
#include <malloc.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -886,8 +886,7 @@ static void initData(FFdata* data)
int main(int argc, const char** argv)
{
FFinstance instance;
ffInitState(&instance.state);
ffDefaultConfig(&instance.config);
ffInitInstance(&instance);
FFdata data;
initData(&data);
+37 -21
View File
@@ -9,16 +9,14 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/utsname.h>
#include <sys/sysinfo.h>
#include "util/FFstrbuf.h"
#define UNUSED(...) (void)(__VA_ARGS__)
#define FASTFETCH_TEXT_MODIFIER_BOLT "\033[1m"
#define FASTFETCH_TEXT_MODIFIER_ERROR "\033[1;31m"
#define FASTFETCH_TEXT_MODIFIER_RESET "\033[0m"
@@ -128,48 +126,66 @@ typedef struct FFformatarg
const void* value;
} FFformatarg;
//Common functions
void ffInitState(FFstate* state);
void ffDefaultConfig(FFconfig* config);
/*************************/
/* Common util functions */
/*************************/
//common/init.c
void ffInitInstance(FFinstance* instance);
void ffFinish(FFinstance* instance);
//common/threading.c
void ffStartCalculationThreads(FFinstance* instance);
//common/io.c
void ffPrintKey(FFinstance* instance, FFstrbuf* customKey, const char* defKey);
void ffPrintLogoAndKey(FFinstance* instance, FFstrbuf* customKey, const char* defKey);
void ffPrintError(FFinstance* instance, FFstrbuf* customKey, const char* defKey, const char* message, ...);
bool ffPrintCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* defKey);
void ffPrintAndSaveCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* defKey, FFstrbuf* value);
void ffAppendFileContent(const char* fileName, FFstrbuf* buffer);
void ffGetFileContent(const char* fileName, FFstrbuf* buffer);
void ffParsePropFile(const char* file, const char* regex, char* buffer);
void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const char* regex, char* buffer);
void ffParseFormatStringV(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, va_list argp);
void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, ...);
void ffPrintFormatString(FFinstance* instance, FFstrbuf* customKey, const char* defKey, FFstrbuf* formatstr, uint32_t numArgs, ...);
void ffFormatGtkPretty(FFstrbuf* buffer, FFstrbuf* gtk2, FFstrbuf* gtk3, FFstrbuf* gtk4);
void ffParseFont(const char* font, FFstrbuf* name, double* size);
void ffFontPretty(FFstrbuf* buffer, const FFstrbuf* name, double size);
void ffFinish(FFinstance* instance);
bool ffPrintCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* defKey);
void ffPrintAndSaveCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* defKey, FFstrbuf* value);
//Logo functions
//common/logo.c
void ffLoadLogoSet(FFconfig* config, const char* logo);
void ffLoadLogo(FFconfig* config);
void ffPrintLogoLine(FFinstance* instance);
void ffPrintRemainingLogo(FFinstance* instance);
#ifndef FLASHFETCH_BUILD_FLASHFATCH
void ffListLogos();
void ffPrintLogos(bool color);
void ffListLogos();
void ffPrintLogos(bool color);
#endif
//Helper functions
//common/format.c
void ffParseFormatStringV(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, va_list argp);
void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, ...);
void ffPrintFormatString(FFinstance* instance, FFstrbuf* customKey, const char* defKey, FFstrbuf* formatstr, uint32_t numArgs, ...);
//common/parsing.c
void ffGetGtkPretty(FFstrbuf* buffer, FFstrbuf* gtk2, FFstrbuf* gtk3, FFstrbuf* gtk4);
void ffGetFont(const char* font, FFstrbuf* name, double* size);
void ffGetFontPretty(FFstrbuf* buffer, const FFstrbuf* name, double size);
//common/calculatePlasma.c
void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr);
//common/calculateGTK.c
void ffCalculateGTK2(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr);
void ffCalculateGTK4(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr);
void ffCalculateGTK3(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr);
//common/calculateWM.c
void ffCalculateWM(FFinstance* instance, FFstrbuf** prettyNamePtr, FFstrbuf** processNamePtr, FFstrbuf** errorPtr);
//common/calculateTerminal.c
void ffCalculateTerminal(FFinstance* instance, FFstrbuf** exeNamePtr, FFstrbuf** processNamePtr, FFstrbuf** errorPtr);
//Module functions
/********************/
/* Module functions */
/********************/
void ffPrintCustom(FFinstance* instance, const char* key, const char* value);
void ffPrintBreak(FFinstance* instance);
+5 -2
View File
@@ -2,9 +2,12 @@
int main(int argc, char** argv)
{
//Disable compiler warnings
UNUSED(argc);
UNUSED(argv);
FFinstance instance;
ffInitState(&instance.state);
ffDefaultConfig(&instance.config);
ffInitInstance(&instance);
//Configuration
ffLoadLogoSet(&instance.config, "arch");
+2
View File
@@ -1,5 +1,7 @@
#include "fastfetch.h"
#include <string.h>
static double getGhz(const char* file)
{
FF_STRBUF_CREATE(content);
+4
View File
@@ -1,7 +1,11 @@
#include "fastfetch.h"
#include <string.h>
static void getKDE(FFstrbuf* name, FFstrbuf* version, FFstrbuf* type)
{
UNUSED(type);
ffStrbufSetS(name, "KDE Plasma");
char versionBuf[256];
+9 -11
View File
@@ -1,7 +1,5 @@
#include "fastfetch.h"
#include <unistd.h>
void ffPrintFont(FFinstance* instance)
{
FFstrbuf* plasma;
@@ -24,30 +22,30 @@ void ffPrintFont(FFinstance* instance)
FF_STRBUF_CREATE(plasmaName);
double plasmaSize;
ffParseFont(plasma->chars, &plasmaName, &plasmaSize);
ffGetFont(plasma->chars, &plasmaName, &plasmaSize);
FF_STRBUF_CREATE(plasmaPretty);
ffFontPretty(&plasmaPretty, &plasmaName, plasmaSize);
ffGetFontPretty(&plasmaPretty, &plasmaName, plasmaSize);
FF_STRBUF_CREATE(gtk2Name);
double gtk2Size;
ffParseFont(gtk2->chars, &gtk2Name, &gtk2Size);
ffGetFont(gtk2->chars, &gtk2Name, &gtk2Size);
FF_STRBUF_CREATE(gtk2Pretty);
ffFontPretty(&gtk2Pretty, &gtk2Name, gtk2Size);
ffGetFontPretty(&gtk2Pretty, &gtk2Name, gtk2Size);
FF_STRBUF_CREATE(gtk3Name);
double gtk3Size;
ffParseFont(gtk3->chars, &gtk3Name, &gtk3Size);
ffGetFont(gtk3->chars, &gtk3Name, &gtk3Size);
FF_STRBUF_CREATE(gtk3Pretty);
ffFontPretty(&gtk3Pretty, &gtk3Name, gtk3Size);
ffGetFontPretty(&gtk3Pretty, &gtk3Name, gtk3Size);
FF_STRBUF_CREATE(gtk4Name);
double gtk4Size;
ffParseFont(gtk4->chars, &gtk4Name, &gtk4Size);
ffGetFont(gtk4->chars, &gtk4Name, &gtk4Size);
FF_STRBUF_CREATE(gtk4Pretty);
ffFontPretty(&gtk4Pretty, &gtk4Name, gtk4Size);
ffGetFontPretty(&gtk4Pretty, &gtk4Name, gtk4Size);
FF_STRBUF_CREATE(gtkPretty);
ffFormatGtkPretty(&gtkPretty, &gtk2Pretty, &gtk3Pretty, &gtk4Pretty);
ffGetGtkPretty(&gtkPretty, &gtk2Pretty, &gtk3Pretty, &gtk4Pretty);
if(instance->config.fontFormat.length == 0)
{
+2 -1
View File
@@ -1,7 +1,8 @@
#include "fastfetch.h"
#include <pci/pci.h>
#include <string.h>
#include <dlfcn.h>
#include <pci/pci.h>
static void getKey(FFinstance* instance, FFstrbuf* key, uint8_t counter, bool showCounter)
{
+1 -1
View File
@@ -21,7 +21,7 @@ void ffPrintIcons(FFinstance* instance)
}
FF_STRBUF_CREATE(gtkPretty);
ffFormatGtkPretty(&gtkPretty, gtk2, gtk3, gtk4);
ffGetGtkPretty(&gtkPretty, gtk2, gtk3, gtk4);
if(instance->config.iconsFormat.length == 0)
{
+2
View File
@@ -1,5 +1,7 @@
#include "fastfetch.h"
#include <string.h>
void ffPrintLocale(FFinstance* instance)
{
if(ffPrintCachedValue(instance, &instance->config.localeKey, "Locale"))
+1 -1
View File
@@ -1,6 +1,6 @@
#include "fastfetch.h"
// Impl by: https://github.com/sam-barr/paleofetch/blob/b7c58a52c0de39b53c9b5f417889a5886d324bfa/paleofetch.c#L544
// Impl inspired by: https://github.com/sam-barr/paleofetch/blob/b7c58a52c0de39b53c9b5f417889a5886d324bfa/paleofetch.c#L544
void ffPrintMemory(FFinstance* instance)
{
FILE* meminfo = fopen("/proc/meminfo", "r");
+2 -2
View File
@@ -1,7 +1,7 @@
#include "fastfetch.h"
#include "X11/extensions/Xrandr.h"
#include "dlfcn.h"
#include <dlfcn.h>
#include <X11/extensions/Xrandr.h>
static int getCurrentRate(FFinstance* instance, Display* display)
{
+2
View File
@@ -1,5 +1,7 @@
#include "fastfetch.h"
#include <string.h>
void ffPrintShell(FFinstance* instance)
{
if(ffPrintCachedValue(instance, &instance->config.shellKey, "Shell"))
+4 -2
View File
@@ -1,12 +1,14 @@
#include "fastfetch.h"
#include <string.h>
static void printTerminalFont(FFinstance* instance, const char* font)
{
FF_STRBUF_CREATE(name);
double size;
ffParseFont(font, &name, &size);
ffGetFont(font, &name, &size);
FF_STRBUF_CREATE(pretty);
ffFontPretty(&pretty, &name, size);
ffGetFontPretty(&pretty, &name, size);
if(instance->config.termFontFormat.length == 0)
{
+1 -1
View File
@@ -21,7 +21,7 @@ void ffPrintTheme(FFinstance* instance)
}
FF_STRBUF_CREATE(gtkPretty);
ffFormatGtkPretty(&gtkPretty, gtk2, gtk3, gtk4);
ffGetGtkPretty(&gtkPretty, gtk2, gtk3, gtk4);
if(instance->config.themeFormat.length == 0)
{
+3
View File
@@ -1,5 +1,8 @@
#include "fastfetch.h"
#include <string.h>
#include <unistd.h>
void ffPrintTitle(FFinstance* instance)
{
char hostname[256];
+3 -7
View File
@@ -1,7 +1,6 @@
#include "FFstrbuf.h"
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
void ffStrbufInit(FFstrbuf* strbuf)
@@ -34,8 +33,8 @@ void ffStrbufInitA(FFstrbuf* strbuf, uint32_t allocate)
{
if(allocate == 0)
{
fprintf(stderr, "ffStrbufInitA(): allocation size == 0");
exit(701);
fprintf(stderr, "ffStrbufInitA(): allocation size == 0, changing to 1");
allocate = 1;
}
strbuf->allocated = allocate;
@@ -222,10 +221,7 @@ void ffStrbufAppendVF(FFstrbuf* strbuf, const char* format, va_list arguments)
char ffStrbufGetC(FFstrbuf* strbuf, uint32_t index)
{
if(index >= strbuf->length)
{
fprintf(stderr, "ffStrbufGetC(): to high index");
exit(702);
}
return '\0';
return strbuf->chars[index];
}
+4 -2
View File
@@ -16,12 +16,14 @@
int main(int argc, char** argv)
{
UNUSED(argc);
UNUSED(argv);
FFinstance instance;
FASTFETCH_TEST_PERFORMANCE(
puts("Initialization");
ffInitState(&instance.state);
ffDefaultConfig(&instance.config);
ffInitInstance(&instance);
)
FASTFETCH_TEST_PERFORMANCE(