/* REXX | | Name: INPUTB | | Author: David Alcock | dalcock@csw.com (work) | davea@ticnet.com (home) | | Purpose: Sample Rexx code that can be used as a template to read | an input file in byte mode on any platform. | | When I say "byte" mode, I mean the whole file is seen | from start to finish as one long stream of bytes. There | are no concept of lines or records. | | Requirements: Rexx Anywhere! | | Disclaimer: This Rexx exec is FREEWARE. Use at your own risk. It | is provided for your enjoyment and neither David | Alcock or his employer provides any warranty for it's | use. I'd like to hear how it works on your system. */ /********************************************************************** * M o d i f i c a t i o n H i s t o r y * * Person Date Description * ---------- ----------- --------------------------------------------- * DGAlcock 26-JAN-1998 v1.0 Initial exec written; **********************************************************************/ mtype = address() /* Get the environment */ execio = 0 /* We haven't done EXECIO yet */ /*--------------------------------------------------------------------- | Read in the input file based on the environment ------------------------------------------------------------------- */ select /*-------------------------------------------------------------- | PC: OS/2, Windows 95, Windows NT, etc. ------------------------------------------------------------ */ when mtype == "CMD" | mtype == "COMMAND" then do arg filein options filesize = chars(filein) if filesize == 0 then do say "Error reading input file: "filein exit end file = charin(filein,1,filesize) name = strip(filein) end /*-------------------------------------------------------------- | MVS (batch execution) - defaults to SYSUT1 for input ------------------------------------------------------------ */ when mtype == "MVS" then do execio = 1 arg options "EXECIO * DISKR SYSUT1 (FINIS STEM filein." erc = rc if erc <> 0 then do say "Error reading SYSUT1" exit end if filein.0 == 0 then do say "SYSUT1 is empty" exit 12 end name = "SYSUT1" /* if a file name is needed later */ end /*-------------------------------------------------------------- | TSO (but not batch "MVS") ------------------------------------------------------------ */ when mtype == "TSO" then do execio = 1 arg filein_dsn options if filein_dsn == "" then do say "%INPUTB - Missing input dataset name, terminating" exit end x = LISTDSI(filein_dsn) if x <> 0 then do say "Error accessing DSN:" filein_dsn say "> "sysmsglvl1 say "> "sysmsglvl2 say "> SYSREASON: "sysreason exit end filein_pdsn = sysdsname parse value filein_dsn with . "(" member ")" . if member <> "" then do filein_pdsn = filein_pdsn"("strip(member)")" end say "Processing input file "filein_pdsn filein_dd = "SYU1"random() address TSO "ALLOCATE FILE("filein_dd")" , "DA('"filein_pdsn"') SHR REUSE" "EXECIO * DISKR "filein_dd , "(FINIS STEM filein." erc = rc address TSO "FREE FILE("filein_dd")" if erc <> 0 then do say "Error reading input file: "filein_pdsn exit end if filein.0 == 0 then do say "Input file is empty: "filein_pdsn exit end if member == "" then name = "UNKNOWN" else name = member end /*-------------------------------------------------------------- | VM files ------------------------------------------------------------ */ when mtype == "CMS" then do execio = 1 parse arg fn ft fm "(" options fn = strip(fn) ft = strip(ft) fm = strip(fm) if fm == "" then fm = "A" else fm = translate(fm) address command "STATE" fn ft fm if rc <> 0 then do upper fn ft fm "STATE" fn ft fm if rc <> 0 then do say "File" fn ft fm "not found" exit end end vmfclear "FINIS" fn ft fm "EXECIO * DISKR "fn ft fm" (STEM FILEIN. FINIS" erc = rc if erc <> 0 then do say "Error reading input file: "fn ft fm exit end if filein.0 == 0 then do say "Input file is empty: "fn ft fm exit end name = fn"."ft end /*-------------------------------------------------------------- | Other systems that we don't support ------------------------------------------------------------ */ otherwise say "Not written to support system type: "mtype say "We do support: CMS, CMD, COMMAND, MVS and TSO" exit end /* of "select" */ /*--------------------------------------------------------------------- | Perform functions for Mainframe environments ------------------------------------------------------------------- */ if execio == 1 then do filesize = 0 file = "" do i = 1 to filein.0 file = file||filein.i filesize = filesize + length(filein.i) drop filein.i end drop filein.0 /* After here, filein.x vars are not needed and aren't valid */ end /*--------------------------------------------------------------------- | From here on out, you can see the entire file contents via | variable "file". ------------------------------------------------------------------- */ say "The input file size is "length(file)"." /*--------------------------------------------------------------------- | END END END END END - End of INPUTB exec - END END END END END ------------------------------------------------------------------- */