-
Notifications
You must be signed in to change notification settings - Fork 1
/
rcmaincl.cpp
205 lines (178 loc) · 5.35 KB
/
rcmaincl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#ifdef RCSID
static char RCSid[] =
"$Header$";
#endif
/*
* Copyright (c) 2000, 2002 Michael J. Roberts. All Rights Reserved.
*
* Please see the accompanying license file, LICENSE.TXT, for information
* on using and copying this software.
*/
/*
Name
rcmaincl.cpp - resource compiler - command line interface
Function
Notes
Modified
01/03/00 MJRoberts - Creation
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "os.h"
#include "t3std.h"
#include "rcmain.h"
/*
* Host interface
*/
class MyHostIfc: public CRcHostIfc
{
public:
/* show an error - display it on standard output */
void display_error(const char *msg) { printf("%s\n", msg); }
/* show a status message - display it on standard output */
void display_status(const char *msg) { printf("%s\n", msg); }
};
/*
* Main program entrypoint
*/
int main(int argc, char **argv)
{
int curarg;
int create;
int recurse = TRUE;
const char *image_fname;
CRcResList *res_list = 0;
rcmain_res_op_mode_t op_mode;
int exit_stat;
int err;
MyHostIfc hostifc;
char image_buf[OSFNMAX];
/* assume we will operate on an existing file */
create = FALSE;
/* start out in add-recursive mode */
op_mode = RCMAIN_RES_OP_MODE_ADD;
/* scan options */
for (curarg = 1 ; curarg < argc && argv[curarg][0] == '-' ; ++curarg)
{
switch(argv[curarg][1])
{
case 'c':
if (strcmp(argv[curarg], "-create") == 0)
create = TRUE;
else
goto bad_option;
break;
default:
bad_option:
/* invalid option - skip all arguments so we go to usage */
curarg = argc;
break;
}
}
/* if there's nothing left, show usage */
if (curarg >= argc)
{
show_usage:
/* display usage */
printf("usage: t3res [options] <image-file> [operations]\n"
"Options:\n"
" -create - create a new resource file\n"
"Operations:\n"
" -add - add the following resource files (default)\n"
" -recurse - recursive - include files in "
"subdirectories (default)\n"
" -norecurse - do not include files in subdirectories\n"
" <file> - add the file\n"
" <dir> - add files in the directory\n"
" <file>=<res> - add file, using <res> as resource name\n"
"\n"
"-add is assumed if no conflicting option is specified.\n"
"If no resource name is explicitly provided for a file, "
"the resource is named\n"
"by converting the filename to a URL-style resource name.\n");
/* give up */
exit_stat = OSEXFAIL;
goto done;
}
/* get the image filename */
image_fname = argv[curarg];
/* create our resource list */
res_list = new CRcResList();
/* parse the operations list */
for (++curarg ; curarg < argc ; ++curarg)
{
/* check for an option */
if (argv[curarg][0] == '-')
{
/* see what we have */
if (strcmp(argv[curarg], "-add"))
{
/* set 'add' mode */
op_mode = RCMAIN_RES_OP_MODE_ADD;
}
else if (strcmp(argv[curarg], "-recurse"))
{
/* set recursive mode */
recurse = TRUE;
}
else if (strcmp(argv[curarg], "-norecurse"))
{
/* set non-recursive mode */
recurse = FALSE;
}
else
{
/* invalid option */
goto show_usage;
}
}
else
{
char *p;
char *alias;
/* check for an alias */
for (p = argv[curarg] ; *p != '\0' && *p != '=' ; ++p) ;
if (*p == '=')
{
/*
* overwrite the '=' with a null byte so that the
* filename ends here
*/
*p = '\0';
/* the alias starts after the '=' */
alias = p + 1;
}
else
{
/* there's no alias */
alias = 0;
}
/* it's a file - add the file to the operations list */
res_list->add_file(argv[curarg], alias, recurse);
}
}
/*
* if we're not creating, and the image doesn't exist, try adding
* the default image file extension
*/
if (!create && osfacc(image_fname))
{
strcpy(image_buf, image_fname);
os_defext(image_buf, "t3"); /* formerly "t3x" */
image_fname = image_buf;
}
/* we've parsed the arguments - go apply the operations list */
err = CResCompMain::add_resources(image_fname, res_list,
&hostifc, create, OSFTT3IMG, FALSE);
/* set the appropriate exit status */
exit_stat = (err ? OSEXFAIL : OSEXSUCC);
done:
/* delete the resource list if we created one */
if (res_list != 0)
delete res_list;
/* show any unfreed memory (if we're in a debug build) */
t3_list_memory_blocks(0);
/* exit with current status */
return exit_stat;
}