diff options
author | Karl Berry <karl@freefriends.org> | 2012-05-31 00:02:26 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-05-31 00:02:26 +0000 |
commit | 19fc9fd9a26973d87fad437ce549ffaba479df54 (patch) | |
tree | f40a9d2592b3cf827970c8bf54a1eebf9cc8f9c0 /Build/source/utils/asymptote/fileio.h | |
parent | 24b3bac312553b2cc61e94fda581aba311967f5c (diff) |
asy 2.16 sources
git-svn-id: svn://tug.org/texlive/trunk@26734 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/fileio.h')
-rw-r--r-- | Build/source/utils/asymptote/fileio.h | 115 |
1 files changed, 105 insertions, 10 deletions
diff --git a/Build/source/utils/asymptote/fileio.h b/Build/source/utils/asymptote/fileio.h index 6cc87c4ca0d..5638047a0c2 100644 --- a/Build/source/utils/asymptote/fileio.h +++ b/Build/source/utils/asymptote/fileio.h @@ -39,12 +39,27 @@ extern string tab; extern string newline; enum Mode {NOMODE,INPUT,OUTPUT,UPDATE,BINPUT,BOUTPUT,BUPDATE,XINPUT,XOUTPUT, - XUPDATE}; + XUPDATE,OPIPE}; -static const string FileModes[]={"none", - "input","output","ouptut(update=false)", - "binput","boutput","boutput(update=false)", - "xinput","xoutput","xoutput(update=false)"}; +static const string FileModes[]= +{"none","input","output","output(update)", + "input(binary)","output(binary)","output(binary,update)", + "input(xdr)","output(xdr)","output(xdr,update)","output(pipe)"}; + +extern FILE *pipeout; + +inline void openpipeout() +{ + int fd=settings::getSetting<Int>("outpipe"); + if(!pipeout) { + if(fd >= 0) pipeout=fdopen(intcast(fd),"w"); + } + if(!pipeout) { + ostringstream buf; + buf << "Cannot open outpipe " << fd; + reportError(buf); + } +} class file : public gc { protected: @@ -113,7 +128,7 @@ public: void Check() { if(error()) { ostringstream buf; - buf << "Cannot open file \"" << name << "\"."; + buf << "Cannot open file \"" << name << "\""; reportError(buf); } } @@ -124,8 +139,8 @@ public: if(closed) { ostringstream buf; buf << "I/O operation attempted on "; - if(name != "") buf << "closed file \'" << name << "\'."; - else buf << "null file."; + if(name != "") buf << "closed file \'" << name << "\'"; + else buf << "null file"; reportError(buf); } return true; @@ -149,7 +164,7 @@ public: void unsupported(const char *rw, const char *type) { ostringstream buf; buf << rw << " of type " << type << " not supported in " << FileMode() - << " mode."; + << " mode"; reportError(buf); } @@ -232,6 +247,86 @@ public: bool SignedInt() {return signedint;} }; +class opipe : public file { +public: + opipe(const string& name) : file(name,false,OPIPE) {} + + void open() { + openpipeout(); + } + + bool text() {return true;} + bool eof() {return pipeout ? feof(pipeout) : true;} + bool error() {return pipeout ? ferror(pipeout) : true;} + void clear() {if(pipeout) clearerr(pipeout);} + void flush() {if(pipeout) fflush(pipeout);} + + void seek(Int pos, bool begin=true) { + if(!standard && pipeout) { + clear(); + fseek(pipeout,pos,begin ? SEEK_SET : SEEK_END); + } + } + + size_t tell() { + return pipeout ? ftell(pipeout) : 0; + } + + void write(const string& val) { + fprintf(pipeout,"%s",val.c_str()); + } + + void write(bool val) { + ostringstream s; + s << val; + write(s.str()); + } + + void write(Int val) { + ostringstream s; + s << val; + write(s.str()); + } + void write(double val) { + ostringstream s; + s << val; + write(s.str()); + } + void write(const pair& val) { + ostringstream s; + s << val; + write(s.str()); + } + void write(const triple& val) { + ostringstream s; + s << val; + write(s.str()); + } + + void write(const pen &val) { + ostringstream s; + s << val; + write(s.str()); + } + + void write(guide *val) { + ostringstream s; + s << *val; + write(s.str()); + } + + void write(const transform& val) { + ostringstream s; + s << val; + write(s.str()); + } + + void writeline() { + fprintf(pipeout,"\n"); + if(errorstream::interrupt) throw interrupted(); + } +}; + class ifile : public file { protected: istream *stream; @@ -443,7 +538,7 @@ public: } } void Read(char& val) {iread(val);} - void Read(string& val) {iread(val);} + void Read(string& val) {char c; iread(c); val=c;} void Read(double& val) { if(singlereal) {float fval; iread(fval); val=fval;} |