From ccba5594a8bdfbc14155b12ae2acd04635d9ac11 Mon Sep 17 00:00:00 2001 From: millert Date: Thu, 10 Apr 1997 00:17:06 +0000 Subject: [PATCH] Sync with NetBSD (lukem) * support $ftp_proxy for ftp:// transfers [bin/3245] * add "more" & "less" as synonyms for "page" * move editline setup code into controlediting(), and call appropriately. only setup setup terminal if going into interactive mode. --- usr.bin/ftp/Makefile | 4 +- usr.bin/ftp/cmds.c | 7 ++-- usr.bin/ftp/cmdtab.c | 8 ++-- usr.bin/ftp/extern.h | 5 ++- usr.bin/ftp/fetch.c | 85 +++++++++++++++++++++++++---------------- usr.bin/ftp/ftp.1 | 21 ++++++++-- usr.bin/ftp/main.c | 51 ++++++++----------------- usr.bin/ftp/pathnames.h | 4 +- usr.bin/ftp/ruserpass.c | 6 +-- usr.bin/ftp/util.c | 44 +++++++++++++++++++-- 10 files changed, 144 insertions(+), 91 deletions(-) diff --git a/usr.bin/ftp/Makefile b/usr.bin/ftp/Makefile index f34f105aee6..a0a852cf725 100644 --- a/usr.bin/ftp/Makefile +++ b/usr.bin/ftp/Makefile @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile,v 1.8 1997/03/26 00:35:23 deraadt Exp $ -# $NetBSD: Makefile,v 1.10 1997/03/14 01:39:31 christos Exp $ +# $OpenBSD: Makefile,v 1.9 1997/04/10 00:17:06 millert Exp $ +# $NetBSD: Makefile,v 1.11 1997/03/24 21:59:36 christos Exp $ # from: @(#)Makefile 8.2 (Berkeley) 4/3/94 # define SMALL to disable command line editing diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c index d30743a12f7..dc3bc4b86d9 100644 --- a/usr.bin/ftp/cmds.c +++ b/usr.bin/ftp/cmds.c @@ -1,5 +1,5 @@ -/* $OpenBSD: cmds.c,v 1.17 1997/03/21 20:59:26 millert Exp $ */ -/* $NetBSD: cmds.c,v 1.21 1997/03/16 14:24:14 lukem Exp $ */ +/* $OpenBSD: cmds.c,v 1.18 1997/04/10 00:17:07 millert Exp $ */ +/* $NetBSD: cmds.c,v 1.22 1997/04/05 03:27:32 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94"; #else -static char rcsid[] = "$OpenBSD: cmds.c,v 1.17 1997/03/21 20:59:26 millert Exp $"; +static char rcsid[] = "$OpenBSD: cmds.c,v 1.18 1997/04/10 00:17:07 millert Exp $"; #endif #endif /* not lint */ @@ -731,6 +731,7 @@ setedit(argc, argv) { code = togglevar(argc, argv, &editing, "Editing mode"); + controlediting(); } #endif /* !SMALL */ diff --git a/usr.bin/ftp/cmdtab.c b/usr.bin/ftp/cmdtab.c index 0e440af8d3f..a15453a130a 100644 --- a/usr.bin/ftp/cmdtab.c +++ b/usr.bin/ftp/cmdtab.c @@ -1,5 +1,5 @@ -/* $OpenBSD: cmdtab.c,v 1.8 1997/03/21 20:59:27 millert Exp $ */ -/* $NetBSD: cmdtab.c,v 1.14 1997/03/14 01:39:34 christos Exp $ */ +/* $OpenBSD: cmdtab.c,v 1.9 1997/04/10 00:17:08 millert Exp $ */ +/* $NetBSD: cmdtab.c,v 1.15 1997/04/05 03:27:33 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)cmdtab.c 8.4 (Berkeley) 10/9/94"; #else -static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.8 1997/03/21 20:59:27 millert Exp $"; +static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.9 1997/04/10 00:17:08 millert Exp $"; #endif #endif /* not lint */ @@ -166,6 +166,7 @@ struct cmd cmdtab[] = { { "idle", idlehelp, 0, 1, 1, CMPL0 idle }, { "image", binaryhelp, 0, 1, 1, CMPL0 setbinary }, { "lcd", lcdhelp, 0, 0, 0, CMPL(l) lcd }, + { "less", pagehelp, 1, 1, 1, CMPL(r) page }, { "lpwd", lpwdhelp, 0, 0, 0, CMPL0 lpwd }, { "ls", lshelp, 1, 1, 1, CMPL(rl) ls }, { "macdef", macdefhelp, 0, 0, 0, CMPL0 macdef }, @@ -176,6 +177,7 @@ struct cmd cmdtab[] = { { "mls", mlshelp, 1, 1, 1, CMPL(R) mls }, { "mode", modehelp, 0, 1, 1, CMPL0 setftmode }, { "modtime", modtimehelp, 0, 1, 1, CMPL(r) modtime }, + { "more", pagehelp, 1, 1, 1, CMPL(r) page }, { "mput", mputhelp, 1, 1, 1, CMPL(L) mput }, { "msend", mputhelp, 1, 1, 1, CMPL(L) mput }, { "newer", newerhelp, 1, 1, 1, CMPL(r) newer }, diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h index e4f3aa6bab1..0cdc98ba3a0 100644 --- a/usr.bin/ftp/extern.h +++ b/usr.bin/ftp/extern.h @@ -1,5 +1,5 @@ -/* $OpenBSD: extern.h,v 1.10 1997/03/21 20:59:28 millert Exp $ */ -/* $NetBSD: extern.h,v 1.13 1997/03/14 01:39:37 christos Exp $ */ +/* $OpenBSD: extern.h,v 1.11 1997/04/10 00:17:08 millert Exp $ */ +/* $NetBSD: extern.h,v 1.14 1997/04/05 03:27:34 lukem Exp $ */ /*- * Copyright (c) 1994 The Regents of the University of California. @@ -56,6 +56,7 @@ void cmdscanner __P((int)); int command __P((const char *, ...)); #ifndef SMALL unsigned char complete __P((EditLine *, int)); +void controlediting __P((void)); #endif /* !SMALL */ int confirm __P((const char *, const char *)); FILE *dataconn __P((const char *)); diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index f0f5484acca..144dc7ca2d4 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -1,5 +1,5 @@ -/* $OpenBSD: fetch.c,v 1.5 1997/03/21 20:59:29 millert Exp $ */ -/* $NetBSD: fetch.c,v 1.4 1997/03/16 14:24:18 lukem Exp $ */ +/* $OpenBSD: fetch.c,v 1.6 1997/04/10 00:17:08 millert Exp $ */ +/* $NetBSD: fetch.c,v 1.5 1997/04/05 03:27:36 lukem Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: fetch.c,v 1.5 1997/03/21 20:59:29 millert Exp $"; +static char rcsid[] = "$OpenBSD: fetch.c,v 1.6 1997/04/10 00:17:08 millert Exp $"; #endif /* not lint */ /* @@ -68,6 +68,7 @@ static char rcsid[] = "$OpenBSD: fetch.c,v 1.5 1997/03/21 20:59:29 millert Exp $ #define FTP_URL "ftp://" /* ftp URL prefix */ #define HTTP_URL "http://" /* http URL prefix */ +#define FTP_PROXY "ftp_proxy" /* env var with ftp proxy location */ #define HTTP_PROXY "http_proxy" /* env var with http proxy location */ @@ -76,32 +77,39 @@ static char rcsid[] = "$OpenBSD: fetch.c,v 1.5 1997/03/21 20:59:29 millert Exp $ jmp_buf httpabort; /* - * Retrieve an http:// URL, via a proxy if necessary. + * Retrieve URL, via the proxy in $proxyvar if necessary. * Modifies the string argument given. * Returns -1 on failure, 0 on success */ int -http_get(line) +url_get(line, proxyenv) char *line; + char *proxyenv; { struct sockaddr_in sin; int i, out, port, s; size_t buflen, len; char c, *cp, *cp2, *savefile, *portnum, *path, buf[4096]; - char *proxyenv, *proxy, *host; + char *proxy, *host; sig_t oldintr; off_t hashbytes; s = -1; proxy = NULL; - host = line + sizeof(HTTP_URL) - 1; + if (strncmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) + host = line + sizeof(HTTP_URL) - 1; + else if (strncmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) + host = line + sizeof(FTP_URL) - 1; + else + errx(1, "url_get: invalid url '%s'", line); + path = strchr(host, '/'); /* find path */ if (EMPTYSTRING(path)) - goto cleanup_http_get; + goto cleanup_url_get; *path++ = '\0'; if (EMPTYSTRING(path)) - goto cleanup_http_get; + goto cleanup_url_get; savefile = strrchr(path, '/'); /* find savefile */ if (savefile != NULL) @@ -109,20 +117,22 @@ http_get(line) else savefile = path; if (EMPTYSTRING(savefile)) - goto cleanup_http_get; + goto cleanup_url_get; - proxyenv = getenv(HTTP_PROXY); if (proxyenv != NULL) { /* use proxy */ - if (strncmp(proxyenv, HTTP_URL, sizeof(HTTP_URL) - 1) != 0) { - warnx("Malformed proxy url: %s", proxyenv); - goto cleanup_http_get; - } proxy = strdup(proxyenv); if (proxy == NULL) errx(1, "Can't allocate memory for proxy url."); - host = proxy + sizeof(HTTP_URL) - 1; + if (strncmp(proxy, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) + host = proxy + sizeof(HTTP_URL) - 1; + else if (strncmp(proxy, FTP_URL, sizeof(FTP_URL) - 1) == 0) + host = proxy + sizeof(FTP_URL) - 1; + else { + warnx("Malformed proxy url: %s", proxy); + goto cleanup_url_get; + } if (EMPTYSTRING(host)) - goto cleanup_http_get; + goto cleanup_url_get; *--path = '/'; /* add / back to real path */ path = strchr(host, '/'); /* remove trailing / on host */ if (! EMPTYSTRING(path)) @@ -144,7 +154,7 @@ http_get(line) if (isdigit(host[0])) { if (inet_aton(host, &sin.sin_addr) == 0) { warnx("invalid IP address: %s", host); - goto cleanup_http_get; + goto cleanup_url_get; } } else { struct hostent *hp; @@ -152,11 +162,11 @@ http_get(line) hp = gethostbyname(host); if (hp == NULL) { warnx("%s: %s", host, hstrerror(h_errno)); - goto cleanup_http_get; + goto cleanup_url_get; } if (hp->h_addrtype != AF_INET) { warnx("%s: not an Internet address?", host); - goto cleanup_http_get; + goto cleanup_url_get; } memcpy(&sin.sin_addr, hp->h_addr, hp->h_length); } @@ -165,7 +175,7 @@ http_get(line) port = atoi(portnum); if (port < 1 || (port & 0xffff) != port) { warnx("invalid port: %s", portnum); - goto cleanup_http_get; + goto cleanup_url_get; } port = htons(port); } else @@ -175,12 +185,12 @@ http_get(line) s = socket(AF_INET, SOCK_STREAM, 0); if (s == -1) { warnx("Can't create socket"); - goto cleanup_http_get; + goto cleanup_url_get; } if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) == -1) { warn("Can't connect to %s", host); - goto cleanup_http_get; + goto cleanup_url_get; } /* @@ -196,7 +206,7 @@ http_get(line) buflen = strlen(buf); if (write(s, buf, buflen) < buflen) { warn("write"); - goto cleanup_http_get; + goto cleanup_url_get; } memset(buf, 0, sizeof(buf)); for (i = 0, buflen = sizeof(buf), cp = buf; i < buflen; cp++, i++) { @@ -215,7 +225,7 @@ http_get(line) cp++; if (strncmp(cp, "200", 3)) { warnx("Error retrieving file: %s", cp); - goto cleanup_http_get; + goto cleanup_url_get; } /* @@ -259,7 +269,7 @@ http_get(line) out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (out < 0) { warn("Can't open %s", savefile); - goto cleanup_http_get; + goto cleanup_url_get; } /* Trap signals */ @@ -267,7 +277,7 @@ http_get(line) if (setjmp(httpabort)) { if (oldintr) (void)signal(SIGINT, oldintr); - goto cleanup_http_get; + goto cleanup_url_get; } oldintr = signal(SIGINT, aborthttp); @@ -282,7 +292,7 @@ http_get(line) for (cp = buf; len > 0; len -= i, cp += i) { if ((i = write(out, cp, len)) == -1) { warn("Writing %s", savefile); - goto cleanup_http_get; + goto cleanup_url_get; } else if (i == 0) break; @@ -303,7 +313,7 @@ http_get(line) } if (len != 0) { warn("Reading from socket"); - goto cleanup_http_get; + goto cleanup_url_get; } progressmeter(1); if (verbose) @@ -318,7 +328,7 @@ http_get(line) improper: warnx("improper response from %s", host); -cleanup_http_get: +cleanup_url_get: if (s != -1) close(s); if (proxy) @@ -362,6 +372,7 @@ auto_fetch(argc, argv) static char lasthost[MAXHOSTNAMELEN]; char *xargv[5]; char *cp, *line, *host, *dir, *file, *portnum; + char *ftpproxy, *httpproxy; int rval, xargc, argpos; int dirhasglob, filehasglob; char rempath[MAXPATHLEN]; @@ -376,6 +387,9 @@ auto_fetch(argc, argv) (void)signal(SIGINT, (sig_t)intr); (void)signal(SIGPIPE, (sig_t)lostpeer); + ftpproxy = getenv(FTP_PROXY); + httpproxy = getenv(HTTP_PROXY); + /* * Loop through as long as there's files to fetch. */ @@ -395,16 +409,23 @@ auto_fetch(argc, argv) * Try HTTP URL-style arguments first. */ if (strncmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) { - if (http_get(line) == -1) + if (url_get(line, httpproxy) == -1) rval = argpos + 1; continue; } /* - * Try FTP URL-style arguments next, then host:file. + * Try FTP URL-style arguments next. If ftpproxy is + * set, use url_get() instead of standard ftp. + * Finally, try host:file. */ host = line; if (strncmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) { + if (ftpproxy) { + if (url_get(line, ftpproxy) == -1) + rval = argpos + 1; + continue; + } host += sizeof(FTP_URL) - 1; cp = strchr(host, '/'); diff --git a/usr.bin/ftp/ftp.1 b/usr.bin/ftp/ftp.1 index f003760e9a9..66ff86344a9 100644 --- a/usr.bin/ftp/ftp.1 +++ b/usr.bin/ftp/ftp.1 @@ -1,5 +1,5 @@ -.\" $OpenBSD: ftp.1,v 1.9 1997/03/14 04:32:15 millert Exp $ -.\" $NetBSD: ftp.1,v 1.18 1997/03/13 06:23:16 lukem Exp $ +.\" $OpenBSD: ftp.1,v 1.10 1997/04/10 00:17:09 millert Exp $ +.\" $NetBSD: ftp.1,v 1.19 1997/04/05 03:27:37 lukem Exp $ .\" .\" Copyright (c) 1985, 1989, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -392,6 +392,9 @@ If no .Ar directory is specified, the user's home directory is used. +.It Ic less Ar file +A synonym for +.Ic page . .It Ic lpwd Print the working directory on the local machine. .It Ic \&ls Op Ar remote-directory Op Ar local-file @@ -491,6 +494,9 @@ to The default mode is \*(Lqstream\*(Rq mode. .It Ic modtime Ar file-name Show the last modification time of the file on the remote machine. +.It Ic more Ar file +A synonym for +.Ic page . .It Ic mput Ar local-files Expand wild cards in the list of local files given as arguments and do a @@ -1011,7 +1017,11 @@ The following formats are valid syntax for an auto-fetch element: .Dq Classic ftp format .It ftp://host[:port]/file -FTP URL, using the ftp protocol. +FTP URL, using the ftp protocol if +.Ev ftp_proxy +isn't defined. +Otherwise, transfer using http via the proxy defined in +.Ev ftp_proxy . .It http://host[:port]/file HTTP URL, using the http protocol. If @@ -1311,8 +1321,11 @@ Used by to display files. .It Ev SHELL For default shell. +.It Ev ftp_proxy +URL of FTP proxy to use when making FTP URL requests +(if not defined, use the standard ftp protocol). .It Ev http_proxy -URL of HTTP proxy to use when making HTTP requests. +URL of HTTP proxy to use when making HTTP URL requests. .El .Sh SEE ALSO .Xr editrc 5 , diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c index 1d94b442032..22ba48dc6ed 100644 --- a/usr.bin/ftp/main.c +++ b/usr.bin/ftp/main.c @@ -1,5 +1,5 @@ -/* $OpenBSD: main.c,v 1.27 1997/04/05 19:53:10 kstailey Exp $ */ -/* $NetBSD: main.c,v 1.20 1997/03/16 14:24:21 lukem Exp $ */ +/* $OpenBSD: main.c,v 1.28 1997/04/10 00:17:10 millert Exp $ */ +/* $NetBSD: main.c,v 1.21 1997/04/05 03:27:39 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.27 1997/04/05 19:53:10 kstailey Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.28 1997/04/10 00:17:10 millert Exp $"; #endif #endif /* not lint */ @@ -74,7 +74,7 @@ main(argc, argv) int ch, top, port, rval; struct passwd *pw = NULL; char *cp, homedir[MAXPATHLEN]; - int from_emacs; + int dumb_terminal = 0; sp = getservbyname("ftp", "tcp"); if (sp == 0) @@ -95,6 +95,8 @@ main(argc, argv) progress = 0; #ifndef SMALL editing = 0; + el = NULL; + hist = NULL; #endif mark = HASHBYTES; marg_sl = sl_init(); @@ -104,16 +106,17 @@ main(argc, argv) if (strcmp(cp, "pftp") == 0) passivemode = 1; - from_emacs = !strcmp(getenv("TERM"), "dumb"); + dumb_terminal = + (!strcmp(getenv("TERM"), "dumb") || !strcmp(getenv("TERM"), "su")); fromatty = isatty(fileno(stdin)); if (fromatty) { verbose = 1; /* verbose if from a tty */ #ifndef SMALL - if (!from_emacs) + if (!dumb_terminal) editing = 1; /* editing mode on if from a tty */ #endif } - if (isatty(fileno(stdout)) && !from_emacs) + if (isatty(fileno(stdout)) && !dumb_terminal) progress = 1; /* progress bar on if going to a tty */ while ((ch = getopt(argc, argv, "adeginpPr:tvV")) != -1) { @@ -127,8 +130,8 @@ main(argc, argv) debug++; break; - case 'e': /* XXX should TERM=dumb be the only way to */ -#ifndef SMALL /* turn off editing or not? */ + case 'e': +#ifndef SMALL editing = 0; #endif break; @@ -201,35 +204,8 @@ main(argc, argv) (void)strcpy(home, pw->pw_dir); } -#ifndef SMALL - if (argc > 0) /* batch mode */ - editing = 0; - if (editing) { - el = el_init(__progname, stdin, stdout); /* init editline */ - - hist = history_init(); /* init the builtin history */ - history(hist, H_EVENT, 100); /* remember 100 events */ - el_set(el, EL_HIST, history, hist); /* use history */ - - el_set(el, EL_EDITOR, "emacs"); /* default editor is emacs */ - el_set(el, EL_PROMPT, prompt); /* set the prompt function */ - - /* add local file completion, bind to TAB */ - el_set(el, EL_ADDFN, "ftp-complete", - "Context sensitive argument completion", - complete); - el_set(el, EL_BIND, "^I", "ftp-complete", NULL); - - el_source(el, NULL); /* read ~/.editrc */ - } -#endif /* !SMALL */ - setttywidth(0); (void)signal(SIGWINCH, setttywidth); -#ifndef SMALL - if (editing) - el_set(el, EL_SIGNAL, 1); -#endif /* !SMALL */ if (argc > 0) { if (strchr(argv[0], ':') != NULL) { @@ -261,6 +237,9 @@ main(argc, argv) } while (!connected); } } +#ifndef SMALL + controlediting(); +#endif /* !SMALL */ top = setjmp(toplevel) == 0; if (top) { (void)signal(SIGINT, (sig_t)intr); diff --git a/usr.bin/ftp/pathnames.h b/usr.bin/ftp/pathnames.h index 575b5131450..a7363267b09 100644 --- a/usr.bin/ftp/pathnames.h +++ b/usr.bin/ftp/pathnames.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pathnames.h,v 1.5 1997/02/03 01:05:43 millert Exp $ */ +/* $OpenBSD: pathnames.h,v 1.6 1997/04/10 00:17:10 millert Exp $ */ /* $NetBSD: pathnames.h,v 1.7 1997/01/09 20:19:40 tls Exp $ */ /* @@ -38,4 +38,4 @@ #include -#define TMPFILE "ftpXXXXXX" +#define TMPFILE "ftpXXXXXXXXXX" diff --git a/usr.bin/ftp/ruserpass.c b/usr.bin/ftp/ruserpass.c index 48c6b24ce93..54784131553 100644 --- a/usr.bin/ftp/ruserpass.c +++ b/usr.bin/ftp/ruserpass.c @@ -1,5 +1,5 @@ -/* $OpenBSD: ruserpass.c,v 1.6 1997/03/14 04:32:17 millert Exp $ */ -/* $NetBSD: ruserpass.c,v 1.12 1997/03/13 06:23:20 lukem Exp $ */ +/* $OpenBSD: ruserpass.c,v 1.7 1997/04/10 00:17:10 millert Exp $ */ +/* $NetBSD: ruserpass.c,v 1.13 1997/04/01 14:20:34 mrg Exp $ */ /* * Copyright (c) 1985, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95"; #else -static char rcsid[] = "$OpenBSD: ruserpass.c,v 1.6 1997/03/14 04:32:17 millert Exp $"; +static char rcsid[] = "$OpenBSD: ruserpass.c,v 1.7 1997/04/10 00:17:10 millert Exp $"; #endif #endif /* not lint */ diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c index b0a8dec3601..e063a0cc061 100644 --- a/usr.bin/ftp/util.c +++ b/usr.bin/ftp/util.c @@ -1,5 +1,5 @@ -/* $OpenBSD: util.c,v 1.4 1997/03/14 04:32:18 millert Exp $ */ -/* $NetBSD: util.c,v 1.5 1997/03/13 06:23:21 lukem Exp $ */ +/* $OpenBSD: util.c,v 1.5 1997/04/10 00:17:11 millert Exp $ */ +/* $NetBSD: util.c,v 1.6 1997/04/05 03:27:39 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -35,7 +35,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: util.c,v 1.4 1997/03/14 04:32:18 millert Exp $"; +static char rcsid[] = "$OpenBSD: util.c,v 1.5 1997/04/10 00:17:11 millert Exp $"; #endif /* not lint */ /* @@ -635,7 +635,6 @@ setttywidth(a) /* * Set the SIGALRM interval timer for wait seconds, 0 to disable. */ - void alarmtimer(wait) int wait; @@ -647,3 +646,40 @@ alarmtimer(wait) itv.it_interval = itv.it_value; setitimer(ITIMER_REAL, &itv, NULL); } + +/* + * Setup or cleanup EditLine structures + */ +#ifndef SMALL +void +controlediting() +{ + if (editing && el == NULL && hist == NULL) { + el = el_init(__progname, stdin, stdout); /* init editline */ + hist = history_init(); /* init the builtin history */ + history(hist, H_EVENT, 100); /* remember 100 events */ + el_set(el, EL_HIST, history, hist); /* use history */ + + el_set(el, EL_EDITOR, "emacs"); /* default editor is emacs */ + el_set(el, EL_PROMPT, prompt); /* set the prompt function */ + + /* add local file completion, bind to TAB */ + el_set(el, EL_ADDFN, "ftp-complete", + "Context sensitive argument completion", + complete); + el_set(el, EL_BIND, "^I", "ftp-complete", NULL); + + el_source(el, NULL); /* read ~/.editrc */ + el_set(el, EL_SIGNAL, 1); + } else if (!editing) { + if (hist) { + history_end(hist); + hist = NULL; + } + if (el) { + el_end(el); + el = NULL; + } + } +} +#endif /* !SMALL */ -- 2.20.1