Thu Feb 24 10:07:47 2022 UTC ()
Pull up following revision(s) (requested by kre in ticket #1736):

	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.48.8.2 -r1.48.8.3 src/bin/sh/histedit.c

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

--- src/bin/sh/histedit.c 2018/08/25 14:45:37 1.48.8.2
+++ src/bin/sh/histedit.c 2022/02/24 10:07:46 1.48.8.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: histedit.c,v 1.48.8.2 2018/08/25 14:45:37 martin Exp $ */ 1/* $NetBSD: histedit.c,v 1.48.8.3 2022/02/24 10:07:46 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.48.8.2 2018/08/25 14:45:37 martin Exp $"); 40__RCSID("$NetBSD: histedit.c,v 1.48.8.3 2022/02/24 10:07:46 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"
@@ -273,27 +273,27 @@ histcmd(volatile int argc, char ** volat @@ -273,27 +273,27 @@ histcmd(volatile int argc, char ** volat
273#endif 273#endif
274 274
275 if (hist == NULL) 275 if (hist == NULL)
276 error("history not active"); 276 error("history not active");
277 277
278 if (argc == 1) 278 if (argc == 1)
279 error("missing history argument"); 279 error("missing history argument");
280 280
281 optreset = 1; optind = 1; /* initialize getopt */ 281 optreset = 1; optind = 1; /* initialize getopt */
282 while (not_fcnumber(argv[optind]) && 282 while (not_fcnumber(argv[optind]) &&
283 (ch = getopt(argc, argv, ":e:lnrs")) != -1) 283 (ch = getopt(argc, argv, ":e:lnrs")) != -1)
284 switch ((char)ch) { 284 switch ((char)ch) {
285 case 'e': 285 case 'e':
286 editor = optionarg; 286 editor = optarg;
287 break; 287 break;
288 case 'l': 288 case 'l':
289 lflg = 1; 289 lflg = 1;
290 break; 290 break;
291 case 'n': 291 case 'n':
292 nflg = 1; 292 nflg = 1;
293 break; 293 break;
294 case 'r': 294 case 'r':
295 rflg = 1; 295 rflg = 1;
296 break; 296 break;
297 case 's': 297 case 's':
298 sflg = 1; 298 sflg = 1;
299 break; 299 break;