[BACK]Return to cmdbuf.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / less

Diff for /src/usr.bin/less/cmdbuf.c between version 1.1.1.3 and 1.1.1.4

version 1.1.1.3, 2011/09/16 17:47:01 version 1.1.1.4, 2014/04/25 13:33:42
Line 1 
Line 1 
 /*  /*
  * Copyright (C) 1984-2011  Mark Nudelman   * Copyright (C) 1984-2012  Mark Nudelman
  *   *
  * You may distribute under the terms of either the GNU General Public   * You may distribute under the terms of either the GNU General Public
  * License or the Less License, as specified in the README file.   * License or the Less License, as specified in the README file.
  *   *
  * For more information about less, or for information on how to   * For more information, see the README file.
  * contact the author, see the README file.  
  */   */
   
   
Line 30 
Line 29 
 static char *cp;                /* Pointer into cmdbuf */  static char *cp;                /* Pointer into cmdbuf */
 static int cmd_offset;          /* Index into cmdbuf of first displayed char */  static int cmd_offset;          /* Index into cmdbuf of first displayed char */
 static int literal;             /* Next input char should not be interpreted */  static int literal;             /* Next input char should not be interpreted */
   static int updown_match = -1;   /* Prefix length in up/down movement */
   
 #if TAB_COMPLETE_FILENAME  #if TAB_COMPLETE_FILENAME
 static int cmd_complete();  static int cmd_complete();
Line 122 
Line 122 
         cmd_offset = 0;          cmd_offset = 0;
         literal = 0;          literal = 0;
         cmd_mbc_buf_len = 0;          cmd_mbc_buf_len = 0;
           updown_match = -1;
 }  }
   
 /*  /*
Line 132 
Line 133 
 {  {
         cmd_col = prompt_col = 0;          cmd_col = prompt_col = 0;
         cmd_mbc_buf_len = 0;          cmd_mbc_buf_len = 0;
           updown_match = -1;
 }  }
   
 /*  /*
Line 154 
Line 156 
                 {                  {
                         cmd_col++;                          cmd_col++;
                         prompt_col++;                          prompt_col++;
                 } else if (!is_composing_char(ch) &&                  }
   #if !SMALL
                   else if (!is_composing_char(ch) &&
                            !is_combining_char(prev_ch, ch))                             !is_combining_char(prev_ch, ch))
                 {                  {
                         int width = is_wide_char(ch) ? 2 : 1;                          int width = is_wide_char(ch) ? 2 : 1;
                         cmd_col += width;                          cmd_col += width;
                         prompt_col += width;                          prompt_col += width;
                 }                  }
   #endif /* !SMALL */
                 prev_ch = ch;                  prev_ch = ch;
         }          }
 }  }
Line 207 
Line 212 
                         if (bswidth != NULL)                          if (bswidth != NULL)
                                 *bswidth = len;                                  *bswidth = len;
                 }                  }
         } else          }
   #if !SMALL
           else
         {          {
                 pr = prutfchar(ch);                  pr = prutfchar(ch);
                 if (pwidth != NULL || bswidth != NULL)                  if (pwidth != NULL || bswidth != NULL)
Line 246 
Line 253 
                         }                          }
                 }                  }
         }          }
   #endif /* !SMALL */
   
         return (pr);          return (pr);
 }  }
Line 504 
Line 512 
         /*          /*
          * Reprint the tail of the line from the inserted char.           * Reprint the tail of the line from the inserted char.
          */           */
           updown_match = -1;
         cmd_repaint(cp);          cmd_repaint(cp);
         cmd_right();          cmd_right();
         return (CC_OK);          return (CC_OK);
