Debian Codegraph @

tads3/vmmaincn.h

raw symbols SCIP
1 /*
2 * Copyright (c) 2002 by Michael J. Roberts. All Rights Reserved.
3 *
4 * Please see the accompanying license file, LICENSE.TXT, for information
5 * on using and copying this software.
6 */
7 /*
8 Name
9 vmmaincn.h - VM main startup - console helper version
10 Function
11 Implements some helpers for the vmmain module and its users, for
12 implementations using the standard system console (G_console and
13 os_printz):
14
15 - provides a CVmMainClientIfc implementation that writes errors to
16 G_console (or os_printz, if no G_console is available), and ignores other
17 notifications
18
19 Notes
20
21 Modified
22 04/05/02 MJRoberts - Creation
23 */
24
25 #include "os.h"cxx . . $ `<file>/tads2/os.h`/
26 #include "t3std.h"cxx . . $ `<file>/tads3/t3std.h`/
27 #include "vmmain.h"cxx . . $ `<file>/tads3/vmmain.h`/
28 #include "vmconsol.h"cxx . . $ `<file>/tads3/vmconsol.h`/
29
30
31 /* ------------------------------------------------------------------------ */
32 /*
33 * Client services interface for T3 VM - console-based version
34 */
35 class CVmMainClientConsolecxx . . $ CVmMainClientConsole#: public CVmMainClientIfccxx . . $ CVmMainClientIfc#
36 {
37 public:
38 /* set plain ASCII mode */
39 void set_plain_modecxx . . $ CVmMainClientConsole#set_plain_mode(49f6e7a06ebc5aa8).()
40 {
41 /* set plain mode in the OS-level console */
42 os_plain();
43 }
44
45 /* create the console */
46 CVmConsoleMaincxx . . $ CVmConsoleMain# *create_consolecxx . . $ CVmMainClientConsole#create_console(fe34d08203b6fe29).(struct vm_globalscxx . . $ vm_globals# *vmg)
47 {
48 /* set up for global access */
49 VMGLOB_PTRcxx . . $ `tads3/vmglob.h:368:9`!(vmg);
50
51 /* create a standard console and return it */
52 return new CVmConsoleMaincxx . . $ CVmConsoleMain#CVmConsoleMain(49f6e7a06ebc5aa8).(vmg0_cxx . . $ `tads3/vmglob.h:352:9`!);
53 }
54
55 /* delete the console */
56 void delete_consolecxx . . $ CVmMainClientConsole#delete_console(62df61eb3179e4b0).(struct vm_globalscxx . . $ vm_globals# *vmg, CVmConsoleMaincxx . . $ CVmConsoleMain# *con)
57 {
58 /* set up for global access */
59 VMGLOB_PTRcxx . . $ `tads3/vmglob.h:368:9`!(vmg);
60
61 /* flush any pending buffered output */
62 con->flushcxx . . $ CVmConsole#flush(9e6e6415703fccd7).(vmg_cxx . . $ `tads3/vmglob.h:351:9`! VM_NL_NONEcxx . . $ VM_NL_NONE.);
63
64 /* delete the output formatter */
65 con->delete_objcxx . . $ CVmConsoleMain#delete_obj(49f6e7a06ebc5aa8).(vmg0_cxx . . $ `tads3/vmglob.h:352:9`!);
66 }
67
68 /* initialize */
69 void client_initcxx . . $ CVmMainClientConsole#client_init(46320dddd8347a33).(struct vm_globalscxx . . $ vm_globals# *vmg,
70 const char *script_file, int script_quiet,
71 const char *log_file,
72 const char *cmd_log_file,
73 const char *banner_str,
74 int more_mode)
75 {
76 /* set up for global access */
77 VMGLOB_PTRcxx . . $ `tads3/vmglob.h:368:9`!(vmg);
78
79 /* set the [More] mode as desired */
80 G_consolecxx . . $ `tads3/vmglob.h:551:9`!->set_more_statecxx . . $ CVmConsoleMain#set_more_state(7864480464b09eea).(more_mode);
81
82 /* if we have a script file, set up script input on the console */
83 if (script_file != 0)
84 {
85 G_consolecxx . . $ `tads3/vmglob.h:551:9`!->open_script_filecxx . . $ CVmConsole#open_script_file(1163be050dbfff7).(
86 vmg_cxx . . $ `tads3/vmglob.h:351:9`! script_file, script_quiet, FALSEcxx . . $ `tads3/t3std.h:336:10`!);
87 }
88
89 /* if we have a log file, set up logging on the console */
90 if (log_file != 0)
91 G_consolecxx . . $ `tads3/vmglob.h:551:9`!->open_log_filecxx . . $ CVmConsole#open_log_file(5c4306d8553b3696).(vmg_cxx . . $ `tads3/vmglob.h:351:9`! log_file);
92
93 /* set up command logging on the console if desired */
94 if (cmd_log_file != 0)
95 G_consolecxx . . $ `tads3/vmglob.h:551:9`!->open_command_logcxx . . $ CVmConsole#open_command_log(cb7559238bb26814).(vmg_cxx . . $ `tads3/vmglob.h:351:9`! cmd_log_file, TRUEcxx . . $ `tads3/t3std.h:333:10`!);
96
97 /* tell the HTML renderer that we're a T3 caller */
98 G_consolecxx . . $ `tads3/vmglob.h:551:9`!->format_textcxx . . $ CVmConsole#format_text(5c4306d8553b3696).(vmg_cxx . . $ `tads3/vmglob.h:351:9`! "<?T3>");
99
100 /* show the banner on the console, if desired */
101 if (banner_str != 0)
102 {
103 G_consolecxx . . $ `tads3/vmglob.h:551:9`!->format_textcxx . . $ CVmConsole#format_text(5c4306d8553b3696).(vmg_cxx . . $ `tads3/vmglob.h:351:9`! banner_str);
104 G_consolecxx . . $ `tads3/vmglob.h:551:9`!->write_blank_linecxx . . $ CVmConsole#write_blank_line(49f6e7a06ebc5aa8).(vmg0_cxx . . $ `tads3/vmglob.h:352:9`!);
105 }
106 }
107
108 /* terminate */
109 void client_terminatecxx . . $ CVmMainClientConsole#client_terminate(4d0d1714ab4c0dd4).(struct vm_globalscxx . . $ vm_globals# *) { }
110
111 /* pre-execution initialization */
112 void pre_execcxx . . $ CVmMainClientConsole#pre_exec(4d0d1714ab4c0dd4).(struct vm_globalscxx . . $ vm_globals# *) { }
113
114 /* post-execution termination/error termination */
115 void post_execcxx . . $ CVmMainClientConsole#post_exec(4d0d1714ab4c0dd4).(struct vm_globalscxx . . $ vm_globals# *) { }
116 void post_exec_errcxx . . $ CVmMainClientConsole#post_exec_err(4d0d1714ab4c0dd4).(struct vm_globalscxx . . $ vm_globals# *) { }
117
118 /* display an error */
119 void display_errorcxx . . $ CVmMainClientConsole#display_error(45509bf1e24dc7a6).(struct vm_globalscxx . . $ vm_globals# *vmg, const struct CVmExceptioncxx . . $ CVmException# *exc,
120 const char *msg, int add_blank_line)
121 {
122 CVmConsolecxx . . $ CVmConsole# *con;
123 size_t len;
124
125 /* check for a newline at the end of the message */
126 int has_nl = ((len = strlen(msg)) != 0 && msg[len-1] == '\n');
127
128 /* set up for global access */
129 VMGLOB_PTRcxx . . $ `tads3/vmglob.h:368:9`!(vmg);
130
131 /* if we have globals, get the console */
132 con = VMGLOB_IF_AVAILcxx . . $ `tads3/vmglob.h:371:9`!(G_consolecxx . . $ `tads3/vmglob.h:551:9`!);
133
134 /* if we have a console, write to it */
135 if (con != 0)
136 {
137 int old_obey;
138
139 /* flush any pending buffered output */
140 con->flushcxx . . $ CVmConsole#flush(9e6e6415703fccd7).(vmg_cxx . . $ `tads3/vmglob.h:351:9`! VM_NL_NONEcxx . . $ VM_NL_NONE.);
141
142 /* put the console in obey-whitespace mode for our message */
143 old_obey = con->set_obey_whitespacecxx . . $ CVmConsole#set_obey_whitespace(7864480464b09eea).(TRUEcxx . . $ `tads3/t3std.h:333:10`!);
144
145 /* display the message on the console */
146 con->format_textcxx . . $ CVmConsole#format_text(5c4306d8553b3696).(vmg_cxx . . $ `tads3/vmglob.h:351:9`! msg);
147
148 /* add a blank line if desired */
149 if (add_blank_line)
150 con->write_blank_linecxx . . $ CVmConsole#write_blank_line(49f6e7a06ebc5aa8).(vmg0_cxx . . $ `tads3/vmglob.h:352:9`!);
151
152 /* restore console mode */
153 con->set_obey_whitespacecxx . . $ CVmConsole#set_obey_whitespace(7864480464b09eea).(old_obey);
154 }
155 else
156 {
157 /* display the error on the OS-level console */
158 os_printz(msg);
159
160 /* add a blank line if desired */
161 if (add_blank_line)
162 {
163 /* add one newline */
164 os_printz("\n");
165
166 /*
167 * if the message itself didn't end with a newline, add
168 * another newline
169 */
170 if (!has_nl)
171 os_printz("\n");
172 }
173 }
174 }
175 };
176