Adjust to cligen 4.5 update

This commit is contained in:
Olof hagsand 2020-04-01 09:56:50 +02:00
parent 5535239363
commit 6e2cb1b97d
7 changed files with 70 additions and 62 deletions

View file

@ -20,6 +20,13 @@
* [3.3.2](#332) Aug 27 2017
* [3.3.1](#331) June 7 2017
## 4.5.0
### C-API changes on existing features (you may need to change your plugin C-code)
* `clicon_parse()`: Changed signature due to new cligen error and result handling:
* Removed: `cli_nomatch()`
## 4.4.0
Expected: March 2020

View file

@ -2,7 +2,9 @@
*
***** BEGIN LICENSE BLOCK *****
Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
Copyright (C) 2017-2019 Olof Hagsand
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC
This file is part of CLIXON.
@ -191,14 +193,6 @@ cli_interrupt_hook(clicon_handle h,
return cligen_interrupt_hook(ch, fn);
}
char *
cli_nomatch(clicon_handle h)
{
cligen_handle ch = cligen(h);
return cligen_nomatch(ch);
}
int
cli_prompt_set(clicon_handle h,
char *prompt)

View file

@ -2,7 +2,9 @@
*
***** BEGIN LICENSE BLOCK *****
Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
Copyright (C) 2017-2019 Olof Hagsand
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC
This file is part of CLIXON.
@ -51,8 +53,6 @@ int cli_susp_hook(clicon_handle h, cligen_susp_cb_t *fn);
int cli_interrupt_hook(clicon_handle h, cligen_interrupt_cb_t *fn);
char *cli_nomatch(clicon_handle h);
int cli_prompt_set(clicon_handle h, char *prompt);
int cli_logsyntax_set(clicon_handle h, int status);

View file

@ -212,11 +212,10 @@ cli_signal_init (clicon_handle h)
static int
cli_interactive(clicon_handle h)
{
int retval = -1;
int res;
char *cmd;
char *new_mode;
int eval;
int retval = -1;
char *cmd;
char *new_mode;
cligen_result result;
/* Loop through all commands */
while(!cligen_exiting(cli_cligen(h))) {
@ -225,8 +224,9 @@ cli_interactive(clicon_handle h)
cligen_exiting_set(cli_cligen(h), 1); /* EOF */
goto ok; /* EOF should not be -1 error? */
}
if ((res = clicon_parse(h, cmd, &new_mode, &eval)) < 0)
if (clicon_parse(h, cmd, &new_mode, &result, NULL) < 0)
goto done;
/* Why not check result? */
}
ok:
retval = 0;
@ -587,8 +587,10 @@ main(int argc, char **argv)
/* Join rest of argv to a single command */
restarg = clicon_strjoin(argc, argv, " ");
#if 0 /* Unsure for why this is enabled by default, turned off in clixon 4.5? */
/* If several cligen object variables match same preference, select first */
cligen_preference_mode_set(cli_cligen(h), 1);
#endif
/* Call start function in all plugins before we go interactive
*/
@ -603,13 +605,15 @@ main(int argc, char **argv)
cligen_utf8_set(cli_cligen(h), clicon_option_int(h,"CLICON_CLI_UTF8"));
/* Launch interfactive event loop, unless -1 */
if (restarg != NULL && strlen(restarg)){
char *mode = cli_syntax_mode(h);
int result;
char *mode = cli_syntax_mode(h);
cligen_result result; /* match result */
int evalresult = 0; /* if result == 1, calback result */
/* */
if (clicon_parse(h, restarg, &mode, &result) != 1)
if (clicon_parse(h, restarg, &mode, &result, &evalresult) < 0)
goto done;
if (result < 0)
if (result != 1) /* Not unique match */
goto done;
if (evalresult < 0)
goto done;
}

View file

@ -2,7 +2,9 @@
*
***** BEGIN LICENSE BLOCK *****
Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
Copyright (C) 2017-2019 Olof Hagsand
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC
This file is part of CLIXON.
@ -465,10 +467,10 @@ cli_handler_err(FILE *f)
}
/*! Evaluate a matched command
* @param[in] h Clicon handle
* @param[in] cmd The command string
* @retval int If there is a callback, the return value of the callback is returned,
* @retval 0 otherwise
* @param[in] h Clicon handle
* @param[in] cmd The command string
* @retval int If there is a callback, the return value of the callback is returned,
* @retval 0 otherwise
*/
int
clicon_eval(clicon_handle h,
@ -501,35 +503,32 @@ clicon_eval(clicon_handle h,
* match is found in another mode, the mode variable is updated to point at
* the new mode string.
*
* @param[in] h Clicon handle
* @param[in] cmd Command string
* @param[in,out] modenamep Pointer to the mode string pointer
* @param[out] evalres Evaluation result if retval=1
* -2 On eof (shouldnt happen)
* -1 On parse error
* >=0 Number of matches
* @retval -2 Eof CG_EOF
* @retval -1 Error CG_ERROR
* @retval 0 No match CG_NOMATCH
* @retval 1 Exactly one match CG_MATCH
* @retval 2+ Multiple matches
* @param[in] h Clicon handle
* @param[in] cmd Command string
* @param[in,out] modenamep Pointer to the mode string pointer
* @param[out] result CLIgen match result, < 0: errors, >=0 number of matches
* @param[out] evalres Evaluation result if result=1
* @retval 0 OK
* @retval -1 Error
*/
int
clicon_parse(clicon_handle h,
char *cmd,
char **modenamep,
int *evalres)
clicon_parse(clicon_handle h,
char *cmd,
char **modenamep,
cligen_result *result,
int *evalres)
{
int retval = -1;
char *modename;
char *modename0;
int r;
int retval = -1;
char *modename;
char *modename0;
int r;
cli_syntax_t *stx = NULL;
cli_syntaxmode_t *smode;
parse_tree *pt; /* Orig */
cg_obj *match_obj;
cvec *cvv = NULL;
FILE *f;
parse_tree *pt; /* Orig */
cg_obj *match_obj;
cvec *cvv = NULL;
FILE *f;
char *reason = NULL;
if (clicon_get_logflags()&CLICON_LOG_STDOUT)
f = stdout;
@ -562,22 +561,21 @@ clicon_parse(clicon_handle h,
clicon_err(OE_UNIX, errno, "cvec_new");
goto done;;
}
retval = cliread_parse(cli_cligen(h), cmd, pt, &match_obj, cvv);
if (retval != CG_MATCH)
if (cliread_parse(cli_cligen(h), cmd, pt, &match_obj, cvv, result, &reason) < 0)
goto done;
if (*result != CG_MATCH)
pt_expand_cleanup_1(pt); /* XXX change to pt_expand_treeref_cleanup */
if (modename0){
cligen_tree_active_set(cli_cligen(h), modename0);
modename0 = NULL;
}
switch (retval) {
switch (*result) {
case CG_EOF: /* eof */
case CG_ERROR:
fprintf(f, "CLI parse error: %s\n", cmd);
break;
case CG_NOMATCH: /* no match */
/* clicon_err(OE_CFG, 0, "CLI syntax error: \"%s\": %s",
cmd, cli_nomatch(h));*/
fprintf(f, "CLI syntax error: \"%s\": %s\n", cmd, cli_nomatch(h));
fprintf(f, "CLI syntax error: \"%s\": %s\n", cmd, reason);
break;
case CG_MATCH:
if (strcmp(modename, *modenamep)){ /* Command in different mode */
@ -593,9 +591,12 @@ clicon_parse(clicon_handle h,
default:
fprintf(f, "CLI syntax error: \"%s\" is ambiguous\n", cmd);
break;
} /* switch retval */
} /* switch result */
}
retval = 0;
done:
if (reason)
free(reason);
if (cvv)
cvec_free(cvv);
return retval;

View file

@ -2,7 +2,9 @@
*
***** BEGIN LICENSE BLOCK *****
Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
Copyright (C) 2017-2019 Olof Hagsand
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC
This file is part of CLIXON.
@ -65,7 +67,7 @@ void *clixon_str2fn(char *name, void *handle, char **error);
int clicon_eval(clicon_handle h, char *cmd, cg_obj *match_obj, cvec *vr);
int clicon_parse(clicon_handle h, char *cmd, char **mode, int *result);
int clicon_parse(clicon_handle h, char *cmd, char **mode, cligen_result *result, int *evalres);
char *clicon_cliread(clicon_handle h);

View file

@ -118,7 +118,7 @@ xmldb_db2file(clicon_handle h,
return retval;
}
/*! Validate database name
/*! Ensure database name is correct
* @param[in] db Name of database
* @retval 0 OK
* @retval -1 Failed validate, xret set to error