$$ SET LINEINFO 00000100 00001000 Begin 00001100 $$ SET OMIT 00001200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00001300 %% %%00001400 %% UNITE/StreamFiles/Algol/StreamList %%00001500 %% %%00002000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00002100 %% %%00002200 %% Copyright (C) 2001: %%00002300 %% Paradigm Corporation %%00002400 %% 9625 Black Mountain Road, Suite 218 %%00002500 %% San Diego, CA 92126-4598 %%00002600 %% 858-536-5533; fax 858-536-5545 %%00002700 %% http://www.digm.com %%00002800 %% %%00002900 %% This material may be copied and used for any purpose providing %%00003000 %% this copyright notice is preservedand that appropriate credit %%00003100 %% given in any derative materials. %%00003200 %% %%00003300 %% This material is offered AS-IS WITH NO WARRANTY. Paradigm hereby %%00003400 %% disclaims all warranties respecting this material, expressed or %%00003500 %% implied, including without limitation warranty of design, %%00003600 %% merchantability, fitness for a particular purpose and against %%00003700 %% infringement. %%00003800 %% %%00010000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00010100 00010200 StreamList reads a byte stream file and formats it into lines for 00010300 output to a standard printer file. 00010400 00010500 Lines in the file are assumed to be delimited by carriage-return 00010600 (CR), line-feed (LF), form-feed (FF), or the multibyte sequences 00010700 CR-LF, CR-FF, LF-FF, or CR-LF-FF. A form-feed in the delimiter 00010800 sequence causes a page skip on the printer listing before the 00010900 next line is printed. 00011000 00011100 Note that the program works only with ClearPath MCP byte stream 00011200 files. That is, the files must have the following physical 00011300 attributes: 00011400 00011500 FILESTRUCTURE = STREAM 00011600 BLOCKSTRUCTURE = FIXED 00011700 FILEORGANIZATION = NOTRESTRICTED 00011800 MAXRECSIZE = 1 00011900 FRAMESIZE = 8 00012000 EXTMODE = . 00012100 00012200 The program assumes INTMODE=EBCDIC, and expects that the logical 00012300 I/O subsystem will translate foreign character sets into native 00012400 MCP EBCDIC. For this reason, the program is not normally 00012500 appropriate for use with binary stream files or files with mixed 00012600 binary and text data. 00012700 00012800 This program is currently capable of processing files with logical 00012900 lines up to 1240 characters in length. Longer lines will be split 00013000 after 1240 characters and interpreted as multiple logical lines. 00013100 00013200 This program may be used with the MCP Redirector to directly list 00013300 files from Microsoft Networking shares. 00013400 00050000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00050010 MODIFICATION LOG. 00050020 ----------------- 00050030 2000-10-20 P.Kimpel, Paradigm Corporation. 00050040 Original Version, from thin air. 00050041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00099900 $$ POP OMIT 00099920 00100000 %----- General Globals ----- 00100020 Define 00100040 %-- TIME(7) word layout -- 00101000 time7Yearf = [47:12] #, 00101020 time7Monthf = [35:6] #, 00101040 time7Dayf = [29:6] #, 00101060 time7Hourf = [23:6] #, 00101080 time7Minutef = [17:6] #, 00101100 time7Secondf = [11:6] #, 00101120 time7DayofWeekf = [5:6] #, 00101140 %-- Logical I/O result word -- 00102000 ioLengthf = [47:20] #, 00102020 ioEoff = [9:1] #, % end of file 00102040 ioErrorf = [0:1] #, 00102060 %-- EBCDIC character defines -- 00103000 nul = 48"00" #, 00103020 ht = 48"05" #, 00103040 ff = 48"0C" #, 00103060 cr = 48"0D" #, 00103080 lf = 48"25" #, 00103100 sp = " " #, 00103120 %-- print line and heading layouts -- 00105000 bufferMax = 4096 #, % bytes in stream rec buffer 00105020 defaultPageMax = 80 #, % default print page size 00105030 foldMax = 124 #, % max bytes per print line 00105040 headMax = 2 #, % number of print heads 00105060 lineMax = 1240 #, % max bytes per logical line 00105080 printWidth = 132 #, % width of printer file lines 00105100 nothing = #; 00109900 00110000 Boolean 00110020 streamEOF; % eof detected on stream file 00110040 00120000 Integer 00120020 bufferOffset, % current line offset in buffer 00120040 bufferSize, % current stream buffer size, 00120060 lineNr, % stream logical line number 00120080 linesLeft, % lines left on print page 00120085 openResult, % result code from stream open 00120090 pageNr, % print file page number 00120100 pageSize; % print file lines/page 00120120 00150000 Ebcdic Array 00150020 buf [0:bufferMax-1], % stream record buffer 00150040 heads [0:headMax-1, 0:printWidth-1]; % print line heads 00150060 00160000 File 00160020 stream (kind=disk, dependentspecs, anysizeio, adaptable, fileuse=in), 00160040 line (kind=printer, maxrecsize=printWidth, framesize=8, fileuse=out, 00160060 pagesize=defaultPageMax); 00160080 00180000 Truthset 00180020 lineDelim (cr or lf or ff); 00180040 00200000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00200020 String Procedure Hexit (v, chars); 00200040 Value v, chars; 00200060 Real v; 00200080 Integer chars; 00200100 Begin comment 00200120 Formats the value "v" into a hexadecimal string of length "chars".00200140 ; 00200160 Ebcdic Array 00200180 temp [0:11]; 00200200 Hex Array 00200220 htemp [0] = temp; 00200240 00200260 replace htemp by v for 1 words; 00200280 replace temp by htemp[12-chars] for chars with hextoebcdic; 00200300 Hexit:= string (temp, chars); 00200320 End Hexit; 00200340 00300000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00300020 Procedure BuildPrintHeading (streamTitle); 00300040 Value streamTitle; 00300060 Pointer streamTitle; 00300080 Begin comment 00300100 formats the print heading lines for the program. 00300120 ; 00300140 Real 00300160 t7; 00300180 00300200 t7:= time(7); 00300220 replace heads[0,0] by sp for printWidth; 00300240 replace heads[0,0] by "Algol StreamList"; 00300260 replace heads[0,(printWidth-36) div 2] by 00300280 "Paradigm Byte Stream Listing Utility"; 00300300 replace heads[0,printWidth-10] by "Page:"; 00300320 00300340 replace heads[1,0] by sp for printWidth; 00300360 replace heads[1,0] by "File: ", 00300380 streamTitle for printWidth-34 until = nul; 00300400 replace heads[1,printWidth-26] by "Printed: ", 00300420 t7.time7Hourf for 2 digits, ":", 00300440 t7.time7Minutef for 2 digits, sp for 2, 00300460 t7.time7Yearf for 4 digits, "-", 00300480 t7.time7Monthf for 2 digits, "-", 00300500 t7.time7Dayf for 2 digits; 00300520 End BuildPrintHeading; 00300540 00300560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00300580 Procedure PrintNewPage; 00300600 Begin comment 00300620 Forces the next line to be printed on a new page. 00300640 ; 00300660 00300680 linesLeft:= 0; 00300700 End PrintNewPage; 00300720 00300740 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00300760 Procedure PrintHeading; 00300780 Begin comment 00300800 Formats and prints the page headings for the printer file. 00300820 ; 00300840 00300860 pageNr:= *+1; 00300880 write (line[skip 1]); 00300900 replace heads[0,printWidth-6] by pageNr for 6 numeric; 00300920 write (line[space 1], printWidth, heads[0,0]); 00300940 write (line[space 2], printWidth, heads[1,0]); 00300960 linesLeft:= pageSize-3; 00300980 End PrintHeading; 00301000 00301020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00301040 Boolean Procedure PrintLine (image, spacing); 00301060 Value spacing; 00301080 Ebcdic Array image[0]; 00301100 Integer spacing; 00301120 Begin comment 00301140 Prints a line from "image" with "spacing" lines after print. 00301160 If the line will not fit on the current page, starts a new 00301180 page first. 00301200 ; 00301220 00301240 If linesLeft < 1 then 00301260 PrintHeading; 00301280 00301300 PrintLine:= write (line[space spacing], printWidth, image); 00301320 linesLeft:= *-spacing; 00301340 End PrintLine; 00301360 00400000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00400020 Boolean Procedure LoadBuffer; 00400040 Begin comment 00400060 Reads one chunk of bytes from the stream file into "buffer", 00400080 sets bufferSize to the number of bytes read, and sets 00400100 bufferOffset to zero. Returns the Logical I/O result word from 00400120 the read. 00400140 ; 00400160 Boolean 00400180 result; 00400200 00400220 bufferSize:= 0; 00400240 bufferOffset:= 0; 00400250 00400260 result:= read (stream, bufferMax, buf); 00400280 if result then 00400300 begin 00400320 if result.ioEoff then 00400340 bufferSize:= 0 00400360 else 00400380 begin 00400400 display ("Unexpected I/O result on stream file" !! 00400420 Hexit (real (result), 12)); 00400440 myself.status:= value(terminated); 00400460 end; 00400480 end 00400500 else 00400520 bufferSize:= real(result).ioLengthf; 00400540 00400560 LoadBuffer:= result; 00400580 End LoadBuffer; 00400600 00500000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00500020 Boolean Procedure ReadLine (rec, lineSize, formFeed); 00500040 Ebcdic Array rec[0]; 00500060 Integer lineSize; 00500080 Boolean formFeed; 00500100 Begin comment 00500120 Reads one logical line from the stream file. Returns the text of 00500140 the line in "rec". The length of the logical line will be in 00500160 "lineSize". If a form-feed is detected in the line delimiter 00500180 string, formFeed will be true. Returns true at eof (in which case 00500200 there is no text in "rec"). 00500220 ; 00500240 Define 00500260 %-- line states -- 00500280 moveChars = 1 #, 00500300 checkLF = 2 #, 00500320 checkFF = 3 #, 00500340 endLine = 4 #; 00500360 Boolean 00500380 result; 00500400 Integer 00500420 left, 00500440 len, 00500460 maxLeft, 00500480 state; 00500500 00500520 formFeed:= false; 00500540 if streamEOF then 00500560 begin 00500580 lineSize:= 0; 00500600 ReadLine:= true; 00500620 end 00500640 else 00500660 begin 00500680 state:= moveChars; 00500700 00500720 do begin 00500740 if bufferOffset >= bufferSize then 00500760 begin 00500780 result:= LoadBuffer; 00500800 if result then 00500820 begin 00500840 streamEOF:= result; 00500860 state:= endLine; 00500880 end; 00500900 end; 00500920 00500940 case state of 00500960 begin 00500980 moveChars: 00501000 begin 00501020 maxLeft:= min (lineMax-len, bufferSize-bufferOffset); 00501040 replace rec[len] by buf[bufferOffset] for left:maxLeft 00501060 until in lineDelim; 00501080 left:= maxLeft-left; 00501100 len:= *+left; 00501120 bufferOffset:= *+left; 00501140 if bufferOffset < bufferSize then 00501150 begin 00501180 case real (buf[bufferOffset], 1) of 00501200 begin 00501220 cr: 00501240 state:= checkLF; 00501260 bufferOffset:= *+1; 00501270 lf: 00501280 state:= checkFF; 00501300 bufferOffset:= *+1; 00501310 ff: 00501320 state:= endLine; 00501340 bufferOffset:= *+1; 00501350 formFeed:= true; 00501360 else: 00501380 state:= endLine; 00501390 end delim case; 00501420 end; 00501460 end moveChars; 00501480 00501500 checkLF: 00501520 begin 00501540 state:= checkFF; 00501560 if buf[bufferOffset] = lf for 1 then 00501580 bufferOffset:= *+1; 00501600 end checkLF; 00501620 00501640 checkFF: 00501660 begin 00501680 state:= endLine; 00501700 if buf[bufferOffset] = ff for 1 then 00501720 begin 00501740 bufferOffset:= *+1; 00501760 formFeed:= true; 00501780 end; 00501800 end checkFF; 00501820 00501840 endLine: 00501860 ; % nothing 00501880 00501900 else: 00501920 myself.status:= value(terminated); % impossible 00501940 end case; 00501960 end 00501980 until state = endLine; 00502000 00502020 lineSize:= len; 00502040 end; 00502060 00502080 End ReadLine; 00502100 00800000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00800100 Procedure ListStreamFile; 00800200 Begin comment 00800300 Formats the lines of text from the stream file to the printer 00800400 file. 00800500 ; 00800600 Boolean 00800700 eof, 00800800 formFeed; 00800900 Integer 00801000 foldSize, 00801100 lineSize, 00801200 x; 00801300 Ebcdic Array 00801400 image [0:printWidth-1], % print line image 00801500 rec [0:lineMax-1]; % current stream line 00801600 00801700 do begin 00801800 eof:= ReadLine (rec, lineSize, formFeed); 00801900 if eof then 00802000 begin 00802100 replace image by sp for printWidth; 00802200 PrintLine (image, 1); 00802300 replace image by "** EOF **"; 00802400 PrintLine (image, 1); 00802500 end 00802600 else 00802700 begin 00802800 foldSize:= (lineSize+foldMax-1) div foldMax; 00802900 if foldSize > linesLeft then 00803000 begin 00803100 PrintHeading; 00803200 formFeed:= false; 00803300 end; 00803400 00803500 lineNr:= *+1; 00803600 replace image by lineNr for 6 numeric, 00803700 sp for printWidth-6; 00803800 x:= 0; 00803900 do begin 00804000 foldSize:= min (lineSize, foldMax); 00804100 replace image[8] by rec[x] for foldSize; 00804200 PrintLine (image, 1); 00804300 replace image by sp for printWidth; 00804400 x:= *+foldSize; 00804500 lineSize:= *-foldSize; 00804600 end 00804700 until lineSize <= 0; 00804800 00804900 if formFeed then 00805000 PrintNewPage; 00805100 end; 00805200 end 00805300 until eof; 00805400 End ListStreamFile; 00805500 00900000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00900100 %% Outer Block 00900200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%00900300 00900400 open (line); 00900420 pageSize:= line.pagesize; 00900440 00900460 openResult:= open (stream); 00900500 00900520 replace buf by stream.ltitle, nul; 00900600 BuildPrintHeading (buf); 00900700 00900800 if boolean(openResult) then 00900900 begin 00901000 if stream.filestructure ^= value(stream) or 00901100 stream.blockstructure ^= value(fixed) or 00901200 stream.maxrecsize ^= 1 or 00901300 stream.framesize ^= 8 then 00901400 begin 00901500 replace buf by sp for printWidth; 00901600 replace buf by "This is not a byte stream file."; 00901700 PrintLine (buf, 2); 00901800 myself.status:= value(terminated); 00901900 end 00902000 else 00902100 ListStreamFile; 00902200 00902300 close (stream); 00902400 end 00902500 else 00902600 begin 00902700 replace buf by sp for printWidth; 00902800 replace buf by "File open error, result = ", openResult for * digits; 00902900 PrintLine (buf, 2); 00903000 myself.status:= value(terminated); 00903100 end; 00903200 00999800 End. 00999900