Formatting changes to jmact

git-svn-id: https://svn.eduke32.com/eduke32@809 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2008-06-29 10:41:01 +00:00
parent 2fa3153a84
commit 3c51265878
8 changed files with 1322 additions and 1185 deletions

View file

@ -51,11 +51,11 @@ static boolean Anim_Started = false;
// //
//**************************************************************************** //****************************************************************************
static void CheckAnimStarted ( char * funcname ) static void CheckAnimStarted(char * funcname)
{ {
if (!Anim_Started) if (!Anim_Started)
Error("ANIMLIB_%s: Anim has not been initialized\n",funcname); Error("ANIMLIB_%s: Anim has not been initialized\n",funcname);
} }
//**************************************************************************** //****************************************************************************
// //
// findpage () // findpage ()
@ -63,12 +63,12 @@ static void CheckAnimStarted ( char * funcname )
// //
//**************************************************************************** //****************************************************************************
uint16 findpage (uint16 framenumber) uint16 findpage(uint16 framenumber)
{ {
uint16 i; uint16 i;
CheckAnimStarted ( "findpage" ); CheckAnimStarted("findpage");
for(i=0; i<anim->lpheader.nLps; i++) for (i=0; i<anim->lpheader.nLps; i++)
{ {
if if
( (
@ -78,7 +78,7 @@ uint16 findpage (uint16 framenumber)
return(i); return(i);
} }
return(i); return(i);
} }
//**************************************************************************** //****************************************************************************
@ -88,12 +88,12 @@ uint16 findpage (uint16 framenumber)
// //
//**************************************************************************** //****************************************************************************
void loadpage (uint16 pagenumber, uint16 *pagepointer) void loadpage(uint16 pagenumber, uint16 *pagepointer)
{ {
int32 size; int32 size;
byte * buffer; byte * buffer;
CheckAnimStarted ( "loadpage" ); CheckAnimStarted("loadpage");
buffer = anim->buffer; buffer = anim->buffer;
if (anim->curlpnum != pagenumber) if (anim->curlpnum != pagenumber)
{ {
@ -113,7 +113,7 @@ void loadpage (uint16 pagenumber, uint16 *pagepointer)
buffer += size + sizeof(uint16); buffer += size + sizeof(uint16);
Bmemcpy(pagepointer,buffer,anim->curlp.nBytes+(anim->curlp.nRecords*2)); Bmemcpy(pagepointer,buffer,anim->curlp.nBytes+(anim->curlp.nRecords*2));
} }
} }
//**************************************************************************** //****************************************************************************
@ -123,8 +123,8 @@ void loadpage (uint16 pagenumber, uint16 *pagepointer)
// //
//**************************************************************************** //****************************************************************************
void CPlayRunSkipDump (char *srcP, char *dstP) void CPlayRunSkipDump(char *srcP, char *dstP)
{ {
signed char cnt; signed char cnt;
uint16 wordCnt; uint16 wordCnt;
byte pixel; byte pixel;
@ -139,14 +139,15 @@ nextOp:
cnt -= 0x80; cnt -= 0x80;
if (cnt == 0) if (cnt == 0)
goto longOp; goto longOp;
/* shortSkip */ /* shortSkip */
dstP += cnt; /* adding 7-bit count to 32-bit pointer */ dstP += cnt; /* adding 7-bit count to 32-bit pointer */
goto nextOp; goto nextOp;
dump: dump:
do do
{ {
*dstP++ = *srcP++; *dstP++ = *srcP++;
} while (--cnt); }
while (--cnt);
goto nextOp; goto nextOp;
run: run:
wordCnt = (byte)*srcP++; /* 8-bit unsigned count */ wordCnt = (byte)*srcP++; /* 8-bit unsigned count */
@ -154,7 +155,8 @@ run:
do do
{ {
*dstP++ = pixel; *dstP++ = pixel;
} while (--wordCnt); }
while (--wordCnt);
goto nextOp; goto nextOp;
longOp: longOp:
@ -163,7 +165,7 @@ longOp:
if ((int16)wordCnt <= 0) if ((int16)wordCnt <= 0)
goto notLongSkip; /* Do SIGNED test. */ goto notLongSkip; /* Do SIGNED test. */
/* longSkip. */ /* longSkip. */
dstP += wordCnt; dstP += wordCnt;
goto nextOp; goto nextOp;
@ -174,11 +176,12 @@ notLongSkip:
if (wordCnt >= 0x4000) if (wordCnt >= 0x4000)
goto longRun; goto longRun;
/* longDump. */ /* longDump. */
do do
{ {
*dstP++ = *srcP++; *dstP++ = *srcP++;
} while (--wordCnt); }
while (--wordCnt);
goto nextOp; goto nextOp;
longRun: longRun:
@ -187,12 +190,13 @@ longRun:
do do
{ {
*dstP++ = pixel; *dstP++ = pixel;
} while (--wordCnt); }
while (--wordCnt);
goto nextOp; goto nextOp;
stop: /* all done */ stop: /* all done */
; ;
} }
@ -203,24 +207,24 @@ stop: /* all done */
// //
//**************************************************************************** //****************************************************************************
void renderframe (uint16 framenumber, uint16 *pagepointer) void renderframe(uint16 framenumber, uint16 *pagepointer)
{ {
uint16 offset=0; uint16 offset=0;
uint16 i; uint16 i;
uint16 destframe; uint16 destframe;
byte *ppointer; byte *ppointer;
CheckAnimStarted ( "renderframe" ); CheckAnimStarted("renderframe");
destframe = framenumber - anim->curlp.baseRecord; destframe = framenumber - anim->curlp.baseRecord;
for(i = 0; i < destframe; i++) for (i = 0; i < destframe; i++)
{ {
offset += B_LITTLE16(pagepointer[i]); offset += B_LITTLE16(pagepointer[i]);
} }
ppointer = (byte *)pagepointer; ppointer = (byte *)pagepointer;
ppointer+=anim->curlp.nRecords*2+offset; ppointer+=anim->curlp.nRecords*2+offset;
if(ppointer[1]) if (ppointer[1])
{ {
ppointer += (4 + B_LITTLE16(((uint16 *)ppointer)[1]) + (B_LITTLE16(((uint16 *)ppointer)[1]) & 1)); ppointer += (4 + B_LITTLE16(((uint16 *)ppointer)[1]) + (B_LITTLE16(((uint16 *)ppointer)[1]) & 1));
} }
@ -229,8 +233,8 @@ void renderframe (uint16 framenumber, uint16 *pagepointer)
ppointer+=4; ppointer+=4;
} }
CPlayRunSkipDump ((char *)ppointer, (char *)anim->imagebuffer); CPlayRunSkipDump((char *)ppointer, (char *)anim->imagebuffer);
} }
//**************************************************************************** //****************************************************************************
@ -240,12 +244,12 @@ void renderframe (uint16 framenumber, uint16 *pagepointer)
// //
//**************************************************************************** //****************************************************************************
void drawframe (uint16 framenumber) void drawframe(uint16 framenumber)
{ {
CheckAnimStarted ( "drawframe" ); CheckAnimStarted("drawframe");
loadpage(findpage(framenumber), anim->thepage); loadpage(findpage(framenumber), anim->thepage);
renderframe(framenumber, anim->thepage); renderframe(framenumber, anim->thepage);
} }
//**************************************************************************** //****************************************************************************
@ -254,12 +258,13 @@ void drawframe (uint16 framenumber)
// //
//**************************************************************************** //****************************************************************************
void ANIM_LoadAnim (char * buffer) void ANIM_LoadAnim(char * buffer)
{ {
uint16 i; uint16 i;
int32 size; int32 size;
if (!Anim_Started) { if (!Anim_Started)
{
anim = SafeMalloc(sizeof(anim_t)); anim = SafeMalloc(sizeof(anim_t));
Anim_Started = true; Anim_Started = true;
} }
@ -268,7 +273,7 @@ void ANIM_LoadAnim (char * buffer)
anim->curlpnum = 0xffff; anim->curlpnum = 0xffff;
anim->currentframe = -1; anim->currentframe = -1;
size = sizeof(lpfileheader); size = sizeof(lpfileheader);
Bmemcpy(&anim->lpheader, buffer, size ); Bmemcpy(&anim->lpheader, buffer, size);
anim->lpheader.id = B_LITTLE32(anim->lpheader.id); anim->lpheader.id = B_LITTLE32(anim->lpheader.id);
anim->lpheader.maxLps = B_LITTLE16(anim->lpheader.maxLps); anim->lpheader.maxLps = B_LITTLE16(anim->lpheader.maxLps);
@ -301,7 +306,7 @@ void ANIM_LoadAnim (char * buffer)
anim->LpArray[i].nRecords = B_LITTLE16(anim->LpArray[i].nRecords); anim->LpArray[i].nRecords = B_LITTLE16(anim->LpArray[i].nRecords);
anim->LpArray[i].nBytes = B_LITTLE16(anim->LpArray[i].nBytes); anim->LpArray[i].nBytes = B_LITTLE16(anim->LpArray[i].nBytes);
} }
} }
//**************************************************************************** //****************************************************************************
// //
@ -309,14 +314,14 @@ void ANIM_LoadAnim (char * buffer)
// //
//**************************************************************************** //****************************************************************************
void ANIM_FreeAnim ( void ) void ANIM_FreeAnim(void)
{ {
if (Anim_Started) if (Anim_Started)
{ {
SafeFree(anim); SafeFree(anim);
Anim_Started = false; Anim_Started = false;
} }
} }
//**************************************************************************** //****************************************************************************
// //
@ -324,11 +329,11 @@ void ANIM_FreeAnim ( void )
// //
//**************************************************************************** //****************************************************************************
int32 ANIM_NumFrames ( void ) int32 ANIM_NumFrames(void)
{ {
CheckAnimStarted ( "NumFrames" ); CheckAnimStarted("NumFrames");
return anim->lpheader.nRecords; return anim->lpheader.nRecords;
} }
//**************************************************************************** //****************************************************************************
// //
@ -336,24 +341,24 @@ int32 ANIM_NumFrames ( void )
// //
//**************************************************************************** //****************************************************************************
byte * ANIM_DrawFrame (int32 framenumber) byte * ANIM_DrawFrame(int32 framenumber)
{ {
int32 cnt; int32 cnt;
CheckAnimStarted ( "DrawFrame" ); CheckAnimStarted("DrawFrame");
if ((anim->currentframe != -1) && (anim->currentframe<=framenumber)) if ((anim->currentframe != -1) && (anim->currentframe<=framenumber))
{ {
for (cnt = anim->currentframe; cnt < framenumber; cnt++) for (cnt = anim->currentframe; cnt < framenumber; cnt++)
drawframe (cnt); drawframe(cnt);
} }
else else
{ {
for (cnt = 0; cnt < framenumber; cnt++) for (cnt = 0; cnt < framenumber; cnt++)
drawframe (cnt); drawframe(cnt);
} }
anim->currentframe = framenumber; anim->currentframe = framenumber;
return anim->imagebuffer; return anim->imagebuffer;
} }
//**************************************************************************** //****************************************************************************
// //
@ -361,8 +366,8 @@ byte * ANIM_DrawFrame (int32 framenumber)
// //
//**************************************************************************** //****************************************************************************
byte * ANIM_GetPalette ( void ) byte * ANIM_GetPalette(void)
{ {
CheckAnimStarted ( "GetPalette" ); CheckAnimStarted("GetPalette");
return anim->pal; return anim->pal;
} }

