#ifndef _QLIB_H
#define _QLIB_H
/*
 *  This header file defines data structures, constants
 *  and function definitions that are common to both the
 *  QDOS and SMS interfaces to the C68 libraries.
 *
 *  AMENDMENT HISTORY
 *  ~~~~~~~~~~~~~~~~~
 *  20 Jan 93   DJW   - This file was created for the first time from
 *                      the QDOS_H and QLIB_H header files to try and
 *                      separate out the SMS and QDOS specific parts
 *                      (and names) of the C68 library interface.
 *
 *  20 Aug 94   DJW   - The iop_outl() call moved to the qptr.h header file
 *                      where it more naturally belongs.
 *
 *  28 Aug 94   DJW   - Added definitions for two new internal library 
 *                      routines _argpack() and _argunpk().
 *
 *  03 Sep 94   DJW   - Added the declarations of various new internal
 *                      library constants:
 *                          _C_esc      _C_esc_a
 *                          _C_hex      _C_hex_a
 *                          _C_oct      _C_oct_a
 *                    - Removed global names that were in start up module
 *                      that no longer needed to be globally visible:
 *                          _dpname
 *                    - Removed reference to _cmdline() and _cmdparse()
 *                      routines as these are no onger used with latest
 *                      version of startup code.
 *                    - Defintion -f _cmdwildcard vector changed slightly
 *                      to reflect new startup code requirements.
 *                    - Name hiding definitions added for all routines that
 *                      are called internally within the libraries.  We have
 *                      not bothered for routines that can only be called
 *                      directly from the user program.
 *
 *  16 Sep 94   DJW   - Moved all definitions that are related to handling
 *                      things to the new things.h header file.
 *
 *  10 Oct 94   DJW   - Added an extra 36 bytes to the definition of the area
 *                      used for Level 2 drivers extended information.  This
 *                      is to cater for a bug in the Miracle Hard disk code
 *                      that read 16 bytes more than it should.
 *
 *  08 Apr 95   DJW   - Added 'typedef's for most common structures and changed
 *                      function declarations to use them.
 *
 *  16 Apr 95   DJW   - Changed the QLSTR_DEF and QLSTR_INIT macros to no
 *                      no longer have a semi-colon as part of their
 *                      definition.  This makes them slightly more flexible,
 *                      and also makes the example code correct!
 *                      (Change suggested by Johnathan Hudson).
 *
 *  28 Sep 95   DJW   - Added '_endtimeout' global variable.
 */

#ifndef _QDOS_H
#ifndef _SMS_H
#ifndef _QPTR_H
#error  This file should only be included indirectly via
#error  the <qdos.h>, <sms.h> or <qptr.h> header files.
#endif
#endif
#endif


#ifndef _SYS_TYPES_H
#include <sys/types.h>
#endif

#ifndef _LIMITS_H
#include <limits.h>
#endif

#ifndef NULL
#define NULL ((void *)0)
#endif

#ifdef __STDC__
#define _P_(params) params
#else
#define _P_(params) ()
#endif

/*
 *  Constant often used in system calls
 */
#define TIMEOUT_FOREVER (timeout_t)-1

/*
*
* The following structure contains the registers that are used to interface
* with the operating system via the QDOSx functions.
*
*/
typedef struct REGS {
   datareg_t D0,D1,D2,D3;
   addreg_t A0,A1,A2,A3;
} REGS_t;

extern int _oserr; /* QDOS system error */

/*
 * Structure of a QL string.
 */
typedef struct QLSTR {
    short qs_strlen;    /* Length of string */
    char  qs_str[1];    /* Start of string */
    } QLSTR_t;

/*
 *  Macro for defining an QL string of a specified size.  This reserves
 *  the appropriate space, buts inserts no values.  Use a declaration
 *  of the format:
 *
 *          QLSTR_DEF(string_name,length);
 *
 *  N.B.    For compatibility with C string handling, an additional byte
 *          is allocated for the NULL byte even though it is not included
 *          in the count field.
 *
 *  It is also possible to initialise such a string using a statement of
 *  the format:
 *          QLSTR_DEF(string_name,length) = {5,"Hello"};
 *
 *  N.B.    If used inside a function, this will need the 'static' keyword
 *          preceding it as you cannot initialise 'auto' variables.
 */
