From 3c51265878a46b0f68a61495ba513a452cbaffe5 Mon Sep 17 00:00:00 2001 From: terminx Date: Sun, 29 Jun 2008 10:41:01 +0000 Subject: [PATCH] Formatting changes to jmact git-svn-id: https://svn.eduke32.com/eduke32@809 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/jmact/animlib.c | 419 ++++---- polymer/eduke32/source/jmact/control.c | 209 ++-- polymer/eduke32/source/jmact/file_lib.c | 97 +- polymer/eduke32/source/jmact/keyboard.c | 310 +++--- polymer/eduke32/source/jmact/mathutil.c | 56 +- polymer/eduke32/source/jmact/mouse.c | 32 +- polymer/eduke32/source/jmact/scriplib.c | 1286 ++++++++++++----------- polymer/eduke32/source/jmact/util_lib.c | 98 +- 8 files changed, 1322 insertions(+), 1185 deletions(-) diff --git a/polymer/eduke32/source/jmact/animlib.c b/polymer/eduke32/source/jmact/animlib.c index 38affd375..75e9ae68e 100644 --- a/polymer/eduke32/source/jmact/animlib.c +++ b/polymer/eduke32/source/jmact/animlib.c @@ -51,11 +51,11 @@ static boolean Anim_Started = false; // //**************************************************************************** -static void CheckAnimStarted ( char * funcname ) - { - if (!Anim_Started) - Error("ANIMLIB_%s: Anim has not been initialized\n",funcname); - } +static void CheckAnimStarted(char * funcname) +{ + if (!Anim_Started) + Error("ANIMLIB_%s: Anim has not been initialized\n",funcname); +} //**************************************************************************** // // findpage () @@ -63,22 +63,22 @@ static void CheckAnimStarted ( char * funcname ) // //**************************************************************************** -uint16 findpage (uint16 framenumber) - { - uint16 i; +uint16 findpage(uint16 framenumber) +{ + uint16 i; - CheckAnimStarted ( "findpage" ); - for(i=0; ilpheader.nLps; i++) - { - if - ( - anim->LpArray[i].baseRecord <= framenumber && - anim->LpArray[i].baseRecord + anim->LpArray[i].nRecords > framenumber - ) - return(i); - } - return(i); - } + CheckAnimStarted("findpage"); + for (i=0; ilpheader.nLps; i++) + { + if + ( + anim->LpArray[i].baseRecord <= framenumber && + anim->LpArray[i].baseRecord + anim->LpArray[i].nRecords > framenumber + ) + return(i); + } + return(i); +} //**************************************************************************** @@ -88,32 +88,32 @@ uint16 findpage (uint16 framenumber) // //**************************************************************************** -void loadpage (uint16 pagenumber, uint16 *pagepointer) - { - int32 size; - byte * buffer; +void loadpage(uint16 pagenumber, uint16 *pagepointer) +{ + int32 size; + byte * buffer; - CheckAnimStarted ( "loadpage" ); - buffer = anim->buffer; - if (anim->curlpnum != pagenumber) - { - anim->curlpnum = pagenumber; - buffer += 0xb00 + (pagenumber*0x10000); - size = sizeof(lp_descriptor); - /* - Bmemcpy(&anim->curlp,buffer,size); + CheckAnimStarted("loadpage"); + buffer = anim->buffer; + if (anim->curlpnum != pagenumber) + { + anim->curlpnum = pagenumber; + buffer += 0xb00 + (pagenumber*0x10000); + size = sizeof(lp_descriptor); + /* + Bmemcpy(&anim->curlp,buffer,size); - // JBF: why didn't this get read from the LpArray[] table? - anim->curlp.baseRecord = B_LITTLE16(anim->curlp.baseRecord); - anim->curlp.nRecords = B_LITTLE16(anim->curlp.nRecords); - anim->curlp.nBytes = B_LITTLE16(anim->curlp.nBytes); - */ - Bmemcpy(&anim->curlp, &anim->LpArray[pagenumber], size); + // JBF: why didn't this get read from the LpArray[] table? + anim->curlp.baseRecord = B_LITTLE16(anim->curlp.baseRecord); + anim->curlp.nRecords = B_LITTLE16(anim->curlp.nRecords); + anim->curlp.nBytes = B_LITTLE16(anim->curlp.nBytes); + */ + Bmemcpy(&anim->curlp, &anim->LpArray[pagenumber], size); - buffer += size + sizeof(uint16); - Bmemcpy(pagepointer,buffer,anim->curlp.nBytes+(anim->curlp.nRecords*2)); - } - } + buffer += size + sizeof(uint16); + Bmemcpy(pagepointer,buffer,anim->curlp.nBytes+(anim->curlp.nRecords*2)); + } +} //**************************************************************************** @@ -123,76 +123,80 @@ void loadpage (uint16 pagenumber, uint16 *pagepointer) // //**************************************************************************** -void CPlayRunSkipDump (char *srcP, char *dstP) - { - signed char cnt; - uint16 wordCnt; - byte pixel; +void CPlayRunSkipDump(char *srcP, char *dstP) +{ + signed char cnt; + uint16 wordCnt; + byte pixel; nextOp: - cnt = (signed char) *srcP++; - if (cnt > 0) - goto dump; - if (cnt == 0) - goto run; - cnt -= 0x80; - if (cnt == 0) - goto longOp; -/* shortSkip */ - dstP += cnt; /* adding 7-bit count to 32-bit pointer */ - goto nextOp; + cnt = (signed char) *srcP++; + if (cnt > 0) + goto dump; + if (cnt == 0) + goto run; + cnt -= 0x80; + if (cnt == 0) + goto longOp; + /* shortSkip */ + dstP += cnt; /* adding 7-bit count to 32-bit pointer */ + goto nextOp; dump: - do - { - *dstP++ = *srcP++; - } while (--cnt); - goto nextOp; + do + { + *dstP++ = *srcP++; + } + while (--cnt); + goto nextOp; run: - wordCnt = (byte)*srcP++; /* 8-bit unsigned count */ - pixel = *srcP++; - do - { - *dstP++ = pixel; - } while (--wordCnt); + wordCnt = (byte)*srcP++; /* 8-bit unsigned count */ + pixel = *srcP++; + do + { + *dstP++ = pixel; + } + while (--wordCnt); - goto nextOp; + goto nextOp; longOp: - wordCnt = B_LITTLE16(*((uint16 *)srcP)); - srcP += sizeof(uint16); - if ((int16)wordCnt <= 0) - goto notLongSkip; /* Do SIGNED test. */ + wordCnt = B_LITTLE16(*((uint16 *)srcP)); + srcP += sizeof(uint16); + if ((int16)wordCnt <= 0) + goto notLongSkip; /* Do SIGNED test. */ -/* longSkip. */ - dstP += wordCnt; - goto nextOp; + /* longSkip. */ + dstP += wordCnt; + goto nextOp; notLongSkip: - if (wordCnt == 0) - goto stop; - wordCnt -= 0x8000; /* Remove sign bit. */ - if (wordCnt >= 0x4000) - goto longRun; + if (wordCnt == 0) + goto stop; + wordCnt -= 0x8000; /* Remove sign bit. */ + if (wordCnt >= 0x4000) + goto longRun; -/* longDump. */ - do - { - *dstP++ = *srcP++; - } while (--wordCnt); - goto nextOp; + /* longDump. */ + do + { + *dstP++ = *srcP++; + } + while (--wordCnt); + goto nextOp; longRun: - wordCnt -= 0x4000; /* Clear "longRun" bit. */ - pixel = *srcP++; - do - { - *dstP++ = pixel; - } while (--wordCnt); - goto nextOp; + wordCnt -= 0x4000; /* Clear "longRun" bit. */ + pixel = *srcP++; + do + { + *dstP++ = pixel; + } + while (--wordCnt); + goto nextOp; stop: /* all done */ - ; - } + ; +} @@ -203,34 +207,34 @@ stop: /* all done */ // //**************************************************************************** -void renderframe (uint16 framenumber, uint16 *pagepointer) - { - uint16 offset=0; - uint16 i; - uint16 destframe; - byte *ppointer; +void renderframe(uint16 framenumber, uint16 *pagepointer) +{ + uint16 offset=0; + uint16 i; + uint16 destframe; + byte *ppointer; - CheckAnimStarted ( "renderframe" ); - destframe = framenumber - anim->curlp.baseRecord; + CheckAnimStarted("renderframe"); + destframe = framenumber - anim->curlp.baseRecord; - for(i = 0; i < destframe; i++) - { - offset += B_LITTLE16(pagepointer[i]); - } - ppointer = (byte *)pagepointer; + for (i = 0; i < destframe; i++) + { + offset += B_LITTLE16(pagepointer[i]); + } + ppointer = (byte *)pagepointer; - ppointer+=anim->curlp.nRecords*2+offset; - if(ppointer[1]) - { - ppointer += (4 + B_LITTLE16(((uint16 *)ppointer)[1]) + (B_LITTLE16(((uint16 *)ppointer)[1]) & 1)); - } - else - { - ppointer+=4; - } + ppointer+=anim->curlp.nRecords*2+offset; + if (ppointer[1]) + { + ppointer += (4 + B_LITTLE16(((uint16 *)ppointer)[1]) + (B_LITTLE16(((uint16 *)ppointer)[1]) & 1)); + } + else + { + 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) - { - CheckAnimStarted ( "drawframe" ); - loadpage(findpage(framenumber), anim->thepage); - renderframe(framenumber, anim->thepage); - } +void drawframe(uint16 framenumber) +{ + CheckAnimStarted("drawframe"); + loadpage(findpage(framenumber), anim->thepage); + renderframe(framenumber, anim->thepage); +} //**************************************************************************** @@ -254,54 +258,55 @@ void drawframe (uint16 framenumber) // //**************************************************************************** -void ANIM_LoadAnim (char * buffer) - { - uint16 i; - int32 size; +void ANIM_LoadAnim(char * buffer) +{ + uint16 i; + int32 size; - if (!Anim_Started) { - anim = SafeMalloc(sizeof(anim_t)); - Anim_Started = true; - } + if (!Anim_Started) + { + anim = SafeMalloc(sizeof(anim_t)); + Anim_Started = true; + } - anim->buffer = (unsigned char *)buffer; - anim->curlpnum = 0xffff; - anim->currentframe = -1; - size = sizeof(lpfileheader); - Bmemcpy(&anim->lpheader, buffer, size ); + anim->buffer = (unsigned char *)buffer; + anim->curlpnum = 0xffff; + anim->currentframe = -1; + size = sizeof(lpfileheader); + Bmemcpy(&anim->lpheader, buffer, size); - anim->lpheader.id = B_LITTLE32(anim->lpheader.id); - anim->lpheader.maxLps = B_LITTLE16(anim->lpheader.maxLps); - anim->lpheader.nLps = B_LITTLE16(anim->lpheader.nLps); - anim->lpheader.nRecords = B_LITTLE32(anim->lpheader.nRecords); - anim->lpheader.maxRecsPerLp = B_LITTLE16(anim->lpheader.maxRecsPerLp); - anim->lpheader.lpfTableOffset = B_LITTLE16(anim->lpheader.lpfTableOffset); - anim->lpheader.contentType = B_LITTLE32(anim->lpheader.contentType); - anim->lpheader.width = B_LITTLE16(anim->lpheader.width); - anim->lpheader.height = B_LITTLE16(anim->lpheader.height); - anim->lpheader.nFrames = B_LITTLE32(anim->lpheader.nFrames); - anim->lpheader.framesPerSecond = B_LITTLE16(anim->lpheader.framesPerSecond); - - buffer += size+128; - // load the color palette - for (i = 0; i < 768; i += 3) - { - anim->pal[i+2] = *buffer++; - anim->pal[i+1] = *buffer++; - anim->pal[i] = *buffer++; - buffer++; - } - // read in large page descriptors - size = sizeof(anim->LpArray); - Bmemcpy(&anim->LpArray,buffer,size); + anim->lpheader.id = B_LITTLE32(anim->lpheader.id); + anim->lpheader.maxLps = B_LITTLE16(anim->lpheader.maxLps); + anim->lpheader.nLps = B_LITTLE16(anim->lpheader.nLps); + anim->lpheader.nRecords = B_LITTLE32(anim->lpheader.nRecords); + anim->lpheader.maxRecsPerLp = B_LITTLE16(anim->lpheader.maxRecsPerLp); + anim->lpheader.lpfTableOffset = B_LITTLE16(anim->lpheader.lpfTableOffset); + anim->lpheader.contentType = B_LITTLE32(anim->lpheader.contentType); + anim->lpheader.width = B_LITTLE16(anim->lpheader.width); + anim->lpheader.height = B_LITTLE16(anim->lpheader.height); + anim->lpheader.nFrames = B_LITTLE32(anim->lpheader.nFrames); + anim->lpheader.framesPerSecond = B_LITTLE16(anim->lpheader.framesPerSecond); - for (i = 0; i < size/sizeof(lp_descriptor); i++) - { - anim->LpArray[i].baseRecord = B_LITTLE16(anim->LpArray[i].baseRecord); - anim->LpArray[i].nRecords = B_LITTLE16(anim->LpArray[i].nRecords); - anim->LpArray[i].nBytes = B_LITTLE16(anim->LpArray[i].nBytes); - } - } + buffer += size+128; + // load the color palette + for (i = 0; i < 768; i += 3) + { + anim->pal[i+2] = *buffer++; + anim->pal[i+1] = *buffer++; + anim->pal[i] = *buffer++; + buffer++; + } + // read in large page descriptors + size = sizeof(anim->LpArray); + Bmemcpy(&anim->LpArray,buffer,size); + + for (i = 0; i < size/sizeof(lp_descriptor); i++) + { + anim->LpArray[i].baseRecord = B_LITTLE16(anim->LpArray[i].baseRecord); + anim->LpArray[i].nRecords = B_LITTLE16(anim->LpArray[i].nRecords); + anim->LpArray[i].nBytes = B_LITTLE16(anim->LpArray[i].nBytes); + } +} //**************************************************************************** // @@ -309,14 +314,14 @@ void ANIM_LoadAnim (char * buffer) // //**************************************************************************** -void ANIM_FreeAnim ( void ) - { - if (Anim_Started) - { - SafeFree(anim); - Anim_Started = false; - } - } +void ANIM_FreeAnim(void) +{ + if (Anim_Started) + { + SafeFree(anim); + Anim_Started = false; + } +} //**************************************************************************** // @@ -324,11 +329,11 @@ void ANIM_FreeAnim ( void ) // //**************************************************************************** -int32 ANIM_NumFrames ( void ) - { - CheckAnimStarted ( "NumFrames" ); - return anim->lpheader.nRecords; - } +int32 ANIM_NumFrames(void) +{ + CheckAnimStarted("NumFrames"); + return anim->lpheader.nRecords; +} //**************************************************************************** // @@ -336,24 +341,24 @@ int32 ANIM_NumFrames ( void ) // //**************************************************************************** -byte * ANIM_DrawFrame (int32 framenumber) - { - int32 cnt; +byte * ANIM_DrawFrame(int32 framenumber) +{ + int32 cnt; - CheckAnimStarted ( "DrawFrame" ); - if ((anim->currentframe != -1) && (anim->currentframe<=framenumber)) - { - for (cnt = anim->currentframe; cnt < framenumber; cnt++) - drawframe (cnt); - } - else - { - for (cnt = 0; cnt < framenumber; cnt++) - drawframe (cnt); - } - anim->currentframe = framenumber; - return anim->imagebuffer; - } + CheckAnimStarted("DrawFrame"); + if ((anim->currentframe != -1) && (anim->currentframe<=framenumber)) + { + for (cnt = anim->currentframe; cnt < framenumber; cnt++) + drawframe(cnt); + } + else + { + for (cnt = 0; cnt < framenumber; cnt++) + drawframe(cnt); + } + anim->currentframe = framenumber; + return anim->imagebuffer; +} //**************************************************************************** // @@ -361,8 +366,8 @@ byte * ANIM_DrawFrame (int32 framenumber) // //**************************************************************************** -byte * ANIM_GetPalette ( void ) - { - CheckAnimStarted ( "GetPalette" ); - return anim->pal; - } +byte * ANIM_GetPalette(void) +{ + CheckAnimStarted("GetPalette"); + return anim->pal; +} diff --git a/polymer/eduke32/source/jmact/control.c b/polymer/eduke32/source/jmact/control.c index 61c6122ac..3a262bd10 100644 --- a/polymer/eduke32/source/jmact/control.c +++ b/polymer/eduke32/source/jmact/control.c @@ -1,7 +1,7 @@ /* * control.c * MACT library controller handling - * + * * Derived from MACT386.LIB disassembly by Jonathon Fowler * */ @@ -50,7 +50,7 @@ static boolean CONTROL_MouseButtonClickedState[MAXMOUSEBUTTONS], CONTROL_JoyButt static boolean CONTROL_MouseButtonClicked[MAXMOUSEBUTTONS], CONTROL_JoyButtonClicked[MAXJOYBUTTONS]; static byte CONTROL_MouseButtonClickedCount[MAXMOUSEBUTTONS], CONTROL_JoyButtonClickedCount[MAXJOYBUTTONS]; static boolean CONTROL_UserInputCleared[3]; -static int32 (*GetTime)(void); +static int32(*GetTime)(void); static boolean CONTROL_Started = false; static int32 ticrate; static int32 CONTROL_DoubleClickSpeed; @@ -92,7 +92,7 @@ boolean CONTROL_StartMouse(void) 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; @@ -139,12 +139,18 @@ void CONTROL_SetFlag(int32 which, boolean active) { if (CONTROL_CheckRange(which)) return; - if (CONTROL_Flags[which].toggle == INSTANT_ONOFF) { + if (CONTROL_Flags[which].toggle == INSTANT_ONOFF) + { CONTROL_Flags[which].active = active; - } else { - if (active) { + } + else + { + if (active) + { 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].active = (CONTROL_Flags[which].active ? false : true); } @@ -181,7 +187,7 @@ void CONTROL_ClearKeyboardFunction(int32 which) 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; @@ -192,14 +198,14 @@ void CONTROL_DefineFlag( int32 which, boolean toggle ) CONTROL_Flags[which].cleared = 0; } -boolean CONTROL_FlagActive( int32 which ) +boolean CONTROL_FlagActive(int32 which) { if (CONTROL_CheckRange(which)) return false; 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; @@ -211,7 +217,8 @@ void CONTROL_PrintKeyMap(void) { int32 i; - for (i=0;i= (uint32)MAXMOUSEBUTTONS) { + if ((uint32)whichbutton >= (uint32)MAXMOUSEBUTTONS) + { //Error("CONTROL_MapButton: button %d out of valid range for %d mouse buttons.", // whichbutton, CONTROL_NumMouseButtons); return; @@ -261,7 +272,8 @@ void CONTROL_MapButton( int32 whichfunction, int32 whichbutton, boolean doublecl break; 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.", // whichbutton, CONTROL_NumJoyButtons); return; @@ -280,19 +292,22 @@ void CONTROL_MapButton( int32 whichfunction, int32 whichbutton, boolean doublecl set[whichbutton].singleclicked = whichfunction; } -void CONTROL_MapAnalogAxis( int32 whichaxis, int32 whichanalog, controldevice device ) +void CONTROL_MapAnalogAxis(int32 whichaxis, int32 whichanalog, controldevice device) { 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.", // whichanalog, analog_maxtype); return; } - switch (device) { + switch (device) + { 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.", // whichaxis, MAXMOUSEAXES); return; @@ -302,7 +317,8 @@ void CONTROL_MapAnalogAxis( int32 whichaxis, int32 whichanalog, controldevice de break; 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.", // whichaxis, MAXJOYAXES); return; @@ -319,13 +335,15 @@ void CONTROL_MapAnalogAxis( int32 whichaxis, int32 whichanalog, controldevice de set[whichaxis].analogmap = whichanalog; } -void CONTROL_SetAnalogAxisScale( int32 whichaxis, int32 axisscale, controldevice device ) +void CONTROL_SetAnalogAxisScale(int32 whichaxis, int32 axisscale, controldevice device) { int32 *set; - switch (device) { + switch (device) + { 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.", // whichaxis, MAXMOUSEAXES); return; @@ -335,7 +353,8 @@ void CONTROL_SetAnalogAxisScale( int32 whichaxis, int32 axisscale, controldevice break; 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.", // whichaxis, MAXJOYAXES); return; @@ -352,15 +371,17 @@ void CONTROL_SetAnalogAxisScale( int32 whichaxis, int32 axisscale, controldevice 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; if (CONTROL_CheckRange(whichfunction)) whichfunction = AXISUNDEFINED; - switch (device) { + switch (device) + { 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.", // whichaxis, MAXMOUSEAXES); return; @@ -370,7 +391,8 @@ void CONTROL_MapDigitalAxis( int32 whichaxis, int32 whichfunction, int32 directi break; 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.", // whichaxis, MAXJOYAXES); return; @@ -384,7 +406,8 @@ void CONTROL_MapDigitalAxis( int32 whichaxis, int32 whichfunction, int32 directi 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_left: set[whichaxis].minmap = whichfunction; @@ -406,7 +429,7 @@ void CONTROL_ClearFlags(void) CONTROL_Flags[i].used = false; } -void CONTROL_ClearAssignments( void ) +void CONTROL_ClearAssignments(void) { int32 i; @@ -433,33 +456,42 @@ static void DoGetDeviceButtons( boolean *ButtonClickedState, boolean *ButtonClicked, byte *ButtonClickedCount -) { +) +{ int32 i, bs; - for (i=0;i> i) & 1; DeviceButtonState[i] = bs; ButtonClickedState[i] = false; - if (bs) { - if (ButtonClicked[i] == false) { + if (bs) + { + if (ButtonClicked[i] == false) + { ButtonClicked[i] = true; - if (ButtonClickedCount[i] == 0 || tm > ButtonClickedTime[i]) { + if (ButtonClickedCount[i] == 0 || tm > ButtonClickedTime[i]) + { ButtonClickedTime[i] = tm + CONTROL_DoubleClickSpeed; ButtonClickedCount[i] = 1; } - else if (tm < ButtonClickedTime[i]) { + else if (tm < ButtonClickedTime[i]) + { ButtonClickedState[i] = true; ButtonClickedTime[i] = 0; ButtonClickedCount[i] = 2; } } - else if (ButtonClickedCount[i] == 2) { + else if (ButtonClickedCount[i] == 2) + { ButtonClickedState[i] = true; } - } else { + } + else + { if (ButtonClickedCount[i] == 2) ButtonClickedCount[i] = 0; @@ -474,7 +506,8 @@ void CONTROL_GetDeviceButtons(void) t = GetTime(); - if (CONTROL_MouseEnabled) { + if (CONTROL_MouseEnabled) + { DoGetDeviceButtons( MOUSE_GetButtons(), t, CONTROL_NumMouseButtons, @@ -486,9 +519,11 @@ void CONTROL_GetDeviceButtons(void) ); } - if (CONTROL_JoystickEnabled) { + if (CONTROL_JoystickEnabled) + { 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 }; int val; @@ -513,7 +548,8 @@ void CONTROL_DigitizeAxis(int32 axis, controldevice device) { controlaxistype *set, *lastset; - switch (device) { + switch (device) + { case controldevice_mouse: set = CONTROL_MouseAxes; lastset = CONTROL_LastMouseAxes; @@ -527,20 +563,31 @@ void CONTROL_DigitizeAxis(int32 axis, controldevice device) default: return; } - if (set[axis].analog > 0) { - if (set[axis].analog > THRESHOLD) { // if very much in one direction, + if (set[axis].analog > 0) + { + if (set[axis].analog > THRESHOLD) // if very much in one direction, + { 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 set[axis].digital = 1; } } - } else { - if (set[axis].analog < -THRESHOLD) { + } + else + { + if (set[axis].analog < -THRESHOLD) + { set[axis].digital = -1; - } else { - if (set[axis].analog < -MINTHRESHOLD) { + } + else + { + if (set[axis].analog < -MINTHRESHOLD) + { if (lastset[axis].digital == -1) set[axis].digital = -1; } @@ -553,7 +600,8 @@ void CONTROL_ScaleAxis(int32 axis, controldevice device) controlaxistype *set; int32 *scale; - switch (device) { + switch (device) + { case controldevice_mouse: set = CONTROL_MouseAxes; scale = CONTROL_MouseAxesScale; @@ -575,7 +623,8 @@ void CONTROL_ApplyAxis(int32 axis, ControlInfo *info, controldevice device) controlaxistype *set; controlaxismaptype *map; - switch (device) { + switch (device) + { case controldevice_mouse: set = CONTROL_MouseAxes; map = CONTROL_MouseAxesMap; @@ -589,7 +638,8 @@ void CONTROL_ApplyAxis(int32 axis, ControlInfo *info, controldevice device) default: return; } - switch (map[axis].analogmap) { + switch (map[axis].analogmap) + { case analog_turning: info->dyaw += set[axis].analog; break; case analog_strafing: info->dx += 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(info, 0, sizeof(ControlInfo)); - if (CONTROL_MouseEnabled) { + if (CONTROL_MouseEnabled) + { CONTROL_GetMouseDelta(); - for (i=0; ibutton1) CONTROL_UserInputCleared[2] = true; } */ -void CONTROL_ClearButton( int32 whichbutton ) +void CONTROL_ClearButton(int32 whichbutton) { - if (CONTROL_CheckRange( whichbutton )) return; - BUTTONCLEAR( whichbutton ); + if (CONTROL_CheckRange(whichbutton)) return; + BUTTONCLEAR(whichbutton); CONTROL_Flags[whichbutton].cleared = true; } @@ -797,7 +855,7 @@ void CONTROL_ProcessBinds(void) { if (boundkeys[i].name[0] && KB_KeyPressed(i)) { - if (boundkeys[i].repeat || (boundkeys[i].laststate == 0)) + if (boundkeys[i].repeat || (boundkeys[i].laststate == 0)) OSD_Dispatch(boundkeys[i].name); // if (!boundkeys[i].repeat) // KB_ClearKeyDown(i); @@ -807,11 +865,11 @@ void CONTROL_ProcessBinds(void) } -void CONTROL_GetInput( ControlInfo *info ) +void CONTROL_GetInput(ControlInfo *info) { int32 i, periphs[CONTROL_NUM_FLAGS]; - CONTROL_PollDevices( info ); + CONTROL_PollDevices(info); memset(periphs, 0, sizeof(periphs)); CONTROL_ButtonFunctionState(periphs); @@ -823,7 +881,8 @@ void CONTROL_GetInput( ControlInfo *info ) CONTROL_ProcessBinds(); - for (i=0; i= 0x47 && ch <= 0x52) shifted = numpad; - - return sctoasc[shifted][ch]; -*/ - return (char)bgetchar(); + shifted = ((keystatus[0x2a]!=0)||(keystatus[0x36]!=0)); + if (ch >= 0x47 && ch <= 0x52) shifted = numpad; + + return sctoasc[shifted][ch]; + */ + return (char)bgetchar(); } -void KB_FlushKeyboardQueue( void ) +void KB_FlushKeyboardQueue(void) { - //keyfifoplc = keyfifoend = 0; - bflushchars(); + //keyfifoplc = keyfifoend = 0; + bflushchars(); } -void KB_ClearKeysDown( void ) +void KB_ClearKeysDown(void) { - KB_LastScan = 0; - memset(keystatus, 0, sizeof(keystatus)); - //keyfifoplc = keyfifoend = 0; - //bflushchars(); + KB_LastScan = 0; + memset(keystatus, 0, sizeof(keystatus)); + //keyfifoplc = keyfifoend = 0; + //bflushchars(); } -char *KB_ScanCodeToString( kb_scancode scancode ) +char *KB_ScanCodeToString(kb_scancode scancode) { - unsigned s; + unsigned s; - for (s=0; s < (sizeof(sctokeylut)/sizeof(sctokeylut[0])); s++) - if (sctokeylut[s].sc == scancode) return sctokeylut[s].key; - - return ""; + for (s=0; s < (sizeof(sctokeylut)/sizeof(sctokeylut[0])); s++) + if (sctokeylut[s].sc == scancode) return sctokeylut[s].key; + + return ""; } -kb_scancode KB_StringToScanCode( char * string ) +kb_scancode KB_StringToScanCode(char * string) { - unsigned s; - - for (s=0; s < (sizeof(sctokeylut)/sizeof(sctokeylut[0])); s++) - if (!Bstrcasecmp(sctokeylut[s].key, string)) return sctokeylut[s].sc; + unsigned s; - return 0; + for (s=0; s < (sizeof(sctokeylut)/sizeof(sctokeylut[0])); s++) + if (!Bstrcasecmp(sctokeylut[s].key, string)) return sctokeylut[s].sc; + + 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; - setkeypresscallback(KB_KeyEvent); + numpad = 0; + setkeypresscallback(KB_KeyEvent); } -void KB_Shutdown( void ) +void KB_Shutdown(void) { - setkeypresscallback((void(*)(int,int))NULL); + setkeypresscallback((void(*)(int,int))NULL); } diff --git a/polymer/eduke32/source/jmact/mathutil.c b/polymer/eduke32/source/jmact/mathutil.c index 422051cce..06bfabe5a 100644 --- a/polymer/eduke32/source/jmact/mathutil.c +++ b/polymer/eduke32/source/jmact/mathutil.c @@ -37,14 +37,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Ken's reverse-engineering job int32 FindDistance2D(int32 x, int32 y) { - int32 i; - x = labs(x); - y = labs(y); - if (!x) return(y); - if (!y) return(x); - if (y < x) { i = x; x = y; y = i; } //swap x, y - x += (x>>1); - return ((x>>6)+(x>>2)+y-(y>>5)-(y>>7)); //handle 1 octant + int32 i; + x = labs(x); + y = labs(y); + if (!x) return(y); + if (!y) return(x); + if (y < x) { i = x; x = y; y = i; } //swap x, y + x += (x>>1); + return ((x>>6)+(x>>2)+y-(y>>5)-(y>>7)); //handle 1 octant } // My abomination @@ -59,7 +59,7 @@ int32 FindDistance2D(int32 dx, int32 dy) int32 FindDistance3D(int32 dx, int32 dy, int32 dz) { // return (int32)floor(sqrt((double)(sqr(dx)+sqr(dy)+sqr(dz)))); - return ksqrt(square(dx)+square(dy)+square(dz)); + return ksqrt(square(dx)+square(dy)+square(dz)); } #else @@ -77,36 +77,36 @@ int32 FindDistance3D(int32 dx, int32 dy, int32 dz) int32 FindDistance2D(int32 x, int32 y) { - int32 t; + int32 t; - x= abs(x); /* absolute values */ - y= abs(y); + x= abs(x); /* absolute values */ + y= abs(y); - if (x>1); + t = y + (y>>1); - return (x - (x>>5) - (x>>7) + (t>>2) + (t>>6)); + return (x - (x>>5) - (x>>7) + (t>>2) + (t>>6)); } int32 FindDistance3D(int32 x, int32 y, int32 z) - { - int32 t; +{ + int32 t; - x= abs(x); /* absolute values */ - y= abs(y); - z= abs(z); + x= abs(x); /* absolute values */ + y= abs(y); + z= abs(z); - if (x>4) + (t>>2) + (t>>3)); - } + return (x - (x>>4) + (t>>2) + (t>>3)); +} #endif diff --git a/polymer/eduke32/source/jmact/mouse.c b/polymer/eduke32/source/jmact/mouse.c index b866cb7b1..01a7f438d 100644 --- a/polymer/eduke32/source/jmact/mouse.c +++ b/polymer/eduke32/source/jmact/mouse.c @@ -1,7 +1,7 @@ /* * mouse.c * MACT library -to- JonoF's Build Port Mouse Glue - * + * * by Jonathon Fowler * * Since we don't have the source to the MACT library I've had to @@ -38,46 +38,46 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "baselayer.h" -boolean MOUSE_Init( void ) +boolean MOUSE_Init(void) { - initmouse(); - return ((inputdevices & 2) == 2); + initmouse(); + 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; - readmousebstatus(&buttons); - return buttons; + int32 buttons; + readmousebstatus(&buttons); + return buttons; } -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); } diff --git a/polymer/eduke32/source/jmact/scriplib.c b/polymer/eduke32/source/jmact/scriplib.c index 9218b648b..b81cd2186 100644 --- a/polymer/eduke32/source/jmact/scriplib.c +++ b/polymer/eduke32/source/jmact/scriplib.c @@ -1,7 +1,7 @@ /* * scriplib.c - * MACT library Script file parsing and writing - * + * MACT library Script file parsing and writing + * * by Jonathon Fowler * * Since we weren't given the source for MACT386.LIB so I've had to do some @@ -56,58 +56,63 @@ static script_t *scriptfiles[MAXSCRIPTFILES]; int32 SCRIPT_New(void) { - int32 i; + int32 i; - for (i=0; i= MAXSCRIPTFILES) return; + ScriptSectionType *s; - if (!SC(scripthandle)) return; + if (scripthandle < 0 || scripthandle >= MAXSCRIPTFILES) return; - if (SCRIPT(scripthandle,script)) { - while (SCRIPT(scripthandle,script)->nextsection != SCRIPT(scripthandle,script)) { - s = SCRIPT(scripthandle,script)->nextsection; - SCRIPT_FreeSection(SCRIPT(scripthandle,script)); - SafeFree(SCRIPT(scripthandle,script)); - SCRIPT(scripthandle,script) = s; - } + if (!SC(scripthandle)) return; - SafeFree(SCRIPT(scripthandle,script)); - } + if (SCRIPT(scripthandle,script)) + { + while (SCRIPT(scripthandle,script)->nextsection != SCRIPT(scripthandle,script)) + { + s = SCRIPT(scripthandle,script)->nextsection; + SCRIPT_FreeSection(SCRIPT(scripthandle,script)); + SafeFree(SCRIPT(scripthandle,script)); + SCRIPT(scripthandle,script) = s; + } - SafeFree(SC(scripthandle)); - SC(scripthandle) = 0; + SafeFree(SCRIPT(scripthandle,script)); + } + + SafeFree(SC(scripthandle)); + SC(scripthandle) = 0; } void SCRIPT_FreeSection(ScriptSectionType * section) { - ScriptEntryType *e; - - if (!section) return; - if (!section->entries) return; + ScriptEntryType *e; - while (section->entries->nextentry != section->entries) { - e = section->entries->nextentry; - SafeFree(section->entries); - section->entries = e; - } + if (!section) return; + if (!section->entries) return; - SafeFree(section->entries); - free(section->name); + while (section->entries->nextentry != section->entries) + { + e = section->entries->nextentry; + SafeFree(section->entries); + section->entries = e; + } + + SafeFree(section->entries); + free(section->name); } #define AllocSection(s) \ @@ -128,752 +133,811 @@ void SCRIPT_FreeSection(ScriptSectionType * section) (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; - if (scripthandle < 0 || scripthandle >= MAXSCRIPTFILES) return NULL; - if (!sectionname) return NULL; - if (!SC(scripthandle)) return NULL; - if (!SCRIPT(scripthandle,script)) return NULL; + if (scripthandle < 0 || scripthandle >= MAXSCRIPTFILES) return NULL; + if (!sectionname) return NULL; + if (!SC(scripthandle)) return NULL; + if (!SCRIPT(scripthandle,script)) return NULL; - for (s = SCRIPT(scripthandle,script); ls != s; ls=s,s=s->nextsection) - if (!Bstrcasecmp(s->name, sectionname)) return s; + for (s = SCRIPT(scripthandle,script); ls != s; ls=s,s=s->nextsection) + if (!Bstrcasecmp(s->name, sectionname)) return s; - return NULL; + return NULL; } -ScriptSectionType * SCRIPT_AddSection( int32 scripthandle, char * sectionname ) +ScriptSectionType * SCRIPT_AddSection(int32 scripthandle, char * sectionname) { - ScriptSectionType *s,*s2; + ScriptSectionType *s,*s2; - if (scripthandle < 0 || scripthandle >= MAXSCRIPTFILES) return NULL; - if (!sectionname) return NULL; - if (!SC(scripthandle)) return NULL; + if (scripthandle < 0 || scripthandle >= MAXSCRIPTFILES) return NULL; + if (!sectionname) return NULL; + if (!SC(scripthandle)) return NULL; - s = SCRIPT_SectionExists(scripthandle, sectionname); - if (s) return s; - - AllocSection(s); - s->name = strdup(sectionname); - if (!SCRIPT(scripthandle,script)) { - SCRIPT(scripthandle,script) = s; - } else { - s2 = SCRIPT(scripthandle,script); - while (s2->nextsection != s2) s2=s2->nextsection; - s2->nextsection = s; - s->prevsection = s2; - } + s = SCRIPT_SectionExists(scripthandle, sectionname); + if (s) return s; - return s; + AllocSection(s); + s->name = strdup(sectionname); + if (!SCRIPT(scripthandle,script)) + { + SCRIPT(scripthandle,script) = s; + } + else + { + s2 = SCRIPT(scripthandle,script); + while (s2->nextsection != s2) s2=s2->nextsection; + s2->nextsection = s; + s->prevsection = s2; + } + + return s; } -ScriptEntryType * SCRIPT_EntryExists ( ScriptSectionType * section, char * entryname ) +ScriptEntryType * SCRIPT_EntryExists(ScriptSectionType * section, char * entryname) { - ScriptEntryType *e,*le=NULL; + ScriptEntryType *e,*le=NULL; - if (!section) return NULL; - if (!entryname) return NULL; - if (!section->entries) return NULL; + if (!section) return NULL; + if (!entryname) return NULL; + if (!section->entries) return NULL; - for (e = section->entries; le != e; le=e,e=e->nextentry) - if (!Bstrcasecmp(e->name, entryname)) return e; + for (e = section->entries; le != e; le=e,e=e->nextentry) + if (!Bstrcasecmp(e->name, entryname)) return e; - 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; - ScriptEntryType *e,*e2; + ScriptSectionType *s; + ScriptEntryType *e,*e2; - if (scripthandle < 0 || scripthandle >= MAXSCRIPTFILES) return; - if (!sectionname || !entryname || !entryvalue) return; - if (!SC(scripthandle)) return; + if (scripthandle < 0 || scripthandle >= MAXSCRIPTFILES) return; + if (!sectionname || !entryname || !entryvalue) return; + if (!SC(scripthandle)) return; // s = SCRIPT_SectionExists(scripthandle, sectionname); // if (!s) { - s = SCRIPT_AddSection(scripthandle, sectionname); - if (!s) return; + s = SCRIPT_AddSection(scripthandle, sectionname); + if (!s) return; // } - e = SCRIPT_EntryExists(s, entryname); - if (!e) { - AllocEntry(e); - e->name = strdup(entryname); - if (!s->entries) { - s->entries = e; - } else { - e2 = s->entries; - while (e2->nextentry != e2) e2=e2->nextentry; - e2->nextentry = e; - e->preventry = e2; - } - } + e = SCRIPT_EntryExists(s, entryname); + if (!e) + { + AllocEntry(e); + e->name = strdup(entryname); + if (!s->entries) + { + s->entries = e; + } + else + { + e2 = s->entries; + while (e2->nextentry != e2) e2=e2->nextentry; + e2->nextentry = e; + e->preventry = e2; + } + } - if (e->value) free(e->value); - e->value = strdup(entryvalue); + if (e->value) free(e->value); + e->value = strdup(entryvalue); } int32 SCRIPT_ParseBuffer(int32 scripthandle, char *data, int32 length) { - char *fence = data + length; - char *dp, *sp, ch=0, lastch=0; - char *currentsection = ""; - char *currententry = NULL; - char *currentvalue = NULL; - enum { - ParsingIdle, - ParsingSectionBegin, - ParsingSectionName, - ParsingEntry, - ParsingValueBegin, - ParsingValue - }; - enum { - ExpectingSection = 1, - ExpectingEntry = 2, - ExpectingAssignment = 4, - ExpectingValue = 8, - ExpectingComment = 16 - }; - int state; - int expect; - int linenum=1; - int rv = 0; + char *fence = data + length; + char *dp, *sp, ch=0, lastch=0; + char *currentsection = ""; + char *currententry = NULL; + char *currentvalue = NULL; + enum + { + ParsingIdle, + ParsingSectionBegin, + ParsingSectionName, + ParsingEntry, + ParsingValueBegin, + ParsingValue + }; + enum + { + ExpectingSection = 1, + ExpectingEntry = 2, + ExpectingAssignment = 4, + ExpectingValue = 8, + ExpectingComment = 16 + }; + int state; + int expect; + int linenum=1; + int rv = 0; #define SETRV(v) if (v>rv||rv==0) rv=v - if (!data) return 1; - if (length < 0) return 1; - - dp = sp = data; - state = ParsingIdle; - expect = ExpectingSection | ExpectingEntry; + if (!data) return 1; + if (length < 0) return 1; + + dp = sp = data; + state = ParsingIdle; + expect = ExpectingSection | ExpectingEntry; #define EATLINE(p) while (length > 0 && *p != '\n' && *p != '\r') { p++; length--; } #define LETTER() { lastch = ch; ch = *(sp++); length--; } - while (length > 0) { - switch (state) { - case ParsingIdle: - LETTER(); - switch (ch) { - // whitespace - case ' ': - case '\t': continue; - case '\n': if (lastch == '\r') continue; linenum++; continue; - case '\r': linenum++; continue; + while (length > 0) + { + switch (state) + { + case ParsingIdle: + LETTER(); + switch (ch) + { + // whitespace + case ' ': + case '\t': continue; + case '\n': if (lastch == '\r') continue; linenum++; continue; + case '\r': linenum++; continue; - case ';': - /*case '#':*/ - EATLINE(sp); - continue; + case ';': + /*case '#':*/ + EATLINE(sp); + continue; - case '[': if (!(expect & ExpectingSection)) { - // Unexpected section start - printf("Unexpected start of section on line %d.\n", linenum); - SETRV(-1); - EATLINE(sp); - continue; - } else { - state = ParsingSectionBegin; - continue; - } + case '[': if (!(expect & ExpectingSection)) + { + // Unexpected section start + printf("Unexpected start of section on line %d.\n", linenum); + SETRV(-1); + EATLINE(sp); + continue; + } + else + { + state = ParsingSectionBegin; + continue; + } - default: if (isalpha(ch)) { - if (!(expect & ExpectingEntry)) { - // Unexpected name start - printf("Unexpected entry label on line %d.\n", linenum); - SETRV(-1); - EATLINE(sp); - continue; - } else { - currententry = dp = sp-1; - state = ParsingEntry; - continue; - } - } else { - // Unexpected character - printf("Illegal character (ASCII %d) on line %d.\n", ch, linenum); - SETRV(-1); - EATLINE(sp); - continue; - } - } + default: if (isalpha(ch)) + { + if (!(expect & ExpectingEntry)) + { + // Unexpected name start + printf("Unexpected entry label on line %d.\n", linenum); + SETRV(-1); + EATLINE(sp); + continue; + } + else + { + currententry = dp = sp-1; + state = ParsingEntry; + continue; + } + } + else + { + // Unexpected character + printf("Illegal character (ASCII %d) on line %d.\n", ch, linenum); + SETRV(-1); + EATLINE(sp); + continue; + } + } - case ParsingSectionBegin: - currentsection = dp = sp; - state = ParsingSectionName; - case ParsingSectionName: - LETTER(); - switch (ch) { - case '\n': - case '\r': // Unexpected newline - printf("Unexpected newline on line %d.\n", linenum); - SETRV(-1); - state = ParsingIdle; - linenum++; - continue; + case ParsingSectionBegin: + currentsection = dp = sp; + state = ParsingSectionName; + case ParsingSectionName: + LETTER(); + switch (ch) + { + case '\n': + case '\r': // Unexpected newline + printf("Unexpected newline on line %d.\n", linenum); + SETRV(-1); + state = ParsingIdle; + linenum++; + continue; - case ']': - *(dp) = 0; // Add new section - expect = ExpectingSection | ExpectingEntry; - state = ParsingIdle; - EATLINE(sp); - continue; + case ']': + *(dp) = 0; // Add new section + expect = ExpectingSection | ExpectingEntry; + state = ParsingIdle; + EATLINE(sp); + continue; - default: - dp++; - continue; - } + default: + dp++; + continue; + } - case ParsingEntry: - LETTER(); - switch (ch) { - case ';': - /*case '#':*/ - // unexpected comment - EATLINE(sp); - printf("Unexpected comment on line %d.\n", linenum); - SETRV(-1); - case '\n': - case '\r': - // Unexpected newline - printf("Unexpected newline on line %d.\n", linenum); - SETRV(-1); - expect = ExpectingSection | ExpectingEntry; - state = ParsingIdle; - linenum++; - continue; + case ParsingEntry: + LETTER(); + switch (ch) + { + case ';': + /*case '#':*/ + // unexpected comment + EATLINE(sp); + printf("Unexpected comment on line %d.\n", linenum); + SETRV(-1); + case '\n': + case '\r': + // Unexpected newline + printf("Unexpected newline on line %d.\n", linenum); + SETRV(-1); + expect = ExpectingSection | ExpectingEntry; + state = ParsingIdle; + linenum++; + continue; - case '=': - // Entry name finished, now for the value - while (*dp == ' ' || *dp == '\t') dp--; - *(++dp) = 0; - state = ParsingValueBegin; - continue; + case '=': + // Entry name finished, now for the value + while (*dp == ' ' || *dp == '\t') dp--; + *(++dp) = 0; + state = ParsingValueBegin; + continue; - default: - dp++; - continue; - } + default: + dp++; + continue; + } - case ParsingValueBegin: - currentvalue = dp = sp; - state = ParsingValue; - case ParsingValue: - LETTER(); - switch (ch) { - case '\n': - case '\r': - // value complete, add it using parsed name - while (*dp == ' ' && *dp == '\t') dp--; - *(dp) = 0; - while (*currentvalue == ' ' || *currentvalue == '\t') currentvalue++; - state = ParsingIdle; - linenum++; + case ParsingValueBegin: + currentvalue = dp = sp; + state = ParsingValue; + case ParsingValue: + LETTER(); + switch (ch) + { + case '\n': + case '\r': + // value complete, add it using parsed name + while (*dp == ' ' && *dp == '\t') dp--; + *(dp) = 0; + while (*currentvalue == ' ' || *currentvalue == '\t') currentvalue++; + state = ParsingIdle; + linenum++; - SCRIPT_AddSection(scripthandle,currentsection); - SCRIPT_AddEntry(scripthandle,currentsection,currententry,currentvalue); - continue; + SCRIPT_AddSection(scripthandle,currentsection); + SCRIPT_AddEntry(scripthandle,currentsection,currententry,currentvalue); + continue; - default: - dp++; - continue; - } + default: + dp++; + continue; + } - default: length=0; - continue; - } - } + default: length=0; + continue; + } + } - if (sp > fence) printf("Stepped outside the fence!\n"); + if (sp > fence) printf("Stepped outside the fence!\n"); - return rv; + return rv; } //--- -int32 SCRIPT_Init( char * name ) +int32 SCRIPT_Init(char * name) { - int32 h = SCRIPT_New(); + int32 h = SCRIPT_New(); - if (h >= 0) strncpy(SCRIPT(h,scriptfilename), name, 127); + if (h >= 0) strncpy(SCRIPT(h,scriptfilename), name, 127); - 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; - char *b; - - h = SafeOpenRead(filename, filetype_binary); - l = SafeFileLength(h)+1; - b = (char *)SafeMalloc(l); - SafeRead(h,b,l-1); - b[l-1] = '\n'; // JBF 20040111: evil nasty hack to trick my evil nasty parser - SafeClose(h); - - s = SCRIPT_Init(filename); - if (s<0) { - SafeFree(b); - return -1; - } + int32 s,h,l; + char *b; - SCRIPT_ParseBuffer(s,b,l); + h = SafeOpenRead(filename, filetype_binary); + l = SafeFileLength(h)+1; + b = (char *)SafeMalloc(l); + SafeRead(h,b,l-1); + b[l-1] = '\n'; // JBF 20040111: evil nasty hack to trick my evil nasty parser + SafeClose(h); - SafeFree(b); - - return s; + s = SCRIPT_Init(filename); + if (s<0) + { + SafeFree(b); + return -1; + } + + SCRIPT_ParseBuffer(s,b,l); + + SafeFree(b); + + return s; } -void SCRIPT_Save (int32 scripthandle, char * filename) +void SCRIPT_Save(int32 scripthandle, char * filename) { - char *section, *entry, *value; - int sec, ent, numsect, nument; - FILE *fp; - + char *section, *entry, *value; + int sec, ent, numsect, nument; + FILE *fp; - if (!filename) return; - if (!SC(scripthandle)) return; - fp = fopen(filename, "w"); - if (!fp) return; + if (!filename) return; + if (!SC(scripthandle)) return; - numsect = SCRIPT_NumberSections(scripthandle); - for (sec=0; sec0) fprintf(fp, "\n"); - if (section[0] != 0) - fprintf(fp, "[%s]\n", section); + fp = fopen(filename, "w"); + if (!fp) return; - nument = SCRIPT_NumberEntries(scripthandle,section); - for (ent=0; ent0) fprintf(fp, "\n"); + if (section[0] != 0) + fprintf(fp, "[%s]\n", section); - fprintf(fp, "%s = %s\n", entry, value); - } - } + nument = SCRIPT_NumberEntries(scripthandle,section); + for (ent=0; entnextsection) c++; + for (s = SCRIPT(scripthandle,script); ls != s; ls=s,s=s->nextsection) c++; - 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; - if (!SC(scripthandle)) return ""; - if (!SCRIPT(scripthandle,script)) return ""; + if (!SC(scripthandle)) return ""; + if (!SCRIPT(scripthandle,script)) return ""; - for (s = SCRIPT(scripthandle,script); which>0 && ls != s; ls=s, s=s->nextsection, which--) ; + for (s = SCRIPT(scripthandle,script); which>0 && ls != s; ls=s, s=s->nextsection, which--) ; - return s->name; + return s->name; } -int32 SCRIPT_NumberEntries( int32 scripthandle, char * sectionname ) +int32 SCRIPT_NumberEntries(int32 scripthandle, char * sectionname) { - ScriptSectionType *s; - ScriptEntryType *e,*le=NULL; - int32 c=0; + ScriptSectionType *s; + ScriptEntryType *e,*le=NULL; + int32 c=0; - if (!SC(scripthandle)) return 0; - if (!SCRIPT(scripthandle,script)) return 0; + if (!SC(scripthandle)) return 0; + if (!SCRIPT(scripthandle,script)) return 0; - s = SCRIPT_SectionExists(scripthandle, sectionname); - if (!s) return 0; + s = SCRIPT_SectionExists(scripthandle, sectionname); + if (!s) return 0; - for (e = s->entries; le != e; le=e,e=e->nextentry) c++; - return c; + for (e = s->entries; le != e; le=e,e=e->nextentry) c++; + return c; } -char * SCRIPT_Entry( int32 scripthandle, char * sectionname, int32 which ) +char * SCRIPT_Entry(int32 scripthandle, char * sectionname, int32 which) { - ScriptSectionType *s; - ScriptEntryType *e,*le=NULL; + ScriptSectionType *s; + ScriptEntryType *e,*le=NULL; - if (!SC(scripthandle)) return 0; - if (!SCRIPT(scripthandle,script)) return 0; + if (!SC(scripthandle)) return 0; + if (!SCRIPT(scripthandle,script)) return 0; - s = SCRIPT_SectionExists(scripthandle, sectionname); - if (!s) return ""; + s = SCRIPT_SectionExists(scripthandle, sectionname); + if (!s) return ""; - for (e = s->entries; which>0 && le != e; le=e, e=e->nextentry, which--) ; - return e->name; + for (e = s->entries; which>0 && le != e; le=e, e=e->nextentry, which--) ; + return e->name; } char * SCRIPT_GetRaw(int32 scripthandle, char * sectionname, char * entryname) { - ScriptSectionType *s; - ScriptEntryType *e; + ScriptSectionType *s; + ScriptEntryType *e; - if (!SC(scripthandle)) return 0; - if (!SCRIPT(scripthandle,script)) return 0; + if (!SC(scripthandle)) return 0; + if (!SCRIPT(scripthandle,script)) return 0; - s = SCRIPT_SectionExists(scripthandle, sectionname); - e = SCRIPT_EntryExists(s, entryname); + s = SCRIPT_SectionExists(scripthandle, sectionname); + e = SCRIPT_EntryExists(s, entryname); - if (!e) return ""; - return e->value; + if (!e) return ""; + 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; - ScriptEntryType *e; - char *p, ch; - int c; + ScriptSectionType *s; + ScriptEntryType *e; + char *p, ch; + int c; - if (!SC(scripthandle)) return 1; - if (!SCRIPT(scripthandle,script)) return 1; + if (!SC(scripthandle)) return 1; + if (!SCRIPT(scripthandle,script)) return 1; - s = SCRIPT_SectionExists(scripthandle, sectionname); - e = SCRIPT_EntryExists(s, entryname); - - //dest[0] = 0; - if (!e) return 1; + s = SCRIPT_SectionExists(scripthandle, sectionname); + e = SCRIPT_EntryExists(s, entryname); - p = e->value; - c = 0; - - if (*p == '\"') { - // quoted string - p++; - while ((ch = *(p++))) { - switch (ch) { - case '\\': - ch = *(p++); - switch (ch) { - case 0: return 0; - case 'n': dest[c++] = '\n'; break; - case 'r': dest[c++] = '\r'; break; - case 't': dest[c++] = '\t'; break; - default: dest[c++] = ch; break; - } - break; - case '\"': - dest[c] = 0; - return 0; - default: - dest[c++] = ch; - break; - } - } - } else { - while ((ch = *(p++))) { - if (ch == ' ' || ch == '\t') { dest[c] = 0; break; } - else dest[c++] = ch; - } - } + //dest[0] = 0; + if (!e) return 1; - return 0; + p = e->value; + c = 0; + + if (*p == '\"') + { + // quoted string + p++; + while ((ch = *(p++))) + { + switch (ch) + { + case '\\': + ch = *(p++); + switch (ch) + { + case 0: return 0; + case 'n': dest[c++] = '\n'; break; + case 'r': dest[c++] = '\r'; break; + case 't': dest[c++] = '\t'; break; + default: dest[c++] = ch; break; + } + break; + case '\"': + dest[c] = 0; + return 0; + default: + dest[c++] = ch; + break; + } + } + } + else + { + while ((ch = *(p++))) + { + if (ch == ' ' || ch == '\t') { dest[c] = 0; break; } + else dest[c++] = ch; + } + } + + 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; - ScriptEntryType *e; - char *p, ch; - int c; + ScriptSectionType *s; + ScriptEntryType *e; + char *p, ch; + int c; - if (!SC(scripthandle)) return 1; - if (!SCRIPT(scripthandle,script)) return 1; + if (!SC(scripthandle)) return 1; + if (!SCRIPT(scripthandle,script)) return 1; - s = SCRIPT_SectionExists(scripthandle, sectionname); - e = SCRIPT_EntryExists(s, entryname); - - //dest1[0] = 0; - //dest2[0] = 0; - if (!e) return 1; + s = SCRIPT_SectionExists(scripthandle, sectionname); + e = SCRIPT_EntryExists(s, entryname); - p = e->value; - c = 0; - - if (*p == '\"') { - // quoted string - p++; - while ((ch = *(p++))) { - switch (ch) { - case '\\': - ch = *(p++); - switch (ch) { - case 0: return 0; - case 'n': dest1[c++] = '\n'; break; - case 'r': dest1[c++] = '\r'; break; - case 't': dest1[c++] = '\t'; break; - default: dest1[c++] = ch; break; - } - break; - case '\"': - dest1[c] = 0; - goto breakme; - default: - dest1[c++] = ch; - break; - } - } - if (ch == 0) return 0; - } else { - while ((ch = *(p++))) { - if (ch == ' ' || ch == '\t') { dest1[c] = 0; break; } - else dest1[c++] = ch; - } - } + //dest1[0] = 0; + //dest2[0] = 0; + if (!e) return 1; + + p = e->value; + c = 0; + + if (*p == '\"') + { + // quoted string + p++; + while ((ch = *(p++))) + { + switch (ch) + { + case '\\': + ch = *(p++); + switch (ch) + { + case 0: return 0; + case 'n': dest1[c++] = '\n'; break; + case 'r': dest1[c++] = '\r'; break; + case 't': dest1[c++] = '\t'; break; + default: dest1[c++] = ch; break; + } + break; + case '\"': + dest1[c] = 0; + goto breakme; + default: + dest1[c++] = ch; + break; + } + } + if (ch == 0) return 0; + } + else + { + while ((ch = *(p++))) + { + if (ch == ' ' || ch == '\t') { dest1[c] = 0; break; } + else dest1[c++] = ch; + } + } breakme: - while (*p == ' ' || *p == '\t') p++; - if (*p == 0) return 0; + while (*p == ' ' || *p == '\t') p++; + if (*p == 0) return 0; - c = 0; - - if (*p == '\"') { - // quoted string - p++; - while ((ch = *(p++))) { - switch (ch) { - case '\\': - ch = *(p++); - switch (ch) { - case 0: return 0; - case 'n': dest2[c++] = '\n'; break; - case 'r': dest2[c++] = '\r'; break; - case 't': dest2[c++] = '\t'; break; - default: dest2[c++] = ch; break; - } - break; - case '\"': - dest2[c] = 0; - return 0; - default: - dest2[c++] = ch; - break; - } - } - } else { - while ((ch = *(p++))) { - if (ch == ' ' || ch == '\t') { dest2[c] = 0; break; } - else dest2[c++] = ch; - } - } + c = 0; - return 0; + if (*p == '\"') + { + // quoted string + p++; + while ((ch = *(p++))) + { + switch (ch) + { + case '\\': + ch = *(p++); + switch (ch) + { + case 0: return 0; + case 'n': dest2[c++] = '\n'; break; + case 'r': dest2[c++] = '\r'; break; + case 't': dest2[c++] = '\t'; break; + default: dest2[c++] = ch; break; + } + break; + case '\"': + dest2[c] = 0; + return 0; + default: + dest2[c++] = ch; + break; + } + } + } + else + { + while ((ch = *(p++))) + { + if (ch == ' ' || ch == '\t') { dest2[c] = 0; break; } + else dest2[c++] = ch; + } + } + + 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; - ScriptEntryType *e; - char *p; + ScriptSectionType *s; + ScriptEntryType *e; + char *p; - if (!SC(scripthandle)) return 1; - if (!SCRIPT(scripthandle,script)) return 1; + if (!SC(scripthandle)) return 1; + if (!SCRIPT(scripthandle,script)) return 1; - s = SCRIPT_SectionExists(scripthandle, sectionname); - e = SCRIPT_EntryExists(s, entryname); - - if (!e) return 1;// *number = 0; - else { - if (e->value[0] == '0' && e->value[1] == 'x') { - // hex - *number = strtol(e->value+2, &p, 16); - if (p == e->value || *p != 0 || *p != ' ' || *p != '\t') return 1; - } else { - // decimal - *number = strtol(e->value, &p, 10); - if (p == e->value || *p != 0 || *p != ' ' || *p != '\t') return 1; - } - } + s = SCRIPT_SectionExists(scripthandle, sectionname); + e = SCRIPT_EntryExists(s, entryname); - return 0; + if (!e) return 1;// *number = 0; + else + { + if (e->value[0] == '0' && e->value[1] == 'x') + { + // hex + *number = strtol(e->value+2, &p, 16); + if (p == e->value || *p != 0 || *p != ' ' || *p != '\t') return 1; + } + else + { + // decimal + *number = strtol(e->value, &p, 10); + if (p == e->value || *p != 0 || *p != ' ' || *p != '\t') return 1; + } + } + + 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; - ScriptEntryType *e; + ScriptSectionType *s; + ScriptEntryType *e; - if (!SC(scripthandle)) return 1; - if (!SCRIPT(scripthandle,script)) return 1; + if (!SC(scripthandle)) return 1; + if (!SCRIPT(scripthandle,script)) return 1; - s = SCRIPT_SectionExists(scripthandle, sectionname); - e = SCRIPT_EntryExists(s, entryname); - - if (!e) return 1;// *boole = 0; - else { - if (!Bstrncasecmp(e->value, "true", 4)) *boole = 1; - 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] == '0' && (e->value[1] == ' ' || e->value[1] == '\t' || e->value[1] == 0)) *boole = 0; - } + s = SCRIPT_SectionExists(scripthandle, sectionname); + e = SCRIPT_EntryExists(s, entryname); - return 0; + if (!e) return 1;// *boole = 0; + else + { + if (!Bstrncasecmp(e->value, "true", 4)) *boole = 1; + 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] == '0' && (e->value[1] == ' ' || e->value[1] == '\t' || e->value[1] == 0)) *boole = 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 - ( - int32 scripthandle, - char * sectionname, - char * entryname, - char * raw - ) +( + int32 scripthandle, + char * sectionname, + char * entryname, + char * raw +) { - SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); + SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); } void SCRIPT_PutString - ( - int32 scripthandle, - char * sectionname, - char * entryname, - char * string - ) +( + int32 scripthandle, + char * sectionname, + char * entryname, + char * string +) { - char *raw,*q,*p; - int len = 3; - if (!string) string = ""; + char *raw,*q,*p; + int len = 3; + if (!string) string = ""; - for (q=string; *q; q++) { - if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2; - else if (*q >= ' ') len++; - } - p = raw = Bmalloc(len); - *(p++) = '"'; - for (q=string; *q; q++) { - if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; } - else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; } - else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; } - else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; } - else if (*q >= ' ') *(p++) = *q; - } - *(p++) = '"'; - *p=0; - - SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); - Bfree(raw); + for (q=string; *q; q++) + { + if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2; + else if (*q >= ' ') len++; + } + p = raw = Bmalloc(len); + *(p++) = '"'; + for (q=string; *q; q++) + { + if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; } + else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; } + else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; } + else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; } + else if (*q >= ' ') *(p++) = *q; + } + *(p++) = '"'; + *p=0; + + SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); + Bfree(raw); } void SCRIPT_PutDoubleString - ( - int32 scripthandle, - char * sectionname, - char * entryname, - char * string1, - char * string2 - ) +( + int32 scripthandle, + char * sectionname, + char * entryname, + char * string1, + char * string2 +) { - char *raw,*q,*p; - int len = 6; - if (!string1) string1 = ""; - if (!string2) string2 = ""; + char *raw,*q,*p; + int len = 6; + if (!string1) string1 = ""; + if (!string2) string2 = ""; - for (q=string1; *q; q++) { - if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2; - else if (*q >= ' ') len++; - } - for (q=string2; *q; q++) { - if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2; - else if (*q >= ' ') len++; - } - p = raw = Bmalloc(len); - *(p++) = '"'; - for (q=string1; *q; q++) { - if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; } - else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; } - else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; } - else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; } - else if (*q >= ' ') *(p++) = *q; - } - *(p++) = '"'; - *(p++) = ' '; - *(p++) = '"'; - for (q=string2; *q; q++) { - if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; } - else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; } - else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; } - else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; } - else if (*q >= ' ') *(p++) = *q; - } - *(p++) = '"'; - *p=0; - - SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); - Bfree(raw); + for (q=string1; *q; q++) + { + if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2; + else if (*q >= ' ') len++; + } + for (q=string2; *q; q++) + { + if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2; + else if (*q >= ' ') len++; + } + p = raw = Bmalloc(len); + *(p++) = '"'; + for (q=string1; *q; q++) + { + if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; } + else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; } + else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; } + else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; } + else if (*q >= ' ') *(p++) = *q; + } + *(p++) = '"'; + *(p++) = ' '; + *(p++) = '"'; + for (q=string2; *q; q++) + { + if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; } + else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; } + else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; } + else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; } + else if (*q >= ' ') *(p++) = *q; + } + *(p++) = '"'; + *p=0; + + SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); + Bfree(raw); } void SCRIPT_PutNumber - ( - int32 scripthandle, - char * sectionname, - char * entryname, - int32 number, - boolean hexadecimal, - boolean defaultvalue - ) +( + int32 scripthandle, + char * sectionname, + char * entryname, + int32 number, + boolean hexadecimal, + boolean defaultvalue +) { - char raw[64]; + char raw[64]; UNREFERENCED_PARAMETER(defaultvalue); - if (hexadecimal) sprintf(raw, "0x%X", number); - else sprintf(raw, "%d", number); + if (hexadecimal) sprintf(raw, "0x%X", number); + else sprintf(raw, "%d", number); - SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); + SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); } void SCRIPT_PutBoolean - ( - int32 scripthandle, - char * sectionname, - char * entryname, - boolean boole - ) +( + int32 scripthandle, + char * sectionname, + char * entryname, + boolean boole +) { - char raw[2] = "0"; + char raw[2] = "0"; - if (boole) raw[0] = '1'; + if (boole) raw[0] = '1'; - SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); + SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); } void SCRIPT_PutDouble - ( - int32 scripthandle, - char * sectionname, - char * entryname, - double number, - boolean defaultvalue - ) +( + int32 scripthandle, + char * sectionname, + char * entryname, + double number, + boolean defaultvalue +) { - char raw[64]; + char raw[64]; UNREFERENCED_PARAMETER(defaultvalue); - sprintf(raw, "%g", number); + sprintf(raw, "%g", number); - SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); + SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw); } diff --git a/polymer/eduke32/source/jmact/util_lib.c b/polymer/eduke32/source/jmact/util_lib.c index 42848d4d8..1f44d9837 100644 --- a/polymer/eduke32/source/jmact/util_lib.c +++ b/polymer/eduke32/source/jmact/util_lib.c @@ -42,112 +42,114 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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; } #ifndef RENDERTYPEWIN void Error(char *error, ...) { - va_list va; + va_list va; - if (ShutDown) ShutDown(); + if (ShutDown) ShutDown(); - if (error) { - va_start(va, error); - vprintf(error, va); - va_end(va); - printf("\n\n"); - } + if (error) + { + va_start(va, error); + vprintf(error, va); + va_end(va); + printf("\n\n"); + } - exit((error != NULL)); + exit((error != NULL)); } #endif char CheckParm(char *check) { - int c; + int c; - for (c=1;c<_buildargc;c++) { - if (_buildargv[c][0] == '/' || _buildargv[c][0] == '-') - if (!Bstrcasecmp(&_buildargv[c][1], check)) return c; - } + for (c=1;c<_buildargc;c++) + { + if (_buildargv[c][0] == '/' || _buildargv[c][0] == '-') + if (!Bstrcasecmp(&_buildargv[c][1], check)) return c; + } - return 0; + return 0; } -void *SafeMalloc (int32 size) +void *SafeMalloc(int32 size) { - void *p; + void *p; - p = malloc(size); - if (!p) Error("SafeMalloc failure for %d bytes",size); + p = malloc(size); + if (!p) Error("SafeMalloc failure for %d bytes",size); - return p; + return p; } -void SafeFree (void * ptr) +void SafeFree(void * ptr) { - if (!ptr) Error("Tried to deallocate NULL pointer."); - free(ptr); + if (!ptr) Error("Tried to deallocate NULL pointer."); + free(ptr); } -void SafeRealloc (void ** ptr, int32 newsize) +void SafeRealloc(void ** ptr, int32 newsize) { - void *p; + void *p; - p = realloc(*ptr, newsize); - if (!p) Error("SafeRealloc failure for %d bytes",newsize); + p = realloc(*ptr, newsize); + if (!p) Error("SafeRealloc failure for %d bytes",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 - return l; + return l; #else - return ((l & 0x00ff) << 8) | ((l & 0xff00) >> 8); + return ((l & 0x00ff) << 8) | ((l & 0xff00) >> 8); #endif } -int16 IntelShort (int16 l) +int16 IntelShort(int16 l) { #if B_BIG_ENDIAN != 0 - return ((l & 0x00ff) << 8) | ((l & 0xff00) >> 8); + return ((l & 0x00ff) << 8) | ((l & 0xff00) >> 8); #else - return l; + return l; #endif } -int32 MotoLong (int32 l) +int32 MotoLong(int32 l) { #if B_LITTLE_ENDIAN != 0 - return l; + return l; #else - int32 t = ((l & 0x00ff00ffl) << 8) | ((l & 0xff00ff00l) >> 8); - return ((t & 0x0000ffffl) << 16) | ((t & 0xffff0000l) >> 16); + int32 t = ((l & 0x00ff00ffl) << 8) | ((l & 0xff00ff00l) >> 8); + return ((t & 0x0000ffffl) << 16) | ((t & 0xffff0000l) >> 16); #endif } -int32 IntelLong (int32 l) +int32 IntelLong(int32 l) { #if B_BIG_ENDIAN != 0 - int32 t = ((l & 0x00ff00ffl) << 8) | ((l & 0xff00ff00l) >> 8); - return ((t & 0x0000ffffl) << 16) | ((t & 0xffff0000l) >> 16); + int32 t = ((l & 0x00ff00ffl) << 8) | ((l & 0xff00ff00l) >> 8); + return ((t & 0x0000ffffl) << 16) | ((t & 0xffff0000l) >> 16); #else - return l; + return l; #endif }