home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / STDERRF.ZIP / EXIT.ASM next >
Assembly Source File  |  1995-05-29  |  6KB  |  199 lines

  1.     page 60,132
  2.     title    Exit - STDERRF's Abnormal Exit Procedure
  3.     name    Exit
  4.     
  5. comment ÷
  6.     Exit                            V1.00
  7. ----------------------------------------------------------------------------
  8. NAME
  9.     Exit                STDERRF's Abnormal Exit Procedure
  10.  
  11. SYNOPSIS
  12.     mov    bx, ax            ; BX = DOS Error Code
  13.     mov    ax, eqERR_EQUATE    ; AX = Error Type
  14.     call    Exit
  15.  
  16. DESCRIPTION
  17.     Exit procedure is STDERRF's abnormal exit procedure.  This procedure
  18.     is called if an error condition is detected.  Since most error
  19.     conditions are the result of failed DOS interrupts, Exit will
  20.     convert the DOS error code to hex and display it along with an error
  21.     message.
  22.  
  23.     Lastly, DupStdErr is checked to see if it was cleared which means
  24.     that STDERR has been restored.    If not, STDERR is retored here.
  25.  
  26. PROGRAMMING NOTES
  27.     An index to the error messae is passed in AX register.
  28.     The DOS Error Code is passed in BX register.
  29.     If no DOS Error, -1 is passed in BX.
  30.  
  31.     Procedures called:
  32.         None
  33.     DOS Interrupts
  34.         Int 21h 40h - Write to file or device
  35.         Int 21h 46h - Force duplication of filehandle
  36.         Int 21h 4ch - Terminate program with return code
  37.  
  38. RETURNS
  39.     The Exit Procedure does not return but terminates the program by
  40.     exiting to DOS.
  41.  
  42. CAUTIONS
  43.     This file assembles with one warning:
  44.         EXIT.ASM(197) : warning A6001: no return from procedure
  45.  
  46.     Since this procedure ALWAYS terminates the program and NEVER
  47.     returns, this warning can be ignored.
  48.  
  49. MEMORY REQUIREMENTS
  50.     Stack:      8 bytes
  51.     Data:     41 bytes
  52.     Const:    558 bytes
  53.     Code:    114 bytes
  54.  
  55. AUTHOR
  56.     Raymond Moon - 5 Mar 95
  57.     Copyright (c) 1995, MoonWare
  58.     ALL RIGHTS RESERVED
  59.  
  60. HISTORY
  61.     Version    - Date        - Remarks
  62.     1.00    -  5 Mar 95    - Orginal
  63.     
  64.     ÷ End of Comment
  65.  
  66.     include procesor.inc
  67. %    .MODEL    small,FORTRAN
  68.     assume    es:DGROUP
  69.  
  70. ;-----------------------------
  71. ;    Include files
  72.  
  73.     include stderrf.inc
  74.  
  75. ;=========================================================================
  76. ;    DATA
  77. ;=========================================================================
  78.  
  79.     .CONST
  80. USAGE        db    LF, "Usage:", CR, LF, TAB, "STDERRF target ",
  81.             "execfile [command line]", CR, LF, TAB, TAB,
  82.             "target is file to which STDERR will be ",
  83.             "redirected", CR, LF, TAB, TAB, "execfile is ",
  84.             "the [drive:full path\]filename.ext of program ",
  85.             "to execute", CR, LF, TAB, TAB, "command line is ",
  86.             "optional command line for execfile", CR, LF, LF
  87. USAGE_LEN    equ    $ - USAGE
  88. USERTERM    db    CR, LF, LF, "STDERRF terminated at user's request.",
  89.             BELL
  90. USERTERM_LEN    equ    $ - USERTERM
  91. WRONGDOS    db    CR, LF, LF, "DOS must be version 3.0 or later.",
  92.             BELL
  93. WRONGDOS_LEN    equ    $ - WRONGDOS
  94. DUPERR        db    "Unable to duplicate STDERR filehandle."
  95. DUPERR_LEN    equ    $ - DUPERR
  96. CREATEERR    db    "Unable to create redirection file."
  97. CREATEERR_LEN    equ    $ - CREATEERR
  98. FORCEDUPERR    db    "Unable to force STDERR to redirection filehandle."
  99. FORCEDUPERR_LEN equ    $ - FORCEDUPERR
  100. EXECERR     db    "Unable to load and execute program."
  101. EXECERR_LEN    equ    $ - EXECERR
  102. RESTOREERR    db    "Unable to restore STDERR."
  103. RESTOREERR_LEN    equ    $ - RESTOREERR
  104. CLOSEERR    db    "Unable to close redirection file."
  105. CLOSEERR_LEN    equ    $ - CLOSEERR
  106.  
  107. ERROR        db    CR, LF, "Error: "
  108. ERRORCODE    db    CR, LF, "DOS Error: 0"
  109. XLATABLE    db    "0123456789abc"
  110.  
  111.     .DATA
  112. CLOSE        db    ?, "h", CR, LF, BELL
  113.  
  114. ;----------------------------
  115. ;    The order of the messages in MSGTEXT and MSGLEN must be in the
  116. ;    same order as the Error Equates in STDERRF.INC
  117.  
  118. MSGTEXT     dw    USAGE,       USERTERM,    WRONGDOS, DUPERR,
  119.             CREATEERR, FORCEDUPERR, EXECERR,  RESTOREERR,
  120.             CLOSEERR
  121.  
  122. MSGLEN        dw    USAGE_LEN,   USERTERM_LEN,   WRONGDOS_LEN,
  123.             DUPERR_LEN,  CREATEERR_LEN,  FORCEDUPERR_LEN,
  124.             EXECERR_LEN, RESTOREERR_LEN, CLOSEERR_LEN
  125.  
  126. ;=========================================================================
  127. ;    CODE
  128. ;=========================================================================
  129.  
  130.     .CODE
  131.  
  132. Exit    proc
  133. local    PASSED_ERR:word, DOS_ERR:word    ; Local storage for passed reg args
  134.  
  135. ;----------------------------
  136. ;    Save passed args
  137.  
  138.     mov    PASSED_ERR, ax        ; Save Passed Error Equate
  139.     mov    DOS_ERR, bx        ; Save DOS Error Code
  140.  
  141. ;----------------------------
  142. ;    If DOS_ERR is not -1, convert DOS Error Code into hex and save
  143. ;    in CLOSE message.  Use XLAT to convert binary to hex
  144.  
  145.     cmp    ax, eqMINDOSERR        ; DOS Error?
  146.     jae    EX1            ; No, skip conversion and error msg
  147.     mov    ax, bx            ; AX = error code
  148.     mov    bx, offset XLATABLE    ; BX => XLAT table
  149.     xlat                ; Translate (convert bin to hex)
  150.     mov    CLOSE, al        ; Save it in error message
  151.  
  152. ;----------------------------
  153. ;    Display the first error message
  154.  
  155.     @WRITE    ERROR, STDOUT
  156.  
  157. ;----------------------------
  158. ;    Display message using passed error type as index
  159.  
  160. EX1:    mov    bx, PASSED_ERR        ; BX = index
  161.     shl    bx, 1            ; BX = word offset
  162.     mov    dx, MSGTEXT[bx]     ; DX => appropriate message
  163.     mov    cx, MSGLEN[bx]        ; CX = message length
  164.     mov    bx, STDOUT        ; Send to STDOUT
  165.     mov    ah, 40h         ; Request DOS write to device or file
  166.     int    21h            ; Call DOS
  167.  
  168. ;------------------------------
  169. ;    Print DOS ERROR header, if appropriate
  170.  
  171.     cmp    PASSED_ERR, eqMINDOSERR    ; Is DOS Error?
  172.     jae    EX2            ; No, skip message
  173.     @WRITE    ERRORCODE, STDOUT    ; Yes, display message
  174.  
  175. ;----------------------------
  176. ;    Print the error ending.  This is skipped if DOS Error = -1.
  177.  
  178.     @WRITE    CLOSE, STDOUT
  179.  
  180. ;----------------------------
  181. ;    See if STDERR needs to be redirected.
  182.  
  183. EX2:    or    DupStdErr, 0        ; Is STDERR still redirected?
  184.     jz    EX3            ; No, continue
  185.  
  186.     mov    cx, DupStdErr        ; CX = new handle for STDERR
  187.     mov    bx, STDERR        ; BX = handle to change
  188.     mov    ah, 46h         ; Request force dup filehandle
  189.     int    21h            ; Call DOS
  190.  
  191. ;----------------------------
  192. ;    Terminate program with error
  193.  
  194. EX3:    mov    ax, 4cffh        ; Terminate with -1 as return code
  195.     int    21h            ; Call DOS
  196.  
  197. Exit    endp
  198.     end
  199.