Skip to content

Commit

Permalink
Shell-escape filenames in history so they can be used again.
Browse files Browse the repository at this point in the history
Use PCRE_UTF8 flag for pcre regular expressions when in UTF-8 mode.
Windows: use wide-char string to set console title.
  • Loading branch information
gwsw committed Aug 3, 2018
1 parent 7d480c6 commit b61df4a
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 14 deletions.
6 changes: 6 additions & 0 deletions NEWS.VER
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

* Redraw screen on SIGWINCH even if screen size doesn't change.

* Shell-escape filenames in history so they can be used again.

* Use PCRE_UTF8 flag for pcre regular expressions when in UTF-8 mode.

* Windows: use wide-char string to set console title.

* Fix bug in v command on empty file.

* Fix bug in v command when filename contains shell metacharacters.
Expand Down
3 changes: 2 additions & 1 deletion cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ cmd_updown(action)
s = ml->string;
if (s == NULL)
s = "";
cmd_offset = 0;
cmd_home();
clear_eol();
strcpy(cmdbuf, s);
Expand Down Expand Up @@ -805,7 +806,7 @@ cmd_accept()
/*
* Nothing to do if there is no currently selected history list.
*/
if (curr_mlist == NULL)
if (curr_mlist == NULL || curr_mlist == ml_examine)
return;
cmd_addhist(curr_mlist, cmdbuf, 1);
curr_mlist->modified = 1;
Expand Down
19 changes: 18 additions & 1 deletion command.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ extern int screen_trashed; /* The screen has been overwritten */
extern int shift_count;
extern int oldbot;
extern int forw_prompt;
#if MSDOS_COMPILER==WIN32C
extern int utf_mode;
#endif

#if SHELL_ESCAPE
static char *shellcmd = NULL; /* For holding last shell command for "!!" */
Expand Down Expand Up @@ -726,7 +729,13 @@ prompt()
* In Win32, display the file name in the window title.
*/
if (!(ch_getflags() & CH_HELPFILE))
SetConsoleTitle(pr_expand("Less?f - %f.", 0));
{
WCHAR w[MAX_PATH+16];
p = pr_expand("Less?f - %f.", 0);
MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w));
SetConsoleTitleW(w);
}

