Skip to content

Commit e32987c

Browse files
committed
JsonConfig: make all non-module keys case-sensitive
1 parent fa4e11c commit e32987c

3 files changed

Lines changed: 47 additions & 56 deletions

File tree

src/options/display.c

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
1313
if (!object) return NULL;
1414
if (!yyjson_is_obj(object)) return "Property 'display' must be an object";
1515

16-
yyjson_val *key_, *val;
16+
yyjson_val *key, *val;
1717
size_t idx, max;
18-
yyjson_obj_foreach(object, idx, max, key_, val)
18+
yyjson_obj_foreach(object, idx, max, key, val)
1919
{
20-
const char* key = yyjson_get_str(key_);
21-
22-
if (ffStrEqualsIgnCase(key, "stat"))
20+
if (unsafe_yyjson_equals_str(key, "stat"))
2321
{
2422
if (yyjson_is_bool(val))
2523
{
@@ -39,21 +37,21 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
3937
else
4038
return "display.stat must be a boolean or a positive integer";
4139
}
42-
else if (ffStrEqualsIgnCase(key, "pipe"))
40+
else if (unsafe_yyjson_equals_str(key, "pipe"))
4341
options->pipe = yyjson_get_bool(val);
44-
else if (ffStrEqualsIgnCase(key, "showErrors"))
42+
else if (unsafe_yyjson_equals_str(key, "showErrors"))
4543
options->showErrors = yyjson_get_bool(val);
46-
else if (ffStrEqualsIgnCase(key, "disableLinewrap"))
44+
else if (unsafe_yyjson_equals_str(key, "disableLinewrap"))
4745
options->disableLinewrap = yyjson_get_bool(val);
48-
else if (ffStrEqualsIgnCase(key, "hideCursor"))
46+
else if (unsafe_yyjson_equals_str(key, "hideCursor"))
4947
options->hideCursor = yyjson_get_bool(val);
50-
else if (ffStrEqualsIgnCase(key, "separator"))
48+
else if (unsafe_yyjson_equals_str(key, "separator"))
5149
ffStrbufSetJsonVal(&options->keyValueSeparator, val);
52-
else if (ffStrEqualsIgnCase(key, "color"))
50+
else if (unsafe_yyjson_equals_str(key, "color"))
5351
{
5452
if (yyjson_is_str(val))
5553
{
56-
ffOptionParseColor(yyjson_get_str(val), &options->colorKeys);
54+
ffOptionParseColor(unsafe_yyjson_get_str(val), &options->colorKeys);
5755
ffStrbufSet(&options->colorTitle, &options->colorKeys);
5856
}
5957
else if (yyjson_is_obj(val))
@@ -74,9 +72,9 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
7472
else
7573
return "display.color must be either a string or an object";
7674
}
77-
else if (ffStrEqualsIgnCase(key, "brightColor"))
75+
else if (unsafe_yyjson_equals_str(key, "brightColor"))
7876
options->brightColor = yyjson_get_bool(val);
79-
else if (ffStrEqualsIgnCase(key, "duration"))
77+
else if (unsafe_yyjson_equals_str(key, "duration"))
8078
{
8179
if (!yyjson_is_obj(val))
8280
return "display.duration must be an object";
@@ -98,7 +96,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
9896
options->durationSpaceBeforeUnit = (FFSpaceBeforeUnitType) value;
9997
}
10098
}
101-
else if (ffStrEqualsIgnCase(key, "size"))
99+
else if (unsafe_yyjson_equals_str(key, "size"))
102100
{
103101
if (!yyjson_is_obj(val))
104102
return "display.size must be an object";
@@ -154,7 +152,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
154152
options->sizeSpaceBeforeUnit = (FFSpaceBeforeUnitType) value;
155153
}
156154
}
157-
else if (ffStrEqualsIgnCase(key, "temp"))
155+
else if (unsafe_yyjson_equals_str(key, "temp"))
158156
{
159157
if (!yyjson_is_obj(val))
160158
return "display.temp must be an object";
@@ -211,7 +209,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
211209
options->tempSpaceBeforeUnit = (FFSpaceBeforeUnitType) value;
212210
}
213211
}
214-
else if (ffStrEqualsIgnCase(key, "percent"))
212+
else if (unsafe_yyjson_equals_str(key, "percent"))
215213
{
216214
if (!yyjson_is_obj(val))
217215
return "display.percent must be an object";
@@ -259,7 +257,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
259257
yyjson_val* width = yyjson_obj_get(val, "width");
260258
if (width) options->percentWidth = (uint8_t) yyjson_get_uint(width);
261259
}
262-
else if (ffStrEqualsIgnCase(key, "bar"))
260+
else if (unsafe_yyjson_equals_str(key, "bar"))
263261
{
264262
if (yyjson_is_obj(val))
265263
{
@@ -369,7 +367,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
369367
else
370368
return "display.bar must be an object";
371369
}
372-
else if (ffStrEqualsIgnCase(key, "fraction"))
370+
else if (unsafe_yyjson_equals_str(key, "fraction"))
373371
{
374372
if (yyjson_is_obj(val))
375373
{
@@ -386,11 +384,9 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
386384
else
387385
return "display.fraction must be an object";
388386
}
389-
else if (ffStrEqualsIgnCase(key, "noBuffer"))
387+
else if (unsafe_yyjson_equals_str(key, "noBuffer"))
390388
options->noBuffer = yyjson_get_bool(val);
391-
else if (ffStrEqualsIgnCase(key, "keyWidth"))
392-
return "display.keyWidth has been renamed to display.key.width";
393-
else if (ffStrEqualsIgnCase(key, "key"))
389+
else if (unsafe_yyjson_equals_str(key, "key"))
394390
{
395391
if (yyjson_is_obj(val))
396392
{
@@ -420,7 +416,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
420416
else
421417
return "display.key must be an object";
422418
}
423-
else if (ffStrEqualsIgnCase(key, "constants"))
419+
else if (unsafe_yyjson_equals_str(key, "constants"))
424420
{
425421
if (!yyjson_is_arr(val))
426422
return "display.constants must be an array";
@@ -429,7 +425,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
429425
yyjson_arr_foreach(val, idx, max, item)
430426
ffStrbufInitJsonVal(ffListAdd(&options->constants), item);
431427
}
432-
else if (ffStrEqualsIgnCase(key, "freq"))
428+
else if (unsafe_yyjson_equals_str(key, "freq"))
433429
{
434430
if (!yyjson_is_obj(val))
435431
return "display.freq must be an object";

src/options/general.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,28 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va
1212
if (!object) return NULL;
1313
if (!yyjson_is_obj(object)) return "Property 'general' must be an object";
1414

15-
yyjson_val *key_, *val;
15+
yyjson_val *key, *val;
1616
size_t idx, max;
17-
yyjson_obj_foreach(object, idx, max, key_, val)
17+
yyjson_obj_foreach(object, idx, max, key, val)
1818
{
19-
const char* key = yyjson_get_str(key_);
20-
21-
if (ffStrEqualsIgnCase(key, "thread"))
19+
if (unsafe_yyjson_equals_str(key, "thread"))
2220
options->multithreading = yyjson_get_bool(val);
23-
else if (ffStrEqualsIgnCase(key, "processingTimeout"))
21+
else if (unsafe_yyjson_equals_str(key, "processingTimeout"))
2422
options->processingTimeout = (int32_t) yyjson_get_int(val);
25-
else if (ffStrEqualsIgnCase(key, "preRun"))
23+
else if (unsafe_yyjson_equals_str(key, "preRun"))
2624
{
2725
if (!yyjson_is_str(val))
2826
return "general.preRun must be a string";
2927
if (system(unsafe_yyjson_get_str(val)) < 0)
3028
return "Failed to execute preRun command";
3129
}
32-
else if (ffStrEqualsIgnCase(key, "detectVersion"))
30+
else if (unsafe_yyjson_equals_str(key, "detectVersion"))
3331
options->detectVersion = yyjson_get_bool(val);
3432

3533
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__)
36-
else if (ffStrEqualsIgnCase(key, "playerName"))
34+
else if (unsafe_yyjson_equals_str(key, "playerName"))
3735
ffStrbufSetJsonVal(&options->playerName, val);
38-
else if (ffStrEqualsIgnCase(key, "dsForceDrm"))
36+
else if (unsafe_yyjson_equals_str(key, "dsForceDrm"))
3937
{
4038
if (yyjson_is_str(val))
4139
{
@@ -127,6 +125,8 @@ void ffOptionsGenerateGeneralJsonConfig(FFOptionsGeneral* options, yyjson_mut_do
127125

128126
yyjson_mut_obj_add_int(doc, obj, "processingTimeout", options->processingTimeout);
129127

128+
yyjson_mut_obj_add_bool(doc, obj, "detectVersion", options->detectVersion);
129+
130130
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__)
131131

132132
yyjson_mut_obj_add_strbuf(doc, obj, "playerName", &options->playerName);

src/options/logo.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,11 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
269269

270270
if (!yyjson_is_obj(object)) return "Property 'logo' must be an object";
271271

272-
yyjson_val *key_, *val;
272+
yyjson_val *key, *val;
273273
size_t idx, max;
274-
yyjson_obj_foreach(object, idx, max, key_, val)
274+
yyjson_obj_foreach(object, idx, max, key, val)
275275
{
276-
const char* key = yyjson_get_str(key_);
277-
278-
if (ffStrEqualsIgnCase(key, "type"))
276+
if (unsafe_yyjson_equals_str(key, "type"))
279277
{
280278
int value;
281279
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
@@ -302,30 +300,29 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
302300
options->type = (FFLogoType) value;
303301
continue;
304302
}
305-
else if (ffStrEqualsIgnCase(key, "source"))
303+
else if (unsafe_yyjson_equals_str(key, "source"))
306304
{
307305
ffStrbufSetJsonVal(&options->source, val);
308306
continue;
309307
}
310-
else if (ffStrEqualsIgnCase(key, "color"))
308+
else if (unsafe_yyjson_equals_str(key, "color"))
311309
{
312310
if (!yyjson_is_obj(val))
313311
return "Property 'color' must be an object";
314312

315-
yyjson_val *key_c, *valc;
313+
yyjson_val *keyc, *valc;
316314
size_t idxc, maxc;
317-
yyjson_obj_foreach(val, idxc, maxc, key_c, valc)
315+
yyjson_obj_foreach(val, idxc, maxc, keyc, valc)
318316
{
319-
const char* keyc = yyjson_get_str(key_c);
320-
uint32_t index = (uint32_t) strtoul(keyc, NULL, 10);
317+
uint32_t index = (uint32_t) strtoul(unsafe_yyjson_get_str(keyc), NULL, 10);
321318
if (index < 1 || index > FASTFETCH_LOGO_MAX_COLORS)
322319
return "Keys of property 'color' must be a number between 1 to 9";
323320

324321
ffOptionParseColor(yyjson_get_str(valc), &options->colors[index - 1]);
325322
}
326323
continue;
327324
}
328-
else if (ffStrEqualsIgnCase(key, "width"))
325+
else if (unsafe_yyjson_equals_str(key, "width"))
329326
{
330327
if (yyjson_is_null(val))
331328
options->width = 0;
@@ -338,7 +335,7 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
338335
}
339336
continue;
340337
}
341-
else if (ffStrEqualsIgnCase(key, "height"))
338+
else if (unsafe_yyjson_equals_str(key, "height"))
342339
{
343340
if (yyjson_is_null(val))
344341
options->height = 0;
@@ -351,7 +348,7 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
351348
}
352349
continue;
353350
}
354-
else if (ffStrEqualsIgnCase(key, "padding"))
351+
else if (unsafe_yyjson_equals_str(key, "padding"))
355352
{
356353
if (!yyjson_is_obj(val))
357354
return "Logo padding must be an object";
@@ -370,24 +367,22 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
370367
#undef FF_PARSE_PADDING_POSITON
371368
continue;
372369
}
373-
else if (ffStrEqualsIgnCase(key, "printRemaining"))
370+
else if (unsafe_yyjson_equals_str(key, "printRemaining"))
374371
{
375372
options->printRemaining = yyjson_get_bool(val);
376373
continue;
377374
}
378-
else if (ffStrEqualsIgnCase(key, "preserveAspectRatio"))
375+
else if (unsafe_yyjson_equals_str(key, "preserveAspectRatio"))
379376
{
380377
options->preserveAspectRatio = yyjson_get_bool(val);
381378
continue;
382379
}
383-
else if (ffStrEqualsIgnCase(key, "recache"))
380+
else if (unsafe_yyjson_equals_str(key, "recache"))
384381
{
385382
options->recache = yyjson_get_bool(val);
386383
continue;
387384
}
388-
else if(ffStrEqualsIgnCase(key, "separate"))
389-
return "logo.separate has been renamed to logo.position\n";
390-
else if (ffStrEqualsIgnCase(key, "position"))
385+
else if (unsafe_yyjson_equals_str(key, "position"))
391386
{
392387
int value;
393388
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
@@ -401,7 +396,7 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
401396
options->position = (FFLogoPosition) value;
402397
continue;
403398
}
404-
else if (ffStrEqualsIgnCase(key, "chafa"))
399+
else if (unsafe_yyjson_equals_str(key, "chafa"))
405400
{
406401
if (!yyjson_is_obj(val))
407402
return "Chafa config must be an object";

0 commit comments

Comments
 (0)