Whitespace, and one typo fix in an error message.

This commit is contained in:
Ragnvald Maartmann-Moe IV 2002-09-18 23:09:09 +00:00
parent ab421330a9
commit b3f842ba65
5 changed files with 521 additions and 911 deletions

View File

@ -19,7 +19,7 @@
// cmdlib.c
# include "config.h"
#include "config.h"
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
@ -48,7 +48,6 @@ qboolean com_eof;
qboolean archive;
char archivedir[1024];
/*
=================
Error
@ -56,35 +55,34 @@ Error
For abnormal program terminations
=================
*/
void Error (char *error, ...)
void
Error (char *error, ...)
{
va_list argptr;
printf ("************ ERROR ************\n");
va_start (argptr,error);
vprintf (error,argptr);
va_start (argptr, error);
vprintf (error, argptr);
va_end (argptr);
printf ("\n");
exit (1);
}
/*
qdir will hold the path up to the quake directory, including the slash
f:\quake\
/raid/quake/
gamedir will hold qdir + the game directory (id1, id2, etc)
*/
*/
char qdir[1024];
char gamedir[1024];
void SetQdirFromPath (char *path)
void
SetQdirFromPath (char *path)
{
char temp[1024];
char *c;
@ -99,15 +97,12 @@ void SetQdirFromPath (char *path)
// search for "quake" in path
for (c=path ; *c ; c++)
if (!Q_strncasecmp (c, "quake", 5))
{
if (!Q_strncasecmp (c, "quake", 5)) {
strncpy (qdir, path, c+6-path);
printf ("qdir: %s\n", qdir);
c += 6;
while (*c)
{
if (*c == '/' || *c == '\\')
{
while (*c) {
if (*c == '/' || *c == '\\') {
strncpy (gamedir, path, c+1-path);
printf ("gamedir: %s\n", gamedir);
return;
@ -117,12 +112,14 @@ void SetQdirFromPath (char *path)
Error ("No gamedir in %s", path);
return;
}
Error ("SeetQdirFromPath: no 'quake' in %s", path);
Error ("SetQdirFromPath: no 'quake' in %s", path);
}
char *ExpandPath (char *path)
char *
ExpandPath (char *path)
{
static char full[1024];
if (!qdir)
Error ("ExpandPath called without qdir set");
if (path[0] == '/' || path[0] == '\\' || path[1] == ':')
@ -131,38 +128,33 @@ char *ExpandPath (char *path)
return full;
}
char *ExpandPathAndArchive (char *path)
char *
ExpandPathAndArchive (char *path)
{
char *expanded;
char archivename[1024];
char archivename[1024];
expanded = ExpandPath (path);
if (archive)
{
if (archive) {
sprintf (archivename, "%s/%s", archivedir, path);
CopyFile (expanded, archivename);
}
return expanded;
}
char *copystring(char *s)
char *
copystring(char *s)
{
char *b;
b = malloc(strlen(s)+1);
b = malloc (strlen (s) + 1);
strcpy (b, s);
return b;
}
/*
================
I_FloatTime
================
*/
double I_FloatTime (void)
double
I_FloatTime (void)
{
time_t t;
@ -171,34 +163,34 @@ double I_FloatTime (void)
return t;
#if 0
// more precise, less portable
struct timeval tp;
struct timezone tzp;
struct timeval tp;
struct timezone tzp;
static int secbase;
gettimeofday(&tp, &tzp);
gettimeofday (&tp, &tzp);
if (!secbase)
{
if (!secbase) {
secbase = tp.tv_sec;
return tp.tv_usec/1000000.0;
}
return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0;
return (tp.tv_sec - secbase) + tp.tv_usec / 1000000.0;
#endif
}
void Q_getwd (char *out)
void
Q_getwd (char *out)
{
#ifdef WIN32
_getcwd (out, 256);
strcat (out, "\\");
_getcwd (out, 256);
strcat (out, "\\");
#else
getcwd (out, 256);
getcwd (out, 256);
#endif
}
void Q_mkdir (char *path)
void
Q_mkdir (char *path)
{
#ifdef WIN32
if (_mkdir (path) != -1)
@ -218,9 +210,10 @@ FileTime
returns -1 if not present
============
*/
int FileTime (char *path)
int
FileTime (char *path)
{
struct stat buf;
struct stat buf;
if (stat (path,&buf) == -1)
return -1;
@ -228,21 +221,19 @@ int FileTime (char *path)
return buf.st_mtime;
}
int Q_strncasecmp (char *s1, char *s2, int n)
int
Q_strncasecmp (char *s1, char *s2, int n)
{
int c1, c2;
while (1)
{
while (1) {
c1 = *s1++;
c2 = *s2++;
if (!n--)
return 0; // strings are equal until end point
if (c1 != c2)
{
if (c1 != c2) {
if (c1 >= 'a' && c1 <= 'z')
c1 -= ('a' - 'A');
if (c2 >= 'a' && c2 <= 'z')
@ -257,19 +248,20 @@ int Q_strncasecmp (char *s1, char *s2, int n)
return -1;
}
int Q_strcasecmp (char *s1, char *s2)
int
Q_strcasecmp (char *s1, char *s2)
{
return Q_strncasecmp (s1, s2, 99999);
}
char *strupr (char *start)
char *
strupr (char *start)
{
char *in;
in = start;
while (*in)
{
*in = toupper(*in);
while (*in) {
*in = toupper (*in);
in++;
}
return start;
@ -278,16 +270,15 @@ char *strupr (char *start)
char *strlower (char *start)
{
char *in;
in = start;
while (*in)
{
*in = tolower(*in);
while (*in) {
*in = tolower (*in);
in++;
}
return start;
}
/*
=============================================================================
@ -296,7 +287,6 @@ char *strlower (char *start)
=============================================================================
*/
/*
=================
CheckParm
@ -305,21 +295,21 @@ Checks for the given parameter in the program's command line arguments
Returns the argument number (1 to argc-1) or 0 if not present
=================
*/
int CheckParm (char *check)
int
CheckParm (char *check)
{
int i;
int i;
for (i = 1;i<myargc;i++)
{
if ( !Q_strcasecmp(check, myargv[i]) )
for (i = 1; i < myargc; i++) {
if (!Q_strcasecmp (check, myargv[i]))
return i;
}
return 0;
}
QFile *SafeOpenWrite (char *filename)
QFile *
SafeOpenWrite (char *filename)
{
QFile *f;
@ -331,7 +321,8 @@ QFile *SafeOpenWrite (char *filename)
return f;
}
QFile *SafeOpenRead (char *filename)
QFile *
SafeOpenRead (char *filename)
{
QFile *f;
@ -343,27 +334,22 @@ QFile *SafeOpenRead (char *filename)
return f;
}
void SafeRead (QFile *f, void *buffer, int count)
void
SafeRead (QFile *f, void *buffer, int count)
{
if ( Qread (f, buffer, count) != (size_t)count)
if (Qread (f, buffer, count) != (size_t) count)
Error ("File read failure");
}
void SafeWrite (QFile *f, void *buffer, int count)
void
SafeWrite (QFile *f, void *buffer, int count)
{
if (Qwrite (f, buffer, count) != (size_t)count)
Error ("File read failure");
}
/*
==============
SaveFile
==============
*/
void SaveFile (char *filename, void *buffer, int count)
void
SaveFile (char *filename, void *buffer, int count)
{
QFile *f;
@ -372,19 +358,17 @@ void SaveFile (char *filename, void *buffer, int count)
Qclose (f);
}
void DefaultExtension (char *path, char *extension)
void
DefaultExtension (char *path, char *extension)
{
char *src;
//
// if path doesn't have a .EXT, append extension
// (extension should include the .)
//
src = path + strlen(path) - 1;
while (*src != PATHSEPERATOR && src != path)
{
src = path + strlen (path) - 1;
while (*src != PATHSEPERATOR && src != path) {
if (*src == '.')
return; // it has an extension
src--;
@ -394,35 +378,36 @@ void DefaultExtension (char *path, char *extension)
}
void DefaultPath (char *path, char *basepath)
void
DefaultPath (char *path, char *basepath)
{
char temp[128];
if (path[0] == PATHSEPERATOR)
return; // absolute path location
strcpy (temp,path);
strcpy (path,basepath);
strcat (path,temp);
strcpy (temp, path);
strcpy (path, basepath);
strcat (path, temp);
}
void StripFilename (char *path)
void
StripFilename (char *path)
{
int length;
length = strlen(path)-1;
length = strlen (path) - 1;
while (length > 0 && path[length] != PATHSEPERATOR)
length--;
path[length] = 0;
}
void StripExtension (char *path)
void
StripExtension (char *path)
{
int length;
length = strlen(path)-1;
while (length > 0 && path[length] != '.')
{
length = strlen (path) - 1;
while (length > 0 && path[length] != '.') {
length--;
if (path[length] == '/')
return; // no extension
@ -431,21 +416,19 @@ void StripExtension (char *path)
path[length] = 0;
}
/*
====================
Extract file parts
====================
*/
void ExtractFilePath (char *path, char *dest)
void
ExtractFilePath (char *path, char *dest)
{
char *src;
src = path + strlen(path) - 1;
//
// back up until a \ or the start
//
while (src != path && *(src-1) != PATHSEPERATOR)
src--;
@ -453,38 +436,34 @@ void ExtractFilePath (char *path, char *dest)
dest[src-path] = 0;
}
void ExtractFileBase (char *path, char *dest)
void
ExtractFileBase (char *path, char *dest)
{
char *src;
src = path + strlen(path) - 1;
//
// back up until a \ or the start
//
while (src != path && *(src-1) != PATHSEPERATOR)
src--;
while (*src && *src != '.')
{
while (*src && *src != '.') {
*dest++ = *src++;
}
*dest = 0;
}
void ExtractFileExtension (char *path, char *dest)
void
ExtractFileExtension (char *path, char *dest)
{
char *src;
src = path + strlen(path) - 1;
//
// back up until a . or the start
//
while (src != path && *(src-1) != '.')
src--;
if (src == path)
{
if (src == path) {
*dest = 0; // no extension
return;
}
@ -492,29 +471,23 @@ void ExtractFileExtension (char *path, char *dest)
strcpy (dest,src);
}
/*
==============
ParseNum / ParseHex
==============
*/
int ParseHex (char *hex)
int
ParseHex (char *hex)
{
char *str;
int num;
char *str;
int num;
num = 0;
str = hex;
while (*str)
{
while (*str) {
num <<= 4;
if (*str >= '0' && *str <= '9')
num += *str-'0';
num += *str - '0';
else if (*str >= 'a' && *str <= 'f')
num += 10 + *str-'a';
num += 10 + *str - 'a';
else if (*str >= 'A' && *str <= 'F')
num += 10 + *str-'A';
num += 10 + *str - 'A';
else
Error ("Bad hex number: %s",hex);
str++;
@ -523,18 +496,16 @@ int ParseHex (char *hex)
return num;
}
int ParseNum (char *str)
int
ParseNum (char *str)
{
if (str[0] == '$')
return ParseHex (str+1);
return ParseHex (str + 1);
if (str[0] == '0' && str[1] == 'x')
return ParseHex (str+2);
return ParseHex (str + 2);
return atol (str);
}
/*
============================================================================
@ -549,7 +520,8 @@ int ParseNum (char *str)
#ifdef __BIG_ENDIAN__
short LittleShort (short l)
short
LittleShort (short l)
{
byte b1,b2;
@ -559,13 +531,14 @@ short LittleShort (short l)
return (b1<<8) + b2;
}
short BigShort (short l)
short
BigShort (short l)
{
return l;
}
int LittleLong (int l)
int
LittleLong (int l)
{
byte b1,b2,b3,b4;
@ -577,13 +550,14 @@ int LittleLong (int l)
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
}
int BigLong (int l)
int
BigLong (int l)
{
return l;
}
float LittleFloat (float l)
float
LittleFloat (float l)
{
union {byte b[4]; float f;} in, out;
@ -596,16 +570,16 @@ float LittleFloat (float l)
return out.f;
}
float BigFloat (float l)
float
BigFloat (float l)
{
return l;
}
#else
short BigShort (short l)
short
BigShort (short l)
{
byte b1,b2;
@ -615,13 +589,15 @@ short BigShort (short l)
return (b1<<8) + b2;
}
short LittleShort (short l)
short
LittleShort (short l)
{
return l;
}
int BigLong (int l)
int
BigLong (int l)
{
byte b1,b2,b3,b4;
@ -633,12 +609,14 @@ int BigLong (int l)
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
}
int LittleLong (int l)
int
LittleLong (int l)
{
return l;
}
float BigFloat (float l)
float
BigFloat (float l)
{
union {byte b[4]; float f;} in, out;
@ -651,15 +629,14 @@ float BigFloat (float l)
return out.f;
}
float LittleFloat (float l)
float
LittleFloat (float l)
{
return l;
}
#endif
//=======================================================
@ -708,33 +685,32 @@ static unsigned short crctable[256] =
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};
void CRC_Init(unsigned short *crcvalue)
void
CRC_Init (unsigned short *crcvalue)
{
*crcvalue = CRC_INIT_VALUE;
}
void CRC_ProcessByte(unsigned short *crcvalue, byte data)
void
CRC_ProcessByte (unsigned short *crcvalue, byte data)
{
*crcvalue = (*crcvalue << 8) ^ crctable[(*crcvalue >> 8) ^ data];
}
unsigned short CRC_Value(unsigned short crcvalue)
unsigned short
CRC_Value (unsigned short crcvalue)
{
return crcvalue ^ CRC_XOR_VALUE;
}
//=============================================================================
/*
============
CreatePath
============
*/
void CreatePath (char *path)
void
CreatePath (char *path)
{
char *ofs, c;
for (ofs = path+1 ; *ofs ; ofs++)
{
for (ofs = path+1 ; *ofs ; ofs++) {
c = *ofs;
if (c == '/' || c == '\\')
{ // create the directory
@ -745,7 +721,6 @@ void CreatePath (char *path)
}
}
/*
============
CopyFile
@ -753,7 +728,8 @@ CopyFile
Used to archive source files
============
*/
void CopyFile (char *from, char *to)
void
CopyFile (char *from, char *to)
{
void *buffer;
int length;

View File

@ -24,8 +24,6 @@
#include "cmdlib.h"
#include "lbmlib.h"
/*
============================================================================
@ -34,7 +32,6 @@
============================================================================
*/
#define FORMID ('F'+('O'<<8)+((int)'R'<<16)+((int)'M'<<24))
#define ILBMID ('I'+('L'<<8)+((int)'B'<<16)+((int)'M'<<24))
#define PBMID ('P'+('B'<<8)+((int)'M'<<16)+((int)' '<<24))
@ -45,92 +42,81 @@
bmhd_t bmhd;
int Align (int l)
int
Align (int l)
{
if (l&1)
return l+1;
return l;
}
/*
================
=
= LBMRLEdecompress
=
= Source must be evenly aligned!
=
LBMRLEdecompress
Source must be evenly aligned!
================
*/
byte *LBMRLEDecompress (byte *source,byte *unpacked, int bpwidth)
byte *
LBMRLEDecompress (byte *source, byte *unpacked, int bpwidth)
{
int count;
byte b,rept;
byte b, rept;
count = 0;
do
{
do {
rept = *source++;
if (rept > 0x80)
{
rept = (rept^0xff)+2;
if (rept > 0x80) {
rept = (rept ^ 0xff) + 2;
b = *source++;
memset(unpacked,b,rept);
memset (unpacked, b, rept);
unpacked += rept;
}
else if (rept < 0x80)
{
} else if (rept < 0x80) {
rept++;
memcpy(unpacked,source,rept);
memcpy (unpacked, source, rept);
unpacked += rept;
source += rept;
}
else
} else
rept = 0; // rept of 0x80 is NOP
count += rept;
} while (count<bpwidth);
} while (count < bpwidth);
if (count>bpwidth)
if (count > bpwidth)
Error ("Decompression exceeded width!\n");
return source;
}
#define BPLANESIZE 128
byte bitplanes[9][BPLANESIZE]; // max size 1024 by 9 bit planes
/*
=================
=
= MungeBitPlanes8
=
= Asm version destroys the bit plane data!
=
MungeBitPlanes8
Asm version destroys the bit plane data!
=================
*/
void MungeBitPlanes8 (int width, byte *dest)
void
MungeBitPlanes8 (int width, byte *dest)
{
int i, ind = 0;
int i, ind = 0;
while (width--) {
for (i = 0; i < 8; i++) {
*dest++ = (((bitplanes[7][ind] << i) & 128) >> 0)
| (((bitplanes[6][ind] << i) & 128) >> 1)
| (((bitplanes[5][ind] << i) & 128) >> 2)
| (((bitplanes[4][ind] << i) & 128) >> 3)
| (((bitplanes[3][ind] << i) & 128) >> 4)
| (((bitplanes[2][ind] << i) & 128) >> 5)
| (((bitplanes[1][ind] << i) & 128) >> 6)
| (((bitplanes[0][ind] << i) & 128) >> 7);
| (((bitplanes[6][ind] << i) & 128) >> 1)
| (((bitplanes[5][ind] << i) & 128) >> 2)
| (((bitplanes[4][ind] << i) & 128) >> 3)
| (((bitplanes[3][ind] << i) & 128) >> 4)
| (((bitplanes[2][ind] << i) & 128) >> 5)
| (((bitplanes[1][ind] << i) & 128) >> 6)
| (((bitplanes[0][ind] << i) & 128) >> 7);
}
ind++;
}
@ -169,16 +155,17 @@ done:
#endif
}
void MungeBitPlanes4 (int width, byte *dest)
void
MungeBitPlanes4 (int width, byte *dest)
{
int i, ind = 0;
int i, ind = 0;
while (width--) {
for (i = 0; i < 8; i++) {
*dest++ = (((bitplanes[3][ind] << i) & 128) >> 4)
| (((bitplanes[2][ind] << i) & 128) >> 5)
| (((bitplanes[1][ind] << i) & 128) >> 6)
| (((bitplanes[0][ind] << i) & 128) >> 7);
| (((bitplanes[2][ind] << i) & 128) >> 5)
| (((bitplanes[1][ind] << i) & 128) >> 6)
| (((bitplanes[0][ind] << i) & 128) >> 7);
}
ind++;
}
@ -211,10 +198,11 @@ done:
#endif
}
void MungeBitPlanes2 (int width, byte *dest)
void
MungeBitPlanes2 (int width, byte *dest)
{
int i, ind = 0;
int i, ind = 0;
while (width--) {
for (i = 0; i < 8; i++) {
*dest++ = (((bitplanes[1][ind] << i) & 128) >> 6)
@ -246,10 +234,11 @@ done:
#endif
}
void MungeBitPlanes1 (int width, byte *dest)
void
MungeBitPlanes1 (int width, byte *dest)
{
int i, ind = 0;
int i, ind = 0;
while (width--) {
for (i = 0; i < 8; i++) {
*dest++ = (((bitplanes[0][ind] << i) & 128) >> 7);
@ -278,79 +267,65 @@ done:
#endif
}
/*
=================
=
= LoadLBM
=
=================
*/
void LoadLBM (char *filename, byte **picture, byte **palette)
void
LoadLBM (char *filename, byte **picture, byte **palette)
{
byte *LBMbuffer, *picbuffer, *cmapbuffer;
int y,p,planes;
byte *LBM_P, *LBMEND_P;
byte *pic_p;
byte *body_p;
unsigned rowsize;
unsigned rowsize;
int y, p, planes;
int formtype, formlength;
int chunktype, chunklength;
int formtype,formlength;
int chunktype,chunklength;
void (*mungecall) (int, byte *);
void (*mungecall) (int, byte *);
// qiet compiler warnings
// quiet compiler warnings
picbuffer = NULL;
cmapbuffer = NULL;
mungecall = NULL;
//
// load the LBM
//
LoadFile (filename, (void **)&LBMbuffer);
LoadFile (filename, (void **) &LBMbuffer);
//
// parse the LBM header
//
LBM_P = LBMbuffer;
if ( *(int *)LBMbuffer != LittleLong(FORMID) )
if (*(int *) LBMbuffer != LittleLong (FORMID))
Error ("No FORM ID at start of file!\n");
LBM_P += 4;
formlength = BigLong( *(int *)LBM_P );
formlength = BigLong (*(int *) LBM_P );
LBM_P += 4;
LBMEND_P = LBM_P + Align(formlength);
LBMEND_P = LBM_P + Align (formlength);
formtype = LittleLong(*(int *)LBM_P);
formtype = LittleLong (*(int *) LBM_P);
if (formtype != ILBMID && formtype != PBMID)
Error ("Unrecognized form type: %c%c%c%c\n", formtype&0xff
,(formtype>>8)&0xff,(formtype>>16)&0xff,(formtype>>24)&0xff);
Error ("Unrecognized form type: %c%c%c%c\n", formtype & 0xff,
(formtype >> 8) & 0xff, (formtype >> 16) & 0xff,
(formtype >> 24) & 0xff);
LBM_P += 4;
//
// parse chunks
//
while (LBM_P < LBMEND_P)
{
chunktype = LBM_P[0] + (LBM_P[1]<<8) + (LBM_P[2]<<16) + (LBM_P[3]<<24);
while (LBM_P < LBMEND_P) {
chunktype = LBM_P[0] + (LBM_P[1] << 8) + (LBM_P[2] << 16)
+ (LBM_P[3] << 24);
LBM_P += 4;
chunklength = LBM_P[3] + (LBM_P[2]<<8) + (LBM_P[1]<<16) + (LBM_P[0]<<24);
chunklength = LBM_P[3] + (LBM_P[2] << 8) + (LBM_P[1] << 16)
+ (LBM_P[0] << 24);
LBM_P += 4;
switch ( chunktype )
{
switch (chunktype) {
case BMHDID:
memcpy (&bmhd,LBM_P,sizeof(bmhd));
bmhd.w = BigShort(bmhd.w);
bmhd.h = BigShort(bmhd.h);
bmhd.x = BigShort(bmhd.x);
bmhd.y = BigShort(bmhd.y);
bmhd.pageWidth = BigShort(bmhd.pageWidth);
bmhd.pageHeight = BigShort(bmhd.pageHeight);
memcpy (&bmhd, LBM_P, sizeof (bmhd));
bmhd.w = BigShort (bmhd.w);
bmhd.h = BigShort (bmhd.h);
bmhd.x = BigShort (bmhd.x);
bmhd.y = BigShort (bmhd.y);
bmhd.pageWidth = BigShort (bmhd.pageWidth);
bmhd.pageHeight = BigShort (bmhd.pageHeight);
break;
case CMAPID:
@ -362,36 +337,25 @@ void LoadLBM (char *filename, byte **picture, byte **palette)
case BODYID:
body_p = LBM_P;
pic_p = picbuffer = malloc (bmhd.w*bmhd.h);
if (formtype == PBMID)
{
//
pic_p = picbuffer = malloc (bmhd.w * bmhd.h);
if (formtype == PBMID) {
// unpack PBM
//
for (y=0 ; y<bmhd.h ; y++, pic_p += bmhd.w)
{
for (y = 0; y < bmhd.h; y++, pic_p += bmhd.w) {
if (bmhd.compression == cm_rle1)
body_p = LBMRLEDecompress ((byte *)body_p
, pic_p , bmhd.w);
else if (bmhd.compression == cm_none)
{
body_p = LBMRLEDecompress ((byte *) body_p , pic_p,
bmhd.w);
else if (bmhd.compression == cm_none) {
memcpy (pic_p,body_p,bmhd.w);
body_p += Align(bmhd.w);
}
}
}
else
{
//
} else {
// unpack ILBM
//
planes = bmhd.nPlanes;
if (bmhd.masking == ms_mask)
planes++;
rowsize = (bmhd.w+15)/16 * 2;
switch (bmhd.nPlanes)
{
rowsize = (bmhd.w + 15) / 16 * 2;
switch (bmhd.nPlanes) {
case 1:
mungecall = MungeBitPlanes1;
break;
@ -408,15 +372,13 @@ void LoadLBM (char *filename, byte **picture, byte **palette)
Error ("Can't munge %i bit planes!\n",bmhd.nPlanes);
}
for (y=0 ; y<bmhd.h ; y++, pic_p += bmhd.w)
{
for (p=0 ; p<planes ; p++)
for (y = 0; y < bmhd.h; y++, pic_p += bmhd.w) {
for (p = 0; p < planes; p++)
if (bmhd.compression == cm_rle1)
body_p = LBMRLEDecompress ((byte *)body_p
, bitplanes[p] , rowsize);
else if (bmhd.compression == cm_none)
{
memcpy (bitplanes[p],body_p,rowsize);
body_p = LBMRLEDecompress ((byte *) body_p,
bitplanes[p], rowsize);
else if (bmhd.compression == cm_none) {
memcpy (bitplanes[p], body_p, rowsize);
body_p += rowsize;
}
@ -426,7 +388,7 @@ void LoadLBM (char *filename, byte **picture, byte **palette)
break;
}
LBM_P += Align(chunklength);
LBM_P += Align (chunklength);
}
free (LBMbuffer);
@ -435,7 +397,6 @@ void LoadLBM (char *filename, byte **picture, byte **palette)
*palette = cmapbuffer;
}
/*
============================================================================
@ -444,15 +405,8 @@ void LoadLBM (char *filename, byte **picture, byte **palette)
============================================================================
*/
/*
==============
=
= WriteLBMfile
=
==============
*/
void WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
void
WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
{
byte *lbm, *lbmptr;
int *formlength, *bmhdlength, *cmaplength, *bodylength;
@ -461,9 +415,7 @@ void WriteLBMfile (char *filename, byte *data, int width, int height, byte *pale
lbm = lbmptr = malloc (width*height+1000);
//
// start FORM
//
*lbmptr++ = 'F';
*lbmptr++ = 'O';
*lbmptr++ = 'R';
@ -477,84 +429,74 @@ void WriteLBMfile (char *filename, byte *data, int width, int height, byte *pale
*lbmptr++ = 'M';
*lbmptr++ = ' ';
//
// write BMHD
//
*lbmptr++ = 'B';
*lbmptr++ = 'M';
*lbmptr++ = 'H';
*lbmptr++ = 'D';
bmhdlength = (int *)lbmptr;
lbmptr+=4; // leave space for length
bmhdlength = (int *) lbmptr;
lbmptr += 4; // leave space for length
memset (&basebmhd,0,sizeof(basebmhd));
basebmhd.w = BigShort((short)width);
basebmhd.h = BigShort((short)height);
basebmhd.nPlanes = BigShort(8);
basebmhd.xAspect = BigShort(5);
basebmhd.yAspect = BigShort(6);
basebmhd.pageWidth = BigShort((short)width);
basebmhd.pageHeight = BigShort((short)height);
memset (&basebmhd, 0, sizeof (basebmhd));
basebmhd.w = BigShort ((short) width);
basebmhd.h = BigShort ((short) height);
basebmhd.nPlanes = BigShort (8);
basebmhd.xAspect = BigShort (5);
basebmhd.yAspect = BigShort (6);
basebmhd.pageWidth = BigShort ((short) width);
basebmhd.pageHeight = BigShort ((short) height);
memcpy (lbmptr,&basebmhd,sizeof(basebmhd));
lbmptr += sizeof(basebmhd);
memcpy (lbmptr, &basebmhd, sizeof (basebmhd));
lbmptr += sizeof (basebmhd);
length = lbmptr-(byte *)bmhdlength-4;
*bmhdlength = BigLong(length);
if (length&1)
*lbmptr++ = 0; // pad chunk to even offset
length = lbmptr - (byte *) bmhdlength - 4;
*bmhdlength = BigLong (length);
if (length & 1)
*lbmptr++ = 0; // pad chunk to even offset
//
// write CMAP
//
*lbmptr++ = 'C';
*lbmptr++ = 'M';
*lbmptr++ = 'A';
*lbmptr++ = 'P';
cmaplength = (int *)lbmptr;
lbmptr+=4; // leave space for length
cmaplength = (int *) lbmptr;
lbmptr += 4; // leave space for length
memcpy (lbmptr,palette,768);
memcpy (lbmptr, palette, 768);
lbmptr += 768;
length = lbmptr-(byte *)cmaplength-4;
*cmaplength = BigLong(length);
if (length&1)
*lbmptr++ = 0; // pad chunk to even offset
length = lbmptr - (byte *) cmaplength - 4;
*cmaplength = BigLong (length);
if (length & 1)
*lbmptr++ = 0; // pad chunk to even offset
//
// write BODY
//
*lbmptr++ = 'B';
*lbmptr++ = 'O';
*lbmptr++ = 'D';
*lbmptr++ = 'Y';
bodylength = (int *)lbmptr;
lbmptr+=4; // leave space for length
bodylength = (int *) lbmptr;
lbmptr += 4; // leave space for length
memcpy (lbmptr,data,width*height);
lbmptr += width*height;
memcpy (lbmptr, data, width * height);
lbmptr += width * height;
length = lbmptr-(byte *)bodylength-4;
length = lbmptr - (byte *) bodylength - 4;
*bodylength = BigLong(length);
if (length&1)
if (length & 1)
*lbmptr++ = 0; // pad chunk to even offset
//
// done
//
length = lbmptr-(byte *)formlength-4;
*formlength = BigLong(length);
if (length&1)
length = lbmptr - (byte *) formlength - 4;
*formlength = BigLong (length);
if (length & 1)
*lbmptr++ = 0; // pad chunk to even offset
//
// write output file
//
SaveFile (filename, lbm, lbmptr-lbm);
SaveFile (filename, lbm, lbmptr - lbm);
free (lbm);
}

File diff suppressed because it is too large Load Diff

View File

@ -37,19 +37,12 @@ int scriptline;
qboolean endofscript;
qboolean tokenready; // only true if UnGetToken was just called
/*
==============
=
= LoadScriptFile
=
==============
*/
void LoadScriptFile (char *filename)
void
LoadScriptFile (char *filename)
{
int size;
size = LoadFile (filename, (void **)&scriptbuffer);
size = LoadFile (filename, (void **) &scriptbuffer);
script_p = scriptbuffer;
scriptend_p = script_p + size;
@ -58,102 +51,81 @@ void LoadScriptFile (char *filename)
tokenready = false;
}
/*
==============
=
= UnGetToken
=
= Signals that the current token was not used, and should be reported
= for the next GetToken. Note that
UnGetToken
Signals that the current token was not used, and should be reported
for the next GetToken. Note that
GetToken (true);
UnGetToken ();
GetToken (false);
= could cross a line boundary.
=
could cross a line boundary.
==============
*/
void UnGetToken (void)
void
UnGetToken (void)
{
tokenready = true;
}
/*
==============
GetToken
==============
*/
qboolean GetToken (qboolean crossline)
qboolean
GetToken (qboolean crossline)
{
char *token_p;
if (tokenready) // is a token allready waiting?
{
if (tokenready) { // is a token allready waiting?
tokenready = false;
return true;
}
if (script_p >= scriptend_p)
{
if (script_p >= scriptend_p) {
if (!crossline)
Error ("Line %i is incomplete\n",scriptline);
endofscript = true;
return false;
}
//
// skip space
//
skipspace:
while (*script_p <= 32)
{
if (script_p >= scriptend_p)
{
while (*script_p <= 32) {
if (script_p >= scriptend_p) {
if (!crossline)
Error ("Line %i is incomplete\n",scriptline);
endofscript = true;
return true;
}
if (*script_p++ == '\n')
{
if (*script_p++ == '\n') {
if (!crossline)
Error ("Line %i is incomplete\n",scriptline);
scriptline++;
}
}
if (script_p >= scriptend_p)
{
if (script_p >= scriptend_p) {
if (!crossline)
Error ("Line %i is incomplete\n",scriptline);
endofscript = true;
return true;
}
if (*script_p == ';' || *script_p == '#') // semicolon is comment field
{ // also make # a comment field
if (*script_p == ';' || *script_p == '#') { // semicolon is comment field
// also make # a comment field
if (!crossline)
Error ("Line %i is incomplete\n",scriptline);
while (*script_p++ != '\n')
if (script_p >= scriptend_p)
{
if (script_p >= scriptend_p) {
endofscript = true;
return false;
}
goto skipspace;
}
//
// copy token
//
token_p = token;
while ( *script_p > 32 && *script_p != ';')
{
while ( *script_p > 32 && *script_p != ';') {
*token_p++ = *script_p++;
if (script_p == scriptend_p)
break;
@ -165,18 +137,15 @@ skipspace:
return true;
}
/*
==============
=
= TokenAvailable
=
= Returns true if there is another token on the line
=
TokenAvailable
Returns true if there is another token on the line
==============
*/
qboolean TokenAvailable (void)
qboolean
TokenAvailable (void)
{
char *search_p;
@ -185,14 +154,12 @@ qboolean TokenAvailable (void)
if (search_p >= scriptend_p)
return false;
while ( *search_p <= 32)
{
while (*search_p <= 32) {
if (*search_p == '\n')
return false;
search_p++;
if (search_p == scriptend_p)
return false;
}
if (*search_p == ';')
@ -200,5 +167,3 @@ qboolean TokenAvailable (void)
return true;
}

View File

@ -17,9 +17,7 @@
See file, 'COPYING', for details.
*/
//
// trilib.c: library for loading triangles from an Alias triangle file
//
#include <stdio.h>
#include <stdlib.h>
@ -33,7 +31,6 @@
// on disk representation of a face
#define FLOAT_START 99999.0
#define FLOAT_END -FLOAT_START
#define MAGIC 123322
@ -58,103 +55,97 @@ typedef struct {
} tf_triangle;
void ByteSwapTri (tf_triangle *tri)
void
ByteSwapTri (tf_triangle *tri)
{
int i;
for (i=0 ; i<sizeof(tf_triangle)/4 ; i++)
{
((int *)tri)[i] = BigLong (((int *)tri)[i]);
for (i = 0; i < sizeof (tf_triangle) / 4; i++) {
((int *) tri)[i] = BigLong (((int *) tri)[i]);
}
}
void LoadTriangleList (char *filename, triangle_t **pptri, int *numtriangles)
void
LoadTriangleList (char *filename, triangle_t **pptri, int *numtriangles)
{
QFile *input;
float start;
char name[256], tex[256];
int i, count, magic;
float start, t;
int count, exitpattern, iLevel, magic, i;
tf_triangle tri;
triangle_t *ptri;
int iLevel;
int exitpattern;
float t;
t = -FLOAT_START;
*((unsigned char *)&exitpattern + 0) = *((unsigned char *)&t + 3);
*((unsigned char *)&exitpattern + 1) = *((unsigned char *)&t + 2);
*((unsigned char *)&exitpattern + 2) = *((unsigned char *)&t + 1);
*((unsigned char *)&exitpattern + 3) = *((unsigned char *)&t + 0);
*((unsigned char *) &exitpattern + 0) = *((unsigned char *) &t + 3);
*((unsigned char *) &exitpattern + 1) = *((unsigned char *) &t + 2);
*((unsigned char *) &exitpattern + 2) = *((unsigned char *) &t + 1);
*((unsigned char *) &exitpattern + 3) = *((unsigned char *) &t + 0);
if ((input = Qopen(filename, "rb")) == 0) {
fprintf(stderr,"reader: could not open file '%s'\n", filename);
exit(0);
fprintf (stderr,"reader: could not open file '%s'\n", filename);
exit (0);
}
iLevel = 0;
Qread(input, &magic, sizeof(int));
if (BigLong(magic) != MAGIC) {
fprintf(stderr,"File is not a Alias object separated triangle file, magic number is wrong.\n");
exit(0);
if (BigLong (magic) != MAGIC) {
fprintf (stderr,"File is not a Alias object separated triangle file, "
"magic number is wrong.\n");
exit (0);
}
ptri = malloc (MAXTRIANGLES * sizeof(triangle_t));
ptri = malloc (MAXTRIANGLES * sizeof (triangle_t));
*pptri = ptri;
while (Qeof(input) == 0) {
Qread(input, &start, sizeof(float));
*(int *)&start = BigLong(*(int *)&start);
if (*(int *)&start != exitpattern)
{
Qread(input, &start, sizeof (float));
*(int *) &start = BigLong (*(int *) &start);
if (*(int *) &start != exitpattern) {
if (start == FLOAT_START) {
/* Start of an object or group of objects. */
// Start of an object or group of objects.
i = -1;
do {
/* There are probably better ways to read a string from */
/* a file, but this does allow you to do error checking */
/* (which I'm not doing) on a per character basis. */
++i;
Qread(input, &(name[i]), sizeof( char ));
} while( name[i] != '\0' );
// There are probably better ways to read a string from
// a file, but this does allow you to do error checking
// (which I'm not doing) on a per character basis.
i++;
Qread(input, &(name[i]), sizeof (char));
} while (name[i] != '\0');
// indent();
// fprintf(stdout,"OBJECT START: %s\n",name);
Qread(input, &count, sizeof(int));
count = BigLong(count);
// indent ();
// fprintf(stdout,"OBJECT START: %s\n",name);
Qread (input, &count, sizeof (int));
count = BigLong (count);
++iLevel;
if (count != 0) {
// indent();
// fprintf(stdout,"NUMBER OF TRIANGLES: %d\n",count);
// indent();
// fprintf (stdout, "NUMBER OF TRIANGLES: %d\n", count);
i = -1;
do {
++i;
Qread(input, &(tex[i]), sizeof( char ));
} while( tex[i] != '\0' );
i++;
Qread (input, &(tex[i]), sizeof (char));
} while (tex[i] != '\0');
// indent();
// fprintf(stdout," Object texture name: '%s'\n",tex);
// indent();
// fprintf(stdout," Object texture name: '%s'\n",tex);
}
/* Else (count == 0) this is the start of a group, and */
/* no texture name is present. */
}
else if (start == FLOAT_END) {
} else if (start == FLOAT_END) {
/* End of an object or group. Yes, the name should be */
/* obvious from context, but it is in here just to be */
/* safe and to provide a little extra information for */
/* those who do not wish to write a recursive reader. */
/* Mia culpa. */
--iLevel;
iLevel--;
i = -1;
do {
++i;
Qread(input, &(name[i]), sizeof( char ));
} while( name[i] != '\0' );
i++;
Qread (input, &(name[i]), sizeof (char));
} while (name[i] != '\0');
// indent();
// fprintf(stdout,"OBJECT END: %s\n",name);
@ -162,20 +153,16 @@ void LoadTriangleList (char *filename, triangle_t **pptri, int *numtriangles)
}
}
//
// read the triangles
//
for (i = 0; i < count; ++i) {
int j;
Qread(input, &tri, sizeof(tf_triangle));
Qread (input, &tri, sizeof (tf_triangle));
ByteSwapTri (&tri);
for (j=0 ; j<3 ; j++)
{
for (j = 0; j < 3; j++) {
int k;
for (k=0 ; k<3 ; k++)
{
for (k = 0; k < 3; k++) {
ptri->verts[j][k] = tri.pt[j].p.v[k];
}
}
@ -191,4 +178,3 @@ void LoadTriangleList (char *filename, triangle_t **pptri, int *numtriangles)
Qclose (input);
}