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

@ -48,7 +48,6 @@ qboolean com_eof;
qboolean archive;
char archivedir[1024];
/*
=================
Error
@ -56,7 +55,8 @@ Error
For abnormal program terminations
=================
*/
void Error (char *error, ...)
void
Error (char *error, ...)
{
va_list argptr;
@ -69,22 +69,20 @@ void Error (char *error, ...)
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];
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);
strcpy (b, s);
return b;
}
/*
================
I_FloatTime
================
*/
double I_FloatTime (void)
double
I_FloatTime (void)
{
time_t t;
@ -177,8 +169,7 @@ double I_FloatTime (void)
gettimeofday (&tp, &tzp);
if (!secbase)
{
if (!secbase) {
secbase = tp.tv_sec;
return tp.tv_usec/1000000.0;
}
@ -187,7 +178,8 @@ double I_FloatTime (void)
#endif
}
void Q_getwd (char *out)
void
Q_getwd (char *out)
{
#ifdef WIN32
_getcwd (out, 256);
@ -197,8 +189,8 @@ void Q_getwd (char *out)
#endif
}
void Q_mkdir (char *path)
void
Q_mkdir (char *path)
{
#ifdef WIN32
if (_mkdir (path) != -1)
@ -218,7 +210,8 @@ FileTime
returns -1 if not present
============
*/
int FileTime (char *path)
int
FileTime (char *path)
{
struct stat buf;
@ -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,18 +248,19 @@ 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)
{
while (*in) {
*in = toupper (*in);
in++;
}
@ -278,16 +270,15 @@ char *strupr (char *start)
char *strlower (char *start)
{
char *in;
in = start;
while (*in)
{
while (*in) {
*in = tolower (*in);
in++;
}
return start;
}
/*
=============================================================================
@ -296,7 +287,6 @@ char *strlower (char *start)
=============================================================================
*/
/*
=================
CheckParm
@ -305,12 +295,12 @@ 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;
for (i = 1;i<myargc;i++)
{
for (i = 1; i < myargc; i++) {
if (!Q_strcasecmp (check, myargv[i]))
return i;
}
@ -318,8 +308,8 @@ int CheckParm (char *check)
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)
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)
{
while (*src != PATHSEPERATOR && src != path) {
if (*src == '.')
return; // it has an extension
src--;
@ -394,7 +378,8 @@ void DefaultExtension (char *path, char *extension)
}
void DefaultPath (char *path, char *basepath)
void
DefaultPath (char *path, char *basepath)
{
char temp[128];
@ -405,8 +390,8 @@ void DefaultPath (char *path, char *basepath)
strcat (path, temp);
}
void StripFilename (char *path)
void
StripFilename (char *path)
{
int length;
@ -416,13 +401,13 @@ void StripFilename (char *path)
path[length] = 0;
}
void StripExtension (char *path)
void
StripExtension (char *path)
{
int length;
length = strlen (path) - 1;
while (length > 0 && path[length] != '.')
{
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,13 +471,8 @@ void ExtractFileExtension (char *path, char *dest)
strcpy (dest,src);
}
/*
==============
ParseNum / ParseHex
==============
*/
int ParseHex (char *hex)
int
ParseHex (char *hex)
{
char *str;
int num;
@ -506,8 +480,7 @@ int ParseHex (char *hex)
num = 0;
str = hex;
while (*str)
{
while (*str) {
num <<= 4;
if (*str >= '0' && *str <= '9')
num += *str - '0';
@ -523,8 +496,8 @@ int ParseHex (char *hex)
return num;
}
int ParseNum (char *str)
int
ParseNum (char *str)
{
if (str[0] == '$')
return ParseHex (str + 1);
@ -533,8 +506,6 @@ int ParseNum (char *str)
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,51 +42,43 @@
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;
count = 0;
do
{
do {
rept = *source++;
if (rept > 0x80)
{
if (rept > 0x80) {
rept = (rept ^ 0xff) + 2;
b = *source++;
memset (unpacked, b, rept);
unpacked += rept;
}
else if (rept < 0x80)
{
} else if (rept < 0x80) {
rept++;
memcpy (unpacked, source, rept);
unpacked += rept;
source += rept;
}
else
} else
rept = 0; // rept of 0x80 is NOP
count += rept;
@ -103,24 +92,21 @@ byte *LBMRLEDecompress (byte *source,byte *unpacked, int bpwidth)
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;
while (width--) {
for (i = 0; i < 8; i++) {
*dest++ = (((bitplanes[7][ind] << i) & 128) >> 0)
@ -169,10 +155,11 @@ done:
#endif
}
void MungeBitPlanes4 (int width, byte *dest)
void
MungeBitPlanes4 (int width, byte *dest)
{
int i, ind = 0;
while (width--) {
for (i = 0; i < 8; i++) {
*dest++ = (((bitplanes[3][ind] << i) & 128) >> 4)
@ -211,10 +198,11 @@ done:
#endif
}
void MungeBitPlanes2 (int width, byte *dest)
void
MungeBitPlanes2 (int width, byte *dest)
{
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;
while (width--) {
for (i = 0; i < 8; i++) {
*dest++ = (((bitplanes[0][ind] << i) & 128) >> 7);
@ -278,41 +267,29 @@ 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;
int y, p, planes;
int formtype, formlength;
int chunktype, chunklength;
void (*mungecall) (int, byte *);
// qiet compiler warnings
// quiet compiler warnings
picbuffer = NULL;
cmapbuffer = NULL;
mungecall = NULL;
//
// load the LBM
//
LoadFile (filename, (void **) &LBMbuffer);
//
// parse the LBM header
//
LBM_P = LBMbuffer;
if (*(int *) LBMbuffer != LittleLong (FORMID))
Error ("No FORM ID at start of file!\n");
@ -325,24 +302,22 @@ void LoadLBM (char *filename, byte **picture, byte **palette)
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);
@ -363,35 +338,24 @@ void LoadLBM (char *filename, byte **picture, byte **palette)
body_p = LBM_P;
pic_p = picbuffer = malloc (bmhd.w * bmhd.h);
if (formtype == PBMID)
{
//
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)
{
switch (bmhd.nPlanes) {
case 1:
mungecall = MungeBitPlanes1;
break;
@ -408,14 +372,12 @@ 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 (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)
{
body_p = LBMRLEDecompress ((byte *) body_p,
bitplanes[p], rowsize);
else if (bmhd.compression == cm_none) {
memcpy (bitplanes[p], body_p, rowsize);
body_p += rowsize;
}
@ -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,9 +429,7 @@ void WriteLBMfile (char *filename, byte *data, int width, int height, byte *pale
*lbmptr++ = 'M';
*lbmptr++ = ' ';
//
// write BMHD
//
*lbmptr++ = 'B';
*lbmptr++ = 'M';
*lbmptr++ = 'H';
@ -505,9 +455,7 @@ void WriteLBMfile (char *filename, byte *data, int width, int height, byte *pale
if (length & 1)
*lbmptr++ = 0; // pad chunk to even offset
//
// write CMAP
//
*lbmptr++ = 'C';
*lbmptr++ = 'M';
*lbmptr++ = 'A';
@ -524,9 +472,7 @@ void WriteLBMfile (char *filename, byte *data, int width, int height, byte *pale
if (length & 1)
*lbmptr++ = 0; // pad chunk to even offset
//
// write BODY
//
*lbmptr++ = 'B';
*lbmptr++ = 'O';
*lbmptr++ = 'D';
@ -543,17 +489,13 @@ void WriteLBMfile (char *filename, byte *data, int width, int height, byte *pale
if (length & 1)
*lbmptr++ = 0; // pad chunk to even offset
//
// done
//
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);
free (lbm);
}

File diff suppressed because it is too large Load diff

View file

@ -37,15 +37,8 @@ int scriptline;
qboolean endofscript;
qboolean tokenready; // only true if UnGetToken was just called
/*
==============
=
= LoadScriptFile
=
==============
*/
void LoadScriptFile (char *filename)
void
LoadScriptFile (char *filename)
{
int 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,28 +55,25 @@ 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++)
{
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);
@ -96,7 +90,8 @@ void LoadTriangleList (char *filename, triangle_t **pptri, int *numtriangles)
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");
fprintf (stderr,"File is not a Alias object separated triangle file, "
"magic number is wrong.\n");
exit (0);
}
@ -107,16 +102,15 @@ void LoadTriangleList (char *filename, triangle_t **pptri, int *numtriangles)
while (Qeof(input) == 0) {
Qread(input, &start, sizeof (float));
*(int *) &start = BigLong (*(int *) &start);
if (*(int *)&start != exitpattern)
{
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;
// 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');
@ -127,12 +121,10 @@ void LoadTriangleList (char *filename, triangle_t **pptri, int *numtriangles)
++iLevel;
if (count != 0) {
// indent();
// fprintf (stdout, "NUMBER OF TRIANGLES: %d\n", count);
i = -1;
do {
++i;
i++;
Qread (input, &(tex[i]), sizeof (char));
} while (tex[i] != '\0');
@ -142,17 +134,16 @@ void LoadTriangleList (char *filename, triangle_t **pptri, int *numtriangles)
/* 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;
i++;
Qread (input, &(name[i]), sizeof (char));
} while (name[i] != '\0');
@ -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));
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);
}