consoleParser.cpp
Engine/source/console/consoleParser.cpp
Namespaces:
namespace
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25#include "console/consoleParser.h" 26 27#include "core/strings/stringFunctions.h" 28#include "console/console.h" 29 30 31namespace Compiler 32{ 33 34static ConsoleParser *gParserList = NULL; 35static ConsoleParser *gDefaultParser = NULL; 36 37void freeConsoleParserList(void) 38{ 39 while(gParserList) 40 { 41 ConsoleParser * pParser = gParserList; 42 gParserList = pParser->next; 43 delete pParser; 44 } 45 46 gDefaultParser = NULL; 47} 48 49bool addConsoleParser(char *ext, fnGetCurrentFile gcf, fnGetCurrentLine gcl, fnParse p, fnRestart r, fnSetScanBuffer ssb, bool def) 50{ 51 AssertFatal(ext && gcf && gcl && p && r, "AddConsoleParser called with one or more NULL arguments"); 52 53 ConsoleParser * pParser = new ConsoleParser; 54 55 pParser->ext = ext; 56 pParser->getCurrentFile = gcf; 57 pParser->getCurrentLine = gcl; 58 pParser->parse = p; 59 pParser->restart = r; 60 pParser->setScanBuffer = ssb; 61 62 if (def) 63 gDefaultParser = pParser; 64 65 pParser->next = gParserList; 66 gParserList = pParser; 67 68 return true; 69} 70 71ConsoleParser * getParserForFile(const char *filename) 72{ 73 if(filename == NULL) 74 return gDefaultParser; 75 76 char *ptr = dStrrchr((char *)filename, '.'); 77 if(ptr != NULL) 78 { 79 ptr++; 80 81 ConsoleParser *p; 82 for(p = gParserList; p; p = p->next) 83 { 84 if(dStricmp(ptr, p->ext) == 0) 85 return p; 86 } 87 } 88 89 return gDefaultParser; 90} 91 92} // end namespace Con 93