cfad47cfa3/t3compiler/tads3/rcmain.h

4b825dc642cb6eb9a060e54bf8d69288fbee4904cfad47cfa334b206c65f22086bcc5d63e6f70944
1
/* $Header$ */
2
3
/* 
4
 *   Copyright (c) 2000, 2002 Michael J. Roberts.  All Rights Reserved.
5
 *   
6
 *   Please see the accompanying license file, LICENSE.TXT, for information
7
 *   on using and copying this software.  
8
 */
9
/*
10
Name
11
  rcmain.h - T3 resource compiler main
12
Function
13
  
14
Notes
15
  
16
Modified
17
  01/03/00 MJRoberts  - Creation
18
*/
19
20
#ifndef RCMAIN_H
21
#define RCMAIN_H
22
23
#include "os.h"
24
#include "t3std.h"
25
26
/*
27
 *   Resource compiler main class
28
 */
29
class CResCompMain
30
{
31
public:
32
    /* 
33
     *   Add the given resources to an image file.  Returns zero on
34
     *   success, nonzero on failure.  If anything goes wrong, we'll use
35
     *   the given host interface to display error messages.  
36
     */
37
    static int add_resources(const char *image_fname,
38
                             const class CRcResList *reslist,
39
                             class CRcHostIfc *hostifc,
40
                             int create_new, os_filetype_t file_type,
41
                             int link_mode);
42
43
private:
44
    /* format an error message and display it via the host interface */
45
    static void disp_error(class CRcHostIfc *hostifc, const char *msg, ...);
46
};
47
48
/*
49
 *   Resource list element 
50
 */
51
class CRcResEntry
52
{
53
public:
54
    CRcResEntry(const char *fname, const char *url)
55
    {
56
        /* make a copy of the filename and URL */
57
        fname_ = lib_copy_str(fname);
58
        url_ = lib_copy_str(url);
59
60
        /* not in a list yet */
61
        next_ = 0;
62
    }
63
64
    ~CRcResEntry()
65
    {
66
        /* delete the filename and url strings */
67
        lib_free_str(fname_);
68
        lib_free_str(url_);
69
    }
70
    
71
    /* get/set the next entry in the list */
72
    CRcResEntry *get_next() const { return next_; }
73
    void set_next(CRcResEntry *nxt) { next_ = nxt; }
74
75
    /* get the entry's filename */
76
    const char *get_fname() const { return fname_; }
77
78
    /* get the entry's URL */
79
    const char *get_url() const { return url_; }
80
81
private:
82
    /* next entry in list */
83
    CRcResEntry *next_;
84
85
    /* filename */
86
    char *fname_;
87
88
    /* URL as stored in resource file */
89
    char *url_;
90
};
91
92
/*
93
 *   Resource operation modes 
94
 */
95
enum rcmain_res_op_mode_t
96
{
97
    /* add resources */
98
    RCMAIN_RES_OP_MODE_ADD,
99
100
    /* replace resources */
101
    RCMAIN_RES_OP_MODE_REPLACE,
102
103
    /* delete resources */
104
    RCMAIN_RES_OP_MODE_DELETE
105
};
106
107
/*
108
 *   Resource list object 
109
 */
110
class CRcResList
111
{
112
public:
113
    CRcResList()
114
    {
115
        /* nothing in the list yet */
116
        head_ = tail_ = 0;
117
        count_ = 0;
118
    }
119
120
    ~CRcResList()
121
    {
122
        /* delete the entire list */
123
        while (head_ != 0)
124
        {
125
            CRcResEntry *nxt;
126
127
            /* remember the next entry */
128
            nxt = head_->get_next();
129
130
            /* delete this entry */
131
            delete head_;
132
133
            /* move on */
134
            head_ = nxt;
135
        }
136
    }
137
138
    /* get the head of the list */
139
    class CRcResEntry *get_head() const { return head_; }
140
141
    /* get the number of elements in the list */
142
    unsigned int get_count() const { return count_; }
143
144
    /* 
145
     *   Add a file or directory.  If 'alias' is non-null, we'll store the
146
     *   alias string as-is (with no URL conversions or any other changes)
147
     *   as the name of the resource.  If 'alias' is null, we'll convert
148
     *   the filename to a URL using the normal rules and store the URL.
149
     *   
150
     *   If 'fname' refers to a directory rather than a file, we'll add
151
     *   all of the files within the directory.  'alias' is ignored in
152
     *   this case, since we construct a URL from the directory path.  If
153
     *   'recurse' is true, we'll also add the contents of any
154
     *   subdirectories found within the given directory; otherwise, we'll
155
     *   only add the files contained directly within the given directory.
156
     */
157
    void add_file(const char *fname, const char *alias, int recurse);
158
159
private:
160
    /* add an item to the list */
161
    void add_element(class CRcResEntry *entry)
162
    {
163
        /* add it to the end of my list */
164
        if (tail_ == 0)
165
            head_ = entry;
166
        else
167
            tail_->set_next(entry);
168
        tail_ = entry;
169
170
        /* count the new element */
171
        ++count_;
172
    }
173
174
    /* head of my list */
175
    class CRcResEntry *head_;
176
177
    /* tail of my list */
178
    class CRcResEntry *tail_;
179
180
    /* number of elements in the list */
181
    unsigned int count_;
182
};
183
184
/*
185
 *   Resource compiler host interface.  This provides access to
186
 *   application operations during resource compilation. 
187
 */
188
class CRcHostIfc
189
{
190
public:
191
    /* display an error message */
192
    virtual void display_error(const char *msg) = 0;
193
194
    /* display a status message */
195
    virtual void display_status(const char *msg) = 0;
196
};
197
198
#endif /* RCMAIN_H */
199