"Fossies" - the Fresh Open Source Software Archive

Member "cln-1.3.6/src/base/output/cl_output_hex.cc" (18 Nov 2019, 2034 Bytes) of package /linux/privat/cln-1.3.6.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "cl_output_hex.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.3.5_vs_1.3.6.

    1 // fprinthexadecimal().
    2 
    3 // General includes.
    4 #include "base/cl_sysdep.h"
    5 
    6 // Specification.
    7 #include "cln/io.h"
    8 
    9 
   10 // Implementation.
   11 
   12 namespace cln {
   13 
   14 static void fprinthexadecimal_impl (std::ostream& stream, uintptr_t x)
   15 {
   16     #define bufsize (sizeof(uintptr_t)*2)
   17     var char buf[bufsize+1];
   18     var char* bufptr = &buf[bufsize];
   19     *bufptr = '\0';
   20     do {
   21         uintptr_t q = x / 16;
   22         uintptr_t r = x % 16;
   23         *--bufptr = (r<10 ? '0'+r : 'A'-10+r);
   24         x = q;
   25     } while (x > 0);
   26     fprint(stream,bufptr);
   27     #undef bufsize
   28 }
   29 
   30 static void fprinthexadecimal_impl (std::ostream& stream, intptr_t x)
   31 {
   32     if (x >= 0)
   33         fprinthexadecimal(stream,(uintptr_t)x);
   34     else {
   35         fprintchar(stream,'-');
   36         fprinthexadecimal(stream,(uintptr_t)(-1-x)+1);
   37     }
   38 }
   39 
   40 void fprinthexadecimal (std::ostream& stream, unsigned int x)
   41 {
   42         fprinthexadecimal_impl(stream,(uintptr_t)x);
   43 }
   44 void fprinthexadecimal (std::ostream& stream, int x)
   45 {
   46         fprinthexadecimal_impl(stream,(intptr_t)x);
   47 }
   48 
   49 void fprinthexadecimal (std::ostream& stream, unsigned long x)
   50 {
   51         fprinthexadecimal_impl(stream,(uintptr_t)x);
   52 }
   53 void fprinthexadecimal (std::ostream& stream, long x)
   54 {
   55         fprinthexadecimal_impl(stream,(intptr_t)x);
   56 }
   57 
   58 #ifdef HAVE_LONGLONG
   59 
   60 void fprinthexadecimal (std::ostream& stream, unsigned long long x)
   61 {
   62 #if long_long_bitsize <= pointer_bitsize
   63     fprinthexadecimal_impl(stream,(uintptr_t)x);
   64 #else
   65     #define bufsize (sizeof(unsigned long long)*2)
   66     var char buf[bufsize+1];
   67     var char* bufptr = &buf[bufsize];
   68     *bufptr = '\0';
   69     do {
   70         unsigned long long q = x / 16;
   71         unsigned long long r = x % 16;
   72         *--bufptr = (r<10 ? '0'+r : 'A'-10+r);
   73         x = q;
   74     } while (x > 0);
   75     fprint(stream,bufptr);
   76     #undef bufsize
   77 #endif
   78 }
   79 
   80 void fprinthexadecimal (std::ostream& stream, long long x)
   81 {
   82 #if long_long_bitsize <= pointer_bitsize
   83     fprinthexadecimal_impl(stream,(intptr_t)x);
   84 #else
   85     if (x >= 0)
   86         fprinthexadecimal(stream,(unsigned long long)x);
   87     else {
   88         fprintchar(stream,'-');
   89         fprinthexadecimal(stream,(unsigned long long)(-1-x)+1);
   90     }
   91 #endif
   92 }
   93 
   94 #endif
   95 
   96 }  // namespace cln