'hexi' class

Wesley Leggette <lists-+42/j/[email protected]> Thu, 23 Jun 2005 15:36:23 +0200
Newsgroups gmane.comp.sysutils.backup.dar.general
Message-ID <1119533783.15541.7.camel@localhost>
Denis,

For the bindings, I'd like to be able to parse and output hexadecimal
strings. To do this, I figure to create a 'hexi' class that mirrors the
'deci' class.

Attached is a patch that tries to accomplish this. The problem is it
doesn't work, and I'm wondering if you can help with this.

Thanks, wesley


-- 
Wesley Leggette <lists-+42/j/[email protected]>

GPG Key:         http://www.kaylix.net/kaylix.asc or http://pgp.mit.edu
GPG Fingerprint: 9B6F 19FB 5296 5E6C 21FE  7614 2A20 5688 F848 9BDD
dar-hexi.patch (text/x-patch, 23.7 KB)
Index: src/libdar/hexi.hpp
===================================================================
--- src/libdar/hexi.hpp	(.../trunk)	(revision 0)
+++ src/libdar/hexi.hpp	(.../branches/hexi)	(revision 87)
@@ -0,0 +1,87 @@
+/*********************************************************************/
+// dar - disk archive - a backup/restoration program
+// Copyright (C) 2002-2052 Denis Corbin
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+//
+// to contact the author : [email protected]
+/*********************************************************************/
+// $Id$
+//
+/*********************************************************************/
+
+    /// \file hexi.hpp
+    /// \brief manages the hexidecimal representation of infinint
+    /// \ingroup Tools
+
+#ifndef DECI_HPP
+#define DECI_HPP
+
+#include "../my_config.h"
+#include <iostream>
+#include "storage.hpp"
+#include "infinint.hpp"
+
+namespace libdar
+{
+
+	/// hexidecimal class, convert infinint from and to hexidecimal representation
+
+	/// the class contains the hexidecimal representation of an integer
+	/// and can produce a readable string to display the corresponding
+	/// integer it can also produce a computer value corresponding to
+	/// the hexidecimal value. In the other side, objects of this class can
+	/// be built from a integer as well as from a string representing
+	/// the decimals of an integer.
+	/// \ingroup Tools
+    class hexi
+    {
+    public :
+	    /// constructor to build a "hexi" object from a string representing decimals
+        hexi(std::string s);
+
+	    /// constructor to build a "hexi" from an infinint
+        hexi(const infinint & x);
+
+	    /// copy constructor
+        hexi(const hexi & ref)
+            { E_BEGIN; copy_from(ref); E_END("deci::deci", "deci"); };
+
+	    /// destructor
+        ~hexi()
+            { E_BEGIN; detruit(); E_END("deci::~deci", ""); };
+
+
+	    /// copy operator
+        hexi & operator = (const hexi & ref)
+            { E_BEGIN; detruit(); copy_from(ref); return *this; E_END("deci::operator = ", ""); };
+
+	    /// this produce a infinint from the hexidecimal stored in the current object
+        infinint computer() const;
+	    /// this produce a string fromr the hexidecimal stored in the current object
+        std::string human() const;
+
+    private :
+        storage *decimales;
+
+        void detruit();
+        void copy_from(const hexi & ref);
+        void reduce();
+    };
+
+
+} // end of namespace
+
+#endif
Index: src/libdar/hexi.cpp
===================================================================
--- src/libdar/hexi.cpp	(.../trunk)	(revision 0)
+++ src/libdar/hexi.cpp	(.../branches/hexi)	(revision 87)
@@ -0,0 +1,328 @@
+/*********************************************************************/
+// dar - disk archive - a backup/restoration program
+// Copyright (C) 2002-2052 Denis Corbin
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+//
+// to contact the author : [email protected]
+/*********************************************************************/
+// $Id$
+//
+/*********************************************************************/
+
+#include "../my_config.h"
+
+#include <iostream>
+#include "hexi.hpp"
+#include "erreurs.hpp"
+#include "integers.hpp"
+
+using namespace std;
+
+namespace libdar
+{
+
+    typedef unsigned char chiffre;
+
+    static const U_I PAS = 5;
+    static inline chiffre get_left(unsigned char a) { return (a & 0xF0) >> 4; }
+    static inline chiffre get_right(unsigned char a) { return a & 0x0F; }
+    static inline void set_left(unsigned char & a, chiffre val) { val <<= 4; a &= 0x0F; a |= val; }
+    static inline void set_right(unsigned char & a, chiffre val) { val &= 0x0F; a &= 0xF0; a |= val; }
+
+    static inline chiffre digit_htoc(unsigned char c)
+    {
+        E_BEGIN;
+        if( c >= '0' && c <= '9' )
+        	return chiffre(c - '0');
+        if( c >= 'A' && c <= 'E' )
+        	return chiffre(c - 'A' + 10);
+        if( c >= 'a' && c <= 'e' )
+        	return chiffre(c - 'a' + 10);
+        throw Edeci("hexi.cpp : digit_htoc", gettext("invalid hexidecimal digit"));
+        E_END("hexi.cpp : digit_htoc", "");
+    }
+
+    static inline unsigned char digit_ctoh(chiffre c)
+    {
+        E_BEGIN;
+        if(c > 16) throw SRC_BUG;
+        if(c > 9)
+        	return 'A' + c;
+        else
+        	return '0' + c;
+        E_END("hexi.cpp : digit_ctoh", "");
+    }
+
+    template <class T> void decicoupe(storage * &decimales, T x)
+    {
+        E_BEGIN;
+        try
+        {
+            chiffre r;
+            const T d_t = 16;
+            T r_t;
+            storage::iterator it;
+            bool recule = false;
+            unsigned char tmp;
+
+            decimales = new storage(PAS);
+            if(decimales == NULL)
+                throw Ememory("template hexi::decicoupe");
+
+            decimales->clear(0xFF);
+            it = decimales->rbegin();
+
+            while(x > 0 || recule)
+            {
+                if(x > 0)
+                {
+                    euclide(x,d_t,x,r_t);
+                    r = 0;
+                    r_t.unstack(r);
+                }
+                else
+                    r = 0xF; // not significative information
+                if(recule)
+                {
+                    set_left(tmp, chiffre(r));
+                    if(it == decimales->rend())
+                    {
+                        decimales->insert_const_bytes_at_iterator(decimales->begin(), 0xFF, PAS);
+                        it = decimales->begin() + PAS - 1;
+                    }
+                    *(it--) = tmp;
+                }
+                else
+                    set_right(tmp, chiffre(r));
+                recule = ! recule;
+            }
+        }
+        catch(Ememory & e)
+        {
+            delete decimales;
+            throw;
+        }
+
+        E_END("decicoupe", "");
+    }
+
+    hexi::hexi(string s)
+    {
+        E_BEGIN;
+        string::reverse_iterator it = s.rbegin();
+        storage::iterator ut;
+        bool recule = false;
+        unsigned char tmp = 0xFF;
+
+        U_I size = s.size() / 2;
+        if(s.size() % 2 != 0)
+            size++;
+
+        if(size == 0) // empty string
+            throw Erange("hexi::hexi(string s)", gettext("an empty string is an invalid argument"));
+
+        decimales = new storage(size);
+        if(decimales == NULL)
+            throw Ememory("hexi::hexi(string s)");
+        decimales->clear(0xFF); // FF is not a valid couple of decimal digit
+
+        ut = decimales->rbegin();
+        try
+        {
+	        while(it != s.rend() || recule)
+	        {
+	            if(recule)
+	            {
+	                if(it != s.rend())
+	                    set_left(tmp, digit_htoc(*it));
+	                else
+	                    set_left(tmp, 0xF);
+	                if(ut == decimales->rend())
+	                    throw SRC_BUG;
+	                *(ut--) = tmp;
+	            }
+	            else
+	                set_right(tmp, digit_htoc(*it));
+	
+	            recule = ! recule;
+	            if(it != s.rend())
+	                it++; // it is a reverse iterator thus ++ for going backward
+	        }
+        } catch (...)
+        {
+        	delete decimales;
+        	throw;
+        }
+
+        reduce();
+        E_END("hexi::hexi", "string");
+    }
+
+    hexi::hexi(const infinint & x)
+    {
+        E_BEGIN;
+        decicoupe(decimales, x);
+        reduce();
+        E_END("hexi::hexi", "infinint");
+    }
+
+    void hexi::copy_from(const hexi & ref)
+    {
+        E_BEGIN;
+        if(decimales != NULL)
+            throw SRC_BUG;
+
+        decimales = new storage(*ref.decimales);
+        E_END("hexi::copy_from", "");
+    }
+
+    void hexi::detruit()
+    {
+        E_BEGIN;
+        if(decimales != NULL)
+        {
+            delete decimales;
+            decimales = NULL;
+        }
+        E_END("hexi::detruit", "");
+    }
+
+
+    void hexi::reduce()
+    {
+        E_BEGIN;
+        bool avance = false, leading_zero = true;
+        chiffre tmp;
+        infinint justif_size = 0;
+
+        if(decimales == NULL)
+            throw SRC_BUG;
+
+        storage::iterator it = decimales->begin();
+
+        while(it != decimales->end() && leading_zero)
+        {
+            if(avance)
+                tmp = get_right(*it);
+            else
+                tmp = get_left(*it);
+
+            if(tmp == 0 && leading_zero)
+            {
+                if(avance)
+                    set_right(*it, 0xF);
+                else
+                    set_left(*it, 0xF);
+
+                tmp = 0xF;
+            }
+
+            if(tmp == 0xF)
+                if(leading_zero)
+                {
+                    if(avance)
+                        justif_size++;
+                }
+                else
+                    throw SRC_BUG;
+
+            if(tmp != 0 && tmp != 0xF)
+                leading_zero = false;
+
+            if(avance)
+                it++;
+
+            avance = ! avance;
+        }
+
+        if(justif_size == decimales->size())
+        {
+            justif_size--;
+            it = decimales->rbegin();
+            *it = 0xF0; // need at least one digit
+        }
+        if(justif_size > 0)
+            decimales->remove_bytes_at_iterator(decimales->begin(), justif_size);
+        E_END("hexi::reduce", "");
+    }
+
+    static void dummy_call(char *x)
+    {
+        static char id[]="$Id$";
+        dummy_call(id);
+    }
+
+    string hexi::human() const
+    {
+        E_BEGIN;
+        string s = "";
+        storage::iterator it = decimales->begin(), fin = decimales->end();
+        bool avance = false;
+        chiffre c;
+
+        while(it != fin)
+        {
+            if(avance)
+            {
+                c = get_right(*it);
+                it++;
+            }
+            else
+                c = get_left(*it);
+
+            if(c != 0xF)
+                s = s + string(1, digit_ctoh(c));
+
+            avance = ! avance;
+        }
+
+        return s;
+        E_END("hexi::human", "");
+    }
+
+    infinint hexi::computer() const
+    {
+        E_BEGIN;
+        infinint r = 0;
+        storage::iterator it = decimales->begin(), fin = decimales->end();
+        bool avance = false;
+        chiffre c;
+
+        while(it != fin)
+        {
+            if(avance)
+            {
+                c = get_right(*it);
+                it++;
+            }
+            else
+                c = get_left(*it);
+
+            if(c != 0xF)
+            {
+                r *= 10;
+                r += c;
+            }
+
+            avance = ! avance;
+        }
+
+        return r;
+        E_END("hexi::computer", "");
+    }
+
+
+} // end of namespace
Index: src/libdar/Makefile.am
===================================================================
--- src/libdar/Makefile.am	(.../trunk)	(revision 87)
+++ src/libdar/Makefile.am	(.../branches/hexi)	(revision 87)
@@ -39,7 +39,7 @@
 noinst_PROGRAMS = get_version
 
 
