@@ -376,13 +376,12 @@ static void listModules(bool pretty)
376
376
}
377
377
}
378
378
379
- static bool parseJsoncFile (const char * path , bool strictJson )
379
+ static bool parseJsoncFile (const char * path , yyjson_read_flag flg )
380
380
{
381
381
assert (!instance .state .configDoc );
382
382
383
383
{
384
384
yyjson_read_err error ;
385
- yyjson_read_flag flg = strictJson ? 0 : YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS ;
386
385
instance .state .configDoc = path
387
386
? yyjson_read_file (path , flg , NULL , & error )
388
387
: yyjson_read_fp (stdin , flg , NULL , & error );
@@ -480,11 +479,19 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
480
479
481
480
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateS (value );
482
481
bool strictJson = ffStrbufEndsWithIgnCaseS (& absolutePath , ".json" );
483
- bool needExtension = !strictJson && !ffStrbufEndsWithIgnCaseS (& absolutePath , ".jsonc" );
482
+ bool jsonc = !strictJson && ffStrbufEndsWithIgnCaseS (& absolutePath , ".jsonc" );
483
+ bool json5 = !strictJson && !jsonc && ffStrbufEndsWithIgnCaseS (& absolutePath , ".json5" );
484
+ bool needExtension = !strictJson && !jsonc && !json5 ;
484
485
if (needExtension )
485
486
ffStrbufAppendS (& absolutePath , ".jsonc" );
486
487
487
- if (parseJsoncFile (absolutePath .chars , strictJson )) return ;
488
+ yyjson_read_flag flag = strictJson
489
+ ? 0
490
+ : jsonc
491
+ ? YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS
492
+ : YYJSON_READ_JSON5 ;
493
+
494
+ if (parseJsoncFile (absolutePath .chars , flag )) return ;
488
495
489
496
//Try to load as a relative path
490
497
@@ -496,7 +503,7 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
496
503
if (needExtension )
497
504
ffStrbufAppendS (& absolutePath , ".jsonc" );
498
505
499
- if (parseJsoncFile (absolutePath .chars , strictJson )) return ;
506
+ if (parseJsoncFile (absolutePath .chars , flag )) return ;
500
507
}
501
508
502
509
//Try to load as a relative path with the directory of fastfetch binary
@@ -511,15 +518,15 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
511
518
ffStrbufAppendS (& absolutePath , value );
512
519
if (needExtension )
513
520
ffStrbufAppendS (& absolutePath , ".jsonc" );
514
- if (parseJsoncFile (absolutePath .chars , strictJson )) return ;
521
+ if (parseJsoncFile (absolutePath .chars , flag )) return ;
515
522
516
523
// Try {exePath}/presets/
517
524
ffStrbufSubstrBefore (& absolutePath , lastSlash );
518
525
ffStrbufAppendS (& absolutePath , "presets/" );
519
526
ffStrbufAppendS (& absolutePath , value );
520
527
if (needExtension )
521
528
ffStrbufAppendS (& absolutePath , ".jsonc" );
522
- if (parseJsoncFile (absolutePath .chars , strictJson )) return ;
529
+ if (parseJsoncFile (absolutePath .chars , flag )) return ;
523
530
}
524
531
525
532
//File not found
@@ -685,7 +692,12 @@ static void parseConfigFiles(void)
685
692
uint32_t dirLength = dir -> length ;
686
693
687
694
ffStrbufAppendS (dir , "fastfetch/config.jsonc" );
688
- bool success = parseJsoncFile (dir -> chars , false);
695
+ bool success = parseJsoncFile (dir -> chars , YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS );
696
+ ffStrbufSubstrBefore (dir , dirLength );
697
+ if (success ) return ;
698
+
699
+ ffStrbufAppendS (dir , "fastfetch/config.json5" );
700
+ success = parseJsoncFile (dir -> chars , YYJSON_READ_JSON5 );
689
701
ffStrbufSubstrBefore (dir , dirLength );
690
702
if (success ) return ;
691
703
}
0 commit comments