home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / skeleton.zip / ErhTrap.cmd < prev    next >
OS/2 REXX Batch file  |  1995-08-03  |  5KB  |  126 lines

  1. /*****************************************************************************\
  2. | Error trap subprocessor for standard REXX Skeleton.                         |
  3. |                                                                             |
  4. | $Revision:   1.0  $
  5. |     $Date:   03 Aug 1995 20:10:12  $                                        |
  6. | Libraries:   REXXSAA, [REXXLIB]                                             |
  7. |  Category:   Error Handler                                                  |
  8. |     Class:   Programming                                                    |
  9. |      Type:   Trap                                                           |
  10. |    Author:   Bob Rice - CompuServe: 72421,3016                              |
  11. |                                                                             |
  12. | Copyright (c) 1995 Empirical Heuristics                                     |
  13. \**************************************************************************r4*/
  14. /*  !tr! = value('TRACE',,'OS2ENVIRONMENT'); parse source . . !who!          */
  15. /*  if !tr! \= '' then say '--> Entering' !who!; trace value !tr!; nop       */
  16.   if arg(1) = '' | left(arg(1),1) = '?' then do
  17.     parse source . . !pgm!; call TellHelp arg(1), !pgm!; exit 2; end
  18.  
  19.   if arg(1) = 'FINISH_UP' then signal Finish_up
  20.   parse arg ., ., ., pgmpath, line
  21.  
  22.   parse value filespec('N', pgmpath) with TRAP.fn '.' TRAP.fe
  23.   dump_file_name = filespec('D', pgmpath) || filespec('P', pgmpath) ||,
  24.                    TRAP.fn'.DMP'
  25.   /*----------------------------------------*\
  26.   | Check for reason not to create .DMP file |
  27.   \*----------------------------------------*/
  28.   if RxFuncQuery('VARDUMP')  \= 0 then dump_file_name = ''
  29.   if pos(':', dump_file_name) = 0 then dump_file_name = ''
  30.   /*----------------------*\
  31.   | Build trap message box |
  32.   \*----------------------*/
  33.   say ' '
  34.   TRAP.error_description = arg(2) 'error in line' arg(1)'.'
  35.   if arg(3) \= '' then do
  36.     TRAP.error_description = TRAP.error_description ' Error code =' arg(3)'.'
  37.     TRAP.error_message = errortext(arg(3))
  38.   end
  39.   else TRAP.error_message = ''
  40.   if dump_file_name \= '' then TRAP.file_message = 'See:' dump_file_name
  41.                           else TRAP.file_message = ''
  42.   TRAP.msg_width = max(length(TRAP.error_description),,
  43.                    length(TRAP.error_message),,
  44.                    length(TRAP.file_message) )
  45.   say   '╔' || copies('═', TRAP.msg_width + 2) ||          '╗'
  46.   say   '║' center(TRAP.fn'.CMD', TRAP.msg_width)          '║'
  47.   say   '║' copies(' ', TRAP.msg_width)                    '║'
  48.   say   '║' center(TRAP.error_description, TRAP.msg_width) '║'
  49.   if arg(3) \= '' then
  50.     say '║' center(TRAP.error_message, TRAP.msg_width)     '║'
  51.   if dump_file_name <> '' then do
  52.     say '║' copies(' ',   TRAP.msg_width)                  '║'
  53.     say '║' center('See:' dump_file_name, TRAP.msg_width)  '║'
  54.   end
  55.   say   '║' copies(' ', TRAP.msg_width)                    '║'
  56.   say   '╚' || copies('═', TRAP.msg_width + 2) ||          '╝'
  57.   say 'Source line at time of trap:'
  58.   say ' ' line; say
  59.   if arg(3) \= '' then
  60.     if AskUser('Ny', 'Would you like elaboration?') = 'Y' then
  61.       '@HELPMSG REX' || right('000'arg(3), 4)
  62.   return dump_file_name
  63.  
  64. Finish_up:
  65.   parse arg ., dump_file_name, pgmpath, errorline
  66.   /*-----------------------------------------*\
  67.   |  Offer to view the DMP file if it exists  |
  68.   \*-----------------------------------------*/
  69.   if dump_file_name \= '' then do
  70.     ans = AskUser('Svn', 'Sort and/or View .DMP file?')
  71.     if ans = 'S' then do                        /* Sort dump file            */
  72.       call fileread  dump_file_name, 'stem.',, 'E', 'CRANDLF'
  73.       call arraysort 'stem.'
  74.       call filewrite dump_file_name, 'stem.','R'
  75.       call QueDump dump_file_name, '/FLUSH /OVERWRITE'
  76.       call ErhView dump_file_name
  77.     end
  78.     if ans = 'V' then do
  79.       call QueDump dump_file_name, '/FLUSH /OVERWRITE'
  80.       call ErhView dump_file_name
  81.     end
  82.   end
  83.   /*----------------------------*\
  84.   |  Offer to edit the CMD file  |
  85.   \*----------------------------*/
  86.   ans = AskUser('Yn', 'Edit .CMD file?')
  87.   if ans = 'Y' then call ErhEdit pgmpath errorline
  88.   exit 254
  89. /*--Begin Help-----------------------------------------------------------------
  90. Error trap subprocessor for standard REXX Skeleton.
  91.  
  92. Params: SIGL, errortype, rc, pgm-path-and-name, source-line
  93.   or
  94. Params: 'FINISH_UP', dump-file-name, pgm-path-and-name
  95.  
  96. ________________
  97. Alternate Params: [ ? | ?? | ??? | ???? ]
  98.  
  99. where:
  100.  
  101.   ?     Displays up to the "Syntax:" or "Params:" portion of this help text.
  102.  
  103.   ??    Displays this entire help text except for the technical information.
  104.  
  105.   ???   Displays this entire help text.
  106.  
  107.   ????  Puts this help text into a file whose name is the same as the name of
  108.         this program and whose extent is .ABS.  The file is written to the same
  109.         directory as that in which this program resides.
  110.  
  111. _______________
  112. Technical Notes
  113.  
  114. This program is not intended to be a general utility.  It is designed to
  115. support the standard REXX Skeleton as part of its error and event trap
  116. processor.
  117.  
  118. ___________________
  119. Development History
  120.  
  121. $Log:   Q:/rxdv/skeleton/vcs/erhtrap.cm!  $
  122.   
  123.      Rev 1.0   03 Aug 1995 20:10:12
  124.   Initial revision.
  125. --End Help-------------------------------------------------------------------*/
  126.