root/trunk/samples/unlzw.md

Revision 292, 0.8 kB (checked in by JarrettBillingsley, 7 months ago)

Closes #65. Also fixed a bug in the regexp.email predefined regexp, and a small bug in dumpVal.

Line 
1 module unlzw
2
3 function main(vararg)
4 {
5     if(#vararg < 2)
6     {
7         writefln("Usage: mdcl unlzw.md inputFile outputFile")
8         return
9     }
10    
11     local input = io.File(vararg[0], io.FileMode.In)
12     local output = io.File(vararg[1], io.FileMode.OutNew)
13     local dict = {}
14     local code
15    
16     for(code = 0; code < 128; code++)
17         dict[code] = toString(toChar(code))
18    
19     local shortCount = input.readInt()
20    
21     local k = input.readShort()
22     output.writeChars(dict[k])
23     shortCount--
24    
25     local w = dict[k]
26     local fchar = w[0]
27     local entry
28    
29     for( ; shortCount > 0; shortCount--)
30     {
31         k = input.readShort()
32    
33         if(k in dict)
34             entry = dict[k]
35         else
36             entry = w ~ fchar
37    
38         output.writeChars(entry)
39    
40         fchar = entry[0]
41         dict[code] = w ~ fchar
42         code++
43         w = entry
44     }
45    
46     output.flush()
47    
48     input.close()
49     output.close()
50 }
Note: See TracBrowser for help on using the browser.