| 1 | /* |
| 2 | * Copyright 1999, 2002 Michael J. Roberts |
| 3 | * |
| 4 | * Please see the accompanying license file, LICENSE.TXT, for information |
| 5 | * on using and copying this software. |
| 6 | */ |
| 7 | /* |
| 8 | * T3 Image File Test - Load and Execute |
| 9 | */ |
| 10 | |
| 11 | #include <stdlib.h> |
| 12 | |
| 13 | #include "os.h" |
| 14 | #include "t3std.h" |
| 15 | #include "vmmain.h" |
| 16 | #include "vmconsol.h" |
| 17 | #include "t3test.h" |
| 18 | #include "vmhostsi.h" |
| 19 | |
| 20 | |
| 21 | /* |
| 22 | * Client services interface |
| 23 | */ |
| 24 | class MyClientIfc: public CVmMainClientIfc |
| 25 | { |
| 26 | public: |
| 27 | /* set plain ASCII mode */ |
| 28 | void set_plain_mode() { os_plain(); } |
| 29 | |
| 30 | /* create the main console */ |
| 31 | CVmConsoleMain *create_console(struct vm_globals *vmg) |
| 32 | { |
| 33 | VMGLOB_PTR(vmg); |
| 34 | return new CVmConsoleMain(vmg0_); |
| 35 | } |
| 36 | |
| 37 | /* delete the console */ |
| 38 | void delete_console(struct vm_globals *vmg, CVmConsoleMain *con) |
| 39 | { |
| 40 | VMGLOB_PTR(vmg); |
| 41 | |
| 42 | /* flush any pending buffered output */ |
| 43 | con->flush(vmg_ VM_NL_NONE); |
| 44 | |
| 45 | /* delete the output formatter */ |
| 46 | con->delete_obj(vmg0_); |
| 47 | } |
| 48 | |
| 49 | /* initialize */ |
| 50 | void client_init(struct vm_globals *vmg, |
| 51 | const char *script_file, int script_quiet, |
| 52 | const char *, |
| 53 | const char *, |
| 54 | const char *, |
| 55 | int) |
| 56 | { |
| 57 | /* set up for global access */ |
| 58 | VMGLOB_PTR(vmg); |
| 59 | |
| 60 | /* if we have a script file, set up script input on the console */ |
| 61 | if (script_file != 0) |
| 62 | { |
| 63 | G_console->open_script_file( |
| 64 | vmg_ script_file, script_quiet, FALSE); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /* terminate */ |
| 69 | void client_terminate(struct vm_globals *vmg) |
| 70 | { |
| 71 | VMGLOB_PTR(vmg); |
| 72 | G_console->close_script_file(vmg0_); |
| 73 | } |
| 74 | |
| 75 | /* pre-execution initialization */ |
| 76 | void pre_exec(struct vm_globals *globals) |
| 77 | { |
| 78 | VMGLOB_PTR(globals); |
| 79 | |
| 80 | /* |
| 81 | * Turn off MORE mode in the display formatter, since this host |
| 82 | * environment is meant primarily for automated testing. |
| 83 | */ |
| 84 | G_console->set_more_state(FALSE); |
| 85 | } |
| 86 | |
| 87 | /* post-execution termination/error termination */ |
| 88 | void post_exec(struct vm_globals *) { } |
| 89 | void post_exec_err(struct vm_globals *) { } |
| 90 | |
| 91 | /* display an error */ |
| 92 | void display_error(struct vm_globals *, const struct CVmException *, |
| 93 | const char *msg, int add_blank_line) |
| 94 | { |
| 95 | /* display the error on the stdio console */ |
| 96 | printf("%s\n", msg); |
| 97 | |
| 98 | /* add a blank line if desired */ |
| 99 | if (add_blank_line) |
| 100 | printf("\n"); |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | /* |
| 105 | * Main program entrypoint |
| 106 | */ |
| 107 | int main(int argc, char **argv) |
| 108 | { |
| 109 | int stat; |
| 110 | MyClientIfc clientifc; |
| 111 | CVmHostIfc *hostifc = new CVmHostIfcStdio(argv[0]); |
| 112 | |
| 113 | /* initialize for testing */ |
| 114 | test_init(); |
| 115 | |
| 116 | /* |
| 117 | * Initialize the OS layer. Since this is a command-line-only |
| 118 | * implementation, there's no need to ask the OS layer to try to get |
| 119 | * us a filename to run, so pass in null for the prompt and filename |
| 120 | * buffer. |
| 121 | */ |
| 122 | os_init(&argc, argv, 0, 0, 0); |
| 123 | |
| 124 | /* run the image */ |
| 125 | stat = vm_run_image_main(&clientifc, "test_exec", argc, argv, |
| 126 | TRUE, TRUE, hostifc); |
| 127 | |
| 128 | /* uninitialize the OS layer */ |
| 129 | os_uninit(); |
| 130 | |
| 131 | /* done with the host interface */ |
| 132 | delete hostifc; |
| 133 | |
| 134 | /* show any unfreed memory */ |
| 135 | t3_list_memory_blocks(0); |
| 136 | |
| 137 | /* done */ |
| 138 | return stat; |
| 139 | } |
| 140 |