View | Details | Raw Unified | Return to bug 169773 | Differences between
and this patch

Collapse All | Expand All

(-)b/bin/sh/histedit.c (-9 / +20 lines)
Lines 67-73 __FBSDID("$FreeBSD$"); Link Here
67
History *hist;	/* history cookie */
67
History *hist;	/* history cookie */
68
EditLine *el;	/* editline cookie */
68
EditLine *el;	/* editline cookie */
69
int displayhist;
69
int displayhist;
70
int histedit_init;
70
static FILE *el_in, *el_out, *el_err;
71
static FILE *el_in, *el_out, *el_err;
72
static int e1v2;
71
73
72
static char *fc_replace(const char *, char *, char *);
74
static char *fc_replace(const char *, char *, char *);
73
static int not_fcnumber(const char *);
75
static int not_fcnumber(const char *);
Lines 76-87 static int str_to_event(const char *, int); Link Here
76
/*
78
/*
77
 * Set history and editing status.  Called whenever the status may
79
 * Set history and editing status.  Called whenever the status may
78
 * have changed (figures out what to do).
80
 * have changed (figures out what to do).
81
 * If force is set then an editline reinit is issued even if the actual edit
82
 * mode hasn't changed - necessary after the locale has changed because
83
 * editline bases it's decision what is reported or not upon isprint(3)
79
 */
84
 */
80
void
85
void
81
histedit(void)
86
histedit(int force)
82
{
87
{
88
	int nedstate;
83
89
84
#define editing (Eflag || Vflag)
90
	if (! histedit_init)
91
		return;
92
93
	histedit_init = 2;
94
	/* options.c ensures these are mutual exclusive */
95
	nedstate = (Eflag ? 1 : 0) | (Vflag ? 2 : 0);
85
96
86
	if (iflag) {
97
	if (iflag) {
87
		if (!hist) {
98
		if (!hist) {
Lines 97-103 histedit(void) Link Here
97
			else
108
			else
98
				out2fmt_flush("sh: can't initialize history\n");
109
				out2fmt_flush("sh: can't initialize history\n");
99
		}
110
		}
100
		if (editing && !el && isatty(0)) { /* && isatty(2) ??? */
111
		if (nedstate && ! el && isatty(0)) { /* && isatty(2) ??? */
101
			/*
112
			/*
102
			 * turn editing on
113
			 * turn editing on
103
			 */
114
			 */
Lines 130-146 bad: Link Here
130
				out2fmt_flush("sh: can't initialize editing\n");
141
				out2fmt_flush("sh: can't initialize editing\n");
131
			}
142
			}
132
			INTON;
143
			INTON;
133
		} else if (!editing && el) {
144
		} else if (! nedstate && el) {
134
			INTOFF;
145
			INTOFF;
135
			el_end(el);
146
			el_end(el);
136
			el = NULL;
147
			el = NULL;
137
			INTON;
148
			INTON;
138
		}
149
		}
139
		if (el) {
150
		if (el && (nedstate != e1v2 || force)) {
140
			if (Vflag)
151
			el_set(el, EL_EDITOR, (nedstate & 1) ? "emacs" : "vi");
141
				el_set(el, EL_EDITOR, "vi");
142
			else if (Eflag)
143
				el_set(el, EL_EDITOR, "emacs");
144
			el_set(el, EL_BIND, "^I", "sh-complete", NULL);
152
			el_set(el, EL_BIND, "^I", "sh-complete", NULL);
145
			el_source(el, NULL);
153
			el_source(el, NULL);
146
		}
154
		}
Lines 155-161 bad: Link Here
155
			hist = NULL;
163
			hist = NULL;
156
		}
164
		}
157
		INTON;
165
		INTON;
166
		nedstate = 0;
158
	}
167
	}
168
169
	e1v2 = nedstate;
159
}
170
}
160
171
161
172
(-)b/bin/sh/input.c (-3 / +3 lines)
Lines 59-66 __FBSDID("$FreeBSD$"); Link Here
59
#include "error.h"
59
#include "error.h"
60
#include "alias.h"
60
#include "alias.h"
61
#include "parser.h"
61
#include "parser.h"
62
#include "myhistedit.h"
63
#include "trap.h"
62
#include "trap.h"
63
#ifndef NO_HISTORY
64
# include "myhistedit.h"
65
#endif
64
66
65
#define EOF_NLEFT -99		/* value of parsenleft when EOF pushed back */
67
#define EOF_NLEFT -99		/* value of parsenleft when EOF pushed back */
66
68
Lines 102-109 static struct parsefile *parsefile = &basepf; /* current input file */ Link Here
102
int init_editline = 0;		/* editline library initialized? */
104
int init_editline = 0;		/* editline library initialized? */
103
int whichprompt;		/* 1 == PS1, 2 == PS2 */
105
int whichprompt;		/* 1 == PS1, 2 == PS2 */
104
106
105
EditLine *el;			/* cookie for editline package */
106
107
static void pushfile(void);
107
static void pushfile(void);
108
static int preadfd(void);
108
static int preadfd(void);
109
static void popstring(void);
109
static void popstring(void);
(-)b/bin/sh/main.c (-1 / +12 lines)
Lines 73-78 __FBSDID("$FreeBSD$"); Link Here
73
#include "exec.h"
73
#include "exec.h"
74
#include "cd.h"
74
#include "cd.h"
75
#include "builtins.h"
75
#include "builtins.h"
76
#ifndef NO_HISTORY
77
# include "myhistedit.h"
78
#endif
76
79
77
int rootpid;
80
int rootpid;
78
int rootshell;
81
int rootshell;
Lines 144-151 main(int argc, char *argv[]) Link Here
144
	setstackmark(&smark2);
