misc: fix issues reported by clang-15
[vpp.git] / src / vlib / cli.c
index b7c4c00..9c53200 100644 (file)
@@ -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");
@@ -814,14 +872,14 @@ show_memory_usage (vlib_main_t * vm,
     }
   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)
        {
@@ -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;