#define QLSTR_DEF(n,l)  \
    struct { \
        short qs_strlen; \
        char  qs_str[l+1]; \
    } n

/*
 *  Macro for defining an initialised QL string of just the right size.
 *  This will both reserve the space, and give the string an initial value.
 *  It is slightly more convenient than QLSTR_DEF in the situation where
 *  the string will be a constant as the compiler works out the required
 *  size from the length of the initialisation string.  Use a declaration
 *  of the format:
 *
 *          QLSTR_INIT(string_name,"string_text");
 *
 *  N.B.    If used inside a function, this will need the 'static' keyword
 *          preceding it as you cannot initialise 'auto' variables.
 *
 *          For compatibility with C string handling, an additional byte
 *          is allocated for the NULL byte even though it is not included
 *          in the count field.
 */
#define QLSTR_INIT(n,s)  QLSTR_DEF(n,sizeof(s)) = {sizeof(s)-1,s}

/*
 * Structure of a QL floating point
 */
typedef struct QLFLOAT {
    short   qfp_exp;    /* Exponent */
    long    qfp_mant;   /* Mantissa */
    } QLFLOAT_t;
/* 
 * Structure before each QL common heap entry 
 */
typedef struct QLHEAP {
    long    qh_size;        /* Size of entry including this header */
    long    qh_freeaddr;    /* Address to jump to on free */
    jobid_t qh_job;         /* Owner job ID of this space */
    long    qh_zero;        /* LONG word of zero */
    } QLHEAP_t;

/*
 * The following structure appears at the beginning (low address) of
 * each free memory block - used in level 2 memory allocations.
 * It is the standard QDOS structure for handling User heaps.
 */
typedef struct MELT {
    long        mp_size;    /* number of MELTSIZE units of bytes in this block */
    struct MELT *mp_next;   /* points to next free */
    } MELT_t;
#define MELTSIZE sizeof(struct MELT)

/* 
 *Structure of a RAM exception vector table 
 */
typedef struct QLVECTABLE {
    long (*qv_adderr)_P_((void));
    long (*qv_illegal)_P_((void));
    long (*qv_divzero)_P_((void));
    long (*qv_CHK)_P_((void));
    long (*qv_TRAPV)_P_((void));
    long (*qv_priviol)_P_((void));
    long (*qv_tracexpt)_P_((void));
    long (*qv_intlev7)_P_((void));
    long (*qv_5trap)_P_((void));
    long (*qv_6trap)_P_((void));
    long (*qv_7trap)_P_((void));
    long (*qv_8trap)_P_((void));
    long (*qv_9trap)_P_((void));
    long (*qv_10trap)_P_((void));
    long (*qv_11trap)_P_((void));
    long (*qv_12trap)_P_((void));
    long (*qv_13trap)_P_((void));
    long (*qv_14trap)_P_((void));
    long (*qv_15trap)_P_((void));
    } QLVECTABLE_t;

/* 
 * QDOS job header definitions 
 */
typedef struct FULLREGS {
    datareg_t   jb_D0, jb_D1, jb_D2, jb_D3, jb_D4, jb_D5, jb_D6, jb_D7;
    addreg_t    jb_A0, jb_A1, jb_A2, jb_A3, jb_A4, jb_A5, jb_A6, jb_A7;
    short       jb_SR;
    addreg_t    jb_PC;
    } FULLREGS_t;

