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