Debian Codegraph @

terps/tads/tads3/test/test_pre.cpp

raw symbols SCIP
1 #ifdef RCSID
2 static char RCSid[] =
3 "$Header$";
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_pre.cpp - preinit builder command line interface
15 Function
16 Command line interface for preinitialization. Allows a program
17 previously compiled to be preinitialized and saved into a final
18 image file.
19 Notes
20 This was originally written as a stand-alone utility, but since
21 preinitialization was integrated a long time ago into t3make and
22 separate preinitialization is of no real value, this has been
23 eliminated except as a test driver. (This file's original name
24 was vmprecl.cpp - it was renamed to conform with the test program
25 naming conventions.)
26 Modified
27 07/21/99 MJRoberts - Creation
28 */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32
33 #include "t3std.h"
34 #include "os.h"
35 #include "vmpreini.h"
36 #include "vmfile.h"
37 #include "vmerr.h"
38 #include "vmhost.h"
39 #include "vmhostsi.h"
40 #include "vmmaincn.h"
41 #include "t3test.h"
42
43
44 int main(int argc, char **argv)
45 {
46 osfildef *fpin;
47 osfildef *fpout;
48 CVmFile *file_in;
49 CVmFile *file_out;
50 int status;
51 CVmHostIfc *hostifc;
52 CVmMainClientConsole clientifc;
53 int curarg;
54
55 /* initialize for testing */
56 test_init();
57
58 /* initialize the error stack */
59 err_init(1024);
60
61 /* start at the first argument */
62 curarg = 1;
63
64 /* check usage */
65 if (curarg + 2 > argc)
66 {
67 printf("usage: t3pre <original-image> <new-image> [program-args]\n"
68 "\n"
69 "Runs preinitialization on the image file, writing a new "
70 "image file\n"
71 "with the state of the program after preinitialization.\n");
72 return OSEXFAIL;
73 }
74
75 /* open the files */
76 if ((fpin = osfoprb(argv[curarg], OSFTT3IMG)) == 0)
77 {
78 printf("Error opening original image file \"%s\"\n", argv[1]);
79 return OSEXFAIL;
80 }
81
82 if ((fpout = osfopwb(argv[curarg + 1], OSFTT3IMG)) == 0)
83 {
84 printf("Error opening new image file \"%s\"\n", argv[2]);
85 return OSEXFAIL;
86 }
87
88 /* create the CVmFile objects */
89 file_in = new CVmFile();
90 file_in->set_file(fpin, 0);
91 file_out = new CVmFile();
92 file_out->set_file(fpout, 0);
93
94 /* create our host interface */
95 hostifc = new CVmHostIfcStdio(argv[0]);
96
97 /* run preinit and write the new image file */
98 err_try
99 {
100 /* load, run, and write */
101 vm_run_preinit(file_in, argv[1], file_out, hostifc, &clientifc,
102 argv + curarg + 1, argc - curarg - 1, 0, 0);
103
104 /* note the success status */
105 status = OSEXSUCC;
106 }
107 err_catch(exc)
108 {
109 const char *msg;
110 char buf[128];
111
112 /* look up the message */
113 msg = err_get_msg(vm_messages, vm_message_count,
114 exc->get_error_code(), FALSE);
115
116 /* if that failed, just show the error number */
117 if (msg == 0)
118 {
119 sprintf(buf, "[no message: code %d]", exc->get_error_code());
120 msg = buf;
121 }
122
123 /* show the message */
124 printf("VM Error: %s\n", msg);
125
126 /* note the failure status */
127 status = OSEXFAIL;
128 }
129 err_end;
130
131 /* delete the file objects, which will close the files */
132 delete file_in;
133 delete file_out;
134
135 /* terminate the error mechanism */
136 err_terminate();
137
138 /* delete our host interface object */
139 delete hostifc;
140
141 /* log any memory leaks */
142 t3_list_memory_blocks(0);
143
144 /* exit with appropriate results */
145 return status;
146 }
147