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

@ -146,7 +146,8 @@ 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:
@ -178,7 +180,8 @@ notLongSkip:
do do
{ {
*dstP++ = *srcP++; *dstP++ = *srcP++;
} while (--wordCnt); }
while (--wordCnt);
goto nextOp; goto nextOp;
longRun: longRun:
@ -187,7 +190,8 @@ longRun:
do do
{ {
*dstP++ = pixel; *dstP++ = pixel;
} while (--wordCnt); }
while (--wordCnt);
goto nextOp; goto nextOp;
stop: /* all done */ stop: /* all done */
@ -259,7 +263,8 @@ 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;
} }

View file

@ -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);
} }
@ -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,14 +237,16 @@ 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);
@ -250,9 +259,11 @@ void CONTROL_MapButton( int32 whichfunction, int32 whichbutton, boolean doublecl
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;
@ -284,15 +296,18 @@ void CONTROL_MapAnalogAxis( int32 whichaxis, int32 whichanalog, controldevice de
{ {
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;
@ -323,9 +339,11 @@ void CONTROL_SetAnalogAxisScale( int32 whichaxis, int32 axisscale, controldevice
{ {
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;
@ -358,9 +377,11 @@ void CONTROL_MapDigitalAxis( int32 whichaxis, int32 whichfunction, int32 directi
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;
@ -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)
@ -672,7 +728,8 @@ 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];
@ -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);

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:
@ -88,14 +90,16 @@ 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;
} }
@ -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 },

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;
@ -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;
@ -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
@ -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;
} }
@ -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);
@ -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;
} }
@ -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;
} }
@ -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;
@ -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;
@ -758,13 +816,15 @@ void SCRIPT_PutString
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'; }
@ -792,17 +852,20 @@ void SCRIPT_PutDoubleString
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'; }

View file

@ -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;
} }