1 //****************************************************************************** 2 /// 3 /// @file frontend/processoptions.h 4 /// 5 /// This module contains all defines, typedefs, and prototypes for the 6 /// C++ interface of `processoptions.cpp`. 7 /// 8 /// @copyright 9 /// @parblock 10 /// 11 /// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8. 12 /// Copyright 1991-2018 Persistence of Vision Raytracer Pty. Ltd. 13 /// 14 /// POV-Ray is free software: you can redistribute it and/or modify 15 /// it under the terms of the GNU Affero General Public License as 16 /// published by the Free Software Foundation, either version 3 of the 17 /// License, or (at your option) any later version. 18 /// 19 /// POV-Ray is distributed in the hope that it will be useful, 20 /// but WITHOUT ANY WARRANTY; without even the implied warranty of 21 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 /// GNU Affero General Public License for more details. 23 /// 24 /// You should have received a copy of the GNU Affero General Public License 25 /// along with this program. If not, see <http://www.gnu.org/licenses/>. 26 /// 27 /// ---------------------------------------------------------------------------- 28 /// 29 /// POV-Ray is based on the popular DKB raytracer version 2.12. 30 /// DKBTrace was originally written by David K. Buck. 31 /// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins. 32 /// 33 /// @endparblock 34 /// 35 //****************************************************************************** 36 37 #ifndef PROCESSOPTIONS_H 38 #define PROCESSOPTIONS_H 39 40 // Module config header file must be the first file included within POV-Ray unit header files 41 #include "frontend/configfrontend.h" 42 43 #include "base/textstream.h" 44 45 #include "povms/povmscpp.h" 46 47 namespace pov_frontend 48 { 49 50 using namespace pov_base; 51 52 enum { 53 kINIOptFlag_SuppressWrite = 0x0001, ///< Suppress when writing complete list of options 54 }; 55 56 enum { 57 kCmdOptFlag_Optional = 0x0001, ///< Parameter is optional 58 }; 59 60 class ProcessOptions 61 { 62 public: 63 struct INI_Parser_Table 64 { 65 const char *keyword; 66 POVMSType key; 67 POVMSType type; 68 int flags; 69 }; 70 71 struct Cmd_Parser_Table 72 { 73 const char *command; 74 POVMSType key; 75 POVMSType type; 76 POVMSType is_switch; 77 int flags; 78 }; 79 80 ProcessOptions(INI_Parser_Table *, Cmd_Parser_Table *); 81 ~ProcessOptions(); 82 83 int ParseFile(const char *, POVMSObjectPtr); 84 int ParseString(const char *, POVMSObjectPtr, bool singleswitch = false); 85 86 int WriteFile(const char *, POVMSObjectPtr); 87 int WriteFile(OTextStream *, POVMSObjectPtr); 88 89 static bool Matches(const char *, const char *); 90 static bool IsTrue(const char *); 91 static bool IsFalse(const char *); 92 93 /// @todo This should be in the POVMS module. 94 /// @note The attribute will be encoded as UCS2 with a trailing NUL byte. 95 static int POVMSAttr_GetUTF8String(POVMSAttributePtr attr, POVMSType type, UTF8String& s); 96 /// @todo This should be in the POVMS module. 97 /// @note The attribute must be encoded as UCS2 with a trailing NUL byte. 98 static int POVMSAttr_SetUTF8String(POVMSAttributePtr, POVMSType, const char *); 99 /// @todo This should be in the POVMS module. 100 /// @note The attribute will be encoded as UCS2 with a trailing NUL byte. 101 static int POVMSUtil_SetUTF8String(POVMSObjectPtr, POVMSType, const char *); 102 103 static size_t ConvertUTF16ToUTF8(const UTF16 *source, UTF8String& dest); 104 static size_t ConvertUCS2ToUTF8(const UCS2 *source, UTF8String& dest); 105 protected: 106 virtual int ReadSpecialOptionHandler(INI_Parser_Table *, char *, POVMSObjectPtr); 107 virtual int ReadSpecialSwitchHandler(Cmd_Parser_Table *, char *, POVMSObjectPtr, bool); 108 virtual int WriteSpecialOptionHandler(INI_Parser_Table *, POVMSObjectPtr, OTextStream *); 109 virtual bool ProcessUnknownSwitch(char *, char *, POVMSObjectPtr); 110 virtual int ProcessUnknownString(char *, POVMSObjectPtr); 111 112 virtual ITextStream *OpenFileForRead(const char *, POVMSObjectPtr) = 0; 113 virtual OTextStream *OpenFileForWrite(const char *, POVMSObjectPtr) = 0; 114 115 virtual void ParseError(const char *, ...); 116 virtual void ParseErrorAt(ITextStream *, const char *, ...); 117 virtual void WriteError(const char *, ...); 118 private: 119 INI_Parser_Table *parse_ini_table; 120 Cmd_Parser_Table *parse_cmd_table; 121 122 int Output_INI_Option(INI_Parser_Table *, POVMSObjectPtr, OTextStream *); 123 124 int Parse_INI_Specification(const char *, char *&, char *&); 125 int Parse_INI_Skip_Space(ITextStream *, bool); 126 int Parse_INI_Skip_Line(ITextStream *); 127 int Parse_INI_Option(ITextStream *, POVMSObjectPtr); 128 int Parse_INI_Switch(ITextStream *, int, POVMSObjectPtr); 129 char *Parse_INI_String(ITextStream *, int endchr = -1, bool smartmode = false); 130 bool Parse_INI_String_Smartmode(ITextStream *); 131 char *Parse_Raw_INI_String(ITextStream *file); 132 133 int Parse_CL(char *, POVMSObjectPtr, bool); 134 void Parse_CL_Skip_Space(const char *&); 135 int Parse_CL_Switch(const char *&, int , POVMSObjectPtr, bool); 136 int Parse_CL_Option(const char *&, POVMSObjectPtr, bool); 137 char *Parse_CL_String(const char *&, int endchr = -1); 138 139 int Process_INI_Option(INI_Parser_Table *, char *, POVMSObjectPtr); 140 int Process_Switch(Cmd_Parser_Table *, char *, POVMSObjectPtr, bool); 141 }; 142 143 } 144 145 #endif 146