-dist_noinst_DATA = libdar.hpp path.hpp mask.hpp integers.hpp real_infinint.hpp statistics.hpp user_interaction.hpp erreurs.hpp deci.hpp limitint.hpp infinint.hpp compressor.hpp special_alloc.hpp generic_file.hpp wrapperlib.hpp storage.hpp tuyau.hpp tools.hpp catalogue.hpp scrambler.hpp archive.hpp header_version.hpp ea.hpp crypto.hpp int_tools.hpp thread_cancellation.hpp tronconneuse.hpp mask_list.hpp
+dist_noinst_DATA = libdar.hpp path.hpp mask.hpp integers.hpp real_infinint.hpp statistics.hpp user_interaction.hpp erreurs.hpp deci.hpp hexi.hpp limitint.hpp infinint.hpp compressor.hpp special_alloc.hpp generic_file.hpp wrapperlib.hpp storage.hpp tuyau.hpp tools.hpp catalogue.hpp scrambler.hpp archive.hpp header_version.hpp ea.hpp crypto.hpp int_tools.hpp thread_cancellation.hpp tronconneuse.hpp mask_list.hpp
 install-data-local:
 	mkdir -p $(DESTDIR)$(pkgincludedir)
 	cp ../../config.h $(DESTDIR)$(pkgincludedir)
