From 43a299e5f55ac4467f442b1c46d0e68e5f5fcaa1 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Mon, 20 Mar 2017 18:07:32 +0100
Subject: [PATCH] pass full parameter set to plot/ so that we can individually
 overwrite setup1D or setup2D, as used in wallpaper itest.

---
 pub/itest/curveplot.f2t                        |  2 +-
 pub/itest/p2D.f2t                              |  1 -
 .../{g4wallpaper.ps => setup_wallpaper.ps}     |  0
 pub/lib/commands.cpp                           | 11 +++++------
 pub/lib/defs.hpp                               |  2 --
 pub/lib/plot.cpp                               |  7 +++----
 pub/lib/reduce_curv.cpp                        |  5 +++--
 pub/lib/reduce_spec.cpp                        |  5 +++--
 pub/lib/registry.hpp                           |  5 +++--
 pub/lib/variables.cpp                          |  9 +++++++++
 pub/lib/variables.hpp                          |  5 +++--
 pub/plot/dualplot.cpp                          |  6 +++---
 pub/plot/dualplot.hpp                          |  5 +++--
 pub/plot/ps_plotter.cpp                        | 18 ++++++++++--------
 pub/plot/ps_plotter.hpp                        |  5 +++--
 pub/share/frida.ini.in                         |  8 +++++---
 16 files changed, 54 insertions(+), 40 deletions(-)
 rename pub/itest/{g4wallpaper.ps => setup_wallpaper.ps} (100%)

diff --git a/pub/itest/curveplot.f2t b/pub/itest/curveplot.f2t
index f157d7ed..b2a4287d 100755
--- a/pub/itest/curveplot.f2t
+++ b/pub/itest/curveplot.f2t
@@ -1,6 +1,6 @@
 #!/usr/bin/env frida
 ! rm -f /tmp/P.ps
-pshead="g4wallpaper.ps"
+ps_setup1D="setup_wallpaper.ps"
 gnc 100
 cca p0+p1*t
 op0 100000
diff --git a/pub/itest/p2D.f2t b/pub/itest/p2D.f2t
index 5420a578..e86ada79 100755
--- a/pub/itest/p2D.f2t
+++ b/pub/itest/p2D.f2t
@@ -2,5 +2,4 @@
 fl grid40x20
 gt+
 p
-gp! /tmp/P.ps
 qui
