Mon Feb 21 17:58:11 2022 UTC ()
Pull up following revision(s) (requested by kre in ticket #1429):

	bin/sh/histedit.c: revision 1.60

After (a few days short of) 21 years, revert 1.25, which did nothing except
make the -e option to "fc" fail to work (the commit message was about some
other changes entirely, so I an only assume this was committed by mistake).

It says a lot about the use of the fc command that no-one noticed that
this did not work properly for all this time.

Internally in sh, it is possible for built in commands to use either
getopt(3) (from libc) or the much simpler internal shell nextopt() routine
for option (flag) parsing.    However it makes no sense to use getopt()
and then access a global variable set only by nextopt() instead of the
one getopt() sets (which is what the code had used previously, forever).

Use the correct variable again.

XXX pullup -9 -8  (-7 -6 -5 ...)


(martin)
diff -r1.55 -r1.55.2.1 src/bin/sh/histedit.c

cvs diff -r1.55 -r1.55.2.1 src/bin/sh/histedit.c (expand / switch to unified diff)

--- src/bin/sh/histedit.c 2019/02/10 19:21:52 1.55
+++ src/bin/sh/histedit.c 2022/02/21 17:58:11 1.55.2.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: histedit.c,v 1.55 2019/02/10 19:21:52 kre Exp $ */ 1/* $NetBSD: histedit.c,v 1.55.2.1 2022/02/21 17:58:11 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1993 4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Kenneth Almquist. 8 * Kenneth Almquist.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36#ifndef lint 36#ifndef lint
37#if 0 37#if 0
38static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95"; 38static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95";
39#else 39#else
40__RCSID("$NetBSD: histedit.c,v 1.55 2019/02/10 19:21:52 kre Exp $"); 40__RCSID("$NetBSD: histedit.c,v 1.55.2.1 2022/02/21 17:58:11 martin Exp $");
41#endif 41#endif
42#endif /* not lint */ 42#endif /* not lint */
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <paths.h> 45#include <paths.h>
46#include <stdio.h> 46#include <stdio.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <unistd.h> 48#include <unistd.h>
49/* 49/*
50 * Editline and history functions (and glue). 50 * Editline and history functions (and glue).
51 */ 51 */
52#include "shell.h" 52#include "shell.h"
53#include "parser.h" 53#include "parser.h"
@@ -285,27 +285,27 @@ histcmd(volatile int argc, char ** volat @@ -285,27 +285,27 @@ histcmd(volatile int argc, char ** volat
285#endif 285#endif
286 286
287 if (hist == NULL) 287 if (hist == NULL)
288 error("history not active"); 288 error("history not active");
289 289
290 if (argc == 1) 290 if (argc == 1)
291 error("missing history argument"); 291 error("missing history argument");
292 292
293 optreset = 1; optind = 1; /* initialize getopt */ 293 optreset = 1; optind = 1; /* initialize getopt */
294 while (not_fcnumber(argv[optind]) && 294 while (not_fcnumber(argv[optind]) &&
295 (ch = getopt(argc, argv, ":e:lnrs")) != -1) 295 (ch = getopt(argc, argv, ":e:lnrs")) != -1)
296 switch ((char)ch) { 296 switch ((char)ch) {
297 case 'e': 297 case 'e':
298 editor = optionarg; 298 editor = optarg;
299 break; 299 break;
300 case 'l': 300 case 'l':
301 lflg = 1; 301 lflg = 1;
302 break; 302 break;
303 case 'n': 303 case 'n':
304 nflg = 1; 304 nflg = 1;
305 break; 305 break;
306 case 'r': 306 case 'r':
307 rflg = 1; 307 rflg = 1;
308 break; 308 break;
309 case 's': 309 case 's':
310 sflg = 1; 310 sflg = 1;
311 break; 311 break;