fixed missing tinyxml2 header path dependency for Win32
[mfgtools.git] / uuu / buildincmd.h
blob46286ccb2bdda8493c3a60e8ad026b550aeab20b
1 /*
2 * Copyright 2018-2021 NXP.
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this
11 * list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
14 * Neither the name of the NXP Semiconductor nor the names of its
15 * contributors may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
32 #pragma once
34 #include <stdint.h>
35 #include <map>
36 #include <string>
37 #include <vector>
39 extern const char * g_vt_boldwhite;
40 extern const char * g_vt_default;
41 extern const char * g_vt_kcyn;
42 extern const char * g_vt_green;
43 extern const char * g_vt_red ;
44 extern const char * g_vt_yellow;
46 /**
47 * @brief Structure to hold the raw data of a built-in script
49 struct BuiltInScriptRawData
51 //! The name of the built-in script
52 const char * const m_name = nullptr;
53 //! The actual built-in script itself
54 const char * const m_text = nullptr;
55 //! A description of the built-in script's purpose
56 const char * const m_desc = nullptr;
59 class BuiltInScript
61 public:
62 /**
63 * @brief A class for representing arguments of built-in scripts represented
64 * by BuiltInScript
66 class Arg
68 public:
69 enum
71 ARG_MUST = 0x1,
72 ARG_OPTION = 0x2,
73 ARG_OPTION_KEY = 0x4,
76 void parser(const std::string &option);
78 //! The name of the argument
79 std::string m_name;
80 //! A description of the argument
81 std::string m_desc;
82 //! Flags of the argument (basically if it's optional or not)
83 uint32_t m_flags = ARG_MUST;
84 //! The argument whose value this one will fall back to if it's optional
85 //! and not given explicitly
86 std::string m_fallback_option;
89 BuiltInScript() {};
90 BuiltInScript(const BuiltInScriptRawData*p);
92 std::string replace_script_args(const std::vector<std::string> &args) const;
93 void show() const;
94 void show_cmd() const;
96 //! The actual script which is being represented
97 const std::string m_text;
98 //! A description of the script's purpose
99 const std::string m_desc;
100 //! A short name of the built-in script
101 const std::string m_name;
102 //! The arguments of the built-in script
103 std::vector<Arg> m_args;
105 private:
106 bool find_args(const std::string &arg) const;
110 * @brief A map of all built-in scripts indexed by their names
112 * Each built-in script is represented by a BuiltInScript instance.
114 class BuiltInScriptMap : public std::map<std::string, BuiltInScript>
116 public:
117 BuiltInScriptMap(const BuiltInScriptRawData*p);
119 void PrintAutoComplete(const std::string &match, const char *space = " ") const;
120 void ShowAll() const;
121 void ShowCmds(FILE * file=stdout) const;
124 //! A map of the built-in scripts' names to their BuiltInScript representations
125 extern BuiltInScriptMap g_BuildScripts;