hist.c (84334) | hist.c (148834) |
---|---|
1/*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Christos Zoulas of Cornell University. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. | 1/*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Christos Zoulas of Cornell University. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. |
16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors | 16 * 3. Neither the name of the University nor the names of its contributors |
21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * | 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * |
36 * $NetBSD: hist.c,v 1.8 2001/01/10 07:45:41 jdolecek Exp $ | 32 * $NetBSD: hist.c,v 1.15 2003/11/01 23:36:39 christos Exp $ |
37 */ 38 39#if !defined(lint) && !defined(SCCSID) 40static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93"; 41#endif /* not lint && not SCCSID */ 42#include <sys/cdefs.h> | 33 */ 34 35#if !defined(lint) && !defined(SCCSID) 36static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93"; 37#endif /* not lint && not SCCSID */ 38#include <sys/cdefs.h> |
43__FBSDID("$FreeBSD: head/lib/libedit/hist.c 84334 2001-10-01 23:00:29Z obrien $"); | 39__FBSDID("$FreeBSD: head/lib/libedit/hist.c 148834 2005-08-07 20:55:59Z stefanf $"); |
44 45/* 46 * hist.c: History access functions 47 */ 48#include "sys.h" 49#include <stdlib.h> 50#include "el.h" 51 --- 73 unchanged lines hidden (view full) --- 125 if (hp == NULL) 126 return (CC_ERROR); 127 128 for (h = 1; h < el->el_history.eventno; h++) 129 if ((hp = HIST_NEXT(el)) == NULL) { 130 el->el_history.eventno = h; 131 return (CC_ERROR); 132 } | 40 41/* 42 * hist.c: History access functions 43 */ 44#include "sys.h" 45#include <stdlib.h> 46#include "el.h" 47 --- 73 unchanged lines hidden (view full) --- 121 if (hp == NULL) 122 return (CC_ERROR); 123 124 for (h = 1; h < el->el_history.eventno; h++) 125 if ((hp = HIST_NEXT(el)) == NULL) { 126 el->el_history.eventno = h; 127 return (CC_ERROR); 128 } |
133 (void) strncpy(el->el_line.buffer, hp, | 129 (void) strlcpy(el->el_line.buffer, hp, |
134 (size_t)(el->el_line.limit - el->el_line.buffer)); 135 el->el_line.lastchar = el->el_line.buffer + strlen(el->el_line.buffer); 136 | 130 (size_t)(el->el_line.limit - el->el_line.buffer)); 131 el->el_line.lastchar = el->el_line.buffer + strlen(el->el_line.buffer); 132 |
137 if (el->el_line.lastchar > el->el_line.buffer) { 138 if (el->el_line.lastchar[-1] == '\n') 139 el->el_line.lastchar--; 140 if (el->el_line.lastchar[-1] == ' ') 141 el->el_line.lastchar--; 142 if (el->el_line.lastchar < el->el_line.buffer) 143 el->el_line.lastchar = el->el_line.buffer; 144 } | 133 if (el->el_line.lastchar > el->el_line.buffer 134 && el->el_line.lastchar[-1] == '\n') 135 el->el_line.lastchar--; 136 if (el->el_line.lastchar > el->el_line.buffer 137 && el->el_line.lastchar[-1] == ' ') 138 el->el_line.lastchar--; |
145#ifdef KSHVI 146 if (el->el_map.type == MAP_VI) 147 el->el_line.cursor = el->el_line.buffer; 148 else 149#endif /* KSHVI */ 150 el->el_line.cursor = el->el_line.lastchar; 151 152 return (CC_REFRESH); 153} 154 155 | 139#ifdef KSHVI 140 if (el->el_map.type == MAP_VI) 141 el->el_line.cursor = el->el_line.buffer; 142 else 143#endif /* KSHVI */ 144 el->el_line.cursor = el->el_line.lastchar; 145 146 return (CC_REFRESH); 147} 148 149 |
156/* hist_list() 157 * List history entries | 150/* hist_command() 151 * process a history command |
158 */ 159protected int | 152 */ 153protected int |
160/*ARGSUSED*/ 161hist_list(EditLine *el, int argc, char **argv) | 154hist_command(EditLine *el, int argc, const char **argv) |
162{ 163 const char *str; | 155{ 156 const char *str; |
157 int num; 158 HistEvent ev; |
|
164 165 if (el->el_history.ref == NULL) 166 return (-1); | 159 160 if (el->el_history.ref == NULL) 161 return (-1); |
167 for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el)) 168 (void) fprintf(el->el_outfile, "%d %s", 169 el->el_history.ev.num, str); 170 return (0); | 162 163 if (argc == 1 || strcmp(argv[1], "list") == 0) { 164 /* List history entries */ 165 166 for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el)) 167 (void) fprintf(el->el_outfile, "%d %s", 168 el->el_history.ev.num, str); 169 return (0); 170 } 171 172 if (argc != 3) 173 return (-1); 174 175 num = (int)strtol(argv[2], NULL, 0); 176 177 if (strcmp(argv[1], "size") == 0) 178 return history(el->el_history.ref, &ev, H_SETSIZE, num); 179 180 if (strcmp(argv[1], "unique") == 0) 181 return history(el->el_history.ref, &ev, H_SETUNIQUE, num); 182 183 return -1; |
171} 172 173/* hist_enlargebuf() 174 * Enlarge history buffer to specified value. Called from el_enlargebufs(). 175 * Return 0 for failure, 1 for success. 176 */ 177protected int 178/*ARGSUSED*/ --- 17 unchanged lines hidden --- | 184} 185 186/* hist_enlargebuf() 187 * Enlarge history buffer to specified value. Called from el_enlargebufs(). 188 * Return 0 for failure, 1 for success. 189 */ 190protected int 191/*ARGSUSED*/ --- 17 unchanged lines hidden --- |