/* A Bison parser, made by GNU Bison 1.875d.  */

/* Skeleton parser for Yacc-like parsing with Bison,
   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

/* As a special exception, when this file is copied by Bison into a
   Bison output file, you may use that output file without restriction.
   This special exception was added by the Free Software Foundation
   in version 1.24 of Bison.  */

/* Written by Richard Stallman by simplifying the original so called
   ``semantic'' parser.  */

/* All symbols defined below should begin with yy or YY, to avoid
   infringing on user name space.  This should be done even for local
   variables, as they might otherwise be expanded by user macros.
   There are some unavoidable exceptions within include files to
   define necessary library symbols; they are noted "INFRINGES ON
   USER NAME SPACE" below.  */

/* Identify Bison output.  */
#define YYBISON 1

/* Skeleton name.  */
#define YYSKELETON_NAME "yacc.c"

/* Pure parsers.  */
#define YYPURE 0

/* Using locations.  */
#define YYLSP_NEEDED 0



/* Tokens.  */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
   /* Put the tokens into the symbol table, so that GDB and other debuggers
      know about them.  */
   enum yytokentype {
     SP = 258,
     CRLF = 259,
     COMMA = 260,
     STRING = 261,
     NUMBER = 262,
     USER = 263,
     PASS = 264,
     ACCT = 265,
     REIN = 266,
     QUIT = 267,
     PORT = 268,
     PASV = 269,
     TYPE = 270,
     STRU = 271,
     MODE = 272,
     RETR = 273,
     STOR = 274,
     APPE = 275,
     MLFL = 276,
     MAIL = 277,
     MSND = 278,
     MSOM = 279,
     MSAM = 280,
     MRSQ = 281,
     MRCP = 282,
     ALLO = 283,
     REST = 284,
     RNFR = 285,
     RNTO = 286,
     ABOR = 287,
     DELE = 288,
     CWD = 289,
     LIST = 290,
     NLST = 291,
     SITE = 292,
     STAT = 293,
     HELP = 294,
     NOOP = 295,
     MKD = 296,
     RMD = 297,
     PWD = 298,
     CDUP = 299,
     STOU = 300,
     SMNT = 301,
     SYST = 302,
     SIZE = 303,
     MDTM = 304,
     AUTH = 305,
     ADAT = 306,
     PROT = 307,
     PBSZ = 308,
     CCC = 309,
     UMASK = 310,
     IDLE = 311,
     CHMOD = 312,
     LEXERR = 313
   };
#endif
#define SP 258
#define CRLF 259
#define COMMA 260
#define STRING 261
#define NUMBER 262
#define USER 263
#define PASS 264
#define ACCT 265
#define REIN 266
#define QUIT 267
#define PORT 268
#define PASV 269
#define TYPE 270
#define STRU 271
#define MODE 272
#define RETR 273
#define STOR 274
#define APPE 275
#define MLFL 276
#define MAIL 277
#define MSND 278
#define MSOM 279
#define MSAM 280
#define MRSQ 281
#define MRCP 282
#define ALLO 283
#define REST 284
#define RNFR 285
#define RNTO 286
#define ABOR 287
#define DELE 288
#define CWD 289
#define LIST 290
#define NLST 291
#define SITE 292
#define STAT 293
#define HELP 294
#define NOOP 295
#define MKD 296
#define RMD 297
#define PWD 298
#define CDUP 299
#define STOU 300
#define SMNT 301
#define SYST 302
#define SIZE 303
#define MDTM 304
#define AUTH 305
#define ADAT 306
#define PROT 307
#define PBSZ 308
#define CCC 309
#define UMASK 310
#define IDLE 311
#define CHMOD 312
#define LEXERR 313




/* Copy the first part of user declarations.  */
#line 42 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"


#ifndef lint
static char sccsid[] = "@(#)ftpcmd.y	5.24 (Berkeley) 2/25/91";
#endif /* not lint */


#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>
#endif
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/ftp.h>
#include <signal.h>
#include <setjmp.h>
#include <syslog.h>
#include <time.h>
#include <pwd.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

#include "ftpd_var.h"

extern	char *auth_type;

unsigned int maxbuf, actualbuf;
unsigned char *ucbuf;

static int kerror;	/* XXX needed for all auth types */
#ifdef KRB5_KRB4_COMPAT
extern	struct sockaddr_in his_addr, ctrl_addr;
#include <krb.h>
extern AUTH_DAT kdata;
extern Key_schedule schedule;
extern MSG_DAT msg_data;
#endif /* KRB5_KRB4_COMPAT */
#ifdef GSSAPI
#include <gssapi/gssapi.h>
#include <gssapi/gssapi_generic.h>
extern gss_ctx_id_t gcontext;
#endif

#ifndef unix
/* sigh */
#if defined(_AIX) || defined(__hpux) || defined(BSD)
#define unix
#endif
#endif

#ifndef NBBY
#define NBBY 8
#endif

static struct sockaddr_in host_port;

extern	struct sockaddr_in data_dest;
extern	int logged_in;
extern	struct passwd *pw;
extern	int guest;
extern	int logging;
extern	int type;
extern	int form;
extern	int clevel;
extern	int debug;


extern	int allow_ccc;
extern	int ccc_ok;
extern	int timeout;
extern	int maxtimeout;
extern  int pdata;
extern	int authlevel;
extern	char hostname[], remotehost[];
extern	char proctitle[];
extern	char *globerr;
extern	int usedefault;
extern  int transflag;
extern  char tmpline[];

char	**ftpglob();

off_t	restart_point;

static	int cmd_type;
static	int cmd_form;
static	int cmd_bytesz;
char	cbuf[FTP_BUFSIZ]; /* was 512 */
char	*fromname;

/* bison needs these decls up front */
extern jmp_buf errcatch;

#define	CMD	0	/* beginning of command */
#define	ARGS	1	/* expect miscellaneous arguments */
#define	STR1	2	/* expect SP followed by STRING */
#define	STR2	3	/* expect STRING */
#define	OSTR	4	/* optional SP then STRING */
#define	ZSTR1	5	/* SP then optional STRING */
#define	ZSTR2	6	/* optional STRING after SP */
#define	SITECMD	7	/* SITE command */
#define	NSTR	8	/* Number followed by a string */

struct tab {
	char	*name;
	short	token;
	short	state;
	short	implemented;	/* 1 if command is implemented */
	char	*help;
};
struct tab cmdtab[];
struct tab sitetab[];

void sizecmd(char *);
void help(struct tab *, char *);
static int yylex(void);
static char *copy(char *);


/* Enabling traces.  */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif

/* Enabling verbose error messages.  */
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# define YYERROR_VERBOSE 0
#endif

#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
#line 167 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
typedef union YYSTYPE { int num; char *str; } YYSTYPE;
/* Line 191 of yacc.c.  */
#line 319 "y.tab.c"
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif



/* Copy the second part of user declarations.  */


/* Line 214 of yacc.c.  */
#line 331 "y.tab.c"

#if ! defined (yyoverflow) || YYERROR_VERBOSE

# ifndef YYFREE
#  define YYFREE free
# endif
# ifndef YYMALLOC
#  define YYMALLOC malloc
# endif

/* The parser invokes alloca or malloc; define the necessary symbols.  */

# ifdef YYSTACK_USE_ALLOCA
#  if YYSTACK_USE_ALLOCA
#   define YYSTACK_ALLOC alloca
#  endif
# else
#  if defined (alloca) || defined (_ALLOCA_H)
#   define YYSTACK_ALLOC alloca
#  else
#   ifdef __GNUC__
#    define YYSTACK_ALLOC __builtin_alloca
#   endif
#  endif
# endif

# ifdef YYSTACK_ALLOC
   /* Pacify GCC's `empty if-body' warning. */
#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
# else
#  if defined (__STDC__) || defined (__cplusplus)
#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
#   define YYSIZE_T size_t
#  endif
#  define YYSTACK_ALLOC YYMALLOC
#  define YYSTACK_FREE YYFREE
# endif
#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */


#if (! defined (yyoverflow) \
     && (! defined (__cplusplus) \
	 || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))

/* A type that is properly aligned for any stack member.  */
union yyalloc
{
  short int yyss;
  YYSTYPE yyvs;
  };

/* The size of the maximum gap between one aligned stack and the next.  */
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)

/* The size of an array large to enough to hold all stacks, each with
   N elements.  */
# define YYSTACK_BYTES(N) \
     ((N) * (sizeof (short int) + sizeof (YYSTYPE))			\
      + YYSTACK_GAP_MAXIMUM)

/* Copy COUNT objects from FROM to TO.  The source and destination do
   not overlap.  */
# ifndef YYCOPY
#  if defined (__GNUC__) && 1 < __GNUC__
#   define YYCOPY(To, From, Count) \
      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
#  else
#   define YYCOPY(To, From, Count)		\
      do					\
	{					\
	  register YYSIZE_T yyi;		\
	  for (yyi = 0; yyi < (Count); yyi++)	\
	    (To)[yyi] = (From)[yyi];		\
	}					\
      while (0)
#  endif
# endif

/* Relocate STACK from its old location to the new one.  The
   local variables YYSIZE and YYSTACKSIZE give the old and new number of
   elements in the stack, and YYPTR gives the new location of the
   stack.  Advance YYPTR to a properly aligned location for the next
   stack.  */
# define YYSTACK_RELOCATE(Stack)					\
    do									\
      {									\
	YYSIZE_T yynewbytes;						\
	YYCOPY (&yyptr->Stack, Stack, yysize);				\
	Stack = &yyptr->Stack;						\
	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
	yyptr += yynewbytes / sizeof (*yyptr);				\
      }									\
    while (0)

#endif

#if defined (__STDC__) || defined (__cplusplus)
   typedef signed char yysigned_char;
#else
   typedef short int yysigned_char;
#endif

/* YYFINAL -- State number of the termination state. */
#define YYFINAL  2
/* YYLAST -- Last index in YYTABLE.  */
#define YYLAST   217

/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS  71
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS  18
/* YYNRULES -- Number of rules. */
#define YYNRULES  85
/* YYNRULES -- Number of states. */
#define YYNSTATES  230

/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
#define YYUNDEFTOK  2
#define YYMAXUTOK   313

#define YYTRANSLATE(YYX) 						\
  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)

/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
static const unsigned char yytranslate[] =
{
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,    66,    70,    62,     2,    65,
      69,     2,     2,    67,     2,     2,    68,     2,    60,     2,
      64,     2,    59,    63,    61,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
      25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
      35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
      45,    46,    47,    48,    49,    50,    51,    52,    53,    54,
      55,    56,    57,    58
};

