Adjust to cligen 4.5 update
This commit is contained in:
parent
5535239363
commit
6e2cb1b97d
7 changed files with 70 additions and 62 deletions
|
|
@ -20,6 +20,13 @@
|
||||||
* [3.3.2](#332) Aug 27 2017
|
* [3.3.2](#332) Aug 27 2017
|
||||||
* [3.3.1](#331) June 7 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
|
## 4.4.0
|
||||||
Expected: March 2020
|
Expected: March 2020
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
*
|
*
|
||||||
***** BEGIN LICENSE BLOCK *****
|
***** 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.
|
This file is part of CLIXON.
|
||||||
|
|
||||||
|
|
@ -191,14 +193,6 @@ cli_interrupt_hook(clicon_handle h,
|
||||||
return cligen_interrupt_hook(ch, fn);
|
return cligen_interrupt_hook(ch, fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
|
||||||
cli_nomatch(clicon_handle h)
|
|
||||||
{
|
|
||||||
cligen_handle ch = cligen(h);
|
|
||||||
|
|
||||||
return cligen_nomatch(ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
cli_prompt_set(clicon_handle h,
|
cli_prompt_set(clicon_handle h,
|
||||||
char *prompt)
|
char *prompt)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
*
|
*
|
||||||
***** BEGIN LICENSE BLOCK *****
|
***** 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.
|
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);
|
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_prompt_set(clicon_handle h, char *prompt);
|
||||||
|
|
||||||
int cli_logsyntax_set(clicon_handle h, int status);
|
int cli_logsyntax_set(clicon_handle h, int status);
|
||||||
|
|
|
||||||
|
|
@ -212,11 +212,10 @@ cli_signal_init (clicon_handle h)
|
||||||
static int
|
static int
|
||||||
cli_interactive(clicon_handle h)
|
cli_interactive(clicon_handle h)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
int res;
|
char *cmd;
|
||||||
char *cmd;
|
char *new_mode;
|
||||||
char *new_mode;
|
cligen_result result;
|
||||||
int eval;
|
|
||||||
|
|
||||||
/* Loop through all commands */
|
/* Loop through all commands */
|
||||||
while(!cligen_exiting(cli_cligen(h))) {
|
while(!cligen_exiting(cli_cligen(h))) {
|
||||||
|
|
@ -225,8 +224,9 @@ cli_interactive(clicon_handle h)
|
||||||
cligen_exiting_set(cli_cligen(h), 1); /* EOF */
|
cligen_exiting_set(cli_cligen(h), 1); /* EOF */
|
||||||
goto ok; /* EOF should not be -1 error? */
|
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;
|
goto done;
|
||||||
|
/* Why not check result? */
|
||||||
}
|
}
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -587,8 +587,10 @@ main(int argc, char **argv)
|
||||||
/* Join rest of argv to a single command */
|
/* Join rest of argv to a single command */
|
||||||
restarg = clicon_strjoin(argc, argv, " ");
|
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 */
|
/* If several cligen object variables match same preference, select first */
|
||||||
cligen_preference_mode_set(cli_cligen(h), 1);
|
cligen_preference_mode_set(cli_cligen(h), 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Call start function in all plugins before we go interactive
|
/* 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"));
|
cligen_utf8_set(cli_cligen(h), clicon_option_int(h,"CLICON_CLI_UTF8"));
|
||||||
/* Launch interfactive event loop, unless -1 */
|
/* Launch interfactive event loop, unless -1 */
|
||||||
if (restarg != NULL && strlen(restarg)){
|
if (restarg != NULL && strlen(restarg)){
|
||||||
char *mode = cli_syntax_mode(h);
|
char *mode = cli_syntax_mode(h);
|
||||||
int result;
|
cligen_result result; /* match result */
|
||||||
|
int evalresult = 0; /* if result == 1, calback result */
|
||||||
|
|
||||||
/* */
|
if (clicon_parse(h, restarg, &mode, &result, &evalresult) < 0)
|
||||||
if (clicon_parse(h, restarg, &mode, &result) != 1)
|
|
||||||
goto done;
|
goto done;
|
||||||
if (result < 0)
|
if (result != 1) /* Not unique match */
|
||||||
|
goto done;
|
||||||
|
if (evalresult < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
*
|
*
|
||||||
***** BEGIN LICENSE BLOCK *****
|
***** 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.
|
This file is part of CLIXON.
|
||||||
|
|
||||||
|
|
@ -465,10 +467,10 @@ cli_handler_err(FILE *f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Evaluate a matched command
|
/*! Evaluate a matched command
|
||||||
* @param[in] h Clicon handle
|
* @param[in] h Clicon handle
|
||||||
* @param[in] cmd The command string
|
* @param[in] cmd The command string
|
||||||
* @retval int If there is a callback, the return value of the callback is returned,
|
* @retval int If there is a callback, the return value of the callback is returned,
|
||||||
* @retval 0 otherwise
|
* @retval 0 otherwise
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
clicon_eval(clicon_handle h,
|
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
|
* match is found in another mode, the mode variable is updated to point at
|
||||||
* the new mode string.
|
* the new mode string.
|
||||||
*
|
*
|
||||||
* @param[in] h Clicon handle
|
* @param[in] h Clicon handle
|
||||||
* @param[in] cmd Command string
|
* @param[in] cmd Command string
|
||||||
* @param[in,out] modenamep Pointer to the mode string pointer
|
* @param[in,out] modenamep Pointer to the mode string pointer
|
||||||
* @param[out] evalres Evaluation result if retval=1
|
* @param[out] result CLIgen match result, < 0: errors, >=0 number of matches
|
||||||
* -2 On eof (shouldnt happen)
|
* @param[out] evalres Evaluation result if result=1
|
||||||
* -1 On parse error
|
* @retval 0 OK
|
||||||
* >=0 Number of matches
|
* @retval -1 Error
|
||||||
* @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
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
clicon_parse(clicon_handle h,
|
clicon_parse(clicon_handle h,
|
||||||
char *cmd,
|
char *cmd,
|
||||||
char **modenamep,
|
char **modenamep,
|
||||||
int *evalres)
|
cligen_result *result,
|
||||||
|
int *evalres)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
char *modename;
|
char *modename;
|
||||||
char *modename0;
|
char *modename0;
|
||||||
int r;
|
int r;
|
||||||
cli_syntax_t *stx = NULL;
|
cli_syntax_t *stx = NULL;
|
||||||
cli_syntaxmode_t *smode;
|
cli_syntaxmode_t *smode;
|
||||||
parse_tree *pt; /* Orig */
|
parse_tree *pt; /* Orig */
|
||||||
cg_obj *match_obj;
|
cg_obj *match_obj;
|
||||||
cvec *cvv = NULL;
|
cvec *cvv = NULL;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
char *reason = NULL;
|
||||||
|
|
||||||
if (clicon_get_logflags()&CLICON_LOG_STDOUT)
|
if (clicon_get_logflags()&CLICON_LOG_STDOUT)
|
||||||
f = stdout;
|
f = stdout;
|
||||||
|
|
@ -562,22 +561,21 @@ clicon_parse(clicon_handle h,
|
||||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||||
goto done;;
|
goto done;;
|
||||||
}
|
}
|
||||||
retval = cliread_parse(cli_cligen(h), cmd, pt, &match_obj, cvv);
|
if (cliread_parse(cli_cligen(h), cmd, pt, &match_obj, cvv, result, &reason) < 0)
|
||||||
if (retval != CG_MATCH)
|
goto done;
|
||||||
|
if (*result != CG_MATCH)
|
||||||
pt_expand_cleanup_1(pt); /* XXX change to pt_expand_treeref_cleanup */
|
pt_expand_cleanup_1(pt); /* XXX change to pt_expand_treeref_cleanup */
|
||||||
if (modename0){
|
if (modename0){
|
||||||
cligen_tree_active_set(cli_cligen(h), modename0);
|
cligen_tree_active_set(cli_cligen(h), modename0);
|
||||||
modename0 = NULL;
|
modename0 = NULL;
|
||||||
}
|
}
|
||||||
switch (retval) {
|
switch (*result) {
|
||||||
case CG_EOF: /* eof */
|
case CG_EOF: /* eof */
|
||||||
case CG_ERROR:
|
case CG_ERROR:
|
||||||
fprintf(f, "CLI parse error: %s\n", cmd);
|
fprintf(f, "CLI parse error: %s\n", cmd);
|
||||||
break;
|
break;
|
||||||
case CG_NOMATCH: /* no match */
|
case CG_NOMATCH: /* no match */
|
||||||
/* clicon_err(OE_CFG, 0, "CLI syntax error: \"%s\": %s",
|
fprintf(f, "CLI syntax error: \"%s\": %s\n", cmd, reason);
|
||||||
cmd, cli_nomatch(h));*/
|
|
||||||
fprintf(f, "CLI syntax error: \"%s\": %s\n", cmd, cli_nomatch(h));
|
|
||||||
break;
|
break;
|
||||||
case CG_MATCH:
|
case CG_MATCH:
|
||||||
if (strcmp(modename, *modenamep)){ /* Command in different mode */
|
if (strcmp(modename, *modenamep)){ /* Command in different mode */
|
||||||
|
|
@ -593,9 +591,12 @@ clicon_parse(clicon_handle h,
|
||||||
default:
|
default:
|
||||||
fprintf(f, "CLI syntax error: \"%s\" is ambiguous\n", cmd);
|
fprintf(f, "CLI syntax error: \"%s\" is ambiguous\n", cmd);
|
||||||
break;
|
break;
|
||||||
} /* switch retval */
|
} /* switch result */
|
||||||
}
|
}
|
||||||
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (reason)
|
||||||
|
free(reason);
|
||||||
if (cvv)
|
if (cvv)
|
||||||
cvec_free(cvv);
|
cvec_free(cvv);
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
*
|
*
|
||||||
***** BEGIN LICENSE BLOCK *****
|
***** 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.
|
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_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);
|
char *clicon_cliread(clicon_handle h);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ xmldb_db2file(clicon_handle h,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Validate database name
|
/*! Ensure database name is correct
|
||||||
* @param[in] db Name of database
|
* @param[in] db Name of database
|
||||||
* @retval 0 OK
|
* @retval 0 OK
|
||||||
* @retval -1 Failed validate, xret set to error
|
* @retval -1 Failed validate, xret set to error
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue