PPI: Checkin of first compiling (yet not working) version
[senf.git] / Utils / hexdump.ct
index 350c8c5..76b95e6 100644 (file)
@@ -26,6 +26,7 @@
 //#include "hexdump.ih"
 
 // Custom includes
+#include <boost/io/ios_state.hpp>
 #include <iomanip> 
 
 //#include "hexdump.mpp"
 ///////////////////////////////cc.p////////////////////////////////////////
 
 template <class Iterator>
-prefix_ void senf::hexdump(Iterator i, Iterator const & i_end, std::ostream& stream, unsigned block_size=16)
+prefix_ void senf::hexdump(Iterator i, Iterator i_end, std::ostream & stream,
+                           unsigned block_size)
 {
+    boost::io::ios_all_saver ias (stream);
     unsigned offset (0);
     std::string ascii;
     for (; i != i_end; ++i, ++offset) {
-        switch ((offset % block_size)==0) {
-        case true:
+        if ((offset % block_size) == 0) {
             if (!ascii.empty()) {
                 stream << "  " << ascii << "\n";
                 ascii = "";
             }
             stream << "  "
-                      << std::hex << std::setw(4) << std::setfill('0')
-                      << offset << ' ';
-            break;
-        case false:
+                   << std::hex << std::setw(4) << std::setfill('0')
+                   << offset << ' ';
+        } else if ((offset % block_size) == block_size/2) {
             stream << " ";
             ascii += ' ';
-            break;
         }
         stream << ' ' << std::hex << std::setw(2) << std::setfill('0')
-                  << unsigned(*i);
+               << unsigned(*i);
         ascii += (*i >= ' ' && *i < 126) ? *i : '.';
     }
     if (!ascii.empty()) {
@@ -65,14 +65,13 @@ prefix_ void senf::hexdump(Iterator i, Iterator const & i_end, std::ostream& str
         }
         stream << "  " << ascii << "\n";
     }
-    stream << std::dec;
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "hexdump.mpp"
 
-\f
 // Local Variables:
 // mode: c++
 // fill-column: 100