Compare commits

...

15 Commits

Author SHA1 Message Date
Linus Dierheimer 779dbab647 Release 1.6.4 2022-08-22 00:13:13 +02:00
Linus Dierheimer 47373998d5 replace gethostbyname with getaddrinfo
#217
2022-08-21 23:35:22 +02:00
Linus Dierheimer 11809e30b5 Parse config files faster 2022-08-21 21:08:11 +02:00
Linus Dierheimer 35253e085c Unified storage of --set and --set-keyless values 2022-08-20 18:17:00 +02:00
Linus Dierheimer 112e83b7c3 Provide apk count to package format string 2022-08-18 22:02:21 +02:00
Linus Dierheimer c74b34aa39 Merge pull request #216 from mxkrsv/apk-support
Add APK (Alpine Package Keeper) support
2022-08-18 21:56:20 +02:00
Maxim Karasev b2e0034c34 Add APK (Alpine Package Keeper) support 2022-08-18 22:28:40 +03:00
Linus Dierheimer e3cdf9d9fd Reset color after custom module 2022-08-18 11:45:44 +02:00
Linus Dierheimer 6cdb694e33 Do simple \ replacement in user strings 2022-08-18 11:36:30 +02:00
Linus Dierheimer 83016289e9 --set-keyless option 2022-08-18 10:44:21 +02:00
Linus Dierheimer f9562d7132 Merge pull request #214 from jonathanspw/master
add AlmaLinux logo
2022-08-17 09:19:38 +02:00
jonathanspw 2f66bc2c95 add AlmaLinux logo 2022-08-16 20:10:47 -05:00
Linus Dierheimer d7c848225c Update CHANGELOG.md 2022-08-12 21:52:29 +02:00
Linus Dierheimer 8404ae8e70 Merge pull request #212 from ceamac/bugs/install-presets
Fix installation of presets/ directory
2022-08-12 21:50:49 +02:00
Viorel d75f72c8fe Fix installation of presets/ directory 2022-08-12 22:35:31 +03:00
16 changed files with 242 additions and 129 deletions
+19
View File
@@ -1,3 +1,22 @@
# 1.6.4
Releasing this, so fedora can package fastfetch. Thanks to @jonathanspw for doing that!
Features:
* --set-keyless option (#215)
* Replace `\n`, `\t`, `\e` and `\\` in user provided strings, just like c would do it (#215)
* APK (Alpine Package Keeper) support (@mxkrsv, #216)
Logos:
* Alma Linux (@jonathanspw, #214)
Bugfixes:
* replace deprecated gethostbyname call with getaddrinfo (#217)
# 1.6.3
Fixes installing presets in their own directory (@ceamac, #212)
# 1.6.2
Releasing this, so void linux can package fastfetch.
+2 -2
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs
project(fastfetch
VERSION 1.6.2
VERSION 1.6.4
LANGUAGES C
)
@@ -522,7 +522,7 @@ install(
)
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/presets/"
DIRECTORY "${CMAKE_SOURCE_DIR}/presets"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${CMAKE_PROJECT_NAME}"
)
+2 -2
View File
@@ -50,7 +50,7 @@ Title, Separator, OS, Host, Kernel, Uptime, Processes, Packages, Shell, Resoluti
##### Logos
```
Alpine, Android, Arch, Arco, Artix, Bedrock, CachyOS, CentOS, Debian, Devuan, Deepin, Endeavour, Fedora, Garuda, Gentoo, KDE Neon, KISS, Kubuntu, LangitKetujuh, Linux, Manjaro, Mint, NixOS, OpenSUSE, OpenSUSE Tumbleweed, OpenSUSE LEAP, Pop!_OS, RebornOS, RedstarOS, Rocky, Rosa, Ubuntu, Void, Zorin
AlmaLinux, Alpine, Android, Arch, Arco, Artix, Bedrock, CachyOS, CentOS, Debian, Devuan, Deepin, Endeavour, Fedora, Garuda, Gentoo, KDE Neon, KISS, Kubuntu, LangitKetujuh, Linux, Manjaro, Mint, NixOS, OpenSUSE, OpenSUSE Tumbleweed, OpenSUSE LEAP, Pop!_OS, RebornOS, RedstarOS, Rocky, Rosa, Ubuntu, Void, Zorin
```
* Most of the logos have a small variant. Access it by appending _small to the logo name.
* Some logos have an old variant. Access it by appending _old to the logo name.
@@ -60,7 +60,7 @@ Alpine, Android, Arch, Arco, Artix, Bedrock, CachyOS, CentOS, Debian, Devuan, De
##### Package managers
```
Pacman, dpkg, rpm, emerge, xbps, nix, Flatpak, Snap
Pacman, dpkg, rpm, emerge, xbps, nix, Flatpak, Snap, apk
```
##### WM themes
+1
View File
@@ -156,6 +156,7 @@ __fastfetch_completion()
"-s"
"--structure"
"--set"
"--set-keyless"
"--gl"
"--os-format"
"--os-key"
-1
View File
@@ -11,7 +11,6 @@ void ffNetworkingGetHttp(const char* host, const char* path, uint32_t timeout, F
struct addrinfo hints = {0};
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
struct addrinfo* addr;
+38 -2
View File
@@ -5,6 +5,10 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
{
ffLogoPrintLine(instance);
//This is used by --set-keyless, in this case we wan't neither the module name nor the separator
if(moduleName == NULL)
return;
if(!instance->config.pipe)
{
fputs(FASTFETCH_TEXT_MODIFIER_RESET FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
@@ -26,7 +30,7 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
ffParseFormatString(&key, customKeyFormat, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex}
});
ffStrbufWriteTo(&key, stdout);
ffPrintUserString(key.chars);
ffStrbufDestroy(&key);
}
@@ -49,7 +53,8 @@ void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t m
if(buffer.length > 0)
{
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
ffStrbufPutTo(&buffer, stdout);
ffPrintUserString(buffer.chars);
putchar('\n');
}
ffStrbufDestroy(&buffer);
@@ -125,3 +130,34 @@ void ffPrintCharTimes(char c, uint32_t times)
for(uint32_t i = 0; i < times; i++)
putchar(c);
}
void ffPrintUserString(const char* value)
{
while(*value != '\0')
{
if(*value != '\\')
{
putchar(*value);
++value;
continue;
}
++value;
if(*value == 'n')
putchar('\n');
else if(*value == 't')
putchar('\t');
else if(*value == 'e')
putchar('\e');
else if(*value == '\\')
putchar('\\');
else
{
putchar('\\');
putchar(*value);
}
++value;
}
}
+1
View File
@@ -13,5 +13,6 @@ void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t mo
void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...);
void ffPrintColor(const FFstrbuf* colorValue);
void ffPrintCharTimes(char c, uint32_t times);
void ffPrintUserString(const char* str);
#endif
+1 -1
View File
@@ -303,4 +303,4 @@
#--lib-egl /usr/lib/libEGL.so
#--lib-glx /usr/lib/libGLX.so
#--lib-osmesa /usr/lib/libOSMesa.so
#--lib-opencl /usr/lib/libOpenCL.so
#--lib-opencl /usr/lib/libOpenCL.so
+1
View File
@@ -43,6 +43,7 @@ Display options:
-c,--color <color>: sets the color of the keys. Must be a linux console color code or the name of a color (+)
--separator <str>: sets the separator between key and value. Default is a colon with a space
--set <key=value>: hard set the value of a key
--set-keyless <key=value>: hard set the value of a key, but don't print the key or the separator
--show-errors <?value>: print occuring errors
--disable-linewrap <?value>: weather to disable linewrap during the run
--hide-cursor <?value>: weather to hide the cursor during the run
+19 -3
View File
@@ -27,9 +27,25 @@ const FFTitleResult* ffDetectTitle(const FFinstance* instance)
ffStrbufAppendS(&result.hostname, instance->state.utsname.nodename);
ffStrbufInitA(&result.fqdn, HOST_NAME_MAX);
struct hostent* host = gethostbyname(result.hostname.chars);
if(host != NULL)
ffStrbufAppendS(&result.fqdn, host->h_name);
struct addrinfo hints = {0};
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
struct addrinfo* info = NULL;
if(getaddrinfo(result.hostname.chars, "80", &hints, &info) == 0)
{
struct addrinfo* current = info;
while(result.fqdn.length == 0 && current != NULL)
{
ffStrbufAppendS(&result.fqdn, current->ai_canonname);
current = current->ai_next;
}
freeaddrinfo(info);
}
if(result.fqdn.length == 0)
ffStrbufAppend(&result.fqdn, &result.hostname);
+71 -55
View File
@@ -4,14 +4,21 @@
#include "common/parsing.h"
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
typedef struct CustomValue
{
bool printKey;
FFstrbuf value;
} CustomValue;
// Things only needed by fastfetch
typedef struct FFdata
{
FFvaluestore valuestore;
FFvaluestore customValues;
FFstrbuf structure;
bool loadUserConfig;
} FFdata;
@@ -106,7 +113,7 @@ static inline void printCommandHelp(const char* command)
}
else if(strcasecmp(command, "packages-format") == 0)
{
constructAndPrintCommandHelpFormat("packages", "{2} (pacman){?3}[{3}]{?}, {4} (dpkg), {5} (rpm), {6} (emerge), {7} (xbps), {8} (nix-user), {9} (nix-default), {10} (flatpak), {11} (snap)", 11,
constructAndPrintCommandHelpFormat("packages", "{2} (pacman){?3}[{3}]{?}, {4} (dpkg), {5} (rpm), {6} (emerge), {7} (xbps), {8} (nix-system), {9} (nix-user), {10} (nix-default), {11} (apk), {12} (flatpak), {13} (snap)", 13,
"Number of all packages",
"Number of pacman packages",
"Pacman branch on manjaro",
@@ -117,6 +124,7 @@ static inline void printCommandHelp(const char* command)
"Number of nix-system packages",
"Number of nix-user packages",
"Number of nix-default packages",
"Number of apk packages",
"Number of flatpak packages",
"Number of snap packages"
);
@@ -446,58 +454,57 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
static void parseConfigFile(FFinstance* instance, FFdata* data, FILE* file)
{
char* lineStart = NULL;
char* line = NULL;
size_t len = 0;
ssize_t read;
FFstrbuf line;
ffStrbufInitA(&line, 256); //The default structure line needs this size
while ((read = getline(&lineStart, &len, file)) != -1)
while ((read = getline(&line, &len, file)) != -1)
{
ffStrbufSetS(&line, lineStart);
ffStrbufTrimRight(&line, '\n');
ffStrbufTrim(&line, ' ');
char* lineStart = line;
char* lineEnd = line + read - 1;
if(line.length == 0 || line.chars[0] == '#')
//Trim line left
while(isspace(*lineStart))
++lineStart;
//Continue if line is empty or a comment
if(*lineStart == '\0' || *lineStart == '#')
continue;
uint32_t firstSpace = ffStrbufFirstIndexC(&line, ' ');
//Trim line right
while(lineEnd > lineStart && isspace(*lineEnd))
--lineEnd;
*(lineEnd + 1) = '\0';
if(firstSpace >= line.length)
char* valueStart = strchr(lineStart, ' ');
//If the line has no white space, it is only a key
if(valueStart == NULL)
{
parseOption(instance, data, line.chars, NULL);
parseOption(instance, data, lineStart, NULL);
continue;
}
//Separate key and value by simply replacing the first space with a \0
char* valueStart = &line.chars[firstSpace];
//separate the key from the value
*valueStart = '\0';
++valueStart;
//Trim whitespace at beginning of value
while(*valueStart == ' ')
//Trim space of value left
while(isspace(*valueStart))
++valueStart;
//If we want whitespace in values, we need to quote it. This is done to keep consistency with shell.
if(*valueStart == '"')
if((*valueStart == '"' || *valueStart == '\'') && *valueStart == *lineEnd && lineEnd > valueStart)
{
char* last = line.chars + line.length - 1;
if(*last == '"')
{
++valueStart;
*last = '\0';
--line.length;
}
++valueStart;
--lineEnd;
}
parseOption(instance, data, line.chars, valueStart);
parseOption(instance, data, lineStart, valueStart);
}
ffStrbufDestroy(&line);
if(lineStart != NULL)
free(lineStart);
if(line != NULL)
free(line);
}
static void optionParseConfigFile(FFinstance* instance, FFdata* data, const char* key, const char* value)
@@ -668,6 +675,32 @@ static uint32_t optionParseUInt32(const char* key, const char* value)
return num;
}
static void optionParseCustomValue(FFdata* data, const char* key, const char* value, bool printKey)
{
if(value == NULL)
{
fprintf(stderr, "Error: usage: %s <key=value>\n", key);
exit(411);
}
char* separator = strchr(value, '=');
if(separator == NULL)
{
fprintf(stderr, "Error: usage: %s <key=value>, '=' missing\n", key);
exit(412);
}
*separator = '\0';
bool created;
CustomValue* customValue = ffValuestoreSet(&data->customValues, value, &created);
if(created)
ffStrbufInit(&customValue->value);
ffStrbufSetS(&customValue->value, separator + 1);
customValue->printKey = printKey;
}
static void parseOption(FFinstance* instance, FFdata* data, const char* key, const char* value)
{
///////////////////////
@@ -879,25 +912,9 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
else if(strcasecmp(key, "-c") == 0 || strcasecmp(key, "--color") == 0)
optionParseColor(key, value, &instance->config.mainColor);
else if(strcasecmp(key, "--set") == 0)
{
if(value == NULL)
{
fprintf(stderr, "Error: usage: %s <key=value>\n", key);
exit(411);
}
char* separator = strchr(value, '=');
if(separator == NULL)
{
fprintf(stderr, "Error: usage: %s <key=value>, '=' missing\n", key);
exit(412);
}
*separator = '\0';
ffValuestoreSet(&data->valuestore, value, separator + 1);
}
optionParseCustomValue(data, key, value, true);
else if(strcasecmp(key, "--set-keyless") == 0)
optionParseCustomValue(data, key, value, false);
////////////////////////////////
//Format + Key + Error options//
@@ -1264,7 +1281,6 @@ static void parseArguments(FFinstance* instance, FFdata* data, int argc, const c
{
if(i == argc - 1 || (
*argv[i + 1] == '-' &&
strcasecmp(argv[i], "--offsetx") != 0 && // --offsetx allows negative values
strcasecmp(argv[i], "--separator-string") != 0 // Separator string can start with a -
)) {
parseOption(instance, data, argv[i], NULL);
@@ -1279,10 +1295,10 @@ static void parseArguments(FFinstance* instance, FFdata* data, int argc, const c
static void parseStructureCommand(FFinstance* instance, FFdata* data, const char* line)
{
const char* setValue = ffValuestoreGet(&data->valuestore, line);
if(setValue != NULL)
CustomValue* customValue = ffValuestoreGet(&data->customValues, line);
if(customValue != NULL)
{
ffPrintCustom(instance, line, setValue);
ffPrintCustom(instance, customValue->printKey ? line : NULL, customValue->value.chars);
return;
}
@@ -1373,7 +1389,7 @@ int main(int argc, const char** argv)
//Data stores things only needed for the configuration of fastfetch
FFdata data;
ffValuestoreInit(&data.valuestore);
ffValuestoreInit(&data.customValues, sizeof(CustomValue));
ffStrbufInitA(&data.structure, 256);
data.loadUserConfig = true;
+37
View File
@@ -43,6 +43,42 @@ static const FFlogo* getLogoNone()
FF_LOGO_RETURN
}
static const FFlogo* getLogoAlmaLinux()
{
FF_LOGO_INIT
FF_LOGO_NAMES("almalinux")
FF_LOGO_LINES(
"$1 'c:.\n"
"$1 lkkkx, .. $2.. ,cc,\n"
"$1 okkkk:ckkx' $2.lxkkx.okkkkd\n"
"$1 .:llcokkx' $2:kkkxkko:xkkd,\n"
"$1 .xkkkkdood: $2;kx, .lkxlll;\n"
"$1 xkkx. $2xk' xkkkkk:\n"
"$1 'xkx. $2xd .....,.\n"
"$3 .. $1:xkl' $2:c ..''..\n"
"$3 .dkx' $1.:ldl:'. $2' $4':lollldkkxo;\n"
"$3 .''lkkko' $4ckkkx.\n"
"$3'xkkkd:kkd. .. $5;' $4:kkxo.\n"
"$3,xkkkd;kk' ,d; $5ld. $4':dkd::cc,\n"
"$3 .,,.;xkko'.';lxo. $5dx, $4:kkk'xkkkkc\n"
"$3 'dkkkkkxo:. $5;kx $4.kkk:;xkkd.\n"
"$3 ..... $5.;dk:. $5lkk. $4:;,\n"
" $5:kkkkkkkdoxkkx\n"
" ,c,,;;;:xkkd.\n"
" ;kkkkl...\n"
" ;kkkkl\n"
" ,od;";
)
FF_LOGO_COLORS(
"31", // red
"1;33", // yellow
"34", // blue
"1;32", // light green
"36" // cyan
)
FF_LOGO_RETURN
}
static const FFlogo* getLogoAlpine()
{
FF_LOGO_INIT
@@ -1572,6 +1608,7 @@ GetLogoMethod* ffLogoBuiltinGetAll()
static GetLogoMethod logoMethods[] = {
ffLogoBuiltinGetUnknown,
getLogoNone,
getLogoAlmaLinux,
getLogoAlpine,
getLogoAlpineSmall,
getLogoAndroid,
+2 -1
View File
@@ -4,5 +4,6 @@
void ffPrintCustom(FFinstance* instance, const char* key, const char* value)
{
ffPrintLogoAndKey(instance, key, 0, NULL);
puts(value);
ffPrintUserString(value);
puts(FASTFETCH_TEXT_MODIFIER_RESET);
}
+15 -7
View File
@@ -12,7 +12,7 @@
#include <sys/stat.h>
#define FF_PACKAGES_MODULE_NAME "Packages"
#define FF_PACKAGES_NUM_FORMAT_ARGS 12
#define FF_PACKAGES_NUM_FORMAT_ARGS 13
typedef struct PackageCounts
{
@@ -23,6 +23,7 @@ typedef struct PackageCounts
uint32_t xbps;
uint32_t nixSystem;
uint32_t nixDefault;
uint32_t apk;
uint32_t flatpak;
uint32_t snap;
@@ -248,11 +249,6 @@ static void getPackageCounts(const FFinstance* instance, FFstrbuf* baseDir, Pack
packageCounts->xbps += getXBPS(baseDir);
ffStrbufSubstrBefore(baseDir, baseDirLength);
//flatpak
ffStrbufAppendS(baseDir, "/var/lib/flatpak/app");
packageCounts->flatpak += getNumElements(baseDir->chars, DT_DIR);
ffStrbufSubstrBefore(baseDir, baseDirLength);
//nix system
ffStrbufAppendS(baseDir, "/run/current-system");
packageCounts->nixSystem += getNixPackages(baseDir->chars);
@@ -263,6 +259,16 @@ static void getPackageCounts(const FFinstance* instance, FFstrbuf* baseDir, Pack
packageCounts->nixDefault += getNixPackages(baseDir->chars);
ffStrbufSubstrBefore(baseDir, baseDirLength);
//apk
ffStrbufAppendS(baseDir, "/lib/apk/db/installed");
packageCounts->apk += getNumStrings(baseDir->chars, "C:Q");
ffStrbufSubstrBefore(baseDir, baseDirLength);
//flatpak
ffStrbufAppendS(baseDir, "/var/lib/flatpak/app");
packageCounts->flatpak += getNumElements(baseDir->chars, DT_DIR);
ffStrbufSubstrBefore(baseDir, baseDirLength);
//snap
ffStrbufAppendS(baseDir, "/snap");
uint32_t snap = getNumElements(baseDir->chars, DT_DIR);
@@ -337,7 +343,7 @@ void ffPrintPackages(FFinstance* instance)
ffStrbufDestroy(&baseDir);
uint32_t all = counts.pacman + counts.dpkg + counts.rpm + counts.emerge + counts.xbps + counts.nixSystem + nixUser + counts.nixDefault + counts.flatpak + counts.snap;
uint32_t all = counts.pacman + counts.dpkg + counts.rpm + counts.emerge + counts.xbps + counts.nixSystem + nixUser + counts.nixDefault + counts.apk + counts.flatpak + counts.snap;
if(all == 0)
{
ffPrintError(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages, "No packages from known package managers found");
@@ -391,6 +397,7 @@ void ffPrintPackages(FFinstance* instance)
printf(", ");
}
FF_PRINT_PACKAGE(apk)
FF_PRINT_PACKAGE(flatpak)
FF_PRINT_PACKAGE(snap)
@@ -414,6 +421,7 @@ void ffPrintPackages(FFinstance* instance)
{FF_FORMAT_ARG_TYPE_UINT, &counts.nixSystem},
{FF_FORMAT_ARG_TYPE_UINT, &nixUser},
{FF_FORMAT_ARG_TYPE_UINT, &counts.nixDefault},
{FF_FORMAT_ARG_TYPE_UINT, &counts.apk},
{FF_FORMAT_ARG_TYPE_UINT, &counts.flatpak},
{FF_FORMAT_ARG_TYPE_UINT, &counts.snap}
});
+27 -36
View File
@@ -1,55 +1,46 @@
#include "FFvaluestore.h"
#include <string.h>
#include <stdlib.h>
void ffValuestoreInit(FFvaluestore* vs)
typedef char KeyType[33]; //32 byte key + \0
void ffValuestoreInit(FFvaluestore* vs, uint32_t valueSize)
{
vs->capacity = 32;
vs->pairs = calloc(vs->capacity, sizeof(FFvaluestorePair));
vs->size = 0;
ffListInit(vs, sizeof(KeyType) + valueSize);
}
void ffValuestoreSet(FFvaluestore* vs, const char* name, const char* value)
void* ffValuestoreGet(FFvaluestore* vs, const char* key)
{
for(uint32_t i = 0; i < vs->size; i++)
for(uint32_t i = 0; i < vs->length; i++)
{
if(strcasecmp(vs->pairs[i].name, name) == 0)
{
strcpy(vs->pairs[i].value, value);
return;
}
}
if(vs->size == vs->capacity)
{
vs->pairs = realloc(vs->pairs, vs->capacity * sizeof(FFvaluestorePair) * 2);
vs->capacity *= 2;
}
strcpy(vs->pairs[vs->size].name, name);
strcpy(vs->pairs[vs->size].value, value);
++vs->size;
}
const char* ffValuestoreGet(FFvaluestore* vs, const char* name)
{
for(uint32_t i = 0; i < vs->size; i++)
{
if(strcasecmp(vs->pairs[i].name, name) == 0)
return vs->pairs[i].value;
char* element = ffListGet(vs, i);
if(strcmp(element, key) == 0)
return element + sizeof(KeyType);
}
return NULL;
}
bool ffValuestoreContains(FFvaluestore* vs, const char* name)
void* ffValuestoreSet(FFvaluestore* vs, const char* key, bool* created)
{
return ffValuestoreGet(vs, name) != NULL;
char* element = ffValuestoreGet(vs, key);
if(element != NULL)
{
if(created != NULL)
*created = false;
return element;
}
element = ffListAdd(vs);
strncpy(element, key, sizeof(KeyType) - 1);
element[sizeof(KeyType) - 1] = '\0';
if(created != NULL)
*created = true;
return element + sizeof(KeyType);
}
void ffValuestoreDelete(FFvaluestore* vs)
void ffValuestoreDestroy(FFvaluestore* vs)
{
free(vs->pairs);
ffListDestroy(vs);
}
+6 -19
View File
@@ -3,26 +3,13 @@
#ifndef FASTFETCH_INCLUDED_FFVALUESTORE
#define FASTFETCH_INCLUDED_FFVALUESTORE
#include <stdbool.h>
#include <stdint.h>
#include "util/FFlist.h"
typedef struct FFvaluestorePair
{
char name[32];
char value[1024];
} FFvaluestorePair;
typedef FFlist FFvaluestore;
typedef struct FFvaluestore
{
FFvaluestorePair* pairs;
uint32_t size;
uint32_t capacity;
} FFvaluestore;
void ffValuestoreInit(FFvaluestore* vs);
void ffValuestoreSet(FFvaluestore* vs, const char* name, const char* value);
const char* ffValuestoreGet(FFvaluestore* vs, const char* name);
bool ffValuestoreContains(FFvaluestore* vs, const char* name);
void ffValuestoreDelete(FFvaluestore* vs);
void ffValuestoreInit(FFvaluestore* vs, uint32_t valueSize);
void* ffValuestoreGet(FFvaluestore* vs, const char* key);
void* ffValuestoreSet(FFvaluestore* vs, const char* key, bool* created); //created may be NULL
void ffValuestoreDestroy(FFvaluestore* vs);
#endif