summaryrefslogtreecommitdiffstats
path: root/contrib/less/edit.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2004-04-17 07:16:34 +0000
committertjr <tjr@FreeBSD.org>2004-04-17 07:16:34 +0000
commit44c4d557e2436dfbb703a9fc3e78fac79c574d4b (patch)
treef46d7e51d83360c5b6bdacf5b08e16a415ed61b5 /contrib/less/edit.c
parentc0c85bc41cb6c023adae56cf0a7e3495bd528cb2 (diff)
downloadFreeBSD-src-44c4d557e2436dfbb703a9fc3e78fac79c574d4b.zip
FreeBSD-src-44c4d557e2436dfbb703a9fc3e78fac79c574d4b.tar.gz
Import less v381.
Diffstat (limited to 'contrib/less/edit.c')
-rw-r--r--contrib/less/edit.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/contrib/less/edit.c b/contrib/less/edit.c
index 1b3c35d..4873c1f 100644
--- a/contrib/less/edit.c
+++ b/contrib/less/edit.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2000 Mark Nudelman
+ * Copyright (C) 1984-2002 Mark Nudelman
*
* You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file.
@@ -54,7 +54,10 @@ init_textlist(tlist, str)
{
char *s;
#if SPACES_IN_FILENAMES
- int quoted = 0;
+ int meta_quoted = 0;
+ int delim_quoted = 0;
+ char *esc = get_meta_escape();
+ int esclen = strlen(esc);
#endif
tlist->string = skipsp(str);
@@ -62,12 +65,25 @@ init_textlist(tlist, str)
for (s = str; s < tlist->endstring; s++)
{
#if SPACES_IN_FILENAMES
- if (*s == ' ' && !quoted)
- *s = '\0';
- if (!quoted && *s == openquote)
- quoted = 1;
- else if (quoted && *s == closequote)
- quoted = 0;
+ if (meta_quoted)
+ {
+ meta_quoted = 0;
+ } else if (esclen > 0 && s + esclen < tlist->endstring &&
+ strncmp(s, esc, esclen) == 0)
+ {
+ meta_quoted = 1;
+ s += esclen - 1;
+ } else if (delim_quoted)
+ {
+ if (*s == closequote)
+ delim_quoted = 0;
+ } else /* (!delim_quoted) */
+ {
+ if (*s == openquote)
+ delim_quoted = 1;
+ else if (*s == ' ')
+ *s = '\0';
+ }
#else
if (*s == ' ')
*s = '\0';
@@ -132,7 +148,6 @@ back_textlist(tlist, prev)
close_file()
{
struct scrpos scrpos;
- char *filename;
if (curr_ifile == NULL_IFILE)
return;
@@ -157,9 +172,8 @@ close_file()
*/
if (curr_altfilename != NULL)
{
- filename = unquote_file(get_filename(curr_ifile));
- close_altfile(curr_altfilename, filename, curr_altpipe);
- free(filename);
+ close_altfile(curr_altfilename, get_filename(curr_ifile),
+ curr_altpipe);
free(curr_altfilename);
curr_altfilename = NULL;
}
@@ -194,6 +208,7 @@ edit_ifile(ifile)
int chflags;
char *filename;
char *open_filename;
+ char *qopen_filename;
char *alt_filename;
void *alt_pipe;
IFILE was_curr_ifile;
@@ -244,13 +259,14 @@ edit_ifile(ifile)
return (0);
}
- filename = unquote_file(get_filename(ifile));
+ filename = save(get_filename(ifile));
/*
* See if LESSOPEN specifies an "alternate" file to open.
*/
alt_pipe = NULL;
alt_filename = open_altfile(filename, &f, &alt_pipe);
open_filename = (alt_filename != NULL) ? alt_filename : filename;
+ qopen_filename = shell_unquote(open_filename);
chflags = 0;
if (alt_pipe != NULL)
@@ -301,13 +317,14 @@ edit_ifile(ifile)
free(alt_filename);
}
del_ifile(ifile);
+ free(qopen_filename);
free(filename);
/*
* Re-open the current file.
*/
reedit_ifile(was_curr_ifile);
return (1);
- } else if ((f = open(open_filename, OPEN_READ)) < 0)
+ } else if ((f = open(qopen_filename, OPEN_READ)) < 0)
{
/*
* Got an error trying to open it.
@@ -335,6 +352,7 @@ edit_ifile(ifile)
}
}
}
+ free(qopen_filename);
/*
* Get the new ifile.
@@ -683,7 +701,7 @@ use_logfile(filename)
/*
* {{ We could use access() here. }}
*/
- filename = unquote_file(filename);
+ filename = shell_unquote(filename);
exists = open(filename, OPEN_READ);
close(exists);
exists = (exists >= 0);
OpenPOWER on IntegriCloud