@@ -101,16 +101,6 @@ const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair p
101
101
return "Invalid enum value type; must be a string or integer" ;
102
102
}
103
103
104
- static inline void genJsonResult (FFModuleBaseInfo * baseInfo , void * options , yyjson_mut_doc * doc )
105
- {
106
- yyjson_mut_val * module = yyjson_mut_arr_add_obj (doc , doc -> root );
107
- yyjson_mut_obj_add_str (doc , module , "type" , baseInfo -> name );
108
- if (baseInfo -> generateJsonResult )
109
- baseInfo -> generateJsonResult (options , doc , module );
110
- else
111
- yyjson_mut_obj_add_str (doc , module , "error" , "Unsupported for JSON format" );
112
- }
113
-
114
104
static bool parseModuleJsonObject (const char * type , yyjson_val * jsonVal , yyjson_mut_doc * jsonDoc )
115
105
{
116
106
if (!ffCharIsEnglishAlphabet (type [0 ])) return false;
@@ -123,14 +113,39 @@ static bool parseModuleJsonObject(const char* type, yyjson_val* jsonVal, yyjson_
123
113
uint8_t optionBuf [FF_OPTION_MAX_SIZE ];
124
114
baseInfo -> initOptions (optionBuf );
125
115
if (jsonVal ) baseInfo -> parseJsonObject (optionBuf , jsonVal );
126
- if (__builtin_expect (jsonDoc != NULL , false))
127
- genJsonResult (baseInfo , optionBuf , jsonDoc );
116
+ bool succeeded ;
117
+ if (jsonDoc )
118
+ {
119
+ yyjson_mut_val * module = yyjson_mut_arr_add_obj (jsonDoc , jsonDoc -> root );
120
+ yyjson_mut_obj_add_str (jsonDoc , module , "type" , baseInfo -> name );
121
+ if (baseInfo -> generateJsonResult )
122
+ succeeded = baseInfo -> generateJsonResult (optionBuf , jsonDoc , module );
123
+ else
124
+ {
125
+ yyjson_mut_obj_add_str (jsonDoc , module , "error" , "Unsupported for JSON format" );
126
+ succeeded = false;
127
+ }
128
+ }
128
129
else
129
- baseInfo -> printModule (optionBuf );
130
+ succeeded = baseInfo -> printModule (optionBuf );
130
131
baseInfo -> destroyOptions (optionBuf );
131
- return true ;
132
+ return succeeded ;
132
133
}
133
134
}
135
+
136
+ if (jsonDoc )
137
+ {
138
+ yyjson_mut_val * module = yyjson_mut_arr_add_obj (jsonDoc , jsonDoc -> root );
139
+ yyjson_mut_obj_add_strcpy (jsonDoc , module , "type" , type );
140
+ yyjson_mut_obj_add_str (jsonDoc , module , "error" , "Unknown module type" );
141
+ }
142
+ else
143
+ {
144
+ FFModuleArgs moduleArgs ;
145
+ ffOptionInitModuleArg (& moduleArgs , "" );
146
+ ffPrintError (type , 0 , & moduleArgs , FF_PRINT_TYPE_DEFAULT , "Unknown module type" );
147
+ ffOptionDestroyModuleArg (& moduleArgs );
148
+ }
134
149
return false;
135
150
}
136
151
@@ -217,6 +232,7 @@ static const char* printJsonConfig(bool prepare, yyjson_mut_doc* jsonDoc)
217
232
if (!modules ) return NULL ;
218
233
if (!yyjson_is_arr (modules )) return "Property 'modules' must be an array of strings or objects" ;
219
234
235
+ bool succeeded = true;
220
236
int32_t thres = instance .config .display .stat ;
221
237
yyjson_val * item ;
222
238
size_t idx , max ;
@@ -253,6 +269,15 @@ static const char* printJsonConfig(bool prepare, yyjson_mut_doc* jsonDoc)
253
269
arch = yyjson_obj_get (conditions , "!arch" );
254
270
if (arch && matchesJsonArray (ffVersionResult .architecture , arch ))
255
271
continue ;
272
+
273
+ yyjson_val * previousSucceeded = yyjson_obj_get (conditions , "succeeded" );
274
+ if (previousSucceeded && !unsafe_yyjson_is_null (previousSucceeded ))
275
+ {
276
+ if (!unsafe_yyjson_is_bool (previousSucceeded ))
277
+ return "Property 'succeeded' in 'condition' must be a boolean" ;
278
+ if (succeeded != unsafe_yyjson_get_bool (previousSucceeded ))
279
+ continue ;
280
+ }
256
281
}
257
282
258
283
type = yyjson_get_str (yyjson_obj_get (module , "type" ));
@@ -265,8 +290,8 @@ static const char* printJsonConfig(bool prepare, yyjson_mut_doc* jsonDoc)
265
290
266
291
if (prepare )
267
292
prepareModuleJsonObject (type , module );
268
- else if (! parseModuleJsonObject ( type , module , jsonDoc ))
269
- return "Unknown module type" ;
293
+ else
294
+ succeeded = parseModuleJsonObject ( type , module , jsonDoc ) ;
270
295
271
296
if (!prepare && thres >= 0 )
272
297
{
0 commit comments