diff --git a/pub/itest/g4wallpaper.ps b/pub/itest/setup_wallpaper.ps
similarity index 100%
rename from pub/itest/g4wallpaper.ps
rename to pub/itest/setup_wallpaper.ps
diff --git a/pub/lib/commands.cpp b/pub/lib/commands.cpp
index 87e5d40f..94789a7c 100644
--- a/pub/lib/commands.cpp
+++ b/pub/lib/commands.cpp
@@ -361,15 +361,13 @@ bool frida_command(string cmd)
             "Allow iterative refinement for curve plotting",
             SPloWin::instance()->current()->refine);
     } else if (cmd == "gp" || cmd == "gf" || cmd == "gfa") {
-        const string ps_setup_dir = CNode::eval("ps_setup_dir")->to_s();
-        const string ps_definitions = (cmd == "gp") ? CNode::eval("ps_definitions")->to_s() : "";
-        const string ext = string(".") + (ps_definitions == "" ? "psa" : "ps");
+        bool withDefs = cmd.substr(0,2)=="gp";
+        const string ext = string(".") + (withDefs ? "ps" : "psa");
         static string fname = "";
         string mode;
         if (cmd != "gfa") {
             fs::path defaultname = triv::next_tmp_file(
-                CNode::eval("ps_output_dir")->to_s() + (ps_definitions == "" ? "l" : "L") + "%i"
-                + ext);
+                CNode::eval("ps_outdir")->to_s() + (withDefs ? "L" : "l") + "%i" + ext);
             defaultname.replace_extension("");
             fname = sask("Graphic file name (without extension "+ext+")", defaultname.string());
             if (fname=="")
@@ -383,7 +381,8 @@ bool frida_command(string cmd)
         }
         if (fname != "")
             SPloWin::instance()->current()->write_postscript(
-                mode, triv::wordexp_unique(fname), ps_setup_dir, ps_definitions);
+                triv::wordexp_unique(fname), mode, withDefs,
+                SVariRegistry::instance()->to_sMap());
     } else if (cmd == "gw") {
         SPloWin::instance()->display_list();
     } else if (sscanf(cmd.c_str(), "g%i", &i) == 1) {
diff --git a/pub/lib/defs.hpp b/pub/lib/defs.hpp
index f0824e2e..9bf1447f 100644
--- a/pub/lib/defs.hpp
+++ b/pub/lib/defs.hpp
@@ -12,14 +12,12 @@
 
 #include "../trivia/string_convs.hpp"
 #include <iostream>
-#include <map>
 #include <vector>
 
 #define S(a) triv::strg((a))
 
 #define SQR(a) ((a) * (a))
 
-using std::map;
 using std::string;
 using std::vector;
 using std::cout;
diff --git a/pub/lib/plot.cpp b/pub/lib/plot.cpp
index 24af67fe..47253e6c 100644
--- a/pub/lib/plot.cpp
+++ b/pub/lib/plot.cpp
@@ -28,6 +28,7 @@
 #include "olf.hpp"
 #include "plot.hpp"
 #include "slice.hpp"
+#include "variables.hpp"
 
 using boost::format;
 
@@ -563,11 +564,9 @@ namespace {
         for (int i = 0; i < fd->lDoc.size(); i++)
             plot->doc_TxLine("  " + fd->lDoc[i]);
         // plot -> file
-        const string ps_setup_dir = CNode::eval("ps_setup_dir")->to_s();
-        const string ps_definitions = CNode::eval("ps_definitions")->to_s();
-        static string fname = "~/P.ps";
+        static string fname = "/tmp/P.ps";
         plot->write_postscript(
-            "overwrite", triv::wordexp_unique(fname), ps_setup_dir, ps_definitions);
+            triv::wordexp_unique(fname), "overwrite", true, SVariRegistry::instance()->to_sMap());
     }
 
 } // anonymous namespace
diff --git a/pub/lib/reduce_curv.cpp b/pub/lib/reduce_curv.cpp
index 69fb19b9..b0abd50e 100644
--- a/pub/lib/reduce_curv.cpp
+++ b/pub/lib/reduce_curv.cpp
@@ -10,6 +10,7 @@
 #include "defs.hpp"
 
 #include <boost/format.hpp>
+#include <map>
 
 #include "../readplus/ask.hpp"
 #include "../trivia/integrate.hpp"
