Skip to content

Commit

Permalink
Add lessecho; make spaces in filenames work on Unix.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Aug 21, 1996
1 parent 1c1d87a commit 17874e2
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 38 deletions.
7 changes: 5 additions & 2 deletions Makefile.aut
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DISTFILES_W = \
DISTFILES = \
${SRC} regexp.c regexp.h \
INSTALL Makefile.in Makefile.aut README NEWS \
configure configure.in acconfig.h lesskey.c \
configure configure.in acconfig.h lesskey.c lessecho.c \
cmd.h funcs.h less.h lesskey.h option.h pckeys.h position.h \
install.sh defines.h.in defines.h.top mkinstalldirs \
less.nro lesskey.nro less.man lesskey.man less.hlp \
Expand All @@ -37,7 +37,10 @@ help.c: less.hlp mkhelp
mkhelp: mkhelp.c
${CC} -o mkhelp mkhelp.c

${srcdir}/configure: ${srcdir}/configure.in
${srcdir}/configure: ${srcdir}/configure.in \
${srcdir}/Makefile.in \
${srcdir}/defines.h.top \
${srcdir}/acconfig.h
cd ${srcdir}; autoheader; autoconf

funcs.h: ${SRC:%=${srcdir}/%}
Expand Down
10 changes: 7 additions & 3 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,31 @@ OBJ = main.${O} screen.${O} brac.${O} ch.${O} charset.${O} cmdbuf.${O} \
output.${O} position.${O} prompt.${O} search.${O} signal.${O} \
tags.${O} ttyin.${O} version.${O} @REGEX_O@

all: less lesskey
all: less lesskey lessecho

less: ${OBJ}
${CC} ${LDFLAGS} -o $@ ${OBJ} ${LIBS}

lesskey: lesskey.${O} version.${O}
${CC} ${LDFLAGS} -o $@ lesskey.${O} version.${O}

lessecho: lessecho.${O} version.${O}
${CC} ${LDFLAGS} -o $@ lessecho.${O} version.${O}

${OBJ}: ${srcdir}/less.h ${srcdir}/funcs.h defines.h

install: all ${srcdir}/less.nro ${srcdir}/lesskey.nro installdirs
${INSTALL_PROGRAM} less ${bindir}/${binprefix}less
${INSTALL_PROGRAM} lesskey ${bindir}/${binprefix}lesskey
${INSTALL_PROGRAM} lessecho ${bindir}/${binprefix}lessecho
${INSTALL_DATA} ${srcdir}/less.nro ${mandir}/${manprefix}less.${manext}
${INSTALL_DATA} ${srcdir}/lesskey.nro ${mandir}/${manprefix}lesskey.${manext}

installdirs: mkinstalldirs
${srcdir}/mkinstalldirs ${bindir} ${mandir}

uninstall:
rm -f ${bindir}/${binprefix}less ${bindir}/${binprefix}lesskey
rm -f ${bindir}/${binprefix}less ${bindir}/${binprefix}lesskey ${bindir}/${binprefix}lessecho
rm -f ${mandir}/less.${manext} ${mandir}/lesskey.${manext}

info:
Expand All @@ -91,7 +95,7 @@ ${srcdir}/configure: ${srcdir}/configure.in
cd ${srcdir}; autoheader; autoconf

clean:
rm -f *.${O} core less lesskey
rm -f *.${O} core less lesskey lessecho

mostlyclean: clean

Expand Down
4 changes: 3 additions & 1 deletion decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ lesskey(filename)
/*
* Try to open the lesskey file.
*/
f = open(UNQUOTE_FILE(filename), OPEN_READ);
filename = unquote_file(filename);
f = open(filename, OPEN_READ);
free(filename);
if (f < 0)
return (1);

Expand Down
9 changes: 7 additions & 2 deletions edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ edit_ifile(ifile)
return (0);
}

