dclib-tables.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. /***************************************************************************
  2. * *
  3. * _____ ____ *
  4. * | __ \ / __ \ _ _ _____ *
  5. * | | \ \ / / \_\ | | | | _ \ *
  6. * | | \ \| | | | | | |_| | *
  7. * | | | || | | | | | ___/ *
  8. * | | / /| | __ | | | | _ \ *
  9. * | |__/ / \ \__/ / | |___| | |_| | *
  10. * |_____/ \____/ |_____|_|_____/ *
  11. * *
  12. * Wiimms source code library *
  13. * *
  14. ***************************************************************************
  15. * *
  16. * Copyright (c) 2012-2022 by Dirk Clemens <wiimm@wiimm.de> *
  17. * *
  18. ***************************************************************************
  19. * *
  20. * This library is free software; you can redistribute it and/or modify *
  21. * it under the terms of the GNU General Public License as published by *
  22. * the Free Software Foundation; either version 2 of the License, or *
  23. * (at your option) any later version. *
  24. * *
  25. * This library is distributed in the hope that it will be useful, *
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  28. * GNU General Public License for more details. *
  29. * *
  30. * See file gpl-2.0.txt or http://www.gnu.org/licenses/gpl-2.0.txt *
  31. * *
  32. ***************************************************************************/
  33. #define _GNU_SOURCE 1
  34. #include <time.h>
  35. #include <utime.h>
  36. #include <sys/types.h>
  37. #include <sys/stat.h>
  38. #include <sys/socket.h>
  39. #include <sys/un.h>
  40. #include <sys/time.h>
  41. #include "dclib-basics.h"
  42. #include "dclib-utf8.h"
  43. #include "dclib-file.h"
  44. #include "dclib-option.h"
  45. #include "dclib-network.h"
  46. #include "dclib-regex.h"
  47. #include "dclib-xdump.h"
  48. #include "dclib-ui.h"
  49. #ifdef DCLIB_MYSQL
  50. #include "dclib-mysql.h"
  51. #endif
  52. #if DCLIB_TERMINAL
  53. #include "dclib-terminal.h"
  54. #endif
  55. #if DCLIB_THREAD
  56. #include "dclib-thread.h"
  57. #endif
  58. //
  59. ///////////////////////////////////////////////////////////////////////////////
  60. /////////////// table element abbreviations ///////////////
  61. ///////////////////////////////////////////////////////////////////////////////
  62. #define DN DECODE_NULL
  63. #define DC DECODE_CONTROL
  64. #define DL DECODE_LINE
  65. #define DS DECODE_SPACE
  66. #define DP DECODE_SEPARATE
  67. #define DF DECODE_FILLER
  68. #define DX DECODE_OTHER
  69. //
  70. ///////////////////////////////////////////////////////////////////////////////
  71. /////////////// bits ///////////////
  72. ///////////////////////////////////////////////////////////////////////////////
  73. const uchar TableBitCount[0x100] =
  74. {
  75. 0,1,1,2, 1,2,2,3, 1,2,2,3, 2,3,3,4,
  76. 1,2,2,3, 2,3,3,4, 2,3,3,4, 3,4,4,5,
  77. 1,2,2,3, 2,3,3,4, 2,3,3,4, 3,4,4,5,
  78. 2,3,3,4, 3,4,4,5, 3,4,4,5, 4,5,5,6,
  79. 1,2,2,3, 2,3,3,4, 2,3,3,4, 3,4,4,5,
  80. 2,3,3,4, 3,4,4,5, 3,4,4,5, 4,5,5,6,
  81. 2,3,3,4, 3,4,4,5, 3,4,4,5, 4,5,5,6,
  82. 3,4,4,5, 4,5,5,6, 4,5,5,6, 5,6,6,7,
  83. 1,2,2,3, 2,3,3,4, 2,3,3,4, 3,4,4,5,
  84. 2,3,3,4, 3,4,4,5, 3,4,4,5, 4,5,5,6,
  85. 2,3,3,4, 3,4,4,5, 3,4,4,5, 4,5,5,6,
  86. 3,4,4,5, 4,5,5,6, 4,5,5,6, 5,6,6,7,
  87. 2,3,3,4, 3,4,4,5, 3,4,4,5, 4,5,5,6,
  88. 3,4,4,5, 4,5,5,6, 4,5,5,6, 5,6,6,7,
  89. 3,4,4,5, 4,5,5,6, 4,5,5,6, 5,6,6,7,
  90. 4,5,5,6, 5,6,6,7, 5,6,6,7, 6,7,7,8
  91. };
  92. ///////////////////////////////////////////////////////////////////////////////
  93. const char TableLowest0Bit[0x100] =
  94. {
  95. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,4,
  96. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,5,
  97. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,4,
  98. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,6,
  99. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,4,
  100. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,5,
  101. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,4,
  102. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,7,
  103. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,4,
  104. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,5,
  105. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,4,
  106. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,6,
  107. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,4,
  108. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,5,
  109. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,4,
  110. 0,1,0,2, 0,1,0,3, 0,1,0,2, 0,1,0,-1
  111. };
  112. ///////////////////////////////////////////////////////////////////////////////
  113. const char TableLowest1Bit[0x100] =
  114. {
  115. -1,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  116. 4,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  117. 5,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  118. 4,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  119. 6,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  120. 4,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  121. 5,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  122. 4,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  123. 7,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  124. 4,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  125. 5,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  126. 4,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  127. 6,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  128. 4,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  129. 5,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0,
  130. 4,0,1,0, 2,0,1,0, 3,0,1,0, 2,0,1,0
  131. };
  132. ///////////////////////////////////////////////////////////////////////////////
  133. const char TableHighest0Bit[0x100] =
  134. {
  135. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  136. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  137. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  138. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  139. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  140. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  141. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  142. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  143. 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6,
  144. 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6,
  145. 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6,
  146. 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6,
  147. 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5,
  148. 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5,
  149. 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4,
  150. 3,3,3,3, 3,3,3,3, 2,2,2,2, 1,1,0,-1
  151. };
  152. ///////////////////////////////////////////////////////////////////////////////
  153. const char TableHighest1Bit[0x100] =
  154. {
  155. -1,0,1,1, 2,2,2,2, 3,3,3,3, 3,3,3,3,
  156. 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4,
  157. 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5,
  158. 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5,
  159. 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6,
  160. 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6,
  161. 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6,
  162. 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6,
  163. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  164. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  165. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  166. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  167. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  168. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  169. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7,
  170. 7,7,7,7, 7,7,7,7, 7,7,7,7, 7,7,7,7
  171. };
  172. //
  173. ///////////////////////////////////////////////////////////////////////////////
  174. /////////////// scanning numbers ///////////////
  175. ///////////////////////////////////////////////////////////////////////////////
  176. const char TableNumbers[256] =
  177. {
  178. DN, DC, DC, DC, DC, DC, DC, DC, DC, DS, DL, DC, DS, DL, DC, DC,
  179. DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC,
  180. DS, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DP, DX, DX, DX,
  181. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, DX, DP, DX, DX, DX, DX,
  182. DX, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  183. 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, DX, DX, DX, DX, DX,
  184. DX, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  185. 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, DX, DX, DX, DX, DX,
  186. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX,
  187. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX,
  188. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX,
  189. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX,
  190. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX,
  191. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX,
  192. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX,
  193. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX,
  194. };
  195. //
  196. ///////////////////////////////////////////////////////////////////////////////
  197. /////////////// CRC32 support ///////////////
  198. ///////////////////////////////////////////////////////////////////////////////
  199. const u32 TableCRC32[0x100] =
  200. {
  201. 0x00000000,0x77073096,0xee0e612c,0x990951ba, 0x076dc419,0x706af48f,0xe963a535,0x9e6495a3,
  202. 0x0edb8832,0x79dcb8a4,0xe0d5e91e,0x97d2d988, 0x09b64c2b,0x7eb17cbd,0xe7b82d07,0x90bf1d91,
  203. 0x1db71064,0x6ab020f2,0xf3b97148,0x84be41de, 0x1adad47d,0x6ddde4eb,0xf4d4b551,0x83d385c7,
  204. 0x136c9856,0x646ba8c0,0xfd62f97a,0x8a65c9ec, 0x14015c4f,0x63066cd9,0xfa0f3d63,0x8d080df5,
  205. 0x3b6e20c8,0x4c69105e,0xd56041e4,0xa2677172, 0x3c03e4d1,0x4b04d447,0xd20d85fd,0xa50ab56b,
  206. 0x35b5a8fa,0x42b2986c,0xdbbbc9d6,0xacbcf940, 0x32d86ce3,0x45df5c75,0xdcd60dcf,0xabd13d59,
  207. 0x26d930ac,0x51de003a,0xc8d75180,0xbfd06116, 0x21b4f4b5,0x56b3c423,0xcfba9599,0xb8bda50f,
  208. 0x2802b89e,0x5f058808,0xc60cd9b2,0xb10be924, 0x2f6f7c87,0x58684c11,0xc1611dab,0xb6662d3d,
  209. 0x76dc4190,0x01db7106,0x98d220bc,0xefd5102a, 0x71b18589,0x06b6b51f,0x9fbfe4a5,0xe8b8d433,
  210. 0x7807c9a2,0x0f00f934,0x9609a88e,0xe10e9818, 0x7f6a0dbb,0x086d3d2d,0x91646c97,0xe6635c01,
  211. 0x6b6b51f4,0x1c6c6162,0x856530d8,0xf262004e, 0x6c0695ed,0x1b01a57b,0x8208f4c1,0xf50fc457,
  212. 0x65b0d9c6,0x12b7e950,0x8bbeb8ea,0xfcb9887c, 0x62dd1ddf,0x15da2d49,0x8cd37cf3,0xfbd44c65,
  213. 0x4db26158,0x3ab551ce,0xa3bc0074,0xd4bb30e2, 0x4adfa541,0x3dd895d7,0xa4d1c46d,0xd3d6f4fb,
  214. 0x4369e96a,0x346ed9fc,0xad678846,0xda60b8d0, 0x44042d73,0x33031de5,0xaa0a4c5f,0xdd0d7cc9,
  215. 0x5005713c,0x270241aa,0xbe0b1010,0xc90c2086, 0x5768b525,0x206f85b3,0xb966d409,0xce61e49f,
  216. 0x5edef90e,0x29d9c998,0xb0d09822,0xc7d7a8b4, 0x59b33d17,0x2eb40d81,0xb7bd5c3b,0xc0ba6cad,
  217. 0xedb88320,0x9abfb3b6,0x03b6e20c,0x74b1d29a, 0xead54739,0x9dd277af,0x04db2615,0x73dc1683,
  218. 0xe3630b12,0x94643b84,0x0d6d6a3e,0x7a6a5aa8, 0xe40ecf0b,0x9309ff9d,0x0a00ae27,0x7d079eb1,
  219. 0xf00f9344,0x8708a3d2,0x1e01f268,0x6906c2fe, 0xf762575d,0x806567cb,0x196c3671,0x6e6b06e7,
  220. 0xfed41b76,0x89d32be0,0x10da7a5a,0x67dd4acc, 0xf9b9df6f,0x8ebeeff9,0x17b7be43,0x60b08ed5,
  221. 0xd6d6a3e8,0xa1d1937e,0x38d8c2c4,0x4fdff252, 0xd1bb67f1,0xa6bc5767,0x3fb506dd,0x48b2364b,
  222. 0xd80d2bda,0xaf0a1b4c,0x36034af6,0x41047a60, 0xdf60efc3,0xa867df55,0x316e8eef,0x4669be79,
  223. 0xcb61b38c,0xbc66831a,0x256fd2a0,0x5268e236, 0xcc0c7795,0xbb0b4703,0x220216b9,0x5505262f,
  224. 0xc5ba3bbe,0xb2bd0b28,0x2bb45a92,0x5cb36a04, 0xc2d7ffa7,0xb5d0cf31,0x2cd99e8b,0x5bdeae1d,
  225. 0x9b64c2b0,0xec63f226,0x756aa39c,0x026d930a, 0x9c0906a9,0xeb0e363f,0x72076785,0x05005713,
  226. 0x95bf4a82,0xe2b87a14,0x7bb12bae,0x0cb61b38, 0x92d28e9b,0xe5d5be0d,0x7cdcefb7,0x0bdbdf21,
  227. 0x86d3d2d4,0xf1d4e242,0x68ddb3f8,0x1fda836e, 0x81be16cd,0xf6b9265b,0x6fb077e1,0x18b74777,
  228. 0x88085ae6,0xff0f6a70,0x66063bca,0x11010b5c, 0x8f659eff,0xf862ae69,0x616bffd3,0x166ccf45,
  229. 0xa00ae278,0xd70dd2ee,0x4e048354,0x3903b3c2, 0xa7672661,0xd06016f7,0x4969474d,0x3e6e77db,
  230. 0xaed16a4a,0xd9d65adc,0x40df0b66,0x37d83bf0, 0xa9bcae53,0xdebb9ec5,0x47b2cf7f,0x30b5ffe9,
  231. 0xbdbdf21c,0xcabac28a,0x53b39330,0x24b4a3a6, 0xbad03605,0xcdd70693,0x54de5729,0x23d967bf,
  232. 0xb3667a2e,0xc4614ab8,0x5d681b02,0x2a6f2b94, 0xb40bbe37,0xc30c8ea1,0x5a05df1b,0x2d02ef8d,
  233. };
  234. //
  235. ///////////////////////////////////////////////////////////////////////////////
  236. /////////////// helpers for codepages ///////////////
  237. ///////////////////////////////////////////////////////////////////////////////
  238. const u16 TableCP1252_80[0x20] =
  239. {
  240. 0x20ac, 0,0x201a,0x0192, 0x201e,0x2026,0x2020,0x2021, // 80..87
  241. 0x02c6,0x2030,0x0160,0x2039, 0x0152, 0,0x017d, 0, // 88..8f
  242. 0,0x2018,0x2019,0x201c, 0x201d,0x2022,0x2013,0x2014, // 90..97
  243. 0x02dc,0x2122,0x0161,0x203a, 0x0153, 0,0x017e,0x0178, // 98..9f
  244. };
  245. //
  246. ///////////////////////////////////////////////////////////////////////////////
  247. /////////////// BASE64 support ///////////////
  248. ///////////////////////////////////////////////////////////////////////////////
  249. // https://en.wikipedia.org/wiki/Base64
  250. char TableDecode64[256] =
  251. {
  252. DN, DC, DC, DC, DC, DC, DC, DC, DC, DS, DS, DC, DS, DS, DC, DC, // 0x
  253. DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, // 1x
  254. DS, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, 62, DP, DX, DX, 63, // 2x
  255. 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, DX, DP, DX, DF, DX, DX, // 3x
  256. DX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 4x
  257. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, DX, DX, DX, DX, DX, // 5x
  258. DX, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 6x
  259. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, DX, DX, DX, DX, DX, // 7x
  260. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // 8x
  261. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // 9x
  262. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Ax
  263. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Bx
  264. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Cx
  265. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Dx
  266. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Ex
  267. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX // Fx
  268. };
  269. ///////////////////////////////////////////////////////////////////////////////
  270. char TableDecode64url[256] =
  271. {
  272. DN, DC, DC, DC, DC, DC, DC, DC, DC, DS, DS, DC, DS, DS, DC, DC, // 0x
  273. DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, // 1x
  274. DS, DX, DX, DX, DX, DX, DX, DX, DX, DX, DF, 62, DP, 62, DX, 63, // 2x
  275. 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, DX, DP, DX, DF, DX, DX, // 3x
  276. DX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 4x
  277. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, DX, DX, DX, DX, 63, // 5x
  278. DX, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 6x
  279. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, DX, DX, DX, DX, DX, // 7x
  280. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // 8x
  281. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // 9x
  282. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Ax
  283. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Bx
  284. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Cx
  285. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Dx
  286. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Ex
  287. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX // Fx
  288. };
  289. ///////////////////////////////////////////////////////////////////////////////
  290. char TableDecode64xml[256] =
  291. {
  292. DN, DC, DC, DC, DC, DC, DC, DC, DC, DS, DS, DC, DS, DS, DC, DC, // 0x
  293. DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, DC, // 1x
  294. DS, DX, DX, DX, DX, DX, DX, DX, DX, DX, DF, 62, DP, 63, 62, 63, // 2x
  295. 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 63, DP, DX, DF, DX, DX, // 3x
  296. DX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 4x
  297. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, DX, DX, DX, DX, 62, // 5x
  298. DX, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 6x
  299. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, DX, DX, DX, DX, DX, // 7x
  300. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // 8x
  301. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // 9x
  302. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Ax
  303. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Bx
  304. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Cx
  305. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Dx
  306. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, // Ex
  307. DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX, DX // Fx
  308. };
  309. ///////////////////////////////////////////////////////////////////////////////
  310. const char TableEncode64[64+1] =
  311. {
  312. 'A','B','C','D','E','F','G','H','I','J','K','L','M',
  313. 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
  314. 'a','b','c','d','e','f','g','h','i','j','k','l','m',
  315. 'n','o','p','q','r','s','t','u','v','w','x','y','z',
  316. '0','1','2','3','4','5','6','7','8','9',
  317. '+','/',
  318. '=' // fill char
  319. };
  320. ///////////////////////////////////////////////////////////////////////////////
  321. const char TableEncode64url[64+1] =
  322. {
  323. 'A','B','C','D','E','F','G','H','I','J','K','L','M',
  324. 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
  325. 'a','b','c','d','e','f','g','h','i','j','k','l','m',
  326. 'n','o','p','q','r','s','t','u','v','w','x','y','z',
  327. '0','1','2','3','4','5','6','7','8','9',
  328. '-','_',
  329. '=' // fill char
  330. };
  331. ///////////////////////////////////////////////////////////////////////////////
  332. const char TableEncode64star[64+1] =
  333. {
  334. 'A','B','C','D','E','F','G','H','I','J','K','L','M',
  335. 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
  336. 'a','b','c','d','e','f','g','h','i','j','k','l','m',
  337. 'n','o','p','q','r','s','t','u','v','w','x','y','z',
  338. '0','1','2','3','4','5','6','7','8','9',
  339. '-','_',
  340. '*' // fill char
  341. };
  342. ///////////////////////////////////////////////////////////////////////////////
  343. const char TableEncode64xml[64+1] =
  344. {
  345. 'A','B','C','D','E','F','G','H','I','J','K','L','M',
  346. 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
  347. 'a','b','c','d','e','f','g','h','i','j','k','l','m',
  348. 'n','o','p','q','r','s','t','u','v','w','x','y','z',
  349. '0','1','2','3','4','5','6','7','8','9',
  350. '.','-',
  351. '*' // fill char
  352. };
  353. ///////////////////////////////////////////////////////////////////////////////
  354. // for tests: encode the 48 bytes to get the full BASE64 alphabet
  355. const u8 TableAlphabet64[48] =
  356. {
  357. 0x00,0x10,0x83,0x10, 0x51,0x87,0x20,0x92, 0x8b,0x30,0xd3,0x8f, 0x41,0x14,0x93,0x51,
  358. 0x55,0x97,0x61,0x96, 0x9b,0x71,0xd7,0x9f, 0x82,0x18,0xa3,0x92, 0x59,0xa7,0xa2,0x9a,
  359. 0xab,0xb2,0xdb,0xaf, 0xc3,0x1c,0xb3,0xd3, 0x5d,0xb7,0xe3,0x9e, 0xbb,0xf3,0xdf,0xbf,
  360. };
  361. //
  362. ///////////////////////////////////////////////////////////////////////////////
  363. /////////////// sizeof_info_t ///////////////
  364. ///////////////////////////////////////////////////////////////////////////////
  365. const sizeof_info_t sizeof_info_linux[] =
  366. {
  367. SIZEOF_INFO_TITLE("Basic C types")
  368. SIZEOF_INFO_ENTRY(char)
  369. SIZEOF_INFO_ENTRY(wchar_t)
  370. SIZEOF_INFO_ENTRY(short)
  371. SIZEOF_INFO_ENTRY(int)
  372. SIZEOF_INFO_ENTRY(long)
  373. SIZEOF_INFO_ENTRY(long long)
  374. #ifdef __SIZEOF_INT128__
  375. SIZEOF_INFO_ENTRY(__int128_t)
  376. #endif
  377. SIZEOF_INFO_ENTRY(float)
  378. SIZEOF_INFO_ENTRY(double)
  379. SIZEOF_INFO_ENTRY(long double)
  380. SIZEOF_INFO_ENTRY(void*)
  381. SIZEOF_INFO_TITLE("Linux C types")
  382. SIZEOF_INFO_ENTRY(size_t)
  383. SIZEOF_INFO_ENTRY(time_t)
  384. SIZEOF_INFO_ENTRY(struct timeval)
  385. SIZEOF_INFO_ENTRY(struct timespec)
  386. SIZEOF_INFO_ENTRY(struct tm)
  387. SIZEOF_INFO_ENTRY(struct timezone)
  388. SIZEOF_INFO_ENTRY(struct utimbuf)
  389. SIZEOF_INFO_ENTRY(struct stat)
  390. SIZEOF_INFO_ENTRY(fd_set)
  391. SIZEOF_INFO_TERM()
  392. };
  393. ///////////////////////////////////////////////////////////////////////////////
  394. const sizeof_info_t sizeof_info_dclib[] =
  395. {
  396. SIZEOF_INFO_TITLE("dcLib basic types")
  397. SIZEOF_INFO_ENTRY(bool)
  398. SIZEOF_INFO_ENTRY(u8)
  399. SIZEOF_INFO_ENTRY(u16)
  400. SIZEOF_INFO_ENTRY(u32)
  401. SIZEOF_INFO_ENTRY(u64)
  402. #if HAVE_INT128
  403. SIZEOF_INFO_ENTRY(u128)
  404. #endif
  405. SIZEOF_INFO_ENTRY(intx_t)
  406. SIZEOF_INFO_ENTRY(mem_t)
  407. SIZEOF_INFO_ENTRY(exmem_t)
  408. SIZEOF_INFO_TITLE("dcLib time & timer")
  409. SIZEOF_INFO_ENTRY(u_sec_t)
  410. SIZEOF_INFO_ENTRY(u_msec_t)
  411. SIZEOF_INFO_ENTRY(u_usec_t)
  412. SIZEOF_INFO_ENTRY(u_nsec_t)
  413. SIZEOF_INFO_ENTRY(DayTime_t)
  414. SIZEOF_INFO_ENTRY(CurrentTime_t)
  415. SIZEOF_INFO_TITLE("dcLib numeric & strings")
  416. SIZEOF_INFO_ENTRY(float3)
  417. SIZEOF_INFO_ENTRY(float3List_t)
  418. SIZEOF_INFO_ENTRY(double3)
  419. SIZEOF_INFO_ENTRY(double3List_t)
  420. SIZEOF_INFO_ENTRY(float34)
  421. SIZEOF_INFO_ENTRY(double34)
  422. SIZEOF_INFO_ENTRY(MatrixD_t)
  423. SIZEOF_INFO_ENTRY(RegexReplace_t)
  424. SIZEOF_INFO_ENTRY(RegexElem_t)
  425. SIZEOF_INFO_ENTRY(Regex_t)
  426. SIZEOF_INFO_ENTRY(dcUnicodeTripel)
  427. SIZEOF_INFO_ENTRY(Escape_t)
  428. SIZEOF_INFO_TITLE("dcLib buffers")
  429. SIZEOF_INFO_ENTRY(exmem_dest_t)
  430. SIZEOF_INFO_ENTRY(sha1_hash_t)
  431. SIZEOF_INFO_ENTRY(sha1_hex_t)
  432. SIZEOF_INFO_ENTRY(sha1_id_t)
  433. SIZEOF_INFO_ENTRY(uuid_text_t)
  434. SIZEOF_INFO_ENTRY(CircBuf_t)
  435. SIZEOF_INFO_ENTRY(FastBuf_t)
  436. SIZEOF_INFO_ENTRY(ContainerData_t)
  437. SIZEOF_INFO_ENTRY(Container_t)
  438. SIZEOF_INFO_ENTRY(DataBuf_t)
  439. SIZEOF_INFO_ENTRY(GrowBuffer_t)
  440. SIZEOF_INFO_TITLE("dcLib lists")
  441. SIZEOF_INFO_ENTRY(mem_src_t)
  442. SIZEOF_INFO_ENTRY(mem_list_t)
  443. SIZEOF_INFO_ENTRY(exmem_key_t)
  444. SIZEOF_INFO_ENTRY(exmem_list_t)
  445. SIZEOF_INFO_ENTRY(sizeof_info_t)
  446. SIZEOF_INFO_ENTRY(PointerList_t)
  447. SIZEOF_INFO_ENTRY(KeywordTab_t)
  448. SIZEOF_INFO_ENTRY(StringField_t)
  449. SIZEOF_INFO_ENTRY(ParamFieldItem_t)
  450. SIZEOF_INFO_ENTRY(ParamField_t)
  451. SIZEOF_INFO_ENTRY(SplitArg_t)
  452. SIZEOF_INFO_ENTRY(ArgManager_t)
  453. SIZEOF_INFO_ENTRY(CommandList_t)
  454. SIZEOF_INFO_ENTRY(MemMapItem_t)
  455. SIZEOF_INFO_ENTRY(MemMap_t)
  456. SIZEOF_INFO_ENTRY(DynData_t)
  457. SIZEOF_INFO_ENTRY(DynDataList_t)
  458. SIZEOF_INFO_ENTRY(MemPoolChunk_t)
  459. SIZEOF_INFO_ENTRY(MemPool_t)
  460. SIZEOF_INFO_ENTRY(GenericOptParm_t)
  461. SIZEOF_INFO_ENTRY(GenericOpt_t)
  462. SIZEOF_INFO_ENTRY(GParam_t)
  463. SIZEOF_INFO_ENTRY(GOptions_t)
  464. SIZEOF_INFO_ENTRY(InfoOption_t)
  465. SIZEOF_INFO_ENTRY(InfoCommand_t)
  466. SIZEOF_INFO_ENTRY(InfoUI_t)
  467. SIZEOF_INFO_TITLE("dcLib file")
  468. SIZEOF_INFO_ENTRY(LogFile_t)
  469. SIZEOF_INFO_ENTRY(FileAttrib_t)
  470. SIZEOF_INFO_ENTRY(File_t)
  471. SIZEOF_INFO_ENTRY(MemFile_t)
  472. SIZEOF_INFO_ENTRY(TraceLog_t)
  473. #ifndef __APPLE__
  474. SIZEOF_INFO_ENTRY(LineBuffer_t)
  475. #endif
  476. SIZEOF_INFO_ENTRY(search_file_t)
  477. SIZEOF_INFO_ENTRY(search_file_list_t)
  478. SIZEOF_INFO_ENTRY(search_paths_stat_t)
  479. SIZEOF_INFO_ENTRY(CatchOutput_t)
  480. SIZEOF_INFO_ENTRY(SectionInfo_t)
  481. SIZEOF_INFO_ENTRY(stat_file_count_t)
  482. SIZEOF_INFO_ENTRY(PrintScript_t)
  483. SIZEOF_INFO_ENTRY(RestoreState_t)
  484. SIZEOF_INFO_ENTRY(RestoreStateTab_t)
  485. SIZEOF_INFO_ENTRY(SaveRestoreType_t)
  486. SIZEOF_INFO_ENTRY(SaveRestoreTab_t)
  487. #ifdef DCLIB_MYSQL
  488. SIZEOF_INFO_ENTRY(MySqlStatus_t)
  489. SIZEOF_INFO_ENTRY(MySqlResult_t)
  490. SIZEOF_INFO_ENTRY(MySql_t)
  491. SIZEOF_INFO_ENTRY(MySqlServerStats_t)
  492. #endif
  493. SIZEOF_INFO_TITLE("dcLib network")
  494. SIZEOF_INFO_ENTRY(ipv4_t)
  495. SIZEOF_INFO_ENTRY(ipv4x_t)
  496. SIZEOF_INFO_ENTRY(ipv6_t)
  497. SIZEOF_INFO_ENTRY(sockaddr_t)
  498. SIZEOF_INFO_ENTRY(sockaddr_in4_t)
  499. SIZEOF_INFO_ENTRY(sockaddr_in6_t)
  500. SIZEOF_INFO_ENTRY(sockaddr_in46_t)
  501. SIZEOF_INFO_ENTRY(sockaddr_un_t)
  502. SIZEOF_INFO_ENTRY(sockaddr_dclib_t)
  503. SIZEOF_INFO_ENTRY(sockaddr_info_t)
  504. SIZEOF_INFO_ENTRY(socket_info_t)
  505. SIZEOF_INFO_ENTRY(FDList_t)
  506. SIZEOF_INFO_ENTRY(SplitIP_t)
  507. SIZEOF_INFO_ENTRY(NamesIP_t)
  508. SIZEOF_INFO_ENTRY(BinIP_t)
  509. SIZEOF_INFO_ENTRY(BinIPItem_t)
  510. SIZEOF_INFO_ENTRY(BinIPList_t)
  511. SIZEOF_INFO_ENTRY(BinIPIterate_t)
  512. SIZEOF_INFO_ENTRY(ManageIP_t)
  513. SIZEOF_INFO_ENTRY(ResolveIP_t)
  514. SIZEOF_INFO_ENTRY(NetworkHost_t)
  515. SIZEOF_INFO_ENTRY(AllowIP4Item_t)
  516. SIZEOF_INFO_ENTRY(AllowIP4_t)
  517. SIZEOF_INFO_ENTRY(ether_head_t)
  518. SIZEOF_INFO_ENTRY(ether_head_vlan_t)
  519. SIZEOF_INFO_ENTRY(arp_head_t)
  520. SIZEOF_INFO_ENTRY(ip4_head_t)
  521. SIZEOF_INFO_ENTRY(udp_head_t)
  522. SIZEOF_INFO_ENTRY(udp_packet_t)
  523. SIZEOF_INFO_ENTRY(tcp_head_t)
  524. SIZEOF_INFO_ENTRY(TransferStats_t)
  525. SIZEOF_INFO_ENTRY(Socket_t)
  526. SIZEOF_INFO_ENTRY(TCPStream_t)
  527. SIZEOF_INFO_ENTRY(TCPHandler_t)
  528. SIZEOF_INFO_ENTRY(CommandTCPInfo_t)
  529. #if defined(SYSTEM_LINUX) || defined(__CYGWIN__)
  530. SIZEOF_INFO_ENTRY(RouteIP4_t)
  531. #endif
  532. #if DCLIB_TERMINAL
  533. SIZEOF_INFO_TITLE("dcLib terminal & colors")
  534. #else
  535. SIZEOF_INFO_TITLE("dcLib colors")
  536. #endif
  537. SIZEOF_INFO_ENTRY(term_size_t)
  538. SIZEOF_INFO_ENTRY(good_term_width_t)
  539. SIZEOF_INFO_ENTRY(TermColorId_t)
  540. SIZEOF_INFO_ENTRY(ColorSet_t)
  541. SIZEOF_INFO_ENTRY(ColorView_t)
  542. SIZEOF_INFO_ENTRY(SavedStdFiles_t)
  543. #if DCLIB_TERMINAL
  544. SIZEOF_INFO_ENTRY(History_t)
  545. SIZEOF_INFO_ENTRY(TelnetRepeat_t)
  546. SIZEOF_INFO_ENTRY(TelnetParam_t)
  547. SIZEOF_INFO_ENTRY(TelnetTCPInfo_t)
  548. SIZEOF_INFO_ENTRY(TelnetClient_t)
  549. SIZEOF_INFO_ENTRY(TerminalKey_t)
  550. SIZEOF_INFO_ENTRY(TerminalInfo_t)
  551. SIZEOF_INFO_ENTRY(TerminalNameList_t)
  552. SIZEOF_INFO_ENTRY(Keyboard_t)
  553. #endif
  554. #if DCLIB_THREAD
  555. SIZEOF_INFO_TITLE("dcLib threads")
  556. SIZEOF_INFO_ENTRY(WatchdogThread_t)
  557. #endif
  558. SIZEOF_INFO_TITLE("dcLib statistics")
  559. SIZEOF_INFO_ENTRY(UsageParam_t)
  560. SIZEOF_INFO_ENTRY(UsageCountEntry_t)
  561. SIZEOF_INFO_ENTRY(UsageCount_t)
  562. SIZEOF_INFO_ENTRY(UsageDurationEntry_t)
  563. SIZEOF_INFO_ENTRY(UsageDuration_t)
  564. SIZEOF_INFO_ENTRY(CpuUsageEntry_t)
  565. SIZEOF_INFO_ENTRY(CpuUsage_t)
  566. SIZEOF_INFO_ENTRY(UsageCtrl_t)
  567. SIZEOF_INFO_ENTRY(usage_count_mgr)
  568. SIZEOF_INFO_ENTRY(CpuStatus_t)
  569. SIZEOF_INFO_ENTRY(MemoryStatus_t)
  570. SIZEOF_INFO_TITLE("dcLib misc")
  571. SIZEOF_INFO_ENTRY(ProgInfo_t)
  572. SIZEOF_INFO_ENTRY(IntervalInfo_t)
  573. SIZEOF_INFO_ENTRY(MultiColumn_t)
  574. SIZEOF_INFO_ENTRY(ScanAddr_t)
  575. SIZEOF_INFO_ENTRY(ResizeElement_t)
  576. SIZEOF_INFO_ENTRY(ResizeHelper_t)
  577. SIZEOF_INFO_ENTRY(XDump_t)
  578. SIZEOF_INFO_TERM()
  579. };
  580. ///////////////////////////////////////////////////////////////////////////////
  581. const sizeof_info_t *sizeof_info_default[] =
  582. {
  583. sizeof_info_linux,
  584. sizeof_info_dclib,
  585. 0
  586. };
  587. PointerList_t SizeofInfoMgr = {0};
  588. ///////////////////////////////////////////////////////////////////////////////
  589. static int compare_sizeof_size
  590. ( const sizeof_info_t *a, const sizeof_info_t *b )
  591. {
  592. DASSERT( a && b );
  593. const int stat = a->size - b->size;
  594. return stat ? stat : strcasecmp(a->name,b->name);
  595. }
  596. //-----------------------------------------------------------------------------
  597. static int compare_sizeof_name
  598. ( const sizeof_info_t *a, const sizeof_info_t *b )
  599. {
  600. DASSERT( a && b );
  601. return strcasecmp(a->name,b->name);
  602. }
  603. ///////////////////////////////////////////////////////////////////////////////
  604. void ListSizeofInfo
  605. (
  606. const PrintMode_t *p_pm, // NULL or print mode
  607. const sizeof_info_t **si_list, // list of list of entries
  608. ArgManager_t *p_filter, // NULL or filter arguments, LOUP_LOWER recommended
  609. sizeof_info_order_t order // kind of order
  610. )
  611. {
  612. if ( !si_list || !*si_list )
  613. return;
  614. //--- setup
  615. PrintMode_t pm = {0};
  616. if (p_pm)
  617. pm = *p_pm;
  618. SetupPrintMode(&pm);
  619. if (!si_list)
  620. {
  621. si_list = GetSizeofInfoMgrList();
  622. if (!si_list)
  623. si_list = sizeof_info_default;
  624. }
  625. int n_tabs = 0, n_records = 0, n_elem = 0, n_cat = 0, str_size = 0;;
  626. for ( const sizeof_info_t **si_ptr = si_list; *si_ptr; si_ptr++ )
  627. {
  628. n_tabs++;
  629. for ( const sizeof_info_t *si = *si_ptr; si->size != -9; si++ )
  630. {
  631. n_records++;
  632. if ( si->size >= 0 )
  633. n_elem++;
  634. else if ( si->size == -1 )
  635. n_cat++;
  636. if (si->name)
  637. str_size += strlen(si->name) + 1;
  638. }
  639. }
  640. if ( pm.debug > 0 )
  641. fprintf(pm.flog,"\n%s> %u source list%s with %u record%s, %u categorie%s"
  642. " and %u element%s, %zu bytes total%s%s",
  643. pm.clog->info,
  644. n_tabs, n_tabs == 1 ? "" : "s",
  645. n_records, n_records == 1 ? "" : "s",
  646. n_cat, n_cat == 1 ? "" : "s",
  647. n_elem, n_elem == 1 ? "" : "s",
  648. (n_records+n_tabs) * sizeof(sizeof_info_t) + str_size,
  649. pm.clog->reset, pm.eol );
  650. ArgManager_t my_filter = {0}, *filter = &my_filter;
  651. if (p_filter)
  652. {
  653. if ( p_filter->force_case == LOUP_LOWER )
  654. filter = p_filter;
  655. else
  656. {
  657. for ( int i = 0; i < p_filter->argc; i++ )
  658. AppendArgManager(&my_filter,p_filter->argv[i],0,false);
  659. for ( int i = 0; i < my_filter.argc; i++ )
  660. {
  661. char *arg = my_filter.argv[i];
  662. StringLowerS(arg,strlen(arg)+1,arg);
  663. }
  664. }
  665. }
  666. sizeof_info_t *list = 0, *list_end = 0;
  667. if (order)
  668. list_end = list = MALLOC( n_elem * sizeof(*list) );
  669. //--- get field widths
  670. int max_size = 0;
  671. for ( const sizeof_info_t **si_ptr = si_list; *si_ptr; si_ptr++ )
  672. {
  673. for ( const sizeof_info_t *si = *si_ptr; si->size != -9; si++ )
  674. {
  675. if ( max_size < si->size && CheckFilterArgManager(filter,si->name) )
  676. max_size = si->size;
  677. }
  678. }
  679. char buf[100];
  680. const int fw_hex = snprintf(buf,sizeof(buf),"%#x",max_size);
  681. const int fw_dec = snprintf(buf,sizeof(buf),"%u",max_size);
  682. //--- print or collect
  683. ccp head = 0;
  684. int n_head = 0, n_sizeof = 0;
  685. for ( const sizeof_info_t **si_ptr = si_list; *si_ptr; si_ptr++ )
  686. {
  687. for ( const sizeof_info_t *si = *si_ptr; si->size != -9; si++ )
  688. {
  689. if ( si->size >= 0 )
  690. {
  691. if (CheckFilterArgManager(filter,si->name))
  692. {
  693. n_sizeof++;
  694. if (order)
  695. *list_end++ = *si;
  696. else
  697. {
  698. if (head)
  699. {
  700. n_head++;
  701. fprintf(pm.fout,"\n%s%s%s\n",pm.cout->caption,head,pm.cout->reset);
  702. head = 0;
  703. }
  704. fprintf(pm.fout," %#*x = %*u : %s\n",
  705. fw_hex, si->size, fw_dec, si->size, si->name );
  706. }
  707. }
  708. }
  709. else if ( si->size == -1 )
  710. head = si->name;
  711. else if ( si->size == -2 )
  712. putchar('\n');
  713. }
  714. }
  715. //--- print ordered list
  716. if (order)
  717. {
  718. putchar('\n');
  719. if ( n_sizeof > 1 )
  720. {
  721. if ( order == SIZEOF_ORDER_NAME )
  722. qsort(list,n_sizeof,sizeof(*list),(qsort_func)compare_sizeof_name);
  723. else
  724. qsort(list,n_sizeof,sizeof(*list),(qsort_func)compare_sizeof_size);
  725. }
  726. ccp prev = "";
  727. for ( const sizeof_info_t *ptr = list; ptr < list_end; ptr++ )
  728. {
  729. if (!strcmp(prev,ptr->name))
  730. fprintf(pm.fout,"%s %#*x = %*u : %s%s\n",
  731. pm.cout->warn, fw_hex, ptr->size,
  732. fw_dec, ptr->size, ptr->name, pm.cout->reset );
  733. else
  734. {
  735. fprintf(pm.fout," %#*x = %*u : %s\n",
  736. fw_hex, ptr->size, fw_dec, ptr->size, ptr->name );
  737. prev = ptr->name;
  738. }
  739. }
  740. }
  741. //--- terminate
  742. ResetArgManager(&my_filter);
  743. if ( pm.debug > 0 )
  744. {
  745. putchar('\n');
  746. if (!n_sizeof)
  747. fprintf(pm.flog,"%s> No elements printed.%s\n",pm.cout->info,pm.cout->reset);
  748. else
  749. {
  750. fputs(pm.cout->info,stdout);
  751. fputs("> ",stdout);
  752. if (n_head)
  753. fprintf(pm.flog,"%u head line%s and ", n_head, n_head == 1 ? "" : "s" );
  754. if ( n_sizeof < n_elem )
  755. fprintf(pm.flog,"%u of %u elements printed.%s\n",
  756. n_sizeof, n_elem, pm.cout->reset );
  757. else
  758. fprintf(pm.flog,"%u element%s printed.%s\n",
  759. n_sizeof, n_sizeof == 1 ? "" : "s",
  760. pm.cout->reset );
  761. }
  762. }
  763. putchar('\n');
  764. FREE(list);
  765. }
  766. //
  767. ///////////////////////////////////////////////////////////////////////////////
  768. /////////////// misc ///////////////
  769. ///////////////////////////////////////////////////////////////////////////////
  770. const IntervalInfo_t interval_info[] =
  771. {
  772. { NSEC_PER_SEC, USEC_PER_SEC, "Second" },
  773. { NSEC_PER_MIN, USEC_PER_MIN, "Minute" },
  774. { NSEC_PER_HOUR, USEC_PER_HOUR, "Hour" },
  775. { NSEC_PER_DAY, USEC_PER_DAY, "Day" },
  776. { NSEC_PER_WEEK, USEC_PER_WEEK, "Week" },
  777. { NSEC_PER_MONTH, USEC_PER_MONTH, "Month" },
  778. { NSEC_PER_YEAR, USEC_PER_YEAR, "Year" },
  779. { M1(u_nsec_t), M1(u_usec_t), "*" },
  780. };
  781. //
  782. ///////////////////////////////////////////////////////////////////////////////
  783. /////////////// END ///////////////
  784. ///////////////////////////////////////////////////////////////////////////////