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