]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: add vector_compact(), use after str splits
authorQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 29 May 2018 21:38:18 +0000 (21:38 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 6 Jun 2018 16:16:12 +0000 (16:16 +0000)
* Add function to move all data to the start of a vector by shifting
  over contiguous empty slots
* Use this function to remove empty slots leftover after
  frrstr_filter_vec

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/command.c
lib/vector.c
lib/vector.h
lib/vty.c

index edf7348ba75e29dff33dca4aa7074aebb46507ae..b7690eac4c2e97d4dbce55e3d80ef552d08b043a 100644 (file)
@@ -290,10 +290,12 @@ vector cmd_make_strvec(const char *string)
        for (unsigned int i = 0; i < vector_active(result); i++) {
                if (strlen(vector_slot(result, i)) == 0) {
                        XFREE(MTYPE_TMP, vector_slot(result, i));
-                       vector_remove(result, i);
-                       --i;
+                       vector_unset(result, i);
                }
        }
+
+       vector_compact(result);
+
        return result;
 }
 
index 696e260cdf3c227aed3aca7edfe59d41d66340d3..0631e836f619c083d43f7a5b174421202a974da1 100644 (file)
@@ -164,6 +164,16 @@ void vector_remove(vector v, unsigned int ix)
        v->index[v->active] = NULL;
 }
 
+void vector_compact(vector v)
+{
+       for (unsigned int i = 0; i < vector_active(v); ++i) {
+               if (vector_slot(v, i) == NULL) {
+                       vector_remove(v, i);
+                       --i;
+               }
+       }
+}
+
 void vector_unset_value(vector v, void *val)
 {
        size_t i;
index 21732a300e6b4249f5e3ca440773ea992fcbf1b4..97e15da04099c621ced75845f0f3dbe8cd7ce801 100644 (file)
@@ -53,6 +53,7 @@ extern int vector_set_index(vector v, unsigned int i, void *val);
 extern void vector_unset(vector v, unsigned int i);
 extern void vector_unset_value(vector v, void *val);
 extern void vector_remove(vector v, unsigned int ix);
+extern void vector_compact(vector v);
 
 extern unsigned int vector_count(vector v);
 extern void vector_free(vector v);
index 803b1c408d5ce03181692ba363d418148dfcfa0c..9e9e90ef318c6c63faaf3985b164c5a86a749412 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -188,6 +188,7 @@ int vty_out(struct vty *vty, const char *format, ...)
                vector lines = frrstr_split_vec(buf, "\n");
 
                frrstr_filter_vec(lines, &vty->include);
+               vector_compact(lines);
 
                /*
                 * Consider the string "foo\n". If the regex is an empty string