View file

@ -50,7 +50,7 @@ static boolean CONTROL_MouseButtonClickedState[MAXMOUSEBUTTONS], CONTROL_JoyButt
static boolean CONTROL_MouseButtonClicked[MAXMOUSEBUTTONS], CONTROL_JoyButtonClicked[MAXJOYBUTTONS]; static boolean CONTROL_MouseButtonClicked[MAXMOUSEBUTTONS], CONTROL_JoyButtonClicked[MAXJOYBUTTONS];
static byte CONTROL_MouseButtonClickedCount[MAXMOUSEBUTTONS], CONTROL_JoyButtonClickedCount[MAXJOYBUTTONS]; static byte CONTROL_MouseButtonClickedCount[MAXMOUSEBUTTONS], CONTROL_JoyButtonClickedCount[MAXJOYBUTTONS];
static boolean CONTROL_UserInputCleared[3]; static boolean CONTROL_UserInputCleared[3];
static int32 (*GetTime)(void); static int32(*GetTime)(void);
static boolean CONTROL_Started = false; static boolean CONTROL_Started = false;
static int32 ticrate; static int32 ticrate;
static int32 CONTROL_DoubleClickSpeed; static int32 CONTROL_DoubleClickSpeed;
@ -92,7 +92,7 @@ boolean CONTROL_StartMouse(void)
return MOUSE_Init(); return MOUSE_Init();
} }
void CONTROL_GetJoyAbs( void ) void CONTROL_GetJoyAbs(void)
{ {
} }
@ -100,7 +100,7 @@ void CONTROL_FilterJoyDelta(void)
{ {
} }
void CONTROL_GetJoyDelta( void ) void CONTROL_GetJoyDelta(void)
{ {
int32 i; int32 i;
@ -139,12 +139,18 @@ void CONTROL_SetFlag(int32 which, boolean active)
{ {
if (CONTROL_CheckRange(which)) return; if (CONTROL_CheckRange(which)) return;
if (CONTROL_Flags[which].toggle == INSTANT_ONOFF) { if (CONTROL_Flags[which].toggle == INSTANT_ONOFF)
{
CONTROL_Flags[which].active = active; CONTROL_Flags[which].active = active;
} else { }
if (active) { else
{
if (active)
{
CONTROL_Flags[which].buttonheld = false; CONTROL_Flags[which].buttonheld = false;
} else if (CONTROL_Flags[which].buttonheld == false) { }
else if (CONTROL_Flags[which].buttonheld == false)
{
CONTROL_Flags[which].buttonheld = true; CONTROL_Flags[which].buttonheld = true;
CONTROL_Flags[which].active = (CONTROL_Flags[which].active ? false : true); CONTROL_Flags[which].active = (CONTROL_Flags[which].active ? false : true);
} }
@ -181,7 +187,7 @@ void CONTROL_ClearKeyboardFunction(int32 which)
KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] = 0; KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] = 0;
} }
void CONTROL_DefineFlag( int32 which, boolean toggle ) void CONTROL_DefineFlag(int32 which, boolean toggle)
{ {
if (CONTROL_CheckRange(which)) return; if (CONTROL_CheckRange(which)) return;
@ -192,14 +198,14 @@ void CONTROL_DefineFlag( int32 which, boolean toggle )
CONTROL_Flags[which].cleared = 0; CONTROL_Flags[which].cleared = 0;
} }
boolean CONTROL_FlagActive( int32 which ) boolean CONTROL_FlagActive(int32 which)
{ {
if (CONTROL_CheckRange(which)) return false; if (CONTROL_CheckRange(which)) return false;
return CONTROL_Flags[which].used; return CONTROL_Flags[which].used;
} }
void CONTROL_MapKey( int32 which, kb_scancode key1, kb_scancode key2 ) void CONTROL_MapKey(int32 which, kb_scancode key1, kb_scancode key2)
{ {
if (CONTROL_CheckRange(which)) return; if (CONTROL_CheckRange(which)) return;
@ -211,7 +217,8 @@ void CONTROL_PrintKeyMap(void)
{ {
int32 i; int32 i;
for (i=0;i<CONTROL_NUM_FLAGS;i++) { for (i=0;i<CONTROL_NUM_FLAGS;i++)
{
initprintf("function %2ld key1=%3x key2=%3x\n", initprintf("function %2ld key1=%3x key2=%3x\n",
i, CONTROL_KeyMapping[i].key1, CONTROL_KeyMapping[i].key2); i, CONTROL_KeyMapping[i].key1, CONTROL_KeyMapping[i].key2);
} }
@ -230,29 +237,33 @@ void CONTROL_PrintAxes(void)
int32 i; int32 i;
initprintf("nummouseaxes=%d\n", CONTROL_NumMouseAxes); initprintf("nummouseaxes=%d\n", CONTROL_NumMouseAxes);
for (i=0;i<CONTROL_NumMouseAxes;i++) { for (i=0;i<CONTROL_NumMouseAxes;i++)
{
initprintf("axis=%d analog=%d digital1=%d digital2=%d\n", initprintf("axis=%d analog=%d digital1=%d digital2=%d\n",
i, CONTROL_MouseAxesMap[i].analogmap, i, CONTROL_MouseAxesMap[i].analogmap,
CONTROL_MouseAxesMap[i].minmap, CONTROL_MouseAxesMap[i].maxmap); CONTROL_MouseAxesMap[i].minmap, CONTROL_MouseAxesMap[i].maxmap);
} }
initprintf("numjoyaxes=%d\n", CONTROL_NumJoyAxes); initprintf("numjoyaxes=%d\n", CONTROL_NumJoyAxes);
for (i=0;i<CONTROL_NumJoyAxes;i++) { for (i=0;i<CONTROL_NumJoyAxes;i++)
{
initprintf("axis=%d analog=%d digital1=%d digital2=%d\n", initprintf("axis=%d analog=%d digital1=%d digital2=%d\n",
i, CONTROL_JoyAxesMap[i].analogmap, i, CONTROL_JoyAxesMap[i].analogmap,
CONTROL_JoyAxesMap[i].minmap, CONTROL_JoyAxesMap[i].maxmap); CONTROL_JoyAxesMap[i].minmap, CONTROL_JoyAxesMap[i].maxmap);
} }
} }
void CONTROL_MapButton( int32 whichfunction, int32 whichbutton, boolean doubleclicked, controldevice device ) void CONTROL_MapButton(int32 whichfunction, int32 whichbutton, boolean doubleclicked, controldevice device)
{ {
controlbuttontype *set; controlbuttontype *set;
if (CONTROL_CheckRange(whichfunction)) whichfunction = BUTTONUNDEFINED; if (CONTROL_CheckRange(whichfunction)) whichfunction = BUTTONUNDEFINED;
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
if ((uint32)whichbutton >= (uint32)MAXMOUSEBUTTONS) { if ((uint32)whichbutton >= (uint32)MAXMOUSEBUTTONS)
{
//Error("CONTROL_MapButton: button %d out of valid range for %d mouse buttons.", //Error("CONTROL_MapButton: button %d out of valid range for %d mouse buttons.",
// whichbutton, CONTROL_NumMouseButtons); // whichbutton, CONTROL_NumMouseButtons);
return; return;
@ -261,7 +272,8 @@ void CONTROL_MapButton( int32 whichfunction, int32 whichbutton, boolean doublecl
break; break;
case controldevice_joystick: case controldevice_joystick:
if ((uint32)whichbutton >= (uint32)MAXJOYBUTTONS) { if ((uint32)whichbutton >= (uint32)MAXJOYBUTTONS)
{
//Error("CONTROL_MapButton: button %d out of valid range for %d joystick buttons.", //Error("CONTROL_MapButton: button %d out of valid range for %d joystick buttons.",
// whichbutton, CONTROL_NumJoyButtons); // whichbutton, CONTROL_NumJoyButtons);
return; return;
@ -280,19 +292,22 @@ void CONTROL_MapButton( int32 whichfunction, int32 whichbutton, boolean doublecl
set[whichbutton].singleclicked = whichfunction; set[whichbutton].singleclicked = whichfunction;
} }
void CONTROL_MapAnalogAxis( int32 whichaxis, int32 whichanalog, controldevice device ) void CONTROL_MapAnalogAxis(int32 whichaxis, int32 whichanalog, controldevice device)
{ {
controlaxismaptype *set; controlaxismaptype *set;
if ((uint32)whichanalog >= (uint32)analog_maxtype) { if ((uint32)whichanalog >= (uint32)analog_maxtype)
{
//Error("CONTROL_MapAnalogAxis: analog function %d out of valid range for %d analog functions.", //Error("CONTROL_MapAnalogAxis: analog function %d out of valid range for %d analog functions.",
// whichanalog, analog_maxtype); // whichanalog, analog_maxtype);
return; return;
} }
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
if ((uint32)whichaxis >= (uint32)MAXMOUSEAXES) { if ((uint32)whichaxis >= (uint32)MAXMOUSEAXES)
{
//Error("CONTROL_MapAnalogAxis: axis %d out of valid range for %d mouse axes.", //Error("CONTROL_MapAnalogAxis: axis %d out of valid range for %d mouse axes.",
// whichaxis, MAXMOUSEAXES); // whichaxis, MAXMOUSEAXES);
return; return;
@ -302,7 +317,8 @@ void CONTROL_MapAnalogAxis( int32 whichaxis, int32 whichanalog, controldevice de
break; break;
case controldevice_joystick: case controldevice_joystick:
if ((uint32)whichaxis >= (uint32)MAXJOYAXES) { if ((uint32)whichaxis >= (uint32)MAXJOYAXES)
{
//Error("CONTROL_MapAnalogAxis: axis %d out of valid range for %d joystick axes.", //Error("CONTROL_MapAnalogAxis: axis %d out of valid range for %d joystick axes.",
// whichaxis, MAXJOYAXES); // whichaxis, MAXJOYAXES);
return; return;
@ -319,13 +335,15 @@ void CONTROL_MapAnalogAxis( int32 whichaxis, int32 whichanalog, controldevice de
set[whichaxis].analogmap = whichanalog; set[whichaxis].analogmap = whichanalog;
} }
void CONTROL_SetAnalogAxisScale( int32 whichaxis, int32 axisscale, controldevice device ) void CONTROL_SetAnalogAxisScale(int32 whichaxis, int32 axisscale, controldevice device)
{ {
int32 *set; int32 *set;
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
if ((uint32)whichaxis >= (uint32)MAXMOUSEAXES) { if ((uint32)whichaxis >= (uint32)MAXMOUSEAXES)
{
//Error("CONTROL_SetAnalogAxisScale: axis %d out of valid range for %d mouse axes.", //Error("CONTROL_SetAnalogAxisScale: axis %d out of valid range for %d mouse axes.",
// whichaxis, MAXMOUSEAXES); // whichaxis, MAXMOUSEAXES);
return; return;
@ -335,7 +353,8 @@ void CONTROL_SetAnalogAxisScale( int32 whichaxis, int32 axisscale, controldevice
break; break;
case controldevice_joystick: case controldevice_joystick:
if ((uint32)whichaxis >= (uint32)MAXJOYAXES) { if ((uint32)whichaxis >= (uint32)MAXJOYAXES)
{
//Error("CONTROL_SetAnalogAxisScale: axis %d out of valid range for %d joystick axes.", //Error("CONTROL_SetAnalogAxisScale: axis %d out of valid range for %d joystick axes.",
// whichaxis, MAXJOYAXES); // whichaxis, MAXJOYAXES);
return; return;
@ -352,15 +371,17 @@ void CONTROL_SetAnalogAxisScale( int32 whichaxis, int32 axisscale, controldevice
set[whichaxis] = axisscale; set[whichaxis] = axisscale;
} }
void CONTROL_MapDigitalAxis( int32 whichaxis, int32 whichfunction, int32 direction, controldevice device ) void CONTROL_MapDigitalAxis(int32 whichaxis, int32 whichfunction, int32 direction, controldevice device)
{ {
controlaxismaptype *set; controlaxismaptype *set;
if (CONTROL_CheckRange(whichfunction)) whichfunction = AXISUNDEFINED; if (CONTROL_CheckRange(whichfunction)) whichfunction = AXISUNDEFINED;
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
if ((uint32)whichaxis >= (uint32)MAXMOUSEAXES) { if ((uint32)whichaxis >= (uint32)MAXMOUSEAXES)
{
//Error("CONTROL_MapDigitalAxis: axis %d out of valid range for %d mouse axes.", //Error("CONTROL_MapDigitalAxis: axis %d out of valid range for %d mouse axes.",
// whichaxis, MAXMOUSEAXES); // whichaxis, MAXMOUSEAXES);
return; return;
@ -370,7 +391,8 @@ void CONTROL_MapDigitalAxis( int32 whichaxis, int32 whichfunction, int32 directi
break; break;
case controldevice_joystick: case controldevice_joystick:
if ((uint32)whichaxis >= (uint32)MAXJOYAXES) { if ((uint32)whichaxis >= (uint32)MAXJOYAXES)
{
//Error("CONTROL_MapDigitalAxis: axis %d out of valid range for %d joystick axes.", //Error("CONTROL_MapDigitalAxis: axis %d out of valid range for %d joystick axes.",
// whichaxis, MAXJOYAXES); // whichaxis, MAXJOYAXES);
return; return;
@ -384,7 +406,8 @@ void CONTROL_MapDigitalAxis( int32 whichaxis, int32 whichfunction, int32 directi
return; return;
} }
switch (direction) { // JBF: this is all very much a guess. The ASM puzzles me. switch (direction) // JBF: this is all very much a guess. The ASM puzzles me.
{
case axis_up: case axis_up:
case axis_left: case axis_left:
set[whichaxis].minmap = whichfunction; set[whichaxis].minmap = whichfunction;
@ -406,7 +429,7 @@ void CONTROL_ClearFlags(void)
CONTROL_Flags[i].used = false; CONTROL_Flags[i].used = false;
} }
void CONTROL_ClearAssignments( void ) void CONTROL_ClearAssignments(void)
{ {
int32 i; int32 i;
@ -433,33 +456,42 @@ static void DoGetDeviceButtons(
boolean *ButtonClickedState, boolean *ButtonClickedState,
boolean *ButtonClicked, boolean *ButtonClicked,
byte *ButtonClickedCount byte *ButtonClickedCount
) { )
{
int32 i, bs; int32 i, bs;
for (i=0;i<NumButtons;i++) { for (i=0;i<NumButtons;i++)
{
bs = (buttons >> i) & 1; bs = (buttons >> i) & 1;
DeviceButtonState[i] = bs; DeviceButtonState[i] = bs;
ButtonClickedState[i] = false; ButtonClickedState[i] = false;
if (bs) { if (bs)
if (ButtonClicked[i] == false) { {
if (ButtonClicked[i] == false)
{
ButtonClicked[i] = true; ButtonClicked[i] = true;
if (ButtonClickedCount[i] == 0 || tm > ButtonClickedTime[i]) { if (ButtonClickedCount[i] == 0 || tm > ButtonClickedTime[i])
{
ButtonClickedTime[i] = tm + CONTROL_DoubleClickSpeed; ButtonClickedTime[i] = tm + CONTROL_DoubleClickSpeed;
ButtonClickedCount[i] = 1; ButtonClickedCount[i] = 1;
} }
else if (tm < ButtonClickedTime[i]) { else if (tm < ButtonClickedTime[i])
{
ButtonClickedState[i] = true; ButtonClickedState[i] = true;
ButtonClickedTime[i] = 0; ButtonClickedTime[i] = 0;
ButtonClickedCount[i] = 2; ButtonClickedCount[i] = 2;
} }
} }
else if (ButtonClickedCount[i] == 2) { else if (ButtonClickedCount[i] == 2)
{
ButtonClickedState[i] = true; ButtonClickedState[i] = true;
} }
} else { }
else
{
if (ButtonClickedCount[i] == 2) if (ButtonClickedCount[i] == 2)
ButtonClickedCount[i] = 0; ButtonClickedCount[i] = 0;
@ -474,7 +506,8 @@ void CONTROL_GetDeviceButtons(void)
t = GetTime(); t = GetTime();
if (CONTROL_MouseEnabled) { if (CONTROL_MouseEnabled)
{
DoGetDeviceButtons( DoGetDeviceButtons(
MOUSE_GetButtons(), t, MOUSE_GetButtons(), t,
CONTROL_NumMouseButtons, CONTROL_NumMouseButtons,
@ -486,9 +519,11 @@ void CONTROL_GetDeviceButtons(void)
); );
} }
if (CONTROL_JoystickEnabled) { if (CONTROL_JoystickEnabled)
{
int32 buttons = joyb; int32 buttons = joyb;
if (joynumhats > 0 && joyhat[0] != -1) { if (joynumhats > 0 && joyhat[0] != -1)
{
static int32 hatstate[] = { 1, 1|2, 2, 2|4, 4, 4|8, 8, 8|1 }; static int32 hatstate[] = { 1, 1|2, 2, 2|4, 4, 4|8, 8, 8|1 };
int val; int val;
@ -513,7 +548,8 @@ void CONTROL_DigitizeAxis(int32 axis, controldevice device)
{ {
controlaxistype *set, *lastset; controlaxistype *set, *lastset;
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
set = CONTROL_MouseAxes; set = CONTROL_MouseAxes;
lastset = CONTROL_LastMouseAxes; lastset = CONTROL_LastMouseAxes;
@ -527,20 +563,31 @@ void CONTROL_DigitizeAxis(int32 axis, controldevice device)
default: return; default: return;
} }
if (set[axis].analog > 0) { if (set[axis].analog > 0)
if (set[axis].analog > THRESHOLD) { // if very much in one direction, {
if (set[axis].analog > THRESHOLD) // if very much in one direction,
{
set[axis].digital = 1; // set affirmative set[axis].digital = 1; // set affirmative
} else { }
if (set[axis].analog > MINTHRESHOLD) { // if hanging in limbo, else
{
if (set[axis].analog > MINTHRESHOLD) // if hanging in limbo,
{
if (lastset[axis].digital == 1) // set if in same direction as last time if (lastset[axis].digital == 1) // set if in same direction as last time
set[axis].digital = 1; set[axis].digital = 1;
} }
} }
} else { }
if (set[axis].analog < -THRESHOLD) { else
{
if (set[axis].analog < -THRESHOLD)
{
set[axis].digital = -1; set[axis].digital = -1;
} else { }
if (set[axis].analog < -MINTHRESHOLD) { else
{
if (set[axis].analog < -MINTHRESHOLD)
{
if (lastset[axis].digital == -1) if (lastset[axis].digital == -1)
set[axis].digital = -1; set[axis].digital = -1;
} }
@ -553,7 +600,8 @@ void CONTROL_ScaleAxis(int32 axis, controldevice device)
controlaxistype *set; controlaxistype *set;
int32 *scale; int32 *scale;
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
set = CONTROL_MouseAxes; set = CONTROL_MouseAxes;
scale = CONTROL_MouseAxesScale; scale = CONTROL_MouseAxesScale;
@ -575,7 +623,8 @@ void CONTROL_ApplyAxis(int32 axis, ControlInfo *info, controldevice device)
controlaxistype *set; controlaxistype *set;
controlaxismaptype *map; controlaxismaptype *map;
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
set = CONTROL_MouseAxes; set = CONTROL_MouseAxes;
map = CONTROL_MouseAxesMap; map = CONTROL_MouseAxesMap;
@ -589,7 +638,8 @@ void CONTROL_ApplyAxis(int32 axis, ControlInfo *info, controldevice device)
default: return; default: return;
} }
switch (map[axis].analogmap) { switch (map[axis].analogmap)
{
case analog_turning: info->dyaw += set[axis].analog; break; case analog_turning: info->dyaw += set[axis].analog; break;
case analog_strafing: info->dx += set[axis].analog; break; case analog_strafing: info->dx += set[axis].analog; break;
case analog_lookingupanddown: info->dpitch += set[axis].analog; break; case analog_lookingupanddown: info->dpitch += set[axis].analog; break;
@ -611,24 +661,28 @@ void CONTROL_PollDevices(ControlInfo *info)
memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes)); memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes));
memset(info, 0, sizeof(ControlInfo)); memset(info, 0, sizeof(ControlInfo));
if (CONTROL_MouseEnabled) { if (CONTROL_MouseEnabled)
{
CONTROL_GetMouseDelta(); CONTROL_GetMouseDelta();
for (i=0; i<MAXMOUSEAXES; i++) { for (i=0; i<MAXMOUSEAXES; i++)
{
CONTROL_DigitizeAxis(i, controldevice_mouse); CONTROL_DigitizeAxis(i, controldevice_mouse);
CONTROL_ScaleAxis(i, controldevice_mouse); CONTROL_ScaleAxis(i, controldevice_mouse);
LIMITCONTROL(&CONTROL_MouseAxes[i].analog); LIMITCONTROL(&CONTROL_MouseAxes[i].analog);
CONTROL_ApplyAxis(i, info, controldevice_mouse); CONTROL_ApplyAxis(i, info, controldevice_mouse);
} }
} }
if (CONTROL_JoystickEnabled) { if (CONTROL_JoystickEnabled)
{
CONTROL_GetJoyDelta(); CONTROL_GetJoyDelta();
// Why? // Why?
//CONTROL_Axes[0].analog /= 2; //CONTROL_Axes[0].analog /= 2;
//CONTROL_Axes[2].analog /= 2; //CONTROL_Axes[2].analog /= 2;
for (i=0; i<MAXJOYAXES; i++) { for (i=0; i<MAXJOYAXES; i++)
{
CONTROL_DigitizeAxis(i, controldevice_joystick); CONTROL_DigitizeAxis(i, controldevice_joystick);
CONTROL_ScaleAxis(i, controldevice_joystick); CONTROL_ScaleAxis(i, controldevice_joystick);
LIMITCONTROL(&CONTROL_JoyAxes[i].analog); LIMITCONTROL(&CONTROL_JoyAxes[i].analog);
@ -643,7 +697,8 @@ void CONTROL_AxisFunctionState(int32 *p1)
{ {
int32 i, j; int32 i, j;
for (i=0; i<CONTROL_NumMouseAxes; i++) { for (i=0; i<CONTROL_NumMouseAxes; i++)
{
if (!CONTROL_MouseAxes[i].digital) continue; if (!CONTROL_MouseAxes[i].digital) continue;
if (CONTROL_MouseAxes[i].digital < 0) if (CONTROL_MouseAxes[i].digital < 0)
@ -655,7 +710,8 @@ void CONTROL_AxisFunctionState(int32 *p1)
p1[j] = 1; p1[j] = 1;
} }
for (i=0; i<CONTROL_NumJoyAxes; i++) { for (i=0; i<CONTROL_NumJoyAxes; i++)
{
if (!CONTROL_JoyAxes[i].digital) continue; if (!CONTROL_JoyAxes[i].digital) continue;
if (CONTROL_JoyAxes[i].digital < 0) if (CONTROL_JoyAxes[i].digital < 0)
@ -668,11 +724,12 @@ void CONTROL_AxisFunctionState(int32 *p1)
} }
} }
void CONTROL_ButtonFunctionState( int32 *p1 ) void CONTROL_ButtonFunctionState(int32 *p1)
{ {
int32 i, j; int32 i, j;
for (i=0; i<CONTROL_NumMouseButtons; i++) { for (i=0; i<CONTROL_NumMouseButtons; i++)
{
j = CONTROL_MouseButtonMapping[i].doubleclicked; j = CONTROL_MouseButtonMapping[i].doubleclicked;
if (j != KEYUNDEFINED) if (j != KEYUNDEFINED)
p1[j] |= CONTROL_MouseButtonClickedState[i]; p1[j] |= CONTROL_MouseButtonClickedState[i];
@ -682,7 +739,8 @@ void CONTROL_ButtonFunctionState( int32 *p1 )
p1[j] |= CONTROL_MouseButtonState[i]; p1[j] |= CONTROL_MouseButtonState[i];
} }
for (i=0; i<CONTROL_NumJoyButtons; i++) { for (i=0; i<CONTROL_NumJoyButtons; i++)
{
j = CONTROL_JoyButtonMapping[i].doubleclicked; j = CONTROL_JoyButtonMapping[i].doubleclicked;
if (j != KEYUNDEFINED) if (j != KEYUNDEFINED)
p1[j] |= CONTROL_JoyButtonClickedState[i]; p1[j] |= CONTROL_JoyButtonClickedState[i];
@ -779,10 +837,10 @@ void CONTROL_ClearUserInput( UserInput *info )
if (info->button1) CONTROL_UserInputCleared[2] = true; if (info->button1) CONTROL_UserInputCleared[2] = true;
} }
*/ */
void CONTROL_ClearButton( int32 whichbutton ) void CONTROL_ClearButton(int32 whichbutton)
{ {
if (CONTROL_CheckRange( whichbutton )) return; if (CONTROL_CheckRange(whichbutton)) return;
BUTTONCLEAR( whichbutton ); BUTTONCLEAR(whichbutton);
CONTROL_Flags[whichbutton].cleared = true; CONTROL_Flags[whichbutton].cleared = true;
} }
@ -807,11 +865,11 @@ void CONTROL_ProcessBinds(void)
} }
void CONTROL_GetInput( ControlInfo *info ) void CONTROL_GetInput(ControlInfo *info)
{ {
int32 i, periphs[CONTROL_NUM_FLAGS]; int32 i, periphs[CONTROL_NUM_FLAGS];
CONTROL_PollDevices( info ); CONTROL_PollDevices(info);
memset(periphs, 0, sizeof(periphs)); memset(periphs, 0, sizeof(periphs));
CONTROL_ButtonFunctionState(periphs); CONTROL_ButtonFunctionState(periphs);
@ -823,7 +881,8 @@ void CONTROL_GetInput( ControlInfo *info )
CONTROL_ProcessBinds(); CONTROL_ProcessBinds();
for (i=0; i<CONTROL_NUM_FLAGS; i++) { for (i=0; i<CONTROL_NUM_FLAGS; i++)
{
CONTROL_SetFlag(i, CONTROL_KeyboardFunctionPressed(i) | periphs[i] | extinput[i]); CONTROL_SetFlag(i, CONTROL_KeyboardFunctionPressed(i) | periphs[i] | extinput[i]);
if (CONTROL_Flags[i].cleared == false) BUTTONSET(i, CONTROL_Flags[i].active); if (CONTROL_Flags[i].cleared == false) BUTTONSET(i, CONTROL_Flags[i].active);
@ -832,15 +891,15 @@ void CONTROL_GetInput( ControlInfo *info )
memset(extinput, 0, sizeof(extinput)); memset(extinput, 0, sizeof(extinput));
} }
void CONTROL_WaitRelease( void ) void CONTROL_WaitRelease(void)
{ {
} }
void CONTROL_Ack( void ) void CONTROL_Ack(void)
{ {
} }
boolean CONTROL_Startup(controltype which, int32 ( *TimeFunction )( void ), int32 ticspersecond) boolean CONTROL_Startup(controltype which, int32(*TimeFunction)(void), int32 ticspersecond)
{ {
int32 i; int32 i;

View file

@ -63,7 +63,8 @@ int32 SafeOpen(const char *filename, int32 mode, int32 sharemode)
h = openfrompath(filename, mode, sharemode); h = openfrompath(filename, mode, sharemode);
if (h < 0) Error("Error opening %s: %s", filename, strerror(errno)); if (h < 0) Error("Error opening %s: %s", filename, strerror(errno));
if (h < MaxFiles) { if (h < MaxFiles)
{
if (FileNames[h]) SafeFree(FileNames[h]); if (FileNames[h]) SafeFree(FileNames[h]);
FileNames[h] = (char*)SafeMalloc(strlen(filename)+1); FileNames[h] = (char*)SafeMalloc(strlen(filename)+1);
if (FileNames[h]) strcpy(FileNames[h], filename); if (FileNames[h]) strcpy(FileNames[h], filename);
@ -74,7 +75,8 @@ int32 SafeOpen(const char *filename, int32 mode, int32 sharemode)
int32 SafeOpenRead(const char *filename, int32 filetype) int32 SafeOpenRead(const char *filename, int32 filetype)
{ {
switch (filetype) { switch (filetype)
{
case filetype_binary: case filetype_binary:
return SafeOpen(filename, O_RDONLY|O_BINARY, S_IREAD); return SafeOpen(filename, O_RDONLY|O_BINARY, S_IREAD);
case filetype_text: case filetype_text:
@ -85,17 +87,19 @@ int32 SafeOpenRead(const char *filename, int32 filetype)
} }
} }
void SafeClose ( int32 handle ) void SafeClose(int32 handle)
{ {
if (handle < 0) return; if (handle < 0) return;
if (close(handle) < 0) { if (close(handle) < 0)
{
if (handle < MaxFiles) if (handle < MaxFiles)
Error("Unable to close file %s", FileNames[handle]); Error("Unable to close file %s", FileNames[handle]);
else else
Error("Unable to close file"); Error("Unable to close file");
} }
if (handle < MaxFiles && FileNames[handle]) { if (handle < MaxFiles && FileNames[handle])
{
SafeFree(FileNames[handle]); SafeFree(FileNames[handle]);
FileNames[handle] = NULL; FileNames[handle] = NULL;
} }
@ -107,7 +111,7 @@ boolean SafeFileExists(const char *filename)
return false; return false;
} }
int32 SafeFileLength ( int32 handle ) int32 SafeFileLength(int32 handle)
{ {
if (handle < 0) return -1; if (handle < 0) return -1;
return Bfilelength(handle); return Bfilelength(handle);
@ -118,7 +122,8 @@ void SafeRead(int32 handle, void *buffer, int32 count)
int32 b; int32 b;
b = read(handle, buffer, count); b = read(handle, buffer, count);
if (b != count) { if (b != count)
{
close(handle); close(handle);
if (handle < MaxFiles) if (handle < MaxFiles)
Error("File read failure %s reading %d bytes from file %s.", Error("File read failure %s reading %d bytes from file %s.",

View file

@ -43,10 +43,12 @@ kb_scancode KB_LastScan;
static boolean numpad = 0; static boolean numpad = 0;
// translation table for taking key names to scancodes and back again // translation table for taking key names to scancodes and back again
static struct { static struct
{
char *key; char *key;
kb_scancode sc; kb_scancode sc;
} sctokeylut[] = { } sctokeylut[] =
{
{ "Escape", 0x1 }, { "Escape", 0x1 },
{ "1", 0x2 }, { "1", 0x2 },
{ "2", 0x3 }, { "2", 0x3 },
@ -194,15 +196,15 @@ static char sctoasc[2][256] = {
}; };
*/ */
boolean KB_KeyWaiting( void ) boolean KB_KeyWaiting(void)
{ {
return bkbhit(); return bkbhit();
// return (keyfifoplc != keyfifoend); // return (keyfifoplc != keyfifoend);
} }
char KB_Getch( void ) char KB_Getch(void)
{ {
/* /*
unsigned char ch; unsigned char ch;
char shifted; char shifted;
if (keyfifoplc == keyfifoend) return 0; if (keyfifoplc == keyfifoend) return 0;
@ -213,17 +215,17 @@ char KB_Getch( void )
if (ch >= 0x47 && ch <= 0x52) shifted = numpad; if (ch >= 0x47 && ch <= 0x52) shifted = numpad;
return sctoasc[shifted][ch]; return sctoasc[shifted][ch];
*/ */
return (char)bgetchar(); return (char)bgetchar();
} }
void KB_FlushKeyboardQueue( void ) void KB_FlushKeyboardQueue(void)
{ {
//keyfifoplc = keyfifoend = 0; //keyfifoplc = keyfifoend = 0;
bflushchars(); bflushchars();
} }
void KB_ClearKeysDown( void ) void KB_ClearKeysDown(void)
{ {
KB_LastScan = 0; KB_LastScan = 0;
memset(keystatus, 0, sizeof(keystatus)); memset(keystatus, 0, sizeof(keystatus));
@ -231,7 +233,7 @@ void KB_ClearKeysDown( void )
//bflushchars(); //bflushchars();
} }
char *KB_ScanCodeToString( kb_scancode scancode ) char *KB_ScanCodeToString(kb_scancode scancode)
{ {
unsigned s; unsigned s;
@ -241,7 +243,7 @@ char *KB_ScanCodeToString( kb_scancode scancode )
return ""; return "";
} }
kb_scancode KB_StringToScanCode( char * string ) kb_scancode KB_StringToScanCode(char * string)
{ {
unsigned s; unsigned s;
@ -251,33 +253,33 @@ kb_scancode KB_StringToScanCode( char * string )
return 0; return 0;
} }
void KB_TurnKeypadOn( void ) void KB_TurnKeypadOn(void)
{ {
numpad = 1; numpad = 1;
} }
void KB_TurnKeypadOff( void ) void KB_TurnKeypadOff(void)
{ {
numpad = 0; numpad = 0;
} }
boolean KB_KeypadActive( void ) boolean KB_KeypadActive(void)
{ {
return numpad; return numpad;
} }
static void KB_KeyEvent( int scancode, int keypressed ) static void KB_KeyEvent(int scancode, int keypressed)
{ {
if (keypressed) KB_LastScan = scancode; if (keypressed) KB_LastScan = scancode;
} }
void KB_Startup( void ) void KB_Startup(void)
{ {
numpad = 0; numpad = 0;
setkeypresscallback(KB_KeyEvent); setkeypresscallback(KB_KeyEvent);
} }
void KB_Shutdown( void ) void KB_Shutdown(void)
{ {
setkeypresscallback((void(*)(int,int))NULL); setkeypresscallback((void(*)(int,int))NULL);
} }

View file

@ -92,7 +92,7 @@ int32 FindDistance2D(int32 x, int32 y)
int32 FindDistance3D(int32 x, int32 y, int32 z) int32 FindDistance3D(int32 x, int32 y, int32 z)
{ {
int32 t; int32 t;
x= abs(x); /* absolute values */ x= abs(x); /* absolute values */
@ -108,5 +108,5 @@ int32 FindDistance3D(int32 x, int32 y, int32 z)
t = y + z; t = y + z;
return (x - (x>>4) + (t>>2) + (t>>3)); return (x - (x>>4) + (t>>2) + (t>>3));
} }
#endif #endif

View file

@ -38,30 +38,30 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "baselayer.h" #include "baselayer.h"
boolean MOUSE_Init( void ) boolean MOUSE_Init(void)
{ {
initmouse(); initmouse();
return ((inputdevices & 2) == 2); return ((inputdevices & 2) == 2);
} }
void MOUSE_Shutdown( void ) void MOUSE_Shutdown(void)
{ {
uninitmouse(); uninitmouse();
} }
void MOUSE_ShowCursor( void ) void MOUSE_ShowCursor(void)
{ {
} }
void MOUSE_HideCursor( void ) void MOUSE_HideCursor(void)
{ {
} }
int32 MOUSE_GetButtons( void ) int32 MOUSE_GetButtons(void)
{ {
int32 buttons; int32 buttons;
readmousebstatus(&buttons); readmousebstatus(&buttons);
@ -69,13 +69,13 @@ int32 MOUSE_GetButtons( void )
} }
int32 MOUSE_ClearButton( int32 b ) int32 MOUSE_ClearButton(int32 b)
{ {
return (mouseb &= ~b); return (mouseb &= ~b);
} }
void MOUSE_GetDelta( int32*x, int32*y ) void MOUSE_GetDelta(int32*x, int32*y)
{ {
readmousexy(x,y); readmousexy(x,y);
} }

View file

@ -58,8 +58,10 @@ int32 SCRIPT_New(void)
{ {
int32 i; int32 i;
for (i=0; i<MAXSCRIPTFILES; i++) { for (i=0; i<MAXSCRIPTFILES; i++)
if (!SC(i)) { {
if (!SC(i))
{
SC(i) = (script_t *)SafeMalloc(sizeof(script_t)); SC(i) = (script_t *)SafeMalloc(sizeof(script_t));
if (!SC(i)) return -1; if (!SC(i)) return -1;
memset(SC(i), 0, sizeof(script_t)); memset(SC(i), 0, sizeof(script_t));
@ -78,8 +80,10 @@ void SCRIPT_Delete(int32 scripthandle)
if (!SC(scripthandle)) return; if (!SC(scripthandle)) return;
if (SCRIPT(scripthandle,script)) { if (SCRIPT(scripthandle,script))
while (SCRIPT(scripthandle,script)->nextsection != SCRIPT(scripthandle,script)) { {
while (SCRIPT(scripthandle,script)->nextsection != SCRIPT(scripthandle,script))
{
s = SCRIPT(scripthandle,script)->nextsection; s = SCRIPT(scripthandle,script)->nextsection;
SCRIPT_FreeSection(SCRIPT(scripthandle,script)); SCRIPT_FreeSection(SCRIPT(scripthandle,script));
SafeFree(SCRIPT(scripthandle,script)); SafeFree(SCRIPT(scripthandle,script));
@ -100,7 +104,8 @@ void SCRIPT_FreeSection(ScriptSectionType * section)
if (!section) return; if (!section) return;
if (!section->entries) return; if (!section->entries) return;
while (section->entries->nextentry != section->entries) { while (section->entries->nextentry != section->entries)
{
e = section->entries->nextentry; e = section->entries->nextentry;
SafeFree(section->entries); SafeFree(section->entries);
section->entries = e; section->entries = e;
@ -128,7 +133,7 @@ void SCRIPT_FreeSection(ScriptSectionType * section)
(e)->preventry = (e); \ (e)->preventry = (e); \
} }
ScriptSectionType * SCRIPT_SectionExists( int32 scripthandle, char * sectionname ) ScriptSectionType * SCRIPT_SectionExists(int32 scripthandle, char * sectionname)
{ {
ScriptSectionType *s, *ls=NULL; ScriptSectionType *s, *ls=NULL;
@ -143,7 +148,7 @@ ScriptSectionType * SCRIPT_SectionExists( int32 scripthandle, char * sectionname
return NULL; return NULL;
} }
ScriptSectionType * SCRIPT_AddSection( int32 scripthandle, char * sectionname ) ScriptSectionType * SCRIPT_AddSection(int32 scripthandle, char * sectionname)
{ {
ScriptSectionType *s,*s2; ScriptSectionType *s,*s2;
@ -156,9 +161,12 @@ ScriptSectionType * SCRIPT_AddSection( int32 scripthandle, char * sectionname )
AllocSection(s); AllocSection(s);
s->name = strdup(sectionname); s->name = strdup(sectionname);
if (!SCRIPT(scripthandle,script)) { if (!SCRIPT(scripthandle,script))
{
SCRIPT(scripthandle,script) = s; SCRIPT(scripthandle,script) = s;
} else { }
else
{
s2 = SCRIPT(scripthandle,script); s2 = SCRIPT(scripthandle,script);
while (s2->nextsection != s2) s2=s2->nextsection; while (s2->nextsection != s2) s2=s2->nextsection;
s2->nextsection = s; s2->nextsection = s;
@ -168,7 +176,7 @@ ScriptSectionType * SCRIPT_AddSection( int32 scripthandle, char * sectionname )
return s; return s;
} }
ScriptEntryType * SCRIPT_EntryExists ( ScriptSectionType * section, char * entryname ) ScriptEntryType * SCRIPT_EntryExists(ScriptSectionType * section, char * entryname)
{ {
ScriptEntryType *e,*le=NULL; ScriptEntryType *e,*le=NULL;
@ -182,7 +190,7 @@ ScriptEntryType * SCRIPT_EntryExists ( ScriptSectionType * section, char * entry
return NULL; return NULL;
} }
void SCRIPT_AddEntry ( int32 scripthandle, char * sectionname, char * entryname, char * entryvalue ) void SCRIPT_AddEntry(int32 scripthandle, char * sectionname, char * entryname, char * entryvalue)
{ {
ScriptSectionType *s; ScriptSectionType *s;
ScriptEntryType *e,*e2; ScriptEntryType *e,*e2;
@ -198,12 +206,16 @@ void SCRIPT_AddEntry ( int32 scripthandle, char * sectionname, char * entryname,
// } // }
e = SCRIPT_EntryExists(s, entryname); e = SCRIPT_EntryExists(s, entryname);
if (!e) { if (!e)
{
AllocEntry(e); AllocEntry(e);
e->name = strdup(entryname); e->name = strdup(entryname);
if (!s->entries) { if (!s->entries)
{
s->entries = e; s->entries = e;
} else { }
else
{
e2 = s->entries; e2 = s->entries;
while (e2->nextentry != e2) e2=e2->nextentry; while (e2->nextentry != e2) e2=e2->nextentry;
e2->nextentry = e; e2->nextentry = e;
@ -223,7 +235,8 @@ int32 SCRIPT_ParseBuffer(int32 scripthandle, char *data, int32 length)
char *currentsection = ""; char *currentsection = "";
char *currententry = NULL; char *currententry = NULL;
char *currentvalue = NULL; char *currentvalue = NULL;
enum { enum
{
ParsingIdle, ParsingIdle,
ParsingSectionBegin, ParsingSectionBegin,
ParsingSectionName, ParsingSectionName,
@ -231,7 +244,8 @@ int32 SCRIPT_ParseBuffer(int32 scripthandle, char *data, int32 length)
ParsingValueBegin, ParsingValueBegin,
ParsingValue ParsingValue
}; };
enum { enum
{
ExpectingSection = 1, ExpectingSection = 1,
ExpectingEntry = 2, ExpectingEntry = 2,
ExpectingAssignment = 4, ExpectingAssignment = 4,
@ -254,11 +268,14 @@ int32 SCRIPT_ParseBuffer(int32 scripthandle, char *data, int32 length)
#define EATLINE(p) while (length > 0 && *p != '\n' && *p != '\r') { p++; length--; } #define EATLINE(p) while (length > 0 && *p != '\n' && *p != '\r') { p++; length--; }
#define LETTER() { lastch = ch; ch = *(sp++); length--; } #define LETTER() { lastch = ch; ch = *(sp++); length--; }
while (length > 0) { while (length > 0)
switch (state) { {
switch (state)
{
case ParsingIdle: case ParsingIdle:
LETTER(); LETTER();
switch (ch) { switch (ch)
{
// whitespace // whitespace
case ' ': case ' ':
case '\t': continue; case '\t': continue;
@ -270,30 +287,39 @@ int32 SCRIPT_ParseBuffer(int32 scripthandle, char *data, int32 length)
EATLINE(sp); EATLINE(sp);
continue; continue;
case '[': if (!(expect & ExpectingSection)) { case '[': if (!(expect & ExpectingSection))
{
// Unexpected section start // Unexpected section start
printf("Unexpected start of section on line %d.\n", linenum); printf("Unexpected start of section on line %d.\n", linenum);
SETRV(-1); SETRV(-1);
EATLINE(sp); EATLINE(sp);
continue; continue;
} else { }
else
{
state = ParsingSectionBegin; state = ParsingSectionBegin;
continue; continue;
} }
default: if (isalpha(ch)) { default: if (isalpha(ch))
if (!(expect & ExpectingEntry)) { {
if (!(expect & ExpectingEntry))
{
// Unexpected name start // Unexpected name start
printf("Unexpected entry label on line %d.\n", linenum); printf("Unexpected entry label on line %d.\n", linenum);
SETRV(-1); SETRV(-1);
EATLINE(sp); EATLINE(sp);
continue; continue;
} else { }
else
{
currententry = dp = sp-1; currententry = dp = sp-1;
state = ParsingEntry; state = ParsingEntry;
continue; continue;
} }
} else { }
else
{
// Unexpected character // Unexpected character
printf("Illegal character (ASCII %d) on line %d.\n", ch, linenum); printf("Illegal character (ASCII %d) on line %d.\n", ch, linenum);
SETRV(-1); SETRV(-1);
@ -307,7 +333,8 @@ int32 SCRIPT_ParseBuffer(int32 scripthandle, char *data, int32 length)
state = ParsingSectionName; state = ParsingSectionName;
case ParsingSectionName: case ParsingSectionName:
LETTER(); LETTER();
switch (ch) { switch (ch)
{
case '\n': case '\n':
case '\r': // Unexpected newline case '\r': // Unexpected newline
printf("Unexpected newline on line %d.\n", linenum); printf("Unexpected newline on line %d.\n", linenum);
@ -330,7 +357,8 @@ int32 SCRIPT_ParseBuffer(int32 scripthandle, char *data, int32 length)
case ParsingEntry: case ParsingEntry:
LETTER(); LETTER();
switch (ch) { switch (ch)
{
case ';': case ';':
/*case '#':*/ /*case '#':*/
// unexpected comment // unexpected comment
@ -364,7 +392,8 @@ int32 SCRIPT_ParseBuffer(int32 scripthandle, char *data, int32 length)
state = ParsingValue; state = ParsingValue;
case ParsingValue: case ParsingValue:
LETTER(); LETTER();
switch (ch) { switch (ch)
{
case '\n': case '\n':
case '\r': case '\r':
// value complete, add it using parsed name // value complete, add it using parsed name
@ -396,7 +425,7 @@ int32 SCRIPT_ParseBuffer(int32 scripthandle, char *data, int32 length)
//--- //---
int32 SCRIPT_Init( char * name ) int32 SCRIPT_Init(char * name)
{ {
int32 h = SCRIPT_New(); int32 h = SCRIPT_New();
@ -405,12 +434,12 @@ int32 SCRIPT_Init( char * name )
return h; return h;
} }
void SCRIPT_Free( int32 scripthandle ) void SCRIPT_Free(int32 scripthandle)
{ {
SCRIPT_Delete(scripthandle); SCRIPT_Delete(scripthandle);
} }
int32 SCRIPT_Load ( char * filename ) int32 SCRIPT_Load(char * filename)
{ {
int32 s,h,l; int32 s,h,l;
char *b; char *b;
@ -423,7 +452,8 @@ int32 SCRIPT_Load ( char * filename )
SafeClose(h); SafeClose(h);
s = SCRIPT_Init(filename); s = SCRIPT_Init(filename);
if (s<0) { if (s<0)
{
SafeFree(b); SafeFree(b);
return -1; return -1;
} }
@ -435,7 +465,7 @@ int32 SCRIPT_Load ( char * filename )
return s; return s;
} }
void SCRIPT_Save (int32 scripthandle, char * filename) void SCRIPT_Save(int32 scripthandle, char * filename)
{ {
char *section, *entry, *value; char *section, *entry, *value;
int sec, ent, numsect, nument; int sec, ent, numsect, nument;
@ -449,14 +479,16 @@ void SCRIPT_Save (int32 scripthandle, char * filename)
if (!fp) return; if (!fp) return;
numsect = SCRIPT_NumberSections(scripthandle); numsect = SCRIPT_NumberSections(scripthandle);
for (sec=0; sec<numsect; sec++) { for (sec=0; sec<numsect; sec++)
{
section = SCRIPT_Section(scripthandle, sec); section = SCRIPT_Section(scripthandle, sec);
if (sec>0) fprintf(fp, "\n"); if (sec>0) fprintf(fp, "\n");
if (section[0] != 0) if (section[0] != 0)
fprintf(fp, "[%s]\n", section); fprintf(fp, "[%s]\n", section);
nument = SCRIPT_NumberEntries(scripthandle,section); nument = SCRIPT_NumberEntries(scripthandle,section);
for (ent=0; ent<nument; ent++) { for (ent=0; ent<nument; ent++)
{
entry = SCRIPT_Entry(scripthandle,section,ent); entry = SCRIPT_Entry(scripthandle,section,ent);
value = SCRIPT_GetRaw(scripthandle,section,entry); value = SCRIPT_GetRaw(scripthandle,section,entry);
@ -467,7 +499,7 @@ void SCRIPT_Save (int32 scripthandle, char * filename)
fclose(fp); fclose(fp);
} }
int32 SCRIPT_NumberSections( int32 scripthandle ) int32 SCRIPT_NumberSections(int32 scripthandle)
{ {
int32 c=0; int32 c=0;
ScriptSectionType *s,*ls=NULL; ScriptSectionType *s,*ls=NULL;
@ -480,7 +512,7 @@ int32 SCRIPT_NumberSections( int32 scripthandle )
return c; return c;
} }
char * SCRIPT_Section( int32 scripthandle, int32 which ) char * SCRIPT_Section(int32 scripthandle, int32 which)
{ {
ScriptSectionType *s,*ls=NULL; ScriptSectionType *s,*ls=NULL;
@ -492,7 +524,7 @@ char * SCRIPT_Section( int32 scripthandle, int32 which )
return s->name; return s->name;
} }
int32 SCRIPT_NumberEntries( int32 scripthandle, char * sectionname ) int32 SCRIPT_NumberEntries(int32 scripthandle, char * sectionname)
{ {
ScriptSectionType *s; ScriptSectionType *s;
ScriptEntryType *e,*le=NULL; ScriptEntryType *e,*le=NULL;
@ -508,7 +540,7 @@ int32 SCRIPT_NumberEntries( int32 scripthandle, char * sectionname )
return c; return c;
} }
char * SCRIPT_Entry( int32 scripthandle, char * sectionname, int32 which ) char * SCRIPT_Entry(int32 scripthandle, char * sectionname, int32 which)
{ {
ScriptSectionType *s; ScriptSectionType *s;
ScriptEntryType *e,*le=NULL; ScriptEntryType *e,*le=NULL;
@ -538,7 +570,7 @@ char * SCRIPT_GetRaw(int32 scripthandle, char * sectionname, char * entryname)
return e->value; return e->value;
} }
boolean SCRIPT_GetString( int32 scripthandle, char * sectionname, char * entryname, char * dest ) boolean SCRIPT_GetString(int32 scripthandle, char * sectionname, char * entryname, char * dest)
{ {
ScriptSectionType *s; ScriptSectionType *s;
ScriptEntryType *e; ScriptEntryType *e;
@ -557,14 +589,18 @@ boolean SCRIPT_GetString( int32 scripthandle, char * sectionname, char * entryna
p = e->value; p = e->value;
c = 0; c = 0;
if (*p == '\"') { if (*p == '\"')
{
// quoted string // quoted string
p++; p++;
while ((ch = *(p++))) { while ((ch = *(p++)))
switch (ch) { {
switch (ch)
{
case '\\': case '\\':
ch = *(p++); ch = *(p++);
switch (ch) { switch (ch)
{
case 0: return 0; case 0: return 0;
case 'n': dest[c++] = '\n'; break; case 'n': dest[c++] = '\n'; break;
case 'r': dest[c++] = '\r'; break; case 'r': dest[c++] = '\r'; break;
@ -580,8 +616,11 @@ boolean SCRIPT_GetString( int32 scripthandle, char * sectionname, char * entryna
break; break;
} }
} }
} else { }
while ((ch = *(p++))) { else
{
while ((ch = *(p++)))
{
if (ch == ' ' || ch == '\t') { dest[c] = 0; break; } if (ch == ' ' || ch == '\t') { dest[c] = 0; break; }
else dest[c++] = ch; else dest[c++] = ch;
} }
@ -590,7 +629,7 @@ boolean SCRIPT_GetString( int32 scripthandle, char * sectionname, char * entryna
return 0; return 0;
} }
boolean SCRIPT_GetDoubleString( int32 scripthandle, char * sectionname, char * entryname, char * dest1, char * dest2 ) boolean SCRIPT_GetDoubleString(int32 scripthandle, char * sectionname, char * entryname, char * dest1, char * dest2)
{ {
ScriptSectionType *s; ScriptSectionType *s;
ScriptEntryType *e; ScriptEntryType *e;
@ -610,14 +649,18 @@ boolean SCRIPT_GetDoubleString( int32 scripthandle, char * sectionname, char * e
p = e->value; p = e->value;
c = 0; c = 0;
if (*p == '\"') { if (*p == '\"')
{
// quoted string // quoted string
p++; p++;
while ((ch = *(p++))) { while ((ch = *(p++)))
switch (ch) { {
switch (ch)
{
case '\\': case '\\':
ch = *(p++); ch = *(p++);
switch (ch) { switch (ch)
{
case 0: return 0; case 0: return 0;
case 'n': dest1[c++] = '\n'; break; case 'n': dest1[c++] = '\n'; break;
case 'r': dest1[c++] = '\r'; break; case 'r': dest1[c++] = '\r'; break;
@ -634,8 +677,11 @@ boolean SCRIPT_GetDoubleString( int32 scripthandle, char * sectionname, char * e
} }
} }
if (ch == 0) return 0; if (ch == 0) return 0;
} else { }
while ((ch = *(p++))) { else
{
while ((ch = *(p++)))
{
if (ch == ' ' || ch == '\t') { dest1[c] = 0; break; } if (ch == ' ' || ch == '\t') { dest1[c] = 0; break; }
else dest1[c++] = ch; else dest1[c++] = ch;
} }
@ -647,14 +693,18 @@ breakme:
c = 0; c = 0;
if (*p == '\"') { if (*p == '\"')
{
// quoted string // quoted string
p++; p++;
while ((ch = *(p++))) { while ((ch = *(p++)))
switch (ch) { {
switch (ch)
{
case '\\': case '\\':
ch = *(p++); ch = *(p++);
switch (ch) { switch (ch)
{
case 0: return 0; case 0: return 0;
case 'n': dest2[c++] = '\n'; break; case 'n': dest2[c++] = '\n'; break;
case 'r': dest2[c++] = '\r'; break; case 'r': dest2[c++] = '\r'; break;
@ -670,8 +720,11 @@ breakme:
break; break;
} }
} }
} else { }
while ((ch = *(p++))) { else
{
while ((ch = *(p++)))
{
if (ch == ' ' || ch == '\t') { dest2[c] = 0; break; } if (ch == ' ' || ch == '\t') { dest2[c] = 0; break; }
else dest2[c++] = ch; else dest2[c++] = ch;
} }
@ -680,7 +733,7 @@ breakme:
return 0; return 0;
} }
boolean SCRIPT_GetNumber( int32 scripthandle, char * sectionname, char * entryname, int32 * number ) boolean SCRIPT_GetNumber(int32 scripthandle, char * sectionname, char * entryname, int32 * number)
{ {
ScriptSectionType *s; ScriptSectionType *s;
ScriptEntryType *e; ScriptEntryType *e;
@ -693,12 +746,16 @@ boolean SCRIPT_GetNumber( int32 scripthandle, char * sectionname, char * entryna
e = SCRIPT_EntryExists(s, entryname); e = SCRIPT_EntryExists(s, entryname);
if (!e) return 1;// *number = 0; if (!e) return 1;// *number = 0;
else { else
if (e->value[0] == '0' && e->value[1] == 'x') { {
if (e->value[0] == '0' && e->value[1] == 'x')
{
// hex // hex
*number = strtol(e->value+2, &p, 16); *number = strtol(e->value+2, &p, 16);
if (p == e->value || *p != 0 || *p != ' ' || *p != '\t') return 1; if (p == e->value || *p != 0 || *p != ' ' || *p != '\t') return 1;
} else { }
else
{
// decimal // decimal
*number = strtol(e->value, &p, 10); *number = strtol(e->value, &p, 10);
if (p == e->value || *p != 0 || *p != ' ' || *p != '\t') return 1; if (p == e->value || *p != 0 || *p != ' ' || *p != '\t') return 1;
@ -708,7 +765,7 @@ boolean SCRIPT_GetNumber( int32 scripthandle, char * sectionname, char * entryna
return 0; return 0;
} }
boolean SCRIPT_GetBoolean( int32 scripthandle, char * sectionname, char * entryname, boolean * boole ) boolean SCRIPT_GetBoolean(int32 scripthandle, char * sectionname, char * entryname, boolean * boole)
{ {
ScriptSectionType *s; ScriptSectionType *s;
ScriptEntryType *e; ScriptEntryType *e;
@ -720,7 +777,8 @@ boolean SCRIPT_GetBoolean( int32 scripthandle, char * sectionname, char * entryn
e = SCRIPT_EntryExists(s, entryname); e = SCRIPT_EntryExists(s, entryname);
if (!e) return 1;// *boole = 0; if (!e) return 1;// *boole = 0;
else { else
{
if (!Bstrncasecmp(e->value, "true", 4)) *boole = 1; if (!Bstrncasecmp(e->value, "true", 4)) *boole = 1;
else if (!Bstrncasecmp(e->value, "false", 5)) *boole = 0; else if (!Bstrncasecmp(e->value, "false", 5)) *boole = 0;
else if (e->value[0] == '1' && (e->value[1] == ' ' || e->value[1] == '\t' || e->value[1] == 0)) *boole = 1; else if (e->value[0] == '1' && (e->value[1] == ' ' || e->value[1] == '\t' || e->value[1] == 0)) *boole = 1;
@ -730,41 +788,43 @@ boolean SCRIPT_GetBoolean( int32 scripthandle, char * sectionname, char * entryn
return 0; return 0;
} }
void SCRIPT_PutSection( int32 scripthandle, char * sectionname ) void SCRIPT_PutSection(int32 scripthandle, char * sectionname)
{ {
SCRIPT_AddSection(scripthandle, sectionname); SCRIPT_AddSection(scripthandle, sectionname);
} }
void SCRIPT_PutRaw void SCRIPT_PutRaw
( (
int32 scripthandle, int32 scripthandle,
char * sectionname, char * sectionname,
char * entryname, char * entryname,
char * raw char * raw
) )
{ {
SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw);
} }
void SCRIPT_PutString void SCRIPT_PutString
( (
int32 scripthandle, int32 scripthandle,
char * sectionname, char * sectionname,
char * entryname, char * entryname,
char * string char * string
) )
{ {
char *raw,*q,*p; char *raw,*q,*p;
int len = 3; int len = 3;
if (!string) string = ""; if (!string) string = "";
for (q=string; *q; q++) { for (q=string; *q; q++)
{
if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2; if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2;
else if (*q >= ' ') len++; else if (*q >= ' ') len++;
} }
p = raw = Bmalloc(len); p = raw = Bmalloc(len);
*(p++) = '"'; *(p++) = '"';
for (q=string; *q; q++) { for (q=string; *q; q++)
{
if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; } if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; }
else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; } else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; }
else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; } else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; }
@ -779,30 +839,33 @@ void SCRIPT_PutString
} }
void SCRIPT_PutDoubleString void SCRIPT_PutDoubleString
( (
int32 scripthandle, int32 scripthandle,
char * sectionname, char * sectionname,
char * entryname, char * entryname,
char * string1, char * string1,
char * string2 char * string2
) )
{ {
char *raw,*q,*p; char *raw,*q,*p;
int len = 6; int len = 6;
if (!string1) string1 = ""; if (!string1) string1 = "";
if (!string2) string2 = ""; if (!string2) string2 = "";
for (q=string1; *q; q++) { for (q=string1; *q; q++)
{
if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2; if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2;
else if (*q >= ' ') len++; else if (*q >= ' ') len++;
} }
for (q=string2; *q; q++) { for (q=string2; *q; q++)
{
if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2; if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2;
else if (*q >= ' ') len++; else if (*q >= ' ') len++;
} }
p = raw = Bmalloc(len); p = raw = Bmalloc(len);
*(p++) = '"'; *(p++) = '"';
for (q=string1; *q; q++) { for (q=string1; *q; q++)
{
if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; } if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; }
else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; } else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; }
else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; } else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; }
@ -812,7 +875,8 @@ void SCRIPT_PutDoubleString
*(p++) = '"'; *(p++) = '"';
*(p++) = ' '; *(p++) = ' ';
*(p++) = '"'; *(p++) = '"';
for (q=string2; *q; q++) { for (q=string2; *q; q++)
{
if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; } if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; }
else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; } else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; }
else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; } else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; }
@ -827,14 +891,14 @@ void SCRIPT_PutDoubleString
} }
void SCRIPT_PutNumber void SCRIPT_PutNumber
( (
int32 scripthandle, int32 scripthandle,
char * sectionname, char * sectionname,
char * entryname, char * entryname,
int32 number, int32 number,
boolean hexadecimal, boolean hexadecimal,
boolean defaultvalue boolean defaultvalue
) )
{ {
char raw[64]; char raw[64];
@ -846,12 +910,12 @@ void SCRIPT_PutNumber
} }
void SCRIPT_PutBoolean void SCRIPT_PutBoolean
( (
int32 scripthandle, int32 scripthandle,
char * sectionname, char * sectionname,
char * entryname, char * entryname,
boolean boole boolean boole
) )
{ {
char raw[2] = "0"; char raw[2] = "0";
@ -861,13 +925,13 @@ void SCRIPT_PutBoolean
} }
void SCRIPT_PutDouble void SCRIPT_PutDouble
( (
int32 scripthandle, int32 scripthandle,
char * sectionname, char * sectionname,
char * entryname, char * entryname,
double number, double number,
boolean defaultvalue boolean defaultvalue
) )
{ {
char raw[64]; char raw[64];

View file

@ -42,7 +42,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void (*ShutDown)(void) = NULL; // this is defined by whoever links us static void (*ShutDown)(void) = NULL; // this is defined by whoever links us
void RegisterShutdownFunction( void (* sh) (void) ) void RegisterShutdownFunction(void (* sh)(void))
{ {
ShutDown = sh; ShutDown = sh;
} }
@ -54,7 +54,8 @@ void Error(char *error, ...)
if (ShutDown) ShutDown(); if (ShutDown) ShutDown();
if (error) { if (error)
{
va_start(va, error); va_start(va, error);
vprintf(error, va); vprintf(error, va);
va_end(va); va_end(va);
@ -69,7 +70,8 @@ char CheckParm(char *check)
{ {
int c; int c;
for (c=1;c<_buildargc;c++) { for (c=1;c<_buildargc;c++)
{
if (_buildargv[c][0] == '/' || _buildargv[c][0] == '-') if (_buildargv[c][0] == '/' || _buildargv[c][0] == '-')
if (!Bstrcasecmp(&_buildargv[c][1], check)) return c; if (!Bstrcasecmp(&_buildargv[c][1], check)) return c;
} }
@ -77,7 +79,7 @@ char CheckParm(char *check)
return 0; return 0;
} }
void *SafeMalloc (int32 size) void *SafeMalloc(int32 size)
{ {
void *p; void *p;
@ -87,13 +89,13 @@ void *SafeMalloc (int32 size)
return p; return p;
} }
void SafeFree (void * ptr) void SafeFree(void * ptr)
{ {
if (!ptr) Error("Tried to deallocate NULL pointer."); if (!ptr) Error("Tried to deallocate NULL pointer.");
free(ptr); free(ptr);
} }
void SafeRealloc (void ** ptr, int32 newsize) void SafeRealloc(void ** ptr, int32 newsize)
{ {
void *p; void *p;
@ -103,17 +105,17 @@ void SafeRealloc (void ** ptr, int32 newsize)
*ptr = p; *ptr = p;
} }
int32 ParseHex (char *hex) int32 ParseHex(char *hex)
{ {
return strtol(hex, NULL, 16); return strtol(hex, NULL, 16);
} }
int32 ParseNum (char *str) int32 ParseNum(char *str)
{ {
return strtol(str, NULL, 10); return strtol(str, NULL, 10);
} }
int16 MotoShort (int16 l) int16 MotoShort(int16 l)
{ {
#if B_LITTLE_ENDIAN != 0 #if B_LITTLE_ENDIAN != 0
return l; return l;
@ -122,7 +124,7 @@ int16 MotoShort (int16 l)
#endif #endif
} }
int16 IntelShort (int16 l) int16 IntelShort(int16 l)
{ {
#if B_BIG_ENDIAN != 0 #if B_BIG_ENDIAN != 0
return ((l & 0x00ff) << 8) | ((l & 0xff00) >> 8); return ((l & 0x00ff) << 8) | ((l & 0xff00) >> 8);
@ -131,7 +133,7 @@ int16 IntelShort (int16 l)
#endif #endif
} }
int32 MotoLong (int32 l) int32 MotoLong(int32 l)
{ {
#if B_LITTLE_ENDIAN != 0 #if B_LITTLE_ENDIAN != 0
return l; return l;
@ -141,7 +143,7 @@ int32 MotoLong (int32 l)
#endif #endif
} }
int32 IntelLong (int32 l) int32 IntelLong(int32 l)
{ {
#if B_BIG_ENDIAN != 0 #if B_BIG_ENDIAN != 0
int32 t = ((l & 0x00ff00ffl) << 8) | ((l & 0xff00ff00l) >> 8); int32 t = ((l & 0x00ff00ffl) << 8) | ((l & 0xff00ff00l) >> 8);