@@ -48,7 +48,7 @@ static char *find_target(char **);
4848static bool parse (char * * input_cursor , struct parse_result * result );
4949
5050static char * call_action (struct ui_ctx * ctx , const struct command * c ,
51- const struct action_container * , size_t len , bool fail_loud );
51+ const struct action_container * , size_t len , bool * found );
5252
5353static char * run (struct ui_ctx * , const struct command * );
5454
@@ -244,10 +244,12 @@ static bool parse(char **input_cursor, struct parse_result *result)
244244}
245245
246246static char * call_action (struct ui_ctx * ctx , const struct command * c ,
247- const struct action_container * candidates , size_t len , bool fail_loud )
247+ const struct action_container * candidates , size_t len , bool * found )
248248{
249249 for (size_t i = 0 ; i < len ; i ++ ) {
250250 if (strcmp (c -> action , candidates [i ].name ) == 0 ) {
251+ * found = true;
252+
251253 char * err_buf = candidates [i ].hook (
252254 ctx , c -> target_name , c -> argc , c -> argv );
253255
@@ -258,25 +260,27 @@ static char *call_action(struct ui_ctx *ctx, const struct command *c,
258260 }
259261 }
260262
261- if (fail_loud ) {
262- char * ret = malloc (512 );
263- snprintf (ret , 512 , "no such action found: %s" , c -> action );
264- return ret ;
265- } else
266- return NULL ;
263+ * found = false;
264+
265+ char * ret = malloc (512 );
266+ snprintf (ret , 512 , "no such action found: %s" , c -> action );
267+ return ret ;
267268}
268269
269270static char * run (struct ui_ctx * ctx , const struct command * c )
270271{
271272 char * ret = NULL ;
273+ bool found ;
274+
272275 if (strcmp (c -> target_name , "root" ) == 0 ) {
273- if ((ret = call_action (ctx , c , root_actions ,
274- sizeof (root_actions ) / sizeof (* root_actions ), false)))
275- return ret ;
276+ char * root_ret = call_action (ctx , c , root_actions ,
277+ sizeof (root_actions ) / sizeof (* root_actions ), & found );
278+ if (found )
279+ return root_ret ;
276280 }
277281
278282 ret = call_action (
279- ctx , c , actions , sizeof (actions ) / sizeof (* actions ), true );
283+ ctx , c , actions , sizeof (actions ) / sizeof (* actions ), & found );
280284 return ret ;
281285}
282286
0 commit comments