#if YYDEBUG
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
   YYRHS.  */
static const unsigned short int yyprhs[] =
{
       0,     0,     3,     4,     7,    10,    15,    20,    25,    29,
      34,    37,    42,    47,    52,    57,    62,    71,    77,    83,
      89,    93,    99,   103,   109,   115,   118,   124,   129,   132,
     136,   142,   145,   150,   153,   159,   165,   169,   173,   178,
     185,   191,   199,   209,   214,   221,   227,   230,   236,   242,
     247,   252,   255,   258,   264,   269,   271,   272,   274,   276,
     288,   290,   292,   294,   296,   298,   300,   302,   304,   308,
     310,   314,   316,   318,   322,   325,   327,   329,   331,   333,
     335,   337,   339,   341,   343,   344
};

/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yysigned_char yyrhs[] =
{
      72,     0,    -1,    -1,    72,    73,    -1,    72,    74,    -1,
       8,     3,    75,     4,    -1,     9,     3,    76,     4,    -1,
      13,     3,    78,     4,    -1,    14,    87,     4,    -1,    52,
       3,    80,     4,    -1,    54,     4,    -1,    53,     3,     6,
       4,    -1,    15,     3,    81,     4,    -1,    16,     3,    82,
       4,    -1,    17,     3,    83,     4,    -1,    28,     3,     7,
       4,    -1,    28,     3,     7,     3,    59,     3,     7,     4,
      -1,    18,    87,     3,    84,     4,    -1,    19,    87,     3,
      84,     4,    -1,    20,    87,     3,    84,     4,    -1,    36,
      87,     4,    -1,    36,    87,     3,     6,     4,    -1,    35,
      87,     4,    -1,    35,    87,     3,    84,     4,    -1,    38,
      87,     3,    84,     4,    -1,    38,     4,    -1,    33,    87,
       3,    84,     4,    -1,    31,     3,    84,     4,    -1,    32,
       4,    -1,    34,    87,     4,    -1,    34,    87,     3,    84,
       4,    -1,    39,     4,    -1,    39,     3,     6,     4,    -1,
      40,     4,    -1,    41,    88,     3,    84,     4,    -1,    42,
      88,     3,    84,     4,    -1,    43,    87,     4,    -1,    44,
      87,     4,    -1,    37,     3,    39,     4,    -1,    37,     3,
      39,     3,     6,     4,    -1,    37,     3,    55,    87,     4,
      -1,    37,     3,    55,    88,     3,    86,     4,    -1,    37,
       3,    57,    88,     3,    86,     3,    84,     4,    -1,    37,
       3,    56,     4,    -1,    37,     3,    56,     3,     7,     4,
      -1,    45,    87,     3,    84,     4,    -1,    47,     4,    -1,
      48,    87,     3,    84,     4,    -1,    49,    87,     3,    84,
       4,    -1,    50,     3,     6,     4,    -1,    51,     3,     6,
       4,    -1,    12,     4,    -1,     1,     4,    -1,    30,    87,
       3,    84,     4,    -1,    29,     3,    77,     4,    -1,     6,
      -1,    -1,     6,    -1,     7,    -1,     7,     5,     7,     5,
       7,     5,     7,     5,     7,     5,     7,    -1,    60,    -1,
      61,    -1,    62,    -1,    62,    -1,    63,    -1,    64,    -1,
      65,    -1,    66,    -1,    66,     3,    79,    -1,    65,    -1,
      65,     3,    79,    -1,    67,    -1,    68,    -1,    68,     3,
      77,    -1,    68,    77,    -1,    69,    -1,    59,    -1,    64,
      -1,    63,    -1,    70,    -1,    62,    -1,    85,    -1,     6,
      -1,     7,    -1,    -1,    87,    -1
};

/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
static const unsigned short int yyrline[] =
{
       0,   197,   197,   198,   203,   206,   211,   216,   235,   240,
     247,   261,   286,   321,   333,   345,   349,   353,   360,   367,
     374,   379,   386,   391,   398,   405,   409,   416,   427,   431,
     436,   443,   447,   462,   466,   473,   480,   485,   490,   494,
     498,   508,   523,   537,   543,   557,   564,   588,   605,   628,
     632,   637,   642,   647,   657,   667,   671,   674,   677,   680,
     693,   697,   701,   707,   711,   715,   719,   725,   730,   735,
     740,   745,   749,   754,   760,   767,   771,   775,   781,   785,
     789,   795,   821,   824,   850,   860
};
#endif

#if YYDEBUG || YYERROR_VERBOSE
/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
   First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
  "$end", "error", "$undefined", "SP", "CRLF", "COMMA", "STRING",
  "NUMBER", "USER", "PASS", "ACCT", "REIN", "QUIT", "PORT", "PASV", "TYPE",
  "STRU", "MODE", "RETR", "STOR", "APPE", "MLFL", "MAIL", "MSND", "MSOM",
  "MSAM", "MRSQ", "MRCP", "ALLO", "REST", "RNFR", "RNTO", "ABOR", "DELE",
  "CWD", "LIST", "NLST", "SITE", "STAT", "HELP", "NOOP", "MKD", "RMD",
  "PWD", "CDUP", "STOU", "SMNT", "SYST", "SIZE", "MDTM", "AUTH", "ADAT",
  "PROT", "PBSZ", "CCC", "UMASK", "IDLE", "CHMOD", "LEXERR", "'R'", "'N'",
  "'T'", "'C'", "'S'", "'P'", "'E'", "'A'", "'I'", "'L'", "'F'", "'B'",
  "$accept", "cmd_list", "cmd", "rcmd", "username", "password",
  "byte_size", "host_port", "form_code", "prot_code", "type_code",
  "struct_code", "mode_code", "pathname", "pathstring", "octal_number",
  "check_login", "nonguest", 0
};
#endif

# ifdef YYPRINT
/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
   token YYLEX-NUM.  */
static const unsigned short int yytoknum[] =
{
       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
     265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
     275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
     285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
     295,   296,   297,   298,   299,   300,   301,   302,   303,   304,
     305,   306,   307,   308,   309,   310,   311,   312,   313,    82,
      78,    84,    67,    83,    80,    69,    65,    73,    76,    70,
      66
};
# endif

/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
static const unsigned char yyr1[] =
{
       0,    71,    72,    72,    72,    73,    73,    73,    73,    73,
      73,    73,    73,    73,    73,    73,    73,    73,    73,    73,
      73,    73,    73,    73,    73,    73,    73,    73,    73,    73,
      73,    73,    73,    73,    73,    73,    73,    73,    73,    73,
      73,    73,    73,    73,    73,    73,    73,    73,    73,    73,
      73,    73,    73,    74,    74,    75,    76,    76,    77,    78,
      79,    79,    79,    80,    80,    80,    80,    81,    81,    81,
      81,    81,    81,    81,    81,    82,    82,    82,    83,    83,
      83,    84,    85,    86,    87,    88
};

/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
static const unsigned char yyr2[] =
{
       0,     2,     0,     2,     2,     4,     4,     4,     3,     4,
       2,     4,     4,     4,     4,     4,     8,     5,     5,     5,
       3,     5,     3,     5,     5,     2,     5,     4,     2,     3,
       5,     2,     4,     2,     5,     5,     3,     3,     4,     6,
       5,     7,     9,     4,     6,     5,     2,     5,     5,     4,
       4,     2,     2,     5,     4,     1,     0,     1,     1,    11,
       1,     1,     1,     1,     1,     1,     1,     1,     3,     1,
       3,     1,     1,     3,     2,     1,     1,     1,     1,     1,
       1,     1,     1,     1,     0,     1
};

/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
   means the default is an error.  */
static const unsigned char yydefact[] =
{
       2,     0,     1,     0,     0,     0,     0,     0,    84,     0,
       0,     0,    84,    84,    84,     0,     0,    84,     0,     0,
      84,    84,    84,    84,     0,    84,     0,     0,    84,    84,
      84,    84,    84,     0,    84,    84,     0,     0,     0,     0,
       0,     3,     4,    52,     0,    56,    51,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,    28,
       0,     0,     0,     0,     0,    25,     0,     0,    31,    33,
      85,     0,     0,     0,     0,     0,    46,     0,     0,     0,
       0,     0,     0,    10,    55,     0,    57,     0,     0,     0,
       8,    69,    67,    71,    72,     0,    76,    77,    75,     0,
      80,    78,    79,     0,     0,     0,     0,     0,    58,     0,
       0,    82,     0,    81,     0,     0,    29,     0,    22,     0,
      20,     0,    84,     0,    84,     0,     0,     0,     0,    36,
      37,     0,     0,     0,     0,     0,    63,    64,    65,    66,
       0,     0,     5,     6,     0,     7,     0,     0,     0,    74,
      12,    13,    14,     0,     0,     0,     0,    15,    54,     0,
      27,     0,     0,     0,     0,     0,    38,    85,     0,     0,
      43,     0,     0,    32,     0,     0,     0,     0,     0,    49,
      50,     9,    11,     0,    60,    61,    62,    70,    68,    73,
      17,    18,    19,     0,    53,    26,    30,    23,    21,     0,
      40,     0,     0,     0,    24,    34,    35,    45,    47,    48,
       0,     0,    39,    83,     0,    44,     0,     0,     0,    41,
       0,     0,    16,     0,     0,    42,     0,     0,     0,    59
};

/* YYDEFGOTO[NTERM-NUM]. */
static const short int yydefgoto[] =
{
      -1,     1,    41,    42,    85,    87,   109,    89,   187,   140,
      95,    99,   103,   112,   113,   214,    70,    71
};

/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
   STATE-NUM.  */
