/*

  header file for DOWNSORT.C */

#define bit   unsigned
#define sword signed int
#define word  unsigned int
#define dword long int
#define byte  unsigned char

#include "..\maximus\area_max.h"        // AREA.DAT layout union

/*----------------------------*/
/* MAXIMUS user Access levels */
/*----------------------------*/
#define TWIT        (-2)
#define DISGRACE     0
#define LIMITED      1
#define NORMAL       2
#define WORTHY       3
#define PRIVIL       4
#define FAVORED      5
#define EXTRA        6
#define CLERK        7
#define ASSTSYSOP    8
#define SYSOP       10
#define HIDDEN      11

#define MAXFN       13
#define MAXRCD     255
#define MAXDESC    (MAXRCD-MAXFN-2)
#define MAXPATH    128
#define MAXTIT      10

#define TRUNC       'T'
#define WRAP        'W'
#define QUIET       'Q'
#define VERBOSE     'V'
#define HELP        'H'
#define QMARK       '?'
#define ALPHA       'A'
#define TIMESTAMP   'D'
#define FONT        'F'

#define DAYS_30     '+'
#define DAYS_7      '*'

#define FONT0       0
#define FONT1       1
#define FONT2       2
#define FONT3       3
#define FONT4       4
#define LINE1       0
#define LINE2       1
#define LINE3       2
#define LINE4       3
#define LINE5       4

/* (foreground) COLORS */

#define O_BLINK   0x80
#define O_BRIGHT  0x08
#define O_LIGHT   0x08

#define O_BLACK   0x00
#define O_BLUE    0x01
#define O_GREEN   0x02
#define O_CYAN    0x03
#define O_RED     0x04
#define O_MAGENTA 0x05
#define O_BROWN   0x06
#define O_GRAY    0x07
#define O_YELLOW  (O_BRIGHT+O_BROWN)
#define O_WHITE   (O_BRIGHT+O_GRAY)


struct _filechain {                     // file information
        struct _filechain *next_element; // to next element
        struct _downpath *parea;        // pointer to area-structure
        struct _FDATE wdate;            // file date (last write)
        struct _FTIME wtime;            // file time (last write)
        struct _FDATE cdate;            // file date (creation)
        struct _FTIME ctime;            // file time (creation)
        ULONG  size;                    // file size
        USHORT attr;                    // attribute
        int    priv;                    // privilege
        char   fname[MAXFN];            // filename
        char   *fdesc;                  // ptr to file description
          };

struct _downpath {                      // download area information
        int  priv;                      // Area Privilege integer
        char name[40];                  // Area name
        USHORT file_count;              // Area file count for area summary
        ULONG  byte_count;              // Area byte count for area summary
        char pname[80];                 // Download-pathname
        char filesbbs[80];              // Path to FILES.BBS
        char adesc[80];                 // Filearea description
          };

#define P_BBS  0                        // Symbolic parameter table
#define P_FIL  1                        // entry index values
#define P_GBL  2                        // for the different lists
#define P_NEW  3
#define P_ALL  4
#define P_ORP  5
#define P_MAX  5                        // indicates highest index!

struct _listparm {                      // list parameters
        int  priv[10];                  // max file priv to list
        int  tfont;                     // title font
        unsigned int max_fil;           // maximum # of files to list
        char sortflag;                  // file sequence (name/date)
        char wrapflag;                  // wrap or truncate
        char name[9];                   // list filename
        char ext[4];                    // list filename
          };

/* externs for global variables */

extern char   PROGNAME[],PROGDESC[],AUTHOR[],CITY[],PHONE[],FIDO[];
extern char   VERSION,SUBVERS,SUFFIX;
extern char   MAX[],MSG_MEM[],MSG_SRT[],MSG_RST[],MSG_TRL[],MSG_REC[],
              OPEN_FAIL[],HS[],HD[],FN[],AC[],DT[],SZ[],DS[],FP[],NDS[],
              ORPHAN[],BAK[],EMPTY[];
extern char   today[],list_title[],
              filesbbs_path[],areadat_path[],cfg_path[],
              all_fname[],new_fname[],bbs_fname[],gbl_fname[],orp_fname[];
extern char   *priv_name[],*pre_title[],*sub_title[],*bot_lines[];
extern char   wrap_flag,oper_mode,sort_mode;
extern USHORT area_count,file_count,title_font;
extern USHORT title_lines[];
extern int    MAX_level,
              bbs_priv[],gbl_priv[],new_priv[],all_priv[],fil_priv[];
extern ULONG  byte_count;
extern struct _filechain *first_element;
extern struct _listparm lp[];
extern struct _COUNTRYCODE c_code;
extern struct _COUNTRYINFO c_info;

/*  function prototypes */

char    *asciiz(char *);
USHORT   collect_down(struct _downpath **);
USHORT   collect_file(USHORT, struct _downpath *);
int      conv_priv(char *, int *, USHORT);
char    *f_date(struct _FDATE);
char    *f_time(struct _FTIME);
char     file_age_ind(struct _FDATE, struct _FTIME);
long     file_time(struct _FDATE, struct _FTIME);
USHORT   fill_chn(struct _downpath *,
                  struct _filechain **,struct _filechain **);
void     get_desc(int, struct _filechain *, struct _downpath *);
void     get_parm(int,char *[]);
void     list_parm(int, char *, int);
void     make_all(struct _filechain **,struct _downpath *, int);
void     make_bbs(struct _filechain **, USHORT, int);
void     make_fil(struct _filechain **, int);
void     make_gbl(struct _filechain **, int);
void     make_new(struct _filechain **, USHORT, int);
void     make_orp(struct _filechain **);
char    *next_word(char *);
struct _filechain *new_acq(struct _filechain *, struct _filechain *);
int     parse_keyword(char *,char **);
struct _filechain **prep_sort(USHORT, struct _filechain *);
void     psort(struct _filechain **, int, int, int (*)());
void     read_cfg(char *);
void     show_help(void);
void     show_welcome(void);
void     signature(void *, char *);
int      sort_all(struct _filechain **, struct _filechain **);
int      sort_al2(struct _filechain **, struct _filechain **);
int      sort_fil(struct _filechain **, struct _filechain **);
int      sort_gbl(struct _filechain **, struct _filechain **);
int      sort_new(struct _filechain **, struct _filechain **);
int      sort_summ(struct _downpath *, struct _downpath *);
char    *strnblk(char *, int, int, int);
int      strsubw(char *, char **, int);
char    *sys_date(char *);
int      non_wild_init(int, char *, char *);
void     title_line(char *, char *[]);
int      wild_init(int, char *, char *);
int      wild_comp(int, char *,char *);
