Diff for /qemu/readline.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2018/04/24 16:37:52 version 1.1.1.2, 2018/04/24 16:47:08
Line 1 Line 1
 /*  /*
  * QEMU readline utility   * QEMU readline utility
  *    *
  * Copyright (c) 2003-2004 Fabrice Bellard   * Copyright (c) 2003-2004 Fabrice Bellard
  *    *
  * Permission is hereby granted, free of charge, to any person obtaining a copy   * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal   * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights   * in the Software without restriction, including without limitation the rights
Line 21 Line 21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.   * THE SOFTWARE.
  */   */
 #include "vl.h"  #include "qemu-common.h"
   #include "console.h"
   
 #define TERM_CMD_BUF_SIZE 4095  #define TERM_CMD_BUF_SIZE 4095
 #define TERM_MAX_CMDS 64  #define TERM_MAX_CMDS 64
Line 156  static void term_backspace(void) Line 157  static void term_backspace(void)
     }      }
 }  }
   
   static void term_backword(void)
   {
       int start;
   
       if (term_cmd_buf_index == 0 || term_cmd_buf_index > term_cmd_buf_size) {
           return;
       }
   
       start = term_cmd_buf_index - 1;
   
       /* find first word (backwards) */
       while (start > 0) {
           if (!isspace(term_cmd_buf[start])) {
               break;
           }
   
           --start;
       }
   
       /* find first space (backwards) */
       while (start > 0) {
           if (isspace(term_cmd_buf[start])) {
               ++start;
               break;
           }
   
           --start;
       }
   
       /* remove word */
       if (start < term_cmd_buf_index) {
           memmove(term_cmd_buf + start,
                   term_cmd_buf + term_cmd_buf_index,
                   term_cmd_buf_size - term_cmd_buf_index);
           term_cmd_buf_size -= term_cmd_buf_index - start;
           term_cmd_buf_index = start;
       }
   }
   
 static void term_bol(void)  static void term_bol(void)
 {  {
     term_cmd_buf_index = 0;      term_cmd_buf_index = 0;
Line 182  static void term_up_char(void) Line 222  static void term_up_char(void)
     }      }
     term_hist_entry--;      term_hist_entry--;
     if (term_hist_entry >= 0) {      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_history[term_hist_entry]);
         term_cmd_buf_index = term_cmd_buf_size = strlen(term_cmd_buf);          term_cmd_buf_index = term_cmd_buf_size = strlen(term_cmd_buf);
     }      }
Line 227  static void term_hist_add(const char *cm Line 267  static void term_hist_add(const char *cm
             new_entry = hist_entry;              new_entry = hist_entry;
             /* Put this entry at the end of history */              /* Put this entry at the end of history */
             memmove(&term_history[idx], &term_history[idx + 1],              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;              term_history[TERM_MAX_CMDS - 1] = NULL;
             for (; idx < TERM_MAX_CMDS; idx++) {              for (; idx < TERM_MAX_CMDS; idx++) {
                 if (term_history[idx] == NULL)                  if (term_history[idx] == NULL)
Line 240  static void term_hist_add(const char *cm Line 280  static void term_hist_add(const char *cm
         /* Need to get one free slot */          /* Need to get one free slot */
         free(term_history[0]);          free(term_history[0]);
         memcpy(term_history, &term_history[1],          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;          term_history[TERM_MAX_CMDS - 1] = NULL;
         idx = TERM_MAX_CMDS - 1;          idx = TERM_MAX_CMDS - 1;
     }      }
Line 261  void add_completion(const char *str) Line 301  void add_completion(const char *str)
   
 static void term_completion(void)  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;      char *cmdline;
   
     nb_completions = 0;      nb_completions = 0;
       
     cmdline = qemu_malloc(term_cmd_buf_index + 1);      cmdline = qemu_malloc(term_cmd_buf_index + 1);
     if (!cmdline)      if (!cmdline)
         return;          return;
Line 288  static void term_completion(void) Line 328  static void term_completion(void)
     } else {      } else {
         term_printf("\n");          term_printf("\n");
         max_width = 0;          max_width = 0;
           max_prefix = 0; 
         for(i = 0; i < nb_completions; i++) {          for(i = 0; i < nb_completions; i++) {
             len = strlen(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)              if (len > max_width)
                 max_width = len;                  max_width = len;
         }          }
           if (max_prefix > 0) 
               for(i = completion_index; i < max_prefix; i++) {
                   term_insert_char(completions[0][i]);
               }
         max_width += 2;          max_width += 2;
         if (max_width < 10)          if (max_width < 10)
             max_width = 10;              max_width = 10;
Line 335  void readline_handle_byte(int ch) Line 390  void readline_handle_byte(int ch)
             if (!term_is_password)              if (!term_is_password)
                 term_hist_add(term_cmd_buf);                  term_hist_add(term_cmd_buf);
             term_printf("\n");              term_printf("\n");
               term_cmd_buf_index = 0;
               term_cmd_buf_size = 0;
               term_last_cmd_buf_index = 0;
               term_last_cmd_buf_size = 0;
             /* NOTE: readline_start can be called here */              /* NOTE: readline_start can be called here */
             term_readline_func(term_readline_opaque, term_cmd_buf);              term_readline_func(term_readline_opaque, term_cmd_buf);
             break;              break;
           case 23:
               /* ^W */
               term_backword();
               break;
         case 27:          case 27:
             term_esc_state = IS_ESC;              term_esc_state = IS_ESC;
             break;              break;

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


unix.superglobalmegacorp.com