#define YYPACT_NINF -105
static const short int yypact[] =
{
    -105,    94,  -105,    21,     2,    12,    38,    19,  -105,    48,
      56,    72,  -105,  -105,  -105,    73,    74,  -105,    75,    76,
    -105,  -105,  -105,  -105,    78,    79,    16,    80,  -105,  -105,
    -105,  -105,  -105,    81,  -105,  -105,    83,    84,    85,    86,
      87,  -105,  -105,  -105,    91,    93,  -105,    97,    88,   -11,
     -52,   -54,    90,    98,   102,   108,   110,   115,   113,  -105,
     117,    30,    33,    64,     5,  -105,   118,   143,  -105,  -105,
    -105,   147,   148,    96,   149,   151,  -105,   152,   153,   146,
     154,     1,   155,  -105,  -105,   158,  -105,   159,    77,   160,
    -105,   156,   162,  -105,    11,   163,  -105,  -105,  -105,   164,
    -105,  -105,  -105,   165,   113,   113,   113,    66,  -105,   166,
     113,  -105,   167,  -105,   113,   113,  -105,   113,  -105,   168,
    -105,    68,  -105,    70,  -105,   113,   169,   113,   113,  -105,
    -105,   113,   113,   113,   171,   172,  -105,  -105,  -105,  -105,
     173,   174,  -105,  -105,   150,  -105,   -15,   -15,   110,  -105,
    -105,  -105,  -105,   175,   176,   177,    20,  -105,  -105,   178,
    -105,   179,   180,   181,   182,   183,  -105,   184,   187,   185,
    -105,   188,   189,  -105,   190,   191,   192,   193,   194,  -105,
    -105,  -105,  -105,   161,  -105,  -105,  -105,  -105,  -105,  -105,
    -105,  -105,  -105,   196,  -105,  -105,  -105,  -105,  -105,   197,
    -105,   195,   199,   195,  -105,  -105,  -105,  -105,  -105,  -105,
     198,   200,  -105,  -105,   202,  -105,   201,   203,   205,  -105,
     113,   204,  -105,   206,   207,  -105,   208,   209,   210,  -105
};

/* YYPGOTO[NTERM-NUM].  */
static const yysigned_char yypgoto[] =
{
    -105,  -105,  -105,  -105,  -105,  -105,   -90,  -105,   -57,  -105,
    -105,  -105,  -105,  -104,  -105,   -45,    18,   -26
};

/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
   positive, shift that token.  If negative, reduce the rule which
   number is the opposite.  If zero, do what YYDEFACT says.
   If YYTABLE_NINF, syntax error.  */
#define YYTABLE_NINF -1
static const unsigned char yytable[] =
{
     153,   154,   155,    72,   149,    44,   159,    96,   100,   101,
     161,   162,    97,   163,   148,    45,   102,    98,   108,    67,
      68,   172,    47,   174,   175,    43,    48,   176,   177,   178,
      52,    53,    54,   115,   116,    57,   117,   118,    60,    61,
      62,    63,    46,    66,   121,   184,   185,   186,    73,    74,
      75,    49,    77,    78,    91,    92,    93,    94,   189,    50,
     122,   123,   124,   136,   137,   138,   139,   119,   120,   156,
     157,   165,   166,   169,   170,    51,    55,    56,    58,   193,
      59,    64,   144,    65,    69,    76,    79,    80,    81,    82,
     188,    83,    90,   104,     2,     3,   168,    84,   171,    86,
     129,   105,     4,     5,    88,   106,     6,     7,     8,     9,
      10,    11,    12,    13,    14,   107,   223,   108,   110,   111,
     114,   125,    15,    16,    17,    18,    19,    20,    21,    22,
      23,    24,    25,    26,    27,    28,    29,    30,    31,    32,
     167,    33,    34,    35,    36,    37,    38,    39,    40,   126,
     127,   128,   134,   130,   131,   132,   133,   183,   216,   146,
     135,   141,   142,   143,   145,   147,   210,   150,   151,   152,
     158,   160,     0,   173,   164,   179,   180,   181,   182,   190,
     191,   192,   194,   195,   196,   197,   198,     0,   200,   199,
     201,   203,   202,   204,   205,   206,   207,   208,   209,   211,
       0,   212,   213,   215,   220,   217,   219,   218,   221,   222,
     225,   224,   226,     0,   228,   227,     0,   229
};

static const short int yycheck[] =
{
     104,   105,   106,    29,    94,     3,   110,    59,    62,    63,
     114,   115,    64,   117,     3,     3,    70,    69,     7,     3,
       4,   125,     3,   127,   128,     4,     8,   131,   132,   133,
      12,    13,    14,     3,     4,    17,     3,     4,    20,    21,
      22,    23,     4,    25,    39,    60,    61,    62,    30,    31,
      32,     3,    34,    35,    65,    66,    67,    68,   148,     3,
      55,    56,    57,    62,    63,    64,    65,     3,     4,     3,
       4,     3,     4,     3,     4,     3,     3,     3,     3,    59,
       4,     3,     5,     4,     4,     4,     3,     3,     3,     3,
     147,     4,     4,     3,     0,     1,   122,     6,   124,     6,
       4,     3,     8,     9,     7,     3,    12,    13,    14,    15,
      16,    17,    18,    19,    20,     7,   220,     7,     3,     6,
       3,     3,    28,    29,    30,    31,    32,    33,    34,    35,
      36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
     122,    47,    48,    49,    50,    51,    52,    53,    54,     6,
       3,     3,     6,     4,     3,     3,     3,     7,   203,     3,
       6,     6,     4,     4,     4,     3,     5,     4,     4,     4,
       4,     4,    -1,     4,     6,     4,     4,     4,     4,     4,
       4,     4,     4,     4,     4,     4,     4,    -1,     4,     6,
       3,     3,     7,     4,     4,     4,     4,     4,     4,     3,
      -1,     4,     7,     4,     3,     7,     4,     7,     5,     4,
       4,     7,     5,    -1,     5,     7,    -1,     7
};

/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
   symbol of state STATE-NUM.  */
static const unsigned char yystos[] =
{
       0,    72,     0,     1,     8,     9,    12,    13,    14,    15,
      16,    17,    18,    19,    20,    28,    29,    30,    31,    32,
      33,    34,    35,    36,    37,    38,    39,    40,    41,    42,
      43,    44,    45,    47,    48,    49,    50,    51,    52,    53,
      54,    73,    74,     4,     3,     3,     4,     3,    87,     3,
       3,     3,    87,    87,    87,     3,     3,    87,     3,     4,
      87,    87,    87,    87,     3,     4,    87,     3,     4,     4,
      87,    88,    88,    87,    87,    87,     4,    87,    87,     3,
       3,     3,     3,     4,     6,    75,     6,    76,     7,    78,
       4,    65,    66,    67,    68,    81,    59,    64,    69,    82,
      62,    63,    70,    83,     3,     3,     3,     7,     7,    77,
       3,     6,    84,    85,     3,     3,     4,     3,     4,     3,
       4,    39,    55,    56,    57,     3,     6,     3,     3,     4,
       4,     3,     3,     3,     6,     6,    62,    63,    64,    65,
      80,     6,     4,     4,     5,     4,     3,     3,     3,    77,
       4,     4,     4,    84,    84,    84,     3,     4,     4,    84,
       4,    84,    84,    84,     6,     3,     4,    87,    88,     3,
       4,    88,    84,     4,    84,    84,    84,    84,    84,     4,
       4,     4,     4,     7,    60,    61,    62,    79,    79,    77,
       4,     4,     4,    59,     4,     4,     4,     4,     4,     6,
       4,     3,     7,     3,     4,     4,     4,     4,     4,     4,
       5,     3,     4,     7,    86,     4,    86,     7,     7,     4,
       3,     5,     4,    84,     7,     4,     5,     7,     5,     7
};

#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
# define YYSIZE_T __SIZE_TYPE__
#endif
#if ! defined (YYSIZE_T) && defined (size_t)
# define YYSIZE_T size_t
#endif
#if ! defined (YYSIZE_T)
# if defined (__STDC__) || defined (__cplusplus)
#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
#  define YYSIZE_T size_t
# endif
#endif
#if ! defined (YYSIZE_T)
# define YYSIZE_T unsigned int
#endif

#define yyerrok		(yyerrstatus = 0)
#define yyclearin	(yychar = YYEMPTY)
#define YYEMPTY		(-2)
#define YYEOF		0

#define YYACCEPT	goto yyacceptlab
#define YYABORT		goto yyabortlab
#define YYERROR		goto yyerrorlab


/* Like YYERROR except do call yyerror.  This remains here temporarily
   to ease the transition to the new meaning of YYERROR, for GCC.
   Once GCC version 2 has supplanted version 1, this can go.  */

#define YYFAIL		goto yyerrlab

#define YYRECOVERING()  (!!yyerrstatus)

#define YYBACKUP(Token, Value)					\
do								\
  if (yychar == YYEMPTY && yylen == 1)				\
    {								\
      yychar = (Token);						\
      yylval = (Value);						\
      yytoken = YYTRANSLATE (yychar);				\
      YYPOPSTACK;						\
      goto yybackup;						\
    }								\
  else								\
    { 								\
      yyerror ("syntax error: cannot back up");\
      YYERROR;							\
    }								\
while (0)

#define YYTERROR	1
#define YYERRCODE	256

/* YYLLOC_DEFAULT -- Compute the default location (before the actions
   are run).  */

#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N)		\
   ((Current).first_line   = (Rhs)[1].first_line,	\
    (Current).first_column = (Rhs)[1].first_column,	\
    (Current).last_line    = (Rhs)[N].last_line,	\
    (Current).last_column  = (Rhs)[N].last_column)
#endif

/* YYLEX -- calling `yylex' with the right arguments.  */

#ifdef YYLEX_PARAM
# define YYLEX yylex (YYLEX_PARAM)
#else
# define YYLEX yylex ()
#endif

/* Enable debugging if requested.  */
#if YYDEBUG

# ifndef YYFPRINTF
#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
#  define YYFPRINTF fprintf
# endif

# define YYDPRINTF(Args)			\
do {						\
  if (yydebug)					\
    YYFPRINTF Args;				\
} while (0)

# define YYDSYMPRINT(Args)			\
do {						\
  if (yydebug)					\
    yysymprint Args;				\
} while (0)

# define YYDSYMPRINTF(Title, Token, Value, Location)		\
do {								\
  if (yydebug)							\
    {								\
      YYFPRINTF (stderr, "%s ", Title);				\
      yysymprint (stderr, 					\
                  Token, Value);	\
      YYFPRINTF (stderr, "\n");					\
    }								\
} while (0)

/*------------------------------------------------------------------.
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
| TOP (included).                                                   |
`------------------------------------------------------------------*/

#if defined (__STDC__) || defined (__cplusplus)
static void
yy_stack_print (short int *bottom, short int *top)
#else
static void
yy_stack_print (bottom, top)
    short int *bottom;
    short int *top;
#endif
{
  YYFPRINTF (stderr, "Stack now");
  for (/* Nothing. */; bottom <= top; ++bottom)
    YYFPRINTF (stderr, " %d", *bottom);
  YYFPRINTF (stderr, "\n");
}

# define YY_STACK_PRINT(Bottom, Top)				\
do {								\
  if (yydebug)							\
    yy_stack_print ((Bottom), (Top));				\
} while (0)


/*------------------------------------------------.
| Report that the YYRULE is going to be reduced.  |
`------------------------------------------------*/

