johnson 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (371) hide show
  1. data/.autotest +14 -0
  2. data/CHANGELOG.rdoc +11 -0
  3. data/Manifest.txt +370 -0
  4. data/README.rdoc +60 -0
  5. data/Rakefile +42 -0
  6. data/bin/johnson +108 -0
  7. data/docs/MINGW32.mk +124 -0
  8. data/docs/cross-compile.txt +38 -0
  9. data/ext/spidermonkey/context.c +115 -0
  10. data/ext/spidermonkey/context.h +19 -0
  11. data/ext/spidermonkey/conversions.c +320 -0
  12. data/ext/spidermonkey/conversions.h +18 -0
  13. data/ext/spidermonkey/debugger.c +226 -0
  14. data/ext/spidermonkey/debugger.h +9 -0
  15. data/ext/spidermonkey/extconf.rb +30 -0
  16. data/ext/spidermonkey/extensions.c +37 -0
  17. data/ext/spidermonkey/extensions.h +12 -0
  18. data/ext/spidermonkey/global.c +40 -0
  19. data/ext/spidermonkey/global.h +11 -0
  20. data/ext/spidermonkey/idhash.c +16 -0
  21. data/ext/spidermonkey/idhash.h +8 -0
  22. data/ext/spidermonkey/immutable_node.c +1153 -0
  23. data/ext/spidermonkey/immutable_node.c.erb +523 -0
  24. data/ext/spidermonkey/immutable_node.h +22 -0
  25. data/ext/spidermonkey/jroot.h +187 -0
  26. data/ext/spidermonkey/js_land_proxy.c +610 -0
  27. data/ext/spidermonkey/js_land_proxy.h +20 -0
  28. data/ext/spidermonkey/ruby_land_proxy.c +543 -0
  29. data/ext/spidermonkey/ruby_land_proxy.h +17 -0
  30. data/ext/spidermonkey/runtime.c +330 -0
  31. data/ext/spidermonkey/runtime.h +25 -0
  32. data/ext/spidermonkey/spidermonkey.c +20 -0
  33. data/ext/spidermonkey/spidermonkey.h +29 -0
  34. data/johnson.gemspec +44 -0
  35. data/js/johnson/cli.js +30 -0
  36. data/js/johnson/prelude.js +80 -0
  37. data/lib/johnson.rb +55 -0
  38. data/lib/johnson/cli.rb +7 -0
  39. data/lib/johnson/cli/options.rb +67 -0
  40. data/lib/johnson/error.rb +4 -0
  41. data/lib/johnson/nodes.rb +7 -0
  42. data/lib/johnson/nodes/binary_node.rb +65 -0
  43. data/lib/johnson/nodes/for.rb +14 -0
  44. data/lib/johnson/nodes/for_in.rb +12 -0
  45. data/lib/johnson/nodes/function.rb +13 -0
  46. data/lib/johnson/nodes/list.rb +28 -0
  47. data/lib/johnson/nodes/node.rb +68 -0
  48. data/lib/johnson/nodes/ternary_node.rb +20 -0
  49. data/lib/johnson/parser.rb +21 -0
  50. data/lib/johnson/parser/syntax_error.rb +13 -0
  51. data/lib/johnson/runtime.rb +63 -0
  52. data/lib/johnson/spidermonkey/context.rb +10 -0
  53. data/lib/johnson/spidermonkey/debugger.rb +67 -0
  54. data/lib/johnson/spidermonkey/immutable_node.rb +282 -0
  55. data/lib/johnson/spidermonkey/js_land_proxy.rb +62 -0
  56. data/lib/johnson/spidermonkey/mutable_tree_visitor.rb +242 -0
  57. data/lib/johnson/spidermonkey/ruby_land_proxy.rb +54 -0
  58. data/lib/johnson/spidermonkey/runtime.rb +103 -0
  59. data/lib/johnson/version.rb +3 -0
  60. data/lib/johnson/visitable.rb +16 -0
  61. data/lib/johnson/visitors.rb +5 -0
  62. data/lib/johnson/visitors/dot_visitor.rb +169 -0
  63. data/lib/johnson/visitors/ecma_visitor.rb +323 -0
  64. data/lib/johnson/visitors/enumerating_visitor.rb +15 -0
  65. data/lib/johnson/visitors/sexp_visitor.rb +174 -0
  66. data/lib/johnson/visitors/visitor.rb +91 -0
  67. data/lib/rails/init.rb +37 -0
  68. data/lib/tasks/gem.rake +9 -0
  69. data/lib/tasks/parsing.rake +37 -0
  70. data/lib/tasks/testing.rake +36 -0
  71. data/lib/tasks/vendor.rake +20 -0
  72. data/test/helper.rb +55 -0
  73. data/test/johnson/browser_test.rb +43 -0
  74. data/test/johnson/conversions/array_test.rb +32 -0
  75. data/test/johnson/conversions/boolean_test.rb +17 -0
  76. data/test/johnson/conversions/callable_test.rb +34 -0
  77. data/test/johnson/conversions/file_test.rb +15 -0
  78. data/test/johnson/conversions/nil_test.rb +20 -0
  79. data/test/johnson/conversions/number_test.rb +34 -0
  80. data/test/johnson/conversions/regexp_test.rb +24 -0
  81. data/test/johnson/conversions/string_test.rb +26 -0
  82. data/test/johnson/conversions/struct_test.rb +15 -0
  83. data/test/johnson/conversions/symbol_test.rb +19 -0
  84. data/test/johnson/conversions/thread_test.rb +24 -0
  85. data/test/johnson/error_test.rb +9 -0
  86. data/test/johnson/extensions_test.rb +56 -0
  87. data/test/johnson/nodes/array_literal_test.rb +57 -0
  88. data/test/johnson/nodes/array_node_test.rb +26 -0
  89. data/test/johnson/nodes/binary_node_test.rb +61 -0
  90. data/test/johnson/nodes/bracket_access_test.rb +16 -0
  91. data/test/johnson/nodes/delete_test.rb +11 -0
  92. data/test/johnson/nodes/do_while_test.rb +12 -0
  93. data/test/johnson/nodes/dot_accessor_test.rb +15 -0
  94. data/test/johnson/nodes/export_test.rb +9 -0
  95. data/test/johnson/nodes/for_test.rb +54 -0
  96. data/test/johnson/nodes/function_test.rb +71 -0
  97. data/test/johnson/nodes/if_test.rb +41 -0
  98. data/test/johnson/nodes/import_test.rb +13 -0
  99. data/test/johnson/nodes/label_test.rb +19 -0
  100. data/test/johnson/nodes/let_test.rb +31 -0
  101. data/test/johnson/nodes/object_literal_test.rb +110 -0
  102. data/test/johnson/nodes/return_test.rb +16 -0
  103. data/test/johnson/nodes/semi_test.rb +8 -0
  104. data/test/johnson/nodes/switch_test.rb +55 -0
  105. data/test/johnson/nodes/ternary_test.rb +25 -0
  106. data/test/johnson/nodes/throw_test.rb +9 -0
  107. data/test/johnson/nodes/try_node_test.rb +59 -0
  108. data/test/johnson/nodes/typeof_test.rb +11 -0
  109. data/test/johnson/nodes/unary_node_test.rb +23 -0
  110. data/test/johnson/nodes/void_test.rb +11 -0
  111. data/test/johnson/nodes/while_test.rb +26 -0
  112. data/test/johnson/nodes/with_test.rb +10 -0
  113. data/test/johnson/prelude_test.rb +56 -0
  114. data/test/johnson/runtime_test.rb +64 -0
  115. data/test/johnson/spidermonkey/context_test.rb +21 -0
  116. data/test/johnson/spidermonkey/immutable_node_test.rb +34 -0
  117. data/test/johnson/spidermonkey/js_land_proxy_test.rb +236 -0
  118. data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +240 -0
  119. data/test/johnson/spidermonkey/runtime_test.rb +17 -0
  120. data/test/johnson/version_test.rb +13 -0
  121. data/test/johnson/visitors/dot_visitor_test.rb +39 -0
  122. data/test/johnson/visitors/enumerating_visitor_test.rb +12 -0
  123. data/test/johnson_test.rb +16 -0
  124. data/test/parser_test.rb +276 -0
  125. data/vendor/spidermonkey/.cvsignore +9 -0
  126. data/vendor/spidermonkey/Makefile.in +449 -0
  127. data/vendor/spidermonkey/Makefile.ref +365 -0
  128. data/vendor/spidermonkey/README.html +820 -0
  129. data/vendor/spidermonkey/SpiderMonkey.rsp +12 -0
  130. data/vendor/spidermonkey/Y.js +19 -0
  131. data/vendor/spidermonkey/build.mk +43 -0
  132. data/vendor/spidermonkey/config.mk +192 -0
  133. data/vendor/spidermonkey/config/AIX4.1.mk +65 -0
  134. data/vendor/spidermonkey/config/AIX4.2.mk +64 -0
  135. data/vendor/spidermonkey/config/AIX4.3.mk +65 -0
  136. data/vendor/spidermonkey/config/Darwin.mk +83 -0
  137. data/vendor/spidermonkey/config/Darwin1.3.mk +81 -0
  138. data/vendor/spidermonkey/config/Darwin1.4.mk +41 -0
  139. data/vendor/spidermonkey/config/Darwin5.2.mk +81 -0
  140. data/vendor/spidermonkey/config/Darwin5.3.mk +81 -0
  141. data/vendor/spidermonkey/config/HP-UXB.10.10.mk +77 -0
  142. data/vendor/spidermonkey/config/HP-UXB.10.20.mk +77 -0
  143. data/vendor/spidermonkey/config/HP-UXB.11.00.mk +80 -0
  144. data/vendor/spidermonkey/config/IRIX.mk +87 -0
  145. data/vendor/spidermonkey/config/IRIX5.3.mk +44 -0
  146. data/vendor/spidermonkey/config/IRIX6.1.mk +44 -0
  147. data/vendor/spidermonkey/config/IRIX6.2.mk +44 -0
  148. data/vendor/spidermonkey/config/IRIX6.3.mk +44 -0
  149. data/vendor/spidermonkey/config/IRIX6.5.mk +44 -0
  150. data/vendor/spidermonkey/config/Linux_All.mk +103 -0
  151. data/vendor/spidermonkey/config/Mac_OS10.0.mk +82 -0
  152. data/vendor/spidermonkey/config/OSF1V4.0.mk +72 -0
  153. data/vendor/spidermonkey/config/OSF1V5.0.mk +69 -0
  154. data/vendor/spidermonkey/config/SunOS4.1.4.mk +101 -0
  155. data/vendor/spidermonkey/config/SunOS5.10.mk +50 -0
  156. data/vendor/spidermonkey/config/SunOS5.3.mk +91 -0
  157. data/vendor/spidermonkey/config/SunOS5.4.mk +92 -0
  158. data/vendor/spidermonkey/config/SunOS5.5.1.mk +44 -0
  159. data/vendor/spidermonkey/config/SunOS5.5.mk +87 -0
  160. data/vendor/spidermonkey/config/SunOS5.6.mk +89 -0
  161. data/vendor/spidermonkey/config/SunOS5.7.mk +44 -0
  162. data/vendor/spidermonkey/config/SunOS5.8.mk +44 -0
  163. data/vendor/spidermonkey/config/SunOS5.9.mk +44 -0
  164. data/vendor/spidermonkey/config/WINNT4.0.mk +117 -0
  165. data/vendor/spidermonkey/config/WINNT5.0.mk +117 -0
  166. data/vendor/spidermonkey/config/WINNT5.1.mk +117 -0
  167. data/vendor/spidermonkey/config/WINNT5.2.mk +117 -0
  168. data/vendor/spidermonkey/config/WINNT6.0.mk +117 -0
  169. data/vendor/spidermonkey/config/dgux.mk +64 -0
  170. data/vendor/spidermonkey/editline/Makefile.ref +144 -0
  171. data/vendor/spidermonkey/editline/README +83 -0
  172. data/vendor/spidermonkey/editline/editline.3 +175 -0
  173. data/vendor/spidermonkey/editline/editline.c +1369 -0
  174. data/vendor/spidermonkey/editline/editline.h +135 -0
  175. data/vendor/spidermonkey/editline/sysunix.c +182 -0
  176. data/vendor/spidermonkey/editline/unix.h +82 -0
  177. data/vendor/spidermonkey/fdlibm/.cvsignore +7 -0
  178. data/vendor/spidermonkey/fdlibm/Makefile.in +127 -0
  179. data/vendor/spidermonkey/fdlibm/Makefile.ref +192 -0
  180. data/vendor/spidermonkey/fdlibm/e_acos.c +147 -0
  181. data/vendor/spidermonkey/fdlibm/e_acosh.c +105 -0
  182. data/vendor/spidermonkey/fdlibm/e_asin.c +156 -0
  183. data/vendor/spidermonkey/fdlibm/e_atan2.c +165 -0
  184. data/vendor/spidermonkey/fdlibm/e_atanh.c +110 -0
  185. data/vendor/spidermonkey/fdlibm/e_cosh.c +133 -0
  186. data/vendor/spidermonkey/fdlibm/e_exp.c +202 -0
  187. data/vendor/spidermonkey/fdlibm/e_fmod.c +184 -0
  188. data/vendor/spidermonkey/fdlibm/e_gamma.c +71 -0
  189. data/vendor/spidermonkey/fdlibm/e_gamma_r.c +70 -0
  190. data/vendor/spidermonkey/fdlibm/e_hypot.c +173 -0
  191. data/vendor/spidermonkey/fdlibm/e_j0.c +524 -0
  192. data/vendor/spidermonkey/fdlibm/e_j1.c +523 -0
  193. data/vendor/spidermonkey/fdlibm/e_jn.c +315 -0
  194. data/vendor/spidermonkey/fdlibm/e_lgamma.c +71 -0
  195. data/vendor/spidermonkey/fdlibm/e_lgamma_r.c +347 -0
  196. data/vendor/spidermonkey/fdlibm/e_log.c +184 -0
  197. data/vendor/spidermonkey/fdlibm/e_log10.c +134 -0
  198. data/vendor/spidermonkey/fdlibm/e_pow.c +386 -0
  199. data/vendor/spidermonkey/fdlibm/e_rem_pio2.c +222 -0
  200. data/vendor/spidermonkey/fdlibm/e_remainder.c +120 -0
  201. data/vendor/spidermonkey/fdlibm/e_scalb.c +89 -0
  202. data/vendor/spidermonkey/fdlibm/e_sinh.c +122 -0
  203. data/vendor/spidermonkey/fdlibm/e_sqrt.c +497 -0
  204. data/vendor/spidermonkey/fdlibm/fdlibm.h +273 -0
  205. data/vendor/spidermonkey/fdlibm/fdlibm.mak +1453 -0
  206. data/vendor/spidermonkey/fdlibm/fdlibm.mdp +0 -0
  207. data/vendor/spidermonkey/fdlibm/k_cos.c +135 -0
  208. data/vendor/spidermonkey/fdlibm/k_rem_pio2.c +354 -0
  209. data/vendor/spidermonkey/fdlibm/k_sin.c +114 -0
  210. data/vendor/spidermonkey/fdlibm/k_standard.c +785 -0
  211. data/vendor/spidermonkey/fdlibm/k_tan.c +170 -0
  212. data/vendor/spidermonkey/fdlibm/s_asinh.c +101 -0
  213. data/vendor/spidermonkey/fdlibm/s_atan.c +175 -0
  214. data/vendor/spidermonkey/fdlibm/s_cbrt.c +133 -0
  215. data/vendor/spidermonkey/fdlibm/s_ceil.c +120 -0
  216. data/vendor/spidermonkey/fdlibm/s_copysign.c +72 -0
  217. data/vendor/spidermonkey/fdlibm/s_cos.c +118 -0
  218. data/vendor/spidermonkey/fdlibm/s_erf.c +356 -0
  219. data/vendor/spidermonkey/fdlibm/s_expm1.c +267 -0
  220. data/vendor/spidermonkey/fdlibm/s_fabs.c +70 -0
  221. data/vendor/spidermonkey/fdlibm/s_finite.c +71 -0
  222. data/vendor/spidermonkey/fdlibm/s_floor.c +121 -0
  223. data/vendor/spidermonkey/fdlibm/s_frexp.c +99 -0
  224. data/vendor/spidermonkey/fdlibm/s_ilogb.c +85 -0
  225. data/vendor/spidermonkey/fdlibm/s_isnan.c +74 -0
  226. data/vendor/spidermonkey/fdlibm/s_ldexp.c +66 -0
  227. data/vendor/spidermonkey/fdlibm/s_lib_version.c +73 -0
  228. data/vendor/spidermonkey/fdlibm/s_log1p.c +211 -0
  229. data/vendor/spidermonkey/fdlibm/s_logb.c +79 -0
  230. data/vendor/spidermonkey/fdlibm/s_matherr.c +64 -0
  231. data/vendor/spidermonkey/fdlibm/s_modf.c +132 -0
  232. data/vendor/spidermonkey/fdlibm/s_nextafter.c +124 -0
  233. data/vendor/spidermonkey/fdlibm/s_rint.c +131 -0
  234. data/vendor/spidermonkey/fdlibm/s_scalbn.c +107 -0
  235. data/vendor/spidermonkey/fdlibm/s_signgam.c +40 -0
  236. data/vendor/spidermonkey/fdlibm/s_significand.c +68 -0
  237. data/vendor/spidermonkey/fdlibm/s_sin.c +118 -0
  238. data/vendor/spidermonkey/fdlibm/s_tan.c +112 -0
  239. data/vendor/spidermonkey/fdlibm/s_tanh.c +122 -0
  240. data/vendor/spidermonkey/fdlibm/w_acos.c +78 -0
  241. data/vendor/spidermonkey/fdlibm/w_acosh.c +78 -0
  242. data/vendor/spidermonkey/fdlibm/w_asin.c +80 -0
  243. data/vendor/spidermonkey/fdlibm/w_atan2.c +79 -0
  244. data/vendor/spidermonkey/fdlibm/w_atanh.c +81 -0
  245. data/vendor/spidermonkey/fdlibm/w_cosh.c +77 -0
  246. data/vendor/spidermonkey/fdlibm/w_exp.c +88 -0
  247. data/vendor/spidermonkey/fdlibm/w_fmod.c +78 -0
  248. data/vendor/spidermonkey/fdlibm/w_gamma.c +85 -0
  249. data/vendor/spidermonkey/fdlibm/w_gamma_r.c +81 -0
  250. data/vendor/spidermonkey/fdlibm/w_hypot.c +78 -0
  251. data/vendor/spidermonkey/fdlibm/w_j0.c +105 -0
  252. data/vendor/spidermonkey/fdlibm/w_j1.c +106 -0
  253. data/vendor/spidermonkey/fdlibm/w_jn.c +128 -0
  254. data/vendor/spidermonkey/fdlibm/w_lgamma.c +85 -0
  255. data/vendor/spidermonkey/fdlibm/w_lgamma_r.c +81 -0
  256. data/vendor/spidermonkey/fdlibm/w_log.c +78 -0
  257. data/vendor/spidermonkey/fdlibm/w_log10.c +81 -0
  258. data/vendor/spidermonkey/fdlibm/w_pow.c +99 -0
  259. data/vendor/spidermonkey/fdlibm/w_remainder.c +77 -0
  260. data/vendor/spidermonkey/fdlibm/w_scalb.c +95 -0
  261. data/vendor/spidermonkey/fdlibm/w_sinh.c +77 -0
  262. data/vendor/spidermonkey/fdlibm/w_sqrt.c +77 -0
  263. data/vendor/spidermonkey/javascript-trace.d +73 -0
  264. data/vendor/spidermonkey/js.c +3951 -0
  265. data/vendor/spidermonkey/js.mdp +0 -0
  266. data/vendor/spidermonkey/js.msg +308 -0
  267. data/vendor/spidermonkey/js3240.rc +79 -0
  268. data/vendor/spidermonkey/jsOS240.def +654 -0
  269. data/vendor/spidermonkey/jsapi.c +5836 -0
  270. data/vendor/spidermonkey/jsapi.h +2624 -0
  271. data/vendor/spidermonkey/jsarena.c +450 -0
  272. data/vendor/spidermonkey/jsarena.h +318 -0
  273. data/vendor/spidermonkey/jsarray.c +2996 -0
  274. data/vendor/spidermonkey/jsarray.h +127 -0
  275. data/vendor/spidermonkey/jsatom.c +1045 -0
  276. data/vendor/spidermonkey/jsatom.h +442 -0
  277. data/vendor/spidermonkey/jsbit.h +253 -0
  278. data/vendor/spidermonkey/jsbool.c +176 -0
  279. data/vendor/spidermonkey/jsbool.h +73 -0
  280. data/vendor/spidermonkey/jsclist.h +139 -0
  281. data/vendor/spidermonkey/jscntxt.c +1348 -0
  282. data/vendor/spidermonkey/jscntxt.h +1120 -0
  283. data/vendor/spidermonkey/jscompat.h +57 -0
  284. data/vendor/spidermonkey/jsconfig.h +248 -0
  285. data/vendor/spidermonkey/jsconfig.mk +181 -0
  286. data/vendor/spidermonkey/jscpucfg.c +396 -0
  287. data/vendor/spidermonkey/jscpucfg.h +212 -0
  288. data/vendor/spidermonkey/jsdate.c +2390 -0
  289. data/vendor/spidermonkey/jsdate.h +124 -0
  290. data/vendor/spidermonkey/jsdbgapi.c +1802 -0
  291. data/vendor/spidermonkey/jsdbgapi.h +464 -0
  292. data/vendor/spidermonkey/jsdhash.c +868 -0
  293. data/vendor/spidermonkey/jsdhash.h +592 -0
  294. data/vendor/spidermonkey/jsdtoa.c +3167 -0
  295. data/vendor/spidermonkey/jsdtoa.h +130 -0
  296. data/vendor/spidermonkey/jsdtracef.c +317 -0
  297. data/vendor/spidermonkey/jsdtracef.h +77 -0
  298. data/vendor/spidermonkey/jsemit.c +6909 -0
  299. data/vendor/spidermonkey/jsemit.h +741 -0
  300. data/vendor/spidermonkey/jsexn.c +1371 -0
  301. data/vendor/spidermonkey/jsexn.h +96 -0
  302. data/vendor/spidermonkey/jsfile.c +2736 -0
  303. data/vendor/spidermonkey/jsfile.h +56 -0
  304. data/vendor/spidermonkey/jsfile.msg +90 -0
  305. data/vendor/spidermonkey/jsfun.c +2634 -0
  306. data/vendor/spidermonkey/jsfun.h +254 -0
  307. data/vendor/spidermonkey/jsgc.c +3562 -0
  308. data/vendor/spidermonkey/jsgc.h +403 -0
  309. data/vendor/spidermonkey/jshash.c +476 -0
  310. data/vendor/spidermonkey/jshash.h +151 -0
  311. data/vendor/spidermonkey/jsify.pl +485 -0
  312. data/vendor/spidermonkey/jsinterp.c +7007 -0
  313. data/vendor/spidermonkey/jsinterp.h +525 -0
  314. data/vendor/spidermonkey/jsinvoke.c +43 -0
  315. data/vendor/spidermonkey/jsiter.c +1067 -0
  316. data/vendor/spidermonkey/jsiter.h +122 -0
  317. data/vendor/spidermonkey/jskeyword.tbl +124 -0
  318. data/vendor/spidermonkey/jskwgen.c +460 -0
  319. data/vendor/spidermonkey/jslibmath.h +266 -0
  320. data/vendor/spidermonkey/jslock.c +1309 -0
  321. data/vendor/spidermonkey/jslock.h +313 -0
  322. data/vendor/spidermonkey/jslocko.asm +60 -0
  323. data/vendor/spidermonkey/jslog2.c +94 -0
  324. data/vendor/spidermonkey/jslong.c +264 -0
  325. data/vendor/spidermonkey/jslong.h +412 -0
  326. data/vendor/spidermonkey/jsmath.c +567 -0
  327. data/vendor/spidermonkey/jsmath.h +57 -0
  328. data/vendor/spidermonkey/jsnum.c +1239 -0
  329. data/vendor/spidermonkey/jsnum.h +283 -0
  330. data/vendor/spidermonkey/jsobj.c +5282 -0
  331. data/vendor/spidermonkey/jsobj.h +709 -0
  332. data/vendor/spidermonkey/jsopcode.c +5245 -0
  333. data/vendor/spidermonkey/jsopcode.h +394 -0
  334. data/vendor/spidermonkey/jsopcode.tbl +523 -0
  335. data/vendor/spidermonkey/jsotypes.h +202 -0
  336. data/vendor/spidermonkey/jsparse.c +6704 -0
  337. data/vendor/spidermonkey/jsparse.h +511 -0
  338. data/vendor/spidermonkey/jsprf.c +1262 -0
  339. data/vendor/spidermonkey/jsprf.h +150 -0
  340. data/vendor/spidermonkey/jsproto.tbl +128 -0
  341. data/vendor/spidermonkey/jsprvtd.h +267 -0
  342. data/vendor/spidermonkey/jspubtd.h +744 -0
  343. data/vendor/spidermonkey/jsregexp.c +4364 -0
  344. data/vendor/spidermonkey/jsregexp.h +183 -0
  345. data/vendor/spidermonkey/jsreops.tbl +145 -0
  346. data/vendor/spidermonkey/jsscan.c +2012 -0
  347. data/vendor/spidermonkey/jsscan.h +387 -0
  348. data/vendor/spidermonkey/jsscope.c +1957 -0
  349. data/vendor/spidermonkey/jsscope.h +418 -0
  350. data/vendor/spidermonkey/jsscript.c +1832 -0
  351. data/vendor/spidermonkey/jsscript.h +287 -0
  352. data/vendor/spidermonkey/jsshell.msg +50 -0
  353. data/vendor/spidermonkey/jsstddef.h +83 -0
  354. data/vendor/spidermonkey/jsstr.c +5005 -0
  355. data/vendor/spidermonkey/jsstr.h +641 -0
  356. data/vendor/spidermonkey/jstypes.h +475 -0
  357. data/vendor/spidermonkey/jsutil.c +345 -0
  358. data/vendor/spidermonkey/jsutil.h +157 -0
  359. data/vendor/spidermonkey/jsxdrapi.c +800 -0
  360. data/vendor/spidermonkey/jsxdrapi.h +218 -0
  361. data/vendor/spidermonkey/jsxml.c +8476 -0
  362. data/vendor/spidermonkey/jsxml.h +349 -0
  363. data/vendor/spidermonkey/lock_SunOS.s +119 -0
  364. data/vendor/spidermonkey/perfect.js +39 -0
  365. data/vendor/spidermonkey/plify_jsdhash.sed +36 -0
  366. data/vendor/spidermonkey/prmjtime.c +846 -0
  367. data/vendor/spidermonkey/prmjtime.h +103 -0
  368. data/vendor/spidermonkey/resource.h +15 -0
  369. data/vendor/spidermonkey/rules.mk +197 -0
  370. data/vendor/spidermonkey/win32.order +384 -0
  371. metadata +513 -0
