return match;
}
-/* Get current command args */
uword
-unformat_vlib_cli_args (unformat_input_t *i, va_list *va)
+unformat_vlib_cli_line (unformat_input_t *i, va_list *va)
{
unformat_input_t *result = va_arg (*va, unformat_input_t *);
- u8 *line;
- uword last_c;
- u32 index = i->index;
+ 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))
- {
- unformat_init (result, 0, 0);
- return 0;
- }
+ return 0;
- /* try to find last non-space character */
- do
+ while ((c = unformat_get_input (i)) != UNFORMAT_END_OF_INPUT)
{
- ASSERT (index > 0);
- last_c = i->buffer[--index];
- }
- while (last_c == ' ');
+ if (c == '\\')
+ {
+ c = unformat_get_input (i);
- if (last_c == '\t' || last_c == '\n' || last_c == '\r' || last_c == '\f' ||
- last_c == '}')
- {
- /* current command has no args */
- unformat_init (result, 0, 0);
- return 0;
- }
+ if (c == '\n')
+ {
+ if (!skip)
+ vec_add1 (line, '\n');
+ skip = 0;
+ continue;
+ }
- if (!unformat_user (i, unformat_line, &line))
- {
- unformat_init (result, 0, 0);
- return 0;
+ 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;
}
}
if (stats_segment)
{
- void *oldheap = vlib_stats_set_heap (0);
+ void *oldheap = vlib_stats_set_heap ();
was_enabled = clib_mem_trace_enable_disable (0);
u8 *s_in_svm = format (0, "%U\n", format_clib_mem_heap, 0, 1);
if (oldheap)
clib_mem_set_heap (oldheap);
u8 *s = vec_dup (s_in_svm);
- oldheap = vlib_stats_set_heap (0);
+ oldheap = vlib_stats_set_heap ();
vec_free (s_in_svm);
if (oldheap)
{