diff --git a/NEWS b/NEWS index 846bda49d..55b5eb26d 100644 --- a/NEWS +++ b/NEWS @@ -59,6 +59,10 @@ New in spot 2.1.2.dev (not yet released) when run with use_simulation (the default) on non-simplified automata. + * When the automaton_stream_parser reads an automaton from an + already opened file descriptor, it will not close the file + anymore. + New in spot 2.1.2 (2016-10-14) Command-line tools: diff --git a/spot/parseaut/public.hh b/spot/parseaut/public.hh index 259371cef..17b549b91 100644 --- a/spot/parseaut/public.hh +++ b/spot/parseaut/public.hh @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2013, 2014, 2015 Laboratoire de Recherche et Développement -// de l'Epita (LRDE). +// Copyright (C) 2013, 2014, 2015, 2016 Laboratoire de Recherche et +// Développement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. // @@ -123,7 +123,7 @@ namespace spot std::string filename_; automaton_parser_options opts_; public: - /// \brief Parse from a file opened file descriptor. + /// \brief Parse from a file. /// /// \param filename The file to read from. /// \param opts Parser options. @@ -132,6 +132,8 @@ namespace spot /// \brief Parse from an already opened file descriptor. /// + /// The file descriptor will not be closed. + /// /// \param fd The file descriptor to read from. /// \param filename What to display in error messages. /// \param opts Parser options. diff --git a/spot/parseaut/scanaut.ll b/spot/parseaut/scanaut.ll index 2018b63a2..1b7b58286 100644 --- a/spot/parseaut/scanaut.ll +++ b/spot/parseaut/scanaut.ll @@ -38,6 +38,7 @@ static int orig_cond = 0; static bool lbtt_s = false; static bool lbtt_t = false; static unsigned lbtt_states = 0; +static bool yyin_close = true; %} @@ -410,15 +411,15 @@ namespace spot if (S_ISFIFO(s.st_mode)) want_interactive = true; - // Only set yyin once we know we will use - // it, so that we do not close it otherwise. yyin = stdin; + yyin_close = false; } else { yyin = fopen(name.c_str(), "r"); if (!yyin) return 1; + yyin_close = true; } // Reset the lexer in case a previous parse // ended badly. @@ -441,6 +442,7 @@ namespace spot hoayyopen(int fd) { bool want_interactive = false; + yyin_close = false; yyin = fdopen(fd, "r"); @@ -470,8 +472,9 @@ namespace spot { if (yyin) { - fclose(yyin); - yyin = NULL; + if (yyin_close) + fclose(yyin); + yyin = NULL; } } }