@@ -0,0 +1,1369 @@
1
+ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
+ *
3
+ * ***** BEGIN LICENSE BLOCK *****
4
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
+ *
6
+ * The contents of this file are subject to the Mozilla Public License Version
7
+ * 1.1 (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ * http://www.mozilla.org/MPL/
10
+ *
11
+ * Software distributed under the License is distributed on an "AS IS" basis,
12
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
+ * for the specific language governing rights and limitations under the
14
+ * License.
15
+ *
16
+ * The Original Code is Mozilla Communicator client code, released
17
+ * March 31, 1998.
18
+ *
19
+ * The Initial Developer of the Original Code is
20
+ * Simmule Turner and Rich Salz.
21
+ * Portions created by the Initial Developer are Copyright (C) 1998
22
+ * the Initial Developer. All Rights Reserved.
23
+ *
24
+ * Contributor(s):
25
+ *
26
+ * Alternatively, the contents of this file may be used under the terms of
27
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
28
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
+ * in which case the provisions of the GPL or the LGPL are applicable instead
30
+ * of those above. If you wish to allow use of your version of this file only
31
+ * under the terms of either the GPL or the LGPL, and not to allow others to
32
+ * use your version of this file under the terms of the MPL, indicate your
33
+ * decision by deleting the provisions above and replace them with the notice
34
+ * and other provisions required by the GPL or the LGPL. If you do not delete
35
+ * the provisions above, a recipient may use your version of this file under
36
+ * the terms of any one of the MPL, the GPL or the LGPL.
37
+ *
38
+ * ***** END LICENSE BLOCK ***** */
39
+
40
+ /*
41
+ * Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved.
42
+ *
43
+ * This software is not subject to any license of the American Telephone
44
+ * and Telegraph Company or of the Regents of the University of California.
45
+ *
46
+ * Permission is granted to anyone to use this software for any purpose on
47
+ * any computer system, and to alter it and redistribute it freely, subject
48
+ * to the following restrictions:
49
+ * 1. The authors are not responsible for the consequences of use of this
50
+ * software, no matter how awful, even if they arise from flaws in it.
51
+ * 2. The origin of this software must not be misrepresented, either by
52
+ * explicit claim or by omission. Since few users ever read sources,
53
+ * credits must appear in the documentation.
54
+ * 3. Altered versions must be plainly marked as such, and must not be
55
+ * misrepresented as being the original software. Since few users
56
+ * ever read sources, credits must appear in the documentation.
57
+ * 4. This notice may not be removed or altered.
58
+ */
59
+
60
+
61
+ /*
62
+ ** Main editing routines for editline library.
63
+ */
64
+ #include "editline.h"
65
+ #include <signal.h>
66
+ #include <ctype.h>
67
+
68
+ /*
69
+ ** Manifest constants.
70
+ */
71
+ #define SCREEN_WIDTH 80
72
+ #define SCREEN_ROWS 24
73
+ #define NO_ARG (-1)
74
+ #define DEL 127
75
+ #define CTL(x) ((x) & 0x1F)
76
+ #define ISCTL(x) ((x) && (x) < ' ')
77
+ #define UNCTL(x) ((x) + 64)
78
+ #define META(x) ((x) | 0x80)
79
+ #define ISMETA(x) ((x) & 0x80)
80
+ #define UNMETA(x) ((x) & 0x7F)
81
+ #if !defined(HIST_SIZE)
82
+ #define HIST_SIZE 20
83
+ #endif /* !defined(HIST_SIZE) */
84
+
85
+ /*
86
+ ** Command status codes.
87
+ */
88
+ typedef enum _STATUS {
89
+ CSdone, CSeof, CSmove, CSdispatch, CSstay, CSsignal
90
+ } STATUS;
91
+
92
+ /*
93
+ ** The type of case-changing to perform.
94
+ */
95
+ typedef enum _CASE {
96
+ TOupper, TOlower
97
+ } CASE;
98
+
99
+ /*
100
+ ** Key to command mapping.
101
+ */
102
+ typedef struct _KEYMAP {
103
+ CHAR Key;
104
+ STATUS (*Function)();
105
+ } KEYMAP;
106
+
107
+ /*
108
+ ** Command history structure.
109
+ */
110
+ typedef struct _HISTORY {
111
+ int Size;
112
+ int Pos;
113
+ CHAR *Lines[HIST_SIZE];
114
+ } HISTORY;
115
+
116
+ /*
117
+ ** Globals.
118
+ */
119
+ int rl_eof;
120
+ int rl_erase;
121
+ int rl_intr;
122
+ int rl_kill;
123
+ int rl_quit;
124
+
125
+ STATIC CHAR NIL[] = "";
126
+ STATIC CONST CHAR *Input = NIL;
127
+ STATIC CHAR *Line;
128
+ STATIC CONST char *Prompt;
129
+ STATIC CHAR *Yanked;
130
+ STATIC char *Screen;
131
+ STATIC char NEWLINE[]= CRLF;
132
+ STATIC HISTORY H;
133
+ STATIC int Repeat;
134
+ STATIC int End;
135
+ STATIC int Mark;
136
+ STATIC int OldPoint;
137
+ STATIC int Point;
138
+ STATIC int PushBack;
139
+ STATIC int Pushed;
140
+ STATIC int Signal;
141
+ FORWARD KEYMAP Map[32];
142
+ FORWARD KEYMAP MetaMap[16];
143
+ STATIC SIZE_T Length;
144
+ STATIC SIZE_T ScreenCount;
145
+ STATIC SIZE_T ScreenSize;
146
+ STATIC char *backspace;
147
+ STATIC int TTYwidth;
148
+ STATIC int TTYrows;
149
+
150
+ /* Display print 8-bit chars as `M-x' or as the actual 8-bit char? */
151
+ int rl_meta_chars = 0;
152
+
153
+ /*
154
+ ** Declarations.
155
+ */
156
+ STATIC CHAR *editinput();
157
+ extern int read();
158
+ extern int write();
159
+ #if defined(USE_TERMCAP)
160
+ extern char *getenv();
161
+ extern char *tgetstr();
162
+ extern int tgetent();
163
+ #endif /* defined(USE_TERMCAP) */
164
+
165
+ /*
166
+ ** TTY input/output functions.
167
+ */
168
+
169
+ STATIC void
170
+ TTYflush()
171
+ {
172
+ if (ScreenCount) {
173
+ (void)write(1, Screen, ScreenCount);
174
+ ScreenCount = 0;
175
+ }
176
+ }
177
+
178
+ STATIC void
179
+ TTYput(c)
180
+ CHAR c;
181
+ {
182
+ Screen[ScreenCount] = c;
183
+ if (++ScreenCount >= ScreenSize - 1) {
184
+ ScreenSize += SCREEN_INC;
185
+ RENEW(Screen, char, ScreenSize);
186
+ }
187
+ }
188
+
189
+ STATIC void
190
+ TTYputs(p)
191
+ CHAR *p;
192
+ {
193
+ while (*p)
194
+ TTYput(*p++);
195
+ }
196
+
197
+ STATIC void
198
+ TTYshow(c)
199
+ CHAR c;
200
+ {
201
+ if (c == DEL) {
202
+ TTYput('^');
203
+ TTYput('?');
204
+ }
205
+ else if (ISCTL(c)) {
206
+ TTYput('^');
207
+ TTYput(UNCTL(c));
208
+ }
209
+ else if (rl_meta_chars && ISMETA(c)) {
210
+ TTYput('M');
211
+ TTYput('-');
212
+ TTYput(UNMETA(c));
213
+ }
214
+ else
215
+ TTYput(c);
216
+ }
217
+
218
+ STATIC void
219
+ TTYstring(p)
220
+ CHAR *p;
221
+ {
222
+ while (*p)
223
+ TTYshow(*p++);
224
+ }
225
+
226
+ STATIC unsigned int
227
+ TTYget()
228
+ {
229
+ CHAR c;
230
+
231
+ TTYflush();
232
+ if (Pushed) {
233
+ Pushed = 0;
234
+ return PushBack;
235
+ }
236
+ if (*Input)
237
+ return *Input++;
238
+ return read(0, &c, (SIZE_T)1) == 1 ? c : EOF;
239
+ }
240
+
241
+ #define TTYback() (backspace ? TTYputs((CHAR *)backspace) : TTYput('\b'))
242
+
243
+ STATIC void
244
+ TTYbackn(n)
245
+ int n;
246
+ {
247
+ while (--n >= 0)
248
+ TTYback();
249
+ }
250
+
251
+ STATIC void
252
+ TTYinfo()
253
+ {
254
+ static int init;
255
+ #if defined(USE_TERMCAP)
256
+ char *term;
257
+ char buff[2048];
258
+ char *bp, *p;
259
+ #endif /* defined(USE_TERMCAP) */
260
+ #if defined(TIOCGWINSZ)
261
+ struct winsize W;
262
+ #endif /* defined(TIOCGWINSZ) */
263
+
264
+ if (init) {
265
+ #if defined(TIOCGWINSZ)
266
+ /* Perhaps we got resized. */
267
+ if (ioctl(0, TIOCGWINSZ, &W) >= 0
268
+ && W.ws_col > 0 && W.ws_row > 0) {
269
+ TTYwidth = (int)W.ws_col;
270
+ TTYrows = (int)W.ws_row;
271
+ }
272
+ #endif /* defined(TIOCGWINSZ) */
273
+ return;
274
+ }
275
+ init++;
276
+
277
+ TTYwidth = TTYrows = 0;
278
+ #if defined(USE_TERMCAP)
279
+ bp = &buff[0];
280
+ if ((term = getenv("TERM")) == NULL)
281
+ term = "dumb";
282
+ if (tgetent(buff, term) < 0) {
283
+ TTYwidth = SCREEN_WIDTH;
284
+ TTYrows = SCREEN_ROWS;
285
+ return;
286
+ }
287
+ p = tgetstr("le", &bp);
288
+ backspace = p ? strdup(p) : NULL;
289
+ TTYwidth = tgetnum("co");
290
+ TTYrows = tgetnum("li");
291
+ #endif /* defined(USE_TERMCAP) */
292
+
293
+ #if defined(TIOCGWINSZ)
294
+ if (ioctl(0, TIOCGWINSZ, &W) >= 0) {
295
+ TTYwidth = (int)W.ws_col;
296
+ TTYrows = (int)W.ws_row;
297
+ }
298
+ #endif /* defined(TIOCGWINSZ) */
299
+
300
+ if (TTYwidth <= 0 || TTYrows <= 0) {
301
+ TTYwidth = SCREEN_WIDTH;
302
+ TTYrows = SCREEN_ROWS;
303
+ }
304
+ }
305
+
306
+
307
+ STATIC void
308
+ reposition()
309
+ {
310
+ int i;
311
+ CHAR *p;
312
+
313
+ TTYput('\r');
314
+ TTYputs((CONST CHAR *)Prompt);
315
+ for (i = Point, p = Line; --i >= 0; p++)
316
+ TTYshow(*p);
317
+ }
318
+
319
+ STATIC void
320
+ left(Change)
321
+ STATUS Change;
322
+ {
323
+ TTYback();
324
+ if (Point) {
325
+ if (ISCTL(Line[Point - 1]))
326
+ TTYback();
327
+ else if (rl_meta_chars && ISMETA(Line[Point - 1])) {
328
+ TTYback();
329
+ TTYback();
330
+ }
331
+ }
332
+ if (Change == CSmove)
333
+ Point--;
334
+ }
335
+
336
+ STATIC void
337
+ right(Change)
338
+ STATUS Change;
339
+ {
340
+ TTYshow(Line[Point]);
341
+ if (Change == CSmove)
342
+ Point++;
343
+ }
344
+
345
+ STATIC STATUS
346
+ ring_bell()
347
+ {
348
+ TTYput('\07');
349
+ TTYflush();
350
+ return CSstay;
351
+ }
352
+
353
+ STATIC STATUS
354
+ do_macro(c)
355
+ unsigned int c;
356
+ {
357
+ CHAR name[4];
358
+
359
+ name[0] = '_';
360
+ name[1] = c;
361
+ name[2] = '_';
362
+ name[3] = '\0';
363
+
364
+ if ((Input = (CHAR *)getenv((char *)name)) == NULL) {
365
+ Input = NIL;
366
+ return ring_bell();
367
+ }
368
+ return CSstay;
369
+ }
370
+
371
+ STATIC STATUS
372
+ do_forward(move)
373
+ STATUS move;
374
+ {
375
+ int i;
376
+ CHAR *p;
377
+
378
+ i = 0;
379
+ do {
380
+ p = &Line[Point];
381
+ for ( ; Point < End && (*p == ' ' || !isalnum(*p)); Point++, p++)
382
+ if (move == CSmove)
383
+ right(CSstay);
384
+
385
+ for (; Point < End && isalnum(*p); Point++, p++)
386
+ if (move == CSmove)
387
+ right(CSstay);
388
+
389
+ if (Point == End)
390
+ break;
391
+ } while (++i < Repeat);
392
+
393
+ return CSstay;
394
+ }
395
+
396
+ STATIC STATUS
397
+ do_case(type)
398
+ CASE type;
399
+ {
400
+ int i;
401
+ int end;
402
+ int count;
403
+ CHAR *p;
404
+
405
+ (void)do_forward(CSstay);
406
+ if (OldPoint != Point) {
407
+ if ((count = Point - OldPoint) < 0)
408
+ count = -count;
409
+ Point = OldPoint;
410
+ if ((end = Point + count) > End)
411
+ end = End;
412
+ for (i = Point, p = &Line[i]; i < end; i++, p++) {
413
+ if (type == TOupper) {
414
+ if (islower(*p))
415
+ *p = toupper(*p);
416
+ }
417
+ else if (isupper(*p))
418
+ *p = tolower(*p);
419
+ right(CSmove);
420
+ }
421
+ }
422
+ return CSstay;
423
+ }
424
+
425
+ STATIC STATUS
426
+ case_down_word()
427
+ {
428
+ return do_case(TOlower);
429
+ }
430
+
431
+ STATIC STATUS
432
+ case_up_word()
433
+ {
434
+ return do_case(TOupper);
435
+ }
436
+
437
+ STATIC void
438
+ ceol()
439
+ {
440
+ int extras;
441
+ int i;
442
+ CHAR *p;
443
+
444
+ for (extras = 0, i = Point, p = &Line[i]; i <= End; i++, p++) {
445
+ TTYput(' ');
446
+ if (ISCTL(*p)) {
447
+ TTYput(' ');
448
+ extras++;
449
+ }
450
+ else if (rl_meta_chars && ISMETA(*p)) {
451
+ TTYput(' ');
452
+ TTYput(' ');
453
+ extras += 2;
454
+ }
455
+ }
456
+
457
+ for (i += extras; i > Point; i--)
458
+ TTYback();
459
+ }
460
+
461
+ STATIC void
462
+ clear_line()
463
+ {
464
+ Point = -strlen(Prompt);
465
+ TTYput('\r');
466
+ ceol();
467
+ Point = 0;
468
+ End = 0;
469
+ Line[0] = '\0';
470
+ }
471
+
472
+ STATIC STATUS
473
+ insert_string(p)
474
+ CHAR *p;
475
+ {
476
+ SIZE_T len;
477
+ int i;
478
+ CHAR *new;
479
+ CHAR *q;
480
+
481
+ len = strlen((char *)p);
482
+ if (End + len >= Length) {
483
+ if ((new = NEW(CHAR, Length + len + MEM_INC)) == NULL)
484
+ return CSstay;
485
+ if (Length) {
486
+ COPYFROMTO(new, Line, Length);
487
+ DISPOSE(Line);
488
+ }
489
+ Line = new;
490
+ Length += len + MEM_INC;
491
+ }
492
+
493
+ for (q = &Line[Point], i = End - Point; --i >= 0; )
494
+ q[len + i] = q[i];
495
+ COPYFROMTO(&Line[Point], p, len);
496
+ End += len;
497
+ Line[End] = '\0';
498
+ TTYstring(&Line[Point]);
499
+ Point += len;
500
+
501
+ return Point == End ? CSstay : CSmove;
502
+ }
503
+
504
+ STATIC STATUS
505
+ redisplay()
506
+ {
507
+ TTYputs((CONST CHAR *)NEWLINE);
508
+ TTYputs((CONST CHAR *)Prompt);
509
+ TTYstring(Line);
510
+ return CSmove;
511
+ }
512
+
513
+ STATIC STATUS
514
+ toggle_meta_mode()
515
+ {
516
+ rl_meta_chars = ! rl_meta_chars;
517
+ return redisplay();
518
+ }
519
+
520
+
521
+ STATIC CHAR *
522
+ next_hist()
523
+ {
524
+ return H.Pos >= H.Size - 1 ? NULL : H.Lines[++H.Pos];
525
+ }
526
+
527
+ STATIC CHAR *
528
+ prev_hist()
529
+ {
530
+ return H.Pos == 0 ? NULL : H.Lines[--H.Pos];
531
+ }
532
+
533
+ STATIC STATUS
534
+ do_insert_hist(p)
535
+ CHAR *p;
536
+ {
537
+ if (p == NULL)
538
+ return ring_bell();
539
+ Point = 0;
540
+ reposition();
541
+ ceol();
542
+ End = 0;
543
+ return insert_string(p);
544
+ }
545
+
546
+ STATIC STATUS
547
+ do_hist(move)
548
+ CHAR *(*move)();
549
+ {
550
+ CHAR *p;
551
+ int i;
552
+
553
+ i = 0;
554
+ do {
555
+ if ((p = (*move)()) == NULL)
556
+ return ring_bell();
557
+ } while (++i < Repeat);
558
+ return do_insert_hist(p);
559
+ }
560
+
561
+ STATIC STATUS
562
+ h_next()
563
+ {
564
+ return do_hist(next_hist);
565
+ }
566
+
567
+ STATIC STATUS
568
+ h_prev()
569
+ {
570
+ return do_hist(prev_hist);
571
+ }
572
+
573
+ STATIC STATUS
574
+ h_first()
575
+ {
576
+ return do_insert_hist(H.Lines[H.Pos = 0]);
577
+ }
578
+
579
+ STATIC STATUS
580
+ h_last()
581
+ {
582
+ return do_insert_hist(H.Lines[H.Pos = H.Size - 1]);
583
+ }
584
+
585
+ /*
586
+ ** Return zero if pat appears as a substring in text.
587
+ */
588
+ STATIC int
589
+ substrcmp(text, pat, len)
590
+ char *text;
591
+ char *pat;
592
+ int len;
593
+ {
594
+ char c;
595
+
596
+ if ((c = *pat) == '\0')
597
+ return *text == '\0';
598
+ for ( ; *text; text++)
599
+ if (*text == c && strncmp(text, pat, len) == 0)
600
+ return 0;
601
+ return 1;
602
+ }
603
+
604
+ STATIC CHAR *
605
+ search_hist(search, move)
606
+ CHAR *search;
607
+ CHAR *(*move)();
608
+ {
609
+ static CHAR *old_search;
610
+ int len;
611
+ int pos;
612
+ int (*match)();
613
+ char *pat;
614
+
615
+ /* Save or get remembered search pattern. */
616
+ if (search && *search) {
617
+ if (old_search)
618
+ DISPOSE(old_search);
619
+ old_search = (CHAR *)strdup((char *)search);
620
+ }
621
+ else {
622
+ if (old_search == NULL || *old_search == '\0')
623
+ return NULL;
624
+ search = old_search;
625
+ }
626
+
627
+ /* Set up pattern-finder. */
628
+ if (*search == '^') {
629
+ match = strncmp;
630
+ pat = (char *)(search + 1);
631
+ }
632
+ else {
633
+ match = substrcmp;
634
+ pat = (char *)search;
635
+ }
636
+ len = strlen(pat);
637
+
638
+ for (pos = H.Pos; (*move)() != NULL; )
639
+ if ((*match)((char *)H.Lines[H.Pos], pat, len) == 0)
640
+ return H.Lines[H.Pos];
641
+ H.Pos = pos;
642
+ return NULL;
643
+ }
644
+
645
+ STATIC STATUS
646
+ h_search()
647
+ {
648
+ static int Searching;
649
+ CONST char *old_prompt;
650
+ CHAR *(*move)();
651
+ CHAR *p;
652
+
653
+ if (Searching)
654
+ return ring_bell();
655
+ Searching = 1;
656
+
657
+ clear_line();
658
+ old_prompt = Prompt;
659
+ Prompt = "Search: ";
660
+ TTYputs((CONST CHAR *)Prompt);
661
+ move = Repeat == NO_ARG ? prev_hist : next_hist;
662
+ p = editinput();
663
+ Prompt = old_prompt;
664
+ Searching = 0;
665
+ TTYputs((CONST CHAR *)Prompt);
666
+ if (p == NULL && Signal > 0) {
667
+ Signal = 0;
668
+ clear_line();
669
+ return redisplay();
670
+ }
671
+ p = search_hist(p, move);
672
+ clear_line();
673
+ if (p == NULL) {
674
+ (void)ring_bell();
675
+ return redisplay();
676
+ }
677
+ return do_insert_hist(p);
678
+ }
679
+
680
+ STATIC STATUS
681
+ fd_char()
682
+ {
683
+ int i;
684
+
685
+ i = 0;
686
+ do {
687
+ if (Point >= End)
688
+ break;
689
+ right(CSmove);
690
+ } while (++i < Repeat);
691
+ return CSstay;
692
+ }
693
+
694
+ STATIC void
695
+ save_yank(begin, i)
696
+ int begin;
697
+ int i;
698
+ {
699
+ if (Yanked) {
700
+ DISPOSE(Yanked);
701
+ Yanked = NULL;
702
+ }
703
+
704
+ if (i < 1)
705
+ return;
706
+
707
+ if ((Yanked = NEW(CHAR, (SIZE_T)i + 1)) != NULL) {
708
+ COPYFROMTO(Yanked, &Line[begin], i);
709
+ Yanked[i] = '\0';
710
+ }
711
+ }
712
+
713
+ STATIC STATUS
714
+ delete_string(count)
715
+ int count;
716
+ {
717
+ int i;
718
+ CHAR *p;
719
+
720
+ if (count <= 0 || End == Point)
721
+ return ring_bell();
722
+
723
+ if (count == 1 && Point == End - 1) {
724
+ /* Optimize common case of delete at end of line. */
725
+ End--;
726
+ p = &Line[Point];
727
+ i = 1;
728
+ TTYput(' ');
729
+ if (ISCTL(*p)) {
730
+ i = 2;
731
+ TTYput(' ');
732
+ }
733
+ else if (rl_meta_chars && ISMETA(*p)) {
734
+ i = 3;
735
+ TTYput(' ');
736
+ TTYput(' ');
737
+ }
738
+ TTYbackn(i);
739
+ *p = '\0';
740
+ return CSmove;
741
+ }
742
+ if (Point + count > End && (count = End - Point) <= 0)
743
+ return CSstay;
744
+
745
+ if (count > 1)
746
+ save_yank(Point, count);
747
+
748
+ for (p = &Line[Point], i = End - (Point + count) + 1; --i >= 0; p++)
749
+ p[0] = p[count];
750
+ ceol();
751
+ End -= count;
752
+ TTYstring(&Line[Point]);
753
+ return CSmove;
754
+ }
755
+
756
+ STATIC STATUS
757
+ bk_char()
758
+ {
759
+ int i;
760
+
761
+ i = 0;
762
+ do {
763
+ if (Point == 0)
764
+ break;
765
+ left(CSmove);
766
+ } while (++i < Repeat);
767
+
768
+ return CSstay;
769
+ }
770
+
771
+ STATIC STATUS
772
+ bk_del_char()
773
+ {
774
+ int i;
775
+
776
+ i = 0;
777
+ do {
778
+ if (Point == 0)
779
+ break;
780
+ left(CSmove);
781
+ } while (++i < Repeat);
782
+
783
+ return delete_string(i);
784
+ }
785
+
786
+ STATIC STATUS
787
+ kill_line()
788
+ {
789
+ int i;
790
+
791
+ if (Repeat != NO_ARG) {
792
+ if (Repeat < Point) {
793
+ i = Point;
794
+ Point = Repeat;
795
+ reposition();
796
+ (void)delete_string(i - Point);
797
+ }
798
+ else if (Repeat > Point) {
799
+ right(CSmove);
800
+ (void)delete_string(Repeat - Point - 1);
801
+ }
802
+ return CSmove;
803
+ }
804
+
805
+ save_yank(Point, End - Point);
806
+ Line[Point] = '\0';
807
+ ceol();
808
+ End = Point;
809
+ return CSstay;
810
+ }
811
+
812
+ STATIC STATUS
813
+ insert_char(c)
814
+ int c;
815
+ {
816
+ STATUS s;
817
+ CHAR buff[2];
818
+ CHAR *p;
819
+ CHAR *q;
820
+ int i;
821
+
822
+ if (Repeat == NO_ARG || Repeat < 2) {
823
+ buff[0] = c;
824
+ buff[1] = '\0';
825
+ return insert_string(buff);
826
+ }
827
+
828
+ if ((p = NEW(CHAR, Repeat + 1)) == NULL)
829
+ return CSstay;
830
+ for (i = Repeat, q = p; --i >= 0; )
831
+ *q++ = c;
832
+ *q = '\0';
833
+ Repeat = 0;
834
+ s = insert_string(p);
835
+ DISPOSE(p);
836
+ return s;
837
+ }
838
+
839
+ STATIC STATUS
840
+ meta()
841
+ {
842
+ unsigned int c;
843
+ KEYMAP *kp;
844
+
845
+ if ((c = TTYget()) == EOF)
846
+ return CSeof;
847
+ #if defined(ANSI_ARROWS)
848
+ /* Also include VT-100 arrows. */
849
+ if (c == '[' || c == 'O')
850
+ switch (c = TTYget()) {
851
+ default: return ring_bell();
852
+ case EOF: return CSeof;
853
+ case 'A': return h_prev();
854
+ case 'B': return h_next();
855
+ case 'C': return fd_char();
856
+ case 'D': return bk_char();
857
+ }
858
+ #endif /* defined(ANSI_ARROWS) */
859
+
860
+ if (isdigit(c)) {
861
+ for (Repeat = c - '0'; (c = TTYget()) != EOF && isdigit(c); )
862
+ Repeat = Repeat * 10 + c - '0';
863
+ Pushed = 1;
864
+ PushBack = c;
865
+ return CSstay;
866
+ }
867
+
868
+ if (isupper(c))
869
+ return do_macro(c);
870
+ for (OldPoint = Point, kp = MetaMap; kp->Function; kp++)
871
+ if (kp->Key == c)
872
+ return (*kp->Function)();
873
+
874
+ return ring_bell();
875
+ }
876
+
877
+ STATIC STATUS
878
+ emacs(c)
879
+ unsigned int c;
880
+ {
881
+ STATUS s;
882
+ KEYMAP *kp;
883
+
884
+ if (rl_meta_chars && ISMETA(c)) {
885
+ Pushed = 1;
886
+ PushBack = UNMETA(c);
887
+ return meta();
888
+ }
889
+ for (kp = Map; kp->Function; kp++)
890
+ if (kp->Key == c)
891
+ break;
892
+ s = kp->Function ? (*kp->Function)() : insert_char((int)c);
893
+ if (!Pushed)
894
+ /* No pushback means no repeat count; hacky, but true. */
895
+ Repeat = NO_ARG;
896
+ return s;
897
+ }
898
+
899
+ STATIC STATUS
900
+ TTYspecial(c)
901
+ unsigned int c;
902
+ {
903
+ if (ISMETA(c))
904
+ return CSdispatch;
905
+
906
+ if (c == rl_erase || c == DEL)
907
+ return bk_del_char();
908
+ if (c == rl_kill) {
909
+ if (Point != 0) {
910
+ Point = 0;
911
+ reposition();
912
+ }
913
+ Repeat = NO_ARG;
914
+ return kill_line();
915
+ }
916
+ if (c == rl_eof && Point == 0 && End == 0)
917
+ return CSeof;
918
+ if (c == rl_intr) {
919
+ Signal = SIGINT;
920
+ return CSsignal;
921
+ }
922
+ if (c == rl_quit) {
923
+ Signal = SIGQUIT;
924
+ return CSeof;
925
+ }
926
+
927
+ return CSdispatch;
928
+ }
929
+
930
+ STATIC CHAR *
931
+ editinput()
932
+ {
933
+ unsigned int c;
934
+
935
+ Repeat = NO_ARG;
936
+ OldPoint = Point = Mark = End = 0;
937
+ Line[0] = '\0';
938
+
939
+ Signal = -1;
940
+ while ((c = TTYget()) != EOF)
941
+ switch (TTYspecial(c)) {
942
+ case CSdone:
943
+ return Line;
944
+ case CSeof:
945
+ return NULL;
946
+ case CSsignal:
947
+ return (CHAR *)"";
948
+ case CSmove:
949
+ reposition();
950
+ break;
951
+ case CSdispatch:
952
+ switch (emacs(c)) {
953
+ case CSdone:
954
+ return Line;
955
+ case CSeof:
956
+ return NULL;
957
+ case CSsignal:
958
+ return (CHAR *)"";
959
+ case CSmove:
960
+ reposition();
961
+ break;
962
+ case CSdispatch:
963
+ case CSstay:
964
+ break;
965
+ }
966
+ break;
967
+ case CSstay:
968
+ break;
969
+ }
970
+ return NULL;
971
+ }
972
+
973
+ STATIC void
974
+ hist_add(p)
975
+ CHAR *p;
976
+ {
977
+ int i;
978
+
979
+ if ((p = (CHAR *)strdup((char *)p)) == NULL)
980
+ return;
981
+ if (H.Size < HIST_SIZE)
982
+ H.Lines[H.Size++] = p;
983
+ else {
984
+ DISPOSE(H.Lines[0]);
985
+ for (i = 0; i < HIST_SIZE - 1; i++)
986
+ H.Lines[i] = H.Lines[i + 1];
987
+ H.Lines[i] = p;
988
+ }
989
+ H.Pos = H.Size - 1;
990
+ }
991
+
992
+ /*
993
+ ** For compatibility with FSF readline.
994
+ */
995
+ /* ARGSUSED0 */
996
+ void
997
+ rl_reset_terminal(p)
998
+ char *p;
999
+ {
1000
+ }
1001
+
1002
+ void
1003
+ rl_initialize()
1004
+ {
1005
+ }
1006
+
1007
+ char *
1008
+ readline(prompt)
1009
+ CONST char *prompt;
1010
+ {
1011
+ CHAR *line;
1012
+ int s;
1013
+
1014
+ if (Line == NULL) {
1015
+ Length = MEM_INC;
1016
+ if ((Line = NEW(CHAR, Length)) == NULL)
1017
+ return NULL;
1018
+ }
1019
+
1020
+ TTYinfo();
1021
+ rl_ttyset(0);
1022
+ hist_add(NIL);
1023
+ ScreenSize = SCREEN_INC;
1024
+ Screen = NEW(char, ScreenSize);
1025
+ Prompt = prompt ? prompt : (char *)NIL;
1026
+ TTYputs((CONST CHAR *)Prompt);
1027
+ if ((line = editinput()) != NULL) {
1028
+ line = (CHAR *)strdup((char *)line);
1029
+ TTYputs((CHAR *)NEWLINE);
1030
+ TTYflush();
1031
+ }
1032
+ rl_ttyset(1);
1033
+ DISPOSE(Screen);
1034
+ DISPOSE(H.Lines[--H.Size]);
1035
+ if (Signal > 0) {
1036
+ s = Signal;
1037
+ Signal = 0;
1038
+ (void)kill(getpid(), s);
1039
+ }
1040
+ return (char *)line;
1041
+ }
1042
+
1043
+ void
1044
+ add_history(p)
1045
+ char *p;
1046
+ {
1047
+ if (p == NULL || *p == '\0')
1048
+ return;
1049
+
1050
+ #if defined(UNIQUE_HISTORY)
1051
+ if (H.Size && strcmp(p, H.Lines[H.Size - 1]) == 0)
1052
+ return;
1053
+ #endif /* defined(UNIQUE_HISTORY) */
1054
+ hist_add((CHAR *)p);
1055
+ }
1056
+
1057
+
1058
+ STATIC STATUS
1059
+ beg_line()
1060
+ {
1061
+ if (Point) {
1062
+ Point = 0;
1063
+ return CSmove;
1064
+ }
1065
+ return CSstay;
1066
+ }
1067
+
1068
+ STATIC STATUS
1069
+ del_char()
1070
+ {
1071
+ return delete_string(Repeat == NO_ARG ? 1 : Repeat);
1072
+ }
1073
+
1074
+ STATIC STATUS
1075
+ end_line()
1076
+ {
1077
+ if (Point != End) {
1078
+ Point = End;
1079
+ return CSmove;
1080
+ }
1081
+ return CSstay;
1082
+ }
1083
+
1084
+ STATIC STATUS
1085
+ accept_line()
1086
+ {
1087
+ Line[End] = '\0';
1088
+ return CSdone;
1089
+ }
1090
+
1091
+ STATIC STATUS
1092
+ transpose()
1093
+ {
1094
+ CHAR c;
1095
+
1096
+ if (Point) {
1097
+ if (Point == End)
1098
+ left(CSmove);
1099
+ c = Line[Point - 1];
1100
+ left(CSstay);
1101
+ Line[Point - 1] = Line[Point];
1102
+ TTYshow(Line[Point - 1]);
1103
+ Line[Point++] = c;
1104
+ TTYshow(c);
1105
+ }
1106
+ return CSstay;
1107
+ }
1108
+
1109
+ STATIC STATUS
1110
+ quote()
1111
+ {
1112
+ unsigned int c;
1113
+
1114
+ return (c = TTYget()) == EOF ? CSeof : insert_char((int)c);
1115
+ }
1116
+
1117
+ STATIC STATUS
1118
+ wipe()
1119
+ {
1120
+ int i;
1121
+
1122
+ if (Mark > End)
1123
+ return ring_bell();
1124
+
1125
+ if (Point > Mark) {
1126
+ i = Point;
1127
+ Point = Mark;
1128
+ Mark = i;
1129
+ reposition();
1130
+ }
1131
+
1132
+ return delete_string(Mark - Point);
1133
+ }
1134
+
1135
+ STATIC STATUS
1136
+ mk_set()
1137
+ {
1138
+ Mark = Point;
1139
+ return CSstay;
1140
+ }
1141
+
1142
+ STATIC STATUS
1143
+ exchange()
1144
+ {
1145
+ unsigned int c;
1146
+
1147
+ if ((c = TTYget()) != CTL('X'))
1148
+ return c == EOF ? CSeof : ring_bell();
1149
+
1150
+ if ((c = Mark) <= End) {
1151
+ Mark = Point;
1152
+ Point = c;
1153
+ return CSmove;
1154
+ }
1155
+ return CSstay;
1156
+ }
1157
+
1158
+ STATIC STATUS
1159
+ yank()
1160
+ {
1161
+ if (Yanked && *Yanked)
1162
+ return insert_string(Yanked);
1163
+ return CSstay;
1164
+ }
1165
+
1166
+ STATIC STATUS
1167
+ copy_region()
1168
+ {
1169
+ if (Mark > End)
1170
+ return ring_bell();
1171
+
1172
+ if (Point > Mark)
1173
+ save_yank(Mark, Point - Mark);
1174
+ else
1175
+ save_yank(Point, Mark - Point);
1176
+
1177
+ return CSstay;
1178
+ }
1179
+
1180
+ STATIC STATUS
1181
+ move_to_char()
1182
+ {
1183
+ unsigned int c;
1184
+ int i;
1185
+ CHAR *p;
1186
+
1187
+ if ((c = TTYget()) == EOF)
1188
+ return CSeof;
1189
+ for (i = Point + 1, p = &Line[i]; i < End; i++, p++)
1190
+ if (*p == c) {
1191
+ Point = i;
1192
+ return CSmove;
1193
+ }
1194
+ return CSstay;
1195
+ }
1196
+
1197
+ STATIC STATUS
1198
+ fd_word()
1199
+ {
1200
+ return do_forward(CSmove);
1201
+ }
1202
+
1203
+ STATIC STATUS
1204
+ fd_kill_word()
1205
+ {
1206
+ int i;
1207
+
1208
+ (void)do_forward(CSstay);
1209
+ if (OldPoint != Point) {
1210
+ i = Point - OldPoint;
1211
+ Point = OldPoint;
1212
+ return delete_string(i);
1213
+ }
1214
+ return CSstay;
1215
+ }
1216
+
1217
+ STATIC STATUS
1218
+ bk_word()
1219
+ {
1220
+ int i;
1221
+ CHAR *p;
1222
+
1223
+ i = 0;
1224
+ do {
1225
+ for (p = &Line[Point]; p > Line && !isalnum(p[-1]); p--)
1226
+ left(CSmove);
1227
+
1228
+ for (; p > Line && p[-1] != ' ' && isalnum(p[-1]); p--)
1229
+ left(CSmove);
1230
+
1231
+ if (Point == 0)
1232
+ break;
1233
+ } while (++i < Repeat);
1234
+
1235
+ return CSstay;
1236
+ }
1237
+
1238
+ STATIC STATUS
1239
+ bk_kill_word()
1240
+ {
1241
+ (void)bk_word();
1242
+ if (OldPoint != Point)
1243
+ return delete_string(OldPoint - Point);
1244
+ return CSstay;
1245
+ }
1246
+
1247
+ STATIC int
1248
+ argify(line, avp)
1249
+ CHAR *line;
1250
+ CHAR ***avp;
1251
+ {
1252
+ CHAR *c;
1253
+ CHAR **p;
1254
+ CHAR **new;
1255
+ int ac;
1256
+ int i;
1257
+
1258
+ i = MEM_INC;
1259
+ if ((*avp = p = NEW(CHAR*, i))== NULL)
1260
+ return 0;
1261
+
1262
+ for (c = line; isspace(*c); c++)
1263
+ continue;
1264
+ if (*c == '\n' || *c == '\0')
1265
+ return 0;
1266
+
1267
+ for (ac = 0, p[ac++] = c; *c && *c != '\n'; ) {
1268
+ if (isspace(*c)) {
1269
+ *c++ = '\0';
1270
+ if (*c && *c != '\n') {
1271
+ if (ac + 1 == i) {
1272
+ new = NEW(CHAR*, i + MEM_INC);
1273
+ if (new == NULL) {
1274
+ p[ac] = NULL;
1275
+ return ac;
1276
+ }
1277
+ COPYFROMTO(new, p, i * sizeof (char **));
1278
+ i += MEM_INC;
1279
+ DISPOSE(p);
1280
+ *avp = p = new;
1281
+ }
1282
+ p[ac++] = c;
1283
+ }
1284
+ }
1285
+ else
1286
+ c++;
1287
+ }
1288
+ *c = '\0';
1289
+ p[ac] = NULL;
1290
+ return ac;
1291
+ }
1292
+
1293
+ STATIC STATUS
1294
+ last_argument()
1295
+ {
1296
+ CHAR **av;
1297
+ CHAR *p;
1298
+ STATUS s;
1299
+ int ac;
1300
+
1301
+ if (H.Size == 1 || (p = H.Lines[H.Size - 2]) == NULL)
1302
+ return ring_bell();
1303
+
1304
+ if ((p = (CHAR *)strdup((char *)p)) == NULL)
1305
+ return CSstay;
1306
+ ac = argify(p, &av);
1307
+
1308
+ if (Repeat != NO_ARG)
1309
+ s = Repeat < ac ? insert_string(av[Repeat]) : ring_bell();
1310
+ else
1311
+ s = ac ? insert_string(av[ac - 1]) : CSstay;
1312
+
1313
+ if (ac)
1314
+ DISPOSE(av);
1315
+ DISPOSE(p);
1316
+ return s;
1317
+ }
1318
+
1319
+ STATIC KEYMAP Map[32] = {
1320
+ { CTL('@'), ring_bell },
1321
+ { CTL('A'), beg_line },
1322
+ { CTL('B'), bk_char },
1323
+ { CTL('D'), del_char },
1324
+ { CTL('E'), end_line },
1325
+ { CTL('F'), fd_char },
1326
+ { CTL('G'), ring_bell },
1327
+ { CTL('H'), bk_del_char },
1328
+ { CTL('J'), accept_line },
1329
+ { CTL('K'), kill_line },
1330
+ { CTL('L'), redisplay },
1331
+ { CTL('M'), accept_line },
1332
+ { CTL('N'), h_next },
1333
+ { CTL('O'), ring_bell },
1334
+ { CTL('P'), h_prev },
1335
+ { CTL('Q'), ring_bell },
1336
+ { CTL('R'), h_search },
1337
+ { CTL('S'), ring_bell },
1338
+ { CTL('T'), transpose },
1339
+ { CTL('U'), ring_bell },
1340
+ { CTL('V'), quote },
1341
+ { CTL('W'), wipe },
1342
+ { CTL('X'), exchange },
1343
+ { CTL('Y'), yank },
1344
+ { CTL('Z'), ring_bell },
1345
+ { CTL('['), meta },
1346
+ { CTL(']'), move_to_char },
1347
+ { CTL('^'), ring_bell },
1348
+ { CTL('_'), ring_bell },
1349
+ { 0, NULL }
1350
+ };
1351
+
1352
+ STATIC KEYMAP MetaMap[16]= {
1353
+ { CTL('H'), bk_kill_word },
1354
+ { DEL, bk_kill_word },
1355
+ { ' ', mk_set },
1356
+ { '.', last_argument },
1357
+ { '<', h_first },
1358
+ { '>', h_last },
1359
+ { 'b', bk_word },
1360
+ { 'd', fd_kill_word },
1361
+ { 'f', fd_word },
1362
+ { 'l', case_down_word },
1363
+ { 'm', toggle_meta_mode },
1364
+ { 'u', case_up_word },
1365
+ { 'y', yank },
1366
+ { 'w', copy_region },
1367
+ { 0, NULL }
1368
+ };
1369
+