typedef struct JOBHEADER {
    long                jb_len;     /* Length of job area (including header) */
    long                jb_start;   /* Start address of job */
    jobid_t             jb_owner;   /* Owner of job (or 0 if independant) */
    long                jb_hold;    /* Location to be cleared when job removed (or 0) */
    unsigned short      jb_tag;     /* High word of job id */
    unsigned char       jb_prior;   /* Job priority */
    unsigned char       jb_princ;   /* Priority increment (0 if inactive) */
    short               jb_stat;    /* Job status,
                                        0 possibly active,
                                        +ve delay time till re-activation,
                                        -1 suspended,
                                        -2 waiting for another job. */
    char                jb_rela6;   /* Bit 7 set after trap #4 */
    char                jb_wflag;   /* Bit 7 set if another job waiting for completion */
    jobid_t             jb_wjob;    /* Job id for job waiting above */
    QLVECTABLE_t  *     jb_trapv;   /* RAM exception vector (0 if none) */
    struct FULLREGS     jb_regs;    /* Save area for jobs registers */
    short               jb_resvd;   /* Unused */
    } JOBHEADER_t;

/*
 * Structure for linking in interrupt, polled task and 
 * scheduler routines to QDOS.
 */
typedef struct QL_LINK {
    struct QL_LINK *l_next; /* Next routine in link */
    void (*l_rtn)_P_((void));        /* Routine to call */
    } QL_LINK_t;

/*
 * Structure for linking in standard device drivers to QDOS.
 */
typedef struct QLD_LINK {
    struct QLD_LINK *ld_next;   /* Next device driver in chain */
    long (*ld_io)_P_((void));            /* Routine to call for I/O */
    long (*ld_open)_P_((void));          /* Routine to call on open */
    long (*ld_close)_P_((void));         /* Routine to call on close */
    } QLD_LINK_t;

/*
 * Structure for linking in directory device drivers to QDOS.
 */
typedef struct QLDDEV_LINK {
    struct QLDDEV_LINK *ldd_next;   /* Next directory device in chain */
    long    (*ldd_io)_P_((void));            /* Routine to call on I/O */
    long    (*ldd_open)_P_((void));          /* Routine to call on open */
    long    (*ldd_close)_P_((void));         /* Routine to call on close */
    long    (*ldd_slave)_P_((void));         /* Routine to call on enforced slaving */
    long    (*ldd_rename)_P_((void));        /* Routine to call on rename */
    long    (*ldd_trunc)_P_((void));         /* Routine to call to truncate at current pos */
    long    (*ldd_format)_P_((void));        /* Routine to call to format */
    long    ldd_plen;               /* Length of physical definition block */
    QLSTR_t ldd_dname;         /* Device name */
} QLDDEV_LINK_t;

#ifndef _QRAM_H
/* 
 * Define for QL rectangle
 */
typedef struct QLRECT {
    unsigned short   q_width;
    unsigned short   q_height;
    unsigned short   q_x;
    unsigned short   q_y;
    } QLRECT_t;
#endif
/*
 *  Define for a complete window
 */
typedef struct WINDOWDEF {
    unsigned char    border_colour;
    unsigned char    border_width;
    unsigned char    paper;
    unsigned char    ink;
    unsigned short   width;
    unsigned short   height;
    unsigned short   x_origin;
    unsigned short   y_origin;
    } WINDOWDEF_t;

/* 
 *  Defines for time conversion funtions 
 */
#define TIME_QL_UNIX(t) ((t) - 283996800)
#define TIME_UNIX_QL(t) ((t) + 283996800)

/* 
 *Defines for QDOS colours 
 */
/* Mode 8 */
#define BLACK_M8    0
#define BLUE_M8     1
#define RED_M8      2
#define MAGENTA_M8  3
#define GREEN_M8    4
#define CYAN_M8     5
#define YELLOW_M8   6
#define WHITE_M8    7

/* Mode 4 */
#define BLACK_M4    0
#define RED_M4      2
#define GREEN_M4    4
#define WHITE_M4    7

/* 
 *Defines for set drawing mode calls 
 */
#define DM_XOR      -1
#define DM_OVER     0
#define DM_OR       1

/* 
 * Defines for character sizes
 */
#define CWIDTH_6    0
#define CWIDTH_8    1
#define CWIDTH_12   2
#define CWIDTH_16   3
#define CHEIGHT_10  0
#define CHEIGHT_20  1

