Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove var viraw #865

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ None at this time.

## Notable non-backward compatible changes

- Vi raw mode is now the default and cannot be disabled (issue #864).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not look like a backward incompatible change to me. I see this entry in RELEASE file:

01-11-26 +The default has compilation mode has been changes so that
              viraw mode will always be on.

I can not disable viraw mode in version of ksh that is shipped with RHEL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that "the default compilation mode" simply means that viraw was enabled by default. The second clause of that sentence seems to be independent of the first clause. And looking at the source in the legacy ast.master and ast.beta branches it is not at all obvious you can't disable viraw behavior. Nonetheless, I'm happy to move this statement about viraw to the "Other significant changes" section.

- Support for the `universe` command has been removed (issue #793).
- Support for building on systems using EBCDIC has been removed (issue #742).
- Support for the `LC_OPTIONS` env var has been removed (issue #579).
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/ksh93/data/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ const char sh_set[] =
"[+trackall?Equivalent to \b-h\b.]"
"[+verbose?Equivalent to \b-v\b.]"
"[+vi?Enables/disables \bvi\b editing mode.]"
"[+viraw?Does not use canonical input mode when using \bvi\b "
"edit mode.]"
"[+viraw?This option no longer does anything.]"
"[+xtrace?Equivalent to \b-x\b.]"
"}"
"[p?Privileged mode. Disabling \b-p\b sets the effective user id to the "
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/ksh93/data/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ const Shtable_t shtab_options[] = {{"allexport", SH_ALLEXPORT},
{"nounset", SH_NOUNSET},
{"verbose", SH_VERBOSE},
{"vi", SH_VI},
// This option is now always enabled and disabling it has no
// effect.
{"viraw", SH_VIRAW},

#if SHOPT_BASH
Expand Down
119 changes: 1 addition & 118 deletions src/cmd/ksh93/edit/vi.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ static void vigetline(Vi_t *, int);
static int getrchar(Vi_t *);
static int mvcursor(Vi_t *, int);
static void pr_string(Vi_t *, const char *);
static void putstring(Vi_t *, int, int);
static void refresh(Vi_t *, int);
static void replace(Vi_t *, int, int);
static void restore_v(Vi_t *);
Expand All @@ -183,17 +182,13 @@ static int textmod(Vi_t *, int, int);
int ed_viread(void *context, int fd, char *shbuf, int nchar, int reedit) {
Edit_t *ed = (Edit_t *)context;
int i; // general variable
int term_char = 0; // read() termination character
Vi_t *vp = ed->e_vi;
char prompt[PRSIZE + 2]; // prompt
genchar Physical[2 * MAXLINE]; // physical image
genchar Ubuf[MAXLINE]; // used for U command
genchar ubuf[MAXLINE]; // used for u command
genchar Window[MAXLINE]; // window image
int Globals[9]; // local global variables
int esc_or_hang = 0; // <ESC> or hangup
char cntl_char = 0; // TRUE if control character present
#define viraw 1

if (!vp) {
ed->e_vi = vp = calloc(1, sizeof(Vi_t));
Expand Down Expand Up @@ -252,104 +247,6 @@ int ed_viread(void *context, int fd, char *shbuf, int nchar, int reedit) {
if (nchar + plen > MAXCHAR) nchar = MAXCHAR - plen;
max_col = nchar - 2;

if (!viraw) {
int kill_erase = 0;
for (i = (echoctl ? last_virt : 0); i < last_virt; ++i) {
// Change \r to \n, check for control characters, delete appropriate ^Vs,
// and estimate last physical column.
if (virtual[i] == '\r') virtual[i] = '\n';
if (echoctl) continue;
int c = virtual[i];
if (c <= usrerase) {
// User typed escaped erase or kill char.
cntl_char = 1;
if (is_print(c)) kill_erase++;
} else if (!is_print(c)) {
cntl_char = 1;
if (c == usrlnext) {
if (i == last_virt) {
// Eol/eof was escaped so replace ^V with it.
virtual[i] = term_char;
break;
}

// Delete ^V.
gencpy((&virtual[i]), (&virtual[i + 1]));
--cur_virt;
--last_virt;
}
}
}

// Copy virtual image to window.
if (last_virt > 0) last_phys = ed_virt_to_phys(vp->ed, virtual, physical, last_virt, 0, 0);
if (last_phys >= w_size) {
// Line longer than window.
vp->last_wind = w_size - 1;
} else {
vp->last_wind = last_phys;
}
genncpy(window, virtual, vp->last_wind + 1);

if (term_char != ESC && (last_virt == INVALID || virtual[last_virt] != term_char)) {
// Line not terminated with ESC or escaped (^V) eol, so return after doing a total
// update. if( (speed is greater or equal to 1200 and something was typed) and (control
// character present or typeahead occurred).
tty_cooked(ERRIO);
if (editb.e_ttyspeed == FAST && last_virt != INVALID && (vp->typeahead || cntl_char)) {
refresh(vp, TRANSLATE);
pr_string(vp, Prompt);
putstring(vp, 0, last_phys + 1);
if (echoctl) {
ed_crlf(vp->ed);
} else {
while (kill_erase-- > 0) putchar(' ');
}
}

if (term_char == '\n') {
if (!echoctl) ed_crlf(vp->ed);
virtual[++last_virt] = '\n';
}
vp->last_cmd = 'i';
save_last(vp);
virtual[last_virt + 1] = 0;
last_virt = ed_external(virtual, shbuf);
return (last_virt);
}

// Line terminated with escape, or escaped eol/eof, so set raw mode.
if (tty_raw(ERRIO, 0) < 0) {
tty_cooked(ERRIO);
// The following prevents drivers that return 0 on causing an infinite loop.
if (esc_or_hang) return -1;
virtual[++last_virt] = '\n';
virtual[last_virt + 1] = 0;
last_virt = ed_external(virtual, shbuf);
return last_virt;
}

if (echoctl) { // for cntl-echo erase the ^[
pr_string(vp, "\b\b\b\b \b\b");
}

if (crallowed) {
// Start over since there may be a control char, or cursor might not be at left margin
// (this lets us know where we are.
cur_phys = 0;
window[0] = '\0';
pr_string(vp, Prompt);
if (term_char == ESC && (last_virt < 0 || virtual[last_virt] != ESC)) {
refresh(vp, CONTROL);
} else {
refresh(vp, INPUT);
}
} else {
// Just update everything internally.
refresh(vp, TRANSLATE);
}
}

// Handle usrintr, usrquit, or EOF.
i = sigsetjmp(editb.e_env, 0);
if (i != 0) {
Expand Down Expand Up @@ -378,13 +275,7 @@ int ed_viread(void *context, int fd, char *shbuf, int nchar, int reedit) {
vp->ofirst_wind = INVALID;
refresh(vp, INPUT);
}
if (viraw) {
vigetline(vp, APPEND);
} else if (last_virt >= 0 && virtual[last_virt] == term_char) {
vigetline(vp, APPEND);
} else {
vigetline(vp, ESC);
}
vigetline(vp, APPEND);
if (vp->ed->e_multiline) cursor(vp, last_phys);
// Add a new line if user typed unescaped \n to cause the shell to process the line.
tty_cooked(ERRIO);
Expand Down Expand Up @@ -1354,14 +1245,6 @@ static_fn void pr_string(Vi_t *vp, const char *sp) {
return;
}

//
// Put nchars starting at column of physical into the workspace to be printed.
//
static_fn void putstring(Vi_t *vp, int col, int nchars) {
while (nchars--) putchar(physical[col++]);
return;
}

//
// This routine will refresh the crt so the physical image matches the virtual image and display the
// proper window.
Expand Down
1 change: 1 addition & 0 deletions src/cmd/ksh93/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef union Shnode_u Shnode_t;
#define SH_MARKDIRS 15
#define SH_BGNICE 16
#define SH_VI 17
// The "viraw" option no longer has any effect as its behavior is now always eanbled.
#define SH_VIRAW 18
#define SH_TFLAG 19
#define SH_TRACKALL 20
Expand Down
5 changes: 1 addition & 4 deletions src/cmd/ksh93/ksh.1
Original file line number Diff line number Diff line change
Expand Up @@ -5230,8 +5230,6 @@ Delete previous character.
.TP 10
.BI ^W
Delete the previous blank separated word.
On some systems the \f3viraw\fP option
may be required for this to work.
.TP 10
.I eof
As the first character of the line causes
Expand All @@ -5248,8 +5246,6 @@ or
if not defined.)
Removes the next character's
editing features (if any).
On some systems the \f3viraw\fP option
may be required for this to work.
.TP 10
.BI \e
Escape the next
Expand Down Expand Up @@ -7261,6 +7257,7 @@ Each character is processed as it is typed
in
.I vi\^
mode.
This is now always enabled. Disabling the option at run time has no effect.
.TP 8
.B xtrace
Same as
Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/sh/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,6 @@ void sh_printopts(Shell_t *shp, Shopt_t oflags, int mode, Shopt_t *mask) {
return;
}

on_option(&oflags, SH_VIRAW);
if (!(mode & (PRINT_ALL | PRINT_VERBOSE))) { // only print set options
if (mode & PRINT_SHOPT) {
sfwrite(sfstdout, "shopt -s", 3);
Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/sh/bash.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ int b_shopt(int argc, char *argv[], Shbltin_t *extra) {
int setflag = 0, quietflag = 0, oflag = 0;

memset(&opt, 0, sizeof(opt));
on_option(&newflags, SH_VIRAW);
while ((n = optget(argv, sh_optshopt))) {
switch (n) {
case 'p': {
Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/sh/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,6 @@ int sh_reinit_20120720(Shell_t *shp, char *argv[]) {
if (sh_isoption(shp, SH_EMACS)) on_option(&opt, SH_EMACS);
if (sh_isoption(shp, SH_GMACS)) on_option(&opt, SH_GMACS);
if (sh_isoption(shp, SH_VI)) on_option(&opt, SH_VI);
if (sh_isoption(shp, SH_VIRAW)) on_option(&opt, SH_VIRAW);
shp->options = opt;
// Set up new args.
if (argv) shp->arglist = sh_argcreate(argv);
Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/sh/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ void job_init(Shell_t *shp, int lflag) {
#endif /* FIOLOOKLD */
if (job.linedisc != NTTYDISC && job.linedisc != OTTYDISC) {
// No job control when running with MPX.
sh_onoption(shp, SH_VIRAW);
return;
}
if (job.linedisc == NTTYDISC) job.linedisc = -1;
Expand Down