@@ -114,8 +115,8 @@ void cvin_integrate(double* r, double* dr, const COlc* fc, int k, int j, const v
 
 namespace NCvin
 { // internals:
-map<string, const CCvin*> hmap; // unsorted hash, for expression evaluation
-vector<const CCvin*> hlist; // sorted array, for help text
+    std::map<string, const CCvin*> hmap; // unsorted hash, for expression evaluation
+    vector<const CCvin*> hlist; // sorted array, for help text
 }
 
 
diff --git a/pub/lib/reduce_spec.cpp b/pub/lib/reduce_spec.cpp
index d7b11975..807d4b46 100644
--- a/pub/lib/reduce_spec.cpp
+++ b/pub/lib/reduce_spec.cpp
@@ -10,6 +10,7 @@
 #include "defs.hpp"
 
 #include <boost/format.hpp>
+#include <map>
 
 #include "../trivia/string_ops.hpp"
 
@@ -251,8 +252,8 @@ RObjNum geni_lastwith(int n, const vector<RObjVecNum>& a)
 
 namespace NGeni
 { // internals:
-map<string, const CGeni*> gmap; // unsorted hash, for expression evaluation
-vector<const CGeni*> glist; // sorted array, for help text
+    std::map<string, const CGeni*> gmap; // unsorted hash, for expression evaluation
+    vector<const CGeni*> glist; // sorted array, for help text
 }
 
 CGeni::CGeni(
diff --git a/pub/lib/registry.hpp b/pub/lib/registry.hpp
index 27eec53c..5dd25570 100644
--- a/pub/lib/registry.hpp
+++ b/pub/lib/registry.hpp
@@ -10,6 +10,7 @@
 #ifndef IREGISTRY_H
 #define IREGISTRY_H
 
+#include <map>
 #include "../trivia/singleton.hpp"
 
 //! Mixin interface for registries holding objects of type T; temporary version for SFuncRegistry.
@@ -18,7 +19,7 @@ template <class T> class IRegistryTmp
 {
 protected:
     virtual string type_name() const = 0;
-    map<string, /*const*/ T*> FMap; //! unsorted hash, for expression evaluation
+    std::map<string, /*const*/ T*> FMap; //! unsorted hash, for expression evaluation
     vector<const T*> FList; //! sorted array, for help text
 public:
     virtual ~IRegistryTmp()
@@ -53,7 +54,7 @@ template <class T> class IRegistry
 {
 protected:
     virtual string type_name() const = 0;
-    map<string, const T*> FMap; //! unsorted hash, for expression evaluation
+    std::map<string, const T*> FMap; //! unsorted hash, for expression evaluation
     vector<const T*> FList; //! sorted array, for help text
 public:
     virtual ~IRegistry()
diff --git a/pub/lib/variables.cpp b/pub/lib/variables.cpp
index b9d47a03..9e6068eb 100644
--- a/pub/lib/variables.cpp
+++ b/pub/lib/variables.cpp
@@ -52,3 +52,12 @@ bool SVariRegistry::undef(const string& key)
     Map.erase(pos);
     return true;
 }
+
+std::map<const string, string> SVariRegistry::to_sMap() const
+{
+    std::map<const string, string> ret;
+    for (const auto& it: Map) {
+        ret[it.first] = it.second->to_s();
+    }
+    return ret;
+}
diff --git a/pub/lib/variables.hpp b/pub/lib/variables.hpp
index f80665fd..f05ef77f 100644
--- a/pub/lib/variables.hpp
+++ b/pub/lib/variables.hpp
@@ -10,8 +10,8 @@
 #ifndef VARIABLES_H
 #define VARIABLES_H
 
+#include <map>
 #include "../trivia/singleton.hpp"
-
 #include "defs.hpp"
 #include "ptr.hpp"
 
@@ -20,7 +20,7 @@
 class SVariRegistry : public triv::ISingleton<SVariRegistry>
 {
 private:
-    map<const string, PObj> Map; //! unsorted hash, for expression evaluation
+    std::map<const string, PObj> Map; //! unsorted hash, for expression evaluation
 
 public:
     PObj find(const string& key) const;
@@ -30,6 +30,7 @@ public:
 
     void register_scalar(const string& key, PObj val);
     bool undef(const string& key);
+    std::map<const string, string> to_sMap() const;
 };
 
 #endif // VARIABLES_H
diff --git a/pub/plot/dualplot.cpp b/pub/plot/dualplot.cpp
index b0620251..b72ba09e 100644
--- a/pub/plot/dualplot.cpp
+++ b/pub/plot/dualplot.cpp
@@ -177,10 +177,10 @@ void CPlot::doc_CvTxLine(const string& line, int num)
 //! Write buffered plot to postscript file.
 
 void CPlot::write_postscript(
-    const string& mode, const string& fname,
-    const string& ps_setup_dir, const string& ps_definitions)
+    const string& fname, const string& mode, const bool withDefs,
+    std::map<const string, string>&& settings)
 {
-    ps_Plotter->copy_header(mode, fname, ps_setup_dir, ps_definitions);
+    ps_Plotter->copy_header(fname, mode, withDefs, settings);
     ps_Plotter->write_data(fname);
 }
 
diff --git a/pub/plot/dualplot.hpp b/pub/plot/dualplot.hpp
index 9e8ccf8a..7ae93ef8 100644
--- a/pub/plot/dualplot.hpp
+++ b/pub/plot/dualplot.hpp
@@ -7,6 +7,7 @@
 //! \file  dualplot.hpp
 //! \brief Declares class CPlot.
 
+#include <map>
 #include <memory>
 #include "axis.hpp"
 
@@ -50,8 +51,8 @@ public:
     void doc_PtTxLine(const std::string& line, int num);
     void doc_CvTxLine(const std::string& line, int num);
     void write_postscript(
-        const std::string& mode, const std::string& fname,
-        const std::string& ps_setup_dir, const std::string& ps_definitions);
+        const std::string& fname, const std::string& mode, const bool withDefs,
+        std::map<const std::string, std::string>&& settings);
     void set_aux(const std::string& cmd);
     std::string info() const;
 
diff --git a/pub/plot/ps_plotter.cpp b/pub/plot/ps_plotter.cpp
index ce8e9ed1..736660b1 100644
--- a/pub/plot/ps_plotter.cpp
+++ b/pub/plot/ps_plotter.cpp
@@ -9,6 +9,7 @@
 
 #include <cmath>
 #include <fstream>
+#include <iostream>
 #include <boost/format.hpp>
 
 #include "../trivia/file_ops.hpp"
@@ -111,26 +112,27 @@ void CPS_Plotter::doc_line(const string& line)
 }
 
 void CPS_Plotter::copy_header(
-    const string& mode, const string& fname,
-    const string& ps_setup_dir, const string& ps_definitions)
+    const string& fname, const string& mode, const bool withDefs,
+    std::map<const string, string>& settings)
 {
     // copy headers to output file
     string cmd;
     if (mode=="append") {
         if (!triv::file_exists(fname))
             throw "Cannot append graphic: file " + fname + " not found";
-        cmd = "cat " + ps_setup_dir + "continuation.ps >> " + fname;
+        cmd = "cat " + settings.at("ps_continuation") + " >> " + fname;
     } else {
         if (mode=="create") {
             if (triv::file_exists(fname))
-                throw "File " + fname + " already exists. Use "
-                    + (ps_definitions=="" ? "gf!" : "gp!") + " to overwrite";
+                throw "File " + fname + " already exists. "
+                    + "Use command suffix '!' to overwrite";
         } else if (mode=="overwrite") {
         } else
             throw "BUG: unexpected mode";
-        string setup_file = ps_setup_dir + "setup" + (p2D ? "2" : "1") + "D.ps";
-        string def_file = ps_definitions=="" ? "" : (ps_setup_dir + ps_definitions);
-        cmd = "cat " + def_file + " " + setup_file + " > " + fname;
+        cmd = "cat ";
+        if (withDefs)
+            cmd += settings.at("ps_definitions") + " ";
+        cmd += settings.at(string("ps_setup") + (p2D ? "2" : "1") + "D") + " > " + fname;
     }
     triv::system(cmd);
 }
