From c7ddc423f67236a99956960cf9fe89abf077839b Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 5 Sep 2008 00:02:14 +0000 Subject: Reformat (beautify) Raven sources and add GPL headers. Subversion-branch: /branches/raven-branch Subversion-revision: 1197 --- src/hexen/sc_man.c | 433 +++++++++++++++++++++++++++-------------------------- 1 file changed, 222 insertions(+), 211 deletions(-) (limited to 'src/hexen/sc_man.c') diff --git a/src/hexen/sc_man.c b/src/hexen/sc_man.c index 394679cc..418c88af 100644 --- a/src/hexen/sc_man.c +++ b/src/hexen/sc_man.c @@ -1,14 +1,26 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright(C) 1993-1996 Id Software, Inc. +// Copyright(C) 1993-2008 Raven Software +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +//----------------------------------------------------------------------------- -//************************************************************************** -//** -//** sc_man.c : Heretic 2 : Raven Software, Corp. -//** -//** $RCSfile: sc_man.c,v $ -//** $Revision: 1.3 $ -//** $Date: 96/01/06 03:23:43 $ -//** $Author: bgokey $ -//** -//************************************************************************** // HEADER FILES ------------------------------------------------------------ @@ -56,7 +68,7 @@ static char *ScriptPtr; static char *ScriptEndPtr; static char StringBuffer[MAX_STRING_SIZE]; static boolean ScriptOpen = false; -static boolean ScriptFreeCLib; // true = de-allocate using free() +static boolean ScriptFreeCLib; // true = de-allocate using free() static int ScriptSize; static boolean AlreadyGot = false; @@ -70,17 +82,17 @@ static boolean AlreadyGot = false; void SC_Open(char *name) { - char fileName[128]; - - if(sc_FileScripts == true) - { - sprintf(fileName, "%s%s.txt", sc_ScriptsDir, name); - SC_OpenFile(fileName); - } - else - { - SC_OpenLump(name); - } + char fileName[128]; + + if (sc_FileScripts == true) + { + sprintf(fileName, "%s%s.txt", sc_ScriptsDir, name); + SC_OpenFile(fileName); + } + else + { + SC_OpenLump(name); + } } //========================================================================== @@ -93,7 +105,7 @@ void SC_Open(char *name) void SC_OpenLump(char *name) { - OpenScript(name, LUMP_SCRIPT); + OpenScript(name, LUMP_SCRIPT); } //========================================================================== @@ -107,7 +119,7 @@ void SC_OpenLump(char *name) void SC_OpenFile(char *name) { - OpenScript(name, FILE_ZONE_SCRIPT); + OpenScript(name, FILE_ZONE_SCRIPT); } //========================================================================== @@ -121,7 +133,7 @@ void SC_OpenFile(char *name) void SC_OpenFileCLib(char *name) { - OpenScript(name, FILE_CLIB_SCRIPT); + OpenScript(name, FILE_CLIB_SCRIPT); } //========================================================================== @@ -132,33 +144,33 @@ void SC_OpenFileCLib(char *name) static void OpenScript(char *name, int type) { - SC_Close(); - if(type == LUMP_SCRIPT) - { // Lump script - ScriptBuffer = (char *)W_CacheLumpName(name, PU_STATIC); - ScriptSize = W_LumpLength(W_GetNumForName(name)); - strcpy(ScriptName, name); - ScriptFreeCLib = false; // De-allocate using Z_Free() - } - else if(type == FILE_ZONE_SCRIPT) - { // File script - zone - ScriptSize = M_ReadFile(name, (byte **)&ScriptBuffer); - M_ExtractFileBase(name, ScriptName); - ScriptFreeCLib = false; // De-allocate using Z_Free() - } - else - { // File script - clib - ScriptSize = M_ReadFileCLib(name, (byte **)&ScriptBuffer); - M_ExtractFileBase(name, ScriptName); - ScriptFreeCLib = true; // De-allocate using free() - } - ScriptPtr = ScriptBuffer; - ScriptEndPtr = ScriptPtr+ScriptSize; - sc_Line = 1; - sc_End = false; - ScriptOpen = true; - sc_String = StringBuffer; - AlreadyGot = false; + SC_Close(); + if (type == LUMP_SCRIPT) + { // Lump script + ScriptBuffer = (char *) W_CacheLumpName(name, PU_STATIC); + ScriptSize = W_LumpLength(W_GetNumForName(name)); + strcpy(ScriptName, name); + ScriptFreeCLib = false; // De-allocate using Z_Free() + } + else if (type == FILE_ZONE_SCRIPT) + { // File script - zone + ScriptSize = M_ReadFile(name, (byte **) & ScriptBuffer); + M_ExtractFileBase(name, ScriptName); + ScriptFreeCLib = false; // De-allocate using Z_Free() + } + else + { // File script - clib + ScriptSize = M_ReadFileCLib(name, (byte **) & ScriptBuffer); + M_ExtractFileBase(name, ScriptName); + ScriptFreeCLib = true; // De-allocate using free() + } + ScriptPtr = ScriptBuffer; + ScriptEndPtr = ScriptPtr + ScriptSize; + sc_Line = 1; + sc_End = false; + ScriptOpen = true; + sc_String = StringBuffer; + AlreadyGot = false; } //========================================================================== @@ -169,18 +181,18 @@ static void OpenScript(char *name, int type) void SC_Close(void) { - if(ScriptOpen) - { - if(ScriptFreeCLib == true) - { - free(ScriptBuffer); - } - else - { - Z_Free(ScriptBuffer); - } - ScriptOpen = false; - } + if (ScriptOpen) + { + if (ScriptFreeCLib == true) + { + free(ScriptBuffer); + } + else + { + Z_Free(ScriptBuffer); + } + ScriptOpen = false; + } } //========================================================================== @@ -191,89 +203,89 @@ void SC_Close(void) boolean SC_GetString(void) { - char *text; - boolean foundToken; - - CheckOpen(); - if(AlreadyGot) - { - AlreadyGot = false; - return true; - } - foundToken = false; - sc_Crossed = false; - if(ScriptPtr >= ScriptEndPtr) - { - sc_End = true; - return false; - } - while(foundToken == false) - { - while(*ScriptPtr <= 32) - { - if(ScriptPtr >= ScriptEndPtr) - { - sc_End = true; - return false; - } - if(*ScriptPtr++ == '\n') - { - sc_Line++; - sc_Crossed = true; - } - } - if(ScriptPtr >= ScriptEndPtr) - { - sc_End = true; - return false; - } - if(*ScriptPtr != ASCII_COMMENT) - { // Found a token - foundToken = true; - } - else - { // Skip comment - while(*ScriptPtr++ != '\n') - { - if(ScriptPtr >= ScriptEndPtr) - { - sc_End = true; - return false; - } - } - sc_Line++; - sc_Crossed = true; - } - } - text = sc_String; - if(*ScriptPtr == ASCII_QUOTE) - { // Quoted string - ScriptPtr++; - while(*ScriptPtr != ASCII_QUOTE) - { - *text++ = *ScriptPtr++; - if(ScriptPtr == ScriptEndPtr - || text == &sc_String[MAX_STRING_SIZE-1]) - { - break; - } - } - ScriptPtr++; - } - else - { // Normal string - while((*ScriptPtr > 32) && (*ScriptPtr != ASCII_COMMENT)) - { - *text++ = *ScriptPtr++; - if(ScriptPtr == ScriptEndPtr - || text == &sc_String[MAX_STRING_SIZE-1]) - { - break; - } - } - } - *text = 0; - return true; + char *text; + boolean foundToken; + + CheckOpen(); + if (AlreadyGot) + { + AlreadyGot = false; + return true; + } + foundToken = false; + sc_Crossed = false; + if (ScriptPtr >= ScriptEndPtr) + { + sc_End = true; + return false; + } + while (foundToken == false) + { + while (*ScriptPtr <= 32) + { + if (ScriptPtr >= ScriptEndPtr) + { + sc_End = true; + return false; + } + if (*ScriptPtr++ == '\n') + { + sc_Line++; + sc_Crossed = true; + } + } + if (ScriptPtr >= ScriptEndPtr) + { + sc_End = true; + return false; + } + if (*ScriptPtr != ASCII_COMMENT) + { // Found a token + foundToken = true; + } + else + { // Skip comment + while (*ScriptPtr++ != '\n') + { + if (ScriptPtr >= ScriptEndPtr) + { + sc_End = true; + return false; + } + } + sc_Line++; + sc_Crossed = true; + } + } + text = sc_String; + if (*ScriptPtr == ASCII_QUOTE) + { // Quoted string + ScriptPtr++; + while (*ScriptPtr != ASCII_QUOTE) + { + *text++ = *ScriptPtr++; + if (ScriptPtr == ScriptEndPtr + || text == &sc_String[MAX_STRING_SIZE - 1]) + { + break; + } + } + ScriptPtr++; + } + else + { // Normal string + while ((*ScriptPtr > 32) && (*ScriptPtr != ASCII_COMMENT)) + { + *text++ = *ScriptPtr++; + if (ScriptPtr == ScriptEndPtr + || text == &sc_String[MAX_STRING_SIZE - 1]) + { + break; + } + } + } + *text = 0; + return true; } //========================================================================== @@ -284,10 +296,10 @@ boolean SC_GetString(void) void SC_MustGetString(void) { - if(SC_GetString() == false) - { - SC_ScriptError("Missing string."); - } + if (SC_GetString() == false) + { + SC_ScriptError("Missing string."); + } } //========================================================================== @@ -298,11 +310,11 @@ void SC_MustGetString(void) void SC_MustGetStringName(char *name) { - SC_MustGetString(); - if(SC_Compare(name) == false) - { - SC_ScriptError(NULL); - } + SC_MustGetString(); + if (SC_Compare(name) == false) + { + SC_ScriptError(NULL); + } } //========================================================================== @@ -313,23 +325,23 @@ void SC_MustGetStringName(char *name) boolean SC_GetNumber(void) { - char *stopper; - - CheckOpen(); - if(SC_GetString()) - { - sc_Number = strtol(sc_String, &stopper, 0); - if(*stopper != 0) - { - I_Error("SC_GetNumber: Bad numeric constant \"%s\".\n" - "Script %s, Line %d", sc_String, ScriptName, sc_Line); - } - return true; - } - else - { - return false; - } + char *stopper; + + CheckOpen(); + if (SC_GetString()) + { + sc_Number = strtol(sc_String, &stopper, 0); + if (*stopper != 0) + { + I_Error("SC_GetNumber: Bad numeric constant \"%s\".\n" + "Script %s, Line %d", sc_String, ScriptName, sc_Line); + } + return true; + } + else + { + return false; + } } //========================================================================== @@ -340,10 +352,10 @@ boolean SC_GetNumber(void) void SC_MustGetNumber(void) { - if(SC_GetNumber() == false) - { - SC_ScriptError("Missing integer."); - } + if (SC_GetNumber() == false) + { + SC_ScriptError("Missing integer."); + } } //========================================================================== @@ -356,7 +368,7 @@ void SC_MustGetNumber(void) void SC_UnGet(void) { - AlreadyGot = true; + AlreadyGot = true; } //========================================================================== @@ -409,16 +421,16 @@ boolean SC_Check(void) int SC_MatchString(char **strings) { - int i; - - for(i = 0; *strings != NULL; i++) - { - if(SC_Compare(*strings++)) - { - return i; - } - } - return -1; + int i; + + for (i = 0; *strings != NULL; i++) + { + if (SC_Compare(*strings++)) + { + return i; + } + } + return -1; } //========================================================================== @@ -429,14 +441,14 @@ int SC_MatchString(char **strings) int SC_MustMatchString(char **strings) { - int i; - - i = SC_MatchString(strings); - if(i == -1) - { - SC_ScriptError(NULL); - } - return i; + int i; + + i = SC_MatchString(strings); + if (i == -1) + { + SC_ScriptError(NULL); + } + return i; } //========================================================================== @@ -447,11 +459,11 @@ int SC_MustMatchString(char **strings) boolean SC_Compare(char *text) { - if(strcasecmp(text, sc_String) == 0) - { - return true; - } - return false; + if (strcasecmp(text, sc_String) == 0) + { + return true; + } + return false; } //========================================================================== @@ -462,12 +474,11 @@ boolean SC_Compare(char *text) void SC_ScriptError(char *message) { - if(message == NULL) - { - message = "Bad syntax."; - } - I_Error("Script error, \"%s\" line %d: %s", ScriptName, - sc_Line, message); + if (message == NULL) + { + message = "Bad syntax."; + } + I_Error("Script error, \"%s\" line %d: %s", ScriptName, sc_Line, message); } //========================================================================== @@ -478,8 +489,8 @@ void SC_ScriptError(char *message) static void CheckOpen(void) { - if(ScriptOpen == false) - { - I_Error("SC_ call before SC_Open()."); - } + if (ScriptOpen == false) + { + I_Error("SC_ call before SC_Open()."); + } } -- cgit v1.2.3