#if defined (__STDC__) || defined (__cplusplus)
static void
yy_reduce_print (int yyrule)
#else
static void
yy_reduce_print (yyrule)
    int yyrule;
#endif
{
  int yyi;
  unsigned int yylno = yyrline[yyrule];
  YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
             yyrule - 1, yylno);
  /* Print the symbols being reduced, and their result.  */
  for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
    YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
  YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
}

# define YY_REDUCE_PRINT(Rule)		\
do {					\
  if (yydebug)				\
    yy_reduce_print (Rule);		\
} while (0)

/* Nonzero means print parse trace.  It is left uninitialized so that
   multiple parsers can coexist.  */
int yydebug;
#else /* !YYDEBUG */
# define YYDPRINTF(Args)
# define YYDSYMPRINT(Args)
# define YYDSYMPRINTF(Title, Token, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */


/* YYINITDEPTH -- initial size of the parser's stacks.  */
#ifndef	YYINITDEPTH
# define YYINITDEPTH 200
#endif

/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
   if the built-in stack extension method is used).

   Do not make this value too large; the results are undefined if
   SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
   evaluated with infinite-precision integer arithmetic.  */

#if defined (YYMAXDEPTH) && YYMAXDEPTH == 0
# undef YYMAXDEPTH
#endif

#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif



#if YYERROR_VERBOSE

# ifndef yystrlen
#  if defined (__GLIBC__) && defined (_STRING_H)
#   define yystrlen strlen
#  else
/* Return the length of YYSTR.  */
static YYSIZE_T
#   if defined (__STDC__) || defined (__cplusplus)
yystrlen (const char *yystr)
#   else
yystrlen (yystr)
     const char *yystr;
#   endif
{
  register const char *yys = yystr;

  while (*yys++ != '\0')
    continue;

  return yys - yystr - 1;
}
#  endif
# endif

# ifndef yystpcpy
#  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
#   define yystpcpy stpcpy
#  else
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
   YYDEST.  */
static char *
#   if defined (__STDC__) || defined (__cplusplus)
yystpcpy (char *yydest, const char *yysrc)
#   else
yystpcpy (yydest, yysrc)
     char *yydest;
     const char *yysrc;
#   endif
{
  register char *yyd = yydest;
  register const char *yys = yysrc;

  while ((*yyd++ = *yys++) != '\0')
    continue;

  return yyd - 1;
}
#  endif
# endif

#endif /* !YYERROR_VERBOSE */



#if YYDEBUG
/*--------------------------------.
| Print this symbol on YYOUTPUT.  |
`--------------------------------*/

#if defined (__STDC__) || defined (__cplusplus)
static void
yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
#else
static void
yysymprint (yyoutput, yytype, yyvaluep)
    FILE *yyoutput;
    int yytype;
    YYSTYPE *yyvaluep;
#endif
{
  /* Pacify ``unused variable'' warnings.  */
  (void) yyvaluep;

  if (yytype < YYNTOKENS)
    {
      YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
# ifdef YYPRINT
      YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
# endif
    }
  else
    YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);

  switch (yytype)
    {
      default:
        break;
    }
  YYFPRINTF (yyoutput, ")");
}

#endif /* ! YYDEBUG */
/*-----------------------------------------------.
| Release the memory associated to this symbol.  |
`-----------------------------------------------*/

#if defined (__STDC__) || defined (__cplusplus)
static void
yydestruct (int yytype, YYSTYPE *yyvaluep)
#else
static void
yydestruct (yytype, yyvaluep)
    int yytype;
    YYSTYPE *yyvaluep;
#endif
{
  /* Pacify ``unused variable'' warnings.  */
  (void) yyvaluep;

  switch (yytype)
    {

      default:
        break;
    }
}


/* Prevent warnings from -Wmissing-prototypes.  */

#ifdef YYPARSE_PARAM
# if defined (__STDC__) || defined (__cplusplus)
int yyparse (void *YYPARSE_PARAM);
# else
int yyparse ();
# endif
#else /* ! YYPARSE_PARAM */
#if defined (__STDC__) || defined (__cplusplus)
int yyparse (void);
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */



/* The lookahead symbol.  */
int yychar;

/* The semantic value of the lookahead symbol.  */
YYSTYPE yylval;

/* Number of syntax errors so far.  */
int yynerrs;



/*----------.
| yyparse.  |
`----------*/

#ifdef YYPARSE_PARAM
# if defined (__STDC__) || defined (__cplusplus)
int yyparse (void *YYPARSE_PARAM)
# else
int yyparse (YYPARSE_PARAM)
  void *YYPARSE_PARAM;
# endif
#else /* ! YYPARSE_PARAM */
#if defined (__STDC__) || defined (__cplusplus)
int
yyparse (void)
#else
int
yyparse ()

#endif
#endif
{
  
  register int yystate;
  register int yyn;
  int yyresult;
  /* Number of tokens to shift before error messages enabled.  */
  int yyerrstatus;
  /* Lookahead token as an internal (translated) token number.  */
  int yytoken = 0;

  /* Three stacks and their tools:
     `yyss': related to states,
     `yyvs': related to semantic values,
     `yyls': related to locations.

     Refer to the stacks thru separate pointers, to allow yyoverflow
     to reallocate them elsewhere.  */

  /* The state stack.  */
  short int yyssa[YYINITDEPTH];
  short int *yyss = yyssa;
  register short int *yyssp;

  /* The semantic value stack.  */
  YYSTYPE yyvsa[YYINITDEPTH];
  YYSTYPE *yyvs = yyvsa;
  register YYSTYPE *yyvsp;



#define YYPOPSTACK   (yyvsp--, yyssp--)

  YYSIZE_T yystacksize = YYINITDEPTH;

  /* The variables used to return semantic value and location from the
     action routines.  */
  YYSTYPE yyval;


  /* When reducing, the number of symbols on the RHS of the reduced
     rule.  */
  int yylen;

  YYDPRINTF ((stderr, "Starting parse\n"));

  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = YYEMPTY;		/* Cause a token to be read.  */

  /* Initialize stack pointers.
     Waste one element of value and location stack
     so that they stay on the same level as the state stack.
     The wasted elements are never initialized.  */

  yyssp = yyss;
  yyvsp = yyvs;


  goto yysetstate;

/*------------------------------------------------------------.
| yynewstate -- Push a new state, which is found in yystate.  |
`------------------------------------------------------------*/
 yynewstate:
  /* In all cases, when you get here, the value and location stacks
     have just been pushed. so pushing a state here evens the stacks.
     */
  yyssp++;

 yysetstate:
  *yyssp = yystate;

  if (yyss + yystacksize - 1 <= yyssp)
    {
      /* Get the current used size of the three stacks, in elements.  */
      YYSIZE_T yysize = yyssp - yyss + 1;

#ifdef yyoverflow
      {
	/* Give user a chance to reallocate the stack. Use copies of
	   these so that the &'s don't force the real ones into
	   memory.  */
	YYSTYPE *yyvs1 = yyvs;
	short int *yyss1 = yyss;


	/* Each stack pointer address is followed by the size of the
	   data in use in that stack, in bytes.  This used to be a
	   conditional around just the two extra args, but that might
	   be undefined if yyoverflow is a macro.  */
	yyoverflow ("parser stack overflow",
		    &yyss1, yysize * sizeof (*yyssp),
		    &yyvs1, yysize * sizeof (*yyvsp),

		    &yystacksize);

	yyss = yyss1;
	yyvs = yyvs1;
      }
#else /* no yyoverflow */
# ifndef YYSTACK_RELOCATE
      goto yyoverflowlab;
# else
      /* Extend the stack our own way.  */
      if (YYMAXDEPTH <= yystacksize)
	goto yyoverflowlab;
      yystacksize *= 2;
      if (YYMAXDEPTH < yystacksize)
	yystacksize = YYMAXDEPTH;

      {
	short int *yyss1 = yyss;
	union yyalloc *yyptr =
	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
	if (! yyptr)
	  goto yyoverflowlab;
	YYSTACK_RELOCATE (yyss);
	YYSTACK_RELOCATE (yyvs);

#  undef YYSTACK_RELOCATE
	if (yyss1 != yyssa)
	  YYSTACK_FREE (yyss1);
      }
# endif
#endif /* no yyoverflow */

      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;


      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
		  (unsigned long int) yystacksize));

      if (yyss + yystacksize - 1 <= yyssp)
	YYABORT;
    }

  YYDPRINTF ((stderr, "Entering state %d\n", yystate));

  goto yybackup;

/*-----------.
| yybackup.  |
`-----------*/
yybackup:

/* Do appropriate processing given the current state.  */
/* Read a lookahead token if we need one and don't already have one.  */
/* yyresume: */

  /* First try to decide what to do without reference to lookahead token.  */

  yyn = yypact[yystate];
  if (yyn == YYPACT_NINF)
    goto yydefault;

  /* Not known => get a lookahead token if don't already have one.  */

  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
  if (yychar == YYEMPTY)
    {
      YYDPRINTF ((stderr, "Reading a token: "));
      yychar = YYLEX;
    }

  if (yychar <= YYEOF)
    {
      yychar = yytoken = YYEOF;
      YYDPRINTF ((stderr, "Now at end of input.\n"));
    }
  else
    {
      yytoken = YYTRANSLATE (yychar);
      YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
    }

  /* If the proper action on seeing token YYTOKEN is to reduce or to
     detect an error, take that action.  */
  yyn += yytoken;
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (yyn == 0 || yyn == YYTABLE_NINF)
	goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }

  if (yyn == YYFINAL)
    YYACCEPT;

  /* Shift the lookahead token.  */
  YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));

  /* Discard the token being shifted unless it is eof.  */
  if (yychar != YYEOF)
    yychar = YYEMPTY;

  *++yyvsp = yylval;


  /* Count tokens shifted since error; after three, turn off error
     status.  */
  if (yyerrstatus)
    yyerrstatus--;

  yystate = yyn;
  goto yynewstate;


/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state.  |
`-----------------------------------------------------------*/
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;


/*-----------------------------.
| yyreduce -- Do a reduction.  |
`-----------------------------*/
yyreduce:
  /* yyn is the number of a rule to reduce with.  */
  yylen = yyr2[yyn];

  /* If YYLEN is nonzero, implement the default value of the action:
     `$$ = $1'.

     Otherwise, the following line sets YYVAL to garbage.
     This behavior is undocumented and Bison
     users should not rely upon it.  Assigning to YYVAL
     unconditionally makes the parser a bit smaller, and it avoids a
     GCC warning that YYVAL may be used uninitialized.  */
  yyval = yyvsp[1-yylen];


  YY_REDUCE_PRINT (yyn);
  switch (yyn)
    {
        case 3:
#line 199 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			fromname = (char *) 0;
			restart_point = (off_t) 0;
		}
    break;

  case 5:
