shoesgem 0.1424.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (808) hide show
  1. data/LICENSE +30 -0
  2. data/README.rdoc +31 -0
  3. data/lib/shoes.rb +4 -0
  4. data/shoes/CHANGELOG.txt +21 -0
  5. data/shoes/COPYING.txt +30 -0
  6. data/shoes/README.txt +117 -0
  7. data/shoes/VERSION.txt +1 -0
  8. data/shoes/fonts/Coolvetica.ttf +0 -0
  9. data/shoes/fonts/Lacuna.ttf +0 -0
  10. data/shoes/freetype6.dll +0 -0
  11. data/shoes/lib/shoes/cache.rb +54 -0
  12. data/shoes/lib/shoes/data.rb +39 -0
  13. data/shoes/lib/shoes/help.rb +421 -0
  14. data/shoes/lib/shoes/image.rb +25 -0
  15. data/shoes/lib/shoes/inspect.rb +128 -0
  16. data/shoes/lib/shoes/log.rb +48 -0
  17. data/shoes/lib/shoes/minitar.rb +986 -0
  18. data/shoes/lib/shoes/override.rb +38 -0
  19. data/shoes/lib/shoes/pack.rb +503 -0
  20. data/shoes/lib/shoes/search.rb +46 -0
  21. data/shoes/lib/shoes/setup.rb +329 -0
  22. data/shoes/lib/shoes/shy.rb +131 -0
  23. data/shoes/lib/shoes/shybuilder.rb +44 -0
  24. data/shoes/lib/shoes.rb +522 -0
  25. data/shoes/libcairo-2.dll +0 -0
  26. data/shoes/libeay32.dll +0 -0
  27. data/shoes/libexpat-1.dll +0 -0
  28. data/shoes/libfontconfig-1.dll +0 -0
  29. data/shoes/libgio-2.0-0.dll +0 -0
  30. data/shoes/libglib-2.0-0.dll +0 -0
  31. data/shoes/libgmodule-2.0-0.dll +0 -0
  32. data/shoes/libgobject-2.0-0.dll +0 -0
  33. data/shoes/libgthread-2.0-0.dll +0 -0
  34. data/shoes/libiconv2.dll +0 -0
  35. data/shoes/libjpeg-8.dll +0 -0
  36. data/shoes/libpango-1.0-0.dll +0 -0
  37. data/shoes/libpangocairo-1.0-0.dll +0 -0
  38. data/shoes/libpangoft2-1.0-0.dll +0 -0
  39. data/shoes/libpangowin32-1.0-0.dll +0 -0
  40. data/shoes/libpng14-14.dll +0 -0
  41. data/shoes/libportaudio-2.dll +0 -0
  42. data/shoes/libshoes.dll +0 -0
  43. data/shoes/libssl32.dll +0 -0
  44. data/shoes/libungif4.dll +0 -0
  45. data/shoes/msvcrt-ruby191.dll +0 -0
  46. data/shoes/readline5.dll +0 -0
  47. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/fast_xs.so +0 -0
  48. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/blankslate.rb +63 -0
  49. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/builder.rb +216 -0
  50. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/elements.rb +510 -0
  51. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/htmlinfo.rb +691 -0
  52. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/inspect.rb +103 -0
  53. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/modules.rb +40 -0
  54. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/parse.rb +38 -0
  55. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/tag.rb +202 -0
  56. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/tags.rb +164 -0
  57. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/traverse.rb +838 -0
  58. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/xchar.rb +94 -0
  59. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot.rb +26 -0
  60. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot_scan.so +0 -0
  61. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/add/core.rb +135 -0
  62. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/add/rails.rb +58 -0
  63. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/common.rb +354 -0
  64. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/ext/generator.so +0 -0
  65. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/ext/parser.so +0 -0
  66. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/ext.rb +13 -0
  67. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/version.rb +9 -0
  68. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json.rb +8 -0
  69. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/constants.rb +49 -0
  70. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/database.rb +721 -0
  71. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/driver/dl/api.rb +152 -0
  72. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/driver/dl/driver.rb +307 -0
  73. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/driver/native/driver.rb +219 -0
  74. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/errors.rb +68 -0
  75. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/pragmas.rb +271 -0
  76. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/resultset.rb +180 -0
  77. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/statement.rb +231 -0
  78. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/translator.rb +109 -0
  79. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/value.rb +57 -0
  80. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/version.rb +16 -0
  81. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3.rb +1 -0
  82. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3_api.so +0 -0
  83. data/shoes/ruby/gems/1.9.1/specifications/hpricot-0.8.1.gemspec +32 -0
  84. data/shoes/ruby/gems/1.9.1/specifications/json-shoes-1.1.3.gemspec +34 -0
  85. data/shoes/ruby/gems/1.9.1/specifications/sqlite3-ruby-1.2.5-x86-mswin32.gemspec +46 -0
  86. data/shoes/ruby/lib/English.rb +155 -0
  87. data/shoes/ruby/lib/Win32API.rb +28 -0
  88. data/shoes/ruby/lib/abbrev.rb +103 -0
  89. data/shoes/ruby/lib/base64.rb +91 -0
  90. data/shoes/ruby/lib/benchmark.rb +573 -0
  91. data/shoes/ruby/lib/bigdecimal/jacobian.rb +85 -0
  92. data/shoes/ruby/lib/bigdecimal/ludcmp.rb +86 -0
  93. data/shoes/ruby/lib/bigdecimal/math.rb +237 -0
  94. data/shoes/ruby/lib/bigdecimal/newton.rb +77 -0
  95. data/shoes/ruby/lib/bigdecimal/util.rb +53 -0
  96. data/shoes/ruby/lib/cgi/cookie.rb +144 -0
  97. data/shoes/ruby/lib/cgi/core.rb +786 -0
  98. data/shoes/ruby/lib/cgi/html.rb +1021 -0
  99. data/shoes/ruby/lib/cgi/session/pstore.rb +111 -0
  100. data/shoes/ruby/lib/cgi/session.rb +537 -0
  101. data/shoes/ruby/lib/cgi/util.rb +181 -0
  102. data/shoes/ruby/lib/cgi.rb +274 -0
  103. data/shoes/ruby/lib/cmath.rb +233 -0
  104. data/shoes/ruby/lib/complex.rb +24 -0
  105. data/shoes/ruby/lib/csv.rb +2320 -0
  106. data/shoes/ruby/lib/date/format.rb +1313 -0
  107. data/shoes/ruby/lib/date.rb +1834 -0
  108. data/shoes/ruby/lib/debug.rb +907 -0
  109. data/shoes/ruby/lib/delegate.rb +311 -0
  110. data/shoes/ruby/lib/digest/hmac.rb +274 -0
  111. data/shoes/ruby/lib/digest/sha2.rb +74 -0
  112. data/shoes/ruby/lib/digest.rb +50 -0
  113. data/shoes/ruby/lib/dl/callback.rb +69 -0
  114. data/shoes/ruby/lib/dl/cparser.rb +109 -0
  115. data/shoes/ruby/lib/dl/func.rb +153 -0
  116. data/shoes/ruby/lib/dl/import.rb +215 -0
  117. data/shoes/ruby/lib/dl/pack.rb +173 -0
  118. data/shoes/ruby/lib/dl/stack.rb +146 -0
  119. data/shoes/ruby/lib/dl/struct.rb +213 -0
  120. data/shoes/ruby/lib/dl/types.rb +40 -0
  121. data/shoes/ruby/lib/dl/value.rb +112 -0
  122. data/shoes/ruby/lib/drb/acl.rb +146 -0
  123. data/shoes/ruby/lib/drb/drb.rb +1778 -0
  124. data/shoes/ruby/lib/drb/eq.rb +16 -0
  125. data/shoes/ruby/lib/drb/extserv.rb +71 -0
  126. data/shoes/ruby/lib/drb/extservm.rb +85 -0
  127. data/shoes/ruby/lib/drb/gw.rb +122 -0
  128. data/shoes/ruby/lib/drb/invokemethod.rb +34 -0
  129. data/shoes/ruby/lib/drb/observer.rb +22 -0
  130. data/shoes/ruby/lib/drb/ssl.rb +190 -0
  131. data/shoes/ruby/lib/drb/timeridconv.rb +91 -0
  132. data/shoes/ruby/lib/drb/unix.rb +108 -0
  133. data/shoes/ruby/lib/drb.rb +2 -0
  134. data/shoes/ruby/lib/e2mmap.rb +172 -0
  135. data/shoes/ruby/lib/erb.rb +902 -0
  136. data/shoes/ruby/lib/fileutils.rb +1592 -0
  137. data/shoes/ruby/lib/find.rb +81 -0
  138. data/shoes/ruby/lib/forwardable.rb +270 -0
  139. data/shoes/ruby/lib/ftsearch/analysis/analyzer.rb +16 -0
  140. data/shoes/ruby/lib/ftsearch/analysis/simple_identifier_analyzer.rb +23 -0
  141. data/shoes/ruby/lib/ftsearch/analysis/whitespace_analyzer.rb +22 -0
  142. data/shoes/ruby/lib/ftsearch/document_map_reader.rb +106 -0
  143. data/shoes/ruby/lib/ftsearch/document_map_writer.rb +46 -0
  144. data/shoes/ruby/lib/ftsearch/field_infos.rb +46 -0
  145. data/shoes/ruby/lib/ftsearch/fragment_writer.rb +114 -0
  146. data/shoes/ruby/lib/ftsearch/fulltext_reader.rb +52 -0
  147. data/shoes/ruby/lib/ftsearch/fulltext_writer.rb +75 -0
  148. data/shoes/ruby/lib/ftsearch/suffix_array_reader.rb +275 -0
  149. data/shoes/ruby/lib/ftsearch/suffix_array_writer.rb +99 -0
  150. data/shoes/ruby/lib/ftsearch/util.rb +21 -0
  151. data/shoes/ruby/lib/getoptlong.rb +610 -0
  152. data/shoes/ruby/lib/gserver.rb +253 -0
  153. data/shoes/ruby/lib/i386-mingw32/bigdecimal.so +0 -0
  154. data/shoes/ruby/lib/i386-mingw32/binject.so +0 -0
  155. data/shoes/ruby/lib/i386-mingw32/bloops.so +0 -0
  156. data/shoes/ruby/lib/i386-mingw32/continuation.so +0 -0
  157. data/shoes/ruby/lib/i386-mingw32/coverage.so +0 -0
  158. data/shoes/ruby/lib/i386-mingw32/curses.so +0 -0
  159. data/shoes/ruby/lib/i386-mingw32/digest/bubblebabble.so +0 -0
  160. data/shoes/ruby/lib/i386-mingw32/digest/md5.so +0 -0
  161. data/shoes/ruby/lib/i386-mingw32/digest/rmd160.so +0 -0
  162. data/shoes/ruby/lib/i386-mingw32/digest/sha1.so +0 -0
  163. data/shoes/ruby/lib/i386-mingw32/digest/sha2.so +0 -0
  164. data/shoes/ruby/lib/i386-mingw32/digest.so +0 -0
  165. data/shoes/ruby/lib/i386-mingw32/dl.so +0 -0
  166. data/shoes/ruby/lib/i386-mingw32/enc/big5.so +0 -0
  167. data/shoes/ruby/lib/i386-mingw32/enc/cp949.so +0 -0
  168. data/shoes/ruby/lib/i386-mingw32/enc/emacs_mule.so +0 -0
  169. data/shoes/ruby/lib/i386-mingw32/enc/encdb.so +0 -0
  170. data/shoes/ruby/lib/i386-mingw32/enc/euc_jp.so +0 -0
  171. data/shoes/ruby/lib/i386-mingw32/enc/euc_kr.so +0 -0
  172. data/shoes/ruby/lib/i386-mingw32/enc/euc_tw.so +0 -0
  173. data/shoes/ruby/lib/i386-mingw32/enc/gb18030.so +0 -0
  174. data/shoes/ruby/lib/i386-mingw32/enc/gb2312.so +0 -0
  175. data/shoes/ruby/lib/i386-mingw32/enc/gbk.so +0 -0
  176. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_1.so +0 -0
  177. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_10.so +0 -0
  178. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_11.so +0 -0
  179. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_13.so +0 -0
  180. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_14.so +0 -0
  181. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_15.so +0 -0
  182. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_16.so +0 -0
  183. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_2.so +0 -0
  184. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_3.so +0 -0
  185. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_4.so +0 -0
  186. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_5.so +0 -0
  187. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_6.so +0 -0
  188. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_7.so +0 -0
  189. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_8.so +0 -0
  190. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_9.so +0 -0
  191. data/shoes/ruby/lib/i386-mingw32/enc/koi8_r.so +0 -0
  192. data/shoes/ruby/lib/i386-mingw32/enc/koi8_u.so +0 -0
  193. data/shoes/ruby/lib/i386-mingw32/enc/shift_jis.so +0 -0
  194. data/shoes/ruby/lib/i386-mingw32/enc/trans/big5.so +0 -0
  195. data/shoes/ruby/lib/i386-mingw32/enc/trans/chinese.so +0 -0
  196. data/shoes/ruby/lib/i386-mingw32/enc/trans/escape.so +0 -0
  197. data/shoes/ruby/lib/i386-mingw32/enc/trans/gb18030.so +0 -0
  198. data/shoes/ruby/lib/i386-mingw32/enc/trans/gbk.so +0 -0
  199. data/shoes/ruby/lib/i386-mingw32/enc/trans/iso2022.so +0 -0
  200. data/shoes/ruby/lib/i386-mingw32/enc/trans/japanese.so +0 -0
  201. data/shoes/ruby/lib/i386-mingw32/enc/trans/japanese_euc.so +0 -0
  202. data/shoes/ruby/lib/i386-mingw32/enc/trans/japanese_sjis.so +0 -0
  203. data/shoes/ruby/lib/i386-mingw32/enc/trans/korean.so +0 -0
  204. data/shoes/ruby/lib/i386-mingw32/enc/trans/single_byte.so +0 -0
  205. data/shoes/ruby/lib/i386-mingw32/enc/trans/transdb.so +0 -0
  206. data/shoes/ruby/lib/i386-mingw32/enc/trans/utf_16_32.so +0 -0
  207. data/shoes/ruby/lib/i386-mingw32/enc/utf_16be.so +0 -0
  208. data/shoes/ruby/lib/i386-mingw32/enc/utf_16le.so +0 -0
  209. data/shoes/ruby/lib/i386-mingw32/enc/utf_32be.so +0 -0
  210. data/shoes/ruby/lib/i386-mingw32/enc/utf_32le.so +0 -0
  211. data/shoes/ruby/lib/i386-mingw32/enc/windows_1251.so +0 -0
  212. data/shoes/ruby/lib/i386-mingw32/etc.so +0 -0
  213. data/shoes/ruby/lib/i386-mingw32/fcntl.so +0 -0
  214. data/shoes/ruby/lib/i386-mingw32/fiber.so +0 -0
  215. data/shoes/ruby/lib/i386-mingw32/ftsearchrt.so +0 -0
  216. data/shoes/ruby/lib/i386-mingw32/gdbm.so +0 -0
  217. data/shoes/ruby/lib/i386-mingw32/iconv.so +0 -0
  218. data/shoes/ruby/lib/i386-mingw32/io/wait.so +0 -0
  219. data/shoes/ruby/lib/i386-mingw32/json/ext/generator.so +0 -0
  220. data/shoes/ruby/lib/i386-mingw32/json/ext/parser.so +0 -0
  221. data/shoes/ruby/lib/i386-mingw32/mathn/complex.so +0 -0
  222. data/shoes/ruby/lib/i386-mingw32/mathn/rational.so +0 -0
  223. data/shoes/ruby/lib/i386-mingw32/nkf.so +0 -0
  224. data/shoes/ruby/lib/i386-mingw32/openssl.so +0 -0
  225. data/shoes/ruby/lib/i386-mingw32/racc/cparse.so +0 -0
  226. data/shoes/ruby/lib/i386-mingw32/rbconfig.rb +196 -0
  227. data/shoes/ruby/lib/i386-mingw32/readline.so +0 -0
  228. data/shoes/ruby/lib/i386-mingw32/ripper.so +0 -0
  229. data/shoes/ruby/lib/i386-mingw32/sdbm.so +0 -0
  230. data/shoes/ruby/lib/i386-mingw32/socket.so +0 -0
  231. data/shoes/ruby/lib/i386-mingw32/stringio.so +0 -0
  232. data/shoes/ruby/lib/i386-mingw32/strscan.so +0 -0
  233. data/shoes/ruby/lib/i386-mingw32/syck.so +0 -0
  234. data/shoes/ruby/lib/i386-mingw32/win32ole.so +0 -0
  235. data/shoes/ruby/lib/i386-mingw32/zlib.so +0 -0
  236. data/shoes/ruby/lib/io/nonblock.rb +23 -0
  237. data/shoes/ruby/lib/ipaddr.rb +813 -0
  238. data/shoes/ruby/lib/irb/cmd/chws.rb +32 -0
  239. data/shoes/ruby/lib/irb/cmd/fork.rb +38 -0
  240. data/shoes/ruby/lib/irb/cmd/help.rb +36 -0
  241. data/shoes/ruby/lib/irb/cmd/load.rb +66 -0
  242. data/shoes/ruby/lib/irb/cmd/nop.rb +38 -0
  243. data/shoes/ruby/lib/irb/cmd/pushws.rb +38 -0
  244. data/shoes/ruby/lib/irb/cmd/subirb.rb +42 -0
  245. data/shoes/ruby/lib/irb/completion.rb +207 -0
  246. data/shoes/ruby/lib/irb/context.rb +255 -0
  247. data/shoes/ruby/lib/irb/ext/change-ws.rb +61 -0
  248. data/shoes/ruby/lib/irb/ext/history.rb +109 -0
  249. data/shoes/ruby/lib/irb/ext/loader.rb +119 -0
  250. data/shoes/ruby/lib/irb/ext/math-mode.rb +36 -0
  251. data/shoes/ruby/lib/irb/ext/multi-irb.rb +240 -0
  252. data/shoes/ruby/lib/irb/ext/save-history.rb +100 -0
  253. data/shoes/ruby/lib/irb/ext/tracer.rb +60 -0
  254. data/shoes/ruby/lib/irb/ext/use-loader.rb +64 -0
  255. data/shoes/ruby/lib/irb/ext/workspaces.rb +55 -0
  256. data/shoes/ruby/lib/irb/extend-command.rb +272 -0
  257. data/shoes/ruby/lib/irb/frame.rb +66 -0
  258. data/shoes/ruby/lib/irb/help.rb +35 -0
  259. data/shoes/ruby/lib/irb/init.rb +288 -0
  260. data/shoes/ruby/lib/irb/input-method.rb +142 -0
  261. data/shoes/ruby/lib/irb/lc/error.rb +29 -0
  262. data/shoes/ruby/lib/irb/lc/help-message +38 -0
  263. data/shoes/ruby/lib/irb/lc/ja/encoding_aliases.rb +8 -0
  264. data/shoes/ruby/lib/irb/lc/ja/error.rb +27 -0
  265. data/shoes/ruby/lib/irb/lc/ja/help-message +39 -0
  266. data/shoes/ruby/lib/irb/locale.rb +195 -0
  267. data/shoes/ruby/lib/irb/magic-file.rb +36 -0
  268. data/shoes/ruby/lib/irb/notifier.rb +144 -0
  269. data/shoes/ruby/lib/irb/output-method.rb +69 -0
  270. data/shoes/ruby/lib/irb/ruby-lex.rb +1188 -0
  271. data/shoes/ruby/lib/irb/ruby-token.rb +270 -0
  272. data/shoes/ruby/lib/irb/slex.rb +282 -0
  273. data/shoes/ruby/lib/irb/src_encoding.rb +4 -0
  274. data/shoes/ruby/lib/irb/version.rb +15 -0
  275. data/shoes/ruby/lib/irb/workspace.rb +108 -0
  276. data/shoes/ruby/lib/irb/ws-for-case-2.rb +14 -0
  277. data/shoes/ruby/lib/irb/xmp.rb +97 -0
  278. data/shoes/ruby/lib/irb.rb +354 -0
  279. data/shoes/ruby/lib/json/add/core.rb +135 -0
  280. data/shoes/ruby/lib/json/add/rails.rb +58 -0
  281. data/shoes/ruby/lib/json/common.rb +354 -0
  282. data/shoes/ruby/lib/json/editor.rb +1371 -0
  283. data/shoes/ruby/lib/json/ext.rb +15 -0
  284. data/shoes/ruby/lib/json/version.rb +9 -0
  285. data/shoes/ruby/lib/json.rb +297 -0
  286. data/shoes/ruby/lib/kconv.rb +282 -0
  287. data/shoes/ruby/lib/logger.rb +732 -0
  288. data/shoes/ruby/lib/mathn.rb +206 -0
  289. data/shoes/ruby/lib/matrix.rb +1381 -0
  290. data/shoes/ruby/lib/minitest/autorun.rb +9 -0
  291. data/shoes/ruby/lib/minitest/mock.rb +37 -0
  292. data/shoes/ruby/lib/minitest/spec.rb +89 -0
  293. data/shoes/ruby/lib/minitest/unit.rb +497 -0
  294. data/shoes/ruby/lib/mkmf.rb +1958 -0
  295. data/shoes/ruby/lib/monitor.rb +265 -0
  296. data/shoes/ruby/lib/mutex_m.rb +91 -0
  297. data/shoes/ruby/lib/net/ftp.rb +981 -0
  298. data/shoes/ruby/lib/net/http.rb +2399 -0
  299. data/shoes/ruby/lib/net/https.rb +136 -0
  300. data/shoes/ruby/lib/net/imap.rb +3500 -0
  301. data/shoes/ruby/lib/net/pop.rb +1000 -0
  302. data/shoes/ruby/lib/net/protocol.rb +382 -0
  303. data/shoes/ruby/lib/net/smtp.rb +1014 -0
  304. data/shoes/ruby/lib/net/telnet.rb +759 -0
  305. data/shoes/ruby/lib/observer.rb +193 -0
  306. data/shoes/ruby/lib/open-uri.rb +832 -0
  307. data/shoes/ruby/lib/open3.rb +98 -0
  308. data/shoes/ruby/lib/openssl/bn.rb +35 -0
  309. data/shoes/ruby/lib/openssl/buffering.rb +242 -0
  310. data/shoes/ruby/lib/openssl/cipher.rb +65 -0
  311. data/shoes/ruby/lib/openssl/digest.rb +61 -0
  312. data/shoes/ruby/lib/openssl/ssl.rb +178 -0
  313. data/shoes/ruby/lib/openssl/x509.rb +155 -0
  314. data/shoes/ruby/lib/openssl.rb +24 -0
  315. data/shoes/ruby/lib/optparse/date.rb +17 -0
  316. data/shoes/ruby/lib/optparse/shellwords.rb +6 -0
  317. data/shoes/ruby/lib/optparse/time.rb +10 -0
  318. data/shoes/ruby/lib/optparse/uri.rb +6 -0
  319. data/shoes/ruby/lib/optparse/version.rb +70 -0
  320. data/shoes/ruby/lib/optparse.rb +1810 -0
  321. data/shoes/ruby/lib/ostruct.rb +145 -0
  322. data/shoes/ruby/lib/pathname.rb +1099 -0
  323. data/shoes/ruby/lib/pp.rb +532 -0
  324. data/shoes/ruby/lib/prettyprint.rb +896 -0
  325. data/shoes/ruby/lib/prime.rb +471 -0
  326. data/shoes/ruby/lib/profile.rb +10 -0
  327. data/shoes/ruby/lib/profiler.rb +59 -0
  328. data/shoes/ruby/lib/pstore.rb +543 -0
  329. data/shoes/ruby/lib/racc/parser.rb +441 -0
  330. data/shoes/ruby/lib/rake/classic_namespace.rb +8 -0
  331. data/shoes/ruby/lib/rake/clean.rb +33 -0
  332. data/shoes/ruby/lib/rake/gempackagetask.rb +97 -0
  333. data/shoes/ruby/lib/rake/loaders/makefile.rb +35 -0
  334. data/shoes/ruby/lib/rake/packagetask.rb +185 -0
  335. data/shoes/ruby/lib/rake/rake_test_loader.rb +5 -0
  336. data/shoes/ruby/lib/rake/rdoctask.rb +147 -0
  337. data/shoes/ruby/lib/rake/runtest.rb +23 -0
  338. data/shoes/ruby/lib/rake/tasklib.rb +23 -0
  339. data/shoes/ruby/lib/rake/testtask.rb +161 -0
  340. data/shoes/ruby/lib/rake/win32.rb +34 -0
  341. data/shoes/ruby/lib/rake.rb +2465 -0
  342. data/shoes/ruby/lib/rational.rb +19 -0
  343. data/shoes/ruby/lib/rbconfig/datadir.rb +24 -0
  344. data/shoes/ruby/lib/rdoc/code_objects.rb +1061 -0
  345. data/shoes/ruby/lib/rdoc/diagram.rb +340 -0
  346. data/shoes/ruby/lib/rdoc/dot.rb +249 -0
  347. data/shoes/ruby/lib/rdoc/generator/chm/chm.rb +100 -0
  348. data/shoes/ruby/lib/rdoc/generator/chm.rb +113 -0
  349. data/shoes/ruby/lib/rdoc/generator/html/common.rb +24 -0
  350. data/shoes/ruby/lib/rdoc/generator/html/frameless.rb +92 -0
  351. data/shoes/ruby/lib/rdoc/generator/html/hefss.rb +150 -0
  352. data/shoes/ruby/lib/rdoc/generator/html/html.rb +769 -0
  353. data/shoes/ruby/lib/rdoc/generator/html/kilmer.rb +151 -0
  354. data/shoes/ruby/lib/rdoc/generator/html/kilmerfactory.rb +427 -0
  355. data/shoes/ruby/lib/rdoc/generator/html/one_page_html.rb +122 -0
  356. data/shoes/ruby/lib/rdoc/generator/html.rb +445 -0
  357. data/shoes/ruby/lib/rdoc/generator/ri.rb +226 -0
  358. data/shoes/ruby/lib/rdoc/generator/texinfo/class.texinfo.erb +44 -0
  359. data/shoes/ruby/lib/rdoc/generator/texinfo/file.texinfo.erb +6 -0
  360. data/shoes/ruby/lib/rdoc/generator/texinfo/method.texinfo.erb +6 -0
  361. data/shoes/ruby/lib/rdoc/generator/texinfo/texinfo.erb +28 -0
  362. data/shoes/ruby/lib/rdoc/generator/texinfo.rb +81 -0
  363. data/shoes/ruby/lib/rdoc/generator/xml/rdf.rb +113 -0
  364. data/shoes/ruby/lib/rdoc/generator/xml/xml.rb +123 -0
  365. data/shoes/ruby/lib/rdoc/generator/xml.rb +117 -0
  366. data/shoes/ruby/lib/rdoc/generator.rb +1082 -0
  367. data/shoes/ruby/lib/rdoc/known_classes.rb +68 -0
  368. data/shoes/ruby/lib/rdoc/markup/attribute_manager.rb +265 -0
  369. data/shoes/ruby/lib/rdoc/markup/formatter.rb +14 -0
  370. data/shoes/ruby/lib/rdoc/markup/fragments.rb +337 -0
  371. data/shoes/ruby/lib/rdoc/markup/inline.rb +101 -0
  372. data/shoes/ruby/lib/rdoc/markup/lines.rb +152 -0
  373. data/shoes/ruby/lib/rdoc/markup/preprocess.rb +75 -0
  374. data/shoes/ruby/lib/rdoc/markup/to_flow.rb +185 -0
  375. data/shoes/ruby/lib/rdoc/markup/to_html.rb +403 -0
  376. data/shoes/ruby/lib/rdoc/markup/to_html_crossref.rb +148 -0
  377. data/shoes/ruby/lib/rdoc/markup/to_latex.rb +328 -0
  378. data/shoes/ruby/lib/rdoc/markup/to_test.rb +50 -0
  379. data/shoes/ruby/lib/rdoc/markup/to_texinfo.rb +69 -0
  380. data/shoes/ruby/lib/rdoc/markup.rb +378 -0
  381. data/shoes/ruby/lib/rdoc/options.rb +638 -0
  382. data/shoes/ruby/lib/rdoc/parser/c.rb +661 -0
  383. data/shoes/ruby/lib/rdoc/parser/f95.rb +1835 -0
  384. data/shoes/ruby/lib/rdoc/parser/perl.rb +165 -0
  385. data/shoes/ruby/lib/rdoc/parser/ruby.rb +2829 -0
  386. data/shoes/ruby/lib/rdoc/parser/simple.rb +38 -0
  387. data/shoes/ruby/lib/rdoc/parser.rb +142 -0
  388. data/shoes/ruby/lib/rdoc/rdoc.rb +293 -0
  389. data/shoes/ruby/lib/rdoc/ri/cache.rb +187 -0
  390. data/shoes/ruby/lib/rdoc/ri/descriptions.rb +156 -0
  391. data/shoes/ruby/lib/rdoc/ri/display.rb +392 -0
  392. data/shoes/ruby/lib/rdoc/ri/driver.rb +669 -0
  393. data/shoes/ruby/lib/rdoc/ri/formatter.rb +616 -0
  394. data/shoes/ruby/lib/rdoc/ri/paths.rb +99 -0
  395. data/shoes/ruby/lib/rdoc/ri/reader.rb +106 -0
  396. data/shoes/ruby/lib/rdoc/ri/util.rb +79 -0
  397. data/shoes/ruby/lib/rdoc/ri/writer.rb +68 -0
  398. data/shoes/ruby/lib/rdoc/ri.rb +8 -0
  399. data/shoes/ruby/lib/rdoc/stats.rb +115 -0
  400. data/shoes/ruby/lib/rdoc/template.rb +64 -0
  401. data/shoes/ruby/lib/rdoc/tokenstream.rb +33 -0
  402. data/shoes/ruby/lib/rdoc.rb +395 -0
  403. data/shoes/ruby/lib/resolv-replace.rb +63 -0
  404. data/shoes/ruby/lib/resolv.rb +2262 -0
  405. data/shoes/ruby/lib/rexml/attlistdecl.rb +62 -0
  406. data/shoes/ruby/lib/rexml/attribute.rb +188 -0
  407. data/shoes/ruby/lib/rexml/cdata.rb +67 -0
  408. data/shoes/ruby/lib/rexml/child.rb +96 -0
  409. data/shoes/ruby/lib/rexml/comment.rb +80 -0
  410. data/shoes/ruby/lib/rexml/doctype.rb +270 -0
  411. data/shoes/ruby/lib/rexml/document.rb +231 -0
  412. data/shoes/ruby/lib/rexml/dtd/attlistdecl.rb +10 -0
  413. data/shoes/ruby/lib/rexml/dtd/dtd.rb +51 -0
  414. data/shoes/ruby/lib/rexml/dtd/elementdecl.rb +17 -0
  415. data/shoes/ruby/lib/rexml/dtd/entitydecl.rb +56 -0
  416. data/shoes/ruby/lib/rexml/dtd/notationdecl.rb +39 -0
  417. data/shoes/ruby/lib/rexml/element.rb +1246 -0
  418. data/shoes/ruby/lib/rexml/encoding.rb +71 -0
  419. data/shoes/ruby/lib/rexml/encodings/CP-1252.rb +103 -0
  420. data/shoes/ruby/lib/rexml/encodings/EUC-JP.rb +35 -0
  421. data/shoes/ruby/lib/rexml/encodings/ICONV.rb +22 -0
  422. data/shoes/ruby/lib/rexml/encodings/ISO-8859-1.rb +7 -0
  423. data/shoes/ruby/lib/rexml/encodings/ISO-8859-15.rb +72 -0
  424. data/shoes/ruby/lib/rexml/encodings/SHIFT-JIS.rb +37 -0
  425. data/shoes/ruby/lib/rexml/encodings/SHIFT_JIS.rb +1 -0
  426. data/shoes/ruby/lib/rexml/encodings/UNILE.rb +34 -0
  427. data/shoes/ruby/lib/rexml/encodings/US-ASCII.rb +30 -0
  428. data/shoes/ruby/lib/rexml/encodings/UTF-16.rb +35 -0
  429. data/shoes/ruby/lib/rexml/encodings/UTF-8.rb +18 -0
  430. data/shoes/ruby/lib/rexml/entity.rb +166 -0
  431. data/shoes/ruby/lib/rexml/formatters/default.rb +109 -0
  432. data/shoes/ruby/lib/rexml/formatters/pretty.rb +139 -0
  433. data/shoes/ruby/lib/rexml/formatters/transitive.rb +58 -0
  434. data/shoes/ruby/lib/rexml/functions.rb +388 -0
  435. data/shoes/ruby/lib/rexml/instruction.rb +70 -0
  436. data/shoes/ruby/lib/rexml/light/node.rb +196 -0
  437. data/shoes/ruby/lib/rexml/namespace.rb +47 -0
  438. data/shoes/ruby/lib/rexml/node.rb +75 -0
  439. data/shoes/ruby/lib/rexml/output.rb +24 -0
  440. data/shoes/ruby/lib/rexml/parent.rb +166 -0
  441. data/shoes/ruby/lib/rexml/parseexception.rb +51 -0
  442. data/shoes/ruby/lib/rexml/parsers/baseparser.rb +530 -0
  443. data/shoes/ruby/lib/rexml/parsers/lightparser.rb +58 -0
  444. data/shoes/ruby/lib/rexml/parsers/pullparser.rb +196 -0
  445. data/shoes/ruby/lib/rexml/parsers/sax2parser.rb +247 -0
  446. data/shoes/ruby/lib/rexml/parsers/streamparser.rb +46 -0
  447. data/shoes/ruby/lib/rexml/parsers/treeparser.rb +100 -0
  448. data/shoes/ruby/lib/rexml/parsers/ultralightparser.rb +56 -0
  449. data/shoes/ruby/lib/rexml/parsers/xpathparser.rb +698 -0
  450. data/shoes/ruby/lib/rexml/quickpath.rb +263 -0
  451. data/shoes/ruby/lib/rexml/rexml.rb +31 -0
  452. data/shoes/ruby/lib/rexml/sax2listener.rb +97 -0
  453. data/shoes/ruby/lib/rexml/source.rb +258 -0
  454. data/shoes/ruby/lib/rexml/streamlistener.rb +92 -0
  455. data/shoes/ruby/lib/rexml/syncenumerator.rb +32 -0
  456. data/shoes/ruby/lib/rexml/text.rb +404 -0
  457. data/shoes/ruby/lib/rexml/undefinednamespaceexception.rb +8 -0
  458. data/shoes/ruby/lib/rexml/validation/relaxng.rb +559 -0
  459. data/shoes/ruby/lib/rexml/validation/validation.rb +155 -0
  460. data/shoes/ruby/lib/rexml/validation/validationexception.rb +9 -0
  461. data/shoes/ruby/lib/rexml/xmldecl.rb +119 -0
  462. data/shoes/ruby/lib/rexml/xmltokens.rb +18 -0
  463. data/shoes/ruby/lib/rexml/xpath.rb +77 -0
  464. data/shoes/ruby/lib/rexml/xpath_parser.rb +792 -0
  465. data/shoes/ruby/lib/rinda/rinda.rb +283 -0
  466. data/shoes/ruby/lib/rinda/ring.rb +271 -0
  467. data/shoes/ruby/lib/rinda/tuplespace.rb +642 -0
  468. data/shoes/ruby/lib/ripper/core.rb +70 -0
  469. data/shoes/ruby/lib/ripper/filter.rb +70 -0
  470. data/shoes/ruby/lib/ripper/lexer.rb +179 -0
  471. data/shoes/ruby/lib/ripper/sexp.rb +99 -0
  472. data/shoes/ruby/lib/ripper.rb +4 -0
  473. data/shoes/ruby/lib/rss/0.9.rb +427 -0
  474. data/shoes/ruby/lib/rss/1.0.rb +452 -0
  475. data/shoes/ruby/lib/rss/2.0.rb +111 -0
  476. data/shoes/ruby/lib/rss/atom.rb +748 -0
  477. data/shoes/ruby/lib/rss/content/1.0.rb +10 -0
  478. data/shoes/ruby/lib/rss/content/2.0.rb +12 -0
  479. data/shoes/ruby/lib/rss/content.rb +31 -0
  480. data/shoes/ruby/lib/rss/converter.rb +170 -0
  481. data/shoes/ruby/lib/rss/dublincore/1.0.rb +13 -0
  482. data/shoes/ruby/lib/rss/dublincore/2.0.rb +13 -0
  483. data/shoes/ruby/lib/rss/dublincore/atom.rb +17 -0
  484. data/shoes/ruby/lib/rss/dublincore.rb +161 -0
  485. data/shoes/ruby/lib/rss/image.rb +193 -0
  486. data/shoes/ruby/lib/rss/itunes.rb +410 -0
  487. data/shoes/ruby/lib/rss/maker/0.9.rb +467 -0
  488. data/shoes/ruby/lib/rss/maker/1.0.rb +434 -0
  489. data/shoes/ruby/lib/rss/maker/2.0.rb +223 -0
  490. data/shoes/ruby/lib/rss/maker/atom.rb +172 -0
  491. data/shoes/ruby/lib/rss/maker/base.rb +880 -0
  492. data/shoes/ruby/lib/rss/maker/content.rb +21 -0
  493. data/shoes/ruby/lib/rss/maker/dublincore.rb +124 -0
  494. data/shoes/ruby/lib/rss/maker/entry.rb +163 -0
  495. data/shoes/ruby/lib/rss/maker/feed.rb +430 -0
  496. data/shoes/ruby/lib/rss/maker/image.rb +111 -0
  497. data/shoes/ruby/lib/rss/maker/itunes.rb +242 -0
  498. data/shoes/ruby/lib/rss/maker/slash.rb +33 -0
  499. data/shoes/ruby/lib/rss/maker/syndication.rb +18 -0
  500. data/shoes/ruby/lib/rss/maker/taxonomy.rb +118 -0
  501. data/shoes/ruby/lib/rss/maker/trackback.rb +61 -0
  502. data/shoes/ruby/lib/rss/maker.rb +44 -0
  503. data/shoes/ruby/lib/rss/parser.rb +568 -0
  504. data/shoes/ruby/lib/rss/rexmlparser.rb +54 -0
  505. data/shoes/ruby/lib/rss/rss.rb +1313 -0
  506. data/shoes/ruby/lib/rss/slash.rb +49 -0
  507. data/shoes/ruby/lib/rss/syndication.rb +67 -0
  508. data/shoes/ruby/lib/rss/taxonomy.rb +145 -0
  509. data/shoes/ruby/lib/rss/trackback.rb +288 -0
  510. data/shoes/ruby/lib/rss/utils.rb +111 -0
  511. data/shoes/ruby/lib/rss/xml-stylesheet.rb +105 -0
  512. data/shoes/ruby/lib/rss/xml.rb +71 -0
  513. data/shoes/ruby/lib/rss/xmlparser.rb +93 -0
  514. data/shoes/ruby/lib/rss/xmlscanner.rb +121 -0
  515. data/shoes/ruby/lib/rss.rb +19 -0
  516. data/shoes/ruby/lib/rubygems/builder.rb +88 -0
  517. data/shoes/ruby/lib/rubygems/command.rb +406 -0
  518. data/shoes/ruby/lib/rubygems/command_manager.rb +146 -0
  519. data/shoes/ruby/lib/rubygems/commands/build_command.rb +53 -0
  520. data/shoes/ruby/lib/rubygems/commands/cert_command.rb +86 -0
  521. data/shoes/ruby/lib/rubygems/commands/check_command.rb +75 -0
  522. data/shoes/ruby/lib/rubygems/commands/cleanup_command.rb +91 -0
  523. data/shoes/ruby/lib/rubygems/commands/contents_command.rb +74 -0
  524. data/shoes/ruby/lib/rubygems/commands/dependency_command.rb +188 -0
  525. data/shoes/ruby/lib/rubygems/commands/environment_command.rb +128 -0
  526. data/shoes/ruby/lib/rubygems/commands/fetch_command.rb +62 -0
  527. data/shoes/ruby/lib/rubygems/commands/generate_index_command.rb +57 -0
  528. data/shoes/ruby/lib/rubygems/commands/help_command.rb +172 -0
  529. data/shoes/ruby/lib/rubygems/commands/install_command.rb +148 -0
  530. data/shoes/ruby/lib/rubygems/commands/list_command.rb +35 -0
  531. data/shoes/ruby/lib/rubygems/commands/lock_command.rb +110 -0
  532. data/shoes/ruby/lib/rubygems/commands/mirror_command.rb +111 -0
  533. data/shoes/ruby/lib/rubygems/commands/outdated_command.rb +33 -0
  534. data/shoes/ruby/lib/rubygems/commands/pristine_command.rb +93 -0
  535. data/shoes/ruby/lib/rubygems/commands/query_command.rb +233 -0
  536. data/shoes/ruby/lib/rubygems/commands/rdoc_command.rb +82 -0
  537. data/shoes/ruby/lib/rubygems/commands/search_command.rb +37 -0
  538. data/shoes/ruby/lib/rubygems/commands/server_command.rb +48 -0
  539. data/shoes/ruby/lib/rubygems/commands/sources_command.rb +152 -0
  540. data/shoes/ruby/lib/rubygems/commands/specification_command.rb +77 -0
  541. data/shoes/ruby/lib/rubygems/commands/stale_command.rb +27 -0
  542. data/shoes/ruby/lib/rubygems/commands/uninstall_command.rb +73 -0
  543. data/shoes/ruby/lib/rubygems/commands/unpack_command.rb +95 -0
  544. data/shoes/ruby/lib/rubygems/commands/update_command.rb +181 -0
  545. data/shoes/ruby/lib/rubygems/commands/which_command.rb +87 -0
  546. data/shoes/ruby/lib/rubygems/config_file.rb +266 -0
  547. data/shoes/ruby/lib/rubygems/custom_require.rb +46 -0
  548. data/shoes/ruby/lib/rubygems/defaults.rb +89 -0
  549. data/shoes/ruby/lib/rubygems/dependency.rb +119 -0
  550. data/shoes/ruby/lib/rubygems/dependency_installer.rb +258 -0
  551. data/shoes/ruby/lib/rubygems/dependency_list.rb +165 -0
  552. data/shoes/ruby/lib/rubygems/digest/digest_adapter.rb +40 -0
  553. data/shoes/ruby/lib/rubygems/digest/md5.rb +23 -0
  554. data/shoes/ruby/lib/rubygems/digest/sha1.rb +17 -0
  555. data/shoes/ruby/lib/rubygems/digest/sha2.rb +17 -0
  556. data/shoes/ruby/lib/rubygems/doc_manager.rb +214 -0
  557. data/shoes/ruby/lib/rubygems/exceptions.rb +84 -0
  558. data/shoes/ruby/lib/rubygems/ext/builder.rb +56 -0
  559. data/shoes/ruby/lib/rubygems/ext/configure_builder.rb +24 -0
  560. data/shoes/ruby/lib/rubygems/ext/ext_conf_builder.rb +23 -0
  561. data/shoes/ruby/lib/rubygems/ext/rake_builder.rb +27 -0
  562. data/shoes/ruby/lib/rubygems/ext.rb +18 -0
  563. data/shoes/ruby/lib/rubygems/format.rb +87 -0
  564. data/shoes/ruby/lib/rubygems/gem_openssl.rb +83 -0
  565. data/shoes/ruby/lib/rubygems/gem_path_searcher.rb +100 -0
  566. data/shoes/ruby/lib/rubygems/gem_runner.rb +58 -0
  567. data/shoes/ruby/lib/rubygems/indexer/abstract_index_builder.rb +88 -0
  568. data/shoes/ruby/lib/rubygems/indexer/latest_index_builder.rb +35 -0
  569. data/shoes/ruby/lib/rubygems/indexer/marshal_index_builder.rb +17 -0
  570. data/shoes/ruby/lib/rubygems/indexer/master_index_builder.rb +54 -0
  571. data/shoes/ruby/lib/rubygems/indexer/quick_index_builder.rb +50 -0
  572. data/shoes/ruby/lib/rubygems/indexer.rb +370 -0
  573. data/shoes/ruby/lib/rubygems/install_update_options.rb +113 -0
  574. data/shoes/ruby/lib/rubygems/installer.rb +578 -0
  575. data/shoes/ruby/lib/rubygems/local_remote_options.rb +134 -0
  576. data/shoes/ruby/lib/rubygems/old_format.rb +148 -0
  577. data/shoes/ruby/lib/rubygems/package/f_sync_dir.rb +24 -0
  578. data/shoes/ruby/lib/rubygems/package/tar_header.rb +245 -0
  579. data/shoes/ruby/lib/rubygems/package/tar_input.rb +219 -0
  580. data/shoes/ruby/lib/rubygems/package/tar_output.rb +143 -0
  581. data/shoes/ruby/lib/rubygems/package/tar_reader/entry.rb +99 -0
  582. data/shoes/ruby/lib/rubygems/package/tar_reader.rb +86 -0
  583. data/shoes/ruby/lib/rubygems/package/tar_writer.rb +180 -0
  584. data/shoes/ruby/lib/rubygems/package.rb +95 -0
  585. data/shoes/ruby/lib/rubygems/platform.rb +178 -0
  586. data/shoes/ruby/lib/rubygems/remote_fetcher.rb +344 -0
  587. data/shoes/ruby/lib/rubygems/require_paths_builder.rb +15 -0
  588. data/shoes/ruby/lib/rubygems/requirement.rb +163 -0
  589. data/shoes/ruby/lib/rubygems/rubygems_version.rb +6 -0
  590. data/shoes/ruby/lib/rubygems/security.rb +786 -0
  591. data/shoes/ruby/lib/rubygems/server.rb +629 -0
  592. data/shoes/ruby/lib/rubygems/source_index.rb +559 -0
  593. data/shoes/ruby/lib/rubygems/source_info_cache.rb +393 -0
  594. data/shoes/ruby/lib/rubygems/source_info_cache_entry.rb +56 -0
  595. data/shoes/ruby/lib/rubygems/spec_fetcher.rb +249 -0
  596. data/shoes/ruby/lib/rubygems/specification.rb +1262 -0
  597. data/shoes/ruby/lib/rubygems/test_utilities.rb +131 -0
  598. data/shoes/ruby/lib/rubygems/timer.rb +25 -0
  599. data/shoes/ruby/lib/rubygems/uninstaller.rb +242 -0
  600. data/shoes/ruby/lib/rubygems/user_interaction.rb +360 -0
  601. data/shoes/ruby/lib/rubygems/validator.rb +208 -0
  602. data/shoes/ruby/lib/rubygems/version.rb +167 -0
  603. data/shoes/ruby/lib/rubygems/version_option.rb +48 -0
  604. data/shoes/ruby/lib/rubygems.rb +888 -0
  605. data/shoes/ruby/lib/scanf.rb +703 -0
  606. data/shoes/ruby/lib/securerandom.rb +182 -0
  607. data/shoes/ruby/lib/set.rb +1274 -0
  608. data/shoes/ruby/lib/shell/builtin-command.rb +160 -0
  609. data/shoes/ruby/lib/shell/command-processor.rb +593 -0
  610. data/shoes/ruby/lib/shell/error.rb +25 -0
  611. data/shoes/ruby/lib/shell/filter.rb +109 -0
  612. data/shoes/ruby/lib/shell/process-controller.rb +319 -0
  613. data/shoes/ruby/lib/shell/system-command.rb +159 -0
  614. data/shoes/ruby/lib/shell/version.rb +15 -0
  615. data/shoes/ruby/lib/shell.rb +300 -0
  616. data/shoes/ruby/lib/shellwords.rb +156 -0
  617. data/shoes/ruby/lib/singleton.rb +313 -0
  618. data/shoes/ruby/lib/sync.rb +307 -0
  619. data/shoes/ruby/lib/tempfile.rb +218 -0
  620. data/shoes/ruby/lib/test/unit/assertions.rb +122 -0
  621. data/shoes/ruby/lib/test/unit/testcase.rb +12 -0
  622. data/shoes/ruby/lib/test/unit.rb +66 -0
  623. data/shoes/ruby/lib/thread.rb +367 -0
  624. data/shoes/ruby/lib/thwait.rb +168 -0
  625. data/shoes/ruby/lib/time.rb +869 -0
  626. data/shoes/ruby/lib/timeout.rb +108 -0
  627. data/shoes/ruby/lib/tmpdir.rb +138 -0
  628. data/shoes/ruby/lib/tracer.rb +166 -0
  629. data/shoes/ruby/lib/tsort.rb +290 -0
  630. data/shoes/ruby/lib/ubygems.rb +10 -0
  631. data/shoes/ruby/lib/un.rb +304 -0
  632. data/shoes/ruby/lib/uri/common.rb +727 -0
  633. data/shoes/ruby/lib/uri/ftp.rb +198 -0
  634. data/shoes/ruby/lib/uri/generic.rb +1128 -0
  635. data/shoes/ruby/lib/uri/http.rb +100 -0
  636. data/shoes/ruby/lib/uri/https.rb +20 -0
  637. data/shoes/ruby/lib/uri/ldap.rb +190 -0
  638. data/shoes/ruby/lib/uri/ldaps.rb +12 -0
  639. data/shoes/ruby/lib/uri/mailto.rb +266 -0
  640. data/shoes/ruby/lib/uri.rb +29 -0
  641. data/shoes/ruby/lib/weakref.rb +80 -0
  642. data/shoes/ruby/lib/webrick/accesslog.rb +75 -0
  643. data/shoes/ruby/lib/webrick/cgi.rb +260 -0
  644. data/shoes/ruby/lib/webrick/compat.rb +15 -0
  645. data/shoes/ruby/lib/webrick/config.rb +100 -0
  646. data/shoes/ruby/lib/webrick/cookie.rb +110 -0
  647. data/shoes/ruby/lib/webrick/htmlutils.rb +25 -0
  648. data/shoes/ruby/lib/webrick/httpauth/authenticator.rb +79 -0
  649. data/shoes/ruby/lib/webrick/httpauth/basicauth.rb +65 -0
  650. data/shoes/ruby/lib/webrick/httpauth/digestauth.rb +344 -0
  651. data/shoes/ruby/lib/webrick/httpauth/htdigest.rb +91 -0
  652. data/shoes/ruby/lib/webrick/httpauth/htgroup.rb +61 -0
  653. data/shoes/ruby/lib/webrick/httpauth/htpasswd.rb +83 -0
  654. data/shoes/ruby/lib/webrick/httpauth/userdb.rb +29 -0
  655. data/shoes/ruby/lib/webrick/httpauth.rb +45 -0
  656. data/shoes/ruby/lib/webrick/httpproxy.rb +288 -0
  657. data/shoes/ruby/lib/webrick/httprequest.rb +402 -0
  658. data/shoes/ruby/lib/webrick/httpresponse.rb +326 -0
  659. data/shoes/ruby/lib/webrick/https.rb +63 -0
  660. data/shoes/ruby/lib/webrick/httpserver.rb +217 -0
  661. data/shoes/ruby/lib/webrick/httpservlet/abstract.rb +70 -0
  662. data/shoes/ruby/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  663. data/shoes/ruby/lib/webrick/httpservlet/cgihandler.rb +110 -0
  664. data/shoes/ruby/lib/webrick/httpservlet/erbhandler.rb +54 -0
  665. data/shoes/ruby/lib/webrick/httpservlet/filehandler.rb +435 -0
  666. data/shoes/ruby/lib/webrick/httpservlet/prochandler.rb +33 -0
  667. data/shoes/ruby/lib/webrick/httpservlet.rb +22 -0
  668. data/shoes/ruby/lib/webrick/httpstatus.rb +132 -0
  669. data/shoes/ruby/lib/webrick/httputils.rb +392 -0
  670. data/shoes/ruby/lib/webrick/httpversion.rb +49 -0
  671. data/shoes/ruby/lib/webrick/log.rb +88 -0
  672. data/shoes/ruby/lib/webrick/server.rb +210 -0
  673. data/shoes/ruby/lib/webrick/ssl.rb +126 -0
  674. data/shoes/ruby/lib/webrick/utils.rb +175 -0
  675. data/shoes/ruby/lib/webrick/version.rb +13 -0
  676. data/shoes/ruby/lib/webrick.rb +29 -0
  677. data/shoes/ruby/lib/win32/registry.rb +832 -0
  678. data/shoes/ruby/lib/win32/resolv.rb +370 -0
  679. data/shoes/ruby/lib/win32/sspi.rb +330 -0
  680. data/shoes/ruby/lib/win32ole/property.rb +16 -0
  681. data/shoes/ruby/lib/xmlrpc/base64.rb +81 -0
  682. data/shoes/ruby/lib/xmlrpc/client.rb +625 -0
  683. data/shoes/ruby/lib/xmlrpc/config.rb +40 -0
  684. data/shoes/ruby/lib/xmlrpc/create.rb +290 -0
  685. data/shoes/ruby/lib/xmlrpc/datetime.rb +142 -0
  686. data/shoes/ruby/lib/xmlrpc/httpserver.rb +178 -0
  687. data/shoes/ruby/lib/xmlrpc/marshal.rb +76 -0
  688. data/shoes/ruby/lib/xmlrpc/parser.rb +813 -0
  689. data/shoes/ruby/lib/xmlrpc/server.rb +778 -0
  690. data/shoes/ruby/lib/xmlrpc/utils.rb +165 -0
  691. data/shoes/ruby/lib/yaml/baseemitter.rb +242 -0
  692. data/shoes/ruby/lib/yaml/basenode.rb +216 -0
  693. data/shoes/ruby/lib/yaml/constants.rb +45 -0
  694. data/shoes/ruby/lib/yaml/dbm.rb +111 -0
  695. data/shoes/ruby/lib/yaml/encoding.rb +33 -0
  696. data/shoes/ruby/lib/yaml/error.rb +34 -0
  697. data/shoes/ruby/lib/yaml/loader.rb +14 -0
  698. data/shoes/ruby/lib/yaml/rubytypes.rb +446 -0
  699. data/shoes/ruby/lib/yaml/store.rb +43 -0
  700. data/shoes/ruby/lib/yaml/stream.rb +40 -0
  701. data/shoes/ruby/lib/yaml/stringio.rb +83 -0
  702. data/shoes/ruby/lib/yaml/syck.rb +19 -0
  703. data/shoes/ruby/lib/yaml/tag.rb +91 -0
  704. data/shoes/ruby/lib/yaml/types.rb +192 -0
  705. data/shoes/ruby/lib/yaml/yamlnode.rb +54 -0
  706. data/shoes/ruby/lib/yaml/ypath.rb +52 -0
  707. data/shoes/ruby/lib/yaml.rb +440 -0
  708. data/shoes/samples/class-book.rb +43 -0
  709. data/shoes/samples/class-book.yaml +387 -0
  710. data/shoes/samples/expert-definr.rb +23 -0
  711. data/shoes/samples/expert-funnies.rb +51 -0
  712. data/shoes/samples/expert-irb.rb +112 -0
  713. data/shoes/samples/expert-minesweeper.rb +267 -0
  714. data/shoes/samples/expert-othello.rb +319 -0
  715. data/shoes/samples/expert-pong.rb +62 -0
  716. data/shoes/samples/expert-tankspank.rb +385 -0
  717. data/shoes/samples/good-arc.rb +37 -0
  718. data/shoes/samples/good-clock.rb +51 -0
  719. data/shoes/samples/good-follow.rb +26 -0
  720. data/shoes/samples/good-reminder.rb +174 -0
  721. data/shoes/samples/good-vjot.rb +56 -0
  722. data/shoes/samples/simple-accordion.rb +75 -0
  723. data/shoes/samples/simple-anim-shapes.rb +17 -0
  724. data/shoes/samples/simple-anim-text.rb +13 -0
  725. data/shoes/samples/simple-arc.rb +23 -0
  726. data/shoes/samples/simple-bounce.rb +24 -0
  727. data/shoes/samples/simple-calc.rb +70 -0
  728. data/shoes/samples/simple-control-sizes.rb +24 -0
  729. data/shoes/samples/simple-curve.rb +26 -0
  730. data/shoes/samples/simple-dialogs.rb +29 -0
  731. data/shoes/samples/simple-downloader.rb +27 -0
  732. data/shoes/samples/simple-draw.rb +13 -0
  733. data/shoes/samples/simple-editor.rb +28 -0
  734. data/shoes/samples/simple-form.rb +28 -0
  735. data/shoes/samples/simple-form.shy +0 -0
  736. data/shoes/samples/simple-mask.rb +21 -0
  737. data/shoes/samples/simple-menu.rb +31 -0
  738. data/shoes/samples/simple-menu1.rb +35 -0
  739. data/shoes/samples/simple-rubygems.rb +29 -0
  740. data/shoes/samples/simple-slide.rb +45 -0
  741. data/shoes/samples/simple-sphere.rb +28 -0
  742. data/shoes/samples/simple-timer.rb +13 -0
  743. data/shoes/samples/simple-video.rb +13 -0
  744. data/shoes/shoes +21 -0
  745. data/shoes/shoes.exe +0 -0
  746. data/shoes/shoes.exe.manifest +17 -0
  747. data/shoes/sqlite3.dll +0 -0
  748. data/shoes/static/Shoes.icns +0 -0
  749. data/shoes/static/Thumbs.db +0 -0
  750. data/shoes/static/app-icon.png +0 -0
  751. data/shoes/static/avatar.png +0 -0
  752. data/shoes/static/code_highlighter.js +188 -0
  753. data/shoes/static/code_highlighter_ruby.js +26 -0
  754. data/shoes/static/icon-debug.png +0 -0
  755. data/shoes/static/icon-error.png +0 -0
  756. data/shoes/static/icon-info.png +0 -0
  757. data/shoes/static/icon-warn.png +0 -0
  758. data/shoes/static/listbox_button1.png +0 -0
  759. data/shoes/static/listbox_button2.png +0 -0
  760. data/shoes/static/man-app.png +0 -0
  761. data/shoes/static/man-builds.png +0 -0
  762. data/shoes/static/man-editor-notepad.png +0 -0
  763. data/shoes/static/man-editor-osx.png +0 -0
  764. data/shoes/static/man-ele-background.png +0 -0
  765. data/shoes/static/man-ele-border.png +0 -0
  766. data/shoes/static/man-ele-button.png +0 -0
  767. data/shoes/static/man-ele-check.png +0 -0
  768. data/shoes/static/man-ele-editbox.png +0 -0
  769. data/shoes/static/man-ele-editline.png +0 -0
  770. data/shoes/static/man-ele-image.png +0 -0
  771. data/shoes/static/man-ele-listbox.png +0 -0
  772. data/shoes/static/man-ele-progress.png +0 -0
  773. data/shoes/static/man-ele-radio.png +0 -0
  774. data/shoes/static/man-ele-shape.png +0 -0
  775. data/shoes/static/man-ele-textblock.png +0 -0
  776. data/shoes/static/man-ele-video.png +0 -0
  777. data/shoes/static/man-intro-dmg.png +0 -0
  778. data/shoes/static/man-intro-exe.png +0 -0
  779. data/shoes/static/man-look-tiger.png +0 -0
  780. data/shoes/static/man-look-ubuntu.png +0 -0
  781. data/shoes/static/man-look-vista.png +0 -0
  782. data/shoes/static/man-run-osx.png +0 -0
  783. data/shoes/static/man-run-vista.png +0 -0
  784. data/shoes/static/man-run-xp.png +0 -0
  785. data/shoes/static/man-shot1.png +0 -0
  786. data/shoes/static/manual-en.txt +2783 -0
  787. data/shoes/static/manual-ja.txt +2780 -0
  788. data/shoes/static/manual.css +167 -0
  789. data/shoes/static/menu-corner1.png +0 -0
  790. data/shoes/static/menu-corner2.png +0 -0
  791. data/shoes/static/menu-gray.png +0 -0
  792. data/shoes/static/menu-left.png +0 -0
  793. data/shoes/static/menu-right.png +0 -0
  794. data/shoes/static/menu-top.png +0 -0
  795. data/shoes/static/shoes-dmg.jpg +0 -0
  796. data/shoes/static/shoes-icon-blue.png +0 -0
  797. data/shoes/static/shoes-icon.png +0 -0
  798. data/shoes/static/shoes-manual-apps.gif +0 -0
  799. data/shoes/static/stripe.png +0 -0
  800. data/shoes/static/stubs/blank.exe +0 -0
  801. data/shoes/static/stubs/blank.hfz +0 -0
  802. data/shoes/static/stubs/blank.run +375 -0
  803. data/shoes/static/stubs/cocoa-install +0 -0
  804. data/shoes/static/stubs/sh-install +48 -0
  805. data/shoes/static/tutor-back.png +0 -0
  806. data/shoes/zlib.dll +0 -0
  807. data/shoes/zlib1.dll +0 -0
  808. metadata +887 -0
