Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Interface of CTextFile.
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //------------------------------------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #ifndef TEXTFILE_H
  14. #define TEXTFILE_H
  15. #ifdef WIN32
  16. #pragma once
  17. #endif
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <string>
  21. #define BUF_SIZE 5000
  22. //------------------------------------------------------------------------------------------------------
  23. // Purpose: CTextFile represents a configuration file. The default delimiters
  24. // are { } = \n \r \t ; " and space. Also C++ style comments are ignored by default.
  25. // CTextFile only supports reading, a 5000 character word /line buffer
  26. // and only supports one pushback
  27. //------------------------------------------------------------------------------------------------------
  28. class CTextFile
  29. {
  30. private:
  31. std::string filename;
  32. char wordBuf[BUF_SIZE];
  33. char peekBuf[BUF_SIZE];
  34. bool fWordPushed;
  35. bool noComments;
  36. FILE* theFile;
  37. char* delims;
  38. char* stringDelims;
  39. char* normalDelims;
  40. char* blockDelims;
  41. char getNextNonWSChar();
  42. bool isDelim(char c);
  43. const char* getToken(char* outputBuf);
  44. public:
  45. explicit CTextFile(const char* filename,bool eliminateComments=true){init(filename,eliminateComments);}
  46. explicit CTextFile(const string& filename,bool eliminateComments=true){init(filename.c_str(),eliminateComments);}
  47. void init(const char* filename,bool eliminateComments=true);
  48. std::string& fileName(){return filename;}
  49. void discardBlock();
  50. const char* readString();
  51. const char* readString(char* buf);
  52. int readInt();
  53. unsigned long readULong();
  54. const char* getToken();
  55. const char* getLine();
  56. bool isValid(){return theFile!=NULL;}
  57. char* currWord(){return wordBuf;}
  58. void pushBack(const char* pushTok);
  59. char* peekNext();
  60. char* peekNextString();
  61. bool eof();
  62. void reset();
  63. bool discard(char* test);
  64. void discard(){getToken();}
  65. ~CTextFile();
  66. };
  67. #endif // TEXTFILE_H