From 8a8938da903d7cf005f0a56cfcc456bd31de9105 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (office)" <j.wuttke@fz-juelich.de>
Date: Fri, 2 Jul 2010 14:31:40 +0200
Subject: [PATCH] gf works with new readln interface

---
 pub/src/dualplot.cpp |  6 +++---
 pub/src/mystd.cpp    | 30 ++++++++++++++++++++----------
 pub/src/mystd.h      |  2 +-
 3 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/pub/src/dualplot.cpp b/pub/src/dualplot.cpp
index 652873d2..6bf04d2a 100644
--- a/pub/src/dualplot.cpp
+++ b/pub/src/dualplot.cpp
@@ -282,9 +282,9 @@ void CPlot::writePostscript( string ps_outdir, string ps_head, string ps_dict )
     while(1) {
         if (ps_fnum>=999)
             throw string( "graph file number overflow" );
-        outf = mystd::glob_one_file(
-            ps_outdir + str( format( "l%d." ) % ++ps_fnum ),
-            ps_dict=="" ? "psa" : "ps" );
+        outf = mystd::wordexp_unique( 
+            ps_outdir + str( format( "l%d" ) % ++ps_fnum ) + "." +
+            ( ps_dict=="" ? "psa" : "ps" ) );
         if( !( pssav = fopen( outf.c_str(), "r" ) ) )
             break; // legal exit
         fclose(pssav);
diff --git a/pub/src/mystd.cpp b/pub/src/mystd.cpp
index e37cdb76..52463cbb 100644
--- a/pub/src/mystd.cpp
+++ b/pub/src/mystd.cpp
@@ -11,6 +11,7 @@
 #include <math.h>
 #include <sys/time.h>
 #include <glob.h>
+#include <wordexp.h>
 #include <iostream>
 #include <boost/format.hpp>
 
@@ -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,
                            vector<string> *flong, vector<string> *fshort )
 // input:
@@ -477,16 +493,10 @@ int mystd::glob_file_list( const string& text, const string& ext,
     return flong->size();
 }
 
-string mystd::glob_one_file( const string& text, const string& ext )
-{
-    vector<string> flong, fshort;
-    int ret = glob_file_list(text, ext, &flong, &fshort);
-    if      ( ret<1 )
-        throw "invalid file name " + text;
-    else if ( ret>1 )
-        throw "file name " + text + " not unique";
-    return flong[0];
-}
+
+//! Read one line from file. 
+
+// OBSOLETE: replace by simpler version from read-plus
 
 int mystd::freadln( FILE *fd, string *s )
 {
diff --git a/pub/src/mystd.h b/pub/src/mystd.h
index 49859654..c2cdd1cb 100644
--- a/pub/src/mystd.h
+++ b/pub/src/mystd.h
@@ -56,7 +56,7 @@ namespace mystd {
                        string *fshort, string *fext);
     int glob_file_list( const string& text, const string& ext, 
                         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 );
 
     // integration
-- 
GitLab