mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-10 07:00:08 +01:00
structure and values can be set in fastfetch via command line and file!
This commit is contained in:
1 parent
4dffbb0bb7
commit
db6d2eb3a3
21 files changed
+398
-329
No files matched your search
@@ -0,0 +1,59 @@
|
||||
#include <stdint.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "FFvaluestore.h"
|
||||
|
||||
void ffValuestoreInit(FFvaluestore* vs)
|
||||
{
|
||||
vs->capacity = 32;
|
||||
vs->pairs = calloc(vs->capacity, sizeof(FFvaluestorePair));
|
||||
vs->size = 0;
|
||||
}
|
||||
|
||||
void ffValuestoreSet(FFvaluestore* vs, const char* name, const char* value)
|
||||
{
|
||||
for(uint32_t i = 0; i < vs->size; i++)
|
||||
{
|
||||
if(strcasecmp(vs->pairs[i].name, name) == 0)
|
||||
{
|
||||
strcpy(vs->pairs[i].value, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(vs->size == vs->capacity)
|
||||
{
|
||||
FFvaluestorePair* pairs = (FFvaluestorePair*) calloc(vs->capacity * 2, sizeof(FFvaluestorePair));
|
||||
memcpy(pairs, vs->pairs, sizeof(FFvaluestorePair) * vs->size);
|
||||
free(vs->pairs);
|
||||
vs->pairs = pairs;
|
||||
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;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool ffValuestoreContains(FFvaluestore* vs, const char* name)
|
||||
{
|
||||
return ffValuestoreGet(vs, name) != NULL;
|
||||
}
|
||||
|
||||
void ffValuestoreDelete(FFvaluestore* vs)
|
||||
{
|
||||
free(vs->pairs);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef FASTFETCH_INCLUDED_FFVALUESTORE
|
||||
#define FASTFETCH_INCLUDED_FFVALUESTORE
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct FFvaluestorePair
|
||||
{
|
||||
char name[32];
|
||||
char value[1024];
|
||||
} FFvaluestorePair;
|
||||
|
||||
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);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user