#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "os.h"
#include "swis.h"

#define MAX_EXIT_CODE           24

#define ARC_MAGIC               "Archie "
#define ARC_FLAG                'A'

#define TAR_FILETYPE_VAR        "tar$filetype"
#define COMPRESS_VAR            "tar$compress"
#define DECOMPRESS_VAR          "tar$decompress"
#define COMPEXT_VAR             "tar$compress$extension"
#define SCRAP_VAR               "tar$scrap"

#define RECORDSIZE              512
#define NBLOCK                  20
#define MAXUNUSED               20480

#define NAMSIZ                  100
#define MAXPATHLEN              256

typedef union HeaderBlock {
        char Block[RECORDSIZE];
        struct header {
                char name[NAMSIZ];
                char mode[8];
                char uid[8];
                char gid[8];
                char size[12];
                char mtime[12];
                char chksum[8];
                char linkflag;
                char linkname[NAMSIZ];
                char magic[8];
                char LoadAddress[12];
                char ExecAddress[12];
                char Attr[12];
                char Date[12];
                char compression[12];
                char archieflag;
                char compressed;
                char ExtentNo[8];
        } Header;
} Block_t;

#define LF_OLDNORMAL    '\0'            /* Normal disk file, Unix compat */
#define LF_NORMAL       '0'             /* Normal disk file */
#define LF_LINK         '1'             /* Link to previously dumped file */
#define LF_SYMLINK      '2'             /* Symbolic link */
#define LF_CHR          '3'             /* Character special file */
#define LF_BLK          '4'             /* Block special file */
#define LF_DIR          '5'             /* Directory */
#define LF_FIFO         '6'             /* FIFO special file */
#define LF_CONTIG       '7'             /* Contiguous file */

#define LF_DUMPDIR      'D'             /* This is a dump dir entry */
#define LF_EXTENT       'X'             /* This is an extent of a file. */
#define LF_LASTEXTENT   'L'
#define LF_VOLHDR       'V'             /* This file is a tape/volume header */
#define LF_VOLEND       'E'             /* This file is a tape/volume end */
#define LF_GNUEXTENT    'M'             /* GNU tar extent of a file */

#define CF_COMPRESSED   'Z'             /* The file is compressed */

typedef enum {
  tapedevice_FILE, tapedevice_DISC, tapedevice_RMT
} tapedevice_t;

typedef enum {
  t_NotFound, t_FileFound, t_DirFound, t_ImageFileFound
} ObjectType;

typedef struct catinfo {
  long LoadAddress;
  long ExecAddress;
  long Length;
  long Attr;
  long Type;
  long SIN;
  char DateAndName[256];
} CatInfo;


extern void usage(void);
extern void Terminate(int);
extern char Decision(char);
extern int chkos(os_error *);
extern int ExecuteCommand(char *, char *, char *, int);
extern void compress_cleanup(void);
extern void PrintBlocks(FILE *, long);
extern void ChkScrapName(void);


extern int CreateArchive;
extern int ArchiveFileSpecified;
extern int IgnoreArchiveErrors;
extern int UseListFile;
extern int DoNotExtractFileDates;
extern int ConvertExclamationMark;
extern int AppendToArchive;
extern int SwapExtensionToDir;
extern int ListArchivesContents;
extern int Verbose;
extern int ConfirmActions;
extern int ExtractFromArchive;
extern int CompressFiles;
extern int Reblock;
extern int PeriodSlashConversion;
extern int FormatFloppies;
extern int MultipleVolumes;
extern int GNUmultipleVolumes;
extern int NoDiskDestroyConfirmation;
extern int QuietExecution;
extern int SwapInWholePath;
extern int CommaFileTypes;
extern int UnixArchive;
extern int VeryVerbose;
extern int AddFileTypeExtension;
extern int ConvertCompressExtension;
extern int UseCanonicalisedPaths;
extern int MaxLeafLength;

extern int tarFileType;

extern int MaxExtLength;

extern tapedevice_t tapedevice;
extern int driveno;
extern char format;

extern char *listfile;
extern char *ArchiveName;
extern int ArchiveOpen;
extern FILE *ArchiveFD;
extern int rmt_fd;

extern int UserInterrupt;

extern Block_t *TmpBlock;
extern Block_t Block;

extern int NumBlocksRead;
extern int nblock;
extern int recno;
extern int first;
extern int DiscNo;
extern int compression;

extern int isArchie;

extern char ScrapName[MAXPATHLEN];
extern char ScrapNameZ[MAXPATHLEN];
extern char CompressExt[256];
extern char CompressTemplate[MAXPATHLEN];
extern char DecompressTemplate[MAXPATHLEN];
