@@ -374,13 +374,13 @@ static void listModules(bool pretty)
374
374
}
375
375
}
376
376
377
- static bool parseJsoncFile (const char * path )
377
+ static bool parseJsoncFile (const char * path , bool strictJson )
378
378
{
379
379
assert (!instance .state .configDoc );
380
380
381
381
{
382
382
yyjson_read_err error ;
383
- instance .state .configDoc = yyjson_read_file (path , YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS , NULL , & error );
383
+ instance .state .configDoc = yyjson_read_file (path , strictJson ? 0 : YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS , NULL , & error );
384
384
if (!instance .state .configDoc )
385
385
{
386
386
if (error .code != YYJSON_READ_ERROR_FILE_OPEN )
@@ -452,57 +452,52 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
452
452
fprintf (stderr , "Error: usage: %s <config>\n" , key );
453
453
exit (413 );
454
454
}
455
- uint32_t fileNameLen = (uint32_t ) strlen (value );
456
- if (fileNameLen == 0 )
457
- {
458
- fprintf (stderr , "Error: usage: %s <config>\n" , key );
459
- exit (413 );
460
- }
461
455
462
- if (ffStrEqualsIgnCase (value , "none" ))
456
+ if (value [ 0 ] == '\0' || ffStrEqualsIgnCase (value , "none" ))
463
457
return ;
464
458
465
- if (ffStrEndsWithIgnCase (value , ".conf" ))
466
- {
467
- fprintf (stderr , "Error: flag based config files are no longer not supported: %s\n" , value );
468
- exit (414 );
469
- }
470
-
471
459
//Try to load as an absolute path
472
460
473
- if (parseJsoncFile (value )) return ;
461
+ FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateS (value );
462
+ bool strictJson = ffStrbufEndsWithIgnCaseS (& absolutePath , ".json" );
463
+ bool needExtension = !strictJson && !ffStrbufEndsWithIgnCaseS (& absolutePath , ".jsonc" );
464
+ if (needExtension )
465
+ ffStrbufAppendS (& absolutePath , ".jsonc" );
474
466
475
- FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA ( 128 ) ;
467
+ if ( parseJsoncFile ( absolutePath . chars , strictJson )) return ;
476
468
477
- //Try to load as a relative path with the directory of fastfetch binary
478
- if (instance .state .platform .exePath .length )
469
+ if (!ffStrbufContainC (& absolutePath , '/' )
470
+ #ifdef _WIN32
471
+ && !ffStrbufContainC (& absolutePath , '\\' )
472
+ #endif
473
+ )
479
474
{
480
- ffStrbufSet (& absolutePath , & instance .state .platform .exePath );
481
- ffStrbufSubstrBeforeLastC (& absolutePath , '/' );
482
- ffStrbufAppendS (& absolutePath , "/" );
483
- ffStrbufAppendS (& absolutePath , value );
475
+ //Try to load as a relative path
484
476
485
- if (parseJsoncFile (absolutePath .chars )) return ;
486
- ffStrbufClear (& absolutePath );
487
- }
477
+ FF_LIST_FOR_EACH (FFstrbuf , path , instance .state .platform .dataDirs )
478
+ {
479
+ ffStrbufSet (& absolutePath , path );
480
+ ffStrbufAppendS (& absolutePath , "fastfetch/presets/" );
481
+ ffStrbufAppendS (& absolutePath , value );
482
+ if (needExtension )
483
+ ffStrbufAppendS (& absolutePath , ".jsonc" );
488
484
489
- //Try to load as a relative path
485
+ if (parseJsoncFile (absolutePath .chars , strictJson )) return ;
486
+ }
490
487
491
- FF_LIST_FOR_EACH (FFstrbuf , path , instance .state .platform .dataDirs )
492
- {
493
- //We need to copy it, because if a config file loads a config file, the value of path must be unchanged
494
- ffStrbufSet (& absolutePath , path );
495
- ffStrbufAppendS (& absolutePath , "fastfetch/presets/" );
496
- ffStrbufAppendS (& absolutePath , value );
488
+ //Try to load as a relative path with the directory of fastfetch binary
497
489
498
- bool success = parseJsoncFile (absolutePath .chars );
499
- if (!success )
490
+ if (instance .state .platform .exePath .length )
500
491
{
501
- ffStrbufAppendS (& absolutePath , ".jsonc" );
502
- success = parseJsoncFile (absolutePath .chars );
492
+ ffStrbufSet (& absolutePath , & instance .state .platform .exePath );
493
+ ffStrbufSubstrBeforeLastC (& absolutePath , '/' );
494
+ ffStrbufAppendS (& absolutePath , "/" );
495
+ ffStrbufAppendS (& absolutePath , value );
496
+ if (needExtension )
497
+ ffStrbufAppendS (& absolutePath , ".jsonc" );
498
+
499
+ if (parseJsoncFile (absolutePath .chars , strictJson )) return ;
503
500
}
504
-
505
- if (success ) return ;
506
501
}
507
502
508
503
//File not found
@@ -665,7 +660,7 @@ static void parseConfigFiles(void)
665
660
uint32_t dirLength = dir -> length ;
666
661
667
662
ffStrbufAppendS (dir , "fastfetch/config.jsonc" );
668
- bool success = parseJsoncFile (dir -> chars );
663
+ bool success = parseJsoncFile (dir -> chars , false );
669
664
ffStrbufSubstrBefore (dir , dirLength );
670
665
if (success ) return ;
671
666
}
0 commit comments