Line 547 
Line 556 
         /*          /*
          * Repaint the buffer after the erased char.           * Repaint the buffer after the erased char.
          */           */
           updown_match = -1;
         cmd_repaint(cp);          cmd_repaint(cp);
   
         /*          /*
Line 643 
Line 653 
         cmd_offset = 0;          cmd_offset = 0;
         cmd_home();          cmd_home();
         *cp = '\0';          *cp = '\0';
           updown_match = -1;
         cmd_repaint(cp);          cmd_repaint(cp);
   
         /*          /*
Line 675 
Line 686 
 #if CMD_HISTORY  #if CMD_HISTORY
 /*  /*
  * Move up or down in the currently selected command history list.   * Move up or down in the currently selected command history list.
    * Only consider entries whose first updown_match chars are equal to
    * cmdbuf's corresponding chars.
  */   */
         static int          static int
 cmd_updown(action)  cmd_updown(action)
         int action;          int action;
 {  {
         char *s;          char *s;
           struct mlist *ml;
   
         if (curr_mlist == NULL)          if (curr_mlist == NULL)
         {          {
Line 690 
Line 704 
                 bell();                  bell();
                 return (CC_OK);                  return (CC_OK);
         }          }
         cmd_home();  
         clear_eol();          if (updown_match < 0)
           {
                   updown_match = cp - cmdbuf;
           }
   
         /*          /*
          * Move curr_mp to the next/prev entry.           * Find the next history entry which matches.
          */           */
         if (action == EC_UP)          for (ml = curr_mlist->curr_mp;;)
                 curr_mlist->curr_mp = curr_mlist->curr_mp->prev;          {
         else                  ml = (action == EC_UP) ? ml->prev : ml->next;
                 curr_mlist->curr_mp = curr_mlist->curr_mp->next;                  if (ml == curr_mlist)
                   {
                           /*
                            * We reached the end (or beginning) of the list.
                            */
                           break;
                   }
                   if (strncmp(cmdbuf, ml->string, updown_match) == 0)
                   {
                           /*
                            * This entry matches; stop here.
                            * Copy the entry into cmdbuf and echo it on the screen.
                            */
                           curr_mlist->curr_mp = ml;
                           s = ml->string;
                           if (s == NULL)
                                   s = "";
                           cmd_home();
                           clear_eol();
                           strlcpy(cmdbuf, s, sizeof(cmdbuf));
                           for (cp = cmdbuf;  *cp != '\0';  )
                                   cmd_right();
                           return (CC_OK);
                   }
           }
         /*          /*
          * Copy the entry into cmdbuf and echo it on the screen.           * We didn't find a history entry that matches.
          */           */
         s = curr_mlist->curr_mp->string;          bell();
         if (s == NULL)  
                 s = "";  
         strcpy(cmdbuf, s);  
         for (cp = cmdbuf;  *cp != '\0';  )  
                 cmd_right();  
         return (CC_OK);          return (CC_OK);
 }  }
 #endif  #endif
Line 1056 
Line 1093 
                 tk_text = fcomplete(word);                  tk_text = fcomplete(word);
         } else          } else
         {          {
   #if MSDOS_COMPILER
                   char *qword = NULL;
   #else
                 char *qword = shell_quote(word+1);                  char *qword = shell_quote(word+1);
   #endif
                 if (qword == NULL)                  if (qword == NULL)
                         tk_text = fcomplete(word+1);                          tk_text = fcomplete(word+1);
                 else                  else
Line 1202 
Line 1243 
         {          {
                 cmd_mbc_buf[0] = c;                  cmd_mbc_buf[0] = c;
                 len = 1;                  len = 1;
         } else          }
   #if !SMALL
           else
         {          {
                 /* Perform strict validation in all possible cases.  */                  /* Perform strict validation in all possible cases.  */
                 if (cmd_mbc_buf_len == 0)                  if (cmd_mbc_buf_len == 0)
Line 1246 
Line 1289 
                 len = cmd_mbc_buf_len;                  len = cmd_mbc_buf_len;
                 cmd_mbc_buf_len = 0;                  cmd_mbc_buf_len = 0;
         }          }
   #endif /* !SMALL */
   
         if (literal)          if (literal)
         {          {
Line 1343 
Line 1387 
                 return (save(name));                  return (save(name));
         }          }
   
         /* Otherwise, file is in $HOME. */          /* Otherwise, file is in $HOME if enabled. */
           if (strcmp (LESSHISTFILE, "-") == 0)
                   return (NULL);
         home = lgetenv("HOME");          home = lgetenv("HOME");
         if (home == NULL || *home == '\0')          if (home == NULL || *home == '\0')
         {          {
Line 1457 
Line 1503 
         FILE *f;          FILE *f;
         int modified = 0;          int modified = 0;
   
         filename = histfile_name();  
         if (filename == NULL)  
                 return;  
         if (mlist_search.modified)          if (mlist_search.modified)
                 modified = 1;                  modified = 1;
 #if SHELL_ESCAPE || PIPEC  #if SHELL_ESCAPE || PIPEC
Line 1467 
Line 1510 
                 modified = 1;                  modified = 1;
 #endif  #endif
         if (!modified)          if (!modified)
                   return;
           filename = histfile_name();
           if (filename == NULL)
                 return;                  return;
         f = fopen(filename, "w");          f = fopen(filename, "w");
         free(filename);          free(filename);

Legend:
Removed from v.1.1.1.3  
changed lines
  Added in v.1.1.1.4