@@ -0,0 +1,1810 @@
1
+ #
2
+ # optparse.rb - command-line option analysis with the OptionParser class.
3
+ #
4
+ # Author:: Nobu Nakada
5
+ # Documentation:: Nobu Nakada and Gavin Sinclair.
6
+ #
7
+ # See OptionParser for documentation.
8
+ #
9
+
10
+
11
+ # == Developer Documentation (not for RDoc output)
12
+ #
13
+ # === Class tree
14
+ #
15
+ # - OptionParser:: front end
16
+ # - OptionParser::Switch:: each switches
17
+ # - OptionParser::List:: options list
18
+ # - OptionParser::ParseError:: errors on parsing
19
+ # - OptionParser::AmbiguousOption
20
+ # - OptionParser::NeedlessArgument
21
+ # - OptionParser::MissingArgument
22
+ # - OptionParser::InvalidOption
23
+ # - OptionParser::InvalidArgument
24
+ # - OptionParser::AmbiguousArgument
25
+ #
26
+ # === Object relationship diagram
27
+ #
28
+ # +--------------+
29
+ # | OptionParser |<>-----+
30
+ # +--------------+ | +--------+
31
+ # | ,-| Switch |
32
+ # on_head -------->+---------------+ / +--------+
33
+ # accept/reject -->| List |<|>-
34
+ # | |<|>- +----------+
35
+ # on ------------->+---------------+ `-| argument |
36
+ # : : | class |
37
+ # +---------------+ |==========|
38
+ # on_tail -------->| | |pattern |
39
+ # +---------------+ |----------|
40
+ # OptionParser.accept ->| DefaultList | |converter |
41
+ # reject |(shared between| +----------+
42
+ # | all instances)|
43
+ # +---------------+
44
+ #
45
+ # == OptionParser
46
+ #
47
+ # === Introduction
48
+ #
49
+ # OptionParser is a class for command-line option analysis. It is much more
50
+ # advanced, yet also easier to use, than GetoptLong, and is a more Ruby-oriented
51
+ # solution.
52
+ #
53
+ # === Features
54
+ #
55
+ # 1. The argument specification and the code to handle it are written in the
56
+ # same place.
57
+ # 2. It can output an option summary; you don't need to maintain this string
58
+ # separately.
59
+ # 3. Optional and mandatory arguments are specified very gracefully.
60
+ # 4. Arguments can be automatically converted to a specified class.
61
+ # 5. Arguments can be restricted to a certain set.
62
+ #
63
+ # All of these features are demonstrated in the examples below.
64
+ #
65
+ # === Minimal example
66
+ #
67
+ # require 'optparse'
68
+ #
69
+ # options = {}
70
+ # OptionParser.new do |opts|
71
+ # opts.banner = "Usage: example.rb [options]"
72
+ #
73
+ # opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
74
+ # options[:verbose] = v
75
+ # end
76
+ # end.parse!
77
+ #
78
+ # p options
79
+ # p ARGV
80
+ #
81
+ # === Complete example
82
+ #
83
+ # The following example is a complete Ruby program. You can run it and see the
84
+ # effect of specifying various options. This is probably the best way to learn
85
+ # the features of +optparse+.
86
+ #
87
+ # require 'optparse'
88
+ # require 'optparse/time'
89
+ # require 'ostruct'
90
+ # require 'pp'
91
+ #
92
+ # class OptparseExample
93
+ #
94
+ # CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
95
+ # CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
96
+ #
97
+ # #
98
+ # # Return a structure describing the options.
99
+ # #
100
+ # def self.parse(args)
101
+ # # The options specified on the command line will be collected in *options*.
102
+ # # We set default values here.
103
+ # options = OpenStruct.new
104
+ # options.library = []
105
+ # options.inplace = false
106
+ # options.encoding = "utf8"
107
+ # options.transfer_type = :auto
108
+ # options.verbose = false
109
+ #
110
+ # opts = OptionParser.new do |opts|
111
+ # opts.banner = "Usage: example.rb [options]"
112
+ #
113
+ # opts.separator ""
114
+ # opts.separator "Specific options:"
115
+ #
116
+ # # Mandatory argument.
117
+ # opts.on("-r", "--require LIBRARY",
118
+ # "Require the LIBRARY before executing your script") do |lib|
119
+ # options.library << lib
120
+ # end
121
+ #
122
+ # # Optional argument; multi-line description.
123
+ # opts.on("-i", "--inplace [EXTENSION]",
124
+ # "Edit ARGV files in place",
125
+ # " (make backup if EXTENSION supplied)") do |ext|
126
+ # options.inplace = true
127
+ # options.extension = ext || ''
128
+ # options.extension.sub!(/\A\.?(?=.)/, ".") # Ensure extension begins with dot.
129
+ # end
130
+ #
131
+ # # Cast 'delay' argument to a Float.
132
+ # opts.on("--delay N", Float, "Delay N seconds before executing") do |n|
133
+ # options.delay = n
134
+ # end
135
+ #
136
+ # # Cast 'time' argument to a Time object.
137
+ # opts.on("-t", "--time [TIME]", Time, "Begin execution at given time") do |time|
138
+ # options.time = time
139
+ # end
140
+ #
141
+ # # Cast to octal integer.
142
+ # opts.on("-F", "--irs [OCTAL]", OptionParser::OctalInteger,
143
+ # "Specify record separator (default \\0)") do |rs|
144
+ # options.record_separator = rs
145
+ # end
146
+ #
147
+ # # List of arguments.
148
+ # opts.on("--list x,y,z", Array, "Example 'list' of arguments") do |list|
149
+ # options.list = list
150
+ # end
151
+ #
152
+ # # Keyword completion. We are specifying a specific set of arguments (CODES
153
+ # # and CODE_ALIASES - notice the latter is a Hash), and the user may provide
154
+ # # the shortest unambiguous text.
155
+ # code_list = (CODE_ALIASES.keys + CODES).join(',')
156
+ # opts.on("--code CODE", CODES, CODE_ALIASES, "Select encoding",
157
+ # " (#{code_list})") do |encoding|
158
+ # options.encoding = encoding
159
+ # end
160
+ #
161
+ # # Optional argument with keyword completion.
162
+ # opts.on("--type [TYPE]", [:text, :binary, :auto],
163
+ # "Select transfer type (text, binary, auto)") do |t|
164
+ # options.transfer_type = t
165
+ # end
166
+ #
167
+ # # Boolean switch.
168
+ # opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
169
+ # options.verbose = v
170
+ # end
171
+ #
172
+ # opts.separator ""
173
+ # opts.separator "Common options:"
174
+ #
175
+ # # No argument, shows at tail. This will print an options summary.
176
+ # # Try it and see!
177
+ # opts.on_tail("-h", "--help", "Show this message") do
178
+ # puts opts
179
+ # exit
180
+ # end
181
+ #
182
+ # # Another typical switch to print the version.
183
+ # opts.on_tail("--version", "Show version") do
184
+ # puts OptionParser::Version.join('.')
185
+ # exit
186
+ # end
187
+ # end
188
+ #
189
+ # opts.parse!(args)
190
+ # options
191
+ # end # parse()
192
+ #
193
+ # end # class OptparseExample
194
+ #
195
+ # options = OptparseExample.parse(ARGV)
196
+ # pp options
197
+ #
198
+ # === Further documentation
199
+ #
200
+ # The above examples should be enough to learn how to use this class. If you
201
+ # have any questions, email me (gsinclair@soyabean.com.au) and I will update
202
+ # this document.
203
+ #
204
+ class OptionParser
205
+ # :stopdoc:
206
+ RCSID = %w$Id: optparse.rb 23396 2009-05-11 15:05:43Z yugui $[1..-1].each {|s| s.freeze}.freeze
207
+ Version = (RCSID[1].split('.').collect {|s| s.to_i}.extend(Comparable).freeze if RCSID[1])
208
+ LastModified = (Time.gm(*RCSID[2, 2].join('-').scan(/\d+/).collect {|s| s.to_i}) if RCSID[2])
209
+ Release = RCSID[2]
210
+
211
+ NoArgument = [NO_ARGUMENT = :NONE, nil].freeze
212
+ RequiredArgument = [REQUIRED_ARGUMENT = :REQUIRED, true].freeze
213
+ OptionalArgument = [OPTIONAL_ARGUMENT = :OPTIONAL, false].freeze
214
+ # :startdoc:
215
+
216
+ #
217
+ # Keyword completion module. This allows partial arguments to be specified
218
+ # and resolved against a list of acceptable values.
219
+ #
220
+ module Completion
221
+ def complete(key, icase = false, pat = nil)
222
+ pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'),
223
+ icase)
224
+ canon, sw, cn = nil
225
+ candidates = []
226
+ each do |k, *v|
227
+ (if Regexp === k
228
+ kn = nil
229
+ k === key
230
+ else
231
+ kn = defined?(k.id2name) ? k.id2name : k
232
+ pat === kn
233
+ end) or next
234
+ v << k if v.empty?
235
+ candidates << [k, v, kn]
236
+ end
237
+ candidates = candidates.sort_by {|k, v, kn| kn.size}
238
+ if candidates.size == 1
239
+ canon, sw, * = candidates[0]
240
+ elsif candidates.size > 1
241
+ canon, sw, cn = candidates.shift
242
+ candidates.each do |k, v, kn|
243
+ next if sw == v
244
+ if String === cn and String === kn
245
+ if cn.rindex(kn, 0)
246
+ canon, sw, cn = k, v, kn
247
+ next
248
+ elsif kn.rindex(cn, 0)
249
+ next
250
+ end
251
+ end
252
+ throw :ambiguous, key
253
+ end
254
+ end
255
+ if canon
256
+ block_given? or return key, *sw
257
+ yield(key, *sw)
258
+ end
259
+ end
260
+
261
+ def convert(opt = nil, val = nil, *)
262
+ val
263
+ end
264
+ end
265
+
266
+
267
+ #
268
+ # Map from option/keyword string to object with completion.
269
+ #
270
+ class OptionMap < Hash
271
+ include Completion
272
+ end
273
+
274
+
275
+ #
276
+ # Individual switch class. Not important to the user.
277
+ #
278
+ # Defined within Switch are several Switch-derived classes: NoArgument,
279
+ # RequiredArgument, etc.
280
+ #
281
+ class Switch
282
+ attr_reader :pattern, :conv, :short, :long, :arg, :desc, :block
283
+
284
+ #
285
+ # Guesses argument style from +arg+. Returns corresponding
286
+ # OptionParser::Switch class (OptionalArgument, etc.).
287
+ #
288
+ def self.guess(arg)
289
+ case arg
290
+ when ""
291
+ t = self
292
+ when /\A=?\[/
293
+ t = Switch::OptionalArgument
294
+ when /\A\s+\[/
295
+ t = Switch::PlacedArgument
296
+ else
297
+ t = Switch::RequiredArgument
298
+ end
299
+ self >= t or incompatible_argument_styles(arg, t)
300
+ t
301
+ end
302
+
303
+ def self.incompatible_argument_styles(arg, t)
304
+ raise(ArgumentError, "#{arg}: incompatible argument styles\n #{self}, #{t}",
305
+ ParseError.filter_backtrace(caller(2)))
306
+ end
307
+
308
+ def self.pattern
309
+ NilClass
310
+ end
311
+
312
+ def initialize(pattern = nil, conv = nil,
313
+ short = nil, long = nil, arg = nil,
314
+ desc = ([] if short or long), block = Proc.new)
315
+ raise if Array === pattern
316
+ @pattern, @conv, @short, @long, @arg, @desc, @block =
317
+ pattern, conv, short, long, arg, desc, block
318
+ end
319
+
320
+ #
321
+ # Parses +arg+ and returns rest of +arg+ and matched portion to the
322
+ # argument pattern. Yields when the pattern doesn't match substring.
323
+ #
324
+ def parse_arg(arg)
325
+ pattern or return nil, [arg]
326
+ unless m = pattern.match(arg)
327
+ yield(InvalidArgument, arg)
328
+ return arg, []
329
+ end
330
+ if String === m
331
+ m = [s = m]
332
+ else
333
+ m = m.to_a
334
+ s = m[0]
335
+ return nil, m unless String === s
336
+ end
337
+ raise InvalidArgument, arg unless arg.rindex(s, 0)
338
+ return nil, m if s.length == arg.length
339
+ yield(InvalidArgument, arg) # didn't match whole arg
340
+ return arg[s.length..-1], m
341
+ end
342
+ private :parse_arg
343
+
344
+ #
345
+ # Parses argument, converts and returns +arg+, +block+ and result of
346
+ # conversion. Yields at semi-error condition instead of raising an
347
+ # exception.
348
+ #
349
+ def conv_arg(arg, val = [])
350
+ if conv
351
+ val = conv.call(*val)
352
+ else
353
+ val = proc {|v| v}.call(*val)
354
+ end
355
+ return arg, block, val
356
+ end
357
+ private :conv_arg
358
+
359
+ #
360
+ # Produces the summary text. Each line of the summary is yielded to the
361
+ # block (without newline).
362
+ #
363
+ # +sdone+:: Already summarized short style options keyed hash.
364
+ # +ldone+:: Already summarized long style options keyed hash.
365
+ # +width+:: Width of left side (option part). In other words, the right
366
+ # side (description part) starts after +width+ columns.
367
+ # +max+:: Maximum width of left side -> the options are filled within
368
+ # +max+ columns.
369
+ # +indent+:: Prefix string indents all summarized lines.
370
+ #
371
+ def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "")
372
+ sopts, lopts = [], [], nil
373
+ @short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
374
+ @long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
375
+ return if sopts.empty? and lopts.empty? # completely hidden
376
+
377
+ left = [sopts.join(', ')]
378
+ right = desc.dup
379
+
380
+ while s = lopts.shift
381
+ l = left[-1].length + s.length
382
+ l += arg.length if left.size == 1 && arg
383
+ l < max or sopts.empty? or left << ''
384
+ left[-1] << if left[-1].empty? then ' ' * 4 else ', ' end << s
385
+ end
386
+
387
+ left[0] << arg if arg
388
+ mlen = left.collect {|ss| ss.length}.max.to_i
389
+ while mlen > width and l = left.shift
390
+ mlen = left.collect {|ss| ss.length}.max.to_i if l.length == mlen
391
+ yield(indent + l)
392
+ end
393
+
394
+ while begin l = left.shift; r = right.shift; l or r end
395
+ l = l.to_s.ljust(width) + ' ' + r if r and !r.empty?
396
+ yield(indent + l)
397
+ end
398
+
399
+ self
400
+ end
401
+
402
+ def add_banner(to) # :nodoc:
403
+ unless @short or @long
404
+ s = desc.join
405
+ to << " [" + s + "]..." unless s.empty?
406
+ end
407
+ to
408
+ end
409
+
410
+ def match_nonswitch?(str) # :nodoc:
411
+ @pattern =~ str unless @short or @long
412
+ end
413
+
414
+ #
415
+ # Main name of the switch.
416
+ #
417
+ def switch_name
418
+ (long.first || short.first).sub(/\A-+(?:\[no-\])?/, '')
419
+ end
420
+
421
+ #
422
+ # Switch that takes no arguments.
423
+ #
424
+ class NoArgument < self
425
+
426
+ #
427
+ # Raises an exception if any arguments given.
428
+ #
429
+ def parse(arg, argv)
430
+ yield(NeedlessArgument, arg) if arg
431
+ conv_arg(arg)
432
+ end
433
+
434
+ def self.incompatible_argument_styles(*)
435
+ end
436
+
437
+ def self.pattern
438
+ Object
439
+ end
440
+ end
441
+
442
+ #
443
+ # Switch that takes an argument.
444
+ #
445
+ class RequiredArgument < self
446
+
447
+ #
448
+ # Raises an exception if argument is not present.
449
+ #
450
+ def parse(arg, argv)
451
+ unless arg
452
+ raise MissingArgument if argv.empty?
453
+ arg = argv.shift
454
+ end
455
+ conv_arg(*parse_arg(arg, &method(:raise)))
456
+ end
457
+ end
458
+
459
+ #
460
+ # Switch that can omit argument.
461
+ #
462
+ class OptionalArgument < self
463
+
464
+ #
465
+ # Parses argument if given, or uses default value.
466
+ #
467
+ def parse(arg, argv, &error)
468
+ if arg
469
+ conv_arg(*parse_arg(arg, &error))
470
+ else
471
+ conv_arg(arg)
472
+ end
473
+ end
474
+ end
475
+
476
+ #
477
+ # Switch that takes an argument, which does not begin with '-'.
478
+ #
479
+ class PlacedArgument < self
480
+
481
+ #
482
+ # Returns nil if argument is not present or begins with '-'.
483
+ #
484
+ def parse(arg, argv, &error)
485
+ if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
486
+ return nil, block, nil
487
+ end
488
+ opt = (val = parse_arg(val, &error))[1]
489
+ val = conv_arg(*val)
490
+ if opt and !arg
491
+ argv.shift
492
+ else
493
+ val[0] = nil
494
+ end
495
+ val
496
+ end
497
+ end
498
+ end
499
+
500
+ #
501
+ # Simple option list providing mapping from short and/or long option
502
+ # string to OptionParser::Switch and mapping from acceptable argument to
503
+ # matching pattern and converter pair. Also provides summary feature.
504
+ #
505
+ class List
506
+ # Map from acceptable argument types to pattern and converter pairs.
507
+ attr_reader :atype
508
+
509
+ # Map from short style option switches to actual switch objects.
510
+ attr_reader :short
511
+
512
+ # Map from long style option switches to actual switch objects.
513
+ attr_reader :long
514
+
515
+ # List of all switches and summary string.
516
+ attr_reader :list
517
+
518
+ #
519
+ # Just initializes all instance variables.
520
+ #
521
+ def initialize
522
+ @atype = {}
523
+ @short = OptionMap.new
524
+ @long = OptionMap.new
525
+ @list = []
526
+ end
527
+
528
+ #
529
+ # See OptionParser.accept.
530
+ #
531
+ def accept(t, pat = /.*/nm, &block)
532
+ if pat
533
+ pat.respond_to?(:match) or
534
+ raise TypeError, "has no `match'", ParseError.filter_backtrace(caller(2))
535
+ else
536
+ pat = t if t.respond_to?(:match)
537
+ end
538
+ unless block
539
+ block = pat.method(:convert).to_proc if pat.respond_to?(:convert)
540
+ end
541
+ @atype[t] = [pat, block]
542
+ end
543
+
544
+ #
545
+ # See OptionParser.reject.
546
+ #
547
+ def reject(t)
548
+ @atype.delete(t)
549
+ end
550
+
551
+ #
552
+ # Adds +sw+ according to +sopts+, +lopts+ and +nlopts+.
553
+ #
554
+ # +sw+:: OptionParser::Switch instance to be added.
555
+ # +sopts+:: Short style option list.
556
+ # +lopts+:: Long style option list.
557
+ # +nlopts+:: Negated long style options list.
558
+ #
559
+ def update(sw, sopts, lopts, nsw = nil, nlopts = nil)
560
+ sopts.each {|o| @short[o] = sw} if sopts
561
+ lopts.each {|o| @long[o] = sw} if lopts
562
+ nlopts.each {|o| @long[o] = nsw} if nsw and nlopts
563
+ used = @short.invert.update(@long.invert)
564
+ @list.delete_if {|o| Switch === o and !used[o]}
565
+ end
566
+ private :update
567
+
568
+ #
569
+ # Inserts +switch+ at the head of the list, and associates short, long
570
+ # and negated long options. Arguments are:
571
+ #
572
+ # +switch+:: OptionParser::Switch instance to be inserted.
573
+ # +short_opts+:: List of short style options.
574
+ # +long_opts+:: List of long style options.
575
+ # +nolong_opts+:: List of long style options with "no-" prefix.
576
+ #
577
+ # prepend(switch, short_opts, long_opts, nolong_opts)
578
+ #
579
+ def prepend(*args)
580
+ update(*args)
581
+ @list.unshift(args[0])
582
+ end
583
+
584
+ #
585
+ # Appends +switch+ at the tail of the list, and associates short, long
586
+ # and negated long options. Arguments are:
587
+ #
588
+ # +switch+:: OptionParser::Switch instance to be inserted.
589
+ # +short_opts+:: List of short style options.
590
+ # +long_opts+:: List of long style options.
591
+ # +nolong_opts+:: List of long style options with "no-" prefix.
592
+ #
593
+ # append(switch, short_opts, long_opts, nolong_opts)
594
+ #
595
+ def append(*args)
596
+ update(*args)
597
+ @list.push(args[0])
598
+ end
599
+
600
+ #
601
+ # Searches +key+ in +id+ list. The result is returned or yielded if a
602
+ # block is given. If it isn't found, nil is returned.
603
+ #
604
+ def search(id, key)
605
+ if list = __send__(id)
606
+ val = list.fetch(key) {return nil}
607
+ block_given? ? yield(val) : val
608
+ end
609
+ end
610
+
611
+ #
612
+ # Searches list +id+ for +opt+ and the optional patterns for completion
613
+ # +pat+. If +icase+ is true, the search is case insensitive. The result
614
+ # is returned or yielded if a block is given. If it isn't found, nil is
615
+ # returned.
616
+ #
617
+ def complete(id, opt, icase = false, *pat, &block)
618
+ __send__(id).complete(opt, icase, *pat, &block)
619
+ end
620
+
621
+ #
622
+ # Iterates over each option, passing the option to the +block+.
623
+ #
624
+ def each_option(&block)
625
+ list.each(&block)
626
+ end
627
+
628
+ #
629
+ # Creates the summary table, passing each line to the +block+ (without
630
+ # newline). The arguments +args+ are passed along to the summarize
631
+ # method which is called on every option.
632
+ #
633
+ def summarize(*args, &block)
634
+ sum = []
635
+ list.reverse_each do |opt|
636
+ if opt.respond_to?(:summarize) # perhaps OptionParser::Switch
637
+ s = []
638
+ opt.summarize(*args) {|l| s << l}
639
+ sum.concat(s.reverse)
640
+ elsif !opt or opt.empty?
641
+ sum << ""
642
+ elsif opt.respond_to?(:each_line)
643
+ sum.concat([*opt.each_line].reverse)
644
+ else
645
+ sum.concat([*opt.each].reverse)
646
+ end
647
+ end
648
+ sum.reverse_each(&block)
649
+ end
650
+
651
+ def add_banner(to) # :nodoc:
652
+ list.each do |opt|
653
+ if opt.respond_to?(:add_banner)
654
+ opt.add_banner(to)
655
+ end
656
+ end
657
+ to
658
+ end
659
+ end
660
+
661
+ #
662
+ # Hash with completion search feature. See OptionParser::Completion.
663
+ #
664
+ class CompletingHash < Hash
665
+ include Completion
666
+
667
+ #
668
+ # Completion for hash key.
669
+ #
670
+ def match(key)
671
+ *values = fetch(key) {
672
+ raise AmbiguousArgument, catch(:ambiguous) {return complete(key)}
673
+ }
674
+ return key, *values
675
+ end
676
+ end
677
+
678
+ # :stopdoc:
679
+
680
+ #
681
+ # Enumeration of acceptable argument styles. Possible values are:
682
+ #
683
+ # NO_ARGUMENT:: The switch takes no arguments. (:NONE)
684
+ # REQUIRED_ARGUMENT:: The switch requires an argument. (:REQUIRED)
685
+ # OPTIONAL_ARGUMENT:: The switch requires an optional argument. (:OPTIONAL)
686
+ #
687
+ # Use like --switch=argument (long style) or -Xargument (short style). For
688
+ # short style, only portion matched to argument pattern is dealed as
689
+ # argument.
690
+ #
691
+ ArgumentStyle = {}
692
+ NoArgument.each {|el| ArgumentStyle[el] = Switch::NoArgument}
693
+ RequiredArgument.each {|el| ArgumentStyle[el] = Switch::RequiredArgument}
694
+ OptionalArgument.each {|el| ArgumentStyle[el] = Switch::OptionalArgument}
695
+ ArgumentStyle.freeze
696
+
697
+ #
698
+ # Switches common used such as '--', and also provides default
699
+ # argument classes
700
+ #
701
+ DefaultList = List.new
702
+ DefaultList.short['-'] = Switch::NoArgument.new {}
703
+ DefaultList.long[''] = Switch::NoArgument.new {throw :terminate}
704
+
705
+ #
706
+ # Default options for ARGV, which never appear in option summary.
707
+ #
708
+ Officious = {}
709
+
710
+ #
711
+ # --help
712
+ # Shows option summary.
713
+ #
714
+ Officious['help'] = proc do |parser|
715
+ Switch::NoArgument.new do
716
+ puts parser.help
717
+ exit
718
+ end
719
+ end
720
+
721
+ #
722
+ # --version
723
+ # Shows version string if Version is defined.
724
+ #
725
+ Officious['version'] = proc do |parser|
726
+ Switch::OptionalArgument.new do |pkg|
727
+ if pkg
728
+ begin
729
+ require 'optparse/version'
730
+ rescue LoadError
731
+ else
732
+ show_version(*pkg.split(/,/)) or
733
+ abort("#{parser.program_name}: no version found in package #{pkg}")
734
+ exit
735
+ end
736
+ end
737
+ v = parser.ver or abort("#{parser.program_name}: version unknown")
738
+ puts v
739
+ exit
740
+ end
741
+ end
742
+
743
+ # :startdoc:
744
+
745
+ #
746
+ # Class methods
747
+ #
748
+
749
+ #
750
+ # Initializes a new instance and evaluates the optional block in context
751
+ # of the instance. Arguments +args+ are passed to #new, see there for
752
+ # description of parameters.
753
+ #
754
+ # This method is *deprecated*, its behavior corresponds to the older #new
755
+ # method.
756
+ #
757
+ def self.with(*args, &block)
758
+ opts = new(*args)
759
+ opts.instance_eval(&block)
760
+ opts
761
+ end
762
+
763
+ #
764
+ # Returns an incremented value of +default+ according to +arg+.
765
+ #
766
+ def self.inc(arg, default = nil)
767
+ case arg
768
+ when Integer
769
+ arg.nonzero?
770
+ when nil
771
+ default.to_i + 1
772
+ end
773
+ end
774
+ def inc(*args)
775
+ self.class.inc(*args)
776
+ end
777
+
778
+ #
779
+ # Initializes the instance and yields itself if called with a block.
780
+ #
781
+ # +banner+:: Banner message.
782
+ # +width+:: Summary width.
783
+ # +indent+:: Summary indent.
784
+ #
785
+ def initialize(banner = nil, width = 32, indent = ' ' * 4)
786
+ @stack = [DefaultList, List.new, List.new]
787
+ @program_name = nil
788
+ @banner = banner
789
+ @summary_width = width
790
+ @summary_indent = indent
791
+ @default_argv = ARGV
792
+ add_officious
793
+ yield self if block_given?
794
+ end
795
+
796
+ def add_officious # :nodoc:
797
+ list = base()
798
+ Officious.each do |opt, block|
799
+ list.long[opt] ||= block.call(self)
800
+ end
801
+ end
802
+
803
+ #
804
+ # Terminates option parsing. Optional parameter +arg+ is a string pushed
805
+ # back to be the first non-option argument.
806
+ #
807
+ def terminate(arg = nil)
808
+ self.class.terminate(arg)
809
+ end
810
+ def self.terminate(arg = nil)
811
+ throw :terminate, arg
812
+ end
813
+
814
+ @stack = [DefaultList]
815
+ def self.top() DefaultList end
816
+
817
+ #
818
+ # Directs to accept specified class +t+. The argument string is passed to
819
+ # the block in which it should be converted to the desired class.
820
+ #
821
+ # +t+:: Argument class specifier, any object including Class.
822
+ # +pat+:: Pattern for argument, defaults to +t+ if it responds to match.
823
+ #
824
+ # accept(t, pat, &block)
825
+ #
826
+ def accept(*args, &blk) top.accept(*args, &blk) end
827
+ #
828
+ # See #accept.
829
+ #
830
+ def self.accept(*args, &blk) top.accept(*args, &blk) end
831
+
832
+ #
833
+ # Directs to reject specified class argument.
834
+ #
835
+ # +t+:: Argument class specifier, any object including Class.
836
+ #
837
+ # reject(t)
838
+ #
839
+ def reject(*args, &blk) top.reject(*args, &blk) end
840
+ #
841
+ # See #reject.
842
+ #
843
+ def self.reject(*args, &blk) top.reject(*args, &blk) end
844
+
845
+ #
846
+ # Instance methods
847
+ #
848
+
849
+ # Heading banner preceding summary.
850
+ attr_writer :banner
851
+
852
+ # Program name to be emitted in error message and default banner,
853
+ # defaults to $0.
854
+ attr_writer :program_name
855
+
856
+ # Width for option list portion of summary. Must be Numeric.
857
+ attr_accessor :summary_width
858
+
859
+ # Indentation for summary. Must be String (or have + String method).
860
+ attr_accessor :summary_indent
861
+
862
+ # Strings to be parsed in default.
863
+ attr_accessor :default_argv
864
+
865
+ #
866
+ # Heading banner preceding summary.
867
+ #
868
+ def banner
869
+ unless @banner
870
+ @banner = "Usage: #{program_name} [options]"
871
+ visit(:add_banner, @banner)
872
+ end
873
+ @banner
874
+ end
875
+
876
+ #
877
+ # Program name to be emitted in error message and default banner, defaults
878
+ # to $0.
879
+ #
880
+ def program_name
881
+ @program_name || File.basename($0, '.*')
882
+ end
883
+
884
+ # for experimental cascading :-)
885
+ alias set_banner banner=
886
+ alias set_program_name program_name=
887
+ alias set_summary_width summary_width=
888
+ alias set_summary_indent summary_indent=
889
+
890
+ # Version
891
+ attr_writer :version
892
+ # Release code
893
+ attr_writer :release
894
+
895
+ #
896
+ # Version
897
+ #
898
+ def version
899
+ @version || (defined?(::Version) && ::Version)
900
+ end
901
+
902
+ #
903
+ # Release code
904
+ #
905
+ def release
906
+ @release || (defined?(::Release) && ::Release) || (defined?(::RELEASE) && ::RELEASE)
907
+ end
908
+
909
+ #
910
+ # Returns version string from program_name, version and release.
911
+ #
912
+ def ver
913
+ if v = version
914
+ str = "#{program_name} #{[v].join('.')}"
915
+ str << " (#{v})" if v = release
916
+ str
917
+ end
918
+ end
919
+
920
+ def warn(mesg = $!)
921
+ super("#{program_name}: #{mesg}")
922
+ end
923
+
924
+ def abort(mesg = $!)
925
+ super("#{program_name}: #{mesg}")
926
+ end
927
+
928
+ #
929
+ # Subject of #on / #on_head, #accept / #reject
930
+ #
931
+ def top
932
+ @stack[-1]
933
+ end
934
+
935
+ #
936
+ # Subject of #on_tail.
937
+ #
938
+ def base
939
+ @stack[1]
940
+ end
941
+
942
+ #
943
+ # Pushes a new List.
944
+ #
945
+ def new
946
+ @stack.push(List.new)
947
+ if block_given?
948
+ yield self
949
+ else
950
+ self
951
+ end
952
+ end
953
+
954
+ #
955
+ # Removes the last List.
956
+ #
957
+ def remove
958
+ @stack.pop
959
+ end
960
+
961
+ #
962
+ # Puts option summary into +to+ and returns +to+. Yields each line if
963
+ # a block is given.
964
+ #
965
+ # +to+:: Output destination, which must have method <<. Defaults to [].
966
+ # +width+:: Width of left side, defaults to @summary_width.
967
+ # +max+:: Maximum length allowed for left side, defaults to +width+ - 1.
968
+ # +indent+:: Indentation, defaults to @summary_indent.
969
+ #
970
+ def summarize(to = [], width = @summary_width, max = width - 1, indent = @summary_indent, &blk)
971
+ blk ||= proc {|l| to << (l.index($/, -1) ? l : l + $/)}
972
+ visit(:summarize, {}, {}, width, max, indent, &blk)
973
+ to
974
+ end
975
+
976
+ #
977
+ # Returns option summary string.
978
+ #
979
+ def help; summarize(banner.to_s.sub(/\n?\z/, "\n")) end
980
+ alias to_s help
981
+
982
+ #
983
+ # Returns option summary list.
984
+ #
985
+ def to_a; summarize(banner.to_a.dup) end
986
+
987
+ #
988
+ # Checks if an argument is given twice, in which case an ArgumentError is
989
+ # raised. Called from OptionParser#switch only.
990
+ #
991
+ # +obj+:: New argument.
992
+ # +prv+:: Previously specified argument.
993
+ # +msg+:: Exception message.
994
+ #
995
+ def notwice(obj, prv, msg)
996
+ unless !prv or prv == obj
997
+ raise(ArgumentError, "argument #{msg} given twice: #{obj}",
998
+ ParseError.filter_backtrace(caller(2)))
999
+ end
1000
+ obj
1001
+ end
1002
+ private :notwice
1003
+
1004
+ SPLAT_PROC = proc {|*a| a.length <= 1 ? a.first : a}
1005
+ #
1006
+ # Creates an OptionParser::Switch from the parameters. The parsed argument
1007
+ # value is passed to the given block, where it can be processed.
1008
+ #
1009
+ # See at the beginning of OptionParser for some full examples.
1010
+ #
1011
+ # +opts+ can include the following elements:
1012
+ #
1013
+ # [Argument style:]
1014
+ # One of the following:
1015
+ # :NONE, :REQUIRED, :OPTIONAL
1016
+ #
1017
+ # [Argument pattern:]
1018
+ # Acceptable option argument format, must be pre-defined with
1019
+ # OptionParser.accept or OptionParser#accept, or Regexp. This can appear
1020
+ # once or assigned as String if not present, otherwise causes an
1021
+ # ArgumentError. Examples:
1022
+ # Float, Time, Array
1023
+ #
1024
+ # [Possible argument values:]
1025
+ # Hash or Array.
1026
+ # [:text, :binary, :auto]
1027
+ # %w[iso-2022-jp shift_jis euc-jp utf8 binary]
1028
+ # { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
1029
+ #
1030
+ # [Long style switch:]
1031
+ # Specifies a long style switch which takes a mandatory, optional or no
1032
+ # argument. It's a string of the following form:
1033
+ # "--switch=MANDATORY" or "--switch MANDATORY"
1034
+ # "--switch[=OPTIONAL]"
1035
+ # "--switch"
1036
+ #
1037
+ # [Short style switch:]
1038
+ # Specifies short style switch which takes a mandatory, optional or no
1039
+ # argument. It's a string of the following form:
1040
+ # "-xMANDATORY"
1041
+ # "-x[OPTIONAL]"
1042
+ # "-x"
1043
+ # There is also a special form which matches character range (not full
1044
+ # set of regular expression):
1045
+ # "-[a-z]MANDATORY"
1046
+ # "-[a-z][OPTIONAL]"
1047
+ # "-[a-z]"
1048
+ #
1049
+ # [Argument style and description:]
1050
+ # Instead of specifying mandatory or optional arguments directly in the
1051
+ # switch parameter, this separate parameter can be used.
1052
+ # "=MANDATORY"
1053
+ # "=[OPTIONAL]"
1054
+ #
1055
+ # [Description:]
1056
+ # Description string for the option.
1057
+ # "Run verbosely"
1058
+ #
1059
+ # [Handler:]
1060
+ # Handler for the parsed argument value. Either give a block or pass a
1061
+ # Proc or Method as an argument.
1062
+ #
1063
+ def make_switch(opts, block = nil)
1064
+ short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
1065
+ ldesc, sdesc, desc, arg = [], [], []
1066
+ default_style = Switch::NoArgument
1067
+ default_pattern = nil
1068
+ klass = nil
1069
+ n, q, a = nil
1070
+
1071
+ opts.each do |o|
1072
+ # argument class
1073
+ next if search(:atype, o) do |pat, c|
1074
+ klass = notwice(o, klass, 'type')
1075
+ if not_style and not_style != Switch::NoArgument
1076
+ not_pattern, not_conv = pat, c
1077
+ else
1078
+ default_pattern, conv = pat, c
1079
+ end
1080
+ end
1081
+
1082
+ # directly specified pattern(any object possible to match)
1083
+ if (!(String === o || Symbol === o)) and o.respond_to?(:match)
1084
+ pattern = notwice(o, pattern, 'pattern')
1085
+ if pattern.respond_to?(:convert)
1086
+ conv = pattern.method(:convert).to_proc
1087
+ else
1088
+ conv = SPLAT_PROC
1089
+ end
1090
+ next
1091
+ end
1092
+
1093
+ # anything others
1094
+ case o
1095
+ when Proc, Method
1096
+ block = notwice(o, block, 'block')
1097
+ when Array, Hash
1098
+ case pattern
1099
+ when CompletingHash
1100
+ when nil
1101
+ pattern = CompletingHash.new
1102
+ conv = pattern.method(:convert).to_proc if pattern.respond_to?(:convert)
1103
+ else
1104
+ raise ArgumentError, "argument pattern given twice"
1105
+ end
1106
+ o.each {|pat, *v| pattern[pat] = v.fetch(0) {pat}}
1107
+ when Module
1108
+ raise ArgumentError, "unsupported argument type: #{o}", ParseError.filter_backtrace(caller(4))
1109
+ when *ArgumentStyle.keys
1110
+ style = notwice(ArgumentStyle[o], style, 'style')
1111
+ when /^--no-([^\[\]=\s]*)(.+)?/
1112
+ q, a = $1, $2
1113
+ o = notwice(a ? Object : TrueClass, klass, 'type')
1114
+ not_pattern, not_conv = search(:atype, o) unless not_style
1115
+ not_style = (not_style || default_style).guess(arg = a) if a
1116
+ default_style = Switch::NoArgument
1117
+ default_pattern, conv = search(:atype, FalseClass) unless default_pattern
1118
+ ldesc << "--no-#{q}"
1119
+ long << 'no-' + (q = q.downcase)
1120
+ nolong << q
1121
+ when /^--\[no-\]([^\[\]=\s]*)(.+)?/
1122
+ q, a = $1, $2
1123
+ o = notwice(a ? Object : TrueClass, klass, 'type')
1124
+ if a
1125
+ default_style = default_style.guess(arg = a)
1126
+ default_pattern, conv = search(:atype, o) unless default_pattern
1127
+ end
1128
+ ldesc << "--[no-]#{q}"
1129
+ long << (o = q.downcase)
1130
+ not_pattern, not_conv = search(:atype, FalseClass) unless not_style
1131
+ not_style = Switch::NoArgument
1132
+ nolong << 'no-' + o
1133
+ when /^--([^\[\]=\s]*)(.+)?/
1134
+ q, a = $1, $2
1135
+ if a
1136
+ o = notwice(NilClass, klass, 'type')
1137
+ default_style = default_style.guess(arg = a)
1138
+ default_pattern, conv = search(:atype, o) unless default_pattern
1139
+ end
1140
+ ldesc << "--#{q}"
1141
+ long << (o = q.downcase)
1142
+ when /^-(\[\^?\]?(?:[^\\\]]|\\.)*\])(.+)?/
1143
+ q, a = $1, $2
1144
+ o = notwice(Object, klass, 'type')
1145
+ if a
1146
+ default_style = default_style.guess(arg = a)
1147
+ default_pattern, conv = search(:atype, o) unless default_pattern
1148
+ end
1149
+ sdesc << "-#{q}"
1150
+ short << Regexp.new(q)
1151
+ when /^-(.)(.+)?/
1152
+ q, a = $1, $2
1153
+ if a
1154
+ o = notwice(NilClass, klass, 'type')
1155
+ default_style = default_style.guess(arg = a)
1156
+ default_pattern, conv = search(:atype, o) unless default_pattern
1157
+ end
1158
+ sdesc << "-#{q}"
1159
+ short << q
1160
+ when /^=/
1161
+ style = notwice(default_style.guess(arg = o), style, 'style')
1162
+ default_pattern, conv = search(:atype, Object) unless default_pattern
1163
+ else
1164
+ desc.push(o)
1165
+ end
1166
+ end
1167
+
1168
+ default_pattern, conv = search(:atype, default_style.pattern) unless default_pattern
1169
+ if !(short.empty? and long.empty?)
1170
+ s = (style || default_style).new(pattern || default_pattern,
1171
+ conv, sdesc, ldesc, arg, desc, block)
1172
+ elsif !block
1173
+ if style or pattern
1174
+ raise ArgumentError, "no switch given", ParseError.filter_backtrace(caller)
1175
+ end
1176
+ s = desc
1177
+ else
1178
+ short << pattern
1179
+ s = (style || default_style).new(pattern,
1180
+ conv, nil, nil, arg, desc, block)
1181
+ end
1182
+ return s, short, long,
1183
+ (not_style.new(not_pattern, not_conv, sdesc, ldesc, nil, desc, block) if not_style),
1184
+ nolong
1185
+ end
1186
+
1187
+ def define(*opts, &block)
1188
+ top.append(*(sw = make_switch(opts, block)))
1189
+ sw[0]
1190
+ end
1191
+
1192
+ #
1193
+ # Add option switch and handler. See #make_switch for an explanation of
1194
+ # parameters.
1195
+ #
1196
+ def on(*opts, &block)
1197
+ define(*opts, &block)
1198
+ self
1199
+ end
1200
+ alias def_option define
1201
+
1202
+ def define_head(*opts, &block)
1203
+ top.prepend(*(sw = make_switch(opts, block)))
1204
+ sw[0]
1205
+ end
1206
+
1207
+ #
1208
+ # Add option switch like with #on, but at head of summary.
1209
+ #
1210
+ def on_head(*opts, &block)
1211
+ define_head(*opts, &block)
1212
+ self
1213
+ end
1214
+ alias def_head_option define_head
1215
+
1216
+ def define_tail(*opts, &block)
1217
+ base.append(*(sw = make_switch(opts, block)))
1218
+ sw[0]
1219
+ end
1220
+
1221
+ #
1222
+ # Add option switch like with #on, but at tail of summary.
1223
+ #
1224
+ def on_tail(*opts, &block)
1225
+ define_tail(*opts, &block)
1226
+ self
1227
+ end
1228
+ alias def_tail_option define_tail
1229
+
1230
+ #
1231
+ # Add separator in summary.
1232
+ #
1233
+ def separator(string)
1234
+ top.append(string, nil, nil)
1235
+ end
1236
+
1237
+ #
1238
+ # Parses command line arguments +argv+ in order. When a block is given,
1239
+ # each non-option argument is yielded.
1240
+ #
1241
+ # Returns the rest of +argv+ left unparsed.
1242
+ #
1243
+ def order(*argv, &block)
1244
+ argv = argv[0].dup if argv.size == 1 and Array === argv[0]
1245
+ order!(argv, &block)
1246
+ end
1247
+
1248
+ #
1249
+ # Same as #order, but removes switches destructively.
1250
+ #
1251
+ def order!(argv = default_argv, &nonopt)
1252
+ parse_in_order(argv, &nonopt)
1253
+ end
1254
+
1255
+ def parse_in_order(argv = default_argv, setter = nil, &nonopt) # :nodoc:
1256
+ opt, arg, val, rest = nil
1257
+ nonopt ||= proc {|a| throw :terminate, a}
1258
+ argv.unshift(arg) if arg = catch(:terminate) {
1259
+ while arg = argv.shift
1260
+ case arg
1261
+ # long option
1262
+ when /\A--([^=]*)(?:=(.*))?/nm
1263
+ opt, rest = $1, $2
1264
+ begin
1265
+ sw, = complete(:long, opt, true)
1266
+ rescue ParseError
1267
+ raise $!.set_option(arg, true)
1268
+ end
1269
+ begin
1270
+ opt, cb, val = sw.parse(rest, argv) {|*exc| raise(*exc)}
1271
+ val = cb.call(val) if cb
1272
+ setter.call(sw.switch_name, val) if setter
1273
+ rescue ParseError
1274
+ raise $!.set_option(arg, rest)
1275
+ end
1276
+
1277
+ # short option
1278
+ when /\A-(.)((=).*|.+)?/nm
1279
+ opt, has_arg, eq, val, rest = $1, $3, $3, $2, $2
1280
+ begin
1281
+ sw, = search(:short, opt)
1282
+ unless sw
1283
+ begin
1284
+ sw, = complete(:short, opt)
1285
+ # short option matched.
1286
+ val = arg.sub(/\A-/, '')
1287
+ has_arg = true
1288
+ rescue InvalidOption
1289
+ # if no short options match, try completion with long
1290
+ # options.
1291
+ sw, = complete(:long, opt)
1292
+ eq ||= !rest
1293
+ end
1294
+ end
1295
+ rescue ParseError
1296
+ raise $!.set_option(arg, true)
1297
+ end
1298
+ begin
1299
+ opt, cb, val = sw.parse(val, argv) {|*exc| raise(*exc) if eq}
1300
+ raise InvalidOption, arg if has_arg and !eq and arg == "-#{opt}"
1301
+ argv.unshift(opt) if opt and (!rest or (opt = opt.sub(/\A-*/, '-')) != '-')
1302
+ val = cb.call(val) if cb
1303
+ setter.call(sw.switch_name, val) if setter
1304
+ rescue ParseError
1305
+ raise $!.set_option(arg, arg.length > 2)
1306
+ end
1307
+
1308
+ # non-option argument
1309
+ else
1310
+ catch(:prune) do
1311
+ visit(:each_option) do |sw0|
1312
+ sw = sw0
1313
+ sw.block.call(arg) if Switch === sw and sw.match_nonswitch?(arg)
1314
+ end
1315
+ nonopt.call(arg)
1316
+ end
1317
+ end
1318
+ end
1319
+
1320
+ nil
1321
+ }
1322
+
1323
+ visit(:search, :short, nil) {|sw| sw.block.call(*argv) if !sw.pattern}
1324
+
1325
+ argv
1326
+ end
1327
+ private :parse_in_order
1328
+
1329
+ #
1330
+ # Parses command line arguments +argv+ in permutation mode and returns
1331
+ # list of non-option arguments.
1332
+ #
1333
+ def permute(*argv)
1334
+ argv = argv[0].dup if argv.size == 1 and Array === argv[0]
1335
+ permute!(argv)
1336
+ end
1337
+
1338
+ #
1339
+ # Same as #permute, but removes switches destructively.
1340
+ #
1341
+ def permute!(argv = default_argv)
1342
+ nonopts = []
1343
+ order!(argv, &nonopts.method(:<<))
1344
+ argv[0, 0] = nonopts
1345
+ argv
1346
+ end
1347
+
1348
+ #
1349
+ # Parses command line arguments +argv+ in order when environment variable
1350
+ # POSIXLY_CORRECT is set, and in permutation mode otherwise.
1351
+ #
1352
+ def parse(*argv)
1353
+ argv = argv[0].dup if argv.size == 1 and Array === argv[0]
1354
+ parse!(argv)
1355
+ end
1356
+
1357
+ #
1358
+ # Same as #parse, but removes switches destructively.
1359
+ #
1360
+ def parse!(argv = default_argv)
1361
+ if ENV.include?('POSIXLY_CORRECT')
1362
+ order!(argv)
1363
+ else
1364
+ permute!(argv)
1365
+ end
1366
+ end
1367
+
1368
+ #
1369
+ # Wrapper method for getopts.rb.
1370
+ #
1371
+ # params = ARGV.getopts("ab:", "foo", "bar:")
1372
+ # # params[:a] = true # -a
1373
+ # # params[:b] = "1" # -b1
1374
+ # # params[:foo] = "1" # --foo
1375
+ # # params[:bar] = "x" # --bar x
1376
+ #
1377
+ def getopts(*args)
1378
+ argv = Array === args.first ? args.shift : default_argv
1379
+ single_options, *long_options = *args
1380
+
1381
+ result = {}
1382
+
1383
+ single_options.scan(/(.)(:)?/) do |opt, val|
1384
+ if val
1385
+ result[opt] = nil
1386
+ define("-#{opt} VAL")
1387
+ else
1388
+ result[opt] = false
1389
+ define("-#{opt}")
1390
+ end
1391
+ end if single_options
1392
+
1393
+ long_options.each do |arg|
1394
+ opt, val = arg.split(':', 2)
1395
+ if val
1396
+ result[opt] = val.empty? ? nil : val
1397
+ define("--#{opt} VAL")
1398
+ else
1399
+ result[opt] = false
1400
+ define("--#{opt}")
1401
+ end
1402
+ end
1403
+
1404
+ parse_in_order(argv, result.method(:[]=))
1405
+ result
1406
+ end
1407
+
1408
+ #
1409
+ # See #getopts.
1410
+ #
1411
+ def self.getopts(*args)
1412
+ new.getopts(*args)
1413
+ end
1414
+
1415
+ #
1416
+ # Traverses @stack, sending each element method +id+ with +args+ and
1417
+ # +block+.
1418
+ #
1419
+ def visit(id, *args, &block)
1420
+ @stack.reverse_each do |el|
1421
+ el.send(id, *args, &block)
1422
+ end
1423
+ nil
1424
+ end
1425
+ private :visit
1426
+
1427
+ #
1428
+ # Searches +key+ in @stack for +id+ hash and returns or yields the result.
1429
+ #
1430
+ def search(id, key)
1431
+ block_given = block_given?
1432
+ visit(:search, id, key) do |k|
1433
+ return block_given ? yield(k) : k
1434
+ end
1435
+ end
1436
+ private :search
1437
+
1438
+ #
1439
+ # Completes shortened long style option switch and returns pair of
1440
+ # canonical switch and switch descriptor OptionParser::Switch.
1441
+ #
1442
+ # +id+:: Searching table.
1443
+ # +opt+:: Searching key.
1444
+ # +icase+:: Search case insensitive if true.
1445
+ # +pat+:: Optional pattern for completion.
1446
+ #
1447
+ def complete(typ, opt, icase = false, *pat)
1448
+ if pat.empty?
1449
+ search(typ, opt) {|sw| return [sw, opt]} # exact match or...
1450
+ end
1451
+ raise AmbiguousOption, catch(:ambiguous) {
1452
+ visit(:complete, typ, opt, icase, *pat) {|o, *sw| return sw}
1453
+ raise InvalidOption, opt
1454
+ }
1455
+ end
1456
+ private :complete
1457
+
1458
+ #
1459
+ # Loads options from file names as +filename+. Does nothing when the file
1460
+ # is not present. Returns whether successfully loaded.
1461
+ #
1462
+ # +filename+ defaults to basename of the program without suffix in a
1463
+ # directory ~/.options.
1464
+ #
1465
+ def load(filename = nil)
1466
+ begin
1467
+ filename ||= File.expand_path(File.basename($0, '.*'), '~/.options')
1468
+ rescue
1469
+ return false
1470
+ end
1471
+ begin
1472
+ parse(*IO.readlines(filename).each {|s| s.chomp!})
1473
+ true
1474
+ rescue Errno::ENOENT, Errno::ENOTDIR
1475
+ false
1476
+ end
1477
+ end
1478
+
1479
+ #
1480
+ # Parses environment variable +env+ or its uppercase with splitting like a
1481
+ # shell.
1482
+ #
1483
+ # +env+ defaults to the basename of the program.
1484
+ #
1485
+ def environment(env = File.basename($0, '.*'))
1486
+ env = ENV[env] || ENV[env.upcase] or return
1487
+ require 'shellwords'
1488
+ parse(*Shellwords.shellwords(env))
1489
+ end
1490
+
1491
+ #
1492
+ # Acceptable argument classes
1493
+ #
1494
+
1495
+ #
1496
+ # Any string and no conversion. This is fall-back.
1497
+ #
1498
+ accept(Object) {|s,|s or s.nil?}
1499
+
1500
+ accept(NilClass) {|s,|s}
1501
+
1502
+ #
1503
+ # Any non-empty string, and no conversion.
1504
+ #
1505
+ accept(String, /.+/nm) {|s,*|s}
1506
+
1507
+ #
1508
+ # Ruby/C-like integer, octal for 0-7 sequence, binary for 0b, hexadecimal
1509
+ # for 0x, and decimal for others; with optional sign prefix. Converts to
1510
+ # Integer.
1511
+ #
1512
+ decimal = '\d+(?:_\d+)*'
1513
+ binary = 'b[01]+(?:_[01]+)*'
1514
+ hex = 'x[\da-f]+(?:_[\da-f]+)*'
1515
+ octal = "0(?:[0-7]*(?:_[0-7]+)*|#{binary}|#{hex})"
1516
+ integer = "#{octal}|#{decimal}"
1517
+ accept(Integer, %r"\A[-+]?(?:#{integer})"io) {|s,| Integer(s) if s}
1518
+
1519
+ #
1520
+ # Float number format, and converts to Float.
1521
+ #
1522
+ float = "(?:#{decimal}(?:\\.(?:#{decimal})?)?|\\.#{decimal})(?:E[-+]?#{decimal})?"
1523
+ floatpat = %r"\A[-+]?#{float}"io
1524
+ accept(Float, floatpat) {|s,| s.to_f if s}
1525
+
1526
+ #
1527
+ # Generic numeric format, converts to Integer for integer format, Float
1528
+ # for float format.
1529
+ #
1530
+ accept(Numeric, %r"\A[-+]?(?:#{octal}|#{float})"io) {|s,| eval(s) if s}
1531
+
1532
+ #
1533
+ # Decimal integer format, to be converted to Integer.
1534
+ #
1535
+ DecimalInteger = /\A[-+]?#{decimal}/io
1536
+ accept(DecimalInteger) {|s,| s.to_i if s}
1537
+
1538
+ #
1539
+ # Ruby/C like octal/hexadecimal/binary integer format, to be converted to
1540
+ # Integer.
1541
+ #
1542
+ OctalInteger = /\A[-+]?(?:[0-7]+(?:_[0-7]+)*|0(?:#{binary}|#{hex}))/io
1543
+ accept(OctalInteger) {|s,| s.oct if s}
1544
+
1545
+ #
1546
+ # Decimal integer/float number format, to be converted to Integer for
1547
+ # integer format, Float for float format.
1548
+ #
1549
+ DecimalNumeric = floatpat # decimal integer is allowed as float also.
1550
+ accept(DecimalNumeric) {|s,| eval(s) if s}
1551
+
1552
+ #
1553
+ # Boolean switch, which means whether it is present or not, whether it is
1554
+ # absent or not with prefix no-, or it takes an argument
1555
+ # yes/no/true/false/+/-.
1556
+ #
1557
+ yesno = CompletingHash.new
1558
+ %w[- no false].each {|el| yesno[el] = false}
1559
+ %w[+ yes true].each {|el| yesno[el] = true}
1560
+ yesno['nil'] = false # shoud be nil?
1561
+ accept(TrueClass, yesno) {|arg, val| val == nil or val}
1562
+ #
1563
+ # Similar to TrueClass, but defaults to false.
1564
+ #
1565
+ accept(FalseClass, yesno) {|arg, val| val != nil and val}
1566
+
1567
+ #
1568
+ # List of strings separated by ",".
1569
+ #
1570
+ accept(Array) do |s,|
1571
+ if s
1572
+ s = s.split(',').collect {|ss| ss unless ss.empty?}
1573
+ end
1574
+ s
1575
+ end
1576
+
1577
+ #
1578
+ # Regular expression with options.
1579
+ #
1580
+ accept(Regexp, %r"\A/((?:\\.|[^\\])*)/([[:alpha:]]+)?\z|.*") do |all, s, o|
1581
+ f = 0
1582
+ if o
1583
+ f |= Regexp::IGNORECASE if /i/ =~ o
1584
+ f |= Regexp::MULTILINE if /m/ =~ o
1585
+ f |= Regexp::EXTENDED if /x/ =~ o
1586
+ k = o.delete("^imx")
1587
+ end
1588
+ Regexp.new(s || all, f, k)
1589
+ end
1590
+
1591
+ #
1592
+ # Exceptions
1593
+ #
1594
+
1595
+ #
1596
+ # Base class of exceptions from OptionParser.
1597
+ #
1598
+ class ParseError < RuntimeError
1599
+ # Reason which caused the error.
1600
+ Reason = 'parse error'.freeze
1601
+
1602
+ def initialize(*args)
1603
+ @args = args
1604
+ @reason = nil
1605
+ end
1606
+
1607
+ attr_reader :args
1608
+ attr_writer :reason
1609
+
1610
+ #
1611
+ # Pushes back erred argument(s) to +argv+.
1612
+ #
1613
+ def recover(argv)
1614
+ argv[0, 0] = @args
1615
+ argv
1616
+ end
1617
+
1618
+ def self.filter_backtrace(array)
1619
+ unless $DEBUG
1620
+ array.delete_if(&%r"\A#{Regexp.quote(__FILE__)}:"o.method(:=~))
1621
+ end
1622
+ array
1623
+ end
1624
+
1625
+ def set_backtrace(array)
1626
+ super(self.class.filter_backtrace(array))
1627
+ end
1628
+
1629
+ def set_option(opt, eq)
1630
+ if eq
1631
+ @args[0] = opt
1632
+ else
1633
+ @args.unshift(opt)
1634
+ end
1635
+ self
1636
+ end
1637
+
1638
+ #
1639
+ # Returns error reason. Override this for I18N.
1640
+ #
1641
+ def reason
1642
+ @reason || self.class::Reason
1643
+ end
1644
+
1645
+ def inspect
1646
+ "#<#{self.class.to_s}: #{args.join(' ')}>"
1647
+ end
1648
+
1649
+ #
1650
+ # Default stringizing method to emit standard error message.
1651
+ #
1652
+ def message
1653
+ reason + ': ' + args.join(' ')
1654
+ end
1655
+
1656
+ alias to_s message
1657
+ end
1658
+
1659
+ #
1660
+ # Raises when ambiguously completable string is encountered.
1661
+ #
1662
+ class AmbiguousOption < ParseError
1663
+ const_set(:Reason, 'ambiguous option'.freeze)
1664
+ end
1665
+
1666
+ #
1667
+ # Raises when there is an argument for a switch which takes no argument.
1668
+ #
1669
+ class NeedlessArgument < ParseError
1670
+ const_set(:Reason, 'needless argument'.freeze)
1671
+ end
1672
+
1673
+ #
1674
+ # Raises when a switch with mandatory argument has no argument.
1675
+ #
1676
+ class MissingArgument < ParseError
1677
+ const_set(:Reason, 'missing argument'.freeze)
1678
+ end
1679
+
1680
+ #
1681
+ # Raises when switch is undefined.
1682
+ #
1683
+ class InvalidOption < ParseError
1684
+ const_set(:Reason, 'invalid option'.freeze)
1685
+ end
1686
+
1687
+ #
1688
+ # Raises when the given argument does not match required format.
1689
+ #
1690
+ class InvalidArgument < ParseError
1691
+ const_set(:Reason, 'invalid argument'.freeze)
1692
+ end
1693
+
1694
+ #
1695
+ # Raises when the given argument word can't be completed uniquely.
1696
+ #
1697
+ class AmbiguousArgument < InvalidArgument
1698
+ const_set(:Reason, 'ambiguous argument'.freeze)
1699
+ end
1700
+
1701
+ #
1702
+ # Miscellaneous
1703
+ #
1704
+
1705
+ #
1706
+ # Extends command line arguments array (ARGV) to parse itself.
1707
+ #
1708
+ module Arguable
1709
+
1710
+ #
1711
+ # Sets OptionParser object, when +opt+ is +false+ or +nil+, methods
1712
+ # OptionParser::Arguable#options and OptionParser::Arguable#options= are
1713
+ # undefined. Thus, there is no ways to access the OptionParser object
1714
+ # via the receiver object.
1715
+ #
1716
+ def options=(opt)
1717
+ unless @optparse = opt
1718
+ class << self
1719
+ undef_method(:options)
1720
+ undef_method(:options=)
1721
+ end
1722
+ end
1723
+ end
1724
+
1725
+ #
1726
+ # Actual OptionParser object, automatically created if nonexistent.
1727
+ #
1728
+ # If called with a block, yields the OptionParser object and returns the
1729
+ # result of the block. If an OptionParser::ParseError exception occurs
1730
+ # in the block, it is rescued, a error message printed to STDERR and
1731
+ # +nil+ returned.
1732
+ #
1733
+ def options
1734
+ @optparse ||= OptionParser.new
1735
+ @optparse.default_argv = self
1736
+ block_given? or return @optparse
1737
+ begin
1738
+ yield @optparse
1739
+ rescue ParseError
1740
+ @optparse.warn $!
1741
+ nil
1742
+ end
1743
+ end
1744
+
1745
+ #
1746
+ # Parses +self+ destructively in order and returns +self+ containing the
1747
+ # rest arguments left unparsed.
1748
+ #
1749
+ def order!(&blk) options.order!(self, &blk) end
1750
+
1751
+ #
1752
+ # Parses +self+ destructively in permutation mode and returns +self+
1753
+ # containing the rest arguments left unparsed.
1754
+ #
1755
+ def permute!() options.permute!(self) end
1756
+
1757
+ #
1758
+ # Parses +self+ destructively and returns +self+ containing the
1759
+ # rest arguments left unparsed.
1760
+ #
1761
+ def parse!() options.parse!(self) end
1762
+
1763
+ #
1764
+ # Substitution of getopts is possible as follows. Also see
1765
+ # OptionParser#getopts.
1766
+ #
1767
+ # def getopts(*args)
1768
+ # ($OPT = ARGV.getopts(*args)).each do |opt, val|
1769
+ # eval "$OPT_#{opt.gsub(/[^A-Za-z0-9_]/, '_')} = val"
1770
+ # end
1771
+ # rescue OptionParser::ParseError
1772
+ # end
1773
+ #
1774
+ def getopts(*args)
1775
+ options.getopts(self, *args)
1776
+ end
1777
+
1778
+ #
1779
+ # Initializes instance variable.
1780
+ #
1781
+ def self.extend_object(obj)
1782
+ super
1783
+ obj.instance_eval {@optparse = nil}
1784
+ end
1785
+ def initialize(*args)
1786
+ super
1787
+ @optparse = nil
1788
+ end
1789
+ end
1790
+
1791
+ #
1792
+ # Acceptable argument classes. Now contains DecimalInteger, OctalInteger
1793
+ # and DecimalNumeric. See Acceptable argument classes (in source code).
1794
+ #
1795
+ module Acceptables
1796
+ const_set(:DecimalInteger, OptionParser::DecimalInteger)
1797
+ const_set(:OctalInteger, OptionParser::OctalInteger)
1798
+ const_set(:DecimalNumeric, OptionParser::DecimalNumeric)
1799
+ end
1800
+ end
1801
+
1802
+ # ARGV is arguable by OptionParser
1803
+ ARGV.extend(OptionParser::Arguable)
1804
+
1805
+ if $0 == __FILE__
1806
+ Version = OptionParser::Version
1807
+ ARGV.options {|q|
1808
+ q.parse!.empty? or puts "what's #{ARGV.join(' ')}?"
1809
+ } or abort(ARGV.options.to_s)
1810
+ end