Skip to content
Snippets Groups Projects
Commit 8a8938da authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

gf works with new readln interface

parent 28d2fc68
No related branches found
No related tags found
No related merge requests found
...@@ -282,9 +282,9 @@ void CPlot::writePostscript( string ps_outdir, string ps_head, string ps_dict ) ...@@ -282,9 +282,9 @@ void CPlot::writePostscript( string ps_outdir, string ps_head, string ps_dict )
while(1) { while(1) {
if (ps_fnum>=999) if (ps_fnum>=999)
throw string( "graph file number overflow" ); throw string( "graph file number overflow" );
outf = mystd::glob_one_file( outf = mystd::wordexp_unique(
ps_outdir + str( format( "l%d." ) % ++ps_fnum ), ps_outdir + str( format( "l%d" ) % ++ps_fnum ) + "." +
ps_dict=="" ? "psa" : "ps" ); ( ps_dict=="" ? "psa" : "ps" ) );
if( !( pssav = fopen( outf.c_str(), "r" ) ) ) if( !( pssav = fopen( outf.c_str(), "r" ) ) )
break; // legal exit break; // legal exit
fclose(pssav); fclose(pssav);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <math.h> #include <math.h>
#include <sys/time.h> #include <sys/time.h>
#include <glob.h> #include <glob.h>
#include <wordexp.h>
#include <iostream> #include <iostream>
#include <boost/format.hpp> #include <boost/format.hpp>
...@@ -442,6 +443,21 @@ void mystd::fname_divide( const string& fname, ...@@ -442,6 +443,21 @@ void mystd::fname_divide( const string& fname,
} }
} }
//! Bash expansion of file name.
string mystd::wordexp_unique( const string& s )
{
wordexp_t p;
if( wordexp( s.c_str(), &p, 0 ) )
throw "cannot expand " + s;
if( p.we_wordc!=1 )
throw "expansion of " + s + " not unique";
string ret = p.we_wordv[0];
wordfree( &p );
return ret;
}
int mystd::glob_file_list( const string& text, const string& ext, int mystd::glob_file_list( const string& text, const string& ext,
vector<string> *flong, vector<string> *fshort ) vector<string> *flong, vector<string> *fshort )
// input: // input:
...@@ -477,16 +493,10 @@ int mystd::glob_file_list( const string& text, const string& ext, ...@@ -477,16 +493,10 @@ int mystd::glob_file_list( const string& text, const string& ext,
return flong->size(); return flong->size();
} }
string mystd::glob_one_file( const string& text, const string& ext )
{ //! Read one line from file.
vector<string> flong, fshort;
int ret = glob_file_list(text, ext, &flong, &fshort); // OBSOLETE: replace by simpler version from read-plus
if ( ret<1 )
throw "invalid file name " + text;
else if ( ret>1 )
throw "file name " + text + " not unique";
return flong[0];
}
int mystd::freadln( FILE *fd, string *s ) int mystd::freadln( FILE *fd, string *s )
{ {
......
...@@ -56,7 +56,7 @@ namespace mystd { ...@@ -56,7 +56,7 @@ namespace mystd {
string *fshort, string *fext); string *fshort, string *fext);
int glob_file_list( const string& text, const string& ext, int glob_file_list( const string& text, const string& ext,
vector<string> *flong, vector<string> *fshort=0); vector<string> *flong, vector<string> *fshort=0);
string glob_one_file( const string& text, const string& ext="" ); string wordexp_unique( const string& s );
int freadln( FILE *fd, string *s ); int freadln( FILE *fd, string *s );
// integration // integration
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment