home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / test164.zip / TEST164.CMD
OS/2 REXX Batch file  |  1995-08-04  |  19KB  |  490 lines

  1. /*------------------------------------------------------------------------*\
  2. |                                                                          |
  3. |           TEST164.CMD  - Version 1.2 - Version Date 1995-08-04           |
  4. |                 Copyright (C) 1995 by C F S Nevada, Inc.                 |
  5. |                                                                          |
  6. |                  by Dick Goran  - Voice    702-732-9616                  |
  7. |                                 - FAX      702-732-3847                  |
  8. |                                 - CIS      71154,2002                    |
  9. |                                 - Internet dgoran@cfsrexx.com            |
  10. |                                                                          |
  11. | ------------------------------------------------------------------------ |
  12. |  Optional: REXXLIB.DLL  - OS/2 REXX external function library            |
  13. |                           (c) Copyright 1992-95 Quercus Systems          |
  14. \*------------------------------------------------------------------------*/
  15. /*
  16.  
  17.    The purpose of this program is to try to confirm a possible problem
  18.    with either a Pentium CPU or its attached BIOS.
  19.  
  20.    It will read a copy of ?:\OS2\DLL\....DLL into storage for
  21.    control use and then will concurrently reread the DLL file
  22.    while, at the same time, copying the same DLL file to a
  23.    floppy diskette in Drive A: in another session.
  24.  
  25.    This program creates TEST164X.CMD (or whatever name this
  26.    program is filed as - providing the name is less than 8
  27.    characters). The ...X.CMD file is launched to copy the named
  28.    test file to drive A:. Both STDOUT and STDERR from the
  29.    ...X.CMD file are written to the ...X.LOG file in the same
  30.    directory where this program resides. The ...X.CMD file is
  31.    not erased when this program terminates but is replaced every
  32.    time this program is run.
  33.  
  34.    This programs requires REXXLIB.DLL for trap processing only and will
  35.    function without it.
  36.  
  37.    95/04/04 - Select largest DLL installed rather than TUTORMRI.DLL
  38.               in case tutorial was not installed.
  39.    95/08/03 - Prevent Synstax error if REXXLIB not present in LibPath.
  40.  
  41. */
  42.  
  43. GBL. = ''             /* initialize stem */
  44. parse Arg             GBL.command_line
  45. parse Version         GBL.REXX_version .
  46. parse Source          GBL.operating_system,
  47.                       GBL.calling_environment,
  48.                       GBL.program_path_and_name
  49. GBL.environment     = 'OS2ENVIRONMENT'
  50. GBL.boot_drive      = LEFT( VALUE( 'RUNWORKPLACE',, GBL.environment ), 2 )
  51. GBL.program_name    = FILESPEC( 'N', GBL.program_path_and_name )
  52. GBL.program_path    = FILESPEC( 'D', GBL.program_path_and_name ) ||,
  53.                       FILESPEC( 'P', GBL.program_path_and_name )
  54. parse upper var GBL.program_name,
  55.                       GBL.program_fn '.',
  56.                       GBL.program_fe
  57. GBL.program_version = 1.2           /* version / mod of this program */
  58. call TIME 'E'                       /* set elapsed timer - sssss.uuuuu */
  59.  
  60. say 'Begin' TRANSLATE( GBL.program_name ) 'at' TIME('N')
  61. call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  62. call SysLoadFuncs
  63.  
  64. SIGNAL ON SYNTAX name SYNTAX_01_TRAP
  65. if GBL.REXX_version = 'REXX/Personal' then
  66.    do
  67.       module = 'qrexxlib'
  68.    end
  69. else
  70.    do
  71.       module = 'rexxlib'
  72.    end
  73. call RxFuncAdd 'RexxLibRegister', module, 'rexxlibregister'
  74. call RexxLibRegister
  75. signal SYNTAX_01_OFF
  76.  
  77. SYNTAX_01_TRAP:
  78. call RxFuncDrop 'rexxlibregister'
  79.  
  80.  
  81. /*------------------------*\
  82. |  Enable trap processing  |
  83. \*------------------------*/
  84. SYNTAX_01_OFF:
  85.    SIGNAL ON ERROR
  86.    SIGNAL ON FAILURE
  87.    SIGNAL ON HALT
  88.    SIGNAL ON NOVALUE
  89.    SIGNAL ON SYNTAX
  90.  
  91. /*---------------------------------------*\
  92. |  Find largest DLL file available        |
  93. |  to use as input data for this program  |
  94. \*---------------------------------------*/
  95. call SysFileTree GBL.boot_drive || '\OS2\DLL\*.*', 'dll_stem', 'F'
  96. if dll_stem.0 = 0 then
  97.    do
  98.       say '   Unable to locate DLLs. Should not occur'
  99.       call EOJ
  100.    end
  101. test_file_size = 0
  102. do ds = 1 to dll_stem.0
  103.    parse value dll_stem.ds with,
  104.       dll_date,
  105.       dll_time,
  106.       dll_size,
  107.       dll_attr,
  108.       dll_path_and_name
  109.    dll_path_and_name = STRIP( dll_path_and_name )
  110.    if dll_size > test_file_size then
  111.       do
  112.          test_file_path_and_name = dll_path_and_name
  113.          test_file_size          = dll_size
  114.       end
  115. end
  116.  
  117.  
  118. if LENGTH( GBL.program_fn ) > 7 then
  119.    do
  120.       say '   This program''s name must not exceed 7 characters'
  121.       call EOJ
  122.    end
  123. subordinate_cmd_file =,
  124.    GBL.program_path ||,
  125.    GBL.program_fn   || 'X.CMD'
  126.  
  127. log_file =,
  128.    GBL.program_path ||,
  129.    GBL.program_fn   || 'X.LOG'
  130.  
  131. /*-----------------------------*\
  132. |  Read test file into storage  |
  133. \*-----------------------------*/
  134. test_file_area = CHARIN( test_file_path_and_name, 1, test_file_size )
  135. call STREAM test_file_path_and_name, 'C', 'CLOSE'
  136.  
  137. /*---------------------------------*\
  138. |  Create REXX data queue and make  |
  139. |  it active for this session       |
  140. \*---------------------------------*/
  141. proposed_queue_name = GBL.program_fn || 'Q'
  142. call RXQUEUE 'DELETE', proposed_queue_name
  143.  
  144. actual_queue_name = RXQUEUE( 'CREATE', proposed_queue_name )
  145. if actual_queue_name <> proposed_queue_name then
  146.    do
  147.       say '   "' || actual_queue_name           ||,
  148.           '" returned while trying to create "' ||,
  149.           proposed_queue_name                   ||,
  150.           '". Possible system error.'
  151.    end
  152. original_queue_name = RXQUEUE( 'SET', actual_queue_name )
  153.  
  154. /*------------------------------------------------*\
  155. |  Build TEST164X.CMD file to copy file to floppy  |
  156. \*------------------------------------------------*/
  157. destination_drive = 'A:\'
  158. c=0
  159. c=c+1; cmd.c = '@echo off'
  160. c=c+1; cmd.c = 'rem  This file was created by ' GBL.program_path_and_name
  161. c=c+1; cmd.c = 'echo ╔══════════════════════════════════════════════════════╗'
  162. c=c+1; cmd.c = 'echo ║ Copy file to floppy while it is being read elsewhere ║'
  163. c=c+1; cmd.c = 'echo ╚══════════════════════════════════════════════════════╝'
  164. c=c+1; cmd.c = 'echo Copying' test_file_path_and_name 'to' destination_drive
  165. c=c+1; cmd.c = 'copy' test_file_path_and_name destination_drive,
  166.                       '2>&1 >>' log_file
  167. c=c+1; cmd.c = 'rem  Clearing the named queue tells the calling program we''re done'
  168. c=c+1; cmd.c = 'rxqueue /clear' actual_queue_name
  169. c=c+1; cmd.c = 'exit'
  170.        cmd.0 = c
  171.  
  172. call SysFileDelete subordinate_cmd_file
  173. do c = 1 to cmd.0
  174.    call LINEOUT subordinate_cmd_file, cmd.c
  175. end
  176. call STREAM subordinate_cmd_file, 'C', 'CLOSE'
  177.  
  178.  
  179. /*------------------------------------------------------------------------*\
  180. |                                                                          |
  181. |    Mainline - Read file on hard drive while copying file to diskette     |
  182. |                                                                          |
  183. \*------------------------------------------------------------------------*/
  184. call SysFileDelete log_file
  185.  
  186. /*-----------------------------------*\
  187. |  Inform user how to cancel program  |
  188. \*-----------------------------------*/
  189. l=0
  190. l=l+1; line.l = ' '
  191. l=l+1; line.l = '╔════════════════════════════════════════════════════════════════╗'
  192. l=l+1; line.l = '║ This test may be ended at any time with <Ctrl-Break>; however, ║'
  193. l=l+1; line.l = '║ the disk copy will run to completion for the current copy.     ║'
  194. l=l+1; line.l = '╚════════════════════════════════════════════════════════════════╝'
  195. l=l+1; line.l = 'The test file being used is ' || test_file_path_and_name ||,
  196.                 ' (' || EDIT( test_file_size ) || ' bytes)'
  197. l=l+1; line.l = ' '
  198.        line.0 = l
  199. do l = 1 to line.0
  200.    say COPIES( ' ', 3 ) || line.l
  201. end
  202.  
  203. diskette_reference_count   = 0
  204. halt_request_switch        = 0
  205. hard_drive_reference_count = 0
  206. mismatch_count             = 0
  207. call ON HALT name HALT_REQUEST
  208.  
  209. do forever
  210.  
  211.    if halt_request_switch > 0 then leave
  212.  
  213.    /*-----------------------------------*\
  214.    |  See if diskete copy is in process  |
  215.    \*-----------------------------------*/
  216.    if QUEUED() = 0 then
  217.       do
  218.          /* stuff something into queue as sentinel */
  219.          queue DATE() TIME()
  220.          /* start COPY in separate session */
  221.          '@start' subordinate_cmd_file
  222.          diskette_reference_count = diskette_reference_count + 1
  223.          call SysSleep 1            /* give it a chance to start */
  224.       end
  225.  
  226.    /*------------------------------------------------------*\
  227.    |  Read hard copy file and compare with data being held  |
  228.    \*------------------------------------------------------*/
  229.    call STREAM test_file_path_and_name, 'C', 'OPEN READ'
  230.    new_file_area = CHARIN( test_file_path_and_name, 1, test_file_size )
  231.    call STREAM test_file_path_and_name, 'C', 'CLOSE'
  232.    scan_ptr = COMPARE( test_file_area, new_file_area )
  233.  
  234.    do while scan_ptr > 0
  235.       hex_displacement = RIGHT( D2X( scan_ptr - 1 ), 6, '0' )
  236.       say '   Compare mismatch occurred at byte ' ||,
  237.           EDIT( scan_ptr )                        ||,
  238.           " - (displ = '" || hex_displacement || "'x)"
  239.       scan_ptr = 0               /* just show 1 error for now */
  240.       mismatch_count = mismatch_count + 1
  241.    end
  242.  
  243.    hard_drive_reference_count = hard_drive_reference_count + 1
  244.  
  245. end
  246.  
  247. /*----------------------------*\
  248. |  Reset external data queues  |
  249. \*----------------------------*/
  250. if QUEUED() > 0 then
  251.    do
  252.       if halt_request_switch > 1 then leave /* bail out */
  253.       say '   Waiting for' subordinate_cmd_file 'to complete'
  254.       do while QUEUED() > 0
  255.          call SysSleep 1
  256.          if halt_request_switch > 1 then leave /* bail out */
  257.       end
  258.    end
  259.  
  260. call RXQUEUE 'DELETE', actual_queue_name
  261. call RXQUEUE 'SET',    original_queue_name
  262.  
  263. say ' '
  264. say '   Floppy copy started      '                ||,
  265.     RIGHT( EDIT( diskette_reference_count ), 10 ) ||,
  266.     ' times.'
  267. say '   Hard drive file compared '                  ||,
  268.     RIGHT( EDIT( hard_drive_reference_count ), 10 ) ||,
  269.     ' times.'
  270. say '   There were '       ||,
  271.     EDIT( mismatch_count ) ||,
  272.     ' errors comparing the hard disk data to the control copy.'
  273. say ' '
  274.  
  275. call EOJ 0
  276.  
  277.  
  278. /*--------------------------------------*\
  279. |  User pressed <Ctrl-Break to end test  |
  280. \*--------------------------------------*/
  281. HALT_REQUEST:
  282. halt_request_switch = halt_request_switch + 1
  283. if halt_request_switch = 1 then
  284.    do
  285.       say '   Halt request acknowledged, program will terminate after'
  286.       say '      ' || subordinate_cmd_file || ' completes'
  287.       say '   <Ctrl-Break> again will force program to halt'
  288.    end
  289. else
  290. return
  291.  
  292. /*------------------------------------------------------------------------*\
  293. |                                                                          |
  294. |             Copy of Dick Goran's public domain EDIT function             |
  295. |                                                                          |
  296. \*------------------------------------------------------------------------*/
  297. EDIT:
  298. /* first time here, build translate tables */
  299. signal OFF NOVALUE
  300. if LEFT(e1, 1) <> '01'x then
  301.    do
  302.       e1 = XRANGE('01'x, '19'x)
  303.       e2 = XRANGE('01'x, '03'x) || '19'x ||,
  304.            XRANGE('04'x, '06'x) || '19'x ||,
  305.            XRANGE('07'x, '09'x) || '19'x ||,
  306.            XRANGE('0A'x, '0C'x) || '19'x ||,
  307.            XRANGE('0D'x, '0F'x) || '19'x ||,
  308.            XRANGE('10'x, '12'x) || '19'x ||,
  309.            XRANGE('13'x, '15'x) || '19'x ||,
  310.            XRANGE('16'x, '18'x)
  311.       /* get punctuation characters from INI file  */
  312.       decimal  = STRIP( SysIni( 'USER',,
  313.                                 'PM_National',,
  314.                                 'sDecimal' ), 'T', '00'x )
  315.       thousand = STRIP( SysIni( 'USER',,
  316.                                 'PM_National',,
  317.                                 'sThousand' ), 'T', '00'x )
  318.    end
  319. signal ON NOVALUE
  320.  
  321. /* return BAD if non-numeric data */
  322. if DATATYPE( ARG(1) ) <> 'NUM' then
  323.    return 'BAD'
  324.  
  325. /* test and save sign value along with absolute numeric value */
  326. if SIGN( ARG(1) ) <> '-1' then
  327.    sign_character = ''
  328. else
  329.    sign_character = '-'
  330. absolute_value = ABS( ARG(1) )
  331.  
  332. /* test for and save decimal value indicator */
  333. decimal_position = POS( decimal, absolute_value )
  334.  
  335. if decimal_position = 0 then
  336.    source = RIGHT( absolute_value, LENGTH(e1) - 1 ) || ' '
  337. else
  338.    source = RIGHT( LEFT( absolute_value, decimal_position - 1 ), LENGTH(e1) - 1 ) || ' '
  339.  
  340. if decimal_position = 0 then
  341.    edited_number =,
  342.       STRIP( TRANSLATE( TRANSLATE( e2, source, e1), ',', ' '), 'B', ',')
  343. else
  344.    edited_number =,
  345.       STRIP( TRANSLATE( TRANSLATE( e2, source, e1), ',', ' '), 'B', ','),
  346.                       || RIGHT( absolute_value,,
  347.                                 LENGTH(absolute_value) - decimal_position + 1)
  348. return sign_character || edited_number
  349.  
  350.  
  351. !tr!=VALUE('TRACE',,'OS2Environment'); if !tr!<>'' then do;TRACE(!tr!);nop;end
  352. /*------------------------------------------------------------------------*\
  353. |                                                                          |
  354. |                                End of Job                                |
  355. |                                                                          |
  356. \*------------------------------------------------------------------------*/
  357. EOJ:
  358.    Procedure expose,
  359.       GBL.
  360.  
  361. if ARG() = 0 then
  362.    eoj_rc = 0
  363. else
  364.    eoj_rc = ARG(1)
  365.  
  366. elapsed_time = TIME('E')            /* get elapsed time - sssss.uuuuu */
  367. parse value elapsed_time with seconds '.' micro_seconds
  368. if LEFT( micro_seconds, 1, 1 ) >= 5 then
  369.    seconds = seconds + 1
  370. ss = FORMAT( seconds // 60, 2 )
  371. minutes = ( seconds - ss ) / 60
  372. mm = FORMAT( minutes // 60, 2 )
  373. hh = FORMAT( ( minutes - mm ) / 60, 2 )
  374. duration = hh':'mm':'ss
  375.  
  376. program_name = TRANSLATE( FILESPEC( 'N', GBL.program_path_and_name ) )
  377. say 'EOJ  ' program_name 'at' TIME('N') ||,
  378.     ', duration' TRANSLATE( duration, '0', ' ' )
  379. exit eoj_rc
  380.  
  381. /*------------------------------------------------------------------------*\
  382. |                                                                          |
  383. |                              Trap Routines                               |
  384. |                                                                          |
  385. \*------------------------------------------------------------------------*/
  386. ERROR:   call TRAP_PROCESSING SIGL, 'ERROR',   RC
  387. FAILURE: call TRAP_PROCESSING SIGL, 'FAILURE', RC
  388. HALT:    call TRAP_PROCESSING SIGL, 'HALT',    ''
  389. NOVALUE: call TRAP_PROCESSING SIGL, 'NOVALUE', ''
  390. SYNTAX:  call TRAP_PROCESSING SIGL, 'SYNTAX',  RC
  391.  
  392. /* Rev. 95/07/29 */
  393. TRAP_PROCESSING:
  394.    parse Source . . TRAP.path_and_program
  395.    trap.line_nbr = ARG(1)
  396.    if POS( ':', TRAP.path_and_program ) > 0 then
  397.       /* get source line if it is available */
  398.       do t = 1
  399.          trap_source_line.t =  SOURCELINE( trap.line_nbr )
  400.          trap_source_line.0 = t
  401.          trap.line_nbr      = trap.line_nbr + 1
  402.          if RIGHT( trap_source_line.t, 1 ) ¬= ',' then
  403.             do
  404.                leave
  405.             end
  406.       end
  407.    else
  408.       /* program is running in macrospace */
  409.       do
  410.          TRAP.path_and_program = VALUE( 'TEMP',, 'OS2ENVIRONMENT' ) ||,
  411.                                  '\' || TRAP.path_and_program
  412.          trap_source_line.1 = 'Source line is not available.'
  413.          trap_source_line.0 = 1
  414.       end
  415.  
  416.    parse value FILESPEC( 'N', TRAP.path_and_program ) with,
  417.       TRAP.fn '.' TRAP.fe
  418.    trap_file_name = FILESPEC( 'D', TRAP.path_and_program ) ||,
  419.                     FILESPEC( 'P', TRAP.path_and_program ) ||,
  420.                     TRAP.fn || '.' || 'DMP'
  421.  
  422.    /*------------------------------------------*\
  423.    |  check for reason not to create .DMP file  |
  424.    \*------------------------------------------*/
  425.    if ARG(2) = 'HALT' then
  426.       do
  427.          trap_file_name = ''
  428.       end
  429.    if RxFuncQuery( 'VARDUMP' ) <> 0 then
  430.       do
  431.          trap_file_name = ''
  432.       end
  433.    if POS( ':', trap_file_name ) = 0 then
  434.       do
  435.          trap_file_name = ''
  436.       end
  437.  
  438.    /*------------------------*\
  439.    |  Build trap message box  |
  440.    \*------------------------*/
  441.    dbl.h    = 'CD'x                 /* ═ double line - horizontal   */
  442.    dbl.v    = 'BA'x                 /* ║ double line - vertical     */
  443.    dbl.bl   = 'C8'x                 /* ╚ double line - bottom left  */
  444.    dbl.br   = 'BC'x                 /* ╝ double line - bottom right */
  445.    dbl.tl   = 'C9'x                 /* ╔ double line - top left     */
  446.    dbl.tr   = 'BB'x                 /* ╗ double line - top right    */
  447.    trap.red = '1B'x || '[1;37;41m'  /* bright white on red          */
  448.    trap.dul = '1B'x || '[0m'        /* reset to normal              */
  449.  
  450.    say ' '
  451.    trap_error_description =,
  452.       'Error line = ' || ARG(1) ||,
  453.       '; ' ||,
  454.       ARG(2) ||,
  455.       ' error.'
  456.    if ARG(3) <> '' then
  457.       trap_error_description = trap_error_description ||,
  458.                                '  Return code = ' || ARG(3)
  459.    trap.width = MAX( 74, LENGTH( trap_error_description ) )
  460.    say trap.red || dbl.tl || COPIES( dbl.h,trap.width + 2 ) || dbl.tr || trap.dul
  461.    say trap.red || dbl.v  || COPIES( ' ',  trap.width + 2 ) || dbl.v  || trap.dul
  462.    say trap.red || dbl.v CENTER( TRAP.fn'.CMD',trap.width )    dbl.v  || trap.dul
  463.    say trap.red || dbl.v CENTER( trap_error_description, trap.width ) dbl.v || trap.dul
  464.    if trap_file_name <> '' then
  465.       do
  466.    say trap.red || dbl.v  || COPIES( ' ',  trap.width + 2 ) || dbl.v  || trap.dul
  467.    say trap.red || dbl.v     CENTER( 'See: ' || trap_file_name,,
  468.                                      trap.width )  dbl.v  || trap.dul
  469.       end
  470.    say trap.red || dbl.v  || COPIES( ' ',  trap.width + 2 ) || dbl.v  || trap.dul
  471.    say trap.red || dbl.bl || COPIES( dbl.h,trap.width + 2 ) || dbl.br || trap.dul
  472.    say trap.red || COPIES( ' ', trap.width + 4 ) || trap.dul
  473.    say trap.red || LEFT( 'Source line(s) at time of trap:', trap.width + 4 ) || trap.dul
  474.    do t = 1 to trap_source_line.0
  475.       say trap.red || LEFT( '   ' || trap_source_line.t, trap.width + 4 ) || trap.dul
  476.    end
  477.    say trap.red || COPIES( ' ', trap.width + 4 ) || trap.dul
  478.  
  479.    /*---------------------------------*\
  480.    |  Create .DMP file if appropriate  |
  481.    \*---------------------------------*/
  482.    if trap_file_name <> '' then
  483.       do
  484.          call SysFileDelete trap_file_name
  485.          /* remove meaningless labels from dump for clarity */
  486.          drop dbl. TRAP. RC RESULT SIGL !tr!
  487.          call VARDUMP trap_file_name  /* write variables to program.DMP file */
  488.       end
  489.    exit 253
  490.