home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / vrac / 4derr220.zip / ON!ERROR.BTM < prev    next >
Text File  |  1994-10-15  |  5KB  |  134 lines

  1. @echo off
  2. rem  ON!ERROR.BTM -- 4Dos Error Handler Batch File for Unknown Commands.
  3. rem    Version 2.2, for 4DOS, version 5.0 or later.
  4. rem    Uses X.COM - K. Ledbetter's Command Archive eXecutive (Optional)
  5. rem    Created on 04/23/94 by STV    Last Revised on 10/15/94 by STV
  6. rem    ("::" - Indicates a Non-executing Code Line!)
  7.  
  8. rem {* Check The Version Of 4Dos Being Used *}
  9. if not %_4ver GE 5.0 (
  10.   *beep %+*echos    ERROR! --
  11.   *echo  Incorrect 4Dos version.
  12.   *echo    (The On!Error.Btm needs version 5 or later to run.)
  13.   cancel
  14. )
  15. rem {* Check For Enough Free Space In The Environment To Run *}
  16. rem - On re-entry to this BTM script, clean up the environment first.
  17. if not "%Unknown_CmdLine%"=="" gosub CleanEnv
  18. if %_Env LT 128 (
  19.   *beep %+*echos    ERROR! --
  20.   *echo  4Dos environment space too small.
  21.   *echo    (The On!Error.Btm needs at least 128 bytes free to run.)
  22.   cancel
  23. )
  24. rem {* Give A Warning If This BTM Script Is Executed By User *}
  25. if %#==0 .or. "%1"=="/?" .or. "%@upper[%1]"=="/H" goto Warning
  26. rem {* Provide A Graceful Exit On A User Abort From This BTM Script *}
  27. rem - On a Ctrl-C (Ctrl-Break) execute the following before quitting.
  28. ON BREAK (
  29.   *beep 440 4 262 2
  30.   *scrput -2 1 bri magenta on %BgClr% [ User Abort! ]
  31.   goto Done
  32. )
  33. rem {* First Get The Unknown Command Line And Save It For Processing *}
  34. *set Unknown_CmdLine=%&
  35. rem {* Check To See If The X.COM Program Is Present In The System *}
  36. rem - Search for the X.COM program along the defined search path to see if
  37. rem - it exists. If it does, then set the X-Path variable to point to it.
  38. *set X_Path=%@path[%@search[X.COM]]
  39. rem {* Get The Current Display's Background Screen Color *}
  40. *set BgClr=%_BG
  41. rem {* Check For Execptions Before Processing *}
  42. *set CmdError=Command Being Used Is Unknown!
  43. gosub Execptions
  44. rem - If the command library eXcutive (X.COM) doesn't exist in the system
  45. rem - then bypass the code to have it process the unknown command line.
  46. if "%X_Path%"=="" goto EditCmdLine
  47. rem - When wildcard characters are in the Command, don't run the X.COM program.
  48. if %@index[%CmdError%,Wildcard] GT -1 goto EditCmdLine
  49. rem - Have the command library eXcutive (X.COM) try to process the command
  50. rem - first. Alert the user by sound that the X.COM program is running.
  51. *beep 880 2
  52. @%X_Path%X %Unknown_CmdLine%
  53.   if errorlevel 1 goto UnknownError
  54.   if errorLevel 0 goto Done
  55. rem - If the command library eXcutive could not process it, then
  56. rem - show the Unknown Command to the user so it can be edited.
  57. :UnknownError
  58. *set CmdError=Unknown Command eXecutive Error!
  59. *echo.
  60. :EditCmdLine
  61. rem {* Inform The User That This Script Is Running *}
  62. *color bri blue on %BgClr% %+*beep %+*echo.
  63. *echos    `>> 4DOS Error Handler Invoked:`
  64. *color red on %BgClr%
  65. *echo  %CmdError%
  66. *unset /q CmdError
  67. rem {* Now Give An Instructional Message *}
  68. *color bri yellow on %BgClr% %+*echo.
  69. *echo    Please correct the following Command Line for execution, or
  70. *echo    press [Esc] to delete it, and [Enter] to cancel execution:
  71. rem - Now show the user the bad command line.
  72. *color blink red on %BgClr% %+*echo.
  73. *echo  [ ERROR! ]
  74. *color cyan on %BgClr%
  75. *echos %@upper[%_Cwd]
  76. *color bri green on %BgClr%
  77. *echos ` >>`
  78. *color bri white on %BgClr%
  79. *input /e %%Unknown_CmdLine
  80. *scrput -2 1 red on %BgClr% [ ERROR! ]
  81. *color white on %BgClr%
  82. rem {* Now Process The Corrected Command Line *}
  83. rem - Place the corrected command in the history buffer.
  84. *history /a %Unknown_CmdLine%
  85. rem - Use a call, so we can properly handle batch files.
  86. call %Unknown_CmdLine%
  87. rem {* We're Done, So Clean Things Up Before Quiting *}
  88. :Done
  89. if not "%Unknown_CmdLine%"=="" gosub CleanUp
  90. quit
  91.  
  92. rem {* Subroutines *}
  93. rem - This subroutine cleans up the 4Dos system before exiting this script.
  94. :CleanUp
  95. rem - Reset the screen colors.
  96. *color white on %BgClr%
  97. rem - Remove any environment variables created by this script.
  98. :CleanEnv
  99. *unset /q BgClr
  100. *unset /q CmdError
  101. *unset /q Unknown_CmdLine
  102. *unset /q CmdVerb
  103. *unset /q X_Path
  104. return
  105.  
  106. rem - This subroutine examines the command verb of the Unknown Command
  107. rem - and then acts on certain execptions. Additional exceptions can be
  108. rem - added as the need arises.
  109. :Execptions
  110. rem - Get the Unknown command verb.
  111. *set CmdVerb=%@lower[%1]
  112. rem [ If the verb is 'Quit' or 'Cancel', then either quit or abort this script. ]
  113. if %@index[%CmdVerb%,quit] GT -1 goto Done
  114. if %@index[%CmdVerb%,cancel] GT -1 goto EndError
  115. rem [ If the verb is 'Else', 'Else(iff)', or 'Endiff', then abort this script. ]
  116. if %@index[%CmdVerb%,else] GT -1 .or. %@index[%CmdVerb%,end] GT -1 goto EndError
  117. rem [ If the verb contains a '*' or a '?' then gave an error msg about it. ]
  118. if %@index[%1,*] GT -1 .or. %@index[%1,?] GT -1 *set CmdError=Command Contains a Wildcard Character!
  119. rem - We're done here, so return for further processing.
  120. *unset /q CmdVerb
  121. return
  122. rem - We're ending on an error, so clean things up, and cancel all processing.
  123. :EndError
  124. gosub CleanUp
  125. cancel
  126.  
  127. rem {* Display A Warning Message To The User *}
  128. :Warning
  129. *echo ON!ERROR.BTM, vers. 2.2 (10/15/94)
  130. *echo On!Error -- Error handler for unknown commands in 4DOS.
  131. *beep %+echo. %+*color red on %_Bg
  132. *echo    Warning: "%@upper[%0]" is NOT an executable batch file!
  133. *color white on %_Bg
  134.