DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
parse_cmdl.cpp
Go to the documentation of this file.
1#include <cstdlib>
2#include <cstring>
3
4#include <iostream>
5#include <string>
6#include <list>
7
8
9static void
11{
12 std::cout <<
13 "usage: oksdalgen [-d | --c++-dir-name directory-name]\n"
14 " [-n | --c++-namespace namespace\n"
15 " [-i | --c++-headers-dir directory-prefix]\n"
16 " [-I | --include-dirs dirs*]\n"
17 " [-c | --classes class*]\n"
18 " [-D | --user-defined-classes [namespace::]user-class[@dir-prefix]*]\n"
19 " [-f | --info-file-name file-name]\n"
20 " [-v | --verbose]\n"
21 " [-h | --help]\n"
22 " -s | --schema-files file.schema.xml+\n"
23 "\n"
24 "Options/Arguments:\n"
25 " -d directory-name name of directory for c++ header and implementation files\n"
26 " -n namespace namespace for c++ classes\n"
27 " -i directory-prefix name of directory prefix for c++ header files\n"
28 " -I dirs* directories where to search for already generated files\n"
29 " -c class* explicit list of classes to be generated\n"
30 " -D [x::]c[@d]* user-defined classes\n"
31 " -f filename name of output file describing generated files\n"
32 " -v switch on verbose output\n"
33 " -h this message\n"
34 " -s files+ the schema files (at least one is mandatory)\n"
35 "\n"
36 "Description:\n"
37 " The utility generates c++ code for OKS schema files.\n\n";
38}
39
40static void
41no_param(const char * s)
42{
43 std::cerr << "ERROR: the required argument for option \'" << s << "\' is missing\n\n";
44 exit(EXIT_FAILURE);
45}
46
47void
48parse_arguments(int argc, char *argv[],
49 std::list<std::string>& class_names,
50 std::list<std::string>& file_names,
51 std::list<std::string>& include_dirs,
52 std::list<std::string>& user_classes,
53 std::string& cpp_dir_name,
54 std::string& cpp_ns_name,
55 std::string& cpp_hdr_dir,
56 std::string& info_file_name,
57 bool& verbose
58 )
59{
60
61 for (int i = 1; i < argc; i++)
62 {
63 const char * cp = argv[i];
64
65 if (!strcmp(cp, "-h") || !strcmp(cp, "--help"))
66 {
67 usage();
68 exit(EXIT_SUCCESS);
69 }
70 else if (!strcmp(cp, "-v") || !strcmp(cp, "--verbose"))
71 {
72 verbose = true;
73 }
74 else if (!strcmp(cp, "-d") || !strcmp(cp, "--c++-dir-name"))
75 {
76 if (++i == argc || argv[i][0] == '-')
77 no_param(cp);
78 else
79 cpp_dir_name = argv[i];
80 }
81 else if (!strcmp(cp, "-n") || !strcmp(cp, "--c++-namespace"))
82 {
83 if (++i == argc || argv[i][0] == '-')
84 no_param(cp);
85 else
86 cpp_ns_name = argv[i];
87 }
88 else if (!strcmp(cp, "-i") || !strcmp(cp, "--c++-headers-dir"))
89 {
90 if (++i == argc || argv[i][0] == '-')
91 no_param(cp);
92 else
93 cpp_hdr_dir = argv[i];
94 }
95 else if (!strcmp(cp, "-f") || !strcmp(cp, "--info-file-name"))
96 {
97 if (++i == argc || argv[i][0] == '-')
98 no_param(cp);
99 else
100 info_file_name = argv[i];
101 }
102 else
103 {
104 std::list<std::string> * slist = (
105 (!strcmp(cp, "-c") || !strcmp(cp, "--classes")) ? &class_names :
106 (!strcmp(cp, "-s") || !strcmp(cp, "--schema-files")) ? &file_names :
107 (!strcmp(cp, "-I") || !strcmp(cp, "--include-dirs")) ? &include_dirs :
108 (!strcmp(cp, "-D") || !strcmp(cp, "--user-defined-classes")) ? &user_classes :
109 nullptr
110 );
111
112 if (slist)
113 {
114 int j = 0;
115 for (; j < argc - i - 1; ++j)
116 {
117 if (argv[i + 1 + j][0] != '-')
118 slist->push_back(argv[i + 1 + j]);
119 else
120 break;
121 }
122 i += j;
123 }
124 else
125 {
126 std::cerr << "ERROR: Unexpected parameter: \"" << cp << "\"\n\n";
127 usage();
128 exit(EXIT_FAILURE);
129 }
130 }
131 }
132
133 if (file_names.size() == 0)
134 {
135 std::cerr << "At least one schema file is required\n";
136 exit(EXIT_FAILURE);
137 }
138
139 if (verbose)
140 {
141 std::cout <<
142 "VERBOSE:\n"
143 " Command line parameters:\n"
144 " c++ directory name: \"" << cpp_dir_name << "\"\n"
145 " c++ namespace name: \"" << cpp_ns_name << "\"\n"
146 " c++ headers directory: \"" << cpp_hdr_dir << "\"\n"
147 " classes:";
148
149 if (!class_names.empty())
150 {
151 std::cout << std::endl;
152
153 for (const auto& i : class_names)
154 std::cout << " - " << i << std::endl;
155 }
156 else
157 {
158 std::cout << " no\n";
159 }
160
161 std::cout << " file names:";
162
163 if (!file_names.empty())
164 {
165 std::cout << std::endl;
166
167 for (const auto& i : file_names)
168 std::cout << " * " << i << std::endl;
169 }
170 else
171 {
172 std::cout << " no\n";
173 }
174
175 std::cout << " include directories for search:";
176
177 if (!include_dirs.empty())
178 {
179 std::cout << std::endl;
180
181 for (const auto& i : include_dirs)
182 std::cout << " * " << i << std::endl;
183 }
184 else
185 {
186 std::cout << " no\n";
187 }
188
189 std::cout << " user-defined classes:";
190
191 if (!user_classes.empty())
192 {
193 std::cout << std::endl;
194
195 for (const auto& i : user_classes)
196 std::cout << " * " << i << std::endl;
197 }
198 else
199 {
200 std::cout << " no\n";
201 }
202 }
203}
static void usage()
static void no_param(const char *s)
void parse_arguments(int argc, char *argv[], std::list< std::string > &class_names, std::list< std::string > &file_names, std::list< std::string > &include_dirs, std::list< std::string > &user_classes, std::string &cpp_dir_name, std::string &cpp_ns_name, std::string &cpp_hdr_dir, std::string &info_file_name, bool &verbose)