heroku-tokyotyrant 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (340) hide show
  1. data/COPYING +504 -0
  2. data/README.rdoc +231 -0
  3. data/Rakefile +72 -0
  4. data/benchmarks/balancer.rb +101 -0
  5. data/benchmarks/bulk_db.rb +74 -0
  6. data/benchmarks/bulk_table.rb +87 -0
  7. data/benchmarks/db.rb +114 -0
  8. data/benchmarks/table.rb +161 -0
  9. data/ext/extconf.rb +43 -0
  10. data/ext/tokyo/bin/tcamgr +0 -0
  11. data/ext/tokyo/bin/tcamttest +0 -0
  12. data/ext/tokyo/bin/tcatest +0 -0
  13. data/ext/tokyo/bin/tcbmgr +0 -0
  14. data/ext/tokyo/bin/tcbmttest +0 -0
  15. data/ext/tokyo/bin/tcbtest +0 -0
  16. data/ext/tokyo/bin/tcfmgr +0 -0
  17. data/ext/tokyo/bin/tcfmttest +0 -0
  18. data/ext/tokyo/bin/tcftest +0 -0
  19. data/ext/tokyo/bin/tchmgr +0 -0
  20. data/ext/tokyo/bin/tchmttest +0 -0
  21. data/ext/tokyo/bin/tchtest +0 -0
  22. data/ext/tokyo/bin/tcrmgr +0 -0
  23. data/ext/tokyo/bin/tcrmttest +0 -0
  24. data/ext/tokyo/bin/tcrtest +0 -0
  25. data/ext/tokyo/bin/tctmgr +0 -0
  26. data/ext/tokyo/bin/tctmttest +0 -0
  27. data/ext/tokyo/bin/tcttest +0 -0
  28. data/ext/tokyo/bin/tcucodec +0 -0
  29. data/ext/tokyo/bin/tcumttest +0 -0
  30. data/ext/tokyo/bin/tcutest +0 -0
  31. data/ext/tokyo/bin/ttserver +0 -0
  32. data/ext/tokyo/bin/ttulmgr +0 -0
  33. data/ext/tokyo/bin/ttultest +0 -0
  34. data/ext/tokyo/include/tcadb.h +548 -0
  35. data/ext/tokyo/include/tcbdb.h +1101 -0
  36. data/ext/tokyo/include/tcfdb.h +858 -0
  37. data/ext/tokyo/include/tchdb.h +871 -0
  38. data/ext/tokyo/include/tcrdb.h +801 -0
  39. data/ext/tokyo/include/tctdb.h +1086 -0
  40. data/ext/tokyo/include/tculog.h +392 -0
  41. data/ext/tokyo/include/tcutil.h +4184 -0
  42. data/ext/tokyo/include/ttutil.h +494 -0
  43. data/ext/tokyo/lib/libtokyocabinet.9.4.0.dylib +0 -0
  44. data/ext/tokyo/lib/libtokyocabinet.9.dylib +0 -0
  45. data/ext/tokyo/lib/libtokyocabinet.a +0 -0
  46. data/ext/tokyo/lib/libtokyocabinet.dylib +0 -0
  47. data/ext/tokyo/lib/libtokyotyrant.3.22.0.dylib +0 -0
  48. data/ext/tokyo/lib/libtokyotyrant.3.dylib +0 -0
  49. data/ext/tokyo/lib/libtokyotyrant.a +0 -0
  50. data/ext/tokyo/lib/libtokyotyrant.dylib +0 -0
  51. data/ext/tokyo/lib/pkgconfig/tokyocabinet.pc +14 -0
  52. data/ext/tokyo/lib/pkgconfig/tokyotyrant.pc +14 -0
  53. data/ext/tokyo/lib/ttskeldir.bundle +0 -0
  54. data/ext/tokyo/lib/ttskelmock.bundle +0 -0
  55. data/ext/tokyo/lib/ttskelnull.bundle +0 -0
  56. data/ext/tokyo/lib/ttskelproxy.bundle +0 -0
  57. data/ext/tokyo/libexec/tcawmgr.cgi +0 -0
  58. data/ext/tokyo/sbin/ttservctl +163 -0
  59. data/ext/tokyo/share/man/man1/tcamgr.1 +97 -0
  60. data/ext/tokyo/share/man/man1/tcamttest.1 +35 -0
  61. data/ext/tokyo/share/man/man1/tcatest.1 +55 -0
  62. data/ext/tokyo/share/man/man1/tcbmgr.1 +125 -0
  63. data/ext/tokyo/share/man/man1/tcbmttest.1 +81 -0
  64. data/ext/tokyo/share/man/man1/tcbtest.1 +107 -0
  65. data/ext/tokyo/share/man/man1/tcfmgr.1 +98 -0
  66. data/ext/tokyo/share/man/man1/tcfmttest.1 +62 -0
  67. data/ext/tokyo/share/man/man1/tcftest.1 +73 -0
  68. data/ext/tokyo/share/man/man1/tchmgr.1 +110 -0
  69. data/ext/tokyo/share/man/man1/tchmttest.1 +85 -0
  70. data/ext/tokyo/share/man/man1/tchtest.1 +95 -0
  71. data/ext/tokyo/share/man/man1/tcrmgr.1 +164 -0
  72. data/ext/tokyo/share/man/man1/tcrmttest.1 +55 -0
  73. data/ext/tokyo/share/man/man1/tcrtest.1 +89 -0
  74. data/ext/tokyo/share/man/man1/tctmgr.1 +140 -0
  75. data/ext/tokyo/share/man/man1/tctmttest.1 +92 -0
  76. data/ext/tokyo/share/man/man1/tcttest.1 +105 -0
  77. data/ext/tokyo/share/man/man1/tcucodec.1 +162 -0
  78. data/ext/tokyo/share/man/man1/tcumttest.1 +41 -0
  79. data/ext/tokyo/share/man/man1/tcutest.1 +81 -0
  80. data/ext/tokyo/share/man/man1/ttserver.1 +84 -0
  81. data/ext/tokyo/share/man/man1/ttulmgr.1 +40 -0
  82. data/ext/tokyo/share/man/man1/ttultest.1 +16 -0
  83. data/ext/tokyo/share/man/man3/tcadb.3 +676 -0
  84. data/ext/tokyo/share/man/man3/tcbdb.3 +1355 -0
  85. data/ext/tokyo/share/man/man3/tcfdb.3 +975 -0
  86. data/ext/tokyo/share/man/man3/tchdb.3 +898 -0
  87. data/ext/tokyo/share/man/man3/tclist.3 +1 -0
  88. data/ext/tokyo/share/man/man3/tcmap.3 +1 -0
  89. data/ext/tokyo/share/man/man3/tcmdb.3 +1 -0
  90. data/ext/tokyo/share/man/man3/tcmpool.3 +1 -0
  91. data/ext/tokyo/share/man/man3/tcrdb.3 +1309 -0
  92. data/ext/tokyo/share/man/man3/tctdb.3 +1110 -0
  93. data/ext/tokyo/share/man/man3/tctree.3 +1 -0
  94. data/ext/tokyo/share/man/man3/tculog.3 +15 -0
  95. data/ext/tokyo/share/man/man3/tcutil.3 +4518 -0
  96. data/ext/tokyo/share/man/man3/tcxstr.3 +1 -0
  97. data/ext/tokyo/share/man/man3/tokyocabinet.3 +132 -0
  98. data/ext/tokyo/share/man/man3/ttutil.3 +14 -0
  99. data/ext/tokyo/share/man/man8/ttservctl.8 +37 -0
  100. data/ext/tokyo/share/tokyocabinet/COPYING +504 -0
  101. data/ext/tokyo/share/tokyocabinet/ChangeLog +1252 -0
  102. data/ext/tokyo/share/tokyocabinet/THANKS +12 -0
  103. data/ext/tokyo/share/tokyocabinet/doc/benchmark.pdf +0 -0
  104. data/ext/tokyo/share/tokyocabinet/doc/common.css +211 -0
  105. data/ext/tokyo/share/tokyocabinet/doc/icon16.png +0 -0
  106. data/ext/tokyo/share/tokyocabinet/doc/index.html +156 -0
  107. data/ext/tokyo/share/tokyocabinet/doc/index.ja.html +197 -0
  108. data/ext/tokyo/share/tokyocabinet/doc/logo-ja.png +0 -0
  109. data/ext/tokyo/share/tokyocabinet/doc/logo.png +0 -0
  110. data/ext/tokyo/share/tokyocabinet/doc/spex-en.html +7145 -0
  111. data/ext/tokyo/share/tokyocabinet/doc/spex-ja.html +7476 -0
  112. data/ext/tokyo/share/tokyocabinet/doc/tokyoproducts.pdf +0 -0
  113. data/ext/tokyo/share/tokyocabinet/doc/tokyoproducts.ppt +0 -0
  114. data/ext/tokyo/share/tokyotyrant/COPYING +504 -0
  115. data/ext/tokyo/share/tokyotyrant/ChangeLog +578 -0
  116. data/ext/tokyo/share/tokyotyrant/THANKS +15 -0
  117. data/ext/tokyo/share/tokyotyrant/doc/common.css +211 -0
  118. data/ext/tokyo/share/tokyotyrant/doc/index.html +79 -0
  119. data/ext/tokyo/share/tokyotyrant/doc/spex.html +2264 -0
  120. data/ext/tokyo/share/tokyotyrant/ext/mapreduce.lua +57 -0
  121. data/ext/tokyo/share/tokyotyrant/ext/queue.lua +55 -0
  122. data/ext/tokyo/share/tokyotyrant/ext/senatus.lua +532 -0
  123. data/ext/tokyo/share/tokyotyrant/ext/usherette.lua +438 -0
  124. data/ext/tokyo_tyrant.c +147 -0
  125. data/ext/tokyo_tyrant.h +48 -0
  126. data/ext/tokyo_tyrant_db.c +227 -0
  127. data/ext/tokyo_tyrant_db.h +8 -0
  128. data/ext/tokyo_tyrant_module.c +453 -0
  129. data/ext/tokyo_tyrant_module.h +10 -0
  130. data/ext/tokyo_tyrant_query.c +226 -0
  131. data/ext/tokyo_tyrant_query.h +9 -0
  132. data/ext/tokyo_tyrant_table.c +319 -0
  133. data/ext/tokyo_tyrant_table.h +8 -0
  134. data/ext/tokyocabinet-1.4.41/COPYING +504 -0
  135. data/ext/tokyocabinet-1.4.41/ChangeLog +1252 -0
  136. data/ext/tokyocabinet-1.4.41/Makefile.in +825 -0
  137. data/ext/tokyocabinet-1.4.41/README +38 -0
  138. data/ext/tokyocabinet-1.4.41/THANKS +12 -0
  139. data/ext/tokyocabinet-1.4.41/bros/Makefile +133 -0
  140. data/ext/tokyocabinet-1.4.41/bros/bdbtest.c +438 -0
  141. data/ext/tokyocabinet-1.4.41/bros/cdbtest.c +219 -0
  142. data/ext/tokyocabinet-1.4.41/bros/cmpsqltctest.c +186 -0
  143. data/ext/tokyocabinet-1.4.41/bros/gdbmtest.c +216 -0
  144. data/ext/tokyocabinet-1.4.41/bros/mapreporter +72 -0
  145. data/ext/tokyocabinet-1.4.41/bros/maptest.cc +677 -0
  146. data/ext/tokyocabinet-1.4.41/bros/ndbmtest.c +204 -0
  147. data/ext/tokyocabinet-1.4.41/bros/qdbmtest.c +375 -0
  148. data/ext/tokyocabinet-1.4.41/bros/reporter +141 -0
  149. data/ext/tokyocabinet-1.4.41/bros/result.xls +0 -0
  150. data/ext/tokyocabinet-1.4.41/bros/sdbmtest.c +204 -0
  151. data/ext/tokyocabinet-1.4.41/bros/sqltest.c +404 -0
  152. data/ext/tokyocabinet-1.4.41/bros/tctest.c +748 -0
  153. data/ext/tokyocabinet-1.4.41/bros/tdbtest.c +205 -0
  154. data/ext/tokyocabinet-1.4.41/configure +7402 -0
  155. data/ext/tokyocabinet-1.4.41/configure.in +362 -0
  156. data/ext/tokyocabinet-1.4.41/doc/benchmark.pdf +0 -0
  157. data/ext/tokyocabinet-1.4.41/doc/common.css +211 -0
  158. data/ext/tokyocabinet-1.4.41/doc/icon16.png +0 -0
  159. data/ext/tokyocabinet-1.4.41/doc/index.html +156 -0
  160. data/ext/tokyocabinet-1.4.41/doc/index.ja.html +197 -0
  161. data/ext/tokyocabinet-1.4.41/doc/logo-ja.png +0 -0
  162. data/ext/tokyocabinet-1.4.41/doc/logo.png +0 -0
  163. data/ext/tokyocabinet-1.4.41/doc/spex-en.html +7145 -0
  164. data/ext/tokyocabinet-1.4.41/doc/spex-ja.html +7476 -0
  165. data/ext/tokyocabinet-1.4.41/doc/tokyoproducts.pdf +0 -0
  166. data/ext/tokyocabinet-1.4.41/doc/tokyoproducts.ppt +0 -0
  167. data/ext/tokyocabinet-1.4.41/example/Makefile +113 -0
  168. data/ext/tokyocabinet-1.4.41/example/tcadbex.c +55 -0
  169. data/ext/tokyocabinet-1.4.41/example/tcbdbex.c +64 -0
  170. data/ext/tokyocabinet-1.4.41/example/tcfdbex.c +60 -0
  171. data/ext/tokyocabinet-1.4.41/example/tchdbex.c +60 -0
  172. data/ext/tokyocabinet-1.4.41/example/tctchat.c +97 -0
  173. data/ext/tokyocabinet-1.4.41/example/tctchat.tmpl +141 -0
  174. data/ext/tokyocabinet-1.4.41/example/tctdbex.c +85 -0
  175. data/ext/tokyocabinet-1.4.41/example/tctsearch.c +95 -0
  176. data/ext/tokyocabinet-1.4.41/example/tctsearch.tmpl +122 -0
  177. data/ext/tokyocabinet-1.4.41/example/tcutilex.c +77 -0
  178. data/ext/tokyocabinet-1.4.41/f.tsv +2 -0
  179. data/ext/tokyocabinet-1.4.41/lab/calccomp +118 -0
  180. data/ext/tokyocabinet-1.4.41/lab/datechange +56 -0
  181. data/ext/tokyocabinet-1.4.41/lab/diffcheck +45 -0
  182. data/ext/tokyocabinet-1.4.41/lab/htmltotsv +102 -0
  183. data/ext/tokyocabinet-1.4.41/lab/magic +19 -0
  184. data/ext/tokyocabinet-1.4.41/lab/printenv.cgi +27 -0
  185. data/ext/tokyocabinet-1.4.41/lab/stepcount +26 -0
  186. data/ext/tokyocabinet-1.4.41/lab/stopwatch +61 -0
  187. data/ext/tokyocabinet-1.4.41/lab/tabcheck +43 -0
  188. data/ext/tokyocabinet-1.4.41/lab/wgettsv +239 -0
  189. data/ext/tokyocabinet-1.4.41/lab/widthcheck +57 -0
  190. data/ext/tokyocabinet-1.4.41/man/htmltoman +104 -0
  191. data/ext/tokyocabinet-1.4.41/man/tcadb.3 +676 -0
  192. data/ext/tokyocabinet-1.4.41/man/tcamgr.1 +97 -0
  193. data/ext/tokyocabinet-1.4.41/man/tcamttest.1 +35 -0
  194. data/ext/tokyocabinet-1.4.41/man/tcatest.1 +55 -0
  195. data/ext/tokyocabinet-1.4.41/man/tcbdb.3 +1355 -0
  196. data/ext/tokyocabinet-1.4.41/man/tcbmgr.1 +125 -0
  197. data/ext/tokyocabinet-1.4.41/man/tcbmttest.1 +81 -0
  198. data/ext/tokyocabinet-1.4.41/man/tcbtest.1 +107 -0
  199. data/ext/tokyocabinet-1.4.41/man/tcfdb.3 +975 -0
  200. data/ext/tokyocabinet-1.4.41/man/tcfmgr.1 +98 -0
  201. data/ext/tokyocabinet-1.4.41/man/tcfmttest.1 +62 -0
  202. data/ext/tokyocabinet-1.4.41/man/tcftest.1 +73 -0
  203. data/ext/tokyocabinet-1.4.41/man/tchdb.3 +898 -0
  204. data/ext/tokyocabinet-1.4.41/man/tchmgr.1 +110 -0
  205. data/ext/tokyocabinet-1.4.41/man/tchmttest.1 +85 -0
  206. data/ext/tokyocabinet-1.4.41/man/tchtest.1 +95 -0
  207. data/ext/tokyocabinet-1.4.41/man/tclist.3 +1 -0
  208. data/ext/tokyocabinet-1.4.41/man/tcmap.3 +1 -0
  209. data/ext/tokyocabinet-1.4.41/man/tcmdb.3 +1 -0
  210. data/ext/tokyocabinet-1.4.41/man/tcmpool.3 +1 -0
  211. data/ext/tokyocabinet-1.4.41/man/tctdb.3 +1110 -0
  212. data/ext/tokyocabinet-1.4.41/man/tctmgr.1 +140 -0
  213. data/ext/tokyocabinet-1.4.41/man/tctmttest.1 +92 -0
  214. data/ext/tokyocabinet-1.4.41/man/tctree.3 +1 -0
  215. data/ext/tokyocabinet-1.4.41/man/tcttest.1 +105 -0
  216. data/ext/tokyocabinet-1.4.41/man/tcucodec.1 +162 -0
  217. data/ext/tokyocabinet-1.4.41/man/tcumttest.1 +41 -0
  218. data/ext/tokyocabinet-1.4.41/man/tcutest.1 +81 -0
  219. data/ext/tokyocabinet-1.4.41/man/tcutil.3 +4518 -0
  220. data/ext/tokyocabinet-1.4.41/man/tcxstr.3 +1 -0
  221. data/ext/tokyocabinet-1.4.41/man/tokyocabinet.3 +132 -0
  222. data/ext/tokyocabinet-1.4.41/md5.c +381 -0
  223. data/ext/tokyocabinet-1.4.41/md5.h +101 -0
  224. data/ext/tokyocabinet-1.4.41/myconf.c +493 -0
  225. data/ext/tokyocabinet-1.4.41/myconf.h +549 -0
  226. data/ext/tokyocabinet-1.4.41/tcadb.c +4339 -0
  227. data/ext/tokyocabinet-1.4.41/tcadb.h +548 -0
  228. data/ext/tokyocabinet-1.4.41/tcamgr.c +1019 -0
  229. data/ext/tokyocabinet-1.4.41/tcamttest.c +542 -0
  230. data/ext/tokyocabinet-1.4.41/tcatest.c +1845 -0
  231. data/ext/tokyocabinet-1.4.41/tcawmgr.c +482 -0
  232. data/ext/tokyocabinet-1.4.41/tcbdb.c +4180 -0
  233. data/ext/tokyocabinet-1.4.41/tcbdb.h +1101 -0
  234. data/ext/tokyocabinet-1.4.41/tcbmgr.c +1012 -0
  235. data/ext/tokyocabinet-1.4.41/tcbmttest.c +1810 -0
  236. data/ext/tokyocabinet-1.4.41/tcbtest.c +2586 -0
  237. data/ext/tokyocabinet-1.4.41/tcfdb.c +2746 -0
  238. data/ext/tokyocabinet-1.4.41/tcfdb.h +858 -0
  239. data/ext/tokyocabinet-1.4.41/tcfmgr.c +786 -0
  240. data/ext/tokyocabinet-1.4.41/tcfmttest.c +1220 -0
  241. data/ext/tokyocabinet-1.4.41/tcftest.c +1695 -0
  242. data/ext/tokyocabinet-1.4.41/tchdb.c +5153 -0
  243. data/ext/tokyocabinet-1.4.41/tchdb.h +871 -0
  244. data/ext/tokyocabinet-1.4.41/tchmgr.c +842 -0
  245. data/ext/tokyocabinet-1.4.41/tchmttest.c +1757 -0
  246. data/ext/tokyocabinet-1.4.41/tchtest.c +2129 -0
  247. data/ext/tokyocabinet-1.4.41/tctdb.c +6199 -0
  248. data/ext/tokyocabinet-1.4.41/tctdb.h +1086 -0
  249. data/ext/tokyocabinet-1.4.41/tctmgr.c +1241 -0
  250. data/ext/tokyocabinet-1.4.41/tctmttest.c +1563 -0
  251. data/ext/tokyocabinet-1.4.41/tcttest.c +2062 -0
  252. data/ext/tokyocabinet-1.4.41/tcucodec.c +1357 -0
  253. data/ext/tokyocabinet-1.4.41/tcumttest.c +578 -0
  254. data/ext/tokyocabinet-1.4.41/tcutest.c +1875 -0
  255. data/ext/tokyocabinet-1.4.41/tcutil.c +10528 -0
  256. data/ext/tokyocabinet-1.4.41/tcutil.h +4184 -0
  257. data/ext/tokyocabinet-1.4.41/tokyocabinet.idl +336 -0
  258. data/ext/tokyocabinet-1.4.41/tokyocabinet.pc.in +14 -0
  259. data/ext/tokyotyrant-1.1.39/COPYING +504 -0
  260. data/ext/tokyotyrant-1.1.39/ChangeLog +578 -0
  261. data/ext/tokyotyrant-1.1.39/Makefile.in +365 -0
  262. data/ext/tokyotyrant-1.1.39/README +38 -0
  263. data/ext/tokyotyrant-1.1.39/THANKS +15 -0
  264. data/ext/tokyotyrant-1.1.39/configure +6979 -0
  265. data/ext/tokyotyrant-1.1.39/configure.in +300 -0
  266. data/ext/tokyotyrant-1.1.39/doc/common.css +211 -0
  267. data/ext/tokyotyrant-1.1.39/doc/index.html +79 -0
  268. data/ext/tokyotyrant-1.1.39/doc/spex.html +2264 -0
  269. data/ext/tokyotyrant-1.1.39/example/Makefile +68 -0
  270. data/ext/tokyotyrant-1.1.39/example/httptest.pl +88 -0
  271. data/ext/tokyotyrant-1.1.39/example/mcftest.pl +39 -0
  272. data/ext/tokyotyrant-1.1.39/example/mctest.pl +43 -0
  273. data/ext/tokyotyrant-1.1.39/example/tcrdbex +0 -0
  274. data/ext/tokyotyrant-1.1.39/example/tcrdbex.c +49 -0
  275. data/ext/tokyotyrant-1.1.39/example/tcrdbex.o +0 -0
  276. data/ext/tokyotyrant-1.1.39/example/tcrdbtblex +0 -0
  277. data/ext/tokyotyrant-1.1.39/example/tcrdbtblex.c +79 -0
  278. data/ext/tokyotyrant-1.1.39/example/tcrdbtblex.o +0 -0
  279. data/ext/tokyotyrant-1.1.39/ext/mapreduce.lua +57 -0
  280. data/ext/tokyotyrant-1.1.39/ext/queue.lua +55 -0
  281. data/ext/tokyotyrant-1.1.39/ext/senatus.lua +532 -0
  282. data/ext/tokyotyrant-1.1.39/ext/usherette.lua +438 -0
  283. data/ext/tokyotyrant-1.1.39/lab/datechange +56 -0
  284. data/ext/tokyotyrant-1.1.39/lab/diffcheck +45 -0
  285. data/ext/tokyotyrant-1.1.39/lab/fibonacci.lua +20 -0
  286. data/ext/tokyotyrant-1.1.39/lab/footprint.lua +67 -0
  287. data/ext/tokyotyrant-1.1.39/lab/highlow.lua +88 -0
  288. data/ext/tokyotyrant-1.1.39/lab/killdualmaster +12 -0
  289. data/ext/tokyotyrant-1.1.39/lab/rundualmaster +38 -0
  290. data/ext/tokyotyrant-1.1.39/lab/stepcount +26 -0
  291. data/ext/tokyotyrant-1.1.39/lab/tabcheck +43 -0
  292. data/ext/tokyotyrant-1.1.39/lab/ushrtregister.pl +55 -0
  293. data/ext/tokyotyrant-1.1.39/lab/widthcheck +57 -0
  294. data/ext/tokyotyrant-1.1.39/man/htmltoman +100 -0
  295. data/ext/tokyotyrant-1.1.39/man/tcrdb.3 +1309 -0
  296. data/ext/tokyotyrant-1.1.39/man/tcrmgr.1 +164 -0
  297. data/ext/tokyotyrant-1.1.39/man/tcrmttest.1 +55 -0
  298. data/ext/tokyotyrant-1.1.39/man/tcrtest.1 +89 -0
  299. data/ext/tokyotyrant-1.1.39/man/tculog.3 +15 -0
  300. data/ext/tokyotyrant-1.1.39/man/ttservctl.8 +37 -0
  301. data/ext/tokyotyrant-1.1.39/man/ttserver.1 +84 -0
  302. data/ext/tokyotyrant-1.1.39/man/ttulmgr.1 +40 -0
  303. data/ext/tokyotyrant-1.1.39/man/ttultest.1 +16 -0
  304. data/ext/tokyotyrant-1.1.39/man/ttutil.3 +14 -0
  305. data/ext/tokyotyrant-1.1.39/myconf.c +169 -0
  306. data/ext/tokyotyrant-1.1.39/myconf.h +408 -0
  307. data/ext/tokyotyrant-1.1.39/scrext.c +2394 -0
  308. data/ext/tokyotyrant-1.1.39/scrext.h +96 -0
  309. data/ext/tokyotyrant-1.1.39/tcrdb.c +2637 -0
  310. data/ext/tokyotyrant-1.1.39/tcrdb.h +801 -0
  311. data/ext/tokyotyrant-1.1.39/tcrmgr.c +1559 -0
  312. data/ext/tokyotyrant-1.1.39/tcrmttest.c +915 -0
  313. data/ext/tokyotyrant-1.1.39/tcrtest.c +1542 -0
  314. data/ext/tokyotyrant-1.1.39/tculog.c +1211 -0
  315. data/ext/tokyotyrant-1.1.39/tculog.h +392 -0
  316. data/ext/tokyotyrant-1.1.39/tokyotyrant.idl +143 -0
  317. data/ext/tokyotyrant-1.1.39/tokyotyrant.pc.in +14 -0
  318. data/ext/tokyotyrant-1.1.39/ttservctl +163 -0
  319. data/ext/tokyotyrant-1.1.39/ttserver.c +3583 -0
  320. data/ext/tokyotyrant-1.1.39/ttskeldir.c +141 -0
  321. data/ext/tokyotyrant-1.1.39/ttskelmock.c +64 -0
  322. data/ext/tokyotyrant-1.1.39/ttskelnull.c +79 -0
  323. data/ext/tokyotyrant-1.1.39/ttskelproxy.c +74 -0
  324. data/ext/tokyotyrant-1.1.39/ttulmgr.c +266 -0
  325. data/ext/tokyotyrant-1.1.39/ttultest.c +371 -0
  326. data/ext/tokyotyrant-1.1.39/ttutil.c +1510 -0
  327. data/ext/tokyotyrant-1.1.39/ttutil.h +494 -0
  328. data/lib/tokyo_tyrant/balancer.rb +189 -0
  329. data/spec/ext.lua +4 -0
  330. data/spec/plu_db.rb +538 -0
  331. data/spec/spec.rb +1 -0
  332. data/spec/spec_base.rb +17 -0
  333. data/spec/start_tyrants.sh +36 -0
  334. data/spec/stop_tyrants.sh +9 -0
  335. data/spec/tokyo_tyrant_balancer_db_spec.rb +160 -0
  336. data/spec/tokyo_tyrant_balancer_table_spec.rb +177 -0
  337. data/spec/tokyo_tyrant_query_spec.rb +159 -0
  338. data/spec/tokyo_tyrant_spec.rb +254 -0
  339. data/spec/tokyo_tyrant_table_spec.rb +301 -0
  340. metadata +402 -0