#line 207 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			user((char *) yyvsp[-1].str);
			free((char *) yyvsp[-1].str);
		}
    break;

  case 6:
#line 212 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			pass((char *) yyvsp[-1].str);
			free((char *) yyvsp[-1].str);
		}
    break;

  case 7:
#line 217 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			/*
			 * Don't allow a port < 1024 if we're not
			 * connecting back to the original source address
			 * This prevents nastier forms of the bounce attack.
			 */
			if (ntohs(host_port.sin_port) < 1024)
				reply(504, "Port number too low");
			else {
				data_dest = host_port;
				usedefault = 0;
				if (pdata >= 0) {
					(void) close(pdata);
					pdata = -1;
				}
				reply(200, "PORT command successful.");
			}
		}
    break;

  case 8:
#line 236 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-1].num)
				passive();
		}
    break;

  case 9:
#line 241 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		    if (maxbuf)
			setdlevel (yyvsp[-1].num);
		    else
			reply(503, "Must first set PBSZ");
		}
    break;

  case 10:
#line 248 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (!allow_ccc) {
			    reply(534, "CCC not supported");
			}
			else {
			    if(clevel == PROT_C && !ccc_ok) {
			        reply(533, "CCC command must be integrity protected");
			    } else {
			        reply(200, "CCC command successful.");
				ccc_ok = 1;
			    }
			}
		}
    break;

  case 11:
#line 262 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			/* Others may want to do something more fancy here */
			if (!auth_type)
			    reply(503, "Must first perform authentication");
			else if (strlen(yyvsp[-1].str) > 10 ||
				 (strlen(yyvsp[-1].str) == 10 && 
				  strcmp(yyvsp[-1].str,"4294967296") >= 0))
			    reply(501, "Bad value for PBSZ: %s", yyvsp[-1].str);
			else {
			    if (ucbuf) (void) free(ucbuf);
			    actualbuf = (unsigned int) atol(yyvsp[-1].str);
			    /* I attempt what is asked for first, and if that
			       fails, I try dividing by 4 */
			    while ((ucbuf = (unsigned char *)malloc(actualbuf)) == NULL)
				if (actualbuf)
				    lreply(200, "Trying %u", actualbuf >>= 2);
				else {
				    perror_reply(421,
					"Local resource failure: malloc");
				    dologout(1);
				}
			    reply(200, "PBSZ=%u", maxbuf = actualbuf);
			}
		}
    break;

  case 12:
#line 287 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			switch (cmd_type) {

			case TYPE_A:
				if (cmd_form == FORM_N) {
					reply(200, "Type set to A.");
					type = cmd_type;
					form = cmd_form;
				} else
					reply(504, "Form must be N.");
				break;

			case TYPE_E:
				reply(504, "Type E not implemented.");
				break;

			case TYPE_I:
				reply(200, "Type set to I.");
				type = cmd_type;
				break;

			case TYPE_L:
#if NBBY == 8
				if (cmd_bytesz == 8) {
					reply(200,
					    "Type set to L (byte size 8).");
					type = cmd_type;
				} else
					reply(504, "Byte size must be 8.");
#else /* NBBY == 8 */
				UNIMPLEMENTED for NBBY != 8
#endif /* NBBY == 8 */
			}
		}
    break;

  case 13:
#line 322 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			switch (yyvsp[-1].num) {

			case STRU_F:
				reply(200, "STRU F ok.");
				break;

			default:
				reply(504, "Unimplemented STRU type.");
			}
		}
    break;

  case 14:
#line 334 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			switch (yyvsp[-1].num) {

			case MODE_S:
				reply(200, "MODE S ok.");
				break;

			default:
				reply(502, "Unimplemented MODE type.");
			}
		}
    break;

  case 15:
#line 346 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			reply(202, "ALLO command ignored.");
		}
    break;

  case 16:
#line 350 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			reply(202, "ALLO command ignored.");
		}
    break;

  case 17:
#line 354 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL)
				retrieve((char *) 0, (char *) yyvsp[-1].str);
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 18:
#line 361 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL)
				store_file((char *) yyvsp[-1].str, "w", 0);
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 19:
#line 368 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL)
				store_file((char *) yyvsp[-1].str, "a", 0);
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 20:
#line 375 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-1].num)
				send_file_list(".");
		}
    break;

  case 21:
#line 380 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL) 
				send_file_list((char *) yyvsp[-1].str);
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 22:
#line 387 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-1].num)
				retrieve("/bin/ls -lgA", "");
		}
    break;

  case 23:
#line 392 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL)
				retrieve("/bin/ls -lgA %s", (char *) yyvsp[-1].str);
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 24:
#line 399 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL)
				statfilecmd((char *) yyvsp[-1].str);
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 25:
#line 406 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			statcmd();
		}
    break;

  case 26:
#line 410 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL)
				delete_file((char *) yyvsp[-1].str);
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 27:
#line 417 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (fromname) {
				renamecmd(fromname, (char *) yyvsp[-1].str);
				free(fromname);
				fromname = (char *) 0;
			} else {
				reply(503, "Bad sequence of commands.");
			}
			free((char *) yyvsp[-1].str);
		}
    break;

  case 28:
#line 428 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			reply(225, "ABOR command successful.");
		}
    break;

  case 29:
#line 432 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-1].num)
				cwd(pw->pw_dir);
		}
    break;

  case 30:
#line 437 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL)
				cwd((char *) yyvsp[-1].str);
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 31:
#line 444 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			help(cmdtab, (char *) 0);
		}
    break;

  case 32:
#line 448 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			register char *cp = (char *)yyvsp[-1].str;

			if (strncasecmp(cp, "SITE", 4) == 0) {
				cp = (char *)yyvsp[-1].str + 4;
				if (*cp == ' ')
					cp++;
				if (*cp)
					help(sitetab, cp);
				else
					help(sitetab, (char *) 0);
			} else
				help(cmdtab, (char *) yyvsp[-1].str);
		}
    break;

  case 33:
#line 463 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			reply(200, "NOOP command successful.");
		}
    break;

  case 34:
#line 467 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL)
				makedir((char *) yyvsp[-1].str);
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 35:
#line 474 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL)
				removedir((char *) yyvsp[-1].str);
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 36:
#line 481 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-1].num)
				pwd();
		}
    break;

  case 37:
#line 486 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-1].num)
				cwd("..");
		}
    break;

  case 38:
#line 491 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			help(sitetab, (char *) 0);
		}
    break;

  case 39:
#line 495 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			help(sitetab, (char *) yyvsp[-1].str);
		}
    break;

  case 40:
#line 499 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			int oldmask;

			if (yyvsp[-1].num) {
				oldmask = umask(0);
				(void) umask(oldmask);
				reply(200, "Current UMASK is %03o", oldmask);
			}
		}
    break;

  case 41:
#line 509 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			int oldmask;

			if (yyvsp[-3].num) {
				if ((yyvsp[-1].num == -1) || (yyvsp[-1].num > 0777)) {
					reply(501, "Bad UMASK value");
				} else {
					oldmask = umask(yyvsp[-1].num);
					reply(200,
					    "UMASK set to %03o (was %03o)",
					    yyvsp[-1].num, oldmask);
				}
			}
		}
    break;

  case 42:
#line 524 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-5].num && (yyvsp[-1].str != NULL)) {
				if (yyvsp[-3].num > 0777)
					reply(501,
				"CHMOD: Mode value must be between 0 and 0777");
				else if (chmod((char *) yyvsp[-1].str, yyvsp[-3].num) < 0)
					perror_reply(550, (char *) yyvsp[-1].str);
				else
					reply(200, "CHMOD command successful.");
			}
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 43:
#line 538 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			reply(200,
			    "Current IDLE time limit is %d seconds; max %d",
				timeout, maxtimeout);
		}
    break;

  case 44:
#line 544 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-1].num < 30 || yyvsp[-1].num > maxtimeout) {
				reply(501,
			"Maximum IDLE time must be between 30 and %d seconds",
				    maxtimeout);
			} else {
				timeout = yyvsp[-1].num;
				(void) alarm((unsigned) timeout);
				reply(200,
				    "Maximum IDLE time set to %d seconds",
				    timeout);
			}
		}
    break;

  case 45:
#line 558 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL)
				store_file((char *) yyvsp[-1].str, "w", 1);
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 46:
#line 565 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
#ifdef unix
#ifdef __svr4__
#undef BSD
#endif
#ifdef BSD
			reply(215, "UNIX Type: L%d Version: BSD-%d",
				NBBY, BSD);
#else /* BSD */
			reply(215, "UNIX Type: L%d", NBBY);
#endif /* BSD */
#else /* unix */
			reply(215, "UNKNOWN Type: L%d", NBBY);
#endif /* unix */
		}
    break;

  case 47:
#line 589 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL)
				sizecmd((char *) yyvsp[-1].str);
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 48:
#line 606 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			if (yyvsp[-3].num && yyvsp[-1].str != NULL) {
				struct stat stbuf;
				if (stat(yyvsp[-1].str, &stbuf) < 0)
					perror_reply(550, yyvsp[-1].str);
				else if ((stbuf.st_mode&S_IFMT) != S_IFREG) {
					reply(550, "%s: not a plain file.",
						(char *) yyvsp[-1].str);
				} else {
					register struct tm *t;
					struct tm *gmtime();
					t = gmtime(&stbuf.st_mtime);
					reply(213,
					    "%4d%02d%02d%02d%02d%02d",
					    1900+t->tm_year, t->tm_mon+1, 
					    t->tm_mday, t->tm_hour, 
					    t->tm_min, t->tm_sec);
				}
			}
			if (yyvsp[-1].str != NULL)
				free((char *) yyvsp[-1].str);
		}
    break;

  case 49:
#line 629 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			auth((char *) yyvsp[-1].str);
		}
    break;

  case 50:
#line 633 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			auth_data((char *) yyvsp[-1].str);
			free((char *) yyvsp[-1].str);
		}
    break;

  case 51:
#line 638 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			reply(221, "Goodbye.");
			dologout(0);
		}
    break;

  case 52:
#line 643 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			yyerrok;
		}
    break;

  case 53:
#line 648 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			restart_point = (off_t) 0;
			if (yyvsp[-3].num && yyvsp[-1].str) {
				fromname = renamefrom((char *) yyvsp[-1].str);
				if (fromname == (char *) 0 && yyvsp[-1].str) {
					free((char *) yyvsp[-1].str);
				}
			}
		}
    break;

  case 54:
