X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlib%2Fcli.c;h=c43371e0d9f144d53e4adedc8bafff0af1c04903;hb=add6a384e9444dfba86ae493a07bf3641e74126e;hp=2187d2886fc342594b30b652caa7537800e492e9;hpb=8973b07eecbbfe23a5267975f8052a5c6339c756;p=vpp.git diff --git a/src/vlib/cli.c b/src/vlib/cli.c index 2187d2886fc..c43371e0d9f 100644 --- a/src/vlib/cli.c +++ b/src/vlib/cli.c @@ -159,6 +159,64 @@ done: return match; } +uword +unformat_vlib_cli_line (unformat_input_t *i, va_list *va) +{ + unformat_input_t *result = va_arg (*va, unformat_input_t *); + u8 *line = 0; + uword c; + int skip; + +next_line: + skip = 0; + + /* skip leading whitespace if any */ + unformat_skip_white_space (i); + + if (unformat_is_eof (i)) + return 0; + + while ((c = unformat_get_input (i)) != UNFORMAT_END_OF_INPUT) + { + if (c == '\\') + { + c = unformat_get_input (i); + + if (c == '\n') + { + if (!skip) + vec_add1 (line, '\n'); + skip = 0; + continue; + } + + if (!skip) + vec_add1 (line, '\\'); + + if (c == UNFORMAT_END_OF_INPUT) + break; + + if (!skip) + vec_add1 (line, c); + continue; + } + + if (c == '#') + skip = 1; + else if (c == '\n') + break; + + if (!skip) + vec_add1 (line, c); + } + + if (line == 0) + goto next_line; + + unformat_init_vector (result, line); + return 1; +} + /* Looks for string based sub-input formatted { SUB-INPUT }. */ uword unformat_vlib_cli_sub_input (unformat_input_t * i, va_list * args) @@ -617,7 +675,7 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm, vec_add1 (c_error->what, 0); ed->err = elog_string (vlib_get_elog_main (), (char *) c_error->what); - _vec_len (c_error->what) -= 1; + vec_dec_len (c_error->what, 1); } else ed->err = elog_string (vlib_get_elog_main (), "OK"); @@ -1097,7 +1155,7 @@ restart_cmd_fn (vlib_main_t * vm, unformat_input_t * input, /* *INDENT-ON* */ /* Exec ourself */ - execve (vgm->name, (char **) vm->argv, environ); + execve (vgm->name, (char **) vgm->argv, environ); return 0; } @@ -1179,7 +1237,7 @@ vlib_cli_normalize_path (char *input, char **result) /* Remove any extra space at end. */ if (l > 0 && s[l - 1] == ' ') - _vec_len (s) -= 1; + vec_dec_len (s, 1); *result = s; return index_of_last_space;