]> git.proxmox.com Git - qemu.git/blobdiff - readline.c
Don't leak VLANClientState on PCI hot remove
[qemu.git] / readline.c
index 577881a196e0156e5877a7322be2ec07b97587fd..85728412e67d4b56f511b6ed3e2a5fbb02954418 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * QEMU readline utility
- * 
+ *
  * Copyright (c) 2003-2004 Fabrice Bellard
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
@@ -21,7 +21,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "vl.h"
+#include "qemu-common.h"
+#include "console.h"
 
 #define TERM_CMD_BUF_SIZE 4095
 #define TERM_MAX_CMDS 64
@@ -168,7 +169,7 @@ static void term_backword(void)
 
     /* find first word (backwards) */
     while (start > 0) {
-        if (!isspace(term_cmd_buf[start])) {
+        if (!qemu_isspace(term_cmd_buf[start])) {
             break;
         }
 
@@ -177,7 +178,7 @@ static void term_backword(void)
 
     /* find first space (backwards) */
     while (start > 0) {
-        if (isspace(term_cmd_buf[start])) {
+        if (qemu_isspace(term_cmd_buf[start])) {
             ++start;
             break;
         }
@@ -221,7 +222,7 @@ static void term_up_char(void)
     }
     term_hist_entry--;
     if (term_hist_entry >= 0) {
-       pstrcpy(term_cmd_buf, sizeof(term_cmd_buf), 
+       pstrcpy(term_cmd_buf, sizeof(term_cmd_buf),
                 term_history[term_hist_entry]);
        term_cmd_buf_index = term_cmd_buf_size = strlen(term_cmd_buf);
     }
@@ -266,7 +267,7 @@ static void term_hist_add(const char *cmdline)
            new_entry = hist_entry;
            /* Put this entry at the end of history */
            memmove(&term_history[idx], &term_history[idx + 1],
-                   &term_history[TERM_MAX_CMDS] - &term_history[idx + 1]);
+                   (TERM_MAX_CMDS - idx + 1) * sizeof(char *));
            term_history[TERM_MAX_CMDS - 1] = NULL;
            for (; idx < TERM_MAX_CMDS; idx++) {
                if (term_history[idx] == NULL)
@@ -279,7 +280,7 @@ static void term_hist_add(const char *cmdline)
        /* Need to get one free slot */
        free(term_history[0]);
        memcpy(term_history, &term_history[1],
-              &term_history[TERM_MAX_CMDS] - &term_history[1]);
+              (TERM_MAX_CMDS - 1) * sizeof(char *));
        term_history[TERM_MAX_CMDS - 1] = NULL;
        idx = TERM_MAX_CMDS - 1;
     }
@@ -300,14 +301,12 @@ void add_completion(const char *str)
 
 static void term_completion(void)
 {
-    int len, i, j, max_width, nb_cols;
+    int len, i, j, max_width, nb_cols, max_prefix;
     char *cmdline;
 
     nb_completions = 0;
-    
+
     cmdline = qemu_malloc(term_cmd_buf_index + 1);
-    if (!cmdline)
-        return;
     memcpy(cmdline, term_cmd_buf, term_cmd_buf_index);
     cmdline[term_cmd_buf_index] = '\0';
     readline_find_completion(cmdline);
@@ -327,11 +326,26 @@ static void term_completion(void)
     } else {
         term_printf("\n");
         max_width = 0;
+        max_prefix = 0;        
         for(i = 0; i < nb_completions; i++) {
             len = strlen(completions[i]);
+            if (i==0) {
+                max_prefix = len;
+            } else {
+                if (len < max_prefix)
+                    max_prefix = len;
+                for(j=0; j<max_prefix; j++) {
+                    if (completions[i][j] != completions[0][j])
+                        max_prefix = j;
+                }
+            }
             if (len > max_width)
                 max_width = len;
         }
+        if (max_prefix > 0) 
+            for(i = completion_index; i < max_prefix; i++) {
+                term_insert_char(completions[0][i]);
+            }
         max_width += 2;
         if (max_width < 10)
             max_width = 10;
@@ -468,5 +482,3 @@ const char *readline_get_history(unsigned int index)
         return NULL;
     return term_history[index];
 }
-
-