=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/cmdbuf.c,v retrieving revision 1.6 retrieving revision 1.7 diff -c -r1.6 -r1.7 *** src/usr.bin/less/cmdbuf.c 2011/11/16 11:30:02 1.6 --- src/usr.bin/less/cmdbuf.c 2014/04/25 13:38:21 1.7 *************** *** 1,11 **** /* ! * Copyright (C) 1984-2011 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. * ! * For more information about less, or for information on how to ! * contact the author, see the README file. */ --- 1,10 ---- /* ! * Copyright (C) 1984-2012 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. * ! * For more information, see the README file. */ *************** *** 30,35 **** --- 29,35 ---- static char *cp; /* Pointer into cmdbuf */ static int cmd_offset; /* Index into cmdbuf of first displayed char */ 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 static int cmd_complete(); *************** *** 122,127 **** --- 122,128 ---- cmd_offset = 0; literal = 0; cmd_mbc_buf_len = 0; + updown_match = -1; } /* *************** *** 132,137 **** --- 133,139 ---- { cmd_col = prompt_col = 0; cmd_mbc_buf_len = 0; + updown_match = -1; } /* *************** *** 510,515 **** --- 512,518 ---- /* * Reprint the tail of the line from the inserted char. */ + updown_match = -1; cmd_repaint(cp); cmd_right(); return (CC_OK); *************** *** 553,558 **** --- 556,562 ---- /* * Repaint the buffer after the erased char. */ + updown_match = -1; cmd_repaint(cp); /* *************** *** 649,654 **** --- 653,659 ---- cmd_offset = 0; cmd_home(); *cp = '\0'; + updown_match = -1; cmd_repaint(cp); /* *************** *** 681,692 **** --- 686,700 ---- #if CMD_HISTORY /* * 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 cmd_updown(action) int action; { char *s; + struct mlist *ml; if (curr_mlist == NULL) { *************** *** 696,719 **** bell(); return (CC_OK); } ! cmd_home(); ! clear_eol(); /* ! * Move curr_mp to the next/prev entry. */ ! if (action == EC_UP) ! curr_mlist->curr_mp = curr_mlist->curr_mp->prev; ! else ! curr_mlist->curr_mp = curr_mlist->curr_mp->next; /* ! * Copy the entry into cmdbuf and echo it on the screen. */ ! s = curr_mlist->curr_mp->string; ! if (s == NULL) ! s = ""; ! strlcpy(cmdbuf, s, sizeof(cmdbuf)); ! for (cp = cmdbuf; *cp != '\0'; ) ! cmd_right(); return (CC_OK); } #endif --- 704,750 ---- bell(); return (CC_OK); } ! ! if (updown_match < 0) ! { ! updown_match = cp - cmdbuf; ! } ! /* ! * Find the next history entry which matches. */ ! for (ml = curr_mlist->curr_mp;;) ! { ! ml = (action == EC_UP) ? ml->prev : ml->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); ! } ! } /* ! * We didn't find a history entry that matches. */ ! bell(); return (CC_OK); } #endif *************** *** 1062,1068 **** --- 1093,1103 ---- tk_text = fcomplete(word); } else { + #if MSDOS_COMPILER + char *qword = NULL; + #else char *qword = shell_quote(word+1); + #endif if (qword == NULL) tk_text = fcomplete(word+1); else *************** *** 1468,1476 **** FILE *f; int modified = 0; - filename = histfile_name(); - if (filename == NULL) - return; if (mlist_search.modified) modified = 1; #if SHELL_ESCAPE || PIPEC --- 1503,1508 ---- *************** *** 1478,1483 **** --- 1510,1518 ---- modified = 1; #endif if (!modified) + return; + filename = histfile_name(); + if (filename == NULL) return; f = fopen(filename, "w"); free(filename);