| 1 | #cxx . . $ `<file>/vendor/Heap-Layers/utility/tprintf.h`/ifndef TPRINTF_H |
| 2 | #define TPRINTF_Hcxx . . $ `vendor/Heap-Layers/utility/tprintf.h:2:9`! |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | // Written by Emery Berger |
| 7 | |
| 8 | #if !defined(_WIN32) |
| 9 | |
| 10 | #include <unistd.h> |
| 11 | #include <string.h> |
| 12 | #include <cmath> |
| 13 | #include <cstdint> |
| 14 | |
| 15 | using namespace std; |
| 16 | |
| 17 | namespace tprintfcxx . . $ tprintf/ { |
| 18 | |
| 19 | const int MAXBUFcxx . . $ tprintf/MAXBUF. = 65536; |
| 20 | static int FDcxx . . $ tprintf/FD. { 1 }; // 2 |
| 21 | |
| 22 | template <typename T> |
| 23 | inline void writevalcxx . . $ tprintf/writeval(9b289cee16747614).(T v); |
| 24 | |
| 25 | |
| 26 | template <typename T> |
| 27 | inline unsigned int itoacxx . . $ tprintf/itoa(9d69a0895ef8e6d).(char * buf, T v) { |
| 28 | long n = (long) v; |
| 29 | auto startbuf = buf; |
| 30 | if (n < 0) { |
| 31 | *buf++ = '-'; |
| 32 | n = -n; |
| 33 | } |
| 34 | if (n == 0) { |
| 35 | *buf++ = '0'; |
| 36 | return static_cast<unsigned int>(buf - startbuf); |
| 37 | } |
| 38 | long tens = 1L; |
| 39 | while (n / (10 * tens)) { |
| 40 | tens *= 10; |
| 41 | } |
| 42 | while (tens) { |
| 43 | *buf++ = '0' + static_cast<char>(n / tens); |
| 44 | n = n - (n / tens) * tens; |
| 45 | tens /= 10; |
| 46 | } |
| 47 | return (unsigned int) (buf - startbuf); |
| 48 | } |
| 49 | |
| 50 | inline unsigned int ftoacxx . . $ tprintf/ftoa(294b2ae1843eeb4e).(char * buf, double n, int decimalPlaces = 4) { |
| 51 | // Extract integer part |
| 52 | auto ipart = (long) n; |
| 53 | |
| 54 | // Extract floating part |
| 55 | auto fpart = n - (double) ipart; |
| 56 | if (fpart < 0.0) { |
| 57 | fpart = -fpart; |
| 58 | } |
| 59 | |
| 60 | // convert integer part to string |
| 61 | auto i = itoacxx . . $ tprintf/itoa(9d69a0895ef8e6d).(buf, ipart); |
| 62 | |
| 63 | if (decimalPlaces > 0) { |
| 64 | buf[i] = '.'; |
| 65 | auto multiple = pow(10, decimalPlaces); |
| 66 | fpart = fpart * multiple; |
| 67 | multiple /= 10; |
| 68 | while ((fpart < multiple) && (decimalPlaces > 0)) { |
| 69 | buf[++i] = '0'; |
| 70 | multiple /= 10; |
| 71 | decimalPlaces--; |
| 72 | } |
| 73 | if (fpart > 0) { |
| 74 | i = i + itoacxx . . $ tprintf/itoa(9d69a0895ef8e6d).(buf + i + 1, (long) fpart) + 1; |
| 75 | } |
| 76 | } |
| 77 | return i; |
| 78 | } |
| 79 | |
| 80 | inline void writevalcxx . . $ tprintf/writeval(ba8836b59fb42830).(double n) { |
| 81 | char buf[MAXBUFcxx . . $ tprintf/MAXBUF.]; |
| 82 | unsigned long len = ftoacxx . . $ tprintf/ftoa(294b2ae1843eeb4e).(buf, n); |
| 83 | auto _ __attribute__((unused)) = write(FDcxx . . $ tprintf/FD., buf, len); |
| 84 | } |
| 85 | |
| 86 | inline void writevalcxx . . $ tprintf/writeval(9364e6e7bff7660).(float n) { |
| 87 | char buf[MAXBUFcxx . . $ tprintf/MAXBUF.]; |
| 88 | auto len = ftoacxx . . $ tprintf/ftoa(294b2ae1843eeb4e).(buf, n); |
| 89 | auto _ __attribute__((unused)) = write(FDcxx . . $ tprintf/FD., buf, len); |
| 90 | } |
| 91 | |
| 92 | inline void writevalcxx . . $ tprintf/writeval(85c52e162fed56f9).(const char * str) { |
| 93 | auto _ __attribute__((unused)) = write(FDcxx . . $ tprintf/FD., str, strlen(str)); |
| 94 | } |
| 95 | |
| 96 | inline void writevalcxx . . $ tprintf/writeval(fda57c8427c60377).(char * str) { |
| 97 | auto _ __attribute__((unused)) = write(FDcxx . . $ tprintf/FD., str, strlen(str)); |
| 98 | } |
| 99 | |
| 100 | inline void writevalcxx . . $ tprintf/writeval(44b6ea1973a07080).(const char c) { |
| 101 | char buf[1]; |
| 102 | buf[0] = c; |
| 103 | auto _ __attribute__((unused)) = write(FDcxx . . $ tprintf/FD., buf, 1); |
| 104 | } |
| 105 | |
| 106 | inline void writevalcxx . . $ tprintf/writeval(2c44cd906ae4e829).(uint64_tcxx . . $ uint64_t# n) { |
| 107 | char buf[MAXBUFcxx . . $ tprintf/MAXBUF.]; |
| 108 | auto len = itoacxx . . $ tprintf/itoa(9d69a0895ef8e6d).(buf, n); |
| 109 | auto _ __attribute__((unused)) = write(FDcxx . . $ tprintf/FD., buf, len); |
| 110 | } |
| 111 | |
| 112 | template <class T> |
| 113 | inline void writevalcxx . . $ tprintf/writeval(9b289cee16747614).(T n) { |
| 114 | char buf[MAXBUFcxx . . $ tprintf/MAXBUF.]; |
| 115 | auto len = itoacxx . . $ tprintf/itoa(9d69a0895ef8e6d).(buf, n); |
| 116 | auto _ __attribute__((unused)) = write(FDcxx . . $ tprintf/FD., buf, len); |
| 117 | } |
| 118 | |
| 119 | inline void tprintfcxx . . $ tprintf/tprintf(85c52e162fed56f9).(const char* format) // base function |
| 120 | { |
| 121 | writevalcxx . . $ tprintf/writeval(85c52e162fed56f9).(format); |
| 122 | } |
| 123 | |
| 124 | template<typename T, typename... Targs> |
| 125 | inline void tprintfcxx . . $ tprintf/tprintf(f744677dd3ca101c).(const char * format, T value, Targs... Fargs) |
| 126 | { |
| 127 | for ( ; *format != '\0'; format++ ) { |
| 128 | if ( *format == '@' ) { |
| 129 | if ( *(format + 1) == '@') { |
| 130 | writevalcxx . . $ tprintf/writeval(85c52e162fed56f9).("@"); |
| 131 | format = format+2; |
| 132 | } else { |
| 133 | writevalcxx . . $ tprintf/writeval(ba8836b59fb42830).(value); |
| 134 | tprintfcxx . . $ tprintf/tprintf(f744677dd3ca101c).(format+1, Fargs...); |
| 135 | return; |
| 136 | } |
| 137 | } |
| 138 | writevalcxx . . $ tprintf/writeval(44b6ea1973a07080).(*format); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | } |
| 143 | |
| 144 | #endif // !_WIN32 |
| 145 | |
| 146 | #endif |