summaryrefslogtreecommitdiffstats
path: root/contrib/less/filename.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2016-01-18 19:13:54 +0000
committerdelphij <delphij@FreeBSD.org>2016-01-18 19:13:54 +0000
commitfa1e90c82bb54806d86166769a4547bf68c3e727 (patch)
treefb469219be6a56d727e63953151fbca9a019057d /contrib/less/filename.c
parent119cebf8a0b980468f7ed411c651dd92ff2a0a88 (diff)
downloadFreeBSD-src-fa1e90c82bb54806d86166769a4547bf68c3e727.zip
FreeBSD-src-fa1e90c82bb54806d86166769a4547bf68c3e727.tar.gz
MFC r293190: MFV r293125: less v481.
Relnotes: yes
Diffstat (limited to 'contrib/less/filename.c')
-rw-r--r--contrib/less/filename.c75
1 files changed, 44 insertions, 31 deletions
diff --git a/contrib/less/filename.c b/contrib/less/filename.c
index 14e85e3..9631f1c 100644
--- a/contrib/less/filename.c
+++ b/contrib/less/filename.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2012 Mark Nudelman
+ * Copyright (C) 1984-2015 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.
@@ -86,7 +86,7 @@ shell_unquote(str)
} else
{
char *esc = get_meta_escape();
- int esclen = strlen(esc);
+ int esclen = (int) strlen(esc);
while (*str != '\0')
{
if (esclen > 0 && strncmp(str, esc, esclen) == 0)
@@ -150,7 +150,7 @@ shell_quote(s)
char *newstr;
int len;
char *esc = get_meta_escape();
- int esclen = strlen(esc);
+ int esclen = (int) strlen(esc);
int use_quotes = 0;
int have_quotes = 0;
@@ -188,7 +188,7 @@ shell_quote(s)
* We can't quote a string that contains quotes.
*/
return (NULL);
- len = strlen(s) + 3;
+ len = (int) strlen(s) + 3;
}
/*
* Allocate and construct the new string.
@@ -235,7 +235,7 @@ dirfile(dirname, filename)
/*
* Construct the full pathname.
*/
- len= strlen(dirname) + strlen(filename) + 2;
+ len = (int) (strlen(dirname) + strlen(filename) + 2);
pathname = (char *) calloc(len, sizeof(char));
if (pathname == NULL)
return (NULL);
@@ -350,7 +350,7 @@ fexpand(s)
if (ifile == NULL_IFILE)
n++;
else
- n += strlen(get_filename(ifile));
+ n += (int) strlen(get_filename(ifile));
}
/*
* Else it is the first char in a string of
@@ -432,7 +432,7 @@ fcomplete(s)
for (slash = s+strlen(s)-1; slash > s; slash--)
if (*slash == *PATHNAME_SEP || *slash == '/')
break;
- len = strlen(s) + 4;
+ len = (int) strlen(s) + 4;
fpat = (char *) ecalloc(len, sizeof(char));
if (strchr(slash, '.') == NULL)
SNPRINTF1(fpat, len, "%s*.*", s);
@@ -441,7 +441,7 @@ fcomplete(s)
}
#else
{
- int len = strlen(s) + 2;
+ int len = (int) strlen(s) + 2;
fpat = (char *) ecalloc(len, sizeof(char));
SNPRINTF1(fpat, len, "%s*", s);
}
@@ -481,17 +481,25 @@ bin_file(f)
if (lseek(f, (off_t)0, SEEK_SET) == BAD_LSEEK)
return (0);
n = read(f, data, sizeof(data));
- pend = &data[n];
- for (p = data; p < pend; )
+ if (n <= 0)
+ return (0);
+ if (utf_mode)
+ {
+ bin_count = utf_bin_count(data, n);
+ } else
{
- LWCHAR c = step_char(&p, +1, pend);
- if (ctldisp == OPT_ONPLUS && IS_CSI_START(c))
+ pend = &data[n];
+ for (p = data; p < pend; )
{
- do {
- c = step_char(&p, +1, pend);
- } while (p < pend && is_ansi_middle(c));
- } else if (binary_char(c))
- bin_count++;
+ LWCHAR c = step_char(&p, +1, pend);
+ if (ctldisp == OPT_ONPLUS && IS_CSI_START(c))
+ {
+ do {
+ c = step_char(&p, +1, pend);
+ } while (p < pend && is_ansi_middle(c));
+ } else if (binary_char(c))
+ bin_count++;
+ }
}
/*
* Call it a binary file if there are more than 5 binary characters
@@ -593,7 +601,7 @@ shellcmd(cmd)
fd = popen(cmd, "r");
} else
{
- int len = strlen(shell) + strlen(esccmd) + 5;
+ int len = (int) (strlen(shell) + strlen(esccmd) + 5);
scmd = (char *) ecalloc(len, sizeof(char));
SNPRINTF3(scmd, len, "%s %s %s", shell, shell_coption(), esccmd);
free(esccmd);
@@ -701,14 +709,14 @@ lglob(filename)
gfilename = (char *) ecalloc(len, sizeof(char));
p = gfilename;
do {
- n = strlen(drive) + strlen(dir) + strlen(fnd.GLOB_NAME) + 1;
+ n = (int) (strlen(drive) + strlen(dir) + strlen(fnd.GLOB_NAME) + 1);
pathname = (char *) ecalloc(n, sizeof(char));
SNPRINTF3(pathname, n, "%s%s%s", drive, dir, fnd.GLOB_NAME);
qpathname = shell_quote(pathname);
free(pathname);
if (qpathname != NULL)
{
- n = strlen(qpathname);
+ n = (int) strlen(qpathname);
while (p - gfilename + n + 2 >= len)
{
/*
@@ -765,7 +773,7 @@ lglob(filename)
/*
* Invoke lessecho, and read its output (a globbed list of filenames).
*/
- len = strlen(lessecho) + strlen(ofilename) + (7*strlen(metachars())) + 24;
+ len = (int) (strlen(lessecho) + strlen(ofilename) + (7*strlen(metachars())) + 24);
cmd = (char *) ecalloc(len, sizeof(char));
SNPRINTF4(cmd, len, "%s -p0x%x -d0x%x -e%s ", lessecho, openquote, closequote, esc);
free(esc);
@@ -813,15 +821,20 @@ lglob(filename)
num_pct_s(lessopen)
char *lessopen;
{
- int num;
+ int num = 0;
- for (num = 0;; num++)
+ while (*lessopen != '\0')
{
- lessopen = strchr(lessopen, '%');
- if (lessopen == NULL)
- break;
- if (*++lessopen != 's')
- return (999);
+ if (*lessopen == '%')
+ {
+ if (lessopen[1] == '%')
+ ++lessopen;
+ else if (lessopen[1] == 's')
+ ++num;
+ else
+ return (999);
+ }
+ ++lessopen;
}
return (num);
}
@@ -881,7 +894,7 @@ open_altfile(filename, pf, pfd)
return (NULL);
}
- len = strlen(lessopen) + strlen(filename) + 2;
+ len = (int) (strlen(lessopen) + strlen(filename) + 2);
cmd = (char *) ecalloc(len, sizeof(char));
SNPRINTF1(cmd, len, lessopen, filename);
fd = shellcmd(cmd);
@@ -971,10 +984,10 @@ close_altfile(altfilename, filename, pipefd)
return;
if (num_pct_s(lessclose) > 2)
{
- error("Invalid LESSCLOSE variable");
+ error("Invalid LESSCLOSE variable", NULL_PARG);
return;
}
- len = strlen(lessclose) + strlen(filename) + strlen(altfilename) + 2;
+ len = (int) (strlen(lessclose) + strlen(filename) + strlen(altfilename) + 2);
cmd = (char *) ecalloc(len, sizeof(char));
SNPRINTF2(cmd, len, lessclose, filename, altfilename);
fd = shellcmd(cmd);
OpenPOWER on IntegriCloud