diff --git a/pub/plot/ps_plotter.hpp b/pub/plot/ps_plotter.hpp
index 84f15581..edc39be0 100644
--- a/pub/plot/ps_plotter.hpp
+++ b/pub/plot/ps_plotter.hpp
@@ -7,6 +7,7 @@
 //! \file  ps_plotter.hpp
 //! \brief Declares class CPS_Plotter
 
+#include <map>
 #include <string>
 #include <vector>
 
@@ -33,8 +34,8 @@ public:
     void main_line(const std::string& line);
     void doc_line(const std::string& line);
     void copy_header(
-        const std::string& mode, const std::string& fname,
-        const std::string& ps_setup_dir, const std::string& ps_definitions);
+        const std::string& fname, const std::string& mode, const bool withDefs,
+        std::map<const std::string, std::string>& settings);
     void write_data(const std::string& fname);
 private:
     bool p2D;
diff --git a/pub/share/frida.ini.in b/pub/share/frida.ini.in
index a2be5e7d..dea7b459 100644
--- a/pub/share/frida.ini.in
+++ b/pub/share/frida.ini.in
@@ -1,7 +1,9 @@
 pop($silent=1)
-ps_output_dir="~/gnew/"
-ps_setup_dir="${CMAKE_INSTALL_PREFIX}/share/frida/"
-ps_definitions="wups17a.ps"
+ps_outdir="~/gnew/"
+ps_setup1D="${CMAKE_INSTALL_PREFIX}/share/frida/setup1D.ps"
+ps_setup2D="${CMAKE_INSTALL_PREFIX}/share/frida/setup2D.ps"
+ps_continuation="${CMAKE_INSTALL_PREFIX}/share/frida/continuation.ps"
+ps_definitions="${CMAKE_INSTALL_PREFIX}/share/frida/wups17a.ps"
 psgsym="${CMAKE_INSTALL_PREFIX}/share/frida/gnuplot-default-symbols.eps"
 FK01="pv"
 FK02="pn"
-- 
GitLab