diff options
author | Karl Berry <karl@freefriends.org> | 2019-01-10 18:49:48 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2019-01-10 18:49:48 +0000 |
commit | 8d656f7b22badc7a1e4e48811521048ef3df7101 (patch) | |
tree | 207c9332ac340eef8b84e90d67a0f0c6a734e547 /Build/source/utils/asymptote/parser.cc | |
parent | c75ad7aa4d5821b7c4034c949a5ed2401e589bea (diff) |
asy 2.47 sources
git-svn-id: svn://tug.org/texlive/trunk@49658 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/parser.cc')
-rw-r--r-- | Build/source/utils/asymptote/parser.cc | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/Build/source/utils/asymptote/parser.cc b/Build/source/utils/asymptote/parser.cc index cbeb54fe230..c12a47c50e1 100644 --- a/Build/source/utils/asymptote/parser.cc +++ b/Build/source/utils/asymptote/parser.cc @@ -6,6 +6,8 @@ #include <fstream> #include <sstream> +#include <cstring> +#include <fcntl.h> #include "common.h" @@ -17,26 +19,47 @@ #include "locate.h" #include "errormsg.h" #include "parser.h" +#include "util.h" // The lexical analysis and parsing functions used by parseFile. void setlexer(size_t (*input) (char* bif, size_t max_size), string filename); extern bool yyparse(void); extern int yydebug; extern int yy_flex_debug; -static const int YY_NULL = 0; extern bool lexerEOF(); extern void reportEOF(); +extern bool hangup; + +static int fd; namespace parser { +static FILE *fin=NULL; + namespace yy { // Lexers std::streambuf *sbuf = NULL; size_t stream_input(char *buf, size_t max_size) { - size_t count= sbuf ? sbuf->sgetn(buf,max_size) : 0; - return count ? count : YY_NULL; + return sbuf ? sbuf->sgetn(buf,max_size) : 0; +} + +int fpeek(int fd) +{ + int flags=fcntl(fd,F_GETFL,0); + fcntl(fd,F_SETFL,flags | O_NONBLOCK); + char c=fgetc(fin); + ungetc(c,fin); + fcntl(fd,F_SETFL,flags & ~O_NONBLOCK); + return c; +} + +size_t pipe_input(char *buf, size_t max_size) +{ + if(hangup && fpeek(fd) == EOF) {hangup=false; return 0;} + fgets(buf,max_size-1,fin); + return strlen(buf); } } // namespace yy @@ -88,8 +111,19 @@ absyntax::file *doParse(size_t (*input) (char* bif, size_t max_size), absyntax::file *parseStdin() { debug(false); - yy::sbuf = cin.rdbuf(); - return doParse(yy::stream_input,"-"); + + if(!fin) { + fd=intcast(settings::getSetting<Int>("inpipe")); + if(fd >= 0) + fin=fdopen(fd,"r"); + } + + if(fin) + return doParse(yy::pipe_input,"-"); + else { + yy::sbuf = cin.rdbuf(); + return doParse(yy::stream_input,"-"); + } } absyntax::file *parseFile(const string& filename, |