mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
The code comes from the RGBDS source and documentation zip files found on this website: http://www.otakunozoku.com/1999/08/01/rednex-gameboy-development-system/ The same website reports: "Best of all, it’s free! That’s right! Free! The executables are free to use, either for personal hobby use, or full blown commercial productions — I know of at least a dozen commercial games you can purchase that are written with RGBDS — and the source code is free to modify. "The only thing I ask is that you do not charge for either distributing the executables or source code, and any derivative works you give credit to the original authors of the tools. That means you have to say “Thanks” to the original authors SurfSmurf and Otaku." Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
143 lines
2.4 KiB
C
143 lines
2.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
|
|
#include "asmotor.h"
|
|
#include "types.h"
|
|
#include "library.h"
|
|
|
|
// Quick and dirty...but it works
|
|
#ifdef __GNUC__
|
|
#define strcmpi strcasecmp
|
|
#endif
|
|
|
|
/*
|
|
* Print out an errormessage
|
|
*
|
|
*/
|
|
|
|
void fatalerror( char *s )
|
|
{
|
|
printf( "*ERROR* : %s\n", s );
|
|
exit( 5 );
|
|
}
|
|
|
|
/*
|
|
* Print the usagescreen
|
|
*
|
|
*/
|
|
|
|
void PrintUsage( void )
|
|
{
|
|
printf( "xLib v" LIB_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\n"
|
|
"Usage: xlib library command [module1 module2 ... modulen]\n"
|
|
"Commands:\n\ta\tAdd/replace modules to library\n"
|
|
"\td\tDelete modules from library\n"
|
|
"\tl\tList library contents\n"
|
|
"\tx\tExtract modules from library\n" );
|
|
exit( 0 );
|
|
}
|
|
|
|
/*
|
|
* The main routine
|
|
*
|
|
*/
|
|
|
|
int main( int argc, char *argv[] )
|
|
{
|
|
SLONG argn=0;
|
|
char *libname;
|
|
|
|
argc-=1;
|
|
argn+=1;
|
|
|
|
if( argc>=2 )
|
|
{
|
|
UBYTE command;
|
|
sLibrary *lib;
|
|
|
|
lib=lib_Read( libname=argv[argn++] );
|
|
argc-=1;
|
|
|
|
if( strlen(argv[argn])==1 )
|
|
{
|
|
command=argv[argn++][0];
|
|
argc-=1;
|
|
|
|
switch( tolower(command) )
|
|
{
|
|
case 'a':
|
|
while( argc )
|
|
{
|
|
lib=lib_AddReplace( lib, argv[argn++] );
|
|
argc-=1;
|
|
}
|
|
lib_Write( lib, libname );
|
|
lib_Free( lib );
|
|
break;
|
|
case 'd':
|
|
while( argc )
|
|
{
|
|
lib=lib_DeleteModule( lib, argv[argn++] );
|
|
argc-=1;
|
|
}
|
|
lib_Write( lib, libname );
|
|
lib_Free( lib );
|
|
break;
|
|
case 'l':
|
|
{
|
|
sLibrary *l;
|
|
|
|
l=lib;
|
|
|
|
while( l )
|
|
{
|
|
printf( "%10d %s\n", l->nByteLength, l->tName );
|
|
l=l->pNext;
|
|
}
|
|
}
|
|
break;
|
|
case 'x':
|
|
while( argc )
|
|
{
|
|
sLibrary *l;
|
|
|
|
l=lib_Find( lib, argv[argn] );
|
|
if( l )
|
|
{
|
|
FILE *f;
|
|
|
|
if( f=fopen(argv[argn],"wb") )
|
|
{
|
|
fwrite( l->pData, sizeof(UBYTE), l->nByteLength, f );
|
|
fclose( f );
|
|
printf( "Extracted module '%s'\n", argv[argn] );
|
|
}
|
|
else
|
|
fatalerror( "Unable to write module" );
|
|
}
|
|
else
|
|
fatalerror( "Module not found" );
|
|
|
|
argn+=1;
|
|
argc-=1;
|
|
}
|
|
lib_Free( lib );
|
|
break;
|
|
default:
|
|
fatalerror( "Invalid command" );
|
|
break;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
fatalerror( "Invalid command" );
|
|
}
|
|
}
|
|
else
|
|
PrintUsage();
|
|
|
|
return( 0 );
|
|
} |