filename = UNQUOTE_FILE(get_filename(ifile));
filename = unquote_file(get_filename(ifile));
/*
* See if LESSOPEN specifies an "alternate" file to open.
*/
Expand Down Expand Up @@ -307,6 +307,7 @@ edit_ifile(ifile)
free(alt_filename);
}
del_ifile(ifile);
free(filename);
/*
* Re-open the current file.
*/
Expand Down Expand Up @@ -393,6 +394,7 @@ edit_ifile(ifile)
error("%s", &parg);
}
}
free(filename);
return (0);
}

Expand Down Expand Up @@ -696,7 +698,7 @@ use_logfile(filename)
/*
* {{ We could use access() here. }}
*/
filename = UNQUOTE_FILE(filename);
filename = unquote_file(filename);
exists = open(filename, OPEN_READ);
close(exists);
exists = (exists >= 0);
Expand Down Expand Up @@ -744,6 +746,7 @@ use_logfile(filename)
/*
* Don't do anything.
*/
free(filename);
return;
case 'q':
quit(QUIT_OK);
Expand All @@ -763,8 +766,10 @@ use_logfile(filename)
*/
parg.p_string = filename;
error("Cannot write to \"%s\"", &parg);
free(filename);
return;
}
free(filename);
SET_BINARY(logfile);
}

Expand Down
50 changes: 32 additions & 18 deletions filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,32 @@ extern int secure;
extern IFILE curr_ifile;
extern IFILE old_ifile;

#if SPACES_IN_FILENAMES
/*
* Remove quotes around a filename.
*/
public char *
unquote_file(str)
char *str;
{
static char name[_MAX_PATH];
char *p = name;
#if SPACES_IN_FILENAMES
char *name;
char *p;

if (strchr(str, '"') == NULL)
return str;

while (*str && (p < &name[sizeof name - 1]))
return (save(str));
name = p = ecalloc(strlen(str)+1, sizeof(char));
while (*str != '\0')
{
if (*str != '"')
{
*p = *str;
p++;
}
*p++ = *str;
str++;
}
*p = '\0';

return name;
}
return (name);
#else
return (save(str));
#endif
}

/*
* Return a pathname that points to a specified file in a specified directory.
Expand All @@ -94,6 +92,7 @@ dirfile(dirname, filename)
char *filename;
{
char *pathname;
char *qpathname;
int f;

if (dirname == NULL || *dirname == '\0')
Expand All @@ -109,7 +108,8 @@ dirfile(dirname, filename)
/*
* Make sure the file exists.
*/
f = open(UNQUOTE_FILE(pathname), OPEN_READ);
qpathname = unquote_file(pathname);
f = open(qpathname, OPEN_READ);
if (f < 0)
{
free(pathname);
Expand All @@ -118,6 +118,7 @@ dirfile(dirname, filename)
{
close(f);
}
free(qpathname);
return (pathname);
}

Expand Down Expand Up @@ -548,7 +549,10 @@ lglob(filename)
return (filename);
}

fd = shellcmd("echo %s", filename, (char*)NULL);
s = lgetenv("LESSECHO");
if (s == NULL || *s == '\0')
s = "lessecho";
fd = shellcmd("%s %s", s, filename);
if (fd == NULL)
{
/*
Expand Down Expand Up @@ -733,6 +737,7 @@ lglob(filename)
char *filename;
{
register char *gfilename;
register char *qfilename;
register char *p;
register int len;
register int n;
Expand All @@ -746,11 +751,15 @@ lglob(filename)
if (secure)
return (filename);

handle = FIND_FIRST(UNQUOTE_FILE(filename), &fnd);
qfilename = unquote_file(filename);
handle = FIND_FIRST(qfilename, &fnd);
if (BAD_HANDLE(handle))
{
free(qfilename);
return (filename);
}

_splitpath(UNQUOTE_FILE(filename), drive, dir, fname, ext);
_splitpath(qfilename, drive, dir, fname, ext);
len = 100;
gfilename = (char *) ecalloc(len, sizeof(char));
p = gfilename;
Expand Down Expand Up @@ -793,6 +802,7 @@ lglob(filename)
*/
*--p = '\0';
FIND_CLOSE(handle);
free(qfilename);
return (gfilename);
}

