diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 61d10bf37b..fd6cae8219 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,7 +1,96 @@ +January 25, 2008 +- Lemon is now producing parsers that don't accept anything, so I'm going + back to v1.43 and trying each intermediate version to see where things + went wrong. + +January 24, 2008 +- Updated Lemon to its latest versions as of today. + (lemon.c: v1.53, lempar.c: v1.31) +- Added .txt files to the list of types (wad, zip, and pk3) that can be + loaded without listing them after -file. +- Fonts that are created by the ACS setfont command to wrap a texture now + support animated textures. +- FON2 fonts can now use their full palette for CR_UNTRANSLATED when drawn + with the hardware 2D path instead of being restricted to the game palette. + +January 23, 2008 +- Fixed: Toggling vid_vsync would reset the displayed fullscreen gamma to 1 + on a Radeon 9000. +- Added back the off-by-one palette handling, but in a much more limited + scope than before. The skipped entry is assumed to always be at 248, and + it is assumed that all Shader Model 1.4 cards suffer from this. That's + because all SM1.4 cards are based on variants of the ATI R200 core, and the + RV250 in a Radeon 9000 craps up like this. I see no reason to assume that + other flavors of the R200 are any different. (Interesting note: With the + Radeon 9000, D3DTADDRESS_CLAMP is an invalid address mode when using the + debug Direct3D 9 runtime, but it works perfectly fine with the retail + Direct3D 9 runtime.) (Insight: The R200 probably uses bytes for all its + math inside pixel shaders. That would explain perfectly why I can't use + constants greater than 1 with PS1.4 and why it can't do an exact mapping to + every entry in the color palette. +- Fixed: The software shaded drawer did not work for 2D, because its selected + "color"map was replaced with the identitymap before being used. +- Fixed: I cannot use Printf to output messages before the framebuffer was + completely setup, meaning that Shader Model 1.4 cards could not change + resolution. +- I have decided to let remap palettes specify variable alpha values for + their colors. D3DFB no longer forces them to 255. + +January 22, 2008 +- Updated re2c to version 0.12.3. +- Fixed: A_Wander used threshold as a timer, when it should have used + reactiontime. +- Fixed: A_CustomRailgun would not fire at all for actors without a target + when the aim parameter was disabled. +- Made the warp command work in multiplayer, again courtesy of Karate Chris. +- Fixed: Trying to spawn a bot while not in a game made for a crashing time. + (Patch courtesy of Karate Chris.) + +January 21, 2008 +- Removed some floating point math from hu_scores.cpp that somebody's GCC + gave warnings for (not mine, though). +- Fixed: The SBarInfo drawbar command crashed if the sprite image was + unavailable. +- Fixed: FString::operator=(const char *) did not release its old buffer when + being assigned to the null string. +- The scanner no longer has an upper limit on the length of strings it + accepts, though short strings will be faster than long ones. +- Moved all the text scanning functions into a class. Mainly, this means that + multiple script scanner states can be stored without being forced to do so + recursively. I think I might be taking advantage of that in the near + future. Possibly. Maybe. +- Removed some potential buffer overflows from the decal parser. + +January 18, 2008 +- Applied Blzut3's SBARINFO update #9: + * Fixed: When using even length values in drawnumber it would cap to a 98 + value instead of a 99 as intended. + * The SBarInfo parser can now accept negatives for coordinates. This + doesn't allow much right now, but later I plan to add better fullscreen + hud support in which the negatives will be more useful. This also cleans + up the source a bit since all calls for (x, y) coordinates are with the + function getCoordinates(). +- Added support for stencilling actors. +- Added support for non-black colors specified with DTA_ColorOverlay to the + software renderer. +- Fixed: The inverse, gold, red, and green fixed colormaps each allocated + space for 32 different colormaps, even though each only used the first one. +- Added two new blending flags to make reverse subtract blending more useful: + STYLEF_InvertSource and STYLEF_InvertOverlay. These invert the color that + gets blended with the background, since that seems like a good idea for + reverse subtraction. They also work with the other two blending operations. + +January 17, 2008 +- Added subtract and reverse subtract blending operations to the renderer. + Since the ERenderStyle enumeration was getting rather unwieldy, I converted + it into a new FRenderStyle structure that lets each parameter of the + blending equation be set separately. This simplified the set up for the + blend quite a bit, and it means a number of new combinations are available + by setting the parameters properly. + January 16, 2008 (Changes by Graf Zahl) - Fixed: The StatusBar pointer was not NULLed after being deleted. - January 15, 2008 - Plugged more leaks in SBARINFO. - Spawned actors that have MF2_DORMANT set in their default instance now have diff --git a/src/actor.h b/src/actor.h index 3320d026d8..8054c12e4c 100644 --- a/src/actor.h +++ b/src/actor.h @@ -40,6 +40,7 @@ #include "info.h" #include "doomdef.h" +#include "r_blend.h" // // NOTES: AActor @@ -330,24 +331,6 @@ enum MF_STRIFEx8000000 = 0, // seems related to MF_SHADOW }; -enum ERenderStyle -{ - STYLE_None, // Do not draw - STYLE_Normal, // Normal; just copy the image to the screen - STYLE_Fuzzy, // Draw silhouette using "fuzz" effect - STYLE_SoulTrans, // Draw translucent with amount in r_transsouls - STYLE_OptFuzzy, // Draw as fuzzy or translucent, based on user preference - STYLE_Stencil, // Fill image interior with alphacolor - - // The following styles can affect visibility in P_CheckSight() - STYLE_Translucent=64, // Draw translucent - STYLE_Add, // Draw additive - STYLE_Shaded, // Treat patch data as alpha values for alphacolor - STYLE_TranslucentStencil, - - STYLE_Count -}; - #define TRANSLUC25 (FRACUNIT/4) #define TRANSLUC33 (FRACUNIT/3) #define TRANSLUC50 (FRACUNIT/2) @@ -623,13 +606,13 @@ public: WORD sprite; // used to find patch_t and flip value BYTE frame; // sprite frame to draw fixed_t scaleX, scaleY; // Scaling values; FRACUNIT is normal size - BYTE RenderStyle; // Style to draw this actor with + FRenderStyle RenderStyle; // Style to draw this actor with DWORD renderflags; // Different rendering flags int picnum; // Draw this instead of sprite if != 0xffff SWORD TIDtoHate; // TID of things to hate (0 if none) DWORD effects; // [RH] see p_effect.h fixed_t alpha; - DWORD alphacolor; // Color to draw when STYLE_Shaded + DWORD fillcolor; // Color to draw when STYLE_Shaded // interaction info fixed_t pitch, roll; diff --git a/src/am_map.cpp b/src/am_map.cpp index 007997e2c8..24e2a31c37 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -1653,7 +1653,7 @@ void AM_drawThings () } static void DrawMarker (FTexture *tex, fixed_t x, fixed_t y, int yadjust, - INTBOOL flip, fixed_t xscale, fixed_t yscale, int translation, fixed_t alpha, DWORD alphacolor, int renderstyle) + INTBOOL flip, fixed_t xscale, fixed_t yscale, int translation, fixed_t alpha, DWORD fillcolor, FRenderStyle renderstyle) { if (tex == NULL || tex->UseType == FTexture::TEX_Null) { @@ -1673,8 +1673,8 @@ static void DrawMarker (FTexture *tex, fixed_t x, fixed_t y, int yadjust, DTA_FlipX, flip, DTA_Translation, TranslationToTable(translation), DTA_Alpha, alpha, - DTA_FillColor, alphacolor, - DTA_RenderStyle, renderstyle, + DTA_FillColor, fillcolor, + DTA_RenderStyle, DWORD(renderstyle), TAG_DONE); } @@ -1684,7 +1684,8 @@ void AM_drawMarks () { if (markpoints[i].x != -1) { - DrawMarker (TexMan(marknums[i]), markpoints[i].x, markpoints[i].y, -3, 0, FRACUNIT, FRACUNIT, 0, FRACUNIT, 0, STYLE_Normal); + DrawMarker (TexMan(marknums[i]), markpoints[i].x, markpoints[i].y, -3, 0, + FRACUNIT, FRACUNIT, 0, FRACUNIT, 0, LegacyRenderStyles[STYLE_Normal]); } } } @@ -1743,7 +1744,7 @@ void AM_drawAuthorMarkers () { DrawMarker (tex, marked->x >> FRACTOMAPBITS, marked->y >> FRACTOMAPBITS, 0, flip, mark->scaleX, mark->scaleY, mark->Translation, - mark->alpha, mark->alphacolor, mark->RenderStyle); + mark->alpha, mark->fillcolor, mark->RenderStyle); } marked = mark->args[0] != 0 ? it.Next() : NULL; } diff --git a/src/b_bot.cpp b/src/b_bot.cpp index 37daafa8db..82ff3323ea 100644 --- a/src/b_bot.cpp +++ b/src/b_bot.cpp @@ -25,6 +25,12 @@ END_POINTERS CCMD (addbot) { + if (gamestate != GS_LEVEL && gamestate != GS_INTERMISSION) + { + Printf ("Bots cannot be added when not in a game!\n"); + return; + } + if (consoleplayer != Net_Arbitrator) { Printf ("Only player %d can add bots\n", Net_Arbitrator + 1); @@ -36,14 +42,7 @@ CCMD (addbot) Printf ("addbot [botname] : add a bot to the game\n"); return; } -/* - if (argc == 3) //Used force colornum - { - color = atoi (argv[2]); - if (color<0) color=0; - if (color>10) color=10; - } -*/ + if (argv.argc() > 1) bglobal.SpawnBot (argv[1]); else diff --git a/src/b_game.cpp b/src/b_game.cpp index 49608b6856..d8dcccf1d3 100644 --- a/src/b_game.cpp +++ b/src/b_game.cpp @@ -504,6 +504,7 @@ void DCajunMaster::ForgetBots () bool DCajunMaster::LoadBots () { + FScanner sc; FString tmp; bool gotteam = false; @@ -526,19 +527,19 @@ bool DCajunMaster::LoadBots () return false; } else - SC_OpenFile (SHARE_DIR BOTFILENAME); + sc.OpenFile (SHARE_DIR BOTFILENAME); } #endif else { - SC_OpenFile (tmp); + sc.OpenFile (tmp); } - while (SC_GetString ()) + while (sc.GetString ()) { - if (!SC_Compare ("{")) + if (!sc.Compare ("{")) { - SC_ScriptError ("Unexpected token '%s'\n", sc_String); + sc.ScriptError ("Unexpected token '%s'\n", sc.String); } botinfo_t *newinfo = new botinfo_t; @@ -550,37 +551,37 @@ bool DCajunMaster::LoadBots () for (;;) { - SC_MustGetString (); - if (SC_Compare ("}")) + sc.MustGetString (); + if (sc.Compare ("}")) break; - switch (SC_MatchString (BotConfigStrings)) + switch (sc.MatchString (BotConfigStrings)) { case BOTCFG_NAME: - SC_MustGetString (); + sc.MustGetString (); appendinfo (newinfo->info, "name"); - appendinfo (newinfo->info, sc_String); - newinfo->name = copystring (sc_String); + appendinfo (newinfo->info, sc.String); + newinfo->name = copystring (sc.String); break; case BOTCFG_AIMING: - SC_MustGetNumber (); - newinfo->skill.aiming = sc_Number; + sc.MustGetNumber (); + newinfo->skill.aiming = sc.Number; break; case BOTCFG_PERFECTION: - SC_MustGetNumber (); - newinfo->skill.perfection = sc_Number; + sc.MustGetNumber (); + newinfo->skill.perfection = sc.Number; break; case BOTCFG_REACTION: - SC_MustGetNumber (); - newinfo->skill.reaction = sc_Number; + sc.MustGetNumber (); + newinfo->skill.reaction = sc.Number; break; case BOTCFG_ISP: - SC_MustGetNumber (); - newinfo->skill.isp = sc_Number; + sc.MustGetNumber (); + newinfo->skill.isp = sc.Number; break; case BOTCFG_TEAM: @@ -588,10 +589,10 @@ bool DCajunMaster::LoadBots () char teamstr[16]; BYTE teamnum; - SC_MustGetString (); - if (IsNum (sc_String)) + sc.MustGetString (); + if (IsNum (sc.String)) { - teamnum = atoi (sc_String); + teamnum = atoi (sc.String); if (!TEAMINFO_IsValidTeam (teamnum)) { teamnum = TEAM_None; @@ -602,7 +603,7 @@ bool DCajunMaster::LoadBots () teamnum = TEAM_None; for (int i = 0; i < int(teams.Size()); ++i) { - if (stricmp (teams[i].name, sc_String) == 0) + if (stricmp (teams[i].name, sc.String) == 0) { teamnum = i; break; @@ -617,13 +618,13 @@ bool DCajunMaster::LoadBots () } default: - if (stricmp (sc_String, "playerclass") == 0) + if (stricmp (sc.String, "playerclass") == 0) { gotclass = true; } - appendinfo (newinfo->info, sc_String); - SC_MustGetString (); - appendinfo (newinfo->info, sc_String); + appendinfo (newinfo->info, sc.String); + sc.MustGetString (); + appendinfo (newinfo->info, sc.String); break; } } @@ -642,10 +643,7 @@ bool DCajunMaster::LoadBots () bglobal.botinfo = newinfo; bglobal.loaded_bots++; } - SC_Close (); - Printf ("%d bots read from %s\n", bglobal.loaded_bots, BOTFILENAME); - return true; } diff --git a/src/c_cmds.cpp b/src/c_cmds.cpp index f3b44a1eed..bd9618e841 100644 --- a/src/c_cmds.cpp +++ b/src/c_cmds.cpp @@ -636,16 +636,15 @@ CCMD (r_visibility) CCMD (warp) { + if (CheckCheatmode ()) + { + return; + } if (gamestate != GS_LEVEL) { Printf ("You can only warp inside a level.\n"); return; } - if (netgame) - { - Printf ("You cannot warp in a net game!\n"); - return; - } if (argv.argc() != 3) { Printf ("Usage: warp \n"); diff --git a/src/cmdlib.cpp b/src/cmdlib.cpp index 1b32884c35..3ece462b4a 100644 --- a/src/cmdlib.cpp +++ b/src/cmdlib.cpp @@ -382,10 +382,11 @@ void CreatePath(const char * fn) } // [RH] Replaces the escape sequences in a string with actual escaped characters. -// This operation is done in-place. +// This operation is done in-place. The result is the new length of the string. -void strbin (char *str) +int strbin (char *str) { + char *start; char *p = str, c; int i; @@ -468,4 +469,5 @@ void strbin (char *str) } } *str = 0; + return str - start; } diff --git a/src/cmdlib.h b/src/cmdlib.h index 5dcda108d5..a6a4509758 100644 --- a/src/cmdlib.h +++ b/src/cmdlib.h @@ -52,7 +52,7 @@ void FormatGUID (char *text, const GUID &guid); const char *myasctime (); -void strbin (char *str); +int strbin (char *str); void CreatePath(const char * fn); diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index fdde1cc5e8..9a728287b3 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -811,7 +811,7 @@ static int PatchThing (int thingy) int style = FindStyle (Line2); if (style >= 0) { - info->RenderStyle = style; + info->RenderStyle = ERenderStyle(style); hadStyle = true; } } diff --git a/src/d_main.cpp b/src/d_main.cpp index 21b9c3c4be..b63bf691b0 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2130,7 +2130,8 @@ void D_DoomMain (void) DArgs *files = Args.GatherFiles ("-file", ".wad", true); DArgs *files1 = Args.GatherFiles (NULL, ".zip", false); DArgs *files2 = Args.GatherFiles (NULL, ".pk3", false); - if (files->NumArgs() > 0 || files1->NumArgs() > 0 || files2->NumArgs() > 0) + DArgs *files3 = Args.GatherFiles (NULL, ".txt", false); + if (files->NumArgs() > 0 || files1->NumArgs() > 0 || files2->NumArgs() > 0 || files3->NumArgs() > 0) { // Check for -file in shareware if (gameinfo.flags & GI_SHAREWARE) @@ -2151,10 +2152,15 @@ void D_DoomMain (void) { D_AddWildFile (files2->GetArg (i)); } + for (int i = 0; i < files3->NumArgs(); i++) + { + D_AddWildFile (files3->GetArg (i)); + } } delete files; delete files1; delete files2; + delete files3; Printf ("W_Init: Init WADfiles.\n"); Wads.InitMultipleFiles (&wadfiles); diff --git a/src/decallib.cpp b/src/decallib.cpp index ce356779bb..40bca2be21 100644 --- a/src/decallib.cpp +++ b/src/decallib.cpp @@ -48,7 +48,7 @@ FDecalLib DecalLibrary; -static fixed_t ReadScale (); +static fixed_t ReadScale (FScanner &sc); static TArray DecalTranslations; // A decal group holds multiple decals and returns one randomly @@ -358,9 +358,8 @@ void FDecalLib::ReadAllDecals () while ((lump = Wads.FindLump ("DECALDEF", &lastlump)) != -1) { - SC_OpenLumpNum (lump, "DECALDEF"); - ReadDecals (); - SC_Close (); + FScanner sc(lump, "DECALDEF"); + ReadDecals (sc); } // Supporting code to allow specifying decals directly in the DECORATE lump for (i = 0; i < PClass::m_RuntimeActors.Size(); i++) @@ -375,79 +374,79 @@ void FDecalLib::ReadAllDecals () } } -void FDecalLib::ReadDecals () +void FDecalLib::ReadDecals(FScanner &sc) { - while (SC_GetString ()) + while (sc.GetString()) { - if (SC_Compare ("decal")) + if (sc.Compare("decal")) { - ParseDecal (); + ParseDecal(sc); } - else if (SC_Compare ("decalgroup")) + else if (sc.Compare("decalgroup")) { - ParseDecalGroup (); + ParseDecalGroup(sc); } - else if (SC_Compare ("generator")) + else if (sc.Compare("generator")) { - ParseGenerator (); + ParseGenerator(sc); } - else if (SC_Compare ("fader")) + else if (sc.Compare("fader")) { - ParseFader (); + ParseFader(sc); } - else if (SC_Compare ("stretcher")) + else if (sc.Compare("stretcher")) { - ParseStretcher (); + ParseStretcher(sc); } - else if (SC_Compare ("slider")) + else if (sc.Compare("slider")) { - ParseSlider (); + ParseSlider(sc); } - else if (SC_Compare ("combiner")) + else if (sc.Compare("combiner")) { - ParseCombiner (); + ParseCombiner(sc); } - else if (SC_Compare ("colorchanger")) + else if (sc.Compare("colorchanger")) { - ParseColorchanger (); + ParseColorchanger(sc); } else { - SC_ScriptError (NULL); + sc.MustGetStringName(NULL); } } } -BYTE FDecalLib::GetDecalID () +BYTE FDecalLib::GetDecalID (FScanner &sc) { - SC_MustGetString (); - if (!IsNum (sc_String)) + sc.MustGetString (); + if (!IsNum (sc.String)) { - SC_UnGet (); + sc.UnGet (); return 0; } else { - unsigned long num = strtoul (sc_String, NULL, 10); + unsigned long num = strtoul (sc.String, NULL, 10); if (num < 1 || num > 255) { - SC_ScriptError ("Decal ID must be between 1 and 255"); + sc.MustGetStringName ("Decal ID must be between 1 and 255"); } return (BYTE)num; } } -void FDecalLib::ParseDecal () +void FDecalLib::ParseDecal (FScanner &sc) { - char decalName[64]; + FString decalName; BYTE decalNum; FDecalTemplate newdecal; int code, picnum; - SC_MustGetString (); - strcpy (decalName, sc_String); - decalNum = GetDecalID (); - SC_MustGetStringName ("{"); + sc.MustGetString (); + decalName = sc.String; + decalNum = GetDecalID (sc); + sc.MustGetStringName ("{"); memset (&newdecal, 0, sizeof(newdecal)); newdecal.PicNum = 0xffff; @@ -458,26 +457,26 @@ void FDecalLib::ParseDecal () for (;;) { - SC_MustGetString (); - if (SC_Compare ("}")) + sc.MustGetString (); + if (sc.Compare ("}")) { AddDecal (decalName, decalNum, newdecal); break; } - switch ((code = SC_MustMatchString (DecalKeywords))) + switch ((code = sc.MustMatchString (DecalKeywords))) { case DECAL_XSCALE: - newdecal.ScaleX = ReadScale (); + newdecal.ScaleX = ReadScale (sc); break; case DECAL_YSCALE: - newdecal.ScaleY = ReadScale (); + newdecal.ScaleY = ReadScale (sc); break; case DECAL_PIC: - SC_MustGetString (); - picnum = TexMan.CheckForTexture (sc_String, FTexture::TEX_Any); - if (picnum < 0 && (picnum = Wads.CheckNumForName (sc_String, ns_graphics)) >= 0) + sc.MustGetString (); + picnum = TexMan.CheckForTexture (sc.String, FTexture::TEX_Any); + if (picnum < 0 && (picnum = Wads.CheckNumForName (sc.String, ns_graphics)) >= 0) { picnum = TexMan.CreateTexture (picnum, FTexture::TEX_Decal); } @@ -489,14 +488,14 @@ void FDecalLib::ParseDecal () break; case DECAL_ADD: - SC_MustGetFloat (); - newdecal.Alpha = (WORD)(32768.f * sc_Float); + sc.MustGetFloat (); + newdecal.Alpha = (WORD)(32768.f * sc.Float); newdecal.RenderStyle = STYLE_Add; break; case DECAL_TRANSLUCENT: - SC_MustGetFloat (); - newdecal.Alpha = (WORD)(32768.f * sc_Float); + sc.MustGetFloat (); + newdecal.Alpha = (WORD)(32768.f * sc.Float); newdecal.RenderStyle = STYLE_Translucent; break; @@ -525,9 +524,9 @@ void FDecalLib::ParseDecal () break; case DECAL_SHADE: - SC_MustGetString (); + sc.MustGetString (); newdecal.RenderStyle = STYLE_Shaded; - newdecal.ShadeColor = V_GetColor (NULL, sc_String); + newdecal.ShadeColor = V_GetColor (NULL, sc.String); newdecal.ShadeColor |= ColorMatcher.Pick (RPART(newdecal.ShadeColor), GPART(newdecal.ShadeColor), BPART(newdecal.ShadeColor)) << 24; @@ -536,42 +535,42 @@ void FDecalLib::ParseDecal () case DECAL_COLORS: DWORD startcolor, endcolor; - SC_MustGetString (); startcolor = V_GetColor (NULL, sc_String); - SC_MustGetString (); endcolor = V_GetColor (NULL, sc_String); + sc.MustGetString (); startcolor = V_GetColor (NULL, sc.String); + sc.MustGetString (); endcolor = V_GetColor (NULL, sc.String); newdecal.Translation = GenerateTranslation (startcolor, endcolor)->Index; break; case DECAL_ANIMATOR: - SC_MustGetString (); - newdecal.Animator = FindAnimator (sc_String); + sc.MustGetString (); + newdecal.Animator = FindAnimator (sc.String); break; case DECAL_LOWERDECAL: - SC_MustGetString (); - newdecal.LowerDecal = GetDecalByName (sc_String); + sc.MustGetString (); + newdecal.LowerDecal = GetDecalByName (sc.String); break; } } } -void FDecalLib::ParseDecalGroup () +void FDecalLib::ParseDecalGroup (FScanner &sc) { - char groupName[64]; + FString groupName; BYTE decalNum; FDecalBase *targetDecal; FDecalGroup *group; - SC_MustGetString (); - strcpy (groupName, sc_String); - decalNum = GetDecalID (); - SC_MustGetStringName ("{"); + sc.MustGetString (); + groupName = sc.String; + decalNum = GetDecalID (sc); + sc.MustGetStringName ("{"); group = new FDecalGroup; for (;;) { - SC_MustGetString (); - if (SC_Compare ("}")) + sc.MustGetString (); + if (sc.Compare ("}")) { group->Name = groupName; group->SpawnID = decalNum; @@ -579,44 +578,44 @@ void FDecalLib::ParseDecalGroup () break; } - targetDecal = ScanTreeForName (sc_String, Root); + targetDecal = ScanTreeForName (sc.String, Root); if (targetDecal == NULL) { - SC_ScriptError ("%s has not been defined", sc_String); + sc.ScriptError ("%s has not been defined", sc.String); } - SC_MustGetNumber (); + sc.MustGetNumber (); - group->AddDecal (targetDecal, sc_Number); + group->AddDecal (targetDecal, sc.Number); } } -void FDecalLib::ParseGenerator () +void FDecalLib::ParseGenerator (FScanner &sc) { const PClass *type; FDecalBase *decal; AActor *actor; // Get name of generator (actor) - SC_MustGetString (); - type = PClass::FindClass (sc_String); + sc.MustGetString (); + type = PClass::FindClass (sc.String); if (type == NULL || type->ActorInfo == NULL) { - SC_ScriptError ("%s is not an actor.", sc_String); + sc.ScriptError ("%s is not an actor.", sc.String); } actor = (AActor *)type->Defaults; // Get name of generated decal - SC_MustGetString (); - if (stricmp (sc_String, "None") == 0) + sc.MustGetString (); + if (stricmp (sc.String, "None") == 0) { decal = NULL; } else { - decal = ScanTreeForName (sc_String, Root); + decal = ScanTreeForName (sc.String, Root); if (decal == NULL) { - SC_ScriptError ("%s has not been defined.", sc_String); + sc.ScriptError ("%s has not been defined.", sc.String); } } @@ -624,19 +623,19 @@ void FDecalLib::ParseGenerator () decal->Users.Push (type); } -void FDecalLib::ParseFader () +void FDecalLib::ParseFader (FScanner &sc) { - char faderName[64]; + FString faderName; int startTime = 0, decayTime = 0; - SC_MustGetString (); - strcpy (faderName, sc_String); - SC_MustGetStringName ("{"); + sc.MustGetString (); + faderName = sc.String; + sc.MustGetStringName ("{"); for (;;) { - SC_MustGetString (); - if (SC_Compare ("}")) + sc.MustGetString (); + if (sc.Compare ("}")) { FDecalFaderAnim *fader = new FDecalFaderAnim (faderName); fader->DecayStart = startTime; @@ -644,37 +643,37 @@ void FDecalLib::ParseFader () Animators.Push (fader); break; } - else if (SC_Compare ("DecayStart")) + else if (sc.Compare ("DecayStart")) { - SC_MustGetFloat (); - startTime = (int)(sc_Float * TICRATE); + sc.MustGetFloat (); + startTime = (int)(sc.Float * TICRATE); } - else if (SC_Compare ("DecayTime")) + else if (sc.Compare ("DecayTime")) { - SC_MustGetFloat (); - decayTime = (int)(sc_Float * TICRATE); + sc.MustGetFloat (); + decayTime = (int)(sc.Float * TICRATE); } else { - SC_ScriptError ("Unknown fader parameter '%s'", sc_String); + sc.ScriptError ("Unknown fader parameter '%s'", sc.String); } } } -void FDecalLib::ParseStretcher () +void FDecalLib::ParseStretcher (FScanner &sc) { - char stretcherName[64]; + FString stretcherName; fixed_t goalX = -1, goalY = -1; int startTime = 0, takeTime = 0; - SC_MustGetString (); - strcpy (stretcherName, sc_String); - SC_MustGetStringName ("{"); + sc.MustGetString (); + stretcherName = sc.String; + sc.MustGetStringName ("{"); for (;;) { - SC_MustGetString (); - if (SC_Compare ("}")) + sc.MustGetString (); + if (sc.Compare ("}")) { if (goalX >= 0 || goalY >= 0) { @@ -687,45 +686,45 @@ void FDecalLib::ParseStretcher () } break; } - else if (SC_Compare ("StretchStart")) + else if (sc.Compare ("StretchStart")) { - SC_MustGetFloat (); - startTime = (int)(sc_Float * TICRATE); + sc.MustGetFloat (); + startTime = (int)(sc.Float * TICRATE); } - else if (SC_Compare ("StretchTime")) + else if (sc.Compare ("StretchTime")) { - SC_MustGetFloat (); - takeTime = (int)(sc_Float * TICRATE); + sc.MustGetFloat (); + takeTime = (int)(sc.Float * TICRATE); } - else if (SC_Compare ("GoalX")) + else if (sc.Compare ("GoalX")) { - goalX = ReadScale (); + goalX = ReadScale (sc); } - else if (SC_Compare ("GoalY")) + else if (sc.Compare ("GoalY")) { - goalY = ReadScale (); + goalY = ReadScale (sc); } else { - SC_ScriptError ("Unknown stretcher parameter '%s'", sc_String); + sc.ScriptError ("Unknown stretcher parameter '%s'", sc.String); } } } -void FDecalLib::ParseSlider () +void FDecalLib::ParseSlider (FScanner &sc) { - char sliderName[64]; + FString sliderName; fixed_t distX = 0, distY = 0; int startTime = 0, takeTime = 0; - SC_MustGetString (); - strcpy (sliderName, sc_String); - SC_MustGetStringName ("{"); + sc.MustGetString (); + sliderName = sc.String; + sc.MustGetStringName ("{"); for (;;) { - SC_MustGetString (); - if (SC_Compare ("}")) + sc.MustGetString (); + if (sc.Compare ("}")) { if ((/*distX |*/ distY) != 0) { @@ -738,48 +737,48 @@ void FDecalLib::ParseSlider () } break; } - else if (SC_Compare ("SlideStart")) + else if (sc.Compare ("SlideStart")) { - SC_MustGetFloat (); - startTime = (int)(sc_Float * TICRATE); + sc.MustGetFloat (); + startTime = (int)(sc.Float * TICRATE); } - else if (SC_Compare ("SlideTime")) + else if (sc.Compare ("SlideTime")) { - SC_MustGetFloat (); - takeTime = (int)(sc_Float * TICRATE); + sc.MustGetFloat (); + takeTime = (int)(sc.Float * TICRATE); } - else if (SC_Compare ("DistX")) + else if (sc.Compare ("DistX")) { - SC_MustGetFloat (); - distX = (fixed_t)(sc_Float * FRACUNIT); - Printf ("DistX in slider decal %s is unsupported\n", sliderName); + sc.MustGetFloat (); + distX = (fixed_t)(sc.Float * FRACUNIT); + Printf ("DistX in slider decal %s is unsupported\n", sliderName.GetChars()); } - else if (SC_Compare ("DistY")) + else if (sc.Compare ("DistY")) { - SC_MustGetFloat (); - distY = (fixed_t)(sc_Float * FRACUNIT); + sc.MustGetFloat (); + distY = (fixed_t)(sc.Float * FRACUNIT); } else { - SC_ScriptError ("Unknown slider parameter '%s'", sc_String); + sc.ScriptError ("Unknown slider parameter '%s'", sc.String); } } } -void FDecalLib::ParseColorchanger () +void FDecalLib::ParseColorchanger (FScanner &sc) { - char faderName[64]; + FString faderName; int startTime = 0, decayTime = 0; PalEntry goal = 0; - SC_MustGetString (); - strcpy (faderName, sc_String); - SC_MustGetStringName ("{"); + sc.MustGetString (); + faderName = sc.String; + sc.MustGetStringName ("{"); for (;;) { - SC_MustGetString (); - if (SC_Compare ("}")) + sc.MustGetString (); + if (sc.Compare ("}")) { FDecalColorerAnim *fader = new FDecalColorerAnim (faderName); fader->DecayStart = startTime; @@ -788,46 +787,46 @@ void FDecalLib::ParseColorchanger () Animators.Push (fader); break; } - else if (SC_Compare ("FadeStart")) + else if (sc.Compare ("FadeStart")) { - SC_MustGetFloat (); - startTime = (int)(sc_Float * TICRATE); + sc.MustGetFloat (); + startTime = (int)(sc.Float * TICRATE); } - else if (SC_Compare ("FadeTime")) + else if (sc.Compare ("FadeTime")) { - SC_MustGetFloat (); - decayTime = (int)(sc_Float * TICRATE); + sc.MustGetFloat (); + decayTime = (int)(sc.Float * TICRATE); } - else if (SC_Compare ("Color")) + else if (sc.Compare ("Color")) { - SC_MustGetString (); - goal = V_GetColor (NULL, sc_String); + sc.MustGetString (); + goal = V_GetColor (NULL, sc.String); } else { - SC_ScriptError ("Unknown color changer parameter '%s'", sc_String); + sc.ScriptError ("Unknown color changer parameter '%s'", sc.String); } } } -void FDecalLib::ParseCombiner () +void FDecalLib::ParseCombiner (FScanner &sc) { - char combinerName[64]; + FString combinerName; size_t first = FDecalCombinerAnim::AnimatorList.Size (); - SC_MustGetString (); - strcpy (combinerName, sc_String); - SC_MustGetStringName ("{"); - SC_MustGetString (); - while (!SC_Compare ("}")) + sc.MustGetString (); + combinerName = sc.String; + sc.MustGetStringName ("{"); + sc.MustGetString (); + while (!sc.Compare ("}")) { - FDecalAnimator *anim = FindAnimator (sc_String); + FDecalAnimator *anim = FindAnimator (sc.String); if (anim == NULL) { - SC_ScriptError ("Undefined animator %s", sc_String); + sc.ScriptError ("Undefined animator %s", sc.String); } FDecalCombinerAnim::AnimatorList.Push (anim); - SC_MustGetString (); + sc.MustGetString (); } size_t last = FDecalCombinerAnim::AnimatorList.Size (); @@ -1022,7 +1021,7 @@ FDecalBase::~FDecalBase () void FDecalTemplate::ApplyToDecal (DBaseDecal *decal, side_t *wall) const { - if (RenderStyle == STYLE_Shaded) + if (RenderStyle.Flags & STYLEF_ColorIsFixed) { decal->SetShade (ShadeColor); } @@ -1165,11 +1164,6 @@ void DDecalFader::Tick () int distanceToEnd = TimeToEndDecay - level.maptime; int fadeDistance = TimeToEndDecay - TimeToStartDecay; TheDecal->Alpha = Scale (StartTrans, distanceToEnd, fadeDistance); - - if (TheDecal->RenderStyle < STYLE_Translucent) - { - TheDecal->RenderStyle = STYLE_Translucent; - } } } @@ -1364,7 +1358,7 @@ void DDecalColorer::Serialize (FArchive &arc) void DDecalColorer::Tick () { - if (TheDecal == NULL || TheDecal->RenderStyle != STYLE_Shaded) + if (TheDecal == NULL || !(TheDecal->RenderStyle.Flags & STYLEF_ColorIsFixed)) { Destroy (); } @@ -1413,8 +1407,8 @@ DThinker *FDecalColorerAnim::CreateThinker (DBaseDecal *actor, side_t *wall) con return Colorer; } -static fixed_t ReadScale () +static fixed_t ReadScale (FScanner &sc) { - SC_MustGetFloat (); - return fixed_t(clamp (sc_Float * FRACUNIT, 256.0, 256.0*FRACUNIT)); + sc.MustGetFloat (); + return fixed_t(clamp (sc.Float * FRACUNIT, 256.0, 256.0*FRACUNIT)); } diff --git a/src/decallib.h b/src/decallib.h index c77b3abdba..e5e213c586 100644 --- a/src/decallib.h +++ b/src/decallib.h @@ -39,8 +39,9 @@ #include "doomtype.h" #include "tarray.h" #include "name.h" +#include "actor.h" -class AActor; +class FScanner; class FDecalTemplate; struct FDecalAnimator; struct PClass; @@ -77,7 +78,7 @@ public: fixed_t ScaleX, ScaleY; DWORD ShadeColor; DWORD Translation; - BYTE RenderStyle; + FRenderStyle RenderStyle; WORD PicNum; WORD RenderFlags; WORD Alpha; // same as (actor->alpha >> 1) @@ -94,7 +95,7 @@ public: ~FDecalLib (); void Clear (); - void ReadDecals (); // SC_Open() should have just been called + void ReadDecals (FScanner &sc); void ReadAllDecals (); const FDecalTemplate *GetDecalByNum (BYTE num) const; @@ -112,15 +113,15 @@ private: void AddDecal (FDecalBase *decal); FDecalAnimator *FindAnimator (const char *name); - BYTE GetDecalID (); - void ParseDecal (); - void ParseDecalGroup (); - void ParseGenerator (); - void ParseFader (); - void ParseStretcher (); - void ParseSlider (); - void ParseCombiner (); - void ParseColorchanger (); + BYTE GetDecalID (FScanner &sc); + void ParseDecal (FScanner &sc); + void ParseDecalGroup (FScanner &sc); + void ParseGenerator (FScanner &sc); + void ParseFader (FScanner &sc); + void ParseStretcher (FScanner &sc); + void ParseSlider (FScanner &sc); + void ParseCombiner (FScanner &sc); + void ParseColorchanger (FScanner &sc); FDecalBase *Root; FTranslation *Translations; diff --git a/src/doomtype.h b/src/doomtype.h index ed23152675..1b689fd8f2 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -180,7 +180,7 @@ struct PalEntry PalEntry (DWORD argb) { *(DWORD *)this = argb; } operator DWORD () const { return *(DWORD *)this; } PalEntry &operator= (DWORD other) { *(DWORD *)this = other; return *this; } - + PalEntry InverseColor() const { PalEntry nc; nc.a = a; nc.r = 255 - r; nc.g = 255 - g; nc.b = 255 - b; return nc; } #ifdef WORDS_BIGENDIAN PalEntry (BYTE ir, BYTE ig, BYTE ib) : a(0), r(ir), g(ig), b(ib) {} PalEntry (BYTE ia, BYTE ir, BYTE ig, BYTE ib) : a(ia), r(ir), g(ig), b(ib) {} diff --git a/src/g_level.cpp b/src/g_level.cpp index a0232652ef..4c40c400e2 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -98,13 +98,13 @@ EXTERN_CVAR (Int, disableautosave) static int FindEndSequence (int type, const char *picname); static void SetEndSequence (char *nextmap, int type); static void InitPlayerClasses (); -static void ParseEpisodeInfo (); +static void ParseEpisodeInfo (FScanner &sc); static void G_DoParseMapInfo (int lump); static void SetLevelNum (level_info_t *info, int num); static void ClearEpisodes (); static void ClearLevelInfoStrings (level_info_t *linfo); static void ClearClusterInfoStrings (cluster_info_t *cinfo); -static void ParseSkill (); +static void ParseSkill (FScanner &sc); static void G_VerifySkill(); static FRandom pr_classchoice ("RandomPlayerClassChoice"); @@ -483,7 +483,8 @@ MapInfoHandler ClusterHandlers[] = { MITYPE_STRING, cioffset(clustername), 0 }, }; -static void ParseMapInfoLower (MapInfoHandler *handlers, +static void ParseMapInfoLower (FScanner &sc, + MapInfoHandler *handlers, const char *strings[], level_info_t *levelinfo, cluster_info_t *clusterinfo, @@ -605,28 +606,29 @@ static void G_DoParseMapInfo (int lump) int clusterindex; QWORD levelflags; + FScanner sc(lump, Wads.GetLumpFullName(lump)); + SetLevelDefaults (&defaultinfo); - SC_OpenLumpNum (lump, Wads.GetLumpFullName(lump)); HexenHack = false; - while (SC_GetString ()) + while (sc.GetString ()) { - switch (SC_MustMatchString (MapInfoTopLevel)) + switch (sc.MustMatchString (MapInfoTopLevel)) { case MITL_DEFAULTMAP: if (defaultinfo.music != NULL) delete [] defaultinfo.music; if (defaultinfo.intermusic != NULL) delete [] defaultinfo.intermusic; SetLevelDefaults (&defaultinfo); - ParseMapInfoLower (MapHandlers, MapInfoMapLevel, &defaultinfo, NULL, defaultinfo.flags); + ParseMapInfoLower (sc, MapHandlers, MapInfoMapLevel, &defaultinfo, NULL, defaultinfo.flags); break; case MITL_MAP: // map levelflags = defaultinfo.flags; - SC_MustGetString (); - if (IsNum (sc_String)) + sc.MustGetString (); + if (IsNum (sc.String)) { // MAPNAME is a number; assume a Hexen wad - int map = atoi (sc_String); - sprintf (sc_String, "MAP%02d", map); + int map = atoi (sc.String); + sprintf (sc.String, "MAP%02d", map); HexenHack = true; // Hexen levels are automatically nointermission, // no auto sound sequences, falling damage, @@ -639,7 +641,7 @@ static void G_DoParseMapInfo (int lump) | LEVEL_MISSILESACTIVATEIMPACT | LEVEL_INFINITE_FLIGHT; } - levelindex = FindWadLevelInfo (sc_String); + levelindex = FindWadLevelInfo (sc.String); if (levelindex == -1) { levelindex = wadlevelinfos.Reserve(1); @@ -662,17 +664,17 @@ static void G_DoParseMapInfo (int lump) { levelinfo->WallHorizLight = levelinfo->WallVertLight = 0; } - uppercopy (levelinfo->mapname, sc_String); - SC_MustGetString (); - if (SC_Compare ("lookup")) + uppercopy (levelinfo->mapname, sc.String); + sc.MustGetString (); + if (sc.Compare ("lookup")) { - SC_MustGetString (); - ReplaceString (&levelinfo->level_name, sc_String); + sc.MustGetString (); + ReplaceString (&levelinfo->level_name, sc.String); levelflags |= LEVEL_LOOKUPLEVELNAME; } else { - ReplaceString (&levelinfo->level_name, sc_String); + ReplaceString (&levelinfo->level_name, sc.String); } // Set up levelnum now so that you can use Teleport_NewMap specials // to teleport to maps with standard names without needing a levelnum. @@ -692,7 +694,7 @@ static void G_DoParseMapInfo (int lump) int mapnum = levelinfo->mapname[3] - '0'; levelinfo->levelnum = epinum*10 + mapnum; } - ParseMapInfoLower (MapHandlers, MapInfoMapLevel, levelinfo, NULL, levelflags); + ParseMapInfoLower (sc, MapHandlers, MapInfoMapLevel, levelinfo, NULL, levelflags); // When the second sky is -NOFLAT-, make it a copy of the first sky if (strcmp (levelinfo->skypic2, "-NOFLAT-") == 0) { @@ -713,8 +715,8 @@ static void G_DoParseMapInfo (int lump) break; case MITL_CLUSTERDEF: // clusterdef - SC_MustGetNumber (); - clusterindex = FindWadClusterInfo (sc_Number); + sc.MustGetNumber (); + clusterindex = FindWadClusterInfo (sc.Number); if (clusterindex == -1) { clusterindex = wadclusterinfos.Reserve(1); @@ -741,20 +743,20 @@ static void G_DoParseMapInfo (int lump) } } memset (clusterinfo, 0, sizeof(cluster_info_t)); - clusterinfo->cluster = sc_Number; - ParseMapInfoLower (ClusterHandlers, MapInfoClusterLevel, NULL, clusterinfo, 0); + clusterinfo->cluster = sc.Number; + ParseMapInfoLower (sc, ClusterHandlers, MapInfoClusterLevel, NULL, clusterinfo, 0); break; case MITL_EPISODE: - ParseEpisodeInfo (); + ParseEpisodeInfo(sc); break; case MITL_CLEAREPISODES: - ClearEpisodes (); + ClearEpisodes(); break; case MITL_SKILL: - ParseSkill(); + ParseSkill(sc); break; case MITL_CLEARSKILLS: @@ -763,7 +765,6 @@ static void G_DoParseMapInfo (int lump) } } - SC_Close (); if (defaultinfo.music != NULL) { delete [] defaultinfo.music; @@ -833,7 +834,8 @@ static void ClearEpisodes() EpiDef.numitems = 0; } -static void ParseMapInfoLower (MapInfoHandler *handlers, +static void ParseMapInfoLower (FScanner &sc, + MapInfoHandler *handlers, const char *strings[], level_info_t *levelinfo, cluster_info_t *clusterinfo, @@ -845,52 +847,52 @@ static void ParseMapInfoLower (MapInfoHandler *handlers, info = levelinfo ? (BYTE *)levelinfo : (BYTE *)clusterinfo; - while (SC_GetString ()) + while (sc.GetString ()) { - if (SC_MatchString (MapInfoTopLevel) != -1) + if (sc.MatchString (MapInfoTopLevel) != -1) { - SC_UnGet (); + sc.UnGet (); break; } - entry = SC_MustMatchString (strings); + entry = sc.MustMatchString (strings); handler = handlers + entry; switch (handler->type) { case MITYPE_EATNEXT: - SC_MustGetString (); + sc.MustGetString (); break; case MITYPE_IGNORE: break; case MITYPE_INT: - SC_MustGetNumber (); - *((int *)(info + handler->data1)) = sc_Number; + sc.MustGetNumber (); + *((int *)(info + handler->data1)) = sc.Number; break; case MITYPE_FLOAT: - SC_MustGetFloat (); - *((float *)(info + handler->data1)) = sc_Float; + sc.MustGetFloat (); + *((float *)(info + handler->data1)) = sc.Float; break; case MITYPE_HEX: - SC_MustGetString (); - *((int *)(info + handler->data1)) = strtoul (sc_String, NULL, 16); + sc.MustGetString (); + *((int *)(info + handler->data1)) = strtoul (sc.String, NULL, 16); break; case MITYPE_COLOR: - SC_MustGetString (); - *((DWORD *)(info + handler->data1)) = V_GetColor (NULL, sc_String); + sc.MustGetString (); + *((DWORD *)(info + handler->data1)) = V_GetColor (NULL, sc.String); break; case MITYPE_REDIRECT: - SC_MustGetString (); - levelinfo->RedirectType = sc_String; + sc.MustGetString (); + levelinfo->RedirectType = sc.String; /* if (levelinfo->RedirectType == NULL || !(levelinfo->RedirectType->IsDescendantOf (RUNTIME_CLASS(AInventory)))) { - SC_ScriptError ("%s is not an inventory item", sc_String); + SC_ScriptError ("%s is not an inventory item", sc.String); } */ // Intentional fall-through @@ -899,24 +901,24 @@ static void ParseMapInfoLower (MapInfoHandler *handlers, EndSequence newSeq; bool useseq = false; - SC_MustGetString (); - if (IsNum (sc_String)) + sc.MustGetString (); + if (IsNum (sc.String)) { - int map = atoi (sc_String); + int map = atoi (sc.String); if (HexenHack) { - sprintf (sc_String, "&wt@%02d", map); + sprintf (sc.String, "&wt@%02d", map); } else { - sprintf (sc_String, "MAP%02d", map); + sprintf (sc.String, "MAP%02d", map); } } - if (strnicmp (sc_String, "EndGame", 7) == 0) + if (strnicmp (sc.String, "EndGame", 7) == 0) { int type; - switch (sc_String[7]) + switch (sc.String[7]) { case '1': type = END_Pic1; break; case '2': type = END_Pic2; break; @@ -929,47 +931,47 @@ static void ParseMapInfoLower (MapInfoHandler *handlers, newSeq.EndType = type; useseq = true; } - else if (SC_Compare ("endpic")) + else if (sc.Compare ("endpic")) { - SC_MustGetString (); + sc.MustGetString (); newSeq.EndType = END_Pic; - strncpy (newSeq.PicName, sc_String, 8); + strncpy (newSeq.PicName, sc.String, 8); newSeq.PicName[8] = 0; useseq = true; } - else if (SC_Compare ("endbunny")) + else if (sc.Compare ("endbunny")) { newSeq.EndType = END_Bunny; useseq = true; } - else if (SC_Compare ("endcast")) + else if (sc.Compare ("endcast")) { newSeq.EndType = END_Cast; useseq = true; } - else if (SC_Compare ("enddemon")) + else if (sc.Compare ("enddemon")) { newSeq.EndType = END_Demon; useseq = true; } - else if (SC_Compare ("endchess")) + else if (sc.Compare ("endchess")) { newSeq.EndType = END_Chess; useseq = true; } - else if (SC_Compare ("endunderwater")) + else if (sc.Compare ("endunderwater")) { newSeq.EndType = END_Underwater; useseq = true; } - else if (SC_Compare ("endbuystrife")) + else if (sc.Compare ("endbuystrife")) { newSeq.EndType = END_BuyStrife; useseq = true; } else { - strncpy ((char *)(info + handler->data1), sc_String, 8); + strncpy ((char *)(info + handler->data1), sc.String, 8); } if (useseq) { @@ -985,22 +987,22 @@ static void ParseMapInfoLower (MapInfoHandler *handlers, } case MITYPE_LUMPNAME: - SC_MustGetString (); - uppercopy ((char *)(info + handler->data1), sc_String); + sc.MustGetString (); + uppercopy ((char *)(info + handler->data1), sc.String); flags |= handler->data2; break; case MITYPE_SKY: - SC_MustGetString (); // get texture name; - uppercopy ((char *)(info + handler->data1), sc_String); - SC_MustGetFloat (); // get scroll speed + sc.MustGetString (); // get texture name; + uppercopy ((char *)(info + handler->data1), sc.String); + sc.MustGetFloat (); // get scroll speed if (HexenHack) { - sc_Float /= 256; + sc.Float /= 256; } // Sky scroll speed is specified as pixels per tic, but we // want pixels per millisecond. - *((float *)(info + handler->data2)) = sc_Float * 35 / 1000; + *((float *)(info + handler->data2)) = sc.Float * 35 / 1000; break; case MITYPE_SETFLAG: @@ -1018,18 +1020,18 @@ static void ParseMapInfoLower (MapInfoHandler *handlers, break; case MITYPE_CLUSTER: - SC_MustGetNumber (); - *((int *)(info + handler->data1)) = sc_Number; + sc.MustGetNumber (); + *((int *)(info + handler->data1)) = sc.Number; // If this cluster hasn't been defined yet, add it. This is especially needed // for Hexen, because it doesn't have clusterdefs. If we don't do this, every // level on Hexen will sometimes be considered as being on the same hub, // depending on the check done. - if (FindWadClusterInfo (sc_Number) == -1) + if (FindWadClusterInfo (sc.Number) == -1) { unsigned int clusterindex = wadclusterinfos.Reserve(1); clusterinfo = &wadclusterinfos[clusterindex]; memset (clusterinfo, 0, sizeof(cluster_info_t)); - clusterinfo->cluster = sc_Number; + clusterinfo->cluster = sc.Number; if (gameinfo.gametype == GAME_Hexen) { clusterinfo->flags |= CLUSTER_HUB; @@ -1038,36 +1040,36 @@ static void ParseMapInfoLower (MapInfoHandler *handlers, break; case MITYPE_STRING: - SC_MustGetString (); - if (SC_Compare ("lookup")) + sc.MustGetString (); + if (sc.Compare ("lookup")) { flags |= handler->data2; - SC_MustGetString (); + sc.MustGetString (); } - ReplaceString ((char **)(info + handler->data1), sc_String); + ReplaceString ((char **)(info + handler->data1), sc.String); break; case MITYPE_F1: - SC_MustGetString (); + sc.MustGetString (); { - char *colon = strchr (sc_String, ':'); + char *colon = strchr (sc.String, ':'); if (colon) { *colon = 0; } - ReplaceString ((char **)(info + handler->data1), sc_String); + ReplaceString ((char **)(info + handler->data1), sc.String); } break; case MITYPE_MUSIC: - SC_MustGetString (); + sc.MustGetString (); { - char *colon = strchr (sc_String, ':'); + char *colon = strchr (sc.String, ':'); if (colon) { *colon = 0; } - ReplaceString ((char **)(info + handler->data1), sc_String); + ReplaceString ((char **)(info + handler->data1), sc.String); *((int *)(info + handler->data2)) = colon ? atoi (colon + 1) : 0; if (levelinfo != NULL) { @@ -1078,8 +1080,8 @@ static void ParseMapInfoLower (MapInfoHandler *handlers, break; case MITYPE_RELLIGHT: - SC_MustGetNumber (); - *((SBYTE *)(info + handler->data1)) = (SBYTE)clamp (sc_Number / 2, -128, 127); + sc.MustGetNumber (); + *((SBYTE *)(info + handler->data1)) = (SBYTE)clamp (sc.Number / 2, -128, 127); break; case MITYPE_CLRBYTES: @@ -1095,29 +1097,29 @@ static void ParseMapInfoLower (MapInfoHandler *handlers, FSpecialAction *sa = new FSpecialAction; sa->Next = *so; *so = sa; - SC_SetCMode(true); - SC_MustGetString(); - sa->Type = FName(sc_String); - SC_CheckString(","); - SC_MustGetString(); - strlwr(sc_String); - sa->Action = FindLineSpecial(sc_String); + sc.SetCMode(true); + sc.MustGetString(); + sa->Type = FName(sc.String); + sc.CheckString(","); + sc.MustGetString(); + strlwr(sc.String); + sa->Action = FindLineSpecial(sc.String); int j = 0; - while (j < 5 && SC_CheckString(",")) + while (j < 5 && sc.CheckString(",")) { - SC_MustGetNumber(); - sa->Args[j++] = sc_Number; + sc.MustGetNumber(); + sa->Args[j++] = sc.Number; } - SC_SetCMode(false); + sc.SetCMode(false); } break; case MITYPE_COMPATFLAG: - if (!SC_CheckNumber()) sc_Number = 1; + if (!sc.CheckNumber()) sc.Number = 1; if (levelinfo != NULL) { - if (sc_Number) levelinfo->compatflags |= (DWORD)handler->data1; + if (sc.Number) levelinfo->compatflags |= (DWORD)handler->data1; else levelinfo->compatflags &= ~ (DWORD)handler->data1; levelinfo->compatmask |= (DWORD)handler->data1; } @@ -1143,7 +1145,7 @@ static void ParseMapInfoLower (MapInfoHandler *handlers, // noskillmenu // remove -static void ParseEpisodeInfo () +static void ParseEpisodeInfo (FScanner &sc) { int i; char map[9]; @@ -1155,54 +1157,54 @@ static void ParseEpisodeInfo () bool noskill = false; // Get map name - SC_MustGetString (); - uppercopy (map, sc_String); + sc.MustGetString (); + uppercopy (map, sc.String); map[8] = 0; - SC_MustGetString (); - if (SC_Compare ("teaser")) + sc.MustGetString (); + if (sc.Compare ("teaser")) { - SC_MustGetString (); + sc.MustGetString (); if (gameinfo.flags & GI_SHAREWARE) { - uppercopy (map, sc_String); + uppercopy (map, sc.String); } - SC_MustGetString (); + sc.MustGetString (); } do { - if (SC_Compare ("name")) + if (sc.Compare ("name")) { - SC_MustGetString (); - ReplaceString (&pic, sc_String); + sc.MustGetString (); + ReplaceString (&pic, sc.String); picisgfx = false; } - else if (SC_Compare ("picname")) + else if (sc.Compare ("picname")) { - SC_MustGetString (); - ReplaceString (&pic, sc_String); + sc.MustGetString (); + ReplaceString (&pic, sc.String); picisgfx = true; } - else if (SC_Compare ("remove")) + else if (sc.Compare ("remove")) { remove = true; } - else if (SC_Compare ("key")) + else if (sc.Compare ("key")) { - SC_MustGetString (); - key = sc_String[0]; + sc.MustGetString (); + key = sc.String[0]; } - else if (SC_Compare("noskillmenu")) + else if (sc.Compare("noskillmenu")) { noskill = true; } else { - SC_UnGet (); + sc.UnGet (); break; } } - while (SC_GetString ()); + while (sc.GetString ()); for (i = 0; i < EpiDef.numitems; ++i) { @@ -3122,7 +3124,7 @@ static void InitPlayerClasses () } -static void ParseSkill () +static void ParseSkill (FScanner &sc) { FSkillInfo skill; @@ -3142,106 +3144,106 @@ static void ParseSkill () skill.Shortcut = 0; skill.TextColor = ""; - SC_MustGetString(); - skill.Name = sc_String; + sc.MustGetString(); + skill.Name = sc.String; - while (SC_GetString ()) + while (sc.GetString ()) { - if (SC_Compare ("ammofactor")) + if (sc.Compare ("ammofactor")) { - SC_MustGetFloat (); - skill.AmmoFactor = FLOAT2FIXED(sc_Float); + sc.MustGetFloat (); + skill.AmmoFactor = FLOAT2FIXED(sc.Float); } - else if (SC_Compare ("doubleammofactor")) + else if (sc.Compare ("doubleammofactor")) { - SC_MustGetFloat (); - skill.DoubleAmmoFactor = FLOAT2FIXED(sc_Float); + sc.MustGetFloat (); + skill.DoubleAmmoFactor = FLOAT2FIXED(sc.Float); } - else if (SC_Compare ("damagefactor")) + else if (sc.Compare ("damagefactor")) { - SC_MustGetFloat (); - skill.DamageFactor = FLOAT2FIXED(sc_Float); + sc.MustGetFloat (); + skill.DamageFactor = FLOAT2FIXED(sc.Float); } - else if (SC_Compare ("fastmonsters")) + else if (sc.Compare ("fastmonsters")) { skill.FastMonsters = true; } - else if (SC_Compare ("disablecheats")) + else if (sc.Compare ("disablecheats")) { skill.DisableCheats = true; } - else if (SC_Compare ("easybossbrain")) + else if (sc.Compare ("easybossbrain")) { skill.EasyBossBrain = true; } - else if (SC_Compare("autousehealth")) + else if (sc.Compare("autousehealth")) { skill.AutoUseHealth = true; } - else if (SC_Compare("respawntime")) + else if (sc.Compare("respawntime")) { - SC_MustGetFloat (); - skill.RespawnCounter = int(sc_Float*TICRATE); + sc.MustGetFloat (); + skill.RespawnCounter = int(sc.Float*TICRATE); } - else if (SC_Compare("Aggressiveness")) + else if (sc.Compare("Aggressiveness")) { - SC_MustGetFloat (); - skill.Aggressiveness = FRACUNIT - FLOAT2FIXED(clamp(sc_Float, 0,1)); + sc.MustGetFloat (); + skill.Aggressiveness = FRACUNIT - FLOAT2FIXED(clamp(sc.Float, 0,1)); } - else if (SC_Compare("SpawnFilter")) + else if (sc.Compare("SpawnFilter")) { - SC_MustGetString (); - strlwr(sc_String); - if (strstr(sc_String, "easy")) skill.SpawnFilter|=MTF_EASY; - if (strstr(sc_String, "normal")) skill.SpawnFilter|=MTF_NORMAL; - if (strstr(sc_String, "hard")) skill.SpawnFilter|=MTF_HARD; + sc.MustGetString (); + strlwr(sc.String); + if (strstr(sc.String, "easy")) skill.SpawnFilter|=MTF_EASY; + if (strstr(sc.String, "normal")) skill.SpawnFilter|=MTF_NORMAL; + if (strstr(sc.String, "hard")) skill.SpawnFilter|=MTF_HARD; } - else if (SC_Compare("ACSReturn")) + else if (sc.Compare("ACSReturn")) { - SC_MustGetNumber (); - skill.ACSReturn = sc_Number; + sc.MustGetNumber (); + skill.ACSReturn = sc.Number; } - else if (SC_Compare("Name")) + else if (sc.Compare("Name")) { - SC_MustGetString (); - skill.MenuName = sc_String; + sc.MustGetString (); + skill.MenuName = sc.String; skill.MenuNameIsLump = false; } - else if (SC_Compare("PlayerClassName")) + else if (sc.Compare("PlayerClassName")) { - SC_MustGetString (); - FName pc = sc_String; - SC_MustGetString (); - skill.MenuNamesForPlayerClass[pc]=sc_String; + sc.MustGetString (); + FName pc = sc.String; + sc.MustGetString (); + skill.MenuNamesForPlayerClass[pc]=sc.String; } - else if (SC_Compare("PicName")) + else if (sc.Compare("PicName")) { - SC_MustGetString (); - skill.MenuName = sc_String; + sc.MustGetString (); + skill.MenuName = sc.String; skill.MenuNameIsLump = true; } - else if (SC_Compare("MustConfirm")) + else if (sc.Compare("MustConfirm")) { skill.MustConfirm = true; - if (SC_CheckToken(TK_StringConst)) + if (sc.CheckToken(TK_StringConst)) { - skill.MustConfirmText = sc_String; + skill.MustConfirmText = sc.String; } } - else if (SC_Compare("Key")) + else if (sc.Compare("Key")) { - SC_MustGetString(); - skill.Shortcut = tolower(sc_String[0]); + sc.MustGetString(); + skill.Shortcut = tolower(sc.String[0]); } - else if (SC_Compare("TextColor")) + else if (sc.Compare("TextColor")) { - SC_MustGetString(); + sc.MustGetString(); skill.TextColor = '['; - skill.TextColor << sc_String << ']'; + skill.TextColor << sc.String << ']'; } else { - SC_UnGet (); + sc.UnGet (); break; } } diff --git a/src/g_shared/a_decals.cpp b/src/g_shared/a_decals.cpp index d3aee07a65..5e4c3141c8 100644 --- a/src/g_shared/a_decals.cpp +++ b/src/g_shared/a_decals.cpp @@ -61,28 +61,31 @@ IMPLEMENT_CLASS (DImpactDecal) DBaseDecal::DBaseDecal () : DThinker(STAT_DECAL), WallNext(0), WallPrev(0), LeftDistance(0), Z(0), ScaleX(FRACUNIT), ScaleY(FRACUNIT), Alpha(FRACUNIT), - AlphaColor(0), Translation(0), PicNum(0xFFFF), RenderFlags(0), RenderStyle(0) + AlphaColor(0), Translation(0), PicNum(0xFFFF), RenderFlags(0) { + RenderStyle = STYLE_None; } DBaseDecal::DBaseDecal (fixed_t z) : DThinker(STAT_DECAL), WallNext(0), WallPrev(0), LeftDistance(0), Z(z), ScaleX(FRACUNIT), ScaleY(FRACUNIT), Alpha(FRACUNIT), - AlphaColor(0), Translation(0), PicNum(0xFFFF), RenderFlags(0), RenderStyle(0) + AlphaColor(0), Translation(0), PicNum(0xFFFF), RenderFlags(0) { + RenderStyle = STYLE_None; } DBaseDecal::DBaseDecal (int statnum, fixed_t z) : DThinker(statnum), WallNext(0), WallPrev(0), LeftDistance(0), Z(z), ScaleX(FRACUNIT), ScaleY(FRACUNIT), Alpha(FRACUNIT), - AlphaColor(0), Translation(0), PicNum(0xFFFF), RenderFlags(0), RenderStyle(0) + AlphaColor(0), Translation(0), PicNum(0xFFFF), RenderFlags(0) { + RenderStyle = STYLE_None; } DBaseDecal::DBaseDecal (const AActor *basis) : DThinker(STAT_DECAL), WallNext(0), WallPrev(0), LeftDistance(0), Z(basis->z), ScaleX(basis->scaleX), ScaleY(basis->scaleY), - Alpha(basis->alpha), AlphaColor(basis->alphacolor), Translation(basis->Translation), PicNum(basis->picnum), + Alpha(basis->alpha), AlphaColor(basis->fillcolor), Translation(basis->Translation), PicNum(basis->picnum), RenderFlags(basis->renderflags), RenderStyle(basis->RenderStyle) { } diff --git a/src/g_shared/a_keys.cpp b/src/g_shared/a_keys.cpp index 76f361ea71..5b280db3ca 100644 --- a/src/g_shared/a_keys.cpp +++ b/src/g_shared/a_keys.cpp @@ -101,7 +101,7 @@ static const char * keywords_lock[]={ // //=========================================================================== -static void AddOneKey(Keygroup * keygroup, const PClass * mi) +static void AddOneKey(Keygroup *keygroup, const PClass *mi, FScanner &sc) { if (mi) { @@ -123,12 +123,12 @@ static void AddOneKey(Keygroup * keygroup, const PClass * mi) } else { - SC_ScriptError("'%s' is not an inventory item", sc_String); + sc.ScriptError("'%s' is not an inventory item", sc.String); } } else { - SC_ScriptError("Unknown item '%s'", sc_String); + sc.ScriptError("Unknown item '%s'", sc.String); } } @@ -138,20 +138,20 @@ static void AddOneKey(Keygroup * keygroup, const PClass * mi) // //=========================================================================== -static Keygroup * ParseKeygroup() +static Keygroup * ParseKeygroup(FScanner &sc) { Keygroup * keygroup; const PClass * mi; - SC_MustGetStringName("{"); - keygroup=new Keygroup; - while (!SC_CheckString("}")) + sc.MustGetStringName("{"); + keygroup = new Keygroup; + while (!sc.CheckString("}")) { - SC_MustGetString(); - mi=PClass::FindClass(sc_String); - AddOneKey(keygroup, mi); + sc.MustGetString(); + mi = PClass::FindClass(sc.String); + AddOneKey(keygroup, mi, sc); } - if (keygroup->anykeylist.Size()==0) + if (keygroup->anykeylist.Size() == 0) { delete keygroup; return NULL; @@ -182,7 +182,7 @@ static void PrintMessage (const char *str) // //=========================================================================== -static void ParseLock() +static void ParseLock(FScanner &sc) { int i,r,g,b; int keynum; @@ -191,84 +191,90 @@ static void ParseLock() Keygroup * keygroup; const PClass * mi; - SC_MustGetNumber(); - keynum=sc_Number; + sc.MustGetNumber(); + keynum = sc.Number; - SC_MustGetString(); - if (SC_Compare("DOOM")) + sc.MustGetString(); + if (sc.Compare("DOOM")) { if (gameinfo.gametype != GAME_Doom) keynum=-1; } - else if (SC_Compare("HERETIC")) + else if (sc.Compare("HERETIC")) { if (gameinfo.gametype != GAME_Heretic) keynum=-1; } - else if (SC_Compare("HEXEN")) + else if (sc.Compare("HEXEN")) { if (gameinfo.gametype != GAME_Hexen) keynum=-1; } - else if (SC_Compare("STRIFE")) + else if (sc.Compare("STRIFE")) { if (gameinfo.gametype != GAME_Strife) keynum=-1; } - else SC_UnGet(); + else sc.UnGet(); - ignorekey=true; - if (keynum>0 && keynum<255) + ignorekey = true; + if (keynum > 0 && keynum < 255) { - lock=new Lock; - if (locks[keynum]) delete locks[keynum]; - locks[keynum]=lock; + lock = new Lock; + if (locks[keynum]) + { + delete locks[keynum]; + } + locks[keynum] = lock; locks[keynum]->locksound = S_FindSound("misc/keytry"); ignorekey=false; } - else if (keynum!=-1) + else if (keynum != -1) { - SC_ScriptError("Lock index %d out of range", keynum); + sc.ScriptError("Lock index %d out of range", keynum); } - SC_MustGetStringName("{"); - while (!SC_CheckString("}")) + sc.MustGetStringName("{"); + while (!sc.CheckString("}")) { - SC_MustGetString(); - switch(i=SC_MatchString(keywords_lock)) + sc.MustGetString(); + switch(i = sc.MatchString(keywords_lock)) { case 0: // Any - keygroup=ParseKeygroup(); - if (keygroup) lock->keylist.Push(keygroup); + keygroup = ParseKeygroup(sc); + if (keygroup) + { + lock->keylist.Push(keygroup); + } break; case 1: // message - SC_MustGetString(); - lock->message=copystring(sc_String); + sc.MustGetString(); + lock->message = copystring(sc.String); break; case 2: // remotemsg - SC_MustGetString(); - lock->remotemsg=copystring(sc_String); + sc.MustGetString(); + lock->remotemsg = copystring(sc.String); break; case 3: // mapcolor - SC_MustGetNumber(); - r=sc_Number; - SC_MustGetNumber(); - g=sc_Number; - SC_MustGetNumber(); - b=sc_Number; - lock->rgb=MAKERGB(r,g,b); + sc.MustGetNumber(); + r = sc.Number; + sc.MustGetNumber(); + g = sc.Number; + sc.MustGetNumber(); + b = sc.Number; + lock->rgb = MAKERGB(r,g,b); break; case 4: // locksound - SC_MustGetString(); - lock->locksound = S_FindSound(sc_String); + sc.MustGetString(); + lock->locksound = S_FindSound(sc.String); break; default: - mi=PClass::FindClass(sc_String); + mi = PClass::FindClass(sc.String); if (mi) { - keygroup=new Keygroup; - AddOneKey(keygroup, mi); + keygroup = new Keygroup; + AddOneKey(keygroup, mi, sc); if (keygroup) { keygroup->anykeylist.ShrinkToFit(); @@ -279,8 +285,14 @@ static void ParseLock() } } // copy the messages if the other one does not exist - if (!lock->remotemsg && lock->message) lock->remotemsg = copystring(lock->message); - if (!lock->message && lock->remotemsg) lock->message = copystring(lock->remotemsg); + if (!lock->remotemsg && lock->message) + { + lock->remotemsg = copystring(lock->message); + } + if (!lock->message && lock->remotemsg) + { + lock->message = copystring(lock->remotemsg); + } lock->keylist.ShrinkToFit(); } @@ -332,24 +344,26 @@ void P_InitKeyMessages() ClearLocks(); while ((lump = Wads.FindLump ("LOCKDEFS", &lastlump)) != -1) { - SC_OpenLumpNum (lump, "LOCKDEFS"); - while (SC_GetString ()) + FScanner sc(lump, "LOCKDEFS"); + while (sc.GetString ()) { - if (SC_Compare("LOCK")) + if (sc.Compare("LOCK")) { - ParseLock(); + ParseLock(sc); } - else if (SC_Compare("CLEARLOCKS")) + else if (sc.Compare("CLEARLOCKS")) { - // clear all existing lock defintions and key numbers + // clear all existing lock definitions and key numbers ClearLocks(); } - else - SC_ScriptError("Unknown command %s in LockDef", sc_String); + else + { + sc.ScriptError("Unknown command %s in LockDef", sc.String); + } } - SC_Close(); + sc.Close(); } - keysdone=true; + keysdone = true; } //=========================================================================== diff --git a/src/g_shared/a_sharedglobal.h b/src/g_shared/a_sharedglobal.h index 17c1c01aca..d89bbe9040 100644 --- a/src/g_shared/a_sharedglobal.h +++ b/src/g_shared/a_sharedglobal.h @@ -51,7 +51,7 @@ public: WORD Translation; WORD PicNum; DWORD RenderFlags; - BYTE RenderStyle; + FRenderStyle RenderStyle; protected: virtual DBaseDecal *CloneSelf (const FDecalTemplate *tpl, fixed_t x, fixed_t y, fixed_t z, side_s *wall) const; diff --git a/src/g_shared/sbarinfo.cpp b/src/g_shared/sbarinfo.cpp index 17274ac658..a57a11afe3 100644 --- a/src/g_shared/sbarinfo.cpp +++ b/src/g_shared/sbarinfo.cpp @@ -198,169 +198,165 @@ void FreeSBarInfoScript() //Laz Bar Script Reader void SBarInfo::ParseSBarInfo(int lump) { + FScanner sc(lump, Wads.GetLumpFullName(lump)); gameType = GAME_Any; - SC_OpenLumpNum(lump, Wads.GetLumpFullName(lump)); - SC_SetCMode(true); - while(SC_CheckToken(TK_Identifier) || SC_CheckToken(TK_Include)) + sc.SetCMode(true); + while(sc.CheckToken(TK_Identifier) || sc.CheckToken(TK_Include)) { - if(sc_TokenType == TK_Include) + if(sc.TokenType == TK_Include) { - SC_MustGetToken(TK_StringConst); - int lump = Wads.CheckNumForFullName(sc_String); //zip/pk3 + sc.MustGetToken(TK_StringConst); + int lump = Wads.CheckNumForFullName(sc.String); //zip/pk3 //Do a normal wad lookup. - if (lump==-1 && strlen(sc_String) <= 8 && !strchr(sc_String, '/')) - lump = Wads.CheckNumForName(sc_String); - if (lump==-1) - SC_ScriptError("Lump '%s' not found", sc_String); - SC_SaveScriptState(); + if (lump == -1 && sc.StringLen <= 8 && !strchr(sc.String, '/')) + lump = Wads.CheckNumForName(sc.String); + if (lump == -1) + sc.ScriptError("Lump '%s' not found", sc.String); ParseSBarInfo(lump); - SC_RestoreScriptState(); continue; } - switch(SC_MustMatchString(SBarInfoTopLevel)) + switch(sc.MustMatchString(SBarInfoTopLevel)) { case SBARINFO_BASE: - SC_MustGetToken(TK_Identifier); - if(SC_Compare("Doom")) + sc.MustGetToken(TK_Identifier); + if(sc.Compare("Doom")) gameType = GAME_Doom; - else if(SC_Compare("Heretic")) + else if(sc.Compare("Heretic")) gameType = GAME_Heretic; - else if(SC_Compare("Hexen")) + else if(sc.Compare("Hexen")) gameType = GAME_Hexen; - else if(SC_Compare("Strife")) + else if(sc.Compare("Strife")) gameType = GAME_Strife; - else if(SC_Compare("None")) + else if(sc.Compare("None")) gameType = GAME_Any; else - SC_ScriptError("Bad game name: %s", sc_String); - SC_MustGetToken(';'); + sc.ScriptError("Bad game name: %s", sc.String); + sc.MustGetToken(';'); break; case SBARINFO_HEIGHT: - SC_MustGetToken(TK_IntConst); - this->height = sc_Number; - SC_MustGetToken(';'); + sc.MustGetToken(TK_IntConst); + this->height = sc.Number; + sc.MustGetToken(';'); break; case SBARINFO_INTERPOLATEHEALTH: //mimics heretics interpolated health values. - if(SC_CheckToken(TK_True)) + if(sc.CheckToken(TK_True)) { interpolateHealth = true; } else { - SC_TokenMustBe(TK_False); + sc.TokenMustBe(TK_False); interpolateHealth = false; } - if(SC_CheckToken(',')) //speed param + if(sc.CheckToken(',')) //speed param { - SC_MustGetToken(TK_IntConst); - this->interpolationSpeed = sc_Number; + sc.MustGetToken(TK_IntConst); + this->interpolationSpeed = sc.Number; } - SC_MustGetToken(';'); + sc.MustGetToken(';'); break; case SBARINFO_STATUSBAR: { - SC_MustGetToken(TK_Identifier); - int barNum = SC_MustMatchString(StatusBars); - while(SC_CheckToken(',')) + sc.MustGetToken(TK_Identifier); + int barNum = sc.MustMatchString(StatusBars); + while(sc.CheckToken(',')) { - SC_MustGetToken(TK_Identifier); - if(SC_Compare("forcescaled")) + sc.MustGetToken(TK_Identifier); + if(sc.Compare("forcescaled")) { this->huds[barNum].forceScaled = true; } else { - SC_ScriptError("Unkown flag '%s'.", sc_String); + sc.ScriptError("Unkown flag '%s'.", sc.String); } } - SC_MustGetToken('{'); + sc.MustGetToken('{'); if(barNum == STBAR_AUTOMAP) { automapbar = true; } - ParseSBarInfoBlock(this->huds[barNum]); + ParseSBarInfoBlock(sc, this->huds[barNum]); break; } } } - SC_SetCMode(false); - SC_Close(); } -void SBarInfo::ParseSBarInfoBlock(SBarInfoBlock &block) +void SBarInfo::ParseSBarInfoBlock(FScanner &sc, SBarInfoBlock &block) { - while(SC_CheckToken(TK_Identifier)) + while(sc.CheckToken(TK_Identifier)) { SBarInfoCommand cmd; - switch(cmd.type = SC_MustMatchString(SBarInfoRoutineLevel)) + switch(cmd.type = sc.MustMatchString(SBarInfoRoutineLevel)) { case SBARINFO_DRAWSWITCHABLEIMAGE: - SC_MustGetToken(TK_Identifier); - if(SC_Compare("weaponslot")) + sc.MustGetToken(TK_Identifier); + if(sc.Compare("weaponslot")) { cmd.flags = DRAWIMAGE_WEAPONSLOT; - SC_MustGetToken(TK_IntConst); - cmd.value = sc_Number; + sc.MustGetToken(TK_IntConst); + cmd.value = sc.Number; } - else if(SC_Compare("invulnerable")) + else if(sc.Compare("invulnerable")) { cmd.flags = DRAWIMAGE_INVULNERABILITY; } else { - cmd.setString(sc_String, 0); - const PClass* item = PClass::FindClass(sc_String); + cmd.setString(sc, sc.String, 0); + const PClass* item = PClass::FindClass(sc.String); if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of Inventory { - SC_ScriptError("'%s' is not a type of inventory item.", sc_String); + sc.ScriptError("'%s' is not a type of inventory item.", sc.String); } } - if(SC_CheckToken(TK_AndAnd)) + if(sc.CheckToken(TK_AndAnd)) { cmd.flags += DRAWIMAGE_SWITCHABLE_AND; - SC_MustGetToken(TK_Identifier); - cmd.setString(sc_String, 1); - const PClass* item = PClass::FindClass(sc_String); + sc.MustGetToken(TK_Identifier); + cmd.setString(sc, sc.String, 1); + const PClass* item = PClass::FindClass(sc.String); if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of Inventory { - SC_ScriptError("'%s' is not a type of inventory item.", sc_String); + sc.ScriptError("'%s' is not a type of inventory item.", sc.String); } - SC_MustGetToken(','); - SC_MustGetToken(TK_StringConst); - cmd.special = newImage(sc_String); - SC_MustGetToken(','); - SC_MustGetToken(TK_StringConst); - cmd.special2 = newImage(sc_String); - SC_MustGetToken(','); - SC_MustGetToken(TK_StringConst); - cmd.special3 = newImage(sc_String); - SC_MustGetToken(','); + sc.MustGetToken(','); + sc.MustGetToken(TK_StringConst); + cmd.special = newImage(sc.String); + sc.MustGetToken(','); + sc.MustGetToken(TK_StringConst); + cmd.special2 = newImage(sc.String); + sc.MustGetToken(','); + sc.MustGetToken(TK_StringConst); + cmd.special3 = newImage(sc.String); + sc.MustGetToken(','); } else { - SC_MustGetToken(','); - SC_MustGetToken(TK_StringConst); - cmd.special = newImage(sc_String); - SC_MustGetToken(','); + sc.MustGetToken(','); + sc.MustGetToken(TK_StringConst); + cmd.special = newImage(sc.String); + sc.MustGetToken(','); } case SBARINFO_DRAWIMAGE: { bool getImage = true; - if(SC_CheckToken(TK_Identifier)) + if(sc.CheckToken(TK_Identifier)) { getImage = false; - if(SC_Compare("playericon")) + if(sc.Compare("playericon")) cmd.flags += DRAWIMAGE_PLAYERICON; - else if(SC_Compare("ammoicon1")) + else if(sc.Compare("ammoicon1")) cmd.flags += DRAWIMAGE_AMMO1; - else if(SC_Compare("ammoicon2")) + else if(sc.Compare("ammoicon2")) cmd.flags += DRAWIMAGE_AMMO2; - else if(SC_Compare("armoricon")) + else if(sc.Compare("armoricon")) cmd.flags += DRAWIMAGE_ARMOR; - else if(SC_Compare("weaponicon")) + else if(sc.Compare("weaponicon")) cmd.flags += DRAWIMAGE_WEAPONICON; - else if(SC_Compare("translatable")) + else if(sc.Compare("translatable")) { cmd.flags += DRAWIMAGE_TRANSLATABLE; getImage = true; @@ -368,531 +364,499 @@ void SBarInfo::ParseSBarInfoBlock(SBarInfoBlock &block) else { cmd.flags += DRAWIMAGE_INVENTORYICON; - const PClass* item = PClass::FindClass(sc_String); + const PClass* item = PClass::FindClass(sc.String); if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of Inventory { - SC_ScriptError("'%s' is not a type of inventory item.", sc_String); + sc.ScriptError("'%s' is not a type of inventory item.", sc.String); } cmd.sprite = ((AInventory *)GetDefaultByType(item))->Icon; } } if(getImage) { - SC_MustGetToken(TK_StringConst); - cmd.sprite = newImage(sc_String); + sc.MustGetToken(TK_StringConst); + cmd.sprite = newImage(sc.String); } - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.x = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.y = sc_Number - (200 - this->height); //the position should be absolute on the screen. - if(SC_CheckToken(',')) + sc.MustGetToken(','); + this->getCoordinates(sc, cmd); + if(sc.CheckToken(',')) { - SC_MustGetToken(TK_Identifier); - if(SC_Compare("center")) + sc.MustGetToken(TK_Identifier); + if(sc.Compare("center")) cmd.flags += DRAWIMAGE_OFFSET_CENTER; else - SC_ScriptError("Expected 'center' got '%s' instead.", sc_String); + sc.ScriptError("Expected 'center' got '%s' instead.", sc.String); } - SC_MustGetToken(';'); + sc.MustGetToken(';'); break; } case SBARINFO_DRAWNUMBER: cmd.special4 = cmd.special3 = -1; - SC_MustGetToken(TK_IntConst); - cmd.special = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_Identifier); - cmd.font = V_GetFont(sc_String); + sc.MustGetToken(TK_IntConst); + cmd.special = sc.Number; + sc.MustGetToken(','); + sc.MustGetToken(TK_Identifier); + cmd.font = V_GetFont(sc.String); if(cmd.font == NULL) - SC_ScriptError("Unknown font '%s'.", sc_String); - SC_MustGetToken(','); - SC_MustGetToken(TK_Identifier); - cmd.translation = this->GetTranslation(sc_String); - SC_MustGetToken(','); - if(SC_CheckToken(TK_IntConst)) + sc.ScriptError("Unknown font '%s'.", sc.String); + sc.MustGetToken(','); + sc.MustGetToken(TK_Identifier); + cmd.translation = this->GetTranslation(sc, sc.String); + sc.MustGetToken(','); + if(sc.CheckToken(TK_IntConst)) { - cmd.value = sc_Number; - SC_MustGetToken(','); + cmd.value = sc.Number; + sc.MustGetToken(','); } else { - SC_MustGetToken(TK_Identifier); - if(SC_Compare("health")) + sc.MustGetToken(TK_Identifier); + if(sc.Compare("health")) cmd.flags = DRAWNUMBER_HEALTH; - else if(SC_Compare("armor")) + else if(sc.Compare("armor")) cmd.flags = DRAWNUMBER_ARMOR; - else if(SC_Compare("ammo1")) + else if(sc.Compare("ammo1")) cmd.flags = DRAWNUMBER_AMMO1; - else if(SC_Compare("ammo2")) + else if(sc.Compare("ammo2")) cmd.flags = DRAWNUMBER_AMMO2; - else if(SC_Compare("ammo")) //request the next string to be an ammo type + else if(sc.Compare("ammo")) //request the next string to be an ammo type { - SC_MustGetToken(TK_Identifier); - cmd.setString(sc_String, 0); + sc.MustGetToken(TK_Identifier); + cmd.setString(sc, sc.String, 0); cmd.flags = DRAWNUMBER_AMMO; - const PClass* ammo = PClass::FindClass(sc_String); + const PClass* ammo = PClass::FindClass(sc.String); if(ammo == NULL || !PClass::FindClass("Ammo")->IsAncestorOf(ammo)) //must be a kind of ammo { - SC_ScriptError("'%s' is not a type of ammo.", sc_String); + sc.ScriptError("'%s' is not a type of ammo.", sc.String); } } - else if(SC_Compare("ammocapacity")) + else if(sc.Compare("ammocapacity")) { - SC_MustGetToken(TK_Identifier); - cmd.setString(sc_String, 0); + sc.MustGetToken(TK_Identifier); + cmd.setString(sc, sc.String, 0); cmd.flags = DRAWNUMBER_AMMOCAPACITY; - const PClass* ammo = PClass::FindClass(sc_String); + const PClass* ammo = PClass::FindClass(sc.String); if(ammo == NULL || !PClass::FindClass("Ammo")->IsAncestorOf(ammo)) //must be a kind of ammo { - SC_ScriptError("'%s' is not a type of ammo.", sc_String); + sc.ScriptError("'%s' is not a type of ammo.", sc.String); } } - else if(SC_Compare("frags")) + else if(sc.Compare("frags")) cmd.flags = DRAWNUMBER_FRAGS; - else if(SC_Compare("kills")) + else if(sc.Compare("kills")) cmd.flags += DRAWNUMBER_KILLS; - else if(SC_Compare("monsters")) + else if(sc.Compare("monsters")) cmd.flags += DRAWNUMBER_MONSTERS; - else if(SC_Compare("items")) + else if(sc.Compare("items")) cmd.flags += DRAWNUMBER_ITEMS; - else if(SC_Compare("totalitems")) + else if(sc.Compare("totalitems")) cmd.flags += DRAWNUMBER_TOTALITEMS; - else if(SC_Compare("secrets")) + else if(sc.Compare("secrets")) cmd.flags += DRAWNUMBER_SECRETS; - else if(SC_Compare("totalsecrets")) + else if(sc.Compare("totalsecrets")) cmd.flags += DRAWNUMBER_TOTALSECRETS; else { cmd.flags = DRAWNUMBER_INVENTORY; - SC_MustGetToken(TK_Identifier); - cmd.setString(sc_String, 0); - const PClass* item = PClass::FindClass(sc_String); + sc.MustGetToken(TK_Identifier); + cmd.setString(sc, sc.String, 0); + const PClass* item = PClass::FindClass(sc.String); if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of ammo { - SC_ScriptError("'%s' is not a type of inventory item.", sc_String); + sc.ScriptError("'%s' is not a type of inventory item.", sc.String); } } - SC_MustGetToken(','); + sc.MustGetToken(','); } - SC_MustGetToken(TK_IntConst); - cmd.x = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.y = sc_Number - (200 - this->height); - if(SC_CheckToken(',')) + this->getCoordinates(sc, cmd); + if(sc.CheckToken(',')) { bool needsComma = false; - if(SC_CheckToken(TK_IntConst)) //font spacing + if(sc.CheckToken(TK_IntConst)) //font spacing { - cmd.special2 = sc_Number; + cmd.special2 = sc.Number; needsComma = true; } - if(!needsComma || SC_CheckToken(',')) //2nd coloring for "low-on" value + if(!needsComma || sc.CheckToken(',')) //2nd coloring for "low-on" value { - SC_MustGetToken(TK_Identifier); - cmd.translation2 = this->GetTranslation(sc_String); - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.special3 = sc_Number; - if(SC_CheckToken(',')) //3rd coloring for "high-on" value + sc.MustGetToken(TK_Identifier); + cmd.translation2 = this->GetTranslation(sc, sc.String); + sc.MustGetToken(','); + sc.MustGetToken(TK_IntConst); + cmd.special3 = sc.Number; + if(sc.CheckToken(',')) //3rd coloring for "high-on" value { - SC_MustGetToken(TK_Identifier); - cmd.translation3 = this->GetTranslation(sc_String); - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.special4 = sc_Number; + sc.MustGetToken(TK_Identifier); + cmd.translation3 = this->GetTranslation(sc, sc.String); + sc.MustGetToken(','); + sc.MustGetToken(TK_IntConst); + cmd.special4 = sc.Number; } } } - SC_MustGetToken(';'); + sc.MustGetToken(';'); break; case SBARINFO_DRAWMUGSHOT: - SC_MustGetToken(TK_StringConst); - cmd.setString(sc_String, 0, 3, true); - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); //accuracy - if(sc_Number < 1 || sc_Number > 9) - SC_ScriptError("Exspected a number between 1 and 9, got %d instead.", sc_Number); - cmd.special = sc_Number; - SC_MustGetToken(','); - while(SC_CheckToken(TK_Identifier)) + sc.MustGetToken(TK_StringConst); + cmd.setString(sc, sc.String, 0, 3, true); + sc.MustGetToken(','); + sc.MustGetToken(TK_IntConst); //accuracy + if(sc.Number < 1 || sc.Number > 9) + sc.ScriptError("Exspected a number between 1 and 9, got %d instead.", sc.Number); + cmd.special = sc.Number; + sc.MustGetToken(','); + while(sc.CheckToken(TK_Identifier)) { - if(SC_Compare("xdeathface")) + if(sc.Compare("xdeathface")) cmd.flags += DRAWMUGSHOT_XDEATHFACE; - else if(SC_Compare("animatedgodmode")) + else if(sc.Compare("animatedgodmode")) cmd.flags += DRAWMUGSHOT_ANIMATEDGODMODE; else - SC_ScriptError("Unknown flag '%s'.", sc_String); - SC_MustGetToken(','); + sc.ScriptError("Unknown flag '%s'.", sc.String); + sc.MustGetToken(','); } - SC_MustGetToken(TK_IntConst); - cmd.x = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.y = sc_Number - (200 - this->height); - if(SC_CheckToken(',')) //hmm I guess we had a numberic flag in there. + this->getCoordinates(sc, cmd); + if(sc.CheckToken(',')) //hmm I guess we had a numberic flag in there. { cmd.flags = cmd.x; cmd.x = cmd.y + (200 - this->height); - SC_MustGetToken(TK_IntConst); - cmd.y = sc_Number - (200 - this->height); + sc.MustGetToken(TK_IntConst); + cmd.y = sc.Number - (200 - this->height); } - SC_MustGetToken(';'); + sc.MustGetToken(';'); break; case SBARINFO_DRAWSELECTEDINVENTORY: { bool alternateonempty = false; while(true) //go until we get a font (non-flag) { - SC_MustGetToken(TK_Identifier); - if(SC_Compare("alternateonempty")) + sc.MustGetToken(TK_Identifier); + if(sc.Compare("alternateonempty")) { alternateonempty = true; cmd.flags += DRAWSELECTEDINVENTORY_ALTERNATEONEMPTY; } - else if(SC_Compare("artiflash")) + else if(sc.Compare("artiflash")) { cmd.flags += DRAWSELECTEDINVENTORY_ARTIFLASH; } - else if(SC_Compare("alwaysshowcounter")) + else if(sc.Compare("alwaysshowcounter")) { cmd.flags += DRAWSELECTEDINVENTORY_ALWAYSSHOWCOUNTER; } else { - cmd.font = V_GetFont(sc_String); + cmd.font = V_GetFont(sc.String); if(cmd.font == NULL) - SC_ScriptError("Unknown font '%s'.", sc_String); - SC_MustGetToken(','); + sc.ScriptError("Unknown font '%s'.", sc.String); + sc.MustGetToken(','); break; } - SC_MustGetToken(','); + sc.MustGetToken(','); } - SC_MustGetToken(TK_IntConst); - cmd.x = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.y = sc_Number - (200 - this->height); + sc.MustGetToken(TK_IntConst); + cmd.x = sc.Number; + sc.MustGetToken(','); + sc.MustGetToken(TK_IntConst); + cmd.y = sc.Number - (200 - this->height); cmd.special2 = cmd.x + 30; cmd.special3 = cmd.y + 24; cmd.translation = CR_GOLD; - if(SC_CheckToken(',')) //more font information + if(sc.CheckToken(',')) //more font information { - SC_MustGetToken(TK_IntConst); - cmd.special2 = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.special3 = sc_Number - (200 - this->height); - if(SC_CheckToken(',')) + sc.MustGetToken(TK_IntConst); + cmd.special2 = sc.Number; + sc.MustGetToken(','); + sc.MustGetToken(TK_IntConst); + cmd.special3 = sc.Number - (200 - this->height); + if(sc.CheckToken(',')) { - SC_MustGetToken(TK_Identifier); - cmd.translation = this->GetTranslation(sc_String); - if(SC_CheckToken(',')) + sc.MustGetToken(TK_Identifier); + cmd.translation = this->GetTranslation(sc, sc.String); + if(sc.CheckToken(',')) { - SC_MustGetToken(TK_IntConst); - cmd.special4 = sc_Number; + sc.MustGetToken(TK_IntConst); + cmd.special4 = sc.Number; } } } if(alternateonempty) { - SC_MustGetToken('{'); - this->ParseSBarInfoBlock(cmd.subBlock); + sc.MustGetToken('{'); + this->ParseSBarInfoBlock(sc, cmd.subBlock); } else { - SC_MustGetToken(';'); + sc.MustGetToken(';'); } break; } case SBARINFO_DRAWINVENTORYBAR: - SC_MustGetToken(TK_Identifier); - if(SC_Compare("Heretic")) + sc.MustGetToken(TK_Identifier); + if(sc.Compare("Heretic")) { cmd.special = GAME_Heretic; } - if(SC_Compare("Doom") || SC_Compare("Heretic")) + if(sc.Compare("Doom") || sc.Compare("Heretic")) { - SC_MustGetToken(','); - while(SC_CheckToken(TK_Identifier)) + sc.MustGetToken(','); + while(sc.CheckToken(TK_Identifier)) { - if(SC_Compare("alwaysshow")) + if(sc.Compare("alwaysshow")) { cmd.flags += DRAWINVENTORYBAR_ALWAYSSHOW; } - else if(SC_Compare("noartibox")) + else if(sc.Compare("noartibox")) { cmd.flags += DRAWINVENTORYBAR_NOARTIBOX; } - else if(SC_Compare("noarrows")) + else if(sc.Compare("noarrows")) { cmd.flags += DRAWINVENTORYBAR_NOARROWS; } - else if(SC_Compare("alwaysshowcounter")) + else if(sc.Compare("alwaysshowcounter")) { cmd.flags += DRAWINVENTORYBAR_ALWAYSSHOWCOUNTER; } else { - SC_ScriptError("Unknown flag '%s'.", sc_String); + sc.ScriptError("Unknown flag '%s'.", sc.String); } - SC_MustGetToken(','); + sc.MustGetToken(','); } - SC_MustGetToken(TK_IntConst); - cmd.value = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_Identifier); - cmd.font = V_GetFont(sc_String); + sc.MustGetToken(TK_IntConst); + cmd.value = sc.Number; + sc.MustGetToken(','); + sc.MustGetToken(TK_Identifier); + cmd.font = V_GetFont(sc.String); if(cmd.font == NULL) - SC_ScriptError("Unknown font '%s'.", sc_String); + sc.ScriptError("Unknown font '%s'.", sc.String); } else { - SC_ScriptError("Unkown style '%s'.", sc_String); + sc.ScriptError("Unkown style '%s'.", sc.String); } - SC_MustGetToken(','); - SC_MustGetNumber(); - cmd.x = sc_Number; - SC_MustGetToken(','); - SC_MustGetNumber(); - cmd.y = sc_Number - (200 - this->height); + sc.MustGetToken(','); + this->getCoordinates(sc, cmd); cmd.special2 = cmd.x + 26; cmd.special3 = cmd.y + 22; cmd.translation = CR_GOLD; - if(SC_CheckToken(',')) //more font information + if(sc.CheckToken(',')) //more font information { - SC_MustGetToken(TK_IntConst); - cmd.special2 = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.special3 = sc_Number - (200 - this->height); - if(SC_CheckToken(',')) + sc.MustGetToken(TK_IntConst); + cmd.special2 = sc.Number; + sc.MustGetToken(','); + sc.MustGetToken(TK_IntConst); + cmd.special3 = sc.Number - (200 - this->height); + if(sc.CheckToken(',')) { - SC_MustGetToken(TK_Identifier); - cmd.translation = this->GetTranslation(sc_String); - if(SC_CheckToken(',')) + sc.MustGetToken(TK_Identifier); + cmd.translation = this->GetTranslation(sc, sc.String); + if(sc.CheckToken(',')) { - SC_MustGetToken(TK_IntConst); - cmd.special4 = sc_Number; + sc.MustGetToken(TK_IntConst); + cmd.special4 = sc.Number; } } } - SC_MustGetToken(';'); + sc.MustGetToken(';'); break; case SBARINFO_DRAWBAR: - SC_MustGetToken(TK_StringConst); - cmd.sprite = newImage(sc_String); - SC_MustGetToken(','); - SC_MustGetToken(TK_StringConst); - cmd.special = newImage(sc_String); - SC_MustGetToken(','); - SC_MustGetToken(TK_Identifier); //yeah, this is the same as drawnumber, there might be a better way to copy it... - if(SC_Compare("health")) + sc.MustGetToken(TK_StringConst); + cmd.sprite = newImage(sc.String); + sc.MustGetToken(','); + sc.MustGetToken(TK_StringConst); + cmd.special = newImage(sc.String); + sc.MustGetToken(','); + sc.MustGetToken(TK_Identifier); //yeah, this is the same as drawnumber, there might be a better way to copy it... + if(sc.Compare("health")) { cmd.flags = DRAWNUMBER_HEALTH; - if(SC_CheckToken(TK_Identifier)) //comparing reference + if(sc.CheckToken(TK_Identifier)) //comparing reference { - cmd.setString(sc_String, 0); - const PClass* item = PClass::FindClass(sc_String); + cmd.setString(sc, sc.String, 0); + const PClass* item = PClass::FindClass(sc.String); if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of inventory { - SC_ScriptError("'%s' is not a type of inventory item.", sc_String); + sc.ScriptError("'%s' is not a type of inventory item.", sc.String); } } else cmd.special2 = DRAWBAR_COMPAREDEFAULTS; } - else if(SC_Compare("armor")) + else if(sc.Compare("armor")) { cmd.flags = DRAWNUMBER_ARMOR; - if(SC_CheckToken(TK_Identifier)) + if(sc.CheckToken(TK_Identifier)) { - cmd.setString(sc_String, 0); - const PClass* item = PClass::FindClass(sc_String); + cmd.setString(sc, sc.String, 0); + const PClass* item = PClass::FindClass(sc.String); if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of inventory { - SC_ScriptError("'%s' is not a type of inventory item.", sc_String); + sc.ScriptError("'%s' is not a type of inventory item.", sc.String); } } else cmd.special2 = DRAWBAR_COMPAREDEFAULTS; } - else if(SC_Compare("ammo1")) + else if(sc.Compare("ammo1")) cmd.flags = DRAWNUMBER_AMMO1; - else if(SC_Compare("ammo2")) + else if(sc.Compare("ammo2")) cmd.flags = DRAWNUMBER_AMMO2; - else if(SC_Compare("ammo")) //request the next string to be an ammo type + else if(sc.Compare("ammo")) //request the next string to be an ammo type { - SC_MustGetToken(TK_Identifier); - cmd.setString(sc_String, 0); + sc.MustGetToken(TK_Identifier); + cmd.setString(sc, sc.String, 0); cmd.flags = DRAWNUMBER_AMMO; - const PClass* ammo = PClass::FindClass(sc_String); + const PClass* ammo = PClass::FindClass(sc.String); if(ammo == NULL || !PClass::FindClass("Ammo")->IsAncestorOf(ammo)) //must be a kind of ammo { - SC_ScriptError("'%s' is not a type of ammo.", sc_String); + sc.ScriptError("'%s' is not a type of ammo.", sc.String); } } - else if(SC_Compare("frags")) + else if(sc.Compare("frags")) cmd.flags = DRAWNUMBER_FRAGS; - else if(SC_Compare("kills")) + else if(sc.Compare("kills")) cmd.flags = DRAWNUMBER_KILLS; - else if(SC_Compare("items")) + else if(sc.Compare("items")) cmd.flags = DRAWNUMBER_ITEMS; - else if(SC_Compare("secrets")) + else if(sc.Compare("secrets")) cmd.flags = DRAWNUMBER_SECRETS; else { cmd.flags = DRAWNUMBER_INVENTORY; - cmd.setString(sc_String, 0); - const PClass* item = PClass::FindClass(sc_String); + cmd.setString(sc, sc.String, 0); + const PClass* item = PClass::FindClass(sc.String); if(item == NULL || !PClass::FindClass("Inventory")->IsAncestorOf(item)) //must be a kind of ammo { - SC_ScriptError("'%s' is not a type of inventory item.", sc_String); + sc.ScriptError("'%s' is not a type of inventory item.", sc.String); } } - SC_MustGetToken(','); - SC_MustGetToken(TK_Identifier); - if(SC_Compare("horizontal")) + sc.MustGetToken(','); + sc.MustGetToken(TK_Identifier); + if(sc.Compare("horizontal")) cmd.special2 += DRAWBAR_HORIZONTAL; - else if(!SC_Compare("vertical")) - SC_ScriptError("Unknown direction '%s'.", sc_String); - SC_MustGetToken(','); - if(SC_CheckToken(TK_Identifier)) + else if(!sc.Compare("vertical")) + sc.ScriptError("Unknown direction '%s'.", sc.String); + sc.MustGetToken(','); + if(sc.CheckToken(TK_Identifier)) { - if(!SC_Compare("reverse")) + if(!sc.Compare("reverse")) { - SC_ScriptError("Exspected 'reverse', got '%s' instead.", sc_String); + sc.ScriptError("Exspected 'reverse', got '%s' instead.", sc.String); } cmd.special2 += DRAWBAR_REVERSE; - SC_MustGetToken(','); + sc.MustGetToken(','); } - SC_MustGetToken(TK_IntConst); - cmd.x = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.y = sc_Number - (200 - this->height); - SC_MustGetToken(';'); + this->getCoordinates(sc, cmd); + sc.MustGetToken(';'); break; case SBARINFO_DRAWGEM: - while(SC_CheckToken(TK_Identifier)) + while(sc.CheckToken(TK_Identifier)) { - if(SC_Compare("wiggle")) + if(sc.Compare("wiggle")) cmd.flags += DRAWGEM_WIGGLE; - else if(SC_Compare("translatable")) + else if(sc.Compare("translatable")) cmd.flags += DRAWGEM_TRANSLATABLE; else - SC_ScriptError("Unkown drawgem flag '%s'.", sc_String); - SC_MustGetToken(','); + sc.ScriptError("Unkown drawgem flag '%s'.", sc.String); + sc.MustGetToken(','); } - SC_MustGetToken(TK_StringConst); //chain - cmd.special = newImage(sc_String); - SC_MustGetToken(','); - SC_MustGetToken(TK_StringConst); //gem - cmd.sprite = newImage(sc_String); - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - if(sc_Number < 0) - SC_ScriptError("Left padding must be a positive number."); - cmd.special2 = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - if(sc_Number < 0) - SC_ScriptError("Right padding must be a positive number."); - cmd.special3 = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - if(sc_Number < 0) - SC_ScriptError("Chain size must be a positive number."); - cmd.special4 = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.x = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.y = sc_Number - (200 - this->height); - SC_MustGetToken(';'); + sc.MustGetToken(TK_StringConst); //chain + cmd.special = newImage(sc.String); + sc.MustGetToken(','); + sc.MustGetToken(TK_StringConst); //gem + cmd.sprite = newImage(sc.String); + sc.MustGetToken(','); + sc.MustGetToken(TK_IntConst); + if(sc.Number < 0) + sc.ScriptError("Left padding must be a positive number."); + cmd.special2 = sc.Number; + sc.MustGetToken(','); + sc.MustGetToken(TK_IntConst); + if(sc.Number < 0) + sc.ScriptError("Right padding must be a positive number."); + cmd.special3 = sc.Number; + sc.MustGetToken(','); + sc.MustGetToken(TK_IntConst); + if(sc.Number < 0) + sc.ScriptError("Chain size must be a positive number."); + cmd.special4 = sc.Number; + sc.MustGetToken(','); + this->getCoordinates(sc, cmd); + sc.MustGetToken(';'); break; case SBARINFO_DRAWSHADER: - SC_MustGetToken(TK_IntConst); - cmd.special = sc_Number; - if(sc_Number < 1) - SC_ScriptError("Width must be greater than 1."); - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.special2 = sc_Number; - if(sc_Number < 1) - SC_ScriptError("Height must be greater than 1."); - SC_MustGetToken(','); - SC_MustGetToken(TK_Identifier); - if(SC_Compare("vertical")) + sc.MustGetToken(TK_IntConst); + cmd.special = sc.Number; + if(sc.Number < 1) + sc.ScriptError("Width must be greater than 1."); + sc.MustGetToken(','); + sc.MustGetToken(TK_IntConst); + cmd.special2 = sc.Number; + if(sc.Number < 1) + sc.ScriptError("Height must be greater than 1."); + sc.MustGetToken(','); + sc.MustGetToken(TK_Identifier); + if(sc.Compare("vertical")) cmd.flags += DRAWSHADER_VERTICAL; - else if(!SC_Compare("horizontal")) - SC_ScriptError("Unknown direction '%s'.", sc_String); - SC_MustGetToken(','); - if(SC_CheckToken(TK_Identifier)) + else if(!sc.Compare("horizontal")) + sc.ScriptError("Unknown direction '%s'.", sc.String); + sc.MustGetToken(','); + if(sc.CheckToken(TK_Identifier)) { - if(!SC_Compare("reverse")) + if(!sc.Compare("reverse")) { - SC_ScriptError("Exspected 'reverse', got '%s' instead.", sc_String); + sc.ScriptError("Exspected 'reverse', got '%s' instead.", sc.String); } cmd.flags += DRAWSHADER_REVERSE; - SC_MustGetToken(','); + sc.MustGetToken(','); } - SC_MustGetToken(TK_IntConst); - cmd.x = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.y = sc_Number - (200 - this->height); - SC_MustGetToken(';'); + this->getCoordinates(sc, cmd); + sc.MustGetToken(';'); break; case SBARINFO_DRAWSTRING: - SC_MustGetToken(TK_Identifier); - cmd.font = V_GetFont(sc_String); + sc.MustGetToken(TK_Identifier); + cmd.font = V_GetFont(sc.String); if(cmd.font == NULL) - SC_ScriptError("Unknown font '%s'.", sc_String); - SC_MustGetToken(','); - SC_MustGetToken(TK_Identifier); - cmd.translation = this->GetTranslation(sc_String); - SC_MustGetToken(','); - SC_MustGetToken(TK_StringConst); - cmd.setString(sc_String, 0, -1, false); - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.x = sc_Number; - SC_MustGetToken(','); - SC_MustGetToken(TK_IntConst); - cmd.y = sc_Number - (200 - this->height); - SC_MustGetToken(';'); + sc.ScriptError("Unknown font '%s'.", sc.String); + sc.MustGetToken(','); + sc.MustGetToken(TK_Identifier); + cmd.translation = this->GetTranslation(sc, sc.String); + sc.MustGetToken(','); + sc.MustGetToken(TK_StringConst); + cmd.setString(sc, sc.String, 0, -1, false); + sc.MustGetToken(','); + this->getCoordinates(sc, cmd); + sc.MustGetToken(';'); break; case SBARINFO_GAMEMODE: - while(SC_CheckToken(TK_Identifier)) + while(sc.CheckToken(TK_Identifier)) { - if(SC_Compare("singleplayer")) + if(sc.Compare("singleplayer")) cmd.flags += GAMETYPE_SINGLEPLAYER; - else if(SC_Compare("cooperative")) + else if(sc.Compare("cooperative")) cmd.flags += GAMETYPE_COOPERATIVE; - else if(SC_Compare("deathmatch")) + else if(sc.Compare("deathmatch")) cmd.flags += GAMETYPE_DEATHMATCH; - else if(SC_Compare("teamgame")) + else if(sc.Compare("teamgame")) cmd.flags += GAMETYPE_TEAMGAME; else - SC_ScriptError("Unknown gamemode: %s", sc_String); - if(SC_CheckToken('{')) + sc.ScriptError("Unknown gamemode: %s", sc.String); + if(sc.CheckToken('{')) break; - SC_MustGetToken(','); + sc.MustGetToken(','); } - this->ParseSBarInfoBlock(cmd.subBlock); + this->ParseSBarInfoBlock(sc, cmd.subBlock); break; case SBARINFO_PLAYERCLASS: cmd.special = cmd.special2 = cmd.special3 = -1; - for(int i = 0;i < 3 && SC_CheckToken(TK_Identifier);i++) //up to 3 classes + for(int i = 0;i < 3 && sc.CheckToken(TK_Identifier);i++) //up to 3 classes { bool foundClass = false; for(unsigned int c = 0;c < PlayerClasses.Size();c++) { - if(stricmp(sc_String, PlayerClasses[c].Type->Meta.GetMetaString(APMETA_DisplayName)) == 0) + if(stricmp(sc.String, PlayerClasses[c].Type->Meta.GetMetaString(APMETA_DisplayName)) == 0) { foundClass = true; if(i == 0) @@ -905,18 +869,30 @@ void SBarInfo::ParseSBarInfoBlock(SBarInfoBlock &block) } } if(!foundClass) - SC_ScriptError("Unkown PlayerClass '%s'.", sc_String); - if(SC_CheckToken('{') || i == 2) + sc.ScriptError("Unkown PlayerClass '%s'.", sc.String); + if(sc.CheckToken('{') || i == 2) goto FinishPlayerClass; - SC_MustGetToken(','); + sc.MustGetToken(','); } FinishPlayerClass: - this->ParseSBarInfoBlock(cmd.subBlock); + this->ParseSBarInfoBlock(sc, cmd.subBlock); break; } block.commands.Push(cmd); } - SC_MustGetToken('}'); + sc.MustGetToken('}'); +} + +void SBarInfo::getCoordinates(FScanner &sc, SBarInfoCommand &cmd) +{ + bool negative = false; + negative = sc.CheckToken('-'); + sc.MustGetToken(TK_IntConst); + cmd.x = negative ? -sc.Number : sc.Number; + sc.MustGetToken(','); + negative = sc.CheckToken('-'); + sc.MustGetToken(TK_IntConst); + cmd.y = (negative ? -sc.Number : sc.Number) - (200 - this->height); } int SBarInfo::newImage(const char* patchname) @@ -927,7 +903,7 @@ int SBarInfo::newImage(const char* patchname) } // if(strlen(patchname) > 8) // { -// SC_ScriptError("Graphic names can not be greater then 8 characters long."); +// sc.ScriptError("Graphic names can not be greater then 8 characters long."); // } for(unsigned int i = 0;i < this->Images.Size();i++) //did we already load it? { @@ -940,7 +916,7 @@ int SBarInfo::newImage(const char* patchname) } //converts a string into a tranlation. -EColorRange SBarInfo::GetTranslation(char* translation) +EColorRange SBarInfo::GetTranslation(FScanner &sc, char* translation) { EColorRange returnVal = CR_UNTRANSLATED; FString namedTranslation; //we must send in "[translation]" @@ -949,7 +925,7 @@ EColorRange SBarInfo::GetTranslation(char* translation) trans_ptr = (const BYTE *)(&namedTranslation[0]); if((returnVal = V_ParseFontColor(trans_ptr, CR_UNTRANSLATED, CR_UNTRANSLATED)) == CR_UNDEFINED) { - SC_ScriptError("Missing definition for color %s.", translation); + sc.ScriptError("Missing definition for color %s.", translation); } return returnVal; } @@ -981,13 +957,13 @@ SBarInfo::~SBarInfo() } } -void SBarInfoCommand::setString(const char* source, int strnum, int maxlength, bool exact) +void SBarInfoCommand::setString(FScanner &sc, const char* source, int strnum, int maxlength, bool exact) { if(!exact) { if(maxlength != -1 && strlen(source) > (unsigned int) maxlength) { - SC_ScriptError("%s is greater than %d characters.", source, maxlength); + sc.ScriptError("%s is greater than %d characters.", source, maxlength); return; } } @@ -995,7 +971,7 @@ void SBarInfoCommand::setString(const char* source, int strnum, int maxlength, b { if(maxlength != -1 && strlen(source) != (unsigned int) maxlength) { - SC_ScriptError("%s must be %d characters.", source, maxlength); + sc.ScriptError("%s must be %d characters.", source, maxlength); return; } } @@ -1854,12 +1830,14 @@ private: } if(cmd.bar != NULL) delete cmd.bar; - if(cmd.special != -1) - cmd.bar = new FBarTexture(Images[cmd.sprite], Images[cmd.special], value, horizontal, reverse); - else - cmd.bar = new FBarTexture(Images[cmd.sprite], NULL, value, horizontal, reverse); - DrawImage(cmd.bar, cmd.x, cmd.y); - //delete cmd.bar; + if (Images[cmd.sprite] != NULL) + { + if(cmd.special != -1) + cmd.bar = new FBarTexture(Images[cmd.sprite], Images[cmd.special], value, horizontal, reverse); + else + cmd.bar = new FBarTexture(Images[cmd.sprite], NULL, value, horizontal, reverse); + DrawImage(cmd.bar, cmd.x, cmd.y); + } break; } case SBARINFO_DRAWGEM: @@ -1973,8 +1951,8 @@ private: void DrawNumber(int num, int len, int x, int y, EColorRange translation, int spacing=0) { FString value; - int maxval = (int) pow(10., len); - num = clamp(num, -maxval+1, maxval-1); + int maxval = (int) ceil(pow(10., len))-1; + num = clamp(num, -maxval, maxval); value.Format("%d", num); x -= int(drawingFont->StringWidth(value)+(spacing * value.Len())); DrawString(value, x, y, translation, spacing); diff --git a/src/g_shared/sbarinfo.h b/src/g_shared/sbarinfo.h index 47d4a99156..29de2e40d5 100644 --- a/src/g_shared/sbarinfo.h +++ b/src/g_shared/sbarinfo.h @@ -5,6 +5,7 @@ #include "v_collection.h" class FBarTexture; +class FScanner; struct SBarInfoCommand; //we need to be able to use this before it is defined. @@ -19,7 +20,7 @@ struct SBarInfoCommand { SBarInfoCommand(); ~SBarInfoCommand(); - void setString(const char* source, int strnum, int maxlength=-1, bool exact=false); + void setString(FScanner &sc, const char* source, int strnum, int maxlength=-1, bool exact=false); int type; int special; @@ -52,10 +53,11 @@ struct SBarInfo int GetGameType() { return gameType; } void ParseSBarInfo(int lump); - void ParseSBarInfoBlock(SBarInfoBlock &block); + void ParseSBarInfoBlock(FScanner &sc, SBarInfoBlock &block); + void getCoordinates(FScanner &sc, SBarInfoCommand &cmd); //retrieves the next two arguments as x and y. int newImage(const char* patchname); void Init(); - EColorRange GetTranslation(char* translation); + EColorRange GetTranslation(FScanner &sc, char* translation); SBarInfo(); SBarInfo(int lumpnum); ~SBarInfo(); diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index cfd7fee6a4..ae113daab5 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -928,42 +928,41 @@ void HUD_InitHud() while ((lump = Wads.FindLump ("ALTHUDCF", &lastlump)) != -1) { - SC_OpenLumpNum(lump, "ALTHUDCF"); - while (SC_GetString()) + FScanner sc(lump, "ALTHUDCF"); + while (sc.GetString()) { - if (SC_Compare("Health")) + if (sc.Compare("Health")) { - SC_MustGetString(); - int tex = TexMan.AddPatch(sc_String); - if (tex<=0) tex = TexMan.AddPatch(sc_String, ns_sprites); + sc.MustGetString(); + int tex = TexMan.AddPatch(sc.String); + if (tex<=0) tex = TexMan.AddPatch(sc.String, ns_sprites); if (tex>0) healthpic = TexMan[tex]; } else { - const PClass * ti = PClass::FindClass(sc_String); + const PClass * ti = PClass::FindClass(sc.String); if (!ti) { - Printf("Unknown item class '%s' in ALTHUDCF\n", sc_String); + Printf("Unknown item class '%s' in ALTHUDCF\n", sc.String); } else if (!ti->IsDescendantOf(RUNTIME_CLASS(AInventory))) { - Printf("Invalid item class '%s' in ALTHUDCF\n", sc_String); + Printf("Invalid item class '%s' in ALTHUDCF\n", sc.String); ti=NULL; } - SC_MustGetString(); + sc.MustGetString(); int tex=0; - if (!SC_Compare("0") && !SC_Compare("NULL") && !SC_Compare("")) + if (!sc.Compare("0") && !sc.Compare("NULL") && !sc.Compare("")) { - tex = TexMan.AddPatch(sc_String); - if (tex<=0) tex = TexMan.AddPatch(sc_String, ns_sprites); + tex = TexMan.AddPatch(sc.String); + if (tex<=0) tex = TexMan.AddPatch(sc.String, ns_sprites); } else tex=-1; if (ti) const_cast(ti)->Meta.SetMetaInt(HUMETA_AltIcon, tex); } } - SC_Close(); } } diff --git a/src/g_strife/a_acolyte.cpp b/src/g_strife/a_acolyte.cpp index 0d7fa4e4ec..87bb3591cd 100644 --- a/src/g_strife/a_acolyte.cpp +++ b/src/g_strife/a_acolyte.cpp @@ -423,7 +423,7 @@ void A_AcolyteBits (AActor *self) } else { - self->RenderStyle = STYLE_None; + self->RenderStyle.BlendOp = STYLEOP_None; } } } diff --git a/src/g_strife/a_rebels.cpp b/src/g_strife/a_rebels.cpp index 816b4d54ec..cc3a6dcdb0 100644 --- a/src/g_strife/a_rebels.cpp +++ b/src/g_strife/a_rebels.cpp @@ -290,7 +290,7 @@ void A_Beacon (AActor *self) self->flags &= ~MF_SPECIAL; static_cast(self)->DropTime = 0; // Set up the new rebel. - rebel->threshold = 100; + rebel->threshold = BASETHRESHOLD; rebel->target = NULL; rebel->flags4 |= MF4_INCOMBAT; rebel->LastHeard = owner; // Make sure the rebels look for targets diff --git a/src/hu_scores.cpp b/src/hu_scores.cpp index f9d693de3b..fe8a553a6b 100644 --- a/src/hu_scores.cpp +++ b/src/hu_scores.cpp @@ -180,7 +180,7 @@ static void HU_DoDrawScores (player_t *player, player_t *sortedplayers[MAXPLAYER } if (teamplay && deathmatch) - gamestate == GS_INTERMISSION ? y = SCREENHEIGHT / 3.5 : y = SCREENHEIGHT / 16; + gamestate == GS_INTERMISSION ? y = SCREENHEIGHT * 7 / 2 : y = SCREENHEIGHT / 16; else gamestate == GS_INTERMISSION ? y = SCREENHEIGHT / 4 : y = SCREENHEIGHT / 16; @@ -216,7 +216,7 @@ static void HU_DoDrawScores (player_t *player, player_t *sortedplayers[MAXPLAYER sprintf (score, "%d", teams[i].score); screen->SetFont (BigFont); - screen->DrawText (teams[i].GetTextColor (), scorexwidth, gamestate == GS_INTERMISSION ? y / 1.25 : y / 2, score, + screen->DrawText (teams[i].GetTextColor (), scorexwidth, gamestate == GS_INTERMISSION ? y * 4 / 5 : y / 2, score, DTA_CleanNoMove, true, TAG_DONE); scorexwidth += SCREENWIDTH / 8; @@ -337,7 +337,7 @@ static void HU_DrawPlayer (player_t *player, bool highlight, int x, int y, int h if (player->mo->ScoreIcon > 0) { - screen->DrawTexture (TexMan[player->mo->ScoreIcon], SCREENWIDTH / 2.25, y, + screen->DrawTexture (TexMan[player->mo->ScoreIcon], SCREENWIDTH * 4 / 9, y, DTA_CleanNoMove, true, TAG_DONE); } } diff --git a/src/infodefaults.cpp b/src/infodefaults.cpp index aa922e1e81..eb8ca25634 100644 --- a/src/infodefaults.cpp +++ b/src/infodefaults.cpp @@ -215,7 +215,7 @@ static void ApplyActorDefault (int defnum, const char *datastr, int dataint) case ADEF_Flags4Clear: actor->flags4 &= ~dataint; break; case ADEF_Flags5Clear: actor->flags5 &= ~dataint; break; case ADEF_Alpha: actor->alpha = dataint; break; - case ADEF_RenderStyle: actor->RenderStyle = dataint; break; + case ADEF_RenderStyle: actor->RenderStyle = ERenderStyle(dataint); break; case ADEF_RenderFlags: actor->renderflags = dataint; break; case ADEF_Translation: actor->Translation = dataint; break; case ADEF_MinMissileChance: actor->MinMissileChance = dataint; break; diff --git a/src/m_options.cpp b/src/m_options.cpp index b89c6ce020..c2f6b4b37b 100644 --- a/src/m_options.cpp +++ b/src/m_options.cpp @@ -3338,12 +3338,12 @@ void InitCrosshairsList() while ((lump = Wads.FindLump("XHAIRS", &lastlump)) != -1) { - SC_OpenLumpNum(lump, "XHAIRS"); - while (SC_GetNumber()) + FScanner sc(lump, "XHAIRS"); + while (sc.GetNumber()) { - value.value = float(sc_Number); - SC_MustGetString(); - value.name = sc_String; + value.value = float(sc.Number); + sc.MustGetString(); + value.name = sc.String; if (value.value != 0) { // Check if it already exists. If not, add it. unsigned int i; @@ -3365,7 +3365,6 @@ void InitCrosshairsList() } } } - SC_Close(); } VideoItems[CROSSHAIR_INDEX].b.numvalues = float(Crosshairs.Size()); VideoItems[CROSSHAIR_INDEX].e.valuestrings = &Crosshairs[0]; diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 40ed4629a3..0d58a001d9 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -555,20 +555,19 @@ void FBehavior::StaticLoadDefaultModules () while ((lump = Wads.FindLump ("LOADACS", &lastlump)) != -1) { - SC_OpenLumpNum (lump, "LOADACS"); - while (SC_GetString()) + FScanner sc(lump, "LOADACS"); + while (sc.GetString()) { - int acslump = Wads.CheckNumForName (sc_String, ns_acslibrary); + int acslump = Wads.CheckNumForName (sc.String, ns_acslibrary); if (acslump >= 0) { StaticLoadModule (acslump); } else { - Printf ("Could not find autoloaded ACS library %s\n", sc_String); + Printf ("Could not find autoloaded ACS library %s\n", sc.String); } } - SC_Close (); } } @@ -2200,7 +2199,7 @@ void DLevelScript::DoSetActorProperty (AActor *actor, int property, int value) break; case APROP_RenderStyle: - actor->RenderStyle = value; + actor->RenderStyle = ERenderStyle(value); break; case APROP_Ambush: @@ -2290,7 +2289,16 @@ int DLevelScript::GetActorProperty (int tid, int property) case APROP_Speed: return actor->Speed; case APROP_Damage: return actor->Damage; // Should this call GetMissileDamage() instead? case APROP_Alpha: return actor->alpha; - case APROP_RenderStyle: return actor->RenderStyle; + case APROP_RenderStyle: for (int style = STYLE_None; style < STYLE_Count; ++style) + { // Check for a legacy render style that matches. + if (LegacyRenderStyles[style] == actor->RenderStyle) + { + return style; + } + } + // The current render style isn't expressable as a legacy style, + // so pretends it's normal. + return STYLE_Normal; case APROP_Gravity: return actor->gravity; case APROP_Ambush: return !!(actor->flags & MF_AMBUSH); case APROP_ChaseGoal: return !!(actor->flags5 & MF5_CHASEGOAL); diff --git a/src/p_doors.cpp b/src/p_doors.cpp index 7a2562e994..2fce22ba69 100644 --- a/src/p_doors.cpp +++ b/src/p_doors.cpp @@ -802,7 +802,7 @@ bool EV_SlidingDoor (line_t *line, AActor *actor, int tag, int speed, int delay) return rtn; } -void P_ParseAnimatedDoor() +void P_ParseAnimatedDoor(FScanner &sc) { const BITFIELD texflags = FTextureManager::TEXMAN_Overridable | FTextureManager::TEXMAN_TryAny; FDoorAnimation anim; @@ -810,8 +810,8 @@ void P_ParseAnimatedDoor() bool error = false; int v; - SC_MustGetString(); - anim.BaseTexture = TexMan.CheckForTexture (sc_String, FTexture::TEX_Wall, texflags); + sc.MustGetString(); + anim.BaseTexture = TexMan.CheckForTexture (sc.String, FTexture::TEX_Wall, texflags); anim.OpenSound = NULL; anim.CloseSound = NULL; @@ -820,38 +820,38 @@ void P_ParseAnimatedDoor() error = true; } - while (SC_GetString ()) + while (sc.GetString ()) { - if (SC_Compare ("opensound")) + if (sc.Compare ("opensound")) { - SC_MustGetString (); - anim.OpenSound = copystring (sc_String); + sc.MustGetString (); + anim.OpenSound = copystring (sc.String); } - else if (SC_Compare ("closesound")) + else if (sc.Compare ("closesound")) { - SC_MustGetString (); - anim.CloseSound = copystring (sc_String); + sc.MustGetString (); + anim.CloseSound = copystring (sc.String); } - else if (SC_Compare ("pic")) + else if (sc.Compare ("pic")) { - SC_MustGetString (); - if (IsNum (sc_String)) + sc.MustGetString (); + if (IsNum (sc.String)) { - v = atoi(sc_String) + anim.BaseTexture -1; + v = atoi(sc.String) + anim.BaseTexture -1; } else { - v = TexMan.CheckForTexture (sc_String, FTexture::TEX_Wall, texflags); + v = TexMan.CheckForTexture (sc.String, FTexture::TEX_Wall, texflags); if (v == -1 && anim.BaseTexture >= 0 && !error) { - SC_ScriptError ("Unknown texture %s", sc_String); + sc.ScriptError ("Unknown texture %s", sc.String); } frames.Push (v); } } else { - SC_UnGet (); + sc.UnGet (); break; } } diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index a07fd1a504..bad0bcae83 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -1664,8 +1664,6 @@ void A_Look (AActor *actor) //========================================================================== void A_Wander (AActor *self) { - int delta; - // [RH] Strife probably clears this flag somewhere, but I couldn't find where. // This seems as good a place as any. self->flags4 &= ~MF4_INCOMBAT; @@ -1673,9 +1671,9 @@ void A_Wander (AActor *self) if (self->flags4 & MF4_STANDSTILL) return; - if (self->threshold != 0) + if (self->reactiontime != 0) { - self->threshold--; + self->reactiontime--; return; } @@ -1683,7 +1681,7 @@ void A_Wander (AActor *self) if (self->movedir < DI_NODIR) { self->angle &= (angle_t)(7<<29); - delta = self->angle - (self->movedir << 29); + int delta = self->angle - (self->movedir << 29); if (delta > 0) { self->angle -= ANG90/2; diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index cb5572463f..197b3566f9 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -245,7 +245,7 @@ void AActor::Serialize (FArchive &arc) } arc << effects << alpha - << alphacolor + << fillcolor << pitch << roll << Sector @@ -387,7 +387,7 @@ void AActor::Serialize (FArchive &arc) touching_sectorlist = NULL; LinkToWorld (Sector); AddToHash (); - SetShade (alphacolor); + SetShade (fillcolor); if (player) { if (playeringame[player - players] && @@ -1125,7 +1125,7 @@ void P_ExplodeMissile (AActor *mo, line_t *line, AActor *target) } else { - mo->RenderStyle = deh.ExplosionStyle; + mo->RenderStyle = ERenderStyle(deh.ExplosionStyle); mo->alpha = deh.ExplosionAlpha; } } @@ -2488,12 +2488,12 @@ bool AActor::IsOkayToAttack (AActor *link) void AActor::SetShade (DWORD rgb) { PalEntry *entry = (PalEntry *)&rgb; - alphacolor = rgb | (ColorMatcher.Pick (entry->r, entry->g, entry->b) << 24); + fillcolor = rgb | (ColorMatcher.Pick (entry->r, entry->g, entry->b) << 24); } void AActor::SetShade (int r, int g, int b) { - alphacolor = MAKEARGB(ColorMatcher.Pick (r, g, b), r, g, b); + fillcolor = MAKEARGB(ColorMatcher.Pick (r, g, b), r, g, b); } // @@ -2607,6 +2607,7 @@ void AActor::Tick () else if (flags & MF_STEALTH) { // [RH] Fade a stealth monster in and out of visibility + RenderStyle.Flags &= ~STYLEF_Alpha1; if (visdir > 0) { alpha += 2*FRACUNIT/TICRATE; diff --git a/src/p_sight.cpp b/src/p_sight.cpp index 9b37183118..a1e964c1c4 100644 --- a/src/p_sight.cpp +++ b/src/p_sight.cpp @@ -493,10 +493,7 @@ sightcounts[0]++; // // [RH] Andy Baker's stealth monsters: // Cannot see an invisible object - if ((flags & 1) == 0 && - (t2->RenderStyle == STYLE_None || - (t2->RenderStyle >= STYLE_Translucent && t2->alpha == 0) || - (t2->renderflags & RF_INVISIBLE))) + if ((flags & 1) == 0 && ((t2->renderflags & RF_INVISIBLE) || !t2->RenderStyle.IsVisible(t2->alpha))) { // small chance of an attack being made anyway if ((bglobal.m_Thinking ? pr_botchecksight() : pr_checksight()) > 50) { diff --git a/src/p_spec.h b/src/p_spec.h index dcb9151ebd..f3a3b73dd6 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -27,6 +27,8 @@ #include "dsectoreffect.h" +class FScanner; + //jff 2/23/98 identify the special classes that can share sectors typedef enum @@ -385,7 +387,7 @@ void EV_StartLightFading (int tag, int value, int tics); bool P_ChangeSwitchTexture (side_t *side, int useAgain, BYTE special, bool *quest=NULL); void P_InitSwitchList (); -void P_ProcessSwitchDef (); +void P_ProcessSwitchDef (FScanner &sc); // // P_PLATS @@ -589,7 +591,7 @@ struct FDoorAnimation char *CloseSound; }; -void P_ParseAnimatedDoor (); +void P_ParseAnimatedDoor (FScanner &sc); class DAnimatedDoor : public DMovingCeiling { diff --git a/src/p_switch.cpp b/src/p_switch.cpp index 88acd7f712..e6f4aea53f 100644 --- a/src/p_switch.cpp +++ b/src/p_switch.cpp @@ -107,7 +107,7 @@ struct FSwitchDef }; static int STACK_ARGS SortSwitchDefs (const void *a, const void *b); -static FSwitchDef *ParseSwitchDef (bool ignoreBad); +static FSwitchDef *ParseSwitchDef (FScanner &sc, bool ignoreBad); static WORD AddSwitchDef (FSwitchDef *def); // @@ -211,84 +211,83 @@ static int STACK_ARGS SortSwitchDefs (const void *a, const void *b) } // Parse a switch block in ANIMDEFS and add the definitions to SwitchList -void P_ProcessSwitchDef () +void P_ProcessSwitchDef (FScanner &sc) { const BITFIELD texflags = FTextureManager::TEXMAN_Overridable | FTextureManager::TEXMAN_TryAny; - char *picname; + FString picname; FSwitchDef *def1, *def2; SWORD picnum; BYTE max; bool quest = false; def1 = def2 = NULL; - SC_MustGetString (); - if (SC_Compare ("doom")) + sc.MustGetString (); + if (sc.Compare ("doom")) { max = 0; } - else if (SC_Compare ("heretic")) + else if (sc.Compare ("heretic")) { max = 17; } - else if (SC_Compare ("hexen")) + else if (sc.Compare ("hexen")) { max = 33; } - else if (SC_Compare ("strife")) + else if (sc.Compare ("strife")) { max = 49; } - else if (SC_Compare ("any")) + else if (sc.Compare ("any")) { max = 240; } else { - //SC_ScriptError ("Unknown game"); // There is no game specified; just treat as any max = 240; - SC_UnGet (); + sc.UnGet (); } if (max == 0) { - SC_MustGetNumber (); - max |= sc_Number & 15; + sc.MustGetNumber (); + max |= sc.Number & 15; } - SC_MustGetString (); - picnum = TexMan.CheckForTexture (sc_String, FTexture::TEX_Wall, texflags); - picname = copystring (sc_String); - while (SC_GetString ()) + sc.MustGetString (); + picnum = TexMan.CheckForTexture (sc.String, FTexture::TEX_Wall, texflags); + picname = sc.String; + while (sc.GetString ()) { - if (SC_Compare ("quest")) + if (sc.Compare ("quest")) { quest = true; } - else if (SC_Compare ("on")) + else if (sc.Compare ("on")) { if (def1 != NULL) { - SC_ScriptError ("Switch already has an on state"); + sc.ScriptError ("Switch already has an on state"); } - def1 = ParseSwitchDef (picnum == -1); + def1 = ParseSwitchDef (sc, picnum == -1); } - else if (SC_Compare ("off")) + else if (sc.Compare ("off")) { if (def2 != NULL) { - SC_ScriptError ("Switch already has an off state"); + sc.ScriptError ("Switch already has an off state"); } - def2 = ParseSwitchDef (picnum == -1); + def2 = ParseSwitchDef (sc, picnum == -1); } else { - SC_UnGet (); + sc.UnGet (); break; } } /* if (def1 == NULL) { - SC_ScriptError ("Switch must have an on state"); + sc.ScriptError ("Switch must have an on state"); } */ if (def1 == NULL || picnum == -1 || @@ -304,7 +303,6 @@ void P_ProcessSwitchDef () { free (def1); } - delete [] picname; return; } @@ -323,15 +321,14 @@ void P_ProcessSwitchDef () def2->PreTexture = def1->u.Textures[def1->NumFrames*2+def1->NumFrames-1]; if (def1->PreTexture == def2->PreTexture) { - SC_ScriptError ("The on state for switch %s must end with a texture other than %s", picname, picname); + sc.ScriptError ("The on state for switch %s must end with a texture other than %s", picname.GetChars(), picname.GetChars()); } def2->PairIndex = AddSwitchDef (def1); def1->PairIndex = AddSwitchDef (def2); def1->QuestPanel = def2->QuestPanel = quest; - delete [] picname; } -FSwitchDef *ParseSwitchDef (bool ignoreBad) +FSwitchDef *ParseSwitchDef (FScanner &sc, bool ignoreBad) { const BITFIELD texflags = FTextureManager::TEXMAN_Overridable | FTextureManager::TEXMAN_TryAny; FSwitchDef *def; @@ -346,45 +343,45 @@ FSwitchDef *ParseSwitchDef (bool ignoreBad) sound = 0; bad = false; - while (SC_GetString ()) + while (sc.GetString ()) { - if (SC_Compare ("sound")) + if (sc.Compare ("sound")) { if (sound != 0) { - SC_ScriptError ("Switch state already has a sound"); + sc.ScriptError ("Switch state already has a sound"); } - SC_MustGetString (); - sound = S_FindSound (sc_String); + sc.MustGetString (); + sound = S_FindSound (sc.String); } - else if (SC_Compare ("pic")) + else if (sc.Compare ("pic")) { if (numframes == MAX_FRAMES) { - SC_ScriptError ("Switch has too many frames"); + sc.ScriptError ("Switch has too many frames"); } - SC_MustGetString (); - picnum = TexMan.CheckForTexture (sc_String, FTexture::TEX_Wall, texflags); + sc.MustGetString (); + picnum = TexMan.CheckForTexture (sc.String, FTexture::TEX_Wall, texflags); if (picnum < 0 && !ignoreBad) { - //Printf ("Unknown switch texture %s\n", sc_String); + //Printf ("Unknown switch texture %s\n", sc.String); bad = true; } pics[numframes] = picnum; - SC_MustGetString (); - if (SC_Compare ("tics")) + sc.MustGetString (); + if (sc.Compare ("tics")) { - SC_MustGetNumber (); - times[numframes] = sc_Number & 65535; + sc.MustGetNumber (); + times[numframes] = sc.Number & 65535; } - else if (SC_Compare ("rand")) + else if (sc.Compare ("rand")) { int min, max; - SC_MustGetNumber (); - min = sc_Number & 65535; - SC_MustGetNumber (); - max = sc_Number & 65535; + sc.MustGetNumber (); + min = sc.Number & 65535; + sc.MustGetNumber (); + max = sc.Number & 65535; if (min > max) { swap (min, max); @@ -393,19 +390,19 @@ FSwitchDef *ParseSwitchDef (bool ignoreBad) } else { - SC_ScriptError ("Must specify a duration for switch frame"); + sc.ScriptError ("Must specify a duration for switch frame"); } numframes++; } else { - SC_UnGet (); + sc.UnGet (); break; } } if (numframes == 0) { - SC_ScriptError ("Switch state needs at least one frame"); + sc.ScriptError ("Switch state needs at least one frame"); } if (bad) { diff --git a/src/p_terrain.cpp b/src/p_terrain.cpp index e91c28b832..be362f0f35 100644 --- a/src/p_terrain.cpp +++ b/src/p_terrain.cpp @@ -103,7 +103,7 @@ struct FGenericParse EGenericType Type; union { size_t Offset; - void (*Handler) (int type, void *fields); + void (*Handler) (FScanner &sc, int type, void *fields); } u; }; @@ -114,16 +114,16 @@ struct FGenericParse // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- static void MakeDefaultTerrain (); -static void ParseOuter (); -static void ParseSplash (); -static void ParseTerrain (); -static void ParseFloor (); +static void ParseOuter (FScanner &sc); +static void ParseSplash (FScanner &sc); +static void ParseTerrain (FScanner &sc); +static void ParseFloor (FScanner &sc); static int FindSplash (FName name); static int FindTerrain (FName name); -static void GenericParse (FGenericParse *parser, const char **keywords, +static void GenericParse (FScanner &sc, FGenericParse *parser, const char **keywords, void *fields, const char *type, FName name); -static void ParseDamage (int keyword, void *fields); -static void ParseFriction (int keyword, void *fields); +static void ParseDamage (FScanner &sc, int keyword, void *fields); +static void ParseFriction (FScanner &sc, int keyword, void *fields); // EXTERNAL DATA DECLARATIONS ---------------------------------------------- @@ -264,9 +264,8 @@ void P_InitTerrainTypes () lastlump = 0; while (-1 != (lump = Wads.FindLump ("TERRAIN", &lastlump)) ) { - SC_OpenLumpNum (lump, "TERRAIN"); - ParseOuter (); - SC_Close (); + FScanner sc(lump, "TERRAIN"); + ParseOuter (sc); } Splashes.ShrinkToFit (); Terrains.ShrinkToFit (); @@ -294,51 +293,51 @@ static void MakeDefaultTerrain () // //========================================================================== -static void ParseOuter () +static void ParseOuter (FScanner &sc) { int bracedepth = 0; bool ifskip = false; - while (SC_GetString ()) + while (sc.GetString ()) { if (ifskip) { if (bracedepth > 0) { - if (SC_Compare ("}")) + if (sc.Compare ("}")) { bracedepth--; continue; } } - else if (SC_Compare ("endif")) + else if (sc.Compare ("endif")) { ifskip = false; continue; } - if (SC_Compare ("{")) + if (sc.Compare ("{")) { bracedepth++; } - else if (SC_Compare ("}")) + else if (sc.Compare ("}")) { - SC_ScriptError ("Too many left braces ('}')"); + sc.ScriptError ("Too many left braces ('}')"); } } else { - switch (SC_MustMatchString (OuterKeywords)) + switch (sc.MustMatchString (OuterKeywords)) { case OUT_SPLASH: - ParseSplash (); + ParseSplash (sc); break; case OUT_TERRAIN: - ParseTerrain (); + ParseTerrain (sc); break; case OUT_FLOOR: - ParseFloor (); + ParseFloor (sc); break; case OUT_IFDOOM: @@ -403,15 +402,15 @@ static void SetSplashDefaults (FSplashDef *splashdef) // //========================================================================== -void ParseSplash () +void ParseSplash (FScanner &sc) { int splashnum; FSplashDef *splashdef; bool isnew = false; FName name; - SC_MustGetString (); - name = sc_String; + sc.MustGetString (); + name = sc.String; splashnum = (int)FindSplash (name); if (splashnum < 0) { @@ -423,8 +422,8 @@ void ParseSplash () } splashdef = &Splashes[splashnum]; - SC_MustGetString (); - if (!SC_Compare ("modify")) + sc.MustGetString (); + if (!sc.Compare ("modify")) { // Set defaults if (!isnew) { // New ones already have their defaults set before they're pushed. @@ -433,15 +432,15 @@ void ParseSplash () } else { - SC_MustGetString(); + sc.MustGetString(); } - if (!SC_Compare ("{")) + if (!sc.Compare ("{")) { - SC_ScriptError ("Expected {"); + sc.ScriptError ("Expected {"); } else { - GenericParse (SplashParser, SplashKeywords, splashdef, "splash", + GenericParse (sc, SplashParser, SplashKeywords, splashdef, "splash", splashdef->Name); } } @@ -452,13 +451,13 @@ void ParseSplash () // //========================================================================== -void ParseTerrain () +void ParseTerrain (FScanner &sc) { int terrainnum; FName name; - SC_MustGetString (); - name = sc_String; + sc.MustGetString (); + name = sc.String; terrainnum = (int)FindTerrain (name); if (terrainnum < 0) { @@ -470,8 +469,8 @@ void ParseTerrain () } // Set defaults - SC_MustGetString (); - if (!SC_Compare ("modify")) + sc.MustGetString (); + if (!sc.Compare ("modify")) { name = Terrains[terrainnum].Name; memset (&Terrains[terrainnum], 0, sizeof(FTerrainDef)); @@ -480,17 +479,17 @@ void ParseTerrain () } else { - SC_MustGetString (); + sc.MustGetString (); } - if (SC_Compare ("{")) + if (sc.Compare ("{")) { - GenericParse (TerrainParser, TerrainKeywords, &Terrains[terrainnum], + GenericParse (sc, TerrainParser, TerrainKeywords, &Terrains[terrainnum], "terrain", Terrains[terrainnum].Name); } else { - SC_ScriptError ("Expected {"); + sc.ScriptError ("Expected {"); } } @@ -500,14 +499,14 @@ void ParseTerrain () // //========================================================================== -static void ParseDamage (int keyword, void *fields) +static void ParseDamage (FScanner &sc, int keyword, void *fields) { FTerrainDef *def = (FTerrainDef *)fields; - SC_MustGetString (); + sc.MustGetString (); // Lava is synonymous with Fire here! - if (SC_Compare("Lava")) def->DamageMOD=NAME_Fire; - else def->DamageMOD=sc_String; + if (sc.Compare("Lava")) def->DamageMOD=NAME_Fire; + else def->DamageMOD=sc.String; } //========================================================================== @@ -516,17 +515,17 @@ static void ParseDamage (int keyword, void *fields) // //========================================================================== -static void ParseFriction (int keyword, void *fields) +static void ParseFriction (FScanner &sc, int keyword, void *fields) { FTerrainDef *def = (FTerrainDef *)fields; fixed_t friction, movefactor; - SC_MustGetFloat (); + sc.MustGetFloat (); // These calculations should match those in P_SetSectorFriction(). // A friction of 1.0 is equivalent to ORIG_FRICTION. - friction = (fixed_t)(0x1EB8*(sc_Float*100))/0x80 + 0xD001; + friction = (fixed_t)(0x1EB8*(sc.Float*100))/0x80 + 0xD001; friction = clamp (friction, 0, FRACUNIT); if (friction > ORIG_FRICTION) // ice @@ -547,7 +546,7 @@ static void ParseFriction (int keyword, void *fields) // //========================================================================== -static void GenericParse (FGenericParse *parser, const char **keywords, +static void GenericParse (FScanner &sc, FGenericParse *parser, const char **keywords, void *fields, const char *type, FName name) { bool notdone = true; @@ -557,8 +556,8 @@ static void GenericParse (FGenericParse *parser, const char **keywords, do { - SC_MustGetString (); - keyword = SC_MustMatchString (keywords); + sc.MustGetString (); + keyword = sc.MustMatchString (keywords); switch (parser[keyword].Type) { case GEN_End: @@ -566,69 +565,69 @@ static void GenericParse (FGenericParse *parser, const char **keywords, break; case GEN_Fixed: - SC_MustGetFloat (); - SET_FIELD (fixed_t, (fixed_t)(FRACUNIT * sc_Float)); + sc.MustGetFloat (); + SET_FIELD (fixed_t, (fixed_t)(FRACUNIT * sc.Float)); break; case GEN_Sound: - SC_MustGetString (); - val = S_FindSound (sc_String); + sc.MustGetString (); + val = S_FindSound (sc.String); SET_FIELD (int, val); if (val == 0) { Printf ("Unknown sound %s in %s %s\n", - sc_String, type, name.GetChars()); + sc.String, type, name.GetChars()); } break; case GEN_Byte: - SC_MustGetNumber (); - SET_FIELD (BYTE, sc_Number); + sc.MustGetNumber (); + SET_FIELD (BYTE, sc.Number); break; case GEN_Class: - SC_MustGetString (); - if (SC_Compare ("None")) + sc.MustGetString (); + if (sc.Compare ("None")) { info = NULL; } else { - info = PClass::FindClass (sc_String); + info = PClass::FindClass (sc.String); if (!info->IsDescendantOf (RUNTIME_CLASS(AActor))) { Printf ("%s is not an Actor (in %s %s)\n", - sc_String, type, name.GetChars()); + sc.String, type, name.GetChars()); info = NULL; } else if (info == NULL) { Printf ("Unknown actor %s in %s %s\n", - sc_String, type, name.GetChars()); + sc.String, type, name.GetChars()); } } SET_FIELD (const PClass *, info); break; case GEN_Splash: - SC_MustGetString (); - val = FindSplash (sc_String); + sc.MustGetString (); + val = FindSplash (sc.String); SET_FIELD (int, val); if (val == -1) { Printf ("Splash %s is not defined yet (in %s %s)\n", - sc_String, type, name.GetChars()); + sc.String, type, name.GetChars()); } break; case GEN_Float: - SC_MustGetFloat (); - SET_FIELD (float, sc_Float); + sc.MustGetFloat (); + SET_FIELD (float, sc.Float); break; case GEN_Time: - SC_MustGetFloat (); - SET_FIELD (int, (int)(sc_Float * TICRATE)); + sc.MustGetFloat (); + SET_FIELD (int, (int)(sc.Float * TICRATE)); break; case GEN_Bool: @@ -636,12 +635,12 @@ static void GenericParse (FGenericParse *parser, const char **keywords, break; case GEN_Int: - SC_MustGetNumber (); - SET_FIELD (int, sc_Number); + sc.MustGetNumber (); + SET_FIELD (int, sc.Number); break; case GEN_Custom: - parser[keyword].u.Handler (keyword, fields); + parser[keyword].u.Handler (sc, keyword, fields); break; } } while (notdone); @@ -653,24 +652,24 @@ static void GenericParse (FGenericParse *parser, const char **keywords, // //========================================================================== -static void ParseFloor () +static void ParseFloor (FScanner &sc) { int picnum; int terrain; - SC_MustGetString (); - picnum = TexMan.CheckForTexture (sc_String, FTexture::TEX_Flat); + sc.MustGetString (); + picnum = TexMan.CheckForTexture (sc.String, FTexture::TEX_Flat); if (picnum == -1) { - Printf ("Unknown flat %s\n", sc_String); - SC_MustGetString (); + Printf ("Unknown flat %s\n", sc.String); + sc.MustGetString (); return; } - SC_MustGetString (); - terrain = FindTerrain (sc_String); + sc.MustGetString (); + terrain = FindTerrain (sc.String); if (terrain == -1) { - Printf ("Unknown terrain %s\n", sc_String); + Printf ("Unknown terrain %s\n", sc.String); terrain = 0; } TerrainTypes[picnum] = terrain; diff --git a/src/p_xlat.cpp b/src/p_xlat.cpp index 6bd4017e1d..39050491d4 100644 --- a/src/p_xlat.cpp +++ b/src/p_xlat.cpp @@ -435,100 +435,99 @@ void P_ReadSectorSpecials() lastlump = 0; while ((lump = Wads.FindLump ("SECTORX", &lastlump)) != -1) { - SC_OpenLumpNum (lump, "SECTORX"); - SC_SetCMode(true); - while (SC_GetString()) + FScanner sc(lump, "SECTORX"); + sc.SetCMode(true); + while (sc.GetString()) { - if (SC_Compare("IFDOOM")) + if (sc.Compare("IFDOOM")) { - SC_MustGetStringName("{"); + sc.MustGetStringName("{"); if (gameinfo.gametype != GAME_Doom) { do { - if (!SC_GetString()) + if (!sc.GetString()) { - SC_ScriptError("Unexpected end of file"); + sc.ScriptError("Unexpected end of file"); } } - while (!SC_Compare("}")); + while (!sc.Compare("}")); } } - else if (SC_Compare("IFHERETIC")) + else if (sc.Compare("IFHERETIC")) { - SC_MustGetStringName("{"); + sc.MustGetStringName("{"); if (gameinfo.gametype != GAME_Heretic) { do { - if (!SC_GetString()) + if (!sc.GetString()) { - SC_ScriptError("Unexpected end of file"); + sc.ScriptError("Unexpected end of file"); } } - while (!SC_Compare("}")); + while (!sc.Compare("}")); } } - else if (SC_Compare("IFSTRIFE")) + else if (sc.Compare("IFSTRIFE")) { - SC_MustGetStringName("{"); + sc.MustGetStringName("{"); if (gameinfo.gametype != GAME_Strife) { do { - if (!SC_GetString()) + if (!sc.GetString()) { - SC_ScriptError("Unexpected end of file"); + sc.ScriptError("Unexpected end of file"); } } - while (!SC_Compare("}")); + while (!sc.Compare("}")); } } - else if (SC_Compare("}")) + else if (sc.Compare("}")) { // ignore } - else if (SC_Compare("BOOMMASK")) + else if (sc.Compare("BOOMMASK")) { - SC_MustGetNumber(); - boommask = sc_Number; - SC_MustGetStringName(","); - SC_MustGetNumber(); - boomshift = sc_Number; + sc.MustGetNumber(); + boommask = sc.Number; + sc.MustGetStringName(","); + sc.MustGetNumber(); + boomshift = sc.Number; } - else if (SC_Compare("[")) + else if (sc.Compare("[")) { int start; int end; - SC_MustGetNumber(); - start = sc_Number; - SC_MustGetStringName(","); - SC_MustGetNumber(); - end = sc_Number; - SC_MustGetStringName("]"); - SC_MustGetStringName(":"); - SC_MustGetNumber(); - for(int j=start;j<=end;j++) + sc.MustGetNumber(); + start = sc.Number; + sc.MustGetStringName(","); + sc.MustGetNumber(); + end = sc.Number; + sc.MustGetStringName("]"); + sc.MustGetStringName(":"); + sc.MustGetNumber(); + for(int j = start; j <= end; j++) { - sectortables[!!boommask][j]=sc_Number + j - start; + sectortables[!!boommask][j]=sc.Number + j - start; } } - else if (IsNum(sc_String)) + else if (IsNum(sc.String)) { int start; - start = atoi(sc_String); - SC_MustGetStringName(":"); - SC_MustGetNumber(); - sectortables[!!boommask][start]=sc_Number; + start = atoi(sc.String); + sc.MustGetStringName(":"); + sc.MustGetNumber(); + sectortables[!!boommask][start] = sc.Number; } else { - SC_ScriptError(NULL); + sc.ScriptError(NULL); } } - SC_Close (); } } diff --git a/src/r_anim.cpp b/src/r_anim.cpp index 2291df61cb..f0786ed633 100644 --- a/src/r_anim.cpp +++ b/src/r_anim.cpp @@ -92,11 +92,11 @@ public: static void R_InitAnimDefs (); static void R_AddComplexAnim (int picnum, const TArray &frames); -static void ParseAnim (bool istex); -static void ParseRangeAnim (int picnum, int usetype, bool missing); -static void ParsePicAnim (int picnum, int usetype, bool missing, TArray &frames); -static int ParseFramenum (int basepicnum, int usetype, bool allowMissing); -static void ParseTime (DWORD &min, DWORD &max); +static void ParseAnim (FScanner &sc, bool istex); +static void ParseRangeAnim (FScanner &sc, int picnum, int usetype, bool missing); +static void ParsePicAnim (FScanner &sc, int picnum, int usetype, bool missing, TArray &frames); +static int ParseFramenum (FScanner &sc, int basepicnum, int usetype, bool allowMissing); +static void ParseTime (FScanner &sc, DWORD &min, DWORD &max); // PUBLIC DATA DEFINITIONS ------------------------------------------------- @@ -255,43 +255,43 @@ static void R_InitAnimDefs () while ((lump = Wads.FindLump ("ANIMDEFS", &lastlump)) != -1) { - SC_OpenLumpNum (lump, "ANIMDEFS"); + FScanner sc(lump, "ANIMDEFS"); - while (SC_GetString ()) + while (sc.GetString ()) { - if (SC_Compare ("flat")) + if (sc.Compare ("flat")) { - ParseAnim (false); + ParseAnim (sc, false); } - else if (SC_Compare ("texture")) + else if (sc.Compare ("texture")) { - ParseAnim (true); + ParseAnim (sc, true); } - else if (SC_Compare ("switch")) + else if (sc.Compare ("switch")) { - P_ProcessSwitchDef (); + P_ProcessSwitchDef (sc); } // [GRB] Added warping type 2 - else if (SC_Compare ("warp") || SC_Compare ("warp2")) + else if (sc.Compare ("warp") || sc.Compare ("warp2")) { bool isflat = false; - bool type2 = SC_Compare ("warp2"); // [GRB] - SC_MustGetString (); - if (SC_Compare ("flat")) + bool type2 = sc.Compare ("warp2"); // [GRB] + sc.MustGetString (); + if (sc.Compare ("flat")) { isflat = true; - SC_MustGetString (); + sc.MustGetString (); } - else if (SC_Compare ("texture")) + else if (sc.Compare ("texture")) { isflat = false; - SC_MustGetString (); + sc.MustGetString (); } else { - SC_ScriptError (NULL); + sc.ScriptError (NULL); } - int picnum = TexMan.CheckForTexture (sc_String, isflat ? FTexture::TEX_Flat : FTexture::TEX_Wall, texflags); + int picnum = TexMan.CheckForTexture (sc.String, isflat ? FTexture::TEX_Flat : FTexture::TEX_Wall, texflags); if (picnum != -1) { FTexture * warper = TexMan[picnum]; @@ -310,31 +310,31 @@ static void R_InitAnimDefs () // Warping information is taken from the last warp // definition for this texture. warper->bNoDecals = true; - if (SC_GetString ()) + if (sc.GetString ()) { - if (SC_Compare ("allowdecals")) + if (sc.Compare ("allowdecals")) { warper->bNoDecals = false; } else { - SC_UnGet (); + sc.UnGet (); } } } } - else if (SC_Compare ("cameratexture")) + else if (sc.Compare ("cameratexture")) { int width, height; int fitwidth, fitheight; FString picname; - SC_MustGetString (); - picname = sc_String; - SC_MustGetNumber (); - width = sc_Number; - SC_MustGetNumber (); - height = sc_Number; + sc.MustGetString (); + picname = sc.String; + sc.MustGetNumber (); + width = sc.Number; + sc.MustGetNumber (); + height = sc.Number; int picnum = TexMan.CheckForTexture (picname, FTexture::TEX_Flat, texflags); FTexture *viewer = new FCanvasTexture (picname, width, height); if (picnum != -1) @@ -353,32 +353,31 @@ static void R_InitAnimDefs () viewer->UseType = FTexture::TEX_Wall; TexMan.AddTexture (viewer); } - if (SC_GetString()) + if (sc.GetString()) { - if (SC_Compare ("fit")) + if (sc.Compare ("fit")) { - SC_MustGetNumber (); - fitwidth = sc_Number; - SC_MustGetNumber (); - fitheight = sc_Number; + sc.MustGetNumber (); + fitwidth = sc.Number; + sc.MustGetNumber (); + fitheight = sc.Number; } else { - SC_UnGet (); + sc.UnGet (); } } viewer->SetScaledSize(fitwidth, fitheight); } - else if (SC_Compare ("animatedDoor")) + else if (sc.Compare ("animatedDoor")) { - P_ParseAnimatedDoor (); + P_ParseAnimatedDoor (sc); } else { - SC_ScriptError (NULL); + sc.ScriptError (NULL); } } - SC_Close (); } } @@ -391,7 +390,7 @@ static void R_InitAnimDefs () // //========================================================================== -static void ParseAnim (bool istex) +static void ParseAnim (FScanner &sc, bool istex) { const BITFIELD texflags = FTextureManager::TEXMAN_Overridable | FTextureManager::TEXMAN_TryAny; TArray frames (32); @@ -402,13 +401,13 @@ static void ParseAnim (bool istex) usetype = istex ? FTexture::TEX_Wall : FTexture::TEX_Flat; - SC_MustGetString (); - if (SC_Compare ("optional")) + sc.MustGetString (); + if (sc.Compare ("optional")) { optional = true; - SC_MustGetString (); + sc.MustGetString (); } - picnum = TexMan.CheckForTexture (sc_String, usetype, texflags); + picnum = TexMan.CheckForTexture (sc.String, usetype, texflags); if (picnum < 0) { @@ -418,7 +417,7 @@ static void ParseAnim (bool istex) } else { - Printf (PRINT_BOLD, "ANIMDEFS: Can't find %s\n", sc_String); + Printf (PRINT_BOLD, "ANIMDEFS: Can't find %s\n", sc.String); } } @@ -428,9 +427,9 @@ static void ParseAnim (bool istex) TexMan[picnum]->bNoDecals = true; } - while (SC_GetString ()) + while (sc.GetString ()) { - if (SC_Compare ("allowdecals")) + if (sc.Compare ("allowdecals")) { if (picnum >= 0) { @@ -438,31 +437,31 @@ static void ParseAnim (bool istex) } continue; } - else if (SC_Compare ("range")) + else if (sc.Compare ("range")) { if (defined == 2) { - SC_ScriptError ("You cannot use \"pic\" and \"range\" together in a single animation."); + sc.ScriptError ("You cannot use \"pic\" and \"range\" together in a single animation."); } if (defined == 1) { - SC_ScriptError ("You can only use one \"range\" per animation."); + sc.ScriptError ("You can only use one \"range\" per animation."); } defined = 1; - ParseRangeAnim (picnum, usetype, missing); + ParseRangeAnim (sc, picnum, usetype, missing); } - else if (SC_Compare ("pic")) + else if (sc.Compare ("pic")) { if (defined == 1) { - SC_ScriptError ("You cannot use \"pic\" and \"range\" together in a single animation."); + sc.ScriptError ("You cannot use \"pic\" and \"range\" together in a single animation."); } defined = 2; - ParsePicAnim (picnum, usetype, missing, frames); + ParsePicAnim (sc, picnum, usetype, missing, frames); } else { - SC_UnGet (); + sc.UnGet (); break; } } @@ -473,7 +472,7 @@ static void ParseAnim (bool istex) { if (frames.Size() < 2) { - SC_ScriptError ("Animation needs at least 2 frames"); + sc.ScriptError ("Animation needs at least 2 frames"); } R_AddComplexAnim (picnum, frames); } @@ -488,14 +487,14 @@ static void ParseAnim (bool istex) // //========================================================================== -static void ParseRangeAnim (int picnum, int usetype, bool missing) +static void ParseRangeAnim (FScanner &sc, int picnum, int usetype, bool missing) { int type, framenum; DWORD min, max; type = FAnimDef::ANIM_Forward; - framenum = ParseFramenum (picnum, usetype, missing); - ParseTime (min, max); + framenum = ParseFramenum (sc, picnum, usetype, missing); + ParseTime (sc, min, max); if (framenum == picnum || picnum < 0) { @@ -507,15 +506,15 @@ static void ParseRangeAnim (int picnum, int usetype, bool missing) TexMan[framenum]->bNoDecals = TexMan[picnum]->bNoDecals; swap (framenum, picnum); } - if (SC_GetString()) + if (sc.GetString()) { - if (SC_Compare ("Oscillate")) + if (sc.Compare ("Oscillate")) { type = type == FAnimDef::ANIM_Forward ? FAnimDef::ANIM_OscillateUp : FAnimDef::ANIM_OscillateDown; } else { - SC_UnGet (); + sc.UnGet (); } } R_AddSimpleAnim (picnum, framenum - picnum + 1, type, min, max - min); @@ -529,13 +528,13 @@ static void ParseRangeAnim (int picnum, int usetype, bool missing) // //========================================================================== -static void ParsePicAnim (int picnum, int usetype, bool missing, TArray &frames) +static void ParsePicAnim (FScanner &sc, int picnum, int usetype, bool missing, TArray &frames) { int framenum; DWORD min, max; - framenum = ParseFramenum (picnum, usetype, missing); - ParseTime (min, max); + framenum = ParseFramenum (sc, picnum, usetype, missing); + ParseTime (sc, min, max); if (picnum >= 0) { @@ -557,22 +556,22 @@ static void ParsePicAnim (int picnum, int usetype, bool missing, TArray= STYLE_Count) + { + legacy = STYLE_None; + } + *this = LegacyRenderStyles[legacy]; + return *this; +} +inline FArchive &operator<< (FArchive &arc, FRenderStyle &style) +{ + arc << style.BlendOp << style.SrcAlpha << style.DestAlpha << style.Flags; + return arc; +} diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index e751666fd4..e2068767e7 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -979,7 +979,7 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static void R_GetExtraLight (int *light, const secplane_t &plane, FExtraLight *el) { - BYTE *floodcolormap; + FDynamicColormap *floodcolormap; int floodlight; bool flooding; vertex_t **triangle; @@ -1020,7 +1020,7 @@ void R_GetExtraLight (int *light, const secplane_t &plane, FExtraLight *el) } else { - basecolormap = el->Lights[i].Master->ColorMap->Maps; + basecolormap = el->Lights[i].Master->ColorMap; *light = el->Lights[i].Master->lightlevel; if (el->Lights[i].bFlooder) { @@ -1060,13 +1060,13 @@ void R_Subsector (subsector_t *sub) frontsector = R_FakeFlat(frontsector, &tempsec, &floorlightlevel, &ceilinglightlevel, false); // killough 4/11/98 - basecolormap = frontsector->ColorMap->Maps; + basecolormap = frontsector->ColorMap; R_GetExtraLight (&ceilinglightlevel, frontsector->ceilingplane, frontsector->ExtraLights); // [RH] set foggy flag foggy = level.fadeto || frontsector->ColorMap->Fade || (level.flags & LEVEL_HASFADETABLE); r_actualextralight = foggy ? 0 : extralight << 4; - basecolormap = frontsector->ColorMap->Maps; + basecolormap = frontsector->ColorMap; ceilingplane = frontsector->ceilingplane.ZatPoint (viewx, viewy) > viewz || frontsector->ceilingpic == skyflatnum || (frontsector->CeilingSkyBox != NULL && frontsector->CeilingSkyBox->bAlways) || @@ -1086,7 +1086,7 @@ void R_Subsector (subsector_t *sub) frontsector->CeilingSkyBox ) : NULL; - basecolormap = frontsector->ColorMap->Maps; + basecolormap = frontsector->ColorMap; R_GetExtraLight (&floorlightlevel, frontsector->floorplane, frontsector->ExtraLights); // killough 3/7/98: Add (x,y) offsets to flats, add deep water check diff --git a/src/r_data.cpp b/src/r_data.cpp index 8eed975673..d92dca7347 100644 --- a/src/r_data.cpp +++ b/src/r_data.cpp @@ -425,38 +425,38 @@ void FTextureManager::LoadHiresTex() while ((remapLump = Wads.FindLump("HIRESTEX", &lastLump)) != -1) { - SC_OpenLumpNum(remapLump, "HIRESTEX"); - while (SC_GetString()) + FScanner sc(remapLump, "HIRESTEX"); + while (sc.GetString()) { - if (SC_Compare("remap")) // remap an existing texture + if (sc.Compare("remap")) // remap an existing texture { - SC_MustGetString(); + sc.MustGetString(); // allow selection by type - if (SC_Compare("wall")) type=FTexture::TEX_Wall, mode=FTextureManager::TEXMAN_Overridable; - else if (SC_Compare("flat")) type=FTexture::TEX_Flat, mode=FTextureManager::TEXMAN_Overridable; - else if (SC_Compare("sprite")) type=FTexture::TEX_Sprite, mode=0; + if (sc.Compare("wall")) type=FTexture::TEX_Wall, mode=FTextureManager::TEXMAN_Overridable; + else if (sc.Compare("flat")) type=FTexture::TEX_Flat, mode=FTextureManager::TEXMAN_Overridable; + else if (sc.Compare("sprite")) type=FTexture::TEX_Sprite, mode=0; else type = FTexture::TEX_Any, mode = 0; - sc_String[8]=0; + sc.String[8]=0; tlist.Clear(); - int amount = ListTextures(sc_String, tlist); + int amount = ListTextures(sc.String, tlist); if (amount == 0) { - int oldtex = AddPatch(sc_String); + int oldtex = AddPatch(sc.String); if (oldtex >= 0) tlist.Push(oldtex); } - FName texname = sc_String; + FName texname = sc.String; - SC_MustGetString(); - int lumpnum = Wads.CheckNumForFullName(sc_String); - if (lumpnum < 0) lumpnum = Wads.CheckNumForName(sc_String, ns_graphics); + sc.MustGetString(); + int lumpnum = Wads.CheckNumForFullName(sc.String); + if (lumpnum < 0) lumpnum = Wads.CheckNumForName(sc.String, ns_graphics); if (tlist.Size() == 0) { Printf("Attempting to remap non-existent texture %s to %s\n", - texname.GetChars(), sc_String); + texname.GetChars(), sc.String); } else { @@ -487,22 +487,22 @@ void FTextureManager::LoadHiresTex() } } } - else if (SC_Compare("define")) // define a new "fake" texture + else if (sc.Compare("define")) // define a new "fake" texture { - SC_GetString(); - memcpy(src, sc_String, 8); + sc.GetString(); + memcpy(src, sc.String, 8); - int lumpnum = Wads.CheckNumForFullName(sc_String); - if (lumpnum < 0) lumpnum = Wads.CheckNumForName(sc_String, ns_graphics); + int lumpnum = Wads.CheckNumForFullName(sc.String); + if (lumpnum < 0) lumpnum = Wads.CheckNumForName(sc.String, ns_graphics); - SC_GetString(); - is32bit = !!SC_Compare("force32bit"); - if (!is32bit) SC_UnGet(); + sc.GetString(); + is32bit = !!sc.Compare("force32bit"); + if (!is32bit) sc.UnGet(); - SC_GetNumber(); - width = sc_Number; - SC_GetNumber(); - height = sc_Number; + sc.GetNumber(); + width = sc.Number; + sc.GetNumber(); + height = sc.Number; if (lumpnum>=0) { @@ -523,7 +523,6 @@ void FTextureManager::LoadHiresTex() //else Printf("Unable to define hires texture '%s'\n", tex->Name); } } - SC_Close(); } } diff --git a/src/r_defs.h b/src/r_defs.h index e8463420f7..1a3e7bb895 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -860,7 +860,7 @@ struct vissprite_t fixed_t xiscale; // negative if flipped fixed_t idepth; // 1/z fixed_t texturemid; - DWORD AlphaColor; + DWORD FillColor; lighttable_t *colormap; sector_t *heightsec; // killough 3/27/98: height sector for underwater/fake ceiling sector_t *sector; // [RH] sector this sprite is in @@ -869,7 +869,7 @@ struct vissprite_t FTexture *pic; short renderflags; DWORD Translation; // [RH] for color translation - BYTE RenderStyle; + FRenderStyle RenderStyle; BYTE FakeFlatStat; // [RH] which side of fake/floor ceiling sprite is on BYTE bSplitSprite; // [RH] Sprite was split by a drawseg }; diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 346c49dda4..e7593f5324 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -111,6 +111,7 @@ fixed_t dc_iscale; fixed_t dc_texturemid; fixed_t dc_texturefrac; int dc_color; // [RH] Color for column filler +DWORD dc_srccolor; DWORD *dc_srcblend; // [RH] Source and destination DWORD *dc_destblend; // blending lookups @@ -134,6 +135,23 @@ cycle_t DetailDoubleCycles; int dc_fillcolor; BYTE *dc_translation; BYTE shadetables[NUMCOLORMAPS*16*256]; +FDynamicColormap ShadeFakeColormap[16]; +BYTE identitymap[256]; + +// Convert legacy render styles to flexible render styles. +const FRenderStyle LegacyRenderStyles[STYLE_Count] = +{ + /* STYLE_None */ {{ STYLEOP_None, }}, + /* STYLE_Normal */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 }}, + /* STYLE_Fuzzy */ {{ STYLEOP_Fuzz, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_Alpha1 }}, + /* STYLE_SoulTrans */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_TransSoulsAlpha }}, + /* STYLE_OptFuzzy */ {{ STYLEOP_FuzzOrAdd, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 }}, + /* STYLE_Stencil */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_Alpha1 | STYLEF_ColorIsFixed }}, + /* STYLE_Translucent */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 }}, + /* STYLE_Add */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_One, 0 }}, + /* STYLE_Shaded */ {{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_RedIsAlpha | STYLEF_ColorIsFixed }}, +/* STYLE_TranslucentStencil */{{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_ColorIsFixed }}, +}; /************************************/ /* */ @@ -233,7 +251,7 @@ void R_FillAddColumn (void) DWORD fg; bg2rgb = dc_destblend; - fg = dc_srcblend[dc_color]; + fg = dc_srccolor; int pitch = dc_pitch; do @@ -246,6 +264,103 @@ void R_FillAddColumn (void) } +void R_FillAddClampColumn (void) +{ + int count; + BYTE *dest; + + count = dc_count; + if (count <= 0) + return; + + dest = dc_dest; + DWORD *bg2rgb; + DWORD fg; + + bg2rgb = dc_destblend; + fg = dc_srccolor; + int pitch = dc_pitch; + + do + { + DWORD a = fg + bg2rgb[*dest]; + DWORD b = a; + + a |= 0x01f07c1f; + b &= 0x40100400; + a &= 0x3fffffff; + b = b - (b >> 5); + a |= b; + *dest = RGB32k[0][0][a & (a>>15)]; + dest += pitch; + } while (--count); + +} + +void R_FillSubClampColumn (void) +{ + int count; + BYTE *dest; + + count = dc_count; + if (count <= 0) + return; + + dest = dc_dest; + DWORD *bg2rgb; + DWORD fg; + + bg2rgb = dc_destblend; + fg = dc_srccolor | 0x40100400; + int pitch = dc_pitch; + + do + { + DWORD a = fg - bg2rgb[*dest]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k[0][0][a & (a>>15)]; + dest += pitch; + } while (--count); + +} + +void R_FillRevSubClampColumn (void) +{ + int count; + BYTE *dest; + + count = dc_count; + if (count <= 0) + return; + + dest = dc_dest; + DWORD *bg2rgb; + DWORD fg; + + bg2rgb = dc_destblend; + fg = dc_srccolor; + int pitch = dc_pitch; + + do + { + DWORD a = (bg2rgb[*dest] | 0x40100400) - fg; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k[0][0][a & (a>>15)]; + dest += pitch; + } while (--count); + +} + // // Spectre/Invisibility. // @@ -593,8 +708,7 @@ void R_DrawAddClampColumnP_C () do { - DWORD a = fg2rgb[colormap[source[frac>>FRACBITS]]] - + bg2rgb[*dest]; + DWORD a = fg2rgb[colormap[source[frac>>FRACBITS]]] + bg2rgb[*dest]; DWORD b = a; a |= 0x01f07c1f; @@ -609,7 +723,7 @@ void R_DrawAddClampColumnP_C () } } -// Add source to destination, clamping it to white +// Add translated source to destination, clamping it to white void R_DrawAddClampTranslatedColumnP_C () { int count; @@ -636,8 +750,7 @@ void R_DrawAddClampTranslatedColumnP_C () do { - DWORD a = fg2rgb[colormap[translation[source[frac>>FRACBITS]]]] - + bg2rgb[*dest]; + DWORD a = fg2rgb[colormap[translation[source[frac>>FRACBITS]]]] + bg2rgb[*dest]; DWORD b = a; a |= 0x01f07c1f; @@ -652,6 +765,168 @@ void R_DrawAddClampTranslatedColumnP_C () } } +// Subtract destination from source, clamping it to black +void R_DrawSubClampColumnP_C () +{ + int count; + BYTE *dest; + fixed_t frac; + fixed_t fracstep; + + count = dc_count; + if (count <= 0) + return; + + dest = dc_dest; + + fracstep = dc_iscale; + frac = dc_texturefrac; + + { + BYTE *colormap = dc_colormap; + const BYTE *source = dc_source; + int pitch = dc_pitch; + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + + do + { + DWORD a = (fg2rgb[colormap[source[frac>>FRACBITS]]] | 0x40100400) - bg2rgb[*dest]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k[0][0][a & (a>>15)]; + dest += pitch; + frac += fracstep; + } while (--count); + } +} + +// Subtract destination from source, clamping it to black +void R_DrawSubClampTranslatedColumnP_C () +{ + int count; + BYTE *dest; + fixed_t frac; + fixed_t fracstep; + + count = dc_count; + if (count <= 0) + return; + + dest = dc_dest; + + fracstep = dc_iscale; + frac = dc_texturefrac; + + { + BYTE *translation = dc_translation; + BYTE *colormap = dc_colormap; + const BYTE *source = dc_source; + int pitch = dc_pitch; + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + + do + { + DWORD a = (fg2rgb[colormap[translation[source[frac>>FRACBITS]]]] | 0x40100400) - bg2rgb[*dest]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k[0][0][(a>>15) & a]; + dest += pitch; + frac += fracstep; + } while (--count); + } +} + +// Subtract source from destination, clamping it to black +void R_DrawRevSubClampColumnP_C () +{ + int count; + BYTE *dest; + fixed_t frac; + fixed_t fracstep; + + count = dc_count; + if (count <= 0) + return; + + dest = dc_dest; + + fracstep = dc_iscale; + frac = dc_texturefrac; + + { + BYTE *colormap = dc_colormap; + const BYTE *source = dc_source; + int pitch = dc_pitch; + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + + do + { + DWORD a = (bg2rgb[*dest] | 0x40100400) - fg2rgb[colormap[source[frac>>FRACBITS]]]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k[0][0][a & (a>>15)]; + dest += pitch; + frac += fracstep; + } while (--count); + } +} + +// Subtract source from destination, clamping it to black +void R_DrawRevSubClampTranslatedColumnP_C () +{ + int count; + BYTE *dest; + fixed_t frac; + fixed_t fracstep; + + count = dc_count; + if (count <= 0) + return; + + dest = dc_dest; + + fracstep = dc_iscale; + frac = dc_texturefrac; + + { + BYTE *translation = dc_translation; + BYTE *colormap = dc_colormap; + const BYTE *source = dc_source; + int pitch = dc_pitch; + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + + do + { + DWORD a = (bg2rgb[*dest] | 0x40100400) - fg2rgb[colormap[translation[source[frac>>FRACBITS]]]]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k[0][0][(a>>15) & a]; + dest += pitch; + frac += fracstep; + } while (--count); + } +} + // @@ -1198,13 +1473,14 @@ void R_DrawFogBoundary (int x1, int x2, short *uclip, short *dclip) int b2 = dclip[x]; int rcolormap = GETPALOOKUP (light, wallshade); int lcolormap; + BYTE *basecolormapdata = basecolormap->Maps; if (b2 > t2) { clearbufshort (spanend+t2, b2-t2, x); } - dc_colormap = basecolormap + (rcolormap << COLORMAPSHIFT); + dc_colormap = basecolormapdata + (rcolormap << COLORMAPSHIFT); for (--x; x >= x1; --x) { @@ -1229,11 +1505,11 @@ void R_DrawFogBoundary (int x1, int x2, short *uclip, short *dclip) clearbufshort (spanend+t2, b2-t2, x); } rcolormap = lcolormap; - dc_colormap = basecolormap + (lcolormap << COLORMAPSHIFT); + dc_colormap = basecolormapdata + (lcolormap << COLORMAPSHIFT); } else { - if (dc_colormap != basecolormap) + if (dc_colormap != basecolormapdata) { stop = MIN (t1, b2); while (t2 < stop) @@ -1406,6 +1682,137 @@ void tmvline4_addclamp () } while (--count); } +fixed_t tmvline1_subclamp () +{ + DWORD fracstep = dc_iscale; + DWORD frac = dc_texturefrac; + BYTE *colormap = dc_colormap; + int count = dc_count; + const BYTE *source = dc_source; + BYTE *dest = dc_dest; + int bits = tmvlinebits; + int pitch = dc_pitch; + + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + + do + { + BYTE pix = source[frac>>bits]; + if (pix != 0) + { + DWORD a = (fg2rgb[colormap[pix]] | 0x40100400) - bg2rgb[*dest]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k[0][0][a & (a>>15)]; + } + frac += fracstep; + dest += pitch; + } while (--count); + + return frac; +} + +void tmvline4_subclamp () +{ + BYTE *dest = dc_dest; + int count = dc_count; + int bits = tmvlinebits; + + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + + do + { + for (int i = 0; i < 4; ++i) + { + BYTE pix = bufplce[i][vplce[i] >> bits]; + if (pix != 0) + { + DWORD a = (fg2rgb[palookupoffse[i][pix]] | 0x40100400) - bg2rgb[dest[i]]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[i] = RGB32k[0][0][a & (a>>15)]; + } + vplce[i] += vince[i]; + } + dest += dc_pitch; + } while (--count); +} + +fixed_t tmvline1_revsubclamp () +{ + DWORD fracstep = dc_iscale; + DWORD frac = dc_texturefrac; + BYTE *colormap = dc_colormap; + int count = dc_count; + const BYTE *source = dc_source; + BYTE *dest = dc_dest; + int bits = tmvlinebits; + int pitch = dc_pitch; + + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + + do + { + BYTE pix = source[frac>>bits]; + if (pix != 0) + { + DWORD a = (bg2rgb[*dest] | 0x40100400) - fg2rgb[colormap[pix]]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k[0][0][a & (a>>15)]; + } + frac += fracstep; + dest += pitch; + } while (--count); + + return frac; +} + +void tmvline4_revsubclamp () +{ + BYTE *dest = dc_dest; + int count = dc_count; + int bits = tmvlinebits; + + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + + do + { + for (int i = 0; i < 4; ++i) + { + BYTE pix = bufplce[i][vplce[i] >> bits]; + if (pix != 0) + { + DWORD a = (bg2rgb[dest[i]] | 0x40100400) - fg2rgb[palookupoffse[i][pix]]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[i] = RGB32k[0][0][a & (a>>15)]; + } + vplce[i] += vince[i]; + } + dest += dc_pitch; + } while (--count); +} void R_DrawBorder (int x1, int y1, int x2, int y2) @@ -1655,21 +2062,15 @@ EXTERN_CVAR (Bool, r_drawfuzz) EXTERN_CVAR (Float, transsouls) CVAR (Bool, r_drawtrans, true, 0) -static BYTE *basecolormapsave; +static FDynamicColormap *basecolormapsave; -// Convenience macros, to make the following look more like OpenGL/Direct3D -#define BL_ONE FRACUNIT -#define BL_ZERO 0 -#define BL_SRC_ALPHA alpha -#define BL_INV_SRC_ALPHA (BL_ONE-alpha) - -static bool stencilling; - -static bool R_SetBlendFunc (fixed_t fglevel, fixed_t bglevel) +static bool R_SetBlendFunc (int op, fixed_t fglevel, fixed_t bglevel, int flags) { - if (!r_drawtrans || (fglevel == BL_ONE && bglevel == BL_ZERO)) + // r_drawtrans is a seriously bad thing to turn off. I wonder if I should + // just remove it completely. + if (!r_drawtrans || (op == STYLEOP_Add && fglevel == FRACUNIT && bglevel == 0 && !(flags & STYLEF_InvertSource))) { - if (stencilling) + if (flags & STYLEF_ColorIsFixed) { colfunc = R_FillColumnP; hcolfunc_post1 = rt_copy1col; @@ -1689,68 +2090,164 @@ static bool R_SetBlendFunc (fixed_t fglevel, fixed_t bglevel) } return true; } - if (fglevel == BL_ZERO && bglevel == BL_ONE) + if (flags & STYLEF_InvertSource) { - return false; + dc_srcblend = Col2RGB8_Inverse[fglevel>>10]; + dc_destblend = Col2RGB8_LessPrecision[bglevel>>10]; } - if (fglevel + bglevel <= BL_ONE) - { // Colors won't overflow when added + else if (op == STYLEOP_Add && fglevel + bglevel <= FRACUNIT) + { dc_srcblend = Col2RGB8[fglevel>>10]; dc_destblend = Col2RGB8[bglevel>>10]; - if (stencilling) + } + else + { + dc_srcblend = Col2RGB8_LessPrecision[fglevel>>10]; + dc_destblend = Col2RGB8_LessPrecision[bglevel>>10]; + } + switch (op) + { + case STYLEOP_Add: + if (fglevel == 0 && bglevel == FRACUNIT) { - colfunc = R_FillAddColumn; - hcolfunc_post1 = rt_add1col; - hcolfunc_post4 = rt_add4cols; + return false; + } + if (fglevel + bglevel <= FRACUNIT) + { // Colors won't overflow when added + if (flags & STYLEF_ColorIsFixed) + { + colfunc = R_FillAddColumn; + hcolfunc_post1 = rt_add1col; + hcolfunc_post4 = rt_add4cols; + } + else if (dc_translation == NULL) + { + colfunc = R_DrawAddColumnP_C; + hcolfunc_post1 = rt_add1col; + hcolfunc_post4 = rt_add4cols; + } + else + { + colfunc = R_DrawTlatedAddColumnP_C; + hcolfunc_post1 = rt_tlateadd1col; + hcolfunc_post4 = rt_tlateadd4cols; + } + } + else + { // Colors might overflow when added + if (flags & STYLEF_ColorIsFixed) + { + colfunc = R_FillAddClampColumn; + hcolfunc_post1 = rt_addclamp1col; + hcolfunc_post4 = rt_addclamp4cols; + } + else if (dc_translation == NULL) + { + colfunc = R_DrawAddClampColumnP_C; + hcolfunc_post1 = rt_addclamp1col; + hcolfunc_post4 = rt_addclamp4cols; + } + else + { + colfunc = R_DrawAddClampTranslatedColumnP_C; + hcolfunc_post1 = rt_tlateaddclamp1col; + hcolfunc_post4 = rt_tlateaddclamp4cols; + } + } + return true; + + case STYLEOP_Sub: + if (flags & STYLEF_ColorIsFixed) + { + colfunc = R_FillSubClampColumn; + hcolfunc_post1 = rt_subclamp1col; + hcolfunc_post4 = rt_subclamp4cols; } else if (dc_translation == NULL) { - colfunc = R_DrawAddColumnP_C; - hcolfunc_post1 = rt_add1col; - hcolfunc_post4 = rt_add4cols; + colfunc = R_DrawSubClampColumnP_C; + hcolfunc_post1 = rt_subclamp1col; + hcolfunc_post4 = rt_subclamp4cols; } else { - colfunc = R_DrawTlatedAddColumnP_C; - hcolfunc_post1 = rt_tlateadd1col; - hcolfunc_post4 = rt_tlateadd4cols; + colfunc = R_DrawSubClampTranslatedColumnP_C; + hcolfunc_post1 = rt_tlatesubclamp1col; + hcolfunc_post4 = rt_tlatesubclamp4cols; } - } - else - { // Colors might overflow when added - dc_srcblend = Col2RGB8_LessPrecision[fglevel>>10]; - dc_destblend = Col2RGB8_LessPrecision[bglevel>>10]; - if (dc_translation == NULL) + return true; + + case STYLEOP_RevSub: + if (fglevel == 0 && bglevel == FRACUNIT) { - colfunc = R_DrawAddClampColumnP_C; - hcolfunc_post1 = rt_addclamp1col; - hcolfunc_post4 = rt_addclamp4cols; + return false; + } + if (flags & STYLEF_ColorIsFixed) + { + colfunc = R_FillRevSubClampColumn; + hcolfunc_post1 = rt_subclamp1col; + hcolfunc_post4 = rt_subclamp4cols; + } + else if (dc_translation == NULL) + { + colfunc = R_DrawRevSubClampColumnP_C; + hcolfunc_post1 = rt_revsubclamp1col; + hcolfunc_post4 = rt_revsubclamp4cols; } else { - colfunc = R_DrawAddClampTranslatedColumnP_C; - hcolfunc_post1 = rt_tlateaddclamp1col; - hcolfunc_post4 = rt_tlateaddclamp4cols; + colfunc = R_DrawRevSubClampTranslatedColumnP_C; + hcolfunc_post1 = rt_tlaterevsubclamp1col; + hcolfunc_post4 = rt_tlaterevsubclamp4cols; } + return true; + + default: + return false; } - return true; } -ESPSResult R_SetPatchStyle (int style, fixed_t alpha, int translation, DWORD color) +static fixed_t GetAlpha(int type, fixed_t alpha) +{ + switch (type) + { + case STYLEALPHA_Zero: return 0; + case STYLEALPHA_One: return FRACUNIT; + case STYLEALPHA_Src: return alpha; + case STYLEALPHA_InvSrc: return FRACUNIT - alpha; + default: return 0; + } +} + +ESPSResult R_SetPatchStyle (FRenderStyle style, fixed_t alpha, int translation, DWORD color) { fixed_t fglevel, bglevel; - if (style == STYLE_OptFuzzy) + if (style.BlendOp == STYLEOP_FuzzOrAdd) { - style = (r_drawfuzz || !r_drawtrans) ? STYLE_Fuzzy : STYLE_Translucent; + style.BlendOp = (r_drawfuzz || !r_drawtrans) ? STYLEOP_Fuzz : STYLEOP_Add; } - else if (style == STYLE_SoulTrans) + else if (style.BlendOp == STYLEOP_FuzzOrSub) { - style = STYLE_Translucent; - alpha = (fixed_t)(FRACUNIT * transsouls); + style.BlendOp = (r_drawfuzz || !r_drawtrans) ? STYLEOP_Fuzz : STYLEOP_Sub; + } + else if (style.BlendOp == STYLEOP_FuzzOrRevSub) + { + style.BlendOp = (r_drawfuzz || !r_drawtrans) ? STYLEOP_Fuzz : STYLEOP_RevSub; } - alpha = clamp (alpha, 0, FRACUNIT); + if (style.Flags & STYLEF_TransSoulsAlpha) + { + alpha = fixed_t(transsouls * FRACUNIT); + } + else if (style.Flags & STYLEF_Alpha1) + { + alpha = FRACUNIT; + } + else + { + alpha = clamp (alpha, 0, FRACUNIT); + } dc_translation = NULL; if (translation != 0) @@ -1762,63 +2259,56 @@ ESPSResult R_SetPatchStyle (int style, fixed_t alpha, int translation, DWORD col } } basecolormapsave = basecolormap; - stencilling = false; hcolfunc_pre = R_DrawColumnHoriz; - switch (style) + // Check for special modes + if (style.BlendOp == STYLEOP_Fuzz) { - // Special modes - case STYLE_Fuzzy: colfunc = fuzzcolfunc; return DoDraw0; - - case STYLE_Shaded: + } + else if (style == LegacyRenderStyles[STYLE_Shaded]) + { // Shaded drawer only gets 16 levels because it saves memory. if ((alpha >>= 12) == 0) return DontDraw; colfunc = R_DrawShadedColumn; hcolfunc_post1 = rt_shaded1col; hcolfunc_post4 = rt_shaded4cols; - dc_color = fixedcolormap ? fixedcolormap[APART(color)] : basecolormap[APART(color)]; - dc_colormap = basecolormap = &shadetables[((16-alpha)*NUMCOLORMAPS)*256]; - if (fixedlightlev) + dc_color = fixedcolormap ? fixedcolormap[APART(color)] : basecolormap->Maps[APART(color)]; + dc_colormap = (basecolormap = &ShadeFakeColormap[16-alpha])->Maps; + if (fixedlightlev && !fixedcolormap) { dc_colormap += fixedlightlev; } return r_columnmethod ? DoDraw1 : DoDraw0; - - // Standard modes - case STYLE_Stencil: - dc_color = APART(color); - stencilling = true; - case STYLE_Normal: - fglevel = BL_ONE; - bglevel = BL_ZERO; - break; - - case STYLE_TranslucentStencil: - dc_color = APART(color); - stencilling = true; - case STYLE_Translucent: - fglevel = BL_SRC_ALPHA; - bglevel = BL_INV_SRC_ALPHA; - break; - - case STYLE_Add: - fglevel = BL_SRC_ALPHA; - bglevel = BL_ONE; - break; - - default: - return DontDraw; } - if (stencilling) + fglevel = GetAlpha(style.SrcAlpha, alpha); + bglevel = GetAlpha(style.DestAlpha, alpha); + + if (style.Flags & STYLEF_ColorIsFixed) { + int x = fglevel >> 10; + int r = RPART(color); + int g = GPART(color); + int b = BPART(color); + // dc_color is used by the rt_* routines. It is indexed into dc_srcblend. + dc_color = RGB32k[r>>3][g>>3][b>>3]; + if (style.Flags & STYLEF_InvertSource) + { + r = 255 - r; + g = 255 - g; + b = 255 - b; + } + // dc_srccolor is used by the R_Fill* routines. It is premultiplied + // with the alpha. + dc_srccolor = ((((r*x)>>4)<<20) | ((g*x)>>4) | ((((b)*x)>>4)<<10)) & 0x3feffbff; hcolfunc_pre = R_FillColumnHorizP; + dc_colormap = identitymap; } - return R_SetBlendFunc (fglevel, bglevel) ? + return R_SetBlendFunc (style.BlendOp, fglevel, bglevel, style.Flags) ? (r_columnmethod ? DoDraw1 : DoDraw0) : DontDraw; } @@ -1841,5 +2331,48 @@ bool R_GetTransMaskDrawers (fixed_t (**tmvline1)(), void (**tmvline4)()) *tmvline4 = tmvline4_addclamp; return true; } + if (colfunc == R_DrawSubClampColumnP_C) + { + *tmvline1 = tmvline1_subclamp; + *tmvline4 = tmvline4_subclamp; + return true; + } + if (colfunc == R_DrawRevSubClampColumnP_C) + { + *tmvline1 = tmvline1_revsubclamp; + *tmvline4 = tmvline4_revsubclamp; + return true; + } return false; } + +//========================================================================== +// +// FRenderStyle :: IsVisible +// +// Coupled with the given alpha, will this render style produce something +// visible on-screen? +// +//========================================================================== + +bool FRenderStyle::IsVisible(fixed_t alpha) const +{ + if (BlendOp == STYLEOP_None) + { + return false; + } + if (BlendOp == STYLEOP_Add || BlendOp == STYLEOP_RevSub) + { + if (Flags & STYLEF_Alpha1) + { + alpha = FRACUNIT; + } + else + { + alpha = clamp(alpha, 0, FRACUNIT); + } + return GetAlpha(SrcAlpha, alpha) != 0 || GetAlpha(DestAlpha, alpha) != FRACUNIT; + } + // Treat anything else as visible. + return true; +} diff --git a/src/r_draw.h b/src/r_draw.h index f26acc9a33..7193bfe300 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -25,7 +25,6 @@ #include "r_data.h" - extern "C" int ylookup[MAXHEIGHT]; extern "C" int dc_pitch; // [RH] Distance between rows @@ -38,6 +37,7 @@ extern "C" fixed_t dc_iscale; extern "C" fixed_t dc_texturemid; extern "C" fixed_t dc_texturefrac; extern "C" int dc_color; // [RH] For flat colors (no texturing) +extern "C" DWORD dc_srccolor; extern "C" DWORD *dc_srcblend; extern "C" DWORD *dc_destblend; @@ -122,6 +122,14 @@ void rt_addclamp1col (int hx, int sx, int yl, int yh); void rt_addclamp4cols (int sx, int yl, int yh); void rt_tlateaddclamp1col (int hx, int sx, int yl, int yh); void rt_tlateaddclamp4cols (int sx, int yl, int yh); +void rt_subclamp1col (int hx, int sx, int yl, int yh); +void rt_subclamp4cols (int sx, int yl, int yh); +void rt_tlatesubclamp1col (int hx, int sx, int yl, int yh); +void rt_tlatesubclamp4cols (int sx, int yl, int yh); +void rt_revsubclamp1col (int hx, int sx, int yl, int yh); +void rt_revsubclamp4cols (int sx, int yl, int yh); +void rt_tlaterevsubclamp1col (int hx, int sx, int yl, int yh); +void rt_tlaterevsubclamp4cols (int sx, int yl, int yh); extern "C" void rt_copy1col_asm (int hx, int sx, int yl, int yh); extern "C" void rt_copy4cols_asm (int sx, int yl, int yh); @@ -202,6 +210,8 @@ extern "C" const BYTE* ds_source; extern "C" int ds_color; // [RH] For flat color (no texturing) extern BYTE shadetables[NUMCOLORMAPS*16*256]; +extern FDynamicColormap ShadeFakeColormap[16]; +extern BYTE identitymap[256]; extern BYTE *dc_translation; // [RH] Double view pixels by detail mode @@ -224,7 +234,7 @@ enum ESPSResult DoDraw0, // draw this as if r_columnmethod is 0 DoDraw1, // draw this as if r_columnmethod is 1 }; -ESPSResult R_SetPatchStyle (int style, fixed_t alpha, int translation, DWORD color); +ESPSResult R_SetPatchStyle (FRenderStyle style, fixed_t alpha, int translation, DWORD color); // Call this after finished drawing the current thing, in case its // style was STYLE_Shade diff --git a/src/r_drawt.cpp b/src/r_drawt.cpp index d63fcf831b..5880fa7ce9 100644 --- a/src/r_drawt.cpp +++ b/src/r_drawt.cpp @@ -773,6 +773,394 @@ void rt_tlateaddclamp4cols (int sx, int yl, int yh) } while (--count); } +// Subtracts one span at hx to the screen at sx with clamping. +void rt_subclamp1col (int hx, int sx, int yl, int yh) +{ + BYTE *colormap; + BYTE *source; + BYTE *dest; + int count; + int pitch; + + count = yh-yl; + if (count < 0) + return; + count++; + + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + dest = ylookup[yl] + sx + dc_destorg; + source = &dc_temp[yl*4 + hx]; + pitch = dc_pitch; + colormap = dc_colormap; + + do { + DWORD a = (fg2rgb[colormap[*source]] | 0x40100400) - bg2rgb[*dest]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k[0][0][(a>>15) & a]; + source += 4; + dest += pitch; + } while (--count); +} + +// Subtracts all four spans to the screen starting at sx with clamping. +void rt_subclamp4cols (int sx, int yl, int yh) +{ + BYTE *colormap; + BYTE *source; + BYTE *dest; + int count; + int pitch; + + count = yh-yl; + if (count < 0) + return; + count++; + + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + dest = ylookup[yl] + sx + dc_destorg; + source = &dc_temp[yl*4]; + pitch = dc_pitch; + colormap = dc_colormap; + + do { + DWORD a = (fg2rgb[colormap[source[0]]] | 0x40100400) - bg2rgb[dest[0]]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[0] = RGB32k[0][0][(a>>15) & a]; + + a = (fg2rgb[colormap[source[1]]] | 0x40100400) - bg2rgb[dest[1]]; + b = a; + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[1] = RGB32k[0][0][(a>>15) & a]; + + a = (fg2rgb[colormap[source[2]]] | 0x40100400) - bg2rgb[dest[2]]; + b = a; + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[2] = RGB32k[0][0][(a>>15) & a]; + + a = (fg2rgb[colormap[source[3]]] | 0x40100400) - bg2rgb[dest[3]]; + b = a; + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[3] = RGB32k[0][0][(a>>15) & a]; + + source += 4; + dest += pitch; + } while (--count); +} + +// Translates and subtracts one span at hx to the screen at sx with clamping. +void rt_tlatesubclamp1col (int hx, int sx, int yl, int yh) +{ + BYTE *translation; + BYTE *colormap; + BYTE *source; + BYTE *dest; + int count; + int pitch; + + count = yh-yl; + if (count < 0) + return; + count++; + + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + dest = ylookup[yl] + sx + dc_destorg; + source = &dc_temp[yl*4 + hx]; + pitch = dc_pitch; + colormap = dc_colormap; + translation = dc_translation; + + do { + DWORD a = (fg2rgb[colormap[translation[*source]]] | 0x40100400) - bg2rgb[*dest]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k[0][0][(a>>15) & a]; + source += 4; + dest += pitch; + } while (--count); +} + +// Translates and subtracts all four spans to the screen starting at sx with clamping. +void rt_tlatesubclamp4cols (int sx, int yl, int yh) +{ + BYTE *translation; + BYTE *colormap; + BYTE *source; + BYTE *dest; + int count; + int pitch; + + count = yh-yl; + if (count < 0) + return; + count++; + + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + dest = ylookup[yl] + sx + dc_destorg; + source = &dc_temp[yl*4]; + pitch = dc_pitch; + colormap = dc_colormap; + translation = dc_translation; + + do { + DWORD a = (fg2rgb[colormap[translation[source[0]]]] | 0x40100400) - bg2rgb[dest[0]]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[0] = RGB32k[0][0][(a>>15) & a]; + + a = (fg2rgb[colormap[translation[source[1]]]] | 0x40100400) - bg2rgb[dest[1]]; + b = a; + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[1] = RGB32k[0][0][(a>>15) & a]; + + a = (fg2rgb[colormap[translation[source[2]]]] | 0x40100400) - bg2rgb[dest[2]]; + b = a; + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[2] = RGB32k[0][0][(a>>15) & a]; + + a = (fg2rgb[colormap[translation[source[3]]]] | 0x40100400) - bg2rgb[dest[3]]; + b = a; + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[3] = RGB32k[0][0][(a>>15) & a]; + + source += 4; + dest += pitch; + } while (--count); +} + +// Subtracts one span at hx from the screen at sx with clamping. +void rt_revsubclamp1col (int hx, int sx, int yl, int yh) +{ + BYTE *colormap; + BYTE *source; + BYTE *dest; + int count; + int pitch; + + count = yh-yl; + if (count < 0) + return; + count++; + + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + dest = ylookup[yl] + sx + dc_destorg; + source = &dc_temp[yl*4 + hx]; + pitch = dc_pitch; + colormap = dc_colormap; + + do { + DWORD a = (bg2rgb[*dest] | 0x40100400) - fg2rgb[colormap[*source]]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k[0][0][(a>>15) & a]; + source += 4; + dest += pitch; + } while (--count); +} + +// Subtracts all four spans from the screen starting at sx with clamping. +void rt_revsubclamp4cols (int sx, int yl, int yh) +{ + BYTE *colormap; + BYTE *source; + BYTE *dest; + int count; + int pitch; + + count = yh-yl; + if (count < 0) + return; + count++; + + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + dest = ylookup[yl] + sx + dc_destorg; + source = &dc_temp[yl*4]; + pitch = dc_pitch; + colormap = dc_colormap; + + do { + DWORD a = (bg2rgb[dest[0]] | 0x40100400) - fg2rgb[colormap[source[0]]]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[0] = RGB32k[0][0][(a>>15) & a]; + + a = (bg2rgb[dest[1]] | 0x40100400) - fg2rgb[colormap[source[1]]]; + b = a; + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[1] = RGB32k[0][0][(a>>15) & a]; + + a = (bg2rgb[dest[2]] | 0x40100400) - fg2rgb[colormap[source[2]]]; + b = a; + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[2] = RGB32k[0][0][(a>>15) & a]; + + a = (bg2rgb[dest[3]] | 0x40100400) - fg2rgb[colormap[source[3]]]; + b = a; + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[3] = RGB32k[0][0][(a>>15) & a]; + + source += 4; + dest += pitch; + } while (--count); +} + +// Translates and subtracts one span at hx from the screen at sx with clamping. +void rt_tlaterevsubclamp1col (int hx, int sx, int yl, int yh) +{ + BYTE *translation; + BYTE *colormap; + BYTE *source; + BYTE *dest; + int count; + int pitch; + + count = yh-yl; + if (count < 0) + return; + count++; + + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + dest = ylookup[yl] + sx + dc_destorg; + source = &dc_temp[yl*4 + hx]; + pitch = dc_pitch; + colormap = dc_colormap; + translation = dc_translation; + + do { + DWORD a = (bg2rgb[dest[0]] | 0x40100400) - fg2rgb[colormap[translation[source[0]]]]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k[0][0][(a>>15) & a]; + source += 4; + dest += pitch; + } while (--count); +} + +// Translates and subtracts all four spans from the screen starting at sx with clamping. +void rt_tlaterevsubclamp4cols (int sx, int yl, int yh) +{ + BYTE *translation; + BYTE *colormap; + BYTE *source; + BYTE *dest; + int count; + int pitch; + + count = yh-yl; + if (count < 0) + return; + count++; + + DWORD *fg2rgb = dc_srcblend; + DWORD *bg2rgb = dc_destblend; + dest = ylookup[yl] + sx + dc_destorg; + source = &dc_temp[yl*4]; + pitch = dc_pitch; + colormap = dc_colormap; + translation = dc_translation; + + do { + DWORD a = (bg2rgb[dest[0]] | 0x40100400) - fg2rgb[colormap[translation[source[0]]]]; + DWORD b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[0] = RGB32k[0][0][(a>>15) & a]; + + a = (bg2rgb[dest[1]] | 0x40100400) - fg2rgb[colormap[translation[source[1]]]]; + b = a; + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[1] = RGB32k[0][0][(a>>15) & a]; + + a = (bg2rgb[dest[2]] | 0x40100400) - fg2rgb[colormap[translation[source[2]]]]; + b = a; + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[2] = RGB32k[0][0][(a>>15) & a]; + + a = (bg2rgb[dest[3]] | 0x40100400) - fg2rgb[colormap[translation[source[3]]]]; + b = a; + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[3] = RGB32k[0][0][(a>>15) & a]; + + source += 4; + dest += pitch; + } while (--count); +} + // Copies all spans in all four columns to the screen starting at sx. // sx should be longword-aligned. void rt_draw4cols (int sx) diff --git a/src/r_main.cpp b/src/r_main.cpp index 7bfffb53ff..bd15a101aa 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -134,7 +134,7 @@ fixed_t FocalLengthY; float FocalLengthXfloat; int viewangleoffset; int validcount = 1; // increment every time a check is made -lighttable_t *basecolormap; // [RH] colormap currently drawing with +FDynamicColormap*basecolormap; // [RH] colormap currently drawing with int fixedlightlev; lighttable_t *fixedcolormap; float WallTMapScale; @@ -1077,7 +1077,7 @@ void R_SetupFrame (AActor *actor) if (player != NULL && gamestate != GS_TITLELEVEL && ((player->cheats & CF_CHASECAM) || (r_deathcamera && camera->health <= 0)) && - (camera->RenderStyle != STYLE_None) && + (camera->RenderStyle.BlendOp != STYLEOP_None) && !(camera->renderflags & RF_INVISIBLE) && camera->sprite != 0) // Sprite 0 is always TNT1 { diff --git a/src/r_main.h b/src/r_main.h index 4914a7bb38..abecbd971f 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -70,7 +70,7 @@ extern fixed_t centeryfrac; extern fixed_t yaspectmul; extern float iyaspectmulfloat; -extern BYTE* basecolormap; // [RH] Colormap for sector currently being drawn +extern FDynamicColormap*basecolormap; // [RH] Colormap for sector currently being drawn extern int validcount; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 93c0ce4df6..7e7c28e541 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -207,7 +207,7 @@ void R_MapPlane (int y, int x1) if (plane_shade) { // Determine lighting based on the span's distance from the viewer. - ds_colormap = basecolormap + (GETPALOOKUP ( + ds_colormap = basecolormap->Maps + (GETPALOOKUP ( FixedMul (GlobVis, abs (centeryfrac - (y << FRACBITS))), planeshade) << COLORMAPSHIFT); } @@ -237,6 +237,7 @@ void STACK_ARGS R_CalcTiltedLighting (fixed_t lval, fixed_t lend, int width) { fixed_t lstep; BYTE *lightfiller; + BYTE *basecolormapdata = basecolormap->Maps; int i = 0; lval = planeshade - lval; @@ -244,19 +245,19 @@ void STACK_ARGS R_CalcTiltedLighting (fixed_t lval, fixed_t lend, int width) if (width == 0 || lval == lend) { // Constant lighting - lightfiller = basecolormap + (GETPALOOKUP (-lval, 0) << COLORMAPSHIFT); + lightfiller = basecolormapdata + (GETPALOOKUP (-lval, 0) << COLORMAPSHIFT); } else if ((lstep = (lend - lval) / width) < 0) { // Going from dark to light if (lval < FRACUNIT) { // All bright - lightfiller = basecolormap; + lightfiller = basecolormapdata; } else { if (lval >= NUMCOLORMAPS*FRACUNIT) { // Starts beyond the dark end - BYTE *clight = basecolormap + ((NUMCOLORMAPS-1) << COLORMAPSHIFT); + BYTE *clight = basecolormapdata + ((NUMCOLORMAPS-1) << COLORMAPSHIFT); while (lval >= NUMCOLORMAPS*FRACUNIT && i <= width) { tiltlighting[i++] = clight; @@ -267,33 +268,33 @@ void STACK_ARGS R_CalcTiltedLighting (fixed_t lval, fixed_t lend, int width) } while (i <= width && lval >= 0) { - tiltlighting[i++] = basecolormap + ((lval >> FRACBITS) << COLORMAPSHIFT); + tiltlighting[i++] = basecolormapdata + ((lval >> FRACBITS) << COLORMAPSHIFT); lval += lstep; } - lightfiller = basecolormap; + lightfiller = basecolormapdata; } } else { // Going from light to dark if (lval >= (NUMCOLORMAPS-1)*FRACUNIT) { // All dark - lightfiller = basecolormap + ((NUMCOLORMAPS-1) << COLORMAPSHIFT); + lightfiller = basecolormapdata + ((NUMCOLORMAPS-1) << COLORMAPSHIFT); } else { while (lval < 0 && i <= width) { - tiltlighting[i++] = basecolormap; + tiltlighting[i++] = basecolormapdata; lval += lstep; } if (i > width) return; while (i <= width && lval < (NUMCOLORMAPS-1)*FRACUNIT) { - tiltlighting[i++] = basecolormap + ((lval >> FRACBITS) << COLORMAPSHIFT); + tiltlighting[i++] = basecolormapdata + ((lval >> FRACBITS) << COLORMAPSHIFT); lval += lstep; } - lightfiller = basecolormap + ((NUMCOLORMAPS-1) << COLORMAPSHIFT); + lightfiller = basecolormapdata + ((NUMCOLORMAPS-1) << COLORMAPSHIFT); } } @@ -1313,7 +1314,7 @@ sky1: { dc_colormap = fixedcolormap; } - else if (!fixedcolormap) + else { fakefixed = true; fixedcolormap = dc_colormap = NormalLight.Maps; @@ -1387,7 +1388,7 @@ void R_DrawNormalPlane (visplane_t *pl, fixed_t alpha, bool masked) GlobVis = FixedDiv (r_FloorVisibility, planeheight); if (fixedlightlev) - ds_colormap = basecolormap + fixedlightlev, plane_shade = false; + ds_colormap = basecolormap->Maps + fixedlightlev, plane_shade = false; else if (fixedcolormap) ds_colormap = fixedcolormap, plane_shade = false; else @@ -1532,11 +1533,11 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool masked) planelightfloat = -planelightfloat; if (fixedlightlev) - ds_colormap = basecolormap + fixedlightlev, plane_shade = false; + ds_colormap = basecolormap->Maps + fixedlightlev, plane_shade = false; else if (fixedcolormap) ds_colormap = fixedcolormap, plane_shade = false; else - ds_colormap = basecolormap, plane_shade = true; + ds_colormap = basecolormap->Maps, plane_shade = true; if (!plane_shade) { diff --git a/src/r_plane.h b/src/r_plane.h index c026286b7b..6994182b02 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -40,7 +40,7 @@ struct visplane_s int lightlevel; fixed_t xoffs, yoffs; // killough 2/28/98: Support scrolling flats int minx, maxx; - BYTE *colormap; // [RH] Support multiple colormaps + FDynamicColormap *colormap; // [RH] Support multiple colormaps fixed_t xscale, yscale; // [RH] Support flat scaling angle_t angle; // [RH] Support flat rotation ASkyViewpoint *skybox; // [RH] Support sky boxes diff --git a/src/r_polymost.cpp b/src/r_polymost.cpp index 3f36d3df23..7adb332196 100644 --- a/src/r_polymost.cpp +++ b/src/r_polymost.cpp @@ -1401,13 +1401,13 @@ void RP_Subsector (subsector_t *sub) frontsector = R_FakeFlat(frontsector, &tempsec, &floorlightlevel, &ceilinglightlevel, false); // killough 4/11/98 - basecolormap = frontsector->ColorMap->Maps; + basecolormap = frontsector->ColorMap; R_GetExtraLight (&ceilinglightlevel, frontsector->ceilingplane, frontsector->ExtraLights); // [RH] set foggy flag foggy = level.fadeto || frontsector->ColorMap->Fade || (level.flags & LEVEL_HASFADETABLE); r_actualextralight = foggy ? 0 : extralight << 4; - basecolormap = frontsector->ColorMap->Maps; + basecolormap = frontsector->ColorMap; /* ceilingplane = frontsector->ceilingplane.ZatPoint (viewx, viewy) > viewz || frontsector->ceilingpic == skyflatnum || (frontsector->CeilingSkyBox != NULL && frontsector->CeilingSkyBox->bAlways) || @@ -1427,7 +1427,7 @@ void RP_Subsector (subsector_t *sub) frontsector->CeilingSkyBox ) : NULL;*/ - basecolormap = frontsector->ColorMap->Maps; + basecolormap = frontsector->ColorMap; R_GetExtraLight (&floorlightlevel, frontsector->floorplane, frontsector->ExtraLights); // killough 3/7/98: Add (x,y) offsets to flats, add deep water check diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 116f994b18..9a3dda538c 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -166,7 +166,7 @@ static void BlastMaskedColumn (void (*blastfunc)(const BYTE *pixels, const FText // calculate lighting if (!fixedcolormap) { - dc_colormap = basecolormap + (GETPALOOKUP (rw_light, wallshade) << COLORMAPSHIFT); + dc_colormap = basecolormap->Maps + (GETPALOOKUP (rw_light, wallshade) << COLORMAPSHIFT); } dc_iscale = MulScale18 (MaskedSWall[dc_x], MaskedScaleY); @@ -205,7 +205,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) // [RH] modified because we don't use user-definable translucency maps ESPSResult drawmode; - drawmode = R_SetPatchStyle (curline->sidedef->Flags & WALLF_ADDTRANS ? STYLE_Add : STYLE_Translucent, + drawmode = R_SetPatchStyle (LegacyRenderStyles[curline->sidedef->Flags & WALLF_ADDTRANS ? STYLE_Add : STYLE_Translucent], curline->linedef->alpha < 255 ? curline->linedef->alpha<<8 : FRACUNIT, 0, 0); @@ -224,7 +224,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) // killough 4/13/98: get correct lightlevel for 2s normal textures const sector_t *sec = R_FakeFlat (frontsector, &tempsec, NULL, NULL, false); - basecolormap = sec->ColorMap->Maps; // [RH] Set basecolormap + basecolormap = sec->ColorMap; // [RH] Set basecolormap wallshade = ds->shade; rw_lightstep = ds->lightstep; @@ -276,7 +276,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) } if (fixedlightlev) - dc_colormap = basecolormap + fixedlightlev; + dc_colormap = basecolormap->Maps + fixedlightlev; else if (fixedcolormap) dc_colormap = fixedcolormap; @@ -403,6 +403,7 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t char bad; fixed_t light = rw_light - rw_lightstep; SDWORD yrepeat, texturemid, xoffset; + BYTE *basecolormapdata; // This function also gets used to draw skies. Unlike BUILD, skies are // drawn by visplane instead of by bunch, so these checks are invalid. @@ -423,6 +424,7 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t yrepeat = rw_pic->yScale >> (2 + shiftval); texturemid = dc_texturemid << (16 - shiftval); xoffset = rw_offset; + basecolormapdata = basecolormap->Maps; x = x1; //while ((umost[x] > dmost[x]) && (x <= x2)) x++; @@ -446,7 +448,7 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t if (!fixedcolormap) { // calculate lighting - dc_colormap = basecolormap + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); + dc_colormap = basecolormapdata + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); } dc_source = getcol (rw_pic, (lwal[x] + xoffset) >> FRACBITS); @@ -484,7 +486,7 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t for (z = 0; z < 4; ++z) { light += rw_lightstep; - palookupoffse[z] = basecolormap + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); + palookupoffse[z] = basecolormapdata + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); } } @@ -539,7 +541,7 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t if (!fixedcolormap) { // calculate lighting - dc_colormap = basecolormap + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); + dc_colormap = basecolormapdata + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); } dc_source = getcol (rw_pic, (lwal[x] + xoffset) >> FRACBITS); @@ -559,11 +561,11 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t void wallscan_striped (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal) { bool flooding = false; - BYTE *startcolormap = basecolormap; + FDynamicColormap *startcolormap = basecolormap; int startshade = wallshade; bool fogginess = foggy; - BYTE *floodcolormap = startcolormap; + FDynamicColormap *floodcolormap = startcolormap; int floodshade = startshade; bool floodfoggy = foggy; @@ -612,8 +614,8 @@ void wallscan_striped (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, } else { - basecolormap = el->Lights[i].Master->ColorMap->Maps; - fogginess = level.fadeto || el->Lights[i].Master->ColorMap->Fade; + basecolormap = el->Lights[i].Master->ColorMap; + fogginess = level.fadeto || basecolormap->Fade; wallshade = LIGHT2SHADE(curline->sidedef->GetLightLevel(fogginess, el->Lights[i].Master->lightlevel) + r_actualextralight); if (el->Lights[i].bFlooder) @@ -649,6 +651,7 @@ void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixe char bad; fixed_t light = rw_light - rw_lightstep; SDWORD yrepeat, texturemid, xoffset; + BYTE *basecolormapdata; if (rw_pic->UseType == FTexture::TEX_Null) { @@ -670,6 +673,7 @@ void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixe yrepeat = rw_pic->yScale >> (2 + shiftval); texturemid = dc_texturemid << (16 - shiftval); xoffset = rw_offset; + basecolormapdata = basecolormap->Maps; x = startx = x1; p = x + dc_destorg; @@ -691,7 +695,7 @@ void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixe if (!fixedcolormap) { // calculate lighting - dc_colormap = basecolormap + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); + dc_colormap = basecolormapdata + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); } dc_source = getcol (rw_pic, (lwal[x] + xoffset) >> FRACBITS); @@ -727,7 +731,7 @@ void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixe for (z = 0; z < 4; ++z) { light += rw_lightstep; - palookupoffse[z] = basecolormap + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); + palookupoffse[z] = basecolormapdata + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); } } @@ -780,7 +784,7 @@ void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixe if (!fixedcolormap) { // calculate lighting - dc_colormap = basecolormap + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); + dc_colormap = basecolormapdata + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); } dc_source = getcol (rw_pic, (lwal[x] + xoffset) >> FRACBITS); @@ -818,6 +822,7 @@ void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, char bad; fixed_t light = rw_light - rw_lightstep; SDWORD yrepeat, texturemid, xoffset; + BYTE *basecolormapdata; if (rw_pic->UseType == FTexture::TEX_Null) { @@ -840,6 +845,7 @@ void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, yrepeat = rw_pic->yScale >> (2 + shiftval); texturemid = dc_texturemid << (16 - shiftval); xoffset = rw_offset; + basecolormapdata = basecolormap->Maps; x = startx = x1; p = x + dc_destorg; @@ -861,7 +867,7 @@ void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, if (!fixedcolormap) { // calculate lighting - dc_colormap = basecolormap + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); + dc_colormap = basecolormapdata + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); } dc_source = getcol (rw_pic, (lwal[x] + xoffset) >> FRACBITS); @@ -897,7 +903,7 @@ void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, for (z = 0; z < 4; ++z) { light += rw_lightstep; - palookupoffse[z] = basecolormap + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); + palookupoffse[z] = basecolormapdata + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); } } @@ -953,7 +959,7 @@ void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, if (!fixedcolormap) { // calculate lighting - dc_colormap = basecolormap + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); + dc_colormap = basecolormapdata + (GETPALOOKUP (light, wallshade) << COLORMAPSHIFT); } dc_source = getcol (rw_pic, (lwal[x] + xoffset) >> FRACBITS); @@ -989,7 +995,7 @@ void R_RenderSegLoop () fixed_t xoffset = rw_offset; if (fixedlightlev) - dc_colormap = basecolormap + fixedlightlev; + dc_colormap = basecolormap->Maps + fixedlightlev; else if (fixedcolormap) dc_colormap = fixedcolormap; @@ -2347,11 +2353,11 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, rw_light = rw_lightleft + (x1 - WallSX1) * rw_lightstep; if (fixedlightlev) - dc_colormap = basecolormap + fixedlightlev; + dc_colormap = basecolormap->Maps + fixedlightlev; else if (fixedcolormap) dc_colormap = fixedcolormap; else if (!foggy && (decal->RenderFlags & RF_FULLBRIGHT)) - dc_colormap = basecolormap; + dc_colormap = basecolormap->Maps; else calclighting = true; @@ -2398,7 +2404,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, { if (calclighting) { // calculate lighting - dc_colormap = basecolormap + (GETPALOOKUP (rw_light, wallshade) << COLORMAPSHIFT); + dc_colormap = basecolormap->Maps + (GETPALOOKUP (rw_light, wallshade) << COLORMAPSHIFT); } WallSpriteColumn (R_DrawMaskedColumn); @@ -2409,7 +2415,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, { if (calclighting) { // calculate lighting - dc_colormap = basecolormap + (GETPALOOKUP (rw_light, wallshade) << COLORMAPSHIFT); + dc_colormap = basecolormap->Maps + (GETPALOOKUP (rw_light, wallshade) << COLORMAPSHIFT); } rt_initcols(); for (int zz = 4; zz; --zz) @@ -2424,7 +2430,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, { if (calclighting) { // calculate lighting - dc_colormap = basecolormap + (GETPALOOKUP (rw_light, wallshade) << COLORMAPSHIFT); + dc_colormap = basecolormap->Maps + (GETPALOOKUP (rw_light, wallshade) << COLORMAPSHIFT); } WallSpriteColumn (R_DrawMaskedColumn); diff --git a/src/r_things.cpp b/src/r_things.cpp index 750f5fc71f..b39ecde2e8 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -453,7 +453,7 @@ void R_InitSkins (void) sndlumps[j] = -1; skins[i].namespc = Wads.GetLumpNamespace (base); - SC_OpenLumpNum (base, "S_SKIN"); + FScanner sc(base, "S_SKIN"); intname = 0; crouchname = 0; @@ -462,18 +462,18 @@ void R_InitSkins (void) transtype = NULL; // Data is stored as "key = data". - while (SC_GetString ()) + while (sc.GetString ()) { - strncpy (key, sc_String, sizeof(key)-1); - if (!SC_GetString() || sc_String[0] != '=') + strncpy (key, sc.String, sizeof(key)-1); + if (!sc.GetString() || sc.String[0] != '=') { Printf (PRINT_BOLD, "Bad format for skin %d: %s\n", i, key); break; } - SC_GetString (); + sc.GetString (); if (0 == stricmp (key, "name")) { - strncpy (skins[i].name, sc_String, 16); + strncpy (skins[i].name, sc.String, 16); for (j = 0; (size_t)j < i; j++) { if (stricmp (skins[i].name, skins[j].name) == 0) @@ -488,27 +488,27 @@ void R_InitSkins (void) else if (0 == stricmp (key, "sprite")) { for (j = 3; j >= 0; j--) - sc_String[j] = toupper (sc_String[j]); - intname = *((DWORD *)sc_String); + sc.String[j] = toupper (sc.String[j]); + intname = *((DWORD *)sc.String); } else if (0 == stricmp (key, "crouchsprite")) { for (j = 3; j >= 0; j--) - sc_String[j] = toupper (sc_String[j]); - crouchname = *((DWORD *)sc_String); + sc.String[j] = toupper (sc.String[j]); + crouchname = *((DWORD *)sc.String); } else if (0 == stricmp (key, "face")) { for (j = 2; j >= 0; j--) - skins[i].face[j] = toupper (sc_String[j]); + skins[i].face[j] = toupper (sc.String[j]); } else if (0 == stricmp (key, "gender")) { - skins[i].gender = D_GenderToInt (sc_String); + skins[i].gender = D_GenderToInt (sc.String); } else if (0 == stricmp (key, "scale")) { - skins[i].Scale = clamp (FLOAT2FIXED(atof (sc_String)), 1, 256*FRACUNIT); + skins[i].Scale = clamp (FLOAT2FIXED(atof (sc.String)), 1, 256*FRACUNIT); } else if (0 == stricmp (key, "game")) { @@ -521,7 +521,7 @@ void R_InitSkins (void) transtype = basetype; - if (stricmp (sc_String, "heretic") == 0) + if (stricmp (sc.String, "heretic") == 0) { if (gameinfo.gametype == GAME_Doom) { @@ -533,7 +533,7 @@ void R_InitSkins (void) remove = true; } } - else if (stricmp (sc_String, "strife") == 0) + else if (stricmp (sc.String, "strife") == 0) { if (gameinfo.gametype != GAME_Strife) { @@ -558,7 +558,7 @@ void R_InitSkins (void) } else if (0 == stricmp (key, "class")) { // [GRB] Define the skin for a specific player class - int pclass = D_PlayerClassToInt (sc_String); + int pclass = D_PlayerClassToInt (sc.String); if (pclass < 0) { @@ -570,11 +570,11 @@ void R_InitSkins (void) } else if (key[0] == '*') { // Player sound replacment (ZDoom extension) - int lump = Wads.CheckNumForName (sc_String, skins[i].namespc); + int lump = Wads.CheckNumForName (sc.String, skins[i].namespc); if (lump == -1) { - lump = Wads.CheckNumForFullName (sc_String); - if (lump == -1) lump = Wads.CheckNumForName (sc_String, ns_sounds); + lump = Wads.CheckNumForFullName (sc.String); + if (lump == -1) lump = Wads.CheckNumForName (sc.String, ns_sounds); } if (lump != -1) { @@ -604,16 +604,16 @@ void R_InitSkins (void) { if (stricmp (key, skinsoundnames[j][0]) == 0) { - sndlumps[j] = Wads.CheckNumForName (sc_String, skins[i].namespc); + sndlumps[j] = Wads.CheckNumForName (sc.String, skins[i].namespc); if (sndlumps[j] == -1) { // Replacement not found, try finding it in the global namespace - sndlumps[j] = Wads.CheckNumForFullName (sc_String); - if (sndlumps[j] == -1) sndlumps[j] = Wads.CheckNumForName (sc_String, ns_sounds); + sndlumps[j] = Wads.CheckNumForFullName (sc.String); + if (sndlumps[j] == -1) sndlumps[j] = Wads.CheckNumForName (sc.String, ns_sounds); } } } //if (j == 8) - // Printf ("Funny info for skin %i: %s = %s\n", i, key, sc_String); + // Printf ("Funny info for skin %i: %s = %s\n", i, key, sc.String); } } @@ -751,8 +751,6 @@ void R_InitSkins (void) } } - SC_Close (); - // Make sure face prefix is a full 3 chars if (skins[i].face[1] == 0 || skins[i].face[2] == 0) { @@ -1095,7 +1093,7 @@ void R_DrawVisSprite (vissprite_t *vis) dc_colormap = vis->colormap; - mode = R_SetPatchStyle (vis->RenderStyle, vis->alpha, vis->Translation, vis->AlphaColor); + mode = R_SetPatchStyle (vis->RenderStyle, vis->alpha, vis->Translation, vis->FillColor); if (mode != DontDraw) { @@ -1192,10 +1190,10 @@ void R_ProjectSprite (AActor *thing, int fakeside) sector_t* heightsec; // killough 3/27/98 + // Don't waste time projecting sprites that are definitely not visible. if (thing == NULL || (thing->renderflags & RF_INVISIBLE) || - thing->RenderStyle == STYLE_None || - (thing->RenderStyle >= STYLE_Translucent && thing->alpha <= 0)) + !thing->RenderStyle.IsVisible(thing->alpha)) { return; } @@ -1385,7 +1383,7 @@ void R_ProjectSprite (AActor *thing, int fakeside) fixed_t yscale = DivScale16(thing->scaleY, tex->yScale); vis->renderflags = thing->renderflags; vis->RenderStyle = thing->RenderStyle; - vis->AlphaColor = thing->alphacolor; + vis->FillColor = thing->fillcolor; vis->xscale = xscale; vis->yscale = Scale (InvZtoScale, yscale, tz)>>4; vis->idepth = (DWORD)DivScale32 (1, tz) >> 1; // tz is 20.12, so idepth ought to be 12.20, but @@ -1417,11 +1415,42 @@ void R_ProjectSprite (AActor *thing, int fakeside) if (vis->x1 > x1) vis->startfrac += vis->xiscale*(vis->x1-x1); - + + // The software renderer cannot invert the source without inverting the overlay + // too. That means if the source is inverted, we need to do the reverse of what + // the invert overlay flag says to do. + INTBOOL invertcolormap = (vis->RenderStyle.Flags & STYLEF_InvertOverlay); + + if (vis->RenderStyle.Flags & STYLEF_InvertSource) + { + invertcolormap = !invertcolormap; + } + + FDynamicColormap *mybasecolormap = basecolormap; + + if (vis->RenderStyle.Flags & STYLEF_FadeToBlack) + { + if (invertcolormap) + { + // Fade to white + mybasecolormap = GetSpecialLights(mybasecolormap->Color, MAKERGB(255,255,255), mybasecolormap->Desaturate); + invertcolormap = false; + } + else + { + // Fade to black + mybasecolormap = GetSpecialLights(mybasecolormap->Color, MAKERGB(0,0,0), mybasecolormap->Desaturate); + } + } + // get light level if (fixedlightlev) { - vis->colormap = basecolormap + fixedlightlev; + if (invertcolormap) + { + mybasecolormap = GetSpecialLights(mybasecolormap->Color, mybasecolormap->Fade.InverseColor(), mybasecolormap->Desaturate); + } + vis->colormap = mybasecolormap->Maps + fixedlightlev; } else if (fixedcolormap) { @@ -1431,12 +1460,20 @@ void R_ProjectSprite (AActor *thing, int fakeside) else if (!foggy && (thing->renderflags & RF_FULLBRIGHT)) { // full bright - vis->colormap = basecolormap; // [RH] Use basecolormap + if (invertcolormap) + { + mybasecolormap = GetSpecialLights(mybasecolormap->Color, mybasecolormap->Fade.InverseColor(), mybasecolormap->Desaturate); + } + vis->colormap = mybasecolormap->Maps; } else { // diminished light - vis->colormap = basecolormap + (GETPALOOKUP ( + if (invertcolormap) + { + mybasecolormap = GetSpecialLights(mybasecolormap->Color, mybasecolormap->Fade.InverseColor(), mybasecolormap->Desaturate); + } + vis->colormap = mybasecolormap->Maps + (GETPALOOKUP ( (fixed_t)DivScale12 (r_SpriteVisibility, tz), spriteshade) << COLORMAPSHIFT); } } @@ -1587,9 +1624,41 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_ { vis->alpha = owner->alpha; vis->RenderStyle = owner->RenderStyle; + + // The software renderer cannot invert the source without inverting the overlay + // too. That means if the source is inverted, we need to do the reverse of what + // the invert overlay flag says to do. + INTBOOL invertcolormap = (vis->RenderStyle.Flags & STYLEF_InvertOverlay); + + if (vis->RenderStyle.Flags & STYLEF_InvertSource) + { + invertcolormap = !invertcolormap; + } + + FDynamicColormap *mybasecolormap = basecolormap; + + if (vis->RenderStyle.Flags & STYLEF_FadeToBlack) + { + if (invertcolormap) + { + // Fade to white + mybasecolormap = GetSpecialLights(mybasecolormap->Color, MAKERGB(255,255,255), mybasecolormap->Desaturate); + invertcolormap = false; + } + else + { + // Fade to black + mybasecolormap = GetSpecialLights(mybasecolormap->Color, MAKERGB(0,0,0), mybasecolormap->Desaturate); + } + } + if (fixedlightlev) { - vis->colormap = basecolormap + fixedlightlev; + if (invertcolormap) + { + mybasecolormap = GetSpecialLights(mybasecolormap->Color, mybasecolormap->Fade.InverseColor(), mybasecolormap->Desaturate); + } + vis->colormap = mybasecolormap->Maps + fixedlightlev; } else if (fixedcolormap) { @@ -1599,12 +1668,20 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_ else if (!foggy && psp->state->GetFullbright()) { // full bright - vis->colormap = basecolormap; // [RH] use basecolormap + if (invertcolormap) + { + mybasecolormap = GetSpecialLights(mybasecolormap->Color, mybasecolormap->Fade.InverseColor(), mybasecolormap->Desaturate); + } + vis->colormap = mybasecolormap->Maps; // [RH] use basecolormap } else { // local light - vis->colormap = basecolormap + (GETPALOOKUP (0, spriteshade) << COLORMAPSHIFT); + if (invertcolormap) + { + mybasecolormap = GetSpecialLights(mybasecolormap->Color, mybasecolormap->Fade.InverseColor(), mybasecolormap->Desaturate); + } + vis->colormap = mybasecolormap->Maps + (GETPALOOKUP (0, spriteshade) << COLORMAPSHIFT); } if (camera->Inventory != NULL) { @@ -1648,7 +1725,7 @@ void R_DrawPlayerSprites (void) r_actualextralight = foggy ? 0 : extralight << 4; // [RH] set basecolormap - basecolormap = sec->ColorMap->Maps; + basecolormap = sec->ColorMap; // get light level lightnum = ((floorlight + ceilinglight) >> 1) + r_actualextralight; diff --git a/src/r_translate.cpp b/src/r_translate.cpp index 39c186bbc1..2ea65daab4 100644 --- a/src/r_translate.cpp +++ b/src/r_translate.cpp @@ -471,6 +471,11 @@ void R_InitTranslationTables () // Full alpha for (i = 0; i < 16; ++i) { + ShadeFakeColormap[i].Color = -1; + ShadeFakeColormap[i].Desaturate = -1; + ShadeFakeColormap[i].Next = NULL; + ShadeFakeColormap[i].Maps = table; + for (j = 0; j < NUMCOLORMAPS; ++j) { int a = (NUMCOLORMAPS - j) * 256 / NUMCOLORMAPS * (16-i); @@ -482,6 +487,16 @@ void R_InitTranslationTables () table += 256; } } + for (i = 0; i < NUMCOLORMAPS*16*256; ++i) + { + assert(shadetables[i] <= 64); + } + + // Set up a guaranteed identity map + for (i = 0; i < 256; ++i) + { + identitymap[i] = i; + } } void R_DeinitTranslationTables() diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index cafaf2bf09..8527d25aa5 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -200,11 +200,11 @@ static int S_AddPlayerClass (const char *name); static int S_AddPlayerGender (int classnum, int gender); static int S_FindPlayerClass (const char *name); static int S_LookupPlayerSound (int classidx, int gender, int refid); -static void S_ParsePlayerSoundCommon (FString &pclass, int &gender, int &refid); +static void S_ParsePlayerSoundCommon (FScanner &sc, FString &pclass, int &gender, int &refid); static void S_AddSNDINFO (int lumpnum); static void S_AddBloodSFX (int lumpnum); static void S_AddStrifeVoice (int lumpnum); -static int S_AddSound (const char *logicalname, int lumpnum); +static int S_AddSound (const char *logicalname, int lumpnum, FScanner *sc=NULL); // EXTERNAL DATA DECLARATIONS ---------------------------------------------- @@ -470,14 +470,14 @@ int S_FindSoundTentative (const char *name) // lump. Otherwise, adds the new mapping by using S_AddSoundLump(). //========================================================================== -int S_AddSound (const char *logicalname, const char *lumpname) +int S_AddSound (const char *logicalname, const char *lumpname, FScanner *sc) { int lump = Wads.CheckNumForFullName (lumpname); if (lump == -1) lump = Wads.CheckNumForName (lumpname, ns_sounds); return S_AddSound (logicalname, lump); } -static int S_AddSound (const char *logicalname, int lumpnum) +static int S_AddSound (const char *logicalname, int lumpnum, FScanner *sc) { int sfxid; @@ -489,7 +489,14 @@ static int S_AddSound (const char *logicalname, int lumpnum) if (sfx->bPlayerReserve) { - SC_ScriptError ("Sounds that are reserved for players cannot be reassigned"); + if (sc != NULL) + { + sc->ScriptError ("Sounds that are reserved for players cannot be reassigned"); + } + else + { + I_Error ("Sounds that are reserved for players cannot be reassigned"); + } } // Redefining a player compatibility sound will redefine the target instead. if (sfx->bPlayerCompat) @@ -867,23 +874,23 @@ static void S_AddSNDINFO (int lump) bool skipToEndIf; TArray list; - SC_OpenLumpNum (lump, "SNDINFO"); + FScanner sc(lump, "SNDINFO"); skipToEndIf = false; - while (SC_GetString ()) + while (sc.GetString ()) { if (skipToEndIf) { - if (SC_Compare ("$endif")) + if (sc.Compare ("$endif")) { skipToEndIf = false; } continue; } - if (sc_String[0] == '$') + if (sc.String[0] == '$') { // Got a command - switch (SC_MatchString (SICommandStrings)) + switch (sc.MatchString (SICommandStrings)) { case SI_Ambient: { // $ambient [point [atten] | surround | [world]] @@ -891,20 +898,20 @@ static void S_AddSNDINFO (int lump) // AmbientSound *ambient, dummy; - SC_MustGetNumber (); - if (sc_Number < 0 || sc_Number > 255) + sc.MustGetNumber (); + if (sc.Number < 0 || sc.Number > 255) { - Printf ("Bad ambient index (%d)\n", sc_Number); + Printf ("Bad ambient index (%d)\n", sc.Number); ambient = &dummy; } - else if (Ambients[sc_Number] == NULL) + else if (Ambients[sc.Number] == NULL) { ambient = new AmbientSound; - Ambients[sc_Number] = ambient; + Ambients[sc.Number] = ambient; } else { - ambient = Ambients[sc_Number]; + ambient = Ambients[sc.Number]; } ambient->type = 0; ambient->periodmin = 0; @@ -913,22 +920,22 @@ static void S_AddSNDINFO (int lump) ambient->attenuation = 0; ambient->sound = ""; - SC_MustGetString (); - ambient->sound = sc_String; + sc.MustGetString (); + ambient->sound = sc.String; ambient->attenuation = 0; - SC_MustGetString (); - if (SC_Compare ("point")) + sc.MustGetString (); + if (sc.Compare ("point")) { float attenuation; ambient->type = POSITIONAL; - SC_MustGetString (); + sc.MustGetString (); - if (IsFloat (sc_String)) + if (IsFloat (sc.String)) { - attenuation = atof (sc_String); - SC_MustGetString (); + attenuation = atof (sc.String); + sc.MustGetString (); if (attenuation > 0) { ambient->attenuation = attenuation; @@ -943,45 +950,45 @@ static void S_AddSNDINFO (int lump) ambient->attenuation = 1; } } - else if (SC_Compare ("surround")) + else if (sc.Compare ("surround")) { ambient->type = SURROUND; - SC_MustGetString (); + sc.MustGetString (); ambient->attenuation = -1; } else { // World is an optional keyword - if (SC_Compare ("world")) + if (sc.Compare ("world")) { - SC_MustGetString (); + sc.MustGetString (); } } - if (SC_Compare ("continuous")) + if (sc.Compare ("continuous")) { ambient->type |= CONTINUOUS; } - else if (SC_Compare ("random")) + else if (sc.Compare ("random")) { ambient->type |= RANDOM; - SC_MustGetFloat (); - ambient->periodmin = (int)(sc_Float * TICRATE); - SC_MustGetFloat (); - ambient->periodmax = (int)(sc_Float * TICRATE); + sc.MustGetFloat (); + ambient->periodmin = (int)(sc.Float * TICRATE); + sc.MustGetFloat (); + ambient->periodmax = (int)(sc.Float * TICRATE); } - else if (SC_Compare ("periodic")) + else if (sc.Compare ("periodic")) { ambient->type |= PERIODIC; - SC_MustGetFloat (); - ambient->periodmin = (int)(sc_Float * TICRATE); + sc.MustGetFloat (); + ambient->periodmin = (int)(sc.Float * TICRATE); } else { - Printf ("Unknown ambient type (%s)\n", sc_String); + Printf ("Unknown ambient type (%s)\n", sc.String); } - SC_MustGetFloat (); - ambient->volume = sc_Float; + sc.MustGetFloat (); + ambient->volume = sc.Float; if (ambient->volume > 1) ambient->volume = 1; else if (ambient->volume < 0) @@ -994,13 +1001,13 @@ static void S_AddSNDINFO (int lump) level_info_t *info; char temp[16]; - SC_MustGetNumber (); - sprintf (temp, "MAP%02d", sc_Number); + sc.MustGetNumber (); + sprintf (temp, "MAP%02d", sc.Number); info = FindLevelInfo (temp); - SC_MustGetString (); - if (info->mapname[0] && (!(info->flags&LEVEL_MUSICDEFINED))) + sc.MustGetString (); + if (info->mapname[0] && (!(info->flags & LEVEL_MUSICDEFINED))) { - ReplaceString (&info->music, sc_String); + ReplaceString (&info->music, sc.String); } } break; @@ -1010,7 +1017,7 @@ static void S_AddSNDINFO (int lump) break; case SI_ArchivePath: - SC_MustGetString (); // Unused for now + sc.MustGetString (); // Unused for now break; case SI_PlayerSound: { @@ -1018,8 +1025,8 @@ static void S_AddSNDINFO (int lump) FString pclass; int gender, refid; - S_ParsePlayerSoundCommon (pclass, gender, refid); - S_AddPlayerSound (pclass, gender, refid, sc_String); + S_ParsePlayerSoundCommon (sc, pclass, gender, refid); + S_AddPlayerSound (pclass, gender, refid, sc.String); } break; @@ -1028,11 +1035,11 @@ static void S_AddSNDINFO (int lump) FString pclass; int gender, refid, targid; - S_ParsePlayerSoundCommon (pclass, gender, refid); - targid = S_FindSoundNoHash (sc_String); + S_ParsePlayerSoundCommon (sc, pclass, gender, refid); + targid = S_FindSoundNoHash (sc.String); if (!S_sfx[targid].bPlayerReserve) { - SC_ScriptError ("%s is not a player sound", sc_String); + sc.ScriptError ("%s is not a player sound", sc.String); } S_DupPlayerSound (pclass, gender, refid, targid); } @@ -1044,8 +1051,8 @@ static void S_AddSNDINFO (int lump) int gender, refid; int sfxfrom, aliasto; - S_ParsePlayerSoundCommon (pclass, gender, refid); - sfxfrom = S_AddSound (sc_String, -1); + S_ParsePlayerSoundCommon (sc, pclass, gender, refid); + sfxfrom = S_AddSound (sc.String, -1, &sc); aliasto = S_LookupPlayerSound (pclass, gender, refid); S_sfx[sfxfrom].link = aliasto; S_sfx[sfxfrom].bPlayerCompat = true; @@ -1058,8 +1065,8 @@ static void S_AddSNDINFO (int lump) int gender, refid; int soundnum; - S_ParsePlayerSoundCommon (pclass, gender, refid); - soundnum = S_FindSoundTentative (sc_String); + S_ParsePlayerSoundCommon (sc, pclass, gender, refid); + soundnum = S_FindSoundTentative (sc.String); S_AddPlayerSoundExisting (pclass, gender, refid, soundnum); } break; @@ -1068,14 +1075,14 @@ static void S_AddSNDINFO (int lump) // $alias int sfxfrom; - SC_MustGetString (); - sfxfrom = S_AddSound (sc_String, -1); - SC_MustGetString (); + sc.MustGetString (); + sfxfrom = S_AddSound (sc.String, -1, &sc); + sc.MustGetString (); if (S_sfx[sfxfrom].bPlayerCompat) { sfxfrom = S_sfx[sfxfrom].link; } - S_sfx[sfxfrom].link = S_FindSoundTentative (sc_String); + S_sfx[sfxfrom].link = S_FindSoundTentative (sc.String); } break; @@ -1083,12 +1090,12 @@ static void S_AddSNDINFO (int lump) // $limit int sfx; - SC_MustGetString (); - sfx = S_FindSoundTentative (sc_String); - SC_MustGetNumber (); - //S_sfx[sfx].MaxChannels = clamp (sc_Number, 0, 255); + sc.MustGetString (); + sfx = S_FindSoundTentative (sc.String); + sc.MustGetNumber (); + //S_sfx[sfx].MaxChannels = clamp (sc.Number, 0, 255); //Can't use clamp because of GCC bugs - S_sfx[sfx].MaxChannels = MIN (MAX (sc_Number, 0), 255); + S_sfx[sfx].MaxChannels = MIN (MAX (sc.Number, 0), 255); } break; @@ -1096,8 +1103,8 @@ static void S_AddSNDINFO (int lump) // $singular int sfx; - SC_MustGetString (); - sfx = S_FindSoundTentative (sc_String); + sc.MustGetString (); + sfx = S_FindSoundTentative (sc.String); S_sfx[sfx].bSingular = true; } break; @@ -1106,17 +1113,17 @@ static void S_AddSNDINFO (int lump) // $pitchshift int sfx; - SC_MustGetString (); - sfx = S_FindSoundTentative (sc_String); - SC_MustGetNumber (); - S_sfx[sfx].PitchMask = (1 << clamp (sc_Number, 0, 7)) - 1; + sc.MustGetString (); + sfx = S_FindSoundTentative (sc.String); + sc.MustGetNumber (); + S_sfx[sfx].PitchMask = (1 << clamp (sc.Number, 0, 7)) - 1; } break; case SI_PitchShiftRange: // $pitchshiftrange - SC_MustGetNumber (); - CurrentPitchMask = (1 << clamp (sc_Number, 0, 7)) - 1; + sc.MustGetNumber (); + CurrentPitchMask = (1 << clamp (sc.Number, 0, 7)) - 1; break; case SI_Random: { @@ -1124,15 +1131,15 @@ static void S_AddSNDINFO (int lump) FRandomSoundList random; list.Clear (); - SC_MustGetString (); - random.SfxHead = S_AddSound (sc_String, -1); - SC_MustGetStringName ("{"); - while (SC_GetString () && !SC_Compare ("}")) + sc.MustGetString (); + random.SfxHead = S_AddSound (sc.String, -1, &sc); + sc.MustGetStringName ("{"); + while (sc.GetString () && !sc.Compare ("}")) { - WORD sfxto = S_FindSoundTentative (sc_String); + WORD sfxto = S_FindSoundTentative (sc.String); if (sfxto == random.SfxHead) { - Printf("Definition of random sound '%s' refers to itself recursively.", sc_String); + Printf("Definition of random sound '%s' refers to itself recursively.", sc.String); continue; } list.Push (sfxto); @@ -1153,11 +1160,11 @@ static void S_AddSNDINFO (int lump) break; case SI_MusicVolume: { - SC_MustGetString(); - FString musname (sc_String); - SC_MustGetFloat(); + sc.MustGetString(); + FString musname (sc.String); + sc.MustGetFloat(); FMusicVolume *mv = (FMusicVolume *)M_Malloc (sizeof(*mv) + musname.Len()); - mv->Volume = sc_Float; + mv->Volume = sc.Float; strcpy (mv->MusicName, musname); mv->Next = MusicVolumes; MusicVolumes = mv; @@ -1165,14 +1172,14 @@ static void S_AddSNDINFO (int lump) break; case SI_MidiDevice: { - SC_MustGetString(); - FName nm = sc_String; - SC_MustGetString(); - if (SC_Compare("timidity")) MidiDevices[nm] = 1; - else if (SC_Compare("standard")) MidiDevices[nm] = 0; - else if (SC_Compare("opl")) MidiDevices[nm] = 2; - else if (SC_Compare("default")) MidiDevices[nm] = -1; - else SC_ScriptError("Unknown MIDI device %s\n", sc_String); + sc.MustGetString(); + FName nm = sc.String; + sc.MustGetString(); + if (sc.Compare("timidity")) MidiDevices[nm] = 1; + else if (sc.Compare("standard")) MidiDevices[nm] = 0; + else if (sc.Compare("opl")) MidiDevices[nm] = 2; + else if (sc.Compare("default")) MidiDevices[nm] = -1; + else sc.ScriptError("Unknown MIDI device %s\n", sc.String); } break; @@ -1207,12 +1214,11 @@ static void S_AddSNDINFO (int lump) } else { // Got a logical sound mapping - FString name (sc_String); - SC_MustGetString (); - S_AddSound (name, sc_String); + FString name (sc.String); + sc.MustGetString (); + S_AddSound (name, sc.String, &sc); } } - SC_Close (); } //========================================================================== @@ -1273,21 +1279,21 @@ static void S_AddStrifeVoice (int lumpnum) // (player class, gender, and ref id) //========================================================================== -static void S_ParsePlayerSoundCommon (FString &pclass, int &gender, int &refid) +static void S_ParsePlayerSoundCommon (FScanner &sc, FString &pclass, int &gender, int &refid) { - SC_MustGetString (); - pclass = sc_String; - SC_MustGetString (); - gender = D_GenderToInt (sc_String); - SC_MustGetString (); - refid = S_FindSoundNoHash (sc_String); + sc.MustGetString (); + pclass = sc.String; + sc.MustGetString (); + gender = D_GenderToInt (sc.String); + sc.MustGetString (); + refid = S_FindSoundNoHash (sc.String); if (refid != 0 && !S_sfx[refid].bPlayerReserve && !S_sfx[refid].bTentative) { - SC_ScriptError ("%s has already been used for a non-player sound.", sc_String); + sc.ScriptError ("%s has already been used for a non-player sound.", sc.String); } if (refid == 0) { - refid = S_AddSound (sc_String, -1); + refid = S_AddSound (sc.String, -1, &sc); S_sfx[refid].bTentative = true; } if (S_sfx[refid].bTentative) @@ -1296,7 +1302,7 @@ static void S_ParsePlayerSoundCommon (FString &pclass, int &gender, int &refid) S_sfx[refid].bTentative = false; S_sfx[refid].bPlayerReserve = true; } - SC_MustGetString (); + sc.MustGetString (); } //========================================================================== diff --git a/src/s_environment.cpp b/src/s_environment.cpp index 999af699b7..4ff1cd21b5 100644 --- a/src/s_environment.cpp +++ b/src/s_environment.cpp @@ -465,8 +465,9 @@ FArchive &operator<< (FArchive &arc, ReverbContainer *&env) return arc; } -static void ReadEAX () +static void ReadEAX (int lump, const char *lumpname) { + FScanner sc; const ReverbContainer *def; ReverbContainer *newenv; REVERB_PROPERTIES props; @@ -475,45 +476,46 @@ static void ReadEAX () bool inited[NUM_EAX_FIELDS]; BYTE bools[32]; - while (SC_GetString ()) + sc.OpenLumpNum(lump, lumpname); + while (sc.GetString ()) { - name = copystring (sc_String); - SC_MustGetNumber (); - id1 = sc_Number; - SC_MustGetNumber (); - id2 = sc_Number; - SC_MustGetStringName ("{"); + name = copystring (sc.String); + sc.MustGetNumber (); + id1 = sc.Number; + sc.MustGetNumber (); + id2 = sc.Number; + sc.MustGetStringName ("{"); memset (inited, 0, sizeof(inited)); props.Flags = 0; - while (SC_MustGetString (), NUM_EAX_FIELDS > (i = SC_MustMatchString (EAXFieldNames))) + while (sc.MustGetString (), NUM_EAX_FIELDS > (i = sc.MustMatchString (EAXFieldNames))) { if (EAXFields[i].Float) { - SC_MustGetFloat (); - props.*EAXFields[i].Float = clamp (sc_Float, + sc.MustGetFloat (); + props.*EAXFields[i].Float = clamp (sc.Float, double(EAXFields[i].Min)/1000, double(EAXFields[i].Max)/1000); } else if (EAXFields[i].Int) { - SC_MustGetNumber (); - props.*EAXFields[i].Int = (j = clamp (sc_Number, + sc.MustGetNumber (); + props.*EAXFields[i].Int = (j = clamp (sc.Number, EAXFields[i].Min, EAXFields[i].Max)); - if (i == 0 && j != sc_Number) + if (i == 0 && j != sc.Number) { - SC_ScriptError ("The Environment field is out of range."); + sc.ScriptError ("The Environment field is out of range."); } } else { - SC_MustGetString (); - bools[EAXFields[i].Flag] = SC_MustMatchString (BoolNames); + sc.MustGetString (); + bools[EAXFields[i].Flag] = sc.MustMatchString (BoolNames); } inited[i] = true; } if (!inited[0]) { - SC_ScriptError ("Sound %s is missing an Environment field.", name); + sc.ScriptError ("Sound %s is missing an Environment field.", name); } // Add the new environment to the list, filling in uninitialized fields @@ -573,9 +575,7 @@ void S_ParseSndEax () while ((lump = Wads.FindLump ("SNDEAX", &lastlump)) != -1) { - SC_OpenLumpNum (lump, "SNDEAX"); - ReadEAX (); - SC_Close (); + ReadEAX (lump, "SNDEAX"); } } diff --git a/src/s_sndseq.cpp b/src/s_sndseq.cpp index eb3e57b6ad..9de65367b0 100644 --- a/src/s_sndseq.cpp +++ b/src/s_sndseq.cpp @@ -161,7 +161,7 @@ struct FSoundSequencePtrArray : public TArray // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- -static void AssignTranslations (int seq, seqtype_t type); +static void AssignTranslations (FScanner &sc, int seq, seqtype_t type); static void AssignHexenTranslations (void); static void AddSequence (int curseq, FName seqname, FName slot, int stopsound, const TArray &ScriptTemp); static int FindSequence (const char *searchname); @@ -388,19 +388,19 @@ void DSeqSectorNode::Serialize (FArchive &arc) // //========================================================================== -static void AssignTranslations (int seq, seqtype_t type) +static void AssignTranslations (FScanner &sc, int seq, seqtype_t type) { - sc_Crossed = false; + sc.Crossed = false; - while (SC_GetString () && !sc_Crossed) + while (sc.GetString () && !sc.Crossed) { - if (IsNum (sc_String)) + if (IsNum (sc.String)) { - SeqTrans[(atoi(sc_String) & 63) + type * 64] = seq; + SeqTrans[(atoi(sc.String) & 63) + type * 64] = seq; } } - SC_UnGet (); + sc.UnGet (); } //========================================================================== @@ -481,17 +481,17 @@ void S_ParseSndSeq (int levellump) lump = levellump; levellump = -2; } - SC_OpenLumpNum (lump, "SNDSEQ"); - while (SC_GetString ()) + FScanner sc(lump, "SNDSEQ"); + while (sc.GetString ()) { - if (*sc_String == ':' || *sc_String == '[') + if (*sc.String == ':' || *sc.String == '[') { if (curseq != -1) { - SC_ScriptError ("S_ParseSndSeq: Nested Script Error"); + sc.ScriptError ("S_ParseSndSeq: Nested Script Error"); } - seqname = sc_String + 1; - seqtype = sc_String[0]; + seqname = sc.String + 1; + seqtype = sc.String[0]; for (curseq = 0; curseq < (int)Sequences.Size(); curseq++) { if (Sequences[curseq]->SeqName == seqname) @@ -510,7 +510,7 @@ void S_ParseSndSeq (int levellump) slot = NAME_None; if (seqtype == '[') { - SC_SetCMode (true); + sc.SetCMode (true); ScriptTemp.Push (0); // to be filled when definition is complete } continue; @@ -521,101 +521,101 @@ void S_ParseSndSeq (int levellump) } if (seqtype == '[') { - if (sc_String[0] == ']') + if (sc.String[0] == ']') { // End of this definition ScriptTemp[0] = MakeCommand(SS_CMD_SELECT, (ScriptTemp.Size()-1)/2); AddSequence (curseq, seqname, slot, stopsound, ScriptTemp); curseq = -1; - SC_SetCMode (false); + sc.SetCMode (false); } else { // Add a selection - SC_UnGet(); - if (SC_CheckNumber()) + sc.UnGet(); + if (sc.CheckNumber()) { - ScriptTemp.Push (sc_Number); - SC_MustGetString(); - ScriptTemp.Push (FName(sc_String)); + ScriptTemp.Push (sc.Number); + sc.MustGetString(); + ScriptTemp.Push (FName(sc.String)); } else { - AssignTranslations (curseq, seqtype_t(SC_MustMatchString (SSStrings + SS_STRING_PLATFORM))); + AssignTranslations (sc, curseq, seqtype_t(sc.MustMatchString (SSStrings + SS_STRING_PLATFORM))); } } continue; } - switch (SC_MustMatchString (SSStrings)) + switch (sc.MustMatchString (SSStrings)) { case SS_STRING_PLAYUNTILDONE: - SC_MustGetString (); - ScriptTemp.Push(MakeCommand(SS_CMD_PLAY, S_FindSound (sc_String))); + sc.MustGetString (); + ScriptTemp.Push(MakeCommand(SS_CMD_PLAY, S_FindSound (sc.String))); ScriptTemp.Push(MakeCommand(SS_CMD_WAITUNTILDONE, 0)); break; case SS_STRING_PLAY: - SC_MustGetString (); - ScriptTemp.Push(MakeCommand(SS_CMD_PLAY, S_FindSound (sc_String))); + sc.MustGetString (); + ScriptTemp.Push(MakeCommand(SS_CMD_PLAY, S_FindSound (sc.String))); break; case SS_STRING_PLAYTIME: - SC_MustGetString (); - ScriptTemp.Push(MakeCommand(SS_CMD_PLAY, S_FindSound (sc_String))); - SC_MustGetNumber (); - ScriptTemp.Push(MakeCommand(SS_CMD_DELAY, sc_Number)); + sc.MustGetString (); + ScriptTemp.Push(MakeCommand(SS_CMD_PLAY, S_FindSound (sc.String))); + sc.MustGetNumber (); + ScriptTemp.Push(MakeCommand(SS_CMD_DELAY, sc.Number)); break; case SS_STRING_PLAYREPEAT: - SC_MustGetString (); - ScriptTemp.Push(MakeCommand (SS_CMD_PLAYREPEAT, S_FindSound (sc_String))); + sc.MustGetString (); + ScriptTemp.Push(MakeCommand (SS_CMD_PLAYREPEAT, S_FindSound (sc.String))); break; case SS_STRING_PLAYLOOP: - SC_MustGetString (); - ScriptTemp.Push(MakeCommand (SS_CMD_PLAYLOOP, S_FindSound (sc_String))); - SC_MustGetNumber (); - ScriptTemp.Push(sc_Number); + sc.MustGetString (); + ScriptTemp.Push(MakeCommand (SS_CMD_PLAYLOOP, S_FindSound (sc.String))); + sc.MustGetNumber (); + ScriptTemp.Push(sc.Number); break; case SS_STRING_DELAY: - SC_MustGetNumber (); - ScriptTemp.Push(MakeCommand(SS_CMD_DELAY, sc_Number)); + sc.MustGetNumber (); + ScriptTemp.Push(MakeCommand(SS_CMD_DELAY, sc.Number)); break; case SS_STRING_DELAYONCE: - SC_MustGetNumber (); - ScriptTemp.Push(MakeCommand(SS_CMD_DELAY, sc_Number)); + sc.MustGetNumber (); + ScriptTemp.Push(MakeCommand(SS_CMD_DELAY, sc.Number)); ScriptTemp.Push(MakeCommand(SS_CMD_LAST2NOP, 0)); break; case SS_STRING_DELAYRAND: - SC_MustGetNumber (); - delaybase = sc_Number; - ScriptTemp.Push(MakeCommand(SS_CMD_DELAYRAND, sc_Number)); - SC_MustGetNumber (); - ScriptTemp.Push(MAX(1, sc_Number - delaybase + 1)); + sc.MustGetNumber (); + delaybase = sc.Number; + ScriptTemp.Push(MakeCommand(SS_CMD_DELAYRAND, sc.Number)); + sc.MustGetNumber (); + ScriptTemp.Push(MAX(1, sc.Number - delaybase + 1)); break; case SS_STRING_VOLUME: // volume is in range 0..100 - SC_MustGetFloat (); - ScriptTemp.Push(MakeCommand(SS_CMD_VOLUME, int(sc_Float * (FRACUNIT/100.f)))); + sc.MustGetFloat (); + ScriptTemp.Push(MakeCommand(SS_CMD_VOLUME, int(sc.Float * (FRACUNIT/100.f)))); break; case SS_STRING_VOLUMEREL: - SC_MustGetFloat (); - ScriptTemp.Push(MakeCommand(SS_CMD_VOLUMEREL, int(sc_Float * (FRACUNIT/100.f)))); + sc.MustGetFloat (); + ScriptTemp.Push(MakeCommand(SS_CMD_VOLUMEREL, int(sc.Float * (FRACUNIT/100.f)))); break; case SS_STRING_VOLUMERAND: - SC_MustGetFloat (); - volumebase = sc_Float; - ScriptTemp.Push(MakeCommand(SS_CMD_VOLUMERAND, int(sc_Float * (FRACUNIT/100.f)))); - SC_MustGetFloat (); - ScriptTemp.Push(int((sc_Float - volumebase) * (256/100.f))); + sc.MustGetFloat (); + volumebase = sc.Float; + ScriptTemp.Push(MakeCommand(SS_CMD_VOLUMERAND, int(sc.Float * (FRACUNIT/100.f)))); + sc.MustGetFloat (); + ScriptTemp.Push(int((sc.Float - volumebase) * (256/100.f))); break; case SS_STRING_STOPSOUND: - SC_MustGetString (); - stopsound = S_FindSound (sc_String); + sc.MustGetString (); + stopsound = S_FindSound (sc.String); ScriptTemp.Push(MakeCommand(SS_CMD_STOPSOUND, 0)); break; @@ -625,8 +625,8 @@ void S_ParseSndSeq (int levellump) break; case SS_STRING_ATTENUATION: - SC_MustGetString (); - ScriptTemp.Push(MakeCommand(SS_CMD_ATTENUATION, SC_MustMatchString(Attenuations))); + sc.MustGetString (); + ScriptTemp.Push(MakeCommand(SS_CMD_ATTENUATION, sc.MustMatchString(Attenuations))); break; case SS_STRING_RANDOMSEQUENCE: @@ -643,24 +643,23 @@ void S_ParseSndSeq (int levellump) break; case SS_STRING_PLATFORM: - AssignTranslations (curseq, SEQ_PLATFORM); + AssignTranslations (sc, curseq, SEQ_PLATFORM); break; case SS_STRING_DOOR: - AssignTranslations (curseq, SEQ_DOOR); + AssignTranslations (sc, curseq, SEQ_DOOR); break; case SS_STRING_ENVIRONMENT: - AssignTranslations (curseq, SEQ_ENVIRONMENT); + AssignTranslations (sc, curseq, SEQ_ENVIRONMENT); break; case SS_STRING_SLOT: - SC_MustGetString(); - slot = sc_String; + sc.MustGetString(); + slot = sc.String; break; } } - SC_Close (); } if (gameinfo.gametype == GAME_Hexen) diff --git a/src/s_sound.h b/src/s_sound.h index 8ea9f0bf96..c139bd20d5 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -25,6 +25,7 @@ #include "tarray.h" class AActor; +class FScanner; // // SoundFX struct. @@ -196,7 +197,7 @@ int S_FindSkinnedSound (AActor *actor, const char *logicalname); int S_FindSkinnedSoundEx (AActor *actor, const char *logicalname, const char *extendedname); int S_FindSkinnedSound (AActor *actor, int refid); int S_FindSoundByLump (int lump); -int S_AddSound (const char *logicalname, const char *lumpname); // Add sound by lumpname +int S_AddSound (const char *logicalname, const char *lumpname, FScanner *sc=NULL); // Add sound by lumpname int S_AddSoundLump (const char *logicalname, int lump); // Add sound by lump index int S_AddPlayerSound (const char *playerclass, const int gender, int refid, const char *lumpname); int S_AddPlayerSound (const char *playerclass, const int gender, int refid, int lumpnum, bool fromskin=false); diff --git a/src/sc_man.cpp b/src/sc_man.cpp index b0e35fe302..cfaeaf24c8 100644 --- a/src/sc_man.cpp +++ b/src/sc_man.cpp @@ -24,7 +24,6 @@ // MACROS ------------------------------------------------------------------ -#define MAX_STRING_SIZE 4096 #define ASCII_COMMENT (';') #define CPP_COMMENT ('/') #define C_COMMENT ('*') @@ -44,253 +43,340 @@ // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- -static void SC_PrepareScript (void); -static bool SC_ScanString (bool tokens); -static void CheckOpen (void); - // EXTERNAL DATA DECLARATIONS ---------------------------------------------- // PUBLIC DATA DEFINITIONS ------------------------------------------------- -int sc_TokenType; -char *sc_String; -unsigned int sc_StringLen; -int sc_Number; -double sc_Float; -FName sc_Name; -int sc_Line; -bool sc_End; -bool sc_Crossed; -bool sc_FileScripts = false; - // PRIVATE DATA DEFINITIONS ------------------------------------------------ -static FString ScriptName; -static char *ScriptBuffer; -static char *ScriptPtr; -static char *ScriptEndPtr; -static char StringBuffer[MAX_STRING_SIZE]; -static bool ScriptOpen = false; -static int ScriptSize; -static bool AlreadyGot = false; -static int AlreadyGotLine; -static bool LastGotToken = false; -static char *LastGotPtr; -static int LastGotLine; -static bool FreeScript = false; -static char *SavedScriptPtr; -static int SavedScriptLine; -static bool CMode; -static bool Escape = true; -static bool AtTermed; - // CODE -------------------------------------------------------------------- //========================================================================== // -// SC_Open +// FScanner Constructor // //========================================================================== -void SC_Open (const char *name) +FScanner::FScanner() { - int lump = Wads.CheckNumForFullName(name); - if (lump==-1) lump = Wads.GetNumForName(name); - SC_OpenLumpNum(lump, name); + ScriptOpen = false; } //========================================================================== // -// SC_OpenFile +// FScanner Destructor +// +//========================================================================== + +FScanner::~FScanner() +{ + // Humm... Nothing to do in here. +} + +//========================================================================== +// +// FScanner Copy Constructor +// +//========================================================================== + +FScanner::FScanner(const FScanner &other) +{ + ScriptOpen = false; + *this = other; +} + +//========================================================================== +// +// FScanner OpenLumpNum Constructor +// +//========================================================================== + +FScanner::FScanner(int lumpnum, const char *name) +{ + ScriptOpen = false; + OpenLumpNum(lumpnum, name); +} + +//========================================================================== +// +// FScanner :: operator = +// +//========================================================================== + +FScanner &FScanner::operator=(const FScanner &other) +{ + if (this == &other) + { + return *this; + } + if (!other.ScriptOpen) + { + Close(); + return *this; + } + + // Copy protected members + ScriptOpen = true; + ScriptName = other.ScriptName; + ScriptBuffer = other.ScriptBuffer; + ScriptPtr = other.ScriptPtr; + ScriptEndPtr = other.ScriptEndPtr; + AlreadyGot = other.AlreadyGot; + AlreadyGotLine = other.AlreadyGotLine; + LastGotToken = other.LastGotToken; + LastGotPtr = other.LastGotPtr; + LastGotLine = other.LastGotLine; + CMode = other.CMode; + Escape = other.Escape; + + // Copy public members + if (other.String == other.StringBuffer) + { + memcpy(StringBuffer, other.StringBuffer, sizeof(StringBuffer)); + BigStringBuffer = ""; + String = StringBuffer; + } + else + { + // Past practice means the string buffer must be writeable, which + // removes some of the benefit from using an FString to store + // the big string buffer. + BigStringBuffer = other.BigStringBuffer; + String = BigStringBuffer.LockBuffer(); + } + StringLen = other.StringLen; + TokenType = other.TokenType; + Number = other.Number; + Float = other.Float; + Name = other.Name; + Line = other.Line; + End = other.End; + Crossed = other.Crossed; + + return *this; +} + +//========================================================================== +// +// FScanner :: Open +// +//========================================================================== + +void FScanner::Open (const char *name) +{ + int lump = Wads.CheckNumForFullName(name); + if (lump == -1) + { + lump = Wads.GetNumForName(name); + } + OpenLumpNum(lump, name); +} + +//========================================================================== +// +// FScanner :: OpenFile // // Loads a script (from a file). Uses the new/delete memory allocator for // memory allocation and de-allocation. // //========================================================================== -void SC_OpenFile (const char *name) +void FScanner::OpenFile (const char *name) { BYTE *filebuf; + int filesize; - SC_Close (); - ScriptSize = M_ReadFile (name, &filebuf); - ScriptBuffer = new char[ScriptSize + 1]; - memcpy (ScriptBuffer, filebuf, ScriptSize); - ScriptBuffer[ScriptSize++] = '\n'; + Close (); + filesize = M_ReadFile (name, &filebuf); + ScriptBuffer = FString((const char *)filebuf, filesize); delete[] filebuf; ScriptName = name; // This is used for error messages so the full file name is preferable - FreeScript = true; - SC_PrepareScript (); + PrepareScript (); } //========================================================================== // -// SC_OpenMem +// FScanner :: OpenMem // -// Prepares a script that is already in memory for parsing. The caller is -// responsible for freeing it, if needed. You MUST ensure that the script -// ends with the newline character '\n'. +// Prepares a script that is already in memory for parsing. The memory is +// copied, so you can do whatever you want with it after opening it. // //========================================================================== -void SC_OpenMem (const char *name, char *buffer, int size) +void FScanner::OpenMem (const char *name, char *buffer, int size) { - SC_Close (); - ScriptSize = size; - ScriptBuffer = buffer; + Close (); + ScriptBuffer = FString(buffer, size); ScriptName = name; - FreeScript = false; - SC_PrepareScript (); + PrepareScript (); } //========================================================================== // -// SC_OpenLumpNum +// FScanner :: OpenLumpNum // // Loads a script (from the WAD files). // //========================================================================== -void SC_OpenLumpNum (int lump, const char *name) +void FScanner :: OpenLumpNum (int lump, const char *name) { - SC_Close (); - ScriptSize = Wads.LumpLength (lump); - ScriptBuffer = new char[ScriptSize + 1]; - Wads.ReadLump (lump, ScriptBuffer); - ScriptBuffer[ScriptSize++] = '\n'; + Close (); + { + FMemLump mem = Wads.ReadLump(lump); + ScriptBuffer = mem.GetString(); + } ScriptName = name; - FreeScript = true; - SC_PrepareScript (); + PrepareScript (); } //========================================================================== // -// SC_PrepareScript +// FScanner :: PrepareScript // // Prepares a script for parsing. // //========================================================================== -static void SC_PrepareScript (void) +void FScanner::PrepareScript () { - ScriptPtr = ScriptBuffer; - ScriptEndPtr = ScriptPtr + ScriptSize; - sc_Line = 1; - sc_End = false; + // The scanner requires the file to end with a '\n', so add one if + // it doesn't already. + if (ScriptBuffer.Len() == 0 || ScriptBuffer[ScriptBuffer.Len() - 1] != '\n') + { + // If the last character in the buffer is a null character, change + // it to a newline. Otherwise, append a newline to the end. + if (ScriptBuffer[ScriptBuffer.Len() - 1] == '\0') + { + ScriptBuffer.LockBuffer()[ScriptBuffer.Len() - 1] = '\n'; + ScriptBuffer.UnlockBuffer(); + } + else + { + ScriptBuffer += '\n'; + } + } + + ScriptPtr = &ScriptBuffer[0]; + ScriptEndPtr = &ScriptBuffer[ScriptBuffer.Len()]; + Line = 1; + End = false; ScriptOpen = true; - sc_String = StringBuffer; + String = StringBuffer; AlreadyGot = false; LastGotToken = false; LastGotPtr = NULL; LastGotLine = 1; - SavedScriptPtr = NULL; CMode = false; Escape = true; + StringBuffer[0] = '\0'; + BigStringBuffer = ""; } //========================================================================== // -// SC_Close +// FScanner :: Close // //========================================================================== -void SC_Close (void) +void FScanner::Close () { - if (ScriptOpen) - { - if (ScriptBuffer) - { - if (FreeScript) - { - delete[] ScriptBuffer; - } - } - ScriptBuffer = NULL; - ScriptOpen = false; - } + ScriptOpen = false; + ScriptBuffer = ""; + BigStringBuffer = ""; + StringBuffer[0] = '\0'; + String = StringBuffer; } //========================================================================== // -// SC_SavePos +// FScanner :: SavePos // // Saves the current script location for restoration later // //========================================================================== -void SC_SavePos (void) +const FScanner::SavedPos FScanner::SavePos () { + SavedPos pos; + CheckOpen (); - if (sc_End) + if (End) { - SavedScriptPtr = NULL; + pos.SavedScriptPtr = NULL; } else { - SavedScriptPtr = ScriptPtr; - SavedScriptLine = sc_Line; + pos.SavedScriptPtr = ScriptPtr; } + pos.SavedScriptLine = Line; + return pos; } //========================================================================== // -// SC_RestorePos +// FScanner :: RestorePos // // Restores the previously saved script location // //========================================================================== -void SC_RestorePos (void) +void FScanner::RestorePos (const FScanner::SavedPos &pos) { - if (SavedScriptPtr) + if (pos.SavedScriptPtr) { - ScriptPtr = SavedScriptPtr; - sc_Line = SavedScriptLine; - sc_End = false; - AlreadyGot = false; - LastGotToken = false; + ScriptPtr = pos.SavedScriptPtr; + Line = pos.SavedScriptLine; + End = false; } + else + { + End = true; + } + AlreadyGot = false; + LastGotToken = false; + Crossed = false; } //========================================================================== // -// SC_SetCMode +// FScanner :: SetCMode // // Enables/disables C mode. In C mode, more characters are considered to // be whole words than in non-C mode. // //========================================================================== -void SC_SetCMode (bool cmode) +void FScanner::SetCMode (bool cmode) { CMode = cmode; } //========================================================================== // -// SC_SetEscape +// FScanner :: SetEscape // // Turns the escape sequence \" in strings on or off. If it's off, that // means you can't include quotation marks inside strings. // //========================================================================== -void SC_SetEscape (bool esc) +void FScanner::SetEscape (bool esc) { Escape = esc; } //========================================================================== // -// SC_ScanString +// FScanner::ScanString // -// Set tokens true if you want sc_TokenType to be set. +// Set tokens true if you want TokenType to be set. // //========================================================================== -static bool SC_ScanString (bool tokens) +bool FScanner::ScanString (bool tokens) { - char *marker, *tok; + const char *marker, *tok; bool return_val; CheckOpen(); @@ -302,18 +388,18 @@ static bool SC_ScanString (bool tokens) return true; } ScriptPtr = LastGotPtr; - sc_Line = LastGotLine; + Line = LastGotLine; } - sc_Crossed = false; + Crossed = false; if (ScriptPtr >= ScriptEndPtr) { - sc_End = true; + End = true; return false; } LastGotPtr = ScriptPtr; - LastGotLine = sc_Line; + LastGotLine = Line; // In case the generated scanner does not use marker, avoid compiler warnings. marker; @@ -324,95 +410,96 @@ static bool SC_ScanString (bool tokens) //========================================================================== // -// SC_GetString +// FScanner :: GetString // //========================================================================== -bool SC_GetString () +bool FScanner::GetString () { - return SC_ScanString (false); + return ScanString (false); } //========================================================================== // -// SC_MustGetString +// FScanner :: MustGetString // //========================================================================== -void SC_MustGetString (void) +void FScanner::MustGetString (void) { - if (SC_GetString () == false) + if (FScanner::GetString() == false) { - SC_ScriptError ("Missing string (unexpected end of file)."); + ScriptError ("Missing string (unexpected end of file)."); } } //========================================================================== // -// SC_MustGetStringName +// FScanner :: MustGetStringName // //========================================================================== -void SC_MustGetStringName (const char *name) +void FScanner::MustGetStringName (const char *name) { - SC_MustGetString (); - if (SC_Compare (name) == false) + MustGetString (); + if (Compare (name) == false) { - SC_ScriptError ("Expected '%s', got '%s'.", name, sc_String); + ScriptError ("Expected '%s', got '%s'.", name, String); } } //========================================================================== // -// SC_CheckString +// FScanner :: CheckString // // Checks if the next token matches the specified string. Returns true if // it does. If it doesn't, it ungets it and returns false. +// //========================================================================== -bool SC_CheckString (const char *name) +bool FScanner::CheckString (const char *name) { - if (SC_GetString ()) + if (GetString ()) { - if (SC_Compare (name)) + if (Compare (name)) { return true; } - SC_UnGet (); + UnGet (); } return false; } //========================================================================== // -// SC_GetToken +// FScanner :: GetToken // // Sets sc_Float, sc_Number, and sc_Name based on sc_TokenType. // //========================================================================== -bool SC_GetToken () +bool FScanner::GetToken () { - if (SC_ScanString (true)) + if (ScanString (true)) { - if (sc_TokenType == TK_NameConst) + if (TokenType == TK_NameConst) { - sc_Name = FName(sc_String); + Name = FName(String); } - else if (sc_TokenType == TK_IntConst) + else if (TokenType == TK_IntConst) { char *stopper; - sc_Number = strtol(sc_String, &stopper, 0); - sc_Float = sc_Number; + Number = strtol(String, &stopper, 0); + Float = Number; } - else if (sc_TokenType == TK_FloatConst) + else if (TokenType == TK_FloatConst) { char *stopper; - sc_Float = strtod(sc_String, &stopper); + Float = strtod(String, &stopper); } - else if (sc_TokenType == TK_StringConst) + else if (TokenType == TK_StringConst) { - strbin (sc_String); + StringLen = strbin(String); } return true; } @@ -421,93 +508,94 @@ bool SC_GetToken () //========================================================================== // -// SC_MustGetAnyToken +// FScanner :: MustGetAnyToken // //========================================================================== -void SC_MustGetAnyToken (void) +void FScanner::MustGetAnyToken (void) { - if (SC_GetToken () == false) + if (GetToken () == false) { - SC_ScriptError ("Missing token (unexpected end of file)."); + ScriptError ("Missing token (unexpected end of file)."); } } //========================================================================== // -// SC_TokenMustBe +// FScanner :: TokenMustBe // //========================================================================== -void SC_TokenMustBe (int token) +void FScanner::TokenMustBe (int token) { - if (sc_TokenType != token) + if (TokenType != token) { - FString tok1 = SC_TokenName(token); - FString tok2 = SC_TokenName(sc_TokenType, sc_String); - SC_ScriptError ("Expected %s but got %s instead.", tok1.GetChars(), tok2.GetChars()); + FString tok1 = TokenName(token); + FString tok2 = TokenName(TokenType, String); + ScriptError ("Expected %s but got %s instead.", tok1.GetChars(), tok2.GetChars()); } } //========================================================================== // -// SC_MustGetToken +// FScanner :: MustGetToken // //========================================================================== -void SC_MustGetToken (int token) +void FScanner::MustGetToken (int token) { - SC_MustGetAnyToken (); - SC_TokenMustBe(token); + MustGetAnyToken (); + TokenMustBe(token); } //========================================================================== // -// SC_CheckToken +// FScanner :: CheckToken // // Checks if the next token matches the specified token. Returns true if // it does. If it doesn't, it ungets it and returns false. +// //========================================================================== -bool SC_CheckToken (int token) +bool FScanner::CheckToken (int token) { - if (SC_GetToken ()) + if (GetToken ()) { - if (sc_TokenType == token) + if (TokenType == token) { return true; } - SC_UnGet (); + UnGet (); } return false; } //========================================================================== // -// SC_GetNumber +// FScanner :: GetNumber // //========================================================================== -bool SC_GetNumber (void) +bool FScanner::GetNumber () { char *stopper; - CheckOpen (); - if (SC_GetString()) + CheckOpen(); + if (GetString()) { - if (strcmp (sc_String, "MAXINT") == 0) + if (strcmp (String, "MAXINT") == 0) { - sc_Number = INT_MAX; + Number = INT_MAX; } else { - sc_Number = strtol (sc_String, &stopper, 0); + Number = strtol (String, &stopper, 0); if (*stopper != 0) { - SC_ScriptError ("SC_GetNumber: Bad numeric constant \"%s\".", sc_String); + ScriptError ("SC_GetNumber: Bad numeric constant \"%s\".", String); } } - sc_Float = (float)sc_Number; + Float = (float)Number; return true; } else @@ -518,52 +606,52 @@ bool SC_GetNumber (void) //========================================================================== // -// SC_MustGetNumber +// FScanner :: MustGetNumber // //========================================================================== -void SC_MustGetNumber (void) +void FScanner::MustGetNumber () { - if (SC_GetNumber() == false) + if (GetNumber() == false) { - SC_ScriptError ("Missing integer (unexpected end of file)."); + ScriptError ("Missing integer (unexpected end of file)."); } } //========================================================================== // -// SC_CheckNumber -// similar to SC_GetNumber but ungets the token if it isn't a number +// FScanner :: CheckNumber +// +// similar to GetNumber but ungets the token if it isn't a number // and does not print an error // //========================================================================== -bool SC_CheckNumber (void) +bool FScanner::CheckNumber () { char *stopper; - //CheckOpen (); - if (SC_GetString()) + if (GetString()) { - if (sc_String[0] == 0) + if (String[0] == 0) { - SC_UnGet(); + UnGet(); return false; } - else if (strcmp (sc_String, "MAXINT") == 0) + else if (strcmp (String, "MAXINT") == 0) { - sc_Number = INT_MAX; + Number = INT_MAX; } else { - sc_Number = strtol (sc_String, &stopper, 0); + Number = strtol (String, &stopper, 0); if (*stopper != 0) { - SC_UnGet(); + UnGet(); return false; } } - sc_Float = (float)sc_Number; + Float = (float)Number; return true; } else @@ -574,28 +662,28 @@ bool SC_CheckNumber (void) //========================================================================== // -// SC_CheckFloat +// FScanner :: CheckFloat +// // [GRB] Same as SC_CheckNumber, only for floats // //========================================================================== -bool SC_CheckFloat (void) +bool FScanner::CheckFloat () { char *stopper; - //CheckOpen (); - if (SC_GetString()) + if (GetString()) { - if (sc_String[0] == 0) + if (String[0] == 0) { - SC_UnGet(); + UnGet(); return false; } - sc_Float = strtod (sc_String, &stopper); + Float = strtod (String, &stopper); if (*stopper != 0) { - SC_UnGet(); + UnGet(); return false; } return true; @@ -609,24 +697,24 @@ bool SC_CheckFloat (void) //========================================================================== // -// SC_GetFloat +// FScanner :: GetFloat // //========================================================================== -bool SC_GetFloat (void) +bool FScanner::GetFloat () { char *stopper; CheckOpen (); - if (SC_GetString()) + if (GetString()) { - sc_Float = (float)strtod (sc_String, &stopper); + Float = (float)strtod (String, &stopper); if (*stopper != 0) { I_Error ("SC_GetFloat: Bad numeric constant \"%s\".\n" - "Script %s, Line %d\n", sc_String, ScriptName.GetChars(), sc_Line); + "Script %s, Line %d\n", String, ScriptName.GetChars(), Line); } - sc_Number = (int)sc_Float; + Number = (int)Float; return true; } else @@ -637,27 +725,27 @@ bool SC_GetFloat (void) //========================================================================== // -// SC_MustGetFloat +// FScanner :: MustGetFloat // //========================================================================== -void SC_MustGetFloat (void) +void FScanner::MustGetFloat () { - if (SC_GetFloat() == false) + if (GetFloat() == false) { - SC_ScriptError ("Missing floating-point number (unexpected end of file)."); + ScriptError ("Missing floating-point number (unexpected end of file)."); } } //========================================================================== // -// SC_UnGet +// FScanner :: UnGet // -// Assumes there is a valid string in sc_String. +// Assumes there is a valid string in String. // //========================================================================== -void SC_UnGet (void) +void FScanner::UnGet () { AlreadyGot = true; AlreadyGotLine = LastGotLine; // in case of an error we want the line of the last token. @@ -665,59 +753,20 @@ void SC_UnGet (void) //========================================================================== // -// SC_Check +// FScanner :: MatchString // -// Returns true if another token is on the current line. -// -//========================================================================== - -/* -bool SC_Check(void) -{ - char *text; - - CheckOpen(); - text = ScriptPtr; - if(text >= ScriptEndPtr) - { - return false; - } - while(*text <= 32) - { - if(*text == '\n') - { - return false; - } - text++; - if(text == ScriptEndPtr) - { - return false; - } - } - if(*text == ASCII_COMMENT) - { - return false; - } - return true; -} -*/ - -//========================================================================== -// -// SC_MatchString -// -// Returns the index of the first match to sc_String from the passed +// Returns the index of the first match to String from the passed // array of strings, or -1 if not found. // //========================================================================== -int SC_MatchString (const char **strings) +int FScanner::MatchString (const char **strings) { int i; for (i = 0; *strings != NULL; i++) { - if (SC_Compare (*strings++)) + if (Compare (*strings++)) { return i; } @@ -727,42 +776,42 @@ int SC_MatchString (const char **strings) //========================================================================== // -// SC_MustMatchString +// FScanner :: MustMatchString // //========================================================================== -int SC_MustMatchString (const char **strings) +int FScanner::MustMatchString (const char **strings) { int i; - i = SC_MatchString (strings); + i = MatchString (strings); if (i == -1) { - SC_ScriptError (NULL); + ScriptError (NULL); } return i; } //========================================================================== // -// SC_Compare +// FScanner :: Compare // //========================================================================== -bool SC_Compare (const char *text) +bool FScanner::Compare (const char *text) { - return (stricmp (text, sc_String) == 0); + return (stricmp (text, String) == 0); } //========================================================================== // -// SC_TokenName +// FScanner :: TokenName // // Returns the name of a token. // //========================================================================== -FString SC_TokenName (int token, const char *string) +FString FScanner::TokenName (int token, const char *string) { static const char *const names[] = { @@ -909,11 +958,11 @@ FString SC_TokenName (int token, const char *string) //========================================================================== // -// SC_ScriptError +// FScanner::ScriptError // //========================================================================== -void STACK_ARGS SC_ScriptError (const char *message, ...) +void STACK_ARGS FScanner::ScriptError (const char *message, ...) { FString composed; @@ -930,103 +979,19 @@ void STACK_ARGS SC_ScriptError (const char *message, ...) } I_Error ("Script error, \"%s\" line %d:\n%s\n", ScriptName.GetChars(), - AlreadyGot? AlreadyGotLine : sc_Line, composed.GetChars()); + AlreadyGot? AlreadyGotLine : Line, composed.GetChars()); } //========================================================================== // -// CheckOpen +// FScanner :: CheckOpen // //========================================================================== -static void CheckOpen(void) +void FScanner::CheckOpen() { if (ScriptOpen == false) { I_FatalError ("SC_ call before SC_Open()."); } } - - -//========================================================================== -// -// Script state saving -// This allows recursive script execution -// This does not save the last token! -// -//========================================================================== - -struct SavedScript -{ - int sc_Line; - bool sc_End; - bool sc_Crossed; - bool sc_FileScripts; - - FString *ScriptName; - char *ScriptBuffer; - char *ScriptPtr; - char *ScriptEndPtr; - bool ScriptOpen; - int ScriptSize; - bool FreeScript; - char *SavedScriptPtr; - int SavedScriptLine; - bool CMode; - bool Escape; -}; - - -static TArray SavedScripts; - -void SC_SaveScriptState() -{ - SavedScript ss; - - ss.sc_Line = sc_Line; - ss.sc_End = sc_End; - ss.sc_Crossed = sc_Crossed; - ss.sc_FileScripts = sc_FileScripts; - ss.ScriptName = ::new FString(ScriptName); - ss.ScriptBuffer = ScriptBuffer; - ss.ScriptPtr = ScriptPtr; - ss.ScriptEndPtr = ScriptEndPtr; - ss.ScriptOpen = ScriptOpen; - ss.ScriptSize = ScriptSize; - ss.FreeScript = FreeScript; - ss.SavedScriptPtr = SavedScriptPtr; - ss.SavedScriptLine = SavedScriptLine; - ss.CMode = CMode; - ss.Escape = Escape; - SavedScripts.Push(ss); - ScriptOpen = false; -} - -void SC_RestoreScriptState() -{ - if (SavedScripts.Size()>0) - { - SavedScript ss; - - SavedScripts.Pop(ss); - sc_Line = ss.sc_Line; - sc_End = ss.sc_End; - sc_Crossed = ss.sc_Crossed; - sc_FileScripts = ss.sc_FileScripts; - ScriptName = *ss.ScriptName; - ::delete ss.ScriptName; - ScriptBuffer = ss.ScriptBuffer; - ScriptPtr = ss.ScriptPtr; - ScriptEndPtr = ss.ScriptEndPtr; - ScriptOpen = ss.ScriptOpen; - ScriptSize = ss.ScriptSize; - FreeScript = ss.FreeScript; - SavedScriptPtr = ss.SavedScriptPtr; - SavedScriptLine = ss.SavedScriptLine; - CMode = ss.CMode; - Escape = ss.Escape; - SavedScripts.ShrinkToFit(); - AlreadyGot = false; - LastGotToken = false; - } -} diff --git a/src/sc_man.h b/src/sc_man.h index b94889b955..245adbff15 100644 --- a/src/sc_man.h +++ b/src/sc_man.h @@ -1,40 +1,98 @@ #ifndef __SC_MAN_H__ #define __SC_MAN_H__ -void SC_Open (const char *name); -void SC_OpenFile (const char *name); -void SC_OpenMem (const char *name, char *buffer, int size); -void SC_OpenLumpNum (int lump, const char *name); -void SC_Close (void); -void SC_SetCMode (bool cmode); -void SC_SetEscape (bool esc); -void SC_SavePos (void); -void SC_RestorePos (void); -FString SC_TokenName (int token, const char *string=NULL); -bool SC_GetString (void); -void SC_MustGetString (void); -void SC_MustGetStringName (const char *name); -bool SC_CheckString (const char *name); -bool SC_GetToken (void); -void SC_MustGetAnyToken (void); -void SC_TokenMustBe (int token); -void SC_MustGetToken (int token); -bool SC_CheckToken (int token); -bool SC_CheckTokenId (ENamedName id); -bool SC_GetNumber (void); -void SC_MustGetNumber (void); -bool SC_CheckNumber (void); -bool SC_CheckFloat (void); -bool SC_GetFloat (void); -void SC_MustGetFloat (void); -void SC_UnGet (void); -//boolean SC_Check(void); -bool SC_Compare (const char *text); -int SC_MatchString (const char **strings); -int SC_MustMatchString (const char **strings); -void STACK_ARGS SC_ScriptError (const char *message, ...); -void SC_SaveScriptState(); -void SC_RestoreScriptState(); +class FScanner +{ +public: + struct SavedPos + { + const char *SavedScriptPtr; + int SavedScriptLine; + }; + + // Methods ------------------------------------------------------ + FScanner(); + FScanner(const FScanner &other); + FScanner(int lumpnum, const char *name); + ~FScanner(); + + FScanner &operator=(const FScanner &other); + + void Open(const char *lumpname); + void OpenFile(const char *filename); + void OpenMem(const char *name, char *buffer, int size); + void OpenLumpNum(int lump, const char *name); + void Close(); + + void SetCMode(bool cmode); + void SetEscape(bool esc); + const SavedPos SavePos(); + void RestorePos(const SavedPos &pos); + + FString TokenName(int token, const char *string=NULL); + + bool GetString(); + void MustGetString(); + void MustGetStringName(const char *name); + bool CheckString(const char *name); + + bool GetToken(); + void MustGetAnyToken(); + void TokenMustBe(int token); + void MustGetToken(int token); + bool CheckToken(int token); + bool CheckTokenId(ENamedName id); + + bool GetNumber(); + void MustGetNumber(); + bool CheckNumber(); + + bool GetFloat(); + void MustGetFloat(); + bool CheckFloat(); + + void UnGet(); + + bool Compare(const char *text); + int MatchString(const char **strings); + int MustMatchString(const char **strings); + + void ScriptError(const char *message, ...); + + // Members ------------------------------------------------------ + char *String; + int StringLen; + int TokenType; + int Number; + double Float; + FName Name; + int Line; + bool End; + bool Crossed; + +protected: + void PrepareScript(); + void CheckOpen(); + bool ScanString(bool tokens); + + // Strings longer than this minus one will be dynamically allocated. + static const int MAX_STRING_SIZE = 128; + + bool ScriptOpen; + FString ScriptName; + FString ScriptBuffer; + const char *ScriptPtr; + const char *ScriptEndPtr; + char StringBuffer[MAX_STRING_SIZE]; + FString BigStringBuffer; + bool AlreadyGot; + int AlreadyGotLine; + bool LastGotToken; + const char *LastGotPtr; + int LastGotLine; + bool CMode; + bool Escape; +}; enum { @@ -152,15 +210,4 @@ enum TK_LastToken }; -extern int sc_TokenType; -extern char *sc_String; -extern unsigned int sc_StringLen; -extern int sc_Number; -extern double sc_Float; -extern FName sc_Name; -extern int sc_Line; -extern bool sc_End; -extern bool sc_Crossed; -extern bool sc_FileScripts; - #endif //__SC_MAN_H__ diff --git a/src/sc_man_scanner.h b/src/sc_man_scanner.h index 658f16f740..7271eb93f4 100644 --- a/src/sc_man_scanner.h +++ b/src/sc_man_scanner.h @@ -23,8 +23,8 @@ //#define YYDEBUG(s,c) { Printf ("%d: %02x\n", s, c); } #define YYDEBUG(s,c) - char *cursor = ScriptPtr; - char *limit = ScriptEndPtr; + const char *cursor = ScriptPtr; + const char *limit = ScriptEndPtr; std1: tok = YYCURSOR; @@ -33,7 +33,7 @@ std2: if (tokens) // A well-defined scanner, based on the c.re example. { -#define RET(x) sc_TokenType = x; goto normal_token; +#define RET(x) TokenType = x; goto normal_token; #line 39 "src/sc_man_scanner.h" { @@ -482,7 +482,7 @@ yy24: yy25: #line 216 "src/sc_man_scanner.re" { - SC_ScriptError ("Unexpected character: %c (ASCII %d)\n", *tok, *tok); + ScriptError ("Unexpected character: %c (ASCII %d)\n", *tok, *tok); goto std1; } #line 489 "src/sc_man_scanner.h" @@ -4396,7 +4396,7 @@ yy683: negative_check: // re2c doesn't have enough state to handle '-' as the start of a negative number // and as its own token, so help it out a little. - sc_TokenType = '-'; + TokenType = '-'; if (YYCURSOR >= YYLIMIT) { goto normal_token; @@ -4440,8 +4440,8 @@ yy689: return_val = false; goto end; } - sc_Line++; - sc_Crossed = true; + Line++; + Crossed = true; goto comment; } #line 4448 "src/sc_man_scanner.h" @@ -4472,23 +4472,45 @@ newline: return_val = false; goto end; } - sc_Line++; - sc_Crossed = true; + Line++; + Crossed = true; goto std1; normal_token: ScriptPtr = (YYCURSOR >= YYLIMIT) ? ScriptEndPtr : cursor; - sc_StringLen = (unsigned int)MIN (ScriptPtr - tok, MAX_STRING_SIZE-1); - if (tokens && (sc_TokenType == TK_StringConst || sc_TokenType == TK_NameConst)) + StringLen = int(ScriptPtr - tok); + if (tokens && (TokenType == TK_StringConst || TokenType == TK_NameConst)) { - sc_StringLen -= 2; - memcpy (sc_String, tok+1, sc_StringLen); + StringLen -= 2; + if (StringLen >= MAX_STRING_SIZE) + { + BigStringBuffer = FString(tok+1, StringLen); + } + else + { + memcpy (StringBuffer, tok+1, StringLen); + } } else { - memcpy (sc_String, tok, sc_StringLen); + if (StringLen >= MAX_STRING_SIZE) + { + BigStringBuffer = FString(tok, StringLen); + } + else + { + memcpy (StringBuffer, tok, StringLen); + } + } + if (StringLen < MAX_STRING_SIZE) + { + String = StringBuffer; + StringBuffer[StringLen] = '\0'; + } + else + { + String = BigStringBuffer.LockBuffer(); } - sc_String[sc_StringLen] = '\0'; return_val = true; goto end; @@ -4500,7 +4522,8 @@ string: goto end; } ScriptPtr = cursor; - for (sc_StringLen = 0; cursor < YYLIMIT; ++cursor) + BigStringBuffer = ""; + for (StringLen = 0; cursor < YYLIMIT; ++cursor) { if (Escape && *cursor == '\\' && *(cursor + 1) == '"') { @@ -4518,24 +4541,36 @@ string: { if (CMode) { - if (!Escape || sc_StringLen == 0 || sc_String[sc_StringLen - 1] != '\\') + if (!Escape || StringLen == 0 || String[StringLen - 1] != '\\') { - SC_ScriptError ("Unterminated string constant"); + ScriptError ("Unterminated string constant"); } else { - sc_StringLen--; // overwrite the \ character with \n + StringLen--; // overwrite the \ character with \n } } - sc_Line++; - sc_Crossed = true; + Line++; + Crossed = true; } - if (sc_StringLen < MAX_STRING_SIZE-1) + if (StringLen == MAX_STRING_SIZE) { - sc_String[sc_StringLen++] = *cursor; + BigStringBuffer.AppendCStrPart(StringBuffer, StringLen); + StringLen = 0; } + StringBuffer[StringLen++] = *cursor; + } + if (BigStringBuffer.IsNotEmpty() || StringLen == MAX_STRING_SIZE) + { + BigStringBuffer.AppendCStrPart(StringBuffer, StringLen); + String = BigStringBuffer.LockBuffer(); + StringLen = int(BigStringBuffer.Len()); + } + else + { + String = StringBuffer; + StringBuffer[StringLen] = '\0'; } ScriptPtr = cursor + 1; - sc_String[sc_StringLen] = '\0'; return_val = true; end: diff --git a/src/sc_man_scanner.re b/src/sc_man_scanner.re index 6782520279..68d243a418 100644 --- a/src/sc_man_scanner.re +++ b/src/sc_man_scanner.re @@ -21,8 +21,8 @@ //#define YYDEBUG(s,c) { Printf ("%d: %02x\n", s, c); } #define YYDEBUG(s,c) - char *cursor = ScriptPtr; - char *limit = ScriptEndPtr; + const char *cursor = ScriptPtr; + const char *limit = ScriptEndPtr; std1: tok = YYCURSOR; @@ -51,7 +51,7 @@ std2: */ if (tokens) // A well-defined scanner, based on the c.re example. { -#define RET(x) sc_TokenType = x; goto normal_token; +#define RET(x) TokenType = x; goto normal_token; /*!re2c "/*" { goto comment; } /* C comment */ "//" (any\"\n")* "\n" { goto newline; } /* C++ comment */ @@ -214,7 +214,7 @@ std2: "\n" { goto newline; } any { - SC_ScriptError ("Unexpected character: %c (ASCII %d)\n", *tok, *tok); + ScriptError ("Unexpected character: %c (ASCII %d)\n", *tok, *tok); goto std1; } */ @@ -265,7 +265,7 @@ std2: negative_check: // re2c doesn't have enough state to handle '-' as the start of a negative number // and as its own token, so help it out a little. - sc_TokenType = '-'; + TokenType = '-'; if (YYCURSOR >= YYLIMIT) { goto normal_token; @@ -304,8 +304,8 @@ comment: return_val = false; goto end; } - sc_Line++; - sc_Crossed = true; + Line++; + Crossed = true; goto comment; } any { goto comment; } @@ -318,23 +318,45 @@ newline: return_val = false; goto end; } - sc_Line++; - sc_Crossed = true; + Line++; + Crossed = true; goto std1; normal_token: ScriptPtr = (YYCURSOR >= YYLIMIT) ? ScriptEndPtr : cursor; - sc_StringLen = (unsigned int)MIN (ScriptPtr - tok, MAX_STRING_SIZE-1); - if (tokens && (sc_TokenType == TK_StringConst || sc_TokenType == TK_NameConst)) + StringLen = int(ScriptPtr - tok); + if (tokens && (TokenType == TK_StringConst || TokenType == TK_NameConst)) { - sc_StringLen -= 2; - memcpy (sc_String, tok+1, sc_StringLen); + StringLen -= 2; + if (StringLen >= MAX_STRING_SIZE) + { + BigStringBuffer = FString(tok+1, StringLen); + } + else + { + memcpy (StringBuffer, tok+1, StringLen); + } } else { - memcpy (sc_String, tok, sc_StringLen); + if (StringLen >= MAX_STRING_SIZE) + { + BigStringBuffer = FString(tok, StringLen); + } + else + { + memcpy (StringBuffer, tok, StringLen); + } + } + if (StringLen < MAX_STRING_SIZE) + { + String = StringBuffer; + StringBuffer[StringLen] = '\0'; + } + else + { + String = BigStringBuffer.LockBuffer(); } - sc_String[sc_StringLen] = '\0'; return_val = true; goto end; @@ -346,7 +368,8 @@ string: goto end; } ScriptPtr = cursor; - for (sc_StringLen = 0; cursor < YYLIMIT; ++cursor) + BigStringBuffer = ""; + for (StringLen = 0; cursor < YYLIMIT; ++cursor) { if (Escape && *cursor == '\\' && *(cursor + 1) == '"') { @@ -364,24 +387,36 @@ string: { if (CMode) { - if (!Escape || sc_StringLen == 0 || sc_String[sc_StringLen - 1] != '\\') + if (!Escape || StringLen == 0 || String[StringLen - 1] != '\\') { - SC_ScriptError ("Unterminated string constant"); + ScriptError ("Unterminated string constant"); } else { - sc_StringLen--; // overwrite the \ character with \n + StringLen--; // overwrite the \ character with \n } } - sc_Line++; - sc_Crossed = true; + Line++; + Crossed = true; } - if (sc_StringLen < MAX_STRING_SIZE-1) + if (StringLen == MAX_STRING_SIZE) { - sc_String[sc_StringLen++] = *cursor; + BigStringBuffer.AppendCStrPart(StringBuffer, StringLen); + StringLen = 0; } + StringBuffer[StringLen++] = *cursor; + } + if (BigStringBuffer.IsNotEmpty() || StringLen == MAX_STRING_SIZE) + { + BigStringBuffer.AppendCStrPart(StringBuffer, StringLen); + String = BigStringBuffer.LockBuffer(); + StringLen = int(BigStringBuffer.Len()); + } + else + { + String = StringBuffer; + StringBuffer[StringLen] = '\0'; } ScriptPtr = cursor + 1; - sc_String[sc_StringLen] = '\0'; return_val = true; end: diff --git a/src/stringtable.cpp b/src/stringtable.cpp index 5a305c9e17..6968357f7d 100644 --- a/src/stringtable.cpp +++ b/src/stringtable.cpp @@ -43,6 +43,7 @@ #include "sc_man.h" #include "zstring.h" #include "c_dispatch.h" +#include "v_text.h" // PassNum identifies which language pass this string is from. // PassNum 0 is for DeHacked. @@ -148,44 +149,44 @@ void FStringTable::LoadLanguage (int lumpnum, DWORD code, bool exactMatch, int p code |= orMask; - SC_OpenLumpNum (lumpnum, "LANGUAGE"); - SC_SetCMode (true); - while (SC_GetString ()) + FScanner sc(lumpnum, "LANGUAGE"); + sc.SetCMode (true); + while (sc.GetString ()) { - if (SC_Compare ("[")) + if (sc.Compare ("[")) { // Process language identifiers bool donot = false; bool forceskip = false; skip = true; - SC_MustGetString (); + sc.MustGetString (); do { - size_t len = strlen (sc_String); + size_t len = sc.StringLen; if (len != 2 && len != 3) { - if (len == 1 && sc_String[0] == '~') + if (len == 1 && sc.String[0] == '~') { donot = true; - SC_MustGetString (); + sc.MustGetString (); continue; } - if (len == 1 && sc_String[0] == '*') + if (len == 1 && sc.String[0] == '*') { inCode = MAKE_ID('*',0,0,0); } - else if (len == 7 && stricmp (sc_String, "default") == 0) + else if (len == 7 && stricmp (sc.String, "default") == 0) { inCode = MAKE_ID('*','*',0,0); } else { - SC_ScriptError ("The language code must be 2 or 3 characters long.\n'%s' is %lu characters long.", - sc_String, len); + sc.ScriptError ("The language code must be 2 or 3 characters long.\n'%s' is %lu characters long.", + sc.String, len); } } else { - inCode = MAKE_ID(tolower(sc_String[0]), tolower(sc_String[1]), tolower(sc_String[2]), 0); + inCode = MAKE_ID(tolower(sc.String[0]), tolower(sc.String[1]), tolower(sc.String[2]), 0); } if ((inCode | orMask) == code) { @@ -199,11 +200,11 @@ void FStringTable::LoadLanguage (int lumpnum, DWORD code, bool exactMatch, int p skip = false; } } - SC_MustGetString (); - } while (!SC_Compare ("]")); + sc.MustGetString (); + } while (!sc.Compare ("]")); if (donot) { - SC_ScriptError ("You must specify a language after ~"); + sc.ScriptError ("You must specify a language after ~"); } skip |= forceskip; } @@ -211,30 +212,30 @@ void FStringTable::LoadLanguage (int lumpnum, DWORD code, bool exactMatch, int p { // Process string definitions. if (inCode == 0) { - SC_ScriptError ("Found a string without a language specified."); + sc.ScriptError ("Found a string without a language specified."); } if (skip) { // We're not interested in this language, so skip the string. - SC_MustGetStringName ("="); - SC_MustGetString (); + sc.MustGetStringName ("="); + sc.MustGetString (); do { - SC_MustGetString (); - } while (!SC_Compare (";")); + sc.MustGetString (); + } while (!sc.Compare (";")); continue; } - FString strName (sc_String); - SC_MustGetStringName ("="); - SC_MustGetString (); - FString strText (sc_String, ProcessEscapes (sc_String)); - SC_MustGetString (); - while (!SC_Compare (";")) + FString strName (sc.String); + sc.MustGetStringName ("="); + sc.MustGetString (); + FString strText (sc.String, ProcessEscapes (sc.String)); + sc.MustGetString (); + while (!sc.Compare (";")) { - ProcessEscapes (sc_String); - strText += sc_String; - SC_MustGetString (); + ProcessEscapes (sc.String); + strText += sc.String; + sc.MustGetString (); } // Does this string exist? If so, should we overwrite it? @@ -267,7 +268,6 @@ void FStringTable::LoadLanguage (int lumpnum, DWORD code, bool exactMatch, int p } } } - SC_Close (); } // Replace \ escape sequences in a string with the escaped characters. @@ -283,7 +283,7 @@ size_t FStringTable::ProcessEscapes (char *iptr) if (c == 'n') c = '\n'; else if (c == 'c') - c = -127 /*0x81*/; + c = TEXTCOLOR_ESCAPE; else if (c == 'r') c = '\r'; else if (c == 't') diff --git a/src/teaminfo.cpp b/src/teaminfo.cpp index 61d02e7bdf..04157eb2f6 100644 --- a/src/teaminfo.cpp +++ b/src/teaminfo.cpp @@ -49,7 +49,7 @@ // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- void TEAMINFO_Init (); -void TEAMINFO_ParseTeam (); +void TEAMINFO_ParseTeam (FScanner &sc); bool TEAMINFO_IsValidTeam (int team); @@ -84,17 +84,16 @@ void TEAMINFO_Init () while ((lump = Wads.FindLump ("TEAMINFO", &lastlump)) != -1) { - SC_OpenLumpNum (lump, "TEAMINFO"); - while (SC_GetString ()) + FScanner sc(lump, "TEAMINFO"); + while (sc.GetString ()) { - if (SC_Compare("CLEARTEAMS")) + if (sc.Compare("CLEARTEAMS")) teams.Clear (); - else if (SC_Compare("TEAM")) - TEAMINFO_ParseTeam (); + else if (sc.Compare("TEAM")) + TEAMINFO_ParseTeam (sc); else - SC_ScriptError ("Unknown command %s in TEAMINFO", sc_String); + sc.ScriptError ("Unknown command %s in TEAMINFO", sc.String); } - SC_Close(); } if (teams.Size () < 2) @@ -107,36 +106,34 @@ void TEAMINFO_Init () // //========================================================================== -void TEAMINFO_ParseTeam () +void TEAMINFO_ParseTeam (FScanner &sc) { TEAMINFO team; int i; - char *color; - SC_MustGetString (); - team.name = sc_String; + sc.MustGetString (); + team.name = sc.String; - SC_MustGetStringName("{"); - while (!SC_CheckString("}")) + sc.MustGetStringName("{"); + while (!sc.CheckString("}")) { - SC_MustGetString(); - switch(i = SC_MatchString (keywords_teaminfo)) + sc.MustGetString(); + switch(i = sc.MatchString (keywords_teaminfo)) { case 0: - SC_MustGetString (); - color = sc_String; - team.playercolor = V_GetColor (NULL, color); + sc.MustGetString (); + team.playercolor = V_GetColor (NULL, sc.String); break; case 1: - SC_MustGetString(); + sc.MustGetString(); team.textcolor = '['; - team.textcolor << sc_String << ']'; + team.textcolor << sc.String << ']'; break; case 2: - SC_MustGetString (); - team.logo = sc_String; + sc.MustGetString (); + team.logo = sc.String; break; default: diff --git a/src/thingdef/olddecorations.cpp b/src/thingdef/olddecorations.cpp index 220d627a02..3ad3ae9834 100644 --- a/src/thingdef/olddecorations.cpp +++ b/src/thingdef/olddecorations.cpp @@ -110,8 +110,8 @@ void A_ActiveSound (AActor *); // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- static void ParseInsideDecoration (FActorInfo *info, AActor *defaults, - TArray &states, FExtraInfo &extra, EDefinitionType def); -static void ParseSpriteFrames (FActorInfo *info, TArray &states); + TArray &states, FExtraInfo &extra, EDefinitionType def, FScanner &sc); +static void ParseSpriteFrames (FActorInfo *info, TArray &states, FScanner &sc); // PRIVATE DATA DEFINITIONS ------------------------------------------------ @@ -229,7 +229,7 @@ static const char *FlagNames3[] = // //========================================================================== -void ParseOldDecoration(EDefinitionType def) +void ParseOldDecoration(FScanner &sc, EDefinitionType def) { TArray states; FExtraInfo extra; @@ -241,37 +241,37 @@ void ParseOldDecoration(EDefinitionType def) if (def == DEF_Pickup) parent = RUNTIME_CLASS(AFakeInventory); else parent = RUNTIME_CLASS(AActor); - SC_MustGetString(); - typeName = FName(sc_String); + sc.MustGetString(); + typeName = FName(sc.String); type = parent->CreateDerivedClass (typeName, parent->Size); info = type->ActorInfo; info->GameFilter = 0x80; MakeStateDefines(parent->ActorInfo->StateList); - SC_MustGetString (); - while (!SC_Compare ("{")) + sc.MustGetString (); + while (!sc.Compare ("{")) { - if (SC_Compare ("Doom")) + if (sc.Compare ("Doom")) { info->GameFilter |= GAME_Doom; } - else if (SC_Compare ("Heretic")) + else if (sc.Compare ("Heretic")) { info->GameFilter |= GAME_Heretic; } - else if (SC_Compare ("Hexen")) + else if (sc.Compare ("Hexen")) { info->GameFilter |= GAME_Hexen; } - else if (SC_Compare ("Raven")) + else if (sc.Compare ("Raven")) { info->GameFilter |= GAME_Raven; } - else if (SC_Compare ("Strife")) + else if (sc.Compare ("Strife")) { info->GameFilter |= GAME_Strife; } - else if (SC_Compare ("Any")) + else if (sc.Compare ("Any")) { info->GameFilter = GAME_Any; } @@ -279,17 +279,17 @@ void ParseOldDecoration(EDefinitionType def) { if (def != DEF_Decoration || info->GameFilter != 0x80) { - SC_ScriptError ("Unknown game type %s in %s", sc_String, typeName.GetChars()); + sc.ScriptError ("Unknown game type %s in %s", sc.String, typeName.GetChars()); } else { // If this is a regular decoration (without preceding keyword) and no game // filters defined this is more likely a general syntax error so output a // more meaningful message. - SC_ScriptError ("Syntax error: Unknown identifier '%s'", typeName.GetChars()); + sc.ScriptError ("Syntax error: Unknown identifier '%s'", typeName.GetChars()); } } - SC_MustGetString (); + sc.MustGetString (); } if (info->GameFilter == 0x80) { @@ -302,24 +302,24 @@ void ParseOldDecoration(EDefinitionType def) states.Clear (); memset (&extra, 0, sizeof(extra)); - ParseInsideDecoration (info, (AActor *)(type->Defaults), states, extra, def); + ParseInsideDecoration (info, (AActor *)(type->Defaults), states, extra, def, sc); info->NumOwnedStates = states.Size(); if (info->NumOwnedStates == 0) { - SC_ScriptError ("%s does not define any animation frames", typeName.GetChars() ); + sc.ScriptError ("%s does not define any animation frames", typeName.GetChars() ); } else if (extra.SpawnEnd == 0) { - SC_ScriptError ("%s does not have a Frames definition", typeName.GetChars() ); + sc.ScriptError ("%s does not have a Frames definition", typeName.GetChars() ); } else if (def == DEF_BreakableDecoration && extra.DeathEnd == 0) { - SC_ScriptError ("%s does not have a DeathFrames definition", typeName.GetChars() ); + sc.ScriptError ("%s does not have a DeathFrames definition", typeName.GetChars() ); } else if (extra.IceDeathEnd != 0 && extra.bGenericIceDeath) { - SC_ScriptError ("You cannot use IceDeathFrames and GenericIceDeath together"); + sc.ScriptError ("You cannot use IceDeathFrames and GenericIceDeath together"); } if (extra.IceDeathEnd != 0) @@ -483,275 +483,271 @@ void ParseOldDecoration(EDefinitionType def) //========================================================================== static void ParseInsideDecoration (FActorInfo *info, AActor *defaults, - TArray &states, FExtraInfo &extra, EDefinitionType def) + TArray &states, FExtraInfo &extra, EDefinitionType def, FScanner &sc) { AFakeInventory *const inv = static_cast(defaults); char sprite[5] = "TNT1"; - SC_MustGetString (); - while (!SC_Compare ("}")) + sc.MustGetString (); + while (!sc.Compare ("}")) { - if (SC_Compare ("DoomEdNum")) + if (sc.Compare ("DoomEdNum")) { - SC_MustGetNumber (); - if (sc_Number < -1 || sc_Number > 32767) + sc.MustGetNumber (); + if (sc.Number < -1 || sc.Number > 32767) { - SC_ScriptError ("DoomEdNum must be in the range [-1,32767]"); + sc.ScriptError ("DoomEdNum must be in the range [-1,32767]"); } - info->DoomEdNum = (SWORD)sc_Number; + info->DoomEdNum = (SWORD)sc.Number; } - else if (SC_Compare ("SpawnNum")) + else if (sc.Compare ("SpawnNum")) { - SC_MustGetNumber (); - if (sc_Number < 0 || sc_Number > 255) + sc.MustGetNumber (); + if (sc.Number < 0 || sc.Number > 255) { - SC_ScriptError ("SpawnNum must be in the range [0,255]"); + sc.ScriptError ("SpawnNum must be in the range [0,255]"); } - info->SpawnID = (BYTE)sc_Number; + info->SpawnID = (BYTE)sc.Number; } - else if (SC_Compare ("Sprite") || ( + else if (sc.Compare ("Sprite") || ( (def == DEF_BreakableDecoration || def == DEF_Projectile) && - SC_Compare ("DeathSprite") && + sc.Compare ("DeathSprite") && (extra.DeathSprite[0] = 1)) // This is intentionally = and not == ) { - SC_MustGetString (); - if (strlen (sc_String) != 4) + sc.MustGetString (); + if (sc.StringLen != 4) { - SC_ScriptError ("Sprite name must be exactly four characters long"); + sc.ScriptError ("Sprite name must be exactly four characters long"); } if (extra.DeathSprite[0] == 1) { - memcpy (extra.DeathSprite, sc_String, 4); + memcpy (extra.DeathSprite, sc.String, 4); } else { - memcpy (sprite, sc_String, 4); + memcpy (sprite, sc.String, 4); } } - else if (SC_Compare ("Frames")) + else if (sc.Compare ("Frames")) { - SC_MustGetString (); + sc.MustGetString (); extra.SpawnStart = states.Size(); - ParseSpriteFrames (info, states); + ParseSpriteFrames (info, states, sc); extra.SpawnEnd = states.Size(); } else if ((def == DEF_BreakableDecoration || def == DEF_Projectile) && - SC_Compare ("DeathFrames")) + sc.Compare ("DeathFrames")) { - SC_MustGetString (); + sc.MustGetString (); extra.DeathStart = states.Size(); - ParseSpriteFrames (info, states); + ParseSpriteFrames (info, states, sc); extra.DeathEnd = states.Size(); } - else if (def == DEF_BreakableDecoration && SC_Compare ("IceDeathFrames")) + else if (def == DEF_BreakableDecoration && sc.Compare ("IceDeathFrames")) { - SC_MustGetString (); + sc.MustGetString (); extra.IceDeathStart = states.Size(); - ParseSpriteFrames (info, states); + ParseSpriteFrames (info, states, sc); extra.IceDeathEnd = states.Size(); } - else if (def == DEF_BreakableDecoration && SC_Compare ("BurnDeathFrames")) + else if (def == DEF_BreakableDecoration && sc.Compare ("BurnDeathFrames")) { - SC_MustGetString (); + sc.MustGetString (); extra.FireDeathStart = states.Size(); - ParseSpriteFrames (info, states); + ParseSpriteFrames (info, states, sc); extra.FireDeathEnd = states.Size(); } - else if (def == DEF_BreakableDecoration && SC_Compare ("GenericIceDeath")) + else if (def == DEF_BreakableDecoration && sc.Compare ("GenericIceDeath")) { extra.bGenericIceDeath = true; } - else if (def == DEF_BreakableDecoration && SC_Compare ("BurnsAway")) + else if (def == DEF_BreakableDecoration && sc.Compare ("BurnsAway")) { extra.bBurnAway = true; } - else if (def == DEF_BreakableDecoration && SC_Compare ("DiesAway")) + else if (def == DEF_BreakableDecoration && sc.Compare ("DiesAway")) { extra.bDiesAway = true; } - else if (SC_Compare ("Alpha")) + else if (sc.Compare ("Alpha")) { - SC_MustGetFloat (); - defaults->alpha = int(clamp (sc_Float, 0.0, 1.0) * OPAQUE); + sc.MustGetFloat (); + defaults->alpha = int(clamp (sc.Float, 0.0, 1.0) * OPAQUE); } - else if (SC_Compare ("Scale")) + else if (sc.Compare ("Scale")) { - SC_MustGetFloat (); - defaults->scaleX = defaults->scaleY = FLOAT2FIXED(sc_Float); + sc.MustGetFloat (); + defaults->scaleX = defaults->scaleY = FLOAT2FIXED(sc.Float); } - else if (SC_Compare ("RenderStyle")) + else if (sc.Compare ("RenderStyle")) { - SC_MustGetString (); - defaults->RenderStyle = SC_MustMatchString (RenderStyles); - if (defaults->RenderStyle > STYLE_OptFuzzy) - { - defaults->RenderStyle += STYLE_Translucent - STYLE_OptFuzzy - 1; - } + sc.MustGetString (); + defaults->RenderStyle = LegacyRenderStyles[sc.MustMatchString (RenderStyles)]; } - else if (SC_Compare ("Radius")) + else if (sc.Compare ("Radius")) { - SC_MustGetFloat (); - defaults->radius = int(sc_Float * FRACUNIT); + sc.MustGetFloat (); + defaults->radius = int(sc.Float * FRACUNIT); } - else if (SC_Compare ("Height")) + else if (sc.Compare ("Height")) { - SC_MustGetFloat (); - defaults->height = int(sc_Float * FRACUNIT); + sc.MustGetFloat (); + defaults->height = int(sc.Float * FRACUNIT); } - else if (def == DEF_BreakableDecoration && SC_Compare ("DeathHeight")) + else if (def == DEF_BreakableDecoration && sc.Compare ("DeathHeight")) { - SC_MustGetFloat (); - extra.DeathHeight = int(sc_Float * FRACUNIT); + sc.MustGetFloat (); + extra.DeathHeight = int(sc.Float * FRACUNIT); } - else if (def == DEF_BreakableDecoration && SC_Compare ("BurnHeight")) + else if (def == DEF_BreakableDecoration && sc.Compare ("BurnHeight")) { - SC_MustGetFloat (); - extra.BurnHeight = int(sc_Float * FRACUNIT); + sc.MustGetFloat (); + extra.BurnHeight = int(sc.Float * FRACUNIT); } - else if (def == DEF_BreakableDecoration && SC_Compare ("Health")) + else if (def == DEF_BreakableDecoration && sc.Compare ("Health")) { - SC_MustGetNumber (); - defaults->health = sc_Number; + sc.MustGetNumber (); + defaults->health = sc.Number; } - else if (def == DEF_Projectile && SC_Compare ("ExplosionRadius")) + else if (def == DEF_Projectile && sc.Compare ("ExplosionRadius")) { - SC_MustGetNumber (); - info->Class->Meta.SetMetaInt(ACMETA_ExplosionRadius, sc_Number); + sc.MustGetNumber (); + info->Class->Meta.SetMetaInt(ACMETA_ExplosionRadius, sc.Number); extra.bExplosive = true; } - else if (def == DEF_Projectile && SC_Compare ("ExplosionDamage")) + else if (def == DEF_Projectile && sc.Compare ("ExplosionDamage")) { - SC_MustGetNumber (); - info->Class->Meta.SetMetaInt(ACMETA_ExplosionDamage, sc_Number); + sc.MustGetNumber (); + info->Class->Meta.SetMetaInt(ACMETA_ExplosionDamage, sc.Number); extra.bExplosive = true; } - else if (def == DEF_Projectile && SC_Compare ("DoNotHurtShooter")) + else if (def == DEF_Projectile && sc.Compare ("DoNotHurtShooter")) { info->Class->Meta.SetMetaInt(ACMETA_DontHurtShooter, true); } - else if (def == DEF_Projectile && SC_Compare ("Damage")) + else if (def == DEF_Projectile && sc.Compare ("Damage")) { - SC_MustGetNumber (); - defaults->Damage = sc_Number; + sc.MustGetNumber (); + defaults->Damage = sc.Number; } - else if (def == DEF_Projectile && SC_Compare ("DamageType")) + else if (def == DEF_Projectile && sc.Compare ("DamageType")) { - SC_MustGetString (); - if (SC_Compare ("Normal")) + sc.MustGetString (); + if (sc.Compare ("Normal")) { defaults->DamageType = NAME_None; } else { - defaults->DamageType = sc_String; + defaults->DamageType = sc.String; } } - else if (def == DEF_Projectile && SC_Compare ("Speed")) + else if (def == DEF_Projectile && sc.Compare ("Speed")) { - SC_MustGetFloat (); - defaults->Speed = fixed_t(sc_Float * 65536.f); + sc.MustGetFloat (); + defaults->Speed = fixed_t(sc.Float * 65536.f); } - else if (SC_Compare ("Mass")) + else if (sc.Compare ("Mass")) { - SC_MustGetFloat (); - defaults->Mass = SDWORD(sc_Float); + sc.MustGetFloat (); + defaults->Mass = SDWORD(sc.Float); } - else if (SC_Compare ("Translation1")) + else if (sc.Compare ("Translation1")) { - SC_MustGetNumber (); - if (sc_Number < 0 || sc_Number > 2) + sc.MustGetNumber (); + if (sc.Number < 0 || sc.Number > 2) { - SC_ScriptError ("Translation1 must be in the range [0,2]"); + sc.ScriptError ("Translation1 must be in the range [0,2]"); } - defaults->Translation = TRANSLATION(TRANSLATION_Standard, sc_Number); + defaults->Translation = TRANSLATION(TRANSLATION_Standard, sc.Number); } - else if (SC_Compare ("Translation2")) + else if (sc.Compare ("Translation2")) { - SC_MustGetNumber (); - if (sc_Number < 0 || sc_Number >= MAX_ACS_TRANSLATIONS) + sc.MustGetNumber (); + if (sc.Number < 0 || sc.Number >= MAX_ACS_TRANSLATIONS) { #define ERROR(foo) "Translation2 must be in the range [0," #foo "]" - SC_ScriptError (ERROR(MAX_ACS_TRANSLATIONS)); + sc.ScriptError (ERROR(MAX_ACS_TRANSLATIONS)); #undef ERROR } - defaults->Translation = TRANSLATION(TRANSLATION_LevelScripted, sc_Number); + defaults->Translation = TRANSLATION(TRANSLATION_LevelScripted, sc.Number); } else if ((def == DEF_BreakableDecoration || def == DEF_Projectile) && - SC_Compare ("DeathSound")) + sc.Compare ("DeathSound")) { - SC_MustGetString (); - defaults->DeathSound = S_FindSound (sc_String); + sc.MustGetString (); + defaults->DeathSound = S_FindSound (sc.String); } - else if (def == DEF_BreakableDecoration && SC_Compare ("BurnDeathSound")) + else if (def == DEF_BreakableDecoration && sc.Compare ("BurnDeathSound")) { - SC_MustGetString (); - defaults->ActiveSound = S_FindSound (sc_String); + sc.MustGetString (); + defaults->ActiveSound = S_FindSound (sc.String); } - else if (def == DEF_Projectile && SC_Compare ("SpawnSound")) + else if (def == DEF_Projectile && sc.Compare ("SpawnSound")) { - SC_MustGetString (); - defaults->SeeSound = S_FindSound (sc_String); + sc.MustGetString (); + defaults->SeeSound = S_FindSound (sc.String); } - else if (def == DEF_Projectile && SC_Compare ("DoomBounce")) + else if (def == DEF_Projectile && sc.Compare ("DoomBounce")) { defaults->flags2 = (defaults->flags2 & ~MF2_BOUNCETYPE) | MF2_DOOMBOUNCE; } - else if (def == DEF_Projectile && SC_Compare ("HereticBounce")) + else if (def == DEF_Projectile && sc.Compare ("HereticBounce")) { defaults->flags2 = (defaults->flags2 & ~MF2_BOUNCETYPE) | MF2_HERETICBOUNCE; } - else if (def == DEF_Projectile && SC_Compare ("HexenBounce")) + else if (def == DEF_Projectile && sc.Compare ("HexenBounce")) { defaults->flags2 = (defaults->flags2 & ~MF2_BOUNCETYPE) | MF2_HEXENBOUNCE; } - else if (def == DEF_Pickup && SC_Compare ("PickupSound")) + else if (def == DEF_Pickup && sc.Compare ("PickupSound")) { - SC_MustGetString (); - inv->PickupSound = S_FindSound (sc_String); + sc.MustGetString (); + inv->PickupSound = S_FindSound (sc.String); } - else if (def == DEF_Pickup && SC_Compare ("PickupMessage")) + else if (def == DEF_Pickup && sc.Compare ("PickupMessage")) { - SC_MustGetString (); - info->Class->Meta.SetMetaString(AIMETA_PickupMessage, sc_String); + sc.MustGetString (); + info->Class->Meta.SetMetaString(AIMETA_PickupMessage, sc.String); } - else if (def == DEF_Pickup && SC_Compare ("Respawns")) + else if (def == DEF_Pickup && sc.Compare ("Respawns")) { inv->Respawnable = true; } - else if (def == DEF_BreakableDecoration && SC_Compare ("SolidOnDeath")) + else if (def == DEF_BreakableDecoration && sc.Compare ("SolidOnDeath")) { extra.bSolidOnDeath = true; } - else if (def == DEF_BreakableDecoration && SC_Compare ("SolidOnBurn")) + else if (def == DEF_BreakableDecoration && sc.Compare ("SolidOnBurn")) { extra.bSolidOnBurn = true; } - else if (sc_String[0] != '*') + else if (sc.String[0] != '*') { - int bit = SC_MatchString (FlagNames1); + int bit = sc.MatchString (FlagNames1); if (bit != -1) { defaults->flags |= 1 << bit; } - else if ((bit = SC_MatchString (FlagNames2)) != -1) + else if ((bit = sc.MatchString (FlagNames2)) != -1) { defaults->flags2 |= 1 << bit; } - else if ((bit = SC_MatchString (FlagNames3)) != -1) + else if ((bit = sc.MatchString (FlagNames3)) != -1) { defaults->flags3 |= 1 << bit; } else { - SC_ScriptError (NULL); + sc.ScriptError (NULL); } } else { - SC_ScriptError (NULL); + sc.ScriptError (NULL); } - SC_MustGetString (); + sc.MustGetString (); } unsigned int i; @@ -798,10 +794,10 @@ static void ParseInsideDecoration (FActorInfo *info, AActor *defaults, // "10:A, 15:B, 8:C, 6:B" //========================================================================== -static void ParseSpriteFrames (FActorInfo *info, TArray &states) +static void ParseSpriteFrames (FActorInfo *info, TArray &states, FScanner &sc) { FState state; - char *token = strtok (sc_String, ",\t\n\r"); + char *token = strtok (sc.String, ",\t\n\r"); memset (&state, 0, sizeof(state)); @@ -823,7 +819,7 @@ static void ParseSpriteFrames (FActorInfo *info, TArray &states) rate = strtol (token, &stop, 10); if (stop == token || rate < 1 || rate > 65534) { - SC_ScriptError ("Rates must be in the range [0,65534]"); + sc.ScriptError ("Rates must be in the range [0,65534]"); } token = colon + 1; rate += 1; @@ -841,13 +837,13 @@ static void ParseSpriteFrames (FActorInfo *info, TArray &states) { if (firstState) { - SC_ScriptError ("* must come after a frame"); + sc.ScriptError ("* must come after a frame"); } state.Frame |= SF_FULLBRIGHT; } else if (*token < 'A' || *token > ']') { - SC_ScriptError ("Frames must be A-Z, [, \\, or ]"); + sc.ScriptError ("Frames must be A-Z, [, \\, or ]"); } else { diff --git a/src/thingdef/thingdef.cpp b/src/thingdef/thingdef.cpp index e69b2859de..47f2f62922 100644 --- a/src/thingdef/thingdef.cpp +++ b/src/thingdef/thingdef.cpp @@ -82,16 +82,16 @@ const PClass *QuestItemClasses[31]; // //========================================================================== -void ParseConstant (PSymbolTable * symt, PClass *cls) +void ParseConstant (FScanner &sc, PSymbolTable * symt, PClass *cls) { // Read the type and make sure it's int. // (Maybe there will be other types later.) - SC_MustGetToken(TK_Int); - SC_MustGetToken(TK_Identifier); - FName symname = sc_String; - SC_MustGetToken('='); - int expr = ParseExpression (false, cls); - SC_MustGetToken(';'); + sc.MustGetToken(TK_Int); + sc.MustGetToken(TK_Identifier); + FName symname = sc.String; + sc.MustGetToken('='); + int expr = ParseExpression (sc, false, cls); + sc.MustGetToken(';'); int val = EvalExpressionI (expr, NULL, cls); PSymbolConst *sym = new PSymbolConst; @@ -101,7 +101,7 @@ void ParseConstant (PSymbolTable * symt, PClass *cls) if (symt->AddSymbol (sym) == NULL) { delete sym; - SC_ScriptError ("'%s' is already defined in class '%s'.", + sc.ScriptError ("'%s' is already defined in class '%s'.", symname.GetChars(), cls->TypeName.GetChars()); } } @@ -114,19 +114,19 @@ void ParseConstant (PSymbolTable * symt, PClass *cls) // //========================================================================== -void ParseEnum (PSymbolTable * symt, PClass *cls) +void ParseEnum (FScanner &sc, PSymbolTable *symt, PClass *cls) { int currvalue = 0; - SC_MustGetToken('{'); - while (!SC_CheckToken('}')) + sc.MustGetToken('{'); + while (!sc.CheckToken('}')) { - SC_MustGetToken(TK_Identifier); - FName symname = sc_String; - if (SC_CheckToken('=')) + sc.MustGetToken(TK_Identifier); + FName symname = sc.String; + if (sc.CheckToken('=')) { - int expr = ParseExpression(false, cls); - currvalue = EvalExpressionI (expr, NULL, cls); + int expr = ParseExpression(sc, false, cls); + currvalue = EvalExpressionI(expr, NULL, cls); } PSymbolConst *sym = new PSymbolConst; sym->SymbolName = symname; @@ -135,15 +135,15 @@ void ParseEnum (PSymbolTable * symt, PClass *cls) if (symt->AddSymbol (sym) == NULL) { delete sym; - SC_ScriptError ("'%s' is already defined in class '%s'.", + sc.ScriptError ("'%s' is already defined in class '%s'.", symname.GetChars(), cls->TypeName.GetChars()); } // This allows a comma after the last value but doesn't enforce it. - if (SC_CheckToken('}')) break; - SC_MustGetToken(','); + if (sc.CheckToken('}')) break; + sc.MustGetToken(','); currvalue++; } - SC_MustGetToken(';'); + sc.MustGetToken(';'); } //========================================================================== @@ -156,7 +156,7 @@ void ParseEnum (PSymbolTable * symt, PClass *cls) // //========================================================================== -static void ParseActionDef (PClass *cls) +static void ParseActionDef (FScanner &sc, PClass *cls) { #define OPTIONAL 1 #define EVAL 2 @@ -166,18 +166,18 @@ static void ParseActionDef (PClass *cls) FName funcname; FString args; - SC_MustGetToken(TK_Native); - SC_MustGetToken(TK_Identifier); - funcname = sc_String; - afd = FindFunction(sc_String); + sc.MustGetToken(TK_Native); + sc.MustGetToken(TK_Identifier); + funcname = sc.String; + afd = FindFunction(sc.String); if (afd == NULL) { - SC_ScriptError ("The function '%s' has not been exported from the executable.", sc_String); + sc.ScriptError ("The function '%s' has not been exported from the executable.", sc.String); } - SC_MustGetToken('('); - if (!SC_CheckToken(')')) + sc.MustGetToken('('); + if (!sc.CheckToken(')')) { - while (sc_TokenType != ')') + while (sc.TokenType != ')') { int flags = 0; char type = '@'; @@ -185,19 +185,19 @@ static void ParseActionDef (PClass *cls) // Retrieve flags before type name for (;;) { - if (SC_CheckToken(TK_Optional)) + if (sc.CheckToken(TK_Optional)) { flags |= OPTIONAL; } - else if (SC_CheckToken(TK_Eval)) + else if (sc.CheckToken(TK_Eval)) { flags |= EVAL; } - else if (SC_CheckToken(TK_EvalNot)) + else if (sc.CheckToken(TK_EvalNot)) { flags |= EVALNOT; } - else if (SC_CheckToken(TK_Coerce) || SC_CheckToken(TK_Native)) + else if (sc.CheckToken(TK_Coerce) || sc.CheckToken(TK_Native)) { } else @@ -206,8 +206,8 @@ static void ParseActionDef (PClass *cls) } } // Read the variable type - SC_MustGetAnyToken(); - switch (sc_TokenType) + sc.MustGetAnyToken(); + switch (sc.TokenType) { case TK_Bool: type = 'i'; break; case TK_Int: type = 'i'; break; @@ -218,28 +218,28 @@ static void ParseActionDef (PClass *cls) case TK_State: type = 'l'; break; case TK_Color: type = 'c'; break; case TK_Class: - SC_MustGetToken('<'); - SC_MustGetToken(TK_Identifier); // Skip class name, since the parser doesn't care - SC_MustGetToken('>'); + sc.MustGetToken('<'); + sc.MustGetToken(TK_Identifier); // Skip class name, since the parser doesn't care + sc.MustGetToken('>'); type = 'm'; break; case TK_Ellipsis: type = '+'; - SC_MustGetToken(')'); - SC_UnGet(); + sc.MustGetToken(')'); + sc.UnGet(); break; default: - SC_ScriptError ("Unknown variable type %s", SC_TokenName(sc_TokenType, sc_String).GetChars()); + sc.ScriptError ("Unknown variable type %s", sc.TokenName(sc.TokenType, sc.String).GetChars()); break; } // Read the optional variable name - if (!SC_CheckToken(',') && !SC_CheckToken(')')) + if (!sc.CheckToken(',') && !sc.CheckToken(')')) { - SC_MustGetToken(TK_Identifier); + sc.MustGetToken(TK_Identifier); } else { - SC_UnGet(); + sc.UnGet(); } // If eval or evalnot were a flag, hey the decorate parser doesn't actually care about the type. if (flags & EVALNOT) @@ -258,14 +258,14 @@ static void ParseActionDef (PClass *cls) #undef EVAL #undef EVALNOT args += type; - SC_MustGetAnyToken(); - if (sc_TokenType != ',' && sc_TokenType != ')') + sc.MustGetAnyToken(); + if (sc.TokenType != ',' && sc.TokenType != ')') { - SC_ScriptError ("Expected ',' or ')' but got %s instead", SC_TokenName(sc_TokenType, sc_String).GetChars()); + sc.ScriptError ("Expected ',' or ')' but got %s instead", sc.TokenName(sc.TokenType, sc.String).GetChars()); } } } - SC_MustGetToken(';'); + sc.MustGetToken(';'); PSymbolActionFunction *sym = new PSymbolActionFunction; sym->SymbolName = funcname; sym->SymbolType = SYM_ActionFunction; @@ -274,7 +274,7 @@ static void ParseActionDef (PClass *cls) if (cls->Symbols.AddSymbol (sym) == NULL) { delete sym; - SC_ScriptError ("'%s' is already defined in class '%s'.", + sc.ScriptError ("'%s' is already defined in class '%s'.", funcname.GetChars(), cls->TypeName.GetChars()); } } @@ -284,27 +284,27 @@ static void ParseActionDef (PClass *cls) // Starts a new actor definition // //========================================================================== -static FActorInfo * CreateNewActor(FActorInfo ** parentc, Baggage *bag) +static FActorInfo *CreateNewActor(FScanner &sc, FActorInfo **parentc, Baggage *bag) { FName typeName; // Get actor name - SC_MustGetString(); + sc.MustGetString(); - char * colon = strchr(sc_String, ':'); + char *colon = strchr(sc.String, ':'); if (colon != NULL) { *colon++ = 0; } - if (PClass::FindClass (sc_String) != NULL) + if (PClass::FindClass (sc.String) != NULL) { - SC_ScriptError ("Actor %s is already defined.", sc_String); + sc.ScriptError ("Actor %s is already defined.", sc.String); } - typeName = sc_String; + typeName = sc.String; - PClass * parent = RUNTIME_CLASS(AActor); + PClass *parent = RUNTIME_CLASS(AActor); if (parentc) { *parentc = NULL; @@ -313,10 +313,10 @@ static FActorInfo * CreateNewActor(FActorInfo ** parentc, Baggage *bag) // without having resort to C-mode (which disallows periods in actor names.) if (colon == NULL) { - SC_MustGetString (); - if (sc_String[0]==':') + sc.MustGetString (); + if (sc.String[0]==':') { - colon = sc_String + 1; + colon = sc.String + 1; } } @@ -324,8 +324,8 @@ static FActorInfo * CreateNewActor(FActorInfo ** parentc, Baggage *bag) { if (colon[0] == 0) { - SC_MustGetString (); - colon = sc_String; + sc.MustGetString (); + colon = sc.String; } } @@ -335,22 +335,22 @@ static FActorInfo * CreateNewActor(FActorInfo ** parentc, Baggage *bag) if (parent == NULL) { - SC_ScriptError ("Parent type '%s' not found", colon); + sc.ScriptError ("Parent type '%s' not found", colon); } else if (parent->ActorInfo == NULL) { - SC_ScriptError ("Parent type '%s' is not an actor", colon); + sc.ScriptError ("Parent type '%s' is not an actor", colon); } else { *parentc = parent->ActorInfo; } } - else SC_UnGet(); + else sc.UnGet(); } - PClass * ti = parent->CreateDerivedClass (typeName, parent->Size); - FActorInfo * info = ti->ActorInfo; + PClass *ti = parent->CreateDerivedClass (typeName, parent->Size); + FActorInfo *info = ti->ActorInfo; MakeStateDefines(parent->ActorInfo->StateList); @@ -372,38 +372,38 @@ static FActorInfo * CreateNewActor(FActorInfo ** parentc, Baggage *bag) } // Check for "replaces" - SC_MustGetString (); - if (SC_Compare ("replaces")) + sc.MustGetString (); + if (sc.Compare ("replaces")) { const PClass *replacee; // Get actor name - SC_MustGetString (); - replacee = PClass::FindClass (sc_String); + sc.MustGetString (); + replacee = PClass::FindClass (sc.String); if (replacee == NULL) { - SC_ScriptError ("Replaced type '%s' not found", sc_String); + sc.ScriptError ("Replaced type '%s' not found", sc.String); } else if (replacee->ActorInfo == NULL) { - SC_ScriptError ("Replaced type '%s' is not an actor", sc_String); + sc.ScriptError ("Replaced type '%s' is not an actor", sc.String); } replacee->ActorInfo->Replacement = ti->ActorInfo; ti->ActorInfo->Replacee = replacee->ActorInfo; } else { - SC_UnGet(); + sc.UnGet(); } // Now, after the actor names have been parsed, it is time to switch to C-mode // for the rest of the actor definition. - SC_SetCMode (true); - if (SC_CheckNumber()) + sc.SetCMode (true); + if (sc.CheckNumber()) { - if (sc_Number>=-1 && sc_Number<32768) info->DoomEdNum = sc_Number; - else SC_ScriptError ("DoomEdNum must be in the range [-1,32767]"); + if (sc.Number>=-1 && sc.Number<32768) info->DoomEdNum = sc.Number; + else sc.ScriptError ("DoomEdNum must be in the range [-1,32767]"); } if (parent == RUNTIME_CLASS(AWeapon)) { @@ -419,7 +419,7 @@ static FActorInfo * CreateNewActor(FActorInfo ** parentc, Baggage *bag) // Reads an actor definition // //========================================================================== -void ParseActor() +void ParseActor(FScanner &sc) { FActorInfo * info=NULL; Baggage bag; @@ -428,43 +428,43 @@ void ParseActor() { FActorInfo * parent; - info=CreateNewActor(&parent, &bag); - SC_MustGetToken('{'); - while (SC_MustGetAnyToken(), sc_TokenType != '}') + info = CreateNewActor(sc, &parent, &bag); + sc.MustGetToken('{'); + while (sc.MustGetAnyToken(), sc.TokenType != '}') { - switch (sc_TokenType) + switch (sc.TokenType) { case TK_Action: - ParseActionDef (info->Class); + ParseActionDef (sc, info->Class); break; case TK_Const: - ParseConstant (&info->Class->Symbols, info->Class); + ParseConstant (sc, &info->Class->Symbols, info->Class); break; case TK_Enum: - ParseEnum (&info->Class->Symbols, info->Class); + ParseEnum (sc, &info->Class->Symbols, info->Class); break; case TK_Identifier: // other identifier related checks here case TK_Projectile: // special case: both keyword and property name - ParseActorProperty(bag); + ParseActorProperty(sc, bag); break; case '+': case '-': - ParseActorFlag(bag, sc_TokenType); + ParseActorFlag(sc, bag, sc.TokenType); break; default: - SC_ScriptError("Unexpected '%s' in definition of '%s'", sc_String, bag.Info->Class->TypeName.GetChars()); + sc.ScriptError("Unexpected '%s' in definition of '%s'", sc.String, bag.Info->Class->TypeName.GetChars()); break; } } - FinishActor(info, bag); + FinishActor(sc, info, bag); } catch(CRecoverableError & e) @@ -476,13 +476,13 @@ void ParseActor() catch (...) { if (info) - SC_ScriptError("Unexpected error during parsing of actor %s", info->Class->TypeName.GetChars()); + sc.ScriptError("Unexpected error during parsing of actor %s", info->Class->TypeName.GetChars()); else - SC_ScriptError("Unexpected error during parsing of actor definitions"); + sc.ScriptError("Unexpected error during parsing of actor definitions"); } #endif - SC_SetCMode (false); + sc.SetCMode (false); } //========================================================================== @@ -635,52 +635,52 @@ void FinishThingdef() // //========================================================================== -void ParseClass() +void ParseClass(FScanner &sc) { Baggage bag; PClass *cls; FName classname; FName supername; - SC_MustGetToken(TK_Identifier); // class name - classname = sc_String; - SC_MustGetToken(TK_Extends); // because I'm not supporting Object - SC_MustGetToken(TK_Identifier); // superclass name - supername = sc_String; - SC_MustGetToken(TK_Native); // use actor definitions for your own stuff - SC_MustGetToken('{'); + sc.MustGetToken(TK_Identifier); // class name + classname = sc.String; + sc.MustGetToken(TK_Extends); // because I'm not supporting Object + sc.MustGetToken(TK_Identifier); // superclass name + supername = sc.String; + sc.MustGetToken(TK_Native); // use actor definitions for your own stuff + sc.MustGetToken('{'); cls = const_cast(PClass::FindClass (classname)); if (cls == NULL) { - SC_ScriptError ("'%s' is not a native class", classname.GetChars()); + sc.ScriptError ("'%s' is not a native class", classname.GetChars()); } if (cls->ParentClass == NULL || cls->ParentClass->TypeName != supername) { - SC_ScriptError ("'%s' does not extend '%s'", classname.GetChars(), supername.GetChars()); + sc.ScriptError ("'%s' does not extend '%s'", classname.GetChars(), supername.GetChars()); } bag.Info = cls->ActorInfo; - SC_MustGetAnyToken(); - while (sc_TokenType != '}') + sc.MustGetAnyToken(); + while (sc.TokenType != '}') { - if (sc_TokenType == TK_Action) + if (sc.TokenType == TK_Action) { - ParseActionDef(cls); + ParseActionDef(sc, cls); } - else if (sc_TokenType == TK_Const) + else if (sc.TokenType == TK_Const) { - ParseConstant(&cls->Symbols, cls); + ParseConstant(sc, &cls->Symbols, cls); } - else if (sc_TokenType == TK_Enum) + else if (sc.TokenType == TK_Enum) { - ParseEnum(&cls->Symbols, cls); + ParseEnum(sc, &cls->Symbols, cls); } else { - FString tokname = SC_TokenName(sc_TokenType, sc_String); - SC_ScriptError ("Expected 'action', 'const' or 'enum' but got %s", tokname.GetChars()); + FString tokname = sc.TokenName(sc.TokenType, sc.String); + sc.ScriptError ("Expected 'action', 'const' or 'enum' but got %s", tokname.GetChars()); } - SC_MustGetAnyToken(); + sc.MustGetAnyToken(); } } diff --git a/src/thingdef/thingdef.h b/src/thingdef/thingdef.h index e34d58aca3..0d78c1483d 100644 --- a/src/thingdef/thingdef.h +++ b/src/thingdef/thingdef.h @@ -1,6 +1,8 @@ #ifndef __THINGDEF_H #define __THINGDEF_H +class FScanner; + //========================================================================== // // This class is for storing a name inside a const PClass* field without @@ -97,9 +99,9 @@ FState * FindState(AActor * actor, const PClass * type, const char * name); void InstallStates(FActorInfo *info, AActor *defaults); void MakeStateDefines(const FStateLabels *list); FState *P_GetState(AActor *self, FState *CallingState, int offset); -int FinishStates (FActorInfo *actor, AActor *defaults, Baggage &bag); -int ParseStates(FActorInfo * actor, AActor * defaults, Baggage &bag); -FState *CheckState(PClass *type); +int FinishStates (FScanner &sc, FActorInfo *actor, AActor *defaults, Baggage &bag); +int ParseStates(FScanner &sc, FActorInfo *actor, AActor *defaults, Baggage &bag); +FState *CheckState(FScanner &sc, PClass *type); //========================================================================== @@ -108,15 +110,15 @@ FState *CheckState(PClass *type); // //========================================================================== -void ParseActorProperty(Baggage &bag); -void ParseActorFlag (Baggage &bag, int mod); -void FinishActor(FActorInfo *info, Baggage &bag); +void ParseActorProperty(FScanner &sc, Baggage &bag); +void ParseActorFlag (FScanner &sc, Baggage &bag, int mod); +void FinishActor(FScanner &sc, FActorInfo *info, Baggage &bag); -void ParseConstant (PSymbolTable * symt, PClass *cls); -void ParseEnum (PSymbolTable * symt, PClass *cls); +void ParseConstant (FScanner &sc, PSymbolTable *symt, PClass *cls); +void ParseEnum (FScanner &sc, PSymbolTable *symt, PClass *cls); -int ParseExpression (bool _not, PClass *cls); +int ParseExpression (FScanner &sc, bool _not, PClass *cls); int EvalExpressionI (int id, AActor *self, const PClass *cls=NULL); float EvalExpressionF (int id, AActor *self, const PClass *cls=NULL); diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 4b362d8077..2d63010a2c 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -1190,21 +1190,22 @@ void A_RailAttack (AActor * self) void A_CustomRailgun (AActor *actor) { - if (!actor->target) + int index = CheckIndex(7); + if (index < 0) return; + + int Damage = EvalExpressionI (StateParameters[index], actor); + int Spawnofs_XY = EvalExpressionI (StateParameters[index+1], actor); + int Color1 = StateParameters[index+2]; + int Color2 = StateParameters[index+3]; + bool Silent = !!EvalExpressionI (StateParameters[index+4], actor); + bool aim = !!EvalExpressionI (StateParameters[index+5], actor); + float MaxDiff = EvalExpressionF (StateParameters[index+6], actor); + ENamedName PuffTypeName = (ENamedName)StateParameters[index+7]; + + if (aim && actor->target == NULL) + { return; - - int index=CheckIndex(7); - if (index<0) return; - - int Damage=EvalExpressionI (StateParameters[index], actor); - int Spawnofs_XY=EvalExpressionI (StateParameters[index+1], actor); - int Color1=StateParameters[index+2]; - int Color2=StateParameters[index+3]; - bool Silent=!!EvalExpressionI (StateParameters[index+4], actor); - bool aim=!!EvalExpressionI (StateParameters[index+5], actor); - float MaxDiff=EvalExpressionF (StateParameters[index+6], actor); - ENamedName PuffTypeName=(ENamedName)StateParameters[index+7]; - + } // [RH] Andy Baker's stealth monsters if (actor->flags & MF_STEALTH) { @@ -1212,7 +1213,7 @@ void A_CustomRailgun (AActor *actor) } actor->flags &= ~MF_AMBUSH; - + if (aim) { actor->angle = R_PointToAngle2 (actor->x, @@ -1692,15 +1693,9 @@ void A_SetTranslucent(AActor * self) int mode = EvalExpressionI (StateParameters[index+1], self); mode = mode == 0 ? STYLE_Translucent : mode == 2 ? STYLE_Fuzzy : STYLE_Add; - self->alpha=clamp(alpha, 0, FRACUNIT); - - if (mode != STYLE_Fuzzy) - { - if (self->alpha == 0) mode = STYLE_None; - else if (mode == STYLE_Translucent && self->alpha >= FRACUNIT) mode = STYLE_Normal; - } - - self->RenderStyle=mode; + self->RenderStyle.Flags &= ~STYLEF_Alpha1; + self->alpha = clamp(alpha, 0, FRACUNIT); + self->RenderStyle = ERenderStyle(mode); } //=========================================================================== @@ -1722,7 +1717,7 @@ void A_FadeIn(AActor * self) if (reduce == 0) reduce = FRACUNIT/10; - if (self->RenderStyle==STYLE_Normal) self->RenderStyle=STYLE_Translucent; + self->RenderStyle.Flags &= ~STYLEF_Alpha1; self->alpha += reduce; //if (self->alpha<=0) self->Destroy(); } @@ -1746,7 +1741,7 @@ void A_FadeOut(AActor * self) if (reduce == 0) reduce = FRACUNIT/10; - if (self->RenderStyle==STYLE_Normal) self->RenderStyle=STYLE_Translucent; + self->RenderStyle.Flags &= ~STYLEF_Alpha1; self->alpha -= reduce; if (self->alpha<=0) self->Destroy(); } diff --git a/src/thingdef/thingdef_exp.cpp b/src/thingdef/thingdef_exp.cpp index 5b849acfa8..d0f8824435 100644 --- a/src/thingdef/thingdef_exp.cpp +++ b/src/thingdef/thingdef_exp.cpp @@ -378,21 +378,21 @@ TArray StateExpressions; // [GRB] Parses an expression and stores it into Expression array // -static ExpData *ParseExpressionM (const PClass *cls); -static ExpData *ParseExpressionL (const PClass *cls); -static ExpData *ParseExpressionK (const PClass *cls); -static ExpData *ParseExpressionJ (const PClass *cls); -static ExpData *ParseExpressionI (const PClass *cls); -static ExpData *ParseExpressionH (const PClass *cls); -static ExpData *ParseExpressionG (const PClass *cls); -static ExpData *ParseExpressionF (const PClass *cls); -static ExpData *ParseExpressionE (const PClass *cls); -static ExpData *ParseExpressionD (const PClass *cls); -static ExpData *ParseExpressionC (const PClass *cls); -static ExpData *ParseExpressionB (const PClass *cls); -static ExpData *ParseExpressionA (const PClass *cls); +static ExpData *ParseExpressionM (FScanner &sc, const PClass *cls); +static ExpData *ParseExpressionL (FScanner &sc, const PClass *cls); +static ExpData *ParseExpressionK (FScanner &sc, const PClass *cls); +static ExpData *ParseExpressionJ (FScanner &sc, const PClass *cls); +static ExpData *ParseExpressionI (FScanner &sc, const PClass *cls); +static ExpData *ParseExpressionH (FScanner &sc, const PClass *cls); +static ExpData *ParseExpressionG (FScanner &sc, const PClass *cls); +static ExpData *ParseExpressionF (FScanner &sc, const PClass *cls); +static ExpData *ParseExpressionE (FScanner &sc, const PClass *cls); +static ExpData *ParseExpressionD (FScanner &sc, const PClass *cls); +static ExpData *ParseExpressionC (FScanner &sc, const PClass *cls); +static ExpData *ParseExpressionB (FScanner &sc, const PClass *cls); +static ExpData *ParseExpressionA (FScanner &sc, const PClass *cls); -int ParseExpression (bool _not, PClass *cls) +int ParseExpression (FScanner &sc, bool _not, PClass *cls) { static bool inited=false; @@ -403,7 +403,7 @@ int ParseExpression (bool _not, PClass *cls) inited=true; } - ExpData *data = ParseExpressionM (cls); + ExpData *data = ParseExpressionM (sc, cls); if (_not) { @@ -426,11 +426,11 @@ int ParseExpression (bool _not, PClass *cls) return StateExpressions.Push (data); } -static ExpData *ParseExpressionM (const PClass *cls) +static ExpData *ParseExpressionM (FScanner &sc, const PClass *cls) { - ExpData *tmp = ParseExpressionL (cls); + ExpData *tmp = ParseExpressionL (sc, cls); - if (SC_CheckToken('?')) + if (sc.CheckToken('?')) { ExpData *data = new ExpData; data->Type = EX_Cond; @@ -438,9 +438,9 @@ static ExpData *ParseExpressionM (const PClass *cls) ExpData *choices = new ExpData; data->Children[1] = choices; choices->Type = EX_Right; - choices->Children[0] = ParseExpressionM (cls); - SC_MustGetToken(':'); - choices->Children[1] = ParseExpressionM (cls); + choices->Children[0] = ParseExpressionM (sc, cls); + sc.MustGetToken(':'); + choices->Children[1] = ParseExpressionM (sc, cls); data->EvalConst (cls); return data; } @@ -450,13 +450,13 @@ static ExpData *ParseExpressionM (const PClass *cls) } } -static ExpData *ParseExpressionL (const PClass *cls) +static ExpData *ParseExpressionL (FScanner &sc, const PClass *cls) { - ExpData *tmp = ParseExpressionK (cls); + ExpData *tmp = ParseExpressionK (sc, cls); - while (SC_CheckToken(TK_OrOr)) + while (sc.CheckToken(TK_OrOr)) { - ExpData *right = ParseExpressionK (cls); + ExpData *right = ParseExpressionK (sc, cls); ExpData *data = new ExpData; data->Type = EX_LogOr; data->Children[0] = tmp; @@ -467,13 +467,13 @@ static ExpData *ParseExpressionL (const PClass *cls) return tmp; } -static ExpData *ParseExpressionK (const PClass *cls) +static ExpData *ParseExpressionK (FScanner &sc, const PClass *cls) { - ExpData *tmp = ParseExpressionJ (cls); + ExpData *tmp = ParseExpressionJ (sc, cls); - while (SC_CheckToken(TK_AndAnd)) + while (sc.CheckToken(TK_AndAnd)) { - ExpData *right = ParseExpressionJ (cls); + ExpData *right = ParseExpressionJ (sc, cls); ExpData *data = new ExpData; data->Type = EX_LogAnd; data->Children[0] = tmp; @@ -484,13 +484,13 @@ static ExpData *ParseExpressionK (const PClass *cls) return tmp; } -static ExpData *ParseExpressionJ (const PClass *cls) +static ExpData *ParseExpressionJ (FScanner &sc, const PClass *cls) { - ExpData *tmp = ParseExpressionI (cls); + ExpData *tmp = ParseExpressionI (sc, cls); - while (SC_CheckToken('|')) + while (sc.CheckToken('|')) { - ExpData *right = ParseExpressionI (cls); + ExpData *right = ParseExpressionI (sc, cls); ExpData *data = new ExpData; data->Type = EX_Or; data->Children[0] = tmp; @@ -501,13 +501,13 @@ static ExpData *ParseExpressionJ (const PClass *cls) return tmp; } -static ExpData *ParseExpressionI (const PClass *cls) +static ExpData *ParseExpressionI (FScanner &sc, const PClass *cls) { - ExpData *tmp = ParseExpressionH (cls); + ExpData *tmp = ParseExpressionH (sc, cls); - while (SC_CheckToken('^')) + while (sc.CheckToken('^')) { - ExpData *right = ParseExpressionH (cls); + ExpData *right = ParseExpressionH (sc, cls); ExpData *data = new ExpData; data->Type = EX_Xor; data->Children[0] = tmp; @@ -518,13 +518,13 @@ static ExpData *ParseExpressionI (const PClass *cls) return tmp; } -static ExpData *ParseExpressionH (const PClass *cls) +static ExpData *ParseExpressionH (FScanner &sc, const PClass *cls) { - ExpData *tmp = ParseExpressionG (cls); + ExpData *tmp = ParseExpressionG (sc, cls); - while (SC_CheckToken('&')) + while (sc.CheckToken('&')) { - ExpData *right = ParseExpressionG (cls); + ExpData *right = ParseExpressionG (sc, cls); ExpData *data = new ExpData; data->Type = EX_And; data->Children[0] = tmp; @@ -535,14 +535,14 @@ static ExpData *ParseExpressionH (const PClass *cls) return tmp; } -static ExpData *ParseExpressionG (const PClass *cls) +static ExpData *ParseExpressionG (FScanner &sc, const PClass *cls) { - ExpData *tmp = ParseExpressionF (cls); + ExpData *tmp = ParseExpressionF (sc, cls); - while (SC_GetToken() && (sc_TokenType == TK_Eq || sc_TokenType == TK_Neq)) + while (sc.GetToken() && (sc.TokenType == TK_Eq || sc.TokenType == TK_Neq)) { - int token = sc_TokenType; - ExpData *right = ParseExpressionF (cls); + int token = sc.TokenType; + ExpData *right = ParseExpressionF (sc, cls); ExpData *data = new ExpData; data->Type = token == TK_Eq? EX_Eq : EX_NE; data->Children[0] = tmp; @@ -550,18 +550,18 @@ static ExpData *ParseExpressionG (const PClass *cls) data->EvalConst (cls); tmp = data; } - if (!sc_End) SC_UnGet(); + if (!sc.End) sc.UnGet(); return tmp; } -static ExpData *ParseExpressionF (const PClass *cls) +static ExpData *ParseExpressionF (FScanner &sc, const PClass *cls) { - ExpData *tmp = ParseExpressionE (cls); + ExpData *tmp = ParseExpressionE (sc, cls); - while (SC_GetToken() && (sc_TokenType == '<' || sc_TokenType == '>' || sc_TokenType == TK_Leq || sc_TokenType == TK_Geq)) + while (sc.GetToken() && (sc.TokenType == '<' || sc.TokenType == '>' || sc.TokenType == TK_Leq || sc.TokenType == TK_Geq)) { - int token = sc_TokenType; - ExpData *right = ParseExpressionE (cls); + int token = sc.TokenType; + ExpData *right = ParseExpressionE (sc, cls); ExpData *data = new ExpData; data->Type = token == '<' ? EX_LT : token == '>' ? EX_GT : token == TK_Leq? EX_LE : EX_GE; data->Children[0] = tmp; @@ -569,18 +569,18 @@ static ExpData *ParseExpressionF (const PClass *cls) data->EvalConst (cls); tmp = data; } - if (!sc_End) SC_UnGet(); + if (!sc.End) sc.UnGet(); return tmp; } -static ExpData *ParseExpressionE (const PClass *cls) +static ExpData *ParseExpressionE (FScanner &sc, const PClass *cls) { - ExpData *tmp = ParseExpressionD (cls); + ExpData *tmp = ParseExpressionD (sc, cls); - while (SC_GetToken() && (sc_TokenType == TK_LShift || sc_TokenType == TK_RShift)) + while (sc.GetToken() && (sc.TokenType == TK_LShift || sc.TokenType == TK_RShift)) { - int token = sc_TokenType; - ExpData *right = ParseExpressionD (cls); + int token = sc.TokenType; + ExpData *right = ParseExpressionD (sc, cls); ExpData *data = new ExpData; data->Type = token == TK_LShift? EX_LShift : EX_RShift; data->Children[0] = tmp; @@ -588,18 +588,18 @@ static ExpData *ParseExpressionE (const PClass *cls) data->EvalConst (cls); tmp = data; } - if (!sc_End) SC_UnGet(); + if (!sc.End) sc.UnGet(); return tmp; } -static ExpData *ParseExpressionD (const PClass *cls) +static ExpData *ParseExpressionD (FScanner &sc, const PClass *cls) { - ExpData *tmp = ParseExpressionC (cls); + ExpData *tmp = ParseExpressionC (sc, cls); - while (SC_GetToken() && (sc_TokenType == '+' || sc_TokenType == '-')) + while (sc.GetToken() && (sc.TokenType == '+' || sc.TokenType == '-')) { - int token = sc_TokenType; - ExpData *right = ParseExpressionC (cls); + int token = sc.TokenType; + ExpData *right = ParseExpressionC (sc, cls); ExpData *data = new ExpData; data->Type = token == '+'? EX_Add : EX_Sub; data->Children[0] = tmp; @@ -607,18 +607,18 @@ static ExpData *ParseExpressionD (const PClass *cls) data->EvalConst (cls); tmp = data; } - if (!sc_End) SC_UnGet(); + if (!sc.End) sc.UnGet(); return tmp; } -static ExpData *ParseExpressionC (const PClass *cls) +static ExpData *ParseExpressionC (FScanner &sc, const PClass *cls) { - ExpData *tmp = ParseExpressionB (cls); + ExpData *tmp = ParseExpressionB (sc, cls); - while (SC_GetToken() && (sc_TokenType == '*' || sc_TokenType == '/' || sc_TokenType == '%')) + while (sc.GetToken() && (sc.TokenType == '*' || sc.TokenType == '/' || sc.TokenType == '%')) { - int token = sc_TokenType; - ExpData *right = ParseExpressionB (cls); + int token = sc.TokenType; + ExpData *right = ParseExpressionB (sc, cls); ExpData *data = new ExpData; data->Type = token == '*'? EX_Mul : token == '/'? EX_Div : EX_Mod; data->Children[0] = tmp; @@ -626,77 +626,77 @@ static ExpData *ParseExpressionC (const PClass *cls) data->EvalConst (cls); tmp = data; } - if (!sc_End) SC_UnGet(); + if (!sc.End) sc.UnGet(); return tmp; } -static ExpData *ParseExpressionB (const PClass *cls) +static ExpData *ParseExpressionB (FScanner &sc, const PClass *cls) { ExpData *data = new ExpData; - if (SC_CheckToken('~')) + if (sc.CheckToken('~')) { data->Type = EX_Compl; } - else if (SC_CheckToken('!')) + else if (sc.CheckToken('!')) { data->Type = EX_Not; } - else if (SC_CheckToken('-')) + else if (sc.CheckToken('-')) { data->Type = EX_Minus; } else { - SC_CheckToken('+'); + sc.CheckToken('+'); delete data; - return ParseExpressionA (cls); + return ParseExpressionA (sc, cls); } - data->Children[0] = ParseExpressionA (cls); + data->Children[0] = ParseExpressionA (sc, cls); data->EvalConst (cls); return data; } -static ExpData *ParseExpressionA (const PClass *cls) +static ExpData *ParseExpressionA (FScanner &sc, const PClass *cls) { - if (SC_CheckToken('(')) + if (sc.CheckToken('(')) { - ExpData *data = ParseExpressionM (cls); - SC_MustGetToken(')'); + ExpData *data = ParseExpressionM (sc, cls); + sc.MustGetToken(')'); return data; } - else if (SC_CheckToken(TK_IntConst)) + else if (sc.CheckToken(TK_IntConst)) { ExpData *data = new ExpData; data->Type = EX_Const; data->Value.Type = VAL_Int; - data->Value.Int = sc_Number; + data->Value.Int = sc.Number; return data; } - else if (SC_CheckToken(TK_FloatConst)) + else if (sc.CheckToken(TK_FloatConst)) { ExpData *data = new ExpData; data->Type = EX_Const; data->Value.Type = VAL_Float; - data->Value.Float = sc_Float; + data->Value.Float = sc.Float; return data; } - else if (SC_CheckToken(TK_Class)) + else if (sc.CheckToken(TK_Class)) { // Accept class'SomeClassName'.SomeConstant - SC_MustGetToken(TK_NameConst); - cls = PClass::FindClass (sc_Name); + sc.MustGetToken(TK_NameConst); + cls = PClass::FindClass (sc.Name); if (cls == NULL) { - SC_ScriptError ("Unknown class '%s'", sc_String); + sc.ScriptError ("Unknown class '%s'", sc.String); } - SC_MustGetToken('.'); - SC_MustGetToken(TK_Identifier); - PSymbol *sym = cls->Symbols.FindSymbol (sc_String, true); + sc.MustGetToken('.'); + sc.MustGetToken(TK_Identifier); + PSymbol *sym = cls->Symbols.FindSymbol (sc.String, true); if (sym != NULL && sym->SymbolType == SYM_Const) { ExpData *data = new ExpData; @@ -707,38 +707,38 @@ static ExpData *ParseExpressionA (const PClass *cls) } else { - SC_ScriptError ("'%s' is not a constant value in class '%s'", sc_String, cls->TypeName.GetChars()); + sc.ScriptError ("'%s' is not a constant value in class '%s'", sc.String, cls->TypeName.GetChars()); return NULL; } } - else if (SC_CheckToken(TK_Identifier)) + else if (sc.CheckToken(TK_Identifier)) { - switch (FName(sc_String)) + switch (FName(sc.String)) { case NAME_Random: { FRandom *rng; - if (SC_CheckToken('[')) + if (sc.CheckToken('[')) { - SC_MustGetToken(TK_Identifier); - rng = FRandom::StaticFindRNG(sc_String); - SC_MustGetToken(']'); + sc.MustGetToken(TK_Identifier); + rng = FRandom::StaticFindRNG(sc.String); + sc.MustGetToken(']'); } else { rng = &pr_exrandom; } - SC_MustGetToken('('); + sc.MustGetToken('('); ExpData *data = new ExpData; data->Type = EX_Random; data->RNG = rng; - data->Children[0] = ParseExpressionM (cls); - SC_MustGetToken(','); - data->Children[1] = ParseExpressionM (cls); - SC_MustGetToken(')'); + data->Children[0] = ParseExpressionM (sc, cls); + sc.MustGetToken(','); + data->Children[1] = ParseExpressionM (sc, cls); + sc.MustGetToken(')'); return data; } break; @@ -747,27 +747,27 @@ static ExpData *ParseExpressionA (const PClass *cls) { FRandom *rng; - if (SC_CheckToken('[')) + if (sc.CheckToken('[')) { - SC_MustGetToken(TK_Identifier); - rng = FRandom::StaticFindRNG(sc_String); - SC_MustGetToken(']'); + sc.MustGetToken(TK_Identifier); + rng = FRandom::StaticFindRNG(sc.String); + sc.MustGetToken(']'); } else { rng = &pr_exrandom; } - SC_MustGetToken('('); + sc.MustGetToken('('); ExpData *data = new ExpData; data->Type = EX_Random2; data->RNG = rng; - if (!SC_CheckToken(')')) + if (!sc.CheckToken(')')) { - data->Children[0] = ParseExpressionM(cls); - SC_MustGetToken(')'); + data->Children[0] = ParseExpressionM(sc, cls); + sc.MustGetToken(')'); } return data; } @@ -775,28 +775,28 @@ static ExpData *ParseExpressionA (const PClass *cls) case NAME_Sin: { - SC_MustGetToken('('); + sc.MustGetToken('('); ExpData *data = new ExpData; data->Type = EX_Sin; - data->Children[0] = ParseExpressionM (cls); + data->Children[0] = ParseExpressionM (sc, cls); - SC_MustGetToken(')'); + sc.MustGetToken(')'); return data; } break; case NAME_Cos: { - SC_MustGetToken('('); + sc.MustGetToken('('); ExpData *data = new ExpData; data->Type = EX_Cos; - data->Children[0] = ParseExpressionM (cls); + data->Children[0] = ParseExpressionM (sc, cls); - SC_MustGetToken(')'); + sc.MustGetToken(')'); return data; } break; @@ -806,35 +806,35 @@ static ExpData *ParseExpressionA (const PClass *cls) int specnum, min_args, max_args; // Check if this is an action special - strlwr (sc_String); - specnum = FindLineSpecialEx (sc_String, &min_args, &max_args); + strlwr (sc.String); + specnum = FindLineSpecialEx (sc.String, &min_args, &max_args); if (specnum != 0) { int i; - SC_MustGetToken('('); + sc.MustGetToken('('); ExpData *data = new ExpData, **left; data->Type = EX_ActionSpecial; data->Value.Int = specnum; - data->Children[0] = ParseExpressionM (cls); + data->Children[0] = ParseExpressionM (sc, cls); left = &data->Children[1]; - for (i = 1; i < 5 && SC_CheckToken(','); ++i) + for (i = 1; i < 5 && sc.CheckToken(','); ++i) { ExpData *right = new ExpData; right->Type = EX_Right; - right->Children[0] = ParseExpressionM (cls); + right->Children[0] = ParseExpressionM (sc, cls); *left = right; left = &right->Children[1]; } *left = NULL; - SC_MustGetToken(')'); + sc.MustGetToken(')'); if (i < min_args) - SC_ScriptError ("Not enough arguments to action special"); + sc.ScriptError ("Not enough arguments to action special"); if (i > max_args) - SC_ScriptError ("Too many arguments to action special"); + sc.ScriptError ("Too many arguments to action special"); return data; } @@ -842,7 +842,7 @@ static ExpData *ParseExpressionA (const PClass *cls) // Check if this is a constant if (cls != NULL) { - PSymbol *sym = cls->Symbols.FindSymbol (sc_String, true); + PSymbol *sym = cls->Symbols.FindSymbol (sc.String, true); if (sym != NULL && sym->SymbolType == SYM_Const) { ExpData *data = new ExpData; @@ -855,7 +855,7 @@ static ExpData *ParseExpressionA (const PClass *cls) // Check if it's a variable we understand int varid = -1; - FName vname = sc_String; + FName vname = sc.String; for (size_t i = 0; i < countof(ExpVars); i++) { if (vname == ExpVars[i].name) @@ -866,7 +866,7 @@ static ExpData *ParseExpressionA (const PClass *cls) } if (varid == -1) - SC_ScriptError ("Unknown value '%s'", sc_String); + sc.ScriptError ("Unknown value '%s'", sc.String); ExpData *data = new ExpData; data->Type = EX_Var; @@ -875,9 +875,9 @@ static ExpData *ParseExpressionA (const PClass *cls) if (ExpVars[varid].array) { - SC_MustGetToken('['); - data->Children[0] = ParseExpressionM (cls); - SC_MustGetToken(']'); + sc.MustGetToken('['); + data->Children[0] = ParseExpressionM (sc, cls); + sc.MustGetToken(']'); } return data; } @@ -886,8 +886,8 @@ static ExpData *ParseExpressionA (const PClass *cls) } else { - FString tokname = SC_TokenName(sc_TokenType, sc_String); - SC_ScriptError ("Unexpected token %s", tokname.GetChars()); + FString tokname = sc.TokenName(sc.TokenType, sc.String); + sc.ScriptError ("Unexpected token %s", tokname.GetChars()); return NULL; } } diff --git a/src/thingdef/thingdef_main.cpp b/src/thingdef/thingdef_main.cpp index 391efe7d21..395d06e509 100644 --- a/src/thingdef/thingdef_main.cpp +++ b/src/thingdef/thingdef_main.cpp @@ -47,12 +47,12 @@ // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- -void ParseActor(); -void ParseClass(); -void ParseGlobalConst(); -void ParseGlobalEnum(); +void ParseActor(FScanner &sc); +void ParseClass(FScanner &sc); +void ParseGlobalConst(FScanner &sc); +void ParseGlobalEnum(FScanner &sc); void FinishThingdef(); -void ParseOldDecoration(EDefinitionType def); +void ParseOldDecoration(FScanner &sc, EDefinitionType def); // STATIC FUNCTION PROTOTYPES -------------------------------------------- @@ -64,65 +64,64 @@ void ParseOldDecoration(EDefinitionType def); // //========================================================================== -static void ParseDecorate () +static void ParseDecorate (FScanner &sc) { - int recursion=0; int lump; // Get actor class name. - while (true) + for(;;) { - SC_SavePos(); - if (!SC_GetToken ()) + FScanner::SavedPos pos = sc.SavePos(); + if (!sc.GetToken ()) { - if (recursion==0) return; - SC_Close(); - SC_RestoreScriptState(); - recursion--; - continue; + return; } - switch (sc_TokenType) + switch (sc.TokenType) { case TK_Include: - SC_MustGetString(); + sc.MustGetString(); // This is not using SC_Open because it can print a more useful error message when done here - lump = Wads.CheckNumForFullName(sc_String); + lump = Wads.CheckNumForFullName(sc.String); // Try a normal WAD name lookup only if it's a proper name without path separator and // not longer than 8 characters. - if (lump==-1 && strlen(sc_String) <= 8 && !strchr(sc_String, '/')) - lump = Wads.CheckNumForName(sc_String); - - if (lump==-1) - SC_ScriptError("Lump '%s' not found", sc_String); - - SC_SaveScriptState(); - SC_OpenLumpNum(lump, sc_String); - recursion++; + if (lump == -1 && sc.StringLen <= 8 && !strchr(sc.String, '/')) + { + lump = Wads.CheckNumForName(sc.String); + } + if (lump == -1) + { + sc.ScriptError("Lump '%s' not found", sc.String); + } + else + { + FScanner newscanner(lump, sc.String); + ParseDecorate(newscanner); + } break; case TK_Class: - ParseClass (); + ParseClass (sc); break; case TK_Const: - ParseConstant (&RUNTIME_CLASS(AActor)->Symbols, RUNTIME_CLASS(AActor)); + ParseConstant (sc, &RUNTIME_CLASS(AActor)->Symbols, RUNTIME_CLASS(AActor)); break; case TK_Enum: - ParseEnum (&RUNTIME_CLASS(AActor)->Symbols, RUNTIME_CLASS(AActor)); + ParseEnum (sc, &RUNTIME_CLASS(AActor)->Symbols, RUNTIME_CLASS(AActor)); break; case TK_Pickup: - ParseOldDecoration (DEF_Pickup); + ParseOldDecoration (sc, DEF_Pickup); break; case TK_Breakable: - ParseOldDecoration (DEF_BreakableDecoration); + ParseOldDecoration (sc, DEF_BreakableDecoration); break; case TK_Projectile: - ParseOldDecoration (DEF_Projectile); + ParseOldDecoration (sc, DEF_Projectile); break; case ';': @@ -130,22 +129,22 @@ static void ParseDecorate () // is used to parse parts of the DECORATE lump. If we don't add // a check here the user will only get weird non-informative // error messages if a semicolon is found. - SC_ScriptError("Unexpected ';'"); + sc.ScriptError("Unexpected ';'"); break; case TK_Identifier: // 'ACTOR' cannot be a keyword because it is also needed as a class identifier // so let's do a special case for this. - if (SC_Compare("ACTOR")) + if (sc.Compare("ACTOR")) { - ParseActor (); + ParseActor (sc); break; } default: // Yuck! Too bad that there's no better way to check this properly - SC_RestorePos(); - ParseOldDecoration(DEF_Decoration); + sc.RestorePos(pos); + ParseOldDecoration(sc, DEF_Decoration); break; } } @@ -166,9 +165,8 @@ void LoadDecorations () lastlump = 0; while ((lump = Wads.FindLump ("DECORATE", &lastlump)) != -1) { - SC_OpenLumpNum (lump, Wads.GetLumpFullName(lump)); - ParseDecorate (); - SC_Close (); + FScanner sc(lump, Wads.GetLumpFullName(lump)); + ParseDecorate (sc); } FinishThingdef(); } diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 8fbe3a5599..3cbb3438f3 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -452,18 +452,18 @@ void A_ChangeFlag(AActor * self) //========================================================================== // //========================================================================== -void ParseActorFlag (Baggage &bag, int mod) +void ParseActorFlag (FScanner &sc, Baggage &bag, int mod) { flagdef *fd; - SC_MustGetString (); + sc.MustGetString (); - FString part1 = sc_String; + FString part1 = sc.String; const char *part2 = NULL; - if (SC_CheckString (".")) + if (sc.CheckString (".")) { - SC_MustGetString (); - part2 = sc_String; + sc.MustGetString (); + part2 = sc.String; } if ( (fd = FindFlag (bag.Info->Class, part1.GetChars(), part2)) ) { @@ -489,11 +489,11 @@ void ParseActorFlag (Baggage &bag, int mod) { if (part2 == NULL) { - SC_ScriptError("\"%s\" is an unknown flag\n", part1.GetChars()); + sc.ScriptError("\"%s\" is an unknown flag\n", part1.GetChars()); } else { - SC_ScriptError("\"%s.%s\" is an unknown flag\n", part1.GetChars(), part2); + sc.ScriptError("\"%s.%s\" is an unknown flag\n", part1.GetChars(), part2); } } } @@ -522,7 +522,7 @@ static bool Check(char *& range, char c, bool error=true) } if (error) { - //SC_ScriptError("Invalid syntax in translation specification: '%c' expected", c); + //sc.ScriptError("Invalid syntax in translation specification: '%c' expected", c); } return false; } @@ -570,7 +570,7 @@ static void AddToTranslation(char * range) } } -static int StoreTranslation() +static int StoreTranslation(FScanner &sc) { unsigned int i; @@ -584,7 +584,7 @@ static int StoreTranslation() } if (translationtables[TRANSLATION_Decorate].Size() >= MAX_DECORATE_TRANSLATIONS) { - SC_ScriptError("Too many translations in DECORATE"); + sc.ScriptError("Too many translations in DECORATE"); } FRemapTable *newtrans = new FRemapTable; *newtrans = CurrentTranslation; @@ -592,7 +592,7 @@ static int StoreTranslation() return TRANSLATION(TRANSLATION_Decorate, i); } -static int CreateBloodTranslation(PalEntry color) +static int CreateBloodTranslation(FScanner &sc, PalEntry color) { unsigned int i; @@ -608,7 +608,7 @@ static int CreateBloodTranslation(PalEntry color) } if (BloodTranslationColors.Size() >= MAX_DECORATE_TRANSLATIONS) { - SC_ScriptError("Too many blood colors in DECORATE"); + sc.ScriptError("Too many blood colors in DECORATE"); } FRemapTable *trans = new FRemapTable; for (i = 0; i < 256; i++) @@ -670,7 +670,7 @@ FDropItem *GetDropItems(const PClass *cls) // //========================================================================== -typedef void (*ActorPropFunction) (AActor *defaults, Baggage &bag); +typedef void (*ActorPropFunction) (FScanner &sc, AActor *defaults, Baggage &bag); struct ActorProps { @@ -679,7 +679,7 @@ struct ActorProps const PClass * type; }; -typedef ActorProps (*ActorPropHandler) (register const char *str, register unsigned int len); +typedef ActorProps (*ActorPropHandler) (const char *str, unsigned int len); static const ActorProps *is_actorprop (const char *str); @@ -689,29 +689,29 @@ static const ActorProps *is_actorprop (const char *str); // Checks for a numeric parameter which may or may not be preceded by a comma // //========================================================================== -static bool CheckNumParm() +static bool CheckNumParm(FScanner &sc) { - if (SC_CheckString(",")) + if (sc.CheckString(",")) { - SC_MustGetNumber(); + sc.MustGetNumber(); return true; } else { - return !!SC_CheckNumber(); + return !!sc.CheckNumber(); } } -static bool CheckFloatParm() +static bool CheckFloatParm(FScanner &sc) { - if (SC_CheckString(",")) + if (sc.CheckString(",")) { - SC_MustGetFloat(); + sc.MustGetFloat(); return true; } else { - return !!SC_CheckFloat(); + return sc.CheckFloat(); } } @@ -724,7 +724,7 @@ static bool CheckFloatParm() //========================================================================== // //========================================================================== -static void ActorSkipSuper (AActor *defaults, Baggage &bag) +static void ActorSkipSuper (FScanner &sc, AActor *defaults, Baggage &bag) { memcpy (defaults, GetDefault(), sizeof(AActor)); if (bag.DropItemList != NULL) @@ -738,80 +738,80 @@ static void ActorSkipSuper (AActor *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void ActorGame (AActor *defaults, Baggage &bag) +static void ActorGame (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString (); - if (SC_Compare ("Doom")) + sc.MustGetString (); + if (sc.Compare ("Doom")) { bag.Info->GameFilter |= GAME_Doom; } - else if (SC_Compare ("Heretic")) + else if (sc.Compare ("Heretic")) { bag.Info->GameFilter |= GAME_Heretic; } - else if (SC_Compare ("Hexen")) + else if (sc.Compare ("Hexen")) { bag.Info->GameFilter |= GAME_Hexen; } - else if (SC_Compare ("Raven")) + else if (sc.Compare ("Raven")) { bag.Info->GameFilter |= GAME_Raven; } - else if (SC_Compare ("Strife")) + else if (sc.Compare ("Strife")) { bag.Info->GameFilter |= GAME_Strife; } - else if (SC_Compare ("Any")) + else if (sc.Compare ("Any")) { bag.Info->GameFilter = GAME_Any; } else { - SC_ScriptError ("Unknown game type %s", sc_String); + sc.ScriptError ("Unknown game type %s", sc.String); } } //========================================================================== // //========================================================================== -static void ActorSpawnID (AActor *defaults, Baggage &bag) +static void ActorSpawnID (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber(); - if (sc_Number<0 || sc_Number>255) + sc.MustGetNumber(); + if (sc.Number<0 || sc.Number>255) { - SC_ScriptError ("SpawnID must be in the range [0,255]"); + sc.ScriptError ("SpawnID must be in the range [0,255]"); } - else bag.Info->SpawnID=(BYTE)sc_Number; + else bag.Info->SpawnID=(BYTE)sc.Number; } //========================================================================== // //========================================================================== -static void ActorConversationID (AActor *defaults, Baggage &bag) +static void ActorConversationID (FScanner &sc, AActor *defaults, Baggage &bag) { int convid; - SC_MustGetNumber(); - convid = sc_Number; + sc.MustGetNumber(); + convid = sc.Number; // Handling for Strife teaser IDs - only of meaning for the standard items // as PWADs cannot be loaded with the teasers. - if (SC_CheckString(",")) + if (sc.CheckString(",")) { - SC_MustGetNumber(); + sc.MustGetNumber(); if ((gameinfo.flags & (GI_SHAREWARE|GI_TEASER2)) == (GI_SHAREWARE)) - convid=sc_Number; + convid=sc.Number; - SC_MustGetStringName(","); - SC_MustGetNumber(); + sc.MustGetStringName(","); + sc.MustGetNumber(); if ((gameinfo.flags & (GI_SHAREWARE|GI_TEASER2)) == (GI_SHAREWARE|GI_TEASER2)) - convid=sc_Number; + convid=sc.Number; if (convid==-1) return; } if (convid<0 || convid>1000) { - SC_ScriptError ("ConversationID must be in the range [0,1000]"); + sc.ScriptError ("ConversationID must be in the range [0,1000]"); } else StrifeTypes[convid] = bag.Info->Class; } @@ -819,73 +819,73 @@ static void ActorConversationID (AActor *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void ActorTag (AActor *defaults, Baggage &bag) +static void ActorTag (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - bag.Info->Class->Meta.SetMetaString(AMETA_StrifeName, sc_String); + sc.MustGetString(); + bag.Info->Class->Meta.SetMetaString(AMETA_StrifeName, sc.String); } //========================================================================== // //========================================================================== -static void ActorHealth (AActor *defaults, Baggage &bag) +static void ActorHealth (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->health=sc_Number; + sc.MustGetNumber(); + defaults->health=sc.Number; } //========================================================================== // //========================================================================== -static void ActorGibHealth (AActor *defaults, Baggage &bag) +static void ActorGibHealth (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber(); - bag.Info->Class->Meta.SetMetaInt (AMETA_GibHealth, sc_Number); + sc.MustGetNumber(); + bag.Info->Class->Meta.SetMetaInt (AMETA_GibHealth, sc.Number); } //========================================================================== // //========================================================================== -static void ActorWoundHealth (AActor *defaults, Baggage &bag) +static void ActorWoundHealth (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber(); - bag.Info->Class->Meta.SetMetaInt (AMETA_WoundHealth, sc_Number); + sc.MustGetNumber(); + bag.Info->Class->Meta.SetMetaInt (AMETA_WoundHealth, sc.Number); } //========================================================================== // //========================================================================== -static void ActorReactionTime (AActor *defaults, Baggage &bag) +static void ActorReactionTime (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->reactiontime=sc_Number; + sc.MustGetNumber(); + defaults->reactiontime=sc.Number; } //========================================================================== // //========================================================================== -static void ActorPainChance (AActor *defaults, Baggage &bag) +static void ActorPainChance (FScanner &sc, AActor *defaults, Baggage &bag) { - if (!SC_CheckNumber()) + if (!sc.CheckNumber()) { FName painType; - SC_MustGetString(); - if (SC_Compare("Normal")) painType = NAME_None; - else painType=sc_String; - SC_MustGetToken(','); - SC_MustGetNumber(); + sc.MustGetString(); + if (sc.Compare("Normal")) painType = NAME_None; + else painType=sc.String; + sc.MustGetToken(','); + sc.MustGetNumber(); if (bag.Info->PainChances == NULL) bag.Info->PainChances=new PainChanceList; - (*bag.Info->PainChances)[painType] = (BYTE)sc_Number; + (*bag.Info->PainChances)[painType] = (BYTE)sc.Number; return; } - defaults->PainChance=sc_Number; + defaults->PainChance=sc.Number; } //========================================================================== // //========================================================================== -static void ActorDamage (AActor *defaults, Baggage &bag) +static void ActorDamage (FScanner &sc, AActor *defaults, Baggage &bag) { // Damage can either be a single number, in which case it is subject // to the original damage calculation rules. Or, it can be an expression @@ -893,100 +893,100 @@ static void ActorDamage (AActor *defaults, Baggage &bag) // compatibility reasons, expressions must be enclosed within // parentheses. - if (SC_CheckString ("(")) + if (sc.CheckString ("(")) { - defaults->Damage = 0x40000000 | ParseExpression (false, bag.Info->Class); - SC_MustGetStringName(")"); + defaults->Damage = 0x40000000 | ParseExpression (sc, false, bag.Info->Class); + sc.MustGetStringName(")"); } else { - SC_MustGetNumber (); - defaults->Damage = sc_Number; + sc.MustGetNumber (); + defaults->Damage = sc.Number; } } //========================================================================== // //========================================================================== -static void ActorSpeed (AActor *defaults, Baggage &bag) +static void ActorSpeed (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - defaults->Speed=fixed_t(sc_Float*FRACUNIT); + sc.MustGetFloat(); + defaults->Speed=fixed_t(sc.Float*FRACUNIT); } //========================================================================== // //========================================================================== -static void ActorFloatSpeed (AActor *defaults, Baggage &bag) +static void ActorFloatSpeed (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - defaults->FloatSpeed=fixed_t(sc_Float*FRACUNIT); + sc.MustGetFloat(); + defaults->FloatSpeed=fixed_t(sc.Float*FRACUNIT); } //========================================================================== // //========================================================================== -static void ActorRadius (AActor *defaults, Baggage &bag) +static void ActorRadius (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - defaults->radius=fixed_t(sc_Float*FRACUNIT); + sc.MustGetFloat(); + defaults->radius=fixed_t(sc.Float*FRACUNIT); } //========================================================================== // //========================================================================== -static void ActorHeight (AActor *defaults, Baggage &bag) +static void ActorHeight (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - defaults->height=fixed_t(sc_Float*FRACUNIT); + sc.MustGetFloat(); + defaults->height=fixed_t(sc.Float*FRACUNIT); } //========================================================================== // //========================================================================== -static void ActorMass (AActor *defaults, Baggage &bag) +static void ActorMass (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->Mass=sc_Number; + sc.MustGetNumber(); + defaults->Mass=sc.Number; } //========================================================================== // //========================================================================== -static void ActorXScale (AActor *defaults, Baggage &bag) +static void ActorXScale (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - defaults->scaleX = FLOAT2FIXED(sc_Float); + sc.MustGetFloat(); + defaults->scaleX = FLOAT2FIXED(sc.Float); } //========================================================================== // //========================================================================== -static void ActorYScale (AActor *defaults, Baggage &bag) +static void ActorYScale (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - defaults->scaleY = FLOAT2FIXED(sc_Float); + sc.MustGetFloat(); + defaults->scaleY = FLOAT2FIXED(sc.Float); } //========================================================================== // //========================================================================== -static void ActorScale (AActor *defaults, Baggage &bag) +static void ActorScale (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - defaults->scaleX= defaults->scaleY = FLOAT2FIXED(sc_Float); + sc.MustGetFloat(); + defaults->scaleX= defaults->scaleY = FLOAT2FIXED(sc.Float); } //========================================================================== // //========================================================================== -static void ActorArgs (AActor *defaults, Baggage &bag) +static void ActorArgs (FScanner &sc, AActor *defaults, Baggage &bag) { - for (int i=0;i<5;i++) + for (int i = 0; i < 5; i++) { - SC_MustGetNumber(); - defaults->args[i] = sc_Number; - if (i < 4 && !SC_CheckToken(',')) break; + sc.MustGetNumber(); + defaults->args[i] = sc.Number; + if (i < 4 && !sc.CheckToken(',')) break; } defaults->flags2|=MF2_ARGSDEFINED; } @@ -994,61 +994,61 @@ static void ActorArgs (AActor *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void ActorSeeSound (AActor *defaults, Baggage &bag) +static void ActorSeeSound (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->SeeSound=S_FindSound(sc_String); + sc.MustGetString(); + defaults->SeeSound=S_FindSound(sc.String); } //========================================================================== // //========================================================================== -static void ActorAttackSound (AActor *defaults, Baggage &bag) +static void ActorAttackSound (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->AttackSound=S_FindSound(sc_String); + sc.MustGetString(); + defaults->AttackSound=S_FindSound(sc.String); } //========================================================================== // //========================================================================== -static void ActorPainSound (AActor *defaults, Baggage &bag) +static void ActorPainSound (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->PainSound=S_FindSound(sc_String); + sc.MustGetString(); + defaults->PainSound=S_FindSound(sc.String); } //========================================================================== // //========================================================================== -static void ActorDeathSound (AActor *defaults, Baggage &bag) +static void ActorDeathSound (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->DeathSound=S_FindSound(sc_String); + sc.MustGetString(); + defaults->DeathSound=S_FindSound(sc.String); } //========================================================================== // //========================================================================== -static void ActorActiveSound (AActor *defaults, Baggage &bag) +static void ActorActiveSound (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->ActiveSound=S_FindSound(sc_String); + sc.MustGetString(); + defaults->ActiveSound=S_FindSound(sc.String); } //========================================================================== // //========================================================================== -static void ActorHowlSound (AActor *defaults, Baggage &bag) +static void ActorHowlSound (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - bag.Info->Class->Meta.SetMetaInt (AMETA_HowlSound, S_FindSound(sc_String)); + sc.MustGetString(); + bag.Info->Class->Meta.SetMetaInt (AMETA_HowlSound, S_FindSound(sc.String)); } //========================================================================== // //========================================================================== -static void ActorDropItem (AActor *defaults, Baggage &bag) +static void ActorDropItem (FScanner &sc, AActor *defaults, Baggage &bag) { // create a linked list of dropitems if (!bag.DropItemSet) @@ -1057,19 +1057,19 @@ static void ActorDropItem (AActor *defaults, Baggage &bag) bag.DropItemList = NULL; } - FDropItem * di=new FDropItem; + FDropItem *di = new FDropItem; - SC_MustGetString(); - di->Name=sc_String; + sc.MustGetString(); + di->Name=sc.String; di->probability=255; di->amount=-1; - if (CheckNumParm()) + if (CheckNumParm(sc)) { - di->probability=sc_Number; - if (CheckNumParm()) + di->probability = sc.Number; + if (CheckNumParm(sc)) { - di->amount=sc_Number; + di->amount = sc.Number; } } di->Next = bag.DropItemList; @@ -1079,137 +1079,137 @@ static void ActorDropItem (AActor *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void ActorSpawnState (AActor *defaults, Baggage &bag) +static void ActorSpawnState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Spawn", CheckState ( bag.Info->Class)); + AddState("Spawn", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorSeeState (AActor *defaults, Baggage &bag) +static void ActorSeeState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("See", CheckState ( bag.Info->Class)); + AddState("See", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorMeleeState (AActor *defaults, Baggage &bag) +static void ActorMeleeState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Melee", CheckState ( bag.Info->Class)); + AddState("Melee", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorMissileState (AActor *defaults, Baggage &bag) +static void ActorMissileState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Missile", CheckState ( bag.Info->Class)); + AddState("Missile", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorPainState (AActor *defaults, Baggage &bag) +static void ActorPainState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Pain", CheckState ( bag.Info->Class)); + AddState("Pain", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorDeathState (AActor *defaults, Baggage &bag) +static void ActorDeathState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Death", CheckState ( bag.Info->Class)); + AddState("Death", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorXDeathState (AActor *defaults, Baggage &bag) +static void ActorXDeathState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("XDeath", CheckState ( bag.Info->Class)); + AddState("XDeath", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorBurnState (AActor *defaults, Baggage &bag) +static void ActorBurnState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Burn", CheckState ( bag.Info->Class)); + AddState("Burn", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorIceState (AActor *defaults, Baggage &bag) +static void ActorIceState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Ice", CheckState ( bag.Info->Class)); + AddState("Ice", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorRaiseState (AActor *defaults, Baggage &bag) +static void ActorRaiseState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Raise", CheckState ( bag.Info->Class)); + AddState("Raise", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorCrashState (AActor *defaults, Baggage &bag) +static void ActorCrashState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Crash", CheckState ( bag.Info->Class)); + AddState("Crash", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorCrushState (AActor *defaults, Baggage &bag) +static void ActorCrushState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Crush", CheckState ( bag.Info->Class)); + AddState("Crush", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorWoundState (AActor *defaults, Baggage &bag) +static void ActorWoundState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Wound", CheckState ( bag.Info->Class)); + AddState("Wound", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorDisintegrateState (AActor *defaults, Baggage &bag) +static void ActorDisintegrateState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Disintegrate", CheckState ( bag.Info->Class)); + AddState("Disintegrate", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorHealState (AActor *defaults, Baggage &bag) +static void ActorHealState (FScanner &sc, AActor *defaults, Baggage &bag) { - AddState("Heal", CheckState ( bag.Info->Class)); + AddState("Heal", CheckState (sc, bag.Info->Class)); } //========================================================================== // //========================================================================== -static void ActorStates (AActor *defaults, Baggage &bag) +static void ActorStates (FScanner &sc, AActor *defaults, Baggage &bag) { - if (!bag.StateSet) ParseStates(bag.Info, defaults, bag); - else SC_ScriptError("Multiple state declarations not allowed"); + if (!bag.StateSet) ParseStates(sc, bag.Info, defaults, bag); + else sc.ScriptError("Multiple state declarations not allowed"); bag.StateSet=true; } //========================================================================== // //========================================================================== -static void ActorRenderStyle (AActor *defaults, Baggage &bag) +static void ActorRenderStyle (FScanner &sc, AActor *defaults, Baggage &bag) { static const char * renderstyles[]={ "NONE","NORMAL","FUZZY","SOULTRANS","OPTFUZZY","STENCIL","TRANSLUCENT", "ADD",NULL}; @@ -1218,48 +1218,48 @@ static void ActorRenderStyle (AActor *defaults, Baggage &bag) STYLE_None, STYLE_Normal, STYLE_Fuzzy, STYLE_SoulTrans, STYLE_OptFuzzy, STYLE_Stencil, STYLE_Translucent, STYLE_Add}; - SC_MustGetString(); - defaults->RenderStyle=renderstyle_values[SC_MustMatchString(renderstyles)]; + sc.MustGetString(); + defaults->RenderStyle = LegacyRenderStyles[renderstyle_values[sc.MustMatchString(renderstyles)]]; } //========================================================================== // //========================================================================== -static void ActorAlpha (AActor *defaults, Baggage &bag) +static void ActorAlpha (FScanner &sc, AActor *defaults, Baggage &bag) { - if (SC_CheckString("DEFAULT")) + if (sc.CheckString("DEFAULT")) { - defaults->alpha = gameinfo.gametype==GAME_Heretic? HR_SHADOW : HX_SHADOW; + defaults->alpha = gameinfo.gametype == GAME_Heretic ? HR_SHADOW : HX_SHADOW; } else { - SC_MustGetFloat(); - defaults->alpha=fixed_t(sc_Float*FRACUNIT); + sc.MustGetFloat(); + defaults->alpha=fixed_t(sc.Float*FRACUNIT); } } //========================================================================== // //========================================================================== -static void ActorObituary (AActor *defaults, Baggage &bag) +static void ActorObituary (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - bag.Info->Class->Meta.SetMetaString (AMETA_Obituary, sc_String); + sc.MustGetString(); + bag.Info->Class->Meta.SetMetaString (AMETA_Obituary, sc.String); } //========================================================================== // //========================================================================== -static void ActorHitObituary (AActor *defaults, Baggage &bag) +static void ActorHitObituary (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - bag.Info->Class->Meta.SetMetaString (AMETA_HitObituary, sc_String); + sc.MustGetString(); + bag.Info->Class->Meta.SetMetaString (AMETA_HitObituary, sc.String); } //========================================================================== // //========================================================================== -static void ActorDontHurtShooter (AActor *defaults, Baggage &bag) +static void ActorDontHurtShooter (FScanner &sc, AActor *defaults, Baggage &bag) { bag.Info->Class->Meta.SetMetaInt (ACMETA_DontHurtShooter, true); } @@ -1267,28 +1267,28 @@ static void ActorDontHurtShooter (AActor *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void ActorExplosionRadius (AActor *defaults, Baggage &bag) +static void ActorExplosionRadius (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber(); - bag.Info->Class->Meta.SetMetaInt (ACMETA_ExplosionRadius, sc_Number); + sc.MustGetNumber(); + bag.Info->Class->Meta.SetMetaInt (ACMETA_ExplosionRadius, sc.Number); } //========================================================================== // //========================================================================== -static void ActorExplosionDamage (AActor *defaults, Baggage &bag) +static void ActorExplosionDamage (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber(); - bag.Info->Class->Meta.SetMetaInt (ACMETA_ExplosionDamage, sc_Number); + sc.MustGetNumber(); + bag.Info->Class->Meta.SetMetaInt (ACMETA_ExplosionDamage, sc.Number); } //========================================================================== // //========================================================================== -static void ActorDeathHeight (AActor *defaults, Baggage &bag) +static void ActorDeathHeight (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - fixed_t h = fixed_t(sc_Float * FRACUNIT); + sc.MustGetFloat(); + fixed_t h = fixed_t(sc.Float * FRACUNIT); // AActor::Die() uses a height of 0 to mean "cut the height to 1/4", // so if a height of 0 is desired, store it as -1. bag.Info->Class->Meta.SetMetaFixed (AMETA_DeathHeight, h <= 0 ? -1 : h); @@ -1297,10 +1297,10 @@ static void ActorDeathHeight (AActor *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void ActorBurnHeight (AActor *defaults, Baggage &bag) +static void ActorBurnHeight (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - fixed_t h = fixed_t(sc_Float * FRACUNIT); + sc.MustGetFloat(); + fixed_t h = fixed_t(sc.Float * FRACUNIT); // The note above for AMETA_DeathHeight also applies here. bag.Info->Class->Meta.SetMetaFixed (AMETA_BurnHeight, h <= 0 ? -1 : h); } @@ -1308,121 +1308,121 @@ static void ActorBurnHeight (AActor *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void ActorMaxTargetRange (AActor *defaults, Baggage &bag) +static void ActorMaxTargetRange (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - defaults->maxtargetrange = fixed_t(sc_Float*FRACUNIT); + sc.MustGetFloat(); + defaults->maxtargetrange = fixed_t(sc.Float*FRACUNIT); } //========================================================================== // //========================================================================== -static void ActorMeleeThreshold (AActor *defaults, Baggage &bag) +static void ActorMeleeThreshold (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - defaults->meleethreshold = fixed_t(sc_Float*FRACUNIT); + sc.MustGetFloat(); + defaults->meleethreshold = fixed_t(sc.Float*FRACUNIT); } //========================================================================== // //========================================================================== -static void ActorMeleeDamage (AActor *defaults, Baggage &bag) +static void ActorMeleeDamage (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber(); - bag.Info->Class->Meta.SetMetaInt (ACMETA_MeleeDamage, sc_Number); + sc.MustGetNumber(); + bag.Info->Class->Meta.SetMetaInt (ACMETA_MeleeDamage, sc.Number); } //========================================================================== // //========================================================================== -static void ActorMeleeRange (AActor *defaults, Baggage &bag) +static void ActorMeleeRange (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - defaults->meleerange = fixed_t(sc_Float*FRACUNIT); + sc.MustGetFloat(); + defaults->meleerange = fixed_t(sc.Float*FRACUNIT); } //========================================================================== // //========================================================================== -static void ActorMeleeSound (AActor *defaults, Baggage &bag) +static void ActorMeleeSound (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - bag.Info->Class->Meta.SetMetaInt (ACMETA_MeleeSound, S_FindSound(sc_String)); + sc.MustGetString(); + bag.Info->Class->Meta.SetMetaInt (ACMETA_MeleeSound, S_FindSound(sc.String)); } //========================================================================== // //========================================================================== -static void ActorMissileType (AActor *defaults, Baggage &bag) +static void ActorMissileType (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - bag.Info->Class->Meta.SetMetaInt (ACMETA_MissileName, FName(sc_String)); + sc.MustGetString(); + bag.Info->Class->Meta.SetMetaInt (ACMETA_MissileName, FName(sc.String)); } //========================================================================== // //========================================================================== -static void ActorMissileHeight (AActor *defaults, Baggage &bag) +static void ActorMissileHeight (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - bag.Info->Class->Meta.SetMetaFixed (ACMETA_MissileHeight, fixed_t(sc_Float*FRACUNIT)); + sc.MustGetFloat(); + bag.Info->Class->Meta.SetMetaFixed (ACMETA_MissileHeight, fixed_t(sc.Float*FRACUNIT)); } //========================================================================== // //========================================================================== -static void ActorTranslation (AActor *defaults, Baggage &bag) +static void ActorTranslation (FScanner &sc, AActor *defaults, Baggage &bag) { - if (SC_CheckNumber()) + if (sc.CheckNumber()) { int max = (gameinfo.gametype==GAME_Strife || (bag.Info->GameFilter&GAME_Strife)) ? 6:2; - if (sc_Number < 0 || sc_Number > max) + if (sc.Number < 0 || sc.Number > max) { - SC_ScriptError ("Translation must be in the range [0,%d]", max); + sc.ScriptError ("Translation must be in the range [0,%d]", max); } - defaults->Translation = TRANSLATION(TRANSLATION_Standard, sc_Number); + defaults->Translation = TRANSLATION(TRANSLATION_Standard, sc.Number); } else { CurrentTranslation.MakeIdentity(); do { - SC_GetString(); - AddToTranslation(sc_String); + sc.GetString(); + AddToTranslation(sc.String); } - while (SC_CheckString(",")); - defaults->Translation = StoreTranslation (); + while (sc.CheckString(",")); + defaults->Translation = StoreTranslation (sc); } } //========================================================================== // //========================================================================== -static void ActorBloodColor (AActor *defaults, Baggage &bag) +static void ActorBloodColor (FScanner &sc, AActor *defaults, Baggage &bag) { int r,g,b; - if (SC_CheckNumber()) + if (sc.CheckNumber()) { - SC_MustGetNumber(); - r=clamp(sc_Number, 0, 255); - SC_CheckString(","); - SC_MustGetNumber(); - g=clamp(sc_Number, 0, 255); - SC_CheckString(","); - SC_MustGetNumber(); - b=clamp(sc_Number, 0, 255); + sc.MustGetNumber(); + r = clamp(sc.Number, 0, 255); + sc.CheckString(","); + sc.MustGetNumber(); + g = clamp(sc.Number, 0, 255); + sc.CheckString(","); + sc.MustGetNumber(); + b = clamp(sc.Number, 0, 255); } else { - SC_MustGetString(); - int c = V_GetColor(NULL, sc_String); - r=RPART(c); - g=GPART(c); - b=BPART(c); + sc.MustGetString(); + int c = V_GetColor(NULL, sc.String); + r = RPART(c); + g = GPART(c); + b = BPART(c); } PalEntry pe = MAKERGB(r,g,b); - pe.a = CreateBloodTranslation(pe); + pe.a = CreateBloodTranslation(sc, pe); bag.Info->Class->Meta.SetMetaInt (AMETA_BloodColor, pe); } @@ -1430,25 +1430,25 @@ static void ActorBloodColor (AActor *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void ActorBloodType (AActor *defaults, Baggage &bag) +static void ActorBloodType (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - FName blood = sc_String; + sc.MustGetString(); + FName blood = sc.String; // normal blood bag.Info->Class->Meta.SetMetaInt (AMETA_BloodType, blood); - if (SC_CheckString(",")) + if (sc.CheckString(",")) { - SC_MustGetString(); - blood = sc_String; + sc.MustGetString(); + blood = sc.String; } // blood splatter bag.Info->Class->Meta.SetMetaInt (AMETA_BloodType2, blood); - if (SC_CheckString(",")) + if (sc.CheckString(",")) { - SC_MustGetString(); - blood = sc_String; + sc.MustGetString(); + blood = sc.String; } // axe blood bag.Info->Class->Meta.SetMetaInt (AMETA_BloodType3, blood); @@ -1457,149 +1457,149 @@ static void ActorBloodType (AActor *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void ActorBounceFactor (AActor *defaults, Baggage &bag) +static void ActorBounceFactor (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat (); - defaults->bouncefactor = clamp(fixed_t(sc_Float * FRACUNIT), 0, FRACUNIT); + sc.MustGetFloat (); + defaults->bouncefactor = clamp(fixed_t(sc.Float * FRACUNIT), 0, FRACUNIT); } //========================================================================== // //========================================================================== -static void ActorBounceCount (AActor *defaults, Baggage &bag) +static void ActorBounceCount (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber (); - defaults->bouncecount = sc_Number; + sc.MustGetNumber (); + defaults->bouncecount = sc.Number; } //========================================================================== // //========================================================================== -static void ActorMinMissileChance (AActor *defaults, Baggage &bag) +static void ActorMinMissileChance (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber (); - defaults->MinMissileChance=sc_Number; + sc.MustGetNumber (); + defaults->MinMissileChance=sc.Number; } //========================================================================== // //========================================================================== -static void ActorDamageType (AActor *defaults, Baggage &bag) +static void ActorDamageType (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString (); - if (SC_Compare("Normal")) defaults->DamageType = NAME_None; - else defaults->DamageType=sc_String; + sc.MustGetString (); + if (sc.Compare("Normal")) defaults->DamageType = NAME_None; + else defaults->DamageType=sc.String; } //========================================================================== // //========================================================================== -static void ActorDamageFactor (AActor *defaults, Baggage &bag) +static void ActorDamageFactor (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString (); + sc.MustGetString (); if (bag.Info->DamageFactors == NULL) bag.Info->DamageFactors=new DmgFactors; FName dmgType; - if (SC_Compare("Normal")) dmgType = NAME_None; - else dmgType=sc_String; + if (sc.Compare("Normal")) dmgType = NAME_None; + else dmgType=sc.String; - SC_MustGetToken(','); - SC_MustGetFloat(); - (*bag.Info->DamageFactors)[dmgType]=(fixed_t)(sc_Float*FRACUNIT); + sc.MustGetToken(','); + sc.MustGetFloat(); + (*bag.Info->DamageFactors)[dmgType]=(fixed_t)(sc.Float*FRACUNIT); } //========================================================================== // //========================================================================== -static void ActorDecal (AActor *defaults, Baggage &bag) +static void ActorDecal (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->DecalGenerator = (FDecalBase *)intptr_t(int(FName(sc_String))); + sc.MustGetString(); + defaults->DecalGenerator = (FDecalBase *)intptr_t(int(FName(sc.String))); } //========================================================================== // //========================================================================== -static void ActorMaxStepHeight (AActor *defaults, Baggage &bag) +static void ActorMaxStepHeight (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber (); - defaults->MaxStepHeight=sc_Number * FRACUNIT; + sc.MustGetNumber (); + defaults->MaxStepHeight=sc.Number * FRACUNIT; } //========================================================================== // //========================================================================== -static void ActorMaxDropoffHeight (AActor *defaults, Baggage &bag) +static void ActorMaxDropoffHeight (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber (); - defaults->MaxDropOffHeight=sc_Number * FRACUNIT; + sc.MustGetNumber (); + defaults->MaxDropOffHeight=sc.Number * FRACUNIT; } //========================================================================== // //========================================================================== -static void ActorPoisonDamage (AActor *defaults, Baggage &bag) +static void ActorPoisonDamage (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber(); - bag.Info->Class->Meta.SetMetaInt (AMETA_PoisonDamage, sc_Number); + sc.MustGetNumber(); + bag.Info->Class->Meta.SetMetaInt (AMETA_PoisonDamage, sc.Number); } //========================================================================== // //========================================================================== -static void ActorFastSpeed (AActor *defaults, Baggage &bag) +static void ActorFastSpeed (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - bag.Info->Class->Meta.SetMetaFixed (AMETA_FastSpeed, fixed_t(sc_Float*FRACUNIT)); + sc.MustGetFloat(); + bag.Info->Class->Meta.SetMetaFixed (AMETA_FastSpeed, fixed_t(sc.Float*FRACUNIT)); } //========================================================================== // //========================================================================== -static void ActorRadiusDamageFactor (AActor *defaults, Baggage &bag) +static void ActorRadiusDamageFactor (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - bag.Info->Class->Meta.SetMetaFixed (AMETA_RDFactor, fixed_t(sc_Float*FRACUNIT)); + sc.MustGetFloat(); + bag.Info->Class->Meta.SetMetaFixed (AMETA_RDFactor, fixed_t(sc.Float*FRACUNIT)); } //========================================================================== // //========================================================================== -static void ActorCameraheight (AActor *defaults, Baggage &bag) +static void ActorCameraheight (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - bag.Info->Class->Meta.SetMetaFixed (AMETA_CameraHeight, fixed_t(sc_Float*FRACUNIT)); + sc.MustGetFloat(); + bag.Info->Class->Meta.SetMetaFixed (AMETA_CameraHeight, fixed_t(sc.Float*FRACUNIT)); } //========================================================================== // //========================================================================== -static void ActorVSpeed (AActor *defaults, Baggage &bag) +static void ActorVSpeed (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - defaults->momz = fixed_t(sc_Float*FRACUNIT); + sc.MustGetFloat(); + defaults->momz = fixed_t(sc.Float*FRACUNIT); } //========================================================================== // //========================================================================== -static void ActorGravity (AActor *defaults, Baggage &bag) +static void ActorGravity (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat (); + sc.MustGetFloat (); - if (sc_Float < 0.f) - SC_ScriptError ("Gravity must not be negative."); + if (sc.Float < 0.f) + sc.ScriptError ("Gravity must not be negative."); - defaults->gravity = FLOAT2FIXED (sc_Float); + defaults->gravity = FLOAT2FIXED (sc.Float); - if (sc_Float == 0.f) + if (sc.Float == 0.f) defaults->flags |= MF_NOGRAVITY; } //========================================================================== // //========================================================================== -static void ActorClearFlags (AActor *defaults, Baggage &bag) +static void ActorClearFlags (FScanner &sc, AActor *defaults, Baggage &bag) { defaults->flags=defaults->flags3=defaults->flags4=defaults->flags5=0; defaults->flags2&=MF2_ARGSDEFINED; // this flag must not be cleared @@ -1608,7 +1608,7 @@ static void ActorClearFlags (AActor *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void ActorMonster (AActor *defaults, Baggage &bag) +static void ActorMonster (FScanner &sc, AActor *defaults, Baggage &bag) { // sets the standard flag for a monster defaults->flags|=MF_SHOOTABLE|MF_COUNTKILL|MF_SOLID; @@ -1620,7 +1620,7 @@ static void ActorMonster (AActor *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void ActorProjectile (AActor *defaults, Baggage &bag) +static void ActorProjectile (FScanner &sc, AActor *defaults, Baggage &bag) { // sets the standard flags for a projectile defaults->flags|=MF_NOBLOCKMAP|MF_NOGRAVITY|MF_DROPOFF|MF_MISSILE; @@ -1637,120 +1637,120 @@ static void ActorProjectile (AActor *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void AmmoBackpackAmount (AAmmo *defaults, Baggage &bag) +static void AmmoBackpackAmount (FScanner &sc, AAmmo *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->BackpackAmount=sc_Number; + sc.MustGetNumber(); + defaults->BackpackAmount=sc.Number; } //========================================================================== // //========================================================================== -static void AmmoBackpackMaxAmount (AAmmo *defaults, Baggage &bag) +static void AmmoBackpackMaxAmount (FScanner &sc, AAmmo *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->BackpackMaxAmount=sc_Number; + sc.MustGetNumber(); + defaults->BackpackMaxAmount=sc.Number; } //========================================================================== // //========================================================================== -static void AmmoDropAmount (AAmmo *defaults, Baggage &bag) +static void AmmoDropAmount (FScanner &sc, AAmmo *defaults, Baggage &bag) { - SC_MustGetNumber(); - bag.Info->Class->Meta.SetMetaInt (AIMETA_DropAmount, sc_Number); + sc.MustGetNumber(); + bag.Info->Class->Meta.SetMetaInt (AIMETA_DropAmount, sc.Number); } //========================================================================== // //========================================================================== -static void ArmorMaxSaveAmount (ABasicArmorBonus *defaults, Baggage &bag) +static void ArmorMaxSaveAmount (FScanner &sc, ABasicArmorBonus *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->MaxSaveAmount = sc_Number; + sc.MustGetNumber(); + defaults->MaxSaveAmount = sc.Number; } //========================================================================== // //========================================================================== -static void ArmorMaxBonus (ABasicArmorBonus *defaults, Baggage &bag) +static void ArmorMaxBonus (FScanner &sc, ABasicArmorBonus *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->BonusCount = sc_Number; + sc.MustGetNumber(); + defaults->BonusCount = sc.Number; } //========================================================================== // //========================================================================== -static void ArmorMaxBonusMax (ABasicArmorBonus *defaults, Baggage &bag) +static void ArmorMaxBonusMax (FScanner &sc, ABasicArmorBonus *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->BonusMax = sc_Number; + sc.MustGetNumber(); + defaults->BonusMax = sc.Number; } //========================================================================== // //========================================================================== -static void ArmorSaveAmount (AActor *defaults, Baggage &bag) +static void ArmorSaveAmount (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetNumber(); + sc.MustGetNumber(); // Special case here because this property has to work for 2 unrelated classes if (bag.Info->Class->IsDescendantOf(RUNTIME_CLASS(ABasicArmorPickup))) { - ((ABasicArmorPickup*)defaults)->SaveAmount=sc_Number; + ((ABasicArmorPickup*)defaults)->SaveAmount=sc.Number; } else if (bag.Info->Class->IsDescendantOf(RUNTIME_CLASS(ABasicArmorBonus))) { - ((ABasicArmorBonus*)defaults)->SaveAmount=sc_Number; + ((ABasicArmorBonus*)defaults)->SaveAmount=sc.Number; } else { - SC_ScriptError("\"%s\" requires an actor of type \"Armor\"\n", sc_String); + sc.ScriptError("\"%s\" requires an actor of type \"Armor\"\n", sc.String); } } //========================================================================== // //========================================================================== -static void ArmorSavePercent (AActor *defaults, Baggage &bag) +static void ArmorSavePercent (FScanner &sc, AActor *defaults, Baggage &bag) { - SC_MustGetFloat(); - if (sc_Float<0.0f) sc_Float=0.0f; - if (sc_Float>100.0f) sc_Float=100.0f; + sc.MustGetFloat(); + if (sc.Float<0.0f) sc.Float=0.0f; + if (sc.Float>100.0f) sc.Float=100.0f; // Special case here because this property has to work for 2 unrelated classes if (bag.Info->Class->IsDescendantOf(RUNTIME_CLASS(ABasicArmorPickup))) { - ((ABasicArmorPickup*)defaults)->SavePercent=fixed_t(sc_Float*FRACUNIT/100.0f); + ((ABasicArmorPickup*)defaults)->SavePercent=fixed_t(sc.Float*FRACUNIT/100.0f); } else if (bag.Info->Class->IsDescendantOf(RUNTIME_CLASS(ABasicArmorBonus))) { - ((ABasicArmorBonus*)defaults)->SavePercent=fixed_t(sc_Float*FRACUNIT/100.0f); + ((ABasicArmorBonus*)defaults)->SavePercent=fixed_t(sc.Float*FRACUNIT/100.0f); } else { - SC_ScriptError("\"%s\" requires an actor of type \"Armor\"\n", sc_String); + sc.ScriptError("\"%s\" requires an actor of type \"Armor\"\n", sc.String); } } //========================================================================== // //========================================================================== -static void InventoryAmount (AInventory *defaults, Baggage &bag) +static void InventoryAmount (FScanner &sc, AInventory *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->Amount=sc_Number; + sc.MustGetNumber(); + defaults->Amount=sc.Number; } //========================================================================== // //========================================================================== -static void InventoryIcon (AInventory *defaults, Baggage &bag) +static void InventoryIcon (FScanner &sc, AInventory *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->Icon = TexMan.AddPatch (sc_String); + sc.MustGetString(); + defaults->Icon = TexMan.AddPatch (sc.String); if (defaults->Icon <= 0) { - defaults->Icon = TexMan.AddPatch (sc_String, ns_sprites); + defaults->Icon = TexMan.AddPatch (sc.String, ns_sprites); if (defaults->Icon<=0) { // Don't print warnings if the item is for another game or if this is a shareware IWAD. @@ -1758,7 +1758,7 @@ static void InventoryIcon (AInventory *defaults, Baggage &bag) if ((bag.Info->GameFilter == GAME_Any || bag.Info->GameFilter & gameinfo.gametype) && !(gameinfo.flags&GI_SHAREWARE)) { - Printf("Icon '%s' for '%s' not found\n", sc_String, bag.Info->Class->TypeName.GetChars()); + Printf("Icon '%s' for '%s' not found\n", sc.String, bag.Info->Class->TypeName.GetChars()); } } } @@ -1767,16 +1767,16 @@ static void InventoryIcon (AInventory *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void InventoryMaxAmount (AInventory *defaults, Baggage &bag) +static void InventoryMaxAmount (FScanner &sc, AInventory *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->MaxAmount=sc_Number; + sc.MustGetNumber(); + defaults->MaxAmount=sc.Number; } //========================================================================== // //========================================================================== -static void InventoryDefMaxAmount (AInventory *defaults, Baggage &bag) +static void InventoryDefMaxAmount (FScanner &sc, AInventory *defaults, Baggage &bag) { defaults->MaxAmount = gameinfo.gametype == GAME_Heretic ? 16 : 25; } @@ -1785,105 +1785,105 @@ static void InventoryDefMaxAmount (AInventory *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void InventoryPickupmsg (AInventory *defaults, Baggage &bag) +static void InventoryPickupmsg (FScanner &sc, AInventory *defaults, Baggage &bag) { // allow game specific pickup messages const char * games[] = {"Doom", "Heretic", "Hexen", "Raven", "Strife", NULL}; int gamemode[]={GAME_Doom, GAME_Heretic, GAME_Hexen, GAME_Raven, GAME_Strife}; - SC_MustGetString(); - int game = SC_MatchString(games); + sc.MustGetString(); + int game = sc.MatchString(games); - if (game!=-1 && SC_CheckString(",")) + if (game!=-1 && sc.CheckString(",")) { - SC_MustGetString(); + sc.MustGetString(); if (!(gameinfo.gametype&gamemode[game])) return; } - bag.Info->Class->Meta.SetMetaString(AIMETA_PickupMessage, sc_String); + bag.Info->Class->Meta.SetMetaString(AIMETA_PickupMessage, sc.String); } //========================================================================== // //========================================================================== -static void InventoryPickupsound (AInventory *defaults, Baggage &bag) +static void InventoryPickupsound (FScanner &sc, AInventory *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->PickupSound=S_FindSound(sc_String); + sc.MustGetString(); + defaults->PickupSound=S_FindSound(sc.String); } //========================================================================== // //========================================================================== -static void InventoryRespawntics (AInventory *defaults, Baggage &bag) +static void InventoryRespawntics (FScanner &sc, AInventory *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->RespawnTics=sc_Number; + sc.MustGetNumber(); + defaults->RespawnTics=sc.Number; } //========================================================================== // //========================================================================== -static void InventoryUsesound (AInventory *defaults, Baggage &bag) +static void InventoryUsesound (FScanner &sc, AInventory *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->UseSound=S_FindSound(sc_String); + sc.MustGetString(); + defaults->UseSound=S_FindSound(sc.String); } //========================================================================== // //========================================================================== -static void InventoryGiveQuest (AInventory *defaults, Baggage &bag) +static void InventoryGiveQuest (FScanner &sc, AInventory *defaults, Baggage &bag) { - SC_MustGetNumber(); - bag.Info->Class->Meta.SetMetaInt(AIMETA_GiveQuest, sc_Number); + sc.MustGetNumber(); + bag.Info->Class->Meta.SetMetaInt(AIMETA_GiveQuest, sc.Number); } //========================================================================== // //========================================================================== -static void HealthLowMessage (AHealth *defaults, Baggage &bag) +static void HealthLowMessage (FScanner &sc, AHealth *defaults, Baggage &bag) { - SC_MustGetNumber(); - bag.Info->Class->Meta.SetMetaInt(AIMETA_LowHealth, sc_Number); - SC_MustGetStringName(","); - SC_MustGetString(); - bag.Info->Class->Meta.SetMetaString(AIMETA_LowHealthMessage, sc_String); + sc.MustGetNumber(); + bag.Info->Class->Meta.SetMetaInt(AIMETA_LowHealth, sc.Number); + sc.MustGetStringName(","); + sc.MustGetString(); + bag.Info->Class->Meta.SetMetaString(AIMETA_LowHealthMessage, sc.String); } //========================================================================== // //========================================================================== -static void PuzzleitemNumber (APuzzleItem *defaults, Baggage &bag) +static void PuzzleitemNumber (FScanner &sc, APuzzleItem *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->PuzzleItemNumber=sc_Number; + sc.MustGetNumber(); + defaults->PuzzleItemNumber=sc.Number; } //========================================================================== // //========================================================================== -static void PuzzleitemFailMsg (APuzzleItem *defaults, Baggage &bag) +static void PuzzleitemFailMsg (FScanner &sc, APuzzleItem *defaults, Baggage &bag) { - SC_MustGetString(); - bag.Info->Class->Meta.SetMetaString(AIMETA_PuzzFailMessage, sc_String); + sc.MustGetString(); + bag.Info->Class->Meta.SetMetaString(AIMETA_PuzzFailMessage, sc.String); } //========================================================================== // //========================================================================== -static void WeaponAmmoGive1 (AWeapon *defaults, Baggage &bag) +static void WeaponAmmoGive1 (FScanner &sc, AWeapon *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->AmmoGive1=sc_Number; + sc.MustGetNumber(); + defaults->AmmoGive1=sc.Number; } //========================================================================== // //========================================================================== -static void WeaponAmmoGive2 (AWeapon *defaults, Baggage &bag) +static void WeaponAmmoGive2 (FScanner &sc, AWeapon *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->AmmoGive2=sc_Number; + sc.MustGetNumber(); + defaults->AmmoGive2=sc.Number; } //========================================================================== @@ -1894,165 +1894,165 @@ static void WeaponAmmoGive2 (AWeapon *defaults, Baggage &bag) // //========================================================================== -static void WeaponAmmoType1 (AWeapon *defaults, Baggage &bag) +static void WeaponAmmoType1 (FScanner &sc, AWeapon *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->AmmoType1 = fuglyname(sc_String); + sc.MustGetString(); + defaults->AmmoType1 = fuglyname(sc.String); } //========================================================================== // //========================================================================== -static void WeaponAmmoType2 (AWeapon *defaults, Baggage &bag) +static void WeaponAmmoType2 (FScanner &sc, AWeapon *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->AmmoType2 = fuglyname(sc_String); + sc.MustGetString(); + defaults->AmmoType2 = fuglyname(sc.String); } //========================================================================== // //========================================================================== -static void WeaponAmmoUse1 (AWeapon *defaults, Baggage &bag) +static void WeaponAmmoUse1 (FScanner &sc, AWeapon *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->AmmoUse1=sc_Number; + sc.MustGetNumber(); + defaults->AmmoUse1=sc.Number; } //========================================================================== // //========================================================================== -static void WeaponAmmoUse2 (AWeapon *defaults, Baggage &bag) +static void WeaponAmmoUse2 (FScanner &sc, AWeapon *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->AmmoUse2=sc_Number; + sc.MustGetNumber(); + defaults->AmmoUse2=sc.Number; } //========================================================================== // //========================================================================== -static void WeaponKickback (AWeapon *defaults, Baggage &bag) +static void WeaponKickback (FScanner &sc, AWeapon *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->Kickback=sc_Number; + sc.MustGetNumber(); + defaults->Kickback=sc.Number; } //========================================================================== // //========================================================================== -static void WeaponReadySound (AWeapon *defaults, Baggage &bag) +static void WeaponReadySound (FScanner &sc, AWeapon *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->ReadySound=S_FindSound(sc_String); + sc.MustGetString(); + defaults->ReadySound=S_FindSound(sc.String); } //========================================================================== // //========================================================================== -static void WeaponSelectionOrder (AWeapon *defaults, Baggage &bag) +static void WeaponSelectionOrder (FScanner &sc, AWeapon *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->SelectionOrder=sc_Number; + sc.MustGetNumber(); + defaults->SelectionOrder=sc.Number; } //========================================================================== // //========================================================================== -static void WeaponSisterWeapon (AWeapon *defaults, Baggage &bag) +static void WeaponSisterWeapon (FScanner &sc, AWeapon *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->SisterWeaponType=fuglyname(sc_String); + sc.MustGetString(); + defaults->SisterWeaponType=fuglyname(sc.String); } //========================================================================== // //========================================================================== -static void WeaponUpSound (AWeapon *defaults, Baggage &bag) +static void WeaponUpSound (FScanner &sc, AWeapon *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->UpSound=S_FindSound(sc_String); + sc.MustGetString(); + defaults->UpSound=S_FindSound(sc.String); } //========================================================================== // //========================================================================== -static void WeaponYAdjust (AWeapon *defaults, Baggage &bag) +static void WeaponYAdjust (FScanner &sc, AWeapon *defaults, Baggage &bag) { - SC_MustGetFloat(); - defaults->YAdjust=fixed_t(sc_Float * FRACUNIT); + sc.MustGetFloat(); + defaults->YAdjust=fixed_t(sc.Float * FRACUNIT); } //========================================================================== // //========================================================================== -static void WPieceValue (AWeaponPiece *defaults, Baggage &bag) +static void WPieceValue (FScanner &sc, AWeaponPiece *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->PieceValue = 1 << (sc_Number-1); + sc.MustGetNumber(); + defaults->PieceValue = 1 << (sc.Number-1); } //========================================================================== // //========================================================================== -static void WPieceWeapon (AWeaponPiece *defaults, Baggage &bag) +static void WPieceWeapon (FScanner &sc, AWeaponPiece *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->WeaponClass = fuglyname(sc_String); + sc.MustGetString(); + defaults->WeaponClass = fuglyname(sc.String); } //========================================================================== // //========================================================================== -static void PowerupColor (APowerupGiver *defaults, Baggage &bag) +static void PowerupColor (FScanner &sc, APowerupGiver *defaults, Baggage &bag) { int r; int g; int b; int alpha; - if (SC_CheckNumber()) + if (sc.CheckNumber()) { - r=clamp(sc_Number, 0, 255); - SC_CheckString(","); - SC_MustGetNumber(); - g=clamp(sc_Number, 0, 255); - SC_CheckString(","); - SC_MustGetNumber(); - b=clamp(sc_Number, 0, 255); + r=clamp(sc.Number, 0, 255); + sc.CheckString(","); + sc.MustGetNumber(); + g=clamp(sc.Number, 0, 255); + sc.CheckString(","); + sc.MustGetNumber(); + b=clamp(sc.Number, 0, 255); } else { - SC_MustGetString(); + sc.MustGetString(); - if (SC_Compare("INVERSEMAP")) + if (sc.Compare("INVERSEMAP")) { defaults->BlendColor = INVERSECOLOR; return; } - else if (SC_Compare("GOLDMAP")) + else if (sc.Compare("GOLDMAP")) { defaults->BlendColor = GOLDCOLOR; return; } // [BC] Yay, more hacks. - else if ( SC_Compare( "REDMAP" )) + else if ( sc.Compare( "REDMAP" )) { defaults->BlendColor = REDCOLOR; return; } - else if ( SC_Compare( "GREENMAP" )) + else if ( sc.Compare( "GREENMAP" )) { defaults->BlendColor = GREENCOLOR; return; } - int c = V_GetColor(NULL, sc_String); + int c = V_GetColor(NULL, sc.String); r=RPART(c); g=GPART(c); b=BPART(c); } - SC_CheckString(","); - SC_MustGetFloat(); - alpha=int(sc_Float*255); + sc.CheckString(","); + sc.MustGetFloat(); + alpha=int(sc.Float*255); alpha=clamp(alpha, 0, 255); if (alpha!=0) defaults->BlendColor = MAKEARGB(alpha, r, g, b); else defaults->BlendColor = 0; @@ -2061,38 +2061,38 @@ static void PowerupColor (APowerupGiver *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void PowerupDuration (APowerupGiver *defaults, Baggage &bag) +static void PowerupDuration (FScanner &sc, APowerupGiver *defaults, Baggage &bag) { - SC_MustGetNumber(); - defaults->EffectTics = sc_Number; + sc.MustGetNumber(); + defaults->EffectTics = sc.Number; } //========================================================================== // //========================================================================== -static void PowerupMode (APowerupGiver *defaults, Baggage &bag) +static void PowerupMode (FScanner &sc, APowerupGiver *defaults, Baggage &bag) { - SC_MustGetString(); - defaults->mode = (FName)sc_String; + sc.MustGetString(); + defaults->mode = (FName)sc.String; } //========================================================================== // //========================================================================== -static void PowerupType (APowerupGiver *defaults, Baggage &bag) +static void PowerupType (FScanner &sc, APowerupGiver *defaults, Baggage &bag) { FString typestr; - SC_MustGetString(); - typestr.Format ("Power%s", sc_String); + sc.MustGetString(); + typestr.Format ("Power%s", sc.String); const PClass * powertype=PClass::FindClass(typestr); if (!powertype) { - SC_ScriptError("Unknown powerup type '%s' in '%s'\n", sc_String, bag.Info->Class->TypeName.GetChars()); + sc.ScriptError("Unknown powerup type '%s' in '%s'\n", sc.String, bag.Info->Class->TypeName.GetChars()); } else if (!powertype->IsDescendantOf(RUNTIME_CLASS(APowerup))) { - SC_ScriptError("Invalid powerup type '%s' in '%s'\n", sc_String, bag.Info->Class->TypeName.GetChars()); + sc.ScriptError("Invalid powerup type '%s' in '%s'\n", sc.String, bag.Info->Class->TypeName.GetChars()); } else { @@ -2109,21 +2109,21 @@ static void PowerupType (APowerupGiver *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void PlayerDisplayName (APlayerPawn *defaults, Baggage &bag) +static void PlayerDisplayName (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetString (); - bag.Info->Class->Meta.SetMetaString (APMETA_DisplayName, sc_String); + sc.MustGetString (); + bag.Info->Class->Meta.SetMetaString (APMETA_DisplayName, sc.String); } //========================================================================== // //========================================================================== -static void PlayerSoundClass (APlayerPawn *defaults, Baggage &bag) +static void PlayerSoundClass (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { FString tmp; - SC_MustGetString (); - tmp = sc_String; + sc.MustGetString (); + tmp = sc.String; tmp.ReplaceChars (' ', '_'); bag.Info->Class->Meta.SetMetaString (APMETA_SoundClass, tmp); } @@ -2131,15 +2131,15 @@ static void PlayerSoundClass (APlayerPawn *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void PlayerColorRange (APlayerPawn *defaults, Baggage &bag) +static void PlayerColorRange (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { int start, end; - SC_MustGetNumber (); - start = sc_Number; - SC_CheckString(","); - SC_MustGetNumber (); - end = sc_Number; + sc.MustGetNumber (); + start = sc.Number; + sc.CheckString(","); + sc.MustGetNumber (); + end = sc.Number; if (start > end) swap (start, end); @@ -2150,38 +2150,38 @@ static void PlayerColorRange (APlayerPawn *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void PlayerAttackZOffset (APlayerPawn *defaults, Baggage &bag) +static void PlayerAttackZOffset (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetFloat (); - defaults->AttackZOffset = FLOAT2FIXED (sc_Float); + sc.MustGetFloat (); + defaults->AttackZOffset = FLOAT2FIXED (sc.Float); } //========================================================================== // //========================================================================== -static void PlayerJumpZ (APlayerPawn *defaults, Baggage &bag) +static void PlayerJumpZ (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetFloat (); - defaults->JumpZ = FLOAT2FIXED (sc_Float); + sc.MustGetFloat (); + defaults->JumpZ = FLOAT2FIXED (sc.Float); } //========================================================================== // //========================================================================== -static void PlayerSpawnClass (APlayerPawn *defaults, Baggage &bag) +static void PlayerSpawnClass (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetString (); - if (SC_Compare ("Any")) + sc.MustGetString (); + if (sc.Compare ("Any")) defaults->SpawnMask = 0; - else if (SC_Compare ("Fighter")) + else if (sc.Compare ("Fighter")) defaults->SpawnMask |= MTF_FIGHTER; - else if (SC_Compare ("Cleric")) + else if (sc.Compare ("Cleric")) defaults->SpawnMask |= MTF_CLERIC; - else if (SC_Compare ("Mage")) + else if (sc.Compare ("Mage")) defaults->SpawnMask |= MTF_MAGE; - else if (IsNum(sc_String)) + else if (IsNum(sc.String)) { - int val = strtol(sc_String, NULL, 0); + int val = strtol(sc.String, NULL, 0); defaults->SpawnMask = (val*MTF_FIGHTER) & (MTF_FIGHTER|MTF_CLERIC|MTF_MAGE); } } @@ -2189,74 +2189,74 @@ static void PlayerSpawnClass (APlayerPawn *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void PlayerViewHeight (APlayerPawn *defaults, Baggage &bag) +static void PlayerViewHeight (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetFloat (); - defaults->ViewHeight = FLOAT2FIXED (sc_Float); + sc.MustGetFloat (); + defaults->ViewHeight = FLOAT2FIXED (sc.Float); } //========================================================================== // //========================================================================== -static void PlayerForwardMove (APlayerPawn *defaults, Baggage &bag) +static void PlayerForwardMove (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetFloat (); - defaults->ForwardMove1 = defaults->ForwardMove2 = FLOAT2FIXED (sc_Float); - if (CheckFloatParm ()) - defaults->ForwardMove2 = FLOAT2FIXED (sc_Float); + sc.MustGetFloat (); + defaults->ForwardMove1 = defaults->ForwardMove2 = FLOAT2FIXED (sc.Float); + if (CheckFloatParm (sc)) + defaults->ForwardMove2 = FLOAT2FIXED (sc.Float); } //========================================================================== // //========================================================================== -static void PlayerSideMove (APlayerPawn *defaults, Baggage &bag) +static void PlayerSideMove (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetFloat (); - defaults->SideMove1 = defaults->SideMove2 = FLOAT2FIXED (sc_Float); - if (CheckFloatParm ()) - defaults->SideMove2 = FLOAT2FIXED (sc_Float); + sc.MustGetFloat (); + defaults->SideMove1 = defaults->SideMove2 = FLOAT2FIXED (sc.Float); + if (CheckFloatParm (sc)) + defaults->SideMove2 = FLOAT2FIXED (sc.Float); } //========================================================================== // //========================================================================== -static void PlayerMaxHealth (APlayerPawn *defaults, Baggage &bag) +static void PlayerMaxHealth (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetNumber (); - defaults->MaxHealth = sc_Number; + sc.MustGetNumber (); + defaults->MaxHealth = sc.Number; } //========================================================================== // //========================================================================== -static void PlayerRunHealth (APlayerPawn *defaults, Baggage &bag) +static void PlayerRunHealth (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetNumber (); - defaults->RunHealth = sc_Number; + sc.MustGetNumber (); + defaults->RunHealth = sc.Number; } //========================================================================== // //========================================================================== -static void PlayerMorphWeapon (APlayerPawn *defaults, Baggage &bag) +static void PlayerMorphWeapon (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetString (); - defaults->MorphWeapon = FName(sc_String); + sc.MustGetString (); + defaults->MorphWeapon = FName(sc.String); } //========================================================================== // //========================================================================== -static void PlayerScoreIcon (APlayerPawn *defaults, Baggage &bag) +static void PlayerScoreIcon (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetString (); - defaults->ScoreIcon = TexMan.AddPatch (sc_String); + sc.MustGetString (); + defaults->ScoreIcon = TexMan.AddPatch (sc.String); if (defaults->ScoreIcon <= 0) { - defaults->ScoreIcon = TexMan.AddPatch (sc_String, ns_sprites); + defaults->ScoreIcon = TexMan.AddPatch (sc.String, ns_sprites); if (defaults->ScoreIcon <= 0) { - Printf("Icon '%s' for '%s' not found\n", sc_String, bag.Info->Class->TypeName.GetChars ()); + Printf("Icon '%s' for '%s' not found\n", sc.String, bag.Info->Class->TypeName.GetChars ()); } } } @@ -2264,11 +2264,14 @@ static void PlayerScoreIcon (APlayerPawn *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void PlayerCrouchSprite (APlayerPawn *defaults, Baggage &bag) +static void PlayerCrouchSprite (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetString (); - for (unsigned int i = 0; i < sc_StringLen; i++) sc_String[i] = toupper (sc_String[i]); - defaults->crouchsprite = GetSpriteIndex (sc_String); + sc.MustGetString (); + for (int i = 0; i < sc.StringLen; i++) + { + sc.String[i] = toupper (sc.String[i]); + } + defaults->crouchsprite = GetSpriteIndex (sc.String); } //========================================================================== @@ -2276,7 +2279,7 @@ static void PlayerCrouchSprite (APlayerPawn *defaults, Baggage &bag) // [GRB] Store start items in drop item list // //========================================================================== -static void PlayerStartItem (APlayerPawn *defaults, Baggage &bag) +static void PlayerStartItem (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { // create a linked list of dropitems if (!bag.DropItemSet) @@ -2287,13 +2290,13 @@ static void PlayerStartItem (APlayerPawn *defaults, Baggage &bag) FDropItem * di=new FDropItem; - SC_MustGetString(); - di->Name = sc_String; + sc.MustGetString(); + di->Name = sc.String; di->probability = 255; di->amount = 1; - if (CheckNumParm()) + if (CheckNumParm(sc)) { - di->amount = sc_Number; + di->amount = sc.Number; } di->Next = bag.DropItemList; bag.DropItemList = di; @@ -2302,50 +2305,50 @@ static void PlayerStartItem (APlayerPawn *defaults, Baggage &bag) //========================================================================== // //========================================================================== -static void PlayerInvulMode (APlayerPawn *defaults, Baggage &bag) +static void PlayerInvulMode (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetString (); - bag.Info->Class->Meta.SetMetaInt (APMETA_InvulMode, (FName)sc_String); + sc.MustGetString (); + bag.Info->Class->Meta.SetMetaInt (APMETA_InvulMode, (FName)sc.String); } //========================================================================== // //========================================================================== -static void PlayerHealRadius (APlayerPawn *defaults, Baggage &bag) +static void PlayerHealRadius (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { - SC_MustGetString (); - bag.Info->Class->Meta.SetMetaInt (APMETA_HealingRadius, (FName)sc_String); + sc.MustGetString (); + bag.Info->Class->Meta.SetMetaInt (APMETA_HealingRadius, (FName)sc.String); } //========================================================================== // //========================================================================== -static void PlayerHexenArmor (APlayerPawn *defaults, Baggage &bag) +static void PlayerHexenArmor (FScanner &sc, APlayerPawn *defaults, Baggage &bag) { for (int i=0;i<5;i++) { - SC_MustGetFloat (); - bag.Info->Class->Meta.SetMetaFixed (APMETA_Hexenarmor0+i, FLOAT2FIXED (sc_Float)); - if (i!=4) SC_MustGetStringName(","); + sc.MustGetFloat (); + bag.Info->Class->Meta.SetMetaFixed (APMETA_Hexenarmor0+i, FLOAT2FIXED (sc.Float)); + if (i!=4) sc.MustGetStringName(","); } } //========================================================================== // //========================================================================== -static void EggFXMonsterClass (AMorphProjectile *defaults, Baggage &bag) +static void EggFXMonsterClass (FScanner &sc, AMorphProjectile *defaults, Baggage &bag) { - SC_MustGetString (); - defaults->MonsterClass = FName(sc_String); + sc.MustGetString (); + defaults->MonsterClass = FName(sc.String); } //========================================================================== // //========================================================================== -static void EggFXPlayerClass (AMorphProjectile *defaults, Baggage &bag) +static void EggFXPlayerClass (FScanner &sc, AMorphProjectile *defaults, Baggage &bag) { - SC_MustGetString (); - defaults->PlayerClass = FName(sc_String); + sc.MustGetString (); + defaults->PlayerClass = FName(sc.String); } //========================================================================== @@ -2537,22 +2540,22 @@ static const ActorProps *is_actorprop (const char *str) // //========================================================================== -void ParseActorProperty(Baggage &bag) +void ParseActorProperty(FScanner &sc, Baggage &bag) { - strlwr (sc_String); + strlwr (sc.String); - FString propname = sc_String; + FString propname = sc.String; - if (SC_CheckString (".")) + if (sc.CheckString (".")) { - SC_MustGetString (); + sc.MustGetString (); propname += '.'; - strlwr (sc_String); - propname += sc_String; + strlwr (sc.String); + propname += sc.String; } else { - SC_UnGet (); + sc.UnGet (); } const ActorProps *prop = is_actorprop (propname.GetChars()); @@ -2561,16 +2564,16 @@ void ParseActorProperty(Baggage &bag) { if (!bag.Info->Class->IsDescendantOf(prop->type)) { - SC_ScriptError("\"%s\" requires an actor of type \"%s\"\n", propname.GetChars(), prop->type->TypeName.GetChars()); + sc.ScriptError("\"%s\" requires an actor of type \"%s\"\n", propname.GetChars(), prop->type->TypeName.GetChars()); } else { - prop->Handler ((AActor *)bag.Info->Class->Defaults, bag); + prop->Handler (sc, (AActor *)bag.Info->Class->Defaults, bag); } } else { - SC_ScriptError("\"%s\" is an unknown actor property\n", propname.GetChars()); + sc.ScriptError("\"%s\" is an unknown actor property\n", propname.GetChars()); } } @@ -2581,11 +2584,11 @@ void ParseActorProperty(Baggage &bag) // //========================================================================== -void FinishActor(FActorInfo *info, Baggage &bag) +void FinishActor(FScanner &sc, FActorInfo *info, Baggage &bag) { AActor *defaults = (AActor*)info->Class->Defaults; - FinishStates (info, defaults, bag); + FinishStates (sc, info, defaults, bag); InstallStates (info, defaults); ProcessStates (info->OwnedStates, info->NumOwnedStates); if (bag.DropItemSet) diff --git a/src/thingdef/thingdef_states.cpp b/src/thingdef/thingdef_states.cpp index aa6e1be35e..169fc2ead6 100644 --- a/src/thingdef/thingdef_states.cpp +++ b/src/thingdef/thingdef_states.cpp @@ -436,12 +436,12 @@ int FindLineSpecialEx (const char *string, int *min_args, int *max_args) // handles action specials as code pointers // //========================================================================== -bool DoActionSpecials(FState & state, bool multistate, int * statecount, Baggage &bag) +bool DoActionSpecials(FScanner &sc, FState & state, bool multistate, int * statecount, Baggage &bag) { int i; const ACSspecials *spec; - if ((spec = is_special (sc_String, sc_StringLen)) != NULL) + if ((spec = is_special (sc.String, sc.StringLen)) != NULL) { int paramindex=PrepareStateParameters(&state, 6); @@ -449,25 +449,25 @@ bool DoActionSpecials(FState & state, bool multistate, int * statecount, Baggage StateParameters[paramindex]=spec->Special; // Make this consistent with all other parameter parsing - if (SC_CheckToken('(')) + if (sc.CheckToken('(')) { for (i = 0; i < 5;) { - StateParameters[paramindex+i+1]=ParseExpression (false, bag.Info->Class); + StateParameters[paramindex+i+1] = ParseExpression (sc, false, bag.Info->Class); i++; - if (!SC_CheckToken (',')) break; + if (!sc.CheckToken (',')) break; } - SC_MustGetToken (')'); + sc.MustGetToken (')'); } else i=0; if (i < spec->MinArgs) { - SC_ScriptError ("Too few arguments to %s", spec->name); + sc.ScriptError ("Too few arguments to %s", spec->name); } if (i > MAX (spec->MinArgs, spec->MaxArgs)) { - SC_ScriptError ("Too many arguments to %s", spec->name); + sc.ScriptError ("Too many arguments to %s", spec->name); } state.Action = A_CallSpecial; return true; @@ -514,21 +514,21 @@ static void RetargetStates (intptr_t count, const char *target) // processes a state block // //========================================================================== -static FString ParseStateString() +static FString ParseStateString(FScanner &sc) { FString statestring; - SC_MustGetString(); - statestring = sc_String; - if (SC_CheckString("::")) + sc.MustGetString(); + statestring = sc.String; + if (sc.CheckString("::")) { - SC_MustGetString (); - statestring << "::" << sc_String; + sc.MustGetString (); + statestring << "::" << sc.String; } - while (SC_CheckString (".")) + while (sc.CheckString (".")) { - SC_MustGetString (); - statestring << "." << sc_String; + sc.MustGetString (); + statestring << "." << sc.String; } return statestring; } @@ -539,7 +539,7 @@ static FString ParseStateString() // parses a state block // //========================================================================== -int ParseStates(FActorInfo * actor, AActor * defaults, Baggage &bag) +int ParseStates(FScanner &sc, FActorInfo * actor, AActor * defaults, Baggage &bag) { FString statestring; intptr_t count = 0; @@ -548,21 +548,21 @@ int ParseStates(FActorInfo * actor, AActor * defaults, Baggage &bag) intptr_t lastlabel = -1; int minrequiredstate = -1; - SC_MustGetStringName ("{"); - SC_SetEscape(false); // disable escape sequences in the state parser - while (!SC_CheckString ("}") && !sc_End) + sc.MustGetStringName ("{"); + sc.SetEscape(false); // disable escape sequences in the state parser + while (!sc.CheckString ("}") && !sc.End) { memset(&state,0,sizeof(state)); - statestring = ParseStateString(); + statestring = ParseStateString(sc); if (!statestring.CompareNoCase("GOTO")) { do_goto: - statestring = ParseStateString(); - if (SC_CheckString ("+")) + statestring = ParseStateString(sc); + if (sc.CheckString ("+")) { - SC_MustGetNumber (); + sc.MustGetNumber (); statestring += '+'; - statestring += sc_String; + statestring += sc.String; } // copy the text - this must be resolved later! if (laststate != NULL) @@ -575,7 +575,7 @@ do_goto: } else { - SC_ScriptError("GOTO before first state"); + sc.ScriptError("GOTO before first state"); } } else if (!statestring.CompareNoCase("STOP")) @@ -591,7 +591,7 @@ do_stop: } else { - SC_ScriptError("STOP before first state"); + sc.ScriptError("STOP before first state"); continue; } } @@ -599,7 +599,7 @@ do_stop: { if (!laststate) { - SC_ScriptError("%s before first state", sc_String); + sc.ScriptError("%s before first state", sc.String); continue; } laststate->NextState=(FState*)-2; @@ -608,7 +608,7 @@ do_stop: { if (!laststate) { - SC_ScriptError("LOOP before first state"); + sc.ScriptError("LOOP before first state"); continue; } laststate->NextState=(FState*)(lastlabel+1); @@ -617,15 +617,15 @@ do_stop: { const char * statestrp; - SC_MustGetString(); - if (SC_Compare (":")) + sc.MustGetString(); + if (sc.Compare (":")) { laststate = NULL; do { lastlabel = count; AddState(statestring, (FState *) (count+1)); - statestring = ParseStateString(); + statestring = ParseStateString(sc); if (!statestring.CompareNoCase("GOTO")) { goto do_goto; @@ -634,72 +634,75 @@ do_stop: { goto do_stop; } - SC_MustGetString (); - } while (SC_Compare (":")); + sc.MustGetString (); + } while (sc.Compare (":")); // continue; } - SC_UnGet (); + sc.UnGet (); if (statestring.Len() != 4) { - SC_ScriptError ("Sprite names must be exactly 4 characters\n"); + sc.ScriptError ("Sprite names must be exactly 4 characters\n"); } memcpy(state.sprite.name, statestring, 4); - state.Misc1=state.Misc2=0; - state.ParameterIndex=0; - SC_MustGetString(); - statestring = (sc_String+1); + state.Misc1 = state.Misc2 = 0; + state.ParameterIndex = 0; + sc.MustGetString(); + statestring = (sc.String+1); statestrp = statestring; - state.Frame=(*sc_String&223)-'A'; - if ((*sc_String&223)<'A' || (*sc_String&223)>']') + state.Frame = (*sc.String & 223)-'A'; + if ((*sc.String & 223)<'A' || (*sc.String & 223)>']') { - SC_ScriptError ("Frames must be A-Z, [, \\, or ]"); + sc.ScriptError ("Frames must be A-Z, [, \\, or ]"); state.Frame=0; } - SC_MustGetNumber(); - sc_Number++; - state.Tics=sc_Number&255; - state.Misc1=(sc_Number>>8)&255; - if (state.Misc1) state.Frame|=SF_BIGTIC; - - while (SC_GetString() && !sc_Crossed) + sc.MustGetNumber(); + sc.Number++; + state.Tics = sc.Number & 255; + state.Misc1 = (sc.Number >> 8) & 255; + if (state.Misc1) { - if (SC_Compare("BRIGHT")) + state.Frame |= SF_BIGTIC; + } + + while (sc.GetString() && !sc.Crossed) + { + if (sc.Compare("BRIGHT")) { - state.Frame|=SF_FULLBRIGHT; + state.Frame |= SF_FULLBRIGHT; continue; } - if (SC_Compare("OFFSET")) + if (sc.Compare("OFFSET")) { - if (state.Frame&SF_BIGTIC) + if (state.Frame & SF_BIGTIC) { - SC_ScriptError("You cannot use OFFSET with a state duration larger than 254!"); + sc.ScriptError("You cannot use OFFSET with a state duration larger than 254!"); } // specify a weapon offset - SC_MustGetStringName("("); - SC_MustGetNumber(); - state.Misc1=sc_Number; - SC_MustGetStringName (","); - SC_MustGetNumber(); - state.Misc2=sc_Number; - SC_MustGetStringName(")"); + sc.MustGetStringName("("); + sc.MustGetNumber(); + state.Misc1 = sc.Number; + sc.MustGetStringName (","); + sc.MustGetNumber(); + state.Misc2 = sc.Number; + sc.MustGetStringName(")"); continue; } // Make the action name lowercase to satisfy the gperf hashers - strlwr (sc_String); + strlwr (sc.String); - int minreq=count; - if (DoActionSpecials(state, !statestring.IsEmpty(), &minreq, bag)) + int minreq = count; + if (DoActionSpecials(sc, state, !statestring.IsEmpty(), &minreq, bag)) { if (minreq>minrequiredstate) minrequiredstate=minreq; goto endofstate; } - PSymbol *sym = bag.Info->Class->Symbols.FindSymbol (FName(sc_String, true), true); + PSymbol *sym = bag.Info->Class->Symbols.FindSymbol (FName(sc.String, true), true); if (sym != NULL && sym->SymbolType == SYM_ActionFunction) { PSymbolActionFunction *afd = static_cast(sym); @@ -713,11 +716,11 @@ do_stop: if (!islower(*params)) { - SC_MustGetStringName("("); + sc.MustGetStringName("("); } else { - if (!SC_CheckString("(")) goto endofstate; + if (!sc.CheckString("(")) goto endofstate; } int paramindex = PrepareStateParameters(&state, numparams); @@ -735,47 +738,47 @@ do_stop: { case 'I': case 'i': // Integer - SC_MustGetNumber(); - v=sc_Number; + sc.MustGetNumber(); + v = sc.Number; break; case 'F': case 'f': // Fixed point - SC_MustGetFloat(); - v=fixed_t(sc_Float*FRACUNIT); + sc.MustGetFloat(); + v = fixed_t(sc.Float*FRACUNIT); break; case 'S': case 's': // Sound name - SC_MustGetString(); - v=S_FindSound(sc_String); + sc.MustGetString(); + v = S_FindSound(sc.String); break; case 'M': case 'm': // Actor name case 'T': case 't': // String - SC_SetEscape(true); - SC_MustGetString(); - SC_SetEscape(false); - v = (int)(sc_String[0] ? FName(sc_String) : NAME_None); + sc.SetEscape(true); + sc.MustGetString(); + sc.SetEscape(false); + v = (int)(sc.String[0] ? FName(sc.String) : NAME_None); break; case 'L': case 'l': // Jump label - if (SC_CheckNumber()) + if (sc.CheckNumber()) { - if (sc_Number > 0 && strlen(statestring)>0) + if (sc.Number > 0 && strlen(statestring)>0) { - SC_ScriptError("You cannot use state jumps commands with a jump offset on multistate definitions\n"); + sc.ScriptError("You cannot use state jumps commands with a jump offset on multistate definitions\n"); } - v=sc_Number; + v=sc.Number; if (v<0) { - SC_ScriptError("Negative jump offsets are not allowed"); + sc.ScriptError("Negative jump offsets are not allowed"); } { @@ -789,13 +792,13 @@ do_stop: v = -(int)JumpParameters.Size(); // This forces quotation marks around the state name. - SC_MustGetToken(TK_StringConst); - if (sc_String[0] == 0 || SC_Compare("None")) + sc.MustGetToken(TK_StringConst); + if (sc.String[0] == 0 || sc.Compare("None")) { v = 0; // an empty string means 'no state'. break; } - FString statestring = sc_String; // ParseStateString(); + FString statestring = sc.String; // ParseStateString(sc); const PClass *stype=NULL; int scope = statestring.IndexOf("::"); if (scope >= 0) @@ -812,15 +815,15 @@ do_stop: stype = PClass::FindClass (scopename); if (stype == NULL) { - SC_ScriptError ("%s is an unknown class.", scopename.GetChars()); + sc.ScriptError ("%s is an unknown class.", scopename.GetChars()); } if (!stype->IsDescendantOf (RUNTIME_CLASS(AActor))) { - SC_ScriptError ("%s is not an actor class, so it has no states.", stype->TypeName.GetChars()); + sc.ScriptError ("%s is not an actor class, so it has no states.", stype->TypeName.GetChars()); } if (!stype->IsAncestorOf (actor->Class)) { - SC_ScriptError ("%s is not derived from %s so cannot access its states.", + sc.ScriptError ("%s is not derived from %s so cannot access its states.", actor->Class->TypeName.GetChars(), stype->TypeName.GetChars()); } } @@ -839,7 +842,7 @@ do_stop: { if (!stype->ActorInfo->FindState(names.Size(), &names[0])) { - SC_ScriptError("Jump to unknown state '%s' in class '%s'", + sc.ScriptError("Jump to unknown state '%s' in class '%s'", statestring.GetChars(), stype->TypeName.GetChars()); } } @@ -855,14 +858,14 @@ do_stop: case 'C': case 'c': // Color - SC_MustGetString (); - if (SC_Compare("none")) + sc.MustGetString (); + if (sc.Compare("none")) { v = -1; } else { - int c = V_GetColor (NULL, sc_String); + int c = V_GetColor (NULL, sc.String); // 0 needs to be the default so we have to mark the color. v = MAKEARGB(1, RPART(c), GPART(c), BPART(c)); } @@ -870,12 +873,12 @@ do_stop: case 'X': case 'x': - v = ParseExpression (false, bag.Info->Class); + v = ParseExpression (sc, false, bag.Info->Class); break; case 'Y': case 'y': - v = ParseExpression (true, bag.Info->Class); + v = ParseExpression (sc, true, bag.Info->Class); break; default: @@ -893,7 +896,7 @@ do_stop: { if (*params == '+') { - if (SC_CheckString(")")) + if (sc.CheckString(")")) { goto endofstate; } @@ -901,29 +904,29 @@ do_stop: v = 0; StateParameters.Push(v); } - else if ((islower(*params) || *params=='!') && SC_CheckString(")")) + else if ((islower(*params) || *params=='!') && sc.CheckString(")")) { goto endofstate; } - SC_MustGetStringName (","); + sc.MustGetStringName (","); } } - SC_MustGetStringName(")"); + sc.MustGetStringName(")"); } else { - SC_MustGetString(); - if (SC_Compare("(")) + sc.MustGetString(); + if (sc.Compare("(")) { - SC_ScriptError("You cannot pass parameters to '%s'\n",sc_String); + sc.ScriptError("You cannot pass parameters to '%s'\n",sc.String); } - SC_UnGet(); + sc.UnGet(); } goto endofstate; } - SC_ScriptError("Invalid state parameter %s\n", sc_String); + sc.ScriptError("Invalid state parameter %s\n", sc.String); } - SC_UnGet(); + sc.UnGet(); endofstate: StateArray.Push(state); while (*statestrp) @@ -932,7 +935,7 @@ endofstate: if (frame<0 || frame>28) { - SC_ScriptError ("Frames must be A-Z, [, \\, or ]"); + sc.ScriptError ("Frames must be A-Z, [, \\, or ]"); frame=0; } @@ -946,9 +949,9 @@ endofstate: } if (count<=minrequiredstate) { - SC_ScriptError("A_Jump offset out of range in %s", actor->Class->TypeName.GetChars()); + sc.ScriptError("A_Jump offset out of range in %s", actor->Class->TypeName.GetChars()); } - SC_SetEscape(true); // re-enable escape sequences + sc.SetEscape(true); // re-enable escape sequences return count; } @@ -958,7 +961,7 @@ endofstate: // //========================================================================== -static FState *ResolveGotoLabel (AActor *actor, const PClass *mytype, char *name) +static FState *ResolveGotoLabel (FScanner &sc, AActor *actor, const PClass *mytype, char *name) { const PClass *type=mytype; FState *state; @@ -986,15 +989,15 @@ static FState *ResolveGotoLabel (AActor *actor, const PClass *mytype, char *name const PClass *stype = PClass::FindClass (classname); if (stype == NULL) { - SC_ScriptError ("%s is an unknown class.", classname); + sc.ScriptError ("%s is an unknown class.", classname); } if (!stype->IsDescendantOf (RUNTIME_CLASS(AActor))) { - SC_ScriptError ("%s is not an actor class, so it has no states.", stype->TypeName.GetChars()); + sc.ScriptError ("%s is not an actor class, so it has no states.", stype->TypeName.GetChars()); } if (!stype->IsAncestorOf (type)) { - SC_ScriptError ("%s is not derived from %s so cannot access its states.", + sc.ScriptError ("%s is not derived from %s so cannot access its states.", type->TypeName.GetChars(), stype->TypeName.GetChars()); } if (type != stype) @@ -1024,7 +1027,7 @@ static FState *ResolveGotoLabel (AActor *actor, const PClass *mytype, char *name } else if (v != 0) { - SC_ScriptError ("Attempt to get invalid state %s from actor %s.", label, type->TypeName.GetChars()); + sc.ScriptError ("Attempt to get invalid state %s from actor %s.", label, type->TypeName.GetChars()); } delete[] namestart; // free the allocated string buffer return state; @@ -1059,15 +1062,15 @@ static void FixStatePointers (FActorInfo *actor, TArray & list) // //========================================================================== -static void FixStatePointersAgain (FActorInfo *actor, AActor *defaults, TArray & list) +static void FixStatePointersAgain (FScanner &sc, FActorInfo *actor, AActor *defaults, TArray & list) { for(unsigned i=0;iClass, (char *)list[i].State); + list[i].State = ResolveGotoLabel (sc, defaults, actor->Class, (char *)list[i].State); } - if (list[i].Children.Size() > 0) FixStatePointersAgain(actor, defaults, list[i].Children); + if (list[i].Children.Size() > 0) FixStatePointersAgain(sc, actor, defaults, list[i].Children); } } @@ -1079,7 +1082,7 @@ static void FixStatePointersAgain (FActorInfo *actor, AActor *defaults, TArrayClass, (char *)realstates[i].NextState); + realstates[i].NextState = ResolveGotoLabel (sc, defaults, bag.Info->Class, (char *)realstates[i].NextState); } } } @@ -1130,7 +1133,7 @@ int FinishStates (FActorInfo *actor, AActor *defaults, Baggage &bag) StateArray.Clear (); // Fix state pointers that are gotos - FixStatePointersAgain (actor, defaults, StateLabels); + FixStatePointersAgain (sc, actor, defaults, StateLabels); return count; } @@ -1142,35 +1145,35 @@ int FinishStates (FActorInfo *actor, AActor *defaults, Baggage &bag) // This is strictly for keeping compatibility with old WADs! // //========================================================================== -FState *CheckState(PClass *type) +FState *CheckState(FScanner &sc, PClass *type) { int v=0; - if (SC_GetString() && !sc_Crossed) + if (sc.GetString() && !sc.Crossed) { - if (SC_Compare("0")) return NULL; - else if (SC_Compare("PARENT")) + if (sc.Compare("0")) return NULL; + else if (sc.Compare("PARENT")) { FState * state = NULL; - SC_MustGetString(); + sc.MustGetString(); FActorInfo * info = type->ParentClass->ActorInfo; if (info != NULL) { - state = info->FindState(FName(sc_String)); + state = info->FindState(FName(sc.String)); } - if (SC_GetString ()) + if (sc.GetString ()) { - if (SC_Compare ("+")) + if (sc.Compare ("+")) { - SC_MustGetNumber (); - v = sc_Number; + sc.MustGetNumber (); + v = sc.Number; } else { - SC_UnGet (); + sc.UnGet (); } } @@ -1178,13 +1181,13 @@ FState *CheckState(PClass *type) if (v!=0 && state==NULL) { - SC_ScriptError("Attempt to get invalid state from actor %s\n", type->ParentClass->TypeName.GetChars()); + sc.ScriptError("Attempt to get invalid state from actor %s\n", type->ParentClass->TypeName.GetChars()); return NULL; } state+=v; return state; } - else SC_ScriptError("Invalid state assignment"); + else sc.ScriptError("Invalid state assignment"); } return NULL; } diff --git a/src/v_draw.cpp b/src/v_draw.cpp index c7f9e1de4d..ea2d429ce3 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -67,7 +67,6 @@ void STACK_ARGS DCanvas::DrawTextureV(FTexture *img, int x, int y, uint32 tag, v { FTexture::Span unmaskedSpan[2]; const FTexture::Span **spanptr, *spans; - static BYTE identitymap[256]; static short bottomclipper[MAXWIDTH], topclipper[MAXWIDTH]; DrawParms parms; @@ -86,32 +85,38 @@ void STACK_ARGS DCanvas::DrawTextureV(FTexture *img, int x, int y, uint32 tag, v spanptr = NULL; } - fixedcolormap = identitymap; - ESPSResult mode = R_SetPatchStyle (parms.style, parms.alpha, 0, parms.fillcolor); - if (APART(parms.colorOverlay) != 0) { - // In software, DTA_ColorOverlay only does black overlays. - // Maybe I will change this later, but right now white is the only - // color that is actually used for this parameter. - // Note that this is also overriding DTA_Translation in software. - if ((parms.colorOverlay & MAKEARGB(0,255,255,255)) == 0) + // The software renderer cannot invert the source without inverting the overlay + // too. That means if the source is inverted, we need to do the reverse of what + // the invert overlay flag says to do. + INTBOOL invertoverlay = (parms.style.Flags & STYLEF_InvertOverlay); + + if (parms.style.Flags & STYLEF_InvertSource) { - parms.translation = &NormalLight.Maps[(APART(parms.colorOverlay)*NUMCOLORMAPS/255)*256]; + invertoverlay = !invertoverlay; } + if (invertoverlay) + { + parms.colorOverlay = PalEntry(parms.colorOverlay).InverseColor(); + } + // Note that this overrides DTA_Translation in software, but not in hardware. + FDynamicColormap *colormap = GetSpecialLights(MAKERGB(255,255,255), + parms.colorOverlay & MAKEARGB(0,255,255,255), 0); + parms.translation = &colormap->Maps[(APART(parms.colorOverlay)*NUMCOLORMAPS/255)*256]; } - if (parms.style != STYLE_Shaded) + if (parms.translation != NULL) { - if (parms.translation != NULL) - { - dc_colormap = (lighttable_t *)parms.translation; - } - else - { - dc_colormap = identitymap; - } + dc_colormap = (lighttable_t *)parms.translation; } + else + { + dc_colormap = identitymap; + } + + fixedcolormap = dc_colormap; + ESPSResult mode = R_SetPatchStyle (parms.style, parms.alpha, 0, parms.fillcolor); BYTE *destorgsave = dc_destorg; dc_destorg = screen->GetBuffer(); @@ -155,13 +160,6 @@ void STACK_ARGS DCanvas::DrawTextureV(FTexture *img, int x, int y, uint32 tag, v if (bottomclipper[0] != parms.dclip) { clearbufshort (bottomclipper, screen->GetWidth(), (short)parms.dclip); - if (identitymap[1] != 1) - { - for (int i = 0; i < 256; ++i) - { - identitymap[i] = i; - } - } } if (parms.uclip != 0) { @@ -299,7 +297,7 @@ bool DCanvas::ParseDrawTextureTags (FTexture *img, int x, int y, DWORD tag, va_l parms->virtWidth = this->GetWidth(); parms->virtHeight = this->GetHeight(); parms->keepratio = false; - parms->style = STYLE_Count; + parms->style.BlendOp = 255; // Dummy "not set" value parms->masked = true; parms->bilinear = false; @@ -601,7 +599,7 @@ bool DCanvas::ParseDrawTextureTags (FTexture *img, int x, int y, DWORD tag, va_l parms->translation = parms->remap->Remap; } - if (parms->style == STYLE_Count) + if (parms->style.BlendOp == 255) { if (parms->fillcolor != -1) { diff --git a/src/v_font.cpp b/src/v_font.cpp index 9ae1bf3d2b..5f2780eb3b 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -32,6 +32,45 @@ ** */ +/* Special file formats handled here: + +FON1 "console" fonts have the following header: + char Magic[4]; -- The characters "FON1" + uword CharWidth; -- Character cell width + uword CharHeight; -- Character cell height + +The FON1 header is followed by RLE character data for all 256 +8-bit ASCII characters. + + +FON2 "standard" fonts have the following header: + char Magic[4]; -- The characters "FON2" + uword FontHeight; -- Every character in a font has the same height + ubyte FirstChar; -- First character defined by this font. + ubyte LastChar; -- Last character definde by this font. + ubyte bConstantWidth; + ubyte ShadingType; + ubyte PaletteSize; -- size of palette in entries (not bytes!) + ubyte Flags; + +There is presently only one flag for FON2: + FOF_WHOLEFONTKERNING 1 -- The Kerning field is present in the file + +The FON2 header is followed by variable length data: + word Kerning; + -- only present if FOF_WHOLEFONTKERNING is set + + ubyte Palette[PaletteSize+1][3]; + -- The last entry is the delimiter color. The delimiter is not used + -- by the font but is used my imagetool when converting the font + -- back to an image. Color 0 is the transparent color and is also + -- used only for converting the font back to an image. The other + -- entries are all presorted in increasing order of brightness. + + ubyte CharacterData[...]; + -- RLE character data, in order +*/ + // HEADER FILES ------------------------------------------------------------ #include @@ -171,7 +210,7 @@ static TArray TranslationColors; // CODE -------------------------------------------------------------------- -FFont * V_GetFont(const char *name) +FFont *V_GetFont(const char *name) { FFont *font = FFont::FindFont (name); if (font == NULL) @@ -210,7 +249,7 @@ FFont * V_GetFont(const char *name) } if (picnum > 0) { - font = new FSingleLumpFont (name, -1); + font = new FSinglePicFont (name); } } } @@ -334,7 +373,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count, { SpaceWidth = 4; } - BuildTranslations (luminosity, identity, &TranslationParms[0][0], ActiveColors); + BuildTranslations (luminosity, identity, &TranslationParms[0][0], ActiveColors, NULL); delete[] luminosity; delete[] charlumps; @@ -538,12 +577,13 @@ int FFont::SimpleTranslation (BYTE *colorsused, BYTE *translation, BYTE *reverse // large this array is. Identity is an array that remaps the colors to // their original values; it is only used for CR_UNTRANSLATED. Ranges // is an array of TranslationParm structs defining the ranges for every -// possible color, in order. +// possible color, in order. Palette is the colors to use for the +// untranslated version of the font. // //========================================================================== void FFont::BuildTranslations (const double *luminosity, const BYTE *identity, - const void *ranges, int total_colors) + const void *ranges, int total_colors, const PalEntry *palette) { int i, j; const TranslationParm *parmstart = (const TranslationParm *)ranges; @@ -559,9 +599,17 @@ void FFont::BuildTranslations (const double *luminosity, const BYTE *identity, if (identity != NULL) { memcpy (remap.Remap, identity, ActiveColors); - for (j = 0; j < ActiveColors; ++j) + if (palette != NULL) { - remap.Palette[j] = GPalette.BaseColors[identity[j]]; + memcpy (remap.Palette, palette, ActiveColors*sizeof(PalEntry)); + } + else + { + remap.Palette[0] = GPalette.BaseColors[identity[0]] & MAKEARGB(0,255,255,255); + for (j = 1; j < ActiveColors; ++j) + { + remap.Palette[j] = GPalette.BaseColors[identity[j]] | MAKEARGB(255,0,0,0); + } } } else @@ -712,52 +760,35 @@ FFont::FFont () // // FSingleLumpFont :: FSingleLumpFont // -// Loads a FON1 or FON2 font resource or a single texture. +// Loads a FON1 or FON2 font resource. // //========================================================================== FSingleLumpFont::FSingleLumpFont (const char *name, int lump) { + assert(lump >= 0); + Name = copystring (name); - // If lump is -1, then the font name is really a texture name, so - // the font should be a redirect to the texture. - // If lump is >= 0, then the font is really a font. - if (lump < 0) - { - int picnum = TexMan.CheckForTexture (name, FTexture::TEX_Any); + FMemLump data1 = Wads.ReadLump (lump); + const BYTE *data = (const BYTE *)data1.GetMem(); - if (picnum > 0) - { - CreateFontFromPic (picnum); - } - else - { - I_FatalError ("%s is not a font or texture", name); - } + if (data[0] != 'F' || data[1] != 'O' || data[2] != 'N' || + (data[3] != '1' && data[3] != '2')) + { + I_FatalError ("%s is not a recognizable font", name); } else { - FMemLump data1 = Wads.ReadLump (lump); - const BYTE *data = (const BYTE *)data1.GetMem(); - - if (data[0] != 'F' || data[1] != 'O' || data[2] != 'N' || - (data[3] != '1' && data[3] != '2')) + switch (data[3]) { - I_FatalError ("%s is not a recognizable font", name); - } - else - { - switch (data[3]) - { - case '1': - LoadFON1 (lump, data); - break; + case '1': + LoadFON1 (lump, data); + break; - case '2': - LoadFON2 (lump, data); - break; - } + case '2': + LoadFON2 (lump, data); + break; } } @@ -813,7 +844,7 @@ void FSingleLumpFont::LoadFON1 (int lump, const BYTE *data) PatchRemap = new BYTE[256]; CheckFON1Chars (lump, data, luminosity); - BuildTranslations (luminosity, NULL, &TranslationParms[1][0], ActiveColors); + BuildTranslations (luminosity, NULL, &TranslationParms[1][0], ActiveColors, NULL); } //========================================================================== @@ -831,6 +862,7 @@ void FSingleLumpFont::LoadFON2 (int lump, const BYTE *data) int *widths2; BYTE identity[256]; double luminosity[256]; + PalEntry local_palette[256]; WORD *widths; const BYTE *palette; const BYTE *data_p; @@ -844,19 +876,19 @@ void FSingleLumpFont::LoadFON2 (int lump, const BYTE *data) Chars = new CharData[count]; widths2 = new int[count]; if (data[11] & 1) - { + { // Font specifies a kerning value. GlobalKerning = LittleShort(*(SWORD *)&data[12]); widths = (WORD *)(data + 14); } else - { + { // Font does not specify a kerning value. GlobalKerning = 0; widths = (WORD *)(data + 12); } totalwidth = 0; if (data[8]) - { + { // Font is mono-spaced. totalwidth = LittleShort(widths[0]); for (i = 0; i < count; ++i) { @@ -866,7 +898,7 @@ void FSingleLumpFont::LoadFON2 (int lump, const BYTE *data) palette = (BYTE *)&widths[1]; } else - { + { // Font has varying character widths. for (i = 0; i < count; ++i) { widths2[i] = LittleShort(widths[i]); @@ -888,7 +920,7 @@ void FSingleLumpFont::LoadFON2 (int lump, const BYTE *data) SpaceWidth = totalwidth * 2 / (3 * count); } - FixupPalette (identity, luminosity, palette, data[9] == 0); + FixupPalette (identity, luminosity, palette, data[9] == 0, local_palette); data_p = palette + (ActiveColors+1)*3; @@ -924,7 +956,7 @@ void FSingleLumpFont::LoadFON2 (int lump, const BYTE *data) } } - BuildTranslations (luminosity, identity, &TranslationParms[0][0], ActiveColors); + BuildTranslations (luminosity, identity, &TranslationParms[0][0], ActiveColors, local_palette); delete[] widths2; } @@ -999,7 +1031,7 @@ void FSingleLumpFont::CheckFON1Chars (int lump, const BYTE *data, double *lumino // //========================================================================== -void FSingleLumpFont::FixupPalette (BYTE *identity, double *luminosity, const BYTE *palette, bool rescale) +void FSingleLumpFont::FixupPalette (BYTE *identity, double *luminosity, const BYTE *palette, bool rescale, PalEntry *out_palette) { int i; double maxlum = 0.0; @@ -1009,20 +1041,24 @@ void FSingleLumpFont::FixupPalette (BYTE *identity, double *luminosity, const BY identity[0] = 0; palette += 3; // Skip the transparent color - for (i = 1; i <= ActiveColors; ++i) + for (i = 1; i <= ActiveColors; ++i, palette += 3) { int r = palette[0]; int g = palette[1]; int b = palette[2]; double lum = r*0.299 + g*0.587 + b*0.114; - palette += 3; identity[i] = ColorMatcher.Pick (r, g, b); luminosity[i] = lum; + out_palette[i].r = r; + out_palette[i].g = g; + out_palette[i].b = b; + out_palette[i].a = 255; if (lum > maxlum) maxlum = lum; if (lum < minlum) minlum = lum; } + out_palette[0] = 0; if (rescale) { @@ -1038,6 +1074,74 @@ void FSingleLumpFont::FixupPalette (BYTE *identity, double *luminosity, const BY } } +//========================================================================== +// +// FSinglePicFont :: FSinglePicFont +// +// Creates a font to wrap a texture so that you can use hudmessage as if it +// were a hudpic command. It does not support translation, but animation +// is supported, unlike all the real fonts. +// +//========================================================================== + +FSinglePicFont::FSinglePicFont(const char *picname) +{ + int picnum = TexMan.CheckForTexture (picname, FTexture::TEX_Any); + + if (picnum <= 0) + { + I_FatalError ("%s is not a font or texture", picname); + } + + FTexture *pic = TexMan[picnum]; + + Name = copystring(picname); + FontHeight = pic->GetHeight(); + SpaceWidth = pic->GetWidth(); + GlobalKerning = 0; + FirstChar = LastChar = 'A'; + ActiveColors = 0; + PicNum = picnum; + + Next = FirstFont; + FirstFont = this; +} + +//========================================================================== +// +// FSinglePicFont :: GetChar +// +// Returns the texture if code is 'a' or 'A', otherwise NULL. +// +//========================================================================== + +FTexture *FSinglePicFont::GetChar (int code, int *const width) const +{ + *width = SpaceWidth; + if (code == 'a' || code == 'A') + { + return TexMan(PicNum); + } + else + { + return NULL; + } +} + +//========================================================================== +// +// FSinglePicFont :: GetCharWidth +// +// Don't expect the text functions to work properly if I actually allowed +// the character width to vary depending on the animation frame. +// +//========================================================================== + +int FSinglePicFont::GetCharWidth (int code) const +{ + return SpaceWidth; +} + //========================================================================== // // FFontChar1 :: FFontChar1 @@ -1438,7 +1542,7 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, int *lumplis SpaceWidth = 4; } - BuildTranslations (luminosity, identity, &TranslationParms[0][0], TotalColors); + BuildTranslations (luminosity, identity, &TranslationParms[0][0], TotalColors, NULL); // add the untranslated colors to the Ranges tables if (ActiveColors < TotalColors) @@ -1470,6 +1574,7 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, int *lumplis void V_InitCustomFonts() { + FScanner sc; int lumplist[256]; bool notranslate[256]; char namebuffer[16], templatebuf[16]; @@ -1482,75 +1587,75 @@ void V_InitCustomFonts() while ((llump = Wads.FindLump ("FONTDEFS", &lastlump)) != -1) { - SC_OpenLumpNum (llump, "FONTDEFS"); - while (SC_GetString()) + sc.OpenLumpNum(llump, "FONTDEFS"); + while (sc.GetString()) { memset (lumplist, -1, sizeof(lumplist)); memset (notranslate, 0, sizeof(notranslate)); - strncpy (namebuffer, sc_String, 15); + strncpy (namebuffer, sc.String, 15); namebuffer[15] = 0; format = 0; start = 33; first = 33; count = 223; - SC_MustGetStringName ("{"); - while (!SC_CheckString ("}")) + sc.MustGetStringName ("{"); + while (!sc.CheckString ("}")) { - SC_MustGetString(); - if (SC_Compare ("TEMPLATE")) + sc.MustGetString(); + if (sc.Compare ("TEMPLATE")) { if (format == 2) goto wrong; - SC_MustGetString(); - strncpy (templatebuf, sc_String, 16); + sc.MustGetString(); + strncpy (templatebuf, sc.String, 16); templatebuf[15] = 0; format = 1; } - else if (SC_Compare ("BASE")) + else if (sc.Compare ("BASE")) { if (format == 2) goto wrong; - SC_MustGetNumber(); - start = sc_Number; + sc.MustGetNumber(); + start = sc.Number; format = 1; } - else if (SC_Compare ("FIRST")) + else if (sc.Compare ("FIRST")) { if (format == 2) goto wrong; - SC_MustGetNumber(); - first = sc_Number; + sc.MustGetNumber(); + first = sc.Number; format = 1; } - else if (SC_Compare ("COUNT")) + else if (sc.Compare ("COUNT")) { if (format == 2) goto wrong; - SC_MustGetNumber(); - count = sc_Number; + sc.MustGetNumber(); + count = sc.Number; format = 1; } - else if (SC_Compare ("NOTRANSLATION")) + else if (sc.Compare ("NOTRANSLATION")) { if (format == 1) goto wrong; - while (SC_CheckNumber() && !sc_Crossed) + while (sc.CheckNumber() && !sc.Crossed) { - if (sc_Number >= 0 && sc_Number < 256) - notranslate[sc_Number] = true; + if (sc.Number >= 0 && sc.Number < 256) + notranslate[sc.Number] = true; } format=2; } else { if (format == 1) goto wrong; - int *p = &lumplist[*(unsigned char*)sc_String]; - SC_MustGetString(); - *p = Wads.CheckNumForName (sc_String); + int *p = &lumplist[*(unsigned char*)sc.String]; + sc.MustGetString(); + *p = Wads.CheckNumForName (sc.String); format=2; } } - if (format==1) + if (format == 1) { new FFont (namebuffer, templatebuf, first, count, start); } - else if (format==2) + else if (format == 2) { for (i = 0; i < 256; i++) { @@ -1575,12 +1680,12 @@ void V_InitCustomFonts() } else goto wrong; } - SC_Close (); + sc.Close(); } return; wrong: - SC_ScriptError ("Invalid combination of properties in font '%s'", namebuffer); + sc.ScriptError ("Invalid combination of properties in font '%s'", namebuffer); } //========================================================================== @@ -1610,8 +1715,8 @@ void V_InitFontColors () while ((lump = Wads.FindLump ("TEXTCOLO", &lastlump)) != -1) { - SC_OpenLumpNum (lump, "textcolors.txt"); - while (SC_GetString()) + FScanner sc(lump, "textcolors.txt"); + while (sc.GetString()) { names.Clear(); @@ -1619,14 +1724,14 @@ void V_InitFontColors () // Everything until the '{' is considered a valid name for the // color range. - names.Push (sc_String); - while (SC_MustGetString(), !SC_Compare ("{")) + names.Push (sc.String); + while (sc.MustGetString(), !sc.Compare ("{")) { if (names[0] == NAME_Untranslated) { - SC_ScriptError ("The \"untranslated\" color may not have any other names"); + sc.ScriptError ("The \"untranslated\" color may not have any other names"); } - names.Push (sc_String); + names.Push (sc.String); } parmchoice = 0; @@ -1635,66 +1740,66 @@ void V_InitFontColors () info.ParmLen[1] = info.ParmLen[0] = 0; tparm.RangeEnd = tparm.RangeStart = -1; - while (SC_MustGetString(), !SC_Compare ("}")) + while (sc.MustGetString(), !sc.Compare ("}")) { - if (SC_Compare ("Console:")) + if (sc.Compare ("Console:")) { if (parmchoice == 1) { - SC_ScriptError ("Each color may only have one set of console ranges"); + sc.ScriptError ("Each color may only have one set of console ranges"); } parmchoice = 1; info.StartParm[1] = parms.Size(); info.ParmLen[0] = info.StartParm[1] - info.StartParm[0]; tparm.RangeEnd = tparm.RangeStart = -1; } - else if (SC_Compare ("Flat:")) + else if (sc.Compare ("Flat:")) { - SC_MustGetString(); - logcolor = V_GetColor (NULL, sc_String); + sc.MustGetString(); + logcolor = V_GetColor (NULL, sc.String); } else { // Get first color - c = V_GetColor (NULL, sc_String); + c = V_GetColor (NULL, sc.String); tparm.Start[0] = RPART(c); tparm.Start[1] = GPART(c); tparm.Start[2] = BPART(c); // Get second color - SC_MustGetString(); - c = V_GetColor (NULL, sc_String); + sc.MustGetString(); + c = V_GetColor (NULL, sc.String); tparm.End[0] = RPART(c); tparm.End[1] = GPART(c); tparm.End[2] = BPART(c); // Check for range specifier - if (SC_CheckNumber()) + if (sc.CheckNumber()) { - if (tparm.RangeStart == -1 && sc_Number != 0) + if (tparm.RangeStart == -1 && sc.Number != 0) { - SC_ScriptError ("The first color range must start at position 0"); + sc.ScriptError ("The first color range must start at position 0"); } - if (sc_Number < 0 || sc_Number > 256) + if (sc.Number < 0 || sc.Number > 256) { - SC_ScriptError ("The color range must be within positions [0,256]"); + sc.ScriptError ("The color range must be within positions [0,256]"); } - if (sc_Number <= tparm.RangeEnd) + if (sc.Number <= tparm.RangeEnd) { - SC_ScriptError ("The color range must not start before the previous one ends"); + sc.ScriptError ("The color range must not start before the previous one ends"); } - tparm.RangeStart = sc_Number; + tparm.RangeStart = sc.Number; - SC_MustGetNumber(); - if (sc_Number < 0 || sc_Number > 256) + sc.MustGetNumber(); + if (sc.Number < 0 || sc.Number > 256) { - SC_ScriptError ("The color range must be within positions [0,256]"); + sc.ScriptError ("The color range must be within positions [0,256]"); } - if (sc_Number <= tparm.RangeStart) + if (sc.Number <= tparm.RangeStart) { - SC_ScriptError ("The color range end position must be larger than the start position"); + sc.ScriptError ("The color range end position must be larger than the start position"); } - tparm.RangeEnd = sc_Number; + tparm.RangeEnd = sc.Number; } else { @@ -1702,7 +1807,7 @@ void V_InitFontColors () tparm.RangeEnd = 256; if (tparm.RangeStart >= tparm.RangeEnd) { - SC_ScriptError ("The color has too many ranges"); + sc.ScriptError ("The color has too many ranges"); } } parms.Push (tparm); @@ -1713,14 +1818,14 @@ void V_InitFontColors () { if (names[0] != NAME_Untranslated) { - SC_ScriptError ("There must be at least one normal range for a color"); + sc.ScriptError ("There must be at least one normal range for a color"); } } else { if (names[0] == NAME_Untranslated) { - SC_ScriptError ("The \"untranslated\" color must be left undefined"); + sc.ScriptError ("The \"untranslated\" color must be left undefined"); } } if (info.ParmLen[1] == 0 && names[0] != NAME_Untranslated) @@ -1755,7 +1860,6 @@ void V_InitFontColors () } } } - SC_Close (); } // Make permananent copies of all the color information we found. for (i = 0, index = 0; i < colorinfo.Size(); ++i) diff --git a/src/v_font.h b/src/v_font.h index ee9a137124..8a383658e1 100644 --- a/src/v_font.h +++ b/src/v_font.h @@ -85,8 +85,8 @@ public: FFont (const char *fontname, const char *nametemplate, int first, int count, int base); ~FFont (); - FTexture *GetChar (int code, int *const width) const; - int GetCharWidth (int code) const; + virtual FTexture *GetChar (int code, int *const width) const; + virtual int GetCharWidth (int code) const; FRemapTable *GetColorTranslation (EColorRange range) const; int GetSpaceWidth () const { return SpaceWidth; } int GetHeight () const { return FontHeight; } @@ -101,9 +101,11 @@ public: protected: FFont (); - void BuildTranslations (const double *luminosity, const BYTE *identity, const void *ranges, int total_colors); + void BuildTranslations (const double *luminosity, const BYTE *identity, + const void *ranges, int total_colors, const PalEntry *palette); - static int SimpleTranslation (BYTE *colorsused, BYTE *translation, BYTE *identity, double **luminosity); + static int SimpleTranslation (BYTE *colorsused, BYTE *translation, + BYTE *identity, double **luminosity); int FirstChar, LastChar; int SpaceWidth; @@ -141,12 +143,26 @@ public: protected: void CheckFON1Chars (int lump, const BYTE *data, double *luminosity); void BuildTranslations2 (); - void FixupPalette (BYTE *identity, double *luminosity, const BYTE *palette, bool rescale); + void FixupPalette (BYTE *identity, double *luminosity, const BYTE *palette, + bool rescale, PalEntry *out_palette); void LoadFON1 (int lump, const BYTE *data); void LoadFON2 (int lump, const BYTE *data); void CreateFontFromPic (int picnum); }; +class FSinglePicFont : public FFont +{ +public: + FSinglePicFont(const char *picname); + + // FFont interface + FTexture *GetChar (int code, int *const width) const; + int GetCharWidth (int code) const; + +protected: + int PicNum; +}; + void RecordTextureColors (FTexture *pic, BYTE *colorsused); extern FFont *SmallFont, *SmallFont2, *BigFont, *ConFont; diff --git a/src/v_palette.cpp b/src/v_palette.cpp index 02614063bb..b315031527 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -59,11 +59,11 @@ extern "C" { FDynamicColormap NormalLight; } FPalette GPalette; -BYTE InverseColormap[NUMCOLORMAPS*256]; -BYTE GoldColormap[NUMCOLORMAPS*256]; +BYTE InverseColormap[256]; +BYTE GoldColormap[256]; // [BC] New Skulltag colormaps. -BYTE RedColormap[NUMCOLORMAPS*256]; -BYTE GreenColormap[NUMCOLORMAPS*256]; +BYTE RedColormap[256]; +BYTE GreenColormap[256]; int Near255; static void FreeSpecialLights();; @@ -386,7 +386,7 @@ void InitPalette () // build special maps (e.g. invulnerability) int intensity; - // Doom invulnerability is an inverted grayscale + // Doom invulnerability is an inverted grayscale. // Strife uses it when firing the Sigil shade = InverseColormap; @@ -396,10 +396,10 @@ void InitPalette () (GPalette.BaseColors[c].r * 77 + GPalette.BaseColors[c].g * 143 + GPalette.BaseColors[c].b * 37)) >> 8; - *shade++ = ColorMatcher.Pick (intensity, intensity, intensity); + shade[c] = ColorMatcher.Pick (intensity, intensity, intensity); } - // Heretic invulnerability is a golden shade + // Heretic invulnerability is a golden shade. shade = GoldColormap; for (c = 0; c < 256; c++) @@ -407,7 +407,7 @@ void InitPalette () intensity = GPalette.BaseColors[c].r * 77 + GPalette.BaseColors[c].g * 143 + GPalette.BaseColors[c].b * 37; - *shade++ = ColorMatcher.Pick ( + shade[c] = ColorMatcher.Pick ( MIN (255, (intensity+intensity/2)>>8), intensity>>8, 0); } @@ -418,7 +418,7 @@ void InitPalette () intensity = ((GPalette.BaseColors[c].r * 77 + GPalette.BaseColors[c].g * 143 + GPalette.BaseColors[c].b * 37)); - *shade++ = ColorMatcher.Pick ( + shade[c] = ColorMatcher.Pick ( MIN( 255, ( intensity + ( intensity / 2 )) >> 8 ), 0, 0 ); } @@ -429,8 +429,10 @@ void InitPalette () intensity = GPalette.BaseColors[c].r * 77 + GPalette.BaseColors[c].g * 143 + GPalette.BaseColors[c].b * 37; - *shade++ = ColorMatcher.Pick ( - MIN( 255, ( intensity + ( intensity / 2 )) >> 8 ), MIN( 255, ( intensity + ( intensity / 2 )) >> 8 ), intensity>>8 ); + shade[c] = ColorMatcher.Pick ( + MIN( 255, ( intensity + ( intensity / 2 )) >> 8 ), + MIN( 255, ( intensity + ( intensity / 2 )) >> 8 ), + intensity>>8 ); } } @@ -743,7 +745,7 @@ void FDynamicColormap::BuildLights () } } else - { // Colored light, so do the slower thing + { // Colored light, so do the (slightly) slower thing for (c = 0; c < 256; c++) { *shade++ = ColorMatcher.Pick ( diff --git a/src/v_palette.h b/src/v_palette.h index 0ea60dd156..179f6fc29c 100644 --- a/src/v_palette.h +++ b/src/v_palette.h @@ -80,11 +80,11 @@ struct FDynamicColormap FDynamicColormap *Next; }; -extern BYTE InverseColormap[NUMCOLORMAPS*256]; -extern BYTE GoldColormap[NUMCOLORMAPS*256]; +extern BYTE InverseColormap[256]; +extern BYTE GoldColormap[256]; // [BC] New Skulltag colormaps. -extern BYTE RedColormap[NUMCOLORMAPS*256]; -extern BYTE GreenColormap[NUMCOLORMAPS*256]; +extern BYTE RedColormap[256]; +extern BYTE GreenColormap[256]; extern FPalette GPalette; extern "C" { extern FDynamicColormap NormalLight; diff --git a/src/v_video.cpp b/src/v_video.cpp index e071c1edd1..f3ddc79ea5 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -132,8 +132,9 @@ int DisplayWidth, DisplayHeight, DisplayBits; FFont *SmallFont, *SmallFont2, *BigFont, *ConFont; extern "C" { -DWORD *Col2RGB8_LessPrecision[65]; DWORD Col2RGB8[65][256]; +DWORD *Col2RGB8_LessPrecision[65]; +DWORD Col2RGB8_Inverse[65][256]; BYTE RGB32k[32][32][32]; } @@ -682,6 +683,15 @@ static void BuildTransTable (const PalEntry *palette) } Col2RGB8_LessPrecision[0] = Col2RGB8[0]; Col2RGB8_LessPrecision[64] = Col2RGB8[64]; + + // create the inverse swizzled palette + for (x = 0; x < 65; x++) + for (y = 0; y < 256; y++) + { + Col2RGB8_Inverse[x][y] = (((((255-palette[y].r)*x)>>4)<<20) | + (((255-palette[y].g)*x)>>4) | + ((((255-palette[y].b)*x)>>4)<<10)) & 0x3feffbff; + } } //========================================================================== diff --git a/src/v_video.h b/src/v_video.h index aa0198142c..efa0cf7587 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -239,7 +239,7 @@ protected: INTBOOL keepratio; INTBOOL masked; INTBOOL bilinear; - ERenderStyle style; + FRenderStyle style; }; bool ClipBox (int &left, int &top, int &width, int &height, const BYTE *&src, const int srcpitch) const; @@ -411,10 +411,35 @@ extern DFrameBuffer *screen; EXTERN_CVAR (Float, Gamma) // Translucency tables -extern "C" DWORD Col2RGB8[65][256]; + +// RGB32k is a normal R5G5B5 -> palette lookup table. extern "C" BYTE RGB32k[32][32][32]; + +// Col2RGB8 is a pre-multiplied palette for color lookup. It is stored in a +// special R10B10G10 format for efficient blending computation. +// --RRRRRrrr--BBBBBbbb--GGGGGggg-- at level 64 +// --------rrrr------bbbb------gggg at level 1 +extern "C" DWORD Col2RGB8[65][256]; + +// Col2RGB8_LessPrecision is the same as Col2RGB8, but the LSB for red +// and blue are forced to zero, so if the blend overflows, it won't spill +// over into the next component's value. +// --RRRRRrrr-#BBBBBbbb-#GGGGGggg-- at level 64 +// --------rrr#------bbb#------gggg at level 1 extern "C" DWORD *Col2RGB8_LessPrecision[65]; +// Col2RGB8_Inverse is the same as Col2RGB8_LessPrecision, except the source +// palette has been inverted. +extern "C" DWORD Col2RGB8_Inverse[65][256]; + +// "Magic" numbers used during the blending: +// --000001111100000111110000011111 = 0x01f07c1f +// -0111111111011111111101111111111 = 0x3FEFFBFF +// -1000000000100000000010000000000 = 0x40100400 +// ------10000000001000000000100000 = 0x40100400 >> 5 +// --11111-----11111-----11111----- = 0x40100400 - (0x40100400 >> 5) aka "white" +// --111111111111111111111111111111 = 0x3FFFFFFF + // Allocates buffer screens, call before R_Init. void V_Init (); diff --git a/src/w_wad.h b/src/w_wad.h index 4ae10e6e38..cab55d7b3a 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -134,6 +134,7 @@ public: ~FMemLump (); void *GetMem () { return Block.Len() == 0 ? NULL : (void *)Block.GetChars(); } size_t GetSize () { return Block.Len(); } + FString GetString () { return Block; } private: FMemLump (const FString &source); diff --git a/src/wi_stuff.cpp b/src/wi_stuff.cpp index 8538c423a7..50fb1f5414 100644 --- a/src/wi_stuff.cpp +++ b/src/wi_stuff.cpp @@ -386,7 +386,7 @@ void WI_LoadBackground(bool isenterpic) lnodes.Clear(); anims.Clear(); yah.Clear(); - splat=NULL; + splat = NULL; // a name with a starting '$' indicates an intermission script if (*lumpname!='$') @@ -400,154 +400,154 @@ void WI_LoadBackground(bool isenterpic) int lumpnum=Wads.GetNumForName(lumpname+1); if (lumpnum>=0) { - SC_OpenLumpNum(lumpnum,lumpname+1); - while (SC_GetString()) + FScanner sc(lumpnum,lumpname+1); + while (sc.GetString()) { memset(&an,0,sizeof(an)); - int caseval=SC_MustMatchString(WI_Cmd); + int caseval = sc.MustMatchString(WI_Cmd); switch(caseval) { case 0: // Background - SC_MustGetString(); - texture=TexMan.CheckForTexture(sc_String, FTexture::TEX_MiscPatch,FTextureManager::TEXMAN_TryAny); - if (texture == -1) texture = TexMan.AddPatch(sc_String); + sc.MustGetString(); + texture=TexMan.CheckForTexture(sc.String, FTexture::TEX_MiscPatch,FTextureManager::TEXMAN_TryAny); + if (texture == -1) texture = TexMan.AddPatch(sc.String); break; case 1: // Splat - SC_MustGetString(); - splat=TexMan[TexMan.AddPatch(sc_String)]; + sc.MustGetString(); + splat=TexMan[TexMan.AddPatch(sc.String)]; break; case 2: // Pointers - while (SC_GetString() && !sc_Crossed) + while (sc.GetString() && !sc.Crossed) { - int v=TexMan.AddPatch(sc_String); + int v = TexMan.AddPatch(sc.String); yah.Push(TexMan[v]); } - if (sc_Crossed) SC_UnGet(); + if (sc.Crossed) sc.UnGet(); break; case 3: // Spots - SC_MustGetStringName("{"); - while (!SC_CheckString("}")) + sc.MustGetStringName("{"); + while (!sc.CheckString("}")) { - SC_MustGetString(); - strncpy(pt.level, sc_String,8); - pt.level[8]=0; - SC_MustGetNumber(); - pt.x=sc_Number; - SC_MustGetNumber(); - pt.y=sc_Number; + sc.MustGetString(); + strncpy(pt.level, sc.String,8); + pt.level[8] = 0; + sc.MustGetNumber(); + pt.x = sc.Number; + sc.MustGetNumber(); + pt.y = sc.Number; lnodes.Push(pt); } break; case 4: // IfEntering - an.type=ANIM_IFENTERING; + an.type = ANIM_IFENTERING; goto readanimation; case 5: // IfEntering - an.type=ANIM_IFNOTENTERING; + an.type = ANIM_IFNOTENTERING; goto readanimation; case 6: // IfVisited - an.type=ANIM_IFVISITED; + an.type = ANIM_IFVISITED; goto readanimation; case 7: // IfNotVisited - an.type=ANIM_IFNOTVISITED; + an.type = ANIM_IFNOTVISITED; goto readanimation; case 8: // IfLeaving - an.type=ANIM_IFLEAVING; + an.type = ANIM_IFLEAVING; goto readanimation; case 9: // IfNotLeaving - an.type=ANIM_IFNOTLEAVING; + an.type = ANIM_IFNOTLEAVING; goto readanimation; case 10: // IfTravelling - an.type=ANIM_IFTRAVELLING; - SC_MustGetString(); - strncpy(an.levelname2,sc_String,8); - an.levelname2[8]=0; + an.type = ANIM_IFTRAVELLING; + sc.MustGetString(); + strncpy(an.levelname2, sc.String, 8); + an.levelname2[8] = 0; goto readanimation; case 11: // IfNotTravelling - an.type=ANIM_IFTRAVELLING; - SC_MustGetString(); - strncpy(an.levelname2,sc_String,8); - an.levelname2[8]=0; + an.type = ANIM_IFTRAVELLING; + sc.MustGetString(); + strncpy(an.levelname2, sc.String, 8); + an.levelname2[8] = 0; goto readanimation; case 14: // NoAutostartMap - noautostartmap=true; + noautostartmap = true; break; readanimation: - SC_MustGetString(); - strncpy(an.levelname,sc_String,8); - an.levelname[8]=0; - SC_MustGetString(); - caseval=SC_MustMatchString(WI_Cmd); + sc.MustGetString(); + strncpy(an.levelname, sc.String, 8); + an.levelname[8] = 0; + sc.MustGetString(); + caseval=sc.MustMatchString(WI_Cmd); default: switch (caseval) { case 12: // Animation an.type |= ANIM_ALWAYS; - SC_MustGetNumber(); - an.loc.x=sc_Number; - SC_MustGetNumber(); - an.loc.y=sc_Number; - SC_MustGetNumber(); - an.period=sc_Number; - an.nexttic = 1 + (M_Random()%an.period); - if (SC_GetString()) + sc.MustGetNumber(); + an.loc.x = sc.Number; + sc.MustGetNumber(); + an.loc.y = sc.Number; + sc.MustGetNumber(); + an.period = sc.Number; + an.nexttic = 1 + (M_Random() % an.period); + if (sc.GetString()) { - if (SC_Compare("ONCE")) + if (sc.Compare("ONCE")) { - an.data=1; + an.data = 1; } else { - SC_UnGet(); + sc.UnGet(); } } - if (!SC_CheckString("{")) + if (!sc.CheckString("{")) { - SC_MustGetString(); - an.p[an.nanims++]=TexMan[TexMan.AddPatch(sc_String)]; + sc.MustGetString(); + an.p[an.nanims++] = TexMan[TexMan.AddPatch(sc.String)]; } else { - while (!SC_CheckString("}")) + while (!sc.CheckString("}")) { - SC_MustGetString(); - if (an.nanimsSetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); AlphaBlendEnabled = FALSE; + AlphaBlendOp = D3DBLENDOP_ADD; AlphaSrcBlend = D3DBLEND(0); AlphaDestBlend = D3DBLEND(0); @@ -332,15 +333,45 @@ void D3DFB::SetInitialState() Texture[0] = NULL; Texture[1] = NULL; - D3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); - D3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); - D3DDevice->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); - D3DDevice->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); + D3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + D3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); + D3DDevice->SetSamplerState(1, D3DSAMP_ADDRESSU, SM14 ? D3DTADDRESS_BORDER : D3DTADDRESS_CLAMP); + D3DDevice->SetSamplerState(1, D3DSAMP_ADDRESSV, SM14 ? D3DTADDRESS_BORDER : D3DTADDRESS_CLAMP); D3DDevice->SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, TRUE); - SetGamma (Gamma); + NeedGammaUpdate = true; + NeedPalUpdate = true; OldRenderTarget = NULL; + + if (!Windowed && SM14) + { + // Fix for Radeon 9000, possibly other R200s: When the device is + // reset, it resets the gamma ramp, but the driver apparently keeps a + // cached copy of the ramp that it doesn't update, so when + // SetGammaRamp is called later to handle the NeedGammaUpdate flag, + // it doesn't do anything, because the gamma ramp is the same as the + // one passed in the last call, even though the visible gamma ramp + // actually has changed. + // + // So here we force the gamma ramp to something absolutely horrible and + // trust that we will be able to properly set the gamma later when + // NeedGammaUpdate is handled. + D3DGAMMARAMP ramp; + memset(&ramp, 0, sizeof(ramp)); + D3DDevice->SetGammaRamp(0, 0, &ramp); + } + + // Used by the inverse color shaders + float ones[4] = { 1, 1, 1, 1 }; + D3DDevice->SetPixelShaderConstantF(6, ones, 1); + + // D3DRS_ALPHATESTENABLE defaults to FALSE + // D3DRS_ALPHAREF defaults to 0 + D3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL); + AlphaTestEnabled = FALSE; + + CurBorderColor = 0; } void D3DFB::FillPresentParameters (D3DPRESENT_PARAMETERS *pp, bool fullscreen, bool vsync) @@ -396,15 +427,21 @@ bool D3DFB::CreateResources () { return false; } + if (FAILED(D3DDevice->CreatePixelShader (InvPalTexShader20Def, &InvPalTexShader)) && + (SM14 = true, FAILED(D3DDevice->CreatePixelShader (InvPalTexShader14Def, &InvPalTexShader)))) + { + return false; + } if (FAILED(D3DDevice->CreatePixelShader (PlainShaderDef, &PlainShader)) || - FAILED(D3DDevice->CreatePixelShader (PlainStencilDef, &PlainStencilShader)) || + FAILED(D3DDevice->CreatePixelShader (InvPlainShaderDef, &InvPlainShader)) || + FAILED(D3DDevice->CreatePixelShader (RedToAlphaDef, &RedToAlphaShader)) || FAILED(D3DDevice->CreatePixelShader (ColorOnlyDef, &ColorOnlyShader))) { return false; } if (FAILED(D3DDevice->CreatePixelShader (GammaFixerDef, &GammaFixerShader))) { - Printf ("Windowed mode gamma will not work.\n"); +// Printf ("Using Shader Model 1.4: Windowed mode gamma will not work.\n"); GammaFixerShader = NULL; } if (FAILED(D3DDevice->CreatePixelShader(PalTexBilinearDef, &PalTexBilinearShader))) @@ -413,13 +450,10 @@ bool D3DFB::CreateResources () } if (FAILED(D3DDevice->CreatePixelShader (BurnShaderDef, &BurnShader))) { - Printf ("Burn screenwipe will not work in D3D mode.\n"); BurnShader = NULL; } if (!CreateFBTexture() || - !CreatePaletteTexture() || - !CreateStencilPaletteTexture() || - !CreateShadedPaletteTexture()) + !CreatePaletteTexture()) { return false; } @@ -439,8 +473,6 @@ void D3DFB::ReleaseResources () SAFE_RELEASE( ScreenshotSurface ); SAFE_RELEASE( ScreenshotTexture ); SAFE_RELEASE( PaletteTexture ); - SAFE_RELEASE( StencilPaletteTexture ); - SAFE_RELEASE( ShadedPaletteTexture ); if (PalTexBilinearShader != NULL) { if (PalTexBilinearShader != PalTexShader) @@ -450,8 +482,10 @@ void D3DFB::ReleaseResources () PalTexBilinearShader = NULL; } SAFE_RELEASE( PalTexShader ); + SAFE_RELEASE( InvPalTexShader ); SAFE_RELEASE( PlainShader ); - SAFE_RELEASE( PlainStencilShader ); + SAFE_RELEASE( InvPlainShader ); + SAFE_RELEASE( RedToAlphaShader ); SAFE_RELEASE( ColorOnlyShader ); SAFE_RELEASE( GammaFixerShader ); SAFE_RELEASE( BurnShader ); @@ -497,6 +531,7 @@ bool D3DFB::Reset () { return false; } + LOG("Device was reset\n"); if (!CreateFBTexture() || !CreateVertexes()) { return false; @@ -578,48 +613,6 @@ bool D3DFB::CreatePaletteTexture () return true; } -bool D3DFB::CreateStencilPaletteTexture() -{ - // The stencil palette is a special palette where the first entry is zero alpha, - // and everything else is white with full alpha. - if (FAILED(D3DDevice->CreateTexture(256, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &StencilPaletteTexture, NULL))) - { - return false; - } - D3DLOCKED_RECT lockrect; - if (SUCCEEDED(StencilPaletteTexture->LockRect(0, &lockrect, NULL, 0))) - { - DWORD *pix = (DWORD *)lockrect.pBits; - *pix = 0; - memset(pix + 1, 0xFF, 255*4); - StencilPaletteTexture->UnlockRect(0); - } - return true; -} - -bool D3DFB::CreateShadedPaletteTexture() -{ - // The shaded palette is similar to the stencil palette, except each entry's - // alpha is the same as its index. - if (FAILED(D3DDevice->CreateTexture(256, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &ShadedPaletteTexture, NULL))) - { - return false; - } - D3DLOCKED_RECT lockrect; - if (SUCCEEDED(ShadedPaletteTexture->LockRect(0, &lockrect, NULL, 0))) - { - BYTE *pix = (BYTE *)lockrect.pBits; - for (int i = 0; i < 256; ++i) - { - pix[3] = i; - pix[2] = pix[1] = pix[0] = 255; - pix += 4; - } - ShadedPaletteTexture->UnlockRect(0); - } - return true; -} - bool D3DFB::CreateVertexes () { VertexPos = -1; @@ -829,12 +822,12 @@ void D3DFB::Update () { ramp.blue[i] = ramp.green[i] = ramp.red[i] = WORD(65535.f * powf(i / 255.f, igamma)); } + LOG("SetGammaRamp\n"); D3DDevice->SetGammaRamp(0, D3DSGR_CALIBRATE, &ramp); } psgamma[2] = psgamma[1] = psgamma[0] = igamma; psgamma[3] = 1; D3DDevice->SetPixelShaderConstantF(7, psgamma, 1); - NeedPalUpdate = true; } if (NeedPalUpdate) @@ -862,7 +855,7 @@ void D3DFB::Update () } unclock (BlitCycles); - LOG1 ("cycles = %d\n", BlitCycles); + //LOG1 ("cycles = %d\n", BlitCycles); Buffer = NULL; UpdatePending = false; @@ -940,11 +933,12 @@ void D3DFB::Draw3DPart(bool copy3d) } SetTexture (0, FBTexture); - SetPaletteTexture(PaletteTexture, 256); + SetPaletteTexture(PaletteTexture, 256, BorderColor); SetPixelShader(PalTexShader); D3DDevice->SetFVF (D3DFVF_FBVERTEX); memset(Constant, 0, sizeof(Constant)); - SetAlphaBlend(FALSE); + SetAlphaBlend(D3DBLENDOP(0)); + EnableAlphaTest(FALSE); if (copy3d) { FBVERTEX verts[4]; @@ -991,7 +985,8 @@ void D3DFB::DoWindowedGamma() D3DDevice->SetFVF(D3DFVF_FBVERTEX); SetTexture(0, TempRenderTexture); SetPixelShader((Windowed && GammaFixerShader != NULL) ? GammaFixerShader : PlainShader); - SetAlphaBlend(FALSE); + SetAlphaBlend(D3DBLENDOP(0)); + EnableAlphaTest(FALSE); D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, verts, sizeof(FBVERTEX)); OldRenderTarget->Release(); OldRenderTarget = NULL; @@ -1001,12 +996,22 @@ void D3DFB::DoWindowedGamma() void D3DFB::UploadPalette () { D3DLOCKED_RECT lockrect; - int i; if (SUCCEEDED(PaletteTexture->LockRect (0, &lockrect, NULL, 0))) { BYTE *pix = (BYTE *)lockrect.pBits; - for (i = 0; i < 256; ++i, pix += 4) + int i, skipat; + + // It is impossible to get the Radeon 9000 to do the proper palette + // lookup. It *will* skip at least one entry in the palette. So we + // let it and have it look at the texture border color for color 255. + // I assume that every other card based on a related graphics chipset + // is similarly affected, which basically means that all Shader Model + // 1.4 cards suffer from this problem, since they all use some variant + // of the ATI R200. + skipat = SM14 ? 256 - 8 : 256; + + for (i = 0; i < skipat; ++i, pix += 4) { pix[0] = SourcePalette[i].b; pix[1] = SourcePalette[i].g; @@ -1014,7 +1019,16 @@ void D3DFB::UploadPalette () pix[3] = (i == 0 ? 0 : 255); // To let masked textures work, the first palette entry's alpha is 0. } + pix += 4; + for (; i < 255; ++i, pix += 4) + { + pix[0] = SourcePalette[i].b; + pix[1] = SourcePalette[i].g; + pix[2] = SourcePalette[i].r; + pix[3] = 255; + } PaletteTexture->UnlockRect (0); + BorderColor = D3DCOLOR_XRGB(SourcePalette[255].r, SourcePalette[255].g, SourcePalette[255].b); } } @@ -1296,18 +1310,17 @@ void D3DFB::DrawPackedTextures(int packnum) BufferedQuad *quad = &QuadExtra[QuadBatchPos]; FBVERTEX *vert = &VertexData[VertexPos]; + quad->Group1 = 0; if (pack->Format == D3DFMT_L8/* && !tex->IsGray*/) { - quad->Flags = BQF_WrapUV | BQF_GamePalette; + quad->Flags = BQF_WrapUV | BQF_GamePalette | BQF_DisableAlphaTest; quad->ShaderNum = BQS_PalTex; } else { - quad->Flags = BQF_WrapUV; + quad->Flags = BQF_WrapUV | BQF_DisableAlphaTest; quad->ShaderNum = BQS_Plain; } - quad->SrcBlend = 0; - quad->DestBlend = 0; quad->Palette = NULL; quad->Texture = pack; @@ -1956,6 +1969,9 @@ D3DPal::D3DPal(FRemapTable *remap, D3DFB *fb) if (fb->SM14) { count = 256; + // If the palette isn't big enough, then we don't need to + // worry about setting the gamma ramp. + BorderColor = (remap->NumEntries >= 256 - 8) ? ~0 : 0; } else { @@ -1965,6 +1981,7 @@ D3DPal::D3DPal(FRemapTable *remap, D3DFB *fb) for (pow2count = 1; pow2count < remap->NumEntries; pow2count <<= 1) { } count = pow2count; + BorderColor = 0; } RoundedPaletteSize = count; if (SUCCEEDED(fb->D3DDevice->CreateTexture(count, 1, 1, 0, @@ -2013,6 +2030,7 @@ bool D3DPal::Update() D3DLOCKED_RECT lrect; D3DCOLOR *buff; const PalEntry *pal; + int skipat, i; assert(Tex != NULL); @@ -2023,12 +2041,19 @@ bool D3DPal::Update() buff = (D3DCOLOR *)lrect.pBits; pal = Remap->Palette; - // Should I allow the source palette to specify alpha values? - buff[0] = D3DCOLOR_ARGB(0, pal[0].r, pal[0].g, pal[0].b); - for (int i = 1; i < Remap->NumEntries; ++i) + // See explanation in UploadPalette() for skipat rationale. + skipat = MIN(Remap->NumEntries, BorderColor != 0 ? 256 - 8 : 256); + + for (i = 0; i < skipat; ++i) { - buff[i] = D3DCOLOR_XRGB(pal[i].r, pal[i].g, pal[i].b); + buff[i] = D3DCOLOR_ARGB(pal[i].a, pal[i].r, pal[i].g, pal[i].b); } + for (++i; i < Remap->NumEntries; ++i) + { + buff[i] = D3DCOLOR_ARGB(pal[i-1].a, pal[i-1].r, pal[i-1].g, pal[i-1].b); + } + BorderColor = D3DCOLOR_ARGB(pal[i-1].a, pal[i-1].r, pal[i-1].g, pal[i-1].b); + Tex->UnlockRect(0); return true; } @@ -2190,7 +2215,7 @@ void D3DFB::EndLineBatch() if (VertexPos > 0) { SetPixelShader(ColorOnlyShader); - SetAlphaBlend(TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); + SetAlphaBlend(D3DBLENDOP_ADD, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); D3DDevice->SetStreamSource(0, VertexBuffer, 0, sizeof(FBVERTEX)); D3DDevice->DrawPrimitive(D3DPT_LINELIST, 0, VertexPos / 2); } @@ -2269,7 +2294,7 @@ void D3DFB::DrawPixel(int x, int y, int palcolor, uint32 color) }; EndBatch(); // Draw out any batched operations. SetPixelShader(ColorOnlyShader); - SetAlphaBlend(TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); + SetAlphaBlend(D3DBLENDOP_ADD, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); D3DDevice->DrawPrimitiveUP(D3DPT_POINTLIST, 1, &pt, sizeof(FBVERTEX)); } @@ -2473,18 +2498,17 @@ void D3DFB::FlatFill(int left, int top, int right, int bottom, FTexture *src, bo BufferedQuad *quad = &QuadExtra[QuadBatchPos]; FBVERTEX *vert = &VertexData[VertexPos]; + quad->Group1 = 0; if (tex->GetTexFormat() == D3DFMT_L8 && !tex->IsGray) { - quad->Flags = BQF_WrapUV | BQF_GamePalette; + quad->Flags = BQF_WrapUV | BQF_GamePalette | BQF_DisableAlphaTest; quad->ShaderNum = BQS_PalTex; } else { - quad->Flags = BQF_WrapUV; + quad->Flags = BQF_WrapUV | BQF_DisableAlphaTest; quad->ShaderNum = BQS_Plain; } - quad->SrcBlend = 0; - quad->DestBlend = 0; quad->Palette = NULL; quad->Texture = tex->Box->Owner; @@ -2556,15 +2580,11 @@ void D3DFB::AddColorOnlyQuad(int left, int top, int width, int height, D3DCOLOR float x = float(left) - 0.5f; float y = float(top) - 0.5f + (GatheringWipeScreen ? 0 : LBOffset); - quad->Flags = 0; + quad->Group1 = 0; quad->ShaderNum = BQS_ColorOnly; - if ((color & 0xFF000000) == 0xFF000000) - { - quad->SrcBlend = 0; - quad->DestBlend = 0; - } - else + if ((color & 0xFF000000) != 0xFF000000) { + quad->BlendOp = D3DBLENDOP_ADD; quad->SrcBlend = D3DBLEND_SRCALPHA; quad->DestBlend = D3DBLEND_INVSRCALPHA; } @@ -2716,48 +2736,43 @@ void D3DFB::EndQuadBatch() // Set the palette (if one) if ((quad->Flags & BQF_Paletted) == BQF_GamePalette) { - SetPaletteTexture(PaletteTexture, 256); + SetPaletteTexture(PaletteTexture, 256, BorderColor); } else if ((quad->Flags & BQF_Paletted) == BQF_CustomPalette) { - SetPaletteTexture(quad->Palette->Tex, quad->Palette->RoundedPaletteSize); - } - else if ((quad->Flags & BQF_Paletted) == BQF_ShadedPalette) - { - SetPaletteTexture(ShadedPaletteTexture, 256); - } - else if ((quad->Flags & BQF_Paletted) == BQF_StencilPalette) - { - SetPaletteTexture(StencilPaletteTexture, 256); + SetPaletteTexture(quad->Palette->Tex, quad->Palette->RoundedPaletteSize, quad->Palette->BorderColor); } // Set paletted bilinear filtering (IF IT WORKED RIGHT!) - if (quad->Flags & (BQF_Paletted | BQF_Bilinear)) + if ((quad->Flags & (BQF_Paletted | BQF_Bilinear)) == (BQF_Paletted | BQF_Bilinear)) { SetPalTexBilinearConstants(quad->Texture); } // Set the alpha blending - if (quad->SrcBlend != 0) - { - SetAlphaBlend(TRUE, D3DBLEND(quad->SrcBlend), D3DBLEND(quad->DestBlend)); - } - else - { - SetAlphaBlend(FALSE); - } + SetAlphaBlend(D3DBLENDOP(quad->BlendOp), D3DBLEND(quad->SrcBlend), D3DBLEND(quad->DestBlend)); + + // Set the alpha test + EnableAlphaTest(!(quad->Flags & BQF_DisableAlphaTest)); // Set the pixel shader if (quad->ShaderNum == BQS_PalTex) { - SetPixelShader(!(quad->Flags & BQF_Bilinear) ? PalTexShader : PalTexBilinearShader); + if (!(quad->Flags & BQF_Bilinear)) + { + SetPixelShader((quad->Flags & BQF_InvertSource) ? InvPalTexShader : PalTexShader); + } + else + { + SetPixelShader(PalTexBilinearShader); + } } else if (quad->ShaderNum == BQS_Plain) { - SetPixelShader(PlainShader); + SetPixelShader((quad->Flags & BQF_InvertSource) ? InvPlainShader : PlainShader); } - else if (quad->ShaderNum == BQS_PlainStencil) + else if (quad->ShaderNum == BQS_RedToAlpha) { - SetPixelShader(PlainStencilShader); + SetPixelShader(RedToAlphaShader); } else if (quad->ShaderNum == BQS_ColorOnly) { @@ -2825,90 +2840,80 @@ void D3DFB::EndBatch() bool D3DFB::SetStyle(D3DTex *tex, DrawParms &parms, D3DCOLOR &color0, D3DCOLOR &color1, BufferedQuad &quad) { D3DFORMAT fmt = tex->GetTexFormat(); - ERenderStyle style = parms.style; - D3DBLEND fglevel, bglevel; + FRenderStyle style = parms.style; float alpha; bool stencilling; - alpha = clamp (parms.alpha, 0, FRACUNIT) / 65536.f; - - if (style == STYLE_OptFuzzy) + if (style.Flags & STYLEF_TransSoulsAlpha) { - style = STYLE_Translucent; - } - else if (style == STYLE_SoulTrans) - { - style = STYLE_Translucent; alpha = transsouls; } - - // FIXME: STYLE_Fuzzy is not written - if (style == STYLE_Fuzzy) + else if (style.Flags & STYLEF_Alpha1) { - style = STYLE_Translucent; - alpha = transsouls; + alpha = 1; + } + else + { + alpha = clamp (parms.alpha, 0, FRACUNIT) / 65536.f; + } + + // FIXME: Fuzz effect is not written + if (style.BlendOp == STYLEOP_FuzzOrAdd || style.BlendOp == STYLEOP_Fuzz) + { + style.BlendOp = STYLEOP_Add; + } + else if (style.BlendOp == STYLEOP_FuzzOrSub) + { + style.BlendOp = STYLEOP_Sub; + } + else if (style.BlendOp == STYLEOP_FuzzOrRevSub) + { + style.BlendOp = STYLEOP_RevSub; } stencilling = false; quad.Palette = NULL; - switch (style) + switch (style.BlendOp) { - // Special modes - case STYLE_Shaded: - if (alpha > 0) - { - color0 = 0; - color1 = parms.fillcolor | (D3DCOLOR(alpha * 255) << 24); - quad.Flags = BQF_ShadedPalette; - quad.SrcBlend = D3DBLEND_SRCALPHA; - quad.DestBlend = D3DBLEND_INVSRCALPHA; - quad.ShaderNum = BQS_PalTex; - return true; - } - return false; - - // Standard modes - case STYLE_Stencil: - stencilling = true; - case STYLE_Normal: - fglevel = D3DBLEND_SRCALPHA; - bglevel = D3DBLEND_INVSRCALPHA; - alpha = 1; - break; - - case STYLE_TranslucentStencil: - stencilling = true; - case STYLE_Translucent: - fglevel = D3DBLEND_SRCALPHA; - bglevel = D3DBLEND_INVSRCALPHA; - if (alpha == 0) - { - return false; - } - if (alpha == 1 && style == STYLE_Translucent) - { - style = STYLE_Normal; - } - break; - - case STYLE_Add: - fglevel = D3DBLEND_SRCALPHA; - bglevel = D3DBLEND_ONE; - break; - default: - return false; + case STYLEOP_Add: quad.BlendOp = D3DBLENDOP_ADD; break; + case STYLEOP_Sub: quad.BlendOp = D3DBLENDOP_SUBTRACT; break; + case STYLEOP_RevSub: quad.BlendOp = D3DBLENDOP_REVSUBTRACT; break; + case STYLEOP_None: return false; + } + quad.SrcBlend = GetStyleAlpha(style.SrcAlpha); + quad.DestBlend = GetStyleAlpha(style.DestAlpha); + + if (style.Flags & STYLEF_InvertOverlay) + { + // Only the overlay color is inverted, not the overlay alpha. + parms.colorOverlay = D3DCOLOR_ARGB(APART(parms.colorOverlay), + 255 - RPART(parms.colorOverlay), 255 - GPART(parms.colorOverlay), + 255 - BPART(parms.colorOverlay)); } - // Masking can only be turned off for STYLE_Normal, because it requires - // turning off the alpha blend. - if (!parms.masked && style == STYLE_Normal) + SetColorOverlay(parms.colorOverlay, alpha, color0, color1); + + if (style.Flags & STYLEF_ColorIsFixed) { - quad.SrcBlend = 0; - quad.DestBlend = 0; - SetColorOverlay(parms.colorOverlay, 1, color0, color1); - if (fmt == D3DFMT_L8 && !tex->IsGray) + if (style.Flags & STYLEF_InvertSource) + { // Since the source color is a constant, we can invert it now + // without spending time doing it in the shader. + parms.fillcolor = D3DCOLOR_XRGB(255 - RPART(parms.fillcolor), + 255 - GPART(parms.fillcolor), 255 - BPART(parms.fillcolor)); + } + // Set up the color mod to replace the color from the image data. + color0 = (color0 & D3DCOLOR_RGBA(0,0,0,255)) | (parms.fillcolor & D3DCOLOR_RGBA(255,255,255,0)); + color1 &= D3DCOLOR_RGBA(0,0,0,255); + + if (style.Flags & STYLEF_RedIsAlpha) + { + // Note that if the source texture is paletted, the palette is ignored. + quad.Flags = 0; + quad.ShaderNum = BQS_RedToAlpha; + } + else if (fmt == D3DFMT_L8) { quad.Flags = BQF_GamePalette; quad.ShaderNum = BQS_PalTex; @@ -2921,56 +2926,72 @@ bool D3DFB::SetStyle(D3DTex *tex, DrawParms &parms, D3DCOLOR &color0, D3DCOLOR & } else { - quad.SrcBlend = fglevel; - quad.DestBlend = bglevel; - - if (!stencilling) + if (style.Flags & STYLEF_RedIsAlpha) { - if (fmt == D3DFMT_L8) + quad.Flags = 0; + quad.ShaderNum = BQS_RedToAlpha; + } + else if (fmt == D3DFMT_L8) + { + if (parms.remap != NULL) { - if (parms.remap != NULL) - { - quad.Flags = BQF_CustomPalette; - quad.Palette = reinterpret_cast(parms.remap->GetNative()); - quad.ShaderNum = BQS_PalTex; - } - else if (tex->IsGray) - { - quad.Flags = 0; - quad.ShaderNum = BQS_Plain; - } - else - { - quad.Flags = BQF_GamePalette; - quad.ShaderNum = BQS_PalTex; - } + quad.Flags = BQF_CustomPalette; + quad.Palette = reinterpret_cast(parms.remap->GetNative()); + quad.ShaderNum = BQS_PalTex; } - else + else if (tex->IsGray) { quad.Flags = 0; quad.ShaderNum = BQS_Plain; } - SetColorOverlay(parms.colorOverlay, alpha, color0, color1); + else + { + quad.Flags = BQF_GamePalette; + quad.ShaderNum = BQS_PalTex; + } } else { - color0 = 0; - color1 = parms.fillcolor | (D3DCOLOR(alpha * 255) << 24); - if (fmt == D3DFMT_L8) - { - quad.Flags = BQF_StencilPalette; - quad.ShaderNum = BQS_PalTex; - } - else - { - quad.Flags = 0; - quad.ShaderNum = BQS_PlainStencil; - } + quad.Flags = 0; + quad.ShaderNum = BQS_Plain; + } + if (style.Flags & STYLEF_InvertSource) + { + quad.Flags |= BQF_InvertSource; } } + + // For unmasked images, force the alpha from the image data to be ignored. + if (!parms.masked) + { + color0 = (color0 & D3DCOLOR_RGBA(255, 255, 255, 0)) | D3DCOLOR_COLORVALUE(0, 0, 0, alpha); + color1 &= D3DCOLOR_RGBA(255, 255, 255, 0); + + // If our alpha is one and we are doing normal adding, then we can turn the blend off completely. + if (quad.BlendOp == D3DBLENDOP_ADD && + ((alpha == 1 && quad.SrcBlend == D3DBLEND_SRCALPHA) || quad.SrcBlend == D3DBLEND_ONE) && + ((alpha == 1 && quad.DestBlend == D3DBLEND_INVSRCALPHA) || quad.DestBlend == D3DBLEND_ZERO)) + { + quad.BlendOp = D3DBLENDOP(0); + } + quad.Flags |= BQF_DisableAlphaTest; + } return true; } +D3DBLEND D3DFB::GetStyleAlpha(int type) +{ + switch (type) + { + case STYLEALPHA_Zero: return D3DBLEND_ZERO; + case STYLEALPHA_One: return D3DBLEND_ONE; + case STYLEALPHA_Src: return D3DBLEND_SRCALPHA; + case STYLEALPHA_InvSrc: return D3DBLEND_INVSRCALPHA; + default: return D3DBLEND_ZERO; + } +} + + void D3DFB::SetColorOverlay(DWORD color, float alpha, D3DCOLOR &color0, D3DCOLOR &color1) { if (APART(color) != 0) @@ -2991,9 +3012,18 @@ void D3DFB::SetColorOverlay(DWORD color, float alpha, D3DCOLOR &color0, D3DCOLOR } } -void D3DFB::SetAlphaBlend(BOOL enabled, D3DBLEND srcblend, D3DBLEND destblend) +void D3DFB::EnableAlphaTest(BOOL enabled) { - if (!enabled) + if (enabled != AlphaTestEnabled) + { + AlphaTestEnabled = enabled; + D3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, enabled); + } +} + +void D3DFB::SetAlphaBlend(D3DBLENDOP op, D3DBLEND srcblend, D3DBLEND destblend) +{ + if (op == 0) { // Disable alpha blend if (AlphaBlendEnabled) { @@ -3011,6 +3041,11 @@ void D3DFB::SetAlphaBlend(BOOL enabled, D3DBLEND srcblend, D3DBLEND destblend) AlphaBlendEnabled = TRUE; D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); } + if (AlphaBlendOp != op) + { + AlphaBlendOp = op; + D3DDevice->SetRenderState(D3DRS_BLENDOP, op); + } if (AlphaSrcBlend != srcblend) { AlphaSrcBlend = srcblend; @@ -3059,12 +3094,17 @@ void D3DFB::SetTexture(int tnum, IDirect3DTexture9 *texture) CVAR(Float, pal, 0.5f, 0) CVAR(Float, pc, 255.f, 0) -void D3DFB::SetPaletteTexture(IDirect3DTexture9 *texture, int count) +void D3DFB::SetPaletteTexture(IDirect3DTexture9 *texture, int count, D3DCOLOR border_color) { - if (count == 256 || SM14) + if (SM14) { // Shader Model 1.4 only uses 256-color palettes. - SetConstant(2, pc / 256.f, pal / 256.f, 0, 0); + SetConstant(2, 1.f, 0.5f / 256.f, 0, 0); + if (border_color != 0 && CurBorderColor != border_color) + { + CurBorderColor = border_color; + D3DDevice->SetSamplerState(1, D3DSAMP_BORDERCOLOR, border_color); + } } else { diff --git a/src/win32/fb_d3d9_shaders.h b/src/win32/fb_d3d9_shaders.h index 9ad4e5ee75..2e72926140 100644 --- a/src/win32/fb_d3d9_shaders.h +++ b/src/win32/fb_d3d9_shaders.h @@ -103,6 +103,118 @@ const DWORD PalTexShader20Def[] = 0x800f0800, 0x80e40000, 0x0000ffff }; +// An inverted paletted texture shader -------------------------------------- + +#if HLSL_SOURCE_CODE +sampler2D Image : register(s0); +sampler1D Palette : register(s1); +float4 PaletteMod : register(c2); +float4 White : register(c6); // Preloaded with (1,1,1,0) + +float4 main (float2 texCoord : TEXCOORD0, float4 Flash : COLOR0, float4 InvFlash : COLOR1) : COLOR +{ + float index = tex2D (Image, texCoord).x; + index = index * PaletteMod.x + PaletteMod.y; + float4 rgb = tex1D (Palette, index); + rgb.xyz = White.xyz - rgb.xyz; + return Flash + rgb * InvFlash; +} +#elif SHADER_ASSEMBLY_CODE +// +// Generated by Microsoft (R) D3DX9 Shader Compiler 9.15.779.0000 +// +// fxc paltex.ps /Tps_1_4 /LD /VnInvPalTexShader14Def /Fhinvpaltex.h +// +// +// Parameters: +// +// sampler2D Image; +// sampler1D Palette; +// float4 PaletteMod; +// float4 White; +// +// +// Registers: +// +// Name Reg Size +// ------------ ----- ---- +// PaletteMod c2 1 +// White c6 1 +// Image s0 1 +// Palette s1 1 +// + + ps_1_4 + texld r0, t0 + mad r0.xy, r0.x, c2.x, c2.y + phase + texld r1, r0 + add r1.xyz, -r1, c6 + mad r0, r1, v1, v0 + +// approximately 5 instruction slots used (2 texture, 3 arithmetic) +#endif + +const DWORD InvPalTexShader14Def[] = +{ + 0xffff0104, 0x003ffffe, 0x42415443, 0x0000001c, 0x000000c5, 0xffff0104, + 0x00000004, 0x0000001c, 0x00000100, 0x000000be, 0x0000006c, 0x00000003, + 0x00000001, 0x00000074, 0x00000000, 0x00000084, 0x00010003, 0x00000001, + 0x0000008c, 0x00000000, 0x0000009c, 0x00020002, 0x00020001, 0x000000a8, + 0x00000000, 0x000000b8, 0x00060002, 0x00020001, 0x000000a8, 0x00000000, + 0x67616d49, 0xabab0065, 0x000c0004, 0x00010001, 0x00000001, 0x00000000, + 0x656c6150, 0x00657474, 0x000b0004, 0x00010001, 0x00000001, 0x00000000, + 0x656c6150, 0x4d657474, 0xab00646f, 0x00030001, 0x00040001, 0x00000001, + 0x00000000, 0x74696857, 0x73700065, 0x345f315f, 0x63694d00, 0x6f736f72, + 0x28207466, 0x44202952, 0x39584433, 0x61685320, 0x20726564, 0x706d6f43, + 0x72656c69, 0x312e3920, 0x37372e35, 0x30302e39, 0xab003030, 0x00000042, + 0x800f0000, 0xb0e40000, 0x00000004, 0x80030000, 0x80000000, 0xa0000002, + 0xa0550002, 0x0000fffd, 0x00000042, 0x800f0001, 0x80e40000, 0x00000002, + 0x80070001, 0x81e40001, 0xa0e40006, 0x00000004, 0x800f0000, 0x80e40001, + 0x90e40001, 0x90e40000, 0x0000ffff +}; + +#if SHADER_ASSEMBLY_CODE + ps_2_0 + dcl t0.xy + dcl v0 + dcl v1 + dcl_2d s0 + dcl_2d s1 + texld r0, t0, s0 + mad r0.xy, r0.x, c2.x, c2.y + texld r0, r0, s1 + add r0.xyz, -r0, c6 + mov r1, v1 + mad r0, r0, r1, v0 + mov oC0, r0 + +// approximately 7 instruction slots used (2 texture, 5 arithmetic) +#endif + +const DWORD InvPalTexShader20Def[] = +{ + 0xffff0200, 0x003ffffe, 0x42415443, 0x0000001c, 0x000000c5, 0xffff0200, + 0x00000004, 0x0000001c, 0x20000100, 0x000000be, 0x0000006c, 0x00000003, + 0x00020001, 0x00000074, 0x00000000, 0x00000084, 0x00010003, 0x00060001, + 0x0000008c, 0x00000000, 0x0000009c, 0x00020002, 0x000a0001, 0x000000a8, + 0x00000000, 0x000000b8, 0x00060002, 0x001a0001, 0x000000a8, 0x00000000, + 0x67616d49, 0xabab0065, 0x000c0004, 0x00010001, 0x00000001, 0x00000000, + 0x656c6150, 0x00657474, 0x000b0004, 0x00010001, 0x00000001, 0x00000000, + 0x656c6150, 0x4d657474, 0xab00646f, 0x00030001, 0x00040001, 0x00000001, + 0x00000000, 0x74696857, 0x73700065, 0x305f325f, 0x63694d00, 0x6f736f72, + 0x28207466, 0x48202952, 0x204c534c, 0x64616853, 0x43207265, 0x69706d6f, + 0x2072656c, 0x39312e39, 0x3934392e, 0x3131322e, 0xabab0031, 0x0200001f, + 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f, + 0x80000000, 0x900f0001, 0x0200001f, 0x90000000, 0xa00f0800, 0x0200001f, + 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, + 0x04000004, 0x80030000, 0x80000000, 0xa0000002, 0xa0550002, 0x03000042, + 0x800f0000, 0x80e40000, 0xa0e40801, 0x03000002, 0x80070000, 0x81e40000, + 0xa0e40006, 0x02000001, 0x800f0001, 0x90e40001, 0x04000004, 0x800f0000, + 0x80e40000, 0x80e40001, 0x90e40000, 0x02000001, 0x800f0800, 0x80e40000, + 0x0000ffff +}; + // A paletted texture shader that does bilinear filtering ------------------- #if HLSL_SOURCE_CODE @@ -293,22 +405,77 @@ const DWORD PlainShaderDef[] = 0x90e40000, 0x0000ffff }; -// A shader that uses vertex color and texture alpha ------------------------ +// A shader that inverts the source's colors -------------------------------- #if HLSL_SOURCE_CODE sampler2D Image : register(s0); +float4 White : register(c6); // Preloaded with (1,1,1,0) -float4 main (float2 texCoord : TEXCOORD0, float4 StencilColor : COLOR1) : COLOR +float4 main (float2 texCoord : TEXCOORD0, float4 Flash : COLOR0, float4 InvFlash : COLOR1) : COLOR { - float4 color = tex2D (Image, texCoord); - color.rgb = StencilColor.rgb; - return color; + float4 rgb = tex2D (Image, texCoord); + rgb.xyz = White.xyz - rgb.xyz; + return Flash + rgb * InvFlash; } #elif SHADER_ASSEMBLY_CODE // // Generated by Microsoft (R) D3DX9 Shader Compiler 9.15.779.0000 // -// fxc plainstencil.ps /Tps_1_1 /LD /VnPlainStencilDef /Fhplainstencil.h +// fxc plain.ps /Tps_1_1 /LD /VnInvPlainShaderDef /Fhinvplain.h +// +// +// Parameters: +// +// sampler2D Image; +// float4 White; +// +// +// Registers: +// +// Name Reg Size +// ------------ ----- ---- +// White c6 1 +// Image s0 1 +// + + ps_1_1 + tex t0 + add t0.xyz, -t0, c6 + mad r0, t0, v1, v0 + +// approximately 3 instruction slots used (1 texture, 2 arithmetic) +#endif + +const DWORD InvPlainShaderDef[] = +{ + 0xffff0101, 0x002dfffe, 0x42415443, 0x0000001c, 0x0000007b, 0xffff0101, + 0x00000002, 0x0000001c, 0x00000100, 0x00000074, 0x00000044, 0x00000003, + 0x00000001, 0x0000004c, 0x00000000, 0x0000005c, 0x00060002, 0x00020001, + 0x00000064, 0x00000000, 0x67616d49, 0xabab0065, 0x000c0004, 0x00010001, + 0x00000001, 0x00000000, 0x74696857, 0xabab0065, 0x00030001, 0x00040001, + 0x00000001, 0x00000000, 0x315f7370, 0x4d00315f, 0x6f726369, 0x74666f73, + 0x29522820, 0x44334420, 0x53203958, 0x65646168, 0x6f432072, 0x6c69706d, + 0x39207265, 0x2e35312e, 0x2e393737, 0x30303030, 0xababab00, 0x00000042, + 0xb00f0000, 0x00000002, 0xb0070000, 0xb1e40000, 0xa0e40006, 0x00000004, + 0x800f0000, 0xb0e40000, 0x90e40001, 0x90e40000, 0x0000ffff +}; + +// A shader that copies the red component to the alpha component ------------ + +#if HLSL_SOURCE_CODE +sampler2D Image : register(s0); + +float4 main (float2 texCoord : TEXCOORD0, float4 Flash : COLOR0, float4 InvFlash : COLOR1) : COLOR +{ + float4 color = tex2D (Image, texCoord); + color.a = color.r; + return Flash + color * InvFlash; +} +#elif SHADER_ASSEMBLY_CODE +// +// Generated by Microsoft (R) D3DX9 Shader Compiler 9.15.779.0000 +// +// fxc redtoalpha.ps /Tps_1_4 /LD /VnRedToAlphaDef /Fhredtoalpha.h // // // Parameters: @@ -323,24 +490,26 @@ float4 main (float2 texCoord : TEXCOORD0, float4 StencilColor : COLOR1) : COLOR // Image s0 1 // - ps_1_1 - tex t0 - mov r0.xyz, v1 - + mov r0.w, t0.w + ps_1_4 + texld r0, t0 + mad r1.xyz, r0, v1, v0 + + mad r1.w, r0.x, v1.w, v0.w + mov r0, r1 -// approximately 2 instruction slots used (1 texture, 1 arithmetic) +// approximately 3 instruction slots used (1 texture, 2 arithmetic) #endif -const DWORD PlainStencilDef[] = +const DWORD RedToAlphaDef[] = { - 0xffff0101, 0x0022fffe, 0x42415443, 0x0000001c, 0x0000004f, 0xffff0101, + 0xffff0104, 0x0022fffe, 0x42415443, 0x0000001c, 0x0000004f, 0xffff0104, 0x00000001, 0x0000001c, 0x00000100, 0x00000048, 0x00000030, 0x00000003, 0x00000001, 0x00000038, 0x00000000, 0x67616d49, 0xabab0065, 0x000c0004, - 0x00010001, 0x00000001, 0x00000000, 0x315f7370, 0x4d00315f, 0x6f726369, + 0x00010001, 0x00000001, 0x00000000, 0x315f7370, 0x4d00345f, 0x6f726369, 0x74666f73, 0x29522820, 0x44334420, 0x53203958, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e35312e, 0x2e393737, 0x30303030, 0xababab00, - 0x00000042, 0xb00f0000, 0x00000001, 0x80070000, 0x90e40001, 0x40000001, - 0x80080000, 0xb0ff0000, 0x0000ffff + 0x00000042, 0x800f0000, 0xb0e40000, 0x00000004, 0x80070001, 0x80e40000, + 0x90e40001, 0x90e40000, 0x40000004, 0x80080001, 0x80000000, 0x90ff0001, + 0x90ff0000, 0x00000001, 0x800f0000, 0x80e40001, 0x0000ffff }; // A shader that just returns the first color component from the vertex ----- diff --git a/src/win32/fb_d3d9_wipe.cpp b/src/win32/fb_d3d9_wipe.cpp index ee27f9444c..01fb67fe0e 100644 --- a/src/win32/fb_d3d9_wipe.cpp +++ b/src/win32/fb_d3d9_wipe.cpp @@ -303,6 +303,7 @@ bool D3DFB::WipeDo(int ticks) } In2D = 3; + EnableAlphaTest(FALSE); bool done = ScreenWipe->Run(ticks, this); DrawLetterbox(); return done; @@ -392,7 +393,7 @@ bool D3DFB::Wiper_Crossfade::Run(int ticks, D3DFB *fb) fb->CalcFullscreenCoords(verts, false, D3DCOLOR_COLORVALUE(0,0,0,Clock / 32.f), D3DCOLOR_RGBA(255,255,255,0)); fb->D3DDevice->SetFVF(D3DFVF_FBVERTEX); fb->SetTexture(0, fb->FinalWipeScreen); - fb->SetAlphaBlend(TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); + fb->SetAlphaBlend(D3DBLENDOP_ADD, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); fb->SetPixelShader(fb->PlainShader); fb->D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, verts, sizeof(FBVERTEX)); @@ -450,7 +451,7 @@ bool D3DFB::Wiper_Melt::Run(int ticks, D3DFB *fb) fb->CalcFullscreenCoords(verts, false, 0, 0xFFFFFFFF); fb->D3DDevice->SetFVF(D3DFVF_FBVERTEX); fb->SetTexture(0, fb->FinalWipeScreen); - fb->SetAlphaBlend(FALSE); + fb->SetAlphaBlend(D3DBLENDOP(0)); fb->SetPixelShader(fb->PlainShader); fb->D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, verts, sizeof(FBVERTEX)); @@ -599,11 +600,21 @@ bool D3DFB::Wiper_Burn::Run(int ticks, D3DFB *fb) fb->D3DDevice->SetFVF(D3DFVF_BURNVERTEX); fb->SetTexture(0, fb->FinalWipeScreen); fb->SetTexture(1, BurnTexture); - fb->SetAlphaBlend(TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); + fb->SetAlphaBlend(D3DBLENDOP_ADD, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); fb->SetPixelShader(fb->BurnShader); fb->D3DDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + if (fb->SM14) + { + fb->D3DDevice->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + fb->D3DDevice->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); + } fb->D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, verts, sizeof(BURNVERTEX)); fb->D3DDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT); + if (fb->SM14) + { + fb->D3DDevice->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + fb->D3DDevice->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + } fb->D3DDevice->SetFVF(D3DFVF_FBVERTEX); // The fire may not always stabilize, so the wipe is forced to end diff --git a/src/win32/win32iface.h b/src/win32/win32iface.h index 291eff4e48..8c887555ea 100644 --- a/src/win32/win32iface.h +++ b/src/win32/win32iface.h @@ -277,7 +277,8 @@ private: struct { BYTE Flags; - BYTE ShaderNum; + BYTE ShaderNum:4; + BYTE BlendOp:4; BYTE SrcBlend, DestBlend; }; DWORD Group1; @@ -292,8 +293,6 @@ private: bool CreateFBTexture(); bool CreatePaletteTexture(); bool CreateGrayPaletteTexture(); - bool CreateStencilPaletteTexture(); - bool CreateShadedPaletteTexture(); bool CreateVertexes(); void UploadPalette(); void FillPresentParameters (D3DPRESENT_PARAMETERS *pp, bool fullscreen, bool vsync); @@ -308,6 +307,7 @@ private: void DrawLetterbox(); void Draw3DPart(bool copy3d); bool SetStyle(D3DTex *tex, DCanvas::DrawParms &parms, D3DCOLOR &color0, D3DCOLOR &color1, BufferedQuad &quad); + static D3DBLEND GetStyleAlpha(int type); static void SetColorOverlay(DWORD color, float alpha, D3DCOLOR &color0, D3DCOLOR &color1); void DoWindowedGamma(); void AddColorOnlyQuad(int left, int top, int width, int height, D3DCOLOR color); @@ -319,21 +319,26 @@ private: void EndBatch(); // State - void SetAlphaBlend(BOOL enabled, D3DBLEND srcblend=D3DBLEND(0), D3DBLEND destblend=D3DBLEND(0)); + void EnableAlphaTest(BOOL enabled); + void SetAlphaBlend(D3DBLENDOP op, D3DBLEND srcblend=D3DBLEND(0), D3DBLEND destblend=D3DBLEND(0)); void SetConstant(int cnum, float r, float g, float b, float a); void SetPixelShader(IDirect3DPixelShader9 *shader); void SetTexture(int tnum, IDirect3DTexture9 *texture); - void SetPaletteTexture(IDirect3DTexture9 *texture, int count); + void SetPaletteTexture(IDirect3DTexture9 *texture, int count, D3DCOLOR border_color); void SetPalTexBilinearConstants(PackingTexture *texture); + BOOL AlphaTestEnabled; BOOL AlphaBlendEnabled; + D3DBLENDOP AlphaBlendOp; D3DBLEND AlphaSrcBlend; D3DBLEND AlphaDestBlend; float Constant[3][4]; + D3DCOLOR CurBorderColor; IDirect3DPixelShader9 *CurPixelShader; IDirect3DTexture9 *Texture[2]; PalEntry SourcePalette[256]; + D3DCOLOR BorderColor; D3DCOLOR FlashColor0, FlashColor1; PalEntry FlashColor; int FlashAmount; @@ -361,8 +366,6 @@ private: IDirect3DTexture9 *FBTexture; IDirect3DTexture9 *TempRenderTexture; IDirect3DTexture9 *PaletteTexture; - IDirect3DTexture9 *StencilPaletteTexture; - IDirect3DTexture9 *ShadedPaletteTexture; IDirect3DTexture9 *ScreenshotTexture; IDirect3DSurface9 *ScreenshotSurface; @@ -376,9 +379,9 @@ private: int QuadBatchPos; enum { BATCH_None, BATCH_Quads, BATCH_Lines } BatchType; - IDirect3DPixelShader9 *PalTexShader, *PalTexBilinearShader; - IDirect3DPixelShader9 *PlainShader; - IDirect3DPixelShader9 *PlainStencilShader; + IDirect3DPixelShader9 *PalTexShader, *PalTexBilinearShader, *InvPalTexShader; + IDirect3DPixelShader9 *PlainShader, *InvPlainShader; + IDirect3DPixelShader9 *RedToAlphaShader; IDirect3DPixelShader9 *ColorOnlyShader; IDirect3DPixelShader9 *GammaFixerShader; IDirect3DPixelShader9 *BurnShader; @@ -412,6 +415,15 @@ private: #define LOG4(x,y,z,a,b) do { if (dbg) { fprintf (dbg, x, y, z, a, b); fflush (dbg); } } while(0) #define LOG5(x,y,z,a,b,c) do { if (dbg) { fprintf (dbg, x, y, z, a, b, c); fflush (dbg); } } while(0) FILE *dbg; +#elif _DEBUG +#define STARTLOG +#define STOPLOG +#define LOG(x) { OutputDebugString(x); } +#define LOG1(x,y) { char poo[1024]; sprintf(poo, x, y); OutputDebugString(poo); } +#define LOG2(x,y,z) { char poo[1024]; sprintf(poo, x, y, z); OutputDebugString(poo); } +#define LOG3(x,y,z,zz) { char poo[1024]; sprintf(poo, x, y, z, zz); OutputDebugString(poo); } +#define LOG4(x,y,z,a,b) { char poo[1024]; sprintf(poo, x, y, z, a, b); OutputDebugString(poo); } +#define LOG5(x,y,z,a,b,c) { char poo[1024]; sprintf(poo, x, y, z, a, b, c); OutputDebugString(poo); } #else #define STARTLOG #define STOPLOG diff --git a/src/zstring.cpp b/src/zstring.cpp index db9d9d4dd5..6c906a331a 100644 --- a/src/zstring.cpp +++ b/src/zstring.cpp @@ -219,6 +219,7 @@ FString &FString::operator = (const char *copyStr) { if (copyStr == NULL || *copyStr == '\0') { + Data()->Release(); NullString.RefCount++; Chars = &NullString.Nothing[0]; } diff --git a/tools/dehsupp/scanner.c b/tools/dehsupp/scanner.c index d7bf94525b..89bf8b8e60 100644 --- a/tools/dehsupp/scanner.c +++ b/tools/dehsupp/scanner.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.10.5 */ +/* Generated by re2c 0.12.3 on Wed Jan 23 17:40:06 2008 */ #line 1 "scanner.re" #include #include @@ -66,8 +66,9 @@ std: unsigned int yyaccept = 0; if((YYLIMIT - YYCURSOR) < 13) YYFILL(13); +(13); yych = *YYCURSOR; - switch(yych){ + switch(yych) { case 0x09: case 0x0B: case 0x0C: @@ -159,7 +160,7 @@ yy2: yy3: #line 107 "scanner.re" { RET(DIVIDE); } -#line 163 "scanner.c" +#line 164 "scanner.c" yy4: ++YYCURSOR; if((yych = *YYCURSOR) == 'n') goto yy192; @@ -167,7 +168,7 @@ yy4: yy5: #line 91 "scanner.re" { RET(SYM); } -#line 171 "scanner.c" +#line 172 "scanner.c" yy6: yych = *++YYCURSOR; if(yych == 'r') goto yy187; @@ -226,7 +227,7 @@ yy17: yy18: #line 94 "scanner.re" { RET(NUM); } -#line 230 "scanner.c" +#line 231 "scanner.c" yy19: yych = *++YYCURSOR; goto yy63; @@ -240,7 +241,7 @@ yy21: printf("unexpected character: %c\n", *s->tok); goto std; } -#line 244 "scanner.c" +#line 245 "scanner.c" yy22: ++YYCURSOR; yych = *YYCURSOR; @@ -248,62 +249,62 @@ yy22: yy23: #line 99 "scanner.re" { goto std; } -#line 252 "scanner.c" +#line 253 "scanner.c" yy24: ++YYCURSOR; #line 101 "scanner.re" { RET(OR); } -#line 257 "scanner.c" +#line 258 "scanner.c" yy26: ++YYCURSOR; #line 102 "scanner.re" { RET(XOR); } -#line 262 "scanner.c" +#line 263 "scanner.c" yy28: ++YYCURSOR; #line 103 "scanner.re" { RET(AND); } -#line 267 "scanner.c" +#line 268 "scanner.c" yy30: ++YYCURSOR; #line 104 "scanner.re" { RET(MINUS); } -#line 272 "scanner.c" +#line 273 "scanner.c" yy32: ++YYCURSOR; #line 105 "scanner.re" { RET(PLUS); } -#line 277 "scanner.c" +#line 278 "scanner.c" yy34: ++YYCURSOR; #line 106 "scanner.re" { RET(MULTIPLY); } -#line 282 "scanner.c" +#line 283 "scanner.c" yy36: ++YYCURSOR; #line 108 "scanner.re" { RET(LPAREN); } -#line 287 "scanner.c" +#line 288 "scanner.c" yy38: ++YYCURSOR; #line 109 "scanner.re" { RET(RPAREN); } -#line 292 "scanner.c" +#line 293 "scanner.c" yy40: ++YYCURSOR; #line 110 "scanner.re" { RET(COMMA); } -#line 297 "scanner.c" +#line 298 "scanner.c" yy42: ++YYCURSOR; #line 111 "scanner.re" { RET(LBRACE); } -#line 302 "scanner.c" +#line 303 "scanner.c" yy44: ++YYCURSOR; #line 113 "scanner.re" { RET(SEMICOLON); } -#line 307 "scanner.c" +#line 308 "scanner.c" yy46: ++YYCURSOR; #line 117 "scanner.re" @@ -312,7 +313,7 @@ yy46: s->pos = cursor; s->line++; goto std; } -#line 316 "scanner.c" +#line 317 "scanner.c" yy48: yych = *++YYCURSOR; goto yy21; @@ -401,7 +402,7 @@ yy55: ++YYCURSOR; #line 97 "scanner.re" { RET(STRING); } -#line 405 "scanner.c" +#line 406 "scanner.c" yy57: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -555,7 +556,7 @@ yy71: yy82: #line 89 "scanner.re" { RET(RenderStyles); } -#line 559 "scanner.c" +#line 560 "scanner.c" yy83: yych = *++YYCURSOR; if(yych != 'r') goto yy70; @@ -589,7 +590,7 @@ yy83: yy92: #line 88 "scanner.re" { RET(FirstState); } -#line 593 "scanner.c" +#line 594 "scanner.c" yy93: yych = *++YYCURSOR; if(yych != 'a') goto yy70; @@ -623,7 +624,7 @@ yy93: yy102: #line 86 "scanner.re" { RET(DeathState); } -#line 627 "scanner.c" +#line 628 "scanner.c" yy103: yych = *++YYCURSOR; if(yych != 'i') goto yy70; @@ -655,7 +656,7 @@ yy103: yy111: #line 85 "scanner.re" { RET(ThingBits); } -#line 659 "scanner.c" +#line 660 "scanner.c" yy112: yych = *++YYCURSOR; if(yych != 'f') goto yy70; @@ -687,7 +688,7 @@ yy112: yy120: #line 84 "scanner.re" { RET(InfoNames); } -#line 691 "scanner.c" +#line 692 "scanner.c" yy121: yych = *++YYCURSOR; if(yych == 'u') goto yy140; @@ -725,7 +726,7 @@ yy123: yy130: #line 82 "scanner.re" { RET(StateMap); } -#line 729 "scanner.c" +#line 730 "scanner.c" yy131: yych = *++YYCURSOR; if(yych != 'w') goto yy70; @@ -757,7 +758,7 @@ yy131: yy139: #line 87 "scanner.re" { RET(SpawnState); } -#line 761 "scanner.c" +#line 762 "scanner.c" yy140: yych = *++YYCURSOR; if(yych != 'n') goto yy70; @@ -785,7 +786,7 @@ yy140: yy146: #line 83 "scanner.re" { RET(SoundMap); } -#line 789 "scanner.c" +#line 790 "scanner.c" yy147: yych = *++YYCURSOR; if(yych != 'd') goto yy70; @@ -817,7 +818,7 @@ yy147: yy155: #line 80 "scanner.re" { RET(CodePConv); } -#line 821 "scanner.c" +#line 822 "scanner.c" yy156: yych = *++YYCURSOR; if(yych != 'g') goto yy70; @@ -860,7 +861,7 @@ yy159: yy167: #line 81 "scanner.re" { RET(OrgSprNames); } -#line 864 "scanner.c" +#line 865 "scanner.c" yy168: yych = *++YYCURSOR; if(yych != 'i') goto yy70; @@ -888,7 +889,7 @@ yy168: yy174: #line 78 "scanner.re" { RET(OrgHeights); } -#line 892 "scanner.c" +#line 893 "scanner.c" yy175: yych = *++YYCURSOR; if(yych != 't') goto yy70; @@ -917,7 +918,7 @@ yy175: yy181: #line 77 "scanner.re" { RET(Actions); } -#line 921 "scanner.c" +#line 922 "scanner.c" yy182: yych = *++YYCURSOR; if(yych != 'i') goto yy70; @@ -941,7 +942,7 @@ yy182: yy186: #line 79 "scanner.re" { RET(ActionList); } -#line 945 "scanner.c" +#line 946 "scanner.c" yy187: yych = *++YYCURSOR; if(yych != 'i') goto yy70; @@ -965,7 +966,7 @@ yy187: yy191: #line 76 "scanner.re" { RET(PRINT); } -#line 969 "scanner.c" +#line 970 "scanner.c" yy192: yych = *++YYCURSOR; if(yych != 'd') goto yy70; @@ -987,7 +988,7 @@ yy192: yy195: #line 75 "scanner.re" { RET(ENDL); } -#line 991 "scanner.c" +#line 992 "scanner.c" yy196: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -998,7 +999,7 @@ yy198: ++YYCURSOR; #line 67 "scanner.re" { goto comment; } -#line 1002 "scanner.c" +#line 1003 "scanner.c" yy200: ++YYCURSOR; #line 69 "scanner.re" @@ -1007,17 +1008,18 @@ yy200: s->tok = s->pos = cursor; s->line++; goto std; } -#line 1011 "scanner.c" +#line 1012 "scanner.c" } #line 128 "scanner.re" comment: -#line 1018 "scanner.c" +#line 1019 "scanner.c" { YYCTYPE yych; if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); +(2); yych = *YYCURSOR; if(yych == 0x0A) goto yy206; if(yych != '*') goto yy208; @@ -1026,7 +1028,7 @@ comment: yy205: #line 139 "scanner.re" { goto comment; } -#line 1030 "scanner.c" +#line 1032 "scanner.c" yy206: ++YYCURSOR; #line 134 "scanner.re" @@ -1035,7 +1037,7 @@ yy206: s->tok = s->pos = cursor; s->line++; goto comment; } -#line 1039 "scanner.c" +#line 1041 "scanner.c" yy208: yych = *++YYCURSOR; goto yy205; @@ -1043,7 +1045,7 @@ yy209: ++YYCURSOR; #line 132 "scanner.re" { goto std; } -#line 1047 "scanner.c" +#line 1049 "scanner.c" } #line 140 "scanner.re" diff --git a/tools/lemon/lempar.c b/tools/lemon/lempar.c index cebc01812c..7058284292 100644 --- a/tools/lemon/lempar.c +++ b/tools/lemon/lempar.c @@ -1,739 +1,780 @@ -/* Driver template for the LEMON parser generator. -** The author disclaims copyright to this source code. -*/ -/* First off, code is included which follows the "include" declaration -** in the input file. */ -#include -#include -%% -/* Next is all token values, in a form suitable for use by makeheaders. -** This section will be null unless lemon is run with the -m switch. -*/ -/* -** These constants (all generated automatically by the parser generator) -** specify the various kinds of tokens (terminals) that the parser -** understands. -** -** Each symbol here is a terminal symbol in the grammar. -*/ -%% -/* Make sure the INTERFACE macro is defined. -*/ -#ifndef INTERFACE -# define INTERFACE 1 -#endif -/* The next thing included is series of defines which control -** various aspects of the generated parser. -** YYCODETYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 terminals -** and nonterminals. "int" is used otherwise. -** YYNOCODE is a number of type YYCODETYPE which corresponds -** to no legal terminal or nonterminal number. This -** number is used to fill in empty slots of the hash -** table. -** YYFALLBACK If defined, this indicates that one or more tokens -** have fall-back values which should be used if the -** original value of the token will not parse. -** YYACTIONTYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 rules and -** states combined. "int" is used otherwise. -** ParseTOKENTYPE is the data type used for minor tokens given -** directly to the parser from the tokenizer. -** YYMINORTYPE is the data type used for all minor tokens. -** This is typically a union of many types, one of -** which is ParseTOKENTYPE. The entry in the union -** for base tokens is called "yy0". -** YYSTACKDEPTH is the maximum depth of the parser's stack. -** ParseARG_SDECL A static variable declaration for the %extra_argument -** ParseARG_PDECL A parameter declaration for the %extra_argument -** ParseARG_STORE Code to store %extra_argument into yypParser -** ParseARG_FETCH Code to extract %extra_argument from yypParser -** YYNSTATE the combined number of states. -** YYNRULE the number of rules in the grammar -** YYERRORSYMBOL is the code number of the error symbol. If not -** defined, then do no error processing. -*/ -%% -#define YY_NO_ACTION (YYNSTATE+YYNRULE+2) -#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) -#define YY_ERROR_ACTION (YYNSTATE+YYNRULE) - -/* Next are that tables used to determine what action to take based on the -** current state and lookahead token. These tables are used to implement -** functions that take a state number and lookahead value and return an -** action integer. -** -** Suppose the action integer is N. Then the action is determined as -** follows -** -** 0 <= N < YYNSTATE Shift N. That is, push the lookahead -** token onto the stack and goto state N. -** -** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE. -** -** N == YYNSTATE+YYNRULE A syntax error has occurred. -** -** N == YYNSTATE+YYNRULE+1 The parser accepts its input. -** -** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused -** slots in the yy_action[] table. -** -** The action table is constructed as a single large table named yy_action[]. -** Given state S and lookahead X, the action is computed as -** -** yy_action[ yy_shift_ofst[S] + X ] -** -** If the index value yy_shift_ofst[S]+X is out of range or if the value -** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] -** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table -** and that yy_default[S] should be used instead. -** -** The formula above is for computing the action when the lookahead is -** a terminal symbol. If the lookahead is a non-terminal (as occurs after -** a reduce action) then the yy_reduce_ofst[] array is used in place of -** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of -** YY_SHIFT_USE_DFLT. -** -** The following are the tables generated in this section: -** -** yy_action[] A single table containing all actions. -** yy_lookahead[] A table containing the lookahead for each entry in -** yy_action. Used to detect hash collisions. -** yy_shift_ofst[] For each state, the offset into yy_action for -** shifting terminals. -** yy_reduce_ofst[] For each state, the offset into yy_action for -** shifting non-terminals after a reduce. -** yy_default[] Default action for each state. -*/ -%% -#define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0])) - -/* The next table maps tokens into fallback tokens. If a construct -** like the following: -** -** %fallback ID X Y Z. -** -** appears in the grammer, then ID becomes a fallback token for X, Y, -** and Z. Whenever one of the tokens X, Y, or Z is input to the parser -** but it does not parse, the type of the token is changed to ID and -** the parse is retried before an error is thrown. -*/ -#ifdef YYFALLBACK -static const YYCODETYPE yyFallback[] = { -%% -}; -#endif /* YYFALLBACK */ - -/* The following structure represents a single element of the -** parser's stack. Information stored includes: -** -** + The state number for the parser at this level of the stack. -** -** + The value of the token stored at this level of the stack. -** (In other words, the "major" token.) -** -** + The semantic value stored at this level of the stack. This is -** the information used by the action routines in the grammar. -** It is sometimes called the "minor" token. -*/ -struct yyStackEntry { - int stateno; /* The state-number */ - int major; /* The major token value. This is the code - ** number for the token at this stack level */ - YYMINORTYPE minor; /* The user-supplied minor token value. This - ** is the value of the token */ -}; -typedef struct yyStackEntry yyStackEntry; - -/* The state of the parser is completely contained in an instance of -** the following structure */ -struct yyParser { - int yyidx; /* Index of top element in stack */ - int yyerrcnt; /* Shifts left before out of the error */ - ParseARG_SDECL /* A place to hold %extra_argument */ - yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ -}; -typedef struct yyParser yyParser; - -#ifndef NDEBUG -#include -static FILE *yyTraceFILE = 0; -static char *yyTracePrompt = 0; -#endif /* NDEBUG */ - -#ifndef NDEBUG -/* -** Turn parser tracing on by giving a stream to which to write the trace -** and a prompt to preface each trace message. Tracing is turned off -** by making either argument NULL -** -** Inputs: -**
    -**
  • A FILE* to which trace output should be written. -** If NULL, then tracing is turned off. -**
  • A prefix string written at the beginning of every -** line of trace output. If NULL, then tracing is -** turned off. -**
-** -** Outputs: -** None. -*/ -void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ - yyTraceFILE = TraceFILE; - yyTracePrompt = zTracePrompt; - if( yyTraceFILE==0 ) yyTracePrompt = 0; - else if( yyTracePrompt==0 ) yyTraceFILE = 0; -} -#endif /* NDEBUG */ - -#ifndef NDEBUG -/* For tracing shifts, the names of all terminals and nonterminals -** are required. The following table supplies these names */ -static const char *const yyTokenName[] = { -%% -}; -#endif /* NDEBUG */ - -#ifndef NDEBUG -/* For tracing reduce actions, the names of all rules are required. -*/ -static const char *const yyRuleName[] = { -%% -}; -#endif /* NDEBUG */ - -/* -** This function returns the symbolic name associated with a token -** value. -*/ -const char *ParseTokenName(int tokenType){ -#ifndef NDEBUG - if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){ - return yyTokenName[tokenType]; - }else{ - return "Unknown"; - } -#else - return ""; -#endif -} - -/* -** This function allocates a new parser. -** The only argument is a pointer to a function which works like -** malloc. -** -** Inputs: -** A pointer to the function used to allocate memory. -** -** Outputs: -** A pointer to a parser. This pointer is used in subsequent calls -** to Parse and ParseFree. -*/ -void *ParseAlloc(void *(*mallocProc)(size_t)){ - yyParser *pParser; - pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); - if( pParser ){ - pParser->yyidx = -1; - } - return pParser; -} - -/* The following function deletes the value associated with a -** symbol. The symbol can be either a terminal or nonterminal. -** "yymajor" is the symbol code, and "yypminor" is a pointer to -** the value. -*/ -static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ - switch( yymajor ){ - /* Here is inserted the actions which take place when a - ** terminal or non-terminal is destroyed. This can happen - ** when the symbol is popped from the stack during a - ** reduce or during error processing or when a parser is - ** being destroyed before it is finished parsing. - ** - ** Note: during a reduce, the only symbols destroyed are those - ** which appear on the RHS of the rule, but which are not used - ** inside the C code. - */ -%% - default: break; /* If no destructor action specified: do nothing */ - } -} - -/* -** Pop the parser's stack once. -** -** If there is a destructor routine associated with the token which -** is popped from the stack, then call it. -** -** Return the major token number for the symbol popped. -*/ -static int yy_pop_parser_stack(yyParser *pParser){ - YYCODETYPE yymajor; - yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; - - if( pParser->yyidx<0 ) return 0; -#ifndef NDEBUG - if( yyTraceFILE && pParser->yyidx>=0 ){ - fprintf(yyTraceFILE,"%sPopping %s\n", - yyTracePrompt, - yyTokenName[yytos->major]); - } -#endif - yymajor = yytos->major; - yy_destructor( yymajor, &yytos->minor); - pParser->yyidx--; - return yymajor; -} - -/* -** Deallocate and destroy a parser. Destructors are all called for -** all stack elements before shutting the parser down. -** -** Inputs: -**
    -**
  • A pointer to the parser. This should be a pointer -** obtained from ParseAlloc. -**
  • A pointer to a function used to reclaim memory obtained -** from malloc. -**
-*/ -void ParseFree( - void *p, /* The parser to be deleted */ - void (*freeProc)(void*) /* Function used to reclaim memory */ -){ - yyParser *pParser = (yyParser*)p; - if( pParser==0 ) return; - while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); - (*freeProc)((void*)pParser); -} - -/* -** Find the appropriate action for a parser given the terminal -** look-ahead token iLookAhead. -** -** If the look-ahead token is YYNOCODE, then check to see if the action is -** independent of the look-ahead. If it is, return the action, otherwise -** return YY_NO_ACTION. -*/ -static int yy_find_shift_action( - yyParser *pParser, /* The parser */ - YYCODETYPE iLookAhead /* The look-ahead token */ -){ - int i; - int stateno = pParser->yystack[pParser->yyidx].stateno; - - if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){ - return yy_default[stateno]; - } - if( iLookAhead==YYNOCODE ){ - return YY_NO_ACTION; - } - i += iLookAhead; - if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ - if( iLookAhead>0 ){ -#ifdef YYFALLBACK - int iFallback; /* Fallback token */ - if( iLookAhead %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); - } -#endif - return yy_find_shift_action(pParser, iFallback); - } -#endif -#ifdef YYWILDCARD - { - int j = i - iLookAhead + YYWILDCARD; - if( j>=0 && j %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]); - } -#endif /* NDEBUG */ - return yy_action[j]; - } - } -#endif /* YYWILDCARD */ - } - return yy_default[stateno]; - }else{ - return yy_action[i]; - } -} - -/* -** Find the appropriate action for a parser given the non-terminal -** look-ahead token iLookAhead. -** -** If the look-ahead token is YYNOCODE, then check to see if the action is -** independent of the look-ahead. If it is, return the action, otherwise -** return YY_NO_ACTION. -*/ -static int yy_find_reduce_action( - int stateno, /* Current state number */ - YYCODETYPE iLookAhead /* The look-ahead token */ -){ - int i; - /* int stateno = pParser->yystack[pParser->yyidx].stateno; */ - - if( stateno>YY_REDUCE_MAX || - (i = yy_reduce_ofst[stateno])==YY_REDUCE_USE_DFLT ){ - return yy_default[stateno]; - } - if( iLookAhead==YYNOCODE ){ - return YY_NO_ACTION; - } - i += iLookAhead; - if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ - return yy_default[stateno]; - }else{ - return yy_action[i]; - } -} - -/* -** Perform a shift action. -*/ -static void yy_shift( - yyParser *yypParser, /* The parser to be shifted */ - int yyNewState, /* The new state to shift in */ - int yyMajor, /* The major token to shift in */ - YYMINORTYPE *yypMinor /* Pointer ot the minor token to shift in */ -){ - yyStackEntry *yytos; - yypParser->yyidx++; - if( yypParser->yyidx>=YYSTACKDEPTH ){ - ParseARG_FETCH; - yypParser->yyidx--; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); - } -#endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will execute if the parser - ** stack ever overflows */ -%% - ParseARG_STORE; /* Suppress warning about unused %extra_argument var */ - return; - } - yytos = &yypParser->yystack[yypParser->yyidx]; - yytos->stateno = yyNewState; - yytos->major = yyMajor; - yytos->minor = *yypMinor; -#ifndef NDEBUG - if( yyTraceFILE && yypParser->yyidx>0 ){ - int i; - fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState); - fprintf(yyTraceFILE,"%sStack:",yyTracePrompt); - for(i=1; i<=yypParser->yyidx; i++) - fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); - fprintf(yyTraceFILE,"\n"); - } -#endif -} - -/* The following table contains information about every rule that -** is used during the reduce. -*/ -static const struct { - YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ - unsigned char nrhs; /* Number of right-hand side symbols in the rule */ -} yyRuleInfo[] = { -%% -}; - -static void yy_accept(yyParser*); /* Forward Declaration */ - -/* -** Perform a reduce action and the shift that must immediately -** follow the reduce. -*/ -static void yy_reduce( - yyParser *yypParser, /* The parser */ - int yyruleno /* Number of the rule by which to reduce */ -){ - int yygoto; /* The next state */ - int yyact; /* The next action */ - YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ - yyStackEntry *yymsp; /* The top of the parser's stack */ - int yysize; /* Amount to pop the stack */ - ParseARG_FETCH; - yymsp = &yypParser->yystack[yypParser->yyidx]; -#ifndef NDEBUG - if( yyTraceFILE && yyruleno>=0 - && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ - fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt, - yyRuleName[yyruleno]); - } -#endif /* NDEBUG */ - - /* Silence complaints from purify about yygotominor being uninitialized - ** in some cases when it is copied into the stack after the following - ** switch. yygotominor is uninitialized when a rule reduces that does - ** not set the value of its left-hand side nonterminal. Leaving the - ** value of the nonterminal uninitialized is utterly harmless as long - ** as the value is never used. So really the only thing this code - ** accomplishes is to quieten purify. - ** - ** 2007-01-16: The wireshark project (www.wireshark.org) reports that - ** without this code, their parser segfaults. I'm not sure what there - ** parser is doing to make this happen. This is the second bug report - ** from wireshark this week. Clearly they are stressing Lemon in ways - ** that it has not been previously stressed... (SQLite ticket #2172) - */ - memset(&yygotominor, 0, sizeof(yygotominor)); - - - switch( yyruleno ){ - /* Beginning here are the reduction cases. A typical example - ** follows: - ** case 0: - ** #line - ** { ... } // User supplied code - ** #line - ** break; - */ -%% - }; - yygoto = yyRuleInfo[yyruleno].lhs; - yysize = yyRuleInfo[yyruleno].nrhs; - yypParser->yyidx -= yysize; - yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto); - if( yyact < YYNSTATE ){ -#ifdef NDEBUG - /* If we are not debugging and the reduce action popped at least - ** one element off the stack, then we can push the new element back - ** onto the stack here, and skip the stack overflow test in yy_shift(). - ** That gives a significant speed improvement. */ - if( yysize ){ - yypParser->yyidx++; - yymsp -= yysize-1; - yymsp->stateno = yyact; - yymsp->major = yygoto; - yymsp->minor = yygotominor; - }else -#endif - { - yy_shift(yypParser,yyact,yygoto,&yygotominor); - } - }else if( yyact == YYNSTATE + YYNRULE + 1 ){ - yy_accept(yypParser); - } -} - -/* -** The following code executes when the parse fails -*/ -static void yy_parse_failed( - yyParser *yypParser /* The parser */ -){ - ParseARG_FETCH; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); - } -#endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will be executed whenever the - ** parser fails */ -%% - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -/* -** The following code executes when a syntax error first occurs. -*/ -static void yy_syntax_error( - yyParser *yypParser, /* The parser */ - int yymajor, /* The major type of the error token */ - YYMINORTYPE yyminor /* The minor type of the error token */ -){ - ParseARG_FETCH; -#define TOKEN (yyminor.yy0) -%% - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -/* -** The following is executed when the parser accepts -*/ -static void yy_accept( - yyParser *yypParser /* The parser */ -){ - ParseARG_FETCH; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); - } -#endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will be executed whenever the - ** parser accepts */ -%% - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -/* The main parser program. -** The first argument is a pointer to a structure obtained from -** "ParseAlloc" which describes the current state of the parser. -** The second argument is the major token number. The third is -** the minor token. The fourth optional argument is whatever the -** user wants (and specified in the grammar) and is available for -** use by the action routines. -** -** Inputs: -**
    -**
  • A pointer to the parser (an opaque structure.) -**
  • The major token number. -**
  • The minor token number. -**
  • An option argument of a grammar-specified type. -**
-** -** Outputs: -** None. -*/ -void Parse( - void *yyp, /* The parser */ - int yymajor, /* The major token code number */ - ParseTOKENTYPE yyminor /* The value for the token */ - ParseARG_PDECL /* Optional %extra_argument parameter */ -){ - YYMINORTYPE yyminorunion; - int yyact; /* The parser action. */ - int yyendofinput; /* True if we are at the end of input */ - int yyerrorhit = 0; /* True if yymajor has invoked an error */ - yyParser *yypParser; /* The parser */ - - /* (re)initialize the parser, if necessary */ - yypParser = (yyParser*)yyp; - if( yypParser->yyidx<0 ){ - /* if( yymajor==0 ) return; // not sure why this was here... */ - yypParser->yyidx = 0; - yypParser->yyerrcnt = -1; - yypParser->yystack[0].stateno = 0; - yypParser->yystack[0].major = 0; - } - yyminorunion.yy0 = yyminor; - yyendofinput = (yymajor==0); - ParseARG_STORE; - -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); - } -#endif - - do{ - yyact = yy_find_shift_action(yypParser,yymajor); - if( yyactyyerrcnt--; - if( yyendofinput && yypParser->yyidx>=0 ){ - yymajor = 0; - }else{ - yymajor = YYNOCODE; - while( yypParser->yyidx>= 0 && (yyact = yy_find_shift_action(yypParser,YYNOCODE)) < YYNSTATE + YYNRULE ){ - yy_reduce(yypParser,yyact-YYNSTATE); - } - } - }else if( yyact < YYNSTATE + YYNRULE ){ - yy_reduce(yypParser,yyact-YYNSTATE); - }else if( yyact == YY_ERROR_ACTION ){ - int yymx; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); - } -#endif -#ifdef YYERRORSYMBOL - /* A syntax error has occurred. - ** The response to an error depends upon whether or not the - ** grammar defines an error token "ERROR". - ** - ** This is what we do if the grammar does define ERROR: - ** - ** * Call the %syntax_error function. - ** - ** * Begin popping the stack until we enter a state where - ** it is legal to shift the error symbol, then shift - ** the error symbol. - ** - ** * Set the error count to three. - ** - ** * Begin accepting and shifting new tokens. No new error - ** processing will occur until three tokens have been - ** shifted successfully. - ** - */ - if( yypParser->yyerrcnt<0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); - } - yymx = yypParser->yystack[yypParser->yyidx].major; - if( yymx==YYERRORSYMBOL || yyerrorhit ){ -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sDiscard input token %s\n", - yyTracePrompt,yyTokenName[yymajor]); - } -#endif - yy_destructor(yymajor,&yyminorunion); - yymajor = YYNOCODE; - }else{ - while( - yypParser->yyidx >= 0 && - yymx != YYERRORSYMBOL && - (yyact = yy_find_reduce_action( - yypParser->yystack[yypParser->yyidx].stateno, - YYERRORSYMBOL)) >= YYNSTATE - ){ - yy_pop_parser_stack(yypParser); - } - if( yypParser->yyidx < 0 || yymajor==0 ){ - yy_destructor(yymajor,&yyminorunion); - yy_parse_failed(yypParser); - yymajor = YYNOCODE; - }else if( yymx!=YYERRORSYMBOL ){ - YYMINORTYPE u2; - u2.YYERRSYMDT = 0; - yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); - } - } - yypParser->yyerrcnt = 3; - yyerrorhit = 1; -#else /* YYERRORSYMBOL is not defined */ - /* This is what we do if the grammar does not define ERROR: - ** - ** * Report an error message, and throw away the input token. - ** - ** * If the input token is $, then fail the parse. - ** - ** As before, subsequent error messages are suppressed until - ** three input tokens have been successfully shifted. - */ - if( yypParser->yyerrcnt<=0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); - } - yypParser->yyerrcnt = 3; - yy_destructor(yymajor,&yyminorunion); - if( yyendofinput ){ - yy_parse_failed(yypParser); - } - yymajor = YYNOCODE; -#endif - }else{ - yy_accept(yypParser); - yymajor = YYNOCODE; - } - }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); - return; -} +/* Driver template for the LEMON parser generator. +** The author disclaims copyright to this source code. +*/ +/* First off, code is included which follows the "include" declaration +** in the input file. */ +#include +#include +#include +%% +/* Next is all token values, in a form suitable for use by makeheaders. +** This section will be null unless lemon is run with the -m switch. +*/ +/* +** These constants (all generated automatically by the parser generator) +** specify the various kinds of tokens (terminals) that the parser +** understands. +** +** Each symbol here is a terminal symbol in the grammar. +*/ +%% +/* Make sure the INTERFACE macro is defined. +*/ +#ifndef INTERFACE +# define INTERFACE 1 +#endif +/* The next thing included is series of defines which control +** various aspects of the generated parser. +** YYCODETYPE is the data type used for storing terminal +** and nonterminal numbers. "unsigned char" is +** used if there are fewer than 250 terminals +** and nonterminals. "int" is used otherwise. +** YYNOCODE is a number of type YYCODETYPE which corresponds +** to no legal terminal or nonterminal number. This +** number is used to fill in empty slots of the hash +** table. +** YYFALLBACK If defined, this indicates that one or more tokens +** have fall-back values which should be used if the +** original value of the token will not parse. +** YYACTIONTYPE is the data type used for storing terminal +** and nonterminal numbers. "unsigned char" is +** used if there are fewer than 250 rules and +** states combined. "int" is used otherwise. +** ParseTOKENTYPE is the data type used for minor tokens given +** directly to the parser from the tokenizer. +** YYMINORTYPE is the data type used for all minor tokens. +** This is typically a union of many types, one of +** which is ParseTOKENTYPE. The entry in the union +** for base tokens is called "yy0". +** YYSTACKDEPTH is the maximum depth of the parser's stack. If +** zero the stack is dynamically sized using realloc() +** ParseARG_SDECL A static variable declaration for the %extra_argument +** ParseARG_PDECL A parameter declaration for the %extra_argument +** ParseARG_STORE Code to store %extra_argument into yypParser +** ParseARG_FETCH Code to extract %extra_argument from yypParser +** YYNSTATE the combined number of states. +** YYNRULE the number of rules in the grammar +** YYERRORSYMBOL is the code number of the error symbol. If not +** defined, then do no error processing. +*/ +%% +#define YY_NO_ACTION (YYNSTATE+YYNRULE+2) +#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) +#define YY_ERROR_ACTION (YYNSTATE+YYNRULE) + +/* Next are that tables used to determine what action to take based on the +** current state and lookahead token. These tables are used to implement +** functions that take a state number and lookahead value and return an +** action integer. +** +** Suppose the action integer is N. Then the action is determined as +** follows +** +** 0 <= N < YYNSTATE Shift N. That is, push the lookahead +** token onto the stack and goto state N. +** +** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE. +** +** N == YYNSTATE+YYNRULE A syntax error has occurred. +** +** N == YYNSTATE+YYNRULE+1 The parser accepts its input. +** +** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused +** slots in the yy_action[] table. +** +** The action table is constructed as a single large table named yy_action[]. +** Given state S and lookahead X, the action is computed as +** +** yy_action[ yy_shift_ofst[S] + X ] +** +** If the index value yy_shift_ofst[S]+X is out of range or if the value +** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] +** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table +** and that yy_default[S] should be used instead. +** +** The formula above is for computing the action when the lookahead is +** a terminal symbol. If the lookahead is a non-terminal (as occurs after +** a reduce action) then the yy_reduce_ofst[] array is used in place of +** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of +** YY_SHIFT_USE_DFLT. +** +** The following are the tables generated in this section: +** +** yy_action[] A single table containing all actions. +** yy_lookahead[] A table containing the lookahead for each entry in +** yy_action. Used to detect hash collisions. +** yy_shift_ofst[] For each state, the offset into yy_action for +** shifting terminals. +** yy_reduce_ofst[] For each state, the offset into yy_action for +** shifting non-terminals after a reduce. +** yy_default[] Default action for each state. +*/ +%% +#define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0])) + +/* The next table maps tokens into fallback tokens. If a construct +** like the following: +** +** %fallback ID X Y Z. +** +** appears in the grammer, then ID becomes a fallback token for X, Y, +** and Z. Whenever one of the tokens X, Y, or Z is input to the parser +** but it does not parse, the type of the token is changed to ID and +** the parse is retried before an error is thrown. +*/ +#ifdef YYFALLBACK +static const YYCODETYPE yyFallback[] = { +%% +}; +#endif /* YYFALLBACK */ + +/* The following structure represents a single element of the +** parser's stack. Information stored includes: +** +** + The state number for the parser at this level of the stack. +** +** + The value of the token stored at this level of the stack. +** (In other words, the "major" token.) +** +** + The semantic value stored at this level of the stack. This is +** the information used by the action routines in the grammar. +** It is sometimes called the "minor" token. +*/ +struct yyStackEntry { + int stateno; /* The state-number */ + int major; /* The major token value. This is the code + ** number for the token at this stack level */ + YYMINORTYPE minor; /* The user-supplied minor token value. This + ** is the value of the token */ +}; +typedef struct yyStackEntry yyStackEntry; + +/* The state of the parser is completely contained in an instance of +** the following structure */ +struct yyParser { + int yyidx; /* Index of top element in stack */ + int yyerrcnt; /* Shifts left before out of the error */ + ParseARG_SDECL /* A place to hold %extra_argument */ +#if YYSTACKDEPTH<=0 + int yystksz; /* Current side of the stack */ + yyStackEntry *yystack; /* The parser's stack */ +#else + yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ +#endif +}; +typedef struct yyParser yyParser; + +#ifndef NDEBUG +#include +static FILE *yyTraceFILE = 0; +static char *yyTracePrompt = 0; +#endif /* NDEBUG */ + +#ifndef NDEBUG +/* +** Turn parser tracing on by giving a stream to which to write the trace +** and a prompt to preface each trace message. Tracing is turned off +** by making either argument NULL +** +** Inputs: +**
    +**
  • A FILE* to which trace output should be written. +** If NULL, then tracing is turned off. +**
  • A prefix string written at the beginning of every +** line of trace output. If NULL, then tracing is +** turned off. +**
+** +** Outputs: +** None. +*/ +void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ + yyTraceFILE = TraceFILE; + yyTracePrompt = zTracePrompt; + if( yyTraceFILE==0 ) yyTracePrompt = 0; + else if( yyTracePrompt==0 ) yyTraceFILE = 0; +} +#endif /* NDEBUG */ + +#ifndef NDEBUG +/* For tracing shifts, the names of all terminals and nonterminals +** are required. The following table supplies these names */ +static const char *const yyTokenName[] = { +%% +}; +#endif /* NDEBUG */ + +#ifndef NDEBUG +/* For tracing reduce actions, the names of all rules are required. +*/ +static const char *const yyRuleName[] = { +%% +}; +#endif /* NDEBUG */ + +#if YYSTACKDEPTH<=0 +/* +** Try to increase the size of the parser stack. +*/ +static void yyGrowStack(yyParser *p){ + int newSize; + yyStackEntry *pNew; + + newSize = p->yystksz*2 + 100; + pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); + if( pNew ){ + p->yystack = pNew; + p->yystksz = newSize; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sStack grows to %d entries!\n", + yyTracePrompt, p->yystksz); + } +#endif + } +} +#endif + +/* +** This function allocates a new parser. +** The only argument is a pointer to a function which works like +** malloc. +** +** Inputs: +** A pointer to the function used to allocate memory. +** +** Outputs: +** A pointer to a parser. This pointer is used in subsequent calls +** to Parse and ParseFree. +*/ +void *ParseAlloc(void *(*mallocProc)(size_t)){ + yyParser *pParser; + pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); + if( pParser ){ + pParser->yyidx = -1; +#if YYSTACKDEPTH<=0 + yyGrowStack(pParser); +#endif + } + return pParser; +} + +/* The following function deletes the value associated with a +** symbol. The symbol can be either a terminal or nonterminal. +** "yymajor" is the symbol code, and "yypminor" is a pointer to +** the value. +*/ +static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ + switch( yymajor ){ + /* Here is inserted the actions which take place when a + ** terminal or non-terminal is destroyed. This can happen + ** when the symbol is popped from the stack during a + ** reduce or during error processing or when a parser is + ** being destroyed before it is finished parsing. + ** + ** Note: during a reduce, the only symbols destroyed are those + ** which appear on the RHS of the rule, but which are not used + ** inside the C code. + */ +%% + default: break; /* If no destructor action specified: do nothing */ + } +} + +/* +** Pop the parser's stack once. +** +** If there is a destructor routine associated with the token which +** is popped from the stack, then call it. +** +** Return the major token number for the symbol popped. +*/ +static int yy_pop_parser_stack(yyParser *pParser){ + YYCODETYPE yymajor; + yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; + + if( pParser->yyidx<0 ) return 0; +#ifndef NDEBUG + if( yyTraceFILE && pParser->yyidx>=0 ){ + fprintf(yyTraceFILE,"%sPopping %s\n", + yyTracePrompt, + yyTokenName[yytos->major]); + } +#endif + yymajor = yytos->major; + yy_destructor( yymajor, &yytos->minor); + pParser->yyidx--; + return yymajor; +} + +/* +** Deallocate and destroy a parser. Destructors are all called for +** all stack elements before shutting the parser down. +** +** Inputs: +**
    +**
  • A pointer to the parser. This should be a pointer +** obtained from ParseAlloc. +**
  • A pointer to a function used to reclaim memory obtained +** from malloc. +**
+*/ +void ParseFree( + void *p, /* The parser to be deleted */ + void (*freeProc)(void*) /* Function used to reclaim memory */ +){ + yyParser *pParser = (yyParser*)p; + if( pParser==0 ) return; + while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); +#if YYSTACKDEPTH<=0 + free(pParser->yystack); +#endif + (*freeProc)((void*)pParser); +} + +/* +** Find the appropriate action for a parser given the terminal +** look-ahead token iLookAhead. +** +** If the look-ahead token is YYNOCODE, then check to see if the action is +** independent of the look-ahead. If it is, return the action, otherwise +** return YY_NO_ACTION. +*/ +static int yy_find_shift_action( + yyParser *pParser, /* The parser */ + YYCODETYPE iLookAhead /* The look-ahead token */ +){ + int i; + int stateno = pParser->yystack[pParser->yyidx].stateno; + + if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){ + return yy_default[stateno]; + } + if( iLookAhead==YYNOCODE ){ + return YY_NO_ACTION; + } + i += iLookAhead; + if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ + if( iLookAhead>0 ){ +#ifdef YYFALLBACK + int iFallback; /* Fallback token */ + if( iLookAhead %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); + } +#endif + return yy_find_shift_action(pParser, iFallback); + } +#endif +#ifdef YYWILDCARD + { + int j = i - iLookAhead + YYWILDCARD; + if( j>=0 && j %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]); + } +#endif /* NDEBUG */ + return yy_action[j]; + } + } +#endif /* YYWILDCARD */ + } + return yy_default[stateno]; + }else{ + return yy_action[i]; + } +} + +/* +** Find the appropriate action for a parser given the non-terminal +** look-ahead token iLookAhead. +** +** If the look-ahead token is YYNOCODE, then check to see if the action is +** independent of the look-ahead. If it is, return the action, otherwise +** return YY_NO_ACTION. +*/ +static int yy_find_reduce_action( + int stateno, /* Current state number */ + YYCODETYPE iLookAhead /* The look-ahead token */ +){ + int i; + assert( stateno<=YY_REDUCE_MAX ); + i = yy_reduce_ofst[stateno]; + assert( i!=YY_REDUCE_USE_DFLT ); + assert( iLookAhead!=YYNOCODE ); + i += iLookAhead; + assert( i>=0 && iyyidx--; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); + } +#endif + while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + /* Here code is inserted which will execute if the parser + ** stack every overflows */ +%% + ParseARG_STORE; /* Suppress warning about unused %extra_argument var */ +} + +/* +** Perform a shift action. +*/ +static void yy_shift( + yyParser *yypParser, /* The parser to be shifted */ + int yyNewState, /* The new state to shift in */ + int yyMajor, /* The major token to shift in */ + YYMINORTYPE *yypMinor /* Pointer ot the minor token to shift in */ +){ + yyStackEntry *yytos; + yypParser->yyidx++; +#if YYSTACKDEPTH>0 + if( yypParser->yyidx>=YYSTACKDEPTH ){ + yyStackOverflow(yypParser, yypMinor); + return; + } +#else + if( yypParser->yyidx>=yypParser->yystksz ){ + yyGrowStack(yypParser); + if( yypParser->yyidx>=yypParser->yystksz ){ + yyStackOverflow(yypParser, yypMinor); + return; + } + } +#endif + yytos = &yypParser->yystack[yypParser->yyidx]; + yytos->stateno = yyNewState; + yytos->major = yyMajor; + yytos->minor = *yypMinor; +#ifndef NDEBUG + if( yyTraceFILE && yypParser->yyidx>0 ){ + int i; + fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState); + fprintf(yyTraceFILE,"%sStack:",yyTracePrompt); + for(i=1; i<=yypParser->yyidx; i++) + fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); + fprintf(yyTraceFILE,"\n"); + } +#endif +} + +/* The following table contains information about every rule that +** is used during the reduce. +*/ +static const struct { + YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ + unsigned char nrhs; /* Number of right-hand side symbols in the rule */ +} yyRuleInfo[] = { +%% +}; + +static void yy_accept(yyParser*); /* Forward Declaration */ + +/* +** Perform a reduce action and the shift that must immediately +** follow the reduce. +*/ +static void yy_reduce( + yyParser *yypParser, /* The parser */ + int yyruleno /* Number of the rule by which to reduce */ +){ + int yygoto; /* The next state */ + int yyact; /* The next action */ + YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ + yyStackEntry *yymsp; /* The top of the parser's stack */ + int yysize; /* Amount to pop the stack */ + ParseARG_FETCH; + yymsp = &yypParser->yystack[yypParser->yyidx]; +#ifndef NDEBUG + if( yyTraceFILE && yyruleno>=0 + && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ + fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt, + yyRuleName[yyruleno]); + } +#endif /* NDEBUG */ + + /* Silence complaints from purify about yygotominor being uninitialized + ** in some cases when it is copied into the stack after the following + ** switch. yygotominor is uninitialized when a rule reduces that does + ** not set the value of its left-hand side nonterminal. Leaving the + ** value of the nonterminal uninitialized is utterly harmless as long + ** as the value is never used. So really the only thing this code + ** accomplishes is to quieten purify. + ** + ** 2007-01-16: The wireshark project (www.wireshark.org) reports that + ** without this code, their parser segfaults. I'm not sure what there + ** parser is doing to make this happen. This is the second bug report + ** from wireshark this week. Clearly they are stressing Lemon in ways + ** that it has not been previously stressed... (SQLite ticket #2172) + */ + memset(&yygotominor, 0, sizeof(yygotominor)); + + + switch( yyruleno ){ + /* Beginning here are the reduction cases. A typical example + ** follows: + ** case 0: + ** #line + ** { ... } // User supplied code + ** #line + ** break; + */ +%% + }; + yygoto = yyRuleInfo[yyruleno].lhs; + yysize = yyRuleInfo[yyruleno].nrhs; + yypParser->yyidx -= yysize; + yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto); + if( yyact < YYNSTATE ){ +#ifdef NDEBUG + /* If we are not debugging and the reduce action popped at least + ** one element off the stack, then we can push the new element back + ** onto the stack here, and skip the stack overflow test in yy_shift(). + ** That gives a significant speed improvement. */ + if( yysize ){ + yypParser->yyidx++; + yymsp -= yysize-1; + yymsp->stateno = yyact; + yymsp->major = yygoto; + yymsp->minor = yygotominor; + }else +#endif + { + yy_shift(yypParser,yyact,yygoto,&yygotominor); + } + }else{ + assert( yyact == YYNSTATE + YYNRULE + 1 ); + yy_accept(yypParser); + } +} + +/* +** The following code executes when the parse fails +*/ +static void yy_parse_failed( + yyParser *yypParser /* The parser */ +){ + ParseARG_FETCH; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); + } +#endif + while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + /* Here code is inserted which will be executed whenever the + ** parser fails */ +%% + ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} + +/* +** The following code executes when a syntax error first occurs. +*/ +static void yy_syntax_error( + yyParser *yypParser, /* The parser */ + int yymajor, /* The major type of the error token */ + YYMINORTYPE yyminor /* The minor type of the error token */ +){ + ParseARG_FETCH; +#define TOKEN (yyminor.yy0) +%% + ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} + +/* +** The following is executed when the parser accepts +*/ +static void yy_accept( + yyParser *yypParser /* The parser */ +){ + ParseARG_FETCH; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); + } +#endif + while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + /* Here code is inserted which will be executed whenever the + ** parser accepts */ +%% + ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} + +/* The main parser program. +** The first argument is a pointer to a structure obtained from +** "ParseAlloc" which describes the current state of the parser. +** The second argument is the major token number. The third is +** the minor token. The fourth optional argument is whatever the +** user wants (and specified in the grammar) and is available for +** use by the action routines. +** +** Inputs: +**
    +**
  • A pointer to the parser (an opaque structure.) +**
  • The major token number. +**
  • The minor token number. +**
  • An option argument of a grammar-specified type. +**
+** +** Outputs: +** None. +*/ +void Parse( + void *yyp, /* The parser */ + int yymajor, /* The major token code number */ + ParseTOKENTYPE yyminor /* The value for the token */ + ParseARG_PDECL /* Optional %extra_argument parameter */ +){ + YYMINORTYPE yyminorunion; + int yyact; /* The parser action. */ + int yyendofinput; /* True if we are at the end of input */ +#ifdef YYERRORSYMBOL + int yyerrorhit = 0; /* True if yymajor has invoked an error */ +#endif + yyParser *yypParser; /* The parser */ + + /* (re)initialize the parser, if necessary */ + yypParser = (yyParser*)yyp; + if( yypParser->yyidx<0 ){ +#if YYSTACKDEPTH<=0 + if( yypParser->yystksz <=0 ){ + memset(&yyminorunion, 0, sizeof(yyminorunion)); + yyStackOverflow(yypParser, &yyminorunion); + return; + } +#endif + yypParser->yyidx = 0; + yypParser->yyerrcnt = -1; + yypParser->yystack[0].stateno = 0; + yypParser->yystack[0].major = 0; + } + yyminorunion.yy0 = yyminor; + yyendofinput = (yymajor==0); + ParseARG_STORE; + +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); + } +#endif + + do{ + yyact = yy_find_shift_action(yypParser,yymajor); + if( yyactyyerrcnt--; + yymajor = YYNOCODE; + /* [RH] If we can reduce the stack now, do it. Otherwise, constructs */ + /* like "include " won't work because the next token after */ + /* the include will be shifted before the include is reduced. Then the */ + /* parser will act as if that token had been the first one in the */ + /* included file. */ + while( yypParser->yyidx>= 0 && (yyact = yy_find_shift_action(yypParser,YYNOCODE)) < YYNSTATE + YYNRULE ){ + yy_reduce(yypParser,yyact-YYNSTATE); + } + }else if( yyact < YYNSTATE + YYNRULE ){ + yy_reduce(yypParser,yyact-YYNSTATE); + }else{ +#ifdef YYERRORSYMBOL + int yymx; +#endif + assert( yyact == YY_ERROR_ACTION ); +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); + } +#endif +#ifdef YYERRORSYMBOL + /* A syntax error has occurred. + ** The response to an error depends upon whether or not the + ** grammar defines an error token "ERROR". + ** + ** This is what we do if the grammar does define ERROR: + ** + ** * Call the %syntax_error function. + ** + ** * Begin popping the stack until we enter a state where + ** it is legal to shift the error symbol, then shift + ** the error symbol. + ** + ** * Set the error count to three. + ** + ** * Begin accepting and shifting new tokens. No new error + ** processing will occur until three tokens have been + ** shifted successfully. + ** + */ + if( yypParser->yyerrcnt<0 ){ + yy_syntax_error(yypParser,yymajor,yyminorunion); + } + yymx = yypParser->yystack[yypParser->yyidx].major; + if( yymx==YYERRORSYMBOL || yyerrorhit ){ +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sDiscard input token %s\n", + yyTracePrompt,yyTokenName[yymajor]); + } +#endif + yy_destructor(yymajor,&yyminorunion); + yymajor = YYNOCODE; + }else{ + while( + yypParser->yyidx >= 0 && + yymx != YYERRORSYMBOL && + (yyact = yy_find_reduce_action( + yypParser->yystack[yypParser->yyidx].stateno, + YYERRORSYMBOL)) >= YYNSTATE + ){ + yy_pop_parser_stack(yypParser); + } + if( yypParser->yyidx < 0 || yymajor==0 ){ + yy_destructor(yymajor,&yyminorunion); + yy_parse_failed(yypParser); + yymajor = YYNOCODE; + }else if( yymx!=YYERRORSYMBOL ){ + YYMINORTYPE u2; + u2.YYERRSYMDT = 0; + yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); + } + } + yypParser->yyerrcnt = 3; + yyerrorhit = 1; +#else /* YYERRORSYMBOL is not defined */ + /* This is what we do if the grammar does not define ERROR: + ** + ** * Report an error message, and throw away the input token. + ** + ** * If the input token is $, then fail the parse. + ** + ** As before, subsequent error messages are suppressed until + ** three input tokens have been successfully shifted. + */ + if( yypParser->yyerrcnt<=0 ){ + yy_syntax_error(yypParser,yymajor,yyminorunion); + } + yypParser->yyerrcnt = 3; + yy_destructor(yymajor,&yyminorunion); + if( yyendofinput ){ + yy_parse_failed(yypParser); + } + yymajor = YYNOCODE; +#endif + } + }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); + return; +} diff --git a/tools/re2c/actions.cc b/tools/re2c/actions.cc index f9fd327f3f..edb5d53a12 100644 --- a/tools/re2c/actions.cc +++ b/tools/re2c/actions.cc @@ -14,6 +14,11 @@ namespace re2c void Symbol::ClearTable() { + for (SymbolTable::iterator it = symbol_table.begin(); it != symbol_table.end(); ++it) + { + delete it->second; + } + symbol_table.clear(); } @@ -519,7 +524,7 @@ uint Scanner::unescape(SubStr &s) const static const char * oct = "01234567"; s.len--; - uint c; + uint c, ucb = 0; if ((c = *s.str++) != '\\' || s.len == 0) { @@ -582,10 +587,20 @@ uint Scanner::unescape(SubStr &s) const if (s.str[1] == '0') { l++; - if (s.str[2] == '0') + if (s.str[2] == '0' || (s.str[2] == '1' && uFlag)) { l++; - if (s.str[3] == '0') + if (uFlag) { + const char *u3 = strchr(hex, tolower(s.str[2])); + const char *u4 = strchr(hex, tolower(s.str[3])); + if (u3 && u4) + { + ucb = (uint)((u3 - hex) << 20) + + (uint)((u4 - hex) << 16); + l++; + } + } + else if (s.str[3] == '0') { l++; } @@ -636,7 +651,8 @@ uint Scanner::unescape(SubStr &s) const uint v = (uint)((p1 - hex) << 12) + (uint)((p2 - hex) << 8) + (uint)((p3 - hex) << 4) - + (uint)((p4 - hex)); + + (uint)((p4 - hex)) + + ucb; if (v >= nRealChars) { diff --git a/tools/re2c/code.cc b/tools/re2c/code.cc index db391046ee..38477a24b8 100644 --- a/tools/re2c/code.cc +++ b/tools/re2c/code.cc @@ -29,8 +29,8 @@ std::string indent(uint ind) static std::string space(uint this_label) { - int nl = next_label > 9999 ? 4 : next_label > 999 ? 3 : next_label > 99 ? 2 : next_label > 9 ? 1 : 0; - int tl = this_label > 9999 ? 4 : this_label > 999 ? 3 : this_label > 99 ? 2 : this_label > 9 ? 1 : 0; + int nl = next_label > 999999 ? 6 : next_label > 99999 ? 5 : next_label > 9999 ? 4 : next_label > 999 ? 3 : next_label > 99 ? 2 : next_label > 9 ? 1 : 0; + int tl = this_label > 999999 ? 6 : this_label > 99999 ? 5 : this_label > 9999 ? 4 : this_label > 999 ? 3 : this_label > 99 ? 2 : this_label > 9 ? 1 : 0; return std::string(std::max(1, nl - tl + 1), ' '); } @@ -180,10 +180,7 @@ BitMap::BitMap(const Go *g, const State *x) BitMap::~BitMap() { - if (next) - { - delete next; - } + delete next; } const BitMap *BitMap::find(const Go *g, const State *x) @@ -214,18 +211,17 @@ const BitMap *BitMap::find(const State *x) void BitMap::gen(std::ostream &o, uint ind, uint lb, uint ub) { - BitMap *b = first; - - if (b && bLastPass) + if (first && bLastPass) { - o << indent(ind) << "static unsigned char yybm[] = {"; + o << indent(ind) << "static const unsigned char " << mapCodeName["yybm"] << "[] = {"; uint c = 1, n = ub - lb; + const BitMap *cb = first; - while((b = const_cast(b->next)) != NULL) { + while((cb = cb->next) != NULL) { ++c; } - b = first; + BitMap *b = first; uint *bm = new uint[n]; @@ -291,27 +287,28 @@ void genGoTo(std::ostream &o, uint ind, const State *from, const State *to, bool { if (readCh && from->label + 1 != to->label) { - o << indent(ind) << "yych = *YYCURSOR;\n"; + o << indent(ind) << mapCodeName["yych"] << " = " << yychConversion << "*" << mapCodeName["YYCURSOR"] << ";\n"; readCh = false; } - o << indent(ind) << "goto yy" << to->label << ";\n"; + o << indent(ind) << "goto " << labelPrefix << to->label << ";\n"; vUsedLabels.insert(to->label); } void genIf(std::ostream &o, uint ind, const char *cmp, uint v, bool &readCh) { + o << indent(ind) << "if("; if (readCh) { - o << indent(ind) << "if((yych = *YYCURSOR) "; + o << "(" << mapCodeName["yych"] << " = " << yychConversion << "*" << mapCodeName["YYCURSOR"] << ")"; readCh = false; } else { - o << indent(ind) << "if(yych "; + o << mapCodeName["yych"]; } - o << cmp << " "; + o << " " << cmp << " "; prtChOrHex(o, v); o << ") "; } @@ -323,33 +320,38 @@ static void need(std::ostream &o, uint ind, uint n, bool & readCh, bool bSetMark if (fFlag) { next_fill_index++; - o << indent(ind) << "YYSETSTATE(" << fillIndex << ");\n"; + o << indent(ind) << mapCodeName["YYSETSTATE"] << "(" << fillIndex << ");\n"; } if (bUseYYFill) { if (n == 1) { - o << indent(ind) << "if(YYLIMIT == YYCURSOR) YYFILL(1);\n"; + o << indent(ind) << "if(" << mapCodeName["YYLIMIT"] << " == " << mapCodeName["YYCURSOR"] << ") " << mapCodeName["YYFILL"]; } else { o << indent(ind) << "if((YYLIMIT - YYCURSOR) < " << n << ") YYFILL(" << n << ");\n"; } + if (bUseYYFillParam) + { + o << "(" << n << ")"; + } + o << ";\n"; } if (fFlag) { - o << "yyFillLabel" << fillIndex << ":\n"; + o << mapCodeName["yyFillLabel"] << fillIndex << ":\n"; } if (bSetMarker) { - o << indent(ind) << "yych = *(YYMARKER = YYCURSOR);\n"; + o << indent(ind) << mapCodeName["yych"] << " = " << yychConversion << "*(" << mapCodeName["YYMARKER"] << " = " << mapCodeName["YYCURSOR"] << ");\n"; } else { - o << indent(ind) << "yych = *YYCURSOR;\n"; + o << indent(ind) << mapCodeName["yych"] << " = " << yychConversion << "*" << mapCodeName["YYCURSOR"] << ";\n"; } readCh = false; } @@ -358,17 +360,17 @@ void Match::emit(std::ostream &o, uint ind, bool &readCh) const { if (state->link) { - o << indent(ind) << "++YYCURSOR;\n"; + o << indent(ind) << "++" << mapCodeName["YYCURSOR"] << ";\n"; } else if (!readAhead()) { /* do not read next char if match */ - o << indent(ind) << "++YYCURSOR;\n"; + o << indent(ind) << "++" << mapCodeName["YYCURSOR"] << ";\n"; readCh = true; } else { - o << indent(ind) << "yych = *++YYCURSOR;\n"; + o << indent(ind) << mapCodeName["yych"] << " = " << yychConversion << "*++" << mapCodeName["YYCURSOR"] << ";\n"; readCh = false; } @@ -382,20 +384,20 @@ void Enter::emit(std::ostream &o, uint ind, bool &readCh) const { if (state->link) { - o << indent(ind) << "++YYCURSOR;\n"; + o << indent(ind) << "++" << mapCodeName["YYCURSOR"] << ";\n"; if (vUsedLabels.count(label)) { - o << "yy" << label << ":\n"; + o << labelPrefix << label << ":\n"; } need(o, ind, state->depth, readCh, false); } else { /* we shouldn't need 'rule-following' protection here */ - o << indent(ind) << "yych = *++YYCURSOR;\n"; + o << indent(ind) << mapCodeName["yych"] << " = " << yychConversion << "*++" << mapCodeName["YYCURSOR"] << ";\n"; if (vUsedLabels.count(label)) { - o << "yy" << label << ":\n"; + o << labelPrefix << label << ":\n"; } readCh = false; } @@ -412,17 +414,17 @@ void Initial::emit(std::ostream &o, uint ind, bool &readCh) const { if (state->link) { - o << indent(ind) << "++YYCURSOR;\n"; + o << indent(ind) << "++" << mapCodeName["YYCURSOR"] << ";\n"; } else { - o << indent(ind) << "yych = *++YYCURSOR;\n"; + o << indent(ind) << mapCodeName["yych"] << " = " << yychConversion << "*++" << mapCodeName["YYCURSOR"] << ";\n"; } } if (vUsedLabels.count(label)) { - o << "yy" << label << ":\n"; + o << labelPrefix << label << ":\n"; } else if (!label) { @@ -431,7 +433,7 @@ void Initial::emit(std::ostream &o, uint ind, bool &readCh) const if (dFlag) { - o << indent(ind) << "YYDEBUG(" << label << ", *YYCURSOR);\n"; + o << indent(ind) << mapCodeName["YYDEBUG"] << "(" << label << ", *" << mapCodeName["YYCURSOR"] << ");\n"; } if (state->link) @@ -442,7 +444,7 @@ void Initial::emit(std::ostream &o, uint ind, bool &readCh) const { if (setMarker && bUsedYYMarker) { - o << indent(ind) << "YYMARKER = YYCURSOR;\n"; + o << indent(ind) << mapCodeName["YYMARKER"] << " = " << mapCodeName["YYCURSOR"] << ";\n"; } readCh = false; } @@ -452,14 +454,14 @@ void Save::emit(std::ostream &o, uint ind, bool &readCh) const { if (bUsedYYAccept) { - o << indent(ind) << "yyaccept = " << selector << ";\n"; + o << indent(ind) << mapCodeName["yyaccept"] << " = " << selector << ";\n"; } if (state->link) { if (bUsedYYMarker) { - o << indent(ind) << "YYMARKER = ++YYCURSOR;\n"; + o << indent(ind) << mapCodeName["YYMARKER"] << " = ++" << mapCodeName["YYCURSOR"] << ";\n"; } need(o, ind, state->depth, readCh, false); } @@ -467,11 +469,11 @@ void Save::emit(std::ostream &o, uint ind, bool &readCh) const { if (bUsedYYMarker) { - o << indent(ind) << "yych = *(YYMARKER = ++YYCURSOR);\n"; + o << indent(ind) << mapCodeName["yych"] << " = " << yychConversion << "*(" << mapCodeName["YYMARKER"] << " = ++" << mapCodeName["YYCURSOR"] << ");\n"; } else { - o << indent(ind) << "yych = *++YYCURSOR;\n"; + o << indent(ind) << mapCodeName["yych"] << " = " << yychConversion << "*++" << mapCodeName["YYCURSOR"] << ";\n"; } readCh = false; } @@ -510,7 +512,7 @@ void Accept::emitBinary(std::ostream &o, uint ind, uint l, uint r, bool &readCh) { uint m = (l + r) >> 1; - o << indent(ind) << "if(yyaccept <= " << m << ") {\n"; + o << indent(ind) << "if(" << mapCodeName["yyaccept"] << " <= " << m << ") {\n"; emitBinary(o, ++ind, l, m, readCh); o << indent(--ind) << "} else {\n"; emitBinary(o, ++ind, m + 1, r, readCh); @@ -527,11 +529,11 @@ void Accept::emit(std::ostream &o, uint ind, bool &readCh) const if (mapRules.size() > 0) { bUsedYYMarker = true; - o << indent(ind) << "YYCURSOR = YYMARKER;\n"; + o << indent(ind) << mapCodeName["YYCURSOR"] << " = " << mapCodeName["YYMARKER"] << ";\n"; if (readCh) // shouldn't be necessary, but might become at some point { - o << indent(ind) << "yych = *YYCURSOR;\n"; + o << indent(ind) << mapCodeName["yych"] << " = " << yychConversion << "*" << mapCodeName["YYCURSOR"] << ";\n"; readCh = false; } @@ -542,14 +544,14 @@ void Accept::emit(std::ostream &o, uint ind, bool &readCh) const if (gFlag && mapRules.size() >= cGotoThreshold) { o << indent(ind++) << "{\n"; - o << indent(ind++) << "static void *yytarget[" << mapRules.size() << "] = {\n"; + o << indent(ind++) << "static void *" << mapCodeName["yytarget"] << "[" << mapRules.size() << "] = {\n"; for (RuleMap::const_iterator it = mapRules.begin(); it != mapRules.end(); ++it) { - o << indent(ind) << "&&yy" << it->second->label << ",\n"; + o << indent(ind) << "&&" << labelPrefix << it->second->label << ",\n"; vUsedLabels.insert(it->second->label); } o << indent(--ind) << "};\n"; - o << indent(ind) << "goto *yytarget[yyaccept];\n"; + o << indent(ind) << "goto *" << mapCodeName["yytarget"] << "[" << mapCodeName["yyaccept"] << "];\n"; o << indent(--ind) << "}\n"; } else if (sFlag) @@ -558,7 +560,7 @@ void Accept::emit(std::ostream &o, uint ind, bool &readCh) const } else { - o << indent(ind) << "switch(yyaccept) {\n"; + o << indent(ind) << "switch(" << mapCodeName["yyaccept"] << ") {\n"; for (RuleMap::const_iterator it = mapRules.begin(); it != mapRules.end(); ++it) { @@ -588,7 +590,7 @@ void Rule::emit(std::ostream &o, uint ind, bool &) const if (back != 0u) { - o << indent(ind) << "YYCURSOR = YYCTXMARKER;\n"; + o << indent(ind) << mapCodeName["YYCURSOR"] << " = " << mapCodeName["YYCTXMARKER"] << ";\n"; } RuleLine rl(*rule); @@ -739,17 +741,17 @@ void Go::genSwitch(std::ostream &o, uint ind, const State *from, const State *ne if (dFlag) { - o << indent(ind) << "YYDEBUG(-1, yych);\n"; + o << indent(ind) << mapCodeName["YYDEBUG"] << "(-1, " << mapCodeName["yych"] << ");\n"; } if (readCh) { - o << indent(ind) << "switch((yych = *YYCURSOR)) {\n"; + o << indent(ind) << "switch((" << mapCodeName["yych"] << " = " << yychConversion << "*" << mapCodeName["YYCURSOR"] << ")) {\n"; readCh = false; } else { - o << indent(ind) << "switch(yych){\n"; + o << indent(ind) << "switch(" << mapCodeName["yych"] << ") {\n"; } while (t != &sP[0]) @@ -893,21 +895,30 @@ void Go::genBase(std::ostream &o, uint ind, const State *from, const State *next void Go::genCpGoto(std::ostream &o, uint ind, const State *from, const State *next, bool &readCh) const { - const char * sYych = readCh ? "(yych = *YYCURSOR)" : "yych"; + std::string sYych; + + if (readCh) + { + sYych = "(" + mapCodeName["yych"] + " = " + yychConversion + "*" + mapCodeName["YYCURSOR"] + ")"; + } + else + { + sYych = mapCodeName["yych"]; + } readCh = false; if (wFlag) { - o << indent(ind) << "if(" << sYych <<" & 0xFF00) {\n"; + o << indent(ind) << "if(" << sYych <<" & ~0xFF) {\n"; genBase(o, ind+1, from, next, readCh, 1); o << indent(ind++) << "} else {\n"; - sYych = "yych"; + sYych = mapCodeName["yych"]; } else { o << indent(ind++) << "{\n"; } - o << indent(ind++) << "static void *yytarget[256] = {\n"; + o << indent(ind++) << "static void *" << mapCodeName["yytarget"] << "[256] = {\n"; o << indent(ind); uint ch = 0; @@ -916,7 +927,7 @@ void Go::genCpGoto(std::ostream &o, uint ind, const State *from, const State *ne vUsedLabels.insert(span[i].to->label); for(; ch < span[i].ub; ++ch) { - o << "&&yy" << span[i].to->label; + o << "&&" << labelPrefix << span[i].to->label; if (ch == 255) { o << "\n"; @@ -934,7 +945,7 @@ void Go::genCpGoto(std::ostream &o, uint ind, const State *from, const State *ne } } o << indent(--ind) << "};\n"; - o << indent(ind) << "goto *yytarget[" << sYych << "];\n"; + o << indent(ind) << "goto *" << mapCodeName["yytarget"] << "[" << sYych << "];\n"; o << indent(--ind) << "}\n"; } @@ -997,19 +1008,26 @@ void Go::genGoto(std::ostream &o, uint ind, const State *from, const State *next if (to && to->isBase) { const BitMap *b = BitMap::find(to); - const char * sYych; + std::string sYych; if (b && matches(b->go, b->on, this, to)) { Go go; go.span = new Span[nSpans]; go.unmap(this, to); - sYych = readCh ? "(yych = *YYCURSOR)" : "yych"; + if (readCh) + { + sYych = "(" + mapCodeName["yych"] + " = " + yychConversion + "*" + mapCodeName["YYCURSOR"] + ")"; + } + else + { + sYych = mapCodeName["yych"]; + } readCh = false; if (wFlag) { - o << indent(ind) << "if(" << sYych << " & 0xFF00) {\n"; - sYych = "yych"; + o << indent(ind) << "if(" << sYych << " & ~0xFF) {\n"; + sYych = mapCodeName["yych"]; genBase(o, ind+1, from, next, readCh, 1); o << indent(ind) << "} else "; } @@ -1017,7 +1035,7 @@ void Go::genGoto(std::ostream &o, uint ind, const State *from, const State *next { o << indent(ind); } - o << "if(yybm[" << b->i << "+" << sYych << "] & "; + o << "if(" << mapCodeName["yybm"] << "[" << b->i << "+" << sYych << "] & "; if (yybmHexTable) { prtHex(o, b->m, false); @@ -1044,15 +1062,15 @@ void State::emit(std::ostream &o, uint ind, bool &readCh) const { if (vUsedLabels.count(label)) { - o << "yy" << label << ":\n"; + o << labelPrefix << label << ":\n"; } if (dFlag && !action->isInitial()) { - o << indent(ind) << "YYDEBUG(" << label << ", *YYCURSOR);\n"; + o << indent(ind) << mapCodeName["YYDEBUG"] << "(" << label << ", *" << mapCodeName["YYCURSOR"] << ");\n"; } if (isPreCtxt) { - o << indent(ind) << "YYCTXMARKER = YYCURSOR + 1;\n"; + o << indent(ind) << mapCodeName["YYCTXMARKER"] << " = " << mapCodeName["YYCURSOR"] << " + 1;\n"; } action->emit(o, ind, readCh); } @@ -1407,6 +1425,7 @@ void DFA::emit(std::ostream &o, uint ind) if (s->go.span[i].to && !s->go.span[i].to->rule) { delete s->action; + s->action = NULL; if (saves[s->rule->accept] == ~0u) { @@ -1500,6 +1519,7 @@ void DFA::emit(std::ostream &o, uint ind) findBaseState(); delete head->action; + head->action = NULL; if (bFlag) { @@ -1550,10 +1570,10 @@ void DFA::emit(std::ostream &o, uint ind) if (!fFlag) { - o << indent(ind) << "YYCTYPE yych;\n"; + o << indent(ind) << mapCodeName["YYCTYPE"] << " " << mapCodeName["yych"] << ";\n"; if (bUsedYYAccept) { - o << indent(ind) << "unsigned int yyaccept = 0;\n"; + o << indent(ind) << "unsigned int "<< mapCodeName["yyaccept"] << " = 0;\n"; } } else @@ -1566,7 +1586,7 @@ void DFA::emit(std::ostream &o, uint ind) if (vUsedLabels.count(1)) { vUsedLabels.insert(0); - o << indent(ind) << "goto yy0;\n"; + o << indent(ind) << "goto " << labelPrefix << "0;\n"; } // Generate code @@ -1602,26 +1622,26 @@ void genGetState(std::ostream &o, uint& ind, uint start_label) if (fFlag && !bWroteGetState) { vUsedLabels.insert(start_label); - o << indent(ind) << "switch(YYGETSTATE()) {\n"; + o << indent(ind) << "switch(" << mapCodeName["YYGETSTATE"] << "()) {\n"; if (bUseStateAbort) { o << indent(ind) << "default: abort();\n"; - o << indent(ind) << "case -1: goto yy" << start_label << ";\n"; + o << indent(ind) << "case -1: goto " << labelPrefix << start_label << ";\n"; } else { - o << indent(ind) << "default: goto yy" << start_label << ";\n"; + o << indent(ind) << "default: goto " << labelPrefix << start_label << ";\n"; } for (size_t i=0; i mapVariableKeys; +static std::set mapDefineKeys; +static std::set mapLabelKeys; + void Scanner::config(const Str& cfg, const Str& val) { + if (mapDefineKeys.empty()) + { + mapVariableKeys.insert("variable:yyaccept"); + mapVariableKeys.insert("variable:yybm"); + mapVariableKeys.insert("variable:yych"); + mapVariableKeys.insert("variable:yytarget"); + mapDefineKeys.insert("define:YYCTXMARKER"); + mapDefineKeys.insert("define:YYCTYPE"); + mapDefineKeys.insert("define:YYCURSOR"); + mapDefineKeys.insert("define:YYDEBUG"); + mapDefineKeys.insert("define:YYFILL"); + mapDefineKeys.insert("define:YYGETSTATE"); + mapDefineKeys.insert("define:YYLIMIT"); + mapDefineKeys.insert("define:YYMARKER"); + mapDefineKeys.insert("define:YYSETSTATE"); + mapLabelKeys.insert("label:yyFillLabel"); + mapLabelKeys.insert("label:yyNext"); + } + + std::string strVal; + + if (val.len >= 2 && val.str[0] == val.str[val.len-1] + && (val.str[0] == '"' || val.str[0] == '\'')) + { + SubStr tmp(val.str + 1, val.len - 2); + unescape(tmp, strVal); + } + else + { + strVal = val.to_string(); + } + if (cfg.to_string() == "indent:string") { - if (val.len >= 2 && val.str[0] == val.str[val.len-1] - && (val.str[0] == '"' || val.str[0] == '\'')) - { - SubStr tmp(val.str + 1, val.len - 2); - unescape(tmp, indString); - } - else - { - indString = val.to_string(); - } - return; + indString = strVal; } else if (cfg.to_string() == "startlabel") { - if (val.len >= 2 && val.str[0] == val.str[val.len-1] - && (val.str[0] == '"' || val.str[0] == '\'')) - { - SubStr tmp(val.str + 1, val.len - 2); - unescape(tmp, startLabelName); - } - else - { - startLabelName = val.to_string(); - } + startLabelName = val.to_string(); bUseStartLabel = !startLabelName.empty(); } + else if (cfg.to_string() == "labelprefix") + { + labelPrefix = strVal; + } + else if (mapVariableKeys.find(cfg.to_string()) != mapVariableKeys.end()) + { + if (bFirstPass && !mapCodeName.insert( + std::make_pair(cfg.to_string().substr(sizeof("variable:") - 1), strVal) + ).second) + { + fatal("variable already being used and cannot be changed"); + } + } + else if (mapDefineKeys.find(cfg.to_string()) != mapDefineKeys.end()) + { + if (bFirstPass && !mapCodeName.insert( + std::make_pair(cfg.to_string().substr(sizeof("define:") - 1), strVal) + ).second) + { + fatal("define already being used and cannot be changed"); + } + } + else if (mapLabelKeys.find(cfg.to_string()) != mapLabelKeys.end()) + { + if (bFirstPass && !mapCodeName.insert( + std::make_pair(cfg.to_string().substr(sizeof("label:") - 1), strVal) + ).second) + { + fatal("label already being used and cannot be changed"); + } + } else { fatal("unrecognized configuration name or illegal string value"); diff --git a/tools/re2c/code_names.h b/tools/re2c/code_names.h new file mode 100644 index 0000000000..4622e20e05 --- /dev/null +++ b/tools/re2c/code_names.h @@ -0,0 +1,33 @@ +/* $Id: token.h 547 2006-05-25 13:40:35Z helly $ */ +#ifndef _code_names_h +#define _code_names_h + +#include +#include + +namespace re2c +{ + +class CodeNames: public std::map +{ +public: + std::string& operator [] (const char * what); +}; + +inline std::string& CodeNames::operator [] (const char * what) +{ + CodeNames::iterator it = find(std::string(what)); + + if (it != end()) + { + return it->second; + } + else + { + return insert(std::make_pair(std::string(what), std::string(what))).first->second; + } +} + +} // end namespace re2c + +#endif diff --git a/tools/re2c/config_w32.h b/tools/re2c/config_w32.h index 0032664db6..2dc92bb016 100644 --- a/tools/re2c/config_w32.h +++ b/tools/re2c/config_w32.h @@ -7,10 +7,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 -/* Define to 1 if your system has a GNU libc compatible `malloc' function, and - to 0 otherwise. */ -#define HAVE_MALLOC 1 - /* Define to 1 if you have the header file. */ #define HAVE_MEMORY_H 1 @@ -63,13 +59,13 @@ #define PACKAGE_NAME "re2c" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "re2c 0.10.5" +#define PACKAGE_STRING "re2c 0.12.3" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "re2c" /* Define to the version of this package. */ -#define PACKAGE_VERSION "0.10.5" +#define PACKAGE_VERSION "0.12.3" /* The size of a `char', as computed by sizeof. */ #define SIZEOF_CHAR 1 @@ -87,7 +83,7 @@ #define STDC_HEADERS 1 /* Version number of package */ -#define VERSION "0.10.5" +#define VERSION "0.12.3" /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ @@ -98,9 +94,6 @@ /* #undef inline */ #endif -/* Define to rpl_malloc if the replacement function should be used. */ -/* #undef malloc */ - /* Define to `unsigned' if does not define. */ /* #undef size_t */ diff --git a/tools/re2c/dfa.cc b/tools/re2c/dfa.cc index 2d3779f48a..d7db03d5c7 100644 --- a/tools/re2c/dfa.cc +++ b/tools/re2c/dfa.cc @@ -15,7 +15,7 @@ void prtChOrHex(std::ostream& o, uint c, bool useTalx) if ((oc < 256) && isprint(oc)) { o << '\''; - prtCh(o, oc); + prtCh(o, c); o << '\''; } else @@ -28,7 +28,19 @@ void prtHex(std::ostream& o, uint c, bool useTalx) { int oc = (int)(re2c::wFlag || !useTalx ? c : re2c::talx[c]); - if (re2c::wFlag) + if (re2c::uFlag) + { + o << "0x" + << hexCh(oc >> 28) + << hexCh(oc >> 24) + << hexCh(oc >> 20) + << hexCh(oc >> 16) + << hexCh(oc >> 12) + << hexCh(oc >> 8) + << hexCh(oc >> 4) + << hexCh(oc); + } + else if (re2c::wFlag) { o << "0x" << hexCh(oc >> 12) @@ -92,6 +104,16 @@ void prtCh(std::ostream& o, uint c, bool useTalx) { o << (char) oc; } + else if (re2c::uFlag) + { + o << "0x" + << hexCh(oc >> 20) + << hexCh(oc >> 16) + << hexCh(oc >> 12) + << hexCh(oc >> 8) + << hexCh(oc >> 4) + << hexCh(oc); + } else if (re2c::wFlag) { o << "0x" @@ -189,6 +211,7 @@ State::State() State::~State() { + delete action; delete [] kernel; delete [] go.span; } diff --git a/tools/re2c/dfa.h b/tools/re2c/dfa.h index eb1f89cebd..e5ac5f4e99 100644 --- a/tools/re2c/dfa.h +++ b/tools/re2c/dfa.h @@ -291,6 +291,7 @@ public: inline Action::Action(State *s) : state(s) { + delete s->action; s->action = this; } diff --git a/tools/re2c/globals.h b/tools/re2c/globals.h index 0c21047d30..b9cc10e163 100644 --- a/tools/re2c/globals.h +++ b/tools/re2c/globals.h @@ -7,6 +7,7 @@ #include #include #include "stream_lc.h" +#include "code_names.h" namespace re2c { @@ -21,9 +22,13 @@ extern bool fFlag; extern bool gFlag; extern bool iFlag; extern bool sFlag; +extern bool uFlag; extern bool wFlag; +extern bool bNoGenerationDate; + extern bool bSinglePass; +extern bool bFirstPass; extern bool bLastPass; extern bool bUsedYYAccept; @@ -32,6 +37,8 @@ extern bool bUsedYYMarker; extern bool bUseStartLabel; extern std::string startLabelName; +extern std::string labelPrefix; +extern std::string yychConversion; extern uint maxFill; extern uint next_label; extern uint cGotoThreshold; @@ -44,6 +51,7 @@ extern bool bUseStateAbort; extern bool bUseStateNext; extern bool bWroteGetState; extern bool bUseYYFill; +extern bool bUseYYFillParam; extern uint asc2ebc[256]; extern uint ebc2asc[256]; @@ -53,20 +61,12 @@ extern uint *xlat, *talx; extern uint next_fill_index; extern uint last_fill_index; extern std::set vUsedLabels; +extern re2c::CodeNames mapCodeName; extern uint nRealChars; -inline char octCh(uint c) -{ - return '0' + c % 8; -} - -inline char hexCh(uint c) -{ - static const char * sHex = "0123456789ABCDEF"; - - return sHex[c & 0x0F]; -} +extern char octCh(uint c); +extern char hexCh(uint c); } // end namespace re2c diff --git a/tools/re2c/main.cc b/tools/re2c/main.cc index d0673b42f6..966d7e5ad4 100644 --- a/tools/re2c/main.cc +++ b/tools/re2c/main.cc @@ -28,20 +28,27 @@ bool fFlag = false; bool gFlag = false; bool iFlag = false; bool sFlag = false; +bool uFlag = false; bool wFlag = false; +bool bNoGenerationDate = false; + bool bSinglePass = false; +bool bFirstPass = true; bool bLastPass = false; bool bUsedYYAccept = false; bool bUsedYYMaxFill = false; bool bUsedYYMarker = true; -bool bUseStartLabel= false; -bool bUseStateNext = false; -bool bUseYYFill = true; +bool bUseStartLabel = false; +bool bUseStateNext = false; +bool bUseYYFill = true; +bool bUseYYFillParam = true; std::string startLabelName; +std::string labelPrefix("yy"); +std::string yychConversion(""); uint maxFill = 1; uint next_label = 0; uint cGotoThreshold = 9; @@ -57,6 +64,10 @@ uint nRealChars = 256; uint next_fill_index = 0; uint last_fill_index = 0; std::set vUsedLabels; +re2c::CodeNames mapCodeName; + +free_list RegExp::vFreeList; +free_list Range::vFreeList; using namespace std; @@ -75,10 +86,12 @@ static const mbo_opt_struct OPTIONS[] = mbo_opt_struct('i', 0, "no-debug-info"), mbo_opt_struct('o', 1, "output"), mbo_opt_struct('s', 0, "nested-ifs"), + mbo_opt_struct('u', 0, "unicode"), mbo_opt_struct('v', 0, "version"), mbo_opt_struct('V', 0, "vernum"), mbo_opt_struct('w', 0, "wide-chars"), mbo_opt_struct('1', 0, "single-pass"), + mbo_opt_struct(10, 0, "no-generation-date"), mbo_opt_struct('-', 0, NULL) /* end of args */ }; @@ -113,7 +126,10 @@ static void usage() "-s --nested-ifs Generate nested ifs for some switches. Many compilers\n" " need this assist to generate better code.\n" "\n" + "-u --unicode Implies -w but supports the full Unicode character set.\n" + "\n" "-v --version Show version information.\n" + "\n" "-V --vernum Show version as one number.\n" "\n" "-w --wide-chars Create a parser that supports wide chars (UCS-2). This\n" @@ -122,6 +138,9 @@ static void usage() "-1 --single-pass Force single pass generation, this cannot be combined\n" " with -f and disables YYMAXFILL generation prior to last\n" " re2c block.\n" + "\n" + "--no-generation-date Suppress the date output in the generated output so that it\n" + " only shows the re2c version.\n" ; } @@ -163,10 +182,6 @@ int main(int argc, char *argv[]) case 'f': fFlag = true; - if (bSinglePass) { - std::cerr << "re2c: error: cannot combine -1 and -f switch\n"; - return 1; - } break; case 'g': @@ -188,10 +203,6 @@ int main(int argc, char *argv[]) break; case '1': - if (bFlag) { - std::cerr << "re2c: error: cannot combine -1 and -f switch\n"; - return 1; - } bSinglePass = true; break; @@ -222,25 +233,51 @@ int main(int argc, char *argv[]) } case 'w': - nRealChars = (1<<16); + nRealChars = (1<<16); /* 0x10000 */ sFlag = true; wFlag = true; break; - + + case 'u': + nRealChars = 0x110000; /* 17 times w-Flag */ + sFlag = true; + uFlag = true; + break; + case 'h': case '?': default: usage(); return 2; + + case 10: + bNoGenerationDate = true; + break; } } + if ((bFlag || fFlag) && bSinglePass) { + std::cerr << "re2c: error: Cannot combine -1 and -b or -f switch\n"; + return 1; + } + if (wFlag && eFlag) { - usage(); + std::cerr << "re2c: error: Cannot combine -e with -w or -u switch\n"; return 2; } - else if (argc == opt_ind + 1) + if (wFlag && uFlag) + { + std::cerr << "re2c: error: Cannot combine -u with -w switch\n"; + return 2; + } + + if (uFlag) + { + wFlag = true; + } + + if (argc == opt_ind + 1) { sourceFileName = argv[opt_ind]; } @@ -303,9 +340,9 @@ int main(int argc, char *argv[]) parse(null_scanner, null_dev); next_label = 0; next_fill_index = 0; - Symbol::ClearTable(); bWroteGetState = false; bUsedYYMaxFill = false; + bFirstPass = false; } bLastPass = true; diff --git a/tools/re2c/mbo_getopt.cc b/tools/re2c/mbo_getopt.cc index 145013d385..8c33332f39 100644 --- a/tools/re2c/mbo_getopt.cc +++ b/tools/re2c/mbo_getopt.cc @@ -81,6 +81,10 @@ int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct *opts, char **o if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) { /* '--' indicates end of args if not followed by a known long option name */ + if (argv[*optind][2] == '\0') { + (*optind)++; + return(EOF); + } while (1) { @@ -89,7 +93,7 @@ int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct *opts, char **o if (opts[opts_idx].opt_char == '-') { (*optind)++; - return (EOF); + return (mbo_opt_error(argc, argv, *optind - 1, optchr, OPTERRARG, show_err)); } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) { @@ -98,22 +102,26 @@ int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct *opts, char **o } optchr = 0; - dash = 1; + dash = 0; arg_start = 2 + strlen(opts[opts_idx].opt_name); } - if (!dash) + else { - dash = 1; - optchr = 1; - } + if (!dash) + { + dash = 1; + optchr = 1; + } - /* Check if the guy tries to do a -: kind of flag */ - if (argv[*optind][optchr] == ':') - { - dash = 0; - (*optind)++; - return (mbo_opt_error(argc, argv, *optind - 1, optchr, OPTERRCOLON, show_err)); + /* Check if the guy tries to do a -: kind of flag */ + if (argv[*optind][optchr] == ':') + { + dash = 0; + (*optind)++; + return (mbo_opt_error(argc, argv, *optind - 1, optchr, OPTERRCOLON, show_err)); + } + arg_start = 1 + optchr; } if (opts_idx < 0) @@ -135,6 +143,7 @@ int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct *opts, char **o else { optchr++; + arg_start++; } return (mbo_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err)); @@ -173,7 +182,7 @@ int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct *opts, char **o } else { - if (arg_start == 2) + if (arg_start >= 2 && !((argv[*optind][0] == '-') && (argv[*optind][1] == '-'))) { if (!argv[*optind][optchr + 1]) { diff --git a/tools/re2c/parser.cc b/tools/re2c/parser.cc index 5cad94a0dd..7cbf7a8032 100644 --- a/tools/re2c/parser.cc +++ b/tools/re2c/parser.cc @@ -1,7 +1,9 @@ -/* A Bison parser, made by GNU Bison 2.1. */ +/* A Bison parser, made by GNU Bison 2.3. */ -/* Skeleton parser for Yacc-like parsing with Bison, - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +/* Skeleton implementation for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. 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 @@ -18,13 +20,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* As a special exception, when this file is copied by Bison into a - Bison output file, you may use that output file without restriction. - This special exception was added by the Free Software Foundation - in version 1.24 of Bison. */ +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. -/* Written by Richard Stallman by simplifying the original so called - ``semantic'' parser. */ + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local @@ -37,7 +47,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.1" +#define YYBISON_VERSION "2.3" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -82,7 +92,7 @@ /* Copy the first part of user declarations. */ -#line 1 "parser.y" +#line 1 "./parser.y" /* $Id: parser.y,v 1.20 2006/04/16 15:15:46 helly Exp $ */ @@ -113,7 +123,7 @@ void yyerror(const char*); static re2c::uint accept; static RegExp *spec; -static Scanner *in; +static Scanner *in = NULL; /* Bison version 1.875 emits a definition that is not working * with several g++ version. Hence we disable it here. @@ -156,9 +166,10 @@ static char* strdup(const char* s) # define YYTOKEN_TABLE 0 #endif -#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 58 "parser.y" -typedef union YYSTYPE { +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +#line 58 "./parser.y" +{ re2c::Symbol *symbol; re2c::RegExp *regexp; re2c::Token *token; @@ -166,9 +177,10 @@ typedef union YYSTYPE { int number; re2c::ExtOp extop; re2c::Str *str; -} YYSTYPE; -/* Line 196 of yacc.c. */ -#line 172 "parser.cc" +} +/* Line 187 of yacc.c. */ +#line 183 "parser.cc" + YYSTYPE; # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 @@ -179,23 +191,56 @@ typedef union YYSTYPE { /* Copy the second part of user declarations. */ -/* Line 219 of yacc.c. */ -#line 184 "parser.cc" +/* Line 216 of yacc.c. */ +#line 196 "parser.cc" -#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) -# define YYSIZE_T __SIZE_TYPE__ +#ifdef short +# undef short #endif -#if ! defined (YYSIZE_T) && defined (size_t) -# define YYSIZE_T size_t + +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else +typedef unsigned char yytype_uint8; #endif -#if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus)) -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; +#elif (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +typedef signed char yytype_int8; +#else +typedef short int yytype_int8; #endif -#if ! defined (YYSIZE_T) -# define YYSIZE_T unsigned int + +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; +#else +typedef unsigned short int yytype_uint16; #endif +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned int +# endif +#endif + +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) + #ifndef YY_ # if YYENABLE_NLS # if ENABLE_NLS @@ -208,7 +253,32 @@ typedef union YYSTYPE { # endif #endif -#if ! defined (yyoverflow) || YYERROR_VERBOSE +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(e) ((void) (e)) +#else +# define YYUSE(e) /* empty */ +#endif + +/* Identity function, used to suppress warnings about constant conditions. */ +#ifndef lint +# define YYID(n) (n) +#else +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static int +YYID (int i) +#else +static int +YYID (i) + int i; +#endif +{ + return i; +} +#endif + +#if ! defined yyoverflow || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ @@ -216,64 +286,76 @@ typedef union YYSTYPE { # if YYSTACK_USE_ALLOCA # ifdef __GNUC__ # define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if defined (__STDC__) || defined (__cplusplus) +# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ -# define YYINCLUDED_STDLIB_H +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif # endif # endif # endif # endif # ifdef YYSTACK_ALLOC - /* Pacify GCC's `empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) # ifndef YYSTACK_ALLOC_MAXIMUM /* The OS might guarantee only one guard page at the bottom of the stack, and a page size can be as small as 4096 bytes. So we cannot safely invoke alloca (N) if N exceeds 4096. Use a slightly smaller number to allow for a few compiler-allocated temporary stack slots. */ -# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2005 */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ # endif # else # define YYSTACK_ALLOC YYMALLOC # define YYSTACK_FREE YYFREE # ifndef YYSTACK_ALLOC_MAXIMUM -# define YYSTACK_ALLOC_MAXIMUM ((YYSIZE_T) -1) +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# ifdef __cplusplus -extern "C" { +# if (defined __cplusplus && ! defined _STDLIB_H \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \ - && (defined (__STDC__) || defined (__cplusplus))) +# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if (! defined (free) && ! defined (YYINCLUDED_STDLIB_H) \ - && (defined (__STDC__) || defined (__cplusplus))) +# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif -# ifdef __cplusplus -} -# endif # endif -#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ -#if (! defined (yyoverflow) \ - && (! defined (__cplusplus) \ - || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))) +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { - short int yyss; + yytype_int16 yyss; YYSTYPE yyvs; }; @@ -283,13 +365,13 @@ union yyalloc /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ - ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) /* Copy COUNT objects from FROM to TO. The source and destination do not overlap. */ # ifndef YYCOPY -# if defined (__GNUC__) && 1 < __GNUC__ +# if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(To, From, Count) \ __builtin_memcpy (To, From, (Count) * sizeof (*(From))) # else @@ -300,7 +382,7 @@ union yyalloc for (yyi = 0; yyi < (Count); yyi++) \ (To)[yyi] = (From)[yyi]; \ } \ - while (0) + while (YYID (0)) # endif # endif @@ -318,28 +400,22 @@ union yyalloc yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ yyptr += yynewbytes / sizeof (*yyptr); \ } \ - while (0) + while (YYID (0)) #endif -#if defined (__STDC__) || defined (__cplusplus) - typedef signed char yysigned_char; -#else - typedef short int yysigned_char; -#endif - -/* YYFINAL -- State number of the termination state. */ +/* YYFINAL -- State number of the termination state. */ #define YYFINAL 2 /* YYLAST -- Last index in YYTABLE. */ #define YYLAST 37 -/* YYNTOKENS -- Number of terminals. */ +/* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS 19 -/* YYNNTS -- Number of nonterminals. */ +/* YYNNTS -- Number of nonterminals. */ #define YYNNTS 11 -/* YYNRULES -- Number of rules. */ +/* YYNRULES -- Number of rules. */ #define YYNRULES 26 -/* YYNRULES -- Number of states. */ +/* YYNRULES -- Number of states. */ #define YYNSTATES 40 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ @@ -350,7 +426,7 @@ union yyalloc ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ -static const unsigned char yytranslate[] = +static const yytype_uint8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -384,19 +460,19 @@ static const unsigned char yytranslate[] = #if YYDEBUG /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in YYRHS. */ -static const unsigned char yyprhs[] = +static const yytype_uint8 yyprhs[] = { 0, 0, 3, 4, 7, 10, 15, 20, 25, 30, 34, 35, 38, 40, 44, 46, 50, 52, 55, 57, 60, 63, 65, 68, 70, 72, 74 }; -/* YYRHS -- A `-1'-separated list of the rules' RHS. */ -static const yysigned_char yyrhs[] = +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yytype_int8 yyrhs[] = { 20, 0, -1, -1, 20, 22, -1, 20, 21, -1, - 5, 12, 24, 13, -1, 9, 12, 10, 13, -1, - 9, 12, 11, 13, -1, 5, 12, 24, 14, -1, + 5, 12, 24, 13, -1, 5, 12, 24, 14, -1, + 9, 12, 10, 13, -1, 9, 12, 11, 13, -1, 24, 23, 6, -1, -1, 14, 24, -1, 25, -1, 24, 15, 25, -1, 26, -1, 25, 16, 26, -1, 27, -1, 26, 27, -1, 29, -1, 29, 28, -1, @@ -405,17 +481,17 @@ static const yysigned_char yyrhs[] = }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ -static const unsigned char yyrline[] = +static const yytype_uint8 yyrline[] = { - 0, 84, 84, 86, 88, 91, 95, 97, 101, 105, - 110, 111, 115, 117, 121, 123, 130, 132, 136, 138, - 152, 158, 160, 164, 168, 170, 172 + 0, 84, 84, 86, 88, 91, 95, 97, 99, 103, + 108, 109, 113, 115, 119, 121, 128, 130, 134, 136, + 150, 156, 158, 162, 166, 168, 170 }; #endif #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - First, the terminals, then, starting at YYNTOKENS, nonterminals. */ + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { "$end", "error", "$undefined", "CLOSESIZE", "CLOSE", "ID", "CODE", @@ -428,7 +504,7 @@ static const char *const yytname[] = # ifdef YYPRINT /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to token YYLEX-NUM. */ -static const unsigned short int yytoknum[] = +static const yytype_uint16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 61, 59, 47, 124, 92, 40, 41 @@ -436,7 +512,7 @@ static const unsigned short int yytoknum[] = # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const unsigned char yyr1[] = +static const yytype_uint8 yyr1[] = { 0, 19, 20, 20, 20, 21, 21, 21, 21, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, @@ -444,7 +520,7 @@ static const unsigned char yyr1[] = }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const unsigned char yyr2[] = +static const yytype_uint8 yyr2[] = { 0, 2, 0, 2, 2, 4, 4, 4, 4, 3, 0, 2, 1, 3, 1, 3, 1, 2, 1, 2, @@ -454,16 +530,16 @@ static const unsigned char yyr2[] = /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state STATE-NUM when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ -static const unsigned char yydefact[] = +static const yytype_uint8 yydefact[] = { 2, 0, 1, 23, 24, 25, 0, 0, 4, 3, 10, 12, 14, 16, 18, 0, 0, 23, 0, 0, 0, 0, 0, 17, 20, 21, 19, 0, 0, 0, - 26, 11, 13, 9, 15, 22, 5, 8, 6, 7 + 26, 11, 13, 9, 15, 22, 5, 6, 7, 8 }; -/* YYDEFGOTO[NTERM-NUM]. */ -static const yysigned_char yydefgoto[] = +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int8 yydefgoto[] = { -1, 1, 8, 9, 21, 10, 11, 12, 13, 26, 14 @@ -472,7 +548,7 @@ static const yysigned_char yydefgoto[] = /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ #define YYPACT_NINF -13 -static const yysigned_char yypact[] = +static const yytype_int8 yypact[] = { -13, 1, -13, -5, -13, -13, 0, -3, -13, -13, 9, 13, -3, -13, 22, -3, 17, -13, -2, -3, @@ -481,7 +557,7 @@ static const yysigned_char yypact[] = }; /* YYPGOTO[NTERM-NUM]. */ -static const yysigned_char yypgoto[] = +static const yytype_int8 yypgoto[] = { -13, -13, -13, -13, -13, -4, 14, 15, -12, -13, -13 @@ -492,7 +568,7 @@ static const yysigned_char yypgoto[] = number is the opposite. If zero, do what YYDEFACT says. If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -1 -static const unsigned char yytable[] = +static const yytype_uint8 yytable[] = { 23, 2, 17, 18, 4, 5, 3, 15, 4, 5, 6, 27, 16, 20, 7, 31, 30, 33, 7, 36, @@ -500,7 +576,7 @@ static const unsigned char yytable[] = 35, 38, 39, 0, 32, 20, 0, 34 }; -static const yysigned_char yycheck[] = +static const yytype_int8 yycheck[] = { 12, 0, 5, 7, 7, 8, 5, 12, 7, 8, 9, 15, 12, 15, 17, 19, 18, 6, 17, 13, @@ -510,7 +586,7 @@ static const yysigned_char yycheck[] = /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ -static const unsigned char yystos[] = +static const yytype_uint8 yystos[] = { 0, 20, 0, 5, 7, 8, 9, 17, 21, 22, 24, 25, 26, 27, 29, 12, 12, 5, 24, 14, @@ -543,7 +619,7 @@ do \ yychar = (Token); \ yylval = (Value); \ yytoken = YYTRANSLATE (yychar); \ - YYPOPSTACK; \ + YYPOPSTACK (1); \ goto yybackup; \ } \ else \ @@ -551,7 +627,7 @@ do \ yyerror (YY_("syntax error: cannot back up")); \ YYERROR; \ } \ -while (0) +while (YYID (0)) #define YYTERROR 1 @@ -566,7 +642,7 @@ while (0) #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(Current, Rhs, N) \ do \ - if (N) \ + if (YYID (N)) \ { \ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ @@ -580,7 +656,7 @@ while (0) (Current).first_column = (Current).last_column = \ YYRHSLOC (Rhs, 0).last_column; \ } \ - while (0) + while (YYID (0)) #endif @@ -592,8 +668,8 @@ while (0) # if YYLTYPE_IS_TRIVIAL # define YY_LOCATION_PRINT(File, Loc) \ fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif @@ -620,36 +696,96 @@ while (0) do { \ if (yydebug) \ YYFPRINTF Args; \ -} while (0) +} while (YYID (0)) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yysymprint (stderr, \ - Type, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (YYID (0)) + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +#else +static void +yy_symbol_value_print (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; +#endif +{ + if (!yyvaluep) + return; +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# else + YYUSE (yyoutput); +# endif + switch (yytype) + { + default: + break; + } +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +#else +static void +yy_symbol_print (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; +#endif +{ + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + yy_symbol_value_print (yyoutput, yytype, yyvaluep); + YYFPRINTF (yyoutput, ")"); +} /*------------------------------------------------------------------. | yy_stack_print -- Print the state stack from its BOTTOM up to its | | TOP (included). | `------------------------------------------------------------------*/ -#if defined (__STDC__) || defined (__cplusplus) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static void -yy_stack_print (short int *bottom, short int *top) +yy_stack_print (yytype_int16 *bottom, yytype_int16 *top) #else static void yy_stack_print (bottom, top) - short int *bottom; - short int *top; + yytype_int16 *bottom; + yytype_int16 *top; #endif { YYFPRINTF (stderr, "Stack now"); - for (/* Nothing. */; bottom <= top; ++bottom) + for (; bottom <= top; ++bottom) YYFPRINTF (stderr, " %d", *bottom); YYFPRINTF (stderr, "\n"); } @@ -658,37 +794,45 @@ yy_stack_print (bottom, top) do { \ if (yydebug) \ yy_stack_print ((Bottom), (Top)); \ -} while (0) +} while (YYID (0)) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -#if defined (__STDC__) || defined (__cplusplus) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static void -yy_reduce_print (int yyrule) +yy_reduce_print (YYSTYPE *yyvsp, int yyrule) #else static void -yy_reduce_print (yyrule) +yy_reduce_print (yyvsp, yyrule) + YYSTYPE *yyvsp; int yyrule; #endif { + int yynrhs = yyr2[yyrule]; int yyi; unsigned long int yylno = yyrline[yyrule]; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ", - yyrule - 1, yylno); - /* Print the symbols being reduced, and their result. */ - for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) - YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]); - YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]); + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + fprintf (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + &(yyvsp[(yyi + 1) - (yynrhs)]) + ); + fprintf (stderr, "\n"); + } } # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (Rule); \ -} while (0) + yy_reduce_print (yyvsp, Rule); \ +} while (YYID (0)) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ @@ -722,42 +866,44 @@ int yydebug; #if YYERROR_VERBOSE # ifndef yystrlen -# if defined (__GLIBC__) && defined (_STRING_H) +# if defined __GLIBC__ && defined _STRING_H # define yystrlen strlen # else /* Return the length of YYSTR. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static YYSIZE_T -# if defined (__STDC__) || defined (__cplusplus) yystrlen (const char *yystr) -# else +#else +static YYSIZE_T yystrlen (yystr) - const char *yystr; -# endif + const char *yystr; +#endif { - const char *yys = yystr; - - while (*yys++ != '\0') + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) continue; - - return yys - yystr - 1; + return yylen; } # endif # endif # ifndef yystpcpy -# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE # define yystpcpy stpcpy # else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static char * -# if defined (__STDC__) || defined (__cplusplus) yystpcpy (char *yydest, const char *yysrc) -# else +#else +static char * yystpcpy (yydest, yysrc) - char *yydest; - const char *yysrc; -# endif + char *yydest; + const char *yysrc; +#endif { char *yyd = yydest; const char *yys = yysrc; @@ -783,7 +929,7 @@ yytnamerr (char *yyres, const char *yystr) { if (*yystr == '"') { - size_t yyn = 0; + YYSIZE_T yyn = 0; char const *yyp = yystr; for (;;) @@ -818,53 +964,123 @@ yytnamerr (char *yyres, const char *yystr) } # endif -#endif /* YYERROR_VERBOSE */ +/* Copy into YYRESULT an error message about the unexpected token + YYCHAR while in state YYSTATE. Return the number of bytes copied, + including the terminating null byte. If YYRESULT is null, do not + copy anything; just return the number of bytes that would be + copied. As a special case, return 0 if an ordinary "syntax error" + message will do. Return YYSIZE_MAXIMUM if overflow occurs during + size calculation. */ +static YYSIZE_T +yysyntax_error (char *yyresult, int yystate, int yychar) +{ + int yyn = yypact[yystate]; + if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) + return 0; + else + { + int yytype = YYTRANSLATE (yychar); + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + int yysize_overflow = 0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + int yyx; + +# if 0 + /* This is so xgettext sees the translatable formats that are + constructed on the fly. */ + YY_("syntax error, unexpected %s"); + YY_("syntax error, unexpected %s, expecting %s"); + YY_("syntax error, unexpected %s, expecting %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); +# endif + char *yyfmt; + char const *yyf; + static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyexpecting[] = ", expecting %s"; + static char const yyor[] = " or %s"; + char yyformat[sizeof yyunexpected + + sizeof yyexpecting - 1 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) + * (sizeof yyor - 1))]; + char const *yyprefix = yyexpecting; + + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 1; + + yyarg[0] = yytname[yytype]; + yyfmt = yystpcpy (yyformat, yyunexpected); + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + yyformat[sizeof yyunexpected - 1] = '\0'; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + yyfmt = yystpcpy (yyfmt, yyprefix); + yyprefix = yyor; + } + + yyf = YY_(yyformat); + yysize1 = yysize + yystrlen (yyf); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + + if (yysize_overflow) + return YYSIZE_MAXIMUM; + + if (yyresult) + { + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + char *yyp = yyresult; + int yyi = 0; + while ((*yyp = *yyf) != '\0') + { + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyf += 2; + } + else + { + yyp++; + yyf++; + } + } + } + return yysize; + } +} +#endif /* YYERROR_VERBOSE */ -#if YYDEBUG -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ - -#if defined (__STDC__) || defined (__cplusplus) -static void -yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep) -#else -static void -yysymprint (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE *yyvaluep; -#endif -{ - /* Pacify ``unused variable'' warnings. */ - (void) yyvaluep; - - if (yytype < YYNTOKENS) - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); - else - YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); - - -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - switch (yytype) - { - default: - break; - } - YYFPRINTF (yyoutput, ")"); -} - -#endif /* ! YYDEBUG */ /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ -#if defined (__STDC__) || defined (__cplusplus) +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static void yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) #else @@ -875,33 +1091,24 @@ yydestruct (yymsg, yytype, yyvaluep) YYSTYPE *yyvaluep; #endif { - /* Pacify ``unused variable'' warnings. */ - (void) yyvaluep; + YYUSE (yyvaluep); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); -/* - switch (yytype) - { - - default: - break; - } -*/ } /* Prevent warnings from -Wmissing-prototypes. */ #ifdef YYPARSE_PARAM -# if defined (__STDC__) || defined (__cplusplus) +#if defined __STDC__ || defined __cplusplus int yyparse (void *YYPARSE_PARAM); -# else +#else int yyparse (); -# endif +#endif #else /* ! YYPARSE_PARAM */ -#if defined (__STDC__) || defined (__cplusplus) +#if defined __STDC__ || defined __cplusplus int yyparse (void); #else int yyparse (); @@ -926,20 +1133,24 @@ int yynerrs; `----------*/ #ifdef YYPARSE_PARAM -# if defined (__STDC__) || defined (__cplusplus) -int yyparse (void *YYPARSE_PARAM) -# else -int yyparse (YYPARSE_PARAM) - void *YYPARSE_PARAM; -# endif +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void *YYPARSE_PARAM) +#else +int +yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +#endif #else /* ! YYPARSE_PARAM */ -#if defined (__STDC__) || defined (__cplusplus) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) int yyparse (void) #else int yyparse () - ; + #endif #endif { @@ -951,6 +1162,12 @@ yyparse () int yyerrstatus; /* Look-ahead token as an internal (translated) token number. */ int yytoken = 0; +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif /* Three stacks and their tools: `yyss': related to states, @@ -961,9 +1178,9 @@ yyparse () to reallocate them elsewhere. */ /* The state stack. */ - short int yyssa[YYINITDEPTH]; - short int *yyss = yyssa; - short int *yyssp; + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss = yyssa; + yytype_int16 *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; @@ -972,7 +1189,7 @@ yyparse () -#define YYPOPSTACK (yyvsp--, yyssp--) +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) YYSIZE_T yystacksize = YYINITDEPTH; @@ -981,9 +1198,9 @@ yyparse () YYSTYPE yyval; - /* When reducing, the number of symbols on the RHS of the reduced - rule. */ - int yylen; + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; YYDPRINTF ((stderr, "Starting parse\n")); @@ -1007,8 +1224,7 @@ yyparse () `------------------------------------------------------------*/ yynewstate: /* In all cases, when you get here, the value and location stacks - have just been pushed. so pushing a state here evens the stacks. - */ + have just been pushed. So pushing a state here evens the stacks. */ yyssp++; yysetstate: @@ -1021,11 +1237,11 @@ yyparse () #ifdef yyoverflow { - /* Give user a chance to reallocate the stack. Use copies of + /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ YYSTYPE *yyvs1 = yyvs; - short int *yyss1 = yyss; + yytype_int16 *yyss1 = yyss; /* Each stack pointer address is followed by the size of the @@ -1053,7 +1269,7 @@ yyparse () yystacksize = YYMAXDEPTH; { - short int *yyss1 = yyss; + yytype_int16 *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) @@ -1088,12 +1304,10 @@ yyparse () `-----------*/ yybackup: -/* Do appropriate processing given the current state. */ -/* Read a look-ahead token if we need one and don't already have one. */ -/* yyresume: */ + /* Do appropriate processing given the current state. Read a + look-ahead token if we need one and don't already have one. */ /* First try to decide what to do without reference to look-ahead token. */ - yyn = yypact[yystate]; if (yyn == YYPACT_NINF) goto yydefault; @@ -1135,22 +1349,21 @@ yybackup: if (yyn == YYFINAL) YYACCEPT; - /* Shift the look-ahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the token being shifted unless it is eof. */ - if (yychar != YYEOF) - yychar = YYEMPTY; - - *++yyvsp = yylval; - - /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; + /* Shift the look-ahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the shifted token unless it is eof. */ + if (yychar != YYEOF) + yychar = YYEMPTY; + yystate = yyn; + *++yyvsp = yylval; + goto yynewstate; @@ -1186,158 +1399,156 @@ yyreduce: switch (yyn) { case 2: -#line 84 "parser.y" +#line 84 "./parser.y" { accept = 0; - spec = NULL; } + spec = NULL; ;} break; case 3: -#line 87 "parser.y" - { spec = spec? mkAlt(spec, (yyvsp[0].regexp)) : (yyvsp[0].regexp); } +#line 87 "./parser.y" + { spec = spec? mkAlt(spec, (yyvsp[(2) - (2)].regexp)) : (yyvsp[(2) - (2)].regexp); ;} break; case 5: -#line 92 "parser.y" - { if((yyvsp[-3].symbol)->re) +#line 92 "./parser.y" + { if((yyvsp[(1) - (4)].symbol)->re) in->fatal("sym already defined"); - (yyvsp[-3].symbol)->re = (yyvsp[-1].regexp); } + (yyvsp[(1) - (4)].symbol)->re = (yyvsp[(3) - (4)].regexp); ;} break; case 6: -#line 96 "parser.y" - { in->config(*(yyvsp[-3].str), *(yyvsp[-1].str)); } +#line 96 "./parser.y" + { in->fatal("trailing contexts are not allowed in named definitions"); ;} break; case 7: -#line 98 "parser.y" - { in->config(*(yyvsp[-3].str), (yyvsp[-1].number)); } +#line 98 "./parser.y" + { in->config(*(yyvsp[(1) - (4)].str), *(yyvsp[(3) - (4)].str)); delete (yyvsp[(1) - (4)].str); delete (yyvsp[(3) - (4)].str); ;} break; case 8: -#line 102 "parser.y" - { in->fatal("trailing contexts are not allowed in named definitions"); } +#line 100 "./parser.y" + { in->config(*(yyvsp[(1) - (4)].str), (yyvsp[(3) - (4)].number)); delete (yyvsp[(1) - (4)].str); ;} break; case 9: -#line 106 "parser.y" - { (yyval.regexp) = new RuleOp((yyvsp[-2].regexp), (yyvsp[-1].regexp), (yyvsp[0].token), accept++); } +#line 104 "./parser.y" + { (yyval.regexp) = new RuleOp((yyvsp[(1) - (3)].regexp), (yyvsp[(2) - (3)].regexp), (yyvsp[(3) - (3)].token), accept++); ;} break; case 10: -#line 110 "parser.y" - { (yyval.regexp) = new NullOp; } +#line 108 "./parser.y" + { (yyval.regexp) = new NullOp; ;} break; case 11: -#line 112 "parser.y" - { (yyval.regexp) = (yyvsp[0].regexp); } +#line 110 "./parser.y" + { (yyval.regexp) = (yyvsp[(2) - (2)].regexp); ;} break; case 12: -#line 116 "parser.y" - { (yyval.regexp) = (yyvsp[0].regexp); } +#line 114 "./parser.y" + { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); ;} break; case 13: -#line 118 "parser.y" - { (yyval.regexp) = mkAlt((yyvsp[-2].regexp), (yyvsp[0].regexp)); } +#line 116 "./parser.y" + { (yyval.regexp) = mkAlt((yyvsp[(1) - (3)].regexp), (yyvsp[(3) - (3)].regexp)); ;} break; case 14: -#line 122 "parser.y" - { (yyval.regexp) = (yyvsp[0].regexp); } +#line 120 "./parser.y" + { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); ;} break; case 15: -#line 124 "parser.y" - { (yyval.regexp) = mkDiff((yyvsp[-2].regexp), (yyvsp[0].regexp)); +#line 122 "./parser.y" + { (yyval.regexp) = mkDiff((yyvsp[(1) - (3)].regexp), (yyvsp[(3) - (3)].regexp)); if(!(yyval.regexp)) in->fatal("can only difference char sets"); - } + ;} break; case 16: -#line 131 "parser.y" - { (yyval.regexp) = (yyvsp[0].regexp); } +#line 129 "./parser.y" + { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); ;} break; case 17: -#line 133 "parser.y" - { (yyval.regexp) = new CatOp((yyvsp[-1].regexp), (yyvsp[0].regexp)); } +#line 131 "./parser.y" + { (yyval.regexp) = new CatOp((yyvsp[(1) - (2)].regexp), (yyvsp[(2) - (2)].regexp)); ;} break; case 18: -#line 137 "parser.y" - { (yyval.regexp) = (yyvsp[0].regexp); } +#line 135 "./parser.y" + { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); ;} break; case 19: -#line 139 "parser.y" +#line 137 "./parser.y" { - switch((yyvsp[0].op)){ + switch((yyvsp[(2) - (2)].op)){ case '*': - (yyval.regexp) = mkAlt(new CloseOp((yyvsp[-1].regexp)), new NullOp()); + (yyval.regexp) = mkAlt(new CloseOp((yyvsp[(1) - (2)].regexp)), new NullOp()); break; case '+': - (yyval.regexp) = new CloseOp((yyvsp[-1].regexp)); + (yyval.regexp) = new CloseOp((yyvsp[(1) - (2)].regexp)); break; case '?': - (yyval.regexp) = mkAlt((yyvsp[-1].regexp), new NullOp()); + (yyval.regexp) = mkAlt((yyvsp[(1) - (2)].regexp), new NullOp()); break; } - } + ;} break; case 20: -#line 153 "parser.y" +#line 151 "./parser.y" { - (yyval.regexp) = new CloseVOp((yyvsp[-1].regexp), (yyvsp[0].extop).minsize, (yyvsp[0].extop).maxsize); - } + (yyval.regexp) = new CloseVOp((yyvsp[(1) - (2)].regexp), (yyvsp[(2) - (2)].extop).minsize, (yyvsp[(2) - (2)].extop).maxsize); + ;} break; case 21: -#line 159 "parser.y" - { (yyval.op) = (yyvsp[0].op); } +#line 157 "./parser.y" + { (yyval.op) = (yyvsp[(1) - (1)].op); ;} break; case 22: -#line 161 "parser.y" - { (yyval.op) = ((yyvsp[-1].op) == (yyvsp[0].op)) ? (yyvsp[-1].op) : '*'; } +#line 159 "./parser.y" + { (yyval.op) = ((yyvsp[(1) - (2)].op) == (yyvsp[(2) - (2)].op)) ? (yyvsp[(1) - (2)].op) : '*'; ;} break; case 23: -#line 165 "parser.y" - { if(!(yyvsp[0].symbol)->re) +#line 163 "./parser.y" + { if(!(yyvsp[(1) - (1)].symbol)->re) in->fatal("can't find symbol"); - (yyval.regexp) = (yyvsp[0].symbol)->re; } + (yyval.regexp) = (yyvsp[(1) - (1)].symbol)->re; ;} break; case 24: -#line 169 "parser.y" - { (yyval.regexp) = (yyvsp[0].regexp); } +#line 167 "./parser.y" + { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); ;} break; case 25: -#line 171 "parser.y" - { (yyval.regexp) = (yyvsp[0].regexp); } +#line 169 "./parser.y" + { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); ;} break; case 26: -#line 173 "parser.y" - { (yyval.regexp) = (yyvsp[-1].regexp); } +#line 171 "./parser.y" + { (yyval.regexp) = (yyvsp[(2) - (3)].regexp); ;} break; +/* Line 1267 of yacc.c. */ +#line 1553 "parser.cc" default: break; } + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); -/* Line 1126 of yacc.c. */ -#line 1335 "parser.cc" - - yyvsp -= yylen; - yyssp -= yylen; - - + YYPOPSTACK (yylen); + yylen = 0; YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; @@ -1366,110 +1577,41 @@ yyerrlab: if (!yyerrstatus) { ++yynerrs; -#if YYERROR_VERBOSE - yyn = yypact[yystate]; - - if (YYPACT_NINF < yyn && yyn < YYLAST) - { - int yytype = YYTRANSLATE (yychar); - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - int yysize_overflow = 0; - char *yymsg = 0; -# define YYERROR_VERBOSE_ARGS_MAXIMUM 5 - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; - -#if 0 - /* This is so xgettext sees the translatable formats that are - constructed on the fly. */ - YY_("syntax error, unexpected %s"); - YY_("syntax error, unexpected %s, expecting %s"); - YY_("syntax error, unexpected %s, expecting %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); -#endif - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - - yyarg[0] = yytname[yytype]; - yyfmt = yystpcpy (yyformat, yyunexpected); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - yysize_overflow |= yysize1 < yysize; - yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; - } - - yyf = YY_(yyformat); - yysize1 = yysize + yystrlen (yyf); - yysize_overflow |= yysize1 < yysize; - yysize = yysize1; - - if (!yysize_overflow && yysize <= YYSTACK_ALLOC_MAXIMUM) - yymsg = (char *) YYSTACK_ALLOC (yysize); - if (yymsg) - { - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - char *yyp = yymsg; - int yyi = 0; - while ((*yyp = *yyf)) - { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; - } - else - { - yyp++; - yyf++; - } - } - yyerror (yymsg); +#if ! YYERROR_VERBOSE + yyerror (YY_("syntax error")); +#else + { + YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); + if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) + { + YYSIZE_T yyalloc = 2 * yysize; + if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) + yyalloc = YYSTACK_ALLOC_MAXIMUM; + if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); - } - else - { - yyerror (YY_("syntax error")); + yymsg = (char *) YYSTACK_ALLOC (yyalloc); + if (yymsg) + yymsg_alloc = yyalloc; + else + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + } + } + + if (0 < yysize && yysize <= yymsg_alloc) + { + (void) yysyntax_error (yymsg, yystate, yychar); + yyerror (yymsg); + } + else + { + yyerror (YY_("syntax error")); + if (yysize != 0) goto yyexhaustedlab; - } - } - else -#endif /* YYERROR_VERBOSE */ - yyerror (YY_("syntax error")); + } + } +#endif } @@ -1480,14 +1622,15 @@ yyerrlab: error, discard it. */ if (yychar <= YYEOF) - { + { /* Return failure if at end of input. */ if (yychar == YYEOF) YYABORT; - } + } else { - yydestruct ("Error: discarding", yytoken, &yylval); + yydestruct ("Error: discarding", + yytoken, &yylval); yychar = YYEMPTY; } } @@ -1505,11 +1648,14 @@ yyerrorlab: /* Pacify compilers like GCC when the user code never invokes YYERROR and the label yyerrorlab therefore never appears in user code. */ - if (0) + if (/*CONSTCOND*/ 0) goto yyerrorlab; -yyvsp -= yylen; - yyssp -= yylen; + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); yystate = *yyssp; goto yyerrlab1; @@ -1539,8 +1685,9 @@ yyerrlab1: YYABORT; - yydestruct ("Error: popping", yystos[yystate], yyvsp); - YYPOPSTACK; + yydestruct ("Error: popping", + yystos[yystate], yyvsp); + YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } @@ -1551,7 +1698,7 @@ yyerrlab1: *++yyvsp = yylval; - /* Shift the error token. */ + /* Shift the error token. */ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; @@ -1586,21 +1733,30 @@ yyreturn: if (yychar != YYEOF && yychar != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", yytoken, &yylval); + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); while (yyssp != yyss) { yydestruct ("Cleanup: popping", yystos[*yyssp], yyvsp); - YYPOPSTACK; + YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif - return yyresult; +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + /* Make sure YYID is used. */ + return YYID (yyresult); } -#line 176 "parser.y" +#line 174 "./parser.y" extern "C" { @@ -1610,7 +1766,7 @@ void yyerror(const char* s) } int yylex(){ - return in->scan(); + return in ? in->scan() : 0; } } // end extern "C" @@ -1621,7 +1777,14 @@ void parse(Scanner& i, std::ostream& o) { in = &i; - o << "/* Generated by re2c " PACKAGE_VERSION " */\n"; + o << "/* Generated by re2c " PACKAGE_VERSION; + if (!bNoGenerationDate) + { + o << " on "; + time_t now = time(&now); + o.write(ctime(&now), 24); + } + o << " */\n"; o << sourceFileInfo; while(i.echo()) @@ -1633,6 +1796,11 @@ void parse(Scanner& i, std::ostream& o) } o << sourceFileInfo; } + + RegExp::vFreeList.clear(); + Range::vFreeList.clear(); + Symbol::ClearTable(); + in = NULL; } } // end namespace re2c diff --git a/tools/re2c/parser.h b/tools/re2c/parser.h index 1d1707f848..1f367c58da 100644 --- a/tools/re2c/parser.h +++ b/tools/re2c/parser.h @@ -19,11 +19,6 @@ public: static Symbol *find(const SubStr&); static void ClearTable(); - ~Symbol() - { - /** \todo should we delete 're'? */ - } - typedef std::map SymbolTable; protected: diff --git a/tools/re2c/parser.y b/tools/re2c/parser.y index 5e3255b17d..fa6e267a71 100644 --- a/tools/re2c/parser.y +++ b/tools/re2c/parser.y @@ -28,7 +28,7 @@ void yyerror(const char*); static re2c::uint accept; static RegExp *spec; -static Scanner *in; +static Scanner *in = NULL; /* Bison version 1.875 emits a definition that is not working * with several g++ version. Hence we disable it here. @@ -92,14 +92,12 @@ decl : ID '=' expr ';' { if($1->re) in->fatal("sym already defined"); $1->re = $3; } - | CONFIG '=' VALUE ';' - { in->config(*$1, *$3); } - | CONFIG '=' NUMBER ';' - { in->config(*$1, $3); } - ; - -decl : ID '=' expr '/' + | ID '=' expr '/' { in->fatal("trailing contexts are not allowed in named definitions"); } + | CONFIG '=' VALUE ';' + { in->config(*$1, *$3); delete $1; delete $3; } + | CONFIG '=' NUMBER ';' + { in->config(*$1, $3); delete $1; } ; rule : expr look CODE @@ -182,7 +180,7 @@ void yyerror(const char* s) } int yylex(){ - return in->scan(); + return in ? in->scan() : 0; } } // end extern "C" @@ -193,9 +191,13 @@ void parse(Scanner& i, std::ostream& o) { in = &i; - o << "/* Generated by re2c " PACKAGE_VERSION " on "; - time_t now = time(&now); - o.write(ctime(&now), 24); + o << "/* Generated by re2c " PACKAGE_VERSION; + if (!bNoGenerationDate) + { + o << " on "; + time_t now = time(&now); + o.write(ctime(&now), 24); + } o << " */\n"; o << sourceFileInfo; @@ -208,6 +210,11 @@ void parse(Scanner& i, std::ostream& o) } o << sourceFileInfo; } + + RegExp::vFreeList.clear(); + Range::vFreeList.clear(); + Symbol::ClearTable(); + in = NULL; } } // end namespace re2c diff --git a/tools/re2c/re.h b/tools/re2c/re.h index 2267576519..2dd652bfc5 100644 --- a/tools/re2c/re.h +++ b/tools/re2c/re.h @@ -3,6 +3,7 @@ #define _re_h #include +#include #include "token.h" #include "ins.h" #include "globals.h" @@ -10,6 +11,51 @@ namespace re2c { +template +class free_list: protected std::set<_Ty> +{ +public: + typedef typename std::set<_Ty>::iterator iterator; + typedef typename std::set<_Ty>::size_type size_type; + typedef typename std::set<_Ty>::key_type key_type; + + free_list(): in_clear(false) + { + } + + using std::set<_Ty>::insert; + + size_type erase(const key_type& key) + { + if (!in_clear) + { + return std::set<_Ty>::erase(key); + } + return 0; + } + + void clear() + { + in_clear = true; + + for(iterator it = this->begin(); it != this->end(); ++it) + { + delete *it; + } + std::set<_Ty>::clear(); + + in_clear = false; + } + + ~free_list() + { + clear(); + } + +protected: + bool in_clear; +}; + typedef struct extop { char op; @@ -46,12 +92,18 @@ public: Range *next; uint lb, ub; // [lb,ub) + static free_list vFreeList; + public: Range(uint l, uint u) : next(NULL), lb(l), ub(u) - { } + { + vFreeList.insert(this); + } Range(Range &r) : next(NULL), lb(r.lb), ub(r.ub) - { } + { + vFreeList.insert(this); + } friend std::ostream& operator<<(std::ostream&, const Range&); friend std::ostream& operator<<(std::ostream&, const Range*); @@ -68,12 +120,18 @@ class RegExp public: uint size; + static free_list vFreeList; + public: RegExp() : size(0) { } - virtual ~RegExp() {} + virtual ~RegExp() + { + vFreeList.erase(this); + } + virtual const char *typeOf() = 0; RegExp *isA(const char *t) { @@ -178,6 +236,12 @@ public: public: RuleOp(RegExp*, RegExp*, Token*, uint); + + ~RuleOp() + { + delete code; + } + const char *typeOf() { return type; @@ -228,6 +292,8 @@ public: const RuleOp& op; }; +RegExp *mkAlt(RegExp*, RegExp*); + class AltOp: public RegExp { diff --git a/tools/re2c/re2c.vcproj b/tools/re2c/re2c.vcproj index 56250b1edd..dbaedb5f6d 100644 --- a/tools/re2c/re2c.vcproj +++ b/tools/re2c/re2c.vcproj @@ -487,6 +487,10 @@ RelativePath=".\code.h" > + + diff --git a/tools/re2c/scanner.cc b/tools/re2c/scanner.cc index 6d32c032ea..ee26a8c786 100644 --- a/tools/re2c/scanner.cc +++ b/tools/re2c/scanner.cc @@ -1,6 +1,6 @@ -/* Generated by re2c 0.10.5 */ +/* Generated by re2c 0.12.3 on Tue Jan 22 23:04:51 2008 */ #line 1 "scanner.re" -/* $Id: scanner.re,v 1.42 2006/04/17 00:18:45 helly Exp $ */ +/* $Id:$ */ #include #include #include @@ -19,7 +19,7 @@ extern YYSTYPE yylval; #define BSIZE 8192 -#define YYCTYPE char +#define YYCTYPE unsigned char #define YYCURSOR cursor #define YYLIMIT lim #define YYMARKER ptr @@ -99,28 +99,34 @@ echo: unsigned int yyaccept = 0; if((YYLIMIT - YYCURSOR) < 16) YYFILL(16); +(16); yych = *YYCURSOR; - if(yych <= ')') { - if(yych <= 0x00) goto yy7; - if(yych == 0x0A) goto yy5; - goto yy9; - } else { - if(yych <= '*') goto yy4; - if(yych != '/') goto yy9; + switch(yych) { + case 0x00: goto yy7; + case 0x0A: goto yy5; + case '*': goto yy4; + case '/': goto yy2; + default: goto yy9; } +yy2: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if(yych == '*') goto yy16; + switch(yych) { + case '*': goto yy16; + default: goto yy3; + } yy3: #line 184 "scanner.re" { goto echo; } -#line 120 "scanner.cc" +#line 124 "scanner.cc" yy4: yych = *++YYCURSOR; - if(yych == '/') goto yy10; - goto yy3; + switch(yych) { + case '/': goto yy10; + default: goto yy3; + } yy5: ++YYCURSOR; #line 167 "scanner.re" @@ -133,7 +139,7 @@ yy5: tok = pos = cursor; cline++; goto echo; } -#line 137 "scanner.cc" +#line 143 "scanner.cc" yy7: ++YYCURSOR; #line 176 "scanner.re" @@ -145,15 +151,18 @@ yy7: RETURN(0); } } -#line 149 "scanner.cc" +#line 155 "scanner.cc" yy9: yych = *++YYCURSOR; goto yy3; yy10: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if(yych == 0x0A) goto yy14; - if(yych == 0x0D) goto yy12; + switch(yych) { + case 0x0A: goto yy14; + case 0x0D: goto yy12; + default: goto yy11; + } yy11: #line 154 "scanner.re" { @@ -169,16 +178,18 @@ yy11: tok = pos = cursor; goto echo; } -#line 173 "scanner.cc" +#line 182 "scanner.cc" yy12: yych = *++YYCURSOR; - if(yych == 0x0A) goto yy14; + switch(yych) { + case 0x0A: goto yy14; + default: goto yy13; + } yy13: YYCURSOR = YYMARKER; - if(yyaccept <= 0) { - goto yy3; - } else { - goto yy11; + switch(yyaccept) { + case 0: goto yy3; + case 1: goto yy11; } yy14: ++YYCURSOR; @@ -197,12 +208,16 @@ yy14: tok = pos = cursor; goto echo; } -#line 201 "scanner.cc" +#line 212 "scanner.cc" yy16: yych = *++YYCURSOR; - if(yych != '!') goto yy13; + switch(yych) { + case '!': goto yy17; + default: goto yy13; + } +yy17: yych = *++YYCURSOR; - switch(yych){ + switch(yych) { case 'g': goto yy19; case 'i': goto yy18; case 'm': goto yy20; @@ -211,23 +226,41 @@ yy16: } yy18: yych = *++YYCURSOR; - if(yych == 'g') goto yy47; - goto yy13; + switch(yych) { + case 'g': goto yy47; + default: goto yy13; + } yy19: yych = *++YYCURSOR; - if(yych == 'e') goto yy34; - goto yy13; + switch(yych) { + case 'e': goto yy34; + default: goto yy13; + } yy20: yych = *++YYCURSOR; - if(yych == 'a') goto yy26; - goto yy13; + switch(yych) { + case 'a': goto yy26; + default: goto yy13; + } yy21: yych = *++YYCURSOR; - if(yych != 'e') goto yy13; + switch(yych) { + case 'e': goto yy22; + default: goto yy13; + } +yy22: yych = *++YYCURSOR; - if(yych != '2') goto yy13; + switch(yych) { + case '2': goto yy23; + default: goto yy13; + } +yy23: yych = *++YYCURSOR; - if(yych != 'c') goto yy13; + switch(yych) { + case 'c': goto yy24; + default: goto yy13; + } +yy24: ++YYCURSOR; #line 111 "scanner.re" { @@ -238,20 +271,44 @@ yy21: tok = cursor; RETURN(1); } -#line 242 "scanner.cc" +#line 275 "scanner.cc" yy26: yych = *++YYCURSOR; - if(yych != 'x') goto yy13; + switch(yych) { + case 'x': goto yy27; + default: goto yy13; + } +yy27: yych = *++YYCURSOR; - if(yych != ':') goto yy13; + switch(yych) { + case ':': goto yy28; + default: goto yy13; + } +yy28: yych = *++YYCURSOR; - if(yych != 'r') goto yy13; + switch(yych) { + case 'r': goto yy29; + default: goto yy13; + } +yy29: yych = *++YYCURSOR; - if(yych != 'e') goto yy13; + switch(yych) { + case 'e': goto yy30; + default: goto yy13; + } +yy30: yych = *++YYCURSOR; - if(yych != '2') goto yy13; + switch(yych) { + case '2': goto yy31; + default: goto yy13; + } +yy31: yych = *++YYCURSOR; - if(yych != 'c') goto yy13; + switch(yych) { + case 'c': goto yy32; + default: goto yy13; + } +yy32: ++YYCURSOR; #line 119 "scanner.re" { @@ -264,30 +321,74 @@ yy26: bUsedYYMaxFill = true; goto echo; } -#line 268 "scanner.cc" +#line 325 "scanner.cc" yy34: yych = *++YYCURSOR; - if(yych != 't') goto yy13; + switch(yych) { + case 't': goto yy35; + default: goto yy13; + } +yy35: yych = *++YYCURSOR; - if(yych != 's') goto yy13; + switch(yych) { + case 's': goto yy36; + default: goto yy13; + } +yy36: yych = *++YYCURSOR; - if(yych != 't') goto yy13; + switch(yych) { + case 't': goto yy37; + default: goto yy13; + } +yy37: yych = *++YYCURSOR; - if(yych != 'a') goto yy13; + switch(yych) { + case 'a': goto yy38; + default: goto yy13; + } +yy38: yych = *++YYCURSOR; - if(yych != 't') goto yy13; + switch(yych) { + case 't': goto yy39; + default: goto yy13; + } +yy39: yych = *++YYCURSOR; - if(yych != 'e') goto yy13; + switch(yych) { + case 'e': goto yy40; + default: goto yy13; + } +yy40: yych = *++YYCURSOR; - if(yych != ':') goto yy13; + switch(yych) { + case ':': goto yy41; + default: goto yy13; + } +yy41: yych = *++YYCURSOR; - if(yych != 'r') goto yy13; + switch(yych) { + case 'r': goto yy42; + default: goto yy13; + } +yy42: yych = *++YYCURSOR; - if(yych != 'e') goto yy13; + switch(yych) { + case 'e': goto yy43; + default: goto yy13; + } +yy43: yych = *++YYCURSOR; - if(yych != '2') goto yy13; + switch(yych) { + case '2': goto yy44; + default: goto yy13; + } +yy44: yych = *++YYCURSOR; - if(yych != 'c') goto yy13; + switch(yych) { + case 'c': goto yy45; + default: goto yy13; + } +yy45: ++YYCURSOR; #line 129 "scanner.re" { @@ -296,26 +397,62 @@ yy34: ignore_eoc = true; goto echo; } -#line 300 "scanner.cc" +#line 401 "scanner.cc" yy47: yych = *++YYCURSOR; - if(yych != 'n') goto yy13; + switch(yych) { + case 'n': goto yy48; + default: goto yy13; + } +yy48: yych = *++YYCURSOR; - if(yych != 'o') goto yy13; + switch(yych) { + case 'o': goto yy49; + default: goto yy13; + } +yy49: yych = *++YYCURSOR; - if(yych != 'r') goto yy13; + switch(yych) { + case 'r': goto yy50; + default: goto yy13; + } +yy50: yych = *++YYCURSOR; - if(yych != 'e') goto yy13; + switch(yych) { + case 'e': goto yy51; + default: goto yy13; + } +yy51: yych = *++YYCURSOR; - if(yych != ':') goto yy13; + switch(yych) { + case ':': goto yy52; + default: goto yy13; + } +yy52: yych = *++YYCURSOR; - if(yych != 'r') goto yy13; + switch(yych) { + case 'r': goto yy53; + default: goto yy13; + } +yy53: yych = *++YYCURSOR; - if(yych != 'e') goto yy13; + switch(yych) { + case 'e': goto yy54; + default: goto yy13; + } +yy54: yych = *++YYCURSOR; - if(yych != '2') goto yy13; + switch(yych) { + case '2': goto yy55; + default: goto yy13; + } +yy55: yych = *++YYCURSOR; - if(yych != 'c') goto yy13; + switch(yych) { + case 'c': goto yy56; + default: goto yy13; + } +yy56: ++YYCURSOR; #line 135 "scanner.re" { @@ -323,7 +460,7 @@ yy47: ignore_eoc = true; goto echo; } -#line 327 "scanner.cc" +#line 464 "scanner.cc" } #line 187 "scanner.re" @@ -348,126 +485,166 @@ scan: goto value; } -#line 352 "scanner.cc" +#line 489 "scanner.cc" { YYCTYPE yych; unsigned int yyaccept = 0; if((YYLIMIT - YYCURSOR) < 5) YYFILL(5); +(5); yych = *YYCURSOR; - if(yych <= '/') { - if(yych <= '!') { - if(yych <= 0x0C) { - if(yych <= 0x08) goto yy85; - if(yych <= 0x09) goto yy79; - if(yych <= 0x0A) goto yy81; - goto yy85; - } else { - if(yych <= 0x0D) goto yy83; - if(yych == ' ') goto yy79; - goto yy85; - } - } else { - if(yych <= ')') { - if(yych <= '"') goto yy66; - if(yych <= '&') goto yy85; - if(yych <= '\'') goto yy68; - goto yy72; - } else { - if(yych <= '+') { - if(yych <= '*') goto yy64; - goto yy73; - } else { - if(yych <= '-') goto yy85; - if(yych <= '.') goto yy77; - goto yy62; - } - } - } - } else { - if(yych <= 'Z') { - if(yych <= '=') { - if(yych == ';') goto yy72; - if(yych <= '<') goto yy85; - goto yy72; - } else { - if(yych == '?') goto yy73; - if(yych <= '@') goto yy85; - goto yy76; - } - } else { - if(yych <= 'q') { - if(yych <= '[') goto yy70; - if(yych <= '\\') goto yy72; - if(yych <= '`') goto yy85; - goto yy76; - } else { - if(yych <= 'z') { - if(yych <= 'r') goto yy74; - goto yy76; - } else { - if(yych <= '{') goto yy60; - if(yych <= '|') goto yy72; - goto yy85; - } - } - } + switch(yych) { + case 0x09: + case ' ': goto yy79; + case 0x0A: goto yy81; + case 0x0D: goto yy83; + case '"': goto yy66; + case '\'': goto yy68; + case '(': + case ')': + case ';': + case '=': + case '\\': + case '|': goto yy72; + case '*': goto yy64; + case '+': + case '?': goto yy73; + case '.': goto yy77; + case '/': goto yy62; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy76; + case '[': goto yy70; + case 'r': goto yy74; + case '{': goto yy60; + default: goto yy85; } yy60: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if(yych <= '/') { - if(yych == ',') goto yy126; - } else { - if(yych <= '0') goto yy123; - if(yych <= '9') goto yy124; + switch(yych) { + case ',': goto yy126; + case '0': goto yy123; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy124; + default: goto yy61; } yy61: #line 209 "scanner.re" { depth = 1; goto code; } -#line 430 "scanner.cc" +#line 593 "scanner.cc" yy62: ++YYCURSOR; - if((yych = *YYCURSOR) == '*') goto yy121; + switch((yych = *YYCURSOR)) { + case '*': goto yy121; + default: goto yy63; + } yy63: #line 239 "scanner.re" { RETURN(*tok); } -#line 437 "scanner.cc" +#line 603 "scanner.cc" yy64: ++YYCURSOR; - if((yych = *YYCURSOR) == '/') goto yy119; + switch((yych = *YYCURSOR)) { + case '/': goto yy119; + default: goto yy65; + } yy65: #line 241 "scanner.re" { yylval.op = *tok; RETURN(CLOSE); } -#line 445 "scanner.cc" +#line 614 "scanner.cc" yy66: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if(yych != 0x0A) goto yy115; + switch(yych) { + case 0x0A: goto yy67; + default: goto yy115; + } yy67: #line 226 "scanner.re" { fatal("unterminated string constant (missing \")"); } -#line 453 "scanner.cc" +#line 625 "scanner.cc" yy68: yyaccept = 2; yych = *(YYMARKER = ++YYCURSOR); - if(yych != 0x0A) goto yy110; + switch(yych) { + case 0x0A: goto yy69; + default: goto yy110; + } yy69: #line 227 "scanner.re" { fatal("unterminated string constant (missing ')"); } -#line 461 "scanner.cc" +#line 636 "scanner.cc" yy70: yyaccept = 3; yych = *(YYMARKER = ++YYCURSOR); - if(yych == 0x0A) goto yy71; - if(yych == '^') goto yy101; - goto yy100; + switch(yych) { + case 0x0A: goto yy71; + case '^': goto yy101; + default: goto yy100; + } yy71: #line 237 "scanner.re" { fatal("unterminated range (missing ])"); } -#line 471 "scanner.cc" +#line 648 "scanner.cc" yy72: yych = *++YYCURSOR; goto yy63; @@ -476,14 +653,16 @@ yy73: goto yy65; yy74: ++YYCURSOR; - if((yych = *YYCURSOR) == 'e') goto yy91; - goto yy90; + switch((yych = *YYCURSOR)) { + case 'e': goto yy91; + default: goto yy90; + } yy75: #line 268 "scanner.re" { cur = cursor; yylval.symbol = Symbol::find(token()); return ID; } -#line 487 "scanner.cc" +#line 666 "scanner.cc" yy76: yych = *++YYCURSOR; goto yy90; @@ -494,7 +673,7 @@ yy77: yylval.regexp = mkDot(); return RANGE; } -#line 498 "scanner.cc" +#line 677 "scanner.cc" yy79: ++YYCURSOR; yych = *YYCURSOR; @@ -502,7 +681,7 @@ yy79: yy80: #line 277 "scanner.re" { goto scan; } -#line 506 "scanner.cc" +#line 685 "scanner.cc" yy81: ++YYCURSOR; yy82: @@ -511,10 +690,13 @@ yy82: pos = cursor; cline++; goto scan; } -#line 515 "scanner.cc" +#line 694 "scanner.cc" yy83: ++YYCURSOR; - if((yych = *YYCURSOR) == 0x0A) goto yy86; + switch((yych = *YYCURSOR)) { + case 0x0A: goto yy86; + default: goto yy84; + } yy84: #line 284 "scanner.re" { std::ostringstream msg; @@ -523,7 +705,7 @@ yy84: fatal(msg.str().c_str()); goto scan; } -#line 527 "scanner.cc" +#line 709 "scanner.cc" yy85: yych = *++YYCURSOR; goto yy84; @@ -535,86 +717,243 @@ yy87: if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; yy88: - if(yych == 0x09) goto yy87; - if(yych == ' ') goto yy87; - goto yy80; + switch(yych) { + case 0x09: + case ' ': goto yy87; + default: goto yy80; + } yy89: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; yy90: - if(yych <= '@') { - if(yych <= '/') goto yy75; - if(yych <= '9') goto yy89; - goto yy75; - } else { - if(yych <= 'Z') goto yy89; - if(yych <= '`') goto yy75; - if(yych <= 'z') goto yy89; - goto yy75; + switch(yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy89; + default: goto yy75; } yy91: yych = *++YYCURSOR; - if(yych != '2') goto yy90; + switch(yych) { + case '2': goto yy92; + default: goto yy90; + } +yy92: yych = *++YYCURSOR; - if(yych != 'c') goto yy90; + switch(yych) { + case 'c': goto yy93; + default: goto yy90; + } +yy93: yyaccept = 4; yych = *(YYMARKER = ++YYCURSOR); - if(yych != ':') goto yy90; + switch(yych) { + case ':': goto yy94; + default: goto yy90; + } yy94: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych <= '@') goto yy95; - if(yych <= 'Z') goto yy96; - if(yych <= '`') goto yy95; - if(yych <= 'z') goto yy96; + switch(yych) { + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy96; + default: goto yy95; + } yy95: YYCURSOR = YYMARKER; - if(yyaccept <= 3) { - if(yyaccept <= 1) { - if(yyaccept <= 0) { - goto yy61; - } else { - goto yy67; - } - } else { - if(yyaccept <= 2) { - goto yy69; - } else { - goto yy71; - } - } - } else { - if(yyaccept <= 5) { - if(yyaccept <= 4) { - goto yy75; - } else { - goto yy98; - } - } else { - goto yy127; - } + switch(yyaccept) { + case 0: goto yy61; + case 1: goto yy67; + case 2: goto yy69; + case 3: goto yy71; + case 4: goto yy75; + case 5: goto yy98; + case 6: goto yy127; } yy96: yyaccept = 5; YYMARKER = ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych <= 'Z') { - if(yych <= '9') { - if(yych >= '0') goto yy96; - } else { - if(yych <= ':') goto yy94; - if(yych >= 'A') goto yy96; - } - } else { - if(yych <= '_') { - if(yych >= '_') goto yy96; - } else { - if(yych <= '`') goto yy98; - if(yych <= 'z') goto yy96; - } + switch(yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy96; + case ':': goto yy94; + default: goto yy98; } yy98: #line 261 "scanner.re" @@ -624,212 +963,256 @@ yy98: yylval.str = new Str(token()); return CONFIG; } -#line 628 "scanner.cc" +#line 967 "scanner.cc" yy99: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; yy100: - if(yych <= '[') { - if(yych == 0x0A) goto yy95; - goto yy99; - } else { - if(yych <= '\\') goto yy103; - if(yych <= ']') goto yy104; - goto yy99; + switch(yych) { + case 0x0A: goto yy95; + case '\\': goto yy103; + case ']': goto yy104; + default: goto yy99; } yy101: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych <= '[') { - if(yych == 0x0A) goto yy95; - goto yy101; - } else { - if(yych <= '\\') goto yy106; - if(yych <= ']') goto yy107; - goto yy101; + switch(yych) { + case 0x0A: goto yy95; + case '\\': goto yy106; + case ']': goto yy107; + default: goto yy101; } yy103: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych == 0x0A) goto yy95; - goto yy99; + switch(yych) { + case 0x0A: goto yy95; + default: goto yy99; + } yy104: ++YYCURSOR; #line 233 "scanner.re" { cur = cursor; yylval.regexp = ranToRE(token()); return RANGE; } -#line 666 "scanner.cc" +#line 1003 "scanner.cc" yy106: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych == 0x0A) goto yy95; - goto yy101; + switch(yych) { + case 0x0A: goto yy95; + default: goto yy101; + } yy107: ++YYCURSOR; #line 229 "scanner.re" { cur = cursor; yylval.regexp = invToRE(token()); return RANGE; } -#line 679 "scanner.cc" +#line 1018 "scanner.cc" yy109: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; yy110: - if(yych <= '&') { - if(yych == 0x0A) goto yy95; - goto yy109; - } else { - if(yych <= '\'') goto yy112; - if(yych != '\\') goto yy109; + switch(yych) { + case 0x0A: goto yy95; + case '\'': goto yy112; + case '\\': goto yy111; + default: goto yy109; } +yy111: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych == 0x0A) goto yy95; - goto yy109; + switch(yych) { + case 0x0A: goto yy95; + default: goto yy109; + } yy112: ++YYCURSOR; #line 222 "scanner.re" { cur = cursor; yylval.regexp = strToCaseInsensitiveRE(token()); return STRING; } -#line 703 "scanner.cc" +#line 1044 "scanner.cc" yy114: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; yy115: - if(yych <= '!') { - if(yych == 0x0A) goto yy95; - goto yy114; - } else { - if(yych <= '"') goto yy117; - if(yych != '\\') goto yy114; + switch(yych) { + case 0x0A: goto yy95; + case '"': goto yy117; + case '\\': goto yy116; + default: goto yy114; } +yy116: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych == 0x0A) goto yy95; - goto yy114; + switch(yych) { + case 0x0A: goto yy95; + default: goto yy114; + } yy117: ++YYCURSOR; #line 218 "scanner.re" { cur = cursor; yylval.regexp = strToRE(token()); return STRING; } -#line 727 "scanner.cc" +#line 1070 "scanner.cc" yy119: ++YYCURSOR; #line 215 "scanner.re" { tok = cursor; RETURN(0); } -#line 733 "scanner.cc" +#line 1076 "scanner.cc" yy121: ++YYCURSOR; #line 212 "scanner.re" { depth = 1; goto comment; } -#line 739 "scanner.cc" +#line 1082 "scanner.cc" yy123: yych = *++YYCURSOR; - if(yych == ',') goto yy137; - goto yy125; + switch(yych) { + case ',': goto yy137; + default: goto yy125; + } yy124: ++YYCURSOR; if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); +(2); yych = *YYCURSOR; yy125: - if(yych <= '/') { - if(yych == ',') goto yy130; - goto yy95; - } else { - if(yych <= '9') goto yy124; - if(yych == '}') goto yy128; - goto yy95; + switch(yych) { + case ',': goto yy130; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy124; + case '}': goto yy128; + default: goto yy95; } yy126: ++YYCURSOR; yy127: #line 259 "scanner.re" { fatal("illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers"); } -#line 762 "scanner.cc" +#line 1115 "scanner.cc" yy128: ++YYCURSOR; #line 247 "scanner.re" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = atoi((char *)tok+1); RETURN(CLOSESIZE); } -#line 769 "scanner.cc" +#line 1122 "scanner.cc" yy130: yyaccept = 6; yych = *(YYMARKER = ++YYCURSOR); - if(yych <= '/') goto yy127; - if(yych <= '9') goto yy133; - if(yych != '}') goto yy127; + switch(yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy133; + case '}': goto yy131; + default: goto yy127; + } +yy131: ++YYCURSOR; #line 255 "scanner.re" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = -1; RETURN(CLOSESIZE); } -#line 781 "scanner.cc" +#line 1146 "scanner.cc" yy133: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych <= '/') goto yy95; - if(yych <= '9') goto yy133; - if(yych != '}') goto yy95; + switch(yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy133; + case '}': goto yy135; + default: goto yy95; + } +yy135: ++YYCURSOR; #line 251 "scanner.re" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = MAX(yylval.extop.minsize,atoi(strchr((char *)tok, ',')+1)); RETURN(CLOSESIZE); } -#line 794 "scanner.cc" +#line 1171 "scanner.cc" yy137: yyaccept = 6; yych = *(YYMARKER = ++YYCURSOR); - if(yych <= '/') goto yy127; - if(yych <= '9') goto yy133; - if(yych != '}') goto yy127; + switch(yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy133; + case '}': goto yy138; + default: goto yy127; + } +yy138: ++YYCURSOR; #line 244 "scanner.re" { yylval.op = '*'; RETURN(CLOSE); } -#line 805 "scanner.cc" +#line 1194 "scanner.cc" } #line 290 "scanner.re" code: -#line 812 "scanner.cc" +#line 1201 "scanner.cc" { YYCTYPE yych; if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); +(2); yych = *YYCURSOR; - if(yych <= '&') { - if(yych <= 0x0A) { - if(yych <= 0x09) goto yy148; - goto yy146; - } else { - if(yych == '"') goto yy150; - goto yy148; - } - } else { - if(yych <= '{') { - if(yych <= '\'') goto yy151; - if(yych <= 'z') goto yy148; - goto yy144; - } else { - if(yych != '}') goto yy148; - } + switch(yych) { + case 0x00: goto yy148; + case 0x0A: goto yy146; + case '"': goto yy152; + case '\'': goto yy153; + case '{': goto yy144; + case '}': goto yy142; + default: goto yy150; } +yy142: ++YYCURSOR; #line 294 "scanner.re" { if(--depth == 0){ @@ -838,13 +1221,13 @@ code: return CODE; } goto code; } -#line 842 "scanner.cc" +#line 1225 "scanner.cc" yy144: ++YYCURSOR; #line 300 "scanner.re" { ++depth; goto code; } -#line 848 "scanner.cc" +#line 1231 "scanner.cc" yy146: ++YYCURSOR; #line 302 "scanner.re" @@ -852,415 +1235,403 @@ yy146: pos = cursor; cline++; goto code; } -#line 856 "scanner.cc" +#line 1239 "scanner.cc" yy148: ++YYCURSOR; -yy149: #line 306 "scanner.re" - { goto code; } -#line 862 "scanner.cc" + { if(cursor == eof) { + if (depth) fatal("missing '}'"); + RETURN(0); + } + goto code; + } +#line 1249 "scanner.cc" yy150: - yych = *(YYMARKER = ++YYCURSOR); - if(yych == 0x0A) goto yy149; - goto yy157; -yy151: - yych = *(YYMARKER = ++YYCURSOR); - if(yych == 0x0A) goto yy149; - goto yy153; -yy152: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; +yy151: +#line 312 "scanner.re" + { goto code; } +#line 1255 "scanner.cc" +yy152: + yych = *(YYMARKER = ++YYCURSOR); + switch(yych) { + case 0x0A: goto yy151; + default: goto yy159; + } yy153: - if(yych <= '&') { - if(yych != 0x0A) goto yy152; - } else { - if(yych <= '\'') goto yy148; - if(yych == '\\') goto yy155; - goto yy152; + yych = *(YYMARKER = ++YYCURSOR); + switch(yych) { + case 0x0A: goto yy151; + default: goto yy155; } yy154: - YYCURSOR = YYMARKER; - goto yy149; + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; yy155: - ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if(yych == 0x0A) goto yy154; - goto yy152; -yy156: - ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy157: - if(yych <= '!') { - if(yych == 0x0A) goto yy154; - goto yy156; - } else { - if(yych <= '"') goto yy148; - if(yych != '\\') goto yy156; + switch(yych) { + case 0x0A: goto yy156; + case '\'': goto yy150; + case '\\': goto yy157; + default: goto yy154; } +yy156: + YYCURSOR = YYMARKER; + goto yy151; +yy157: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych == 0x0A) goto yy154; - goto yy156; + switch(yych) { + case 0x0A: goto yy156; + default: goto yy154; + } +yy158: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy159: + switch(yych) { + case 0x0A: goto yy156; + case '"': goto yy150; + case '\\': goto yy160; + default: goto yy158; + } +yy160: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych) { + case 0x0A: goto yy156; + default: goto yy158; + } } -#line 307 "scanner.re" +#line 313 "scanner.re" comment: -#line 915 "scanner.cc" +#line 1315 "scanner.cc" { YYCTYPE yych; if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); +(2); yych = *YYCURSOR; - if(yych <= ')') { - if(yych == 0x0A) goto yy164; - goto yy166; - } else { - if(yych <= '*') goto yy161; - if(yych == '/') goto yy163; - goto yy166; + switch(yych) { + case 0x0A: goto yy166; + case '*': goto yy163; + case '/': goto yy165; + default: goto yy168; } -yy161: +yy163: ++YYCURSOR; - if((yych = *YYCURSOR) == '/') goto yy169; -yy162: -#line 322 "scanner.re" + switch((yych = *YYCURSOR)) { + case '/': goto yy171; + default: goto yy164; + } +yy164: +#line 328 "scanner.re" { if(cursor == eof) RETURN(0); goto comment; } -#line 935 "scanner.cc" -yy163: +#line 1337 "scanner.cc" +yy165: yych = *++YYCURSOR; - if(yych == '*') goto yy167; - goto yy162; -yy164: + switch(yych) { + case '*': goto yy169; + default: goto yy164; + } +yy166: ++YYCURSOR; -#line 318 "scanner.re" +#line 324 "scanner.re" { if(cursor == eof) RETURN(0); tok = pos = cursor; cline++; goto comment; } -#line 947 "scanner.cc" -yy166: +#line 1351 "scanner.cc" +yy168: yych = *++YYCURSOR; - goto yy162; -yy167: + goto yy164; +yy169: ++YYCURSOR; -#line 315 "scanner.re" +#line 321 "scanner.re" { ++depth; fatal("ambiguous /* found"); goto comment; } -#line 957 "scanner.cc" -yy169: +#line 1361 "scanner.cc" +yy171: ++YYCURSOR; -#line 311 "scanner.re" +#line 317 "scanner.re" { if(--depth == 0) goto scan; else goto comment; } -#line 965 "scanner.cc" +#line 1369 "scanner.cc" } -#line 324 "scanner.re" +#line 330 "scanner.re" config: -#line 972 "scanner.cc" +#line 1376 "scanner.cc" { YYCTYPE yych; if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); +(2); yych = *YYCURSOR; - if(yych <= 0x1F) { - if(yych != 0x09) goto yy177; - } else { - if(yych <= ' ') goto yy173; - if(yych == '=') goto yy175; - goto yy177; + switch(yych) { + case 0x09: + case ' ': goto yy175; + case '=': goto yy177; + default: goto yy179; } -yy173: - ++YYCURSOR; - yych = *YYCURSOR; - goto yy182; -yy174: -#line 328 "scanner.re" - { goto config; } -#line 991 "scanner.cc" yy175: ++YYCURSOR; yych = *YYCURSOR; - goto yy180; + goto yy184; yy176: -#line 329 "scanner.re" +#line 334 "scanner.re" + { goto config; } +#line 1395 "scanner.cc" +yy177: + ++YYCURSOR; + yych = *YYCURSOR; + goto yy182; +yy178: +#line 335 "scanner.re" { iscfg = 2; cur = cursor; RETURN('='); } -#line 1002 "scanner.cc" -yy177: - ++YYCURSOR; -#line 333 "scanner.re" - { fatal("missing '='"); } -#line 1007 "scanner.cc" +#line 1406 "scanner.cc" yy179: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy180: - if(yych == 0x09) goto yy179; - if(yych == ' ') goto yy179; - goto yy176; +#line 339 "scanner.re" + { fatal("missing '='"); } +#line 1411 "scanner.cc" yy181: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; yy182: - if(yych == 0x09) goto yy181; - if(yych == ' ') goto yy181; - goto yy174; + switch(yych) { + case 0x09: + case ' ': goto yy181; + default: goto yy178; + } +yy183: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy184: + switch(yych) { + case 0x09: + case ' ': goto yy183; + default: goto yy176; + } } -#line 334 "scanner.re" +#line 340 "scanner.re" value: -#line 1030 "scanner.cc" +#line 1438 "scanner.cc" { YYCTYPE yych; if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); +(2); yych = *YYCURSOR; - if(yych <= '&') { - if(yych <= 0x0D) { - if(yych <= 0x08) goto yy191; - if(yych <= 0x0A) goto yy185; - if(yych <= 0x0C) goto yy191; - } else { - if(yych <= ' ') { - if(yych <= 0x1F) goto yy191; - } else { - if(yych == '"') goto yy193; - goto yy191; - } - } - } else { - if(yych <= '/') { - if(yych <= '\'') goto yy195; - if(yych == '-') goto yy188; - goto yy191; - } else { - if(yych <= '9') { - if(yych <= '0') goto yy186; - goto yy189; - } else { - if(yych != ';') goto yy191; - } - } + switch(yych) { + case 0x09: + case 0x0A: + case 0x0D: + case ' ': + case ';': goto yy187; + case '"': goto yy195; + case '\'': goto yy197; + case '-': goto yy190; + case '0': goto yy188; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy191; + default: goto yy193; } -yy185: -#line 343 "scanner.re" +yy187: +#line 349 "scanner.re" { cur = cursor; yylval.str = new Str(token()); iscfg = 0; return VALUE; } -#line 1069 "scanner.cc" -yy186: +#line 1472 "scanner.cc" +yy188: ++YYCURSOR; - if((yych = *YYCURSOR) <= 0x0D) { - if(yych <= 0x08) goto yy191; - if(yych <= 0x0A) goto yy187; - if(yych <= 0x0C) goto yy191; - } else { - if(yych <= ' ') { - if(yych <= 0x1F) goto yy191; - } else { - if(yych != ';') goto yy191; - } + switch((yych = *YYCURSOR)) { + case 0x09: + case 0x0A: + case 0x0D: + case ' ': + case ';': goto yy189; + default: goto yy193; } -yy187: -#line 338 "scanner.re" +yy189: +#line 344 "scanner.re" { cur = cursor; yylval.number = atoi(token().to_string().c_str()); iscfg = 0; return NUMBER; } -#line 1090 "scanner.cc" -yy188: +#line 1490 "scanner.cc" +yy190: yych = *++YYCURSOR; - if(yych <= '0') goto yy192; - if(yych >= ':') goto yy192; -yy189: - ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if(yych <= 0x1F) { - if(yych <= 0x0A) { - if(yych >= 0x09) goto yy187; - } else { - if(yych == 0x0D) goto yy187; - } - } else { - if(yych <= '9') { - if(yych <= ' ') goto yy187; - if(yych >= '0') goto yy189; - } else { - if(yych == ';') goto yy187; - } + switch(yych) { + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy191; + default: goto yy194; } yy191: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy192: - if(yych <= 0x0D) { - if(yych <= 0x08) goto yy191; - if(yych <= 0x0A) goto yy185; - if(yych <= 0x0C) goto yy191; - goto yy185; - } else { - if(yych <= ' ') { - if(yych <= 0x1F) goto yy191; - goto yy185; - } else { - if(yych == ';') goto yy185; - goto yy191; - } + switch(yych) { + case 0x09: + case 0x0A: + case 0x0D: + case ' ': + case ';': goto yy189; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy191; + default: goto yy193; } yy193: - YYMARKER = ++YYCURSOR; + ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych <= ' ') { - if(yych <= 0x0A) { - if(yych <= 0x08) goto yy193; - if(yych <= 0x09) goto yy203; - goto yy185; - } else { - if(yych == 0x0D) goto yy203; - if(yych <= 0x1F) goto yy193; - goto yy203; - } - } else { - if(yych <= ':') { - if(yych == '"') goto yy191; - goto yy193; - } else { - if(yych <= ';') goto yy203; - if(yych == '\\') goto yy205; - goto yy193; - } +yy194: + switch(yych) { + case 0x09: + case 0x0A: + case 0x0D: + case ' ': + case ';': goto yy187; + default: goto yy193; } yy195: YYMARKER = ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych <= ' ') { - if(yych <= 0x0A) { - if(yych <= 0x08) goto yy195; - if(yych >= 0x0A) goto yy185; - } else { - if(yych == 0x0D) goto yy197; - if(yych <= 0x1F) goto yy195; - } - } else { - if(yych <= ':') { - if(yych == '\'') goto yy191; - goto yy195; - } else { - if(yych <= ';') goto yy197; - if(yych == '\\') goto yy200; - goto yy195; - } + switch(yych) { + case 0x09: + case 0x0D: + case ' ': + case ';': goto yy205; + case 0x0A: goto yy187; + case '"': goto yy193; + case '\\': goto yy207; + default: goto yy195; } yy197: - ++YYCURSOR; + YYMARKER = ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych <= '&') { - if(yych != 0x0A) goto yy197; - } else { - if(yych <= '\'') goto yy201; - if(yych == '\\') goto yy202; - goto yy197; + switch(yych) { + case 0x09: + case 0x0D: + case ' ': + case ';': goto yy199; + case 0x0A: goto yy187; + case '\'': goto yy193; + case '\\': goto yy202; + default: goto yy197; } yy199: - YYCURSOR = YYMARKER; - goto yy185; -yy200: - YYMARKER = ++YYCURSOR; + ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych <= 0x0D) { - if(yych <= 0x09) { - if(yych <= 0x08) goto yy195; - goto yy197; - } else { - if(yych <= 0x0A) goto yy185; - if(yych <= 0x0C) goto yy195; - goto yy197; - } - } else { - if(yych <= ' ') { - if(yych <= 0x1F) goto yy195; - goto yy197; - } else { - if(yych == ';') goto yy197; - goto yy195; - } + switch(yych) { + case 0x0A: goto yy201; + case '\'': goto yy203; + case '\\': goto yy204; + default: goto yy199; } yy201: - yych = *++YYCURSOR; - goto yy185; + YYCURSOR = YYMARKER; + goto yy187; yy202: - ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if(yych == 0x0A) goto yy199; - goto yy197; -yy203: - ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if(yych <= '!') { - if(yych == 0x0A) goto yy199; - goto yy203; - } else { - if(yych <= '"') goto yy201; - if(yych == '\\') goto yy206; - goto yy203; - } -yy205: YYMARKER = ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych <= 0x0D) { - if(yych <= 0x09) { - if(yych <= 0x08) goto yy193; - goto yy203; - } else { - if(yych <= 0x0A) goto yy185; - if(yych <= 0x0C) goto yy193; - goto yy203; - } - } else { - if(yych <= ' ') { - if(yych <= 0x1F) goto yy193; - goto yy203; - } else { - if(yych == ';') goto yy203; - goto yy193; - } + switch(yych) { + case 0x09: + case 0x0D: + case ' ': + case ';': goto yy199; + case 0x0A: goto yy187; + default: goto yy197; } -yy206: +yy203: + yych = *++YYCURSOR; + goto yy187; +yy204: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych == 0x0A) goto yy199; - goto yy203; + switch(yych) { + case 0x0A: goto yy201; + default: goto yy199; + } +yy205: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych) { + case 0x0A: goto yy201; + case '"': goto yy203; + case '\\': goto yy208; + default: goto yy205; + } +yy207: + YYMARKER = ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych) { + case 0x09: + case 0x0D: + case ' ': + case ';': goto yy205; + case 0x0A: goto yy187; + default: goto yy195; + } +yy208: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych) { + case 0x0A: goto yy201; + default: goto yy205; + } } -#line 348 "scanner.re" +#line 354 "scanner.re" } @@ -1279,5 +1650,13 @@ void Scanner::fatal(uint ofs, const char *msg) const exit(1); } +Scanner::~Scanner() +{ + if (bot) + { + delete [] bot; + } +} + } // end namespace re2c diff --git a/tools/re2c/scanner.h b/tools/re2c/scanner.h index 94358b389e..ddff0c13b8 100644 --- a/tools/re2c/scanner.h +++ b/tools/re2c/scanner.h @@ -28,6 +28,8 @@ private: public: Scanner(const char*, std::istream&, std::ostream&); + ~Scanner(); + int echo(); int scan(); @@ -66,7 +68,7 @@ inline SubStr Scanner::token() const inline uint Scanner::xlat(uint c) const { - return re2c::wFlag ? c : re2c::xlat[c]; + return re2c::wFlag ? c : re2c::xlat[c & 0xFF]; } } // end namespace re2c diff --git a/tools/re2c/scanner.re b/tools/re2c/scanner.re index 3ce436e49d..743675df6e 100644 --- a/tools/re2c/scanner.re +++ b/tools/re2c/scanner.re @@ -1,4 +1,4 @@ -/* $Id: scanner.re,v 1.42 2006/04/17 00:18:45 helly Exp $ */ +/* $Id:$ */ #include #include #include @@ -17,7 +17,7 @@ extern YYSTYPE yylval; #define BSIZE 8192 -#define YYCTYPE char +#define YYCTYPE unsigned char #define YYCURSOR cursor #define YYLIMIT lim #define YYMARKER ptr @@ -86,8 +86,8 @@ sstring = "'" ((esc \ ['] ) | "\\" dot)* "'" ; letter = [a-zA-Z]; digit = [0-9]; number = "0" | ("-"? [1-9] digit*); -name = letter (letter|digit)*; -cname = ":" letter (letter|digit|"_")*; +name = (letter|"_") (letter|digit|"_")*; +cname = ":" name; space = [ \t]; eol = ("\r\n" | "\n"); config = "re2c" cname+; @@ -299,10 +299,16 @@ code: goto code; } "{" { ++depth; goto code; } - "\n" { if(cursor == eof) fatal("missing '}'"); + "\n" { if(cursor == eof) fatal("missing '}'"); pos = cursor; cline++; goto code; } + zero { if(cursor == eof) { + if (depth) fatal("missing '}'"); + RETURN(0); + } + goto code; + } dstring | sstring | any { goto code; } */ @@ -362,6 +368,14 @@ void Scanner::fatal(uint ofs, const char *msg) const #endif exit(1); } + +Scanner::~Scanner() +{ + if (bot) + { + delete [] bot; + } +} } // end namespace re2c diff --git a/tools/re2c/stream_lc.h b/tools/re2c/stream_lc.h index 5f8e5e6bdc..92a56c309b 100644 --- a/tools/re2c/stream_lc.h +++ b/tools/re2c/stream_lc.h @@ -258,7 +258,9 @@ protected: virtual int sync() { - fwrite(buffer.c_str(), sizeof(_E), buffer.length(), fp); + if (buffer.length() != 0) { + fwrite(buffer.c_str(), sizeof(_E), buffer.length(), fp); + } buffer.clear(); return fp == 0 || _Tr::eq_int_type(_Tr::eof(), overflow()) @@ -267,7 +269,9 @@ protected: virtual std::streamsize xsputn(const _E *buf, std::streamsize cnt) { - fwrite(buffer.c_str(), sizeof(_E), buffer.length(), fp); + if (buffer.length() != 0) { + fwrite(buffer.c_str(), sizeof(_E), buffer.length(), fp); + } buffer.clear(); /*fline += std::count(buf, buf + cnt, '\n');*/ for (std::streamsize pos = 0; pos < cnt; ++pos) @@ -277,7 +281,11 @@ protected: ++fline; } } - return fwrite(buf, sizeof(_E), cnt, fp); + if (cnt != 0) { + return fwrite(buf, sizeof(_E), cnt, fp); + } else { + return 0; + } } private: diff --git a/tools/re2c/translate.cc b/tools/re2c/translate.cc index 9ac65a8854..3955622ebe 100644 --- a/tools/re2c/translate.cc +++ b/tools/re2c/translate.cc @@ -4,6 +4,18 @@ namespace re2c { +static const char * sHex = "0123456789ABCDEF"; + +char octCh(uint c) +{ + return '0' + c % 8; +} + +char hexCh(uint c) +{ + return sHex[c & 0x0F]; +} + uint asc2asc[256] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, diff --git a/tools/re2c/y.tab.h b/tools/re2c/y.tab.h index 1c3e5849ea..84b92e8071 100644 --- a/tools/re2c/y.tab.h +++ b/tools/re2c/y.tab.h @@ -1,7 +1,9 @@ -/* A Bison parser, made by GNU Bison 2.1. */ +/* A Bison parser, made by GNU Bison 2.3. */ -/* Skeleton parser for Yacc-like parsing with Bison, - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +/* Skeleton interface for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. 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 @@ -18,10 +20,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* As a special exception, when this file is copied by Bison into a - Bison output file, you may use that output file without restriction. - This special exception was added by the Free Software Foundation - in version 1.24 of Bison. */ +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ /* Tokens. */ #ifndef YYTOKENTYPE @@ -54,9 +64,10 @@ -#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 58 "parser.y" -typedef union YYSTYPE { +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +#line 58 "./parser.y" +{ re2c::Symbol *symbol; re2c::RegExp *regexp; re2c::Token *token; @@ -64,9 +75,10 @@ typedef union YYSTYPE { int number; re2c::ExtOp extop; re2c::Str *str; -} YYSTYPE; -/* Line 1447 of yacc.c. */ -#line 70 "y.tab.h" +} +/* Line 1489 of yacc.c. */ +#line 81 "y.tab.h" + YYSTYPE; # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 @@ -74,5 +86,3 @@ typedef union YYSTYPE { extern YYSTYPE yylval; - - diff --git a/tools/xlatcc/gen.c b/tools/xlatcc/gen.c index 9aae1ce2d5..a022933c73 100644 --- a/tools/xlatcc/gen.c +++ b/tools/xlatcc/gen.c @@ -250,6 +250,9 @@ int main (int argc, char **argv) printf ("Usage: %s \n", argv[0]); return -1; } +#if !defined(NDEBUG) && 1 + ParseTrace(fopen("trace.txt", "w"), ":"); +#endif IncludeFile (argv[1]); yyparse (); count = CountSimpleTranslators (); diff --git a/tools/xlatcc/xlat-parse.c b/tools/xlatcc/xlat-parse.c index 9d83daced6..43dc70c2d3 100644 --- a/tools/xlatcc/xlat-parse.c +++ b/tools/xlatcc/xlat-parse.c @@ -1,2090 +1,2131 @@ -/* Driver template for the LEMON parser generator. -** The author disclaims copyright to this source code. -*/ -/* First off, code is included which follows the "include" declaration -** in the input file. */ -#include -#include -#line 1 "xlat-parse.y" - -#include "xlat.h" -#include "xlat-parse.h" -#include -#include - -int yyerror (char *s); - -typedef struct _Symbol -{ - struct _Symbol *Next; - int Value; - char Sym[1]; -} Symbol; - -static bool FindToken (char *tok, int *type); -static void AddSym (char *sym, int val); -static bool FindSym (char *sym, Symbol **val); - -static int EnumVal; - -struct ListFilter -{ - WORD filter; - BYTE value; -}; - -typedef struct _morefilters -{ - struct _morefilters *next; - struct ListFilter filter; -} MoreFilters; - -typedef struct _morelines -{ - struct _morelines *next; - BoomArg arg; -} MoreLines; - -typedef struct _specialargs -{ - BYTE addflags; - BYTE args[5]; -} SpecialArgs; - -typedef struct _boomarg -{ - BYTE constant; - WORD mask; - MoreFilters *filters; -} ParseBoomArg; - -typedef union YYSTYPE -{ - int val; - char sym[80]; - char string[80]; - Symbol *symval; -} YYSTYPE; - -#include -#include - -int yylex (YYSTYPE *yylval) -{ - char token[80]; - int toksize; - int c; - -loop: - while (Source == NULL) - { - if (!EndFile ()) - return 0; - } - while (isspace (c = fgetc (Source)) && c != EOF) - { - if (c == '\n') - SourceLine++; - } - - if (c == EOF) - { - if (EndFile ()) - goto loop; - return 0; - } - if (isdigit (c)) - { - int buildup = c - '0'; - if (c == '0') - { - c = fgetc (Source); - if (c == 'x' || c == 'X') - { - for (;;) - { - c = fgetc (Source); - if (isdigit (c)) - { - buildup = (buildup<<4) + c - '0'; - } - else if (c >= 'a' && c <= 'f') - { - buildup = (buildup<<4) + c - 'a' + 10; - } - else if (c >= 'A' && c <= 'F') - { - buildup = (buildup<<4) + c - 'A' + 10; - } - else - { - ungetc (c, Source); - yylval->val = buildup; - return NUM; - } - } - } - else - { - ungetc (c, Source); - } - } - while (isdigit (c = fgetc (Source))) - { - buildup = buildup*10 + c - '0'; - } - ungetc (c, Source); - yylval->val = buildup; - return NUM; - } - if (isalpha (c)) - { - int buildup = 0; - - token[0] = c; - toksize = 1; - while (toksize < 79 && (isalnum (c = fgetc (Source)) || c == '_')) - { - token[toksize++] = c; - } - token[toksize] = 0; - if (toksize == 79 && isalnum (c)) - { - while (isalnum (c = fgetc (Source))) - ; - } - ungetc (c, Source); - if (FindToken (token, &buildup)) - { - return buildup; - } - if (FindSym (token, &yylval->symval)) - { - return SYMNUM; - } - strcpy (yylval->sym, token); - return SYM; - } - if (c == '/') - { - c = fgetc (Source); - if (c == '*') - { - for (;;) - { - while ((c = fgetc (Source)) != '*' && c != EOF) - { - if (c == '\n') - SourceLine++; - } - if (c == EOF) - return 0; - if ((c = fgetc (Source)) == '/') - goto loop; - if (c == EOF) - return 0; - ungetc (c, Source); - } - } - else if (c == '/') - { - while ((c = fgetc (Source)) != '\n' && c != EOF) - ; - if (c == '\n') - SourceLine++; - else if (c == EOF) - return 0; - goto loop; - } - else - { - ungetc (c, Source); - return DIVIDE; - } - } - if (c == '"') - { - int tokensize = 0; - while ((c = fgetc (Source)) != '"' && c != EOF) - { - yylval->string[tokensize++] = c; - } - yylval->string[tokensize] = 0; - return STRING; - } - if (c == '|') - { - c = fgetc (Source); - if (c == '=') - return OR_EQUAL; - ungetc (c, Source); - return OR; - } - switch (c) - { - case '^': return XOR; - case '&': return AND; - case '-': return MINUS; - case '+': return PLUS; - case '*': return MULTIPLY; - case '(': return LPAREN; - case ')': return RPAREN; - case ',': return COMMA; - case '{': return LBRACE; - case '}': return RBRACE; - case '=': return EQUALS; - case ';': return SEMICOLON; - case ':': return COLON; - case '[': return LBRACKET; - case ']': return RBRACKET; - default: return 0; - } -} - -void *ParseAlloc(void *(*mallocProc)(size_t)); -void Parse(void *yyp, int yymajor, YYSTYPE yyminor); -void ParseFree(void *p, void (*freeProc)(void*)); -void ParseTrace(FILE *TraceFILE, char *zTracePrompt); - -void yyparse (void) -{ - void *pParser = ParseAlloc (malloc); - YYSTYPE token; - int tokentype; - - while ((tokentype = yylex(&token)) != 0) - { - Parse (pParser, tokentype, token); - } - memset (&token, 0, sizeof(token)); - Parse (pParser, 0, token); - ParseFree (pParser, free); -} - -static Symbol *FirstSym; - -static void AddSym (char *sym, int val) -{ - Symbol *syme = malloc (strlen (sym) + sizeof(Symbol)); - syme->Next = FirstSym; - syme->Value = val; - strcpy (syme->Sym, sym); - FirstSym = syme; -} - -static bool FindSym (char *sym, Symbol **val) -{ - Symbol *syme = FirstSym; - - while (syme != NULL) - { - if (strcmp (syme->Sym, sym) == 0) - { - *val = syme; - return 1; - } - syme = syme->Next; - } - return 0; -} - -static bool FindToken (char *tok, int *type) -{ - static const char tokens[][8] = - { - "endl", "print", "include", "special", "define", "enum", - "arg5", "arg4", "arg3", "arg2", "flags", "lineid", "tag" - - }; - static const short types[] = - { - ENDL, PRINT, INCLUDE, SPECIAL, DEFINE, ENUM, - ARG5, ARG4, ARG3, ARG2, FLAGS, LINEID, TAG - }; - int i; - - for (i = sizeof(tokens)/sizeof(tokens[0])-1; i >= 0; i--) - { - if (strcmp (tok, tokens[i]) == 0) - { - *type = types[i]; - return 1; - } - } - return 0; -} - -int yyerror (char *s) -{ - if (SourceName != NULL) - printf ("%s, line %d: %s\n", SourceName, SourceLine, s); - else - printf ("%s\n", s); - return 0; -} - -#line 327 "xlat-parse.c" -/* Next is all token values, in a form suitable for use by makeheaders. -** This section will be null unless lemon is run with the -m switch. -*/ -/* -** These constants (all generated automatically by the parser generator) -** specify the various kinds of tokens (terminals) that the parser -** understands. -** -** Each symbol here is a terminal symbol in the grammar. -*/ -/* Make sure the INTERFACE macro is defined. -*/ -#ifndef INTERFACE -# define INTERFACE 1 -#endif -/* The next thing included is series of defines which control -** various aspects of the generated parser. -** YYCODETYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 terminals -** and nonterminals. "int" is used otherwise. -** YYNOCODE is a number of type YYCODETYPE which corresponds -** to no legal terminal or nonterminal number. This -** number is used to fill in empty slots of the hash -** table. -** YYFALLBACK If defined, this indicates that one or more tokens -** have fall-back values which should be used if the -** original value of the token will not parse. -** YYACTIONTYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 rules and -** states combined. "int" is used otherwise. -** ParseTOKENTYPE is the data type used for minor tokens given -** directly to the parser from the tokenizer. -** YYMINORTYPE is the data type used for all minor tokens. -** This is typically a union of many types, one of -** which is ParseTOKENTYPE. The entry in the union -** for base tokens is called "yy0". -** YYSTACKDEPTH is the maximum depth of the parser's stack. -** ParseARG_SDECL A static variable declaration for the %extra_argument -** ParseARG_PDECL A parameter declaration for the %extra_argument -** ParseARG_STORE Code to store %extra_argument into yypParser -** ParseARG_FETCH Code to extract %extra_argument from yypParser -** YYNSTATE the combined number of states. -** YYNRULE the number of rules in the grammar -** YYERRORSYMBOL is the code number of the error symbol. If not -** defined, then do no error processing. -*/ -#define YYCODETYPE unsigned char -#define YYNOCODE 66 -#define YYACTIONTYPE unsigned short int -#define ParseTOKENTYPE YYSTYPE -typedef union { - ParseTOKENTYPE yy0; - MoreLines * yy49; - SpecialArgs yy57; - BoomArg yy58; - int yy72; - ParseBoomArg yy83; - MoreFilters * yy87; - struct ListFilter yy124; - int yy131; -} YYMINORTYPE; -#define YYSTACKDEPTH 100 -#define ParseARG_SDECL -#define ParseARG_PDECL -#define ParseARG_FETCH -#define ParseARG_STORE -#define YYNSTATE 173 -#define YYNRULE 93 -#define YYERRORSYMBOL 37 -#define YYERRSYMDT yy131 -#define YY_NO_ACTION (YYNSTATE+YYNRULE+2) -#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) -#define YY_ERROR_ACTION (YYNSTATE+YYNRULE) - -/* Next are that tables used to determine what action to take based on the -** current state and lookahead token. These tables are used to implement -** functions that take a state number and lookahead value and return an -** action integer. -** -** Suppose the action integer is N. Then the action is determined as -** follows -** -** 0 <= N < YYNSTATE Shift N. That is, push the lookahead -** token onto the stack and goto state N. -** -** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE. -** -** N == YYNSTATE+YYNRULE A syntax error has occurred. -** -** N == YYNSTATE+YYNRULE+1 The parser accepts its input. -** -** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused -** slots in the yy_action[] table. -** -** The action table is constructed as a single large table named yy_action[]. -** Given state S and lookahead X, the action is computed as -** -** yy_action[ yy_shift_ofst[S] + X ] -** -** If the index value yy_shift_ofst[S]+X is out of range or if the value -** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] -** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table -** and that yy_default[S] should be used instead. -** -** The formula above is for computing the action when the lookahead is -** a terminal symbol. If the lookahead is a non-terminal (as occurs after -** a reduce action) then the yy_reduce_ofst[] array is used in place of -** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of -** YY_SHIFT_USE_DFLT. -** -** The following are the tables generated in this section: -** -** yy_action[] A single table containing all actions. -** yy_lookahead[] A table containing the lookahead for each entry in -** yy_action. Used to detect hash collisions. -** yy_shift_ofst[] For each state, the offset into yy_action for -** shifting terminals. -** yy_reduce_ofst[] For each state, the offset into yy_action for -** shifting non-terminals after a reduce. -** yy_default[] Default action for each state. -*/ -static const YYACTIONTYPE yy_action[] = { - /* 0 */ 65, 41, 32, 35, 52, 42, 28, 51, 77, 117, - /* 10 */ 267, 163, 160, 149, 148, 147, 146, 145, 144, 143, - /* 20 */ 30, 80, 14, 128, 164, 156, 151, 23, 123, 127, - /* 30 */ 55, 4, 152, 102, 33, 108, 80, 119, 128, 107, - /* 40 */ 5, 111, 113, 22, 2, 41, 32, 35, 52, 42, - /* 50 */ 28, 51, 32, 35, 52, 42, 28, 51, 19, 3, - /* 60 */ 41, 32, 35, 52, 42, 28, 51, 52, 42, 28, - /* 70 */ 51, 135, 116, 41, 32, 35, 52, 42, 28, 51, - /* 80 */ 41, 32, 35, 52, 42, 28, 51, 28, 51, 11, - /* 90 */ 9, 168, 169, 170, 171, 172, 77, 106, 26, 66, - /* 100 */ 41, 32, 35, 52, 42, 28, 51, 35, 52, 42, - /* 110 */ 28, 51, 10, 27, 61, 41, 32, 35, 52, 42, - /* 120 */ 28, 51, 68, 120, 100, 139, 165, 49, 18, 166, - /* 130 */ 41, 32, 35, 52, 42, 28, 51, 55, 4, 101, - /* 140 */ 167, 12, 40, 29, 43, 41, 32, 35, 52, 42, - /* 150 */ 28, 51, 136, 131, 113, 91, 66, 98, 16, 115, - /* 160 */ 41, 32, 35, 52, 42, 28, 51, 124, 130, 159, - /* 170 */ 56, 59, 129, 37, 61, 41, 32, 35, 52, 42, - /* 180 */ 28, 51, 138, 109, 48, 57, 60, 154, 20, 54, - /* 190 */ 41, 32, 35, 52, 42, 28, 51, 13, 62, 90, - /* 200 */ 89, 17, 15, 21, 7, 41, 32, 35, 52, 42, - /* 210 */ 28, 51, 39, 132, 63, 99, 94, 87, 31, 142, - /* 220 */ 41, 32, 35, 52, 42, 28, 51, 134, 133, 67, - /* 230 */ 88, 157, 74, 41, 32, 35, 52, 42, 28, 51, - /* 240 */ 41, 32, 35, 52, 42, 28, 51, 84, 161, 30, - /* 250 */ 141, 104, 86, 38, 156, 151, 23, 1, 153, 6, - /* 260 */ 96, 41, 32, 35, 52, 42, 28, 51, 41, 32, - /* 270 */ 35, 52, 42, 28, 51, 8, 41, 32, 35, 52, - /* 280 */ 42, 28, 51, 25, 103, 64, 97, 125, 71, 95, - /* 290 */ 24, 76, 41, 32, 35, 52, 42, 28, 51, 150, - /* 300 */ 158, 78, 268, 162, 268, 45, 83, 41, 32, 35, - /* 310 */ 52, 42, 28, 51, 92, 81, 82, 268, 70, 69, - /* 320 */ 44, 85, 41, 32, 35, 52, 42, 28, 51, 268, - /* 330 */ 72, 79, 75, 58, 73, 36, 93, 41, 32, 35, - /* 340 */ 52, 42, 28, 51, 268, 268, 268, 268, 268, 268, - /* 350 */ 46, 268, 41, 32, 35, 52, 42, 28, 51, 268, - /* 360 */ 268, 268, 268, 268, 268, 34, 268, 41, 32, 35, - /* 370 */ 52, 42, 28, 51, 268, 268, 268, 268, 268, 268, - /* 380 */ 47, 268, 41, 32, 35, 52, 42, 28, 51, 268, - /* 390 */ 268, 268, 268, 268, 268, 50, 268, 41, 32, 35, - /* 400 */ 52, 42, 28, 51, 268, 268, 268, 268, 268, 268, - /* 410 */ 53, 88, 41, 32, 35, 52, 42, 28, 51, 30, - /* 420 */ 268, 268, 30, 268, 156, 151, 23, 156, 151, 23, - /* 430 */ 30, 110, 104, 140, 137, 156, 151, 23, 268, 268, - /* 440 */ 30, 268, 268, 268, 105, 156, 151, 23, 268, 30, - /* 450 */ 114, 126, 30, 268, 156, 151, 23, 156, 151, 23, - /* 460 */ 30, 268, 268, 30, 268, 156, 151, 23, 156, 151, - /* 470 */ 23, 155, 268, 268, 268, 268, 268, 268, 268, 268, - /* 480 */ 122, 268, 268, 118, 268, 268, 268, 268, 268, 268, - /* 490 */ 268, 121, 268, 268, 112, -}; -static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 38, 1, 2, 3, 4, 5, 6, 7, 38, 39, - /* 10 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - /* 20 */ 4, 38, 60, 40, 41, 9, 10, 11, 28, 13, - /* 30 */ 44, 45, 46, 17, 14, 19, 38, 21, 40, 41, - /* 40 */ 24, 61, 62, 27, 11, 1, 2, 3, 4, 5, - /* 50 */ 6, 7, 2, 3, 4, 5, 6, 7, 14, 22, - /* 60 */ 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, - /* 70 */ 7, 12, 18, 1, 2, 3, 4, 5, 6, 7, - /* 80 */ 1, 2, 3, 4, 5, 6, 7, 6, 7, 11, - /* 90 */ 11, 29, 30, 31, 32, 33, 38, 39, 26, 38, - /* 100 */ 1, 2, 3, 4, 5, 6, 7, 3, 4, 5, - /* 110 */ 6, 7, 43, 14, 38, 1, 2, 3, 4, 5, - /* 120 */ 6, 7, 38, 47, 63, 64, 42, 11, 14, 23, - /* 130 */ 1, 2, 3, 4, 5, 6, 7, 44, 45, 46, - /* 140 */ 34, 14, 14, 14, 14, 1, 2, 3, 4, 5, - /* 150 */ 6, 7, 25, 61, 62, 38, 38, 38, 14, 10, - /* 160 */ 1, 2, 3, 4, 5, 6, 7, 18, 12, 38, - /* 170 */ 38, 38, 22, 14, 38, 1, 2, 3, 4, 5, - /* 180 */ 6, 7, 64, 47, 14, 38, 38, 12, 14, 23, - /* 190 */ 1, 2, 3, 4, 5, 6, 7, 11, 38, 38, - /* 200 */ 38, 14, 14, 14, 14, 1, 2, 3, 4, 5, - /* 210 */ 6, 7, 14, 20, 38, 38, 38, 38, 14, 12, - /* 220 */ 1, 2, 3, 4, 5, 6, 7, 12, 15, 38, - /* 230 */ 38, 12, 38, 1, 2, 3, 4, 5, 6, 7, - /* 240 */ 1, 2, 3, 4, 5, 6, 7, 38, 28, 4, - /* 250 */ 58, 59, 38, 14, 9, 10, 11, 14, 12, 27, - /* 260 */ 38, 1, 2, 3, 4, 5, 6, 7, 1, 2, - /* 270 */ 3, 4, 5, 6, 7, 11, 1, 2, 3, 4, - /* 280 */ 5, 6, 7, 11, 18, 38, 26, 12, 38, 38, - /* 290 */ 23, 38, 1, 2, 3, 4, 5, 6, 7, 20, - /* 300 */ 38, 38, 65, 38, 65, 14, 38, 1, 2, 3, - /* 310 */ 4, 5, 6, 7, 38, 38, 38, 65, 38, 38, - /* 320 */ 14, 38, 1, 2, 3, 4, 5, 6, 7, 65, - /* 330 */ 38, 38, 38, 38, 38, 14, 38, 1, 2, 3, - /* 340 */ 4, 5, 6, 7, 65, 65, 65, 65, 65, 65, - /* 350 */ 14, 65, 1, 2, 3, 4, 5, 6, 7, 65, - /* 360 */ 65, 65, 65, 65, 65, 14, 65, 1, 2, 3, - /* 370 */ 4, 5, 6, 7, 65, 65, 65, 65, 65, 65, - /* 380 */ 14, 65, 1, 2, 3, 4, 5, 6, 7, 65, - /* 390 */ 65, 65, 65, 65, 65, 14, 65, 1, 2, 3, - /* 400 */ 4, 5, 6, 7, 65, 65, 65, 65, 65, 65, - /* 410 */ 14, 38, 1, 2, 3, 4, 5, 6, 7, 4, - /* 420 */ 65, 65, 4, 65, 9, 10, 11, 9, 10, 11, - /* 430 */ 4, 58, 59, 15, 16, 9, 10, 11, 65, 65, - /* 440 */ 4, 65, 65, 65, 18, 9, 10, 11, 65, 4, - /* 450 */ 35, 36, 4, 65, 9, 10, 11, 9, 10, 11, - /* 460 */ 4, 65, 65, 4, 65, 9, 10, 11, 9, 10, - /* 470 */ 11, 35, 65, 65, 65, 65, 65, 65, 65, 65, - /* 480 */ 35, 65, 65, 35, 65, 65, 65, 65, 65, 65, - /* 490 */ 65, 35, 65, 65, 35, -}; -#define YY_SHIFT_USE_DFLT (-1) -#define YY_SHIFT_MAX 128 -static const short yy_shift_ofst[] = { - /* 0 */ 16, 418, 418, 62, 62, 245, 245, 245, 415, 415, - /* 10 */ 245, 245, 245, 245, 54, 54, 456, 459, 448, 426, - /* 20 */ 445, 436, 245, 245, 245, 245, 245, 245, 245, 245, - /* 30 */ 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, - /* 40 */ 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, - /* 50 */ 245, 245, 245, 245, 245, 106, 396, 381, 366, 351, - /* 60 */ 336, 321, 306, 291, 275, 267, 260, 239, 232, 0, - /* 70 */ 219, 204, 189, 174, 159, 144, 129, 114, 99, 79, - /* 80 */ 72, 59, 44, 411, 411, 411, 411, 411, 411, 411, - /* 90 */ 411, 411, 411, 411, 50, 104, 63, 149, 81, 81, - /* 100 */ 127, 279, 266, 272, 243, 264, 246, 220, 213, 215, - /* 110 */ 207, 193, 198, 188, 187, 186, 166, 175, 170, 150, - /* 120 */ 156, 130, 128, 116, 78, 37, 20, 33, 190, -}; -#define YY_REDUCE_USE_DFLT (-39) -#define YY_REDUCE_MAX 55 -static const short yy_reduce_ofst[] = { - /* 0 */ -38, 192, 373, 93, -14, 61, -2, -17, 58, -30, - /* 10 */ 84, 76, 118, 136, -20, 92, 296, 295, 294, 293, - /* 20 */ 292, 283, 281, 280, 278, 277, 276, 268, 265, 263, - /* 30 */ 262, 253, 251, 250, 247, 222, 214, 209, 194, 191, - /* 40 */ 179, 178, 177, 176, 162, 161, 160, 148, 147, 133, - /* 50 */ 132, 131, 119, 298, 117, 69, -}; -static const YYACTIONTYPE yy_default[] = { - /* 0 */ 185, 195, 195, 221, 221, 266, 266, 266, 236, 236, - /* 10 */ 266, 215, 266, 215, 205, 205, 266, 266, 266, 266, - /* 20 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, - /* 30 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, - /* 40 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, - /* 50 */ 266, 266, 266, 266, 266, 266, 258, 257, 238, 266, - /* 60 */ 239, 216, 240, 261, 266, 266, 266, 243, 231, 266, - /* 70 */ 266, 247, 254, 253, 244, 252, 248, 251, 249, 266, - /* 80 */ 266, 266, 266, 250, 245, 255, 217, 264, 199, 241, - /* 90 */ 262, 209, 235, 259, 180, 182, 181, 266, 177, 176, - /* 100 */ 266, 266, 266, 266, 196, 266, 266, 266, 266, 266, - /* 110 */ 266, 266, 242, 206, 237, 266, 208, 266, 256, 266, - /* 120 */ 266, 260, 263, 266, 266, 266, 246, 266, 233, 204, - /* 130 */ 213, 207, 203, 202, 214, 201, 210, 200, 212, 211, - /* 140 */ 198, 197, 194, 193, 192, 191, 190, 189, 188, 187, - /* 150 */ 220, 175, 222, 219, 218, 265, 174, 184, 183, 179, - /* 160 */ 186, 232, 178, 173, 234, 223, 229, 230, 224, 225, - /* 170 */ 226, 227, 228, -}; -#define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0])) - -/* The next table maps tokens into fallback tokens. If a construct -** like the following: -** -** %fallback ID X Y Z. -** -** appears in the grammer, then ID becomes a fallback token for X, Y, -** and Z. Whenever one of the tokens X, Y, or Z is input to the parser -** but it does not parse, the type of the token is changed to ID and -** the parse is retried before an error is thrown. -*/ -#ifdef YYFALLBACK -static const YYCODETYPE yyFallback[] = { -}; -#endif /* YYFALLBACK */ - -/* The following structure represents a single element of the -** parser's stack. Information stored includes: -** -** + The state number for the parser at this level of the stack. -** -** + The value of the token stored at this level of the stack. -** (In other words, the "major" token.) -** -** + The semantic value stored at this level of the stack. This is -** the information used by the action routines in the grammar. -** It is sometimes called the "minor" token. -*/ -struct yyStackEntry { - int stateno; /* The state-number */ - int major; /* The major token value. This is the code - ** number for the token at this stack level */ - YYMINORTYPE minor; /* The user-supplied minor token value. This - ** is the value of the token */ -}; -typedef struct yyStackEntry yyStackEntry; - -/* The state of the parser is completely contained in an instance of -** the following structure */ -struct yyParser { - int yyidx; /* Index of top element in stack */ - int yyerrcnt; /* Shifts left before out of the error */ - ParseARG_SDECL /* A place to hold %extra_argument */ - yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ -}; -typedef struct yyParser yyParser; - -#ifndef NDEBUG -#include -static FILE *yyTraceFILE = 0; -static char *yyTracePrompt = 0; -#endif /* NDEBUG */ - -#ifndef NDEBUG -/* -** Turn parser tracing on by giving a stream to which to write the trace -** and a prompt to preface each trace message. Tracing is turned off -** by making either argument NULL -** -** Inputs: -**
    -**
  • A FILE* to which trace output should be written. -** If NULL, then tracing is turned off. -**
  • A prefix string written at the beginning of every -** line of trace output. If NULL, then tracing is -** turned off. -**
-** -** Outputs: -** None. -*/ -void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ - yyTraceFILE = TraceFILE; - yyTracePrompt = zTracePrompt; - if( yyTraceFILE==0 ) yyTracePrompt = 0; - else if( yyTracePrompt==0 ) yyTraceFILE = 0; -} -#endif /* NDEBUG */ - -#ifndef NDEBUG -/* For tracing shifts, the names of all terminals and nonterminals -** are required. The following table supplies these names */ -static const char *const yyTokenName[] = { - "$", "OR", "XOR", "AND", - "MINUS", "PLUS", "MULTIPLY", "DIVIDE", - "NEG", "NUM", "SYMNUM", "LPAREN", - "RPAREN", "PRINT", "COMMA", "STRING", - "ENDL", "DEFINE", "SYM", "INCLUDE", - "RBRACE", "ENUM", "LBRACE", "EQUALS", - "SPECIAL", "SEMICOLON", "COLON", "LBRACKET", - "RBRACKET", "FLAGS", "ARG2", "ARG3", - "ARG4", "ARG5", "OR_EQUAL", "TAG", - "LINEID", "error", "exp", "special_args", - "list_val", "arg_list", "boom_args", "boom_op", - "boom_selector", "boom_line", "boom_body", "maybe_argcount", - "main", "translation_unit", "external_declaration", "define_statement", - "include_statement", "print_statement", "enum_statement", "linetype_declaration", - "boom_declaration", "special_declaration", "print_list", "print_item", - "enum_open", "enum_list", "single_enum", "special_list", - "special_def", -}; -#endif /* NDEBUG */ - -#ifndef NDEBUG -/* For tracing reduce actions, the names of all rules are required. -*/ -static const char *const yyRuleName[] = { - /* 0 */ "main ::= translation_unit", - /* 1 */ "exp ::= NUM", - /* 2 */ "exp ::= SYMNUM", - /* 3 */ "exp ::= exp PLUS exp", - /* 4 */ "exp ::= exp MINUS exp", - /* 5 */ "exp ::= exp MULTIPLY exp", - /* 6 */ "exp ::= exp DIVIDE exp", - /* 7 */ "exp ::= exp OR exp", - /* 8 */ "exp ::= exp AND exp", - /* 9 */ "exp ::= exp XOR exp", - /* 10 */ "exp ::= MINUS exp", - /* 11 */ "exp ::= LPAREN exp RPAREN", - /* 12 */ "translation_unit ::=", - /* 13 */ "translation_unit ::= external_declaration", - /* 14 */ "external_declaration ::= define_statement", - /* 15 */ "external_declaration ::= include_statement", - /* 16 */ "external_declaration ::= print_statement", - /* 17 */ "external_declaration ::= enum_statement", - /* 18 */ "external_declaration ::= linetype_declaration", - /* 19 */ "external_declaration ::= boom_declaration", - /* 20 */ "external_declaration ::= special_declaration", - /* 21 */ "print_statement ::= PRINT LPAREN print_list RPAREN", - /* 22 */ "print_list ::=", - /* 23 */ "print_list ::= print_item", - /* 24 */ "print_list ::= print_item COMMA print_list", - /* 25 */ "print_item ::= STRING", - /* 26 */ "print_item ::= exp", - /* 27 */ "print_item ::= ENDL", - /* 28 */ "define_statement ::= DEFINE SYM LPAREN exp RPAREN", - /* 29 */ "include_statement ::= INCLUDE STRING", - /* 30 */ "enum_statement ::= enum_open enum_list RBRACE", - /* 31 */ "enum_open ::= ENUM LBRACE", - /* 32 */ "enum_list ::=", - /* 33 */ "enum_list ::= single_enum", - /* 34 */ "enum_list ::= single_enum COMMA enum_list", - /* 35 */ "single_enum ::= SYM", - /* 36 */ "single_enum ::= SYM EQUALS exp", - /* 37 */ "special_declaration ::= SPECIAL special_list SEMICOLON", - /* 38 */ "special_list ::= special_def", - /* 39 */ "special_list ::= special_list COMMA special_def", - /* 40 */ "special_def ::= exp COLON SYM LPAREN maybe_argcount RPAREN", - /* 41 */ "special_def ::= exp COLON SYMNUM LPAREN maybe_argcount RPAREN", - /* 42 */ "maybe_argcount ::=", - /* 43 */ "maybe_argcount ::= exp", - /* 44 */ "maybe_argcount ::= exp COMMA exp", - /* 45 */ "linetype_declaration ::= exp EQUALS exp COMMA exp LPAREN special_args RPAREN", - /* 46 */ "linetype_declaration ::= exp EQUALS exp COMMA SYM LPAREN special_args RPAREN", - /* 47 */ "boom_declaration ::= LBRACKET exp RBRACKET LPAREN exp COMMA exp RPAREN LBRACE boom_body RBRACE", - /* 48 */ "boom_body ::=", - /* 49 */ "boom_body ::= boom_line boom_body", - /* 50 */ "boom_line ::= boom_selector boom_op boom_args", - /* 51 */ "boom_selector ::= FLAGS", - /* 52 */ "boom_selector ::= ARG2", - /* 53 */ "boom_selector ::= ARG3", - /* 54 */ "boom_selector ::= ARG4", - /* 55 */ "boom_selector ::= ARG5", - /* 56 */ "boom_op ::= EQUALS", - /* 57 */ "boom_op ::= OR_EQUAL", - /* 58 */ "boom_args ::= exp", - /* 59 */ "boom_args ::= exp LBRACKET arg_list RBRACKET", - /* 60 */ "arg_list ::= list_val", - /* 61 */ "arg_list ::= list_val COMMA arg_list", - /* 62 */ "list_val ::= exp COLON exp", - /* 63 */ "special_args ::=", - /* 64 */ "special_args ::= TAG", - /* 65 */ "special_args ::= TAG COMMA exp", - /* 66 */ "special_args ::= TAG COMMA exp COMMA exp", - /* 67 */ "special_args ::= TAG COMMA exp COMMA exp COMMA exp", - /* 68 */ "special_args ::= TAG COMMA exp COMMA exp COMMA exp COMMA exp", - /* 69 */ "special_args ::= TAG COMMA TAG", - /* 70 */ "special_args ::= TAG COMMA TAG COMMA exp", - /* 71 */ "special_args ::= TAG COMMA TAG COMMA exp COMMA exp", - /* 72 */ "special_args ::= TAG COMMA TAG COMMA exp COMMA exp COMMA exp", - /* 73 */ "special_args ::= LINEID", - /* 74 */ "special_args ::= LINEID COMMA exp", - /* 75 */ "special_args ::= LINEID COMMA exp COMMA exp", - /* 76 */ "special_args ::= LINEID COMMA exp COMMA exp COMMA exp", - /* 77 */ "special_args ::= LINEID COMMA exp COMMA exp COMMA exp COMMA exp", - /* 78 */ "special_args ::= exp", - /* 79 */ "special_args ::= exp COMMA exp", - /* 80 */ "special_args ::= exp COMMA exp COMMA exp", - /* 81 */ "special_args ::= exp COMMA exp COMMA exp COMMA exp", - /* 82 */ "special_args ::= exp COMMA exp COMMA exp COMMA exp COMMA exp", - /* 83 */ "special_args ::= exp COMMA TAG", - /* 84 */ "special_args ::= exp COMMA TAG COMMA exp", - /* 85 */ "special_args ::= exp COMMA TAG COMMA exp COMMA exp", - /* 86 */ "special_args ::= exp COMMA TAG COMMA exp COMMA exp COMMA exp", - /* 87 */ "special_args ::= exp COMMA exp COMMA TAG", - /* 88 */ "special_args ::= exp COMMA exp COMMA TAG COMMA exp", - /* 89 */ "special_args ::= exp COMMA exp COMMA TAG COMMA exp COMMA exp", - /* 90 */ "special_args ::= exp COMMA exp COMMA exp COMMA TAG", - /* 91 */ "special_args ::= exp COMMA exp COMMA exp COMMA TAG COMMA exp", - /* 92 */ "special_args ::= exp COMMA exp COMMA exp COMMA exp COMMA TAG", -}; -#endif /* NDEBUG */ - -/* -** This function returns the symbolic name associated with a token -** value. -*/ -const char *ParseTokenName(int tokenType){ -#ifndef NDEBUG - if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){ - return yyTokenName[tokenType]; - }else{ - return "Unknown"; - } -#else - return ""; -#endif -} - -/* -** This function allocates a new parser. -** The only argument is a pointer to a function which works like -** malloc. -** -** Inputs: -** A pointer to the function used to allocate memory. -** -** Outputs: -** A pointer to a parser. This pointer is used in subsequent calls -** to Parse and ParseFree. -*/ -void *ParseAlloc(void *(*mallocProc)(size_t)){ - yyParser *pParser; - pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); - if( pParser ){ - pParser->yyidx = -1; - } - return pParser; -} - -/* The following function deletes the value associated with a -** symbol. The symbol can be either a terminal or nonterminal. -** "yymajor" is the symbol code, and "yypminor" is a pointer to -** the value. -*/ -static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ - switch( yymajor ){ - /* Here is inserted the actions which take place when a - ** terminal or non-terminal is destroyed. This can happen - ** when the symbol is popped from the stack during a - ** reduce or during error processing or when a parser is - ** being destroyed before it is finished parsing. - ** - ** Note: during a reduce, the only symbols destroyed are those - ** which appear on the RHS of the rule, but which are not used - ** inside the C code. - */ - default: break; /* If no destructor action specified: do nothing */ - } -} - -/* -** Pop the parser's stack once. -** -** If there is a destructor routine associated with the token which -** is popped from the stack, then call it. -** -** Return the major token number for the symbol popped. -*/ -static int yy_pop_parser_stack(yyParser *pParser){ - YYCODETYPE yymajor; - yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; - - if( pParser->yyidx<0 ) return 0; -#ifndef NDEBUG - if( yyTraceFILE && pParser->yyidx>=0 ){ - fprintf(yyTraceFILE,"%sPopping %s\n", - yyTracePrompt, - yyTokenName[yytos->major]); - } -#endif - yymajor = yytos->major; - yy_destructor( yymajor, &yytos->minor); - pParser->yyidx--; - return yymajor; -} - -/* -** Deallocate and destroy a parser. Destructors are all called for -** all stack elements before shutting the parser down. -** -** Inputs: -**
    -**
  • A pointer to the parser. This should be a pointer -** obtained from ParseAlloc. -**
  • A pointer to a function used to reclaim memory obtained -** from malloc. -**
-*/ -void ParseFree( - void *p, /* The parser to be deleted */ - void (*freeProc)(void*) /* Function used to reclaim memory */ -){ - yyParser *pParser = (yyParser*)p; - if( pParser==0 ) return; - while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); - (*freeProc)((void*)pParser); -} - -/* -** Find the appropriate action for a parser given the terminal -** look-ahead token iLookAhead. -** -** If the look-ahead token is YYNOCODE, then check to see if the action is -** independent of the look-ahead. If it is, return the action, otherwise -** return YY_NO_ACTION. -*/ -static int yy_find_shift_action( - yyParser *pParser, /* The parser */ - YYCODETYPE iLookAhead /* The look-ahead token */ -){ - int i; - int stateno = pParser->yystack[pParser->yyidx].stateno; - - if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){ - return yy_default[stateno]; - } - if( iLookAhead==YYNOCODE ){ - return YY_NO_ACTION; - } - i += iLookAhead; - if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ - if( iLookAhead>0 ){ -#ifdef YYFALLBACK - int iFallback; /* Fallback token */ - if( iLookAhead %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); - } -#endif - return yy_find_shift_action(pParser, iFallback); - } -#endif -#ifdef YYWILDCARD - { - int j = i - iLookAhead + YYWILDCARD; - if( j>=0 && j %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]); - } -#endif /* NDEBUG */ - return yy_action[j]; - } - } -#endif /* YYWILDCARD */ - } - return yy_default[stateno]; - }else{ - return yy_action[i]; - } -} - -/* -** Find the appropriate action for a parser given the non-terminal -** look-ahead token iLookAhead. -** -** If the look-ahead token is YYNOCODE, then check to see if the action is -** independent of the look-ahead. If it is, return the action, otherwise -** return YY_NO_ACTION. -*/ -static int yy_find_reduce_action( - int stateno, /* Current state number */ - YYCODETYPE iLookAhead /* The look-ahead token */ -){ - int i; - /* int stateno = pParser->yystack[pParser->yyidx].stateno; */ - - if( stateno>YY_REDUCE_MAX || - (i = yy_reduce_ofst[stateno])==YY_REDUCE_USE_DFLT ){ - return yy_default[stateno]; - } - if( iLookAhead==YYNOCODE ){ - return YY_NO_ACTION; - } - i += iLookAhead; - if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ - return yy_default[stateno]; - }else{ - return yy_action[i]; - } -} - -/* -** Perform a shift action. -*/ -static void yy_shift( - yyParser *yypParser, /* The parser to be shifted */ - int yyNewState, /* The new state to shift in */ - int yyMajor, /* The major token to shift in */ - YYMINORTYPE *yypMinor /* Pointer ot the minor token to shift in */ -){ - yyStackEntry *yytos; - yypParser->yyidx++; - if( yypParser->yyidx>=YYSTACKDEPTH ){ - ParseARG_FETCH; - yypParser->yyidx--; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); - } -#endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will execute if the parser - ** stack ever overflows */ - ParseARG_STORE; /* Suppress warning about unused %extra_argument var */ - return; - } - yytos = &yypParser->yystack[yypParser->yyidx]; - yytos->stateno = yyNewState; - yytos->major = yyMajor; - yytos->minor = *yypMinor; -#ifndef NDEBUG - if( yyTraceFILE && yypParser->yyidx>0 ){ - int i; - fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState); - fprintf(yyTraceFILE,"%sStack:",yyTracePrompt); - for(i=1; i<=yypParser->yyidx; i++) - fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); - fprintf(yyTraceFILE,"\n"); - } -#endif -} - -/* The following table contains information about every rule that -** is used during the reduce. -*/ -static const struct { - YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ - unsigned char nrhs; /* Number of right-hand side symbols in the rule */ -} yyRuleInfo[] = { - { 48, 1 }, - { 38, 1 }, - { 38, 1 }, - { 38, 3 }, - { 38, 3 }, - { 38, 3 }, - { 38, 3 }, - { 38, 3 }, - { 38, 3 }, - { 38, 3 }, - { 38, 2 }, - { 38, 3 }, - { 49, 0 }, - { 49, 1 }, - { 50, 1 }, - { 50, 1 }, - { 50, 1 }, - { 50, 1 }, - { 50, 1 }, - { 50, 1 }, - { 50, 1 }, - { 53, 4 }, - { 58, 0 }, - { 58, 1 }, - { 58, 3 }, - { 59, 1 }, - { 59, 1 }, - { 59, 1 }, - { 51, 5 }, - { 52, 2 }, - { 54, 3 }, - { 60, 2 }, - { 61, 0 }, - { 61, 1 }, - { 61, 3 }, - { 62, 1 }, - { 62, 3 }, - { 57, 3 }, - { 63, 1 }, - { 63, 3 }, - { 64, 6 }, - { 64, 6 }, - { 47, 0 }, - { 47, 1 }, - { 47, 3 }, - { 55, 8 }, - { 55, 8 }, - { 56, 11 }, - { 46, 0 }, - { 46, 2 }, - { 45, 3 }, - { 44, 1 }, - { 44, 1 }, - { 44, 1 }, - { 44, 1 }, - { 44, 1 }, - { 43, 1 }, - { 43, 1 }, - { 42, 1 }, - { 42, 4 }, - { 41, 1 }, - { 41, 3 }, - { 40, 3 }, - { 39, 0 }, - { 39, 1 }, - { 39, 3 }, - { 39, 5 }, - { 39, 7 }, - { 39, 9 }, - { 39, 3 }, - { 39, 5 }, - { 39, 7 }, - { 39, 9 }, - { 39, 1 }, - { 39, 3 }, - { 39, 5 }, - { 39, 7 }, - { 39, 9 }, - { 39, 1 }, - { 39, 3 }, - { 39, 5 }, - { 39, 7 }, - { 39, 9 }, - { 39, 3 }, - { 39, 5 }, - { 39, 7 }, - { 39, 9 }, - { 39, 5 }, - { 39, 7 }, - { 39, 9 }, - { 39, 7 }, - { 39, 9 }, - { 39, 9 }, -}; - -static void yy_accept(yyParser*); /* Forward Declaration */ - -/* -** Perform a reduce action and the shift that must immediately -** follow the reduce. -*/ -static void yy_reduce( - yyParser *yypParser, /* The parser */ - int yyruleno /* Number of the rule by which to reduce */ -){ - int yygoto; /* The next state */ - int yyact; /* The next action */ - YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ - yyStackEntry *yymsp; /* The top of the parser's stack */ - int yysize; /* Amount to pop the stack */ - ParseARG_FETCH; - yymsp = &yypParser->yystack[yypParser->yyidx]; -#ifndef NDEBUG - if( yyTraceFILE && yyruleno>=0 - && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ - fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt, - yyRuleName[yyruleno]); - } -#endif /* NDEBUG */ - - /* Silence complaints from purify about yygotominor being uninitialized - ** in some cases when it is copied into the stack after the following - ** switch. yygotominor is uninitialized when a rule reduces that does - ** not set the value of its left-hand side nonterminal. Leaving the - ** value of the nonterminal uninitialized is utterly harmless as long - ** as the value is never used. So really the only thing this code - ** accomplishes is to quieten purify. - ** - ** 2007-01-16: The wireshark project (www.wireshark.org) reports that - ** without this code, their parser segfaults. I'm not sure what there - ** parser is doing to make this happen. This is the second bug report - ** from wireshark this week. Clearly they are stressing Lemon in ways - ** that it has not been previously stressed... (SQLite ticket #2172) - */ - memset(&yygotominor, 0, sizeof(yygotominor)); - - - switch( yyruleno ){ - /* Beginning here are the reduction cases. A typical example - ** follows: - ** case 0: - ** #line - ** { ... } // User supplied code - ** #line - ** break; - */ - case 1: -#line 344 "xlat-parse.y" -{ yygotominor.yy72 = yymsp[0].minor.yy0.val; } -#line 1197 "xlat-parse.c" - break; - case 2: -#line 345 "xlat-parse.y" -{ yygotominor.yy72 = yymsp[0].minor.yy0.symval->Value; } -#line 1202 "xlat-parse.c" - break; - case 3: -#line 346 "xlat-parse.y" -{ yygotominor.yy72 = yymsp[-2].minor.yy72 + yymsp[0].minor.yy72; } -#line 1207 "xlat-parse.c" - break; - case 4: -#line 347 "xlat-parse.y" -{ yygotominor.yy72 = yymsp[-2].minor.yy72 - yymsp[0].minor.yy72; } -#line 1212 "xlat-parse.c" - break; - case 5: -#line 348 "xlat-parse.y" -{ yygotominor.yy72 = yymsp[-2].minor.yy72 * yymsp[0].minor.yy72; } -#line 1217 "xlat-parse.c" - break; - case 6: -#line 349 "xlat-parse.y" -{ yygotominor.yy72 = yymsp[-2].minor.yy72 / yymsp[0].minor.yy72; } -#line 1222 "xlat-parse.c" - break; - case 7: -#line 350 "xlat-parse.y" -{ yygotominor.yy72 = yymsp[-2].minor.yy72 | yymsp[0].minor.yy72; } -#line 1227 "xlat-parse.c" - break; - case 8: -#line 351 "xlat-parse.y" -{ yygotominor.yy72 = yymsp[-2].minor.yy72 & yymsp[0].minor.yy72; } -#line 1232 "xlat-parse.c" - break; - case 9: -#line 352 "xlat-parse.y" -{ yygotominor.yy72 = yymsp[-2].minor.yy72 ^ yymsp[0].minor.yy72; } -#line 1237 "xlat-parse.c" - break; - case 10: -#line 353 "xlat-parse.y" -{ yygotominor.yy72 = -yymsp[0].minor.yy72; } -#line 1242 "xlat-parse.c" - break; - case 11: -#line 354 "xlat-parse.y" -{ yygotominor.yy72 = yymsp[-1].minor.yy72; } -#line 1247 "xlat-parse.c" - break; - case 21: -#line 368 "xlat-parse.y" -{ - printf ("\n"); -} -#line 1254 "xlat-parse.c" - break; - case 25: -#line 376 "xlat-parse.y" -{ printf ("%s", yymsp[0].minor.yy0.string); } -#line 1259 "xlat-parse.c" - break; - case 26: -#line 377 "xlat-parse.y" -{ printf ("%d", yymsp[0].minor.yy72); } -#line 1264 "xlat-parse.c" - break; - case 27: -#line 378 "xlat-parse.y" -{ printf ("\n"); } -#line 1269 "xlat-parse.c" - break; - case 28: -#line 381 "xlat-parse.y" -{ - AddSym (yymsp[-3].minor.yy0.sym, yymsp[-1].minor.yy72); -} -#line 1276 "xlat-parse.c" - break; - case 29: -#line 386 "xlat-parse.y" -{ - IncludeFile (yymsp[0].minor.yy0.string); -} -#line 1283 "xlat-parse.c" - break; - case 31: -#line 393 "xlat-parse.y" -{ - EnumVal = 0; -} -#line 1290 "xlat-parse.c" - break; - case 35: -#line 402 "xlat-parse.y" -{ - AddSym (yymsp[0].minor.yy0.sym, EnumVal++); -} -#line 1297 "xlat-parse.c" - break; - case 36: -#line 407 "xlat-parse.y" -{ - AddSym (yymsp[-2].minor.yy0.sym, EnumVal = yymsp[0].minor.yy72); -} -#line 1304 "xlat-parse.c" - break; - case 40: -#line 420 "xlat-parse.y" -{ - AddSym (yymsp[-3].minor.yy0.sym, yymsp[-5].minor.yy72); -} -#line 1311 "xlat-parse.c" - break; - case 41: -#line 424 "xlat-parse.y" -{ - printf ("%s, line %d: %s is already defined\n", SourceName, SourceLine, yymsp[-3].minor.yy0.symval->Sym); -} -#line 1318 "xlat-parse.c" - break; - case 45: -#line 433 "xlat-parse.y" -{ - Simple[yymsp[-7].minor.yy72].NewSpecial = yymsp[-3].minor.yy72; - Simple[yymsp[-7].minor.yy72].Flags = yymsp[-5].minor.yy72 | yymsp[-1].minor.yy57.addflags; - Simple[yymsp[-7].minor.yy72].Args[0] = yymsp[-1].minor.yy57.args[0]; - Simple[yymsp[-7].minor.yy72].Args[1] = yymsp[-1].minor.yy57.args[1]; - Simple[yymsp[-7].minor.yy72].Args[2] = yymsp[-1].minor.yy57.args[2]; - Simple[yymsp[-7].minor.yy72].Args[3] = yymsp[-1].minor.yy57.args[3]; - Simple[yymsp[-7].minor.yy72].Args[4] = yymsp[-1].minor.yy57.args[4]; -} -#line 1331 "xlat-parse.c" - break; - case 46: -#line 443 "xlat-parse.y" -{ - printf ("%s, line %d: %s is undefined\n", SourceName, SourceLine, yymsp[-3].minor.yy0.sym); -} -#line 1338 "xlat-parse.c" - break; - case 47: -#line 448 "xlat-parse.y" -{ - if (NumBoomish == MAX_BOOMISH) - { - MoreLines *probe = yymsp[-1].minor.yy49; - - while (probe != NULL) - { - MoreLines *next = probe->next; - free (probe); - probe = next; - } - printf ("%s, line %d: Too many BOOM translators\n", SourceName, SourceLine); - } - else - { - int i; - MoreLines *probe; - - Boomish[NumBoomish].FirstLinetype = yymsp[-6].minor.yy72; - Boomish[NumBoomish].LastLinetype = yymsp[-4].minor.yy72; - Boomish[NumBoomish].NewSpecial = yymsp[-9].minor.yy72; - - for (i = 0, probe = yymsp[-1].minor.yy49; probe != NULL; i++) - { - MoreLines *next = probe->next;; - if (i < MAX_BOOMISH_EXEC) - { - Boomish[NumBoomish].Args[i] = probe->arg; - } - else if (i == MAX_BOOMISH_EXEC) - { - printf ("%s, line %d: Too many commands for this BOOM translator\n", SourceName, SourceLine); - } - free (probe); - probe = next; - } - if (i < MAX_BOOMISH_EXEC) - { - Boomish[NumBoomish].Args[i].bDefined = 0; - } - NumBoomish++; - } -} -#line 1385 "xlat-parse.c" - break; - case 48: -#line 493 "xlat-parse.y" -{ - yygotominor.yy49 = NULL; -} -#line 1392 "xlat-parse.c" - break; - case 49: -#line 497 "xlat-parse.y" -{ - yygotominor.yy49 = malloc (sizeof(MoreLines)); - yygotominor.yy49->next = yymsp[0].minor.yy49; - yygotominor.yy49->arg = yymsp[-1].minor.yy58; -} -#line 1401 "xlat-parse.c" - break; - case 50: -#line 504 "xlat-parse.y" -{ - yygotominor.yy58.bDefined = 1; - yygotominor.yy58.bOrExisting = (yymsp[-1].minor.yy72 == OR_EQUAL); - yygotominor.yy58.bUseConstant = (yymsp[0].minor.yy83.filters == NULL); - yygotominor.yy58.ArgNum = yymsp[-2].minor.yy72; - yygotominor.yy58.ConstantValue = yymsp[0].minor.yy83.constant; - yygotominor.yy58.AndValue = yymsp[0].minor.yy83.mask; - - if (yymsp[0].minor.yy83.filters != NULL) - { - int i; - MoreFilters *probe; - - for (i = 0, probe = yymsp[0].minor.yy83.filters; probe != NULL; i++) - { - MoreFilters *next = probe->next; - if (i < 15) - { - yygotominor.yy58.ResultFilter[i] = probe->filter.filter; - yygotominor.yy58.ResultValue[i] = probe->filter.value; - } - else if (i == 15) - { - yyerror ("Lists can only have 15 elements"); - } - free (probe); - probe = next; - } - yygotominor.yy58.ListSize = i > 15 ? 15 : i; - } -} -#line 1436 "xlat-parse.c" - break; - case 51: -#line 536 "xlat-parse.y" -{ yygotominor.yy72 = 4; } -#line 1441 "xlat-parse.c" - break; - case 52: -#line 537 "xlat-parse.y" -{ yygotominor.yy72 = 0; } -#line 1446 "xlat-parse.c" - break; - case 53: -#line 538 "xlat-parse.y" -{ yygotominor.yy72 = 1; } -#line 1451 "xlat-parse.c" - break; - case 54: -#line 539 "xlat-parse.y" -{ yygotominor.yy72 = 2; } -#line 1456 "xlat-parse.c" - break; - case 55: -#line 540 "xlat-parse.y" -{ yygotominor.yy72 = 3; } -#line 1461 "xlat-parse.c" - break; - case 56: -#line 542 "xlat-parse.y" -{ yygotominor.yy72 = '='; } -#line 1466 "xlat-parse.c" - break; - case 57: -#line 543 "xlat-parse.y" -{ yygotominor.yy72 = OR_EQUAL; } -#line 1471 "xlat-parse.c" - break; - case 58: -#line 546 "xlat-parse.y" -{ - yygotominor.yy83.constant = yymsp[0].minor.yy72; - yygotominor.yy83.filters = NULL; -} -#line 1479 "xlat-parse.c" - break; - case 59: -#line 551 "xlat-parse.y" -{ - yygotominor.yy83.mask = yymsp[-3].minor.yy72; - yygotominor.yy83.filters = yymsp[-1].minor.yy87; -} -#line 1487 "xlat-parse.c" - break; - case 60: -#line 557 "xlat-parse.y" -{ - yygotominor.yy87 = malloc (sizeof(MoreFilters)); - yygotominor.yy87->next = NULL; - yygotominor.yy87->filter = yymsp[0].minor.yy124; -} -#line 1496 "xlat-parse.c" - break; - case 61: -#line 563 "xlat-parse.y" -{ - yygotominor.yy87 = malloc (sizeof(MoreFilters)); - yygotominor.yy87->next = yymsp[0].minor.yy87; - yygotominor.yy87->filter = yymsp[-2].minor.yy124; -} -#line 1505 "xlat-parse.c" - break; - case 62: -#line 570 "xlat-parse.y" -{ - yygotominor.yy124.filter = yymsp[-2].minor.yy72; - yygotominor.yy124.value = yymsp[0].minor.yy72; -} -#line 1513 "xlat-parse.c" - break; - case 63: -#line 576 "xlat-parse.y" -{ - yygotominor.yy57.addflags = 0; - memset (yygotominor.yy57.args, 0, 5); -} -#line 1521 "xlat-parse.c" - break; - case 64: -#line 581 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT1; - memset (yygotominor.yy57.args, 0, 5); -} -#line 1529 "xlat-parse.c" - break; - case 65: -#line 586 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT1; - yygotominor.yy57.args[0] = 0; - yygotominor.yy57.args[1] = yymsp[0].minor.yy72; - yygotominor.yy57.args[2] = 0; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1541 "xlat-parse.c" - break; - case 66: -#line 595 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT1; - yygotominor.yy57.args[0] = 0; - yygotominor.yy57.args[1] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[2] = yymsp[0].minor.yy72; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1553 "xlat-parse.c" - break; - case 67: -#line 604 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT1; - yygotominor.yy57.args[0] = 0; - yygotominor.yy57.args[1] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[2] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[3] = yymsp[0].minor.yy72; - yygotominor.yy57.args[4] = 0; -} -#line 1565 "xlat-parse.c" - break; - case 68: -#line 613 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT1; - yygotominor.yy57.args[0] = 0; - yygotominor.yy57.args[1] = yymsp[-6].minor.yy72; - yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[4] = yymsp[0].minor.yy72; -} -#line 1577 "xlat-parse.c" - break; - case 69: -#line 622 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HAS2TAGS; - yygotominor.yy57.args[0] = yygotominor.yy57.args[1] = 0; - yygotominor.yy57.args[2] = 0; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1588 "xlat-parse.c" - break; - case 70: -#line 630 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HAS2TAGS; - yygotominor.yy57.args[0] = yygotominor.yy57.args[1] = 0; - yygotominor.yy57.args[2] = yymsp[0].minor.yy72; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1599 "xlat-parse.c" - break; - case 71: -#line 638 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HAS2TAGS; - yygotominor.yy57.args[0] = yygotominor.yy57.args[1] = 0; - yygotominor.yy57.args[2] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[3] = yymsp[0].minor.yy72; - yygotominor.yy57.args[4] = 0; -} -#line 1610 "xlat-parse.c" - break; - case 72: -#line 646 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HAS2TAGS; - yygotominor.yy57.args[0] = yygotominor.yy57.args[1] = 0; - yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[4] = yymsp[0].minor.yy72; -} -#line 1621 "xlat-parse.c" - break; - case 73: -#line 654 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASLINEID; - memset (yygotominor.yy57.args, 0, 5); -} -#line 1629 "xlat-parse.c" - break; - case 74: -#line 659 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASLINEID; - yygotominor.yy57.args[0] = 0; - yygotominor.yy57.args[1] = yymsp[0].minor.yy72; - yygotominor.yy57.args[2] = 0; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1641 "xlat-parse.c" - break; - case 75: -#line 668 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASLINEID; - yygotominor.yy57.args[0] = 0; - yygotominor.yy57.args[1] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[2] = yymsp[0].minor.yy72; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1653 "xlat-parse.c" - break; - case 76: -#line 677 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASLINEID; - yygotominor.yy57.args[0] = 0; - yygotominor.yy57.args[1] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[2] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[3] = yymsp[0].minor.yy72; - yygotominor.yy57.args[4] = 0; -} -#line 1665 "xlat-parse.c" - break; - case 77: -#line 686 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASLINEID; - yygotominor.yy57.args[0] = 0; - yygotominor.yy57.args[1] = yymsp[-6].minor.yy72; - yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[4] = yymsp[0].minor.yy72; -} -#line 1677 "xlat-parse.c" - break; - case 78: -#line 695 "xlat-parse.y" -{ - yygotominor.yy57.addflags = 0; - yygotominor.yy57.args[0] = yymsp[0].minor.yy72; - yygotominor.yy57.args[1] = 0; - yygotominor.yy57.args[2] = 0; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1689 "xlat-parse.c" - break; - case 79: -#line 704 "xlat-parse.y" -{ - yygotominor.yy57.addflags = 0; - yygotominor.yy57.args[0] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[1] = yymsp[0].minor.yy72; - yygotominor.yy57.args[2] = 0; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1701 "xlat-parse.c" - break; - case 80: -#line 713 "xlat-parse.y" -{ - yygotominor.yy57.addflags = 0; - yygotominor.yy57.args[0] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[1] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[2] = yymsp[0].minor.yy72; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1713 "xlat-parse.c" - break; - case 81: -#line 722 "xlat-parse.y" -{ - yygotominor.yy57.addflags = 0; - yygotominor.yy57.args[0] = yymsp[-6].minor.yy72; - yygotominor.yy57.args[1] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[2] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[3] = yymsp[0].minor.yy72; - yygotominor.yy57.args[4] = 0; -} -#line 1725 "xlat-parse.c" - break; - case 82: -#line 731 "xlat-parse.y" -{ - yygotominor.yy57.addflags = 0; - yygotominor.yy57.args[0] = yymsp[-8].minor.yy72; - yygotominor.yy57.args[1] = yymsp[-6].minor.yy72; - yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[4] = yymsp[0].minor.yy72; -} -#line 1737 "xlat-parse.c" - break; - case 83: -#line 740 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT2; - yygotominor.yy57.args[0] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[1] = 0; - yygotominor.yy57.args[2] = 0; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1749 "xlat-parse.c" - break; - case 84: -#line 749 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT2; - yygotominor.yy57.args[0] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[1] = 0; - yygotominor.yy57.args[2] = yymsp[0].minor.yy72; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1761 "xlat-parse.c" - break; - case 85: -#line 758 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT2; - yygotominor.yy57.args[0] = yymsp[-6].minor.yy72; - yygotominor.yy57.args[1] = 0; - yygotominor.yy57.args[2] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[3] = yymsp[0].minor.yy72; - yygotominor.yy57.args[4] = 0; -} -#line 1773 "xlat-parse.c" - break; - case 86: -#line 767 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT2; - yygotominor.yy57.args[0] = yymsp[-8].minor.yy72; - yygotominor.yy57.args[1] = 0; - yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[4] = yymsp[0].minor.yy72; -} -#line 1785 "xlat-parse.c" - break; - case 87: -#line 776 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT3; - yygotominor.yy57.args[0] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[1] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[2] = 0; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1797 "xlat-parse.c" - break; - case 88: -#line 785 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT3; - yygotominor.yy57.args[0] = yymsp[-6].minor.yy72; - yygotominor.yy57.args[1] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[2] = 0; - yygotominor.yy57.args[3] = yymsp[0].minor.yy72; - yygotominor.yy57.args[4] = 0; -} -#line 1809 "xlat-parse.c" - break; - case 89: -#line 794 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT3; - yygotominor.yy57.args[0] = yymsp[-8].minor.yy72; - yygotominor.yy57.args[1] = yymsp[-6].minor.yy72; - yygotominor.yy57.args[2] = 0; - yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[4] = yymsp[0].minor.yy72; -} -#line 1821 "xlat-parse.c" - break; - case 90: -#line 803 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT4; - yygotominor.yy57.args[0] = yymsp[-6].minor.yy72; - yygotominor.yy57.args[1] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[2] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = 0; -} -#line 1833 "xlat-parse.c" - break; - case 91: -#line 812 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT4; - yygotominor.yy57.args[0] = yymsp[-8].minor.yy72; - yygotominor.yy57.args[1] = yymsp[-6].minor.yy72; - yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[3] = 0; - yygotominor.yy57.args[4] = yymsp[0].minor.yy72; -} -#line 1845 "xlat-parse.c" - break; - case 92: -#line 821 "xlat-parse.y" -{ - yygotominor.yy57.addflags = SIMPLE_HASTAGAT5; - yygotominor.yy57.args[0] = yymsp[-8].minor.yy72; - yygotominor.yy57.args[1] = yymsp[-6].minor.yy72; - yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; - yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; - yygotominor.yy57.args[4] = 0; -} -#line 1857 "xlat-parse.c" - break; - }; - yygoto = yyRuleInfo[yyruleno].lhs; - yysize = yyRuleInfo[yyruleno].nrhs; - yypParser->yyidx -= yysize; - yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto); - if( yyact < YYNSTATE ){ -#ifdef NDEBUG - /* If we are not debugging and the reduce action popped at least - ** one element off the stack, then we can push the new element back - ** onto the stack here, and skip the stack overflow test in yy_shift(). - ** That gives a significant speed improvement. */ - if( yysize ){ - yypParser->yyidx++; - yymsp -= yysize-1; - yymsp->stateno = yyact; - yymsp->major = yygoto; - yymsp->minor = yygotominor; - }else -#endif - { - yy_shift(yypParser,yyact,yygoto,&yygotominor); - } - }else if( yyact == YYNSTATE + YYNRULE + 1 ){ - yy_accept(yypParser); - } -} - -/* -** The following code executes when the parse fails -*/ -static void yy_parse_failed( - yyParser *yypParser /* The parser */ -){ - ParseARG_FETCH; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); - } -#endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will be executed whenever the - ** parser fails */ - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -/* -** The following code executes when a syntax error first occurs. -*/ -static void yy_syntax_error( - yyParser *yypParser, /* The parser */ - int yymajor, /* The major type of the error token */ - YYMINORTYPE yyminor /* The minor type of the error token */ -){ - ParseARG_FETCH; -#define TOKEN (yyminor.yy0) -#line 322 "xlat-parse.y" -yyerror("syntax error"); -#line 1916 "xlat-parse.c" - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -/* -** The following is executed when the parser accepts -*/ -static void yy_accept( - yyParser *yypParser /* The parser */ -){ - ParseARG_FETCH; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); - } -#endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will be executed whenever the - ** parser accepts */ - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -/* The main parser program. -** The first argument is a pointer to a structure obtained from -** "ParseAlloc" which describes the current state of the parser. -** The second argument is the major token number. The third is -** the minor token. The fourth optional argument is whatever the -** user wants (and specified in the grammar) and is available for -** use by the action routines. -** -** Inputs: -**
    -**
  • A pointer to the parser (an opaque structure.) -**
  • The major token number. -**
  • The minor token number. -**
  • An option argument of a grammar-specified type. -**
-** -** Outputs: -** None. -*/ -void Parse( - void *yyp, /* The parser */ - int yymajor, /* The major token code number */ - ParseTOKENTYPE yyminor /* The value for the token */ - ParseARG_PDECL /* Optional %extra_argument parameter */ -){ - YYMINORTYPE yyminorunion; - int yyact; /* The parser action. */ - int yyendofinput; /* True if we are at the end of input */ - int yyerrorhit = 0; /* True if yymajor has invoked an error */ - yyParser *yypParser; /* The parser */ - - /* (re)initialize the parser, if necessary */ - yypParser = (yyParser*)yyp; - if( yypParser->yyidx<0 ){ - /* if( yymajor==0 ) return; // not sure why this was here... */ - yypParser->yyidx = 0; - yypParser->yyerrcnt = -1; - yypParser->yystack[0].stateno = 0; - yypParser->yystack[0].major = 0; - } - yyminorunion.yy0 = yyminor; - yyendofinput = (yymajor==0); - ParseARG_STORE; - -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); - } -#endif - - do{ - yyact = yy_find_shift_action(yypParser,yymajor); - if( yyactyyerrcnt--; - if( yyendofinput && yypParser->yyidx>=0 ){ - yymajor = 0; - }else{ - yymajor = YYNOCODE; - while( yypParser->yyidx>= 0 && (yyact = yy_find_shift_action(yypParser,YYNOCODE)) < YYNSTATE + YYNRULE ){ - yy_reduce(yypParser,yyact-YYNSTATE); - } - } - }else if( yyact < YYNSTATE + YYNRULE ){ - yy_reduce(yypParser,yyact-YYNSTATE); - }else if( yyact == YY_ERROR_ACTION ){ - int yymx; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); - } -#endif -#ifdef YYERRORSYMBOL - /* A syntax error has occurred. - ** The response to an error depends upon whether or not the - ** grammar defines an error token "ERROR". - ** - ** This is what we do if the grammar does define ERROR: - ** - ** * Call the %syntax_error function. - ** - ** * Begin popping the stack until we enter a state where - ** it is legal to shift the error symbol, then shift - ** the error symbol. - ** - ** * Set the error count to three. - ** - ** * Begin accepting and shifting new tokens. No new error - ** processing will occur until three tokens have been - ** shifted successfully. - ** - */ - if( yypParser->yyerrcnt<0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); - } - yymx = yypParser->yystack[yypParser->yyidx].major; - if( yymx==YYERRORSYMBOL || yyerrorhit ){ -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sDiscard input token %s\n", - yyTracePrompt,yyTokenName[yymajor]); - } -#endif - yy_destructor(yymajor,&yyminorunion); - yymajor = YYNOCODE; - }else{ - while( - yypParser->yyidx >= 0 && - yymx != YYERRORSYMBOL && - (yyact = yy_find_reduce_action( - yypParser->yystack[yypParser->yyidx].stateno, - YYERRORSYMBOL)) >= YYNSTATE - ){ - yy_pop_parser_stack(yypParser); - } - if( yypParser->yyidx < 0 || yymajor==0 ){ - yy_destructor(yymajor,&yyminorunion); - yy_parse_failed(yypParser); - yymajor = YYNOCODE; - }else if( yymx!=YYERRORSYMBOL ){ - YYMINORTYPE u2; - u2.YYERRSYMDT = 0; - yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); - } - } - yypParser->yyerrcnt = 3; - yyerrorhit = 1; -#else /* YYERRORSYMBOL is not defined */ - /* This is what we do if the grammar does not define ERROR: - ** - ** * Report an error message, and throw away the input token. - ** - ** * If the input token is $, then fail the parse. - ** - ** As before, subsequent error messages are suppressed until - ** three input tokens have been successfully shifted. - */ - if( yypParser->yyerrcnt<=0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); - } - yypParser->yyerrcnt = 3; - yy_destructor(yymajor,&yyminorunion); - if( yyendofinput ){ - yy_parse_failed(yypParser); - } - yymajor = YYNOCODE; -#endif - }else{ - yy_accept(yypParser); - yymajor = YYNOCODE; - } - }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); - return; -} +/* Driver template for the LEMON parser generator. +** The author disclaims copyright to this source code. +*/ +/* First off, code is included which follows the "include" declaration +** in the input file. */ +#include +#include +#include +#line 1 "xlat-parse.y" + +#include "xlat.h" +#include "xlat-parse.h" +#include +#include + +int yyerror (char *s); + +typedef struct _Symbol +{ + struct _Symbol *Next; + int Value; + char Sym[1]; +} Symbol; + +static bool FindToken (char *tok, int *type); +static void AddSym (char *sym, int val); +static bool FindSym (char *sym, Symbol **val); + +static int EnumVal; + +struct ListFilter +{ + WORD filter; + BYTE value; +}; + +typedef struct _morefilters +{ + struct _morefilters *next; + struct ListFilter filter; +} MoreFilters; + +typedef struct _morelines +{ + struct _morelines *next; + BoomArg arg; +} MoreLines; + +typedef struct _specialargs +{ + BYTE addflags; + BYTE args[5]; +} SpecialArgs; + +typedef struct _boomarg +{ + BYTE constant; + WORD mask; + MoreFilters *filters; +} ParseBoomArg; + +typedef union YYSTYPE +{ + int val; + char sym[80]; + char string[80]; + Symbol *symval; +} YYSTYPE; + +#include +#include + +int yylex (YYSTYPE *yylval) +{ + char token[80]; + int toksize; + int c; + +loop: + while (Source == NULL) + { + if (!EndFile ()) + return 0; + } + while (isspace (c = fgetc (Source)) && c != EOF) + { + if (c == '\n') + SourceLine++; + } + + if (c == EOF) + { + if (EndFile ()) + goto loop; + return 0; + } + if (isdigit (c)) + { + int buildup = c - '0'; + if (c == '0') + { + c = fgetc (Source); + if (c == 'x' || c == 'X') + { + for (;;) + { + c = fgetc (Source); + if (isdigit (c)) + { + buildup = (buildup<<4) + c - '0'; + } + else if (c >= 'a' && c <= 'f') + { + buildup = (buildup<<4) + c - 'a' + 10; + } + else if (c >= 'A' && c <= 'F') + { + buildup = (buildup<<4) + c - 'A' + 10; + } + else + { + ungetc (c, Source); + yylval->val = buildup; + return NUM; + } + } + } + else + { + ungetc (c, Source); + } + } + while (isdigit (c = fgetc (Source))) + { + buildup = buildup*10 + c - '0'; + } + ungetc (c, Source); + yylval->val = buildup; + return NUM; + } + if (isalpha (c)) + { + int buildup = 0; + + token[0] = c; + toksize = 1; + while (toksize < 79 && (isalnum (c = fgetc (Source)) || c == '_')) + { + token[toksize++] = c; + } + token[toksize] = 0; + if (toksize == 79 && isalnum (c)) + { + while (isalnum (c = fgetc (Source))) + ; + } + ungetc (c, Source); + if (FindToken (token, &buildup)) + { + return buildup; + } + if (FindSym (token, &yylval->symval)) + { + return SYMNUM; + } + strcpy (yylval->sym, token); + return SYM; + } + if (c == '/') + { + c = fgetc (Source); + if (c == '*') + { + for (;;) + { + while ((c = fgetc (Source)) != '*' && c != EOF) + { + if (c == '\n') + SourceLine++; + } + if (c == EOF) + return 0; + if ((c = fgetc (Source)) == '/') + goto loop; + if (c == EOF) + return 0; + ungetc (c, Source); + } + } + else if (c == '/') + { + while ((c = fgetc (Source)) != '\n' && c != EOF) + ; + if (c == '\n') + SourceLine++; + else if (c == EOF) + return 0; + goto loop; + } + else + { + ungetc (c, Source); + return DIVIDE; + } + } + if (c == '"') + { + int tokensize = 0; + while ((c = fgetc (Source)) != '"' && c != EOF) + { + yylval->string[tokensize++] = c; + } + yylval->string[tokensize] = 0; + return STRING; + } + if (c == '|') + { + c = fgetc (Source); + if (c == '=') + return OR_EQUAL; + ungetc (c, Source); + return OR; + } + switch (c) + { + case '^': return XOR; + case '&': return AND; + case '-': return MINUS; + case '+': return PLUS; + case '*': return MULTIPLY; + case '(': return LPAREN; + case ')': return RPAREN; + case ',': return COMMA; + case '{': return LBRACE; + case '}': return RBRACE; + case '=': return EQUALS; + case ';': return SEMICOLON; + case ':': return COLON; + case '[': return LBRACKET; + case ']': return RBRACKET; + default: return 0; + } +} + +void *ParseAlloc(void *(*mallocProc)(size_t)); +void Parse(void *yyp, int yymajor, YYSTYPE yyminor); +void ParseFree(void *p, void (*freeProc)(void*)); +void ParseTrace(FILE *TraceFILE, char *zTracePrompt); + +void yyparse (void) +{ + void *pParser = ParseAlloc (malloc); + YYSTYPE token; + int tokentype; + + while ((tokentype = yylex(&token)) != 0) + { + Parse (pParser, tokentype, token); + } + memset (&token, 0, sizeof(token)); + Parse (pParser, 0, token); + ParseFree (pParser, free); +} + +static Symbol *FirstSym; + +static void AddSym (char *sym, int val) +{ + Symbol *syme = malloc (strlen (sym) + sizeof(Symbol)); + syme->Next = FirstSym; + syme->Value = val; + strcpy (syme->Sym, sym); + FirstSym = syme; +} + +static bool FindSym (char *sym, Symbol **val) +{ + Symbol *syme = FirstSym; + + while (syme != NULL) + { + if (strcmp (syme->Sym, sym) == 0) + { + *val = syme; + return 1; + } + syme = syme->Next; + } + return 0; +} + +static bool FindToken (char *tok, int *type) +{ + static const char tokens[][8] = + { + "endl", "print", "include", "special", "define", "enum", + "arg5", "arg4", "arg3", "arg2", "flags", "lineid", "tag" + + }; + static const short types[] = + { + ENDL, PRINT, INCLUDE, SPECIAL, DEFINE, ENUM, + ARG5, ARG4, ARG3, ARG2, FLAGS, LINEID, TAG + }; + int i; + + for (i = sizeof(tokens)/sizeof(tokens[0])-1; i >= 0; i--) + { + if (strcmp (tok, tokens[i]) == 0) + { + *type = types[i]; + return 1; + } + } + return 0; +} + +int yyerror (char *s) +{ + if (SourceName != NULL) + printf ("%s, line %d: %s\n", SourceName, SourceLine, s); + else + printf ("%s\n", s); + return 0; +} + +#line 328 "xlat-parse.c" +/* Next is all token values, in a form suitable for use by makeheaders. +** This section will be null unless lemon is run with the -m switch. +*/ +/* +** These constants (all generated automatically by the parser generator) +** specify the various kinds of tokens (terminals) that the parser +** understands. +** +** Each symbol here is a terminal symbol in the grammar. +*/ +/* Make sure the INTERFACE macro is defined. +*/ +#ifndef INTERFACE +# define INTERFACE 1 +#endif +/* The next thing included is series of defines which control +** various aspects of the generated parser. +** YYCODETYPE is the data type used for storing terminal +** and nonterminal numbers. "unsigned char" is +** used if there are fewer than 250 terminals +** and nonterminals. "int" is used otherwise. +** YYNOCODE is a number of type YYCODETYPE which corresponds +** to no legal terminal or nonterminal number. This +** number is used to fill in empty slots of the hash +** table. +** YYFALLBACK If defined, this indicates that one or more tokens +** have fall-back values which should be used if the +** original value of the token will not parse. +** YYACTIONTYPE is the data type used for storing terminal +** and nonterminal numbers. "unsigned char" is +** used if there are fewer than 250 rules and +** states combined. "int" is used otherwise. +** ParseTOKENTYPE is the data type used for minor tokens given +** directly to the parser from the tokenizer. +** YYMINORTYPE is the data type used for all minor tokens. +** This is typically a union of many types, one of +** which is ParseTOKENTYPE. The entry in the union +** for base tokens is called "yy0". +** YYSTACKDEPTH is the maximum depth of the parser's stack. If +** zero the stack is dynamically sized using realloc() +** ParseARG_SDECL A static variable declaration for the %extra_argument +** ParseARG_PDECL A parameter declaration for the %extra_argument +** ParseARG_STORE Code to store %extra_argument into yypParser +** ParseARG_FETCH Code to extract %extra_argument from yypParser +** YYNSTATE the combined number of states. +** YYNRULE the number of rules in the grammar +** YYERRORSYMBOL is the code number of the error symbol. If not +** defined, then do no error processing. +*/ +#define YYCODETYPE unsigned char +#define YYNOCODE 66 +#define YYACTIONTYPE unsigned short int +#define ParseTOKENTYPE YYSTYPE +typedef union { + ParseTOKENTYPE yy0; + MoreLines * yy49; + SpecialArgs yy57; + BoomArg yy58; + int yy72; + ParseBoomArg yy83; + MoreFilters * yy87; + struct ListFilter yy124; + int yy131; +} YYMINORTYPE; +#define YYSTACKDEPTH 100 +#define ParseARG_SDECL +#define ParseARG_PDECL +#define ParseARG_FETCH +#define ParseARG_STORE +#define YYNSTATE 173 +#define YYNRULE 93 +#define YYERRORSYMBOL 37 +#define YYERRSYMDT yy131 +#define YY_NO_ACTION (YYNSTATE+YYNRULE+2) +#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) +#define YY_ERROR_ACTION (YYNSTATE+YYNRULE) + +/* Next are that tables used to determine what action to take based on the +** current state and lookahead token. These tables are used to implement +** functions that take a state number and lookahead value and return an +** action integer. +** +** Suppose the action integer is N. Then the action is determined as +** follows +** +** 0 <= N < YYNSTATE Shift N. That is, push the lookahead +** token onto the stack and goto state N. +** +** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE. +** +** N == YYNSTATE+YYNRULE A syntax error has occurred. +** +** N == YYNSTATE+YYNRULE+1 The parser accepts its input. +** +** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused +** slots in the yy_action[] table. +** +** The action table is constructed as a single large table named yy_action[]. +** Given state S and lookahead X, the action is computed as +** +** yy_action[ yy_shift_ofst[S] + X ] +** +** If the index value yy_shift_ofst[S]+X is out of range or if the value +** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] +** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table +** and that yy_default[S] should be used instead. +** +** The formula above is for computing the action when the lookahead is +** a terminal symbol. If the lookahead is a non-terminal (as occurs after +** a reduce action) then the yy_reduce_ofst[] array is used in place of +** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of +** YY_SHIFT_USE_DFLT. +** +** The following are the tables generated in this section: +** +** yy_action[] A single table containing all actions. +** yy_lookahead[] A table containing the lookahead for each entry in +** yy_action. Used to detect hash collisions. +** yy_shift_ofst[] For each state, the offset into yy_action for +** shifting terminals. +** yy_reduce_ofst[] For each state, the offset into yy_action for +** shifting non-terminals after a reduce. +** yy_default[] Default action for each state. +*/ +static const YYACTIONTYPE yy_action[] = { + /* 0 */ 65, 41, 32, 35, 52, 42, 28, 51, 77, 117, + /* 10 */ 267, 163, 160, 149, 148, 147, 146, 145, 144, 143, + /* 20 */ 30, 80, 14, 128, 164, 156, 151, 23, 123, 127, + /* 30 */ 55, 4, 152, 102, 33, 108, 80, 119, 128, 107, + /* 40 */ 5, 111, 113, 22, 2, 41, 32, 35, 52, 42, + /* 50 */ 28, 51, 32, 35, 52, 42, 28, 51, 19, 3, + /* 60 */ 41, 32, 35, 52, 42, 28, 51, 52, 42, 28, + /* 70 */ 51, 135, 116, 41, 32, 35, 52, 42, 28, 51, + /* 80 */ 41, 32, 35, 52, 42, 28, 51, 28, 51, 11, + /* 90 */ 9, 168, 169, 170, 171, 172, 77, 106, 26, 66, + /* 100 */ 41, 32, 35, 52, 42, 28, 51, 35, 52, 42, + /* 110 */ 28, 51, 10, 27, 61, 41, 32, 35, 52, 42, + /* 120 */ 28, 51, 68, 120, 100, 139, 165, 49, 18, 166, + /* 130 */ 41, 32, 35, 52, 42, 28, 51, 55, 4, 101, + /* 140 */ 167, 12, 40, 29, 43, 41, 32, 35, 52, 42, + /* 150 */ 28, 51, 136, 131, 113, 91, 66, 98, 16, 115, + /* 160 */ 41, 32, 35, 52, 42, 28, 51, 124, 130, 159, + /* 170 */ 56, 59, 129, 37, 61, 41, 32, 35, 52, 42, + /* 180 */ 28, 51, 138, 109, 48, 57, 60, 154, 20, 54, + /* 190 */ 41, 32, 35, 52, 42, 28, 51, 13, 62, 90, + /* 200 */ 89, 17, 15, 21, 7, 41, 32, 35, 52, 42, + /* 210 */ 28, 51, 39, 132, 63, 99, 94, 87, 31, 142, + /* 220 */ 41, 32, 35, 52, 42, 28, 51, 134, 133, 67, + /* 230 */ 88, 157, 74, 41, 32, 35, 52, 42, 28, 51, + /* 240 */ 41, 32, 35, 52, 42, 28, 51, 84, 161, 30, + /* 250 */ 141, 104, 86, 38, 156, 151, 23, 1, 153, 6, + /* 260 */ 96, 41, 32, 35, 52, 42, 28, 51, 41, 32, + /* 270 */ 35, 52, 42, 28, 51, 8, 41, 32, 35, 52, + /* 280 */ 42, 28, 51, 25, 103, 64, 97, 125, 71, 95, + /* 290 */ 24, 76, 41, 32, 35, 52, 42, 28, 51, 150, + /* 300 */ 158, 78, 268, 162, 268, 45, 83, 41, 32, 35, + /* 310 */ 52, 42, 28, 51, 92, 81, 82, 268, 70, 69, + /* 320 */ 44, 85, 41, 32, 35, 52, 42, 28, 51, 268, + /* 330 */ 72, 79, 75, 58, 73, 36, 93, 41, 32, 35, + /* 340 */ 52, 42, 28, 51, 268, 268, 268, 268, 268, 268, + /* 350 */ 46, 268, 41, 32, 35, 52, 42, 28, 51, 268, + /* 360 */ 268, 268, 268, 268, 268, 34, 268, 41, 32, 35, + /* 370 */ 52, 42, 28, 51, 268, 268, 268, 268, 268, 268, + /* 380 */ 47, 268, 41, 32, 35, 52, 42, 28, 51, 268, + /* 390 */ 268, 268, 268, 268, 268, 50, 268, 41, 32, 35, + /* 400 */ 52, 42, 28, 51, 268, 268, 268, 268, 268, 268, + /* 410 */ 53, 88, 41, 32, 35, 52, 42, 28, 51, 30, + /* 420 */ 268, 268, 30, 268, 156, 151, 23, 156, 151, 23, + /* 430 */ 30, 110, 104, 140, 137, 156, 151, 23, 268, 268, + /* 440 */ 30, 268, 268, 268, 105, 156, 151, 23, 268, 30, + /* 450 */ 114, 126, 30, 268, 156, 151, 23, 156, 151, 23, + /* 460 */ 30, 268, 268, 30, 268, 156, 151, 23, 156, 151, + /* 470 */ 23, 155, 268, 268, 268, 268, 268, 268, 268, 268, + /* 480 */ 122, 268, 268, 118, 268, 268, 268, 268, 268, 268, + /* 490 */ 268, 121, 268, 268, 112, +}; +static const YYCODETYPE yy_lookahead[] = { + /* 0 */ 38, 1, 2, 3, 4, 5, 6, 7, 38, 39, + /* 10 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + /* 20 */ 4, 38, 60, 40, 41, 9, 10, 11, 28, 13, + /* 30 */ 44, 45, 46, 17, 14, 19, 38, 21, 40, 41, + /* 40 */ 24, 61, 62, 27, 11, 1, 2, 3, 4, 5, + /* 50 */ 6, 7, 2, 3, 4, 5, 6, 7, 14, 22, + /* 60 */ 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, + /* 70 */ 7, 12, 18, 1, 2, 3, 4, 5, 6, 7, + /* 80 */ 1, 2, 3, 4, 5, 6, 7, 6, 7, 11, + /* 90 */ 11, 29, 30, 31, 32, 33, 38, 39, 26, 38, + /* 100 */ 1, 2, 3, 4, 5, 6, 7, 3, 4, 5, + /* 110 */ 6, 7, 43, 14, 38, 1, 2, 3, 4, 5, + /* 120 */ 6, 7, 38, 47, 63, 64, 42, 11, 14, 23, + /* 130 */ 1, 2, 3, 4, 5, 6, 7, 44, 45, 46, + /* 140 */ 34, 14, 14, 14, 14, 1, 2, 3, 4, 5, + /* 150 */ 6, 7, 25, 61, 62, 38, 38, 38, 14, 10, + /* 160 */ 1, 2, 3, 4, 5, 6, 7, 18, 12, 38, + /* 170 */ 38, 38, 22, 14, 38, 1, 2, 3, 4, 5, + /* 180 */ 6, 7, 64, 47, 14, 38, 38, 12, 14, 23, + /* 190 */ 1, 2, 3, 4, 5, 6, 7, 11, 38, 38, + /* 200 */ 38, 14, 14, 14, 14, 1, 2, 3, 4, 5, + /* 210 */ 6, 7, 14, 20, 38, 38, 38, 38, 14, 12, + /* 220 */ 1, 2, 3, 4, 5, 6, 7, 12, 15, 38, + /* 230 */ 38, 12, 38, 1, 2, 3, 4, 5, 6, 7, + /* 240 */ 1, 2, 3, 4, 5, 6, 7, 38, 28, 4, + /* 250 */ 58, 59, 38, 14, 9, 10, 11, 14, 12, 27, + /* 260 */ 38, 1, 2, 3, 4, 5, 6, 7, 1, 2, + /* 270 */ 3, 4, 5, 6, 7, 11, 1, 2, 3, 4, + /* 280 */ 5, 6, 7, 11, 18, 38, 26, 12, 38, 38, + /* 290 */ 23, 38, 1, 2, 3, 4, 5, 6, 7, 20, + /* 300 */ 38, 38, 65, 38, 65, 14, 38, 1, 2, 3, + /* 310 */ 4, 5, 6, 7, 38, 38, 38, 65, 38, 38, + /* 320 */ 14, 38, 1, 2, 3, 4, 5, 6, 7, 65, + /* 330 */ 38, 38, 38, 38, 38, 14, 38, 1, 2, 3, + /* 340 */ 4, 5, 6, 7, 65, 65, 65, 65, 65, 65, + /* 350 */ 14, 65, 1, 2, 3, 4, 5, 6, 7, 65, + /* 360 */ 65, 65, 65, 65, 65, 14, 65, 1, 2, 3, + /* 370 */ 4, 5, 6, 7, 65, 65, 65, 65, 65, 65, + /* 380 */ 14, 65, 1, 2, 3, 4, 5, 6, 7, 65, + /* 390 */ 65, 65, 65, 65, 65, 14, 65, 1, 2, 3, + /* 400 */ 4, 5, 6, 7, 65, 65, 65, 65, 65, 65, + /* 410 */ 14, 38, 1, 2, 3, 4, 5, 6, 7, 4, + /* 420 */ 65, 65, 4, 65, 9, 10, 11, 9, 10, 11, + /* 430 */ 4, 58, 59, 15, 16, 9, 10, 11, 65, 65, + /* 440 */ 4, 65, 65, 65, 18, 9, 10, 11, 65, 4, + /* 450 */ 35, 36, 4, 65, 9, 10, 11, 9, 10, 11, + /* 460 */ 4, 65, 65, 4, 65, 9, 10, 11, 9, 10, + /* 470 */ 11, 35, 65, 65, 65, 65, 65, 65, 65, 65, + /* 480 */ 35, 65, 65, 35, 65, 65, 65, 65, 65, 65, + /* 490 */ 65, 35, 65, 65, 35, +}; +#define YY_SHIFT_USE_DFLT (-1) +#define YY_SHIFT_MAX 128 +static const short yy_shift_ofst[] = { + /* 0 */ 16, 418, 418, 62, 62, 245, 245, 245, 415, 415, + /* 10 */ 245, 245, 245, 245, 54, 54, 456, 459, 448, 426, + /* 20 */ 445, 436, 245, 245, 245, 245, 245, 245, 245, 245, + /* 30 */ 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + /* 40 */ 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + /* 50 */ 245, 245, 245, 245, 245, 106, 396, 381, 366, 351, + /* 60 */ 336, 321, 306, 291, 275, 267, 260, 239, 232, 0, + /* 70 */ 219, 204, 189, 174, 159, 144, 129, 114, 99, 79, + /* 80 */ 72, 59, 44, 411, 411, 411, 411, 411, 411, 411, + /* 90 */ 411, 411, 411, 411, 50, 104, 63, 149, 81, 81, + /* 100 */ 127, 279, 266, 272, 243, 264, 246, 220, 213, 215, + /* 110 */ 207, 193, 198, 188, 187, 186, 166, 175, 170, 150, + /* 120 */ 156, 130, 128, 116, 78, 37, 20, 33, 190, +}; +#define YY_REDUCE_USE_DFLT (-39) +#define YY_REDUCE_MAX 55 +static const short yy_reduce_ofst[] = { + /* 0 */ -38, 192, 373, 93, -14, 61, -2, -17, 58, -30, + /* 10 */ 84, 76, 118, 136, -20, 92, 296, 295, 294, 293, + /* 20 */ 292, 283, 281, 280, 278, 277, 276, 268, 265, 263, + /* 30 */ 262, 253, 251, 250, 247, 222, 214, 209, 194, 191, + /* 40 */ 179, 178, 177, 176, 162, 161, 160, 148, 147, 133, + /* 50 */ 132, 131, 119, 298, 117, 69, +}; +static const YYACTIONTYPE yy_default[] = { + /* 0 */ 185, 195, 195, 221, 221, 266, 266, 266, 236, 236, + /* 10 */ 266, 215, 266, 215, 205, 205, 266, 266, 266, 266, + /* 20 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 30 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 40 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 50 */ 266, 266, 266, 266, 266, 266, 258, 257, 238, 266, + /* 60 */ 239, 216, 240, 261, 266, 266, 266, 243, 231, 266, + /* 70 */ 266, 247, 254, 253, 244, 252, 248, 251, 249, 266, + /* 80 */ 266, 266, 266, 250, 245, 255, 217, 264, 199, 241, + /* 90 */ 262, 209, 235, 259, 180, 182, 181, 266, 177, 176, + /* 100 */ 266, 266, 266, 266, 196, 266, 266, 266, 266, 266, + /* 110 */ 266, 266, 242, 206, 237, 266, 208, 266, 256, 266, + /* 120 */ 266, 260, 263, 266, 266, 266, 246, 266, 233, 204, + /* 130 */ 213, 207, 203, 202, 214, 201, 210, 200, 212, 211, + /* 140 */ 198, 197, 194, 193, 192, 191, 190, 189, 188, 187, + /* 150 */ 220, 175, 222, 219, 218, 265, 174, 184, 183, 179, + /* 160 */ 186, 232, 178, 173, 234, 223, 229, 230, 224, 225, + /* 170 */ 226, 227, 228, +}; +#define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0])) + +/* The next table maps tokens into fallback tokens. If a construct +** like the following: +** +** %fallback ID X Y Z. +** +** appears in the grammer, then ID becomes a fallback token for X, Y, +** and Z. Whenever one of the tokens X, Y, or Z is input to the parser +** but it does not parse, the type of the token is changed to ID and +** the parse is retried before an error is thrown. +*/ +#ifdef YYFALLBACK +static const YYCODETYPE yyFallback[] = { +}; +#endif /* YYFALLBACK */ + +/* The following structure represents a single element of the +** parser's stack. Information stored includes: +** +** + The state number for the parser at this level of the stack. +** +** + The value of the token stored at this level of the stack. +** (In other words, the "major" token.) +** +** + The semantic value stored at this level of the stack. This is +** the information used by the action routines in the grammar. +** It is sometimes called the "minor" token. +*/ +struct yyStackEntry { + int stateno; /* The state-number */ + int major; /* The major token value. This is the code + ** number for the token at this stack level */ + YYMINORTYPE minor; /* The user-supplied minor token value. This + ** is the value of the token */ +}; +typedef struct yyStackEntry yyStackEntry; + +/* The state of the parser is completely contained in an instance of +** the following structure */ +struct yyParser { + int yyidx; /* Index of top element in stack */ + int yyerrcnt; /* Shifts left before out of the error */ + ParseARG_SDECL /* A place to hold %extra_argument */ +#if YYSTACKDEPTH<=0 + int yystksz; /* Current side of the stack */ + yyStackEntry *yystack; /* The parser's stack */ +#else + yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ +#endif +}; +typedef struct yyParser yyParser; + +#ifndef NDEBUG +#include +static FILE *yyTraceFILE = 0; +static char *yyTracePrompt = 0; +#endif /* NDEBUG */ + +#ifndef NDEBUG +/* +** Turn parser tracing on by giving a stream to which to write the trace +** and a prompt to preface each trace message. Tracing is turned off +** by making either argument NULL +** +** Inputs: +**
    +**
  • A FILE* to which trace output should be written. +** If NULL, then tracing is turned off. +**
  • A prefix string written at the beginning of every +** line of trace output. If NULL, then tracing is +** turned off. +**
+** +** Outputs: +** None. +*/ +void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ + yyTraceFILE = TraceFILE; + yyTracePrompt = zTracePrompt; + if( yyTraceFILE==0 ) yyTracePrompt = 0; + else if( yyTracePrompt==0 ) yyTraceFILE = 0; +} +#endif /* NDEBUG */ + +#ifndef NDEBUG +/* For tracing shifts, the names of all terminals and nonterminals +** are required. The following table supplies these names */ +static const char *const yyTokenName[] = { + "$", "OR", "XOR", "AND", + "MINUS", "PLUS", "MULTIPLY", "DIVIDE", + "NEG", "NUM", "SYMNUM", "LPAREN", + "RPAREN", "PRINT", "COMMA", "STRING", + "ENDL", "DEFINE", "SYM", "INCLUDE", + "RBRACE", "ENUM", "LBRACE", "EQUALS", + "SPECIAL", "SEMICOLON", "COLON", "LBRACKET", + "RBRACKET", "FLAGS", "ARG2", "ARG3", + "ARG4", "ARG5", "OR_EQUAL", "TAG", + "LINEID", "error", "exp", "special_args", + "list_val", "arg_list", "boom_args", "boom_op", + "boom_selector", "boom_line", "boom_body", "maybe_argcount", + "main", "translation_unit", "external_declaration", "define_statement", + "include_statement", "print_statement", "enum_statement", "linetype_declaration", + "boom_declaration", "special_declaration", "print_list", "print_item", + "enum_open", "enum_list", "single_enum", "special_list", + "special_def", +}; +#endif /* NDEBUG */ + +#ifndef NDEBUG +/* For tracing reduce actions, the names of all rules are required. +*/ +static const char *const yyRuleName[] = { + /* 0 */ "main ::= translation_unit", + /* 1 */ "exp ::= NUM", + /* 2 */ "exp ::= SYMNUM", + /* 3 */ "exp ::= exp PLUS exp", + /* 4 */ "exp ::= exp MINUS exp", + /* 5 */ "exp ::= exp MULTIPLY exp", + /* 6 */ "exp ::= exp DIVIDE exp", + /* 7 */ "exp ::= exp OR exp", + /* 8 */ "exp ::= exp AND exp", + /* 9 */ "exp ::= exp XOR exp", + /* 10 */ "exp ::= MINUS exp", + /* 11 */ "exp ::= LPAREN exp RPAREN", + /* 12 */ "translation_unit ::=", + /* 13 */ "translation_unit ::= external_declaration", + /* 14 */ "external_declaration ::= define_statement", + /* 15 */ "external_declaration ::= include_statement", + /* 16 */ "external_declaration ::= print_statement", + /* 17 */ "external_declaration ::= enum_statement", + /* 18 */ "external_declaration ::= linetype_declaration", + /* 19 */ "external_declaration ::= boom_declaration", + /* 20 */ "external_declaration ::= special_declaration", + /* 21 */ "print_statement ::= PRINT LPAREN print_list RPAREN", + /* 22 */ "print_list ::=", + /* 23 */ "print_list ::= print_item", + /* 24 */ "print_list ::= print_item COMMA print_list", + /* 25 */ "print_item ::= STRING", + /* 26 */ "print_item ::= exp", + /* 27 */ "print_item ::= ENDL", + /* 28 */ "define_statement ::= DEFINE SYM LPAREN exp RPAREN", + /* 29 */ "include_statement ::= INCLUDE STRING", + /* 30 */ "enum_statement ::= enum_open enum_list RBRACE", + /* 31 */ "enum_open ::= ENUM LBRACE", + /* 32 */ "enum_list ::=", + /* 33 */ "enum_list ::= single_enum", + /* 34 */ "enum_list ::= single_enum COMMA enum_list", + /* 35 */ "single_enum ::= SYM", + /* 36 */ "single_enum ::= SYM EQUALS exp", + /* 37 */ "special_declaration ::= SPECIAL special_list SEMICOLON", + /* 38 */ "special_list ::= special_def", + /* 39 */ "special_list ::= special_list COMMA special_def", + /* 40 */ "special_def ::= exp COLON SYM LPAREN maybe_argcount RPAREN", + /* 41 */ "special_def ::= exp COLON SYMNUM LPAREN maybe_argcount RPAREN", + /* 42 */ "maybe_argcount ::=", + /* 43 */ "maybe_argcount ::= exp", + /* 44 */ "maybe_argcount ::= exp COMMA exp", + /* 45 */ "linetype_declaration ::= exp EQUALS exp COMMA exp LPAREN special_args RPAREN", + /* 46 */ "linetype_declaration ::= exp EQUALS exp COMMA SYM LPAREN special_args RPAREN", + /* 47 */ "boom_declaration ::= LBRACKET exp RBRACKET LPAREN exp COMMA exp RPAREN LBRACE boom_body RBRACE", + /* 48 */ "boom_body ::=", + /* 49 */ "boom_body ::= boom_line boom_body", + /* 50 */ "boom_line ::= boom_selector boom_op boom_args", + /* 51 */ "boom_selector ::= FLAGS", + /* 52 */ "boom_selector ::= ARG2", + /* 53 */ "boom_selector ::= ARG3", + /* 54 */ "boom_selector ::= ARG4", + /* 55 */ "boom_selector ::= ARG5", + /* 56 */ "boom_op ::= EQUALS", + /* 57 */ "boom_op ::= OR_EQUAL", + /* 58 */ "boom_args ::= exp", + /* 59 */ "boom_args ::= exp LBRACKET arg_list RBRACKET", + /* 60 */ "arg_list ::= list_val", + /* 61 */ "arg_list ::= list_val COMMA arg_list", + /* 62 */ "list_val ::= exp COLON exp", + /* 63 */ "special_args ::=", + /* 64 */ "special_args ::= TAG", + /* 65 */ "special_args ::= TAG COMMA exp", + /* 66 */ "special_args ::= TAG COMMA exp COMMA exp", + /* 67 */ "special_args ::= TAG COMMA exp COMMA exp COMMA exp", + /* 68 */ "special_args ::= TAG COMMA exp COMMA exp COMMA exp COMMA exp", + /* 69 */ "special_args ::= TAG COMMA TAG", + /* 70 */ "special_args ::= TAG COMMA TAG COMMA exp", + /* 71 */ "special_args ::= TAG COMMA TAG COMMA exp COMMA exp", + /* 72 */ "special_args ::= TAG COMMA TAG COMMA exp COMMA exp COMMA exp", + /* 73 */ "special_args ::= LINEID", + /* 74 */ "special_args ::= LINEID COMMA exp", + /* 75 */ "special_args ::= LINEID COMMA exp COMMA exp", + /* 76 */ "special_args ::= LINEID COMMA exp COMMA exp COMMA exp", + /* 77 */ "special_args ::= LINEID COMMA exp COMMA exp COMMA exp COMMA exp", + /* 78 */ "special_args ::= exp", + /* 79 */ "special_args ::= exp COMMA exp", + /* 80 */ "special_args ::= exp COMMA exp COMMA exp", + /* 81 */ "special_args ::= exp COMMA exp COMMA exp COMMA exp", + /* 82 */ "special_args ::= exp COMMA exp COMMA exp COMMA exp COMMA exp", + /* 83 */ "special_args ::= exp COMMA TAG", + /* 84 */ "special_args ::= exp COMMA TAG COMMA exp", + /* 85 */ "special_args ::= exp COMMA TAG COMMA exp COMMA exp", + /* 86 */ "special_args ::= exp COMMA TAG COMMA exp COMMA exp COMMA exp", + /* 87 */ "special_args ::= exp COMMA exp COMMA TAG", + /* 88 */ "special_args ::= exp COMMA exp COMMA TAG COMMA exp", + /* 89 */ "special_args ::= exp COMMA exp COMMA TAG COMMA exp COMMA exp", + /* 90 */ "special_args ::= exp COMMA exp COMMA exp COMMA TAG", + /* 91 */ "special_args ::= exp COMMA exp COMMA exp COMMA TAG COMMA exp", + /* 92 */ "special_args ::= exp COMMA exp COMMA exp COMMA exp COMMA TAG", +}; +#endif /* NDEBUG */ + +#if YYSTACKDEPTH<=0 +/* +** Try to increase the size of the parser stack. +*/ +static void yyGrowStack(yyParser *p){ + int newSize; + yyStackEntry *pNew; + + newSize = p->yystksz*2 + 100; + pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); + if( pNew ){ + p->yystack = pNew; + p->yystksz = newSize; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sStack grows to %d entries!\n", + yyTracePrompt, p->yystksz); + } +#endif + } +} +#endif + +/* +** This function allocates a new parser. +** The only argument is a pointer to a function which works like +** malloc. +** +** Inputs: +** A pointer to the function used to allocate memory. +** +** Outputs: +** A pointer to a parser. This pointer is used in subsequent calls +** to Parse and ParseFree. +*/ +void *ParseAlloc(void *(*mallocProc)(size_t)){ + yyParser *pParser; + pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); + if( pParser ){ + pParser->yyidx = -1; +#if YYSTACKDEPTH<=0 + yyGrowStack(pParser); +#endif + } + return pParser; +} + +/* The following function deletes the value associated with a +** symbol. The symbol can be either a terminal or nonterminal. +** "yymajor" is the symbol code, and "yypminor" is a pointer to +** the value. +*/ +static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ + switch( yymajor ){ + /* Here is inserted the actions which take place when a + ** terminal or non-terminal is destroyed. This can happen + ** when the symbol is popped from the stack during a + ** reduce or during error processing or when a parser is + ** being destroyed before it is finished parsing. + ** + ** Note: during a reduce, the only symbols destroyed are those + ** which appear on the RHS of the rule, but which are not used + ** inside the C code. + */ + default: break; /* If no destructor action specified: do nothing */ + } +} + +/* +** Pop the parser's stack once. +** +** If there is a destructor routine associated with the token which +** is popped from the stack, then call it. +** +** Return the major token number for the symbol popped. +*/ +static int yy_pop_parser_stack(yyParser *pParser){ + YYCODETYPE yymajor; + yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; + + if( pParser->yyidx<0 ) return 0; +#ifndef NDEBUG + if( yyTraceFILE && pParser->yyidx>=0 ){ + fprintf(yyTraceFILE,"%sPopping %s\n", + yyTracePrompt, + yyTokenName[yytos->major]); + } +#endif + yymajor = yytos->major; + yy_destructor( yymajor, &yytos->minor); + pParser->yyidx--; + return yymajor; +} + +/* +** Deallocate and destroy a parser. Destructors are all called for +** all stack elements before shutting the parser down. +** +** Inputs: +**
    +**
  • A pointer to the parser. This should be a pointer +** obtained from ParseAlloc. +**
  • A pointer to a function used to reclaim memory obtained +** from malloc. +**
+*/ +void ParseFree( + void *p, /* The parser to be deleted */ + void (*freeProc)(void*) /* Function used to reclaim memory */ +){ + yyParser *pParser = (yyParser*)p; + if( pParser==0 ) return; + while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); +#if YYSTACKDEPTH<=0 + free(pParser->yystack); +#endif + (*freeProc)((void*)pParser); +} + +/* +** Find the appropriate action for a parser given the terminal +** look-ahead token iLookAhead. +** +** If the look-ahead token is YYNOCODE, then check to see if the action is +** independent of the look-ahead. If it is, return the action, otherwise +** return YY_NO_ACTION. +*/ +static int yy_find_shift_action( + yyParser *pParser, /* The parser */ + YYCODETYPE iLookAhead /* The look-ahead token */ +){ + int i; + int stateno = pParser->yystack[pParser->yyidx].stateno; + + if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){ + return yy_default[stateno]; + } + if( iLookAhead==YYNOCODE ){ + return YY_NO_ACTION; + } + i += iLookAhead; + if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ + if( iLookAhead>0 ){ +#ifdef YYFALLBACK + int iFallback; /* Fallback token */ + if( iLookAhead %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); + } +#endif + return yy_find_shift_action(pParser, iFallback); + } +#endif +#ifdef YYWILDCARD + { + int j = i - iLookAhead + YYWILDCARD; + if( j>=0 && j %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]); + } +#endif /* NDEBUG */ + return yy_action[j]; + } + } +#endif /* YYWILDCARD */ + } + return yy_default[stateno]; + }else{ + return yy_action[i]; + } +} + +/* +** Find the appropriate action for a parser given the non-terminal +** look-ahead token iLookAhead. +** +** If the look-ahead token is YYNOCODE, then check to see if the action is +** independent of the look-ahead. If it is, return the action, otherwise +** return YY_NO_ACTION. +*/ +static int yy_find_reduce_action( + int stateno, /* Current state number */ + YYCODETYPE iLookAhead /* The look-ahead token */ +){ + int i; + assert( stateno<=YY_REDUCE_MAX ); + i = yy_reduce_ofst[stateno]; + assert( i!=YY_REDUCE_USE_DFLT ); + assert( iLookAhead!=YYNOCODE ); + i += iLookAhead; + assert( i>=0 && iyyidx--; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); + } +#endif + while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + /* Here code is inserted which will execute if the parser + ** stack every overflows */ + ParseARG_STORE; /* Suppress warning about unused %extra_argument var */ +} + +/* +** Perform a shift action. +*/ +static void yy_shift( + yyParser *yypParser, /* The parser to be shifted */ + int yyNewState, /* The new state to shift in */ + int yyMajor, /* The major token to shift in */ + YYMINORTYPE *yypMinor /* Pointer ot the minor token to shift in */ +){ + yyStackEntry *yytos; + yypParser->yyidx++; +#if YYSTACKDEPTH>0 + if( yypParser->yyidx>=YYSTACKDEPTH ){ + yyStackOverflow(yypParser, yypMinor); + return; + } +#else + if( yypParser->yyidx>=yypParser->yystksz ){ + yyGrowStack(yypParser); + if( yypParser->yyidx>=yypParser->yystksz ){ + yyStackOverflow(yypParser, yypMinor); + return; + } + } +#endif + yytos = &yypParser->yystack[yypParser->yyidx]; + yytos->stateno = yyNewState; + yytos->major = yyMajor; + yytos->minor = *yypMinor; +#ifndef NDEBUG + if( yyTraceFILE && yypParser->yyidx>0 ){ + int i; + fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState); + fprintf(yyTraceFILE,"%sStack:",yyTracePrompt); + for(i=1; i<=yypParser->yyidx; i++) + fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); + fprintf(yyTraceFILE,"\n"); + } +#endif +} + +/* The following table contains information about every rule that +** is used during the reduce. +*/ +static const struct { + YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ + unsigned char nrhs; /* Number of right-hand side symbols in the rule */ +} yyRuleInfo[] = { + { 48, 1 }, + { 38, 1 }, + { 38, 1 }, + { 38, 3 }, + { 38, 3 }, + { 38, 3 }, + { 38, 3 }, + { 38, 3 }, + { 38, 3 }, + { 38, 3 }, + { 38, 2 }, + { 38, 3 }, + { 49, 0 }, + { 49, 1 }, + { 50, 1 }, + { 50, 1 }, + { 50, 1 }, + { 50, 1 }, + { 50, 1 }, + { 50, 1 }, + { 50, 1 }, + { 53, 4 }, + { 58, 0 }, + { 58, 1 }, + { 58, 3 }, + { 59, 1 }, + { 59, 1 }, + { 59, 1 }, + { 51, 5 }, + { 52, 2 }, + { 54, 3 }, + { 60, 2 }, + { 61, 0 }, + { 61, 1 }, + { 61, 3 }, + { 62, 1 }, + { 62, 3 }, + { 57, 3 }, + { 63, 1 }, + { 63, 3 }, + { 64, 6 }, + { 64, 6 }, + { 47, 0 }, + { 47, 1 }, + { 47, 3 }, + { 55, 8 }, + { 55, 8 }, + { 56, 11 }, + { 46, 0 }, + { 46, 2 }, + { 45, 3 }, + { 44, 1 }, + { 44, 1 }, + { 44, 1 }, + { 44, 1 }, + { 44, 1 }, + { 43, 1 }, + { 43, 1 }, + { 42, 1 }, + { 42, 4 }, + { 41, 1 }, + { 41, 3 }, + { 40, 3 }, + { 39, 0 }, + { 39, 1 }, + { 39, 3 }, + { 39, 5 }, + { 39, 7 }, + { 39, 9 }, + { 39, 3 }, + { 39, 5 }, + { 39, 7 }, + { 39, 9 }, + { 39, 1 }, + { 39, 3 }, + { 39, 5 }, + { 39, 7 }, + { 39, 9 }, + { 39, 1 }, + { 39, 3 }, + { 39, 5 }, + { 39, 7 }, + { 39, 9 }, + { 39, 3 }, + { 39, 5 }, + { 39, 7 }, + { 39, 9 }, + { 39, 5 }, + { 39, 7 }, + { 39, 9 }, + { 39, 7 }, + { 39, 9 }, + { 39, 9 }, +}; + +static void yy_accept(yyParser*); /* Forward Declaration */ + +/* +** Perform a reduce action and the shift that must immediately +** follow the reduce. +*/ +static void yy_reduce( + yyParser *yypParser, /* The parser */ + int yyruleno /* Number of the rule by which to reduce */ +){ + int yygoto; /* The next state */ + int yyact; /* The next action */ + YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ + yyStackEntry *yymsp; /* The top of the parser's stack */ + int yysize; /* Amount to pop the stack */ + ParseARG_FETCH; + yymsp = &yypParser->yystack[yypParser->yyidx]; +#ifndef NDEBUG + if( yyTraceFILE && yyruleno>=0 + && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ + fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt, + yyRuleName[yyruleno]); + } +#endif /* NDEBUG */ + + /* Silence complaints from purify about yygotominor being uninitialized + ** in some cases when it is copied into the stack after the following + ** switch. yygotominor is uninitialized when a rule reduces that does + ** not set the value of its left-hand side nonterminal. Leaving the + ** value of the nonterminal uninitialized is utterly harmless as long + ** as the value is never used. So really the only thing this code + ** accomplishes is to quieten purify. + ** + ** 2007-01-16: The wireshark project (www.wireshark.org) reports that + ** without this code, their parser segfaults. I'm not sure what there + ** parser is doing to make this happen. This is the second bug report + ** from wireshark this week. Clearly they are stressing Lemon in ways + ** that it has not been previously stressed... (SQLite ticket #2172) + */ + memset(&yygotominor, 0, sizeof(yygotominor)); + + + switch( yyruleno ){ + /* Beginning here are the reduction cases. A typical example + ** follows: + ** case 0: + ** #line + ** { ... } // User supplied code + ** #line + ** break; + */ + case 1: +#line 344 "xlat-parse.y" +{ yygotominor.yy72 = yymsp[0].minor.yy0.val; } +#line 1227 "xlat-parse.c" + break; + case 2: +#line 345 "xlat-parse.y" +{ yygotominor.yy72 = yymsp[0].minor.yy0.symval->Value; } +#line 1232 "xlat-parse.c" + break; + case 3: +#line 346 "xlat-parse.y" +{ yygotominor.yy72 = yymsp[-2].minor.yy72 + yymsp[0].minor.yy72; } +#line 1237 "xlat-parse.c" + break; + case 4: +#line 347 "xlat-parse.y" +{ yygotominor.yy72 = yymsp[-2].minor.yy72 - yymsp[0].minor.yy72; } +#line 1242 "xlat-parse.c" + break; + case 5: +#line 348 "xlat-parse.y" +{ yygotominor.yy72 = yymsp[-2].minor.yy72 * yymsp[0].minor.yy72; } +#line 1247 "xlat-parse.c" + break; + case 6: +#line 349 "xlat-parse.y" +{ yygotominor.yy72 = yymsp[-2].minor.yy72 / yymsp[0].minor.yy72; } +#line 1252 "xlat-parse.c" + break; + case 7: +#line 350 "xlat-parse.y" +{ yygotominor.yy72 = yymsp[-2].minor.yy72 | yymsp[0].minor.yy72; } +#line 1257 "xlat-parse.c" + break; + case 8: +#line 351 "xlat-parse.y" +{ yygotominor.yy72 = yymsp[-2].minor.yy72 & yymsp[0].minor.yy72; } +#line 1262 "xlat-parse.c" + break; + case 9: +#line 352 "xlat-parse.y" +{ yygotominor.yy72 = yymsp[-2].minor.yy72 ^ yymsp[0].minor.yy72; } +#line 1267 "xlat-parse.c" + break; + case 10: +#line 353 "xlat-parse.y" +{ yygotominor.yy72 = -yymsp[0].minor.yy72; } +#line 1272 "xlat-parse.c" + break; + case 11: +#line 354 "xlat-parse.y" +{ yygotominor.yy72 = yymsp[-1].minor.yy72; } +#line 1277 "xlat-parse.c" + break; + case 21: +#line 368 "xlat-parse.y" +{ + printf ("\n"); +} +#line 1284 "xlat-parse.c" + break; + case 25: +#line 376 "xlat-parse.y" +{ printf ("%s", yymsp[0].minor.yy0.string); } +#line 1289 "xlat-parse.c" + break; + case 26: +#line 377 "xlat-parse.y" +{ printf ("%d", yymsp[0].minor.yy72); } +#line 1294 "xlat-parse.c" + break; + case 27: +#line 378 "xlat-parse.y" +{ printf ("\n"); } +#line 1299 "xlat-parse.c" + break; + case 28: +#line 381 "xlat-parse.y" +{ + AddSym (yymsp[-3].minor.yy0.sym, yymsp[-1].minor.yy72); +} +#line 1306 "xlat-parse.c" + break; + case 29: +#line 386 "xlat-parse.y" +{ + IncludeFile (yymsp[0].minor.yy0.string); +} +#line 1313 "xlat-parse.c" + break; + case 31: +#line 393 "xlat-parse.y" +{ + EnumVal = 0; +} +#line 1320 "xlat-parse.c" + break; + case 35: +#line 402 "xlat-parse.y" +{ + AddSym (yymsp[0].minor.yy0.sym, EnumVal++); +} +#line 1327 "xlat-parse.c" + break; + case 36: +#line 407 "xlat-parse.y" +{ + AddSym (yymsp[-2].minor.yy0.sym, EnumVal = yymsp[0].minor.yy72); +} +#line 1334 "xlat-parse.c" + break; + case 40: +#line 420 "xlat-parse.y" +{ + AddSym (yymsp[-3].minor.yy0.sym, yymsp[-5].minor.yy72); +} +#line 1341 "xlat-parse.c" + break; + case 41: +#line 424 "xlat-parse.y" +{ + printf ("%s, line %d: %s is already defined\n", SourceName, SourceLine, yymsp[-3].minor.yy0.symval->Sym); +} +#line 1348 "xlat-parse.c" + break; + case 45: +#line 433 "xlat-parse.y" +{ + Simple[yymsp[-7].minor.yy72].NewSpecial = yymsp[-3].minor.yy72; + Simple[yymsp[-7].minor.yy72].Flags = yymsp[-5].minor.yy72 | yymsp[-1].minor.yy57.addflags; + Simple[yymsp[-7].minor.yy72].Args[0] = yymsp[-1].minor.yy57.args[0]; + Simple[yymsp[-7].minor.yy72].Args[1] = yymsp[-1].minor.yy57.args[1]; + Simple[yymsp[-7].minor.yy72].Args[2] = yymsp[-1].minor.yy57.args[2]; + Simple[yymsp[-7].minor.yy72].Args[3] = yymsp[-1].minor.yy57.args[3]; + Simple[yymsp[-7].minor.yy72].Args[4] = yymsp[-1].minor.yy57.args[4]; +} +#line 1361 "xlat-parse.c" + break; + case 46: +#line 443 "xlat-parse.y" +{ + printf ("%s, line %d: %s is undefined\n", SourceName, SourceLine, yymsp[-3].minor.yy0.sym); +} +#line 1368 "xlat-parse.c" + break; + case 47: +#line 448 "xlat-parse.y" +{ + if (NumBoomish == MAX_BOOMISH) + { + MoreLines *probe = yymsp[-1].minor.yy49; + + while (probe != NULL) + { + MoreLines *next = probe->next; + free (probe); + probe = next; + } + printf ("%s, line %d: Too many BOOM translators\n", SourceName, SourceLine); + } + else + { + int i; + MoreLines *probe; + + Boomish[NumBoomish].FirstLinetype = yymsp[-6].minor.yy72; + Boomish[NumBoomish].LastLinetype = yymsp[-4].minor.yy72; + Boomish[NumBoomish].NewSpecial = yymsp[-9].minor.yy72; + + for (i = 0, probe = yymsp[-1].minor.yy49; probe != NULL; i++) + { + MoreLines *next = probe->next;; + if (i < MAX_BOOMISH_EXEC) + { + Boomish[NumBoomish].Args[i] = probe->arg; + } + else if (i == MAX_BOOMISH_EXEC) + { + printf ("%s, line %d: Too many commands for this BOOM translator\n", SourceName, SourceLine); + } + free (probe); + probe = next; + } + if (i < MAX_BOOMISH_EXEC) + { + Boomish[NumBoomish].Args[i].bDefined = 0; + } + NumBoomish++; + } +} +#line 1415 "xlat-parse.c" + break; + case 48: +#line 493 "xlat-parse.y" +{ + yygotominor.yy49 = NULL; +} +#line 1422 "xlat-parse.c" + break; + case 49: +#line 497 "xlat-parse.y" +{ + yygotominor.yy49 = malloc (sizeof(MoreLines)); + yygotominor.yy49->next = yymsp[0].minor.yy49; + yygotominor.yy49->arg = yymsp[-1].minor.yy58; +} +#line 1431 "xlat-parse.c" + break; + case 50: +#line 504 "xlat-parse.y" +{ + yygotominor.yy58.bDefined = 1; + yygotominor.yy58.bOrExisting = (yymsp[-1].minor.yy72 == OR_EQUAL); + yygotominor.yy58.bUseConstant = (yymsp[0].minor.yy83.filters == NULL); + yygotominor.yy58.ArgNum = yymsp[-2].minor.yy72; + yygotominor.yy58.ConstantValue = yymsp[0].minor.yy83.constant; + yygotominor.yy58.AndValue = yymsp[0].minor.yy83.mask; + + if (yymsp[0].minor.yy83.filters != NULL) + { + int i; + MoreFilters *probe; + + for (i = 0, probe = yymsp[0].minor.yy83.filters; probe != NULL; i++) + { + MoreFilters *next = probe->next; + if (i < 15) + { + yygotominor.yy58.ResultFilter[i] = probe->filter.filter; + yygotominor.yy58.ResultValue[i] = probe->filter.value; + } + else if (i == 15) + { + yyerror ("Lists can only have 15 elements"); + } + free (probe); + probe = next; + } + yygotominor.yy58.ListSize = i > 15 ? 15 : i; + } +} +#line 1466 "xlat-parse.c" + break; + case 51: +#line 536 "xlat-parse.y" +{ yygotominor.yy72 = 4; } +#line 1471 "xlat-parse.c" + break; + case 52: +#line 537 "xlat-parse.y" +{ yygotominor.yy72 = 0; } +#line 1476 "xlat-parse.c" + break; + case 53: +#line 538 "xlat-parse.y" +{ yygotominor.yy72 = 1; } +#line 1481 "xlat-parse.c" + break; + case 54: +#line 539 "xlat-parse.y" +{ yygotominor.yy72 = 2; } +#line 1486 "xlat-parse.c" + break; + case 55: +#line 540 "xlat-parse.y" +{ yygotominor.yy72 = 3; } +#line 1491 "xlat-parse.c" + break; + case 56: +#line 542 "xlat-parse.y" +{ yygotominor.yy72 = '='; } +#line 1496 "xlat-parse.c" + break; + case 57: +#line 543 "xlat-parse.y" +{ yygotominor.yy72 = OR_EQUAL; } +#line 1501 "xlat-parse.c" + break; + case 58: +#line 546 "xlat-parse.y" +{ + yygotominor.yy83.constant = yymsp[0].minor.yy72; + yygotominor.yy83.filters = NULL; +} +#line 1509 "xlat-parse.c" + break; + case 59: +#line 551 "xlat-parse.y" +{ + yygotominor.yy83.mask = yymsp[-3].minor.yy72; + yygotominor.yy83.filters = yymsp[-1].minor.yy87; +} +#line 1517 "xlat-parse.c" + break; + case 60: +#line 557 "xlat-parse.y" +{ + yygotominor.yy87 = malloc (sizeof(MoreFilters)); + yygotominor.yy87->next = NULL; + yygotominor.yy87->filter = yymsp[0].minor.yy124; +} +#line 1526 "xlat-parse.c" + break; + case 61: +#line 563 "xlat-parse.y" +{ + yygotominor.yy87 = malloc (sizeof(MoreFilters)); + yygotominor.yy87->next = yymsp[0].minor.yy87; + yygotominor.yy87->filter = yymsp[-2].minor.yy124; +} +#line 1535 "xlat-parse.c" + break; + case 62: +#line 570 "xlat-parse.y" +{ + yygotominor.yy124.filter = yymsp[-2].minor.yy72; + yygotominor.yy124.value = yymsp[0].minor.yy72; +} +#line 1543 "xlat-parse.c" + break; + case 63: +#line 576 "xlat-parse.y" +{ + yygotominor.yy57.addflags = 0; + memset (yygotominor.yy57.args, 0, 5); +} +#line 1551 "xlat-parse.c" + break; + case 64: +#line 581 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT1; + memset (yygotominor.yy57.args, 0, 5); +} +#line 1559 "xlat-parse.c" + break; + case 65: +#line 586 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT1; + yygotominor.yy57.args[0] = 0; + yygotominor.yy57.args[1] = yymsp[0].minor.yy72; + yygotominor.yy57.args[2] = 0; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1571 "xlat-parse.c" + break; + case 66: +#line 595 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT1; + yygotominor.yy57.args[0] = 0; + yygotominor.yy57.args[1] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[2] = yymsp[0].minor.yy72; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1583 "xlat-parse.c" + break; + case 67: +#line 604 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT1; + yygotominor.yy57.args[0] = 0; + yygotominor.yy57.args[1] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[2] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[3] = yymsp[0].minor.yy72; + yygotominor.yy57.args[4] = 0; +} +#line 1595 "xlat-parse.c" + break; + case 68: +#line 613 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT1; + yygotominor.yy57.args[0] = 0; + yygotominor.yy57.args[1] = yymsp[-6].minor.yy72; + yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[4] = yymsp[0].minor.yy72; +} +#line 1607 "xlat-parse.c" + break; + case 69: +#line 622 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HAS2TAGS; + yygotominor.yy57.args[0] = yygotominor.yy57.args[1] = 0; + yygotominor.yy57.args[2] = 0; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1618 "xlat-parse.c" + break; + case 70: +#line 630 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HAS2TAGS; + yygotominor.yy57.args[0] = yygotominor.yy57.args[1] = 0; + yygotominor.yy57.args[2] = yymsp[0].minor.yy72; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1629 "xlat-parse.c" + break; + case 71: +#line 638 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HAS2TAGS; + yygotominor.yy57.args[0] = yygotominor.yy57.args[1] = 0; + yygotominor.yy57.args[2] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[3] = yymsp[0].minor.yy72; + yygotominor.yy57.args[4] = 0; +} +#line 1640 "xlat-parse.c" + break; + case 72: +#line 646 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HAS2TAGS; + yygotominor.yy57.args[0] = yygotominor.yy57.args[1] = 0; + yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[4] = yymsp[0].minor.yy72; +} +#line 1651 "xlat-parse.c" + break; + case 73: +#line 654 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASLINEID; + memset (yygotominor.yy57.args, 0, 5); +} +#line 1659 "xlat-parse.c" + break; + case 74: +#line 659 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASLINEID; + yygotominor.yy57.args[0] = 0; + yygotominor.yy57.args[1] = yymsp[0].minor.yy72; + yygotominor.yy57.args[2] = 0; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1671 "xlat-parse.c" + break; + case 75: +#line 668 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASLINEID; + yygotominor.yy57.args[0] = 0; + yygotominor.yy57.args[1] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[2] = yymsp[0].minor.yy72; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1683 "xlat-parse.c" + break; + case 76: +#line 677 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASLINEID; + yygotominor.yy57.args[0] = 0; + yygotominor.yy57.args[1] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[2] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[3] = yymsp[0].minor.yy72; + yygotominor.yy57.args[4] = 0; +} +#line 1695 "xlat-parse.c" + break; + case 77: +#line 686 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASLINEID; + yygotominor.yy57.args[0] = 0; + yygotominor.yy57.args[1] = yymsp[-6].minor.yy72; + yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[4] = yymsp[0].minor.yy72; +} +#line 1707 "xlat-parse.c" + break; + case 78: +#line 695 "xlat-parse.y" +{ + yygotominor.yy57.addflags = 0; + yygotominor.yy57.args[0] = yymsp[0].minor.yy72; + yygotominor.yy57.args[1] = 0; + yygotominor.yy57.args[2] = 0; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1719 "xlat-parse.c" + break; + case 79: +#line 704 "xlat-parse.y" +{ + yygotominor.yy57.addflags = 0; + yygotominor.yy57.args[0] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[1] = yymsp[0].minor.yy72; + yygotominor.yy57.args[2] = 0; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1731 "xlat-parse.c" + break; + case 80: +#line 713 "xlat-parse.y" +{ + yygotominor.yy57.addflags = 0; + yygotominor.yy57.args[0] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[1] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[2] = yymsp[0].minor.yy72; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1743 "xlat-parse.c" + break; + case 81: +#line 722 "xlat-parse.y" +{ + yygotominor.yy57.addflags = 0; + yygotominor.yy57.args[0] = yymsp[-6].minor.yy72; + yygotominor.yy57.args[1] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[2] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[3] = yymsp[0].minor.yy72; + yygotominor.yy57.args[4] = 0; +} +#line 1755 "xlat-parse.c" + break; + case 82: +#line 731 "xlat-parse.y" +{ + yygotominor.yy57.addflags = 0; + yygotominor.yy57.args[0] = yymsp[-8].minor.yy72; + yygotominor.yy57.args[1] = yymsp[-6].minor.yy72; + yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[4] = yymsp[0].minor.yy72; +} +#line 1767 "xlat-parse.c" + break; + case 83: +#line 740 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT2; + yygotominor.yy57.args[0] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[1] = 0; + yygotominor.yy57.args[2] = 0; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1779 "xlat-parse.c" + break; + case 84: +#line 749 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT2; + yygotominor.yy57.args[0] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[1] = 0; + yygotominor.yy57.args[2] = yymsp[0].minor.yy72; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1791 "xlat-parse.c" + break; + case 85: +#line 758 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT2; + yygotominor.yy57.args[0] = yymsp[-6].minor.yy72; + yygotominor.yy57.args[1] = 0; + yygotominor.yy57.args[2] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[3] = yymsp[0].minor.yy72; + yygotominor.yy57.args[4] = 0; +} +#line 1803 "xlat-parse.c" + break; + case 86: +#line 767 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT2; + yygotominor.yy57.args[0] = yymsp[-8].minor.yy72; + yygotominor.yy57.args[1] = 0; + yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[4] = yymsp[0].minor.yy72; +} +#line 1815 "xlat-parse.c" + break; + case 87: +#line 776 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT3; + yygotominor.yy57.args[0] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[1] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[2] = 0; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1827 "xlat-parse.c" + break; + case 88: +#line 785 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT3; + yygotominor.yy57.args[0] = yymsp[-6].minor.yy72; + yygotominor.yy57.args[1] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[2] = 0; + yygotominor.yy57.args[3] = yymsp[0].minor.yy72; + yygotominor.yy57.args[4] = 0; +} +#line 1839 "xlat-parse.c" + break; + case 89: +#line 794 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT3; + yygotominor.yy57.args[0] = yymsp[-8].minor.yy72; + yygotominor.yy57.args[1] = yymsp[-6].minor.yy72; + yygotominor.yy57.args[2] = 0; + yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[4] = yymsp[0].minor.yy72; +} +#line 1851 "xlat-parse.c" + break; + case 90: +#line 803 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT4; + yygotominor.yy57.args[0] = yymsp[-6].minor.yy72; + yygotominor.yy57.args[1] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[2] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = 0; +} +#line 1863 "xlat-parse.c" + break; + case 91: +#line 812 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT4; + yygotominor.yy57.args[0] = yymsp[-8].minor.yy72; + yygotominor.yy57.args[1] = yymsp[-6].minor.yy72; + yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[3] = 0; + yygotominor.yy57.args[4] = yymsp[0].minor.yy72; +} +#line 1875 "xlat-parse.c" + break; + case 92: +#line 821 "xlat-parse.y" +{ + yygotominor.yy57.addflags = SIMPLE_HASTAGAT5; + yygotominor.yy57.args[0] = yymsp[-8].minor.yy72; + yygotominor.yy57.args[1] = yymsp[-6].minor.yy72; + yygotominor.yy57.args[2] = yymsp[-4].minor.yy72; + yygotominor.yy57.args[3] = yymsp[-2].minor.yy72; + yygotominor.yy57.args[4] = 0; +} +#line 1887 "xlat-parse.c" + break; + }; + yygoto = yyRuleInfo[yyruleno].lhs; + yysize = yyRuleInfo[yyruleno].nrhs; + yypParser->yyidx -= yysize; + yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto); + if( yyact < YYNSTATE ){ +#ifdef NDEBUG + /* If we are not debugging and the reduce action popped at least + ** one element off the stack, then we can push the new element back + ** onto the stack here, and skip the stack overflow test in yy_shift(). + ** That gives a significant speed improvement. */ + if( yysize ){ + yypParser->yyidx++; + yymsp -= yysize-1; + yymsp->stateno = yyact; + yymsp->major = yygoto; + yymsp->minor = yygotominor; + }else +#endif + { + yy_shift(yypParser,yyact,yygoto,&yygotominor); + } + }else{ + assert( yyact == YYNSTATE + YYNRULE + 1 ); + yy_accept(yypParser); + } +} + +/* +** The following code executes when the parse fails +*/ +static void yy_parse_failed( + yyParser *yypParser /* The parser */ +){ + ParseARG_FETCH; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); + } +#endif + while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + /* Here code is inserted which will be executed whenever the + ** parser fails */ + ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} + +/* +** The following code executes when a syntax error first occurs. +*/ +static void yy_syntax_error( + yyParser *yypParser, /* The parser */ + int yymajor, /* The major type of the error token */ + YYMINORTYPE yyminor /* The minor type of the error token */ +){ + ParseARG_FETCH; +#define TOKEN (yyminor.yy0) +#line 322 "xlat-parse.y" +yyerror("syntax error"); +#line 1947 "xlat-parse.c" + ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} + +/* +** The following is executed when the parser accepts +*/ +static void yy_accept( + yyParser *yypParser /* The parser */ +){ + ParseARG_FETCH; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); + } +#endif + while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + /* Here code is inserted which will be executed whenever the + ** parser accepts */ + ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} + +/* The main parser program. +** The first argument is a pointer to a structure obtained from +** "ParseAlloc" which describes the current state of the parser. +** The second argument is the major token number. The third is +** the minor token. The fourth optional argument is whatever the +** user wants (and specified in the grammar) and is available for +** use by the action routines. +** +** Inputs: +**
    +**
  • A pointer to the parser (an opaque structure.) +**
  • The major token number. +**
  • The minor token number. +**
  • An option argument of a grammar-specified type. +**
+** +** Outputs: +** None. +*/ +void Parse( + void *yyp, /* The parser */ + int yymajor, /* The major token code number */ + ParseTOKENTYPE yyminor /* The value for the token */ + ParseARG_PDECL /* Optional %extra_argument parameter */ +){ + YYMINORTYPE yyminorunion; + int yyact; /* The parser action. */ + int yyendofinput; /* True if we are at the end of input */ +#ifdef YYERRORSYMBOL + int yyerrorhit = 0; /* True if yymajor has invoked an error */ +#endif + yyParser *yypParser; /* The parser */ + + /* (re)initialize the parser, if necessary */ + yypParser = (yyParser*)yyp; + if( yypParser->yyidx<0 ){ +#if YYSTACKDEPTH<=0 + if( yypParser->yystksz <=0 ){ + memset(&yyminorunion, 0, sizeof(yyminorunion)); + yyStackOverflow(yypParser, &yyminorunion); + return; + } +#endif + yypParser->yyidx = 0; + yypParser->yyerrcnt = -1; + yypParser->yystack[0].stateno = 0; + yypParser->yystack[0].major = 0; + } + yyminorunion.yy0 = yyminor; + yyendofinput = (yymajor==0); + ParseARG_STORE; + +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); + } +#endif + + do{ + yyact = yy_find_shift_action(yypParser,yymajor); + if( yyactyyerrcnt--; + yymajor = YYNOCODE; + /* [RH] If we can reduce the stack now, do it. Otherwise, constructs */ + /* like "include " won't work because the next token after */ + /* the include will be shifted before the include is reduced. Then the */ + /* parser will act as if that token had been the first one in the */ + /* included file. */ + while( yypParser->yyidx>= 0 && (yyact = yy_find_shift_action(yypParser,YYNOCODE)) < YYNSTATE + YYNRULE ){ + yy_reduce(yypParser,yyact-YYNSTATE); + } + }else if( yyact < YYNSTATE + YYNRULE ){ + yy_reduce(yypParser,yyact-YYNSTATE); + }else{ +#ifdef YYERRORSYMBOL + int yymx; +#endif + assert( yyact == YY_ERROR_ACTION ); +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); + } +#endif +#ifdef YYERRORSYMBOL + /* A syntax error has occurred. + ** The response to an error depends upon whether or not the + ** grammar defines an error token "ERROR". + ** + ** This is what we do if the grammar does define ERROR: + ** + ** * Call the %syntax_error function. + ** + ** * Begin popping the stack until we enter a state where + ** it is legal to shift the error symbol, then shift + ** the error symbol. + ** + ** * Set the error count to three. + ** + ** * Begin accepting and shifting new tokens. No new error + ** processing will occur until three tokens have been + ** shifted successfully. + ** + */ + if( yypParser->yyerrcnt<0 ){ + yy_syntax_error(yypParser,yymajor,yyminorunion); + } + yymx = yypParser->yystack[yypParser->yyidx].major; + if( yymx==YYERRORSYMBOL || yyerrorhit ){ +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sDiscard input token %s\n", + yyTracePrompt,yyTokenName[yymajor]); + } +#endif + yy_destructor(yymajor,&yyminorunion); + yymajor = YYNOCODE; + }else{ + while( + yypParser->yyidx >= 0 && + yymx != YYERRORSYMBOL && + (yyact = yy_find_reduce_action( + yypParser->yystack[yypParser->yyidx].stateno, + YYERRORSYMBOL)) >= YYNSTATE + ){ + yy_pop_parser_stack(yypParser); + } + if( yypParser->yyidx < 0 || yymajor==0 ){ + yy_destructor(yymajor,&yyminorunion); + yy_parse_failed(yypParser); + yymajor = YYNOCODE; + }else if( yymx!=YYERRORSYMBOL ){ + YYMINORTYPE u2; + u2.YYERRSYMDT = 0; + yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); + } + } + yypParser->yyerrcnt = 3; + yyerrorhit = 1; +#else /* YYERRORSYMBOL is not defined */ + /* This is what we do if the grammar does not define ERROR: + ** + ** * Report an error message, and throw away the input token. + ** + ** * If the input token is $, then fail the parse. + ** + ** As before, subsequent error messages are suppressed until + ** three input tokens have been successfully shifted. + */ + if( yypParser->yyerrcnt<=0 ){ + yy_syntax_error(yypParser,yymajor,yyminorunion); + } + yypParser->yyerrcnt = 3; + yy_destructor(yymajor,&yyminorunion); + if( yyendofinput ){ + yy_parse_failed(yypParser); + } + yymajor = YYNOCODE; +#endif + } + }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); + return; +} diff --git a/tools/xlatcc/xlat-parse.y b/tools/xlatcc/xlat-parse.y index 1f94dae10c..203f3ee78c 100644 --- a/tools/xlatcc/xlat-parse.y +++ b/tools/xlatcc/xlat-parse.y @@ -341,17 +341,17 @@ int yyerror (char *s) main ::= translation_unit. -exp(A) ::= NUM(B). { A = B.val; } -exp(A) ::= SYMNUM(B). { A = B.symval->Value; } -exp(A) ::= exp(B) PLUS exp(C). { A = B + C; } -exp(A) ::= exp(B) MINUS exp(C). { A = B - C; } -exp(A) ::= exp(B) MULTIPLY exp(C). { A = B * C; } -exp(A) ::= exp(B) DIVIDE exp(C). { A = B / C; } -exp(A) ::= exp(B) OR exp(C). { A = B | C; } -exp(A) ::= exp(B) AND exp(C). { A = B & C; } -exp(A) ::= exp(B) XOR exp(C). { A = B ^ C; } -exp(A) ::= MINUS exp(B). [NEG] { A = -B; } -exp(A) ::= LPAREN exp(B) RPAREN. { A = B; } +exp(A) ::= NUM(B). { A = B.val; } +exp(A) ::= SYMNUM(B). { A = B.symval->Value; } +exp(A) ::= exp(B) PLUS exp(C). { A = B + C; } +exp(A) ::= exp(B) MINUS exp(C). { A = B - C; } +exp(A) ::= exp(B) MULTIPLY exp(C). { A = B * C; } +exp(A) ::= exp(B) DIVIDE exp(C). { A = B / C; } +exp(A) ::= exp(B) OR exp(C). { A = B | C; } +exp(A) ::= exp(B) AND exp(C). { A = B & C; } +exp(A) ::= exp(B) XOR exp(C). { A = B ^ C; } +exp(A) ::= MINUS exp(B). [NEG] { A = -B; } +exp(A) ::= LPAREN exp(B) RPAREN. { A = B; } translation_unit ::= . /* empty */ translation_unit ::= external_declaration. @@ -369,13 +369,13 @@ print_statement ::= PRINT LPAREN print_list RPAREN. printf ("\n"); } -print_list ::= . /* EMPTY */ -print_list ::= print_item. -print_list ::= print_item COMMA print_list. +print_list ::= . /* EMPTY */ +print_list ::= print_item. +print_list ::= print_item COMMA print_list. -print_item ::= STRING(A). { printf ("%s", A.string); } -print_item ::= exp(A). { printf ("%d", A); } -print_item ::= ENDL. { printf ("\n"); } +print_item ::= STRING(A). { printf ("%s", A.string); } +print_item ::= exp(A). { printf ("%d", A); } +print_item ::= ENDL. { printf ("\n"); } define_statement ::= DEFINE SYM(A) LPAREN exp(B) RPAREN. { diff --git a/wadsrc/dehsupp.lmp b/wadsrc/dehsupp.lmp index 97bf44534e..905bbaa43a 100644 Binary files a/wadsrc/dehsupp.lmp and b/wadsrc/dehsupp.lmp differ diff --git a/wadsrc/doomx.lmp b/wadsrc/doomx.lmp index 96447d78ca..551954c41c 100644 Binary files a/wadsrc/doomx.lmp and b/wadsrc/doomx.lmp differ diff --git a/zdoom.sln b/zdoom.sln index 7705de3083..5b5ba175f7 100644 --- a/zdoom.sln +++ b/zdoom.sln @@ -2,13 +2,12 @@ Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zdoom", "zdoom.vcproj", "{8049475B-5C87-46F9-9358-635218A4EF18}" ProjectSection(ProjectDependencies) = postProject - {AC3F5340-40CB-4C3A-8AA7-CB7158DB4466} = {AC3F5340-40CB-4C3A-8AA7-CB7158DB4466} - {DA47396F-60C1-4BDE-A977-7F7DE461CF77} = {DA47396F-60C1-4BDE-A977-7F7DE461CF77} - {873F2EEA-24DF-454C-B245-CB9738BA993E} = {873F2EEA-24DF-454C-B245-CB9738BA993E} - {667D2EE7-C357-49E2-9BAB-0A4A45F0F76E} = {667D2EE7-C357-49E2-9BAB-0A4A45F0F76E} - {6077B7D6-349F-4077-B552-3BC302EF5859} = {6077B7D6-349F-4077-B552-3BC302EF5859} {F9D9E7D4-E1A2-4866-9E85-B1B14137EE63} = {F9D9E7D4-E1A2-4866-9E85-B1B14137EE63} - {1D179D4B-F008-431B-8C72-111F8372584F} = {1D179D4B-F008-431B-8C72-111F8372584F} + {6077B7D6-349F-4077-B552-3BC302EF5859} = {6077B7D6-349F-4077-B552-3BC302EF5859} + {667D2EE7-C357-49E2-9BAB-0A4A45F0F76E} = {667D2EE7-C357-49E2-9BAB-0A4A45F0F76E} + {873F2EEA-24DF-454C-B245-CB9738BA993E} = {873F2EEA-24DF-454C-B245-CB9738BA993E} + {DA47396F-60C1-4BDE-A977-7F7DE461CF77} = {DA47396F-60C1-4BDE-A977-7F7DE461CF77} + {AC3F5340-40CB-4C3A-8AA7-CB7158DB4466} = {AC3F5340-40CB-4C3A-8AA7-CB7158DB4466} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "zlib\zlib.vcproj", "{F9D9E7D4-E1A2-4866-9E85-B1B14137EE63}" @@ -21,9 +20,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "re2c", "tools\re2c\re2c.vcp EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wadsrc", "wadsrc\wadsrc.vcproj", "{1D179D4B-F008-431B-8C72-111F8372584F}" ProjectSection(ProjectDependencies) = postProject - {3FFA68B3-9449-4B03-ADEE-194C3638623B} = {3FFA68B3-9449-4B03-ADEE-194C3638623B} - {AC64EE8F-F019-4A3E-BCAF-BD1FD072B9C8} = {AC64EE8F-F019-4A3E-BCAF-BD1FD072B9C8} {24A19C02-F041-4AB0-A1A1-02E1E88EDBD3} = {24A19C02-F041-4AB0-A1A1-02E1E88EDBD3} + {AC64EE8F-F019-4A3E-BCAF-BD1FD072B9C8} = {AC64EE8F-F019-4A3E-BCAF-BD1FD072B9C8} + {3FFA68B3-9449-4B03-ADEE-194C3638623B} = {3FFA68B3-9449-4B03-ADEE-194C3638623B} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "makewad", "tools\makewad\makewad.vcproj", "{24A19C02-F041-4AB0-A1A1-02E1E88EDBD3}" @@ -35,8 +34,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xlatcc", "tools\xlatcc\xlat EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dehsupp", "tools\dehsupp\dehsupp.vcproj", "{AC64EE8F-F019-4A3E-BCAF-BD1FD072B9C8}" ProjectSection(ProjectDependencies) = postProject - {667D2EE7-C357-49E2-9BAB-0A4A45F0F76E} = {667D2EE7-C357-49E2-9BAB-0A4A45F0F76E} {0F80ACBF-460E-44F0-B28E-B3272D1774A7} = {0F80ACBF-460E-44F0-B28E-B3272D1774A7} + {667D2EE7-C357-49E2-9BAB-0A4A45F0F76E} = {667D2EE7-C357-49E2-9BAB-0A4A45F0F76E} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "updaterevision", "tools\updaterevision\updaterevision.vcproj", "{6077B7D6-349F-4077-B552-3BC302EF5859}" diff --git a/zdoom.vcproj b/zdoom.vcproj index a4cf0d5aa5..6bb55164e6 100644 --- a/zdoom.vcproj +++ b/zdoom.vcproj @@ -8978,6 +8978,10 @@ + +