/*
* the following structure defines the standard QDOS file header
* - also the QDOS directory structure.
*/

typedef struct qdirect {
    unsigned long   d_length;       /* file length */
    unsigned char   d_access;       /* file access type */
    unsigned char   d_type;         /* file type */
    unsigned long   d_datalen;      /* data length for execable files */
    long            d_reserved;     /* Unused */
    unsigned short  d_szname;       /* size of name */
    char            d_name[36];     /* name area */
    long            d_update;       /* Date of last update */
    union {
        long        d_refdate;      /* Version 1 Filing systems */
        struct {
            unsigned short d_version;   /* \ Version 2 filing systems */
            unsigned short d_fileno;    /* /                          */
        } v2;
    } u;
    long            d_backup;       /* Disk data finishes here */
    } qdirect_t;

typedef struct DIR_LIST { /* Linked list of directories in memory */
    struct DIR_LIST     *dl_next;   /* Pointer to next in link */
    struct qdirect      dl_dir;     /* Actual directory structure */
    char                dl_cname[1];/* C file name (really variable length) */ 
    } DIR_LIST_t;

#define DREADSIZE sizeof( struct qdirect )

/*
* The possible file types in d_type are :-
*/
#define QF_DATA_TYPE    0   /* Data file */
#define QF_PROG_TYPE    1   /* Program file */
#define QF_RELOC_TYPE   2   /* SROFF file */
#define THOR_DIR_TYPE   3   /* Directory (Thor hard disk only) */
#define CST_DIR_TYPE    4   /* Directory (CST hard disk only) */ 
#define QF_DIR_TYPE   255   /* Directory (TT drivers for hard disk only) */

/*
 * Define structure used for extended information on file system
 * (available with systems that support File System 2 or later).
 */
typedef struct ext_mdinf {
    union {
        char    m_size[22];    /* Used to define size of union */
        QLSTR_t m_name;        /* Actual element used to access name */
    } xm_name;
    union {
        char    m_dsize[6];    /* Used to define size of union */
        QLSTR_t m_dname;       /* Actual element used to access drive name */
    } xm_dname;
    unsigned char   xm_dnum;        /* Drive number */
    char            xm_rdonly;      /* Non - zero if read only */
    unsigned short  xm_alloc;       /* Allocation unit size (in bytes ) */
    unsigned long   xm_total;       /* Total medium size (in allocation units) */
    unsigned long   xm_free;        /* Free space on medium (in allocation units) */
    unsigned long   xm_hdrlen;      /* File header length (per file storeage overhead) */
    char            xm_spare[20];   /* Twenty bytes set to -1 */
    char            xm_spare2[36];  /* Additional area used by early level 2 drivers */
    } ext_mdinf_t;

/*
* Codes for specifying what types of files to read in qdir_read
* More than one may be OR'ed together to produce a compound file list.
*/
#define QDR_ALL     0   /* Return all files found */
#define QDR_DATA    1   /* Return data files */
#define QDR_PROG    2   /* Return prog files */
#define QDR_DIR     4   /* Return directorys (hard disk only) */

/*
 *   QDOS codes for different types of file open
 */
#define OLD_EXCL    0   /* Old exclusive file open */
#define OLD_SHARE   1   /* Old shared file open */
#define NEW_EXCL    2   /* New exclusive file open */
#define NEW_OVER    3   /* New overwrite file */ 
#define DIROPEN     4   /* Code for opening a directory */

/*
*   Device structures for validating devices
*/
#define NETDEV  0x1     /* Device across the NET */
#define DIRDEV  0x2     /* Directory device */


/*
 *  Global data areas (that the user can change)
 *      (see QdosC68_DOC for details)
 */
extern  WINDOWDEF_t _condetails;
                                /* Default set-up parameters for initial console */
