C****************************** Module Header ******************************
C*
C* Copyright (c) 1990  Microsoft Corporation
C*
C* Module Name: FLIB.FD
C*
C* This module provides parameter and structure type declarations
C* needed to communicate with subprograms found in the various FORTRAN
C* libraries.  Each of the functional areas covered by this include file
C* are small enough that separate include files for each are not warranted.
C*
C* The functional areas covered are the following.
C*
C*    Math error support
C*    Signal handling
C*    Date and Time
C*    Command Line Arguments
C*    Random Numbers
C*    Spawning programs
C*    Handling drives, directories, and files
C*    Keyboard input
C*    Error handling
C*    Environment variables
C*
C***************************************************************************

C -----------------------------------------------------------------
C Data Type Codes.
C -----------------------------------------------------------------

      INTEGER*4 TY$REAL4
      INTEGER*4 TY$REAL8
      INTEGER*4 TY$CMPLX8
      INTEGER*4 TY$CMPLX16

      PARAMETER (TY$REAL4           = 1)
      PARAMETER (TY$REAL8           = 2)
      PARAMETER (TY$CMPLX8          = 3)
      PARAMETER (TY$CMPLX16         = 4)

C -----------------------------------------------------------------
C Math Error Support
C -----------------------------------------------------------------
C Codes for function failure.
      INTEGER*4 MTH$E_DOMAIN              ! Argument domain error
      INTEGER*4 MTH$E_SINGULARITY         ! Argument Singularity
      INTEGER*4 MTH$E_OVERFLOW            ! Overflow range error
      INTEGER*4 MTH$E_UNDERFLOW           ! Underflow range error
      INTEGER*4 MTH$E_TLOSS               ! Total loss of precision
      INTEGER*4 MTH$E_PLOSS               ! Partial loss of precision

      PARAMETER (MTH$E_DOMAIN      = 1)
      PARAMETER (MTH$E_SINGULARITY = 2)
      PARAMETER (MTH$E_OVERFLOW    = 3)
      PARAMETER (MTH$E_UNDERFLOW   = 4)
      PARAMETER (MTH$E_TLOSS       = 5)
      PARAMETER (MTH$E_PLOSS       = 6)

C Math error information structure.
      STRUCTURE /MTH$E_INFO/
        INTEGER*4 ERRCODE        ! INPUT : One of the MTH$ values above
        INTEGER*4 FTYPE          ! INPUT : One of the TY$ values above
        UNION
        MAP
            REAL*4 R4ARG1        ! INPUT : FIrst argument
            REAL*4 R4ARG2        ! INPUT : Second argument (if any)
            REAL*4 R4RES         ! OUTPUT : Desired result
        END MAP
        MAP
            REAL*8 R8ARG1        ! INPUT : FIrst argument
            REAL*8 R8ARG2        ! INPUT : Second argument (if any)
            REAL*8 R8RES         ! OUTPUT : Desired result
        END MAP
        MAP
            COMPLEX*8 C8ARG1     ! INPUT : FIrst argument
            COMPLEX*8 C8ARG2     ! INPUT : Second argument (if any)
            COMPLEX*8 C8RES      ! OUTPUT : Desired result
        END MAP
        MAP
            COMPLEX*16 C16ARG1   ! INPUT : FIrst argument
            COMPLEX*16 C16ARG2   ! INPUT : Second argument (if any)
            COMPLEX*16 C16RES    ! OUTPUT : Desired result
        END MAP
        END UNION
      END STRUCTURE

      EXTERNAL MATHERRQQ

