Debian Codegraph @

trip/addrtest4.rexx

raw
1 /*
2 * Another ADDRESS...WITH test program
3 * Ideally the argument should be a large text file
4 * Requires a diff and wc executable and filter.c compiled to an executable
5 */
6 Parse Arg infn
7 If Stream( infn, 'C', 'QUERY EXISTS' ) = '' Then
8 Do
9 Say infn 'does not exist.'
10 Exit 1
11 End
12 infnsize = Stream( infn, 'C', 'QUERY SIZE' ) + 10
13 outfn = infn'.out'
14 Parse Source os .
15 Select
16 When Left( os, 3 ) = 'WIN' Then
17 Do
18 _diff = 'qdiff'
19 _cat = 'type'
20 _rm = 'del'
21 _filter = '.\filter'
22 _wc = 'wc'
23 End
24 When os = 'OS/2' Then
25 Do
26 _diff = 'diff'
27 _cat = 'type'
28 _rm = 'del'
29 _filter = '.\filter'
30 _wc = 'wc'
31 End
32 Otherwise
33 Do
34 _diff = 'diff'
35 _cat = '/bin/cat'
36 _rm = 'rm'
37 _filter = './filter'
38 _wc = 'wc'
39 End
40 End
41 _rm 'filter.log'
42 Call Mix
43 Call RoundTrip
44 Call Blob
45 Return 0
46
47 Mix:
48 Say 'Running Mix: ************************************'
49 -- split input file into stdout and stderr half/half
50 Address System _filter infnsize 'line stderr' with input stream infn output stem out. error stem err.
51 Say 'Have split' infn 'in half. Lines sent to stdout:' out.0'; lines sent to stderr:' err.0'.'
52 Say 'The number of lines should be within 1 of each other.'
53 diffs = Abs( out.0 - err.0 )
54 If diffs > 1 Then Say '=== Error: Too many differences in line count:' diffs
55 -- put 'stdout' half into queue
56 Address System _filter infnsize 'char' with input stem out. output FIFO ''
57 step2 = queued()
58 Parse Value 'wc'( '-l' infn ) With count .
59 If (out.0 + err.0) \= count Then Say '=== Error: Lines in input file ('infn'):' count 'stdout stem lines:' out.0 'stderr stem lines:' err.0
60 -- put 'stdout' half into another file
61 Address System _filter infnsize 'char' with input FIFO '' output stream outfn
62 -- put 'stderr' half into another file
63 outerr = outfn'.err'
64 Address System _filter infnsize 'char' with input stem err. output stream outerr
65 -- sort original input file
66 Address System 'sort' infn '>' infn'.sorted'
67 -- cat both output files into sort...
68 cmd = _cat outfn outerr' | sort >' outfn'.sorted'
69 Address System cmd
70 -- ...and compare them
71 _diff '-q' infn'.sorted' outfn'.sorted'
72 If rc \= 0 Then
73 Do
74 Say '=== Error: Differences between' infn'.sorted' 'and' outfn'.sorted'
75 End
76 Call Stream infn, 'C', 'CLOSE'
77 Return
78
79 RoundTrip:
80 Say 'Running RoundTrip: ************************************'
81 -- read input file into stem
82 Address System _filter infnsize 'char' with input stream infn output stem out.
83 step1 = out.0
84 -- then the stem into a queue
85 Address System _filter infnsize 'char' with input stem out. output FIFO ''
86 step2 = queued()
87 -- and back out to another file
88 Address System _filter infnsize 'char' with input FIFO '' output stream outfn
89 -- now compare them without sorting
90 If step1 \= step2 Then Say '*** An error occured. stem output:' step1 'FIFO output:' step2'. See filter.log for possible reasons.'
91 _diff '-q' infn outfn
92 Call Stream infn, 'C', 'CLOSE'
93 Return
94
95 Blob:
96 Say 'Running Blob: ************************************'
97 -- create our blob file
98 outfn = 'out.blob'
99 count = 0
100 lines = 10000
101 columns = 1000
102 Do i = 1 To lines
103 line = ''
104 Do j = 1 To columns
105 line = line || D2C( Random( 32, 128 ) )
106 count = count + 1
107 End
108 line.i = line
109 Queue line
110 End
111 line.0 = i - 1
112 outfnsize = count + 10 + (lines * 2 ) -- we need enough space to handle CRLF at the end of each line
113 -- read input from queue into file
114 outfnqueue = outfn'.queue'
115 Address System _filter outfnsize 'char' with input FIFO '' output stream outfnqueue
116 outfnstem = outfn'.stem'
117 -- then the stem into a stream via stderr
118 Address System _filter outfnsize 'char stderr' with input stem line. error stream outfnstem
119 -- now compare them without sorting
120 _diff '-q' outfnqueue outfnstem
121 _rm outfnqueue
122 _rm outfnstem
123 Return