#line 658 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			fromname = (char *) 0;
			restart_point = yyvsp[-1].num;
			reply(350, "Restarting at %ld. %s", 
			      (long) restart_point,
			      "Send STORE or RETRIEVE to initiate transfer.");
		}
    break;

  case 56:
#line 671 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			*(char **)&(yyval.str) = (char *)calloc(1, sizeof(char));
		}
    break;

  case 59:
#line 682 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
			register char *a, *p;

			a = (char *)&host_port.sin_addr;
			a[0] = yyvsp[-10].num; a[1] = yyvsp[-8].num; a[2] = yyvsp[-6].num; a[3] = yyvsp[-4].num;
			p = (char *)&host_port.sin_port;
			p[0] = yyvsp[-2].num; p[1] = yyvsp[0].num;
			host_port.sin_family = AF_INET;
		}
    break;

  case 60:
#line 694 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = FORM_N;
	}
    break;

  case 61:
#line 698 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = FORM_T;
	}
    break;

  case 62:
#line 702 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = FORM_C;
	}
    break;

  case 63:
#line 708 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = PROT_C;
	}
    break;

  case 64:
#line 712 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = PROT_S;
	}
    break;

  case 65:
#line 716 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = PROT_P;
	}
    break;

  case 66:
#line 720 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = PROT_E;
	}
    break;

  case 67:
#line 726 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		cmd_type = TYPE_A;
		cmd_form = FORM_N;
	}
    break;

  case 68:
#line 731 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		cmd_type = TYPE_A;
		cmd_form = yyvsp[0].num;
	}
    break;

  case 69:
#line 736 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		cmd_type = TYPE_E;
		cmd_form = FORM_N;
	}
    break;

  case 70:
#line 741 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		cmd_type = TYPE_E;
		cmd_form = yyvsp[0].num;
	}
    break;

  case 71:
#line 746 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		cmd_type = TYPE_I;
	}
    break;

  case 72:
#line 750 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		cmd_type = TYPE_L;
		cmd_bytesz = NBBY;
	}
    break;

  case 73:
#line 755 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		cmd_type = TYPE_L;
		cmd_bytesz = yyvsp[0].num;
	}
    break;

  case 74:
#line 761 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		cmd_type = TYPE_L;
		cmd_bytesz = yyvsp[0].num;
	}
    break;

  case 75:
#line 768 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = STRU_F;
	}
    break;

  case 76:
#line 772 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = STRU_R;
	}
    break;

  case 77:
#line 776 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = STRU_P;
	}
    break;

  case 78:
#line 782 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = MODE_S;
	}
    break;

  case 79:
#line 786 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = MODE_B;
	}
    break;

  case 80:
#line 790 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		yyval.num = MODE_C;
	}
    break;

  case 81:
#line 796 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		/*
		 * Problem: this production is used for all pathname
		 * processing, but only gives a 550 error reply.
		 * This is a valid reply in some cases but not in others.
		 */
		if (logged_in && yyvsp[0].str && strncmp((char *) yyvsp[0].str, "~", 1) == 0) {
			char **vv;

			vv = ftpglob((char *) yyvsp[0].str);
			yyval.str = (vv != NULL) ? *vv : NULL;
			if (yyval.str == NULL) {
				if (globerr == NULL)
					yyval.str = yyvsp[0].str;
				else {
					reply(550, "%s", globerr);
					free((char *) yyvsp[0].str);
				}
			} else
				free((char *) yyvsp[0].str);
		} else
			yyval.str = yyvsp[0].str;
	}
    break;

  case 83:
#line 825 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		register int ret, dec, multby, digit;

		/*
		 * Convert a number that was read as decimal number
		 * to what it would be if it had been read as octal.
		 */
		dec = yyvsp[0].num;
		multby = 1;
		ret = 0;
		while (dec) {
			digit = dec%10;
			if (digit > 7) {
				ret = -1;
				break;
			}
			ret += digit * multby;
			multby *= 8;
			dec /= 10;
		}
		yyval.num = ret;
	}
    break;

  case 84:
#line 850 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		if (logged_in)
			yyval.num = 1;
		else {
			reply(530, "Please login with USER and PASS.");
			yyval.num = 0;
		}
	}
    break;

  case 85:
#line 861 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"
    {
		if (guest) {
			reply(550, "Operation prohibited for anonymous users.");
			yyval.num = 0;
		}
		else
			yyval.num = yyvsp[0].num;
	}
    break;


    }

/* Line 1010 of yacc.c.  */
#line 2248 "y.tab.c"

  yyvsp -= yylen;
  yyssp -= yylen;


  YY_STACK_PRINT (yyss, yyssp);

  *++yyvsp = yyval;


  /* Now `shift' the result of the reduction.  Determine what state
     that goes to, based on the state we popped back to and the rule
     number reduced by.  */

  yyn = yyr1[yyn];

  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
    yystate = yytable[yystate];
  else
    yystate = yydefgoto[yyn - YYNTOKENS];

  goto yynewstate;


/*------------------------------------.
| yyerrlab -- here on detecting error |
`------------------------------------*/
yyerrlab:
  /* If not already recovering from an error, report this error.  */
  if (!yyerrstatus)
    {
      ++yynerrs;
#if YYERROR_VERBOSE
      yyn = yypact[yystate];

      if (YYPACT_NINF < yyn && yyn < YYLAST)
	{
	  YYSIZE_T yysize = 0;
	  int yytype = YYTRANSLATE (yychar);
	  const char* yyprefix;
	  char *yymsg;
	  int yyx;

	  /* Start YYX at -YYN if negative to avoid negative indexes in
	     YYCHECK.  */
	  int yyxbegin = yyn < 0 ? -yyn : 0;

	  /* Stay within bounds of both yycheck and yytname.  */
	  int yychecklim = YYLAST - yyn;
	  int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
	  int yycount = 0;

	  yyprefix = ", expecting ";
	  for (yyx = yyxbegin; yyx < yyxend; ++yyx)
	    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
	      {
		yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
		yycount += 1;
		if (yycount == 5)
		  {
		    yysize = 0;
		    break;
		  }
	      }
	  yysize += (sizeof ("syntax error, unexpected ")
		     + yystrlen (yytname[yytype]));
	  yymsg = (char *) YYSTACK_ALLOC (yysize);
	  if (yymsg != 0)
	    {
	      char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
	      yyp = yystpcpy (yyp, yytname[yytype]);

	      if (yycount < 5)
		{
		  yyprefix = ", expecting ";
		  for (yyx = yyxbegin; yyx < yyxend; ++yyx)
		    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
		      {
			yyp = yystpcpy (yyp, yyprefix);
			yyp = yystpcpy (yyp, yytname[yyx]);
			yyprefix = " or ";
		      }
		}
	      yyerror (yymsg);
	      YYSTACK_FREE (yymsg);
	    }
	  else
	    yyerror ("syntax error; also virtual memory exhausted");
	}
      else
#endif /* YYERROR_VERBOSE */
	yyerror ("syntax error");
    }



  if (yyerrstatus == 3)
    {
      /* If just tried and failed to reuse lookahead token after an
	 error, discard it.  */

      if (yychar <= YYEOF)
        {
          /* If at end of input, pop the error token,
	     then the rest of the stack, then return failure.  */
	  if (yychar == YYEOF)
	     for (;;)
	       {
		 YYPOPSTACK;
		 if (yyssp == yyss)
		   YYABORT;
		 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
		 yydestruct (yystos[*yyssp], yyvsp);
	       }
        }
      else
	{
	  YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
	  yydestruct (yytoken, &yylval);
	  yychar = YYEMPTY;

	}
    }

  /* Else will try to reuse lookahead token after shifting the error
     token.  */
  goto yyerrlab1;


/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR.  |
`---------------------------------------------------*/
yyerrorlab:

#ifdef __GNUC__
  /* Pacify GCC when the user code never invokes YYERROR and the label
     yyerrorlab therefore never appears in user code.  */
  if (0)
     goto yyerrorlab;
#endif

  yyvsp -= yylen;
  yyssp -= yylen;
  yystate = *yyssp;
  goto yyerrlab1;


/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
`-------------------------------------------------------------*/
yyerrlab1:
  yyerrstatus = 3;	/* Each real token shifted decrements this.  */

  for (;;)
    {
      yyn = yypact[yystate];
      if (yyn != YYPACT_NINF)
	{
	  yyn += YYTERROR;
	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
	    {
	      yyn = yytable[yyn];
	      if (0 < yyn)
		break;
	    }
	}

      /* Pop the current state because it cannot handle the error token.  */
      if (yyssp == yyss)
	YYABORT;

      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
      yydestruct (yystos[yystate], yyvsp);
      YYPOPSTACK;
      yystate = *yyssp;
      YY_STACK_PRINT (yyss, yyssp);
    }

  if (yyn == YYFINAL)
    YYACCEPT;

  YYDPRINTF ((stderr, "Shifting error token, "));

  *++yyvsp = yylval;


  yystate = yyn;
  goto yynewstate;


/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here.  |
`-------------------------------------*/
yyacceptlab:
  yyresult = 0;
  goto yyreturn;

/*-----------------------------------.
| yyabortlab -- YYABORT comes here.  |
`-----------------------------------*/
yyabortlab:
  yyresult = 1;
  goto yyreturn;

#ifndef yyoverflow
/*----------------------------------------------.
| yyoverflowlab -- parser overflow comes here.  |
`----------------------------------------------*/
yyoverflowlab:
  yyerror ("parser stack overflow");
  yyresult = 2;
  /* Fall through.  */
#endif

yyreturn:
#ifndef yyoverflow
  if (yyss != yyssa)
    YYSTACK_FREE (yyss);
#endif
  return yyresult;
}


#line 870 "../../../../src/appl/gssftp/ftpd/ftpcmd.y"