@@ -65,17 +65,17 @@
 noinst_HEADERS = defile.hpp ea_filesystem.hpp etage.hpp filesystem.hpp filtre.hpp header.hpp macro_tools.hpp null_file.hpp sar.hpp sar_tools.hpp terminateur.hpp tronc.hpp zapette.hpp test_memory.hpp cygwin_adapt.hpp elastic.hpp nls_swap.hpp
 
 libdar_la_LDFLAGS = -version-info `./get_version$(EXEEXT)`
-libdar_la_SOURCES = catalogue.cpp catalogue.hpp compressor.cpp compressor.hpp deci.cpp deci.hpp defile.cpp defile.hpp ea.cpp ea.hpp ea_filesystem.cpp ea_filesystem.hpp erreurs.cpp erreurs.hpp etage.cpp etage.hpp filesystem.cpp filesystem.hpp filtre.cpp filtre.hpp generic_file.cpp generic_file.hpp header.cpp header_version.cpp real_infinint.cpp libdar.cpp macro_tools.cpp mask.cpp path.cpp sar.cpp sar_tools.cpp scrambler.cpp storage.cpp terminateur.cpp test_memory.cpp tools.cpp tronc.cpp tuyau.cpp user_interaction.cpp wrapperlib.cpp zapette.cpp special_alloc.cpp archive.cpp crypto.cpp cache.cpp cache.hpp int_tools.cpp tronconneuse.cpp elastic.cpp thread_cancellation.cpp mask_list.cpp
+libdar_la_SOURCES = catalogue.cpp catalogue.hpp compressor.cpp compressor.hpp deci.cpp deci.hpp hexi.cpp hexi.hpp defile.cpp defile.hpp ea.cpp ea.hpp ea_filesystem.cpp ea_filesystem.hpp erreurs.cpp erreurs.hpp etage.cpp etage.hpp filesystem.cpp filesystem.hpp filtre.cpp filtre.hpp generic_file.cpp generic_file.hpp header.cpp header_version.cpp real_infinint.cpp libdar.cpp macro_tools.cpp mask.cpp path.cpp sar.cpp sar_tools.cpp scrambler.cpp storage.cpp terminateur.cpp test_memory.cpp tools.cpp tronc.cpp tuyau.cpp user_interaction.cpp wrapperlib.cpp zapette.cpp special_alloc.cpp archive.cpp crypto.cpp cache.cpp cache.hpp int_tools.cpp tronconneuse.cpp elastic.cpp thread_cancellation.cpp mask_list.cpp
 libdar_la_DEPENDENCIES = get_version$(EXEEXT)
 
 libdar32_la_LDFLAGS = -version-info `./get_version$(EXEEXT)`