extern  char     _copyright[];  /* Copyright of this program */
extern  long     _def_priority; /* Default priority that jobs are started with (32) */
extern  char *   _endmsg;       /* Message displayed when program closes */
extern  timeout_t _endtimeout;  /* Timeout used for end message */
extern  long     _Jobid;        /* Job id of this job */
extern  long     _memincr;      /* Memory Increment size */
extern  long     _memmax;       /* Maximum heap memory size */
extern  long     _memqdos;      /* QDOS memory allocation that program cannot use */
extern  long     _mneed;        /* Initial memory allocation */
extern  long     _pipesize;     /* Default size that pipes will be created with (4096) */ 
extern  char     _prog_name[];  /* QDOS name for this job ("C_PROG") */
extern  char     _SLASH;        /* Directory seperator character */
extern  char *   _SPorig;       /* Stack pointer on original program entry */
extern  long     _stack;        /* Size of stack to be allocated to job */
extern  long     _stackmargin;  /* Margin at which stack checks start failing */
extern  char *   _sys_var;      /* declare external base of system variables */
extern  char     _tmpdir_[];    /* Default directory for temporary files (normally "") */
extern  char     _tmpnam_[];    /* Default prefix for temporary files (normally "tmp") */
extern  char     _version[];    /* Version number of this program */
extern  int      os_nerr;       /* Number of messages in os_errlist (below) */
extern  char     *os_errlist[]; /* List of messages for QDOS error codes */
/*
 *  Global variables that are not guaranteed to be
 *  present in future releases of the C68 system.
 */
extern  char     _CPU;          /* CPU type.  0x00 = 68008 or 68000 */
                                /*            0x10 = 68010  */
                                /*            0x20 = 68020  */
                                /*            0x30 = 68030  */
                                /*            0x40 = 68040  */
extern  char    _FPU;           /* FPU type:  0 = none */
                                /*            1 = 68881 */
                                /*            2 = 68882 (or compatible) */
/*
 *  Global vectors (that the user can change)
 *      (see QdosC68_DOC for details)
 */
extern  long (*_cmdchannels)    _P_((long));
                                /* Vector for channels via command line redirection */
extern  int  (*_cmdparams)      _P_((const char *, char ***, int *, int (*)_P_((char *, char ***, int *)) ));
                                /* Vector for command line parsing routine */
extern  int  (*_cmdwildcard)    _P_((char *, char ***, int *));
                                /* Vector for wildcard expansion on command line */
extern  void (*_consetup)       _P_((chanid_t, WINDOWDEF_t *));
                                /* Vector for console initialisation */
extern void   _initcon         _P_((void));
                                /* Internal library routine for console/screen  */
                                /* device set-up after opens performed          */
extern  long (*_stackchannels)  _P_((long));
                                /* Vector for channels via stack */
extern  int  (*_readkbd)        _P_((chanid_t, timeout_t, char *));
                                /* Vector to routine to read keyboard, used by _conread() */
/*
 *  Routines that can be set for use via global vectors
 *      (see QdosC68_DOC for details)
 */
int  cmdexpand          _P_((char *, char ***, int*));
void consetup_qpac      _P_((chanid_t, WINDOWDEF_t *));
void consetup_title     _P_((chanid_t, WINDOWDEF_t *));
int  readkbd_move       _P_((chanid_t, timeout_t, char *));

/**
 *
 *  Function definitions that are common to the
 *  QDOS and SMS interfaces to the C68 library.
 *
 **/
/*
 *  Screen handling  (TRAP #3)
 */
int   ioppick       _P_((jobid_t));

/*
 *  Conversion routines
 */

/*  Name Hiding Definitions */
#define cstr_to_ql  _cstr_to_ql
#define d_to_qlfp   _d_to_qlfp
/*  Prototypes */
QLSTR_t *   cstr_to_ql  _P_((QLSTR_t *, char *));
QLFLOAT_t * d_to_qlfp   _P_((QLFLOAT_t *, double));
char *      qlstr_to_c  _P_((char *, QLSTR_t *));
QLFLOAT_t * i_to_qlfp   _P_((QLFLOAT_t *, int));
QLFLOAT_t * l_to_qlfp   _P_((QLFLOAT_t *, long));
QLFLOAT_t * w_to_qlfp   _P_((QLFLOAT_t *, int));
double      qlfp_to_d   _P_((QLFLOAT_t *));
long        qlfp_to_f   _P_((QLFLOAT_t *));

