Debian Codegraph @

terps/tads/tads3/rcmaincl.cpp

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