-libdar32_la_SOURCES = catalogue.cpp catalogue.hpp compressor.cpp compressor.hpp deci.cpp deci.hpp defile.cpp defile.hpp ea.cpp ea.hpp ea_filesystem.cpp ea_filesystem.hpp erreurs.cpp erreurs.hpp etage.cpp etage.hpp filesystem.cpp filesystem.hpp filtre.cpp filtre.hpp generic_file.cpp generic_file.hpp header.cpp header_version.cpp libdar.cpp macro_tools.cpp mask.cpp path.cpp sar.cpp sar_tools.cpp scrambler.cpp terminateur.cpp test_memory.cpp tools.cpp tronc.cpp tuyau.cpp user_interaction.cpp wrapperlib.cpp zapette.cpp special_alloc.cpp limitint.cpp storage.cpp archive.cpp crypto.cpp cache.cpp cache.hpp int_tools.cpp tronconneuse.cpp elastic.cpp thread_cancellation.cpp mask_list.cpp
+libdar32_la_SOURCES = catalogue.cpp catalogue.hpp compressor.cpp compressor.hpp deci.cpp deci.hpp hexi.cpp hexi.hpp defile.cpp defile.hpp ea.cpp ea.hpp ea_filesystem.cpp ea_filesystem.hpp erreurs.cpp erreurs.hpp etage.cpp etage.hpp filesystem.cpp filesystem.hpp filtre.cpp filtre.hpp generic_file.cpp generic_file.hpp header.cpp header_version.cpp libdar.cpp macro_tools.cpp mask.cpp path.cpp sar.cpp sar_tools.cpp scrambler.cpp terminateur.cpp test_memory.cpp tools.cpp tronc.cpp tuyau.cpp user_interaction.cpp wrapperlib.cpp zapette.cpp special_alloc.cpp limitint.cpp storage.cpp archive.cpp crypto.cpp cache.cpp cache.hpp int_tools.cpp tronconneuse.cpp elastic.cpp thread_cancellation.cpp mask_list.cpp
 libdar32_la_DEPENDENCIES = get_version$(EXEEXT)
 
 libdar64_la_LDFLAGS = -version-info `./get_version$(EXEEXT)`
