[BACK]Return to main.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / usr.bin / ftp

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/usr.bin/ftp/main.c between version 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 1993/03/21 09:45:37 version 1.1.1.2, 1995/09/05 01:20:09
Line 1 
Line 1 
 /*  /*
  * Copyright (c) 1985, 1989 Regents of the University of California.   * Copyright (c) 1985, 1989, 1993, 1994
  * All rights reserved.   *      The Regents of the University of California.  All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions   * modification, are permitted provided that the following conditions
Line 32 
Line 32 
  */   */
   
 #ifndef lint  #ifndef lint
 char copyright[] =  static char copyright[] =
 "@(#) Copyright (c) 1985, 1989 Regents of the University of California.\n\  "@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
  All rights reserved.\n";          The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */  #endif /* not lint */
   
 #ifndef lint  #ifndef lint
 static char sccsid[] = "@(#)main.c      5.18 (Berkeley) 3/1/91";  static char sccsid[] = "@(#)main.c      8.6 (Berkeley) 10/9/94";
 #endif /* not lint */  #endif /* not lint */
   
 /*  /*
  * FTP User Program -- Command Interface.   * FTP User Program -- Command Interface.
  */   */
 #include "ftp_var.h"  /*#include <sys/ioctl.h>*/
 #include <sys/socket.h>  
 #include <sys/ioctl.h>  
 #include <sys/types.h>  #include <sys/types.h>
   #include <sys/socket.h>
   
 #include <arpa/ftp.h>  #include <arpa/ftp.h>
   
 #include <signal.h>  
 #include <stdio.h>  
 #include <errno.h>  
 #include <ctype.h>  #include <ctype.h>
   #include <err.h>
 #include <netdb.h>  #include <netdb.h>
 #include <pwd.h>  #include <pwd.h>
   #include <signal.h>
   #include <stdio.h>
   #include <stdlib.h>
   #include <unistd.h>
   
 uid_t   getuid();  #include "ftp_var.h"
 void    intr(), lostpeer();  
 extern  char *home;  
 char    *getlogin();  
   
   int
 main(argc, argv)  main(argc, argv)
           int argc;
         char *argv[];          char *argv[];
 {  {
         register char *cp;          int ch, top;
         int top;  
         struct passwd *pw = NULL;          struct passwd *pw = NULL;
         char homedir[MAXPATHLEN];          char *cp, homedir[MAXPATHLEN];
   
         sp = getservbyname("ftp", "tcp");          sp = getservbyname("ftp", "tcp");
         if (sp == 0) {          if (sp == 0)
                 fprintf(stderr, "ftp: ftp/tcp: unknown service\n");                  errx(1, "ftp/tcp: unknown service");
                 exit(1);  
         }  
         doglob = 1;          doglob = 1;
         interactive = 1;          interactive = 1;
         autologin = 1;          autologin = 1;
         argc--, argv++;  
         while (argc > 0 && **argv == '-') {          while ((ch = getopt(argc, argv, "dgintv")) != EOF) {
                 for (cp = *argv + 1; *cp; cp++)                  switch (ch) {
                         switch (*cp) {                  case 'd':
                           options |= SO_DEBUG;
                         case 'd':                          debug++;
                                 options |= SO_DEBUG;                          break;
                                 debug++;  
                                 break;  
   
                         case 'v':                  case 'g':
                                 verbose++;                          doglob = 0;
                                 break;                          break;
   
                         case 't':                  case 'i':
                                 trace++;                          interactive = 0;
                                 break;                          break;
   
                         case 'i':                  case 'n':
                                 interactive = 0;                          autologin = 0;
                                 break;                          break;
   
                         case 'n':                  case 't':
                                 autologin = 0;                          trace++;
                                 break;                          break;
   
                         case 'g':                  case 'v':
                                 doglob = 0;                          verbose++;
                                 break;                          break;
   
                         default:                  default:
                                 fprintf(stdout,                          (void)fprintf(stderr,
                                   "ftp: %c: unknown option\n", *cp);                                  "usage: ftp [-dgintv] [host [port]]\n");
                                 exit(1);                          exit(1);
                         }                  }
                 argc--, argv++;  
         }          }
           argc -= optind;
           argv += optind;
   
         fromatty = isatty(fileno(stdin));          fromatty = isatty(fileno(stdin));
         if (fromatty)          if (fromatty)
                 verbose++;                  verbose++;
         cpend = 0;      /* no pending replies */          cpend = 0;      /* no pending replies */
         proxy = 0;      /* proxy not active */          proxy = 0;      /* proxy not active */
           passivemode = 0; /* passive mode not active */
         crflag = 1;     /* strip c.r. on ascii gets */          crflag = 1;     /* strip c.r. on ascii gets */
         sendport = -1;  /* not using ports */          sendport = -1;  /* not using ports */
         /*          /*
Line 137  main(argc, argv)
Line 135  main(argc, argv)
                 (void) strcpy(home, pw->pw_dir);                  (void) strcpy(home, pw->pw_dir);
         }          }
         if (argc > 0) {          if (argc > 0) {
                   char *xargv[5];
                   extern char *__progname;
   
                 if (setjmp(toplevel))                  if (setjmp(toplevel))
                         exit(0);                          exit(0);
                 (void) signal(SIGINT, intr);                  (void) signal(SIGINT, intr);
                 (void) signal(SIGPIPE, lostpeer);                  (void) signal(SIGPIPE, lostpeer);
                 setpeer(argc + 1, argv - 1);                  xargv[0] = __progname;
                   xargv[1] = argv[0];
                   xargv[2] = argv[1];
                   xargv[3] = argv[2];
                   xargv[4] = NULL;
                   setpeer(argc+1, xargv);
         }          }
         top = setjmp(toplevel) == 0;          top = setjmp(toplevel) == 0;
         if (top) {          if (top) {
Line 164  intr()
Line 170  intr()
 void  void
 lostpeer()  lostpeer()
 {  {
         extern FILE *cout;  
         extern int data;  
   
         if (connected) {          if (connected) {
                 if (cout != NULL) {                  if (cout != NULL) {
Line 193  lostpeer()
Line 197  lostpeer()
         pswitch(0);          pswitch(0);
 }  }
   
 /*char *  /*
   char *
 tail(filename)  tail(filename)
         char *filename;          char *filename;
 {  {
         register char *s;          char *s;
   
         while (*filename) {          while (*filename) {
                 s = rindex(filename, '/');                  s = strrchr(filename, '/');
                 if (s == NULL)                  if (s == NULL)
                         break;                          break;
                 if (s[1])                  if (s[1])
Line 210  tail(filename)
Line 215  tail(filename)
         return (filename);          return (filename);
 }  }
 */  */
   
 /*  /*
  * Command parser.   * Command parser.
  */   */
   void
 cmdscanner(top)  cmdscanner(top)
         int top;          int top;
 {  {
         register struct cmd *c;          struct cmd *c;
         register int l;          int l;
         struct cmd *getcmd();  
         extern int help();  
   
         if (!top)          if (!top)
                 (void) putchar('\n');                  (void) putchar('\n');
Line 229  cmdscanner(top)
Line 234  cmdscanner(top)
                         (void) fflush(stdout);                          (void) fflush(stdout);
                 }                  }
                 if (fgets(line, sizeof line, stdin) == NULL)                  if (fgets(line, sizeof line, stdin) == NULL)
                         quit();                          quit(0, 0);
                 l = strlen(line);                  l = strlen(line);
                 if (l == 0)                  if (l == 0)
                         break;                          break;
Line 272  cmdscanner(top)
Line 277  cmdscanner(top)
   
 struct cmd *  struct cmd *
 getcmd(name)  getcmd(name)
         register char *name;          char *name;
 {  {
         extern struct cmd cmdtab[];          char *p, *q;
         register char *p, *q;          struct cmd *c, *found;
         register struct cmd *c, *found;          int nmatches, longest;
         register int nmatches, longest;  
   
         longest = 0;          longest = 0;
         nmatches = 0;          nmatches = 0;
Line 306  getcmd(name)
Line 310  getcmd(name)
   
 int slrflag;  int slrflag;
   
   void
 makeargv()  makeargv()
 {  {
         char **argp;          char **argp;
         char *slurpstring();  
   
         margc = 0;          margc = 0;
         argp = margv;          argp = margv;
Line 329  char *
Line 333  char *
 slurpstring()  slurpstring()
 {  {
         int got_one = 0;          int got_one = 0;
         register char *sb = stringbase;          char *sb = stringbase;
         register char *ap = argbase;          char *ap = argbase;
         char *tmp = argbase;            /* will return this if token found */          char *tmp = argbase;            /* will return this if token found */
   
         if (*sb == '!' || *sb == '$') { /* recognize ! as a token for shell */          if (*sb == '!' || *sb == '$') { /* recognize ! as a token for shell */
Line 427  OUT:
Line 431  OUT:
         argbase = ap;                   /* update storage pointer */          argbase = ap;                   /* update storage pointer */
         stringbase = sb;                /* update scan pointer */          stringbase = sb;                /* update scan pointer */
         if (got_one) {          if (got_one) {
                 return(tmp);                  return (tmp);
         }          }
         switch (slrflag) {          switch (slrflag) {
                 case 0:                  case 0:
Line 440  OUT:
Line 444  OUT:
                 default:                  default:
                         break;                          break;
         }          }
         return((char *)0);          return ((char *)0);
 }  }
   
 #define HELPINDENT (sizeof ("directory"))  #define HELPINDENT ((int) sizeof ("directory"))
   
 /*  /*
  * Help command.   * Help command.
  * Call each command handler with argc == 0 and argv[0] == name.   * Call each command handler with argc == 0 and argv[0] == name.
  */   */
   void
 help(argc, argv)  help(argc, argv)
         int argc;          int argc;
         char *argv[];          char *argv[];
 {  {
         extern struct cmd cmdtab[];          struct cmd *c;
         register struct cmd *c;  
   
         if (argc == 1) {          if (argc == 1) {
                 register int i, j, w, k;                  int i, j, w, k;
                 int columns, width = 0, lines;                  int columns, width = 0, lines;
                 extern int NCMDS;  
   
                 printf("Commands may be abbreviated.  Commands are:\n\n");                  printf("Commands may be abbreviated.  Commands are:\n\n");
                 for (c = cmdtab; c < &cmdtab[NCMDS]; c++) {                  for (c = cmdtab; c < &cmdtab[NCMDS]; c++) {
Line 498  help(argc, argv)
Line 501  help(argc, argv)
                 return;                  return;
         }          }
         while (--argc > 0) {          while (--argc > 0) {
                 register char *arg;                  char *arg;
                 arg = *++argv;                  arg = *++argv;
                 c = getcmd(arg);                  c = getcmd(arg);
                 if (c == (struct cmd *)-1)                  if (c == (struct cmd *)-1)

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2

CVSweb <webmaster@jp.NetBSD.org>