diff options
author | Norbert Preining <norbert@preining.info> | 2020-08-07 03:02:55 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-08-07 03:02:55 +0000 |
commit | 3710c23789342d9d88783cbe9ad23eb5263a7c33 (patch) | |
tree | 1c40b2bfb9f6b652f7877ad0991f5d6b44391154 /graphics/asymptote/fileio.cc | |
parent | d99fea72e367e8d4d2809b43b3b0206b1bb526b8 (diff) |
CTAN sync 202008070302
Diffstat (limited to 'graphics/asymptote/fileio.cc')
-rw-r--r-- | graphics/asymptote/fileio.cc | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/graphics/asymptote/fileio.cc b/graphics/asymptote/fileio.cc index d738438820..524e653e12 100644 --- a/graphics/asymptote/fileio.cc +++ b/graphics/asymptote/fileio.cc @@ -18,6 +18,41 @@ string newline="\n"; ofile Stdout(""); file nullfile("",false,NOMODE,false,true); +void ifile::open() +{ + if(standard) { + if(mode & std::ios::binary) + reportError("Cannot open standard input in binary mode"); + stream=&cin; + } else { + if(mode & std::ios::out) + name=outpath(name); + else { +#ifdef HAVE_LIBCURL + if(parser::isURL(name)) { + parser::readURL(buf,name); + stream=&buf; + } else +#endif + { + name=locatefile(inpath(name)); + stream=fstream=new std::fstream(name.c_str(),mode); + } + } + + if(mode & std::ios::out) { + if(error()) { + delete fstream; + std::ofstream f(name.c_str()); + f.close(); + stream=fstream=new std::fstream(name.c_str(),mode); + } + } + index=processData().ifile.add(fstream); + if(check) Check(); + } +} + void ifile::ignoreComment() { if(comment == 0) return; @@ -38,7 +73,7 @@ void ifile::ignoreComment() } else {if(c != EOF && eol) stream->unget(); return;} } } - + bool ifile::eol() { int c; @@ -51,7 +86,7 @@ bool ifile::eol() } return false; } - + bool ifile::nexteol() { int c; @@ -59,7 +94,7 @@ bool ifile::nexteol() nullfield=false; return true; } - + while(isspace(c=stream->peek())) { if(c == '\n' && comma) { nullfield=true; @@ -80,7 +115,7 @@ bool ifile::nexteol() } return false; } - + void ifile::csv() { comma=false; @@ -96,7 +131,7 @@ void ifile::csv() } else stream->clear(rdstate); if(c == ',') comma=true; } - + void ifile::Read(string& val) { string s; @@ -132,7 +167,7 @@ void ifile::Read(string& val) } } else getline(*stream,s); - + if(comment) { size_t p=0; while((p=s.find(comment,p)) < string::npos) { @@ -140,7 +175,7 @@ void ifile::Read(string& val) s.erase(p,1); ++p; } else { - s.erase(p); + s.erase(p); break; } } @@ -152,8 +187,8 @@ void ifile::Read(string& val) } val=whitespace+s; } - -void ofile::writeline() + +void ofile::writeline() { if(standard && interact::query && !vm::indebugger) { Int scroll=settings::getScroll(); @@ -176,5 +211,5 @@ void ofile::writeline() } else *stream << newline; if(errorstream::interrupt) {interact::lines=0; throw interrupted();} } - + } // namespace camp |