-libdar64_la_SOURCES = catalogue.cpp catalogue.hpp compressor.cpp compressor.hpp deci.cpp deci.hpp defile.cpp defile.hpp ea.cpp ea.hpp ea_filesystem.cpp ea_filesystem.hpp erreurs.cpp erreurs.hpp etage.cpp etage.hpp filesystem.cpp filesystem.hpp filtre.cpp filtre.hpp generic_file.cpp generic_file.hpp header.cpp header_version.cpp libdar.cpp macro_tools.cpp mask.cpp path.cpp sar.cpp sar_tools.cpp scrambler.cpp terminateur.cpp test_memory.cpp tools.cpp tronc.cpp tuyau.cpp user_interaction.cpp wrapperlib.cpp zapette.cpp special_alloc.cpp limitint.cpp storage.cpp archive.cpp crypto.cpp cache.cpp cache.hpp int_tools.cpp tronconneuse.cpp elastic.cpp thread_cancellation.cpp mask_list.cpp
+libdar64_la_SOURCES = catalogue.cpp catalogue.hpp compressor.cpp compressor.hpp deci.cpp deci.hpp hexi.cpp hexi.hpp defile.cpp defile.hpp ea.cpp ea.hpp ea_filesystem.cpp ea_filesystem.hpp erreurs.cpp erreurs.hpp etage.cpp etage.hpp filesystem.cpp filesystem.hpp filtre.cpp filtre.hpp generic_file.cpp generic_file.hpp header.cpp header_version.cpp libdar.cpp macro_tools.cpp mask.cpp path.cpp sar.cpp sar_tools.cpp scrambler.cpp terminateur.cpp test_memory.cpp tools.cpp tronc.cpp tuyau.cpp user_interaction.cpp wrapperlib.cpp zapette.cpp special_alloc.cpp limitint.cpp storage.cpp archive.cpp crypto.cpp cache.cpp cache.hpp int_tools.cpp tronconneuse.cpp elastic.cpp thread_cancellation.cpp mask_list.cpp
 libdar64_la_DEPENDENCIES = get_version$(EXEEXT)
 
 get_version_SOURCES = get_version.cpp
-get_version_DEPENDENCIES = catalogue.o compressor.o deci.o defile.o ea.o ea_filesystem.o erreurs.o etage.o filesystem.o filtre.o generic_file.o header.o header_version.o libdar.o macro_tools.o mask.o path.o sar.o sar_tools.o scrambler.o storage.o terminateur.o test_memory.o tools.o tronc.o tuyau.o user_interaction.o wrapperlib.o zapette.o special_alloc.o archive.o cache.o int_tools.o crypto.o tronconneuse.o elastic.o thread_cancellation.o $(VER_SRC)
-get_version_LDADD = catalogue.o compressor.o deci.o defile.o ea.o ea_filesystem.o erreurs.o etage.o filesystem.o filtre.o generic_file.o header.o header_version.o libdar.o macro_tools.o mask.o path.o sar.o sar_tools.o scrambler.o storage.o terminateur.o test_memory.o tools.o tronc.o tuyau.o user_interaction.o wrapperlib.o zapette.o special_alloc.o archive.o cache.o int_tools.o crypto.o tronconneuse.o elastic.o thread_cancellation.o $(VER_SRC)
+get_version_DEPENDENCIES = catalogue.o compressor.o deci.o hexi.o defile.o ea.o ea_filesystem.o erreurs.o etage.o filesystem.o filtre.o generic_file.o header.o header_version.o libdar.o macro_tools.o mask.o path.o sar.o sar_tools.o scrambler.o storage.o terminateur.o test_memory.o tools.o tronc.o tuyau.o user_interaction.o wrapperlib.o zapette.o special_alloc.o archive.o cache.o int_tools.o crypto.o tronconneuse.o elastic.o thread_cancellation.o $(VER_SRC)
+get_version_LDADD = catalogue.o compressor.o deci.o hexi.o defile.o ea.o ea_filesystem.o erreurs.o etage.o filesystem.o filtre.o generic_file.o header.o header_version.o libdar.o macro_tools.o mask.o path.o sar.o sar_tools.o scrambler.o storage.o terminateur.o test_memory.o tools.o tronc.o tuyau.o user_interaction.o wrapperlib.o zapette.o special_alloc.o archive.o cache.o int_tools.o crypto.o tronconneuse.o elastic.o thread_cancellation.o $(VER_SRC)
Index: src/testing/Makefile.am
===================================================================
--- src/testing/Makefile.am	(.../trunk)	(revision 87)
+++ src/testing/Makefile.am	(.../branches/hexi)	(revision 87)
@@ -12,7 +12,7 @@
 endif
 
 if BUILD_DAR_STATIC
