mirror of
https://github.com/libretro/mame2003-plus-libretro.git
synced 2024-11-23 16:29:44 +00:00
Create datmagic.c
This commit is contained in:
parent
69c0a52c16
commit
6a0c1099fd
169
tools/datmagic/datmagic.c
Normal file
169
tools/datmagic/datmagic.c
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
|
||||
Beta version 1 - Jan. 9th 2021
|
||||
by: mahoneyt944 - MAME 2003-Plus Team.
|
||||
|
||||
notes: - currently writes to a log, will work on writing to a html table next.
|
||||
- one issue is present so far, parent roms that use samples are listed as nosampleof
|
||||
because we scan the game tag for the sample name and parents do not list this here.
|
||||
Will probably have to scan for the actual sample.wav lines if sampleof is not found
|
||||
first and end if it reaches a closing tag.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAXCHAR 200
|
||||
|
||||
void banner(void)
|
||||
{
|
||||
printf("\n'########:::::'###::::'########:\n");
|
||||
printf(" ##.... ##:::'## ##:::... ##..::\n");
|
||||
printf(" ##:::: ##::'##:. ##::::: ##::::\n");
|
||||
printf(" ##:::: ##:'##:::. ##:::: ##::::\n");
|
||||
printf(" ##:::: ##: #########:::: ##::::\n");
|
||||
printf(" ##:::: ##: ##.... ##:::: ##::::\n");
|
||||
printf(" ########:: ##:::: ##:::: ##::::\n");
|
||||
printf("........:::..:::::..:::::..:::::\n");
|
||||
printf("'##::::'##::::'###:::::'######:::'####::'######::\n");
|
||||
printf(" ###::'###:::'## ##:::'##... ##::. ##::'##... ##:\n");
|
||||
printf(" ####'####::'##:. ##:: ##:::..:::: ##:: ##:::..::\n");
|
||||
printf(" ## ### ##:'##:::. ##: ##::'####:: ##:: ##:::::::\n");
|
||||
printf(" ##. #: ##: #########: ##::: ##::: ##:: ##:::::::\n");
|
||||
printf(" ##:.:: ##: ##.... ##: ##::: ##::: ##:: ##::: ##:\n");
|
||||
printf(" ##:::: ##: ##:::: ##:. ######:::'####:. ######::\n");
|
||||
printf("..:::::..::..:::::..:::......::::....:::......:::\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
banner();
|
||||
char* dat = "mame2003-plus.xml";
|
||||
FILE *read;
|
||||
FILE *write;
|
||||
char readline[MAXCHAR];
|
||||
|
||||
char game_id[] = "<game name=\"";
|
||||
char driver_id[] = "<driver status=\"";
|
||||
|
||||
char sampleof[] = "sampleof=\"";
|
||||
char color[] = "color=\"";
|
||||
char sound[] = "sound=\"";
|
||||
|
||||
int found = 0;
|
||||
|
||||
|
||||
read = fopen(dat, "r");
|
||||
write = fopen("log.txt", "w");
|
||||
|
||||
if (read == NULL)
|
||||
{
|
||||
printf("\nCould not open DAT file: %s not found in directory.\n\n", dat);
|
||||
return 1;
|
||||
}
|
||||
printf("\nOpening DAT file: %s\n", dat);
|
||||
|
||||
|
||||
/***************** Search the DAT file line by line for ids *****************/
|
||||
while ( fgets(readline, MAXCHAR, read) != NULL )
|
||||
{
|
||||
char *target = NULL;
|
||||
char *start, *end;
|
||||
|
||||
/***************** Read game tag *****************/
|
||||
if ( start = strstr( readline, game_id ) )
|
||||
{
|
||||
start += strlen( game_id );
|
||||
if ( end = strstr( start, "\"" ) )
|
||||
{
|
||||
target = ( char * )malloc( end - start + 1 );
|
||||
memcpy( target, start, end - start );
|
||||
target[end - start] = '\0';
|
||||
|
||||
fputs(target, write);
|
||||
fputs(":", write);
|
||||
free(target);
|
||||
}
|
||||
|
||||
/***************** Check for sampleof *****************/
|
||||
if ( start = strstr( readline, sampleof ) )
|
||||
{
|
||||
start += strlen( sampleof );
|
||||
if ( end = strstr( start, "\"" ) )
|
||||
{
|
||||
target = ( char * )malloc( end - start + 1 );
|
||||
memcpy( target, start, end - start );
|
||||
target[end - start] = '\0';
|
||||
|
||||
fputs(target, write);
|
||||
fputs(":", write);
|
||||
free(target);
|
||||
}
|
||||
}
|
||||
else fputs("nosampleof:", write);
|
||||
|
||||
found++;
|
||||
}
|
||||
|
||||
/***************** Read driver status tag *****************/
|
||||
else if ( start = strstr( readline, driver_id ) )
|
||||
{
|
||||
start += strlen( driver_id );
|
||||
if ( end = strstr( start, "\"" ) )
|
||||
{
|
||||
target = ( char * )malloc( end - start + 1 );
|
||||
memcpy( target, start, end - start );
|
||||
target[end - start] = '\0';
|
||||
|
||||
fputs(target, write);
|
||||
fputs(":", write);
|
||||
free(target);
|
||||
}
|
||||
|
||||
/***************** Check for color *****************/
|
||||
if ( start = strstr( readline, color ) )
|
||||
{
|
||||
start += strlen( color );
|
||||
if ( end = strstr( start, "\"" ) )
|
||||
{
|
||||
target = ( char * )malloc( end - start + 1 );
|
||||
memcpy( target, start, end - start );
|
||||
target[end - start] = '\0';
|
||||
|
||||
fputs(target, write);
|
||||
fputs(":", write);
|
||||
free(target);
|
||||
}
|
||||
}
|
||||
|
||||
/***************** Check for sound *****************/
|
||||
if ( start = strstr( readline, sound ) )
|
||||
{
|
||||
start += strlen( sound );
|
||||
if ( end = strstr( start, "\"" ) )
|
||||
{
|
||||
target = ( char * )malloc( end - start + 1 );
|
||||
memcpy( target, start, end - start );
|
||||
target[end - start] = '\0';
|
||||
|
||||
fputs(target, write);
|
||||
fputs("\n", write);
|
||||
free(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* close up our files */
|
||||
printf("Closing DAT file.\n");
|
||||
fclose(read);
|
||||
fclose(write);
|
||||
|
||||
/* Total games found*/
|
||||
printf("\nRoms found and processed: %i\n\n", found);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user