Debian Codegraph @

terps/tads/tads3/test/test_gets.cpp

raw symbols SCIP
1 #ifdef RCSID
2 static char RCSid[] =
3 "$Header: d:/cvsroot/tads/tads3/test/test_gets.cpp,v 1.2 1999/05/17 02:52:31 MJRoberts Exp $";
4 #endif
5
6 /*
7 * Copyright (c) 1999, 2002 Michael J. Roberts. All Rights Reserved.
8 *
9 * Please see the accompanying license file, LICENSE.TXT, for information
10 * on using and copying this software.
11 */
12 /*
13 Name
14 test_gets.cpp - test reading from an input file
15 Function
16
17 Notes
18
19 Modified
20 04/14/99 MJRoberts - Creation
21 */
22
23 #include "os.h"
24 #include "t3std.h"
25 #include "tcsrc.h"
26 #include "resload.h"
27 #include "vmimage.h"
28 #include "t3test.h"
29
30
31 static void errexit(const char *msg)
32 {
33 printf("%s\n", msg);
34 exit(1);
35 }
36
37 int main(int argc, char **argv)
38 {
39 CTcSrcFile *src;
40 CResLoader *resl;
41 int lnum;
42 int charset_error;
43 int default_charset_error;
44 char pathbuf[OSFNMAX];
45
46 /* initialize for testing */
47 test_init();
48
49 /* make sure we got an input file argument */
50 if (argc != 2)
51 errexit("usage: test_gets <input-text-filename>");
52
53 /* create a resource loader */
54 os_get_special_path(pathbuf, sizeof(pathbuf), argv[0], OS_GSP_T3_RES);
55 resl = new CResLoader(pathbuf);
56
57 /* create a reader for the file */
58 src = CTcSrcFile::open_source(argv[1], resl, 0, &charset_error,
59 &default_charset_error);
60 if (src == 0)
61 {
62 if (default_charset_error)
63 errexit("unable to open default character set");
64 else
65 errexit("unable to create reader for input file");
66 }
67
68 /* warn on #charset errors */
69 if (charset_error)
70 printf("warning: cannot load character set specified in #charset");
71
72 /* read lines and display them */
73 for (lnum = 1 ; ; ++lnum)
74 {
75 char buf[256];
76
77 /* read a line */
78 if (src->read_line(buf, sizeof(buf)))
79 break;
80
81 /* display what we read */
82 printf("%d:%s\n", lnum, buf);
83 }
84
85 /* delete our objects */
86 delete src;
87 delete resl;
88
89 /* success */
90 return 0;
91 }
92
93