~ubuntu-branches/ubuntu/quantal/vice/quantal

« back to all changes in this revision

Viewing changes to src/arch/win32/utils/genwinres.c

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2009-03-31 00:37:15 UTC
  • mfrom: (1.1.7 upstream) (9.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090331003715-i5yisvcfv7mgz3eh
Tags: 2.1.dfsg-1
* New major upstream release (closes: #495937).
* Add desktop files (closes: #501181).

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#define SKIP_LINE                4
37
37
#define OUTPUT_LINE              5
38
38
 
39
 
void process_file(char *filename, FILE *output)
 
39
void process_file(char *filename, FILE *houtput, FILE *moutput)
40
40
{
41
41
FILE *infile;
42
42
int state;
43
 
int res_value;
 
43
int res_value = 0;
 
44
int is_idm = 0;
44
45
 
45
46
    infile = fopen(filename, "rb");
46
47
    if (infile) {
51
52
            while (buffer_readpointer < buffer_size) {
52
53
                switch (state) {
53
54
                    case GET_HEADER_FIRST_BYTE:
 
55
                        is_idm = 0;
54
56
                        header[0] = buffer[buffer_readpointer];
55
57
                        if ((header[0] == 0x0a) || (header[1] == 0x0d)) {
56
58
                            // Empty line, find start of next line.
83
85
                        } else {
84
86
                            if ((header[0] == 'I') && (header[1] == 'D') && (header[2] == 'R')) {
85
87
                                res_value = idr_counter++;
86
 
                                fprintf(output, "#define ");
87
 
                                fwrite(header, 1, 3, output);
 
88
                                fprintf(houtput, "#define ");
 
89
                                fwrite(header, 1, 3, houtput);
88
90
                                state = OUTPUT_LINE;
89
91
                            } else if ((header[0] == 'I') && (header[1] == 'D') && (header[2] == 'D')) {
90
92
                                res_value = idd_counter++;
91
 
                                fprintf(output, "#define ");
92
 
                                fwrite(header, 1, 3, output);
 
93
                                fprintf(houtput, "#define ");
 
94
                                fwrite(header, 1, 3, houtput);
93
95
                                state = OUTPUT_LINE;
94
96
                            } else if ((header[0] == 'I') && (header[1] == 'D') && (header[2] == 'C')) {
95
97
                                res_value = idc_counter++;
96
 
                                fprintf(output, "#define ");
97
 
                                fwrite(header, 1, 3, output);
 
98
                                fprintf(houtput, "#define ");
 
99
                                fwrite(header, 1, 3, houtput);
98
100
                                state = OUTPUT_LINE;
99
101
                            } else if ((header[0] == 'I') && (header[1] == 'D') && (header[2] == 'S')) {
100
102
                                res_value = ids_counter++;
101
 
                                fprintf(output, "#define ");
102
 
                                fwrite(header, 1, 3, output);
 
103
                                fprintf(houtput, "#define ");
 
104
                                fwrite(header, 1, 3, houtput);
103
105
                                state = OUTPUT_LINE;
104
106
                            } else if ((header[0] == 'I') && (header[1] == 'D') && (header[2] == 'M')) {
105
107
                                res_value = idm_counter++;
106
 
                                fprintf(output, "#define ");
107
 
                                fwrite(header, 1, 3, output);
 
108
                                is_idm = 1;
 
109
                                fprintf(houtput, "#define ");
 
110
                                fwrite(header, 1, 3, houtput);
 
111
                                fprintf(moutput, "  { \"");
 
112
                                fwrite(header, 1, 3, moutput);
108
113
                                state = OUTPUT_LINE;
109
114
                            } else if ((header[0] == 'I') && (header[1] == 'D') && (header[2] == 'I')) {
110
115
                                res_value = idi_counter++;
111
 
                                fprintf(output, "#define ");
112
 
                                fwrite(header, 1, 3, output);
 
116
                                fprintf(houtput, "#define ");
 
117
                                fwrite(header, 1, 3, houtput);
113
118
                                state = OUTPUT_LINE;
114
119
                            } else {
115
120
                                res_value = general_counter++;
116
 
                                fprintf(output, "#define ");
117
 
                                fwrite(header, 1, 3, output);
 
121
                                fprintf(houtput, "#define ");
 
122
                                fwrite(header, 1, 3, houtput);
118
123
                                state = OUTPUT_LINE;
119
124
                            }
120
125
                        }
135
140
                        break;
136
141
                    case OUTPUT_LINE:
137
142
                        if ((buffer[buffer_readpointer] == 0x0a) || (buffer[buffer_readpointer] == 0x0d)) {
138
 
                            fprintf(output, " %d\n", res_value);
 
143
                            fprintf(houtput, " %d\n", res_value);
 
144
                            if (is_idm)
 
145
                                fprintf(moutput, "\", %d }, \n", res_value);
139
146
                            state = GET_HEADER_FIRST_BYTE;
140
147
                        } else {
141
 
                            fwrite(&buffer[buffer_readpointer], 1, 1, output);
 
148
                            fwrite(&buffer[buffer_readpointer], 1, 1, houtput);
 
149
                            if (is_idm)
 
150
                                fwrite(&buffer[buffer_readpointer], 1, 1, moutput);
142
151
                        }
143
152
                        buffer_readpointer++;
144
153
                        break;
150
159
}
151
160
 
152
161
 
153
 
void main(int argc, char **argv)
 
162
int main(int argc, char **argv)
154
163
{
155
 
FILE *output;
 
164
FILE *houtput, *moutput;
156
165
int i;
157
166
 
158
 
    if (argc < 3) {
159
 
        printf("Usage: genwinres output-filename source-filename [source-filenames]\n");
 
167
    if (argc < 4) {
 
168
        printf("Usage: genwinres header-houtput menuid-houtput source-filename [source-filenames]\n");
160
169
        exit(0);
161
170
    }
162
 
    output = fopen(argv[1], "wt");
163
 
    if (output) {
 
171
    houtput = fopen(argv[1], "wt");
 
172
    moutput = fopen(argv[2], "wt");
 
173
    if (houtput && moutput) {
164
174
        idr_start = idr_counter = 100;
165
175
        idd_start = idd_counter = 100;
166
176
        /* Command ID codes 0-11 and 32000 are used by the OS as well, to be safe we start at 100 */
170
180
        idi_start = idi_counter = 1;
171
181
        general_start = general_counter = 1;
172
182
 
173
 
        fprintf(output, "/*\n");
174
 
        fprintf(output, " * %s\n", argv[1]);
175
 
        fprintf(output, " *\n");
176
 
        fprintf(output, " * Autogenerated genwinres file, DO NOT EDIT !!!\n");
177
 
        fprintf(output, " *\n");
178
 
        fprintf(output, " * Written by\n");
179
 
        fprintf(output, " *  Andreas Boose <viceteam@t-online.de>\n");
180
 
        fprintf(output, " *  Ettore Perazzoli <ettore@comm2000.it>\n");
181
 
        fprintf(output, " *  Tibor Biczo <crown@t-online.hu>\n");
182
 
        fprintf(output, " *\n");
183
 
        fprintf(output, " * This file is part of VICE, the Versatile Commodore Emulator.\n");
184
 
        fprintf(output, " * See README for copyright notice.\n");
185
 
        fprintf(output, " *\n");
186
 
        fprintf(output, " *  This program is free software; you can redistribute it and/or modify\n");
187
 
        fprintf(output, " *  it under the terms of the GNU General Public License as published by\n");
188
 
        fprintf(output, " *  the Free Software Foundation; either version 2 of the License, or\n");
189
 
        fprintf(output, " *  (at your option) any later version.\n");
190
 
        fprintf(output, " *\n");
191
 
        fprintf(output, " *  This program is distributed in the hope that it will be useful,\n");
192
 
        fprintf(output, " *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
193
 
        fprintf(output, " *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
194
 
        fprintf(output, " *  GNU General Public License for more details.\n");
195
 
        fprintf(output, " *\n");
196
 
        fprintf(output, " *  You should have received a copy of the GNU General Public License\n");
197
 
        fprintf(output, " *  along with this program; if not, write to the Free Software\n");
198
 
        fprintf(output, " *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\n");
199
 
        fprintf(output, " *  02111-1307  USA.\n");
200
 
        fprintf(output, " *\n");
201
 
        fprintf(output, " */\n");
202
 
        fprintf(output, "\n");
203
 
        fprintf(output, "#ifndef _RES_H\n");
204
 
        fprintf(output, "#define _RES_H\n");
205
 
        fprintf(output, "\n");
206
 
 
207
 
        for (i = 2; i < argc; i++) {
208
 
            fprintf(output, "/*  Definitions from %s  */\n\n", argv[i]);
209
 
            process_file(argv[i], output);
210
 
            fprintf(output, "\n");
 
183
        fprintf(houtput, "/*\n");
 
184
        fprintf(houtput, " * %s\n", argv[1]);
 
185
        fprintf(houtput, " *\n");
 
186
        fprintf(houtput, " * Autogenerated genwinres file, DO NOT EDIT !!!\n");
 
187
        fprintf(houtput, " *\n");
 
188
        fprintf(houtput, " * Written by\n");
 
189
        fprintf(houtput, " *  Andreas Boose <viceteam@t-online.de>\n");
 
190
        fprintf(houtput, " *  Ettore Perazzoli <ettore@comm2000.it>\n");
 
191
        fprintf(houtput, " *  Tibor Biczo <crown@t-online.hu>\n");
 
192
        fprintf(houtput, " *\n");
 
193
        fprintf(houtput, " * This file is part of VICE, the Versatile Commodore Emulator.\n");
 
194
        fprintf(houtput, " * See README for copyright notice.\n");
 
195
        fprintf(houtput, " *\n");
 
196
        fprintf(houtput, " *  This program is free software; you can redistribute it and/or modify\n");
 
197
        fprintf(houtput, " *  it under the terms of the GNU General Public License as published by\n");
 
198
        fprintf(houtput, " *  the Free Software Foundation; either version 2 of the License, or\n");
 
199
        fprintf(houtput, " *  (at your option) any later version.\n");
 
200
        fprintf(houtput, " *\n");
 
201
        fprintf(houtput, " *  This program is distributed in the hope that it will be useful,\n");
 
202
        fprintf(houtput, " *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
 
203
        fprintf(houtput, " *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
 
204
        fprintf(houtput, " *  GNU General Public License for more details.\n");
 
205
        fprintf(houtput, " *\n");
 
206
        fprintf(houtput, " *  You should have received a copy of the GNU General Public License\n");
 
207
        fprintf(houtput, " *  along with this program; if not, write to the Free Software\n");
 
208
        fprintf(houtput, " *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\n");
 
209
        fprintf(houtput, " *  02111-1307  USA.\n");
 
210
        fprintf(houtput, " *\n");
 
211
        fprintf(houtput, " */\n");
 
212
        fprintf(houtput, "\n");
 
213
        fprintf(houtput, "#ifndef _RES_H\n");
 
214
        fprintf(houtput, "#define _RES_H\n");
 
215
        fprintf(houtput, "\n");
 
216
 
 
217
        fprintf(moutput, "/*\n");
 
218
        fprintf(moutput, " * %s\n", argv[2]);
 
219
        fprintf(moutput, " *\n");
 
220
        fprintf(moutput, " * Autogenerated genwinres file, DO NOT EDIT !!!\n");
 
221
        fprintf(moutput, " *\n");
 
222
        fprintf(moutput, " */\n");
 
223
        fprintf(moutput, "#ifndef _MENUID_H\n");
 
224
        fprintf(moutput, "#define _MENUID_H\n");
 
225
        fprintf(moutput, "\n");
 
226
        fprintf(moutput, "static struct { char *str; int cmd; } idmlist[] = {\n");
 
227
 
 
228
        for (i = 3; i < argc; i++) {
 
229
            fprintf(houtput, "/*  Definitions from %s  */\n\n", argv[i]);
 
230
            process_file(argv[i], houtput, moutput);
 
231
            fprintf(houtput, "\n");
211
232
        }
212
 
        fprintf(output, "#define FIRST_IDR %d\n", idr_start);
213
 
        fprintf(output, "#define LAST_IDR %d\n", idr_counter);
214
 
        fprintf(output, "#define FIRST_IDD %d\n", idd_start);
215
 
        fprintf(output, "#define LAST_IDD %d\n", idd_counter);
216
 
        fprintf(output, "#define FIRST_IDC %d\n", idc_start);
217
 
        fprintf(output, "#define LAST_IDC %d\n", idc_counter);
218
 
        fprintf(output, "#define FIRST_IDS %d\n", ids_start);
219
 
        fprintf(output, "#define LAST_IDS %d\n", ids_counter);
220
 
        fprintf(output, "#define FIRST_IDM %d\n", idm_start);
221
 
        fprintf(output, "#define LAST_IDM %d\n", idm_counter);
222
 
        fprintf(output, "#define FIRST_IDI %d\n", idi_start);
223
 
        fprintf(output, "#define LAST_IDI %d\n", idi_counter);
224
 
        fprintf(output, "#define FIRST_GENERAL %d\n", general_start);
225
 
        fprintf(output, "#define LAST_GENERAL %d\n", general_counter);
226
 
        fprintf(output, "\n");
227
 
        fprintf(output, "#endif\n");
228
 
 
229
 
        fclose(output);
 
233
        fprintf(houtput, "#define FIRST_IDR %d\n", idr_start);
 
234
        fprintf(houtput, "#define LAST_IDR %d\n", idr_counter);
 
235
        fprintf(houtput, "#define FIRST_IDD %d\n", idd_start);
 
236
        fprintf(houtput, "#define LAST_IDD %d\n", idd_counter);
 
237
        fprintf(houtput, "#define FIRST_IDC %d\n", idc_start);
 
238
        fprintf(houtput, "#define LAST_IDC %d\n", idc_counter);
 
239
        fprintf(houtput, "#define FIRST_IDS %d\n", ids_start);
 
240
        fprintf(houtput, "#define LAST_IDS %d\n", ids_counter);
 
241
        fprintf(houtput, "#define FIRST_IDM %d\n", idm_start);
 
242
        fprintf(houtput, "#define LAST_IDM %d\n", idm_counter);
 
243
        fprintf(houtput, "#define FIRST_IDI %d\n", idi_start);
 
244
        fprintf(houtput, "#define LAST_IDI %d\n", idi_counter);
 
245
        fprintf(houtput, "#define FIRST_GENERAL %d\n", general_start);
 
246
        fprintf(houtput, "#define LAST_GENERAL %d\n", general_counter);
 
247
        fprintf(houtput, "\n");
 
248
        fprintf(houtput, "#endif\n");
 
249
 
 
250
        fprintf(moutput, " { NULL, 0 }\n};\n");
 
251
        fprintf(moutput, "#endif\n");
 
252
 
 
253
        fclose(houtput);
 
254
        fclose(moutput);
230
255
    }
231
256
}
232
257