home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / mkwin929.zip / MKWINOS2.CMD < prev    next >
OS/2 REXX Batch file  |  1995-09-19  |  14KB  |  374 lines

  1. /*------------------------------------------------------------------------*\
  2. |                                                                          |
  3. |           MKWINOS2.CMD - Version 1.0 - Version Date 1995-09-29           |
  4. |                 Copyright (c) 1995 by C F S Nevada, Inc.                 |
  5. |                                                                          |
  6. |                 Dick Goran      - Voice      702-732-9616                |
  7. |                                 - FAX        702-732-3847                |
  8. |                                 - CompuServe 71154,2002                  |
  9. |                                 - Internet   dgoran@cfsrexx.com          |
  10. |                                                                          |
  11. |          Produced and distributed by Productivity Solutions, Inc.        |
  12. |                 David Moskowitz - Voice      610-631-5685                |
  13. |                                 - FAX        610-631-0414                |
  14. |                                 - CompuServe 76701,100                   |
  15. |                                 - Internet   davidm@cfsrexx.com          |
  16. |                                                                          |
  17. | ------------------------------------------------------------------------ |
  18. |  Requires: REXXLIB.DLL  - OS/2 REXX external function library            |
  19. |                           (c) Copyright 1992-95 Quercus Systems          |
  20. \*------------------------------------------------------------------------*/
  21. /*
  22.  
  23. #1 Command Line
  24.  
  25.    MKWINOS2 [ path to windows directory ] [ /d ]
  26.  
  27.    An optional path to the Windows directory which is to serve as the
  28.    source for the information used to create the Windows Desktop equivalent.
  29.    The default is the value specified when OS/2 was installed (which is the
  30.    path pointed to by the WINOS2_LOCATION in the PM_INSTALL application name
  31.    in the OS2.INI file).
  32.  
  33.    The /d (debug) parameter is intended primarily for support use.
  34.  
  35. #2 WARNING!
  36.  
  37.    The order and position of the lines of code within this program are
  38.    critical. Altering them may result in incorrect output by the code
  39.    generation phase of MKWINOS2.
  40.  
  41. */
  42.  
  43.    SIGNAL ON ERROR                  /* trap object time errors     */
  44.    SIGNAL ON FAILURE                /* trap object time errors     */
  45.    SIGNAL ON HALT                   /* trap object time errors     */
  46.    SIGNAL ON NOVALUE                /* trap object time errors     */
  47.    SIGNAL ON SYNTAX                 /* trap object time errors     */
  48.  
  49. GBL. = ''             /* initialize stem */
  50. parse Arg             GBL.command_line
  51. parse Version         GBL.REXX_version .
  52. parse Source          GBL.operating_system,
  53.                       GBL.calling_environment,
  54.                       GBL.program_path_and_name
  55. GBL.package_name    = 'MKWINOS2'
  56. GBL.environment     = 'OS2ENVIRONMENT'
  57. GBL.boot_drive      = LEFT( VALUE( 'RUNWORKPLACE',, GBL.environment ), 2 )
  58. GBL.program_version = 1.0           /* version / mod of this program */
  59. GBL.program_name    = FILESPEC( 'N', GBL.program_path_and_name )
  60. GBL.program_path    = FILESPEC( 'D', GBL.program_path_and_name ) ||,
  61.                       FILESPEC( 'P', GBL.program_path_and_name )
  62.  
  63. parse var GBL.program_name,
  64.    GBL.program_fn '.',
  65.    GBL.program_fe
  66.  
  67. /*-----------------------------------------------*\
  68. |  Assure that REXXUTIL & REXXLIB are registered  |
  69. \*-----------------------------------------------*/
  70. call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  71. call SysLoadFuncs
  72.  
  73. if RxFuncQuery( 'RexxLibDeregister' ) = 0 then
  74.    do
  75.       call RexxLibDeregister
  76.    end
  77. if GBL.REXX_version = 'REXX/Personal' then
  78.    do
  79.       dll_name = 'QREXXLIB'
  80.    end
  81. else
  82.    do
  83.       dll_name = 'REXXLIB'
  84.    end
  85. call RxFuncAdd 'RexxLibRegister', dll_name, 'rexxlibregister'
  86. call RexxLibRegister
  87.  
  88. call TIME 'E'                       /* set elapsed timer - sssss.uuuuu */
  89. call SysCls
  90. say 'Begin' TRANSLATE( GBL.program_name ) 'at' TIME('N')
  91.  
  92. GBL.width         = 76              /* report file max width */
  93. GBL.white_on_blue = '1B'x || '[1;37;44m'
  94. GBL.ansi_off      = '1B'x || '[0m'
  95.  
  96. call CHAROUT 'CON:',,
  97.    '1B'x || '[s'      ||,
  98.    COPIES( ' ', 2 )   ||,
  99.    GBL.white_on_blue  ||,
  100.    CENTER( 'This program may take a couple of minutes to run', GBL.width - 2 ) ||,
  101.    GBL.ansi_off       ||,
  102.    '1B'x || '[u'      ||,
  103.    ''
  104. call STREAM 'CON:', 'C', 'CLOSE'
  105.  
  106. /*-------------------*\
  107. |  Start report file  |
  108. \*-------------------*/
  109. GBL.report_file =,
  110.    GBL.program_path ||,
  111.    GBL.package_name || '.RPT'
  112. call SysFileDelete GBL.report_file
  113. heading_1 =,
  114.    'MKWINOS2 Report created on' DATE() 'at' TIME()
  115. call LINEOUT GBL.report_file,,
  116.    CENTER( heading_1, GBL.width )
  117. call LINEOUT GBL.report_file,,
  118.    CENTER( COPIES( '-', LENGTH(heading_1) ), GBL.width )
  119.  
  120. /*-----------------*\
  121. |  Start copy file  |
  122. \*-----------------*/
  123. GBL.copy_file =,
  124.    GBL.program_path ||,
  125.    'MKWINRUN.CPY'
  126. call SysFileDelete GBL.copy_file
  127.  
  128. uppercase_command_line = STRIP( SPACE( TRANSLATE( GBL.command_line ) ) )
  129.  
  130. if POS( '?', uppercase_command_line ) > 0 then
  131.    do forever
  132.       input_line = LINEIN( GBL.program_path_and_name )
  133.       if LEFT( input_line, 1 ) = '#' then
  134.          if GBL.copy_switch = 1 then
  135.             do
  136.                call STREAM GBL.program_path_and_name, 'C', 'CLOSE'
  137.                call EOJ 000
  138.             end
  139.       if LEFT( input_line, 2 ) = '#1' then
  140.          do
  141.             GBL.copy_switch = 1
  142.             iterate
  143.          end
  144.       if GBL.copy_switch = 1 then
  145.          do
  146.             say GBL.white_on_blue             ||,
  147.                 LEFT( input_line, GBL.width ) ||,
  148.                 GBL.ansi_off
  149.          end
  150.    end
  151.  
  152. debug_word_number =,
  153.    BITOR( WORDPOS( '/D', uppercase_command_line ),,
  154.           WORDPOS( '-D', uppercase_command_line ) )
  155. if debug_word_number > 0 then
  156.    do
  157.       GBL.debug_file =,
  158.          GBL.program_path ||,
  159.          GBL.package_name || '.LOG'
  160.       call SysFileDelete GBL.debug_file
  161.       uppercase_command_line =,
  162.          SPACE( OVERLAY( '  ',,
  163.                          uppercase_command_line,,
  164.                          WORDINDEX(uppercase_command_line,,
  165.                                    debug_word_number ) ) )
  166.    end
  167.  
  168. /*-----------------------------------*\
  169. |  For the time being, the debug log  |
  170. |          will be forced             |
  171. \*-----------------------------------*/
  172. GBL.debug_file =,
  173.    GBL.program_path ||,
  174.    GBL.package_name || '.LOG'
  175. call SysFileDelete GBL.debug_file
  176.  
  177. /*------------------------------------*\
  178. |  Set required environment variables  |
  179. \*------------------------------------*/
  180. '@echo off'                         /* eliminate junk on 4OS2 - 95/07/28 */
  181. call SETLOCAL                       /* let system save environment */
  182.  
  183. /* set TEMP to MKWINOS2 path */
  184. call VALUE 'TEMP',,
  185.            STRIP( GBL.program_path, 'T', '\' ),,
  186.            GBL.environment
  187.  
  188. /* MKWINOS2 variables */
  189. v=0
  190. v=v+1; var.v = 'COPY'    GBL.copy_file
  191. v=v+1; var.v = 'DEBUG'   GBL.debug_file
  192. v=v+1; var.v = 'PATH'    GBL.program_path
  193. v=v+1; var.v = 'REPORT'  GBL.report_file
  194.        var.0 = v
  195. do v = 1 to var.0
  196.    call VALUE GBL.package_name || '_' || WORD( var.v, 1 ),,
  197.               WORD( var.v, 2 ),,
  198.               GBL.environment
  199. end
  200.  
  201. /*-----------------*\
  202. |  Load macrospace  |
  203. \*-----------------*/
  204. do m = 1 to 10
  205.    call MACRODROP 'MKWIN' || RIGHT( m, 3, '0' )
  206. end
  207.  
  208. program_file_extension = 'SAA'
  209. if GBL.REXX_Version = 'REXX/Personal' then
  210.    do
  211.       program_file_extension = 'PER'
  212.    end
  213. macro_file =,
  214.    STREAM( GBL.program_path || 'MKWINOS2.' || program_file_extension,,
  215.            'C', 'QUERY EXISTS' )
  216.  
  217. if macro_file ¬= '' then
  218.    do
  219.       call MACROLOAD macro_file
  220.    end
  221. call mkwin001 uppercase_command_line
  222.  
  223. /*-------------------*\
  224. |  Unload macrospace  |
  225. \*-------------------*/
  226. do m = 1 to 10
  227.    call MACRODROP 'MKWIN' || RIGHT( m, 3, '0' )
  228. end
  229.  
  230. call STREAM GBL.report_file, 'C', 'CLOSE'
  231. call ENDLOCAL                       /* let system restore environment */
  232. call EOJ 0
  233.  
  234.  
  235. /* EOJ marker */
  236. /*------------------------------------------------------------------------*\
  237. |                                                                          |
  238. |                                End of Job                                |
  239. |                                                                          |
  240. \*------------------------------------------------------------------------*/
  241. EOJ:
  242.    Procedure expose,
  243.       GBL.
  244.  
  245. if ARG() = 0 then
  246.    eoj_rc = 0
  247. else
  248.    eoj_rc = ARG(1)
  249.  
  250. elapsed_time = TIME('E')            /* get elapsed time - sssss.uuuuu */
  251. parse value elapsed_time with seconds '.' micro_seconds
  252. if LEFT( micro_seconds, 1, 1 ) >= 5 then
  253.    seconds = seconds + 1
  254. ss = FORMAT( seconds // 60, 2 )
  255. minutes = ( seconds - ss ) / 60
  256. mm = FORMAT( minutes // 60, 2 )
  257. hh = FORMAT( ( minutes - mm ) / 60, 2 )
  258. duration = hh':'mm':'ss
  259.  
  260. program_name = TRANSLATE( FILESPEC( 'N', GBL.program_path_and_name ) )
  261. say 'End  ' program_name 'at' TIME('N') ||,
  262.     ', duration' TRANSLATE( duration, '0', ' ' )
  263. exit eoj_rc
  264.  
  265. /*------------------------------------------------------------------------*\
  266. |                                                                          |
  267. |                              Trap Routines                               |
  268. |                                                                          |
  269. \*------------------------------------------------------------------------*/
  270. ERROR:   call TRAP_PROCESSING SIGL, 'ERROR',   RC
  271. FAILURE: call TRAP_PROCESSING SIGL, 'FAILURE', RC
  272. HALT:    call TRAP_PROCESSING SIGL, 'HALT',    ''
  273. NOVALUE: call TRAP_PROCESSING SIGL, 'NOVALUE', ''
  274. SYNTAX:  call TRAP_PROCESSING SIGL, 'SYNTAX',  RC
  275.  
  276. /* Rev. 95/07/29 */
  277. TRAP_PROCESSING:
  278.    parse Source . . TRAP.path_and_program
  279.    trap.line_nbr = ARG(1)
  280.    if POS( ':', TRAP.path_and_program ) > 0 then
  281.       /* get source line if it is available */
  282.       do t = 1
  283.          trap_source_line.t =  SOURCELINE( trap.line_nbr )
  284.          trap_source_line.0 = t
  285.          trap.line_nbr      = trap.line_nbr + 1
  286.          if RIGHT( trap_source_line.t, 1 ) ¬= ',' then
  287.             do
  288.                leave
  289.             end
  290.       end
  291.    else
  292.       /* program is running in macrospace */
  293.       do
  294.          TRAP.path_and_program = VALUE( 'TEMP',, 'OS2ENVIRONMENT' ) ||,
  295.                                  '\' || TRAP.path_and_program
  296.          trap_source_line.1 = 'Source line is not available.'
  297.          trap_source_line.0 = 1
  298.       end
  299.  
  300.    parse value FILESPEC( 'N', TRAP.path_and_program ) with,
  301.       TRAP.fn '.' TRAP.fe
  302.    trap_file_name = FILESPEC( 'D', TRAP.path_and_program ) ||,
  303.                     FILESPEC( 'P', TRAP.path_and_program ) ||,
  304.                     TRAP.fn || '.' || 'DMP'
  305.  
  306.    /*------------------------------------------*\
  307.    |  check for reason not to create .DMP file  |
  308.    \*------------------------------------------*/
  309.    if ARG(2) = '----' then
  310.       do
  311.          trap_file_name = ''
  312.       end
  313.    if RxFuncQuery( 'VARDUMP' ) <> 0 then
  314.       do
  315.          trap_file_name = ''
  316.       end
  317.    if POS( ':', trap_file_name ) = 0 then
  318.       do
  319.          trap_file_name = ''
  320.       end
  321.  
  322.    /*------------------------*\
  323.    |  Build trap message box  |
  324.    \*------------------------*/
  325.    dbl.h    = 'CD'x                 /* ═ double line - horizontal   */
  326.    dbl.v    = 'BA'x                 /* ║ double line - vertical     */
  327.    dbl.bl   = 'C8'x                 /* ╚ double line - bottom left  */
  328.    dbl.br   = 'BC'x                 /* ╝ double line - bottom right */
  329.    dbl.tl   = 'C9'x                 /* ╔ double line - top left     */
  330.    dbl.tr   = 'BB'x                 /* ╗ double line - top right    */
  331.    trap.red = '1B'x || '[1;37;41m'  /* bright white on red          */
  332.    trap.dul = '1B'x || '[0m'        /* reset to normal              */
  333.  
  334.    say ' '
  335.    trap_error_description =,
  336.       'Error line = ' || ARG(1) ||,
  337.       '; ' ||,
  338.       ARG(2) ||,
  339.       ' error.'
  340.    if ARG(3) <> '' then
  341.       trap_error_description = trap_error_description ||,
  342.                                '  Return code = ' || ARG(3)
  343.    trap.width = MAX( 74, LENGTH( trap_error_description ) )
  344.    say trap.red || dbl.tl || COPIES( dbl.h,trap.width + 2 ) || dbl.tr || trap.dul
  345.    say trap.red || dbl.v  || COPIES( ' ',  trap.width + 2 ) || dbl.v  || trap.dul
  346.    say trap.red || dbl.v CENTER( TRAP.fn'.CMD',trap.width )    dbl.v  || trap.dul
  347.    say trap.red || dbl.v CENTER( trap_error_description, trap.width ) dbl.v || trap.dul
  348.    if trap_file_name <> '' then
  349.       do
  350.    say trap.red || dbl.v  || COPIES( ' ',  trap.width + 2 ) || dbl.v  || trap.dul
  351.    say trap.red || dbl.v     CENTER( 'See: ' || trap_file_name,,
  352.                                      trap.width )  dbl.v  || trap.dul
  353.       end
  354.    say trap.red || dbl.v  || COPIES( ' ',  trap.width + 2 ) || dbl.v  || trap.dul
  355.    say trap.red || dbl.bl || COPIES( dbl.h,trap.width + 2 ) || dbl.br || trap.dul
  356.    say trap.red || COPIES( ' ', trap.width + 4 ) || trap.dul
  357.    say trap.red || LEFT( 'Source line(s) at time of trap:', trap.width + 4 ) || trap.dul
  358.    do t = 1 to trap_source_line.0
  359.       say trap.red || LEFT( '   ' || trap_source_line.t, trap.width + 4 ) || trap.dul
  360.    end
  361.    say trap.red || COPIES( ' ', trap.width + 4 ) || trap.dul
  362.  
  363.    /*---------------------------------*\
  364.    |  Create .DMP file if appropriate  |
  365.    \*---------------------------------*/
  366.    if trap_file_name <> '' then
  367.       do
  368.          call SysFileDelete trap_file_name
  369.          /* remove meaningless labels from dump for clarity */
  370.          drop dbl. TRAP. RC RESULT SIGL !tr!
  371.          call VARDUMP trap_file_name  /* write variables to program.DMP file */
  372.       end
  373.    exit 253
  374.