Run `indent' on the whole tree

Can't indent the .y files yet, they need special treatment.

Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
This commit is contained in:
Vegard Nossum
2009-06-11 07:59:46 +02:00
parent 660f5daac3
commit b6c749ffbd
47 changed files with 5105 additions and 5495 deletions

View File

@@ -3,11 +3,11 @@
#include "libwrap.h"
extern sLibrary *lib_Read( char *filename );
extern BBOOL lib_Write( sLibrary *lib, char *filename );
extern sLibrary *lib_AddReplace( sLibrary *lib, char *filename );
extern void lib_Free( sLibrary *lib );
extern sLibrary *lib_DeleteModule( sLibrary *lib, char *filename );
extern sLibrary *lib_Find( sLibrary *lib, char *filename );
extern sLibrary *lib_Read(char *filename);
extern BBOOL lib_Write(sLibrary * lib, char *filename);
extern sLibrary *lib_AddReplace(sLibrary * lib, char *filename);
extern void lib_Free(sLibrary * lib);
extern sLibrary *lib_DeleteModule(sLibrary * lib, char *filename);
extern sLibrary *lib_Find(sLibrary * lib, char *filename);
#endif
#endif

View File

@@ -5,16 +5,15 @@
#define MAXNAMELENGTH 256
struct LibraryWrapper
{
char tName[MAXNAMELENGTH];
UWORD uwTime;
UWORD uwDate;
SLONG nByteLength;
UBYTE *pData;
struct LibraryWrapper *pNext;
struct LibraryWrapper {
char tName[MAXNAMELENGTH];
UWORD uwTime;
UWORD uwDate;
SLONG nByteLength;
UBYTE *pData;
struct LibraryWrapper *pNext;
};
typedef struct LibraryWrapper sLibrary;
typedef struct LibraryWrapper sLibrary;
#endif
#endif

View File

@@ -5,12 +5,12 @@
#define _MAX_PATH 512
#endif
typedef unsigned char UBYTE;
typedef signed char SBYTE;
typedef unsigned short UWORD;
typedef signed short SWORD;
typedef unsigned long ULONG;
typedef signed long SLONG;
typedef signed char BBOOL;
typedef unsigned char UBYTE;
typedef signed char SBYTE;
typedef unsigned short UWORD;
typedef signed short SWORD;
typedef unsigned long ULONG;
typedef signed long SLONG;
typedef signed char BBOOL;
#endif
#endif

View File

@@ -4,305 +4,286 @@
#include "types.h"
#include "libwrap.h"
extern void fatalerror( char *s );
extern void fatalerror(char *s);
SLONG file_Length( FILE *f )
SLONG file_Length(FILE * f)
{
ULONG r,
p;
ULONG r, p;
p=ftell( f );
fseek( f, 0, SEEK_END );
r=ftell( f );
fseek( f, p, SEEK_SET );
p = ftell(f);
fseek(f, 0, SEEK_END);
r = ftell(f);
fseek(f, p, SEEK_SET);
return( r );
return (r);
}
SLONG file_ReadASCIIz( char *b, FILE *f )
SLONG file_ReadASCIIz(char *b, FILE * f)
{
SLONG r=0;
SLONG r = 0;
while( (*b++ = fgetc(f))!=0 )
r+=1;
while ((*b++ = fgetc(f)) != 0)
r += 1;
return( r+1 );
return (r + 1);
}
void file_WriteASCIIz( char *b, FILE *f )
void file_WriteASCIIz(char *b, FILE * f)
{
while( *b )
fputc(*b++,f);
while (*b)
fputc(*b++, f);
fputc( 0, f );
fputc(0, f);
}
UWORD file_ReadWord( FILE *f )
UWORD file_ReadWord(FILE * f)
{
UWORD r;
UWORD r;
r =fgetc( f );
r|=fgetc( f )<<8;
r = fgetc(f);
r |= fgetc(f) << 8;
return( r );
return (r);
}
void file_WriteWord( UWORD w, FILE *f )
void file_WriteWord(UWORD w, FILE * f)
{
fputc( w, f );
fputc( w>>8, f );
fputc(w, f);
fputc(w >> 8, f);
}
ULONG file_ReadLong( FILE *f )
ULONG file_ReadLong(FILE * f)
{
ULONG r;
ULONG r;
r =fgetc( f );
r|=fgetc( f )<<8;
r|=fgetc( f )<<16;
r|=fgetc( f )<<24;
r = fgetc(f);
r |= fgetc(f) << 8;
r |= fgetc(f) << 16;
r |= fgetc(f) << 24;
return( r );
return (r);
}
void file_WriteLong( UWORD w, FILE *f )
void file_WriteLong(UWORD w, FILE * f)
{
fputc( w, f );
fputc( w>>8, f );
fputc( w>>16, f );
fputc( w>>24, f );
fputc(w, f);
fputc(w >> 8, f);
fputc(w >> 16, f);
fputc(w >> 24, f);
}
sLibrary *lib_ReadLib0( FILE *f, SLONG size )
sLibrary *lib_ReadLib0(FILE * f, SLONG size)
{
if( size )
{
sLibrary *l=NULL,
*first=NULL;
if (size) {
sLibrary *l = NULL, *first = NULL;
while( size>0 )
{
if( l==NULL )
{
if( (l=(sLibrary *)malloc(sizeof(sLibrary)))==NULL )
fatalerror( "Out of memory" );
while (size > 0) {
if (l == NULL) {
if ((l =
(sLibrary *) malloc(sizeof(sLibrary))) ==
NULL)
fatalerror("Out of memory");
first=l;
}
else
{
if( (l->pNext=(sLibrary *)malloc(sizeof(sLibrary)))==NULL )
fatalerror( "Out of memory" );
l=l->pNext;
first = l;
} else {
if ((l->pNext =
(sLibrary *) malloc(sizeof(sLibrary))) ==
NULL)
fatalerror("Out of memory");
l = l->pNext;
}
size-=file_ReadASCIIz( l->tName, f );
l->uwTime=file_ReadWord( f ); size-=2;
l->uwDate=file_ReadWord( f ); size-=2;
l->nByteLength=file_ReadLong( f ); size-=4;
if( l->pData=(UBYTE *)malloc(l->nByteLength) )
{
fread( l->pData, sizeof(UBYTE), l->nByteLength, f );
size-=l->nByteLength;
}
else
fatalerror( "Out of memory" );
size -= file_ReadASCIIz(l->tName, f);
l->uwTime = file_ReadWord(f);
size -= 2;
l->uwDate = file_ReadWord(f);
size -= 2;
l->nByteLength = file_ReadLong(f);
size -= 4;
if (l->pData = (UBYTE *) malloc(l->nByteLength)) {
fread(l->pData, sizeof(UBYTE), l->nByteLength,
f);
size -= l->nByteLength;
} else
fatalerror("Out of memory");
l->pNext=NULL;
l->pNext = NULL;
}
return( first );
return (first);
}
return( NULL );
return (NULL);
}
sLibrary *lib_Read( char *filename )
sLibrary *lib_Read(char *filename)
{
FILE *f;
FILE *f;
if( f=fopen(filename,"rb") )
{
SLONG size;
char ID[5];
if (f = fopen(filename, "rb")) {
SLONG size;
char ID[5];
size=file_Length( f );
if( size==0 )
{
fclose( f );
return( NULL );
size = file_Length(f);
if (size == 0) {
fclose(f);
return (NULL);
}
fread( ID, sizeof(char), 4, f );
ID[4]=0;
size-=4;
fread(ID, sizeof(char), 4, f);
ID[4] = 0;
size -= 4;
if( strcmp(ID,"XLB0")==0 )
{
sLibrary *r;
if (strcmp(ID, "XLB0") == 0) {
sLibrary *r;
r=lib_ReadLib0( f, size );
fclose( f );
printf( "Library '%s' opened\n", filename );
return( r );
r = lib_ReadLib0(f, size);
fclose(f);
printf("Library '%s' opened\n", filename);
return (r);
} else {
fclose(f);
fatalerror("Not a valid xLib library");
return (NULL);
}
else
{
fclose( f );
fatalerror( "Not a valid xLib library" );
return( NULL );
}
}
else
{
printf( "Library '%s' not found, it will be created if necessary\n", filename );
return( NULL );
} else {
printf
("Library '%s' not found, it will be created if necessary\n",
filename);
return (NULL);
}
}
BBOOL lib_Write( sLibrary *lib, char *filename )
BBOOL lib_Write(sLibrary * lib, char *filename)
{
FILE *f;
FILE *f;
if( f=fopen(filename,"wb") )
{
fwrite( "XLB0", sizeof(char), 4, f );
while( lib )
{
file_WriteASCIIz( lib->tName, f );
file_WriteWord( lib->uwTime, f );
file_WriteWord( lib->uwDate, f );
file_WriteLong( lib->nByteLength, f );
fwrite( lib->pData, sizeof(UBYTE), lib->nByteLength,f );
lib=lib->pNext;
if (f = fopen(filename, "wb")) {
fwrite("XLB0", sizeof(char), 4, f);
while (lib) {
file_WriteASCIIz(lib->tName, f);
file_WriteWord(lib->uwTime, f);
file_WriteWord(lib->uwDate, f);
file_WriteLong(lib->nByteLength, f);
fwrite(lib->pData, sizeof(UBYTE), lib->nByteLength, f);
lib = lib->pNext;
}
fclose( f );
printf( "Library '%s' closed\n", filename );
return( 1 );
fclose(f);
printf("Library '%s' closed\n", filename);
return (1);
}
return( 0 );
return (0);
}
void TruncateFileName( char *dest, char *src )
void TruncateFileName(char *dest, char *src)
{
SLONG l;
SLONG l;
l=strlen( src )-1;
while( (l>=0) && (src[l]!='\\') && (src[l]!='/') )
l-=1;
l = strlen(src) - 1;
while ((l >= 0) && (src[l] != '\\') && (src[l] != '/'))
l -= 1;
strcpy( dest, &src[l+1] );
strcpy(dest, &src[l + 1]);
}
sLibrary *lib_Find( sLibrary *lib, char *filename )
sLibrary *lib_Find(sLibrary * lib, char *filename)
{
char truncname[MAXNAMELENGTH];
char truncname[MAXNAMELENGTH];
TruncateFileName( truncname, filename );
TruncateFileName(truncname, filename);
while( lib )
{
if( strcmp(lib->tName,truncname)==0 )
while (lib) {
if (strcmp(lib->tName, truncname) == 0)
break;
lib=lib->pNext;
lib = lib->pNext;
}
return( lib );
return (lib);
}
sLibrary *lib_AddReplace( sLibrary *lib, char *filename )
sLibrary *lib_AddReplace(sLibrary * lib, char *filename)
{
FILE *f;
FILE *f;
if( f=fopen(filename,"rb") )
{
sLibrary *module;
char truncname[MAXNAMELENGTH];
if (f = fopen(filename, "rb")) {
sLibrary *module;
char truncname[MAXNAMELENGTH];
TruncateFileName( truncname, filename );
TruncateFileName(truncname, filename);
if( (module=lib_Find(lib,filename))==NULL )
{
if( module=(sLibrary *)malloc(sizeof(sLibrary)) )
{
module->pNext=lib;
lib=module;
}
else
fatalerror( "Out of memory" );
}
else
{
if ((module = lib_Find(lib, filename)) == NULL) {
if (module = (sLibrary *) malloc(sizeof(sLibrary))) {
module->pNext = lib;
lib = module;
} else
fatalerror("Out of memory");
} else {
/* Module already exists */
free( module->pData );
free(module->pData);
}
module->nByteLength=file_Length( f );
strcpy( module->tName, truncname );
if( module->pData=(UBYTE *)malloc(module->nByteLength) )
{
fread( module->pData, sizeof(UBYTE), module->nByteLength, f );
module->nByteLength = file_Length(f);
strcpy(module->tName, truncname);
if (module->pData = (UBYTE *) malloc(module->nByteLength)) {
fread(module->pData, sizeof(UBYTE), module->nByteLength,
f);
}
printf( "Added module '%s'\n", truncname );
printf("Added module '%s'\n", truncname);
fclose( f );
fclose(f);
}
return( lib );
return (lib);
}
sLibrary *lib_DeleteModule( sLibrary *lib, char *filename )
sLibrary *lib_DeleteModule(sLibrary * lib, char *filename)
{
char truncname[MAXNAMELENGTH];
sLibrary **pp,
**first;
BBOOL found=0;
char truncname[MAXNAMELENGTH];
sLibrary **pp, **first;
BBOOL found = 0;
pp=&lib;
first=pp;
pp = &lib;
first = pp;
TruncateFileName( truncname, filename );
while( (*pp) && (!found) )
{
if( strcmp((*pp)->tName,truncname)==0 )
{
sLibrary *t;
TruncateFileName(truncname, filename);
while ((*pp) && (!found)) {
if (strcmp((*pp)->tName, truncname) == 0) {
sLibrary *t;
t=*pp;
t = *pp;
if( t->pData )
free( t->pData );
if (t->pData)
free(t->pData);
*pp = t->pNext;
free( t );
found=1;
free(t);
found = 1;
}
pp=&((*pp)->pNext);
pp = &((*pp)->pNext);
}
if( !found )
fatalerror( "Module not found" );
if (!found)
fatalerror("Module not found");
else
printf( "Module '%s' deleted from library\n", truncname );
printf("Module '%s' deleted from library\n", truncname);
return( *first );
return (*first);
}
void lib_Free( sLibrary *lib )
void lib_Free(sLibrary * lib)
{
while( lib )
{
sLibrary *l;
while (lib) {
sLibrary *l;
if( lib->pData )
free( lib->pData );
if (lib->pData)
free(lib->pData);
l=lib;
lib=lib->pNext;
free( l );
l = lib;
lib = lib->pNext;
free(l);
}
}
}

View File

@@ -7,7 +7,7 @@
#include "types.h"
#include "library.h"
// Quick and dirty...but it works
// Quick and dirty...but it works
#ifdef __GNUC__
#define strcmpi strcasecmp
#endif
@@ -17,10 +17,10 @@
*
*/
void fatalerror( char *s )
void fatalerror(char *s)
{
printf( "*ERROR* : %s\n", s );
exit( 5 );
printf("*ERROR* : %s\n", s);
exit(5);
}
/*
@@ -28,15 +28,15 @@ void fatalerror( char *s )
*
*/
void PrintUsage( void )
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 );
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);
}
/*
@@ -44,100 +44,95 @@ void PrintUsage( void )
*
*/
int main( int argc, char *argv[] )
int main(int argc, char *argv[])
{
SLONG argn=0;
char *libname;
SLONG argn = 0;
char *libname;
argc-=1;
argn+=1;
argc -= 1;
argn += 1;
if( argc>=2 )
{
UBYTE command;
sLibrary *lib;
if (argc >= 2) {
UBYTE command;
sLibrary *lib;
lib=lib_Read( libname=argv[argn++] );
argc-=1;
lib = lib_Read(libname = argv[argn++]);
argc -= 1;
if( strlen(argv[argn])==1 )
{
command=argv[argn++][0];
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;
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;
}
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;
}
break;
case 'x':
while (argc) {
sLibrary *l;
l=lib;
l = lib_Find(lib, argv[argn]);
if (l) {
FILE *f;
while( l )
{
printf( "%10d %s\n", l->nByteLength, l->tName );
l=l->pNext;
}
}
break;
case 'x':
while( argc )
{
sLibrary *l;
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");
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;
argn += 1;
argc -= 1;
}
lib_Free(lib);
break;
default:
fatalerror("Invalid command");
break;
}
} else {
fatalerror("Invalid command");
}
else
{
fatalerror( "Invalid command" );
}
}
else
} else
PrintUsage();
return( 0 );
}
return (0);
}