summaryrefslogtreecommitdiffstats
path: root/contrib/tnftp/src/complete.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/tnftp/src/complete.c')
-rw-r--r--contrib/tnftp/src/complete.c76
1 files changed, 40 insertions, 36 deletions
diff --git a/contrib/tnftp/src/complete.c b/contrib/tnftp/src/complete.c
index 8831bc1..df75d3a 100644
--- a/contrib/tnftp/src/complete.c
+++ b/contrib/tnftp/src/complete.c
@@ -1,7 +1,8 @@
-/* $NetBSD: complete.c,v 1.38 2000/05/01 10:35:17 lukem Exp $ */
+/* $NetBSD: complete.c,v 1.10 2009/05/20 12:53:47 lukem Exp $ */
+/* from NetBSD: complete.c,v 1.46 2009/04/12 10:18:52 lukem Exp */
/*-
- * Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -15,13 +16,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -36,9 +30,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "tnftp.h"
+
+#if 0 /* tnftp */
+
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: complete.c,v 1.38 2000/05/01 10:35:17 lukem Exp $");
+__RCSID(" NetBSD: complete.c,v 1.46 2009/04/12 10:18:52 lukem Exp ");
#endif /* not lint */
/*
@@ -54,6 +52,8 @@ __RCSID("$NetBSD: complete.c,v 1.38 2000/05/01 10:35:17 lukem Exp $");
#include <stdlib.h>
#include <string.h>
+#endif /* tnftp */
+
#include "ftp_var.h"
#ifndef NO_EDITCOMPLETE
@@ -68,7 +68,7 @@ static unsigned char complete_remote (char *, int);
static int
comparstr(const void *a, const void *b)
{
- return (strcmp(*(const char **)a, *(const char **)b));
+ return (strcmp(*(const char * const *)a, *(const char * const *)b));
}
/*
@@ -87,7 +87,7 @@ complete_ambiguous(char *word, int list, StringList *words)
{
char insertstr[MAXPATHLEN];
char *lastmatch, *p;
- int i, j;
+ size_t i, j;
size_t matchlen, wordlen;
wordlen = strlen(word);
@@ -143,14 +143,14 @@ complete_command(char *word, int list)
size_t wordlen;
unsigned char rv;
- words = xsl_init();
+ words = ftp_sl_init();
wordlen = strlen(word);
for (c = cmdtab; c->c_name != NULL; c++) {
if (wordlen > strlen(c->c_name))
continue;
if (strncmp(word, c->c_name, wordlen) == 0)
- xsl_add(words, c->c_name);
+ ftp_sl_add(words, ftp_strdup(c->c_name));
}
rv = complete_ambiguous(word, list, words);
@@ -158,7 +158,7 @@ complete_command(char *word, int list)
if (el_insertstr(el, " ") == -1)
rv = CC_ERROR;
}
- sl_free(words, 0);
+ sl_free(words, 1);
return (rv);
}
@@ -200,7 +200,7 @@ complete_local(char *word, int list)
if ((dd = opendir(dir)) == NULL)
return (CC_ERROR);
- words = xsl_init();
+ words = ftp_sl_init();
len = strlen(file);
for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
@@ -217,8 +217,8 @@ complete_local(char *word, int list)
if (strncmp(file, dp->d_name, len) == 0) {
char *tcp;
- tcp = xstrdup(dp->d_name);
- xsl_add(words, tcp);
+ tcp = ftp_strdup(dp->d_name);
+ ftp_sl_add(words, tcp);
}
}
closedir(dd);
@@ -255,14 +255,14 @@ complete_option(char *word, int list)
size_t wordlen;
unsigned char rv;
- words = xsl_init();
+ words = ftp_sl_init();
wordlen = strlen(word);
for (o = optiontab; o->name != NULL; o++) {
if (wordlen > strlen(o->name))
continue;
if (strncmp(word, o->name, wordlen) == 0)
- xsl_add(words, o->name);
+ ftp_sl_add(words, ftp_strdup(o->name));
}
rv = complete_ambiguous(word, list, words);
@@ -270,7 +270,7 @@ complete_option(char *word, int list)
if (el_insertstr(el, " ") == -1)
rv = CC_ERROR;
}
- sl_free(words, 0);
+ sl_free(words, 1);
return (rv);
}
@@ -285,10 +285,13 @@ complete_remote(char *word, int list)
StringList *words;
char dir[MAXPATHLEN];
char *file, *cp;
- int i;
+ size_t i;
unsigned char rv;
+ char cmdbuf[MAX_C_NAME];
+ char *dummyargv[3] = { NULL, NULL, NULL };
- char *dummyargv[] = { "complete", NULL, NULL };
+ (void)strlcpy(cmdbuf, "complete", sizeof(cmdbuf));
+ dummyargv[0] = cmdbuf;
dummyargv[1] = dir;
if ((file = strrchr(word, '/')) == NULL) {
@@ -304,11 +307,11 @@ complete_remote(char *word, int list)
if (dirchange || dirlist == NULL ||
strcmp(dir, lastdir) != 0) { /* dir not cached */
- char *emesg;
+ const char *emesg;
if (dirlist != NULL)
sl_free(dirlist, 1);
- dirlist = xsl_init();
+ dirlist = ftp_sl_init();
mflag = 1;
emesg = NULL;
@@ -326,8 +329,8 @@ complete_remote(char *word, int list)
tcp++;
else
tcp = cp;
- tcp = xstrdup(tcp);
- xsl_add(dirlist, tcp);
+ tcp = ftp_strdup(tcp);
+ ftp_sl_add(dirlist, tcp);
}
if (emesg != NULL) {
fprintf(ttyout, "\n%s\n", emesg);
@@ -337,13 +340,13 @@ complete_remote(char *word, int list)
dirchange = 0;
}
- words = xsl_init();
+ words = ftp_sl_init();
for (i = 0; i < dirlist->sl_cur; i++) {
cp = dirlist->sl_str[i];
if (strlen(file) > strlen(cp))
continue;
if (strncmp(file, cp, strlen(file)) == 0)
- xsl_add(words, cp);
+ ftp_sl_add(words, cp);
}
rv = complete_ambiguous(file, list, words);
sl_free(words, 0);
@@ -354,17 +357,17 @@ complete_remote(char *word, int list)
* Generic complete routine
*/
unsigned char
-complete(EditLine *el, int ch)
+complete(EditLine *cel, int ch)
{
static char word[FTPBUFLEN];
- static int lastc_argc, lastc_argo;
+ static size_t lastc_argc, lastc_argo;
struct cmd *c;
const LineInfo *lf;
- int celems, dolist, cmpltype;
- size_t len;
+ int dolist, cmpltype;
+ size_t celems, len;
- lf = el_line(el);
+ lf = el_line(cel);
len = lf->lastchar - lf->buffer;
if (len >= sizeof(line))
return (CC_ERROR);
@@ -383,7 +386,7 @@ complete(EditLine *el, int ch)
&& strncmp(word, margv[cursor_argc] ? margv[cursor_argc] : "",
cursor_argo) == 0)
dolist = 1;
- else if (cursor_argc < margc)
+ else if (cursor_argc < (size_t)margc)
(void)strlcpy(word, margv[cursor_argc], cursor_argo + 1);
word[cursor_argo] = '\0';
@@ -426,7 +429,8 @@ complete(EditLine *el, int ch)
}
return (complete_remote(word, dolist));
default:
- errx(1, "unknown complete type `%c'", cmpltype);
+ errx(1, "complete: unknown complete type `%c'",
+ cmpltype);
return (CC_ERROR);
}
/* NOTREACHED */
OpenPOWER on IntegriCloud