1 /*
2 
3 	Beta version 5  -  Jan. 17th 2021
4 	by: mahoneyt944 - MAME 2003-Plus Team.
5 
6 	- Still need to generalize the XML DAT and h1 header name instead of hardcoded to 2003+
7 	- Currently tested to be compatible with MAME2003-Plus, MAME2003, MAME2010, MAME2014, MAME2015
8 
9 */
10 
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
14 
15 #define MAXCHAR 250
16 
banner(void)17 void banner(void)
18 {
19 	printf("\n:'########:::::'###::::'########:\n");
20 	printf(  ": ##.... ##:::'## ##:::... ##..::\n");
21 	printf(  ": ##:::: ##::'##:. ##::::: ##::::\n");
22 	printf(  ": ##:::: ##:'##:::. ##:::: ##::::\n");
23 	printf(  ": ##:::: ##: #########:::: ##::::\n");
24 	printf(  ": ##:::: ##: ##.... ##:::: ##::::\n");
25 	printf(  ": ########:: ##:::: ##:::: ##::::\n");
26 	printf(  ":........:::..:::::..:::::..:::::\n");
27 	printf(  ":'##::::'##::::'###:::::'######:::'####::'######::\n");
28 	printf(  ": ###::'###:::'## ##:::'##... ##::. ##::'##... ##:\n");
29 	printf(  ": ####'####::'##:. ##:: ##:::..:::: ##:: ##:::..::\n");
30 	printf(  ": ## ### ##:'##:::. ##: ##::'####:: ##:: ##:::::::\n");
31 	printf(  ": ##. #: ##: #########: ##::: ##::: ##:: ##:::::::\n");
32 	printf(  ": ##:.:: ##: ##.... ##: ##::: ##::: ##:: ##::: ##:\n");
33 	printf(  ": ##:::: ##: ##:::: ##:. ######:::'####:. ######::\n");
34 	printf(  ":..:::::..::..:::::..:::......::::....:::......:::\n");
35 }
36 
main()37 int main()
38 {
39 	banner();
40 	char* dat = "mame2003-plus.xml";
41 	FILE *read;
42 	FILE *write;
43 	char readline[MAXCHAR];
44 
45 	/***************** ID tags *****************/
46 	char game_id[]         = "<game ";
47 	char description_id[]  = "<description>";
48 	char sample_id[]       = "<sample ";
49 	char bios_id[]         = "<biosset ";
50 	char driver_id[]       = "<driver ";
51 	char endgame_id[]      = "</game>";
52 
53 	/***************** Search fields *****************/
54 	char name[]            = "name=\"";
55 	char sampleof[]        = "sampleof=\"";
56 	char runnable[]        = "runnable=\"";
57 	char status[]          = "status=\"";
58 	char emulation[]       = "emulation=\"";
59 	char color[]           = "color=\"";
60 	char sound[]           = "sound=\"";
61 	char graphic[]         = "graphic=\"";
62 	char protection[]      = "protection=\"";
63 
64 	/***************** Flags and counters *****************/
65 	int found=0, parentsample=0, clonesample=0;
66 
67 	/***************** Allocate memory to use *****************/
68 	char *romname          = malloc(sizeof(char) * 30);
69 	char *description      = malloc(sizeof(char) * 150);
70 	char *driverstatus     = malloc(sizeof(char) * 22);
71 	char *emulationstatus  = malloc(sizeof(char) * 20);
72 	char *colorstatus      = malloc(sizeof(char) * 20);
73 	char *soundstatus      = malloc(sizeof(char) * 20);
74 	char *graphicstatus    = malloc(sizeof(char) * 20);
75 	char *protectionstatus = malloc(sizeof(char) * 20);
76 	char *sampleused       = malloc(sizeof(char) * 20);
77 	char *biosused         = malloc(sizeof(char) * 4);
78 
79 
80 	/***************** Try to open the DAT file *****************/
81 	read = fopen(dat, "r");
82 	printf("\nTrying to open the DAT file:  %s\n", dat);
83 
84 	if (read == NULL)
85 	{
86 		printf("Could not open the DAT file:  Not found in directory.\n\n");
87 		return 1;
88 	}
89 
90 	/***************** Open new html file to write to *****************/
91 	write = fopen("mame2003-plus.html", "w");
92 	printf("\nProcessing DAT now.\n");
93 
94 
95 	/***************** Write out html table header *****************/
96 	fputs( "<!DOCTYPE html>\n<html lang=\"en\">\n\n<head>\n", write );
97 	fputs( "\t<meta charset=\"utf-8\"/>\n\t<style type=\"text/css\">\n", write );
98 	fputs( "\t\ttable, th, td {border: 1px solid black; border-collapse: collapse;}\n", write );
99 	fputs( "\t\tth, td {padding: 5px;}\n", write );
100 	fputs( "\t\tth {text-align: left;}\n", write );
101 	fputs( "\t</style>\n\t<title>Compatibility Table</title>\n", write );
102 	fputs( "</head>\n\n<body>\n", write );
103 	fputs( "\t<h1>MAME 2003-Plus</h1>\n\n", write );
104 	fputs( "\t<table style=\"width:100%; background-color:#E6FFEA;\">\n", write );
105 	fputs( "\t\t<tr style=\"background-color:lightgrey;\">\n", write );
106 	fputs( "\t\t\t<th>Roms</th>\n", write );
107 	fputs( "\t\t\t<th style=\"width:400px;\">Description</th>\n", write );
108 	fputs( "\t\t\t<th>Driver status</th>\n", write );
109 	fputs( "\t\t\t<th>Color</th>\n", write );
110 	fputs( "\t\t\t<th>Sound</th>\n", write );
111 	fputs( "\t\t\t<th>Graphics</th>\n", write );
112 	fputs( "\t\t\t<th>Samples</th>\n", write );
113 	fputs( "\t\t\t<th>Bios</th>\n", write );
114 	fputs( "\t\t</tr>\n", write );
115 
116 
117 	/***************** Search the DAT file line by line and process IDs *****************/
118 	while ( fgets(readline, MAXCHAR, read) != NULL )
119 	{
120 		char *target = NULL;
121 		char *start, *end;
122 
123 		/***************** Read game tag *****************/
124 		if (( start = strstr( readline, game_id ) ))
125 		{
126 			/***************** Clear entries when new game is found *****************/
127 			romname[0]         = '\0';		soundstatus[0]      = '\0';
128 			description[0]     = '\0';		graphicstatus[0]    = '\0';
129 			driverstatus[0]    = '\0';		protectionstatus[0] = '\0';
130 			emulationstatus[0] = '\0';		sampleused[0]       = '\0';
131 			colorstatus[0]     = '\0';		biosused[0]         = '\0';
132 
133 
134 			/***************** Check for name *****************/
135 			if (( start = strstr( readline, name ) ))
136 			{
137 				start += strlen( name );
138 				if (( end = strstr( start, "\"" ) ))
139 				{
140 					target = ( char * )malloc( end - start + 1 );
141 					memcpy( target, start, end - start );
142 					target[end - start] = '\0';
143 
144 					strcpy( romname, target );
145 				}
146 			}
147 
148 			/***************** Check for runnable *****************/
149 			if (( start = strstr( readline, runnable ) ))
150 			{
151 				start += strlen( runnable );
152 				if (( end = strstr( start, "\"" ) ))
153 				{
154 					target = ( char * )malloc( end - start + 1 );
155 					memcpy( target, start, end - start );
156 					target[end - start] = '\0';
157 
158 					if ( strcmp( target, "no" ) == 0 ) { romname[0] = '\0'; found--; }
159 				}
160 			}
161 
162 			/***************** Check for sampleof *****************/
163 			if (( start = strstr( readline, sampleof ) ))
164 			{
165 				start += strlen( sampleof );
166 				if (( end = strstr( start, "\"" ) ))
167 				{
168 					target = ( char * )malloc( end - start + 1 );
169 					memcpy( target, start, end - start );
170 					target[end - start] = '\0';
171 					clonesample = 1;
172 
173 					strcpy( sampleused, target );
174 				}
175 			}
176 
177 			found++;
178 		}
179 
180 		/***************** Read description tag *****************/
181 		else if (( start = strstr( readline, description_id ) ))
182 		{
183 			start += strlen( description_id );
184 			if (( end = strstr( start, "<" ) ))
185 			{
186 				target = ( char * )malloc( end - start + 1 );
187 				memcpy( target, start, end - start );
188 				target[end - start] = '\0';
189 
190 				strcpy( description, target );
191 			}
192 		}
193 
194 		/***************** Read sample tag *****************/
195 		else if ( (start = strstr( readline, sample_id )) && !(parentsample) )
196 		{
197 			if (( start = strstr( readline, name ) ))
198 			{
199 				start += strlen( name );
200 				if (( end = strstr( start, "\"" ) ))
201 				{
202 					parentsample = 1;
203 				}
204 			}
205 		}
206 
207 		/***************** Read bios tag *****************/
208 		else if ( (start = strstr( readline, bios_id )) && (biosused[0] == '\0') )
209 		{
210 			if (( start = strstr( readline, name ) ))
211 			{
212 				start += strlen( name );
213 				if (( end = strstr( start, "\"" ) ))
214 				{
215 					strcpy( biosused, "yes" );
216 				}
217 			}
218 		}
219 
220 		/***************** Read driver tag *****************/
221 		else if (( start = strstr( readline, driver_id ) ))
222 		{
223 			/***************** Check for status *****************/
224 			if (( start = strstr( readline, status ) ))
225 			{
226 				start += strlen( status );
227 				if (( end = strstr( start, "\"" ) ))
228 				{
229 					target = ( char * )malloc( end - start + 1 );
230 					memcpy( target, start, end - start );
231 					target[end - start] = '\0';
232 
233 					strcpy( driverstatus, target );
234 				}
235 			}
236 
237 			/***************** Check for emulation *****************/
238 			if (( start = strstr( readline, emulation ) ))
239 			{
240 				start += strlen( emulation );
241 				if (( end = strstr( start, "\"" ) ))
242 				{
243 					target = ( char * )malloc( end - start + 1 );
244 					memcpy( target, start, end - start );
245 					target[end - start] = '\0';
246 
247 					strcpy( emulationstatus, target );
248 				}
249 			}
250 
251 			/***************** Check for color *****************/
252 			if (( start = strstr( readline, color ) ))
253 			{
254 				start += strlen( color );
255 				if (( end = strstr( start, "\"" ) ))
256 				{
257 					target = ( char * )malloc( end - start + 1 );
258 					memcpy( target, start, end - start );
259 					target[end - start] = '\0';
260 
261 					strcpy( colorstatus, target );
262 				}
263 			}
264 
265 			/***************** Check for sound *****************/
266 			if (( start = strstr( readline, sound ) ))
267 			{
268 				start += strlen( sound );
269 				if (( end = strstr( start, "\"" ) ))
270 				{
271 					target = ( char * )malloc( end - start + 1 );
272 					memcpy( target, start, end - start );
273 					target[end - start] = '\0';
274 
275 					strcpy( soundstatus, target );
276 				}
277 			}
278 
279 			/***************** Check for graphic *****************/
280 			if (( start = strstr( readline, graphic ) ))
281 			{
282 				start += strlen( graphic );
283 				if (( end = strstr( start, "\"" ) ))
284 				{
285 					target = ( char * )malloc( end - start + 1 );
286 					memcpy( target, start, end - start );
287 					target[end - start] = '\0';
288 
289 					strcpy( graphicstatus, target );
290 				}
291 			}
292 
293 			/***************** Check for protection *****************/
294 			if (( start = strstr( readline, protection ) ))
295 			{
296 				start += strlen( protection );
297 				if (( end = strstr( start, "\"" ) ))
298 				{
299 					target = ( char * )malloc( end - start + 1 );
300 					memcpy( target, start, end - start );
301 					target[end - start] = '\0';
302 
303 					strcpy( protectionstatus, target );
304 				}
305 			}
306 		}
307 
308 		/***************** Read end game tag *****************/
309 		else if (( start = strstr( readline, endgame_id ) ))
310 		{
311 			if ( romname[0] != '\0' )
312 			{
313 				/***************** Configure parent sample *****************/
314 				if ( parentsample && !clonesample ) strcpy( sampleused, romname );
315 				else if ( !parentsample && !clonesample ) sampleused[0] = '\0';
316 
317 
318 				/***************** Write out html table data *****************/
319 				fputs( "\t\t<tr>\n\t\t\t<td>", write );
320 				fputs( romname, write );
321 				fputs( "</td>\n\t\t\t", write );
322 
323 
324 				fputs( "<td>", write );
325 				fputs( description, write );
326 				fputs( "</td>\n\t\t\t", write );
327 
328 
329 				if ( (strcmp(driverstatus, "preliminary") == 0  && emulationstatus[0] == '\0') || (strcmp(emulationstatus, "preliminary") == 0) )
330 					fputs( "<td style=\"background-color:pink;\">game not working", write );
331 				else if ( (strcmp(driverstatus, "protection") == 0) || (strcmp(protectionstatus, "preliminary") == 0) )
332 					fputs( "<td style=\"background-color:pink;\">unemulated protection", write );
333 				else if ( strcmp(driverstatus, "preliminary") == 0 )
334 					fputs( "<td style=\"background-color:pink;\">preliminary", write );
335 				else if ( strcmp(driverstatus, "imperfect") == 0 )
336 					fputs( "<td style=\"background-color:#F4F4B9;\">imperfect", write );
337 				else
338 					fputs( "<td>good", write );
339 				fputs( "</td>\n\t\t\t", write );
340 
341 
342 				if ( strcmp(colorstatus, "preliminary") == 0 )
343 					fputs( "<td style=\"background-color:pink;\">wrong colors", write );
344 				else if ( strcmp(colorstatus, "imperfect") == 0 )
345 					fputs( "<td style=\"background-color:#F4F4B9;\">imperfect colors", write );
346 				else
347 					fputs( "<td>good", write );
348 				fputs( "</td>\n\t\t\t", write );
349 
350 
351 				if ( strcmp(soundstatus, "preliminary") == 0 )
352 					fputs( "<td style=\"background-color:pink;\">no sound", write );
353 				else if ( strcmp(soundstatus, "imperfect") == 0 )
354 					fputs( "<td style=\"background-color:#F4F4B9;\">imperfect sound", write );
355 				else
356 					fputs( "<td>good", write );
357 				fputs( "</td>\n\t\t\t", write );
358 
359 
360 				if ( strcmp(graphicstatus, "imperfect") == 0 )
361 					fputs( "<td style=\"background-color:#F4F4B9\">imperfect graphics", write );
362 				else
363 					fputs( "<td>good", write );
364 				fputs( "</td>\n\t\t\t", write );
365 
366 
367 				fputs( "<td>", write );
368 				if ( sampleused[0] != '\0' )
369 					fputs( sampleused, write );
370 				fputs( "</td>\n\t\t\t", write );
371 
372 
373 				fputs( "<td>", write );
374 				if ( biosused[0] != '\0' )
375 					fputs( biosused, write );
376 				fputs( "</td>\n\t\t</tr>\n", write );
377 			}
378 
379 			/***************** Reset flags *****************/
380 			parentsample = 0;
381 			clonesample = 0;
382 		}
383 
384 		free( target );
385 
386 	}
387 
388 	/***************** Free memory *****************/
389 	free( romname );
390 	free( description );
391 	free( driverstatus );
392 	free( emulationstatus );
393 	free( colorstatus );
394 	free( soundstatus );
395 	free( graphicstatus );
396 	free( protectionstatus );
397 	free( sampleused );
398 	free( biosused );
399 
400 	/***************** Close up our files *****************/
401 	printf("Closing DAT file.\n");
402 	fputs( "\t</table>\n</body>\n\n</html>\n", write );
403 	fclose(read);
404 	fclose(write);
405 
406 	/***************** Total games found *****************/
407 	printf("\nRoms found and processed:  %i\n\n", found);
408 
409 	return 0;
410 }
411