#endif
/*
* Select the proper prompt and display it.
Expand All @@ -752,6 +761,14 @@ prompt()
putchr(':');
else
{
#if MSDOS_COMPILER==WIN32C
WCHAR w[MAX_PATH*2];
char a[MAX_PATH*2];
MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w));
WideCharToMultiByte(utf_mode ? CP_UTF8 : GetConsoleOutputCP(),
0, w, -1, a, sizeof(a), NULL, NULL);
p = a;
#endif
at_enter(AT_STANDOUT);
putstr(p);
at_exit();
Expand Down
7 changes: 6 additions & 1 deletion edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,12 @@ edit_ifile(ifile)
clr_hilite();
#endif
if (strcmp(filename, FAKE_HELPFILE) && strcmp(filename, FAKE_EMPTYFILE))
cmd_addhist(ml_examine, filename, 1);
{
char *qfilename = shell_quote(filename);
cmd_addhist(ml_examine, qfilename, 1);
free(qfilename);
}

if (no_display && errmsgs > 0)
{
/*
Expand Down
2 changes: 2 additions & 0 deletions filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,9 @@ readfd(fd)

#if HAVE_POPEN

#if MSDOS_COMPILER!=WIN32C
FILE *popen();
#endif

/*
* Execute a shell command.
Expand Down
6 changes: 3 additions & 3 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extern int sc_width, sc_height;
extern int utf_mode;
extern POSITION start_attnpos;
extern POSITION end_attnpos;
extern LWCHAR rscroll_char;
extern char rscroll_char;
extern int rscroll_attr;

static char mbc_buf[MAX_UTF_CHAR_LEN];
Expand Down Expand Up @@ -172,7 +172,7 @@ prewind()
static void
set_linebuf(n, ch, a)
int n;
LWCHAR ch;
char ch;
char a;
{
linebuf[n] = ch;
Expand All @@ -184,7 +184,7 @@ set_linebuf(n, ch, a)
*/
static void
add_linebuf(ch, a, w)
LWCHAR ch;
char ch;
char a;
int w;
{
Expand Down
2 changes: 1 addition & 1 deletion optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern int jump_sline;
extern long jump_sline_fraction;
extern int shift_count;
extern long shift_count_fraction;
extern LWCHAR rscroll_char;
extern char rscroll_char;
extern int rscroll_attr;
extern int less_is_more;
#if LOGFILE
Expand Down
2 changes: 1 addition & 1 deletion opttbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public int quit_on_intr; /* Quit on interrupt */
public int follow_mode; /* F cmd Follows file desc or file name? */
public int oldbot; /* Old bottom of screen behavior {{REMOVE}} */
public int opt_use_backslash; /* Use backslash escaping in option parsing */
public LWCHAR rscroll_char; /* Char which marks chopped lines with -S */
public char rscroll_char; /* Char which marks chopped lines with -S */
public int rscroll_attr; /* Attribute of rscroll_char */
public int no_hist_dups; /* Remove dups from history list */
#if HILITE_SEARCH
Expand Down
7 changes: 5 additions & 2 deletions pattern.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "less.h"

extern int caseless;
#if HAVE_PCRE
extern int utf_mode;
#endif

/*
* Compile a search pattern, for future use by match_pattern.
Expand Down Expand Up @@ -56,11 +59,11 @@ compile_pattern2(pattern, search_type, comp_pattern, show_error)
*comp_pattern = comp;
#endif
#if HAVE_PCRE
pcre *comp;
constant char *errstring;
int erroffset;
PARG parg;
comp = pcre_compile(pattern, 0,
pcre *comp = pcre_compile(pattern,
(utf_mode) ? PCRE_UTF8 | PCRE_NO_UTF8_CHECK : 0,
&errstring, &erroffset, NULL);
if (comp == NULL)
{
Expand Down
11 changes: 8 additions & 3 deletions signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern long jump_sline_fraction;
/*
* Interrupt signal handler.
*/
#if MSDOS_COMPILER!=WIN32C
/* ARGSUSED*/
static RETSIGTYPE
u_interrupt(type)
Expand All @@ -54,6 +55,7 @@ u_interrupt(type)
if (reading)
intread(); /* May longjmp */
}
#endif

#ifdef SIGTSTP
/*
Expand Down Expand Up @@ -100,7 +102,8 @@ winch(type)
/*
* Handle CTRL-C and CTRL-BREAK keys.
*/
#include "windows.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

static BOOL WINAPI
wbreak_handler(dwCtrlType)
Expand Down Expand Up @@ -138,9 +141,10 @@ init_signals(on)
/*
* Set signal handlers.
*/
(void) LSIGNAL(SIGINT, u_interrupt);
#if MSDOS_COMPILER==WIN32C
SetConsoleCtrlHandler(wbreak_handler, TRUE);
#else
(void) LSIGNAL(SIGINT, u_interrupt);
#endif
#ifdef SIGTSTP
(void) LSIGNAL(SIGTSTP, stop);
Expand All @@ -162,9 +166,10 @@ init_signals(on)
/*
* Restore signals to defaults.
*/
(void) LSIGNAL(SIGINT, SIG_DFL);
#if MSDOS_COMPILER==WIN32C
SetConsoleCtrlHandler(wbreak_handler, FALSE);
#else
(void) LSIGNAL(SIGINT, SIG_DFL);
#endif
#ifdef SIGTSTP
(void) LSIGNAL(SIGTSTP, SIG_DFL);
Expand Down
4 changes: 3 additions & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,8 @@ v530 12/2/17 Minor doc change and add missing VOID_PARAM.
v531 5/13/18 Fix bug with v on empty file; fix bug with v on file with
metachars in name; add --nohistdups option.
v532 7/27/18 Redraw screen on SIGWINCH even if screen size doesn't change.
v533 8/1/18 Shell escape filenames in history; use PCRE_UTF8 flag;
use wide-chars for Windows console title (thanks to Jason Hood).
*/

char version[] = "532";
char version[] = "533";

0 comments on commit b61df4a

Please sign in to comment.