| 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 |
return /* FGC */ |
| 66 |
-- sort original input file |
| 67 |
Address System 'sort' infn '>' infn'.sorted' |
| 68 |
-- cat both output files into sort... |
| 69 |
cmd = _cat outfn outerr' | sort >' outfn'.sorted' |
| 70 |
Address System cmd |
| 71 |
-- ...and compare them |
| 72 |
_diff '-q' infn'.sorted' outfn'.sorted' |
| 73 |
If rc \= 0 Then |
| 74 |
Do |
| 75 |
Say '=== Error: Differences between' infn'.sorted' 'and' outfn'.sorted' |
| 76 |
End |
| 77 |
Call Stream infn, 'C', 'CLOSE' |
| 78 |
Return |
| 79 |
|
| 80 |
RoundTrip: |
| 81 |
Say 'Running RoundTrip: ************************************' |
| 82 |
-- read input file into stem |
| 83 |
Address System _filter infnsize 'char' with input stream infn output stem out. |
| 84 |
step1 = out.0 |
| 85 |
-- then the stem into a queue |
| 86 |
Address System _filter infnsize 'char' with input stem out. output FIFO '' |
| 87 |
step2 = queued() |
| 88 |
-- and back out to another file |
| 89 |
Address System _filter infnsize 'char' with input FIFO '' output stream outfn |
| 90 |
-- now compare them without sorting |
| 91 |
If step1 \= step2 Then Say '*** An error occured. stem output:' step1 'FIFO output:' step2'. See filter.log for possible reasons.' |
| 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 = 1000 |
| 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 |
return /* FGC */ |
| 120 |
-- now compare them without sorting |
| 121 |
_diff '-q' outfnqueue outfnstem |
| 122 |
_rm outfnqueue |
| 123 |
_rm outfnstem |
| 124 |
Return |