147
	setstackmark(&smark2);
145
	procargs(argc, argv);
148
	procargs(argc, argv);
146
	pwd_init(iflag);
149
	pwd_init(iflag);
147
	if (iflag)
150
	if (iflag) {
148
		chkmail(1);
151
		chkmail(1);
152
#ifndef NO_HISTORY
153
		histedit_init = 1;
154
#endif
155
	}
149
	if (argv[0] && argv[0][0] == '-') {
156
	if (argv[0] && argv[0][0] == '-') {
150
		state = 1;
157
		state = 1;
151
		read_profile("/etc/profile");
158
		read_profile("/etc/profile");
Lines 157-162 state1: Link Here
157
			read_profile("/etc/suid_profile");
164
			read_profile("/etc/suid_profile");
158
	}
165
	}
159
state2:
166
state2:
167
#ifndef NO_HISTORY
168
	if (iflag && histedit_init != 2)
169
		histedit(1);
170
#endif
160
	state = 3;
171
	state = 3;
161
	if (!privileged && iflag) {
172
	if (!privileged && iflag) {
162
		if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') {
173
		if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') {
(-)b/bin/sh/myhistedit.h (-2 / +2 lines)
Lines 35-42 Link Here
35
extern History *hist;
35
extern History *hist;
36
extern EditLine *el;
36
extern EditLine *el;
37
extern int displayhist;
37
extern int displayhist;
38
extern int histedit_init;
38
39
39
void histedit(void);
40
void histedit(int);
40
void sethistsize(const char *);
41
void sethistsize(const char *);
41
void setterm(const char *);
42
void setterm(const char *);
42
(-)b/bin/sh/options.c (-2 / +2 lines)
Lines 58-64 __FBSDID("$FreeBSD$"); Link Here
58
#include "mystring.h"
58
#include "mystring.h"
59
#include "builtins.h"
59
#include "builtins.h"
60
#ifndef NO_HISTORY
60
#ifndef NO_HISTORY
61
#include "myhistedit.h"
61
# include "myhistedit.h"
62
#endif
62
#endif
63
63
64
char *arg0;			/* value of $0 */
64
char *arg0;			/* value of $0 */
Lines 131-137 optschanged(void) Link Here
131
{
131
{
132
	setinteractive(iflag);
132
	setinteractive(iflag);
133
#ifndef NO_HISTORY
133
#ifndef NO_HISTORY
134
	histedit();
134
	histedit(0);
135
#endif
135
#endif
136
	setjobctl(mflag);
136
	setjobctl(mflag);
137
}
137
}
(-)b/bin/sh/trap.c (-2 / +3 lines)
Lines 56-63 __FBSDID("$FreeBSD$"); Link Here
56
#include "trap.h"
56
#include "trap.h"
57
#include "mystring.h"
57
#include "mystring.h"
58
#include "builtins.h"
58
#include "builtins.h"
59
#include "myhistedit.h"
59
#ifndef NO_HISTORY
60
60
# include "myhistedit.h"
61
#endif
61
62
62
/*
63
/*
63
 * Sigmode records the current value of the signal handlers for the various
64
 * Sigmode records the current value of the signal handlers for the various
(-)b/bin/sh/var.c (-1 / +4 lines)
Lines 65-71 __FBSDID("$FreeBSD$"); Link Here
65
#include "parser.h"
65
#include "parser.h"
66
#include "builtins.h"
66
#include "builtins.h"
67
#ifndef NO_HISTORY
67
#ifndef NO_HISTORY
68
#include "myhistedit.h"
68
# include "myhistedit.h"
69
#endif
69
#endif
70
70
71
71
Lines 523-528 updatecharset(void) Link Here
523
523
524
	charset = nl_langinfo(CODESET);
524
	charset = nl_langinfo(CODESET);
525
	localeisutf8 = !strcmp(charset, "UTF-8");
525
	localeisutf8 = !strcmp(charset, "UTF-8");
526
#ifndef NO_HISTORY
527
	histedit(1);
528
#endif
526
}
529
}
527
530
528
void
531
void

Return to bug 169773