/*
 * This file is part of uudeview, the simple and friendly multi-part multi-
 * file uudecoder  program  (c)  1994 by Frank Pilhofer. The author may be
 * contacted by his email address,          fp@informatik.uni-frankfurt.de
 *
 * 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 of the License, 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.
 */



#define ST_READ		0x00	/* Read in, but not further processed */
#define ST_MISPART	0x01	/* Missing Part detected */
#define ST_NOBEGIN	0x02	/* No 'begin' found */
#define ST_NOEND	0x03	/* No 'end' found */
#define ST_NODATA       0x05    /* File does not contain valid uudata */
#define ST_OK           0x08    /* All Parts found, ready to decode */
#define ST_DECOERR	0x10	/* Error while decoding */
#define ST_DECODED	0x20	/* Successfully decoded */
#define ST_UNCOMP	0x40	/* Decoded and uncompressed */

#define UU_ENCODED	0x01	/* UUencoded data   */
#define B64ENCODED	0x02	/* Mime-Base64 data */
#define XX_ENCODED	0x03	/* XXencoded data   */

#define SHOW_INFO	0x01	/* For more () */
#define SHOW_FILE	0x02

/*
 * Structure that holds the information for a single file / part of
 * a file. If a subject line is encountered, it is copied to subject;
 * if a begin is found, the mode and name of the file is extracted.
 * flags are set if 'begin' or 'end' is detected and 'uudet' if valid
 * uuencoded data is found. If the file contains a 'From:' line with
 * a '@' in it (indicating an origin email address), it is preserved
 * in 'origin'.
 **/

typedef struct _fileread {
  char *subject;      /* Whole subject line */
  char *filename;     /* Only filled in if begin detected */
  char *origin;       /* Whole 'From:' line */
  char *mimeid;       /* the ID for Mime-encoded files */
  short mode;         /* Mode of File (from 'begin') */
  unsigned begin : 1; /* begin detected */
  unsigned end   : 1; /* end detected */

  short uudet;	      /* valid encoded data. value indicates encoding */
  short partno;       /* Mime-files have a part number within */
  short maxpno;       /* ... plus the total number of parts   */

  char *sfname;       /* Associated source file */
  long startpos;      /* ftell() position where data starts */
  long length;        /* length of data */
} fileread;

/*
 * Structure for holding one part of a file
 * Linked List, ordered by partno.
 **/

typedef struct _uufile {
  char     *filename;
  char     *subfname;
  char     *mimeid;
  short     partno;
  fileread *data;
  struct _uufile *NEXT;
} uufile;

typedef struct _uulist {
  short state, mode;

  unsigned begin : 1;
  unsigned end   : 1;

  short    uudet;

  char    *filename;
  char    *subfname;
  char    *mimeid;

  long     tarblock;
  char    *binfile;

  uufile  *thisfile;
  char    *misparts;

  struct _uulist *branch;
  struct _uulist *NEXT;
} uulist;

extern uulist *GlobalFileList;

typedef struct _extlist {
  char extension[8];
  struct _extlist *NEXT;
} extlist;

typedef struct _infile {
  int   delflag;
  char  name[256];
  struct _infile *NEXT;
} infile;

extern infile  *ftoread;
extern extlist *extensions;
extern int      ignreply, desperate, overwrite, quiet, fast;
extern char    *knownexts[], *hateheaders[];

int       IsHeaderLine   (char *);
int       IsKnownExtension (char *);
int       addftoread     (char *);
int       addexts        (char *);
int       work_file      (char *);
int       proc_stdin     (void);
void      loadparfile    (char *);
int       work_comline   (int, char *[]);
void      load_files     (void);
char      getyn          (char);
void	  more		 (uulist *, FILE *, int);
char *    indent         (int);
int       process_one    (uulist *, int);
int       process_files  (uulist *, int);
void      sighandler     (int);
void      usage          (void);
