]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Make <cr> appear first in completions
authorQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 6 Oct 2016 01:15:48 +0000 (01:15 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 6 Oct 2016 01:15:48 +0000 (01:15 +0000)
When a command is complete and <cr> appears in tab- or
?-completions, make sure it appears first

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

index 6368ebffe11fdcd48ddc914bcb050e20d42a8971..f51b2c69ee4b9ab609fa61190304e2a7a78056d8 100644 (file)
@@ -498,7 +498,10 @@ compare_completions (const void *fst, const void *snd)
 /**
  * Takes a list of completions returned by command_complete,
  * dedeuplicates them based on both text and description,
- * and returns them as a vector.
+ * sorts them, and returns them as a vector.
+ *
+ * @param completions linked list of cmd_token
+ * @return deduplicated and sorted vector with
  */
 static vector
 completions_to_vec (struct list *completions)
@@ -506,10 +509,13 @@ completions_to_vec (struct list *completions)
   vector comps = vector_init (VECTOR_MIN_SIZE);
 
   struct listnode *ln;
-  struct cmd_token *token;
+  struct cmd_token *token, *cr = NULL;
   unsigned int i, exists;
   for (ALL_LIST_ELEMENTS_RO(completions,ln,token))
   {
+    if (token->type == END_TKN && (cr = token))
+      continue;
+
     // linear search for token in completions vector
     exists = 0;
     for (i = 0; i < vector_active (comps) && !exists; i++)
@@ -529,6 +535,13 @@ completions_to_vec (struct list *completions)
          sizeof (void *),
          &compare_completions);
 
+  if (cr)
+  {
+    vector_set_index (comps, vector_active (comps), NULL);
+    memmove (comps->index + 1, comps->index, (comps->alloced - 1) * sizeof (void *));
+    vector_set_index (comps, 0, copy_cmd_token (cr));
+  }
+
   return comps;
 }
 /**