Expand Down Expand Up @@ -864,9 +874,13 @@ bad_file(filename)
char *filename;
{
register char *m;
int r;
struct stat statbuf;

if (stat(UNQUOTE_FILE(filename), &statbuf) < 0)
m = unquote_file(filename);
r = stat(m, &statbuf);
free(m);
if (r < 0)
return (errno_message(filename));

if (force_open)
Expand Down
3 changes: 2 additions & 1 deletion forwback.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ forw(n, pos, force, only_last, nblank)
eof = 1;
if (!force && position(TOP) != NULL_POSITION)
break;
if (empty_lines(2, sc_height-1))
if (empty_lines(2, sc_height-1) &&
!empty_lines(0, 0))
break;
}
}
Expand Down
6 changes: 0 additions & 6 deletions less.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,7 @@ typedef long POSITION;
#define SHELL_META_QUEST 1
#endif

#if MSDOS_COMPILER || OS2
#define SPACES_IN_FILENAMES 1
#define UNQUOTE_FILE(x) unquote_file(x)
#else
#define SPACES_IN_FILENAMES 0
#define UNQUOTE_FILE(x) (x)
#endif

/*
* An IFILE represents an input file.
Expand Down
4 changes: 4 additions & 0 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,10 @@ Defines a character set.
Selects a predefined character set.
.IP LESSCLOSE
Command line to invoke the (optional) input-postprocessor.
.IP LESSECHO
Name of the lessecho program (default "lessecho").
The lessecho program is needed to expand metacharacters, such as * and ?,
in filenames on Unix systems.
.IP LESSEDIT
Editor prototype string (used for the v command).
See discussion under PROMPTS.
Expand Down
9 changes: 6 additions & 3 deletions optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ opt_o(type, s)
error("No log file", NULL_PARG);
else
{
parg.p_string = UNQUOTE_FILE(namelogfile);
parg.p_string = unquote_file(namelogfile);
error("Log file \"%s\"", &parg);
free(parg.p_string);
}
break;
}
Expand Down Expand Up @@ -179,8 +180,9 @@ opt_k(type, s)
case INIT:
if (lesskey(s))
{
parg.p_string = UNQUOTE_FILE(s);
parg.p_string = unquote_file(s);
error("Cannot use lesskey file \"%s\"", &parg);
free(parg.p_string);
}
break;
}
Expand Down Expand Up @@ -246,8 +248,9 @@ opt__T(type, s)
tags = lglob(s);
break;
case QUERY:
parg.p_string = UNQUOTE_FILE(tags);
parg.p_string = unquote_file(tags);
error("Tags file \"%s\"", &parg);
free(parg.p_string);
break;
}
}
Expand Down
5 changes: 4 additions & 1 deletion tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ findtag(tag)
int err;
char tline[TAGLINE_SIZE];

if ((f = fopen(UNQUOTE_FILE(tags), "r")) == NULL)
p = unquote_file(tags);
f = fopen(p, "r");
free(p);
if (f == NULL)
{
error("No tags file", NULL_PARG);
tagfile = NULL;
Expand Down
3 changes: 2 additions & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ v323 8/19/96 Fixes for Windows version (thanks to Simon Munton);
fix for Linux library weirdness (thanks to Jim Diamond);
port to DJGPP (thanks to Eli Zaretskii).
v324 8/21/96 Add support for spaces in filenames (thanks to Simon Munton).
v325 8/21/96 Add lessecho, for spaces in filenames under Unix.
*/

char version[] = "324";
char version[] = "325";

0 comments on commit 17874e2

Please sign in to comment.