/*
 *  QDOS string handling routines
 */
QLSTR_t *   qstrcat     _P_((QLSTR_t *, const QLSTR_t *));
char *      qstrchr     _P_((const QLSTR_t *, int));
int         qstrcmp     _P_((const QLSTR_t *, const QLSTR_t *));
QLSTR_t *   qstrcpy     _P_((QLSTR_t *, const QLSTR_t *));
int         qstricmp    _P_((QLSTR_t *, QLSTR_t *));
size_t      qstrlen     _P_((const QLSTR_t *));
QLSTR_t *   qstrncat    _P_((QLSTR_t *, const QLSTR_t *, short));
int         qstrncmp    _P_((const QLSTR_t *, const QLSTR_t *, short));
QLSTR_t *   qstrncpy    _P_((QLSTR_t *, const QLSTR_t *, short));
int         qstrnicmp   _P_((QLSTR_t *, QLSTR_t *, short));

/*
 *  Miscellaneous
 */
/*  Name Hiding definitions */
#define argfree   _argfree
#define argpack   _argpack
#define argunpack _argunpack
#ifndef BEEP
#define beep      _beep
#endif /* BEEP */
#define chpdir    _chpdir
#define do_sound  _do_sound
/*  Prototypes */
void     _super      _P_((void));
void     _user       _P_((void));
void     argfree     _P_((char ***));
char *   argpack     _P_((char * const *, int));
int      argunpack   _P_((const char *, char ***, int *, int (*)_P_((char *, char ***, int*)) ));
#ifndef _BEEP
void     beep        _P_((unsigned short, unsigned char));
#define _BEEP
#endif /* _BEEP */
int      chddir      _P_((char *));
int      chpdir      _P_((char *));
void     do_sound    _P_((unsigned short, unsigned char, unsigned char, unsigned char, \
                          unsigned short, unsigned char, unsigned char, unsigned char));
int      fnmatch     _P_((char *, char *));
int      fqstat      _P_((int, struct qdirect *));
char *   getcdd      _P_((char *, int));
char *   getcpd      _P_((char *, int));
long     getchid     _P_((int));
char *   getcname    _P_((chanid_t, char *));
int      iscon       _P_((chanid_t, timeout_t));
int      isdevice    _P_((const char *, int *));
struct QLDDEV_LINK *  isdirchid  _P_((chanid_t));
int      isdirdev    _P_((const char *));
int      isnoclose   _P_((int));
int      keyrow      _P_((char));
chanid_t open_qdir   _P_((const char *));
int      poserr      _P_((const char *));
void     qdir_delete _P_((DIR_LIST_t *));
DIR_LIST_t * qdir_read  _P_((char *, char *, int));
DIR_LIST_t * qdir_sort  _P_((DIR_LIST_t *, char *, \
                            int (*)(DIR_LIST_t *, DIR_LIST_t *, char *)));
long     qdos1       _P_((struct REGS *, struct REGS *));
long     qdos2       _P_((struct REGS *, struct REGS *));
long     qdos3       _P_((struct REGS *, struct REGS *));
pid_t    qforkl      _P_((const jobid_t, const char *, int *, const char *, ...));
pid_t    qforklp     _P_((const jobid_t, const char *, int *, const char *, ...));
pid_t    qforkv      _P_((const jobid_t, const char *, int *, char * const *));
pid_t    qforkvp     _P_((const jobid_t, const char *, int *, char * const *));
int      qinstrn     _P_((char *, int));
int      read_qdir   _P_((chanid_t, char *, char *, struct qdirect *, int));
int      qstat       _P_((char *, struct qdirect *));
long     stackcheck  _P_((void));
long     stackreport _P_((void));
char *   str_oserr   _P_((int));
int      usechid     _P_((chanid_t));
int      waitfor     _P_((jobid_t, int *));
QLFLOAT_t * d_to_qlfp   _P_((QLFLOAT_t *, double));
QLFLOAT_t * l_to_qlfp   _P_((QLFLOAT_t *, long));

