mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
gen-zam: gen-zam extended to read from multiple files on the command-line
This commit is contained in:
parent
aee70af743
commit
4ae4548ceb
1 changed files with 20 additions and 13 deletions
|
@ -1959,30 +1959,37 @@ void TemplateInput::Gripe(const char* msg, const InputLoc& l) const
|
||||||
|
|
||||||
ZAMGen::ZAMGen(int argc, char** argv)
|
ZAMGen::ZAMGen(int argc, char** argv)
|
||||||
{
|
{
|
||||||
auto prog_name = argv[0];
|
auto prog_name = (argv++)[0];
|
||||||
|
|
||||||
if ( argc != 2 )
|
if ( --argc < 1 )
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s <ZAM-templates-file>\n", prog_name);
|
fprintf(stderr, "usage: %s <ZAM-templates-file>\n", prog_name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto file_name = argv[1];
|
while ( argc-- > 0 )
|
||||||
auto f = strcmp(file_name, "-") ? fopen(file_name, "r") : stdin;
|
|
||||||
|
|
||||||
if ( ! f )
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: cannot open \"%s\"\n", prog_name, file_name);
|
auto file_name = (argv++)[0];
|
||||||
exit(1);
|
bool is_stdin = file_name == std::string("-");
|
||||||
|
auto f = is_stdin ? stdin : fopen(file_name, "r");
|
||||||
|
|
||||||
|
if ( ! f )
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: cannot open \"%s\"\n", prog_name, file_name);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ti = make_unique<TemplateInput>(f, prog_name, file_name);
|
||||||
|
|
||||||
|
while ( ParseTemplate() )
|
||||||
|
;
|
||||||
|
|
||||||
|
if ( ! is_stdin )
|
||||||
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
ti = make_unique<TemplateInput>(f, prog_name, file_name);
|
|
||||||
|
|
||||||
InitEmitTargets();
|
InitEmitTargets();
|
||||||
|
|
||||||
while ( ParseTemplate() )
|
|
||||||
;
|
|
||||||
|
|
||||||
for ( auto& t : templates )
|
for ( auto& t : templates )
|
||||||
t->Instantiate();
|
t->Instantiate();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue