consoleParser.cpp 2.6 KB

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