@@ -0,0 +1,1357 @@
1
+ /*************************************************************************************************
2
+ * Popular encoders and decoders of the utility API
3
+ * Copyright (C) 2006-2009 Mikio Hirabayashi
4
+ * This file is part of Tokyo Cabinet.
5
+ * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
6
+ * the GNU Lesser General Public License as published by the Free Software Foundation; either
7
+ * version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope
8
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10
+ * License for more details.
11
+ * You should have received a copy of the GNU Lesser General Public License along with Tokyo
12
+ * Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
13
+ * Boston, MA 02111-1307 USA.
14
+ *************************************************************************************************/
15
+
16
+
17
+ #include <tcutil.h>
18
+ #include "myconf.h"
19
+
20
+
21
+ /* global variables */
22
+ const char *g_progname; // program name
23
+
24
+
25
+ /* function prototypes */
26
+ int main(int argc, char **argv);
27
+ static void usage(void);
28
+ static void eprintf(const char *format, ...);
29
+ static int runurl(int argc, char **argv);
30
+ static int runbase(int argc, char **argv);
31
+ static int runquote(int argc, char **argv);
32
+ static int runmime(int argc, char **argv);
33
+ static int runhex(int argc, char **argv);
34
+ static int runpack(int argc, char **argv);
35
+ static int runtcbs(int argc, char **argv);
36
+ static int runzlib(int argc, char **argv);
37
+ static int runbzip(int argc, char **argv);
38
+ static int runxml(int argc, char **argv);
39
+ static int runcstr(int argc, char **argv);
40
+ static int runucs(int argc, char **argv);
41
+ static int runhash(int argc, char **argv);
42
+ static int runcipher(int argc, char **argv);
43
+ static int rundate(int argc, char **argv);
44
+ static int runtmpl(int argc, char **argv);
45
+ static int runconf(int argc, char **argv);
46
+ static int procurl(const char *ibuf, int isiz, bool dec, bool br, const char *base);
47
+ static int procbase(const char *ibuf, int isiz, bool dec);
48
+ static int procquote(const char *ibuf, int isiz, bool dec);
49
+ static int procmime(const char *ibuf, int isiz, bool dec, const char *ename, bool qb, bool on,
50
+ bool hd, bool bd, int part);
51
+ static int prochex(const char *ibuf, int isiz, bool dec);
52
+ static int procpack(const char *ibuf, int isiz, bool dec, bool bwt);
53
+ static int proctcbs(const char *ibuf, int isiz, bool dec);
54
+ static int proczlib(const char *ibuf, int isiz, bool dec, bool gz);
55
+ static int procbzip(const char *ibuf, int isiz, bool dec);
56
+ static int procxml(const char *ibuf, int isiz, bool dec, bool br);
57
+ static int proccstr(const char *ibuf, int isiz, bool dec, bool js);
58
+ static int procucs(const char *ibuf, int isiz, bool dec, bool un, const char *kw);
59
+ static int prochash(const char *ibuf, int isiz, bool crc, int ch);
60
+ static int proccipher(const char *ibuf, int isiz, const char *key);
61
+ static int procdate(const char *str, int jl, bool wf, bool rf);
62
+ static int proctmpl(const char *ibuf, int isiz, TCMAP *vars);
63
+ static int procconf(int mode);
64
+
65
+
66
+ /* main routine */
67
+ int main(int argc, char **argv){
68
+ g_progname = argv[0];
69
+ if(argc < 2) usage();
70
+ int rv = 0;
71
+ if(!strcmp(argv[1], "url")){
72
+ rv = runurl(argc, argv);
73
+ } else if(!strcmp(argv[1], "base")){
74
+ rv = runbase(argc, argv);
75
+ } else if(!strcmp(argv[1], "quote")){
76
+ rv = runquote(argc, argv);
77
+ } else if(!strcmp(argv[1], "mime")){
78
+ rv = runmime(argc, argv);
79
+ } else if(!strcmp(argv[1], "hex")){
80
+ rv = runhex(argc, argv);
81
+ } else if(!strcmp(argv[1], "pack")){
82
+ rv = runpack(argc, argv);
83
+ } else if(!strcmp(argv[1], "tcbs")){
84
+ rv = runtcbs(argc, argv);
85
+ } else if(!strcmp(argv[1], "zlib")){
86
+ rv = runzlib(argc, argv);
87
+ } else if(!strcmp(argv[1], "bzip")){
88
+ rv = runbzip(argc, argv);
89
+ } else if(!strcmp(argv[1], "xml")){
90
+ rv = runxml(argc, argv);
91
+ } else if(!strcmp(argv[1], "cstr")){
92
+ rv = runcstr(argc, argv);
93
+ } else if(!strcmp(argv[1], "ucs")){
94
+ rv = runucs(argc, argv);
95
+ } else if(!strcmp(argv[1], "hash")){
96
+ rv = runhash(argc, argv);
97
+ } else if(!strcmp(argv[1], "cipher")){
98
+ rv = runcipher(argc, argv);
99
+ } else if(!strcmp(argv[1], "date")){
100
+ rv = rundate(argc, argv);
101
+ } else if(!strcmp(argv[1], "tmpl")){
102
+ rv = runtmpl(argc, argv);
103
+ } else if(!strcmp(argv[1], "conf")){
104
+ rv = runconf(argc, argv);
105
+ } else {
106
+ usage();
107
+ }
108
+ return rv;
109
+ }
110
+
111
+
112
+ /* print the usage and exit */
113
+ static void usage(void){
114
+ fprintf(stderr, "%s: popular encoders and decoders of Tokyo Cabinet\n", g_progname);
115
+ fprintf(stderr, "\n");
116
+ fprintf(stderr, "usage:\n");
117
+ fprintf(stderr, " %s url [-d] [-br] [-rs base] [file]\n", g_progname);
118
+ fprintf(stderr, " %s base [-d] [file]\n", g_progname);
119
+ fprintf(stderr, " %s quote [-d] [file]\n", g_progname);
120
+ fprintf(stderr, " %s mime [-d] [-en name] [-q] [-on] [-hd] [-bd] [-part num] [file]\n",
121
+ g_progname);
122
+ fprintf(stderr, " %s hex [-d] [file]\n", g_progname);
123
+ fprintf(stderr, " %s pack [-d] [-bwt] [file]\n", g_progname);
124
+ fprintf(stderr, " %s tcbs [-d] [file]\n", g_progname);
125
+ fprintf(stderr, " %s zlib [-d] [-gz] [file]\n", g_progname);
126
+ fprintf(stderr, " %s bzip [-d] [file]\n", g_progname);
127
+ fprintf(stderr, " %s xml [-d] [-br] [file]\n", g_progname);
128
+ fprintf(stderr, " %s cstr [-d] [-js] [file]\n", g_progname);
129
+ fprintf(stderr, " %s ucs [-d] [-un] [file]\n", g_progname);
130
+ fprintf(stderr, " %s hash [-crc] [-ch num] [file]\n", g_progname);
131
+ fprintf(stderr, " %s cipher [-key str] [file]\n", g_progname);
132
+ fprintf(stderr, " %s date [-ds str] [-jl num] [-wf] [-rf]\n", g_progname);
133
+ fprintf(stderr, " %s tmpl [-var name val] [file]\n", g_progname);
134
+ fprintf(stderr, " %s conf [-v|-i|-l|-p]\n", g_progname);
135
+ fprintf(stderr, "\n");
136
+ exit(1);
137
+ }
138
+
139
+
140
+ /* print formatted error string */
141
+ static void eprintf(const char *format, ...){
142
+ va_list ap;
143
+ va_start(ap, format);
144
+ fprintf(stderr, "%s: ", g_progname);
145
+ vfprintf(stderr, format, ap);
146
+ fprintf(stderr, "\n");
147
+ va_end(ap);
148
+ }
149
+
150
+
151
+ /* parse arguments of url command */
152
+ static int runurl(int argc, char **argv){
153
+ char *path = NULL;
154
+ bool dec = false;
155
+ bool br = false;
156
+ char *base = NULL;
157
+ for(int i = 2; i < argc; i++){
158
+ if(!path && argv[i][0] == '-'){
159
+ if(!strcmp(argv[i], "-d")){
160
+ dec = true;
161
+ } else if(!strcmp(argv[i], "-br")){
162
+ br = true;
163
+ } else if(!strcmp(argv[i], "-rs")){
164
+ if(++i >= argc) usage();
165
+ base = argv[i];
166
+ } else {
167
+ usage();
168
+ }
169
+ } else if(!path){
170
+ path = argv[i];
171
+ } else {
172
+ usage();
173
+ }
174
+ }
175
+ char *ibuf;
176
+ int isiz;
177
+ if(path && path[0] == '@'){
178
+ isiz = strlen(path) - 1;
179
+ ibuf = tcmemdup(path + 1, isiz);
180
+ } else {
181
+ ibuf = tcreadfile(path, -1, &isiz);
182
+ }
183
+ if(!ibuf){
184
+ eprintf("%s: cannot open", path ? path : "(stdin)");
185
+ return 1;
186
+ }
187
+ int rv = procurl(ibuf, isiz, dec, br, base);
188
+ if(path && path[0] == '@' && !br) printf("\n");
189
+ tcfree(ibuf);
190
+ return rv;
191
+ }
192
+
193
+
194
+ /* parse arguments of base command */
195
+ static int runbase(int argc, char **argv){
196
+ char *path = NULL;
197
+ bool dec = false;
198
+ for(int i = 2; i < argc; i++){
199
+ if(!path && argv[i][0] == '-'){
200
+ if(!strcmp(argv[i], "-d")){
201
+ dec = true;
202
+ } else {
203
+ usage();
204
+ }
205
+ } else if(!path){
206
+ path = argv[i];
207
+ } else {
208
+ usage();
209
+ }
210
+ }
211
+ char *ibuf;
212
+ int isiz;
213
+ if(path && path[0] == '@'){
214
+ isiz = strlen(path) - 1;
215
+ ibuf = tcmemdup(path + 1, isiz);
216
+ } else {
217
+ ibuf = tcreadfile(path, -1, &isiz);
218
+ }
219
+ if(!ibuf){
220
+ eprintf("%s: cannot open", path ? path : "(stdin)");
221
+ return 1;
222
+ }
223
+ int rv = procbase(ibuf, isiz, dec);
224
+ if(path && path[0] == '@') printf("\n");
225
+ tcfree(ibuf);
226
+ return rv;
227
+ }
228
+
229
+
230
+ /* parse arguments of quote command */
231
+ static int runquote(int argc, char **argv){
232
+ char *path = NULL;
233
+ bool dec = false;
234
+ for(int i = 2; i < argc; i++){
235
+ if(!path && argv[i][0] == '-'){
236
+ if(!strcmp(argv[i], "-d")){
237
+ dec = true;
238
+ } else {
239
+ usage();
240
+ }
241
+ } else if(!path){
242
+ path = argv[i];
243
+ } else {
244
+ usage();
245
+ }
246
+ }
247
+ char *ibuf;
248
+ int isiz;
249
+ if(path && path[0] == '@'){
250
+ isiz = strlen(path) - 1;
251
+ ibuf = tcmemdup(path + 1, isiz);
252
+ } else {
253
+ ibuf = tcreadfile(path, -1, &isiz);
254
+ }
255
+ if(!ibuf){
256
+ eprintf("%s: cannot open", path ? path : "(stdin)");
257
+ return 1;
258
+ }
259
+ int rv = procquote(ibuf, isiz, dec);
260
+ if(path && path[0] == '@') printf("\n");
261
+ tcfree(ibuf);
262
+ return rv;
263
+ }
264
+
265
+
266
+ /* parse arguments of mime command */
267
+ static int runmime(int argc, char **argv){
268
+ char *path = NULL;
269
+ bool dec = false;
270
+ char *ename = NULL;
271
+ bool qb = false;
272
+ bool on = false;
273
+ bool hd = false;
274
+ bool bd = false;
275
+ int part = -1;
276
+ for(int i = 2; i < argc; i++){
277
+ if(!path && argv[i][0] == '-'){
278
+ if(!strcmp(argv[i], "-d")){
279
+ dec = true;
280
+ } else if(!strcmp(argv[i], "-en")){
281
+ if(++i >= argc) usage();
282
+ ename = argv[i];
283
+ } else if(!strcmp(argv[i], "-q")){
284
+ qb = true;
285
+ } else if(!strcmp(argv[i], "-on")){
286
+ on = true;
287
+ } else if(!strcmp(argv[i], "-hd")){
288
+ hd = true;
289
+ } else if(!strcmp(argv[i], "-bd")){
290
+ bd = true;
291
+ } else if(!strcmp(argv[i], "-part")){
292
+ if(++i >= argc) usage();
293
+ part = tcatoix(argv[i]);
294
+ } else {
295
+ usage();
296
+ }
297
+ } else if(!path){
298
+ path = argv[i];
299
+ } else {
300
+ usage();
301
+ }
302
+ }
303
+ char *ibuf;
304
+ int isiz;
305
+ if(path && path[0] == '@'){
306
+ isiz = strlen(path) - 1;
307
+ ibuf = tcmemdup(path + 1, isiz);
308
+ } else {
309
+ ibuf = tcreadfile(path, -1, &isiz);
310
+ }
311
+ if(!ibuf){
312
+ eprintf("%s: cannot open", path ? path : "(stdin)");
313
+ return 1;
314
+ }
315
+ if(!ename) ename = "UTF-8";
316
+ int rv = procmime(ibuf, isiz, dec, ename, qb, on, hd, bd, part);
317
+ if(path && path[0] == '@') printf("\n");
318
+ tcfree(ibuf);
319
+ return rv;
320
+ }
321
+
322
+
323
+ /* parse arguments of hex command */
324
+ static int runhex(int argc, char **argv){
325
+ char *path = NULL;
326
+ bool dec = false;
327
+ for(int i = 2; i < argc; i++){
328
+ if(!path && argv[i][0] == '-'){
329
+ if(!strcmp(argv[i], "-d")){
330
+ dec = true;
331
+ } else {
332
+ usage();
333
+ }
334
+ } else if(!path){
335
+ path = argv[i];
336
+ } else {
337
+ usage();
338
+ }
339
+ }
340
+ char *ibuf;
341
+ int isiz;
342
+ if(path && path[0] == '@'){
343
+ isiz = strlen(path) - 1;
344
+ ibuf = tcmemdup(path + 1, isiz);
345
+ } else {
346
+ ibuf = tcreadfile(path, -1, &isiz);
347
+ }
348
+ if(!ibuf){
349
+ eprintf("%s: cannot open", path ? path : "(stdin)");
350
+ return 1;
351
+ }
352
+ int rv = prochex(ibuf, isiz, dec);
353
+ if(path && path[0] == '@') printf("\n");
354
+ tcfree(ibuf);
355
+ return rv;
356
+ }
357
+
358
+
359
+ /* parse arguments of pack command */
360
+ static int runpack(int argc, char **argv){
361
+ char *path = NULL;
362
+ bool dec = false;
363
+ bool bwt = false;
364
+ for(int i = 2; i < argc; i++){
365
+ if(!path && argv[i][0] == '-'){
366
+ if(!strcmp(argv[i], "-d")){
367
+ dec = true;
368
+ } else if(!strcmp(argv[i], "-bwt")){
369
+ bwt = true;
370
+ } else {
371
+ usage();
372
+ }
373
+ } else if(!path){
374
+ path = argv[i];
375
+ } else {
376
+ usage();
377
+ }
378
+ }
379
+ char *ibuf;
380
+ int isiz;
381
+ if(path && path[0] == '@'){
382
+ isiz = strlen(path) - 1;
383
+ ibuf = tcmemdup(path + 1, isiz);
384
+ } else {
385
+ ibuf = tcreadfile(path, -1, &isiz);
386
+ }
387
+ if(!ibuf){
388
+ eprintf("%s: cannot open", path ? path : "(stdin)");
389
+ return 1;
390
+ }
391
+ int rv = procpack(ibuf, isiz, dec, bwt);
392
+ if(path && path[0] == '@') printf("\n");
393
+ tcfree(ibuf);
394
+ return rv;
395
+ }
396
+
397
+
398
+ /* parse arguments of tcbs command */
399
+ static int runtcbs(int argc, char **argv){
400
+ char *path = NULL;
401
+ bool dec = false;
402
+ for(int i = 2; i < argc; i++){
403
+ if(!path && argv[i][0] == '-'){
404
+ if(!strcmp(argv[i], "-d")){
405
+ dec = true;
406
+ } else {
407
+ usage();
408
+ }
409
+ } else if(!path){
410
+ path = argv[i];
411
+ } else {
412
+ usage();
413
+ }
414
+ }
415
+ char *ibuf;
416
+ int isiz;
417
+ if(path && path[0] == '@'){
418
+ isiz = strlen(path) - 1;
419
+ ibuf = tcmemdup(path + 1, isiz);
420
+ } else {
421
+ ibuf = tcreadfile(path, -1, &isiz);
422
+ }
423
+ if(!ibuf){
424
+ eprintf("%s: cannot open", path ? path : "(stdin)");
425
+ return 1;
426
+ }
427
+ int rv = proctcbs(ibuf, isiz, dec);
428
+ if(path && path[0] == '@') printf("\n");
429
+ tcfree(ibuf);
430
+ return rv;
431
+ }
432
+
433
+
434
+ /* parse arguments of zlib command */
435
+ static int runzlib(int argc, char **argv){
436
+ char *path = NULL;
437
+ bool dec = false;
438
+ bool gz = false;
439
+ for(int i = 2; i < argc; i++){
440
+ if(!path && argv[i][0] == '-'){
441
+ if(!strcmp(argv[i], "-d")){
442
+ dec = true;
443
+ } else if(!strcmp(argv[i], "-gz")){
444
+ gz = true;
445
+ } else {
446
+ usage();
447
+ }
448
+ } else if(!path){
449
+ path = argv[i];
450
+ } else {
451
+ usage();
452
+ }
453
+ }
454
+ char *ibuf;
455
+ int isiz;
456
+ if(path && path[0] == '@'){
457
+ isiz = strlen(path) - 1;
458
+ ibuf = tcmemdup(path + 1, isiz);
459
+ } else {
460
+ ibuf = tcreadfile(path, -1, &isiz);
461
+ }
462
+ if(!ibuf){
463
+ eprintf("%s: cannot open", path ? path : "(stdin)");
464
+ return 1;
465
+ }
466
+ int rv = proczlib(ibuf, isiz, dec, gz);
467
+ if(path && path[0] == '@') printf("\n");
468
+ tcfree(ibuf);
469
+ return rv;
470
+ }
471
+
472
+
473
+ /* parse arguments of bzip command */
474
+ static int runbzip(int argc, char **argv){
475
+ char *path = NULL;
476
+ bool dec = false;
477
+ for(int i = 2; i < argc; i++){
478
+ if(!path && argv[i][0] == '-'){
479
+ if(!strcmp(argv[i], "-d")){
480
+ dec = true;
481
+ } else {
482
+ usage();
483
+ }
484
+ } else if(!path){
485
+ path = argv[i];
486
+ } else {
487
+ usage();
488
+ }
489
+ }
490
+ char *ibuf;
491
+ int isiz;
492
+ if(path && path[0] == '@'){
493
+ isiz = strlen(path) - 1;
494
+ ibuf = tcmemdup(path + 1, isiz);
495
+ } else {
496
+ ibuf = tcreadfile(path, -1, &isiz);
497
+ }
498
+ if(!ibuf){
499
+ eprintf("%s: cannot open", path ? path : "(stdin)");
500
+ return 1;
501
+ }
502
+ int rv = procbzip(ibuf, isiz, dec);
503
+ if(path && path[0] == '@') printf("\n");
504
+ tcfree(ibuf);
505
+ return rv;
506
+ }
507
+
508
+
509
+ /* parse arguments of xml command */
510
+ static int runxml(int argc, char **argv){
511
+ char *path = NULL;
512
+ bool dec = false;
513
+ bool br = false;
514
+ for(int i = 2; i < argc; i++){
515
+ if(!path && argv[i][0] == '-'){
516
+ if(!strcmp(argv[i], "-d")){
517
+ dec = true;
518
+ } else if(!strcmp(argv[i], "-br")){
519
+ br = true;
520
+ } else {
521
+ usage();
522
+ }
523
+ } else if(!path){
524
+ path = argv[i];
525
+ } else {
526
+ usage();
527
+ }
528
+ }
529
+ char *ibuf;
530
+ int isiz;
531
+ if(path && path[0] == '@'){
532
+ isiz = strlen(path) - 1;
533
+ ibuf = tcmemdup(path + 1, isiz);
534
+ } else {
535
+ ibuf = tcreadfile(path, -1, &isiz);
536
+ }
537
+ if(!ibuf){
538
+ eprintf("%s: cannot open", path ? path : "(stdin)");
539
+ return 1;
540
+ }
541
+ int rv = procxml(ibuf, isiz, dec, br);
542
+ if(path && path[0] == '@') printf("\n");
543
+ tcfree(ibuf);
544
+ return rv;
545
+ }
546
+
547
+
548
+ /* parse arguments of cstr command */
549
+ static int runcstr(int argc, char **argv){
550
+ char *path = NULL;
551
+ bool dec = false;
552
+ bool js = false;
553
+ for(int i = 2; i < argc; i++){
554
+ if(!path && argv[i][0] == '-'){
555
+ if(!strcmp(argv[i], "-d")){
556
+ dec = true;
557
+ } else if(!strcmp(argv[i], "-js")){
558
+ js = true;
559
+ } else {
560
+ usage();
561
+ }
562
+ } else if(!path){
563
+ path = argv[i];
564
+ } else {
565
+ usage();
566
+ }
567
+ }
568
+ char *ibuf;
569
+ int isiz;
570
+ if(path && path[0] == '@'){
571
+ isiz = strlen(path) - 1;
572
+ ibuf = tcmemdup(path + 1, isiz);
573
+ } else {
574
+ ibuf = tcreadfile(path, -1, &isiz);
575
+ }
576
+ if(!ibuf){
577
+ eprintf("%s: cannot open", path ? path : "(stdin)");
578
+ return 1;
579
+ }
580
+ int rv = proccstr(ibuf, isiz, dec, js);
581
+ if(path && path[0] == '@') printf("\n");
582
+ tcfree(ibuf);
583
+ return rv;
584
+ }
585
+
586
+
587
+ /* parse arguments of ucs command */
588
+ static int runucs(int argc, char **argv){
589
+ char *path = NULL;
590
+ bool dec = false;
591
+ bool un = false;
592
+ char *kw = NULL;
593
+ for(int i = 2; i < argc; i++){
594
+ if(!path && argv[i][0] == '-'){
595
+ if(!strcmp(argv[i], "-d")){
596
+ dec = true;
597
+ } else if(!strcmp(argv[i], "-un")){
598
+ un = true;
599
+ } else if(!strcmp(argv[i], "-kw")){
600
+ if(++i >= argc) usage();
601
+ kw = argv[i];
602
+ } else {
603
+ usage();
604
+ }
605
+ } else if(!path){
606
+ path = argv[i];
607
+ } else {
608
+ usage();
609
+ }
610
+ }
611
+ char *ibuf;
612
+ int isiz;
613
+ if(path && path[0] == '@'){
614
+ isiz = strlen(path) - 1;
615
+ ibuf = tcmemdup(path + 1, isiz);
616
+ } else {
617
+ ibuf = tcreadfile(path, -1, &isiz);
618
+ }
619
+ if(!ibuf){
620
+ eprintf("%s: cannot open", path ? path : "(stdin)");
621
+ return 1;
622
+ }
623
+ int rv = procucs(ibuf, isiz, dec, un, kw);
624
+ if(path && path[0] == '@') printf("\n");
625
+ tcfree(ibuf);
626
+ return rv;
627
+ }
628
+
629
+
630
+ /* parse arguments of hash command */
631
+ static int runhash(int argc, char **argv){
632
+ char *path = NULL;
633
+ bool crc = false;
634
+ int ch = 0;
635
+ for(int i = 2; i < argc; i++){
636
+ if(!path && argv[i][0] == '-'){
637
+ if(!strcmp(argv[i], "-crc")){
638
+ crc = true;
639
+ } else if(!strcmp(argv[i], "-ch")){
640
+ if(++i >= argc) usage();
641
+ ch = tcatoix(argv[i]);
642
+ } else {
643
+ usage();
644
+ }
645
+ } else if(!path){
646
+ path = argv[i];
647
+ } else {
648
+ usage();
649
+ }
650
+ }
651
+ char *ibuf;
652
+ int isiz;
653
+ if(path && path[0] == '@'){
654
+ isiz = strlen(path) - 1;
655
+ ibuf = tcmemdup(path + 1, isiz);
656
+ } else {
657
+ ibuf = tcreadfile(path, -1, &isiz);
658
+ }
659
+ if(!ibuf){
660
+ eprintf("%s: cannot open", path ? path : "(stdin)");
661
+ return 1;
662
+ }
663
+ int rv = prochash(ibuf, isiz, crc, ch);
664
+ tcfree(ibuf);
665
+ return rv;
666
+ }
667
+
668
+
669
+ /* parse arguments of cipher command */
670
+ static int runcipher(int argc, char **argv){
671
+ char *path = NULL;
672
+ char *key = NULL;
673
+ for(int i = 2; i < argc; i++){
674
+ if(!path && argv[i][0] == '-'){
675
+ if(!strcmp(argv[i], "-key")){
676
+ if(++i >= argc) usage();
677
+ key = argv[i];
678
+ } else {
679
+ usage();
680
+ }
681
+ } else if(!path){
682
+ path = argv[i];
683
+ } else {
684
+ usage();
685
+ }
686
+ }
687
+ char *ibuf;
688
+ int isiz;
689
+ if(path && path[0] == '@'){
690
+ isiz = strlen(path) - 1;
691
+ ibuf = tcmemdup(path + 1, isiz);
692
+ } else {
693
+ ibuf = tcreadfile(path, -1, &isiz);
694
+ }
695
+ if(!ibuf){
696
+ eprintf("%s: cannot open", path ? path : "(stdin)");
697
+ return 1;
698
+ }
699
+ int rv = proccipher(ibuf, isiz, key);
700
+ if(path && path[0] == '@') printf("\n");
701
+ tcfree(ibuf);
702
+ return rv;
703
+ }
704
+
705
+
706
+ /* parse arguments of date command */
707
+ static int rundate(int argc, char **argv){
708
+ char *str = NULL;
709
+ int jl = INT_MAX;
710
+ bool wf = false;
711
+ bool rf = false;
712
+ for(int i = 2; i < argc; i++){
713
+ if(argv[i][0] == '-'){
714
+ if(!strcmp(argv[i], "-ds")){
715
+ if(++i >= argc) usage();
716
+ str = argv[i];
717
+ } else if(!strcmp(argv[i], "-jl")){
718
+ if(++i >= argc) usage();
719
+ jl = tcatoix(argv[i]);
720
+ } else if(!strcmp(argv[i], "-wf")){
721
+ wf = true;
722
+ } else if(!strcmp(argv[i], "-rf")){
723
+ rf = true;
724
+ } else {
725
+ usage();
726
+ }
727
+ } else {
728
+ usage();
729
+ }
730
+ }
731
+ int rv = procdate(str, jl, wf, rf);
732
+ return rv;
733
+ }
734
+
735
+
736
+ /* parse arguments of tmpl command */
737
+ static int runtmpl(int argc, char **argv){
738
+ char *path = NULL;
739
+ TCMAP *vars = tcmpoolmapnew(tcmpoolglobal());
740
+ for(int i = 2; i < argc; i++){
741
+ if(!path && argv[i][0] == '-'){
742
+ if(!strcmp(argv[i], "-var")){
743
+ if(++i >= argc) usage();
744
+ const char *name = argv[i];
745
+ if(++i >= argc) usage();
746
+ const char *value = argv[i];
747
+ tcmapput2(vars, name, value);
748
+ } else {
749
+ usage();
750
+ }
751
+ } else if(!path){
752
+ path = argv[i];
753
+ } else {
754
+ usage();
755
+ }
756
+ }
757
+ char *ibuf;
758
+ int isiz;
759
+ if(path && path[0] == '@'){
760
+ isiz = strlen(path) - 1;
761
+ ibuf = tcmemdup(path + 1, isiz);
762
+ } else {
763
+ ibuf = tcreadfile(path, -1, &isiz);
764
+ }
765
+ if(!ibuf){
766
+ eprintf("%s: cannot open", path ? path : "(stdin)");
767
+ return 1;
768
+ }
769
+ int rv = proctmpl(ibuf, isiz, vars);
770
+ if(path && path[0] == '@') printf("\n");
771
+ tcfree(ibuf);
772
+ return rv;
773
+ }
774
+
775
+
776
+ /* parse arguments of conf command */
777
+ static int runconf(int argc, char **argv){
778
+ int mode = 0;
779
+ for(int i = 2; i < argc; i++){
780
+ if(argv[i][0] == '-'){
781
+ if(!strcmp(argv[i], "-v")){
782
+ mode = 'v';
783
+ } else if(!strcmp(argv[i], "-i")){
784
+ mode = 'i';
785
+ } else if(!strcmp(argv[i], "-l")){
786
+ mode = 'l';
787
+ } else if(!strcmp(argv[i], "-p")){
788
+ mode = 'p';
789
+ } else {
790
+ usage();
791
+ }
792
+ } else {
793
+ usage();
794
+ }
795
+ }
796
+ int rv = procconf(mode);
797
+ return rv;
798
+ }
799
+
800
+
801
+ /* perform url command */
802
+ static int procurl(const char *ibuf, int isiz, bool dec, bool br, const char *base){
803
+ if(base){
804
+ char *obuf = tcurlresolve(base, ibuf);
805
+ printf("%s", obuf);
806
+ tcfree(obuf);
807
+ } else if(br){
808
+ TCMAP *elems = tcurlbreak(ibuf);
809
+ const char *elem;
810
+ if((elem = tcmapget2(elems, "self")) != NULL) printf("self: %s\n", elem);
811
+ if((elem = tcmapget2(elems, "scheme")) != NULL) printf("scheme: %s\n", elem);
812
+ if((elem = tcmapget2(elems, "host")) != NULL) printf("host: %s\n", elem);
813
+ if((elem = tcmapget2(elems, "port")) != NULL) printf("port: %s\n", elem);
814
+ if((elem = tcmapget2(elems, "authority")) != NULL) printf("authority: %s\n", elem);
815
+ if((elem = tcmapget2(elems, "path")) != NULL) printf("path: %s\n", elem);
816
+ if((elem = tcmapget2(elems, "file")) != NULL) printf("file: %s\n", elem);
817
+ if((elem = tcmapget2(elems, "query")) != NULL) printf("query: %s\n", elem);
818
+ if((elem = tcmapget2(elems, "fragment")) != NULL) printf("fragment: %s\n", elem);
819
+ tcmapdel(elems);
820
+ } else if(dec){
821
+ int osiz;
822
+ char *obuf = tcurldecode(ibuf, &osiz);
823
+ fwrite(obuf, 1, osiz, stdout);
824
+ tcfree(obuf);
825
+ } else {
826
+ char *obuf = tcurlencode(ibuf, isiz);
827
+ fwrite(obuf, 1, strlen(obuf), stdout);
828
+ tcfree(obuf);
829
+ }
830
+ return 0;
831
+ }
832
+
833
+
834
+ /* perform base command */
835
+ static int procbase(const char *ibuf, int isiz, bool dec){
836
+ if(dec){
837
+ int osiz;
838
+ char *obuf = tcbasedecode(ibuf, &osiz);
839
+ fwrite(obuf, 1, osiz, stdout);
840
+ tcfree(obuf);
841
+ } else {
842
+ char *obuf = tcbaseencode(ibuf, isiz);
843
+ fwrite(obuf, 1, strlen(obuf), stdout);
844
+ tcfree(obuf);
845
+ }
846
+ return 0;
847
+ }
848
+
849
+
850
+ /* perform quote command */
851
+ static int procquote(const char *ibuf, int isiz, bool dec){
852
+ if(dec){
853
+ int osiz;
854
+ char *obuf = tcquotedecode(ibuf, &osiz);
855
+ fwrite(obuf, 1, osiz, stdout);
856
+ tcfree(obuf);
857
+ } else {
858
+ char *obuf = tcquoteencode(ibuf, isiz);
859
+ fwrite(obuf, 1, strlen(obuf), stdout);
860
+ tcfree(obuf);
861
+ }
862
+ return 0;
863
+ }
864
+
865
+
866
+ /* perform mime command */
867
+ static int procmime(const char *ibuf, int isiz, bool dec, const char *ename, bool qb, bool on,
868
+ bool hd, bool bd, int part){
869
+ if(hd || bd || part > 0){
870
+ TCMAP *hmap = tcmapnew2(16);
871
+ int osiz;
872
+ char *obuf = tcmimebreak(ibuf, isiz, hmap, &osiz);
873
+ if(part > 0){
874
+ const char *value;
875
+ if(!(value = tcmapget2(hmap, "TYPE")) || !tcstrifwm(value, "multipart/") ||
876
+ !(value = tcmapget2(hmap, "BOUNDARY"))){
877
+ eprintf("not multipart");
878
+ } else {
879
+ TCLIST *parts = tcmimeparts(obuf, osiz, value);
880
+ if(part <= tclistnum(parts)){
881
+ int bsiz;
882
+ const char *body = tclistval(parts, part - 1, &bsiz);
883
+ fwrite(body, 1, bsiz, stdout);
884
+ } else {
885
+ eprintf("no such part");
886
+ }
887
+ tclistdel(parts);
888
+ }
889
+ } else {
890
+ if(hd){
891
+ TCLIST *names = tcmapkeys(hmap);
892
+ tclistsort(names);
893
+ int num = tclistnum(names);
894
+ for(int i = 0; i < num; i++){
895
+ const char *name = tclistval2(names, i);
896
+ printf("%s\t%s\n", name, tcmapget2(hmap, name));
897
+ }
898
+ tclistdel(names);
899
+ if(bd) putchar('\n');
900
+ }
901
+ if(bd) fwrite(obuf, 1, osiz, stdout);
902
+ }
903
+ tcfree(obuf);
904
+ tcmapdel(hmap);
905
+ } else if(dec){
906
+ char ebuf[32];
907
+ char *obuf = tcmimedecode(ibuf, ebuf);
908
+ if(on){
909
+ fwrite(ebuf, 1, strlen(ebuf), stdout);
910
+ } else {
911
+ fwrite(obuf, 1, strlen(obuf), stdout);
912
+ }
913
+ tcfree(obuf);
914
+ } else {
915
+ char *obuf = tcmimeencode(ibuf, ename, !qb);
916
+ fwrite(obuf, 1, strlen(obuf), stdout);
917
+ tcfree(obuf);
918
+ }
919
+ return 0;
920
+ }
921
+
922
+
923
+ /* perform hex command */
924
+ static int prochex(const char *ibuf, int isiz, bool dec){
925
+ if(dec){
926
+ int osiz;
927
+ char *obuf = tchexdecode(ibuf, &osiz);
928
+ fwrite(obuf, 1, osiz, stdout);
929
+ tcfree(obuf);
930
+ } else {
931
+ char *obuf = tchexencode(ibuf, isiz);
932
+ fwrite(obuf, 1, strlen(obuf), stdout);
933
+ tcfree(obuf);
934
+ }
935
+ return 0;
936
+ }
937
+
938
+
939
+ /* perform pack command */
940
+ static int procpack(const char *ibuf, int isiz, bool dec, bool bwt){
941
+ if(dec){
942
+ int osiz;
943
+ char *obuf = tcpackdecode(ibuf, isiz, &osiz);
944
+ if(bwt && osiz > 0){
945
+ int idx, step;
946
+ TCREADVNUMBUF(obuf, idx, step);
947
+ char *tbuf = tcbwtdecode(obuf + step, osiz - step, idx);
948
+ fwrite(tbuf, 1, osiz - step, stdout);
949
+ tcfree(tbuf);
950
+ } else {
951
+ fwrite(obuf, 1, osiz, stdout);
952
+ }
953
+ tcfree(obuf);
954
+ } else {
955
+ char *tbuf = NULL;
956
+ if(bwt){
957
+ int idx;
958
+ tbuf = tcbwtencode(ibuf, isiz, &idx);
959
+ char vnumbuf[sizeof(int)+1];
960
+ int step;
961
+ TCSETVNUMBUF(step, vnumbuf, idx);
962
+ tbuf = tcrealloc(tbuf, isiz + step + 1);
963
+ memmove(tbuf + step, tbuf, isiz);
964
+ memcpy(tbuf, vnumbuf, step);
965
+ isiz += step;
966
+ ibuf = tbuf;
967
+ }
968
+ int osiz;
969
+ char *obuf = tcpackencode(ibuf, isiz, &osiz);
970
+ fwrite(obuf, 1, osiz, stdout);
971
+ tcfree(obuf);
972
+ tcfree(tbuf);
973
+ }
974
+ return 0;
975
+ }
976
+
977
+
978
+ /* perform tcbs command */
979
+ static int proctcbs(const char *ibuf, int isiz, bool dec){
980
+ if(dec){
981
+ int osiz;
982
+ char *obuf = tcbsdecode(ibuf, isiz, &osiz);
983
+ fwrite(obuf, 1, osiz, stdout);
984
+ tcfree(obuf);
985
+ } else {
986
+ int osiz;
987
+ char *obuf = tcbsencode(ibuf, isiz, &osiz);
988
+ fwrite(obuf, 1, osiz, stdout);
989
+ tcfree(obuf);
990
+ }
991
+ return 0;
992
+ }
993
+
994
+
995
+ /* perform zlib command */
996
+ static int proczlib(const char *ibuf, int isiz, bool dec, bool gz){
997
+ if(dec){
998
+ int osiz;
999
+ char *obuf = gz ? tcgzipdecode(ibuf, isiz, &osiz) : tcinflate(ibuf, isiz, &osiz);
1000
+ if(obuf){
1001
+ fwrite(obuf, 1, osiz, stdout);
1002
+ tcfree(obuf);
1003
+ } else {
1004
+ eprintf("inflate failure");
1005
+ }
1006
+ } else {
1007
+ int osiz;
1008
+ char *obuf = gz ? tcgzipencode(ibuf, isiz, &osiz) : tcdeflate(ibuf, isiz, &osiz);
1009
+ if(obuf){
1010
+ fwrite(obuf, 1, osiz, stdout);
1011
+ tcfree(obuf);
1012
+ } else {
1013
+ eprintf("deflate failure");
1014
+ }
1015
+ }
1016
+ return 0;
1017
+ }
1018
+
1019
+
1020
+ /* perform bzip command */
1021
+ static int procbzip(const char *ibuf, int isiz, bool dec){
1022
+ if(dec){
1023
+ int osiz;
1024
+ char *obuf = tcbzipdecode(ibuf, isiz, &osiz);
1025
+ if(obuf){
1026
+ fwrite(obuf, 1, osiz, stdout);
1027
+ tcfree(obuf);
1028
+ } else {
1029
+ eprintf("inflate failure");
1030
+ }
1031
+ } else {
1032
+ int osiz;
1033
+ char *obuf = tcbzipencode(ibuf, isiz, &osiz);
1034
+ if(obuf){
1035
+ fwrite(obuf, 1, osiz, stdout);
1036
+ tcfree(obuf);
1037
+ } else {
1038
+ eprintf("deflate failure");
1039
+ }
1040
+ }
1041
+ return 0;
1042
+ }
1043
+
1044
+
1045
+ /* perform xml command */
1046
+ static int procxml(const char *ibuf, int isiz, bool dec, bool br){
1047
+ if(br){
1048
+ TCLIST *elems = tcxmlbreak(ibuf);
1049
+ for(int i = 0; i < tclistnum(elems); i++){
1050
+ int esiz;
1051
+ const char *elem = tclistval(elems, i, &esiz);
1052
+ char *estr = tcmemdup(elem, esiz);
1053
+ tcstrsubchr(estr, "\t\n\r", " ");
1054
+ tcstrtrim(estr);
1055
+ if(*estr != '\0'){
1056
+ if(*elem == '<'){
1057
+ if(tcstrfwm(estr, "<!--")){
1058
+ printf("COMMENT\t%s\n", estr);
1059
+ } else if(tcstrfwm(estr, "<![CDATA[")){
1060
+ printf("CDATA\t%s\n", estr);
1061
+ } else if(tcstrfwm(estr, "<!")){
1062
+ printf("DECL\t%s\n", estr);
1063
+ } else if(tcstrfwm(estr, "<?")){
1064
+ printf("XMLDECL\t%s\n", estr);
1065
+ } else {
1066
+ TCMAP *attrs = tcxmlattrs(estr);
1067
+ tcmapiterinit(attrs);
1068
+ const char *name;
1069
+ if((name = tcmapget2(attrs, "")) != NULL){
1070
+ if(tcstrfwm(estr, "</")){
1071
+ printf("END");
1072
+ } else if(tcstrbwm(estr, "/>")){
1073
+ printf("EMPTY");
1074
+ } else {
1075
+ printf("BEGIN");
1076
+ }
1077
+ printf("\t%s", name);
1078
+ while((name = tcmapiternext2(attrs)) != NULL){
1079
+ if(*name == '\0') continue;
1080
+ printf("\t%s\t%s", name, tcmapiterval2(name));
1081
+ }
1082
+ printf("\n");
1083
+ }
1084
+ tcmapdel(attrs);
1085
+ }
1086
+ } else {
1087
+ char *dstr = tcxmlunescape(estr);
1088
+ printf("TEXT\t%s\n", dstr);
1089
+ tcfree(dstr);
1090
+ }
1091
+ }
1092
+ tcfree(estr);
1093
+ }
1094
+ tclistdel(elems);
1095
+ } else if(dec){
1096
+ char *obuf = tcxmlunescape(ibuf);
1097
+ fwrite(obuf, 1, strlen(obuf), stdout);
1098
+ tcfree(obuf);
1099
+ } else {
1100
+ char *obuf = tcxmlescape(ibuf);
1101
+ fwrite(obuf, 1, strlen(obuf), stdout);
1102
+ tcfree(obuf);
1103
+ }
1104
+ return 0;
1105
+ }
1106
+
1107
+
1108
+ /* perform cstr command */
1109
+ static int proccstr(const char *ibuf, int isiz, bool dec, bool js){
1110
+ if(js){
1111
+ if(dec){
1112
+ char *ostr = tcjsonunescape(ibuf);
1113
+ printf("%s", ostr);
1114
+ tcfree(ostr);
1115
+ } else {
1116
+ char *ostr = tcjsonescape(ibuf);
1117
+ printf("%s", ostr);
1118
+ tcfree(ostr);
1119
+ }
1120
+ } else {
1121
+ if(dec){
1122
+ char *ostr = tccstrunescape(ibuf);
1123
+ printf("%s", ostr);
1124
+ tcfree(ostr);
1125
+ } else {
1126
+ char *ostr = tccstrescape(ibuf);
1127
+ printf("%s", ostr);
1128
+ tcfree(ostr);
1129
+ }
1130
+ }
1131
+ return 0;
1132
+ }
1133
+
1134
+
1135
+ /* perform ucs command */
1136
+ static int procucs(const char *ibuf, int isiz, bool dec, bool un, const char *kw){
1137
+ if(un){
1138
+ uint16_t *ary = tcmalloc(isiz * sizeof(uint16_t) + 1);
1139
+ int anum;
1140
+ tcstrutftoucs(ibuf, ary, &anum);
1141
+ anum = tcstrucsnorm(ary, anum, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
1142
+ char *str = tcmalloc(anum * 3 + 1);
1143
+ tcstrucstoutf(ary, anum, str);
1144
+ printf("%s", str);
1145
+ tcfree(str);
1146
+ tcfree(ary);
1147
+ } else if(kw){
1148
+ TCLIST *words = tcstrtokenize(kw);
1149
+ TCLIST *texts = tcstrkwic(ibuf, words, 10, TCKWMUTAB);
1150
+ for(int i = 0; i < tclistnum(texts); i++){
1151
+ printf("%s\n", tclistval2(texts, i));
1152
+ }
1153
+ tclistdel(texts);
1154
+ tclistdel(words);
1155
+ } else if(dec){
1156
+ uint16_t *ary = tcmalloc(isiz + 1);
1157
+ int anum = 0;
1158
+ for(int i = 0; i < isiz; i += 2){
1159
+ ary[anum++] = (((unsigned char *)ibuf)[i] << 8) + ((unsigned char *)ibuf)[i+1];
1160
+ }
1161
+ char *str = tcmalloc(isiz * 3 + 1);
1162
+ tcstrucstoutf(ary, anum, str);
1163
+ printf("%s", str);
1164
+ tcfree(str);
1165
+ tcfree(ary);
1166
+ } else {
1167
+ uint16_t *ary = tcmalloc(isiz * sizeof(uint16_t) + 1);
1168
+ int anum;
1169
+ tcstrutftoucs(ibuf, ary, &anum);
1170
+ for(int i = 0; i < anum; i++){
1171
+ int c = ary[i];
1172
+ putchar(c >> 8);
1173
+ putchar(c & 0xff);
1174
+ }
1175
+ tcfree(ary);
1176
+ }
1177
+ return 0;
1178
+ }
1179
+
1180
+
1181
+ /* perform hash command */
1182
+ static int prochash(const char *ibuf, int isiz, bool crc, int ch){
1183
+ if(crc){
1184
+ printf("%08x\n", tcgetcrc(ibuf, isiz));
1185
+ } else if(ch > 0){
1186
+ TCCHIDX *chidx = tcchidxnew(ch);
1187
+ printf("%d\n", tcchidxhash(chidx, ibuf, isiz));
1188
+ tcchidxdel(chidx);
1189
+ } else {
1190
+ char buf[48];
1191
+ tcmd5hash(ibuf, isiz, buf);
1192
+ printf("%s\n", buf);
1193
+ }
1194
+ return 0;
1195
+ }
1196
+
1197
+
1198
+ /* perform cipher command */
1199
+ static int proccipher(const char *ibuf, int isiz, const char *key){
1200
+ char *obuf = tcmalloc(isiz + 1);
1201
+ const char *kbuf = "";
1202
+ int ksiz = 0;
1203
+ if(key){
1204
+ kbuf = key;
1205
+ ksiz = strlen(key);
1206
+ }
1207
+ tcarccipher(ibuf, isiz, kbuf, ksiz, obuf);
1208
+ fwrite(obuf, 1, isiz, stdout);
1209
+ tcfree(obuf);
1210
+ return 0;
1211
+ }
1212
+
1213
+
1214
+ /* perform date command */
1215
+ static int procdate(const char *str, int jl, bool wf, bool rf){
1216
+ int64_t t = str ? tcstrmktime(str) : time(NULL);
1217
+ if(wf){
1218
+ char buf[48];
1219
+ tcdatestrwww(t, jl, buf);
1220
+ printf("%s\n", buf);
1221
+ } else if(rf){
1222
+ char buf[48];
1223
+ tcdatestrhttp(t, jl, buf);
1224
+ printf("%s\n", buf);
1225
+ } else {
1226
+ printf("%lld\n", (long long int)t);
1227
+ }
1228
+ return 0;
1229
+ }
1230
+
1231
+
1232
+ /* perform tmpl command */
1233
+ static int proctmpl(const char *ibuf, int isiz, TCMAP *vars){
1234
+ TCTMPL *tmpl = tctmplnew();
1235
+ tctmplload(tmpl, ibuf);
1236
+ char *str = tctmpldump(tmpl, vars);
1237
+ printf("%s", str);
1238
+ tcfree(str);
1239
+ tctmpldel(tmpl);
1240
+ return 0;
1241
+ }
1242
+
1243
+
1244
+ /* perform conf command */
1245
+ static int procconf(int mode){
1246
+ switch(mode){
1247
+ case 'v':
1248
+ printf("%s\n", tcversion);
1249
+ break;
1250
+ case 'i':
1251
+ printf("%s\n", _TC_APPINC);
1252
+ break;
1253
+ case 'l':
1254
+ printf("%s\n", _TC_APPLIBS);
1255
+ break;
1256
+ case 'p':
1257
+ printf("%s\n", _TC_BINDIR);
1258
+ break;
1259
+ default:
1260
+ printf("myconf(version): %s\n", tcversion);
1261
+ printf("myconf(sysname): %s\n", TCSYSNAME);
1262
+ printf("myconf(libver): %d\n", _TC_LIBVER);
1263
+ printf("myconf(formatver): %s\n", _TC_FORMATVER);
1264
+ printf("myconf(prefix): %s\n", _TC_PREFIX);
1265
+ printf("myconf(includedir): %s\n", _TC_INCLUDEDIR);
1266
+ printf("myconf(libdir): %s\n", _TC_LIBDIR);
1267
+ printf("myconf(bindir): %s\n", _TC_BINDIR);
1268
+ printf("myconf(libexecdir): %s\n", _TC_LIBEXECDIR);
1269
+ printf("myconf(appinc): %s\n", _TC_APPINC);
1270
+ printf("myconf(applibs): %s\n", _TC_APPLIBS);
1271
+ printf("myconf(bigend): %d\n", TCBIGEND);
1272
+ printf("myconf(usezlib): %d\n", TCUSEZLIB);
1273
+ printf("myconf(usebzip): %d\n", TCUSEBZIP);
1274
+ printf("type(bool): size=%d align=%d offset=%d max=%llu\n",
1275
+ (int)sizeof(bool), (int)_alignof(bool), TCALIGNOF(bool),
1276
+ (unsigned long long)true);
1277
+ printf("type(char): size=%d align=%d offset=%d max=%llu\n",
1278
+ (int)sizeof(char), (int)_alignof(char), TCALIGNOF(char),
1279
+ (unsigned long long)CHAR_MAX);
1280
+ printf("type(short): size=%d align=%d offset=%d max=%llu\n",
1281
+ (int)sizeof(short), (int)_alignof(short), TCALIGNOF(short),
1282
+ (unsigned long long)SHRT_MAX);
1283
+ printf("type(int): size=%d align=%d offset=%d max=%llu\n",
1284
+ (int)sizeof(int), (int)_alignof(int), TCALIGNOF(int),
1285
+ (unsigned long long)INT_MAX);
1286
+ printf("type(long): size=%d align=%d offset=%d max=%llu\n",
1287
+ (int)sizeof(long), (int)_alignof(long), TCALIGNOF(long),
1288
+ (unsigned long long)LONG_MAX);
1289
+ printf("type(long long): size=%d align=%d offset=%d max=%llu\n",
1290
+ (int)sizeof(long long), (int)_alignof(long long), TCALIGNOF(long long),
1291
+ (unsigned long long)LLONG_MAX);
1292
+ printf("type(float): size=%d align=%d offset=%d max=%g\n",
1293
+ (int)sizeof(float), (int)_alignof(float), TCALIGNOF(float),
1294
+ (double)FLT_MAX);
1295
+ printf("type(double): size=%d align=%d offset=%d max=%g\n",
1296
+ (int)sizeof(double), (int)_alignof(double), TCALIGNOF(double),
1297
+ (double)DBL_MAX);
1298
+ printf("type(long double): size=%d align=%d offset=%d max=%Lg\n",
1299
+ (int)sizeof(long double), (int)_alignof(long double), TCALIGNOF(long double),
1300
+ (long double)LDBL_MAX);
1301
+ printf("type(void *): size=%d align=%d offset=%d\n",
1302
+ (int)sizeof(void *), (int)_alignof(void *), TCALIGNOF(void *));
1303
+ printf("type(intptr_t): size=%d align=%d offset=%d max=%llu\n",
1304
+ (int)sizeof(intptr_t), (int)_alignof(intptr_t), TCALIGNOF(intptr_t),
1305
+ (unsigned long long)INTPTR_MAX);
1306
+ printf("type(size_t): size=%d align=%d offset=%d max=%llu\n",
1307
+ (int)sizeof(size_t), (int)_alignof(size_t), TCALIGNOF(size_t),
1308
+ (unsigned long long)SIZE_MAX);
1309
+ printf("type(ptrdiff_t): size=%d align=%d offset=%d max=%llu\n",
1310
+ (int)sizeof(ptrdiff_t), (int)_alignof(ptrdiff_t), TCALIGNOF(ptrdiff_t),
1311
+ (unsigned long long)PTRDIFF_MAX);
1312
+ printf("type(wchar_t): size=%d align=%d offset=%d max=%llu\n",
1313
+ (int)sizeof(wchar_t), (int)_alignof(wchar_t), TCALIGNOF(wchar_t),
1314
+ (unsigned long long)WCHAR_MAX);
1315
+ printf("type(sig_atomic_t): size=%d align=%d offset=%d max=%llu\n",
1316
+ (int)sizeof(sig_atomic_t), (int)_alignof(sig_atomic_t), TCALIGNOF(sig_atomic_t),
1317
+ (unsigned long long)SIG_ATOMIC_MAX);
1318
+ printf("type(time_t): size=%d align=%d offset=%d max=%llu\n",
1319
+ (int)sizeof(time_t), (int)_alignof(time_t), TCALIGNOF(time_t),
1320
+ (unsigned long long)_maxof(time_t));
1321
+ printf("type(off_t): size=%d align=%d offset=%d max=%llu\n",
1322
+ (int)sizeof(off_t), (int)_alignof(off_t), TCALIGNOF(off_t),
1323
+ (unsigned long long)_maxof(off_t));
1324
+ printf("type(ino_t): size=%d align=%d offset=%d max=%llu\n",
1325
+ (int)sizeof(ino_t), (int)_alignof(ino_t), TCALIGNOF(ino_t),
1326
+ (unsigned long long)_maxof(ino_t));
1327
+ printf("type(tcgeneric_t): size=%d align=%d offset=%d\n",
1328
+ (int)sizeof(tcgeneric_t), (int)_alignof(tcgeneric_t), TCALIGNOF(tcgeneric_t));
1329
+ printf("macro(RAND_MAX): %llu\n", (unsigned long long)RAND_MAX);
1330
+ printf("macro(PATH_MAX): %llu\n", (unsigned long long)PATH_MAX);
1331
+ printf("macro(NAME_MAX): %llu\n", (unsigned long long)NAME_MAX);
1332
+ printf("macro(P_tmpdir): %s\n", P_tmpdir);
1333
+ printf("sysconf(_SC_CLK_TCK): %ld\n", sysconf(_SC_CLK_TCK));
1334
+ printf("sysconf(_SC_OPEN_MAX): %ld\n", sysconf(_SC_OPEN_MAX));
1335
+ printf("sysconf(_SC_PAGESIZE): %ld\n", sysconf(_SC_PAGESIZE));
1336
+ TCMAP *info = tcsysinfo();
1337
+ if(info){
1338
+ tcmapiterinit(info);
1339
+ const char *name;
1340
+ while((name = tcmapiternext2(info)) != NULL){
1341
+ printf("sysinfo(%s): %s\n", name, tcmapiterval2(name));
1342
+ }
1343
+ tcmapdel(info);
1344
+ }
1345
+ struct stat sbuf;
1346
+ if(stat(MYCDIRSTR, &sbuf) == 0){
1347
+ printf("stat(st_uid): %d\n", (int)sbuf.st_uid);
1348
+ printf("stat(st_gid): %d\n", (int)sbuf.st_gid);
1349
+ printf("stat(st_blksize): %d\n", (int)sbuf.st_blksize);
1350
+ }
1351
+ }
1352
+ return 0;
1353
+ }
1354
+
1355
+
1356
+
1357
+ // END OF FILE