-noinst_PROGRAMS = test_hide_file test_terminateur test_catalogue test_infinint test_tronc test_compressor test_mask test_tuyau test_deci test_path test_erreurs test_sar test_filesystem test_scrambler test_generic_file test_storage test_special_alloc test_limitint test_libdar test_cache test_tronconneuse test_elastic test_blowfish test_mask_list
+noinst_PROGRAMS = test_hide_file test_terminateur test_catalogue test_infinint test_tronc test_compressor test_mask test_tuyau test_deci test_hexi test_path test_erreurs test_sar test_filesystem test_scrambler test_generic_file test_storage test_special_alloc test_limitint test_libdar test_cache test_tronconneuse test_elastic test_blowfish test_mask_list
 AM_LDFLAGS = -all-static @LTLIBINTL@
 else
 noinst_PROGRAMS =
@@ -50,6 +50,9 @@
 test_deci_SOURCES = test_deci.cpp
 test_deci_DEPENDENCIES = ../libdar/lib$(MYLIB).la
 
+test_hexi_SOURCES = test_hexi.cpp
+test_hexi_DEPENDENCIES = ../libdar/lib$(MYLIB).la
+
 test_path_SOURCES = test_path.cpp
 test_path_DEPENDENCIES = ../libdar/lib$(MYLIB).la
 
Index: src/testing/test_hexi.cpp
===================================================================
--- src/testing/test_hexi.cpp	(.../trunk)	(revision 0)
+++ src/testing/test_hexi.cpp	(.../branches/hexi)	(revision 87)
@@ -0,0 +1,81 @@
+/*********************************************************************/
+// dar - disk archive - a backup/restoration program
+// Copyright (C) 2002-2052 Denis Corbin
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+//
+// to contact the author : [email protected]
+/*********************************************************************/
+// $Id$
+//
+/*********************************************************************/
+
+#include "../my_config.h"
+#include <iostream>
+
+#include "test_memory.hpp"
+#include "hexi.hpp"
+
+using namespace libdar;
+using namespace std;
+
+static void f1();
+
+int main()
+{
+    MEM_BEGIN;
+    MEM_IN;
+    f1();
+    MEM_OUT;
+    MEM_END;
+}
+
+static void f1()
+{
+	try
+	{
+		hexi h1 = string("00001");
+		hexi h2 = string("3E8");
+		hexi h3 = string("00AE04");
+	
+		infinint t = 3;
+		hexi h4 = t;
+		t = 0x3E8;
+		hexi h5 = t;
+		hexi h6 = infinint(1000);
+		U_I c;
+		
+		cout << h1.human() << endl;
+		cout << h2.human() << endl;
+		cout << h3.human() << endl;
+		cout << h4.human() << endl;
+		cout << h5.human() << endl;
+		cout << h6.human() << endl;
+	
+	    c = h1.computer() % 200;
+	    c = h2.computer() % 200;
+	    c = h3.computer() % 200;
+	    c = h4.computer() % 200;
+	    c = h5.computer() % 200;
+	    c = h6.computer() % 200;
+	    
+	} catch (Egeneric &e)
+	{
+		cout << "Exception: " <<e.get_source() << " : " << e.get_message() << endl;
+	}
+	
+
+    
+}
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBCurrXKiBWiPhIm90RAhxVAJwIJcpGWWp+2/4FaopdehNcM85YjgCeMbk/
vnVWznZbOMd8wGs2wAoMHsw=
=P7Y/
-----END PGP SIGNATURE-----