Reduce visibility where applicable
[mfgtools.git] / uuu / buildincmd.h
blobeeb581e2751d0ced552ed3d9f285b7ff11b2668c
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 <locale>
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 *m_name = nullptr;
53 //! The actual built-in script itself
54 const char *m_text = nullptr;
55 //! A description of the built-in script's purpose
56 const char *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 Arg() { m_flags = ARG_MUST; }
78 int parser(const std::string &option);
80 //! The name of the argument
81 std::string m_name;
82 //! A description of the argument
83 std::string m_desc;
84 //! Flags of the argument (basically if it's optional or not)
85 uint32_t m_flags;
86 //! The argument whose value this one will fall back to if it's optional
87 //! and not given explicitly
88 std::string m_fallback_option;
91 BuiltInScript() {};
92 BuiltInScript(const BuiltInScriptRawData*p);
94 std::string replace_script_args(const std::vector<std::string> &args) const;
95 void show() const;
96 void show_cmd() const;
98 //! The actual script which is being represented
99 std::string m_text;
100 //! A description of the script's purpose
101 std::string m_desc;
102 //! A short name of the built-in script
103 std::string m_name;
104 //! The arguments of the built-in script
105 std::vector<Arg> m_args;
107 private:
108 bool find_args(const std::string &arg) const;
112 * @brief A map of all built-in scripts indexed by their names
114 * Each built-in script is represented by a BuiltInScript instance.
116 class BuiltInScriptMap : public std::map<std::string, BuiltInScript>
118 public:
119 BuiltInScriptMap(const BuiltInScriptRawData*p);
121 void PrintAutoComplete(std::string match, const char *space=" " ) const;
122 void ShowAll() const;
123 void ShowCmds(FILE * file=stdout) const;
126 //! A map of the built-in scripts' names to their BuiltInScript representations
127 extern BuiltInScriptMap g_BuildScripts;