134 for (
const auto &t : types) {
135 if (t.name.compare(name) != 0)
137 for (
const auto &dep : t.depend) {
138 EntryList::const_iterator entry = entries.begin();
139 for (; entry != entries.end(); ++entry) {
140 if (entry->name.compare(dep) == 0)
143 if (entry == entries.end()) {
144 std::cerr <<
"ERROR: '" << directive <<
"' (" << name <<
") depends on '" << dep <<
"'\n";
150 std::cerr <<
"ERROR: Dependencies for cf.data type '" << name <<
"' used in ' " << directive <<
"' not defined\n" ;
171 char *input_filename;
175 const char *type_depend;
184 std::stack<std::string> IFDEFS;
189 input_filename = argv[1];
190 type_depend = argv[2];
195 fp.open(type_depend, std::ifstream::in);
197 std::cerr <<
"Error while opening type dependencies file '" <<
198 type_depend <<
"': " <<
strerror(errno) << std::endl;
204 const char *type = strtok(buff,
WS);
206 if (!type || type[0] ==
'#')
209 while ((dep = strtok(
nullptr,
WS)) !=
nullptr) {
222 fp.open(input_filename, std::ifstream::in);
224 std::cerr <<
"Error while opening input file '" <<
225 input_filename <<
"': " <<
strerror(errno) << std::endl;
231 while (fp.getline(buff,
MAX_LINE), fp.good() && state !=
sEXIT) {
236 if ((t = strchr(buff,
'\n')))
239 if (strncmp(buff,
"IF ", 3) == 0) {
240 if ((ptr = strtok(buff + 3,
WS)) ==
nullptr) {
241 errorMsg(input_filename, linenum,
"Missing IF parameter");
246 }
else if (strcmp(buff,
"ENDIF") == 0) {
247 if (IFDEFS.size() == 0) {
248 errorMsg(input_filename, linenum,
"ENDIF without IF first");
252 }
else if (!IFDEFS.size() ||
isDefined(IFDEFS.top()))
257 if ((strlen(buff) == 0) || (!strncmp(buff,
"#", 1))) {
260 }
else if (!strncmp(buff,
"NAME:", 5)) {
261 char *name, *aliasname;
263 if ((name = strtok(buff + 5,
WS)) ==
nullptr) {
264 errorMsg(input_filename, linenum, buff);
268 auto &newEntry = entries.emplace_back(name);
270 while ((aliasname = strtok(
nullptr,
WS)) !=
nullptr)
271 newEntry.alias.push_front(aliasname);
274 }
else if (!strcmp(buff,
"EOF")) {
276 }
else if (!strcmp(buff,
"COMMENT_START")) {
277 auto &newEntry = entries.emplace_back(
"comment");
278 newEntry.loc =
"none";
281 errorMsg(input_filename, linenum, buff);
288 Entry &curr = entries.back();
290 if ((strlen(buff) == 0) || (!strncmp(buff,
"#", 1))) {
293 }
else if (!strncmp(buff,
"COMMENT:", 8)) {
296 while (isspace((
unsigned char)*ptr))
300 }
else if (!strncmp(buff,
"DEFAULT:", 8)) {
303 while (isspace((
unsigned char)*ptr))
307 }
else if (!strncmp(buff,
"DEFAULT_IF_NONE:", 16)) {
310 while (isspace((
unsigned char)*ptr))
314 }
else if (!strncmp(buff,
"POSTSCRIPTUM:", 13)) {
317 while (isspace((
unsigned char)*ptr))
321 }
else if (!strncmp(buff,
"DEFAULT_DOC:", 12)) {
324 while (isspace((
unsigned char)*ptr))
328 }
else if (!strncmp(buff,
"LOC:", 4)) {
329 if ((ptr = strtok(buff + 4,
WS)) ==
nullptr) {
330 errorMsg(input_filename, linenum, buff);
335 }
else if (!strncmp(buff,
"TYPE:", 5)) {
336 if ((ptr = strtok(buff + 5,
WS)) ==
nullptr) {
337 errorMsg(input_filename, linenum, buff);
342 if (strcmp(ptr + strlen(ptr) - 2,
"[]") == 0) {
344 *(ptr + strlen(ptr) - 2) =
'\0';
349 }
else if (!strncmp(buff,
"IFDEF:", 6)) {
350 if ((ptr = strtok(buff + 6,
WS)) ==
nullptr) {
351 errorMsg(input_filename, linenum, buff);
356 }
else if (!strcmp(buff,
"DOC_START")) {
358 }
else if (!strcmp(buff,
"DOC_NONE")) {
361 errorMsg(input_filename, linenum, buff);
368 if (!strcmp(buff,
"DOC_END") || !strcmp(buff,
"COMMENT_END")) {
370 }
else if (strcmp(buff,
"CONFIG_START") == 0) {
373 entries.back().doc.push_back(buff);
378 if (strcmp(buff,
"CONFIG_END") == 0) {
381 entries.back().cfgLines.push_back(buff);
391 if (state !=
sEXIT) {
392 errorMsg(input_filename, linenum,
"Error: unexpected EOF");
408 std::ofstream fout(output_filename,std::ostream::out);
410 std::cerr <<
"Error while opening output .c file '" <<
411 output_filename <<
"': " <<
strerror(errno) << std::endl;
416 " * Generated automatically from " << input_filename <<
" by " <<
419 " * Abstract: This file contains routines used to configure the\n"
420 " * variables in the squid server.\n"
439 fout.open(conf_filename,std::ostream::out);
441 std::cerr <<
"Error while opening output conf file '" <<
442 output_filename <<
"': " <<
strerror(errno) << std::endl;
450 fout.open(conf_filename_short,std::ostream::out);
452 std::cerr <<
"Error while opening output short conf file '" <<
453 output_filename <<
"': " <<
strerror(errno) << std::endl;
466 fout <<
"static void" << std::endl <<
467 "default_line(const char *s)" << std::endl <<
469 " char *tmp_line = xstrdup(s);" << std::endl <<
470 " int len = strlen(tmp_line);" << std::endl <<
471 " ProcessMacros(tmp_line, len);" << std::endl <<
472 " xstrncpy(config_input_line, tmp_line, sizeof(config_input_line));" << std::endl <<
473 " config_lineno++;" << std::endl <<
474 " parse_line(tmp_line);" << std::endl <<
475 " xfree(tmp_line);" << std::endl <<
476 "}" << std::endl << std::endl;
477 fout <<
"static void" << std::endl <<
478 "default_all(void)" << std::endl <<
480 " cfg_filename = \"Default Configuration\";" << std::endl <<
481 " config_lineno = 0;" << std::endl;
483 for (
const auto &entry :
head) {
484 assert(entry.name.size());
486 if (!entry.name.compare(
"comment"))
489 if (!entry.type.compare(
"obsolete"))
492 if (!entry.loc.size()) {
493 std::cerr <<
"NO LOCATION FOR " << entry.name << std::endl;
498 if (!entry.defaults.preset.size() && entry.defaults.if_none.empty()) {
499 std::cerr <<
"NO DEFAULT FOR " << entry.name << std::endl;
504 if (!entry.defaults.preset.size() || entry.defaults.preset.front().compare(
"none") == 0) {
505 fout <<
" // No default for " << entry.name << std::endl;
507 if (entry.ifdef.size())
508 fout <<
"#if " << entry.ifdef << std::endl;
510 for (
const auto &l : entry.defaults.preset)
511 fout <<
" default_line(\"" << entry.name <<
" " <<
gen_quote_escape(l) <<
"\");" << std::endl;
513 if (entry.ifdef.size())
514 fout <<
"#endif" << std::endl;
518 fout <<
" cfg_filename = nullptr;" << std::endl <<
519 "}" << std::endl << std::endl;
526 fout <<
"static void" << std::endl <<
527 "defaults_if_none(void)" << std::endl <<
529 " cfg_filename = \"Default Configuration (if absent)\";" << std::endl <<
530 " config_lineno = 0;" << std::endl;
532 for (
const auto &entry :
head) {
533 assert(entry.name.size());
535 if (!entry.loc.size())
538 if (entry.defaults.if_none.empty())
541 if (!entry.defaults.preset.empty()) {
542 std::cerr <<
"ERROR: " << entry.name <<
" has preset defaults. DEFAULT_IF_NONE cannot be true." << std::endl;
546 if (entry.ifdef.size())
547 fout <<
"#if " << entry.ifdef << std::endl;
549 fout <<
" if (check_null_" << entry.type <<
"(" << entry.loc <<
")) {" << std::endl;
550 for (
const auto &l : entry.defaults.if_none)
551 fout <<
" default_line(\"" << entry.name <<
" " <<
gen_quote_escape(l) <<
"\");" << std::endl;
552 fout <<
" }" << std::endl;
554 if (entry.ifdef.size())
555 fout <<
"#endif" << std::endl;
558 fout <<
" cfg_filename = nullptr;" << std::endl <<
559 "}" << std::endl << std::endl;
757 for (
const auto &entry :
head) {
763 if (!entry.name.compare(
"comment"))
765 else if (!entry.name.compare(
"obsolete"))
767 else if (verbose_output) {
768 fout <<
"# TAG: " << entry.name;
770 if (entry.comment.size())
771 fout <<
"\t" << entry.comment;
778 if (verbose_output) {
779 fout <<
"# Note: This option is only available if Squid is rebuilt with the" << std::endl <<
787 if (verbose_output && entry.doc.size()) {
788 for (
const auto &line : entry.doc) {
789 fout <<
"#" << line << std::endl;
793 if (entry.defaults.docs.size()) {
795 def = entry.defaults.docs;
797 if (entry.defaults.preset.size() && entry.defaults.preset.front().compare(
"none") != 0) {
799 for (
const auto &l : entry.defaults.preset) {
800 snprintf(buf,
sizeof(buf),
"%s %s", entry.name.c_str(), l.c_str());
803 }
else if (entry.defaults.if_none.size()) {
805 for (
const auto &l : entry.defaults.if_none) {
806 snprintf(buf,
sizeof(buf),
"%s %s", entry.name.c_str(), l.c_str());
813 if (def.empty() && entry.cfgLines.empty() && entry.name.compare(
"comment") != 0)
814 def.push_back(
"none");
816 if (verbose_output && def.size()) {
817 fout <<
"#Default:\n";
819 fout <<
"# " << def.front() << std::endl;
822 if (entry.doc.empty() && entry.cfgLines.empty())
826 if (verbose_output && entry.cfgLines.size())
827 fout <<
"#" << std::endl;
829 if (enabled || verbose_output) {
830 for (
const auto &line : entry.cfgLines) {
831 if (!enabled && line.at(0) !=
'#')
833 fout << line << std::endl;
837 if (verbose_output && entry.doc.size()) {
LineList cfgLines
between CONFIG_START and CONFIG_END
void genParseAlias(const std::string &, std::ostream &) const
void genParse(std::ostream &fout) const
int array_flag
TYPE is a raw array[] declaration.