~ubuntu-branches/ubuntu/wily/gargoyle-free/wily-proposed

« back to all changes in this revision

Viewing changes to tads/tads3/test/test_exec.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sylvain Beucler
  • Date: 2009-09-11 20:09:43 UTC
  • Revision ID: james.westby@ubuntu.com-20090911200943-idgzoyupq6650zpn
Tags: upstream-2009-08-25
ImportĀ upstreamĀ versionĀ 2009-08-25

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
        delete con;
 
47
    }
 
48
 
 
49
    /* initialize */
 
50
    void client_init(struct vm_globals *,
 
51
                     const char *, int,
 
52
                     const char *,
 
53
                     const char *,
 
54
                     const char *)
 
55
    {
 
56
        /* do nothing */
 
57
    }
 
58
 
 
59
    /* terminate */
 
60
    void client_terminate(struct vm_globals *) { }
 
61
 
 
62
    /* pre-execution initialization */
 
63
    void pre_exec(struct vm_globals *globals)
 
64
    {
 
65
        VMGLOB_PTR(globals);
 
66
        
 
67
        /*
 
68
         *   Turn off MORE mode in the display formatter, since this host
 
69
         *   environment is meant primarily for automated testing.  
 
70
         */
 
71
        G_console->set_more_state(FALSE);
 
72
    }
 
73
 
 
74
    /* post-execution termination/error termination */
 
75
    void post_exec(struct vm_globals *) { }
 
76
    void post_exec_err(struct vm_globals *) { }
 
77
 
 
78
    /* display an error */
 
79
    void display_error(struct vm_globals *, const char *msg,
 
80
                       int add_blank_line)
 
81
    {
 
82
        /* display the error on the stdio console */
 
83
        printf("%s\n", msg);
 
84
 
 
85
        /* add a blank line if desired */
 
86
        if (add_blank_line)
 
87
            printf("\n");
 
88
    }
 
89
};
 
90
 
 
91
/*
 
92
 *   Main program entrypoint 
 
93
 */
 
94
int main(int argc, char **argv)
 
95
{
 
96
    int stat;
 
97
    MyClientIfc clientifc;
 
98
    CVmHostIfc *hostifc = new CVmHostIfcStdio(argv[0]);
 
99
 
 
100
    /* initialize for testing */
 
101
    test_init();
 
102
 
 
103
    /* 
 
104
     *   Initialize the OS layer.  Since this is a command-line-only
 
105
     *   implementation, there's no need to ask the OS layer to try to get
 
106
     *   us a filename to run, so pass in null for the prompt and filename
 
107
     *   buffer.  
 
108
     */
 
109
    os_init(&argc, argv, 0, 0, 0);
 
110
 
 
111
    /* run the image */
 
112
    stat = vm_run_image_main(&clientifc, "test_exec", argc, argv,
 
113
                             TRUE, TRUE, hostifc);
 
114
 
 
115
    /* uninitialize the OS layer */
 
116
    os_uninit();
 
117
 
 
118
    /* done with the host interface */
 
119
    delete hostifc;
 
120
 
 
121
    /* show any unfreed memory */
 
122
    t3_list_memory_blocks(0);
 
123
 
 
124
    /* done */
 
125
    return stat;
 
126
}
 
127