struct tab cmdtab[] = {		/* In order defined in RFC 765 */
	{ "USER", USER, STR1, 1,	"<sp> username" },
	{ "PASS", PASS, ZSTR1, 1,	"<sp> password" },
	{ "ACCT", ACCT, STR1, 0,	"(specify account)" },
	{ "SMNT", SMNT, ARGS, 0,	"(structure mount)" },
	{ "REIN", REIN, ARGS, 0,	"(reinitialize server state)" },
	{ "QUIT", QUIT, ARGS, 1,	"(terminate service)", },
	{ "PORT", PORT, ARGS, 1,	"<sp> b0, b1, b2, b3, b4" },
	{ "PASV", PASV, ARGS, 1,	"(set server in passive mode)" },
	{ "TYPE", TYPE, ARGS, 1,	"<sp> [ A | E | I | L ]" },
	{ "STRU", STRU, ARGS, 1,	"(specify file structure)" },
	{ "MODE", MODE, ARGS, 1,	"(specify transfer mode)" },
	{ "RETR", RETR, STR1, 1,	"<sp> file-name" },
	{ "STOR", STOR, STR1, 1,	"<sp> file-name" },
	{ "APPE", APPE, STR1, 1,	"<sp> file-name" },
	{ "MLFL", MLFL, OSTR, 0,	"(mail file)" },
	{ "MAIL", MAIL, OSTR, 0,	"(mail to user)" },
	{ "MSND", MSND, OSTR, 0,	"(mail send to terminal)" },
	{ "MSOM", MSOM, OSTR, 0,	"(mail send to terminal or mailbox)" },
	{ "MSAM", MSAM, OSTR, 0,	"(mail send to terminal and mailbox)" },
	{ "MRSQ", MRSQ, OSTR, 0,	"(mail recipient scheme question)" },
	{ "MRCP", MRCP, STR1, 0,	"(mail recipient)" },
	{ "ALLO", ALLO, ARGS, 1,	"allocate storage (vacuously)" },
	{ "REST", REST, ARGS, 1,	"(restart command)" },
	{ "RNFR", RNFR, STR1, 1,	"<sp> file-name" },
	{ "RNTO", RNTO, STR1, 1,	"<sp> file-name" },
	{ "ABOR", ABOR, ARGS, 1,	"(abort operation)" },
	{ "DELE", DELE, STR1, 1,	"<sp> file-name" },
	{ "CWD",  CWD,  OSTR, 1,	"[ <sp> directory-name ]" },
	{ "XCWD", CWD,	OSTR, 1,	"[ <sp> directory-name ]" },
	{ "LIST", LIST, OSTR, 1,	"[ <sp> path-name ]" },
	{ "NLST", NLST, OSTR, 1,	"[ <sp> path-name ]" },
	{ "SITE", SITE, SITECMD, 1,	"site-cmd [ <sp> arguments ]" },
	{ "SYST", SYST, ARGS, 1,	"(get type of operating system)" },
	{ "STAT", STAT, OSTR, 1,	"[ <sp> path-name ]" },
	{ "HELP", HELP, OSTR, 1,	"[ <sp> <string> ]" },
	{ "NOOP", NOOP, ARGS, 1,	"" },
	{ "MKD",  MKD,  STR1, 1,	"<sp> path-name" },
	{ "XMKD", MKD,  STR1, 1,	"<sp> path-name" },
	{ "RMD",  RMD,  STR1, 1,	"<sp> path-name" },
	{ "XRMD", RMD,  STR1, 1,	"<sp> path-name" },
	{ "PWD",  PWD,  ARGS, 1,	"(return current directory)" },
	{ "XPWD", PWD,  ARGS, 1,	"(return current directory)" },
	{ "CDUP", CDUP, ARGS, 1,	"(change to parent directory)" },
	{ "XCUP", CDUP, ARGS, 1,	"(change to parent directory)" },
	{ "STOU", STOU, STR1, 1,	"<sp> file-name" },
	{ "AUTH", AUTH, STR1, 1,	"<sp> auth-type" },
	{ "ADAT", ADAT, STR1, 1,	"<sp> auth-data" },
	{ "PROT", PROT, ARGS, 1,	"<sp> protection-level" },
	{ "PBSZ", PBSZ, STR1, 1,	"<sp> buffer-size" },
	{ "CCC",  CCC,  ARGS, 1,	"(clear command channel)" },
	{ "SIZE", SIZE, OSTR, 1,	"<sp> path-name" },
	{ "MDTM", MDTM, OSTR, 1,	"<sp> path-name" },
	{ NULL,   0,    0,    0,	0 }
};

struct tab sitetab[] = {
	{ "UMASK", UMASK, ARGS, 1,	"[ <sp> umask ]" },
	{ "IDLE", IDLE, ARGS, 1,	"[ <sp> maximum-idle-time ]" },
	{ "CHMOD", CHMOD, NSTR, 1,	"<sp> mode <sp> file-name" },
	{ "HELP", HELP, OSTR, 1,	"[ <sp> <string> ]" },
	{ NULL,   0,    0,    0,	0 }
};

static struct tab *
lookup(p, cmd)
	register struct tab *p;
	char *cmd;
{

	for (; p->name != NULL; p++)
		if (strcmp(cmd, p->name) == 0)
			return (p);
	return (0);
}

/*
 * urgsafe_getc - hacked up getc to ignore EOF if SIOCATMARK returns TRUE
 */
static int
urgsafe_getc(f)
	FILE *f;
{
	register int c;
	int atmark;

	c = getc(f);
	if (c == EOF) {
		if (ioctl(fileno(f), SIOCATMARK, &atmark) != -1) {
			c = getc(f);
			syslog(LOG_DEBUG, "atmark: c=%d", c);
		}
	}
	return c;
}

#include <arpa/telnet.h>

/*
 * getline - a hacked up version of fgets to ignore TELNET escape codes.
 */
char *
ftpd_getline(s, n, iop)
	char *s;
	int n;
	register FILE *iop;
{
	register int c;
	register char *cs;

	cs = s;
/* tmpline may contain saved command from urgent mode interruption */
	for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
		*cs++ = tmpline[c];
		if (tmpline[c] == '\n') {
			*cs++ = '\0';
			if (debug)
				syslog(LOG_DEBUG, "command: %s", s);
			tmpline[0] = '\0';
			return(s);
		}
		if (c == 0)
			tmpline[0] = '\0';
	}
	while ((c = urgsafe_getc(iop)) != EOF) {
		c &= 0377;
		if (c == IAC) {
			if (debug) syslog(LOG_DEBUG, "got IAC");
		    if ((c = urgsafe_getc(iop)) != EOF) {
			c &= 0377;
			if (debug) syslog(LOG_DEBUG, "got IAC %d", c);
			switch (c) {
			case WILL:
			case WONT:
				c = urgsafe_getc(iop);
				printf("%c%c%c", IAC, DONT, 0377&c);
				(void) fflush(stdout);
				continue;
			case DO:
			case DONT:
				c = urgsafe_getc(iop);
				printf("%c%c%c", IAC, WONT, 0377&c);
				(void) fflush(stdout);
				continue;
			case IAC:
				break;
			default:
				continue;	/* ignore command */
			}
		    }
		}
		*cs++ = c;
		if (--n <= 0 || c == '\n')
			break;
	}
	if (c == EOF && cs == s)
		return (NULL);
	*cs++ = '\0';
	if (auth_type) {
	    char out[sizeof(cbuf)], *cp;
	    int len, mic;


	    /* Check to see if we have a protected command. */
	    if (!((mic = strncmp(s, "ENC", 3)) && strncmp(s, "MIC", 3)
		&& strncmp(s, "AUTH", 4)
#ifndef NOCONFIDENTIAL
	        && strncmp(s, "CONF", 4)
#endif
	        ) && (cs = strpbrk(s, " \r\n"))) {
	    	    *cs++ = '\0'; /* If so, split it into s and cs. */
	    } else { /* If not, check if unprotected commands are allowed. */
		if(ccc_ok) {
		    clevel = PROT_C;
		    upper(s);
		    return(s);
		} else {
		    reply(533, "All commands must be protected.");
		    syslog(LOG_ERR, "Unprotected command received");
		    *s = '\0';
		    return(s);
		}
	    }
	    upper(s);
	    if (debug)
	        syslog(LOG_INFO, "command %s received (mic=%d)", s, mic);
#ifdef NOCONFIDENTIAL
	    if (!strcmp(s, "CONF")) {
		reply(537, "CONF protected commands not supported.");
		*s = '\0';
		return(s);
	    }
#endif
/* Some paranoid sites may want to require that commands be encrypted. */
#ifdef PARANOID
	    if (mic) {
		reply(533, "All commands must be ENC protected.  Retry command under ENC.");
		*s = '\0';
		return(s);
	    }
#endif /* PARANOID */
#ifdef NOENCRYPTION
	    if (!mic) {
		reply(533, "ENC protection not supported.  Retry command under MIC.");
		*s = '\0';
		return(s);
	    }
#endif /* NOENCRYPTION */
	    if ((cp = strpbrk(cs, " \r\n")))
		*cp = '\0';
	    kerror = radix_encode(cs, out, &len, 1);
	    if (kerror) {
		reply(501, "Can't base 64 decode argument to %s command (%s)",
		      mic ? "MIC" : "ENC", radix_error(kerror));
		*s = '\0';
		return(s);
	    }
	    if (debug) syslog(LOG_DEBUG, "getline got %d from %s <%s>\n", 
			      len, cs, mic?"MIC":"ENC");
	    clevel = mic ? PROT_S : PROT_P;
#ifdef KRB5_KRB4_COMPAT
	    if (strcmp(auth_type, "KERBEROS_V4") == 0) {
		if ((kerror = mic ?
		    krb_rd_safe((unsigned char *)out, len, &kdata.session,
			    &his_addr, &ctrl_addr, &msg_data)
		  : krb_rd_priv((unsigned char *)out, len, schedule,
			    &kdata.session, &his_addr, &ctrl_addr, &msg_data))
			!= KSUCCESS) {
		    reply(535, "%s! (%s)",
			   mic ? "MIC command modified" : "ENC command garbled",
			   krb_get_err_text(kerror));
		    syslog(LOG_ERR,"%s failed: %s",
			   mic ? "MIC krb_rd_safe" : "ENC krb_rd_priv",
			   krb_get_err_text(kerror));
		    *s = '\0';
		    return(s);
		}
		(void) memcpy(s, msg_data.app_data, msg_data.app_length);
		(void) strcpy(s+msg_data.app_length, "\r\n");
	    }
#endif /* KRB5_KRB4_COMPAT */
#ifdef GSSAPI
/* we know this is a MIC or ENC already, and out/len already has the bits */
	    if (strcmp(auth_type, "GSSAPI") == 0) {
		gss_buffer_desc xmit_buf, msg_buf;
		OM_uint32 maj_stat, min_stat;
		int conf_state;

		xmit_buf.value = out;
		xmit_buf.length = len;
		/* decrypt the message */
		conf_state = !mic;
		maj_stat = gss_unseal(&min_stat, gcontext, &xmit_buf,
				      &msg_buf, &conf_state, NULL);
		if (maj_stat == GSS_S_CONTINUE_NEEDED) {
			if (debug) syslog(LOG_DEBUG, "%s-unseal continued", 
					  mic?"MIC":"ENC");
			reply(535, "%s-unseal continued, oops",
			      mic?"MIC":"ENC");
			*s = 0; return s;
		}
		if (maj_stat != GSS_S_COMPLETE) {
			reply_gss_error(535, maj_stat, min_stat, 
					mic? "failed unsealing MIC message":
					"failed unsealing ENC message");
			*s = 0;
			return s;
		}

		memcpy(s, msg_buf.value, msg_buf.length);
		strcpy(s+msg_buf.length-(s[msg_buf.length-1]?0:1), "\r\n");
		gss_release_buffer(&min_stat, &msg_buf);
	    }
#endif /* GSSAPI */
	    /* Other auth types go here ... */

	    /* A password should never be MICed, but the CNS ftp
	     * client and the pre-6/98 Krb5 client did this if you
	     * authenticated but didn't encrypt.
	     */
	    if (authlevel && mic && !strncmp(s, "PASS", 4)) {
	    	lreply(530, "There is a problem with your ftp client. Password refused.");
		reply(530, "Enable encryption before logging in, or update your ftp program.");
		*s = 0;
		return s;
	    }

	}
