88#include <dirent.h>
99#include <sys/stat.h>
1010
11+ typedef struct CustomValue
12+ {
13+ bool printKey ;
14+ FFstrbuf value ;
15+ } CustomValue ;
16+
1117// Things only needed by fastfetch
1218typedef struct FFdata
1319{
14- FFvaluestore customWithKey ; //Prints with key
15- FFvaluestore customKeyless ; //Prints without
20+ FFvaluestore customValues ;
1621 FFstrbuf structure ;
1722 bool loadUserConfig ;
1823} FFdata ;
@@ -670,7 +675,7 @@ static uint32_t optionParseUInt32(const char* key, const char* value)
670675 return num ;
671676}
672677
673- static void optionParseCustom ( const char * key , const char * value , FFvaluestore * valuestore )
678+ static void optionParseCustomValue ( FFdata * data , const char * key , const char * value , bool printKey )
674679{
675680 if (value == NULL )
676681 {
@@ -688,7 +693,12 @@ static void optionParseCustom(const char* key, const char* value, FFvaluestore*
688693
689694 * separator = '\0' ;
690695
691- ffValuestoreSet (valuestore , value , separator + 1 );
696+ bool created ;
697+ CustomValue * customValue = ffValuestoreSet (& data -> customValues , value , & created );
698+ if (created )
699+ ffStrbufInit (& customValue -> value );
700+ ffStrbufSetS (& customValue -> value , separator + 1 );
701+ customValue -> printKey = printKey ;
692702}
693703
694704static void parseOption (FFinstance * instance , FFdata * data , const char * key , const char * value )
@@ -902,9 +912,9 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
902912 else if (strcasecmp (key , "-c" ) == 0 || strcasecmp (key , "--color" ) == 0 )
903913 optionParseColor (key , value , & instance -> config .mainColor );
904914 else if (strcasecmp (key , "--set" ) == 0 )
905- optionParseCustom ( key , value , & data -> customWithKey );
915+ optionParseCustomValue ( data , key , value , true );
906916 else if (strcasecmp (key , "--set-keyless" ) == 0 )
907- optionParseCustom ( key , value , & data -> customKeyless );
917+ optionParseCustomValue ( data , key , value , false );
908918
909919 ////////////////////////////////
910920 //Format + Key + Error options//
@@ -1286,17 +1296,10 @@ static void parseArguments(FFinstance* instance, FFdata* data, int argc, const c
12861296
12871297static void parseStructureCommand (FFinstance * instance , FFdata * data , const char * line )
12881298{
1289- const char * setValue = ffValuestoreGet (& data -> customWithKey , line );
1290- if (setValue != NULL )
1291- {
1292- ffPrintCustom (instance , line , setValue );
1293- return ;
1294- }
1295-
1296- setValue = ffValuestoreGet (& data -> customKeyless , line );
1297- if (setValue != NULL )
1299+ CustomValue * customValue = ffValuestoreGet (& data -> customValues , line );
1300+ if (customValue != NULL )
12981301 {
1299- ffPrintCustom (instance , NULL , setValue );
1302+ ffPrintCustom (instance , customValue -> printKey ? line : NULL , customValue -> value . chars );
13001303 return ;
13011304 }
13021305
@@ -1387,8 +1390,7 @@ int main(int argc, const char** argv)
13871390
13881391 //Data stores things only needed for the configuration of fastfetch
13891392 FFdata data ;
1390- ffValuestoreInit (& data .customWithKey );
1391- ffValuestoreInit (& data .customKeyless );
1393+ ffValuestoreInit (& data .customValues , sizeof (CustomValue ));
13921394 ffStrbufInitA (& data .structure , 256 );
13931395 data .loadUserConfig = true;
13941396
0 commit comments