Debian Codegraph @

terps/tads/tads3/test/data/charconv.t

raw
1 #include <tads.h>
2 #include <file.h>
3
4 translate(inFileName, outFileName)
5 {
6 local inFile, outFile;
7 local csMac, csISO;
8
9 /* create the character set objects */
10 csMac = new CharacterSet('cp1250');
11 csISO = new CharacterSet('cp1252');
12
13 /* open the files */
14 inFile = File.openTextFile(inFileName, FileAccessRead, csMac);
15 outFile = File.openTextFile(outFileName, FileAccessWrite, csISO);
16 if (inFile == nil || outFile == nil)
17 {
18 "Error: cannot open files.\n";
19 return;
20 }
21
22 /* read text and write it back out */
23 for (;;)
24 {
25 local txt;
26
27 /* read a line of input; stop if at end of file */
28 txt = inFile.readFile();
29 if (txt == nil)
30 break;
31
32 /* write it out */
33 outFile.writeFile(txt);
34 }
35
36 /* close the files */
37 inFile.closeFile();
38 outFile.closeFile();
39 }
40
41 main(args)
42 {
43 try
44 {
45 translate(args[2], args[3]);
46 }
47 catch (Exception e)
48 {
49 "Exception!\n";
50 e.displayException();
51 }
52 }