Index: trunk/FACT++/src/fitsdump.cc
===================================================================
--- trunk/FACT++/src/fitsdump.cc	(revision 17389)
+++ trunk/FACT++/src/fitsdump.cc	(revision 17393)
@@ -72,5 +72,5 @@
     /// Lists all columns of an open file
     void List();                          
-    void ListFileContent(const string& filename);
+    void ListFileContent() const;
     void ListHeader(const string& filename);
     void ListKeywords(ostream &);
@@ -166,45 +166,13 @@
 }
 
-void FitsDumper::ListFileContent(const string& filename)
-{
-    ofstream fout(filename=="-"?"/dev/stdout":filename);
-    if (!fout)
-    {
-        cerr << "Cannot open file " << filename << ": " << strerror(errno) << endl;
-        return;
-    }
-
-    int table_id = 0;
-
-    vector<string> table_names;
-    vector<uint32_t> table_rows;
-    try
-    {
-
-        while (true)
-        {
-            clear();
-            seekg(0);
-            fTable = Table();
-            Constructor(fFilename, "", "", false, table_id);
-
-            table_names.push_back(fTable.Get<string>("EXTNAME"));
-            table_rows.push_back(GetNumRows());
-
-            table_id++;
-        }
-    }
-    catch (runtime_error e)
-    {
-        //nothing to see here, just catching the error thrown by EOF
-    }
-
-    fout << "File " << fFilename << " has " << table_names.size() << " tables: " << endl;
-    for (uint32_t i=0; i<table_names.size(); i++)
-    {
-        fout << "#" << i << ": \"" << table_names[i];
-        fout << "\" num. rows = " << table_rows[i] << endl;
-    }
-}
+void FitsDumper::ListFileContent() const
+{
+    const std::vector<std::string> &tables = GetTables();
+
+    cout << "File " << fFilename << " has " << tables.size() << " table(s): " << endl;
+    for (auto it=tables.begin(); it!=tables.end(); it++)
+        cout << " * " << *it << endl;
+}
+
 void FitsDumper::ListHeader(const string& filename)
 {
@@ -607,10 +575,13 @@
                     break;
 
-            ostringstream id;
-            id << '[' << p << ']';
-
-            it->replace(ibeg-it->begin()+what.position(1), what.length()-1, id.str());
-
-            ibeg = what[0].first+3;
+            const string id = '['+to_string(p)+']';
+
+            // Replace might reallocate the memory. Therefore, we cannot use what[0].first
+            // directly but have to store the offset
+            const size_t offset = what[0].first - it->begin();
+
+            it->replace(ibeg-it->begin()+what.position(1), what.length()-1, id);
+
+            ibeg = it->begin() + offset + id.size();
             iend = it->end();
 
@@ -972,5 +943,5 @@
 
     if (conf.Get<bool>("filecontent"))
-        ListFileContent(conf.Get<string>("outfile"));
+        ListFileContent();
 
     if (conf.Get<bool>("header"))
@@ -1135,14 +1106,15 @@
     po::options_description configs("Fitsdump options");
     configs.add_options()
-        ("fitsfile,f",  var<string>()
+        ("filecontent", po_switch(),            "List the number of tables in the file, along with their name")
+        ("header,h",    po_switch(),            "Dump header of given table")
+        ("list,l",      po_switch(),            "List all tables and columns in file")
+        ("fitsfile",    var<string>()
 #if BOOST_VERSION >= 104200
          ->required()
 #endif
                                               , "Name of FITS file")
-        ("col,c",       vars<string>(),         "List of columns to dump\narg is a list of columns, separated by a space.\nAdditionnally, a list of sub-columns can be added\ne.g. Data[3] will dump sub-column 3 of column Data\nData[3:4] will dump sub-columns 3 and 4\nOmitting this argument dump the entire column\nnota: all indices start at zero")
+        ("col,c",       vars<string>(),         "List of columns to dump\narg is a list of columns, separated by a space.\nAdditionnally, a list of sub-columns can be added\ne.g. Data[3] will dump sub-column 3 of column Data\nData[3:4] will dump sub-columns 3 and 4\nOmitting this argument dump the entire column\nnote: all indices start at zero")
         ("outfile,o",   var<string>("-"),       "Name of output file (-:/dev/stdout)")
         ("precision,p", var<int>(20),           "Precision of ofstream")
-        ("list,l",      po_switch(),            "List all tables and columns in file")
-        ("header,h",    po_switch(),            "Dump header of given table")
         ("stat,s",      po_switch(),            "Perform statistics instead of dump")
         ("minmax,m",    po_switch(),            "Calculates min and max of data")
@@ -1155,5 +1127,4 @@
         ("limit",       var<size_t>(size_t(0)), "Limit for the maximum number of rows to read (0=unlimited)")
         ("tablename,t", var<string>(""),        "Name of the table to open. If not specified, first binary table is opened")
-        ("filecontent", po_switch(),            "List the number of tables in the file, along with their name")
 #ifdef HAVE_ROOT
         ("root,r",      po_switch(),            "Enable root mode")
