home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / tapeutils.zip / tuiros.rex < prev    next >
OS/2 REXX Batch file  |  1991-01-10  |  8KB  |  254 lines

  1. /*
  2. This REXX exec replaces the function of OSTAPE ASSEMBLE for loading
  3. the Kermit distribution tape onto a IBM VM system.
  4.  
  5. Calling format is
  6.  
  7.    OSTAPE <file_name_prefix> <residence_disk>
  8.  
  9. All files on the tape that begin with the file_name_prefix will
  10. be loaded to the filemode pointed to by the residence_disk.
  11.  
  12. The default for the file_name_prefix is AA, so you will get all the
  13. general help files on the tape.
  14.  
  15. The default for the residence_disk is whatever file_mode this exec
  16. was executed from.  I reccomend that you put it on a disk -other-
  17. than your a-disk, so that your private files do not get mixed in with
  18. the KERMIT distribution.
  19.  
  20. You will get some messages that look like errors,
  21. but they're usually not.  I elected not to supress them, so that you
  22. wouldn't be left in "limbo" if something happened to go wrong.
  23.  
  24. Here is a console log of a sample run:
  25. ostape xx f
  26.  OSTAPE 2: will load all KERMIT files beginning with XX to disk F
  27.  DMSERS002E File OSTAPE $$TEMP$$ A1 not found
  28.  OSTAPE 2: bypassed OSTAPE.ASSEMBLE
  29.  OSTAPE 2: bypassed AAAREAD.ME
  30.  OSTAPE 2: bypassed AAAUPD.HLP
  31.            .
  32.            .
  33.            .
  34.  OSTAPE 2: bypassed XKAAAA.HLP
  35.  OSTAPE 2: bypassed XKM936.HLP
  36.  OSTAPE 2: bypassed XKMAAA.HLP
  37.  OSTAPE 2: loading XXU.C             as XXU C
  38.  DMSCPY721I Copy OSTAPE $$TEMP$$ A1 to XXU C F1 (old file)
  39.  DMSSTT002E File OSTAPE $$TEMP$$ not found
  40.  OSTAPE 2: loaded 1 files
  41.  OSTAPE 2: tape was left at physical file 1555
  42.  Ready; T=27.16/36.90 15:44:09
  43.  
  44.  
  45. Another Typical Example:  You just got in a new KERMIT tape, you
  46. want to load its documentation to your D-disk, and you want to load
  47. the latest TSO KERMIT to your E-disk.
  48.  
  49. You would enter the following commands:
  50.  
  51.    OSTAPE AA  D
  52.  
  53.    OSTAPE IKT E
  54.  
  55. ----------------------------------------------------------------------
  56.  
  57. While this REXX implementation has the disadvantage of requiring VM/CMS
  58. release 4 or above, it has the distinct advantages of maintainability,
  59. readability and portability to other REXX systems with minor changes.
  60. The only system dependencies here are in the PARSE SOURCE, FILEDEF and
  61. MOVEFILE statements.
  62.  
  63. Especially good things:
  64. 1) This exec takes pains to use only characters that will translate
  65.    cleanly from EBCDIC to ASCII to EBCDIC, so that the many
  66.    translations that the KERMIT distribution goes through will not
  67.    cause any failures.
  68.    This means that some of the code is less elegant than the ideal,
  69.    because REXX's "OR" operator (the vertical bar) fails this test.
  70.    So, I have to write certain compound conditions as multiple IF's.
  71.    Another character that I can't use is the standard IBM "NOT"
  72.    operator.  REXX conveniently supports "slash =" (/=), meaning
  73.    "NOT EQUAL" as a rough equivalent.
  74.  
  75. Implementation restrictions:
  76. 1) This exec expects the files on the tape to be sorted in ascending
  77.    order by the first 2 characters of their file name.
  78.  
  79. 2) The KERMIT distribution tapes are mostly sorted, the exception being
  80.    that the OSTAPE files (like this one) are at the beginning.
  81.    So, if you use this exec to load the OSTAPE files,
  82.    then you will get messages that most of the other (until the P's)
  83.    files on the tape were bypassed.  This is annoying, but harmless.
  84.  
  85. 3) This exec uses several methods of end-of-tape detection.  The one
  86.    that is really used now (Dec-90) is the "missing-file" method in
  87.    the routine load-a-file.
  88.    A consequence of this is the message:
  89.      DMSSTT002E File OSTAPE $$TEMP$$ not found
  90.    when you hit end-of-tape.  This is annoying, but harmless.
  91.    The other methods may work in the future, depending on
  92.    how the distribution tapes are formatted, and wether MOVEFILE ever
  93.    passes a return code to RC.  To find them all, look for all
  94.    occurances of "eof".
  95.  
  96. 4) This exec loads each file from the tape to the disk that it runs
  97.    from.  It then decides if the file is a label or a data file.
  98.    If it is a data file, and it is one the user asked for, it is
  99.    copied to its final destination.  It would be possible to not
  100.    load all the files to disk, but the more complex logic seems
  101.    hardly worth the trouble.
  102.  
  103. V2 20-Dec-90 Bob Meizlik - add distinction between eof and finished
  104. V1 19-Dec-90 Bob Meizlik, Pan American World Airways - original coding
  105.  
  106. */ version = 2
  107. parse upper source . . exec_name exec_type exec_mode .
  108. parse upper arg file_name_prefix residence_disk .
  109.  
  110. call init
  111.  
  112. call position_tape
  113.  
  114. call load_files
  115.  
  116. call clean_up
  117.  
  118. exit
  119.  
  120. load_files:
  121.    do i = 1 by 1
  122.      call load_a_file
  123.      if eof then
  124.         leave
  125.      if finished then
  126.         leave
  127.  
  128.      if 1 /= this_file_is_label then do
  129.         if file_wanted then do
  130.            call copy_file
  131.            files_loaded = files_loaded + 1
  132.            end
  133.         else do
  134.            say exec_name version': bypassed' name
  135.            end
  136.         end
  137.      end
  138.    return
  139.  
  140. copy_file:
  141.    say exec_name version': loading' name 'as' tape_fn tape_ft
  142.    'copy' temp_file_name tape_fn tape_ft residence_disk '(TYPE'
  143.    return
  144.  
  145. load_a_file:
  146.    tape_pos = tape_pos + 1
  147.    'erase' temp_file_name      /* required for end-of-tape detection */
  148.  
  149.    if next_file_is_label then do
  150.       'FILEDEF  INMOVE TAP1 (RECFM F  LRECL 80 BLOCK 80'
  151.       'FILEDEF OUTMOVE DISK' temp_file_name '(RECFM VB LRECL 80'
  152.       'MOVEFILE INMOVE OUTMOVE'
  153.       If rc = 3 then do /* this doesn't work under vm/xa sp 2.1 */
  154.          eof = 1        /* but, may work under future versions */
  155.          leave
  156.          end
  157.       this_file_is_label = 1
  158.       call analyze_label
  159.       end
  160.    else do
  161.       'FILEDEF  INMOVE TAP1 (RECFM VB LRECL 80 BLOCK 16000'
  162.       'FILEDEF OUTMOVE DISK' temp_file_name '(RECFM VB LRECL 80'
  163.       'MOVEFILE INMOVE OUTMOVE'
  164.       If rc = 3 then do
  165.          eof = 1
  166.          leave
  167.          end
  168.       this_file_is_label = 0
  169.       next_file_is_label = 1       /* always a label after a data file */
  170.       end
  171.    return
  172.  
  173. analyze_label:
  174.  
  175.    do al = 1 by 1
  176.       'EXECIO 1 DISKR' temp_file_name al '(VAR TEMP'
  177.       if rc /= 0,        /* no label must be end-of-tape */
  178.        & al  = 1 then do
  179.          eof = 1
  180.          leave
  181.          end
  182.       if rc /= 0 then do /* no more label left           */
  183.          leave
  184.          end
  185.       parse var temp label_type +4 .
  186.       select
  187.       when label_type = 'VOL1' then parse var temp +4 volser +6
  188.       when label_type = 'HDR1' then do
  189.            next_file_is_label = 0
  190.            parse var temp +4 name +17 .
  191.            parse var name tape_fn '.' tape_ft .
  192.            if abbrev(name, file_name_prefix)
  193.               then file_wanted = 1
  194.               else file_wanted = 0
  195.            if left(name, length(file_name_prefix)) > file_name_prefix,
  196.             & tape_fn /= 'OSTAPE'
  197.            then do
  198.               finished = 1
  199.               leave
  200.               end
  201.            end
  202.       when label_type = 'HDR2' then do
  203.            next_file_is_label = 0
  204.            parse var temp +4 recfm +1 blksize +5 lrecl +4 .
  205.            end
  206.       when label_type = 'EOF1' then do
  207.            next_file_is_label = 1
  208.            parse var temp +4 .
  209.            end
  210.       when label_type = 'EOF2' then do
  211.            next_file_is_label = 1
  212.            parse var temp +4 .
  213.            end
  214.       when label_type = 'EOV1' then do
  215.            next_file_is_label = 1
  216.            parse var temp +4 .
  217.            eof = 1
  218.            end
  219.       otherwise do
  220.           say exec_name version': invalid label type found=' label_type
  221.           exit 16
  222.           end
  223.       end
  224.       end
  225.    return
  226.  
  227. position_tape:
  228.    'tape rew' /* beginning of tape */
  229.    return
  230.  
  231. init:
  232.    if file_name_prefix = '' then file_name_prefix = 'AA'
  233.    if residence_disk   = '' then residence_disk   = exec_mode
  234.  
  235.    say exec_name version': will load all KERMIT files beginning with',
  236.        file_name_prefix 'to disk' residence_disk
  237.  
  238.    temp_file_name = exec_name '$$TEMP$$' exec_mode
  239.    eof          = 0
  240.    files_loaded = 0
  241.    file_wanted  = 0
  242.    finished     = 0
  243.    tape_error   = 0
  244.    tape_pos     = 0
  245.    this_file_is_label = 1 /* the first file is always a label */
  246.    next_file_is_label = 1 /* the first file is always a label */
  247.    return
  248.  
  249. halt:
  250. clean_up:
  251.     say exec_name version': loaded' files_loaded 'files'
  252.     say exec_name version': tape was left at physical file' tape_pos
  253.     return
  254.