#if defined KRB5_KRB4_COMPAT || defined GSSAPI	/* or other auth types */
	else {	/* !auth_type */
	    if ( (!(strncmp(s, "ENC", 3))) || (!(strncmp(s, "MIC", 3)))
#ifndef NOCONFIDENTIAL
                || (!(strncmp(s, "CONF", 4)))
#endif
                                        ) {
                reply(503, "Must perform authentication before sending protected commands");
                *s = '\0';
                return(s);
	    }
	}
#endif /* KRB5_KRB4_COMPAT || GSSAPI */

	if (debug) {
		if (!strncmp(s, "PASS ", 5) && !guest)
			syslog(LOG_DEBUG, "command: <PASS XXX>");
		else
			syslog(LOG_DEBUG, "command: <%.*s>(%d)",
			       strlen(s) - 2, s, strlen(s));
	}
	return (s);
}

static krb5_sigtype
toolong(sig)
	int sig;
{
	time_t now;

	reply(421,
	  "Timeout (%d seconds): closing control connection.", timeout);
	(void) time(&now);
	if (logging) {
		syslog(LOG_INFO,
			"User %s timed out after %d seconds at %s",
			(pw ? pw -> pw_name : "unknown"), timeout, ctime(&now));
	}
	dologout(1);
}

static int
yylex()
{
	static int cpos, state;
	register char *cp, *cp2;
	register struct tab *p;
	int n;
	char c;

	for (;;) {
		switch (state) {

		case CMD:
			(void) signal(SIGALRM, toolong);
			(void) alarm((unsigned) timeout);
			if (ftpd_getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
				reply(221, "You could at least say goodbye.");
				dologout(0);
			}
			(void) alarm(0);

			/* If getline() finds an error, the string is null */
			if (*cbuf == '\0')
				continue;

#ifdef SETPROCTITLE
			if (strncasecmp(cbuf, "PASS", 4) != NULL)
				setproctitle("%s: %s", proctitle, cbuf);
#endif /* SETPROCTITLE */
			if ((cp = strchr(cbuf, '\r'))) {
				*cp++ = '\n';
				*cp = '\0';
			}
			if ((cp = strpbrk(cbuf, " \n")))
				cpos = cp - cbuf;
			if (cpos == 0)
				cpos = 4;
			c = cbuf[cpos];
			cbuf[cpos] = '\0';
			upper(cbuf);
			p = lookup(cmdtab, cbuf);
			cbuf[cpos] = c;
			if (p != 0) {
				if (p->implemented == 0) {
					nack(p->name);
					longjmp(errcatch,0);
					/* NOTREACHED */
				}
				state = p->state;
				yylval.str = p->name;
				return (p->token);
			}
			break;

		case SITECMD:
			if (cbuf[cpos] == ' ') {
				cpos++;
				return (SP);
			}
			cp = &cbuf[cpos];
			if ((cp2 = strpbrk(cp, " \n")))
				cpos = cp2 - cbuf;
			c = cbuf[cpos];
			cbuf[cpos] = '\0';
			upper(cp);
			p = lookup(sitetab, cp);
			cbuf[cpos] = c;
			if (p != 0) {
				if (p->implemented == 0) {
					state = CMD;
					nack(p->name);
					longjmp(errcatch,0);
					/* NOTREACHED */
				}
				state = p->state;
				yylval.str = p->name;
				return (p->token);
			}
			state = CMD;
			break;

		case OSTR:
			if (cbuf[cpos] == '\n') {
				state = CMD;
				return (CRLF);
			}
			/* FALLTHROUGH */

		case STR1:
		case ZSTR1:
		dostr1:
			if (cbuf[cpos] == ' ') {
				cpos++;
				state = state == OSTR ? STR2 : state+1;
				return (SP);
			}
			break;

		case ZSTR2:
			if (cbuf[cpos] == '\n') {
				state = CMD;
				return (CRLF);
			}
			/* FALLTHROUGH */

		case STR2:
			cp = &cbuf[cpos];
			n = strlen(cp);
			cpos += n - 1;
			/*
			 * Make sure the string is nonempty and \n terminated.
			 */
			if (n > 1 && cbuf[cpos] == '\n') {
				cbuf[cpos] = '\0';
				yylval.str = copy(cp);
				cbuf[cpos] = '\n';
				state = ARGS;
				return (STRING);
			}
			break;

		case NSTR:
			if (cbuf[cpos] == ' ') {
				cpos++;
				return (SP);
			}
			if (isdigit((int) cbuf[cpos])) {
				cp = &cbuf[cpos];
				while (isdigit((int) cbuf[++cpos]))
					;
				c = cbuf[cpos];
				cbuf[cpos] = '\0';
				yylval.num = atoi(cp);
				cbuf[cpos] = c;
				state = STR1;
				return (NUMBER);
			}
			state = STR1;
			goto dostr1;

		case ARGS:
			if (isdigit((int) cbuf[cpos])) {
				cp = &cbuf[cpos];
				while (isdigit((int) cbuf[++cpos]))
					;
				c = cbuf[cpos];
				cbuf[cpos] = '\0';
				yylval.num = atoi(cp);
				cbuf[cpos] = c;
				return (NUMBER);
			}
			switch (cbuf[cpos++]) {

			case '\n':
				state = CMD;
				return (CRLF);

			case ' ':
				return (SP);

			case ',':
				return (COMMA);

			case 'A':
			case 'a':
				return ('A');

			case 'B':
			case 'b':
				return ('B');

			case 'C':
			case 'c':
				return ('C');

			case 'E':
			case 'e':
				return ('E');

			case 'F':
			case 'f':
				return ('F');

			case 'I':
			case 'i':
				return ('I');

			case 'L':
			case 'l':
				return ('L');

			case 'N':
			case 'n':
				return ('N');

			case 'P':
			case 'p':
				return ('P');

			case 'R':
			case 'r':
				return ('R');

			case 'S':
			case 's':
				return ('S');

			case 'T':
			case 't':
				return ('T');

			}
			break;

		default:
			fatal("Unknown state in scanner.");
		}
		yyerror((char *) 0);
		state = CMD;
		longjmp(errcatch,0);
	}
}

void
upper(s)
	register char *s;
{
	while (*s != '\0') {
		if (islower((int) (*s)))
			*s = toupper((int) (*s));
		s++;
	}
}

static char *
copy(s)
	char *s;
{
	char *p;

	p = malloc((unsigned) strlen(s) + 1);
	if (p == NULL)
		fatal("Ran out of memory.");
	(void) strcpy(p, s);
	return (p);
}

void
help(ctab, s)
	struct tab *ctab;
	char *s;
{
	register struct tab *c;
	register int width, NCMDS;
	char str[80];
	char *ftype;

	if (ctab == sitetab)
		ftype = "SITE ";
	else
		ftype = "";
	width = 0, NCMDS = 0;
	for (c = ctab; c->name != NULL; c++) {
		int len = strlen(c->name);

		if (len > width)
			width = len;
		NCMDS++;
	}
	width = (width + 8) &~ 7;
	if (s == 0) {
		register int i, j, w;
		int columns, lines;

		lreply(214, "The following %scommands are recognized %s.",
		    ftype, "(* =>'s unimplemented)");
		columns = 76 / width;
		if (columns == 0)
			columns = 1;
		lines = (NCMDS + columns - 1) / columns;
		for (i = 0; i < lines; i++) {
			strcpy(str, "   ");
			for (j = 0; j < columns; j++) {
				c = ctab + j * lines + i;
				sprintf(&str[strlen(str)], "%s%c", c->name,
					c->implemented ? ' ' : '*');
				if (c + lines >= &ctab[NCMDS])
					break;
				w = strlen(c->name) + 1;
				while (w < width) {
					strcat(str, " ");
					w++;
				}
			}
			reply(0, "%s", str);
		}
		reply(214, "Direct comments to ftp-bugs@%s.", hostname);
		return;
	}
	upper(s);
	c = lookup(ctab, s);
	if (c == (struct tab *)0) {
		reply(502, "Unknown command %s.", s);
		return;
	}
	if (c->implemented)
		reply(214, "Syntax: %s%s %s", ftype, c->name, c->help);
	else
		reply(214, "%s%-*s\t%s; unimplemented.", ftype, width,
		    c->name, c->help);
}

void
sizecmd(filename)
char *filename;
{
	switch (type) {
	case TYPE_L:
	case TYPE_I: {
		struct stat stbuf;
		if (stat(filename, &stbuf) < 0 ||
		    (stbuf.st_mode&S_IFMT) != S_IFREG)
			reply(550, "%s: not a plain file.", filename);
		else
			reply(213, "%lu", (long) stbuf.st_size);
		break;}
	case TYPE_A: {
		FILE *fin;
		register int c;
		register long count;
		struct stat stbuf;
		fin = fopen(filename, "r");
		if (fin == NULL) {
			perror_reply(550, filename);
			return;
		}
		if (fstat(fileno(fin), &stbuf) < 0 ||
		    (stbuf.st_mode&S_IFMT) != S_IFREG) {
			reply(550, "%s: not a plain file.", filename);
			(void) fclose(fin);
			return;
		}

		count = 0;
		while((c=getc(fin)) != EOF) {
			if (c == '\n')	/* will get expanded to \r\n */
				count++;
			count++;
		}
		(void) fclose(fin);

		reply(213, "%ld", count);
		break;}
	default:
		reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
	}
}