C -----------------------------------------------------------------
C Signal support
C -----------------------------------------------------------------
      INTEGER*4 SIG$ERR                   ! SIGNALQQ return value
      INTEGER*4 SIG$NSIG
      INTEGER*4 SIG$INT
      INTEGER*4 SIG$ILL
      INTEGER*4 SIG$FPE
      INTEGER*4 SIG$SEGV
      INTEGER*4 SIG$TERM
      INTEGER*4 SIG$USR1
      INTEGER*4 SIG$USR2
      INTEGER*4 SIG$USR3
      INTEGER*4 SIG$BREAK
      INTEGER*4 SIG$ABORT

      PARAMETER (SIG$ERR   = -1)
      PARAMETER (SIG$NSIG  = 23)
      PARAMETER (SIG$INT   =  2)
      PARAMETER (SIG$ILL   =  4)
      PARAMETER (SIG$FPE   =  8)
      PARAMETER (SIG$SEGV  = 11)
      PARAMETER (SIG$TERM  = 15)
      PARAMETER (SIG$USR1  = 16)
      PARAMETER (SIG$USR2  = 17)
      PARAMETER (SIG$USR3  = 20)
      PARAMETER (SIG$BREAK = 21)
      PARAMETER (SIG$ABORT = 22)

      INTEGER*4 FPE$INVALID
      INTEGER*4 FPE$DENORMAL
      INTEGER*4 FPE$ZERODIVIDE
      INTEGER*4 FPE$OVERFLOW
      INTEGER*4 FPE$UNDERFLOW
      INTEGER*4 FPE$INEXACT
      INTEGER*4 FPE$UNEMULATED
      INTEGER*4 FPE$SQRTNEG
      INTEGER*4 FPE$STACKOVERFLOW
      INTEGER*4 FPE$STACKUNDERFLOW
      INTEGER*4 FPE$EXPLICITGEN                 ! RAISEQQ( SIGFPE )

      PARAMETER (FPE$INVALID        = #81)
      PARAMETER (FPE$DENORMAL       = #82)
      PARAMETER (FPE$ZERODIVIDE     = #83)
      PARAMETER (FPE$OVERFLOW       = #84)
      PARAMETER (FPE$UNDERFLOW      = #85)
      PARAMETER (FPE$INEXACT        = #86)
      PARAMETER (FPE$UNEMULATED     = #87)
      PARAMETER (FPE$SQRTNEG        = #88)
      PARAMETER (FPE$STACKOVERFLOW  = #8a)
      PARAMETER (FPE$STACKUNDERFLOW = #8b)
      PARAMETER (FPE$EXPLICITGEN    = #8c)

      INTEGER*4 SIGNALQQ[EXTERN]
      INTEGER*4 RAISEQQ[EXTERN]

C -----------------------------------------------------------------
C Floating Point Control and Status
C -----------------------------------------------------------------

      INTEGER*2 FPCW$MCW_EM
      INTEGER*2 FPCW$INEXACT
      INTEGER*2 FPCW$UNDERFLOW
      INTEGER*2 FPCW$OVERFLOW
      INTEGER*2 FPCW$ZERODIVIDE
      INTEGER*2 FPCW$INVALID
      INTEGER*2 FPCW$DENORMAL

      INTEGER*2 FPCW$MCW_PC
      INTEGER*2 FPCW$64
      INTEGER*2 FPCW$53
      INTEGER*2 FPCW$24

      INTEGER*2 FPCW$MCW_IC
      INTEGER*2 FPCW$AFFINE
      INTEGER*2 FPCW$PROJECTIVE

      INTEGER*2 FPCW$MCW_RC
      INTEGER*2 FPCW$NEAR
      INTEGER*2 FPCW$DOWN
      INTEGER*2 FPCW$UP
      INTEGER*2 FPCW$CHOP

      INTEGER*2 FPSW$MSW_EM
      INTEGER*2 FPSW$INVALID
      INTEGER*2 FPSW$DENORMAL
      INTEGER*2 FPSW$ZERODIVIDE
      INTEGER*2 FPSW$OVERFLOW
      INTEGER*2 FPSW$UNDERFLOW
      INTEGER*2 FPSW$INEXACT

      PARAMETER (FPCW$MCW_EM        = #003F)  ! exception mask
      PARAMETER (FPCW$INVALID       = #0001)  ! invalid
      PARAMETER (FPCW$DENORMAL      = #0002)  ! denormal
      PARAMETER (FPCW$ZERODIVIDE    = #0004)  ! zero divide
      PARAMETER (FPCW$OVERFLOW      = #0008)  ! overflow
      PARAMETER (FPCW$UNDERFLOW     = #0010)  ! underflow
      PARAMETER (FPCW$INEXACT       = #0020)  ! inexact (precision)

      PARAMETER (FPCW$MCW_PC        = #0300)  ! precision control mask
      PARAMETER (FPCW$64            = #0300)  ! 64 bits
      PARAMETER (FPCW$53            = #0200)  ! 53 bits
      PARAMETER (FPCW$24            = #0000)  ! 24 bits

      PARAMETER (FPCW$MCW_IC        = #1000)  ! infinity control mask
      PARAMETER (FPCW$AFFINE        = #1000)  ! affine
      PARAMETER (FPCW$PROJECTIVE    = #0000)  ! projective

      PARAMETER (FPCW$MCW_RC        = #0C00)  ! rounding control mask
      PARAMETER (FPCW$CHOP          = #0C00)  ! chop
      PARAMETER (FPCW$UP            = #0800)  ! up
      PARAMETER (FPCW$DOWN          = #0400)  ! down
      PARAMETER (FPCW$NEAR          = #0000)  ! near

      PARAMETER (FPSW$MSW_EM        = #003F)  ! exception mask
      PARAMETER (FPSW$INVALID       = #0001)  ! invalid
      PARAMETER (FPSW$DENORMAL      = #0002)  ! denormal
      PARAMETER (FPSW$ZERODIVIDE    = #0004)  ! zero divide
      PARAMETER (FPSW$OVERFLOW      = #0008)  ! overflow
      PARAMETER (FPSW$UNDERFLOW     = #0010)  ! underflow
      PARAMETER (FPSW$INEXACT       = #0020)  ! inexact (precision)

      EXTERNAL    LCWRQQ
      EXTERNAL    SCWRQQ
      EXTERNAL    SSWRQQ
      EXTERNAL    SETCONTROLFPQQ
      EXTERNAL    GETCONTROLFPQQ
      EXTERNAL    GETSTATUSFPQQ

C -----------------------------------------------------------------
C Time and Date Support
C -----------------------------------------------------------------
      LOGICAL*4 SETTIM[EXTERN]
      LOGICAL*4 SETDAT[EXTERN]
      EXTERNAL  GETTIM
      EXTERNAL  GETDAT

C -----------------------------------------------------------------
C Command Line Arguments
C -----------------------------------------------------------------
      INTEGER*4 NARGS[EXTERN]
      EXTERNAL  GETARG

C -----------------------------------------------------------------
C Random Numbers
C -----------------------------------------------------------------
      INTEGER*4 RND$TIMESEED

      PARAMETER (RND$TIMESEED = -1)

      EXTERNAL    RANDOM
      EXTERNAL    SEED

C -----------------------------------------------------------------
C Running Programs and System Commands
C -----------------------------------------------------------------
      INTEGER*4 RUNQQ[EXTERN]
      LOGICAL*4 SYSTEMQQ[EXTERN]

C -----------------------------------------------------------------
C Drives and Directories
C -----------------------------------------------------------------

      LOGICAL*4 GETDRIVESIZEQQ[EXTERN]
      CHARACTER*26 GETDRIVESQQ[EXTERN]
      INTEGER*4 GETDRIVEDIRQQ[EXTERN]
      LOGICAL*4 CHANGEDRIVEQQ[EXTERN]
      LOGICAL*4 CHANGEDIRQQ[EXTERN]
      LOGICAL*4 MAKEDIRQQ[EXTERN]
      LOGICAL*4 DELDIRQQ[EXTERN]
      INTEGER*4 FULLPATHQQ[EXTERN]
      INTEGER*4 SPLITPATHQQ[EXTERN]

      CHARACTER*1 FILE$CURDRIVE
      INTEGER*4   FILE$MAXNAME

      PARAMETER (FILE$CURDRIVE = ' ')
      PARAMETER (FILE$MAXNAME = 255)

C -----------------------------------------------------------------
C Files
C -----------------------------------------------------------------

      INTEGER*4 GETFILEINFOQQ[EXTERN]
      LOGICAL*4 SETFILETIMEQQ[EXTERN]
      LOGICAL*4 SETFILEACCESSQQ[EXTERN]
      LOGICAL*4 RENAMEFILEQQ[EXTERN]
      EXTERNAL  PACKTIME
      EXTERNAL  UNPACKTIME
      INTEGER*4 DELFILESQQ[EXTERN]
      INTEGER*4 FINDFILEQQ[EXTERN]
      LOGICAL*4 COMMITQQ[EXTERN]

      STRUCTURE / FILE$INFO /
        INTEGER*4       CREATION          ! Creation time (-1 on FAT)
        INTEGER*4       LASTWRITE         ! Last write to file
        INTEGER*4       LASTACCESS        ! Last access (-1 on FAT)
        INTEGER*4       LENGTH            ! Length of file
        INTEGER*2       PERMIT            ! File access mode
        CHARACTER*13    NAME              ! File name
      END STRUCTURE

      INTEGER*4 FILE$NORMAL
      INTEGER*4 FILE$READONLY
      INTEGER*4 FILE$HIDDEN
      INTEGER*4 FILE$SYSTEM
      INTEGER*4 FILE$VOLUME
      INTEGER*4 FILE$DIR
      INTEGER*4 FILE$ARCHIVE
      INTEGER*4 FILE$FIRST
      INTEGER*4 FILE$LAST
      INTEGER*4 FILE$ERROR
      INTEGER*4 FILE$INVALID
      INTEGER*4 FILE$CURTIME

      PARAMETER (FILE$NORMAL      = #0000)
      PARAMETER (FILE$READONLY    = #0001)
      PARAMETER (FILE$HIDDEN      = #0002)
      PARAMETER (FILE$SYSTEM      = #0004)
      PARAMETER (FILE$VOLUME      = #0008)
      PARAMETER (FILE$DIR         = #0010)
      PARAMETER (FILE$ARCHIVE     = #0020)

      PARAMETER (FILE$FIRST       = -1)
      PARAMETER (FILE$LAST        = -2)
      PARAMETER (FILE$ERROR       = -3)

      PARAMETER (FILE$INVALID     = -1) ! For PACKTIMEQQ and UNPACKTIMEQQ
      PARAMETER (FILE$CURTIME     = -1) ! For SETFILETIMEQQ

C -----------------------------------------------------------------
C Keyboard
C -----------------------------------------------------------------

      CHARACTER*1 GETCHARQQ[EXTERN]
      LOGICAL*4 PEEKCHARQQ[EXTERN]
      INTEGER*4 GETSTRQQ[EXTERN]

C -----------------------------------------------------------------
C Errors
C -----------------------------------------------------------------

      INTEGER*4 ERR$ZERO
      INTEGER*4 ERR$PERM
      INTEGER*4 ERR$NOENT
      INTEGER*4 ERR$SRCH
      INTEGER*4 ERR$INTR
      INTEGER*4 ERR$IO
      INTEGER*4 ERR$NXIO
      INTEGER*4 ERR$2BIG
      INTEGER*4 ERR$NOEXEC
      INTEGER*4 ERR$BADF
      INTEGER*4 ERR$CHILD
      INTEGER*4 ERR$AGAIN
      INTEGER*4 ERR$NOMEM
      INTEGER*4 ERR$ACCES
      INTEGER*4 ERR$FAULT
      INTEGER*4 ERR$NOTBLK
      INTEGER*4 ERR$BUSY
      INTEGER*4 ERR$EXIST
      INTEGER*4 ERR$XDEV
      INTEGER*4 ERR$NODEV
      INTEGER*4 ERR$NOTDIR
      INTEGER*4 ERR$ISDIR
      INTEGER*4 ERR$INVAL
      INTEGER*4 ERR$NFILE
      INTEGER*4 ERR$MFILE
      INTEGER*4 ERR$NOTTY
      INTEGER*4 ERR$TXTBSY
      INTEGER*4 ERR$FBIG
      INTEGER*4 ERR$NOSPC
      INTEGER*4 ERR$SPIPE
      INTEGER*4 ERR$ROFS
      INTEGER*4 ERR$MLINK
      INTEGER*4 ERR$PIPE
      INTEGER*4 ERR$DOM
      INTEGER*4 ERR$RANGE
      INTEGER*4 ERR$UCLEAN
      INTEGER*4 ERR$DEADLOCK

      PARAMETER (ERR$ZERO         =  0)
      PARAMETER (ERR$PERM         =  1)
      PARAMETER (ERR$NOENT        =  2)
      PARAMETER (ERR$SRCH         =  3)
      PARAMETER (ERR$INTR         =  4)
      PARAMETER (ERR$IO           =  5)
      PARAMETER (ERR$NXIO         =  6)
      PARAMETER (ERR$2BIG         =  7)
      PARAMETER (ERR$NOEXEC       =  8)
      PARAMETER (ERR$BADF         =  9)
      PARAMETER (ERR$CHILD        = 10)
      PARAMETER (ERR$AGAIN        = 11)
      PARAMETER (ERR$NOMEM        = 12)
      PARAMETER (ERR$ACCES        = 13)
      PARAMETER (ERR$FAULT        = 14)
      PARAMETER (ERR$NOTBLK       = 15)
      PARAMETER (ERR$BUSY         = 16)
      PARAMETER (ERR$EXIST        = 17)
      PARAMETER (ERR$XDEV         = 18)
      PARAMETER (ERR$NODEV        = 19)
      PARAMETER (ERR$NOTDIR       = 20)
      PARAMETER (ERR$ISDIR        = 21)
      PARAMETER (ERR$INVAL        = 22)
      PARAMETER (ERR$NFILE        = 23)
      PARAMETER (ERR$MFILE        = 24)
      PARAMETER (ERR$NOTTY        = 25)
      PARAMETER (ERR$TXTBSY       = 26)
      PARAMETER (ERR$FBIG         = 27)
      PARAMETER (ERR$NOSPC        = 28)
      PARAMETER (ERR$SPIPE        = 29)
      PARAMETER (ERR$ROFS         = 30)
      PARAMETER (ERR$MLINK        = 31)
      PARAMETER (ERR$PIPE         = 32)
      PARAMETER (ERR$DOM          = 33)
      PARAMETER (ERR$RANGE        = 34)
      PARAMETER (ERR$UCLEAN       = 35)
      PARAMETER (ERR$DEADLOCK     = 36)

      LOGICAL*4 ERR$HARDPROMPT      ! For SETERRORMODEQQ
      LOGICAL*4 ERR$HARDFAIL

      PARAMETER (ERR$HARDPROMPT   = .TRUE.)
      PARAMETER (ERR$HARDFAIL     = .FALSE.)

      INTEGER*4 GETLASTERRORQQ[EXTERN]
      EXTERNAL  SETERRORMODEQQ

C ----------------------------------------------------------------
C Environment
C ----------------------------------------------------------------

      INTEGER*4 GETENVQQ[EXTERN]
      LOGICAL*4 SETENVQQ[EXTERN]

C -----------------------------------------------------------------
C Beep and Sleep
C -----------------------------------------------------------------

      EXTERNAL SLEEPQQ
      EXTERNAL BEEPQQ

C ----------------------------------------------------------------
C Sorting and Searching Arrays
C ----------------------------------------------------------------

      INTEGER*4 SRT$REAL4
      INTEGER*4 SRT$REAL8
      INTEGER*4 SRT$INTEGER1
      INTEGER*4 SRT$INTEGER2
      INTEGER*4 SRT$INTEGER4

      PARAMETER (SRT$REAL4          = #00010000)
      PARAMETER (SRT$REAL8          = #00020000)
      PARAMETER (SRT$INTEGER1       = #00030000)
      PARAMETER (SRT$INTEGER2       = #00040000)
      PARAMETER (SRT$INTEGER4       = #00050000)

      INTEGER*4 BSEARCHQQ[EXTERN]
      EXTERNAL  SORTQQ

C ----------------------------------------------------------------
C Configuration
C ----------------------------------------------------------------

      INTEGER*4 GETCONFIGQQ[EXTERN]

      INTEGER*4 CFG$WINNT

      PARAMETER (CFG$WINNT          = #00000001)