#ifdef __LIBRARY__
/*************************************************************************
 *
 *                          C A U T I O N
 *                          ~~~~~~~~~~~~~
 *
 *  The remainder of this header contains definitions that are internal
 *  to the way that the C68 libraries have been implemented on QDOS/SMS.
 *  These definitions should not be used by any user program as they are
 *  subject to change without notice.
 *
 *************************************************************************/


#define DIR_MAGIC   0x4AFB      /* Magic Number for directories passed on stack */
#define ENV_MAGIC   0x4AFC      /* Magic Number for environment passed on stack */

extern unsigned char _CCX_option;   /* The X? option used with CC (if any) */

extern unsigned char _C_esc_a[];    /* List of C escape characters */
extern unsigned char _C_esc[];      /* ... and corresponding internal values */

extern unsigned char _C_hex_a[];    /* List of C hex characters (both cases)*/
extern unsigned char _C_hex[];      /* ... and corresponding internal values */

extern unsigned char _C_oct_a[];    /* List of C octal characters */
extern unsigned char _C_oct[];      /* ... and corresponding internal values */

extern char _data_use[];        /* Tag for data directory */
extern char _prog_use[];        /* Tag for program directory */
extern char _spl_use[];         /* Tag for spool (destination) directory */

extern int  _argc;              /* Argument count */
extern char **_VARG;            /* Arguments vector */
extern char *_VENV;             /* Environment strings pointer */
extern char **_VENVP;           /* Environment pointer array address */
extern char _iname[];           /* stdin name */
extern char _oname[];           /* stdout name */
extern char _ename[];           /* stderr name */
extern char *_Envp;             /* environment control area pointer */
extern long _nsems;
extern char _conname[];         /* Default name for console channels */
extern chanid_t _conchan;       /* Channel to be used for conio */
extern chanid_t _endchanid;     /* Channel Id for end message (if any) */
extern int  _fmode;
extern int  _iomode;            /* Default I/O mode */
extern long  _stackmax;         /* Maximum stack used (when stack checking active) */
extern int  _ydays_per_month[]; /* List of day of year in which months start */


/**
 *
 *  Vectors to functions
 *
**/
extern void (*_tmpdel)(void);

/**
 *
 * External definitions
 *
**/
int     _cd         _P_((char *, char *));
int     _ch_chown   _P_((chanid_t, jobid_t));
int     _chksmpl    _P_((QLSTR_t *));
long    _cmdchans   _P_((long));
void    _cmdparse   _P_((char *));
chanid_t _conget    _P_((void));
void    _consetup_default  _P_((chanid_t, WINDOWDEF_t *));
void    _envsetup   _P_((char *));                               /* EJ */
long    _forkexec   _P_((const char *, int, int *, char * const *, jobid_t));
int     _fqstat     _P_((chanid_t, struct qdirect *));
char *  _getcd      _P_((char *, char *, int));
jobid_t _get_chown  _P_((chanid_t));
void    _main           _P_((char *));
char *  _mkname         _P_((char *, const char *));
int     _read_qdir_action _P_((chanid_t, char *, char *, struct qdirect *, \
                                      int, char *, char *, int, char *, int));
int     _read_qdir_prep   _P_((char *, char *, char *, int *, char *, \
                                      char *, char **, int *));
int     _qlmknam        _P_((char *, const char *, const char *, int));
void    _setcd          _P_((char *, char *));
void    _stdchans       _P_((void));
long    _stkchans       _P_((long));
void    _stack_error    _P_((long));
void    _stack_newmax   _P_((void));
int     _waitforjob     _P_((jobid_t));

#endif /* __LIBRARY__ */

#undef _P_

#endif /* _SYS_QLIB_H */
                                                                         
