* Copyright (c) 1985 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1985 Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.11 (Berkeley) %G%";
* FTP User Program -- Command Interface.
struct passwd
*pw
= NULL
;
char homedir
[MAXPATHLEN
];
sp
= getservbyname("ftp", "tcp");
fprintf(stderr
, "ftp: ftp/tcp: unknown service\n");
while (argc
> 0 && **argv
== '-') {
for (cp
= *argv
+ 1; *cp
; cp
++)
"ftp: %c: unknown option\n", *cp
);
fromatty
= isatty(fileno(stdin
));
* Set up defaults for FTP.
(void) strcpy(typename
, "ascii"), type
= TYPE_A
;
(void) strcpy(formname
, "non-print"), form
= FORM_N
;
(void) strcpy(modename
, "stream"), mode
= MODE_S
;
(void) strcpy(structname
, "file"), stru
= STRU_F
;
(void) strcpy(bytename
, "8"), bytesize
= 8;
cpend
= 0; /* no pending replies */
proxy
= 0; /* proxy not active */
crflag
= 1; /* strip c.r. on ascii gets */
* Set up the home directory in case we're globbing.
(void) strcpy(home
, pw
->pw_dir
);
(void) signal(SIGINT
, intr
);
(void) signal(SIGPIPE
, lostpeer
);
setpeer(argc
+ 1, argv
- 1);
top
= setjmp(toplevel
) == 0;
(void) signal(SIGINT
, intr
);
(void) signal(SIGPIPE
, lostpeer
);
(void) shutdown(fileno(cout
), 1+1);
(void) shutdown(data
, 1+1);
(void) shutdown(fileno(cout
), 1+1);
s = rindex(filename, '/');
if (feof(stdin
) || ferror(stdin
))
if (c
== (struct cmd
*)-1) {
printf("?Ambiguous command\n");
printf("?Invalid command\n");
if (c
->c_conn
&& !connected
) {
printf ("Not connected.\n");
(*c
->c_handler
)(margc
, margv
);
(void) putchar(CTRL('g'));
if (c
->c_handler
!= help
)
(void) signal(SIGINT
, intr
);
(void) signal(SIGPIPE
, lostpeer
);
extern struct cmd cmdtab
[];
register struct cmd
*c
, *found
;
register int nmatches
, longest
;
for (c
= cmdtab
; p
= c
->c_name
; c
++) {
for (q
= name
; *q
== *p
++; q
++)
if (*q
== 0) /* exact match? */
if (!*q
) { /* the name was a prefix */
if (q
- name
> longest
) {
} else if (q
- name
== longest
)
return ((struct cmd
*)-1);
* Slice a string up into argc/argv.
stringbase
= line
; /* scan from first of buffer */
argbase
= argbuf
; /* store from first of buffer */
while (*argp
++ = slurpstring())
* Parse string into argbuf;
* implemented with FSM to
* handle quoting and strings
register char *sb
= stringbase
;
register char *ap
= argbase
;
char *tmp
= argbase
; /* will return this if token found */
if (*sb
== '!' || *sb
== '$') { /* recognize ! as a token for shell */
switch (slrflag
) { /* and $ as token for macro invoke */
return ((*sb
== '!') ? "!" : "$");
goto OUT
; /* end of token */
sb
++; goto S2
; /* slurp next character */
sb
++; goto S3
; /* slurp quoted string */
*ap
++ = *sb
++; /* add character to token */
argbase
= ap
; /* update storage pointer */
stringbase
= sb
; /* update scan pointer */
#define HELPINDENT (sizeof ("directory"))
* Call each command handler with argc == 0 and argv[0] == name.
extern struct cmd cmdtab
[];
int columns
, width
= 0, lines
;
printf("Commands may be abbreviated. Commands are:\n\n");
for (c
= cmdtab
; c
< &cmdtab
[NCMDS
]; c
++) {
int len
= strlen(c
->c_name
);
width
= (width
+ 8) &~ 7;
lines
= (NCMDS
+ columns
- 1) / columns
;
for (i
= 0; i
< lines
; i
++) {
for (j
= 0; j
< columns
; j
++) {
c
= cmdtab
+ j
* lines
+ i
;
if (c
->c_name
&& (!proxy
|| c
->c_proxy
)) {
for (k
=0; k
< strlen(c
->c_name
); k
++) {
if (c
+ lines
>= &cmdtab
[NCMDS
]) {
if (c
== (struct cmd
*)-1)
printf("?Ambiguous help command %s\n", arg
);
else if (c
== (struct cmd
*)0)
printf("?Invalid help command %s\n", arg
);
printf("%-*s\t%s\n", HELPINDENT
,
* Call routine with argc, argv set from args (terminated by 0).
for (argc
= 0, argp
= &args
; *argp
++ != 0; argc
++)