summaryrefslogtreecommitdiff
path: root/spec/ruby/language/fixtures/constants_sclass.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/language/fixtures/constants_sclass.rb')
0 files changed, 0 insertions, 0 deletions
amp;id2=3c848f79b7eb5ad26b57c4d9edde577cc1ba7026'>NEWS586
-rw-r--r--README6
-rw-r--r--README.EXT5
-rw-r--r--README.EXT.ja6
-rw-r--r--README.ja6
-rw-r--r--array.c1172
-rw-r--r--bcc32/Makefile.sub68
-rwxr-xr-xbcc32/configure.bat92
-rw-r--r--bcc32/setup.mak78
-rw-r--r--bignum.c277
-rw-r--r--class.c47
-rw-r--r--common.mk96
-rw-r--r--configure.in270
-rw-r--r--defines.h25
-rw-r--r--dir.c15
-rw-r--r--dln.c86
-rw-r--r--enum.c1246
-rw-r--r--enumerator.c450
-rw-r--r--error.c31
-rw-r--r--eval.c830
-rw-r--r--ext/Win32API/lib/win32/registry.rb2
-rw-r--r--ext/Win32API/lib/win32/resolv.rb2
-rw-r--r--ext/bigdecimal/bigdecimal.c59
-rw-r--r--ext/bigdecimal/extconf.rb8
-rw-r--r--ext/curses/extconf.rb2
-rw-r--r--ext/dbm/dbm.c2
-rw-r--r--ext/dl/dl.c16
-rw-r--r--ext/dl/ptr.c38
-rw-r--r--ext/dl/sym.c1
-rw-r--r--ext/enumerator/.cvsignore2
-rw-r--r--ext/enumerator/enumerator.c298
-rw-r--r--ext/enumerator/enumerator.txt102
-rw-r--r--ext/enumerator/extconf.rb2
-rw-r--r--ext/etc/etc.c2
-rw-r--r--ext/extmk.rb34
-rw-r--r--ext/iconv/iconv.c59
-rw-r--r--ext/io/wait/wait.c4
-rw-r--r--ext/openssl/extconf.rb5
-rw-r--r--ext/openssl/lib/net/ftptls.rb10
-rw-r--r--ext/openssl/lib/net/telnets.rb3
-rw-r--r--ext/openssl/lib/openssl.rb1
-rw-r--r--ext/openssl/lib/openssl/cipher.rb33
-rw-r--r--ext/openssl/lib/openssl/digest.rb14
-rw-r--r--ext/openssl/lib/openssl/pkcs7.rb25
-rw-r--r--ext/openssl/lib/openssl/ssl.rb90
-rw-r--r--ext/openssl/openssl_missing.c12
-rw-r--r--ext/openssl/openssl_missing.h60
-rw-r--r--ext/openssl/ossl.c32
-rw-r--r--ext/openssl/ossl.h21
-rw-r--r--ext/openssl/ossl_asn1.c60
-rw-r--r--ext/openssl/ossl_bio.c23
-rw-r--r--ext/openssl/ossl_bn.c163
-rw-r--r--ext/openssl/ossl_bn.h5
-rw-r--r--ext/openssl/ossl_cipher.c247
-rw-r--r--ext/openssl/ossl_cipher.h1
-rw-r--r--ext/openssl/ossl_config.c12
-rw-r--r--ext/openssl/ossl_digest.c195
-rw-r--r--ext/openssl/ossl_digest.h1
-rw-r--r--ext/openssl/ossl_engine.c10
-rw-r--r--ext/openssl/ossl_hmac.c68
-rw-r--r--ext/openssl/ossl_ns_spki.c12
-rw-r--r--ext/openssl/ossl_ocsp.c24
-rw-r--r--ext/openssl/ossl_pkcs12.c76
-rw-r--r--ext/openssl/ossl_pkcs12.h1
-rw-r--r--ext/openssl/ossl_pkcs5.c96
-rw-r--r--ext/openssl/ossl_pkcs7.c62
-rw-r--r--ext/openssl/ossl_pkcs7.h1
-rw-r--r--ext/openssl/ossl_pkey.c24
-rw-r--r--ext/openssl/ossl_pkey.h21
-rw-r--r--ext/openssl/ossl_pkey_dh.c101
-rw-r--r--ext/openssl/ossl_pkey_dsa.c92
-rw-r--r--ext/openssl/ossl_pkey_ec.c1582
-rw-r--r--ext/openssl/ossl_pkey_rsa.c119
-rw-r--r--ext/openssl/ossl_rand.c88
-rw-r--r--ext/openssl/ossl_ssl.c645
-rw-r--r--ext/openssl/ossl_ssl.h15
-rw-r--r--ext/openssl/ossl_ssl_session.c298
-rw-r--r--ext/openssl/ossl_x509attr.c36
-rw-r--r--ext/openssl/ossl_x509cert.c109
-rw-r--r--ext/openssl/ossl_x509crl.c16
-rw-r--r--ext/openssl/ossl_x509ext.c24
-rw-r--r--ext/openssl/ossl_x509name.c42
-rw-r--r--ext/openssl/ossl_x509req.c10
-rw-r--r--ext/openssl/ossl_x509revoked.c8
-rw-r--r--ext/openssl/ossl_x509store.c17
-rw-r--r--ext/openssl/ruby_missing.h27
-rw-r--r--ext/pty/expect_sample.rb15
-rw-r--r--ext/pty/lib/expect.rb2
-rw-r--r--ext/pty/pty.c70
-rw-r--r--ext/purelib.rb9
-rw-r--r--ext/readline/extconf.rb7
-rw-r--r--ext/readline/readline.c21
-rw-r--r--ext/socket/addrinfo.h5
-rw-r--r--ext/socket/socket.c134
-rw-r--r--ext/stringio/stringio.c83
-rw-r--r--ext/syck/rubyext.c16
-rw-r--r--ext/syslog/syslog.c3
-rw-r--r--ext/syslog/syslog.txt5
-rw-r--r--ext/thread/thread.c82
-rw-r--r--ext/tk/ChangeLog.tkextlib6
-rw-r--r--ext/tk/MANUAL_tcltklib.eng24
-rw-r--r--ext/tk/MANUAL_tcltklib.eucj22
-rw-r--r--ext/tk/README.1st13
-rw-r--r--ext/tk/README.tcltklib20
-rw-r--r--ext/tk/extconf.rb166
-rw-r--r--ext/tk/lib/multi-tk.rb200
-rw-r--r--ext/tk/lib/tcltk.rb2
-rw-r--r--ext/tk/lib/tk.rb1226
-rw-r--r--ext/tk/lib/tk/autoload.rb358
-rw-r--r--ext/tk/lib/tk/bindtag.rb83
-rw-r--r--ext/tk/lib/tk/button.rb5
-rw-r--r--ext/tk/lib/tk/canvas.rb54
-rw-r--r--ext/tk/lib/tk/canvastag.rb117
-rw-r--r--ext/tk/lib/tk/checkbutton.rb9
-rw-r--r--ext/tk/lib/tk/composite.rb70
-rw-r--r--ext/tk/lib/tk/encodedstr.rb84
-rw-r--r--ext/tk/lib/tk/entry.rb6
-rw-r--r--ext/tk/lib/tk/event.rb62
-rw-r--r--ext/tk/lib/tk/font.rb732
-rw-r--r--ext/tk/lib/tk/frame.rb5
-rw-r--r--ext/tk/lib/tk/grid.rb49
-rw-r--r--ext/tk/lib/tk/image.rb62
-rw-r--r--ext/tk/lib/tk/itemconfig.rb164
-rw-r--r--ext/tk/lib/tk/itemfont.rb33
-rw-r--r--ext/tk/lib/tk/label.rb5
-rw-r--r--ext/tk/lib/tk/labelframe.rb8
-rw-r--r--ext/tk/lib/tk/listbox.rb5
-rw-r--r--ext/tk/lib/tk/macpkg.rb9
-rw-r--r--ext/tk/lib/tk/menu.rb91
-rw-r--r--ext/tk/lib/tk/menubar.rb2
-rw-r--r--ext/tk/lib/tk/menuspec.rb26
-rw-r--r--ext/tk/lib/tk/message.rb5
-rw-r--r--ext/tk/lib/tk/msgcat.rb6
-rw-r--r--ext/tk/lib/tk/namespace.rb149
-rw-r--r--ext/tk/lib/tk/optiondb.rb16
-rw-r--r--ext/tk/lib/tk/pack.rb17
-rw-r--r--ext/tk/lib/tk/package.rb4
-rw-r--r--ext/tk/lib/tk/palette.rb2
-rw-r--r--ext/tk/lib/tk/panedwindow.rb32
-rw-r--r--ext/tk/lib/tk/radiobutton.rb9
-rw-r--r--ext/tk/lib/tk/root.rb37
-rw-r--r--ext/tk/lib/tk/scale.rb33
-rw-r--r--ext/tk/lib/tk/scrollbar.rb65
-rw-r--r--ext/tk/lib/tk/scrollbox.rb7
-rw-r--r--ext/tk/lib/tk/spinbox.rb24
-rw-r--r--ext/tk/lib/tk/text.rb178
-rw-r--r--ext/tk/lib/tk/textimage.rb14
-rw-r--r--ext/tk/lib/tk/textmark.rb102
-rw-r--r--ext/tk/lib/tk/texttag.rb113
-rw-r--r--ext/tk/lib/tk/textwindow.rb13
-rw-r--r--ext/tk/lib/tk/timer.rb55
-rw-r--r--ext/tk/lib/tk/toplevel.rb13
-rw-r--r--ext/tk/lib/tk/ttk_selector.rb76
-rw-r--r--ext/tk/lib/tk/validation.rb25
-rw-r--r--ext/tk/lib/tk/variable.rb488
-rw-r--r--ext/tk/lib/tk/virtevent.rb77
-rw-r--r--ext/tk/lib/tk/winpkg.rb18
-rw-r--r--ext/tk/lib/tk/wm.rb476
-rw-r--r--ext/tk/lib/tkextlib/SUPPORT_STATUS2
-rw-r--r--ext/tk/lib/tkextlib/blt/bitmap.rb21
-rw-r--r--ext/tk/lib/tkextlib/blt/busy.rb2
-rw-r--r--ext/tk/lib/tkextlib/blt/component.rb452
-rw-r--r--ext/tk/lib/tkextlib/blt/dragdrop.rb54
-rw-r--r--ext/tk/lib/tkextlib/blt/eps.rb2
-rw-r--r--ext/tk/lib/tkextlib/blt/htext.rb1
-rw-r--r--ext/tk/lib/tkextlib/blt/table.rb17
-rw-r--r--ext/tk/lib/tkextlib/blt/tabset.rb81
-rw-r--r--ext/tk/lib/tkextlib/blt/ted.rb9
-rw-r--r--ext/tk/lib/tkextlib/blt/tile/button.rb2
-rw-r--r--ext/tk/lib/tkextlib/blt/tile/checkbutton.rb2
-rw-r--r--ext/tk/lib/tkextlib/blt/tile/frame.rb2
-rw-r--r--ext/tk/lib/tkextlib/blt/tile/label.rb2
-rw-r--r--ext/tk/lib/tkextlib/blt/tile/radiobutton.rb2
-rw-r--r--ext/tk/lib/tkextlib/blt/tile/scrollbar.rb2
-rw-r--r--ext/tk/lib/tkextlib/blt/tile/toplevel.rb2
-rw-r--r--ext/tk/lib/tkextlib/blt/tree.rb341
-rw-r--r--ext/tk/lib/tkextlib/blt/treeview.rb228
-rw-r--r--ext/tk/lib/tkextlib/blt/unix_dnd.rb16
-rw-r--r--ext/tk/lib/tkextlib/blt/vector.rb37
-rw-r--r--ext/tk/lib/tkextlib/blt/watch.rb47
-rw-r--r--ext/tk/lib/tkextlib/bwidget/button.rb2
-rw-r--r--ext/tk/lib/tkextlib/bwidget/buttonbox.rb20
-rw-r--r--ext/tk/lib/tkextlib/bwidget/combobox.rb8
-rw-r--r--ext/tk/lib/tkextlib/bwidget/dialog.rb33
-rw-r--r--ext/tk/lib/tkextlib/bwidget/dynamichelp.rb7
-rw-r--r--ext/tk/lib/tkextlib/bwidget/entry.rb2
-rw-r--r--ext/tk/lib/tkextlib/bwidget/label.rb2
-rw-r--r--ext/tk/lib/tkextlib/bwidget/labelentry.rb2
-rw-r--r--ext/tk/lib/tkextlib/bwidget/labelframe.rb8
-rw-r--r--ext/tk/lib/tkextlib/bwidget/listbox.rb37
-rw-r--r--ext/tk/lib/tkextlib/bwidget/mainframe.rb48
-rw-r--r--ext/tk/lib/tkextlib/bwidget/messagedlg.rb16
-rw-r--r--ext/tk/lib/tkextlib/bwidget/notebook.rb24
-rw-r--r--ext/tk/lib/tkextlib/bwidget/pagesmanager.rb16
-rw-r--r--ext/tk/lib/tkextlib/bwidget/panedwindow.rb8
-rw-r--r--ext/tk/lib/tkextlib/bwidget/panelframe.rb8
-rw-r--r--ext/tk/lib/tkextlib/bwidget/progressdlg.rb4
-rw-r--r--ext/tk/lib/tkextlib/bwidget/scrollableframe.rb8
-rw-r--r--ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb8
-rw-r--r--ext/tk/lib/tkextlib/bwidget/selectcolor.rb28
-rw-r--r--ext/tk/lib/tkextlib/bwidget/selectfont.rb7
-rw-r--r--ext/tk/lib/tkextlib/bwidget/spinbox.rb2
-rw-r--r--ext/tk/lib/tkextlib/bwidget/statusbar.rb8
-rw-r--r--ext/tk/lib/tkextlib/bwidget/titleframe.rb8
-rw-r--r--ext/tk/lib/tkextlib/bwidget/tree.rb37
-rw-r--r--ext/tk/lib/tkextlib/bwidget/widget.rb20
-rw-r--r--ext/tk/lib/tkextlib/itcl/incr_tcl.rb12
-rw-r--r--ext/tk/lib/tkextlib/itk/incr_tk.rb44
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/buttonbox.rb5
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/calendar.rb19
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/checkbox.rb21
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/dialogshell.rb5
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/entryfield.rb19
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/hierarchy.rb58
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/menubar.rb5
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/messagebox.rb5
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/notebook.rb16
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/panedwindow.rb5
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/radiobox.rb16
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb12
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb2
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb30
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/selectionbox.rb2
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/selectiondialog.rb2
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/spinner.rb19
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb21
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/tabset.rb49
-rw-r--r--ext/tk/lib/tkextlib/tcllib/autoscroll.rb2
-rw-r--r--ext/tk/lib/tkextlib/tcllib/ctext.rb2
-rw-r--r--ext/tk/lib/tkextlib/tcllib/datefield.rb2
-rw-r--r--ext/tk/lib/tkextlib/tcllib/getstring.rb5
-rw-r--r--ext/tk/lib/tkextlib/tcllib/ico.rb6
-rw-r--r--ext/tk/lib/tkextlib/tcllib/ip_entry.rb2
-rw-r--r--ext/tk/lib/tkextlib/tcllib/plotchart.rb77
-rw-r--r--ext/tk/lib/tkextlib/tcllib/swaplist.rb5
-rw-r--r--ext/tk/lib/tkextlib/tcllib/tablelist_core.rb16
-rw-r--r--ext/tk/lib/tkextlib/tcllib/tkpiechart.rb14
-rw-r--r--ext/tk/lib/tkextlib/tile.rb257
-rw-r--r--ext/tk/lib/tkextlib/tile/dialog.rb14
-rw-r--r--ext/tk/lib/tkextlib/tile/sizegrip.rb4
-rw-r--r--ext/tk/lib/tkextlib/tile/style.rb239
-rw-r--r--ext/tk/lib/tkextlib/tile/tbutton.rb7
-rw-r--r--ext/tk/lib/tkextlib/tile/tcheckbutton.rb8
-rw-r--r--ext/tk/lib/tkextlib/tile/tcombobox.rb3
-rw-r--r--ext/tk/lib/tkextlib/tile/tentry.rb12
-rw-r--r--ext/tk/lib/tkextlib/tile/tframe.rb7
-rw-r--r--ext/tk/lib/tkextlib/tile/tlabel.rb7
-rw-r--r--ext/tk/lib/tkextlib/tile/tlabelframe.rb8
-rw-r--r--ext/tk/lib/tkextlib/tile/tmenubutton.rb12
-rw-r--r--ext/tk/lib/tkextlib/tile/tnotebook.rb31
-rw-r--r--ext/tk/lib/tkextlib/tile/tpaned.rb55
-rw-r--r--ext/tk/lib/tkextlib/tile/tprogressbar.rb3
-rw-r--r--ext/tk/lib/tkextlib/tile/tradiobutton.rb8
-rw-r--r--ext/tk/lib/tkextlib/tile/treeview.rb193
-rw-r--r--ext/tk/lib/tkextlib/tile/tscale.rb7
-rw-r--r--ext/tk/lib/tkextlib/tile/tscrollbar.rb28
-rw-r--r--ext/tk/lib/tkextlib/tile/tseparator.rb3
-rw-r--r--ext/tk/lib/tkextlib/tkDND/shape.rb32
-rw-r--r--ext/tk/lib/tkextlib/tkDND/tkdnd.rb18
-rw-r--r--ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb17
-rw-r--r--ext/tk/lib/tkextlib/tktable/tktable.rb188
-rw-r--r--ext/tk/lib/tkextlib/tktrans/tktrans.rb4
-rw-r--r--ext/tk/lib/tkextlib/treectrl/tktreectrl.rb300
-rw-r--r--ext/tk/lib/tkextlib/version.rb2
-rw-r--r--ext/tk/lib/tkextlib/vu/pie.rb77
-rw-r--r--ext/tk/lib/tkextlib/vu/spinbox.rb2
-rw-r--r--ext/tk/lib/tkextlib/winico/winico.rb57
-rw-r--r--ext/tk/sample/binstr_usage.rb12
-rw-r--r--ext/tk/sample/demos-en/anilabel.rb10
-rw-r--r--ext/tk/sample/demos-en/aniwave.rb9
-rw-r--r--ext/tk/sample/demos-en/arrow.rb26
-rw-r--r--ext/tk/sample/demos-en/bind.rb33
-rw-r--r--ext/tk/sample/demos-en/bitmap.rb10
-rw-r--r--ext/tk/sample/demos-en/button.rb2
-rw-r--r--ext/tk/sample/demos-en/check.rb14
-rw-r--r--ext/tk/sample/demos-en/check2.rb14
-rw-r--r--ext/tk/sample/demos-en/clrpick.rb22
-rw-r--r--ext/tk/sample/demos-en/colors.rb18
-rw-r--r--ext/tk/sample/demos-en/combo.rb96
-rw-r--r--ext/tk/sample/demos-en/cscroll.rb14
-rw-r--r--ext/tk/sample/demos-en/ctext.rb53
-rw-r--r--ext/tk/sample/demos-en/entry1.rb12
-rw-r--r--ext/tk/sample/demos-en/entry2.rb8
-rw-r--r--ext/tk/sample/demos-en/entry3.rb50
-rw-r--r--ext/tk/sample/demos-en/filebox.rb17
-rw-r--r--ext/tk/sample/demos-en/floor.rb14
-rw-r--r--ext/tk/sample/demos-en/floor2.rb14
-rw-r--r--ext/tk/sample/demos-en/form.rb8
-rw-r--r--ext/tk/sample/demos-en/goldberg.rb23
-rw-r--r--ext/tk/sample/demos-en/hello6
-rw-r--r--ext/tk/sample/demos-en/hscale.rb29
-rw-r--r--ext/tk/sample/demos-en/icon.rb20
-rw-r--r--ext/tk/sample/demos-en/image1.rb13
-rw-r--r--ext/tk/sample/demos-en/image2.rb22
-rw-r--r--ext/tk/sample/demos-en/image3.rb29
-rw-r--r--ext/tk/sample/demos-en/items.rb17
-rw-r--r--ext/tk/sample/demos-en/knightstour.rb271
-rw-r--r--ext/tk/sample/demos-en/label.rb13
-rw-r--r--ext/tk/sample/demos-en/labelframe.rb8
-rw-r--r--ext/tk/sample/demos-en/mclist.rb117
-rw-r--r--ext/tk/sample/demos-en/menu.rb12
-rw-r--r--ext/tk/sample/demos-en/menu84.rb8
-rw-r--r--ext/tk/sample/demos-en/menubu.rb10
-rw-r--r--ext/tk/sample/demos-en/msgbox.rb10
-rw-r--r--ext/tk/sample/demos-en/msgbox2.rb91
-rw-r--r--ext/tk/sample/demos-en/paned1.rb14
-rw-r--r--ext/tk/sample/demos-en/paned2.rb8
-rw-r--r--ext/tk/sample/demos-en/patch_1.1c193
-rw-r--r--ext/tk/sample/demos-en/pendulum.rb43
-rw-r--r--ext/tk/sample/demos-en/plot.rb8
-rw-r--r--ext/tk/sample/demos-en/puzzle.rb32
-rw-r--r--ext/tk/sample/demos-en/radio.rb12
-rw-r--r--ext/tk/sample/demos-en/radio2.rb17
-rw-r--r--ext/tk/sample/demos-en/radio3.rb19
-rw-r--r--ext/tk/sample/demos-en/rolodex-j323
-rw-r--r--ext/tk/sample/demos-en/ruler.rb8
-rw-r--r--ext/tk/sample/demos-en/sayings.rb8
-rw-r--r--ext/tk/sample/demos-en/search.rb19
-rw-r--r--ext/tk/sample/demos-en/spin.rb12
-rw-r--r--ext/tk/sample/demos-en/states.rb8
-rw-r--r--ext/tk/sample/demos-en/style.rb42
-rw-r--r--ext/tk/sample/demos-en/text.rb8
-rw-r--r--ext/tk/sample/demos-en/textpeer.rb76
-rw-r--r--ext/tk/sample/demos-en/toolbar.rb130
-rw-r--r--ext/tk/sample/demos-en/tree.rb119
-rw-r--r--ext/tk/sample/demos-en/ttkbut.rb139
-rw-r--r--ext/tk/sample/demos-en/ttkmenu.rb85
-rw-r--r--ext/tk/sample/demos-en/ttknote.rb89
-rw-r--r--ext/tk/sample/demos-en/ttkpane.rb213
-rw-r--r--ext/tk/sample/demos-en/ttkprogress.rb66
-rw-r--r--ext/tk/sample/demos-en/twind.rb14
-rw-r--r--ext/tk/sample/demos-en/twind2.rb6
-rw-r--r--ext/tk/sample/demos-en/unicodeout.rb14
-rw-r--r--ext/tk/sample/demos-en/vscale.rb29
-rw-r--r--ext/tk/sample/demos-en/widget232
-rw-r--r--ext/tk/sample/demos-jp/anilabel.rb11
-rw-r--r--ext/tk/sample/demos-jp/aniwave.rb10
-rw-r--r--ext/tk/sample/demos-jp/arrow.rb27
-rw-r--r--ext/tk/sample/demos-jp/bind.rb34
-rw-r--r--ext/tk/sample/demos-jp/bitmap.rb11
-rw-r--r--ext/tk/sample/demos-jp/button.rb4
-rw-r--r--ext/tk/sample/demos-jp/check.rb15
-rw-r--r--ext/tk/sample/demos-jp/check2.rb15
-rw-r--r--ext/tk/sample/demos-jp/clrpick.rb21
-rw-r--r--ext/tk/sample/demos-jp/colors.rb19
-rw-r--r--ext/tk/sample/demos-jp/combo.rb98
-rw-r--r--ext/tk/sample/demos-jp/cscroll.rb15
-rw-r--r--ext/tk/sample/demos-jp/ctext.rb54
-rw-r--r--ext/tk/sample/demos-jp/dialog1.rb1
-rw-r--r--ext/tk/sample/demos-jp/dialog2.rb1
-rw-r--r--ext/tk/sample/demos-jp/entry1.rb13
-rw-r--r--ext/tk/sample/demos-jp/entry2.rb9
-rw-r--r--ext/tk/sample/demos-jp/entry3.rb49
-rw-r--r--ext/tk/sample/demos-jp/filebox.rb18
-rw-r--r--ext/tk/sample/demos-jp/floor.rb15
-rw-r--r--ext/tk/sample/demos-jp/floor2.rb15
-rw-r--r--ext/tk/sample/demos-jp/form.rb9
-rw-r--r--ext/tk/sample/demos-jp/goldberg.rb24
-rw-r--r--ext/tk/sample/demos-jp/hello1
-rw-r--r--ext/tk/sample/demos-jp/hscale.rb29
-rw-r--r--ext/tk/sample/demos-jp/icon.rb21
-rw-r--r--ext/tk/sample/demos-jp/image1.rb14
-rw-r--r--ext/tk/sample/demos-jp/image2.rb24
-rw-r--r--ext/tk/sample/demos-jp/image3.rb18
-rw-r--r--ext/tk/sample/demos-jp/items.rb18
-rw-r--r--ext/tk/sample/demos-jp/ixset21
-rw-r--r--ext/tk/sample/demos-jp/knightstour.rb273
-rw-r--r--ext/tk/sample/demos-jp/label.rb14
-rw-r--r--ext/tk/sample/demos-jp/labelframe.rb10
-rw-r--r--ext/tk/sample/demos-jp/mclist.rb121
-rw-r--r--ext/tk/sample/demos-jp/menu.rb15
-rw-r--r--ext/tk/sample/demos-jp/menu84.rb9
-rw-r--r--ext/tk/sample/demos-jp/menu8x.rb13
-rw-r--r--ext/tk/sample/demos-jp/menubu.rb11
-rw-r--r--ext/tk/sample/demos-jp/msgbox.rb15
-rw-r--r--ext/tk/sample/demos-jp/msgbox2.rb90
-rw-r--r--ext/tk/sample/demos-jp/paned1.rb16
-rw-r--r--ext/tk/sample/demos-jp/paned2.rb10
-rw-r--r--ext/tk/sample/demos-jp/pendulum.rb44
-rw-r--r--ext/tk/sample/demos-jp/plot.rb15
-rw-r--r--ext/tk/sample/demos-jp/puzzle.rb33
-rw-r--r--ext/tk/sample/demos-jp/radio.rb13
-rw-r--r--ext/tk/sample/demos-jp/radio2.rb19
-rw-r--r--ext/tk/sample/demos-jp/radio3.rb21
-rw-r--r--ext/tk/sample/demos-jp/rolodex-j1
-rw-r--r--ext/tk/sample/demos-jp/ruler.rb9
-rw-r--r--ext/tk/sample/demos-jp/sayings.rb9
-rw-r--r--ext/tk/sample/demos-jp/search.rb20
-rw-r--r--ext/tk/sample/demos-jp/spin.rb16
-rw-r--r--ext/tk/sample/demos-jp/states.rb9
-rw-r--r--ext/tk/sample/demos-jp/style.rb42
-rw-r--r--ext/tk/sample/demos-jp/tcolor1
-rw-r--r--ext/tk/sample/demos-jp/text.rb9
-rw-r--r--ext/tk/sample/demos-jp/textpeer.rb82
-rw-r--r--ext/tk/sample/demos-jp/toolbar.rb136
-rw-r--r--ext/tk/sample/demos-jp/tree.rb120
-rw-r--r--ext/tk/sample/demos-jp/ttkbut.rb145
-rw-r--r--ext/tk/sample/demos-jp/ttkmenu.rb91
-rw-r--r--ext/tk/sample/demos-jp/ttknote.rb97
-rw-r--r--ext/tk/sample/demos-jp/ttkpane.rb216
-rw-r--r--ext/tk/sample/demos-jp/ttkprogress.rb71
-rw-r--r--ext/tk/sample/demos-jp/twind.rb13
-rw-r--r--ext/tk/sample/demos-jp/twind2.rb7
-rw-r--r--ext/tk/sample/demos-jp/unicodeout.rb16
-rw-r--r--ext/tk/sample/demos-jp/vscale.rb30
-rw-r--r--ext/tk/sample/demos-jp/widget278
-rw-r--r--ext/tk/sample/encstr_usage.rb5
-rw-r--r--ext/tk/sample/figmemo_sample.rb456
-rw-r--r--ext/tk/sample/irbtkw.rbw24
-rw-r--r--ext/tk/sample/tcltklib/sample2.rb2
-rw-r--r--ext/tk/sample/tkextlib/tile/demo.rb39
-rw-r--r--ext/tk/sample/tkextlib/tile/themes/blue/pkgIndex.tcl2
-rw-r--r--ext/tk/sample/tkextlib/tile/themes/kroc.rb30
-rw-r--r--ext/tk/sample/tkextlib/treectrl/demo.rb7
-rw-r--r--ext/tk/sample/tkextlib/vu/canvSticker2.rb12
-rw-r--r--ext/tk/sample/tkrttimer.rb13
-rw-r--r--ext/tk/sample/tksleep_sample.rb29
-rw-r--r--ext/tk/sample/tktextio.rb12
-rw-r--r--ext/tk/sample/ttk_wrapper.rb154
-rw-r--r--ext/tk/stubs.c78
-rw-r--r--ext/tk/tcltklib.c2692
-rw-r--r--ext/tk/tkutil/extconf.rb2
-rw-r--r--ext/tk/tkutil/tkutil.c708
-rw-r--r--ext/win32ole/tests/testOLEEVENT.rb91
-rw-r--r--ext/win32ole/tests/testWIN32OLE.rb3
-rw-r--r--ext/win32ole/tests/test_win32ole_event.rb133
-rw-r--r--ext/win32ole/tests/testall.rb1
-rw-r--r--ext/win32ole/win32ole.c190
-rw-r--r--ext/zlib/extconf.rb4
-rw-r--r--ext/zlib/zlib.c15
-rw-r--r--file.c317
-rw-r--r--gc.c294
-rw-r--r--hash.c518
-rw-r--r--inits.c2
-rwxr-xr-xinstruby.rb176
-rw-r--r--intern.h30
-rw-r--r--io.c417
-rw-r--r--keywords2
-rw-r--r--lex.c2
-rw-r--r--lib/README4
-rw-r--r--lib/benchmark.rb9
-rw-r--r--lib/cgi.rb25
-rw-r--r--lib/cgi/session.rb44
-rw-r--r--lib/cgi/session/pstore.rb2
-rw-r--r--lib/complex.rb32
-rw-r--r--lib/date.rb173
-rw-r--r--lib/date/format.rb386
-rw-r--r--lib/delegate.rb48
-rw-r--r--lib/drb/drb.rb25
-rw-r--r--lib/drb/extservm.rb41
-rw-r--r--lib/erb.rb304
-rw-r--r--lib/forwardable.rb2
-rw-r--r--lib/generator.rb38
-rw-r--r--lib/ipaddr.rb146
-rw-r--r--lib/irb.rb18
-rw-r--r--lib/irb/extend-command.rb2
-rw-r--r--lib/irb/help.rb2
-rw-r--r--lib/irb/notifier.rb2
-rw-r--r--lib/irb/ruby-lex.rb2
-rw-r--r--lib/irb/slex.rb2
-rw-r--r--lib/logger.rb2
-rw-r--r--lib/matrix.rb18
-rw-r--r--lib/mkmf.rb330
-rw-r--r--lib/net/ftp.rb19
-rw-r--r--lib/net/http.rb3
-rw-r--r--lib/net/https.rb4
-rw-r--r--lib/net/imap.rb7
-rw-r--r--lib/net/pop.rb230
-rw-r--r--lib/net/protocol.rb4
-rw-r--r--lib/net/smtp.rb635
-rw-r--r--lib/net/telnet.rb22
-rw-r--r--lib/open-uri.rb12
-rw-r--r--lib/optparse.rb17
-rw-r--r--lib/pp.rb13
-rw-r--r--lib/pstore.rb4
-rw-r--r--lib/rational.rb78
-rw-r--r--lib/rdoc/options.rb6
-rw-r--r--lib/rdoc/parsers/parse_c.rb8
-rw-r--r--lib/rdoc/parsers/parse_f95.rb8
-rw-r--r--lib/rdoc/parsers/parse_rb.rb8
-rw-r--r--lib/rdoc/ri/ri_options.rb34
-rw-r--r--lib/rdoc/ri/ri_paths.rb27
-rw-r--r--lib/resolv-replace.rb3
-rw-r--r--lib/resolv.rb1244
-rw-r--r--lib/rexml/attlistdecl.rb2
-rw-r--r--lib/rexml/attribute.rb2
-rw-r--r--lib/rexml/document.rb5
-rw-r--r--lib/rexml/element.rb17
-rw-r--r--lib/rexml/encoding.rb9
-rw-r--r--lib/rexml/encodings/SHIFT-JIS.rb4
-rw-r--r--lib/rexml/formatters/pretty.rb2
-rw-r--r--lib/rexml/functions.rb2
-rw-r--r--lib/rexml/node.rb2
-rw-r--r--lib/rexml/parsers/baseparser.rb58
-rw-r--r--lib/rexml/parsers/treeparser.rb6
-rw-r--r--lib/rexml/rexml.rb14
-rw-r--r--lib/rexml/source.rb16
-rw-r--r--lib/rexml/text.rb2
-rw-r--r--lib/rexml/undefinednamespaceexception.rb8
-rw-r--r--lib/rexml/xpath.rb2
-rw-r--r--lib/rinda/ring.rb4
-rw-r--r--lib/rinda/tuplespace.rb100
-rw-r--r--lib/rss.rb7
-rw-r--r--lib/rss/0.9.rb22
-rw-r--r--lib/rss/1.0.rb13
-rw-r--r--lib/rss/2.0.rb2
-rw-r--r--lib/rss/atom.rb749
-rw-r--r--lib/rss/content.rb25
-rw-r--r--lib/rss/content/1.0.rb10
-rw-r--r--lib/rss/content/2.0.rb12
-rw-r--r--lib/rss/converter.rb8
-rw-r--r--lib/rss/dublincore.rb39
-rw-r--r--lib/rss/dublincore/1.0.rb13
-rw-r--r--lib/rss/dublincore/2.0.rb13
-rw-r--r--lib/rss/dublincore/atom.rb17
-rw-r--r--lib/rss/image.rb10
-rw-r--r--lib/rss/itunes.rb410
-rw-r--r--lib/rss/maker.rb25
-rw-r--r--lib/rss/maker/0.9.rb375
-rw-r--r--lib/rss/maker/1.0.rb332
-rw-r--r--lib/rss/maker/2.0.rb147
-rw-r--r--lib/rss/maker/atom.rb172
-rw-r--r--lib/rss/maker/base.rb844
-rw-r--r--lib/rss/maker/content.rb14
-rw-r--r--lib/rss/maker/dublincore.rb145
-rw-r--r--lib/rss/maker/entry.rb163
-rw-r--r--lib/rss/maker/feed.rb429
-rw-r--r--lib/rss/maker/image.rb116
-rw-r--r--lib/rss/maker/itunes.rb242
-rw-r--r--lib/rss/maker/slash.rb33
-rw-r--r--lib/rss/maker/syndication.rb13
-rw-r--r--lib/rss/maker/taxonomy.rb118
-rw-r--r--lib/rss/maker/trackback.rb115
-rw-r--r--lib/rss/parser.rb167
-rw-r--r--lib/rss/rss.rb735
-rw-r--r--lib/rss/slash.rb49
-rw-r--r--lib/rss/syndication.rb9
-rw-r--r--lib/rss/taxonomy.rb2
-rw-r--r--lib/rss/utils.rb78
-rw-r--r--lib/rss/xml-stylesheet.rb4
-rw-r--r--lib/rss/xml.rb71
-rw-r--r--lib/securerandom.rb137
-rw-r--r--lib/set.rb48
-rw-r--r--lib/shellwords.rb146
-rw-r--r--lib/singleton.rb61
-rw-r--r--lib/tempfile.rb26
-rw-r--r--lib/time.rb18
-rw-r--r--lib/timeout.rb23
-rw-r--r--lib/tmpdir.rb104
-rw-r--r--lib/uri.rb1
-rw-r--r--lib/uri/common.rb2
-rw-r--r--lib/uri/ftp.rb86
-rw-r--r--lib/uri/generic.rb107
-rw-r--r--lib/uri/ldaps.rb12
-rw-r--r--lib/webrick/httpproxy.rb2
-rw-r--r--lib/webrick/httpresponse.rb2
-rw-r--r--lib/webrick/httpservlet/abstract.rb2
-rw-r--r--lib/webrick/httpservlet/cgi_runner.rb4
-rw-r--r--lib/webrick/httpservlet/cgihandler.rb4
-rw-r--r--lib/webrick/httpservlet/filehandler.rb71
-rw-r--r--lib/webrick/httputils.rb16
-rw-r--r--lib/xmlrpc/client.rb17
-rw-r--r--lib/xmlrpc/parser.rb4
-rw-r--r--lib/xmlrpc/server.rb6
-rw-r--r--lib/xmlrpc/utils.rb2
-rw-r--r--lib/yaml.rb4
-rw-r--r--lib/yaml/baseemitter.rb2
-rw-r--r--lib/yaml/basenode.rb2
-rw-r--r--lib/yaml/encoding.rb6
-rw-r--r--lib/yaml/rubytypes.rb20
-rw-r--r--lib/yaml/store.rb20
-rw-r--r--lib/yaml/types.rb8
-rw-r--r--marshal.c69
-rw-r--r--math.c4
-rw-r--r--misc/README3
-rw-r--r--misc/rdebug.el136
-rw-r--r--misc/ruby-mode.el37
-rw-r--r--misc/ruby-style.el66
-rw-r--r--missing.h2
-rw-r--r--missing/crypt.c34
-rw-r--r--missing/isinf.c7
-rw-r--r--missing/strftime.c56
-rw-r--r--missing/vsnprintf.c2
-rwxr-xr-xmkconfig.rb8
-rw-r--r--node.h24
-rw-r--r--numeric.c511
-rw-r--r--object.c124
-rw-r--r--pack.c30
-rw-r--r--parse.y241
-rw-r--r--process.c140
-rw-r--r--random.c20
-rw-r--r--range.c96
-rw-r--r--re.c147
-rw-r--r--regex.c97
-rw-r--r--regex.h4
-rw-r--r--ruby.c96
-rw-r--r--ruby.h27
-rw-r--r--rubyio.h25
-rw-r--r--rubysig.h8
-rwxr-xr-xrunruby.rb17
-rw-r--r--sample/README3
-rw-r--r--sample/cal.rb84
-rw-r--r--sample/cbreak.rb4
-rw-r--r--sample/dualstack-httpd.rb2
-rw-r--r--sample/erb/erb4html.rb60
-rw-r--r--sample/eval.rb2
-rw-r--r--sample/from.rb2
-rw-r--r--sample/goodfriday.rb48
-rw-r--r--sample/philos.rb2
-rw-r--r--sample/regx.rb2
-rwxr-xr-xsample/rss/blend.rb6
-rwxr-xr-xsample/rss/convert.rb2
-rw-r--r--[-rwxr-xr-x]sample/rss/list_description.rb13
-rwxr-xr-xsample/rss/re_read.rb10
-rw-r--r--[-rwxr-xr-x]sample/rss/rss_recent.rb20
-rw-r--r--sample/test.rb64
-rw-r--r--sample/time.rb16
-rw-r--r--signal.c64
-rw-r--r--sprintf.c21
-rw-r--r--string.c468
-rw-r--r--struct.c28
-rw-r--r--test/drb/drbtest.rb2
-rw-r--r--test/erb/hello.erb4
-rw-r--r--test/erb/test_erb.rb386
-rw-r--r--test/gdbm/test_gdbm.rb4
-rw-r--r--test/iconv/test_basic.rb49
-rw-r--r--test/iconv/test_option.rb31
-rw-r--r--test/iconv/test_partial.rb41
-rw-r--r--test/iconv/utils.rb26
-rw-r--r--test/net/http/test_https_proxy.rb9
-rw-r--r--test/openssl/test_ec.rb113
-rw-r--r--test/openssl/test_ssl.rb348
-rw-r--r--test/pathname/test_pathname.rb26
-rw-r--r--test/rinda/test_rinda.rb97
-rw-r--r--test/rss/dot.pngbin111 -> 0 bytes-rw-r--r--test/rss/rss-assertions.rb1894
-rw-r--r--test/rss/rss-testcase.rb208
-rw-r--r--test/rss/test_1.0.rb61
-rw-r--r--test/rss/test_2.0.rb28
-rw-r--r--test/rss/test_atom.rb681
-rw-r--r--test/rss/test_content.rb68
-rw-r--r--test/rss/test_dublincore.rb316
-rw-r--r--test/rss/test_image.rb49
-rw-r--r--test/rss/test_inherit.rb5
-rw-r--r--test/rss/test_itunes.rb347
-rw-r--r--test/rss/test_maker_0.9.rb147
-rw-r--r--test/rss/test_maker_1.0.rb205
-rw-r--r--test/rss/test_maker_2.0.rb56
-rw-r--r--test/rss/test_maker_atom_entry.rb367
-rw-r--r--test/rss/test_maker_atom_feed.rb389
-rw-r--r--test/rss/test_maker_content.rb13
-rw-r--r--test/rss/test_maker_dc.rb9
-rw-r--r--test/rss/test_maker_itunes.rb471
-rw-r--r--test/rss/test_maker_slash.rb37
-rw-r--r--test/rss/test_maker_sy.rb1
-rw-r--r--test/rss/test_maker_xml-stylesheet.rb8
-rw-r--r--test/rss/test_parser.rb26
-rw-r--r--test/rss/test_parser_1.0.rb10
-rw-r--r--test/rss/test_parser_atom_entry.rb163
-rw-r--r--test/rss/test_parser_atom_feed.rb276
-rw-r--r--test/rss/test_setup_maker_0.9.rb25
-rw-r--r--test/rss/test_setup_maker_1.0.rb26
-rw-r--r--test/rss/test_setup_maker_atom_entry.rb409
-rw-r--r--test/rss/test_setup_maker_atom_feed.rb445
-rw-r--r--test/rss/test_setup_maker_itunes.rb144
-rw-r--r--test/rss/test_setup_maker_slash.rb38
-rw-r--r--test/rss/test_slash.rb64
-rw-r--r--test/rss/test_syndication.rb4
-rw-r--r--test/rss/test_taxonomy.rb16
-rw-r--r--test/rss/test_to_s.rb232
-rw-r--r--test/rss/test_version.rb2
-rw-r--r--test/rss/test_xml-stylesheet.rb6
-rw-r--r--test/ruby/test_array.rb1159
-rw-r--r--test/ruby/test_beginendblock.rb18
-rw-r--r--test/ruby/test_bignum.rb19
-rw-r--r--test/ruby/test_enum.rb258
-rw-r--r--test/ruby/test_enumerator.rb105
-rw-r--r--test/ruby/test_fixnum.rb26
-rw-r--r--test/ruby/test_float.rb34
-rw-r--r--test/ruby/test_hash.rb3
-rw-r--r--test/ruby/test_integer.rb653
-rw-r--r--test/ruby/test_marshal.rb20
-rw-r--r--test/ruby/test_method.rb18
-rw-r--r--test/ruby/test_proc.rb5
-rw-r--r--test/ruby/test_settracefunc.rb6
-rw-r--r--test/ruby/test_sleep.rb10
-rw-r--r--test/ruby/test_symbol.rb15
-rw-r--r--test/ruby/test_time.rb21
-rwxr-xr-xtest/thread/lbtest.rb51
-rw-r--r--test/thread/test_thread.rb14
-rw-r--r--test/uri/test_common.rb5
-rw-r--r--test/uri/test_ftp.rb22
-rw-r--r--test/uri/test_generic.rb80
-rw-r--r--test/webrick/.htaccess1
-rw-r--r--test/webrick/test_cgi.rb9
-rw-r--r--test/webrick/test_filehandler.rb135
-rw-r--r--test/webrick/utils.rb12
-rw-r--r--test/webrick/webrick_long_filename.cgi36
-rw-r--r--test/xmlrpc/test_cookie.rb96
-rw-r--r--test/yaml/test_yaml.rb8
-rw-r--r--test/yaml/test_yamlstore.rb74
-rw-r--r--time.c19
-rw-r--r--util.c3444
-rw-r--r--variable.c90
-rw-r--r--version.c31
-rw-r--r--version.h32
-rw-r--r--win32/Makefile.sub227
-rwxr-xr-xwin32/mkexports.rb15
-rwxr-xr-xwin32/resource.rb8
-rw-r--r--win32/setup.mak17
-rw-r--r--win32/win32.c481
-rw-r--r--win32/win32.h25
-rw-r--r--wince/Makefile.sub489
-rw-r--r--wince/mkconfig_wce.rb7
-rw-r--r--wince/mkexports.rb35
-rw-r--r--wince/resource.rb96
718 files changed, 12180 insertions, 55370 deletions
diff --git a/ChangeLog b/ChangeLog
index d98cfcc88c..4a8ecbd0d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3325 +1,13 @@
-Thu Jan 15 14:34:32 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * gc.c (STACK_LEVEL_MAX, ruby_stack_length): returns size_t.
- [ruby-core:18207]
-Wed Jan 14 10:39:56 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * stable/ext/socket/socket.c (NI_MAXHOST, NI_MAXSERV): fixed invalid
- preprocessor directives. a patch from Peter Bowen at
- [ruby-core:18211].
-
-Tue Jan 13 04:40:30 2009 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/net/ftp.rb (login): raise FTPReplyError if passwd or acct
- is not supplied. backported from trunk. fixed [ruby-core:18058].
-
-Mon Jan 12 00:23:37 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * gc.c (gc_sweep, obj_free, run_final): defer finalizers of IO and
- Data. [ruby-dev:35578]
-
- * gc.c (rb_gc_call_finalizer_at_exit): self-referencing finalizers
- cannot be invoked. [ruby-dev:35681]
-
-Sun Jan 11 11:33:27 2009 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/net/ftp.rb (chdir): handle 5xx errors correctly.
- backported from trunk. fixed [ruby-core:18057].
-
-Fri Jan 9 19:25:25 2009 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/net/imap.rb (disconnect): do not refer SSL::SSLSocket for
- environments without OpenSSL. backported from trunk.
- fixed [ruby-dev:35755].
-
-Thu Jan 8 13:24:23 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (deferred_nodes, compstmt, arg, fixup_nodes, range_op): fix
- up fixnum range literal in conditional as automagical line number
- comparison. [ruby-core:12124], [ruby-dev:35731]
-
-Wed Jan 7 10:09:46 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (timeofday): use monotonic clock. based on a patch
- from zimbatm <zimbatm@oree.ch> in [ruby-core:16627].
-
-Tue Jan 6 09:03:35 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (yylex): 8 and 9 in octal integer should cause compile
- error. [ruby-dev:35729]
-
-Mon Jan 5 11:14:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_thread_schedule): runs deferred finalizers.
-
- * gc.c (gc_sweep): sets rb_thread_pending to run deferred finalizers.
-
- * rubysig.h (CHECK_INTS): now checks rb_thread_pending even on
- platforms where setitimer is not available. [ruby-core:18045]
-
-Mon Jan 5 11:14:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * rubysig.h (CHECK_INTS): gives the chance to perform to deferred
- finalizers before explicit GC.start or the process termination.
- [ruby-core:18045]
-
-Sun Jan 4 04:49:01 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (rb_w32_telldir): just returns loc.
-
- * win32/win32.c (rb_w32_rewinddir): needs to intialize loc.
- [ruby-core:18041]
-
-Sun Jan 4 04:45:26 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (rb_w32_select): recalc the rest of timeout for each
- iterations. [ruby-core:18015]
-
-Fri Jan 2 03:08:47 2009 Kouhei Sutou <kou@cozmixng.org>
-
- * test/rss/: use PNG instead of zlib as binary data. [ruby-dev:35666]
-
-Tue Nov 11 01:07:32 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * configure.in: fix SEGV on Mac OS X 10.5.3 with --enable-pthread.
- a patch from Wataru Kimura in Bug #193 [ruby-core:17333].
-
-Mon Aug 11 09:37:17 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/dl/dl.c (rb_str_to_ptr): should propagate taint to dlptr.
-
- * ext/dl/dl.c (rb_ary_to_ptr): ditto.
-
- * ext/dl/sym.c (rb_dlsym_call): should check taint of DLPtrData as
- well.
-
-Fri Aug 8 10:53:52 2008 Tanaka Akira <akr@fsij.org>
-
- * lib/resolv.rb: randomize source port and transaction id.
- CVE-2008-1447.
-
- * lib/resolv-replace.rb (UDPSocket#bind): don't resolv host if host is
- "".
-
-Mon Aug 4 14:49:35 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * lib/net/smtp.rb (Net::SMTP::rcptto): fix a typo. a patch from
- Masao Takaku <masao at nii.ac.jp>
- fix [ruby-dev:35489].
-
-Mon Aug 4 14:13:15 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * regex.c (xmalloc, xrealloc, xfree): not to use ruby managed memory.
-
- * regex.c (DOUBLE_STACK, re_compile_fastmap0, re_adjust_startpos),
- (re_search, re_match_exec): check if failed to allocate memory.
-
-Mon Aug 4 13:53:42 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big2str0, bigsqr): made interruptible. [ruby-Bugs-20622]
-
-Mon Aug 4 13:31:41 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * numeric.c (check_uint, rb_num2uint, rb_fix2uint): fixed wrong check
- about 64bit positive value.
-Mon Aug 4 13:31:41 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * numeric.c (check_uint, rb_num2uint, rb_fix2uint): strict check.
- fixed [ruby-dev:33683]
-
-Thu Jul 17 21:42:07 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * lib/net/smtp.rb (Net::SMTP::start): revert to avoid RFC2821
- violation. [ruby-dev:35487]
-
-Thu Jul 17 21:32:49 2008 Tanaka Akira <akr@fsij.org>
-
- * string.c (rb_str_format_m): make tmp volatile to avoid possible GC
- problem.
-
-Thu Jul 17 21:30:55 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/optparse.rb (OptionParser#environment): requires shellwords.
- [ruby-dev:35466]
-
-Thu Jul 17 02:05:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/xmlrpc/client.rb (XMLRPC::Client#do_rpc): requires
- webrick/cookie. [ ruby-Bugs-21139 ]
-
-Thu Jul 17 01:38:31 2008 Yusuke Endoh <mame@tsg.ne.jp>
-
- * ext/zlib/zlib.c (rb_gzfile_set_mtime): fix typo. [ruby-core:17713]
-
-Sun Jul 13 00:08:16 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/ipaddr.rb (IPAddr#initialize): get rid of ArgumentError in
- IPAddr#to_range. a patch from okkez <okkez000 AT gmail.com> in
- [ruby-dev:35091].
-
-Sun Jul 13 00:04:38 2008 Tanaka Akira <akr@fsij.org>
-
- * configure.in (erfc): erfc of glibc comes with Debian GNU/Linux Etch
- on IA64 is broken. erfc(10000.0) aborts.
- use missing/erf.c instead.
- http://sources.redhat.com/ml/libc-hacker/2005-08/msg00008.html
-
-Thu Jul 10 18:50:48 2008 Tanaka Akira <akr@fsij.org>
-
- * common.mk (SPEC_GIT_BASE): update RubySpec GIT URL.
-
-Thu Jul 10 18:46:28 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (rb_file_s_extname): fix for file name with spaces.
- [ruby-talk:307404]
-
-Thu Jul 10 18:42:37 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/erb.rb (PercentScanner#scan): fix %% line bug. [ruby-core:17491]
-
- * test/erb/test_erb.rb (test_percent): ditto.
-
-Thu Jul 10 18:40:22 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/net/ftp.rb (Net::FTP#sendport): use divmod. [ruby-core:17557]
-
-Thu Jul 10 18:36:53 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * ruby.c: Mac OS X needs origargc times of '\0' in
- origargv. [ruby-dev:35308]
-
-Thu Jul 10 13:53:08 2008 Tanaka Akira <akr@fsij.org>
-
- * include/ruby/ruby.h (POSFIXABLE): use FIXNUM_MAX+1 instead of
- FIXNUM_MAX to make it possible to convert to double accurately.
- It assumes FLT_RADIX is 2.
- fix RubyForge bug #14102.
- backported from 1.9.
-
-Mon Jul 7 16:21:38 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/net/smtp.rb (Net::SMTP::start): use 'localhost' instead of
- 'localhost.localdomain'. [ruby-dev:35333]
-
- * lib/net/smtp.rb (Net::SMTP::SMTP.start): ditto.
-
-Mon Jul 7 15:02:13 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_longjmp): duplicate the thrown exception to set backtrace
- if it was frozen. clear all raised flags.
-
- * eval.c (stack_check): leave clearing flag to rb_longjmp.
-
- * eval.c (rb_thread_set_raised, rb_thread_reset_raised): use generic
- flags.
-
- * eval.c (Init_Proc), gc.c (Init_GC): freeze preallocated special exceptions.
-
- * gc.c (rb_memerror): use thread raised flag instead of static flag,
- and raise nomem_error without backtrace if failed to make backtrace.
- [ruby-dev:34724]
-
- * gc.c (ruby_xmalloc): increase malloc_increase only if malloc
- succeeds. failed malloc size can be huge. it may increase
- malloc_limit too big which cause less GC and memory full.
- (ruby_xrealloc): ditto.
-
-Mon Jul 7 12:23:05 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c: avoid creating Ruby object during
- GC. thanks to arton <artonx AT yahoo.co.jp>. [ruby-dev:35313]
-
- * ext/win32ole/tests: add test_win32ole_event.rb, remove
- testOLEEVENT.rb
-
- * ext/win32ole/tests/testWIN32OLE.rb(test_convert_bignum):
- fix test.
-
-Mon Jul 7 12:23:05 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * gc.c: add rb_during_gc(). based on a patch from arton <artonx AT
- yahoo.co.jp> at [ruby-dev:35313].
-
- * intern.h: ditto.
-
-Thu Jul 3 20:13:20 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * marshal.c (w_object, marshal_dump, r_object0, marshal_load): search
- public methods only. [ruby-core:17283]
-
- * object.c (convert_type): ditto.
-
- * lib/singleton.rb (Singleton#_dump): conversion method should be
- public.
-
-Wed Jul 2 19:06:43 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/cgi.rb (CGI::QueryExtension.read_multipart): blanks inside
- double quotes are allowed. [ruby-list:45140]
-
-Wed Jul 2 19:03:37 2008 Tanaka Akira <akr@fsij.org>
-
- * numeric.c (num_coerce): call rb_Float(x) first. don't depend on
- evaluation order of function arguments.
-
-Wed Jul 2 18:57:19 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/syslog/syslog.c (syslog_write): syslog operations should be
- protected from $SAFE level 4. a patch from Keita Yamaguchi
- <keita.yamaguchi at gmail.com>.
-
- * ext/syslog/syslog.c (mSyslog_close): ditto.
-
- * ext/syslog/syslog.c (mSyslog_set_mask): ditto.
-
-Wed Jul 2 18:26:20 2008 Tanaka Akira <akr@fsij.org>
-
- * math.c (domain_check): fix preprocess condition.
-
-Wed Jul 2 18:22:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/tmpdir.rb (@@systmpdir): prior LOCAL_APPDATA if possible, and
- should be clean. based on a patch from arton <artonx AT
- yahoo.co.jp> at [ruby-dev:35269]
-
-Wed Jul 2 18:16:19 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c (date2time_str): fix the overflow in
- some situation. [ruby-bugs-20793]
-
-Tue Jul 1 15:11:14 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * array.c (rb_ary_fill): check if beg is too big.
-
-Mon Jun 30 20:35:32 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * string.c (str_buf_cat): check for self concatenation.
-
-Sun Jun 29 21:39:54 2008 Tanaka Akira <akr@fsij.org>
-
- * eval.c (rb_obj_respond_to): use RTEST to test the result of
- respond_to? method.
-
-Sun Jun 29 21:20:17 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * array.c (rb_ary_fill): (compatibility) do not raise
- ArgumentError on negative length. This behaviour shall change
- in a future release.
-
-Sun Jun 29 20:08:11 2008 Tanaka Akira <akr@fsij.org>
-
- * time.c (time_timeval): fix rounding negative float.
-
-Sun Jun 29 19:19:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/inlinetest.rb (InlineTest.in_progname): workaround for frozen
- $0. [ruby-dev:35261]
-
- * lib/test/unit/ui/console/testrunner.rb (TestRunner#finished): ditto.
-
-Sun Jun 29 19:19:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ruby.c (set_arg0, ruby_prog_init): freeze $0. a patch from Keita
- Yamaguchi <keita.yamaguchi at gmail.com>.
-
-Sun Jun 29 18:33:33 2008 Tanaka Akira <akr@fsij.org>
-
- * process.c: include sys/resource.h if HAVE_SYS_RESOURCE_H is defined.
- pointed by TOYOFUKU Chikanobu. [ruby-dev:35258]
-
-Sun Jun 29 18:26:01 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * variable.c (rb_f_trace_var): should not be allowed at safe level 4.
- a patch from Keita Yamaguchi <keita.yamaguchi at gmail.com>.
-
- * eval.c (rb_call0): wrong condition to check insecure method.
- a patch from Keita Yamaguchi <keita.yamaguchi at gmail.com>.
-
-Sun Jun 29 18:22:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * array.c (rb_ary_fill): not depend on unspecified behavior at integer
- overflow. reported by Vincenzo Iozzo <snagg AT openssl.it>.
-
-Sun Jun 29 18:22:06 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c(ole_invoke): fix memory leak.
- [ruby-bugs-20792]
-
-Sun Jun 29 18:19:11 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (PUSH_FRAME, PUSH_CLASS): Add volatile to avoid a
- possible optimization bug on OS X/PPC. This at least makes
- build with gcc -O1 and `make test' pass.
-
-Sun Jun 29 17:24:43 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/rdoc/parsers/parse_rb.rb (RDoc#collect_first_comment): skip
- magic comment.
-
-Sun Jun 29 17:22:09 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/stringio/stringio.c (strio_each, strio_readlines): IO#each and
- IO#readlines do not affect $_. [ruby-core:17277]
-
-Sun Jun 29 17:19:59 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/stringio/stringio.c (strio_readline, strio_each)
- (strio_readlines): set lastline. [ruby-core:17257]
-
-Sun Jun 29 17:15:49 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/openssl/ossl.h: include winsock.h if USE_WINSOCK2 is not defined.
- a patch from arton <artonx at yahoo.co.jp> in [ruby-dev:35078]
-
-Sun Jun 29 17:09:48 2008 wanabe <s.wanabe@gmail.com>
-
- * util.c (ruby_strtod): ruby_strtod don't allow a trailing
- decimal point like "7.". [ruby-dev:34835] [ruby-dev:35009]
-
-Sat Jun 28 19:23:40 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * class.c (clone_method): use rb_copy_node_scope.
- fixed [ruby-list:45102]
- fixed [ruby-core:17393]
-
-Sat Jun 28 18:49:50 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * class.c: revert to r15855.
-
-Fri Jun 20 18:25:18 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * string.c (rb_str_buf_append): should infect.
-
-Fri Jun 20 16:33:09 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * array.c (rb_ary_store, rb_ary_splice): not depend on unspecified
- behavior at integer overflow.
-
- * string.c (str_buf_cat): ditto.
-
-Wed Jun 18 22:24:46 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * array.c (ary_new, rb_ary_initialize, rb_ary_store,
- rb_ary_aplice, rb_ary_times): integer overflows should be
- checked. based on patches from Drew Yao <ayao at apple.com>
- fixed CVE-2008-2726
-
- * string.c (rb_str_buf_append): fixed unsafe use of alloca,
- which led memory corruption. based on a patch from Drew Yao
- <ayao at apple.com> fixed CVE-2008-2726
-
- * sprintf.c (rb_str_format): backported from trunk.
-
- * intern.h: ditto.
-
-Tue Jun 17 15:09:46 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (file_expand_path): no need to expand root path which has no
- short file name. [ruby-dev:35095]
-
-Sun Jun 15 19:27:40 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * configure.in: Fix $LOAD_PATH. Properly expand vendor_ruby
- directories; submitted by Takahiro Kambe <taca at
- back-street.net> in [ruby-dev:35099].
-
-Mon Jun 9 17:56:30 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/set.rb (Set#delete_if): Call to_a.
- (SortedSet#delete_if, TC_SortedSet#test_sortedset): Use super to
- yield elements in sorted order; [ruby-core:17144] by Arthur
- Schreiber.
- (SortedSet#each, SortedSet#each, TC_Set#test_each)
- (TC_SortedSet#test_sortedset): Return self; [ruby-dev:35002] by
- Arthur Schreiber.
-
-Mon Jun 9 03:28:05 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/zlib/zlib.c (rb_deflate_initialize, Init_zlib): Fix up
- initialize_copy; [ruby-list:45016], [ruby-list:45018].
-
-Mon Jun 9 03:26:03 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * NEWS: Mention new constants.
-
-Mon Jun 9 03:24:18 2008 Tanaka Akira <akr@fsij.org>
-
- * hash.c (hash_i): make Hash#hash order insensitive.
-
-Mon Jun 9 03:22:43 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (VENDOR_DIR): use LIBDIR instead of PREFIX as well as
- SITE_DIR. a patch from Richard Brown <rbrown AT exherbo.org> in
- [ruby-core:17129].
-
-Mon Jun 9 03:21:20 2008 Tanaka Akira <akr@fsij.org>
-
- * gc.c (os_obj_of): assure to not free the scanning heap.
-
-Mon Jun 9 03:20:12 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * io.c (rb_open_file, rb_io_s_sysopen): fmode should be unsigned int.
- fixed [ruby-dev:34979]
-
-Fri Jun 6 21:16:55 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/Makefile.sub (COMMON_HEADERS): include ws2tcpip.h.
-
- * ext/socket/addrinfo.h (addrinfo, getaddrinfo, getnameinfo,
- freehostent, freeaddrinfo): undef before define because these are
- macros in some versions of Windows SDK.
-
- * win32/setup.mak: maybe commit miss.
-
-Fri Jun 6 19:34:22 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * mkconfig.rb: hide build path from rbconfig.rb.
-
- * util.c (ruby_strtod, dtoa): initialize more variables for error
- handling.
-
- * io.c (rscheck), marshal.c (w_nbyte, w_bytes, w_unique),
- (path2class, path2module): constified.
-
- * pack.c (pack_unpack), process.c (rb_syswait): suppress warnings.
-
- * suppress warnings on cygwin, mingw and mswin.
-
-Fri Jun 6 19:23:53 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (file_expand_path): fix for non-existent files and SFN of
- symlinks. [ruby-talk:303736]
-
-Fri Jun 6 18:25:43 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/iconv: Tests fixed.
-
-Fri Jun 6 17:04:56 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * win32/win32.h: include ws2tcpip.h. fixed [ruby-Bugs-20528]
-
- * lib/time.rb (Time.xmlschema): don't use float. fix
- http://rubyforge.org/tracker/index.php?func=detail&group_id=426&atid=1698&aid=20504
-
- * object.c (rb_obj_alloc): RDoc updated. a patch from Gaston
- Ramos <ramos.gaston at gmail.com> in [ruby-core:17073].
-
- * lib/rdoc.rb: massive spelling correction patch from Evan Farrar
- <evanfarrar at gmail.com> in [ruby-doc:1382] applied.
-
- * ext/openssl/ossl_ssl_session.c (ossl_ssl_session_initialize):
- Add a null check for ssl; submitted by akira yamada
- in [ruby-dev:34950].
-
- * ext/openssl/ossl_ssl.c (Init_ossl_ssl): Define OP_NO_TICKET if
- SSL_OP_NO_TICKET is present; submitted by akira yamada
- in [ruby-dev:34944].
-
- * test/openssl/test_ssl.rb (OpenSSL#test_server_session): Add a
- workaround for the case where OpenSSL is configured with
- --enable-tlsext; submitted by akira yamada in [ruby-dev:34944].
-
-Fri Jun 6 16:58:23 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/iconv/iconv.c (iconv_iconv): fix for length argument and now
- allows range. [ruby-core:17092] [ruby-core:17115]
-
-Wed Jun 4 17:22:30 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * NEWS: Fix typos and move misplaced entries.
- NEWS: Somehow optflags and warnflags were not actually included
- in this release.
-
-Tue Jun 3 19:33:22 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enumerator.c (enumerator_init_copy): Take care of
- initialize_copy as well as initialize.
-
- * test/ruby/test_enumerator.rb: Pull in the test suite for
- enumerator from trunk.
-
-Tue Jun 3 12:51:57 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enumerator.c (enumerator_allocate, enumerator_ptr): Properly
- detect if the object is initialized and raise error when
- appropriate.
- (enumerator_initialize): Fix a typo in rdoc. [ruby-core:17052]
-
-Tue Jun 3 10:16:40 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/erb.rb (ERB::Compiler::TrimScanner#scan_line): Fix a bug
- where tokens are not yilelded one by one.
- (ERB::Compiler::TrimScanner#explicit_trim_line): Fix without-
- strscan problems. [ruby_core:17028].
-
- * test/erb/test_erb.rb (TestERBCore#_test_01)
- (TestERBCore#test_02_safe_04): The expected value should come
- first for assert_equal().
- (TestERBCoreWOStrScan): Add test class for without-strscan.
-
-Mon Jun 2 19:47:16 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/delegate.rb (DelegateClass, Delegator#respond_to?):
- respond_to? must take optional second argument. This was a
- latent bug exposed by a recent internal change of marshal.c to
- call respond_to? with a second argument; submitted by Jeremy
- Kemper <jeremy at bitsweat.net> in [ruby-core:17045].
-
-Sat May 31 23:53:35 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * .: Release as Ruby 1.8.7.
-
-Sat May 31 23:33:34 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * README, README.ja: Add a note about default C flags.
-
-Sat May 31 22:11:15 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * version.c (ruby_description, ruby_copyright): backported from
- 1.9. bug#19002, [ruby-dev:34883]
-
- * error.c (report_bug): uses ruby_description.
-
-Sat May 31 20:56:04 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_delete_if): should return enumerator if no block
- is given. [ruby-dev:34901]
-
-Sat May 31 18:28:17 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * suppress warnings with -Wwrite-string.
-
-Sat May 31 15:58:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * Makefile.in, configure.in (warnflags): defaulted to -Wall
- -Wno-parentheses with gcc. [ruby-dev:34810]
-
-Fri May 30 05:28:18 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * enum.c (count_i, count_iter_i, count_all_i): add prototypes for VC.
-
-Fri May 30 04:32:07 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enum.c (count_i, count_iter_i): Sync with trunk.
- enum.c (enum_count, count_all_i, Init_Enumerable),
- array.c (rb_ary_count): Sync with trunk. If no argument or
- block is given, count the number of all elements.
-
-Fri May 30 03:12:18 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/openssl/ossl_bn.c (ossl_bn_s_rand, ossl_bn_s_pseudo_rand):
- Int should be enough here.
-
-Fri May 30 02:35:00 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/openssl/ossl_bn.c (ossl_bn_s_rand, ossl_bn_s_pseudo_rand),
- ext/openssl/ossl_pkey_dh.c (ossl_dh_s_generate)
- (ossl_dh_initialize),
- ext/openssl/ossl_pkey_dsa.c (ossl_dsa_s_generate),
- ext/openssl/ossl_rand.c (ossl_rand_bytes)
- (ossl_rand_pseudo_bytes, ossl_rand_egd_bytes),
- ext/openssl/ossl_x509store.c (ossl_x509stctx_set_error): Do not
- use FIX2INT() without checking the value type. Use NUM2INT()
- instead; found by akr in [ruby-dev:34890].
-
-Thu May 29 20:07:45 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * configure.in, win32/Makefile.sub, mkconfig.rb, instruby.rb,
- ruby.c, lib/mkmf.rb, README.EXT, README.EXT.ja: Backport the
- vendor_ruby directory support.
-
-Thu May 29 17:52:31 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/zlib/extconf.rb: search zlib1, and regard mswin32 later than VC6
- as WIN32. [ruby-core:16984]
-
-Wed May 28 17:54:29 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * string.c (rb_str_start_with): Remove an unused variable.
- (rb_str_upto_m): Fix a prototype.
-
-Wed May 28 17:48:28 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * range.c (range_step): Fix brokenness when a non-integer numeric
- value is specified as step. [rubyspec]
- (range_step): Make use of String#step internally if a string (or
- string-alike) range is given.
-
- * string.c (rb_str_upto_m, Init_String): Add an optional second
- argument to specify if the last value should be included.
-
-Wed May 28 16:53:39 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_slice_bang): Call rb_ary_modify_check() at the
- beginning. [rubyspec]
-
-Wed May 28 16:12:44 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/webrick/httpservlet/cgihandler.rb (WEBrick::HTTPServlet::CGIHandler#do_GET):
- Set the HTTP status code to 302 if a Location header field is
- present and the status code is not valid as a client
- redirection. cf. RFC 3875 6.2.3, 6.2.4.
-
-Wed May 28 15:18:16 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/singleton.rb (SingletonClassMethods): _load should be public.
-
-Wed May 28 12:52:41 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * marshal.c (w_object, marshal_dump, r_object0, marshal_load): search
- private methods too. [ruby-dev:34671]
-
- * object.c (convert_type): ditto.
-
-Tue May 27 23:26:49 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * error.c (rb_bug): description from rb_bug() should include
- patchlevel. [ruby-dev:34826]
-
-Tue May 27 20:19:22 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_slice_bang): Return an empty array instead of
- nil when pos is valid and len is adjusted from a valid value to
- zero; caught by RubySpec.
-
-Tue May 27 19:45:20 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * numeric.c (flo_divmod): Revert the behavior change; do not
- suppress an exception when div is NaN or Inf. [ruby-dev:34857]
-
-Tue May 27 19:24:40 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enum.c (enum_to_a): Pass arguments through to #each().
- (enum_sort): Follow the enum_to_a signature change.
- (enum_reverse_each): Add #reverse_each().
-
-Tue May 27 18:54:02 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/stringio/stringio.c (strio_each_char, Init_stringio): Add
- StringIO#{each_char,chars}.
-
-Tue May 27 17:59:34 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/stringio/stringio.c (strio_each): Return an enumerator if no
- block is given.
- (strio_each_byte): Return an enumerator if no block is given,
- and return self if one is given as the rdoc says.
-
- * io.c (rb_io_each_byte): Fix rdoc. IO#each_byte returns self,
- not nil.
-
-Tue May 27 16:02:58 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (rb_mod_module_exec, Init_eval): Add
- Module#{module_exec,class_exec}.
-
-Tue May 27 15:36:37 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * io.c (rb_io_each_char, argf_each_char, Init_IO):
- Add {IO#,ARGF.}{each_char,chars}.
-
-Tue May 27 13:46:52 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/stringio/stringio.c (Init_stringio): Define
- StringIO#{getbyte,readbyte}.
-
-Tue May 27 13:38:51 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * io.c (Init_IO): Define {IO#,ARGF.}{getbyte,readbyte}.
-
-Tue May 27 13:26:15 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/stringio/stringio.c (Init_stringio): Define #bytes and
- #lines.
-
-Tue May 27 13:20:35 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * io.c: (rb_io_lines, rb_io_bytes, Init_IO): Define
- IO#{lines,bytes} and ARGF.{lines,bytes}.
-
-Tue May 27 12:13:17 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * file.c (BUFCHECK): wrong condition. [ruby-core:16921]
-
- * file.c (file_expand_buf): shouldn't use buflen for length of string.
-
-Mon May 26 18:24:48 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (BUFCHECK): no resize if enough room.
-
- * file.c (file_expand_path): use BUFCHECK.
-
-Mon May 26 16:46:19 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * file.c (ntfs_tail): filename which starts with '.' is valid.
-
- * file.c (file_expand_path): cygwin symlink support.
-
-Mon May 26 12:16:43 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * .: Release as Ruby 1.8.7-preview4.
-
-Mon May 26 12:12:26 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * marshal.c (dump_ensure, load_ensure): should return values.
-
- * eval.c (yield_under, yield_under_i, yield_args_under_i)
- (specific_eval, rb_obj_instance_exec, Init_eval): Implement
- Object#instance_exec(), a 1.9 feature.
-
-Mon May 26 11:53:21 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (rb_yield_0, proc_invoke, proc_arity): allow passing a
- block to a Proc. [ruby-dev:23533]; by nobu; backported from
- 1.9. This implementation in current shape is known to be
- buggy/broken, especially with nested block invocation. Take
- this as an experimental feature.
-
- * parse.y (block_par, block_var): ditto.
-
-Mon May 26 08:00:52 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * marshal.c (r_object0, Init_marshal): Fix the garbled s_call
- definition; fixes [ruby-dev:34843].
-
-Mon May 26 03:16:20 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * hash.c (rb_hash_default): Fix rdoc.
- (rb_hash_each, env_each_value, env_each_pair): Return an
- enumerator if no block is given.
- (rb_hash_update): Update rdoc.
- (envix): Conditionalize the definition itself.
- (rb_f_getenv, env_fetch, env_keys, env_values, env_values_at)
- (env_select, env_inspect, env_to_a, env_empty_p, env_has_key)
- (env_has_value, env_index, env_indexes, env_to_hash, env_shift)
- (env_update): Require secure level 4.
- (env_each_value, env_each_i): Delay variable initialization.
- (env_each_key, env_each_value, env_reject_bang)
- (env_clear, env_replace): Omit duplicated secure level check.
- (env_has_value): Do to_str conversion.
-
-Sun May 25 19:48:12 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * hash.c (env_delete_if): Return an enumerator if no block is
- given.
- (env_each_key): Delay a variable initialization after
- RETURN_ENUMERATOR().
-
-Sun May 25 05:07:19 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_slice_bang): Be consistent with Array#slice()
- and String#slice!(). Just return nil when a negative length or
- out of boundary index is given instead of raising an exception
- via internal functions.
- (rb_ary_slice_bang): should not use rb_ary_subseq() which shares
- internal pointer. splice modifies the receiver right after
- subseq. [ruby-dev:34005]
- (rb_ary_slice_bang): should adjust length before making
- sub-array.
-
- * enumerator.c (Init_Enumerator): Override
- Enumerable::Enumerator#each_with_index with #with_index.
-
-Sun May 25 03:13:09 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (Init_Thread): Initialize recursive_key.
-
-Sun May 25 02:45:49 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * error.c (syserr_eqq): Use en.
-
-Sat May 24 22:32:49 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (rb_cstr_to_dbl): should clear errno before calling
- strtod(3). [ruby-dev:34834]
-
-Sat May 24 22:27:44 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * marshal.c (marshal_load): should initialize arg.data used for
- reentrant check. [ruby-dev:34837]
-
-Sat May 24 00:34:59 2008 Tanaka Akira <akr@fsij.org>
-
- * lib/rational.rb (Rational#to_i): fix rdoc. Rational(-7,4).to_i
- should be -1.
-
-Fri May 23 20:22:44 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * marshal.c (reentrant_check): check reentrance via callcc.
- [ruby-dev:34802]
-
-Fri May 23 16:46:28 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enumerator.c (proc_call): Remove an unused static function.
-
-Fri May 23 13:46:09 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (cflags): commit miss.
-
-Fri May 23 09:52:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (MINIRUBY), common.mk (RUBYOPT): add purelib.rb.
- [ruby-core:16642]
-
- * ext/extmk.rb: load purelib.rb only when not cross compiling.
-
-Fri May 23 08:47:02 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * error.c (syserr_eqq): === should be able to handle delegated
- objects as well.
-
-Fri May 23 04:22:19 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/tcltklib.c, ext/tk/tkutil/tkutil.c: fix memory leak.
-
- * ext/tk/lib/tk.rb: avoid trouble when finalize TclTkIp.
-
- * ext/tk/lib/tk.rb, ext/tk/lib/tk/*: help to fix troubles when
- use Ttk widgets on old Tk scripts.
-
- * ext/tk/sample/*: update and add demo scripts. some of them are
- introduction about new features of Tcl/Tk8.5.
-
-Fri May 23 03:48:10 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * class.c (clone_method): Just use ruby_cref as cref.
-
-Fri May 23 01:03:23 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * class.c (rb_singleton_class_clone): Pass Qnil, not 0.
-
-Fri May 23 00:51:48 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * class.c (clone_method): Totally revamp the previous fix which
- was incorrect.
- (rb_mod_init_copy): Ditto.
- (singleton_class_clone_int): Ditto.
-
-Fri May 23 00:48:10 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (rb_copy_node_scope), node.h: Rename from copy_node_scope
- and export.
-
-Thu May 22 21:24:15 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (top_local_setup): fixed memory leak bug based on a
- patch from Roger Pack <rogerpack2005 at gmail.com> in
- [ruby-core:16610].
-
-Thu May 22 14:20:54 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * array.c (flatten): check if reentered. [ruby-dev:34798]
-
-Thu May 22 08:28:49 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * array.c (flatten): free memo hash table before raising exception.
- [ruby-dev:34789]
-
-Thu May 22 06:30:10 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * array.c (flatten): fix memory leak.
-
-Thu May 22 05:45:30 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * proc.c (proc_dup): should copy safe_level from src proc
- properly. a patch from Keita Yamaguchi
- <keita.yamaguchi at gmail.com>
-
-Wed May 21 23:31:44 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_get_method_body, rb_alias, rb_eval): should not cache
- uninitialized value, since search_method doesn't set origin if the
- method wasn't found.
-
- * eval.c (search_method, remove_method, error_print, rb_alias)
- (rb_eval, rb_rescue2, search_required, Init_eval, rb_thread_create),
- gc.c (rb_source_filename, Init_stack), io.c (rb_io_getline),
- parse.y (rb_id2name, rb_parser_free): suppress warnings.
-
-Wed May 21 12:34:51 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * hash.c (rb_hash_delete): rdoc fix based on a patch from Gaston Ramos
- <ramos.gaston AT gmail.com>. [ruby-core:16825]
-
-Tue May 20 13:15:46 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * file.c (lchmod_internal): Remove a compiler warning.
-
-Mon May 19 18:22:35 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/openssl/ossl_pkcs5.c (ossl_pkcs5_pbkdf2_hmac): Fix the type
- of md; pointed out by Takahiro Kambe <taca at back-street.net>
- in [ruby-dev:34748].
-
-Mon May 19 14:20:13 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * sprintf.c (rb_f_sprintf): fixed SEGV on win32 with "% 0e" % 1.0/0.0.
-
-Mon May 19 13:29:58 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * process.c (rb_f_system): set last_status when status == -1 because
- there is no path to set it on win32. this patch is derived from
- [ruby-core:16787], submitted by Luis Lavena <luislavena at gmail.com>
-
-Mon May 19 13:01:05 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * common.mk ({MSPEC,RUBYSPEC}_GIT_URL): moved from Makefine.in.
-
- * {win32,bcc32}/Makefile.sub (update-rubyspec): added.
-
-Mon May 19 11:53:45 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/openssl/openssl_missing.c (HMAC_CTX_copy): adopted
- prototype change in openssl bundled with newer OpenBSD.
- a patch from Takahiro Kambe <taca at back-street.net> in
- [ruby-dev:34691].
-
-Mon May 19 06:36:37 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * .: Release as Ruby 1.8.7-preview3.
-
-Sun May 18 22:26:51 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/httpservlet/filehandler.rb: should normalize path
- name in path_info to prevent script disclosure vulnerability on
- DOSISH filesystems. (fix: CVE-2008-1891)
- Note: NTFS/FAT filesystem should not be published by the platforms
- other than Windows. Pathname interpretation (including short
- filename) is less than perfect.
-
- * lib/webrick/httpservlet/abstract.rb
- (WEBrick::HTTPServlet::AbstracServlet#redirect_to_directory_uri):
- should escape the value of Location: header.
-
- * lib/webrick/httpservlet/cgi_runner.rb: accept interpreter
- command line arguments.
-
-Sat May 17 23:53:57 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (file_expand_path): fix for short file name on Cygwin.
-
-Sat May 17 11:29:11 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (rb_file_s_extname): first dot is not an extension name.
-
-Sat May 17 10:18:44 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * re.c (rb_reg_search): need to free allocated buffer in re_register.
-
-Fri May 16 17:01:44 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/Makefile.sub (test-rubyspec): added.
-
-Fri May 16 16:22:40 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/tcltklib.c: sometimes freeze when receive Interrupt signal.
-
-Fri May 16 14:54:56 2008 Tanaka Akira <akr@fsij.org>
-
- * Makefile.in (update-rubyspec): move rubyspec to srcdir.
- (test-rubyspec): ditto.
-
-Fri May 16 14:25:22 2008 Tanaka Akira <akr@fsij.org>
-
- * Makefile.in (test-rubyspec): use RUNRUBY. suggested by nobu.
-
-Fri May 16 13:01:43 2008 Tanaka Akira <akr@fsij.org>
-
- * Makefile.in (update-rubyspec): new target to download rubyspec.
- (test-rubyspec): new target to run rubyspec. this doesn't work
- before install.
-
-Fri May 16 08:15:52 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk.rb: fix memory (object) leak bug.
-
- * ext/tk/sample/demos-jp/aniwave.rb, ext/tk/sample/demos-en/aniwave.rb:
- bug fix.
-
-Thu May 15 17:00:22 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * string.c (Init_String): Define #bytesize as an alias for #size
- for compatibility with 1.9.
-
-Thu May 15 15:33:59 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (file_expand_path): support for alternative data stream
- and ignored trailing garbages of NTFS.
-
- * file.c (rb_file_s_basename): ditto.
-
- * file.c (rb_file_s_extname): ditto.
-
-Wed May 14 19:24:59 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_count): Override Enumerable#count for better
- performance.
- (rb_ary_nitems): Undo the backport. Use #count {} instead.
-
- * enumerator.c (enumerator_iter_i): Remove an unused function.
- (enumerator_with_index, enumerator_each): Remove unused
- variables.
-
-Wed May 14 17:15:11 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/tk/tkutil/extronf.rb: check stdndup() because it's not standard
- function of C.
-
- * ext/tk/tkutil/tkutil.c (cbsubst_table_setup): use malloc() and
- strncpy() instead of strndup() if not available.
-
-Wed May 14 09:52:02 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/tkutil/tkutil.c: improve handling callback-subst-keys.
- Now, support longnam-keys (e.g. '%CTT' on tkdnd-2.0; however, still
- not support tkdnd-2.0 on tkextlib), and symbols of parameters (e.g.
- :widget=>'%W', :keycode=>'%k', '%x'=>:x, '%X'=>:root_x, and so on;
- those are attributes of event object). It means that Ruby/Tk accepts
- not only "widget.bind(ev, '%W', '%k', ...){|w, k, ...| ... }", but
- also "widget.bind(ev, :widget, :keycode, ...){|w, k, ...| ... }".
- It is potentially incompatible, when user passes symbols to the
- arguments of the callback block (the block receives the symbols as
- strings). I think that is very rare case (probably, used by Ruby/Tk
- experts only). When causes such trouble, please give strings instead
- of such symbol parameters (e.g. call Symbol#to_s method).
-
- * ext/tk/lib/tk/event.rb, ext/tk/lib/tk/validation.rb,
- ext/tk/lib/tkextlib/blt/treeview.rb,
- ext/tk/lib/tkextlib/winico/winico.rb: ditto.
-
- * ext/tk/tkutil/tkutil.c: strings are available on subst_tables on
- TkUtil::CallbackSubst class (it is useful on Ruby 1.9).
-
- * ext/tk/lib/tk/spinbox.rb, ext/tk/lib/tkextlib/iwidgets/hierarchy.rb,
- ext/tk/lib/tkextlib/iwidgets/spinner.rb,
- ext/tk/lib/tkextlib/iwidgets/entryfield.rb,
- ext/tk/lib/tkextlib/iwidgets/calendar.rb,
- ext/tk/lib/tkextlib/blt/dragdrop.rb,
- ext/tk/lib/tkextlib/tkDND/tkdnd.rb,
- ext/tk/lib/tkextlib/treectrl/tktreectrl.rb,
- ext/tk/lib/tkextlib/tktable/tktable.rb: disable code piece became
- unnecessary by reason of the changes of ext/tk/tkutil/tkutil.c.
-
-Tue May 13 15:10:50 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enumerator.c: Update rdoc.
- (enumerator_initialize): Discourage the use.
- (enum_each_slice, enum_each_cons, enumerator_each)
- (enumerator_with_index): Add a note about a call without a block.
-
- * NEWS: Intentionally omit enum_slice and enum_cons, which are
- removed in 1.9.
-
-Tue May 13 07:56:36 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * string.c (rb_str_cat): fixed buffer overrun reported by
- Christopher Thompson <cthompson at nexopia.com> in [ruby-core:16746]
-
-Mon May 12 13:57:19 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (is_defined): add NODE_OP_ASGN_{OR,AND}. "defined?(a||=1)"
- should not operate assignment. [ruby-dev:34645]
-
-Mon May 12 12:59:23 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk/wm.rb: Wm#overrideredirect overwrites arguemnt to
- an invalid value.
-
- * ext/tk/sample/ttk_wrapper.rb: support "if __FILE__ == $0" idiom.
-
-Mon May 12 12:36:55 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (rb_w32_select): backport from trunk.
- [ruby-talk:300743]
-
-Mon May 12 12:33:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * common.mk (RUBYLIB, RUBYOPT): clear.
-
-Mon May 12 10:41:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/delegate.rb (SimpleDelegator::dup): removed needless argument.
- [ruby-list:44910]
-
- * lib/delegate.rb (clone, dup): keep relationship with the target
- object.
-
-Sun May 11 23:19:39 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * enum.c (all_iter_i, any_iter_i): reduced duplicated code.
-
-Sun May 11 17:57:36 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (MINIRUBY): should not include extension library path.
-
-Sun May 11 10:36:10 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * eval.c (method_name, method_owner): New methods; backported
- from 1.9. (UnboundMethod#name, UnboundMethod#owner)
-
-Sun May 11 02:48:13 2008 <nagai@orca16.orcabay.ddo.jp>
-
- * ext/tk/lib/tk/pack.rb, ext/tk/lib/tk/grid.rb: fail to do pack/grid
- without options.
-
- * ext/tk/lib/tk.rb: add TkWindow#grid_anchor, grid_column, grid_row.
-
-Sat May 10 18:19:16 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * string.c (rb_str_each_line): RDoc updated. [ruby-dev:34586]
-
-Sat May 10 13:17:56 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk/pack.rb, ext/tk/lib/tk/grid.rb: increase supported
- parameter patterns of configure method.
-
-Sat May 10 09:16:13 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * util.c (ruby_strtod): backported from 1.9. a patch from Satoshi
- Nakagawa <psychs at limechat.net> in [ruby-dev:34625].
- fixed: [ruby-dev:34623]
-
-Fri May 9 23:33:25 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk/wm.rb: methods of Tk::Wm_for_General module cannot
- pass the given block to methods of Tk::Wm module.
-
- * ext/tk/lib/tk/grid.rb: lack of module-method definitions.
-
- * ext/tk/lib/tkextlib/tile.rb: lack of autoload definitions.
-
- * ext/tk/lib/tkextlib/tile/tnotebook.rb: cannot use kanji (not UTF-8)
- characters for headings.
-
- * ext/tk/tcltklib.c: maybe a little more stable about @encoding value
- of TclTkIp object.
-
-Wed May 7 08:46:44 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * struct.c (rb_struct_s_def): to_str should be called only once.
- [ruby-core:16647]
-
-Wed May 7 00:54:25 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/zlib/zlib.c (gzreader_gets): may cause infinite loop.
- a patch from Kouya <kouyataifu4 at gmail.com> in
- [ruby-reference-manual:762].
-
-Sun May 4 09:35:51 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * sample/erb/erb4html.rb (ERB4Html) : add example of ERB#set_eoutvar.
- ERB4Html is an auto-quote ERB.
-
-Sat May 3 22:52:48 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tkextlib/tile.rb, ext/tk/lib/tkextlib/tile/style.rb,
- ext/tk/sample/ttk_wrapper.rb: improve treating and control themes.
- add Tk::Tile.themes and Tk::Tile.set_theme(theme).
-
-Fri May 2 14:52:33 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * misc/ruby-mode.el: move fontifying code from hook. a patch from
- Phil Hagelberg <phil at hagelb.org> in [ruby-core:16636].
-
-Fri May 2 13:47:51 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * re.c (match_select): restore previous behavior of MatchData#select.
- RDoc updated as well, mentioning the plan to remove this method
- in the future. [ruby-dev:34556]
-
-Fri May 2 13:04:04 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/dbm/dbm.c (Init_dbm): defines DBM::VERSION even when
- DB_VERSION_STRING is not available. [ruby-dev:34569]
-
-Thu May 1 23:57:06 2008 James Edward Gray II <jeg2@ruby-lang.org>
-
- Merged 16257 from trunk.
-
- * lib/net/telnet.rb: This patch from Brian Candler adds a FailEOF mode which
- can be activated to have net/telnet raise EOFError exceptions when the
- remote connection is closed. The default behavior remains unchanged though.
-
-Thu May 1 23:43:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * range.c (range_step): check if step can be converted to an integer.
- [ruby-dev:34558]
-
- * range.c (range_step): allow float step bigger than zero but less
- than one. [ruby-dev:34557]
-
-Wed Apr 30 20:22:40 2008 James Edward Gray II <jeg2@ruby-lang.org>
-
- Merged 16241 from trunk.
-
- * lib/net/telnet.rb: Fixing a bug where line endings would not be properly
- escaped when the two character ending was broken up into separate TCP
- packets. Issue reported and patched by Brian Candler.
-
-Wed Apr 30 17:47:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * re.c (rb_reg_search): use local variable. a patch from wanabe
- <s.wanabe AT gmail.com> in [ruby-dev:34537]. [ruby-dev:34492]
-
-Sat Apr 26 19:40:34 2008 Guy Decoux <decoux@moulon.inra.fr>
-
- * class.c (struct clone_method_data): Add cref.
- (clone_method): Properly handle NODE_BMETHOD and NODE_DMETHOD.
- (rb_singleton_class_clone, singleton_class_clone_int): Set a
- proper value to klass and propagate cref. [ruby-core:16238]
-
- * eval.c (rb_block_dup, rb_method_dup), intern.h: Add duplicator
- methods for use from class.c#clone_method().
-
-Fri Apr 25 15:46:37 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk.rb, ext/tk/lib/tk/scrollbar.rb, ext/tk/lib/tk/scale.rb:
- improve unknonw-option check when create a widget.
-
- * ext/tk/lib/tkextlib/blt/unix_dnd.rb, ext/tk/lib/tkextlib/blt/ted.rb,
- ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: bug fix on 'cget'.
-
- * ext/tk/lib/tk/menuspec.rb: option check will fail when
- TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ is true.
-
- * ext/tk/lib/tk/palette.rb: bug fix.
-
-Fri Apr 25 12:37:54 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * array.c (flatten): returns an instance of same class.
- [ruby-core:16554]
-
-Thu Apr 24 23:47:50 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * lib/net/pop.rb: backported from 1.9. bug#19003
-
- * ext/openssl/lib/openssl/ssl.rb: set_params; backported from 1.9.
- bug#19552, [ruby-dev:34402]
-
- * ext/openssl/ossl_ssl.c: ditto.
-
- * test/openssl/test_ssl.rb: ditto.
-
-Thu Apr 24 17:06:34 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (THREAD_SAVE_CONTEXT): remove unnecessary
- FLUSH_REGISTER_WINDOWS before calling setjmp(). [ruby-core:16285]
-
-Thu Apr 24 14:15:11 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * dln.c (dln_find_1): prior files with extensions to files sans
- extensions. [ruby-core:16517]
-
-Wed Apr 23 15:39:31 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (bind_eval): Add Binding#eval, a shorthand method for
- eval(str, binding, ..); backported from 1.9.
-
-Wed Apr 23 15:28:52 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * test/gdbm/test_gdbm.rb (TestGDBM#test_s_open_no_create): failed
- notice moved from comment to assertion message. [ruby-dev:29127]
-
-Wed Apr 23 14:00:05 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/mkmf.rb (create_makefile): Add a missing dependency on the
- target directory for each .rb file. This will hopefully fix
- parallel make (-jN). Tested on FreeBSD.
-
-Wed Apr 23 11:49:54 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/set.rb (Set#each, SortedSet#each, TC_Set#test_each): Return
- an enumerator if no block is given.
-
-Wed Apr 23 00:42:49 2008 Tanaka Akira <akr@fsij.org>
-
- * eval.c (error_print): show full stack grace except SystemStackError.
- backport from 1.9. [ruby-dev:31014]
-
-Wed Apr 23 00:18:45 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * test/ruby/test_symbol.rb (TestSymbol#test_to_proc): Improve
- tests of Symbol#to_proc.
-
-Tue Apr 22 22:43:05 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (rb_proc_new, YIELD_FUNC_LAMBDA): Add a new nd_state
- YIELD_FUNC_LAMBDA which avoids automatic `avalue' conversion for
- arguments. This fixes a bug where [1,[2,3]].map(&:object_id)
- fails.
-
- * intern.h, object.c: Hide rb_proc_new() from intern.h. It should
- not be considered an official API function yet.
-
-Tue Apr 22 21:24:32 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (rb_proc_new): Turn the BLOCK_LAMBDA flag on.
-
- * object.c (sym_to_proc), test/ruby/test_symbol.rb: Add back
- Symbol#to_proc, now that it passes the tests.
-
-Tue Apr 22 19:35:03 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enumerator.c (enumerator_initialize): Remove an undocumented
- feature (passing a block to the constructor) that's broken.
- This is not what I intended.
-
-Tue Apr 22 17:49:46 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * sprintf.c (rb_f_sprintf): should protect temporary string from
- GC. [ruby-dev:34480]
-
-Tue Apr 22 17:12:05 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * regex.c (re_search): string might be NULL. [ruby-core:16478]
-
-Tue Apr 22 16:44:00 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * object.c (rb_obj_tap): Correct documentation; pointed out by
- okkez in [ruby-dev:34472].
-
-Tue Apr 22 10:05:51 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * file.c (eaccess): workaround for recent msvcrt's behavior.
- [ruby-core:16460]
-
-Mon Apr 21 16:06:47 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * enumerator.c (enumerator_init): preserve the method name in ID.
-
- * enumerator.c (enumerator_each): need not to call rb_to_id().
-
- * enumerator.c (enumerator_with_index): ditto.
-
-Mon Apr 21 17:19:52 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (rb_f_method_name): New gloval function: __method__;
- backported from matzruby / 1.9.
-
- * eval.c (rb_frame_this_func), intern.h: New internal function.
-
- * intern.h (RETURN_ENUMERATOR): Use rb_frame_this_func() instead
- of rb_frame_last_func(), to accommodate the behavior to that of
- 1.9.
-
-Mon Apr 21 15:54:48 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/tempfile.rb (Tempfile::_close): check @data before modifying
- it; backported from 1.9. [ruby-dev:34094]
-
- * lib/tempfile.rb (Tempfile::close): clear @data and @tmpname.
-
-Mon Apr 21 10:17:17 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * time.c: should include <errno.h> to refer errno.
-
-Mon Apr 21 10:02:43 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * hash.c (recursive_hash): prototype.
-
-Mon Apr 21 10:00:51 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * time.c (rb_strftime): check errno to detect strftime(3)'s error.
- this is workaround for recent version of MSVCRT.
- [ruby-dev:34456]
-
-Sun Apr 20 21:10:04 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * .: Release as Ruby 1.8.7-preview2.
-
-Sun Apr 20 21:02:06 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enumerator.c: Resolve the method every time an enumeration
- method is run, not once when the enumerator is initialized as it
- was before, so that method_missing() and method (re)definition
- afterwards are both in effect; pointed out in: [ruby-core:16441]
-
-Sun Apr 20 17:59:25 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * object.c, NEWS, test/ruby/test_symbol.rb: Revert Symbol#to_proc
- since it does not pass the tests.
-
-Sun Apr 20 14:29:35 2008 Technorama Ltd. <oss-ruby@technorama.net>
-
- * ext/openssl/ossl_ssl.c: initialize session class.
-
-Sat Apr 19 20:54:42 2008 akira yamada <akira@arika.org>
-
- * lib/uri/ftp.rb, lib/uri/generic.rb, test/uri/test_common.rb,
- test/uri/test_ftp.rb, test/uri/test_generic.rb: backported from 1.9.
- [ruby-dev:31318]
-
-Sat Apr 19 20:35:02 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/yaml/baseemitter.rb, lib/yaml/encoding.rb: performance
- tuning around String#gsub.
-
- * lib/yaml/tag.rb: Replace nodoc with stopdoc so Module methods get
- documented.
-
- * lib/yaml/store.rb (YAML::load): modified to support empty
- database.
-
- * lib/yaml/store.rb (YAML::Store::marshal_dump_supports_canonical_option?):
- add a method to support faster PStore.
-
-Sat Apr 19 20:16:52 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/yaml/types.rb: Likewise, pass self to YAML::quick_emit;
- merged from 1.9.
-
- * lib/yaml.rb (quick_emit): use combination of object_id and hash to
- identify repeated object references, since GC will reuse memory of
- objects during output of YAML. [ruby-Bugs-8548] [ruby-Bugs-3698];
- merged from 1.9.
-
-Sat Apr 19 20:05:39 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_equal, rb_ary_eql, rb_ary_hash, rb_ary_cmp):
- Make Array#eql?, #hash, #== and #<=> use rb_exec_recursive() and
- handle recursive data properly.
-
- * hash.c (hash_equal, rb_hash_hash): Make Hash#eql?, #hash and #==
- use rb_exec_recursive() and handle recursive data properly.
-
-Sat Apr 19 19:26:09 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * intern.h, eval.c (rb_exec_recursive): New internal function to
- help perform recursive operation; backported from 1.9.
-
-Sat Apr 19 18:42:04 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * intern.h, hash.c (rb_hash_lookup): New internal function to
- check if a key exists in a hash, ignoring #default; backported
- from 1.9.
-
-Fri Apr 18 18:56:57 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/syck/rubyext.c (syck_genericresolver_node_import): should
- not set instance variable "@kind" before initializing it.
- [ruby-dev:32677]
-
- * ext/syck/rubyext.c (syck_resolver_initialize,
- syck_resolver_detect_implicit, syck_emitter_emit): remove unused
- variables.
-
-Fri Apr 18 18:54:57 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/syck/rubyext.c: Node#value defined twice.
-
- * lib/yaml/: several method redefinitions causing warnings.
-
-Fri Apr 18 16:36:16 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/rexml/node.rb (REXML::Node::indent): should initialize rv
- variable. a patch from Tadayoshi Funaba <tadf AT dotrb.org> in
- [ruby-dev:32783].
-
-Fri Apr 18 16:01:37 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/rexml: Merge fixes since 1.8.6 made solely on the ruby_1_8_6
- branch.
-
-Wed Apr 16 06:11:49 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * test/ruby/test_settracefunc.rb (TestSetTraceFunc#test_event):
- Fix tests to reflect the following changes: r15833, r15759.
-
-Wed Apr 16 05:03:48 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * .: Release as Ruby 1.8.7-preview1.
-
-Wed Apr 16 02:09:14 2008 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/xmlrpc/client.rb: fix cookie handling. [ruby-dev:34403]
-
- * test/xmlrpc/test_cookie.rb: add a test for the above fix.
-
-Tue Apr 15 23:48:28 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * version.h: Branch off ruby_1_8_7 from ruby_1_8 in preparation
- for the forthcoming 1.8.7 release.
-
-Tue Apr 15 23:40:39 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/syck/rubyext.c (rb_syck_mktime): Avoid buffer overflow.
-
-Tue Apr 15 20:32:03 2008 Tanaka Akira <akr@fsij.org>
-
- * re.c (match_inspect): backported from 1.9.
-
-Tue Apr 15 19:03:28 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * eval.c (method_receiver, method_name, method_owner): New
- methods; backported from 1.9. bug#19007
-
-Tue Apr 15 18:39:14 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * lib/uri.rb, lib/uri/ldaps.rb: added LDAPS
- scheme; backported from 1.9. bug#19015, [ruby-dev:31896]
-
-Tue Apr 15 17:45:43 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * lib/net/smtp.rb: backported from 1.9. bug#19003
-
-Tue Apr 15 17:06:12 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * test/ruby/test_symbol.rb (TestSymbol#test_to_proc): add tests.
-
-Tue Apr 15 16:58:55 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk/menuspec.rb: option check will fail when
- TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ is true.
-
- * ext/tk/lib/tk/palette.rb: bug fix.
-
-Tue Apr 15 16:47:48 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * signal.c, gc.c: New methods: GC.stress, GC.stress=;
- backported from 1.9. a patch from Tadashi Saito
- in [ruby-dev:34394] and bug#19000
-
-Tue Apr 15 12:35:44 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * rubyio.h (rb_io_t): renamed from OpenFile.
-
- * ruby.h (struct RHash), file.c, gc.c, io.c, ext/dl/dl.c,
- ext/io/wait/wait.c, ext/pty/pty.c, ext/readline/readline.c,
- ext/socket/socket.c: ditto.
-
- * win32/win32.h: removed workaround for OpenFile.
-
-Tue Apr 15 00:15:29 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk/text.rb: typo. call a wrong method.
-
- * ext/tk/lib/tk/itemconfig.rb: ditto.
-
- * ext/tk/sample/ttk_wrapper.rb: bug fix.
-
- * ext/tk/sample/tktextio.rb: add binding for 'Ctrl-u' at console mode.
-
- * ext/tk/lib/tk.rb, ext/tk/lib/tk/itemfont.rb, ext/tk/lib/font.rb:
- support __IGNORE_UNKNOWN_CONFIGURE_OPTION__ about font options.
-
- * ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb,
- ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb,
- ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb: bug fix.
-
- * ext/tk/lib/tkextlib/tile/tpaned.rb: improve TPaned#add.
-
- * ext/tk/lib/tk/timer.rb: add TkTimer#at_end(proc) to register the
- procedure which called at end of the timer.
-
-Mon Apr 14 19:54:21 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_flatten, rb_ary_flatten_bang): Take an optional
- argument that determines the level of recursion to flatten;
- backported from 1.9.
-
- * array.c (rb_ary_shuffle_bang, rb_ary_shuffle, rb_ary_choice,
- rb_ary_cycle, rb_ary_permutation, rb_ary_combination,
- rb_ary_product, rb_ary_take, rb_ary_take_while, rb_ary_drop,
- rb_ary_drop_while): New methods: Array#shuffle, #shuffle!,
- #choice, #cycle, #permutation, #combination, #product, #take,
- #take_while, #drop, #drop_while; backported from 1.9.
-
-Mon Apr 14 19:52:35 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ruby.h: New macro: RB_GC_GUARD().
-
-Mon Apr 14 19:49:35 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * random.c (rb_genrand_int32, rb_genrand_real), intern.h: Export.
-
- * string.c (rb_str_tmp_new), intern.h: New function.
-
-Mon Apr 14 19:18:55 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * enum.c (inject_i, inject_op_i): prototype.
-
-Mon Apr 14 19:10:47 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enum.c New methods: Enumerable#take, #take_while, #drop and
- #drop_while; backported from 1.9.
-
-Mon Apr 14 18:50:15 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enum.c: New methods: Enumerable#one?, #none?, #minmax, #min_by,
- #max_by, #minmax_by and #cycle; backported from 1.9.
-
- * enum.c (enum_find_index): Add support for find_index(obj);
- [ruby-dev:34313]; backported from 1.9.
-
- * enum.c (enum_inject): Add support for Enumerable#inject(:binop);
- backported from 1.9.
-
- * enum.c: Alias Enumerable#reject to #inject; backported from 1.9.
-
-Mon Apr 14 18:14:19 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enum.c (enum_find, enum_reject): Return an enumerator if no
- block is given; backported from 1.9.
-
- * io.c (rb_io_each_line, rb_io_each_byte, rb_io_s_foreach,
- argf_each_line, argf_each_byte): Ditto.
-
- * string.c (str_gsub): Ditto.
-
-Mon Apr 14 18:10:05 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * enum.c (find_index_i, find_index_iter_i): add prototype for VC.
-
-Mon Apr 14 17:55:30 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_collect_bang, rb_ary_select): Return an
- enumerator if no block is given; backported from 1.9.
-
- * dir.c (dir_each, dir_foreach): Ditto.
-
- * enum.c (enum_partition, enum_sort_by): Ditto.
-
- * gc.c (os_each_obj): Ditto.
-
- * hash.c (rb_hash_delete_if, rb_hash_reject_bang, rb_hash_select,
- rb_hash_each_value, rb_hash_each_key, rb_hash_each_pair,
- env_each_key, env_each_value, env_each, env_each_pair,
- env_reject_bang, env_delete_if, env_select): Ditto.
-
- * numeric.c (num_step, int_upto, int_downto, int_dotimes): Ditto.
-
-Mon Apr 14 16:42:53 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ruby.h (rb_block_call_func): Fix prototype.
-
- * enumerator.c (enumerator_iter_i, enumerator_each_i): Ditto.
-
-Mon Apr 14 15:49:05 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enum.c (enum_count, enum_find_index): New methods:
- Enumerable#count and #find_index; backported from 1.9.
-
-Mon Apr 14 14:16:08 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * enumerator.c (enumerator_mark, enumerator_iter_i, enumerator_each_i,
- enumerator_allocate): add prototype.
-
- * enumerator.c (enumerator_each_i): declare unused two arguments.
-
-Mon Apr 14 13:58:32 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * string.c (rb_str_each_char): New methods: String#chars and
- #each_char; backported from 1.9.
-
-Mon Apr 14 13:42:20 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * string.c (rb_str_each_line, rb_str_each_byte): Reflect
- enumerator integration. #lines and #bytes are now aliases to
- #each_line and #each_byte, respectively.
-
-Mon Apr 14 13:19:36 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * range.c (range_each, range_step): Return an enumerator if no
- block is given; backported from 1.9.
-
- * struct.c (rb_struct_each, rb_struct_each_pair): Ditto.
-
-Mon Apr 14 13:07:59 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * string.c (rb_str_partition, rb_str_rpartition,
- rb_str_start_with, rb_str_end_with): New methods:
- String#partition, #rpartition, #start_with? and #end_with?;
- backported from 1.9. These methods are $KCODE aware unlike
- #index, #rindex and #include?.
-
-Sun Apr 13 15:55:52 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * object.c (sym_to_proc): new method Symbol#to_proc; backported
- from 1.9. bug#19012
-
-Fri Apr 11 19:14:30 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * object.c (rb_obj_tap): new method Object#tap; backported from
- 1.9. bug#19008
-
-Fri Apr 11 18:58:09 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * process.c: new method Process.exec; backported from 1.9. bug#19006
-
-Fri Apr 11 12:43:56 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tkextlib/tile.rb, ext/tk/lib/tkextlib/tile/style.rb,
- ext/tk/sample/tkextlib/tile/demo.rb: previous patch is not complete.
-
-Fri Apr 11 10:22:54 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tkextlib/tile.rb:
- __define_LoadImages_proc_for_compatibility__! do nothing when the
- Tcl command exists.
-
- * ext/tk/lib/tkextlib/tile/style.rb:
- __define_wrapper_proc_for_compatibility__! do nothing when the Tcl
- command exists.
-
- * ext/tk/sample/tkextlib/tile/demo.rb: don't create 'step' theme if
- it already exists.
-
-Fri Apr 11 08:05:12 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * marshal.c (w_object): add volatile to avoid potential GC bug. a
- patch from Tomoyuki Chikanaga <chikanag at nippon-control-system.co.jp>
- in [ruby-dev:34311].
-
-Thu Apr 10 20:29:13 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * misc/rdebug.el, misc/README: Remove rdebug.el as per request
- from the maintainer and mention the ruby-debug project at
- RubyForge in README; bug#19043.
-
-Thu Apr 10 20:08:37 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enum.c (enum_first, enum_group_by): New methods:
- Enumerable#first and #group_by; backported from 1.9.
-
-Thu Apr 10 19:49:10 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enumerator.c (rb_eStopIteration), eval.c (rb_f_loop), ruby.h:
- Add a new exception class StopIteration, which breaks Kernel#loop
- iteration when raised; backported from 1.9.
-
- * enumerator.c (enumerator_next, enumerator_rewind): Implement
- #next and #rewind using the "generator" library.
-
- * lib/generator.rb: Implement Enumerable::Enumerator#next and
- #rewind.
-
-Thu Apr 10 19:29:48 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_first, rb_ary_last): Return a shared array when
- possible.
-
- * array.c (rb_ary_pop, rb_ary_pop_m, rb_ary_shift, rb_ary_shift_m):
- Array#pop and Array#shift can take an optional argument
- specifying the number of elements to remove and return;
- backported from 1.9.
-
-Thu Apr 10 14:00:44 2008 Tanaka Akira <akr@fsij.org>
-
- * lib/resolv.rb (Resolv::DNS#each_address): backport from 1.9 for
- CNAME. [ruby-dev:34200]
-
-Thu Apr 10 01:42:25 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * enum.c (iterate_method): add prototype to avoid warning on VC++.
-
-Wed Apr 9 23:12:41 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/tcltklib.c: SEGV when tcltk-stubs is enabled.
-
- * ext/tk/tcltklib.c: avoid error on a shared object.
-
- * ext/tk/extconf.rb: support --with-tcltkversion
-
- * ext/tk/README.tcltklib: add document about --with-tcltkversion
-
- * ext/tk/sample/demos-jp/widget, ext/tk/sample/demos-en/widget,
- ext/tk/sample/demos-jp/style.rb, ext/tk/sample/demos-en/style.rb,
- ext/tk/sample/demos-jp/bind.rb, ext/tk/sample/demos-en/bind.rb:
- bug fix.
-
-Wed Apr 9 21:54:45 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_pop): Do not reallocate too often; backported
- from 1.9.
-
-Wed Apr 9 21:13:05 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_each, rb_ary_each_index, rb_ary_reverse_each,
- rb_ary_reject, rb_ary_reject_bang): Array#each, #each_index,
- #reverse_each, #reject, #reject! and #delete_if return an
- enumerator if no block is given; backported from 1.9.
-
-Wed Apr 9 20:47:16 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_index, rb_ary_index): Array#index and #rindex
- can take a block instead of an argument; backported from 1.9.
-
-Wed Apr 9 19:58:31 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * enumerator.c, inits.c (rb_call_inits), ruby.h, intern.h,
- ext/enumerator, common.mk (OBJS, enumerator.$(OBJEXT)): Make the
- enumerator module built-in.
-
- * enumerator.c: New method: Enumerable::Enumerator#with_index.
-
- * enum.c (enum_each_with_index): Enumerable#each_with_index now
- returns an enumerator instead of raising an exception if no
- block is given. Enumerable#enum_with_index, formerly defined in
- the enumerator module, is kept as an alias to each_with_index
- for backward compatibility.
-
-Wed Apr 9 19:43:51 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (rb_obj_method, rb_proc_call), intern.h: Export.
-
-Tue Apr 8 11:11:28 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (EXEC_TAG): remove unnecessary FLUSH_REGISTER_WINDOWS for
- better performance on SPARC. [ruby-core:16159]
-
-Tue Apr 8 10:49:54 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * re.c (rb_reg_quote): should always copy the quoting string.
- [ruby-core:16235]
-
-Mon Apr 7 21:35:08 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_nitems): Backport Array#nitems with a block;
- suggested by Bertram Scharpf <lists@bertram-scharpf.de> in
- [ruby-talk:134083].
-
-Sun Apr 6 09:45:00 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * dir.c (dir_tell): check if closed. [ruby-core:16223]
-
-Sat Apr 5 10:05:00 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * object.c (rb_check_to_integer): backported for range_step.
-
-Fri Apr 4 05:57:11 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/net/pop.rb (Net::POP3::do_finish): clear @n_mails and
- @n_bytes as well. [ruby-core:16144]
-
-Fri Apr 4 02:17:06 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * range.c (range_step): should not round step into integer if
- begin and end are numeric. [ruby-core:15990]
-
-Tue Apr 1 14:43:38 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in: get rid of empty expansion.
-
- * {bcc,win}32/Makefile (config.h): need to define RUBY_SETJMP, etc.
-
-Tue Apr 1 11:36:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in: _setjmp is available but _longjmp is not on mingw.
-
-Tue Apr 1 03:20:40 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (RUBY_SETJMP, RUBY_LONGJMP, RUBY_JMP_BUF): prefers
- _setjmp over setjmp and sigsetjmp. [ruby-core:16023]
- __builtin_setjmp cannot handle a variable.
-
- * configure.in (--with-setjmp-type): new option to override the
- default rule in the above.
-
- * eval_intern.h (ruby_setjmp, ruby_longjmp), gc.c (rb_setjmp),
- vm_core.h (rb_jmpbuf_t): use RUBY_SETJMP, RUBY_LONGJMP and
- RUBY_JMP_BUF.
-
-Tue Apr 1 01:55:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/resolv.rb (Resolv::Config.default_config_hash): requires
- win32/resolv to use Win32::Resolv. [ruby-dev:34138]
-
-Mon Mar 31 14:51:11 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * bignum.c (rb_big_div): Bignum#div should return integer for
- floating number operand.
-
-Sun Mar 30 07:00:32 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/tk/tcltklib.c: rb_hash_lookup has not been backported yet.
-
-Sat Mar 29 14:18:41 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/*: full update Ruby/Tk to support Ruby(1.9|1.8) and Tc/Tk8.5.
-
- * ext/tk/lib/tkextlib/tile.rb: [incompatible] remove TileWidgets'
- instate/state/identify method to avoid the conflict with standard
- widget options. Those methods are renamed to ttk_instate/ttk_state/
- ttk_identify (tile_instate/tile_state/tile_identify are available
- too). Although I don't recommend, if you realy need old methods,
- please define "Tk::USE_OBSOLETE_TILE_STATE_METHOD = true" before
- "require 'tkextlib/tile'".
-
- * ext/tk/lib/tkextlib/tile.rb: "Tk::Tile::__Import_Tile_Widgets__!"
- is obsolete. It outputs warning. To control default widget set,
- use "Tk.default_widget_set = :Ttk".
-
- * ext/tk/lib/tk.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__ method and
- __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method are defind
- as module methods of TkConfigMethod. It may help users to wrap old
- Ruby/Tk scripts (use standard widgets) to force to use Ttk widgets.
- Ttk widgets don't have some options of standard widgets which are
- control the view of widgets. When set ignore-mode true, configure
- method tries to ignoure such unknown options with no exception.
- Of course, it may raise other troubles on the GUI design.
- So, those are a little danger methods.
-
- * ext/tk/lib/tk/itemconfig.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__
- method and __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method
- are defind as module methods of TkItemConfigMethod as the same
- purpose as TkConfigMethod's ones.
-
- * ext/tk/sample/ttk_wrapper.rb: A new example. This is a tool for
- wrapping old Ruby/Tk scripts (which use standard widgets) to use
- Ttk (Tile) widgets as default.
-
- * ext/tk/sample/tkextlib/tile/demo.rb: use ttk_instate/ttk_state
- method instead of instate/state method.
-
- * ext/tk/lib/tk/root, ext/tk/lib/tk/namespace.rb,
- ext/tk/lib/tk/text.rb, ext/tk/lib/tkextlib/*: some 'instance_eval's
- are replaced to "instance_exec(self)".
-
- * ext/tk/lib/tk/event.rb: bug fix on KEY_TBL and PROC_TBL (?x is not
- a character code on Ruby1.9).
-
- * ext/tk/lib/tk/variable.rb: support new style of operation argument
- on Tcl/Tk's 'trace' command for variables.
-
- * ext/tk/sample/demos-jp/widget, ext/tk/sample/demos-en/widget: bug fix
-
- * ext/tk/sammple/demos-jp/textpeer.rb,
- ext/tk/sammple/demos-en/textpeer.rb: new widget demo.
-
- * ext/tk/tcltklib.c: decrase SEGV troubles (probably)
-
- * ext/tk/lib/tk.rb: remove Thread.critical access if Ruby1.9
-
- * ext/tk/lib/tk/multi-tk.rb: support Ruby1.9 (probably)
-
- * ext/tk/lib/tkextlib/tile.rb: add method to define Tcl/Tk command
- to make Tcl/Tk theme sources (based on different version of Tile
- extension) available.
- (Tk::Tile::__define_LoadImages_proc_for_comaptibility__)
-
- * ext/tk/lib/tk.rb, ext/tk/lib/tk/wm.rb: support dockable frames
- (Tcl/Tk8.5 feature). 'wm' command can treat many kinds of widgets
- as toplevel widgets.
-
- * ext/tk/lib/tkextlib/tile/style.rb: ditto.
- (Tk::Tile::Style.__define_wrapper_proc_for_compatibility__)
-
- * ext/tk/lib/tk/font.rb: add actual_hash and metrics_hash to get
- properties as a hash. metrics_hash method returns a boolean value
- for 'fixed' option. But metrics method returns numeric value
- (0 or 1) for 'fixed' option, because of backward compatibility.
-
- * ext/tk/lib/tk/timer.rb: somtimes fail to set callback procedure.
-
- * ext/tk/lib/tk.rb: add Tk.sleep and Tk.wakeup method. Tk.sleep
- doesn't block the eventloop. It will be better to use the method
- in event callbacks.
-
- * ext/tk/sample/tksleep_sample.rb: sample script about Tk.sleep.
-
-Sat Mar 29 04:08:59 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * class.c (clone_method): should copy cref as well.
- [ruby-core:15833]
-
-Mon Mar 24 20:07:42 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (rb_eval): Call trace hook for if expression after the
- condition has been evaluated, not before; submitted by Rocky
- Bernstein in #18722.
-
-Mon Mar 24 19:44:53 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * parse.y (yycompile): Always prepare a new array for each file's
- SCRIPT_LINES__ storage, instead of appending source lines every
- time a file is re-loaded; submitted by Rocky Bernstein in
- #18517.
-
-Mon Mar 24 10:25:54 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in: sitearch should use target_cpu. [ruby-core:15986]
-
-Mon Mar 24 01:24:24 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/erb.rb (result): use proc instead of Thread. [ruby-dev:33692]
-
-Fri Mar 21 21:26:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/resolv.rb (Resolv::Hosts): should not use win32/resolv on cygwin.
- [ruby-dev:29945], [ruby-dev:34095]
-
- * lib/win32/registry.rb (Win32::Registry.expand_environ): try upcased
- name too for cygwin. [ruby-dev:29945]
-
- * lib/win32/resolv.rb (Win32::Resolv.get_hosts_path): use expand_path.
-
-Fri Mar 21 21:10:00 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/ipaddr.rb: Say that I am the current maintainer.
-
- * lib/set.rb: Ditto.
-
- * lib/shellwords.rb: Ditto.
-
- * ext/syslog/syslog.txt: Ditto.
-
-Fri Mar 21 09:24:28 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * instruby.rb (open_for_install): write block result and rewrite only
- if changed from existing file.
-
-Wed Mar 19 21:01:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * dir.c (dir_inspect, dir_path, dir_tell): check for frozen and closed
- is not needed. [ruby-dev:32640]
-
-Wed Mar 19 20:25:40 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * dir.c (Init_Dir): define inspect method. [ruby-core:15960]
-
-Wed Mar 19 14:59:12 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * misc/ruby-style.el (ruby-style-{case,label}-indent): fix for labels
- inside blocks in switch and function top level.
-
-Wed Mar 19 14:36:40 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_cstr_to_inum): treat successive underscores as
- nondigit. [ruby-dev:34089]
-
-Wed Mar 19 00:01:23 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/erb.rb (ERB::Compiler): Make some minor code optimization.
-
-Mon Mar 17 17:11:13 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * misc/ruby-mode.el (ruby-mode): should use `run-mode-hooks' instead
- of calling `run-hooks' directly to run the mode hook. patch from
- Chiyuan Zhang <pluskid AT gmail.com> in [ruby-core:15915]
-
-Mon Mar 17 16:41:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in: unset GREP_OPTIONS. [ruby-core:15918]
-
-Fri Mar 14 16:59:23 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (RUBY_LIB_PREFIX): fix for prefix.
-
-Fri Mar 14 16:35:11 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/cgi.rb (CGI::Cookie::initialize): performance patch from
- Makoto Kuwata <kwa@kuwata-lab.com> in [ruby-dev:34048].
-
-Fri Mar 14 15:49:05 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (RUBY_LIB_PREFIX): use libdir.
-
-Fri Mar 14 10:12:29 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (RUBY_CHECK_VARTYPE): should not indent preprocessor
- directives.
-
-Thu Mar 13 00:37:20 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_call0): yields the last executed node line number at
- return event. [ruby-core:15855]
-
-Wed Mar 12 02:12:20 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * lib/delegate.rb: check $@ to avoid NoMethodError.
-
-Tue Mar 11 19:48:09 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * numeric.c (fix_coerce): try conversion before type check.
- [ruby-core:15838]
-
-Tue Mar 11 17:03:23 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/delegate.rb (Delegator#initialize, DelegateClass): skip correct
- backtrace. [ruby-dev:34019]
-
-Tue Mar 11 16:43:53 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (rb_w32_cmdvector): terminate shrunken command line.
-
-Tue Mar 11 12:39:03 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * common.mk (clean-local): removes MINOBJS.
-
-Sat Mar 8 18:50:57 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (isdirsep): backslash is valid path separator on cygwin too.
-
-Fri Mar 7 19:56:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb: rdoc added. [ruby-Patches-9762]
-
-Thu Mar 6 15:10:21 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * {bcc32,win32}/Makefile.sub (RUNRUBY): use $(PROGRAM) instead of
- ruby$(EXEEXT).
- suggested by KIMURA Koichi <kimura.koichi at canon.co.jp>.
- [ruby-dev:34000]
-
-Thu Mar 6 12:15:06 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (opt_block_param): command can start just after block param
- definition. [ruby-list:44479]
-
-Thu Mar 6 00:34:11 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/erb.rb: update RDoc. Thanks Makoto Kuwata [ruby-dev:33702]
-
-Mon Mar 3 23:28:34 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/httpservlet/filehandler.rb: should normalize path
- separators in path_info to prevent directory traversal attacks
- on DOSISH platforms.
- reported by Digital Security Research Group [DSECRG-08-026].
-
- * lib/webrick/httpservlet/filehandler.rb: pathnames which have
- not to be published should be checked case-insensitively.
-
-Mon Mar 3 16:14:24 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * hash.c (rb_any_hash): shrinks all results in Fixnum range.
- [ruby-core:15713]
-
-Sat Mar 1 02:35:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (big2str_find_n1): check integer overflow.
-
-Tue Feb 26 16:06:00 2008 Technorama Ltd. <oss-ruby@technorama.net>
-
- * ext/openssl/ossl_pkey_{ec,dh,dsa,rsa}.c: Remove useless warnings.
-
- * ext/openssl/ossl_asn1.c: Simplify code.
-
- * ext/openssl/ossl_ssl_session.c Fix compiler warnings.
- Undefine #id if SSL_SESSION_get_id is not supported.
-
-Tue Feb 26 15:43:42 2008 Tanaka Akira <akr@fsij.org>
-
- * parse.y (tokadd_escape): refactored. [ruby-core:15657]
-
-Mon Feb 25 17:30:29 2008 Technorama Ltd. <oss-ruby@technorama.net>
-
- * ext/openssl/digest.c ext/openssl/lib/openssl/digest.rb:
- Commit patch #9280 from Akinori MUSHA.
- Simplify the OpenSSL::Digest class and make use of the
- existing Digest framework.
- Enhance performance.
-
-Mon Feb 25 13:40:03 2008 Tanaka Akira <akr@fsij.org>
-
- * process.c (Init_process): share bignum objects for RLIM_INFINITY,
- RLIM_SAVED_MAX and RLIM_SAVED_CUR if they are equal.
-
-Sun Feb 24 23:29:48 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * common.mk, {bcc,win}32/Makefile.sub (clean-local): remove
- intermediate files.
-
-Sun Feb 24 03:52:58 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * util.c (valid_filename): use O_EXCL to get rid of clobbering
- existing files in race conditions.
-
-Fri Feb 22 19:50:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (BIGZEROP): fix for longer Bignum zeros. [ruby-Bugs-17454]
-
-Fri Feb 22 16:09:53 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big_lshift, rb_big_rshift, rb_big_aref): removed excess
- arguments.
-
-Thu Feb 21 00:01:34 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (RPATHFLAG): -R option of HP-UX ld is not for runtime
- load path. [ruby-list:44600]
-
-Wed Feb 20 23:55:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (rb_w32_map_errno): exported.
-
-Wed Feb 20 13:08:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * instruby.rb (parse_args): added --dir-mode, --script-mode and
- --cmd-type options. [ruby-dev:33816]
-
- * instruby.rb (parse_args): added bin-arch and bin-comm to install
- type, for compiled files and script files.
-
- * instruby.rb (parse_args): deal with make style command line macros,
- and count as long syle options if prefixed with INSTALL_.
-
- * instruby.rb (makedirs): use $dir_mode. [ruby-dev:33805]
-
- * instruby.rb (open_for_install): set file mode, which is now
- permission mode instead of access mode.
-
- * instruby.rb (bin-comm): installs scripts with replacing shebang
- lines.
-
-Tue Feb 19 18:34:32 2008 Tanaka Akira <akr@fsij.org>
-
- * gc.c (STACK_LENGTH) [SPARC] : 0x80 offset removed. [ruby-dev:33857]
-
-Tue Feb 19 14:27:32 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/readline/readline.c (readline_event): prevent polling. based on
- a patch from error errorsson in [ruby-Bugs-17675].
-
-Tue Feb 19 12:08:29 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (yycompile): clear ruby_eval_tree_begin if parse failed.
-
-Mon Feb 18 16:23:45 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (yycompile): clear ruby_eval_tree_begin too before parse.
-
-Mon Feb 18 10:17:42 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/pty/lib/expect.rb (IO#expect): check if peer is closed.
- [ruby-Bugs-17940]
-
-Fri Feb 15 20:37:06 2008 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/rational.rb (floor, ceil, truncate, round): do not use
- definitions of Numeric.
-
- * lib/rational.rb (to_i): should returns truncated self.
-
- * lib/complex.rb (numerator): requires
- Integer#{numerator,denominator}.
-
- * lib/complex.rb (quo): do not use definition of Numeric.
-
- * lib/complex.rb (div, divmod, floor, ceil, truncate, round):
- undef'ed.
-
-Fri Feb 15 15:23:12 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/iconv/iconv.c (iconv_convert): check upper bound. a patch from
- Daniel Luz at [ruby-Bugs-17910].
-
-Fri Feb 15 02:42:25 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (ftruncate): check if available.
-
- * file.c (rb_file_truncate): check if ftruncate instead of truncate.
-
-Fri Feb 15 02:40:54 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (sigsetmask): check when signal semantics is not POSIX.
-
- * signal.c (USE_TRAP_MASK): set true if sigprocmask or sigsetmask is
- available.
-
-Thu Feb 14 17:44:32 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/dl/ptr.c (dlmem_each_i): typo fixed. a patch from IKOMA
- Yoshiki <ikoma AT mb.i-chubu.ne.jp> in [ruby-dev:33776].
-
-Thu Feb 14 16:02:51 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (rb_file_s_utime): inhibits with secure level 2 or higher.
-
-Thu Feb 14 01:43:16 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/timeout.rb (Timeout::timeout): made sensitive to location on the
- stack. [ruby-core:15458]
-
-Thu Feb 14 00:49:53 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * common.mk (INSTRUBY_ARGS): pass mode to install. [ruby-dev:33766]
-
- * instruby.rb (parse_args): added --data-mode and --prog-mode options.
-
-Tue Feb 12 11:33:26 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * test/erb/test_erb.rb(TestERBCore): import from erb-2.0.4.
-
- * test/erb/hello.erb: ditto
-
-Mon Feb 11 17:25:21 2008 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb (RSS::VERSION), test/rss/test_version.rb, NEWS:
- 0.2.3 -> 0.2.4.
-
- * lib/rss/maker.rb, lib/rss/maker/, test/rss/test_maker_2.0.rb:
- fixed a bug that RSS::Maker.make("0.9")'s item doesn't make some
- elements if description is missed.
- Reported by Michael Auzenne. Thanks!!!
-
- * lib/rss/maker/0.9.rb, test/rss/test_maker_0.9.rb:
- RSS::Maker.make("0.9") generates RSS 0.92 not RSS 0.91.
-
-Mon Feb 11 16:57:00 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * ChangeLog: format-time-string under C locale. [ruby-dev:33261]
-
-Mon Feb 11 16:31:47 2008 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
-
- * gc.c (rb_newobj): prohibit call of rb_newobj() during gc.
- Submitted by Sylvain Joyeux [ruby-core:12099].
-
- * ext/dl/ptr.c: do not use LONG2NUM() inside dlptr_free().
- Slightly modified fix bassed on a patch by Sylvain Joyeux
- [ruby-core:12099] [ ruby-bugs-11859 ] [ ruby-bugs-11882 ]
- [ ruby-patches-13151 ].
-
-Mon Feb 11 00:22:55 2008 NARUSE, Yui <naruse@ruby-lang.org>
-
- * lib/benchmark.rb (Job::Benchmark#item): fix typo.
-
-Sat Feb 9 23:22:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/bigdecimal/extconf.rb: simplified the condition.
-
-Sat Feb 9 17:51:24 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/bigdecimal/bigdecimal.c (BigDecimal_to_f): use strtod() for more
- precision. [ruby-talk:290296]
-
- * ext/bigdecimal/bigdecimal.c (BASE_FIG): made constant.
-
- * ext/bigdecimal/extconf.rb: ditto. [ruby-dev:33658]
-
-Sat Feb 9 00:44:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/irb.rb (IRB::Irb::eval_input): rescues Interrupt and other than
- SystemExit and SignalException. [ruby-core:15359]
-
-Fri Feb 8 15:09:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb (xsystem): expand macros like as make.
-
-Tue Feb 5 11:14:11 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb (INSTALL_DIRS, install_dirs): added BINDIR.
-
- * lib/mkmf.rb (install_files): rejects files matching to
- $NONINSTALLFILES.
-
- * lib/mkmf.rb (init_mkmf): defaults $NONINSTALLFILES to backup and
- temporary filse.
-
-Mon Feb 4 16:44:24 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (darwin): NSIG is not defined if _XOPEN_SOURCE > 500L.
- [ruby-dev:33584]
-
-Sat Feb 2 20:06:42 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/benchmark.rb (Benchmark::realtime): make Benchmark#realtime
- a bit faster. a patch from Alexander Dymo <dymo AT ukrpost.ua> in
- [ruby-core:15337].
-
-Sat Feb 2 09:53:39 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (darwin): disabled fat-binary support which confuses
- configure much, since ``universal'' implies hidden cross-compiling.
- TODO: ruby and libruby.bundle might be possible to bound with `lipo'
- after builds for each archs. Anyway, config.h and rbconfig.rb must
- be separated definitely at least.
-
-Fri Feb 1 21:42:37 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (darwin): _XOPEN_SOURCE is necessary to make ucontext_t
- consistent with the library implementation of MacOS X 10.5.
- [ruby-dev:33461]
-
- * configure.in (darwin): ucontext on PowerPC MacOS X 10.5 is broken.
-
-Thu Jan 31 08:31:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * common.mk (ext/extmk.rb, instruby.rb): inlined $(MAKE) so that can
- be executed even with -n.
-
-Thu Jan 31 07:00:19 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/rinda/tuplespace.rb (bin_for_find): should find a symbol by
- Symbol class.
-
- * test/rinda/test_rinda.rb (test_symbol_tuple): ditto.
-
-Wed Jan 30 22:07:58 2008 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date.rb: refined deprecated methods.
-
-Wed Jan 30 22:06:54 2008 Tadayoshi Funaba <tadf@dotrb.org>
-
- * bignum.c (rb_cstr_to_inum): '0_2' is a valid representation.
-
-Tue Jan 29 22:40:12 2008 Yusuke Endoh <mame@tsg.ne.jp>
-
- * range.c (step_i): rb_funcall receives VALUE as an argument.
-
-Tue Jan 29 11:53:05 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in: rm largefile.h.
-
-Mon Jan 28 01:21:15 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * io.c (rb_open_file): should check NUL in path.
- <http://www.rubyist.net/~matz/20080125.html#c01>.
-
- * io.c (rb_io_s_popen): ditto.
-
- * io.c (rb_io_reopen): ditto.
-
- * io.c (next_argv): ditto.
-
- * io.c (rb_io_s_foreach): ditto.
-
- * io.c (rb_io_s_readlines): ditto.
-
- * io.c (rb_io_s_read): ditto.
-
-Fri Jan 25 22:33:38 2008 Yusuke Endoh <mame@tsg.ne.jp>
-
- * math.c: fix comment. [ruby-dev:33276]
-
-Fri Jan 25 10:31:58 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * */*.bat: set svn:mime-type to text/batch.
-
-Thu Jan 24 19:36:22 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/uri/generic.rb (URI::Generic::inspect): use Kernel#to_s instead
- object_id with printf. [ruby-dev:33347]
-
-Tue Jan 22 11:22:47 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/setup.mak ($(ARCH)): if a macro is appended by $(APPEND),
- a space will be inserted on the top of the line.
-
- * win32/Makefile.sub (MKFILES): stop make process if Makefile is
- updated.
-
-Mon Jan 21 17:34:41 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * io.c (rb_io_mode_flags, rb_io_mode_modenum): Ignore encoding
- options for forward compatibility.
-
-Mon Jan 21 12:50:02 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c, gc.c (setjmp): sigsetjmp is a macro on cygwin.
-
-Sat Jan 19 11:21:53 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (sigsetjmp): check if available.
-
- * eval.c, gc.c (setjmp): do not use _setjmp if sigsetjmp is available.
-
-Sat Jan 19 11:10:11 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in: Remove wrong assumptions about Cygwin. a patch from
- Corinna Vinschen in [ruby-Bugs-17018].
-
-Thu Jan 17 21:06:01 2008 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date.rb (Date::Infinity#<=>): didn't work. A patch from
- Dirkjan Bussink <d.bussink AT gmail.com> [ruby-core:15098].
- This is a bug obviously. However it didn't affect the library's
- functions.
-
- * lib/date.rb, lib/date/format.rb: some trivial changes.
-
-Tue Jan 15 15:09:28 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/setup.mak: strip out empty lines from CPP output.
-
-Tue Jan 15 03:41:42 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (eval): check if backtrace is empty. [ruby-core:15040]
-
-Tue Jan 15 01:28:47 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * common.mk: simplified dummy objects dependencies.
-
-Mon Jan 14 16:12:58 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/shellwords.rb: scape should be an alias to shellescape. a
- patch from Masahiro Kawato <m-kawato AT mwb.biglobe.ne.jp> in
- [ruby-dev:33060].
-
-Mon Jan 14 09:32:40 2008 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/time.rb: do not reference Time directly from the inside of
- definitions. [ruby-dev:33059]
-
-Sat Jan 12 18:27:41 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_define_alloc_func, rb_undef_alloc_func): should
- define/undef on a signleton class. [ruby-core:09959]
-
-Sat Jan 12 12:04:14 2008 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date.rb, lib/date/format.rb: tuning for performance.
-
-Fri Jan 11 12:35:56 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in: moved broken syscall checks from process.c etc.
-
- * defines.h (WORDS_BIGENDIAN): honor __BIG_ENDIAN__ than the result of
- configure.
-
- * dln.c: use dlopen on Mac OS X 10.3 or later. backport from trunk.
-
- * lib/rdoc/options.rb (check_diagram): more precise check, darwin
- is not Windows but minwg is on it.
-
-Thu Jan 10 10:53:50 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (rb_w32_open_osfhandle): reverted to old definition.
- [ ruby-Bugs-16948 ]
-
-Tue Jan 8 20:02:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win{32,ce}/Makefile.sub: merged.
-
-Sun Jan 6 09:39:02 2008 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date.rb, lib/date/format.rb: introduced some constants
- (for internal use).
-
- * sample/cal.rb: trivial adjustments.
-
-Fri Jan 4 23:08:48 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * time.c (time_arg): use converted object. [ruby-core:14759]
-
-Fri Jan 4 01:20:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32.h: only VC6 needs extern "C++" for math.h. [ruby-talk:285660]
-
-Thu Jan 3 11:28:58 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (fptr_finalize): clear errno first. [ruby-talk:284492]
-
-Wed Jan 2 10:18:56 2008 Tadayoshi Funaba <tadf@dotrb.org>
-
- * sample/time.rb: use Process.times instead of Time.times.
-
-Wed Jan 2 09:18:11 2008 Tadayoshi Funaba <tadf@dotrb.org>
-
- * sample/goodfriday.rb: examples for date are enough. retired.
-
-Wed Jan 2 09:06:55 2008 Tadayoshi Funaba <tadf@dotrb.org>
-
- * sample/cal.rb: just updated with the newest version.
-
-Mon Dec 31 06:50:38 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * trunk/common.mk: not use -I$(srcdir)/lib with $(MINIRUBY) for cross
- compiling.
-
- * configure.in, {win,bcc}32/Makefile.sub (MINIRUBY): -I$(srcdir)/lib
- moved.
-
-Sun Dec 30 22:48:37 2007 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date.rb (_valid_time?): I'm not sure to recommend such an
- expression. but anyway it is acceptable now. [ruby-core:14580]
-
-Fri Dec 28 16:36:33 2007 NARUSE, Yui <naruse@airemix.com>
-
- * lib/resolv.rb (Resolv::DNS#each_address): now returns IPv6 address.
-
-Fri Dec 28 13:21:32 2007 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb, test/rss/test_version.rb, NEWS: 0.2.2 -> 0.2.3.
-
- * lib/rss/parser.rb, test/rss/test_parser.rb: supported "-" in tag name.
- Reported by Ray Chen. Thanks.
-
-Thu Dec 27 23:56:01 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * mkconfig.rb: should not use the libraries under the source directory
- at cross compiling.
-
-Thu Dec 27 11:02:45 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * intern.h, string.c (rb_str_set_len): added for upgrading path from
- 1.8 to 1.9. [ruby-dev:32807]
-
- * string.c (rb_str_lines, rb_str_bytes): ditto.
-
-Thu Dec 27 10:47:32 2007 Technorama Ltd. <oss-ruby@technorama.net>
-
- * ext/openssl/ossl_ssl.c: Only show a warning if the default
- DH callback is actually used.
-
- * ext/openssl/ossl_rand.c: New method: random_add().
-
-Wed Dec 26 22:27:45 2007 NARUSE, Yui <naruse@ruby-lang.org>
-
- * lib/resolv.rb (Resolv::DNS::Name.==): fix for other is array of
- Resolv::DNS::Label::Str.
-
- * lib/resolv.rb (Resolv::DNS::MessageEncoder#put_label): String#string
- is not defined, so replace to_s.
-
- * lib/resolv.rb (Resolv::IPv6#to_name): ip6.int is obsoleted by
- int.arpa.
-
-Mon Dec 24 16:18:57 2007 Eric Hodel <drbrain@segment7.net>
-
- * lib/rdoc/ri/ri_options.rb: Fix ri --help listing of gem ri paths.
- Merge of r14567 and r14569 from trunk.
-
- * lib/rdoc/ri/ri_paths.rb: Fix duplication of ri data for multiple
- gems. Merge of r14567 from trunk
-
-Mon Dec 24 12:35:03 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win{32,ce}/Makefile.sub (MFLAGS): defaulted to -l.
-
-Mon Dec 24 11:56:31 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * {bcc32,win{32,ce}}/Makefile.sub (SET_MAKE): set MFLAGS which is not
- set by default, to get rid of chaotic situation of MFLAGS/MAKEFLAGS.
-
-Sat Dec 22 14:49:46 2007 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date.rb: don't freeze nil even if 1.8 will not be aware of
- the issue. [ruby-dev:32677]
-
-Wed Dec 19 13:57:43 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (TIMEZONE_VOID): check whether timezone requires zero
- arguments. [ruby-dev:32631]
-
-Wed Dec 19 12:01:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (f_rest_arg): check if duplicated. [ruby-core:14140]
-
-Wed Dec 19 10:52:29 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_cstr_to_inum): an underscore succeeding after octal
- prefix is allowed. [ruby-core:14139]
-
-Mon Dec 17 13:43:15 2007 Tanaka Akira <akr@fsij.org>
-
- * gc.c (stack_end_address): use local variable address instead of
- __builtin_frame_address(0) to avoid SEGV on SunOS 5.11 on x86 with
- gcc (GCC) 3.4.3 (csl-sol210-3_4-20050802).
- stack_end_address returned a frame address of garbage_collect
- since stack_end_address doesn't create its own frame.
- So a VALUE stored in a callee saved register, %edi, pushed into
- the stack at the beginning of garbage_collect was not marked.
-
-Mon Dec 17 12:21:25 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * Makefile.in (RUNRUBY): added RUNRUBYOPT.
-
-Fri Dec 14 12:36:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (RUBY_CHECK_VARTYPE): check if a variable is defined
- and its type.
-
- * configure.in (timezone, altzone): check for recent cygwin.
-
- * missing/strftime.c (strftime): fix for timezone. [ruby-dev:32536]
-
- * lib/mkmf.rb (try_var): should fail for functions.
-
- * ext/readline/extconf.rb: should use have_func for functions instead
- of have_var.
-
-Tue Dec 11 00:04:05 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * array.c (rb_ary_slice_bang): If an invalid negative index (<
- -size) is given, do not raise an exception but return nil just
- like slice() does.
-
- * test/ruby/test_array.rb (TestArray::test_slice,
- TestArray::test_slice!): Pull in test cases from trunk.
-
-Mon Dec 10 21:47:53 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * transcode.c (str_transcode): allow non-registered encodings.
- [ruby-dev:32520]
-
-Mon Dec 10 21:00:30 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * array.c (rb_ary_slice_bang): should return nil if position out
- of range. a patch from Akinori MUSHA <knu AT iDaemons.org>.
- [ruby-dev:32518]
-
-Mon Dec 10 18:28:06 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/uri/common.rb (URI::REGEXP::PATTERN): typo in REG_NAME
- regular expression. a patch from Ueda Satoshi
- <s-ueda AT livedoor.jp>. [ruby-dev:32514]
-
-Sun Dec 9 12:39:01 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/cgi.rb (read_multipart): exclude blanks from header values.
- [ruby-list:44327]
-
-Wed Dec 5 23:38:50 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * range.c (range_each): followed step_i change.
-
-Wed Dec 5 18:08:45 2007 Tanaka Akira <akr@fsij.org>
-
- * numeric.c (int_odd_p): new method Integer#odd?.
- (int_even_p): new method Integer#even?.
- (int_pred): new method Integer#pred.
- (fix_odd_p): new method Fixnum#odd?.
- (fix_even_p): new method Fixnum#even?.
-
-Wed Dec 5 15:15:21 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * range.c (step_i, range_step): support non-fixnum steps.
- [ruby-talk:282100]
-
-Tue Dec 4 11:23:50 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_cstr_to_inum): trailing spaces may exist at sqeezing
- preceeding 0s. [ruby-core:13873]
-
-Sun Dec 2 22:43:45 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (error_print): put newline unless multiple line message ends
- with a newline. [ruby-dev:32429]
-
-Sun Dec 2 15:49:20 2007 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb, test/rss/test_version.rb, NEWS: 0.2.1 -> 0.2.2.
-
- * lib/rss/maker/itunes.rb: fixed new_itunes_category.
- * lib/rss/maker/taxonomy.rb: new_taxo_topic -> new_topic because
- of consistency.
-
- * test/rss/test_maker_itunes.rb, test/rss/test_itunes.rb: removed
- needless UTF-8 characters.
-
-Sun Dec 2 01:12:15 2007 James Edward Gray II <jeg2@ruby-lang.org>
-
- Merged 14070 from trunk.
-
- * lib/xmlrpc/server.rb (XMLRPC::Server#server): Improve signal handling so
- pressing control-c in the controlling terminal or sending SIGTERM stops
- the XML-RPC server.
-
-Sat Dec 1 15:13:33 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/resolv.rb: documentation update. backported from 1.9.
- [ruby-core:13273]
-
-Sat Dec 1 03:30:47 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (newline_node): set line from outermost node before removing
- NODE_BEGIN. [ruby-dev:32406]
-
-Fri Nov 30 21:53:28 2007 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb, test/rss/test_version.rb: 0.2.0 -> 0.2.1.
-
- * lib/rss/content.rb, lib/rss/content/1.0.rb,
- lib/rss/content/2.0.rb, lib/rss/maker/content.rb,
- test/rss/rss-testcase.rb, test/rss/test_content.rb,
- test/rss/test_maker_content.rb: supported content:encoded with RSS
- 2.0.
- Suggested by Sam Lown. Thanks.
-
- * NEWS: added the above changes.
-
-Thu Nov 29 16:59:10 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (stmt): remove unnecessary NODE_BEGIN. [ruby-core:13814]
-
-Wed Nov 28 14:43:14 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb (extract_makefile): use dldflags instead of DLDFLAGS to
- get rid of mixing $LDFLAGS and $ARCH_FLAG.
-
- * lib/mkmf.rb (configuration): ditto.
-
- * lib/mkmf.rb (create_makefile): support for extensions which has no
- shared object.
-
-Wed Nov 28 09:51:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big2str0): do not clobber space for sign.
-
- * sprintf.c (remove_sign_bits): extends sign bit first.
-
-Wed Nov 21 01:04:12 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (nil_plus): remove unused function. [ruby-core:13737]
-
-Sun Nov 18 14:03:44 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_alias): do not call hook functions until initialization
- finishes. [ruby-talk:279538]
-
-Sun Nov 18 09:09:48 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb (String#tr_cpp): make preprocessor identifiers.
-
-Sat Nov 17 13:58:11 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c (ole_invoke): bug fix. [ruby-talk:279100]
-
-Fri Nov 16 17:41:34 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/iconv/iconv.c (Document-class): moved the simplest example to
- the top.
-
- * ext/iconv/iconv.c (iconv_s_iconv): Document-method: needs class
- prefix for class method. [ruby-core:13542]
-
- * ext/iconv/iconv.c (iconv_iconv): also instance method needs to be
- qualified.
-
-Fri Nov 16 11:16:41 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/yaml/rubytypes.rb (String#is_binary_data?): use Integer#fdiv.
-
-Thu Nov 15 19:50:46 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/curses/extconf.rb: check macro if cannot find func.
- [ruby-list:44224]
-
-Thu Nov 15 12:19:14 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/cgi/session.rb (CGI::Session::FileStore::restore): use
- lockfile for exclusive locks. a patch from <tommy AT tmtm.org>.
- [ruby-dev:32296]
-
-Wed Nov 14 01:52:59 2007 Tanaka Akira <akr@fsij.org>
-
- * missing/isinf.c (isinf): don't define if the macro is defined.
-
-Wed Nov 14 01:34:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * numeric.c (round): fallback definition.
-
- * numeric.c (flo_divmod, flo_round): use round() always.
- [ruby-dev:32269]
-
-Tue Nov 13 22:02:23 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/drb/drb.rb: remove Thread.exclusive.
-
- * lib/drb/extservm.rb: ditto.
-
-Tue Nov 13 16:33:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * numeric.c (flodivmod): work around for infinity.
-
- * numeric.c (flo_divmod): work around for platforms have no round().
- [ruby-dev:32247]
-
-Tue Nov 13 13:58:51 2007 Tanaka Akira <akr@fsij.org>
-
- * numeric.c (numeric.c): Integer#ord implemented. [ruby-dev:32206]
-
-Tue Nov 13 02:57:04 2007 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
-
- * numeric.c (flo_divmod): round to the nearest integer.
- [ ruby-Bugs-14540 ]
-
-Mon Nov 12 16:52:29 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb (create_makefile): rdoc about srcprefix. a patch from
- Daniel Berger <djberg96 AT gmail.com> in [ruby-core:13378].
-
-Mon Nov 12 13:53:06 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * misc/ruby-mode.el (ruby-parse-partial): handle stringified
- symbols properly using ruby-forward-string.
-
-Mon Nov 12 12:38:31 2007 Tanaka Akira <akr@fsij.org>
-
- * Makefile.in (lex.c): don't remove lex.c at first.
-
-Fri Nov 9 07:26:04 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * random.c: update MT URL.[ruby-core:13305].
-
-Wed Nov 7 03:32:38 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/rexml/encodings/SHIFT-JIS.rb (REXML::Encoding): place -x for
- nkf conversion. a patch from <moonwolf AT moonwolf.com>.
- [ruby-dev:32183]
-
-Mon Nov 5 05:17:04 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/optparse.rb (OptionParser::Switch::summarize): fix for long form
- option with very long argument. a patch from Kobayashi Noritada
- <nori1 AT dolphin.c.u-tokyo.ac.jp> in [ruby-list:44179].
-
-Mon Nov 5 01:20:33 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (call_args): remove "parenthesize argument(s) for future
- version" warning. when I added this warning, I had a plan to
- reimplement the parser that is simpler than the current one.
- since we abandoned the plan, warning no longer required.
-
-Fri Nov 2 00:13:51 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * array.c (rb_ary_assoc): check and convert inner arrays (assocs)
- using #to_ary.
-
- * hash.c (rb_hash_s_create): check and convert argument hash
- using #to_hash.
-
- * hash.c (rb_hash_s_create): Hash#[] now takes assocs as source of
- hash conversion.
-
-Thu Nov 1 23:47:43 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/drb/drb.rb (DRbTCPSocket): Improving with multiple network
- interface.
-
- * test/drb/drbtest.rb: ditto.
-
-Fri Oct 26 17:14:14 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * numeric.c (fix_pow): returns 1.0 for 0**0.0.
-
- * numeric.c (fix_pow): returns infinity for 0**-1. [ruby-dev:32084]
-
-Wed Oct 25 07:18:09 2007 James Edward Gray II <jeg2@ruby-lang.org>
-
- Merged 13781 from trunk.
-
- * lib/net/telnet.rb (Net::Telnet#login): Allowing "passphrase" in
- addition to "password" for Telnet login prompts. [ruby-Bugs-10746]
-
-Wed Oct 25 06:46:21 2007 James Edward Gray II <jeg2@ruby-lang.org>
-
- Merged 13779 from trunk.
-
- * lib/net/telnet.rb (Net::Telnet#login): Making the password prompt
- pattern case insensitive. [ruby-Bugs-10746]
-
-Thu Oct 25 14:19:33 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (rb_io_tell, rb_io_seek): check errno too. [ruby-dev:32093]
-
-Wed Oct 25 08:03:53 2007 James Edward Gray II <jeg2@ruby-lang.org>
-
- Merged 13767, 13768, 13769, and 13770 from trunk.
-
- * lib/xmlrpc/parser.rb (XMLRPC::Convert::dateTime): Fixing a bug that
- caused time zone conversion to fail for some ISO 8601 date formats.
- [ruby-Bugs-12677]
-
- * lib/xmlrpc/client.rb (XMLRPC::Client#do_rpc): Explicitly start
- the HTTP connection to support keepalive requests. [ruby-Bugs-9353]
-
- * lib/xmlrpc/client.rb (XMLRPC::Client#do_rpc): Improving the error
- message for Content-Type check failures. [ruby-core:12163]
-
- * lib/xmlrpc/utils.rb (XMLRPC::ParseContentType#parse_content_type):
- Making Content-Type checks case insensitive. [ruby-Bugs-3367]
-
-Sun Oct 21 21:16:43 2007 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss.rb, lib/rss/, test/rss/, sample/rss/: merged from trunk.
- - 0.1.6 -> 2.0.0.
- - fixed image module URI. Thanks to Dmitry Borodaenko.
- - supported Atom.
- - supported ITunes module.
- - supported Slash module.
-
- * NEWS: added an entry for RSS Parser.
-
-Thu Oct 18 10:57:06 2007 Tanaka Akira <akr@fsij.org>
-
- * ruby.h (RCLASS_IV_TBL): defined.
- (RCLASS_M_TBL): ditto.
- (RCLASS_SUPER): ditto.
- (RMODULE_IV_TBL): ditto.
- (RMODULE_M_TBL): ditto.
- (RMODULE_SUPER): ditto.
-
-Mon Oct 15 22:08:55 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * NEWS: Merge some of the sub-sections, as the differences were
- unclear.
-
-Mon Oct 15 21:57:07 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * NEWS: Mention ipaddr enhancements.
-
- * lib/ipaddr.rb (in_addr, in6_addr, addr_mask): Make some minor
- code optimization.
-
- * lib/ipaddr.rb (<=>): Implement IPAddr#<=> and make IPAddr
- comparable.
-
- * lib/ipaddr.rb (succ): Implement IPAddr#succ. You can now create
- a range between two IPAddr's, which (Range) object is
- enumerable.
-
- * lib/ipaddr.rb (to_range): A new method to create a Range object
- for the (network) address.
-
- * lib/ipaddr.rb (coerce_other): Support type coercion and make &,
- |, == and include? accept a string or an integer instead of an
- IPAddr object as the argument.
-
- * lib/ipaddr.rb (initialize): Give better error messages.
-
- * lib/ipaddr.rb: Improve documentation.
-
-Mon Oct 15 21:24:25 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * NEWS: Mention shellwords and tempfile enhancements.
-
- * NEWS: Move the entry about Tk::X_Scrollable to a better section.
-
-Mon Oct 15 17:28:20 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/openssl/lib/openssl/buffering.rb (read, readpartial): revert
- r12496. handling EOF is a little differnt in ruby 1.8 and ruby 1.9.
- [ruby-dev:31979]
-
-Mon Oct 15 11:45:12 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * marshal.c (r_bytes0): refined length check. [ruby-dev:32059]
-
-Mon Oct 15 09:58:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * marshal.c (r_bytes0): check if source has enough data.
- [ruby-dev:32054]
-
-Mon Oct 15 01:15:09 2007 Tanaka Akira <akr@fsij.org>
-
- * ext/socket/socket.c (s_accept_nonblock): make accepted fd
- nonblocking. [ruby-talk:274079]
-
-Sun Oct 14 04:08:34 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (AC_SYS_LARGEFILE): keep results also in command
- options, to vail out of mismatch. [ruby-list:44114]
-
- * mkconfig.rb, lib/mkmf.rb (configuration): add DEFS.
-
-Sun Oct 14 03:55:52 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/mkexports.rb: deal with __fastcall name decorations.
- [ruby-list:44111]
-
-Sat Oct 13 09:02:16 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * {bcc,win}32/mkexports.rb: explicit data. [ruby-list:44108]
-
-Sat Oct 13 00:35:03 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/rexml/source.rb (REXML::SourceFactory::SourceFactory): typo
- fixed. [ruby-list:44099]
-
-Fri Oct 12 11:22:15 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * re.c (match_values_at): make #select to be alias to #values_at
- to adapt RDoc description. [ruby-core:12588]
-
-Thu Oct 11 14:32:46 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * {bcc32,win32}/Makefile.sub (COMMON_MACROS): workaround for old SDK's
- bug. [ruby-core:12584]
-
-Wed Oct 10 23:34:45 2007 Tanaka Akira <akr@fsij.org>
-
- * lib/securerandom.rb: new file. [ruby-dev:31928]
-
- * lib/cgi/session.rb (create_new_id): use securerandom if available.
-
-Tue Oct 9 01:01:55 2007 Tanaka Akira <akr@fsij.org>
-
- * re.c (rb_reg_s_union_m): Regexp.union accepts single
- argument which is an array of patterns. [ruby-list:44084]
-
-Mon Oct 8 20:06:23 2007 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/net/http.rb, lib/open-uri.rb: remove
- Net::HTTP#enable_post_connection_check. [ruby-dev:31960]
-
- * lib/net/imap.rb: hostname should be verified against server's
- indentity as persented in the server's certificate. [ruby-dev:31960]
-
- * ext/openssl/lib/net/telnets.rb, ext/openssl/lib/net/ftptls.rb: ditto.
-
-Sat Oct 6 23:14:54 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * string.c (rb_str_to_i): update RDoc since base can be any value
- between 2 and 36. [ruby-talk:272879]
-
-Fri Oct 5 15:44:50 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/shellwords.rb: Add shellescape() and shelljoin().
-
- * lib/shellwords.rb: Rename shellwords() to shellsplit() and make
- the former an alias to the latter.
-
- * lib/shellwords.rb: Add escape(), split(), join() as class
- methods, which are aliases to their respective long names
- prefixed with `shell'.
-
- * lib/shellwords.rb: Add String#shellescape(), String#shellsplit()
- and Array#shelljoin() for convenience.
-
-Fri Oct 5 15:40:04 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/tempfile.rb (Tempfile::make_tmpname): Allow to specify a
- suffix for a temporary file name.
-
- * lib/tempfile.rb (Tempfile::make_tmpname): Make temporary file
- names less predictable by including a random string.
- [inspired by: akr]
-
-Tue Oct 2 21:20:14 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (make_cmdvector): adjust escaped successive
- double-quote handling. (merge from trunk)
-
-Tue Oct 2 20:35:24 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (init_env): initialize HOME and USER environment
- variables unless set. [ruby-core:12328] (merge from trunk)
-
- * win32/win32.c (NtInitialize, getlogin): ditto.
-
- * configure.in, win32/Makefile.sub (LIBS): need to link shell32
- library for SH* functions on mswin32 and mingw32.
-
-Mon Oct 1 12:50:59 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * gc.c (id2ref): valid id should not refer T_VALUE nor T_ICLASS.
- [ruby-dev:31911]
-
-Wed Sep 26 23:54:37 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb (extmake), lib/mkmf.rb (configuration): top_srcdir
- should not prefixed with DESTDIR.
-
-Wed Sep 26 08:36:31 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * Makefile.in (ext/extinit.o): use $(OUTFLAG) as well as other
- objects. [ruby-Bugs-14228]
-
-Wed Sep 26 05:12:17 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (yyerror): limit error message length. [ruby-dev:31848]
-
- * regex.c (re_mbc_startpos): separated from re_adjust_startpos.
-
-Tue Sep 25 13:47:38 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (remove_method): should not remove undef place holder.
- [ruby-dev:31817]
-
-Mon Sep 24 16:52:11 2007 Urabe Shyouhei <shyouhei@ruby-lang.org>
-
- * lib/net/http.rb: fix typo.
-
-Sun Sep 23 21:57:25 2007 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/net/http.rb: an SSL verification (the server hostname should
- be matched with its certificate's commonName) is added.
- this verification can be skipped by
- "Net::HTTP#enable_post_connection_check=(false)".
- suggested by Chris Clark <cclark at isecpartners.com>
-
- * lib/net/open-uri.rb: use Net::HTTP#enable_post_connection_check to
- perform SSL post connection check.
-
- * ext/openssl/lib/openssl/ssl.c
- (OpenSSL::SSL::SSLSocket#post_connection_check): refine error message.
-
-Sun Sep 23 09:05:05 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * gc.c (os_obj_of, os_each_obj): hide objects to be finalized.
- [ruby-dev:31810]
-
-Sun Sep 23 08:58:01 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval_method.ci (rb_attr): should not use alloca for unknowen size
- input. [ruby-dev:31816]
-
- * parse.y (rb_intern_str): prevent str from optimization.
-
-Sun Sep 23 05:42:35 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * lib/rdoc/options.rb (Options::check_diagram): dot -V output
- changed. [ ruby-Bugs-11978 ], Thanks Florian Frank.
-
-Sat Sep 22 06:02:11 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/optparse.rb (OptionParser::List::summarize): use each_line if
- defined rather than each. [ruby-Patches-14096]
-
-Sat Sep 22 05:19:49 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/stringio/stringio.c (strio_init): separate from strio_initialize
- to share with strio_reopen properly. [ruby-Bugs-13919]
-
-Fri Sep 21 15:46:20 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * process.c (struct rb_exec_arg): proc should be a VALUE.
-
- * process.c (rb_f_exec): suppress a warning.
-
-Fri Sep 21 03:05:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c, intern.h, ext/thread/thread.c: should not free queue while
- any live threads are waiting. [ruby-dev:30653]
-
-Thu Sep 20 17:24:59 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * process.c (rb_detach_process): cast for the platforms where size of
- pointer differs from size of int.
-
- * process.c (rb_f_exec, rb_f_system): should not exceptions after
- fork. [ruby-core:08262]
-
-Fri Sep 14 00:34:25 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/drb/extservm.rb (invoke_service): use Thread.exclusive instead of
- Thread.critical
-
-Wed Sep 12 23:12:22 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ruby.c (proc_options): -W should be allowed in RUBYOPT
- environment variable. [ruby-core:12118]
-
-Mon Sep 10 01:05:25 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Sep 17 04:37:10 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* range.c (range_step): fixed integer overflow. [ruby-dev:31763]
-Sun Sep 9 09:14:45 2007 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date/format.rb (_strptime): now also attaches an element
- which denotes leftover substring if exists.
-
-Sat Sep 8 10:22:20 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * struct.c (rb_struct_s_members): should raise TypeError instead
- of call rb_bug(). [ruby-dev:31709]
-
- * marshal.c (r_object0): no nil check require any more.
+Fri Sep 7 17:06:16 2007 Vincent Isambart <vincent.isambart@gmail.com>
-Sat Sep 8 09:38:19 2007 Tadayoshi Funaba <tadf@dotrb.org>
+ * eval.c (rb_thread_start_0): should unset time_thread_alive_p.
+ [ruby-talk:257219], [ruby-core:11542], [ruby-dev:31253]
- * lib/date/format.rb (str[fp]time): now check specifications more
- strictly.
-
-Fri Sep 7 05:36:19 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * test/rinda/test_rinda.rb (MockClock): correct synchronous problems
- of the MultiThreading. [ruby-dev:31692]
-
-Wed Sep 5 22:02:27 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+Fri Sep 7 16:39:23 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_subseq): need integer overflow check.
[ruby-dev:31736]
@@ -3331,116 +19,39 @@ Wed Sep 5 22:02:27 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_splice): integer overflow for length.
[ruby-dev:31739]
-Sun Sep 2 00:48:15 2007 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date/format.rb (_parse): improved parsing of ordinal dates.
-
- * lib/date/format.rb (_parse): use named character classes in some
- regular expressions.
-
-Sat Sep 1 08:13:36 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c: add WIN32OLE#ole_activex_initialize.
-
-Thu Aug 30 13:13:13 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb (try_const, have_const): check for a const is defined.
- [ruby-core:04422]
-
-Thu Aug 30 13:10:57 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (group_member): check if presents.
-
- * configure.in (XCFLAGS): add _GNU_SOURCE on linux.
-
- * file.c (group_member): use system routine if available.
-
-Thu Aug 30 08:24:18 2007 Tanaka Akira <akr@fsij.org>
-
- * ruby.h (RHASH_TBL): defined for compatibility to 1.9.
- * (RHASH_ITER_LEV): ditto.
- * (RHASH_IFNONE): ditto.
- * (RHASH_SIZE): ditto.
- * (RHASH_EMPTY_P): ditto.
-
-Wed Aug 29 13:05:59 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+Fri Sep 7 16:33:23 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* include/ruby/defines.h (flush_register_windows): call "ta 0x03"
even on Linux/Sparc. [ruby-dev:31674]
-Tue Aug 28 23:26:12 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+Fri Sep 7 16:09:39 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
- * ext/win32ole/win32ole.c (ole_type_progid, reg_enum_key,
- reg_get_val, ole_wc2mb): fix the bug. Thanks, arton.
+ * ext/win32ole/win32ole.c (ole_type_progid, reg_enum_key,
+ reg_get_val, ole_wc2mb): fix the bug. Thanks, arton.
[ruby-dev:31576]
-Mon Aug 27 19:10:50 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/etc/etc.c (etc_getlogin): update documentation to note
- security issue. [ruby-Bugs-11821]
-
-Tue Aug 21 21:09:48 2007 Tanaka Akira <akr@fsij.org>
-
- * lib/tmpdir.rb (Dir.mktmpdir): make directory suffix specifiable.
-
-Tue Aug 21 13:57:04 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * hash.c (st_foreach_func, rb_foreach_func): typedefed.
-
-Mon Aug 20 17:25:33 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+Fri Sep 7 15:50:50 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (mnew): should preserve noex as safe_level.
* eval.c (rb_call0): tighten security check condition..
-Sat Aug 18 21:32:20 2007 Tanaka Akira <akr@fsij.org>
-
- * lib/tmpdir.rb (Dir.mktmpdir): new method.
- [ruby-dev:31462]
-
-Sat Aug 18 17:44:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Sep 7 15:43:43 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/tk/tcltklib.c (Init_tcltklib): use rb_set_end_proc().
-Sat Aug 18 15:59:52 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Sep 7 15:42:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* process.c (detach_process_watcher): should not pass the pointer
to an auto variable to the thread to be created. pointed and
fix by KUBO Takehiro <kubo at jiubao.org> [ruby-dev:30618]
-Sat Aug 18 12:24:30 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Sep 7 15:40:47 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sample/test.rb, test/ruby/test_system.rb(valid_syntax?): keep
comment lines first.
-Thu Aug 16 20:40:50 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * bignum.c (bigtrunc): RBIGNUM(x)->len may be zero. out of bound
- access. [ruby-dev:31404]
-
-Thu Aug 16 16:46:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (aix): enable shared by default.
-
- * configure.in (aix): for 64bit-mode AIX. [ruby-dev:31401]
- + use CC for LDSHARED if non-gcc,
- + moved -G option from *LDFLAGS to LDSHARED,
- + set -brtl only in XLDFLAGS.
-
-Thu Aug 16 13:06:08 2007 Tanaka Akira <akr@fsij.org>
-
- * bignum.c (big_lshift): make shift offset long type.
- (big_rshift): ditto.
- (rb_big_lshift): ditto.
- (big_rshift): ditto.
- [ruby-dev:31434]
-
-Thu Aug 16 04:09:19 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/rinda/tuplespace.rb (Rinda::TupleSpace#start_keeper): improve
- keeper thread.
-
-Wed Aug 15 13:50:10 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 12:40:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* hash.c (rb_hash_delete_key): delete the entry without calling block.
@@ -3452,36 +63,24 @@ Wed Aug 15 13:50:10 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
Sun Arg 12 03:56:30 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/rinda/tuplespace.rb: fix Rinda::TupleSpace keeper thread bug.
- the thread is started too early. [ruby-talk:264062]
+ the thread is started too early. [ruby-talk:264062]
* test/rinda/test_rinda.rb: ditto.
-Sat Aug 11 07:34:10 2007 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date/format.rb: reverted some wrongly erased "o" options
- (pointed out by nobu).
-
-Tue Aug 7 14:58:39 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/pty/pty.c (establishShell): handshaking before close slave
- device. [ruby-talk:263410]
-
- * ext/pty/pty.c (MasterDevice, SlaveDevice, deviceNo): constified.
-
- * ext/pty/pty.c (SlaveName): removed static buffer.
-
- * ext/pty/expect_sample.rb: support for autologin.
-
-Tue Aug 7 12:45:13 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 12:31:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (ac_cv_func_isinf): set yes also on OpenSolaris.
[ruby-Bugs-12859]
-Mon Aug 6 17:36:29 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 12:30:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/rexml/encodings/{ISO-8859-15,CP-1252}.rb: fixed invalid syntax.
-Fri Aug 3 11:05:54 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 12:29:36 2007 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * lib/README: fixed a typo.
+
+Wed Aug 22 12:13:54 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb (extmake): save all CONFIG values.
@@ -3491,37 +90,20 @@ Fri Aug 3 11:05:54 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb: remove rdoc at clean, and installed list file at
distclean, respectively.
-Fri Aug 3 07:09:05 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb: more verbose message. [ruby-Bugs-12766]
-
- * lib/mkmf.rb (have_type): suppress a warning with -Wall.
-
- * lib/mkmf.rb (find_type): new method.
-
-Thu Aug 2 13:46:39 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 11:49:00 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sprintf.c (rb_f_sprintf): should not check positional number as
width. [ruby-core:11838]
-Mon Jul 30 11:16:40 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 11:47:11 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bignum.c (rb_big_aref): check for Bignum index range.
- [ruby-dev:31271]
-
-Sat Jul 28 09:35:41 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/digest/lib/digest.rb (Digest::self.const_missing): avoid
- infinite recursive const_missing call. [ruby-talk:262193]
+ [ruby-dev:31271]
-Thu Jul 26 13:57:45 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * dln.c (load_1, dln_find_1): constified.
+Wed Aug 22 11:41:44 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* dln.c (conv_to_posix_path): removed.
- * ruby.c (usage): constified.
-
* ruby.c (rubylib_mangled_path, rubylib_mangled_path2): return
VALUE instead of a pointer to static buffer.
@@ -3530,77 +112,26 @@ Thu Jul 26 13:57:45 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (ruby_init_loadpath): not convert built-in paths.
-Sun Jul 22 16:07:12 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 11:39:31 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* intern.h (is_ruby_native_thread): removed since declared as an int
function in ruby.h already.
-Sun Jul 22 14:33:40 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (rb_file_s_rename): deleted code to get rid of a bug of
- old Cygwin.
-
- * file.c (rb_file_truncate): added prototype of GetLastError()
- on cygwin. [ruby-dev:31239]
-
- * intern.h (is_ruby_native_thread): prototype.
-
- * missing/strftime.c (strftime): fix printf format and actual
- arguments.
-
- * ext/Win32API/Win32API.c (Win32API_initialize): ditto.
-
- * ext/tk/tcltklib.c (ip_finalize): ditto.
-
- * ext/dl/ptr.c (rb_dlptr_inspect): ditto. [ruby-dev:31268]
-
- * ext/dl/sym.c (rb_dlsym_inspect): ditto.
-
- * ext/socket/getnameinfo.c: include stdio.h always.
-
- * ext/win32ole/win32ole.c (ole_hresult2msg, folevariable_name,
- folevariable_ole_type, folevariable_ole_type_detail,
- folevariable_value, folemethod_visible): missing return value.
-
-Sat Jul 21 17:48:26 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb (create_makefile): make OBJS depend on RUBY_EXTCONF_H
- only if extconf.h is created.
-
- * bcc32/{Makefile.sub,configure.bat,setup.mak: configure_args
- support.
-
- * bcc32/setup.mak: check runtime version.
-
- * win32/win32.c (rb_w32_open_osfhandle): prototype has changed
- in bcc 5.82.
-
- * {win32,wince,bcc32}/setup.mak (-version-): no RUBY_EXTERN magic.
-
- * win32/resource.rb: include patchlevel number.
-
-Sat Jul 21 12:06:48 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 11:00:20 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (init_mkmf): should remove mkmf.log too.
-Sat Jul 21 01:53:17 2007 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date/format.rb (Date._parse): completes calendar week based year.
-
- * lib/date/format.rb (Date._parse): detects year of ordinal date in
- extended format.
-
-Fri Jul 20 15:22:51 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 10:57:50 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/openssl/ossl_config.c (ossl_config_set_section): do not
initialize aggregations with dynamic values. [ruby-talk:259306]
-Thu Jul 19 19:24:14 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 10:55:00 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (get_backtrace): check the result more.
[ruby-dev:31261] [ruby-bugs-12398]
-Thu Jul 19 14:38:45 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 10:36:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bignum.c (rb_big_lshift, rb_big_rshift): separated functions
to get rid of infinite recursion. fixed calculation in edge
@@ -3608,48 +139,35 @@ Thu Jul 19 14:38:45 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* numeric.c (rb_fix_lshift, rb_fix_rshift): ditto.
-Wed Jul 18 16:57:41 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 10:29:45 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bignum.c (rb_big_pow): refine overflow check. [ruby-dev:31242]
-Wed Jul 18 08:47:09 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Aug 22 10:26:59 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* time.c (time_succ): Time#succ should return a time object in the
same timezone mode to the original. [ruby-talk:260256]
-Tue Jul 17 00:50:53 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Aug 22 10:24:00 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
- * numeric.c (fix_pow): integer power calculation: 0**n => 0,
+ * numeric.c (fix_pow): integer power calculation: 0**n => 0,
1**n => 1, -1**n => 1 (n: even) / -1 (n: odd).
* test/ruby/test_fixnum.rb (TestFixnum::test_pow): update test
suite. pow(-3, 2^64) gives NaN when pow(3, 2^64) gives Inf.
-Mon Jul 16 23:07:51 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Aug 22 10:23:01 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/base64.rb (Base64::b64encode): should not specify /o option
for regular expression. [ruby-dev:31221]
-Mon Jul 16 18:29:33 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * string.c (rb_str_rindex_m): accept string-like object convertible
- with #to_str method, as well as rb_str_index_m. [ruby-core:11692]
-
-Mon Jul 16 05:45:53 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 10:20:32 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sprintf.c (rb_f_sprintf): more checks for format argument.
[ruby-core:11569], [ruby-core:11570], [ruby-core:11571],
[ruby-core:11573]
-Mon Jul 16 00:26:10 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big_pow): removed invariant variable. [ruby-dev:31236]
-
-Sun Jul 15 23:59:57 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big_neg): SIGNED_VALUE isn't in 1.8.
-
-Sun Jul 15 22:24:49 2007 pegacorn <subscriber.jp AT gmail.com>
+Wed Aug 22 10:13:45 2007 pegacorn <subscriber.jp AT gmail.com>
* ext/digest/digest.c (rb_digest_instance_update,
rb_digest_instance_finish, rb_digest_instance_reset,
@@ -3675,198 +193,101 @@ Sun Jul 15 22:24:49 2007 pegacorn <subscriber.jp AT gmail.com>
* win32.h (rb_w32_getcwd): prototype added. [ruby-dev:31232]
-Sun Jul 15 21:07:43 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (bigtrunc): do not empty Bignum. [ruby-dev:31229]
-
-Sun Jul 15 19:05:28 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 10:11:59 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bignum.c (rb_cstr_to_inum): check leading non-digits.
[ruby-core:11691]
-Sun Jul 15 04:42:20 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 10:07:48 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * bignum.c (get2comp): do nothing for empty Bignum. [ruby-dev:31225]
-
-Sat Jul 14 14:04:06 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * enum.c (sort_by_cmp): check if reentered. [ruby-dev:24291]
-
-Sat Jul 14 12:44:14 2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * test/openssl/test_pkcs7.rb: reverted the previous patch. it should
- be as it was to check interface compatibility. sorry for bothering
- with this.
-
-Sat Jul 14 12:16:17 2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+ * bignum.c (rb_big_neg): SIGNED_VALUE isn't in 1.8.
- * test/openssl/test_pkcs7.rb: follow the library change. applied a
- patch from <zn at mbf.nifty.com> [ruby-dev:31214].
- NOTE: r12496 imports the latest openssl libs from trunk to ruby_1_8
- though its's not ChangeLog-ed. maintainer should aware that.
+ * bignum.c (bigtrunc): do not empty Bignum. [ruby-dev:31229]
-Sat Jul 14 02:51:52 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Aug 22 10:02:42 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* numeric.c (fix_pow): 0**2 should not raise floating point
exception. [ruby-dev:31216]
-Sat Jul 14 02:25:48 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * numeric.c (int_pow): wrong overflow detection. [ruby-dev:31213]
-
- * numeric.c (int_pow): wrong overflow detection. [ruby-dev:31215]
-
-Fri Jul 13 16:10:00 2007 Tanaka Akira <akr@fsij.org>
-
- * lib/open-uri.rb (URI::Generic#find_proxy): use ENV.to_hash to access
- http_proxy environment variable to avoid case insensitive
- environment search.
-
-Fri Jul 13 15:02:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 10:01:08 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/win32.c (CreateChild): enclose command line except for
command.com which can not handle quotes. [ruby-talk:258939]
-Fri Jul 13 10:10:46 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 09:58:30 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (link_command, cc_command, cpp_command): do not expand
::CONFIG which is an alias of MAKEFILE_CONFIG.
-Thu Jul 12 17:03:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 09:55:08 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* struct.c (rb_struct_init_copy): disallow changing the size.
[ruby-dev:31168]
-Wed Jul 11 23:38:14 2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Wed Aug 22 09:54:28 2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* random.c: documentation fix. srand(0) initializes PRNG with '0',
not with random_seed.
-Tue Jul 10 14:50:01 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 09:53:14 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bcc32/{Makefile.sub,setup.mak}: remove surplus slash from srcdir.
-Fri Jul 6 15:22:58 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_interrupt): suppress a gcc's officious warning.
-
-Thu Jul 5 16:44:28 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * numeric.c (int_pow): fix previous nubu's commit.
-
- * test/ruby/test_fixnum.rb: new test.
-
-Thu Jul 5 15:56:06 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * numeric.c (int_pow): even number multiplication never be negative.
-
-Mon Jul 2 14:34:43 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 09:46:25 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sprintf.c (rb_f_sprintf): sign bit extension should not be done
if FPLUS flag is specified. [ruby-list:39224]
-Sat Jun 30 16:05:41 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Aug 22 09:41:56 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_initialize): should call rb_ary_modify() first.
[ruby-core:11562]
-Sat Jun 30 00:17:00 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 09:40:25 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (yylex): return non-valid token for an invalid
- instance/class variable name. a patch from Yusuke ENDOH
+ instance/class variable name. a patch from from Yusuke ENDOH
<mame AT tsg.ne.jp>. [ruby-dev:31095]
-Fri Jun 29 11:23:09 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 09:39:26 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (dsym): return non-null NODE even if yyerror(). based on a
- patch from Yusuke ENDOH <mame AT tsg.ne.jp>. [ruby-dev:31085]
+ patch from from Yusuke ENDOH <mame AT tsg.ne.jp>. [ruby-dev:31085]
-Tue Jun 26 16:35:21 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * process.c (ruby_setreuid, ruby_setregid): rename to get rid of name
- clash.
+Wed Aug 22 09:38:43 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* process.c (proc_exec_v, rb_proc_exec): preserve errno.
-Sat Jun 23 00:37:46 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * hash.c (rb_hash_select): remove unnecessary varargs for
- rb_hash_select. a patch from Daniel Berger
- <Daniel.Berger at qwest.com>. [ruby-core:11527]
-
- * hash.c: ditto.
-
-Mon Jun 18 08:47:54 2007 Technorama Ltd. <oss-ruby@technorama.net>
-
- * ext/openssl/{extconf.rb,ossl_ssl_session.c}:
- Fix ruby-Bugs-11513.
-
- * ext/openssl/ossl_pkey_ec.c
- New methods EC::Point.[eql,make_affine!,invert!,on_curve?,infinity?]
- By default output the same key form as the openssl command.
-
- * ext/openssl/ossl_rand.c
- New method Random.status?
-
-Mon Jun 18 13:54:36 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 09:00:23 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (ruby_cleanup): return EXIT_FAILURE if any exceptions occured
in at_exit blocks. [ruby-core:11263]
-Mon Jun 18 01:14:10 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 08:52:02 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* variable.c (rb_path2class): get rid of dangling pointer caused by
optimized out value.
- * variable.c (rb_global_entry, rb_f_untrace_var, rb_alias_variable,
- rb_generic_ivar_table, generic_ivar_get, generic_ivar_set,
- generic_ivar_defined, generic_ivar_remove, rb_mark_generic_ivar,
- rb_free_generic_ivar, rb_copy_generic_ivar,
- rb_obj_instance_variables): suppress warnings.
-
-Fri Jun 15 22:33:29 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * common.mk (realclean): separate local and ext.
-
- * ext/extmk.rb: not remove unrelated directories.
-
-Fri Jun 15 17:01:20 2007 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Aug 22 08:51:20 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/dl/lib/dl/win32.rb: seems that dl doesn't accept void argument.
fixed [ruby-bugs:PR#5489].
-Thu Jun 14 17:09:48 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser): handle more
- extensions. [ruby-dev:30972]
-
-Wed Jun 13 06:05:12 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 08:49:47 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (darwin): prohibit loading extension libraries to
miniruby.
-Wed Jun 13 05:47:58 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 08:34:20 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_kill_thread): renamed in order to get rid of conflict
with a BeOS system function. [ruby-core:10830]
-Tue Jun 12 14:53:51 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb (Logging.quiet, Logging.message): added quiet flag and
- use it. [ruby-core:10909]
-
- * lib/mkmf.rb (find_header): use header names in the message.
-
-Sun Jun 10 13:47:36 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 08:32:32 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * test/ruby/test_beginendblock.rb (test_should_propagate_signaled):
- get rid of invoking shell. [ruby-dev:30942]
-
-Thu Jun 7 19:02:48 2007 Tanaka Akira <akr@fsij.org>
-
- * lib/pp.rb: call original "method" method instead of redefined one.
-
-Mon Jun 4 11:11:12 2007 Shugo Maeda <shugo@ruby-lang.org>
+ * process.c (ruby_setreuid, ruby_setregid): rename to get rid of name
+ clash.
+Wed Aug 22 08:27:53 2007 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (ResponseParser#next_token): fixed
error message. (backported from HEAD)
@@ -3875,20 +296,28 @@ Mon Jun 4 11:11:12 2007 Shugo Maeda <shugo@ruby-lang.org>
the condition not to refer @token.symbol unexpectedly.
Thanks, Dick Monahan. (backported from HEAD)
-Thu May 31 17:27:53 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 22 08:26:33 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/benchmark.rb (Benchmark::Job::item): avoid modifying the
- argument unintentionally. [ruby-talk:253676]
+ * marshal.c (w_extended): erroneous check condition when dump
+ method is defined. [ruby-core:10646]
+
+Mon Jun 18 11:29:49 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Thu May 31 02:12:32 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+ * intern.h, ext/thread/thread.c: moved prototype of rb_thread_status()
+ to get rid of error in C++. [ruby-list:43615]
- * lib/rinda/tuplespace.rb (Rinda::TupleBag): create index on tuple bag
- by first column.
+Sun Jun 10 13:47:36 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Wed May 30 13:27:40 2007 Shugo Maeda <shugo@ruby-lang.org>
+ * test/ruby/test_beginendblock.rb (test_should_propagate_signaled):
+ get rid of invoking shell. [ruby-dev:30942]
- * lib/net/ftp.rb (Net::FTP#transfercmd): skip 2XX
- responses for some FTP servers. (backported from HEAD)
+Sat Jun 9 10:40:00 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
+
+ * stable version 1.8.6-p36 released.
+
+Fri Jun 8 17:50:17 2007 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * eval.c (rb_thread_cancel_timer): fix undefined function
Wed May 30 05:17:55 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -3913,16 +342,34 @@ Tue May 29 11:01:06 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/win32.c (rb_w32_opendir, rb_w32_readdir): eliminate magic
numbers.
-Mon May 28 02:54:05 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Thu Jun 7 20:10:51 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/rinda/tuplespace.rb (Rinda::TupleBag#delete): use rindex and
- delete_at instead of delete for little improvement.
+ * eval.c, intern.h, ext/thread/thread.c: should not free queue
+ while any live threads are waiting.
+ [ruby-dev:30653]
-Sat May 26 00:05:22 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Jun 7 14:53:46 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
- * test/ruby/test_beginendblock.rb (test_should_propagate_signaled):
- skip tests for exitstatus and termsig on the platforms where
- signals not supported.
+ * eval.c (method_inspect): show proper class name.
+ [ruby-talk:248647], Thanks Calamitas.
+
+Sun May 27 05:24:56 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
+
+ * runruby.rb: eliminate uninitialized variable.
+ [ruby-core:11255]
+
+Sun May 27 05:19:03 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
+
+ * eval.c (mnew): call of super via a method object should work again.
+ [ruby-talk:248647], Thanks Calamitas.
+
+ * test/ruby/test_method.rb (TestMethod::test_method_super): test for
+ above fix.
+
+Wed May 23 07:29:53 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
+
+ * process.c (proc_exec_v): terminate timer thread in advance.
+ [ruby-dev:30581], Thanks H. Holon.
Wed May 23 06:51:46 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
@@ -3935,119 +382,35 @@ Wed May 23 05:49:49 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
load path to get rid of load pre-installed extensions/libraries.
[ruby-core:11017]
-Sat May 19 10:29:18 2007 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date/format.rb (Date._parse): detects some OFX dates
- (Of course not fully).
-
-Fri May 18 23:07:33 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * array.c (rb_ary_first): call rb_ary_subseq() instead of pushing
- values by itself. [ruby-talk:252062]
-
- * array.c (rb_ary_first): add negative length check.
-
-Fri May 18 17:10:31 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed May 23 06:14:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/win32.c (move_to_next_entry): loc also must move forward.
[ruby-talk:251987]
-Fri May 18 03:02:40 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/mkexports.rb: preserve prefixed underscores for WINAPI
- symbols.
-
- * wince/mkconfig_wce.rb, wince/mkexports.rb: obsolete.
-
-Thu May 17 17:03:11 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * misc/ruby-style.el (ruby-style-label-indent): for yacc rules.
-
-Tue May 15 14:54:07 2007 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed May 23 05:55:04 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (init_stdhandle): stderr should be without buffering,
but mswin32 use buffering when stderr is not connected to tty.
-Mon May 14 13:28:03 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed May 23 05:35:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/thread/thread.c (wait_list): supress a warning.
+ * bignum.c (rb_big_pow): truncate all zero BDIGITs. [ruby-dev:30733]
-Thu May 10 15:21:51 2007 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed May 23 05:17:33 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/iconv/iconv.c (iconv_s_conv): rdoc fix.
-Thu May 10 10:14:14 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed May 23 05:10:02 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_thread_priority): rdoc fix; the initial value is
inherited from the creating thread. [ruby-core:10607]
-Wed May 9 12:28:57 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (Init_Bignum), numeric.c (Init_Numeric): added fdiv as
- aliases of quo. [ruby-dev:30771]
-
-Wed May 9 11:55:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big_quo): now calculate in integer. [ruby-dev:30753]
-
-Wed May 9 11:51:06 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big_pow): reduce multiplying for even number.
-
- * bignum.c (rb_big_pow): truncate all zero BDIGITs. [ruby-dev:30733]
-
- * bignum.c (rb_big_pow): improvement by calculating from MSB and using
- factorization. <http://yowaken.dip.jp/tdiary/20070426.html#p01>
-
- * numeric.c (int_pow): calculate power in Fixnum as possible.
- [ruby-dev:30726]
-
-Tue May 8 23:42:51 2007 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date/format.rb (Date._parse): revised treatment of
- hyphened/separatorless dates.
-
- * lib/date/format.rb: some trivial adjustments.
-
-Tue May 8 20:25:05 2007 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date/format.rb: reverted.
-
-Sat May 5 16:26:33 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/date/format.rb (Format::Bag#method_missing): get rid of
- modifying orginal argument. [ruby-core:11090]
-
-Mon Apr 30 01:17:51 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/rinda/tuplespace.rb (TupleSpace#create_entry, TupleBag#push,
- delete): extract method, and rename parameter.
-
-Fri Apr 27 02:00:17 2007 Ryan Davis <ryand-ruby@zenspider.com>
-
- * signal.c: Fixed backwards compatibility for 'raise Interrupt'.
-
- * lib/yaml/tag.rb: Running rdoc over the 1.8.6 tree skips
- Module. Patch from James Britt
-
-Thu Apr 26 13:54:51 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * misc/ruby-style.el: new file. C/C++ style for ruby source code.
-
-Wed Apr 25 19:49:16 2007 Tanaka Akira <akr@fsij.org>
-
- * ext/socket/socket.c (unix_send_io, unix_recv_io): use CMSG_DATA to
- align file descriptor appropriately.
-
-Tue Apr 24 09:33:57 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed May 23 04:22:57 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* dir.c (do_stat, do_lstat, do_opendir): should not warn ENOTDIR.
[ruby-talk:248288]
-Mon Apr 23 22:14:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb ($ruby): add extout directory to include path.
- [ruby-core:11003]
+Wed May 23 03:50:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (libpathflag): not to append RPATHFLAG to current
directory.
@@ -4057,29 +420,16 @@ Mon Apr 23 22:14:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (LINK_SO): LIBPATH to be placed before DLDFLAGS.
-Fri Apr 20 16:05:22 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (LIBPATHFLAG, RPATHFLAG): no needs to be quoted,
- it is done by libpathflag in mkmf.rb.
-
-Fri Apr 20 12:27:04 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/optparse.rb: fix to override conv proc.
-
-Fri Apr 20 12:17:05 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (ruby_cleanup): inversed the order of errinfos.
-
-Thu Apr 19 14:53:32 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed May 23 03:33:55 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/monitor.rb (ConditionVariable#wait, mon_enter, mon_exit_for_cond):
ensures Thread.critical to be false. [ruby-talk:248300]
-Wed Apr 18 10:41:21 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed May 23 03:25:13 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* util.c (ruby_strtod): exponent is radix 10. [ruby-talk:248272]
-Wed Apr 18 02:30:24 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed May 23 03:12:17 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (LDFLAGS): prepend -L. instead appending it to
XLDFLAGS. [ruby-core:10933]
@@ -4087,7 +437,7 @@ Wed Apr 18 02:30:24 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (Makefile): remove $U for automake from MISSING.
[ruby-talk:248171]
-Tue Apr 17 16:46:46 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed May 23 02:09:32 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_yield_0): should not clear state on TAG_NEXT when
it's invoked from within lambda body. [ruby-talk:248136]
@@ -4095,66 +445,25 @@ Tue Apr 17 16:46:46 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (proc_invoke): handle TAG_NEXT which would be caused by
next in the lambda body as well.
-Mon Apr 16 22:56:01 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/pty/expect_sample.rb: avoid symbolic link representation for
- expect. a patch from Kazuhiro NISHIYAMA <zn at mbf.nifty.com>.
- [ruby-dev:30714]
-
-Mon Apr 16 22:51:11 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * sample: replace TRUE, FALSE with true, false respectively.
- a patch from Kazuhiro NISHIYAMA <zn at mbf.nifty.com>.
- [ruby-dev:30713]
-
-Mon Apr 16 17:08:02 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/optparse.rb (make_switch): do not clobber converter if pattern
- has no convert method. reported by sheepman in [ruby-dev:30709].
-
-Mon Apr 16 16:49:32 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/stringio/stringio.c (strio_seek): consistent behavior with
- IO#seek. patch by sheepman in [ruby-dev:30710].
-
-Mon Apr 16 16:34:08 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (parser_yylex): should set command_start after block
- starting "do"s and braces. [ruby-core:10916]
-
-Sun Apr 15 09:19:57 2007 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date/format.rb: added some zone names.
-
- * lib/date/format.rb (_parse): now interprets doted numerical
- dates as a big endian (except dd.mm.yyyy).
-
-Tue Apr 10 17:37:36 2007 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed May 23 01:55:49 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_fclose, rb_w32_close): need to save errno
before calling original fclose()/close().
-Mon Apr 9 09:30:44 2007 Shugo Maeda <shugo@ruby-lang.org>
+Wed May 23 01:42:29 2007 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (disconnect): call shutdown for
SSLSocket. Thanks, Technorama Ltd.
-Thu Apr 5 00:42:48 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed May 23 01:28:14 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* error.c (rb_notimplement), io.c (pipe_open): removed definite
articles and UNIX manual section from messages. [ruby-dev:30690]
-Wed Apr 4 17:09:17 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (pipe_open): refined the message of NotImplementedError.
- [ruby-dev:30685]
-
-Wed Apr 4 10:18:04 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
* io.c (pipe_open): raise NotImplementedError for command "-" on
platforms where fork(2) is not available. [ruby-dev:30681]
-Tue Apr 3 15:45:41 2007 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed May 23 00:03:42 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/socket/socket.c (s_recv, s_recvfrom): some systems (such as
windows) doesn't set fromlen if the socket is connection-oriented.
@@ -4172,7 +481,7 @@ Sat Mar 24 23:40:29 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (io_fread): ditto.
-Sat Mar 24 01:54:03 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue May 22 23:27:16 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (ruby_cleanup): exit by SystemExit and SignalException in END
block. [ruby-core:10609]
@@ -4183,55 +492,26 @@ Sat Mar 24 01:54:03 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/ruby/test_beginendblock.rb (test_should_propagate_signaled):
test for signal in END block.
-Thu Mar 22 23:13:17 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue May 22 23:14:19 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_provided): check for extension library if SOEXT is
explicitly given. [ruby-dev:30657]
-Thu Mar 22 10:29:25 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * test/ruby/test_bignum.rb (test_to_s): add tests for Bignum#to_s.
-
-Wed Mar 21 17:04:30 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue May 22 21:29:08 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bignum.c (rb_big2str0): round up for the most significant digit.
[ruby-core:10686]
-Wed Mar 21 07:21:24 2007 Akinori MUSHA <knu@iDaemons.org>
+Tue May 22 20:53:02 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/thread/thread.c (remove_one): Preserve List invariants;
submitted by: MenTaLguY <mental AT rydia.net>
in [ruby-core:10598] and [ruby-bugs:PR#9388].
-Tue Mar 20 22:54:50 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * marshal.c (w_extended): erroneous check condition when dump
- method is defined. [ruby-core:10646]
-
Tue Mar 20 15:37:24 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
* distruby.rb: Add zip generation.
-Tue Mar 20 11:28:41 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/matrix.rb (Matrix::inverse_from): adding partial pivoting to
- the Gauss-Jordan algorithm, making it stable. a patch from
- Peter Vanbroekhoven. [ruby-core:10641]
-
-Mon Mar 19 11:39:29 2007 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/protocol.rb (rbuf_read): extend buffer size for speed.
-
-Sun Mar 18 04:23:52 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * NEWS: Add a note about the new `date' library defining
- Time#to_date and Time#to_datetime private methods.
-
- * NEWS: Inform that the old `thread' library is considered to be
- stable.
-
- * NEWS: Sort library entries in alphabetical order.
-
Fri Mar 16 21:48:11 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/dl/dl.c (rb_ary2cary): Fix a bug in type validation;
@@ -4272,24 +552,11 @@ Wed Mar 14 12:30:00 2007 Shigeo Kobayashi <shigeo@tinyforest.jp>
* ext/bigdecimal/bigdecimal.c: BigDecimal("-.31") is now
treated as ("-0.31") not as ("0.31").
-Tue Mar 13 09:25:10 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * common.mk (clear-installed-list): separated from install-prereq.
-
-Tue Mar 13 06:38:43 2007 Akinori MUSHA <knu@iDaemons.org>
+Tue Mar 13 04:04:04 2007 Akinori MUSHA <knu@iDaemons.org>
- * NEWS: Reword and improve entries.
+ * stable version 1.8.6 released.
-Tue Mar 13 06:03:46 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * stable version 1.8.6 released from the ruby_1_8_6 branch.
-
-Tue Mar 13 03:24:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * runruby.rb: added --pure (turned on by default) and --debugger
- options.
-
-Tue Mar 13 02:50:28 2007 Akinori MUSHA <knu@iDaemons.org>
+Tue Mar 13 02:54:17 2007 Akinori MUSHA <knu@iDaemons.org>
* lib/cgi.rb (CGI::header): IIS >= 5.0 does not need the nph
assumption any more; submitted by MIYASAKA Masaru <alkaid AT
@@ -4321,7 +588,7 @@ Mon Mar 12 11:07:44 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/openssl/ossl_ssl.c (Init_ossl_ssl): Ditto.
-Mon Mar 12 01:05:17 2007 Akinori MUSHA <knu@iDaemons.org>
+Mon Mar 12 01:23:50 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/dl/sym.c (rb_dlsym_inspect): Use "0x%x" rather for pointers.
This might not be very right but it is commonly used in other
@@ -4330,16 +597,14 @@ Mon Mar 12 01:05:17 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/dl/ptr.c (rb_dlptr_inspect): Ditto.
-Mon Mar 12 00:59:19 2007 Akinori MUSHA <knu@iDaemons.org>
-
* ext/dl/lib/dl/import.rb (DL::Importable::Internal::import,
DL::Importable::Internal::callback): Avoid race condition for an
instance variable; submitted by sheepman <sheepman AT
sheepman.sakura.ne.jp> in [ruby-dev:30530].
-Sun Mar 11 18:57:50 2007 Akinori MUSHA <knu@iDaemons.org>
+Sun Mar 11 19:04:29 2007 Akinori MUSHA <knu@iDaemons.org>
- * misc/README: Add a note about ruby-electric.el.
+ * misc/README: Add a note about ruby-electric.el.
* misc/ruby-mode.el (ruby-non-block-do-re): Fix
ruby-non-block-do-re. [ruby-core:03719]
@@ -4350,14 +615,14 @@ Sun Mar 11 18:57:50 2007 Akinori MUSHA <knu@iDaemons.org>
interface based on rubydb3x.el; submitted by Martin Nordholts
<enselic AT gmail.com> in [ruby-bugs:PR#9023].
-Sun Mar 11 17:45:51 2007 Akinori MUSHA <knu@iDaemons.org>
+Sun Mar 11 17:51:46 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/dl/mkcallback.rb (mkfunc): Make sure that a callback
function is found in the function table before trying to call
it; submitted by sheepman <sheepman AT sheepman.sakura.ne.jp>
in [ruby-dev:30524].
-Sun Mar 11 12:09:37 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Mar 11 17:30:53 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (error_handle): no message when exiting by signal.
@@ -4380,83 +645,63 @@ Sun Mar 11 12:09:37 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* signal.c (rb_signal_exec, trap): handle SIGTERM. [ruby-dev:30505]
-Tue Mar 6 19:08:46 2007 Akinori MUSHA <knu@iDaemons.org>
+Tue Mar 6 19:03:42 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/digest/lib/md5.rb (MD5::new, MD5::md5): Do not modify
Digest::MD5.
* ext/digest/lib/sha1.rb (SHA1::new, SHA1::sha1): Ditto.
-Tue Mar 6 18:58:37 2007 Keiju Ishitsuka <keiju@ruby-lang.org>
-
* lib/shell/process-controller.rb: fix thread synchronization
problem for [ruby-dev:30477].
-Tue Mar 6 18:44:26 2007 Akinori MUSHA <knu@iDaemons.org>
-
* ext/digest/lib/md5.rb (MD5::new, MD5::md5): Catch up with
Digest's API changes; noted by: Kazuhiro Yoshida <moriq AT
moriq.com> in [ruby-dev:30500].
* ext/digest/lib/sha1.rb (SHA1::new, SHA1::sha1): Ditto.
-
-Tue Mar 6 18:24:19 2007 Akinori MUSHA <knu@iDaemons.org>
-
+
* time.c (time_to_s): Back out the format changes; discussed
in [ruby-dev:30495].
-Tue Mar 6 11:53:25 2007 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
* ext/tk/sample/irbtkw.rbw: fails to exit process.
-Mon Mar 5 20:14:49 2007 Akinori MUSHA <knu@iDaemons.org>
+Mon Mar 5 20:26:10 2007 Akinori MUSHA <knu@iDaemons.org>
* time.c (time_to_s): Correct the wrong format which did not
really conform to RFC 2822; pointed out by: OHARA Shigeki <os at
iij.ad.jp> in [ruby-dev:30487].
-Sun Mar 4 23:38:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Mar 4 23:53:27 2007 Minero Aoki <aamine@loveruby.net>
- * file.c (rb_stat_s_utime): fixed a commit miss for the platforms
- where utimes() does not exist.
+ * lib/fileutils.rb (mv): could not move a directory between
+ different filesystems. [ruby-dev:30411]
- * lib/fileutils.rb (touch): ditto.
+Sun Mar 4 23:46:40 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sun Mar 4 14:46:56 2007 WATANABE Hirofumi <eban@ruby-lang.org>
+ * file.c (rb_file_s_utime): allow nil to set the current time.
+
+ * lib/fileutils.rb (touch): ditto, and added :mtime and :nocreate
+ options. fixed: [ruby-talk:219037]
+
+Sun Mar 4 23:19:00 2007 WATANABE Hirofumi <eban@ruby-lang.org>
* util.c (push_element): should return a int value.
-Sun Mar 4 01:05:57 2007 Akinori MUSHA <knu@iDaemons.org>
+Sun Mar 4 01:06:55 2007 Akinori MUSHA <knu@iDaemons.org>
* lib/set.rb (Set#^, Set#&): Correct documentation. Those methods
return sets, not arrays; noted by Oliver Frank Wittich <nietz AT
mangabrain.de>.
-Sat Mar 3 23:01:07 2007 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (mv): could not move a directory between
- different filesystems. [ruby-dev:30411]
-
-Sat Mar 3 22:57:11 2007 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (touch): last commit causes error if :mtime
- option was not given.
-
-Sat Mar 3 22:37:02 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (rb_file_s_utime): allow nil to set the current time.
-
- * lib/fileutils.rb (touch): ditto, and added :mtime and :nocreate
- options. fixed: [ruby-talk:219037]
-
-Sat Mar 3 21:17:35 2007 Akinori MUSHA <knu@iDaemons.org>
+Sat Mar 3 21:41:31 2007 Akinori MUSHA <knu@iDaemons.org>
* eval.c (stack_check): Unset inline to fix build with GCC 3.4.6;
submitted by: NISHIMATSU Takeshi <t_nissie AT yahoo.co.jp> in
[ruby-list:43218].
cf. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24556
-Sat Mar 3 19:05:31 2007 Akinori MUSHA <knu@iDaemons.org>
+Sat Mar 3 19:07:05 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/thread/thread.c (push_list): Use ALLOC().
@@ -4464,11 +709,21 @@ Sat Mar 3 19:05:31 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/thread/thread.c (rb_condvar_alloc): Ditto.
-Sat Mar 3 18:53:11 2007 Akinori MUSHA <knu@iDaemons.org>
+Sat Mar 3 18:56:40 2007 Akinori MUSHA <knu@iDaemons.org>
* NEWS: Add a note for String#intern.
-Sat Mar 3 16:23:13 2007 Akinori MUSHA <knu@iDaemons.org>
+Sat Mar 3 18:36:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (rb_provided): return true only for features loaded from
+ .rb files, and not search actual library type. [ruby-dev:30414]
+
+ * eval.c (rb_feature_p): check loading_tbl if the given ext is
+ empty. [ruby-dev:30452]
+
+ * eval.c (rb_feature_p): fix possible buffer overrun.
+
+Sat Mar 3 16:30:39 2007 Akinori MUSHA <knu@iDaemons.org>
* env.h (SCOPE_CLONE): Introduce a new scope flag to prevent a
local_tbl region from getting freed many times; submitted by
@@ -4481,108 +736,78 @@ Sat Mar 3 16:23:13 2007 Akinori MUSHA <knu@iDaemons.org>
* parse.y (top_local_setup_gen): Ditto.
-Sat Mar 3 16:07:02 2007 Akinori MUSHA <knu@iDaemons.org>
+Sat Mar 3 16:09:27 2007 Akinori MUSHA <knu@iDaemons.org>
* object.c (rb_obj_ivar_set): RDoc updated according to a
suggestion from Brian Candler <B.Candler AT pobox.com>.
[ruby-core:10469]
-Thu Mar 1 21:38:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat Mar 3 15:41:33 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (stmt, arg): should not omit lhs of OP_ASGN1 even if
- empty. [ruby-dev:30455]
-
-Thu Mar 1 08:55:38 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_feature_p): check loading_tbl if the given ext is
empty. [ruby-dev:30452]
- * eval.c (rb_feature_p): fix possible buffer overrun.
+Thu Mar 1 04:08:30 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * mkconfig.rb (patchlevel): read from version.h.
-Thu Mar 1 03:30:21 2007 Akinori MUSHA <knu@iDaemons.org>
+Thu Mar 1 03:42:09 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/digest/digest.c (get_digest_base_metadata): Allow inheriting
Digest::Base subclasses, which was unintentionally made
impossible while restructuring Digest classes.
-Thu Mar 1 02:05:17 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * mkconfig.rb (patchlevel): read from version.h.
-
-Thu Mar 1 00:09:39 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Feb 28 22:10:55 2007 Akinori MUSHA <knu@iDaemons.org>
- * eval.c (rb_provided): return true only for features loaded from
- .rb files, and not search actual library type. [ruby-dev:30414]
+ * doc/NEWS-1.8.0: Rename NEWS to NEWS-1.8.0. This is way too old
+ NEWS.
-Wed Feb 28 21:15:00 2007 WATANABE Hirofumi <eban@ruby-lang.org>
+ * NEWS: Add NEWS, a document file to keep user visible feature
+ changes between releases.
* configure.in (ac_cv_func_fcntl): fcntl support for MinGW.
* missing/flock.c: workaround for MinGW.
-Wed Feb 28 20:51:32 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * pack.c (pack_unpack): properly ignore non-base64 octets such as
- UTF-8 encoded BOMs; submitted by SOUMA Yutaka <holon@radastery.jp>
- to fix [ruby-core:10437]
-
-Wed Feb 28 18:59:57 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * NEWS: Add NEWS, a document file to keep user visible feature
- changes between releases.
-
-Wed Feb 28 18:35:50 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
* ext/openssl/extconf.rb: no need to check unistd.h and sys/time.h.
they are already checked at configure.
reported by KOBAYASHI Yasuhiro [ruby-list:43225]
-Wed Feb 28 18:34:48 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
* lib/mkmf.rb ($DEFLIBPATH): default library paths ($(topdir), etc)
should be the first elements of library paths list.
reported by KOBAYASHI Yasuhiro [ruby-list:43225]
-Wed Feb 28 18:31:32 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * doc/NEWS-1.8.0: Rename NEWS to NEWS-1.8.0. This is way too old
- NEWS.
-
-Wed Feb 28 01:22:58 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
* test/{dbm,gdbm}/test_{dbm,gdbm}.rb: shouldn't use host_os. use
target_os instead. reported by KOBAYASHI Yasuhiro [ruby-list:43225]
-Wed Feb 28 00:08:11 2007 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
-
* mkconfig.rb (RbConfig): add CONFIG['PATCHLEVEL']
* common.mk: new target dist
* distruby.rb: new file
-Tue Feb 27 22:18:45 2007 WATANABE Hirofumi <eban@ruby-lang.org>
-
* configure.in (--enable-auto-image-base): avoid the neccessity to
rebase the shared libs as much as possible;
submitted by Corinna Vinschen <spam at vinschen.de> in
[ruby-talk:240964].
-Tue Feb 27 21:36:47 2007 WATANABE Hirofumi <eban@ruby-lang.org>
+Wed Feb 28 20:51:32 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
- * util.c (__crt0_glob_function): use ruby_glob() instead of rb_globi().
+ * pack.c (pack_unpack): properly ignore non-base64 octets such as
+ UTF-8 encoded BOMs; submitted by SOUMA Yutaka <holon@radastery.jp>
+ to fix [ruby-core:10437]
+
+Tue Feb 27 21:50:10 2007 WATANABE Hirofumi <eban@ruby-lang.org>
-Tue Feb 27 21:33:04 2007 WATANABE Hirofumi <eban@ruby-lang.org>
+ * util.c (__crt0_glob_function): use ruby_glob() instead of rb_globi().
* configure.in (ac_cv_func_setrlimit): workaround for djgpp.
-Tue Feb 27 19:38:52 2007 Akinori MUSHA <knu@iDaemons.org>
+Tue Feb 27 20:49:19 2007 Akinori MUSHA <knu@iDaemons.org>
* lib/base64.rb (Base64::b64encode): Fix documentation; submitted
by David Symonds <dsymonds@gmail.com> in [ruby-core:10432].
-Tue Feb 27 19:36:57 2007 Akinori MUSHA <knu@iDaemons.org>
-
* regex.c (calculate_must_string, slow_search, re_search): Silence
warnings regarding char * vs. unsigned char * mismatch;
submitted by Lyle Johnson <lyle.johnson@gmail.com>
@@ -4600,8 +825,6 @@ Tue Feb 27 19:36:57 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/nkf/nkf.c (rb_str_resize, rb_nkf_kconv, rb_nkf_guess1,
rb_nkf_guess2): Ditto.
-Tue Feb 27 03:40:09 2007 Akinori MUSHA <knu@iDaemons.org>
-
* ext/thread/thread.c (wait_list_cleanup, rb_mutex_try_lock):
Eliminate rb_thread_critical switching where unnecessary;
implied by shugo in [ruby-dev:30412].
@@ -4612,35 +835,28 @@ Tue Feb 27 03:40:09 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/thread/thread.c: Consistently use 0 and 1 for
rb_thread_critical values.
-Mon Feb 26 15:18:23 2007 Akinori MUSHA <knu@iDaemons.org>
-
* ext/thread/thread.c: Use xmalloc()/xfree() instead of
malloc()/free(); pointed out by shugo in [ruby-dev:30412].
-Sun Feb 25 23:02:55 2007 Akinori MUSHA <knu@iDaemons.org>
-
* lib/test/unit/autorunner.rb (Test::Unit::AutoRunner::initialize):
Initialize @workdir properly to silence a warning under -w.
Submitted by <tommy at tmtm.org> in [ruby-dev:30400].
-Sun Feb 25 02:47:43 2007 Akinori MUSHA <knu@iDaemons.org>
+Sun Feb 25 02:50:51 2007 Akinori MUSHA <knu@iDaemons.org>
* defines.h: Pull the RUBY_MBCHAR_MAXSIZE definition from trunk,
which is necessary for dir.c to compile on djgpp and emx.
-Sat Feb 24 10:42:01 2007 Minero Aoki <aamine@loveruby.net>
+Sat Feb 24 17:04:01 2007 Tadayoshi Funaba <tadf@dotrb.org>
- * ext/racc/cparse/cparse.c (cparse_params_mark): remove useless
- rb_gc_mark. Thanks Tomoyuki Chikanaga. [ruby-dev:30405]
-
-Fri Feb 23 15:10:46 2007 NAKAMURA Usaku <usa@ruby-lang.org>
+ * lib/date/format.rb: updated based on date2 4.0.3.
- * win32/win32.c (set_pioinfo_extra): new function for VC++8 SP1
- workaround. [ruby-core:10259]
+Sat Feb 24 17:01:02 2007 Minero Aoki <aamine@loveruby.net>
- * win32/win32.c (NtInitialize): call above function.
+ * ext/racc/cparse/cparse.c (cparse_params_mark): remove useless
+ rb_gc_mark. Thanks Tomoyuki Chikanaga. [ruby-dev:30405]
-Fri Feb 23 14:19:40 2007 NAKAMURA Usaku <usa@ruby-lang.org>
+Sat Feb 24 16:53:09 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* signal.c (sighandler): need to tell to be interrupted to main
context when handler is installed.
@@ -4648,14 +864,19 @@ Fri Feb 23 14:19:40 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.[ch] (rb_win32_interrupted): new function to listen
interrupt.
-Fri Feb 23 13:02:17 2007 Akinori MUSHA <knu@iDaemons.org>
+ * win32/win32.c (set_pioinfo_extra): new function for VC++8 SP1
+ workaround. [ruby-core:10259]
+
+ * win32/win32.c (NtInitialize): call above function.
+
+Fri Feb 23 13:04:43 2007 Akinori MUSHA <knu@iDaemons.org>
* numeric.c (fix_cmp, fix_equal): Remove FIX2LONG() to optimize.
suggested in
http://t-a-w.blogspot.com/2007/02/making-ruby-faster.html.
[ruby-talk:240223]
-Fri Feb 23 12:43:17 2007 James Edward Gray II <james@grayproductions.net>
+Fri Feb 23 12:47:13 2007 James Edward Gray II <james@grayproductions.net>
* lib/xmlrpc/client.rb (XMLRPC::Client::do_rpc): Make the
Content-Length parameter optional for responses in
@@ -4665,43 +886,38 @@ Fri Feb 23 12:43:17 2007 James Edward Gray II <james@grayproductions.net>
* lib/xmlrpc/create.rb (XMLRPC::Create::conv2value): Add DateTime
support to xmlrpc; approved by the maintainer.
-Mon Feb 19 18:22:52 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in, defines.h, eval.c (rb_feature_p, rb_provided,
- load_wait, search_required, rb_require_safe), ext/extmk.rb: Fix
- a bug where a statically linked extension cannot be autoloaded.
- [ruby-dev:30023] / [ruby-dev:30239]
-
-Mon Feb 19 17:14:28 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Feb 19 18:33:30 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/socket/socket.c (unix_peeraddr): wrong syscall name in error
message for #peeraddr. a patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:10366]
-Sun Feb 18 19:35:21 2007 Tadayoshi Funaba <tadf@dotrb.org>
+Mon Feb 19 18:27:42 2007 Akinori MUSHA <knu@iDaemons.org>
- * lib/date/format.rb: updated based on date2 4.0.3.
+ * configure.in, defines.h, eval.c (rb_feature_p, rb_provided,
+ load_wait, search_required, rb_require_safe), ext/extmk.rb: Fix
+ a bug where a statically linked extension cannot be autoloaded.
+ [ruby-dev:30023] / [ruby-dev:30239]
+Thu Feb 15 20:31:07 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * lib/uri/ftp.rb: Revert the previous change pending discussion.
+
Fri Feb 16 11:18:21 2007 Eric Hodel <drbrain@segment7.net>
* lib/.document: Apply patch for irb, e2mmap and README by Hugh Sasse
- <hgs at dmu.ac.uk> from [ruby-core:10135]
+ <hgs at dmu.ac.uk> from [ruby-core:10135]
* lib/prettyprint.rb: Suppress RDoc for PrettyPrint test suite.
-Thu Feb 15 20:26:30 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/uri/ftp.rb: Revert the previous change pending discussion.
-
-Thu Feb 15 18:08:17 2007 Akinori MUSHA <knu@iDaemons.org>
+Thu Feb 15 18:10:09 2007 Akinori MUSHA <knu@iDaemons.org>
* dir.c (glob_helper): Fix the function declaration.
-Thu Feb 15 17:13:32 2007 Akinori MUSHA <knu@iDaemons.org>
+Thu Feb 15 16:55:33 2007 Akinori MUSHA <knu@iDaemons.org>
- * version.h: Welcome to the post-1.8.6 world. Radical changes are
- inhibited in the ruby_1_8 branch until the 1.8.6 final release
- goes out of the door.
+ * version.h: Branch off ruby_1_8_6 from ruby_1_8 in preparation
+ for the forthcoming 1.8.6 release.
Thu Feb 15 16:44:14 2007 Akinori MUSHA <knu@iDaemons.org>
@@ -4808,7 +1024,7 @@ Sat Feb 10 07:41:52 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
Sat Feb 10 00:13:11 2007 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/lib/tk.rb: fix typo (TkConfigMethod::__confinfo_cmd,
+ * ext/tk/lib/tk.rb: fix typo (TkConfigMethod::__confinfo_cmd,
__conv_keyonly_opts).
Fri Feb 9 20:44:53 2007 Akinori MUSHA <knu@iDaemons.org>
@@ -4832,15 +1048,15 @@ Fri Feb 9 15:46:09 2007 Akinori MUSHA <knu@iDaemons.org>
Tue Feb 06 22:06:45 2007 NARUSE, Yui <naruse@ruby-lang.org>
- * ext/nkf/nkf-utf8/{nkf.c,utf8tbl.c}:
- imported nkf 2007-01-28.
- * Fixed: can't decode MIME encode JIS string.
- * Fixed: Fullwitdh-halfwidth conversion.
- * Support DoCoMo's and Softbank's EMOJI
- * Support CP932, CP5022x, eucJP-ms UDC
- * Support UTF-32 encoding
- * Support beyond BMP
- [ruby-dev:29700] [ruby-dev:29922] [ruby-dev:30144]
+ * ext/nkf/nkf-utf8/{nkf.c,utf8tbl.c}:
+ imported nkf 2007-01-28.
+ * Fixed: can't decode MIME encode JIS string.
+ * Fixed: Fullwitdh-halfwidth conversion.
+ * Support DoCoMo's and Softbank's EMOJI
+ * Support CP932, CP5022x, eucJP-ms UDC
+ * Support UTF-32 encoding
+ * Support beyond BMP
+ [ruby-dev:29700] [ruby-dev:29922] [ruby-dev:30144]
Wed Jan 31 14:52:09 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -4888,8 +1104,8 @@ Wed Jan 24 18:05:39 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
regexp font-lock bug. [ruby-talk:235758]
Tue Jan 23 11:02:33 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/webrick/httprequest.rb (WEBrick::HTTPRequest::read_line):
+
+ * lib/webrick/httprequest.rb (WEBrick::HTTPRequest::read_line):
Tue Jan 23 18:26:12 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -4908,8 +1124,8 @@ Mon Jan 22 14:57:25 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
Sat Jan 13 23:54:48 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
- * ext/win32ole/win32ole.c (ole_free, ole_type_free,
- olemethod_free, olevariable_free, oleparam_free,
+ * ext/win32ole/win32ole.c (ole_free, ole_type_free,
+ olemethod_free, olevariable_free, oleparam_free,
ole_event_free): fix memory leak. [ruby-core:09846]
Fri Jan 12 11:13:55 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -4939,7 +1155,7 @@ Tue Jan 9 03:54:38 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_upto): String#upto from empty string makes
inifinite loop. [ruby-core:09864]
-Sun Jan 7 12:13:26 2007 Eric Hodel <drbrain@segment7.net>
+Sun Jan 7 12:13:26 2007 Eric Hodel <drbrain@segment7.net>
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#find_class_comment):
Look for class and module comments above rb_define_class and
@@ -4963,20 +1179,20 @@ Wed Jan 3 11:36:51 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
Mon Jan 1 06:13:11 2007 Eric Hodel <drbrain@segment7.net>
* lib/rdoc/parsers/c_parser.rb: Make Rdoc accessible. Update constant
- value information.
+ value information.
Mon Jan 1 06:13:11 2007 Eric Hodel <drbrain@segment7.net>
* ext/bigdecimal/bigdecimal.c: Update constant comments to provide
- values for RDoc.
+ values for RDoc.
Mon Jan 1 06:05:55 2007 Eric Hodel <drbrain@segment7.net>
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#handle_constansts):
- Allow RDoc comment to give friendly value for rb_define_const. Patch
- by Daniel Berger <djberg96 at gmail.com>, [ruby-patches-7499].
+ Allow RDoc comment to give friendly value for rb_define_const. Patch
+ by Daniel Berger <djberg96 at gmail.com>, [ruby-patches-7499].
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#handle_constansts): Fix
- whitespace handling in constant comments.
+ whitespace handling in constant comments.
Sun Dec 31 00:31:16 2006 Tadayoshi Funaba <tadf@dotrb.org>
@@ -6311,7 +2527,7 @@ Thu Jul 20 15:07:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
Thu Jul 20 00:06:29 2006 Keiju Ishitsuka <keiju@ishitsuka.com>
* lib/irb/completion.rb: support for completion of numeric
- number. [ruby-dev: 29038]
+ number. [ruby-dev: 29038]
Wed Jul 19 23:53:05 2006 Kouhei Sutou <kou@cozmixng.org>
@@ -6425,7 +2641,7 @@ Thu Jul 13 22:23:56 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
Thu Jul 13 20:32:19 2006 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/parser.rb: updated documents by a patch from
- Hugh Sasse <hgs at dmu.ac.uk>. [ruby-core:8194]
+ Hugh Sasse <hgs at dmu.ac.uk>. [ruby-core:8194]
Wed Jul 12 13:54:09 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -9498,8 +5714,8 @@ Sat Sep 17 09:45:26 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
Sat Sep 17 08:35:39 2005 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/maker/base.rb (RSS::Maker::ItemsBase#normalize): fixed
- strange RSS::Maker::Item#max_size behavior.
- Thanks to Kazuhiko <kazuhiko@fdiary.net>.
+ strange RSS::Maker::Item#max_size behavior.
+ Thanks to Kazuhiko <kazuhiko@fdiary.net>.
* test/rss/test_maker_1.0.rb (RSS::TestMaker10#test_items): ditto.
@@ -10257,7 +6473,6 @@ Mon Aug 1 01:17:40 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* test/drb/ut_drb.rb: ditto.
Mon Aug 1 00:07:32 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
-
* lib/irb/context.rb: fix `irb --readline` option. [ruby-list:40955]
Fri Jul 29 09:59:38 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -10742,7 +6957,6 @@ Fri Jul 1 00:18:40 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
destination object. [ruby-talk:146894]
Thu Jun 30 19:00:21 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
-
* lib/irb/ruby-lex.rb (RubyLex::identify_number): alternative implements
for [ruby-dev:26410]. And support a numeric form of 0d99999.
@@ -11714,6 +7928,7 @@ Sat Apr 9 11:59:57 2005 Kouhei Sutou <kou@cozmixng.org>
- gave a name to 'x'.
- undef_method -> remove_method for avoiding a warning in ruby 1.6.
+
* lib/rss/parser.rb: @@setter -> @@setters.
* lib/rss/parser.rb
@@ -11741,28 +7956,34 @@ Sat Apr 9 11:59:57 2005 Kouhei Sutou <kou@cozmixng.org>
elements. (ex. have childlen elements, have some attributes and
a child element and so on.)
+
* lib/rss/dublincore.rb: supported multiple Dublin Core items.
* lib/rss/maker/dublincore.rb: ditto.
* lib/rss/maker/image.rb: supproted new Dublin Core API.
+
* lib/rss/maker/base.rb: added default current_element implementation.
+
* lib/rss/trackback.rb (RSS::TrackBackUtils.new_with_value_if_need):
moved to RSS::Utils.
* lib/rss/utils.rb (RSS::Utils.new_with_value_if_need):
moved from RSS::TrackBackUtils.
+
* lib/rss/maker/image.rb: fixed invalid argument of
add_need_initialize_variable bug.
* lib/rss/maker/trackback.rb: ditto.
+
* lib/rss/rss.rb (Hash#merge): added for ruby 1.6.
* lib/rss/rss.rb (RSS::BaseModel.date_writer): changed to accept nil
for date value.
+
* test/test_dublincore.rb: added tests for plural accessor and
multiple Dublin Core items.
@@ -11778,6 +7999,7 @@ Sat Apr 9 11:59:57 2005 Kouhei Sutou <kou@cozmixng.org>
* test/rss/test_maker_dc.rb (test_date): added a test for #date=
and #dc_date=.
+
* sample/rss/tdiary_plugin/rss-recent.rb:
new option: @options['rss-recent.use-image-link']:
use image as link instread of text if available.
@@ -12768,7 +8990,7 @@ Wed Feb 2 21:56:01 2005 Kouhei Sutou <kou@cozmixng.org>
Tue Feb 1 22:48:48 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb (DRb::DRbObject#respond_to?): check marshal_dump and
- _dump.
+ _dump.
Tue Feb 1 00:20:23 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -13675,7 +9897,7 @@ Wed Dec 15 18:57:01 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
Wed Dec 15 18:48:42 2004 Shugo Maeda <shugo@ruby-lang.org>
* ext/curses/curses.c (window_subwin): call NUM2INT() before
- GetWINDOW(). (backported from CVS HEAD)
+ GetWINDOW(). (backported from CVS HEAD)
Wed Dec 15 17:03:50 2004 NAKAMURA Usaku <usa@ruby-lang.org>
@@ -14298,7 +10520,7 @@ Thu Nov 18 18:41:08 2004 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* test/ruby/test_stringchar.rb (test_bang): added.
* string.c (rb_str_upcase_bang, rb_str_capitalize_bang)
- (rb_str_swapcase_bang): missing rb_str_modify(). [ruby-dev:24915]
+ (rb_str_swapcase_bang): missing rb_str_modify(). [ruby-dev:24915]
Thu Nov 18 00:21:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -14914,7 +11136,7 @@ Mon Oct 18 15:58:01 2004 NAKAMURA Usaku <usa@ruby-lang.org>
Fri Oct 29 16:34:19 2004 Daiki Ueno <ueno@unixuser.org>
* misc/ruby-mode.el (ruby-parse-partial): Parse the rest of the
- line after opening heredoc identifier. [ruby-dev:24635]
+ line after opening heredoc identifier. [ruby-dev:24635]
Mon Oct 18 07:26:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -15110,7 +11332,7 @@ Mon Oct 4 12:53:45 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
Sun Oct 3 21:20:03 2004 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (TEXT_REGEXP): allow 8-bit characters for the german
- version of Microsoft Exchange Server. (backported from HEAD)
+ version of Microsoft Exchange Server. (backported from HEAD)
* lib/net/imap.rb (RTEXT_REGEXP): ditto.
@@ -15435,6 +11657,7 @@ Sun Sep 12 02:41:58 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c: add TclTkIp#allow_ruby_exit? and
allow_ruby_exit=
+
* ext/tk/lib/multi-tk.rb: ditto.
* ext/tk/lib/remote-tk.rb: ditto.
@@ -15915,9 +12138,9 @@ Sun Jul 18 03:21:42 2004 Akinori MUSHA <knu@iDaemons.org>
Sun Jul 18 03:12:11 2004 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (receive_responses): return if a LOGOUT response
- received. (backported from HEAD)
+ received. (backported from HEAD)
* lib/net/imap.rb (send_string_data): wait command continuation
- requests before sending octet data of literals. (backported from HEAD)
+ requests before sending octet data of literals. (backported from HEAD)
Sat Jul 17 23:54:59 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -15988,7 +12211,7 @@ Thu Jul 15 23:53:38 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
Thu Jul 15 22:59:48 2004 Shugo Maeda <shugo@ruby-lang.org>
* ext/readline/extconf.rb: added dir_config for curses, ncurses,
- termcap. (backported from HEAD)
+ termcap. (backported from HEAD)
Thu Jul 15 20:29:15 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
@@ -16020,6 +12243,7 @@ Thu Jul 15 10:15:04 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/tkextlib/: add samples of Iwidget and TkTable
+
Wed Jul 14 18:08:37 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_asn1.c (ossl_asn1cons_to_der): fix type of
@@ -16508,7 +12732,7 @@ Tue Jun 22 21:11:36 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
Tue Jun 22 16:47:42 2004 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/ftp.rb (MDTM_REGEXP): fix for demon's ftp server.
- Thanks, Rutger Nijlunsing.
+ Thanks, Rutger Nijlunsing.
Mon Jun 21 10:19:23 2004 NAKAMURA Usaku <usa@ruby-lang.org>
@@ -18496,6 +14720,7 @@ Tue Dec 30 12:30:30 2003 Dave Thomas <dave@pragprog.com>
class and a method have the same name, finding Xxx.abc was trying
to find 'abc' in method 'Xxx', not class 'Xxx'.
+
Tue Dec 30 08:32:32 2003 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_method):
@@ -18503,6 +14728,7 @@ Tue Dec 30 08:32:32 2003 Dave Thomas <dave@pragprog.com>
def each_entry(&b) Dir.foreach(@path) {|f| yield P.new(f) } end
+
Tue Dec 30 08:32:32 2003 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_method):
@@ -20408,7 +16634,6 @@ Sat Nov 8 13:49:50 2003 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* configure.in: improvement of pthread check
Sat Nov 8 13:28:46 2003 Takaaki Tateishi <ttate@ttsky.net>
-
* ext/dl/sym.c: Add DL.win32_last_error and DL.last_error.
Thanks, Kaoru Shirai.
@@ -23246,7 +19471,6 @@ Tue Aug 12 02:48:56 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (THREAD_ALLOC): initialize IA64 members.
Mon Aug 11 22:31:50 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
* lib/debug.rb(debug_command): inspection command should inspect
resulting value even if it's nil. [ruby-dev:21180] by OMAE, jun
<jun66j5@ybb.ne.jp>.
@@ -23447,10 +19671,9 @@ For the changes before 1.8.0, see doc/ChangeLog-1.8.0
Local variables:
add-log-time-format: (lambda ()
(let* ((time (current-time))
- (system-time-locale "C")
(diff (+ (cadr time) 32400))
(lo (% diff 65536))
- (hi (+ (car time) (/ diff 65536))))
+ (hi (+ (car time) (/ diff 65536))))
(format-time-string "%a %b %e %H:%M:%S %Y" (list hi lo) t)))
indent-tabs-mode: t
tab-width: 8
diff --git a/Makefile.in b/Makefile.in
index a37bcf65fb..1e372885b7 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -35,9 +35,6 @@ RIDATADIR = $(DESTDIR)$(datadir)/ri/$(MAJOR).$(MINOR)/system
empty =
OUTFLAG = @OUTFLAG@$(empty)
CFLAGS = @CFLAGS@ @XCFLAGS@ @ARCH_FLAG@
-cflags = @cflags@
-optflags = @optflags@
-debugflags = @debugflags@
CPPFLAGS = -I. -I$(srcdir) @CPPFLAGS@
LDFLAGS = @STATIC@ $(CFLAGS) @LDFLAGS@
EXTLDFLAGS =
@@ -57,7 +54,7 @@ EXEEXT = @EXEEXT@
PROGRAM=$(RUBY_INSTALL_NAME)$(EXEEXT)
RUBY = $(RUBY_INSTALL_NAME)
MINIRUBY = @MINIRUBY@ $(MINIRUBYOPT)
-RUNRUBY = @RUNRUBY@ $(RUNRUBYOPT) --
+RUNRUBY = @RUNRUBY@
#### End of system configuration section. ####
@@ -158,12 +155,9 @@ $(srcdir)/configure: $(srcdir)/configure.in
cd $(srcdir) && $(AUTOCONF)
lex.c: keywords
- ( gperf -C -p -j1 -i 1 -g -o -t -N rb_reserved_word -k1,3,$$ $? > $@.tmp && mv $@.tmp $@ ) || \
- if test -f $@; then \
- touch $@ && echo $@ touched.; \
- else \
- cp $(srcdir)/lex.c $@ && echo $@ copied.; \
- fi
+ @-$(RM) $@
+ gperf -p -j1 -i 1 -g -o -t -N rb_reserved_word -k1,3,$$ $? > $@ || \
+ cp "$(srcdir)/$@" .
.y.c:
$(YACC) $<
@@ -183,20 +177,4 @@ distclean-local::
@$(RM) ext/config.cache $(RBCONFIG)
ext/extinit.$(OBJEXT): ext/extinit.c $(SETUP)
- $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(OUTFLAG)$@ -c ext/extinit.c
-
-update-rubyspec:
- if [ -d $(srcdir)/rubyspec ]; then \
- cd $(srcdir)/rubyspec/mspec; \
- git pull; \
- cd ../spec/rubyspec; \
- git pull; \
- else \
- git clone $(MSPEC_GIT_URL) $(srcdir)/rubyspec/mspec; \
- git clone $(RUBYSPEC_GIT_URL) $(srcdir)/rubyspec/spec/rubyspec; \
- fi
-
-test-rubyspec:
- @if [ ! -d $(srcdir)/rubyspec ]; then echo No rubyspec here. make update-rubyspec first.; exit 1; fi
- $(RUNRUBY) $(srcdir)/rubyspec/mspec/bin/mspec -r$(srcdir)/ext/purelib.rb $(srcdir)/rubyspec/spec/rubyspec/$(MAJOR).$(MINOR)
-
+ $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -o$@ -c ext/extinit.c
diff --git a/NEWS b/NEWS
index 61373187e5..de1dafb533 100644
--- a/NEWS
+++ b/NEWS
@@ -1,532 +1,55 @@
= NEWS
This document is a list of user visible feature changes made between
-releases except for bug fixes.
+releases excluding bug fixes.
Note that each entry is kept so brief that no reason behind or
reference information is supplied with. For a full list of changes
with all sufficient information, see the ChangeLog file.
-== Changes since the 1.8.6 release
+== Changes with Ruby 1.8.5
-=== Configuration changes
-
-* vendor_ruby directory
-
- A new library directory named `vendor_ruby' is introduced in
- addition to `site_ruby'. The idea is to separate libraries
- installed by the package system (`vendor') from manually (`site')
- installed libraries preventing the former from getting overwritten
- by the latter, while preserving the user option to override vendor
- libraries with site libraries. (`site_ruby' takes precedence over
- `vendor_ruby')
-
- If you are a package maintainer, make each library package configure
- the library passing the `--vendor' option to `extconf.rb' so that
- the library files will get installed under `vendor_ruby'.
-
- You can change the directory locations using configure options such
- as `--with-sitedir=DIR' and `--with-vendordir=DIR'.
+=== New platforms/build tools support
-=== Global constants
+* IA64 HP-UX
-* new constants
+* Visual C++ 8 SP1
- * RUBY_COPYRIGHT
- * RUBY_DESCRIPTION
+* autoconf 2.6x
=== Library updates (outstanding ones only)
-* new library
-
- * securerandom
-
-* builtin classes
-
- * Array#flatten
- * Array#flatten!
-
- Takes an optional argument that determines the level of recursion
- to flatten.
-
- * Array#eql?
- * Array#hash
- * Array#==
- * Array#<=>
-
- Handle recursive data properly.
-
- * Array#index
- * Array#rindex
-
- Take a block instead of an argument.
-
- * Array#collect!
- * Array#map!
- * Array#each
- * Array#each_index
- * Array#reverse_each
- * Array#reject
- * Array#reject!
- * Array#delete_if
-
- Return an enumerator if no block is given.
-
- Note that #map and #collect still return an array unlike Ruby 1.9
- to keep compatibility.
-
- * Array#pop
- * Array#shift
-
- Take an optional argument specifying the number of elements to
- remove.
-
- * Array#choice
- * Array#combination
- * Array#cycle
- * Array#drop
- * Array#drop_while
- * Array#permutation
- * Array#product
- * Array#shuffle
- * Array#shuffle!
- * Array#take,
- * Array#take_while
-
- New methods.
-
- * Binding#eval
-
- New method.
-
- * Dir#each
- * Dir#foreach
-
- Return an enumerator if no block is given.
-
- * Enumerable::Enumerator
-
- New class for various enumeration defined by the enumerator library.
-
- * Enumerable#each_slice
- * Enumerable#each_cons
- * Object#to_enum
- * Object#enum_for
-
- New methods for various enumeration defined by the enumerator library.
-
- * Enumerable#count
- * Enumerable#cycle
- * Enumerable#drop
- * Enumerable#drop_while
- * Enumerable#find_index
- * Enumerable#first
- * Enumerable#group_by
- * Enumerable#max_by
- * Enumerable#min_by
- * Enumerable#minmax
- * Enumerable#minmax_by
- * Enumerable#none?
- * Enumerable#one?
- * Enumerable#take
- * Enumerable#take_while
-
- New methods.
-
- * Enumerable#find
- * Enumerable#find_all
- * Enumerable#partition
- * Enumerable#reject
- * Enumerable#select
- * Enumerable#sort_by
-
- Return an enumerator if no block is given.
-
- Note that #map and #collect still return an array unlike Ruby 1.9
- to keep compatibility.
-
- * Enumerable#inject
-
- Accepts a binary operator instead of a block.
-
- * Enumerable#reduce
-
- New alias to #inject.
-
- * Hash#eql?
- * Hash#hash
- * Hash#==
-
- Handle recursive data properly.
-
- * Hash#delete_if
- * Hash#each
- * Hash#each_key
- * Hash#each_pair
- * Hash#each_value
- * Hash#reject!
- * Hash#select
- * ENV.delete_if
- * ENV.each
- * ENV.each_key
- * ENV.each_pair
- * ENV.each_value
- * ENV.reject!
- * ENV.select
-
- Return an enumerator if no block is given.
-
- * GC.stress
- * GC.stress=
-
- New methods.
-
- * Integer#ord
- * Integer#odd?
- * Integer#even?
- * Integer#pred
-
- New methods.
-
- * Integer#downto
- * Integer#times
- * Integer#upto
-
- Return an enumerator if no block is given.
-
- * IO#each
- * IO#each_line
- * IO#each_byte
- * IO.foreach
- * ARGF.each
- * ARGF.each_line
- * ARGF.each_byte
-
- Return an enumerator if no block is given.
-
- * IO#bytes
- * IO#chars
- * IO#each_char
- * IO#getbyte
- * IO#lines
- * IO#readbyte
- * ARGF.bytes
- * ARGF.chars
- * ARGF.each_char
- * ARGF.getbyte
- * ARGF.lines
- * ARGF.readbyte
-
- New methods.
-
- * Method#name
- * Method#owner
- * Method#receiver
- * UnboundMethod#name
- * UnboundMethod#owner
-
- New methods.
-
- * Module#class_exec
- * Module#module_exec
-
- New methods.
-
- * Numeric#step
-
- Return an enumerator if no block is given.
-
- * Object#instance_exec
- * Object#tap
-
- New methods.
-
- * ObjectSpace.each_object
-
- Return an enumerator if no block is given.
-
- * Process.exec implemented.
-
- * Range#each
- * Range#step
-
- Return an enumerator if no block is given.
-
- * Regexp.union accepts an array of patterns.
-
- * String#bytesize
-
- New method, returning the size in bytes. (alias length and size)
-
- * String#chars
- * String#each_char
- * String#partition
- * String#rpartition
- * String#start_with?
- * String#end_with?
-
- New methods. These are $KCODE aware unlike #index, #rindex and
- #include?.
-
- * String#each_byte
- * String#each
- * String#each_line
- * String#gsub(pattern)
-
- Return an enumerator if no block is given.
-
- * String#upto
-
- An optional second argument is added to specify if the last value
- should be included.
-
- * StopIteration
-
- New exception class that causes Kernel#loop to stop iteration when
- raised.
-
- * Struct#each
- * Struct#each_pair
-
- Return an enumerator if no block is given.
-
- * Symbol#to_proc
-
- New method.
-
- * __method__
-
- New global function that returns the name of the current method as
- a Symbol.
-
-* enumerator
-
- * Enumerator is now a built-in module. The #next and #rewind
- methods are implemented using the "generator" library. Use with
- care and be aware of the performance loss.
-
-* ipaddr
-
- * New methods
- * IPAddr#<=>
- * IPAddr#succ
-
- IPAddr objects are now comparable and enumerable having these
- methods. This also means that it is possible to have a Range
- object between two IPAddr objects.
-
- * IPAddr#to_range
-
- A new method to create a Range object for the (network) address.
-
- * Type coercion support
- * IPAddr#&
- * IPAddr#|
- * IPAddr#==
- * IPAddr#include?
-
- These methods now accept a string or an integer instead of an
- IPAddr object as the argument.
-
-* net/smtp
-
- * Support SSL/TLS.
-
-* openssl
-
- * New classes
- * OpenSSL::PKey::EC
- * OpenSSL::PKey::EC::Group
- * OpenSSL::PKey::EC::Point
- * OpenSSL::PKey::PKCS5
- * OpenSSL::SSL::Session
-
- * Documentation!
-
- * Various new methods (see documentation).
-
- * Remove redundant module namespace in Cipher, Digest, PKCS7, PKCS12.
- Compatibility classes are provided which will be removed in Ruby 1.9.
-
-* shellwords
-
- * Add methods for escaping shell-unsafe characters:
- * Shellwords.join
- * Shellwords.escape
- * Array#shelljoin
- * String#shellescape
-
- * Add shorthand methods:
- * Shellwords.split (alias shellwords)
- * String#shellsplit
-
-* stringio
-
- * StringIO#getbyte
- * StringIO#readbyte
-
- New methods. (aliases for compatibility with 1.9)
-
- * StringIO#each_char
- * StringIO#chars
-
- New methods.
-
- * StringIO#each
- * StringIO#each_line
- * StringIO#each_byte
-
- Return an enumerator if no block is given.
-
-* tempfile
-
- * Tempfile.open and Tempfile.new now accept a suffix for the
- temporary file to be created. To specify a suffix, pass an array
- of [basename, suffix] as the first argument.
-
- Tempfile.open(['image', 'jpg']) { |tempfile| ... }
-
-* tmpdir
-
- * New method:
-
- * Dir.mktmpdir
-
-* uri
-
- * added LDAPS scheme.
- * Change for RFC3986:
- * FTP
- * URI('ftp://example.com/foo').path #=> 'foo'
- * URI('ftp://example.com/%2Ffoo').path #=> '/foo'
- * URI::FTP.build([nil, 'example.com', nil, '/foo', 'i').to_s #=> 'ftp://example.com/%2Ffoo;type=i'
- * URI merge
- * URI('http://a/b/c/d;p?q').merge('?y') == URI('http://a/b/c/d;p?y')
- * URI('http://a/b/c/d;p?q').merge('/./g') == URI('http://a/g')
- * URI('http://a/b/c/d;p?q').merge('/../g') == URI('http://a/g')
- * URI('http://a/b/c/d;p?q').merge('../../../g') == URI('http://a/g')
- * URI('http://a/b/c/d;p?q').merge('../../../../g') == URI('http://a/g')
-
-* rss
-
- * 0.1.6 -> 0.2.4
-
- * Fix image module URI
-
- * Atom support
-
- * ITunes module support
-
- * Slash module support
-
- * content:encoded with RSS 2.0 support
-
-=== Interpreter Implementation
-
-* passing a block to a Proc [experimental]
-
- This implementation in current shape is known to be buggy/broken,
- especially with nested block invocation. Take this as an
- experimental feature.
-
-* stack trace
-
- On non-SystemStackError exception, full stack trace is shown.
-
-=== Compatibility issues (excluding feature bug fixes)
-
-* String#slice! had some unintentional bugs and they have been fixed
- because either they disagreed with documentation or their respective
- behavior of #slice. Unfortunately, this causes some
- incompatibilities in the following (somewhat rare) cases.
-
- * #slice! no longer expands the array when an out-of-boundary value
- is given.
-
- # Ruby 1.8.6
- a = [1,2]
- a.slice!(4,0) #=> nil
- a #=> [1,2,nil,nil]
-
- # Ruby 1.8.7
- a = [1,2]
- a.slice!(4,0) #=> nil
- a #=> [1,2]
-
- * #slice! no longer raises an exception but returns nil when a
- negative length or out-of-boundary negative position is given.
-
- # Ruby 1.8.6
- a = [1,2]
- a.slice!(1,-1) #=> (raises IndexError)
- a.slice!(-5,1) #=> (raises IndexError)
-
- # Ruby 1.8.7
- a = [1,2]
- a.slice!(1,-1) #=> nil
- a.slice!(-5,1) #=> nil
-
-* String#to_i, String#hex and String#oct no longer accept a sequence
- of underscores (`__') as part of a number.
-
- # Ruby 1.8.6
- '1__0'.to_i #=> 10
- '1__0'.to_i(2) #=> 2 # 0b10
- '1__0'.oct #=> 8 # 010
- '1__0'.hex #=> 16 # 0x10
-
- # Ruby 1.8.7
- '1__0'.to_i #=> 1
- '1__0'.to_i(2) #=> 1
- '1__0'.oct #=> 1
- '1__0'.hex #=> 1
-
- The old behavior was inconsistent with Ruby syntax and considered as
- a bug.
-
* date
- * Date.parse
-
- '##.##.##' (where each '#' is a digit) is now taken as 'YY.MM.DD'
- instead of 'MM.DD.YY'. While the change may confuse you, you can
- always use Date.strptime() when you know what you are dealing
- with.
-
-* stringio
-
- * StringIO#each_byte
-
- The return value changed from nil to self. This is what the
- document says and the same as each_line() does.
-
-* tempfile
+ * Updated based on date2 4.0.3.
- * The file name format has changed. No dots are included by default
- in temporary file names any more. See above for how to specify a
- suffix.
+* digest
-* uri
+ * New internal APIs for C and Ruby.
- * See above for details.
+ * Support for autoloading.
-== Changes since the 1.8.5 release
+ * See below for new features and compatibility issues.
-=== New platforms/build tools support
+* nkf
-* IA64 HP-UX
+ * Updated based on nkf as of 2007-01-28.
-* Visual C++ 8 SP1
+* tk
-* autoconf 2.6x
+ * Tk::X_Scrollable (Y_Scrollable) is renamed to Tk::XScrollable
+ (YScrollable). Tk::X_Scrollable (Y_Scrollable) is still available,
+ but it is an alias name.
-=== Global constants
+ * Updated Tile extension support based on Tile 0.7.8.
-* RUBY_PATCHLEVEL
+ * Support --without-X11 configure option for non-X11 versions of
+ Tcl/Tk (e.g. Tcl/Tk Aqua).
- New constant since 1.8.5-p1.
+ * New sample script: irbtkw.rbw -- IRB on Ruby/Tk. It has no trouble
+ about STDIN blocking on Windows.
-=== Library updates (outstanding ones only)
+=== New methods and features
* builtin classes
@@ -536,25 +59,13 @@ with all sufficient information, see the ChangeLog file.
* New feature: Dir::glob() can now take an array of glob patterns.
-* date
-
- * Updated based on date2 4.0.3.
-
* digest
- * New internal APIs for C and Ruby.
-
- * Support for autoloading.
-
- require 'digest'
-
- # autoloads digest/md5
- md = Digest::MD5.digest("string")
-
* New digest class methods: file
- * New digest instance methods: clone, reset, new, inspect,
- digest_length (alias size or length), block_length()
+ * New digest instance methods: clone, reset, new,
+ inspect, digest_length (alias size or length),
+ block_length()
* New library: digest/bubblebabble
@@ -564,25 +75,11 @@ with all sufficient information, see the ChangeLog file.
* New option for FileUtils.cp_r(): :remove_destination
-* nkf
-
- * Updated based on nkf as of 2007-01-28.
-
* thread
- * Replaced with much faster mutex implementation in C. The former
- implementation, which is slow but considered to be stable, is
- available with a configure option `--disable-fastthread'.
-
-* tk
-
- * Updated Tile extension support based on Tile 0.7.8.
-
- * Support --without-X11 configure option for non-X11 versions of
- Tcl/Tk (e.g. Tcl/Tk Aqua).
-
- * New sample script: irbtkw.rbw -- IRB on Ruby/Tk. It has no trouble
- about STDIN blocking on Windows.
+ * Replaced with much faster mutex implementation in C.
+ The former implementation is available with a
+ configure option `--disable-fastthread'.
* webrick
@@ -595,17 +92,17 @@ with all sufficient information, see the ChangeLog file.
* String#intern now raises SecurityError when $SAFE level is greater
than zero.
-* date
+* fileutils
- * Time#to_date and Time#to_datetime are added as private methods.
- They cause name conflict error in ActiveSupport 1.4.1 and prior,
- which comes with Rails 1.2.2 and prior. Updating ActiveSupport
- and/or Rails to the latest versions fixes the problem.
+ * A minor implementation change breaks Rake <=0.7.1.
+ Updating Rake to 0.7.2 fixes the problem.
* digest
- * The constructor does no longer take an initial string to feed.
- The following examples show how to migrate:
+ * The constructor does no longer take an initial
+ string to feed; digest() and hexdigest() now do,
+ instead. The following examples show how to
+ migrate:
# Before
md = Digest::MD5.new("string")
@@ -616,14 +113,3 @@ with all sufficient information, see the ChangeLog file.
hd = Digest::MD5.new("string").hexdigest
# After (works with any version)
hd = Digest::MD5.hexdigest("string")
-
-* fileutils
-
- * A minor implementation change breaks Rake <=0.7.1.
- Updating Rake to 0.7.2 or higher fixes the problem.
-
-* tk
-
- * Tk::X_Scrollable (Y_Scrollable) is renamed to Tk::XScrollable
- (YScrollable). Tk::X_Scrollable (Y_Scrollable) is still available,
- but it is an alias name.
diff --git a/README b/README
index 1b79781367..cf836415ad 100644
--- a/README
+++ b/README
@@ -29,7 +29,7 @@ The Ruby distribution files can be found in the following FTP site:
The latest source code of this version series can be checked out
through SVN with the following command:
- $ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8/
+ $ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_6/
The trunk of the Ruby source tree can be checked out with the
following command:
@@ -70,10 +70,6 @@ This is what you need to do to compile and install Ruby:
2. Run ./configure, which will generate config.h and Makefile.
- Some C compiler flags may be added by default depending on your
- environment. Specify optflags=.. and warnflags=.. as necessary
- to override them.
-
3. Edit defines.h if you need. Usually this step will not be needed.
4. Remove comment mark(#) before the module names from ext/Setup (or
diff --git a/README.EXT b/README.EXT
index 637b19d25b..2fc2fd606a 100644
--- a/README.EXT
+++ b/README.EXT
@@ -662,11 +662,6 @@ Try generating the Makefile by:
ruby extconf.rb
-If the library should be installed under vendor_ruby directory
-instead of site_ruby directory, use --vendor option as follows.
-
- ruby extconf.rb --vendor
-
You don't need this step if you put the extension library under the ext
directory of the ruby source tree. In that case, compilation of the
interpreter will do this step for you.
diff --git a/README.EXT.ja b/README.EXT.ja
index 73425c2cdb..30c4d520ba 100644
--- a/README.EXT.ja
+++ b/README.EXT.ja
@@ -765,12 +765,6 @@ Makefile¤ò¼ÂºÝ¤ËÀ¸À®¤¹¤ë¤¿¤á¤Ë¤Ï
¤È¤·¤Æ¤¯¤À¤µ¤¤¡¥
-site_ruby ¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤Ê¤¯¡¢
-vendor_ruby ¥Ç¥£¥ì¥¯¥È¥ê¤Ë¥¤¥ó¥¹¥È¡¼¥ë¤¹¤ë¾ì¹ç¤Ë¤Ï
-°Ê²¼¤Î¤è¤¦¤Ë --vendor ¥ª¥×¥·¥ç¥ó¤ò²Ã¤¨¤Æ¤¯¤À¤µ¤¤¡¥
-
- ruby extconf.rb --vendor
-
¥Ç¥£¥ì¥¯¥È¥ê¤òext°Ê²¼¤ËÍѰդ·¤¿¾ì¹ç¤Ë¤ÏRubyÁ´ÂΤÎmake¤Î»þ¤Ë
¼«Æ°Åª¤ËMakefile¤¬À¸À®¤µ¤ì¤Þ¤¹¤Î¤Ç¡¤¤³¤Î¥¹¥Æ¥Ã¥×¤ÏÉÔÍפǤ¹¡¥
diff --git a/README.ja b/README.ja
index 71ce4ee12c..df8cfc03f4 100644
--- a/README.ja
+++ b/README.ja
@@ -36,7 +36,7 @@ Ruby¤Ï¥Æ¥­¥¹¥È½èÍý´Ø·¸¤ÎǽÎϤʤɤËÍ¥¤ì¡¤Perl¤ÈƱ¤¸¤¯¤é¤¤¶¯ÎÏ
ËÜ¥Ö¥é¥ó¥Á¤ÎRuby¤ÎºÇ¿·¤Î¥½¡¼¥¹¥³¡¼¥É¤Ï¼¡¤Î¥³¥Þ¥ó¥É¤Ç¼èÆÀ¤Ç¤­¤Þ¤¹¡¥
- $ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8/
+ $ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_6/
³«È¯Àèü¤Î¥½¡¼¥¹¥³¡¼¥É¤Ï¼¡¤Î¥³¥Þ¥ó¥É¤Ç¼èÆÀ¤Ç¤­¤Þ¤¹¡¥
@@ -92,10 +92,6 @@ Ruby³ÈÄ¥¥â¥¸¥å¡¼¥ë¤Ë¤Ä¤¤¤ÆÏ䷹礦ruby-ext¥á¡¼¥ê¥ó¥°¥ê¥¹¥È¤È
2. configure¤ò¼Â¹Ô¤·¤ÆMakefile¤Ê¤É¤òÀ¸À®¤¹¤ë
- ´Ä¶­¤Ë¤è¤Ã¤Æ¤Ï¥Ç¥Õ¥©¥ë¥È¤ÎC¥³¥ó¥Ñ¥¤¥éÍÑ¥ª¥×¥·¥ç¥ó¤¬ÉÕ¤­
- ¤Þ¤¹¡¥configure¥ª¥×¥·¥ç¥ó¤Ç optflags=.. warnflags=.. Åù
- ¤Ç¾å½ñ¤­¤Ç¤­¤Þ¤¹¡¥
-
3. (ɬÍפʤé¤Ð)defines.h¤òÊÔ½¸¤¹¤ë
¿ʬ¡¤É¬Í×̵¤¤¤È»×¤¤¤Þ¤¹¡¥
diff --git a/array.c b/array.c
index 7e8c12b683..fbca3c193e 100644
--- a/array.c
+++ b/array.c
@@ -20,7 +20,6 @@ VALUE rb_cArray;
static ID id_cmp;
#define ARY_DEFAULT_SIZE 16
-#define ARY_MAX_SIZE (LONG_MAX / sizeof(VALUE))
void
rb_mem_clear(mem, size)
@@ -121,7 +120,7 @@ ary_new(klass, len)
if (len < 0) {
rb_raise(rb_eArgError, "negative array size (or size too big)");
}
- if (len > ARY_MAX_SIZE) {
+ if (len > 0 && len * sizeof(VALUE) <= len) {
rb_raise(rb_eArgError, "array size too big");
}
if (len == 0) len++;
@@ -196,27 +195,6 @@ rb_ary_new4(n, elts)
return ary;
}
-static VALUE
-ary_make_shared(ary)
- VALUE ary;
-{
- if (!FL_TEST(ary, ELTS_SHARED)) {
- NEWOBJ(shared, struct RArray);
- OBJSETUP(shared, rb_cArray, T_ARRAY);
-
- shared->len = RARRAY(ary)->len;
- shared->ptr = RARRAY(ary)->ptr;
- shared->aux.capa = RARRAY(ary)->aux.capa;
- RARRAY(ary)->aux.shared = (VALUE)shared;
- FL_SET(ary, ELTS_SHARED);
- OBJ_FREEZE(shared);
- return (VALUE)shared;
- }
- else {
- return RARRAY(ary)->aux.shared;
- }
-}
-
VALUE
rb_assoc_new(car, cdr)
VALUE car, cdr;
@@ -315,7 +293,7 @@ rb_ary_initialize(argc, argv, ary)
if (len < 0) {
rb_raise(rb_eArgError, "negative array size");
}
- if (len > ARY_MAX_SIZE) {
+ if (len > 0 && len * (long)sizeof(VALUE) <= len) {
rb_raise(rb_eArgError, "array size too big");
}
if (len > RARRAY(ary)->aux.capa) {
@@ -380,9 +358,6 @@ rb_ary_store(ary, idx, val)
idx - RARRAY(ary)->len);
}
}
- else if (idx >= ARY_MAX_SIZE) {
- rb_raise(rb_eIndexError, "index %ld too big", idx);
- }
rb_ary_modify(ary);
if (idx >= RARRAY(ary)->aux.capa) {
@@ -391,10 +366,10 @@ rb_ary_store(ary, idx, val)
if (new_capa < ARY_DEFAULT_SIZE) {
new_capa = ARY_DEFAULT_SIZE;
}
- if (new_capa >= ARY_MAX_SIZE - idx) {
- new_capa = (ARY_MAX_SIZE - idx) / 2;
- }
new_capa += idx;
+ if (new_capa * (long)sizeof(VALUE) <= new_capa) {
+ rb_raise(rb_eArgError, "index too big");
+ }
REALLOC_N(RARRAY(ary)->ptr, VALUE, new_capa);
RARRAY(ary)->aux.capa = new_capa;
}
@@ -409,50 +384,6 @@ rb_ary_store(ary, idx, val)
RARRAY(ary)->ptr[idx] = val;
}
-static VALUE
-ary_shared_array(klass, ary)
- VALUE klass;
- VALUE ary;
-{
- VALUE val = ary_alloc(klass);
-
- ary_make_shared(ary);
- RARRAY(val)->ptr = RARRAY(ary)->ptr;
- RARRAY(val)->len = RARRAY(ary)->len;
- RARRAY(val)->aux.shared = RARRAY(ary)->aux.shared;
- FL_SET(val, ELTS_SHARED);
- return val;
-}
-
-static VALUE
-ary_shared_first(argc, argv, ary, last)
- int argc;
- VALUE *argv;
- VALUE ary;
- int last;
-{
- VALUE nv, result;
- long n;
- long offset = 0;
-
- rb_scan_args(argc, argv, "1", &nv);
- n = NUM2LONG(nv);
- if (n > RARRAY(ary)->len) {
- n = RARRAY(ary)->len;
- }
- else if (n < 0) {
- rb_raise(rb_eArgError, "negative array size");
- }
- if (last) {
- offset = RARRAY(ary)->len - n;
- }
- result = ary_shared_array(rb_cArray, ary);
- RARRAY(result)->ptr += offset;
- RARRAY(result)->len = n;
-
- return result;
-}
-
/*
* call-seq:
* array << obj -> array
@@ -500,6 +431,18 @@ rb_ary_push_m(argc, argv, ary)
return ary;
}
+/*
+ * call-seq:
+ * array.pop -> obj or nil
+ *
+ * Removes the last element from <i>self</i> and returns it, or
+ * <code>nil</code> if the array is empty.
+ *
+ * a = [ "a", "m", "z" ]
+ * a.pop #=> "z"
+ * a #=> ["a", "m"]
+ */
+
VALUE
rb_ary_pop(ary)
VALUE ary;
@@ -507,7 +450,7 @@ rb_ary_pop(ary)
rb_ary_modify_check(ary);
if (RARRAY(ary)->len == 0) return Qnil;
if (!FL_TEST(ary, ELTS_SHARED) &&
- RARRAY(ary)->len * 3 < RARRAY(ary)->aux.capa &&
+ RARRAY(ary)->len * 2 < RARRAY(ary)->aux.capa &&
RARRAY(ary)->aux.capa > ARY_DEFAULT_SIZE) {
RARRAY(ary)->aux.capa = RARRAY(ary)->len * 2;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa);
@@ -515,112 +458,62 @@ rb_ary_pop(ary)
return RARRAY(ary)->ptr[--RARRAY(ary)->len];
}
-/*
- * call-seq:
- * array.pop -> obj or nil
- * array.pop(n) -> array
- *
- * Removes the last element from <i>self</i> and returns it, or
- * <code>nil</code> if the array is empty.
- *
- * If a number _n_ is given, returns an array of the last n elements
- * (or less) just like <code>array.slice!(-n, n)</code> does.
- *
- * a = [ "a", "b", "c", "d" ]
- * a.pop #=> "d"
- * a.pop(2) #=> ["b", "c"]
- * a #=> ["a"]
- */
-
static VALUE
-rb_ary_pop_m(argc, argv, ary)
- int argc;
- VALUE *argv;
+ary_make_shared(ary)
VALUE ary;
{
- VALUE result;
+ if (!FL_TEST(ary, ELTS_SHARED)) {
+ NEWOBJ(shared, struct RArray);
+ OBJSETUP(shared, rb_cArray, T_ARRAY);
- if (argc == 0) {
- return rb_ary_pop(ary);
+ shared->len = RARRAY(ary)->len;
+ shared->ptr = RARRAY(ary)->ptr;
+ shared->aux.capa = RARRAY(ary)->aux.capa;
+ RARRAY(ary)->aux.shared = (VALUE)shared;
+ FL_SET(ary, ELTS_SHARED);
+ OBJ_FREEZE(shared);
+ return (VALUE)shared;
}
-
- rb_ary_modify_check(ary);
- result = ary_shared_first(argc, argv, ary, Qtrue);
- RARRAY(ary)->len -= RARRAY(result)->len;
- return result;
-}
-
-VALUE
-rb_ary_shift(ary)
- VALUE ary;
-{
- VALUE top;
-
- rb_ary_modify_check(ary);
- if (RARRAY(ary)->len == 0) return Qnil;
- top = RARRAY(ary)->ptr[0];
- if (!FL_TEST(ary, ELTS_SHARED)) {
- if (RARRAY(ary)->len < ARY_DEFAULT_SIZE) {
- MEMMOVE(RARRAY(ary)->ptr, RARRAY(ary)->ptr+1, VALUE, RARRAY(ary)->len-1);
- RARRAY(ary)->len--;
- return top;
- }
- RARRAY(ary)->ptr[0] = Qnil;
- ary_make_shared(ary);
+ else {
+ return RARRAY(ary)->aux.shared;
}
- RARRAY(ary)->ptr++; /* shift ptr */
- RARRAY(ary)->len--;
-
- return top;
}
/*
* call-seq:
- * array.shift -> obj or nil
- * array.shift(n) -> array
+ * array.shift -> obj or nil
*
* Returns the first element of <i>self</i> and removes it (shifting all
* other elements down by one). Returns <code>nil</code> if the array
* is empty.
- *
- * If a number _n_ is given, returns an array of the first n elements
- * (or less) just like <code>array.slice!(0, n)</code> does.
*
* args = [ "-m", "-q", "filename" ]
- * args.shift #=> "-m"
- * args #=> ["-q", "filename"]
- *
- * args = [ "-m", "-q", "filename" ]
- * args.shift(2) #=> ["-m", "-q"]
- * args #=> ["filename"]
+ * args.shift #=> "-m"
+ * args #=> ["-q", "filename"]
*/
-static VALUE
-rb_ary_shift_m(argc, argv, ary)
- int argc;
- VALUE *argv;
+VALUE
+rb_ary_shift(ary)
VALUE ary;
{
- VALUE result;
- long n;
-
- if (argc == 0) {
- return rb_ary_shift(ary);
- }
+ VALUE top;
rb_ary_modify_check(ary);
- result = ary_shared_first(argc, argv, ary, Qfalse);
- n = RARRAY(result)->len;
- if (FL_TEST(ary, ELTS_SHARED)) {
- RARRAY(ary)->ptr += n;
- RARRAY(ary)->len -= n;
- }
+ if (RARRAY(ary)->len == 0) return Qnil;
+ top = RARRAY(ary)->ptr[0];
+ if (RARRAY_LEN(ary) < ARY_DEFAULT_SIZE && !FL_TEST(ary, ELTS_SHARED)) {
+ MEMMOVE(RARRAY_PTR(ary), RARRAY_PTR(ary)+1, VALUE, RARRAY_LEN(ary)-1);
+ }
else {
- MEMMOVE(RARRAY(ary)->ptr, RARRAY(ary)->ptr+n, VALUE, RARRAY(ary)->len-n);
- RARRAY(ary)->len -= n;
+ if (!FL_TEST(ary, ELTS_SHARED)) {
+ RARRAY(ary)->ptr[0] = Qnil;
+ }
+ ary_make_shared(ary);
+ RARRAY(ary)->ptr++; /* shift ptr */
}
+ RARRAY(ary)->len--;
- return result;
+ return top;
}
VALUE
@@ -855,7 +748,17 @@ rb_ary_first(argc, argv, ary)
return RARRAY(ary)->ptr[0];
}
else {
- return ary_shared_first(argc, argv, ary, Qfalse);
+ VALUE nv, result;
+ long n, i;
+
+ rb_scan_args(argc, argv, "01", &nv);
+ n = NUM2LONG(nv);
+ if (n > RARRAY(ary)->len) n = RARRAY(ary)->len;
+ result = rb_ary_new2(n);
+ for (i=0; i<n; i++) {
+ rb_ary_push(result, RARRAY(ary)->ptr[i]);
+ }
+ return result;
}
}
@@ -881,7 +784,17 @@ rb_ary_last(argc, argv, ary)
return RARRAY(ary)->ptr[RARRAY(ary)->len-1];
}
else {
- return ary_shared_first(argc, argv, ary, Qtrue);
+ VALUE nv, result;
+ long n, i;
+
+ rb_scan_args(argc, argv, "01", &nv);
+ n = NUM2LONG(nv);
+ if (n > RARRAY(ary)->len) n = RARRAY(ary)->len;
+ result = rb_ary_new2(n);
+ for (i=RARRAY(ary)->len-n; n--; i++) {
+ rb_ary_push(result, RARRAY(ary)->ptr[i]);
+ }
+ return result;
}
}
@@ -937,41 +850,24 @@ rb_ary_fetch(argc, argv, ary)
/*
* call-seq:
- * array.index(obj) -> int or nil
- * array.index {|item| block} -> int or nil
+ * array.index(obj) -> int or nil
*
- * Returns the index of the first object in <i>self</i> such that is
- * <code>==</code> to <i>obj</i>. If a block is given instead of an
- * argument, returns first object for which <em>block</em> is true.
- * Returns <code>nil</code> if no match is found.
+ * Returns the index of the first object in <i>self</i> such that is
+ * <code>==</code> to <i>obj</i>. Returns <code>nil</code> if
+ * no match is found.
*
* a = [ "a", "b", "c" ]
- * a.index("b") #=> 1
- * a.index("z") #=> nil
- * a.index{|x|x=="b"} #=> 1
- *
- * This is an alias of <code>#find_index</code>.
+ * a.index("b") #=> 1
+ * a.index("z") #=> nil
*/
static VALUE
-rb_ary_index(argc, argv, ary)
- int argc;
- VALUE *argv;
+rb_ary_index(ary, val)
VALUE ary;
-{
VALUE val;
+{
long i;
- if (argc == 0) {
- RETURN_ENUMERATOR(ary, 0, 0);
- for (i=0; i<RARRAY(ary)->len; i++) {
- if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
- return LONG2NUM(i);
- }
- }
- return Qnil;
- }
- rb_scan_args(argc, argv, "01", &val);
for (i=0; i<RARRAY(ary)->len; i++) {
if (rb_equal(RARRAY(ary)->ptr[i], val))
return LONG2NUM(i);
@@ -983,44 +879,29 @@ rb_ary_index(argc, argv, ary)
* call-seq:
* array.rindex(obj) -> int or nil
*
- * Returns the index of the last object in <i>array</i>
- * <code>==</code> to <i>obj</i>. If a block is given instead of an
- * argument, returns first object for which <em>block</em> is
- * true. Returns <code>nil</code> if no match is found.
+ * Returns the index of the last object in <i>array</i>
+ * <code>==</code> to <i>obj</i>. Returns <code>nil</code> if
+ * no match is found.
*
* a = [ "a", "b", "b", "b", "c" ]
- * a.rindex("b") #=> 3
- * a.rindex("z") #=> nil
- * a.rindex{|x|x=="b"} #=> 3
+ * a.rindex("b") #=> 3
+ * a.rindex("z") #=> nil
*/
static VALUE
-rb_ary_rindex(argc, argv, ary)
- int argc;
- VALUE *argv;
+rb_ary_rindex(ary, val)
VALUE ary;
-{
VALUE val;
+{
long i = RARRAY(ary)->len;
- if (argc == 0) {
- RETURN_ENUMERATOR(ary, 0, 0);
- while (i--) {
- if (RTEST(rb_yield(RARRAY(ary)->ptr[i])))
- return LONG2NUM(i);
- if (i > RARRAY(ary)->len) {
- i = RARRAY(ary)->len;
- }
- }
- return Qnil;
- }
- rb_scan_args(argc, argv, "01", &val);
while (i--) {
- if (rb_equal(RARRAY(ary)->ptr[i], val))
- return LONG2NUM(i);
if (i > RARRAY(ary)->len) {
i = RARRAY(ary)->len;
+ continue;
}
+ if (rb_equal(RARRAY(ary)->ptr[i], val))
+ return LONG2NUM(i);
}
return Qnil;
}
@@ -1094,9 +975,6 @@ rb_ary_splice(ary, beg, len, rpl)
rb_ary_modify(ary);
if (beg >= RARRAY(ary)->len) {
- if (beg > ARY_MAX_SIZE - rlen) {
- rb_raise(rb_eIndexError, "index %ld too big", beg);
- }
len = beg + rlen;
if (len >= RARRAY(ary)->aux.capa) {
REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
@@ -1256,7 +1134,6 @@ rb_ary_each(ary)
{
long i;
- RETURN_ENUMERATOR(ary, 0, 0);
for (i=0; i<RARRAY(ary)->len; i++) {
rb_yield(RARRAY(ary)->ptr[i]);
}
@@ -1284,7 +1161,6 @@ rb_ary_each_index(ary)
{
long i;
- RETURN_ENUMERATOR(ary, 0, 0);
for (i=0; i<RARRAY(ary)->len; i++) {
rb_yield(LONG2NUM(i));
}
@@ -1310,10 +1186,8 @@ static VALUE
rb_ary_reverse_each(ary)
VALUE ary;
{
- long len;
+ long len = RARRAY(ary)->len;
- RETURN_ENUMERATOR(ary, 0, 0);
- len = RARRAY(ary)->len;
while (len--) {
rb_yield(RARRAY(ary)->ptr[len]);
if (RARRAY(ary)->len < len) {
@@ -1860,7 +1734,6 @@ rb_ary_collect_bang(ary)
{
long i;
- RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_modify(ary);
for (i = 0; i < RARRAY(ary)->len; i++) {
rb_ary_store(ary, i, rb_yield(RARRAY(ary)->ptr[i]));
@@ -1945,7 +1818,6 @@ rb_ary_select(ary)
VALUE result;
long i;
- RETURN_ENUMERATOR(ary, 0, 0);
result = rb_ary_new2(RARRAY(ary)->len);
for (i = 0; i < RARRAY(ary)->len; i++) {
if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
@@ -2085,42 +1957,22 @@ rb_ary_slice_bang(argc, argv, ary)
VALUE ary;
{
VALUE arg1, arg2;
- long pos, len, orig_len;
+ long pos, len;
- rb_ary_modify_check(ary);
if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) {
pos = NUM2LONG(arg1);
len = NUM2LONG(arg2);
delete_pos_len:
- if (len < 0) return Qnil;
- orig_len = RARRAY_LEN(ary);
if (pos < 0) {
- pos += orig_len;
- if (pos < 0) return Qnil;
+ pos = RARRAY(ary)->len + pos;
}
- else if (orig_len < pos) return Qnil;
- if (orig_len < pos + len) {
- len = orig_len - pos;
- }
- if (len == 0) return rb_ary_new2(0);
- arg2 = rb_ary_new4(len, RARRAY_PTR(ary)+pos);
- RBASIC(arg2)->klass = rb_obj_class(ary);
- rb_ary_splice(ary, pos, len, Qnil); /* Qundef in 1.9 */
+ arg2 = rb_ary_subseq(ary, pos, len);
+ rb_ary_splice(ary, pos, len, Qnil); /* Qnil/rb_ary_new2(0) */
return arg2;
}
- if (!FIXNUM_P(arg1)) {
- switch (rb_range_beg_len(arg1, &pos, &len, RARRAY_LEN(ary), 0)) {
- case Qtrue:
- /* valid range */
- goto delete_pos_len;
- case Qnil:
- /* invalid range */
- return Qnil;
- default:
- /* not a range */
- break;
- }
+ if (!FIXNUM_P(arg1) && rb_range_beg_len(arg1, &pos, &len, RARRAY(ary)->len, 1)) {
+ goto delete_pos_len;
}
return rb_ary_delete_at(ary, NUM2LONG(arg1));
@@ -2142,7 +1994,6 @@ rb_ary_reject_bang(ary)
{
long i1, i2;
- RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_modify(ary);
for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
VALUE v = RARRAY(ary)->ptr[i1];
@@ -2171,7 +2022,6 @@ static VALUE
rb_ary_reject(ary)
VALUE ary;
{
- RETURN_ENUMERATOR(ary, 0, 0);
ary = rb_ary_dup(ary);
rb_ary_reject_bang(ary);
return ary;
@@ -2192,7 +2042,6 @@ static VALUE
rb_ary_delete_if(ary)
VALUE ary;
{
- RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_reject_bang(ary);
return ary;
}
@@ -2416,13 +2265,10 @@ rb_ary_fill(argc, argv, ary)
break;
}
rb_ary_modify(ary);
- if (len < 0) {
- return ary;
- }
- if (beg >= ARY_MAX_SIZE || len > ARY_MAX_SIZE - beg) {
+ end = beg + len;
+ if (end < 0) {
rb_raise(rb_eArgError, "argument too big");
}
- end = beg + len;
if (end > RARRAY(ary)->len) {
if (end >= RARRAY(ary)->aux.capa) {
REALLOC_N(RARRAY(ary)->ptr, VALUE, end);
@@ -2532,7 +2378,7 @@ rb_ary_times(ary, times)
if (len < 0) {
rb_raise(rb_eArgError, "negative argument");
}
- if (ARY_MAX_SIZE/len < RARRAY(ary)->len) {
+ if (LONG_MAX/len < RARRAY(ary)->len) {
rb_raise(rb_eArgError, "argument too big");
}
len *= RARRAY(ary)->len;
@@ -2576,8 +2422,9 @@ rb_ary_assoc(ary, key)
VALUE v;
for (i = 0; i < RARRAY(ary)->len; ++i) {
- v = rb_check_array_type(RARRAY(ary)->ptr[i]);
- if (!NIL_P(v) && RARRAY(v)->len > 0 &&
+ v = RARRAY(ary)->ptr[i];
+ if (TYPE(v) == T_ARRAY &&
+ RARRAY(v)->len > 0 &&
rb_equal(RARRAY(v)->ptr[0], key))
return v;
}
@@ -2615,22 +2462,6 @@ rb_ary_rassoc(ary, value)
return Qnil;
}
-static VALUE recursive_equal _((VALUE, VALUE, int));
-static VALUE
-recursive_equal(ary1, ary2, recur)
- VALUE ary1, ary2;
- int recur;
-{
- long i;
-
- if (recur) return Qfalse;
- for (i=0; i<RARRAY(ary1)->len; i++) {
- if (!rb_equal(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
- return Qfalse;
- }
- return Qtrue;
-}
-
/*
* call-seq:
* array == other_array -> bool
@@ -2649,6 +2480,8 @@ static VALUE
rb_ary_equal(ary1, ary2)
VALUE ary1, ary2;
{
+ long i;
+
if (ary1 == ary2) return Qtrue;
if (TYPE(ary2) != T_ARRAY) {
if (!rb_respond_to(ary2, rb_intern("to_ary"))) {
@@ -2657,20 +2490,8 @@ rb_ary_equal(ary1, ary2)
return rb_equal(ary2, ary1);
}
if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
- return rb_exec_recursive(recursive_equal, ary1, ary2);
-}
-
-static VALUE recursive_eql _((VALUE, VALUE, int));
-static VALUE
-recursive_eql(ary1, ary2, recur)
- VALUE ary1, ary2;
- int recur;
-{
- long i;
-
- if (recur) return Qfalse;
for (i=0; i<RARRAY(ary1)->len; i++) {
- if (!rb_eql(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
+ if (!rb_equal(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
return Qfalse;
}
return Qtrue;
@@ -2688,33 +2509,16 @@ static VALUE
rb_ary_eql(ary1, ary2)
VALUE ary1, ary2;
{
+ long i;
+
if (ary1 == ary2) return Qtrue;
if (TYPE(ary2) != T_ARRAY) return Qfalse;
if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
- return rb_exec_recursive(recursive_eql, ary1, ary2);
-}
-
-static VALUE recursive_hash _((VALUE, VALUE, int));
-static VALUE
-recursive_hash(ary, dummy, recur)
- VALUE ary;
- VALUE dummy;
- int recur;
-{
- long i, h;
- VALUE n;
-
- if (recur) {
- return LONG2FIX(0);
- }
-
- h = RARRAY(ary)->len;
- for (i=0; i<RARRAY(ary)->len; i++) {
- h = (h << 1) | (h<0 ? 1 : 0);
- n = rb_hash(RARRAY(ary)->ptr[i]);
- h ^= NUM2LONG(n);
+ for (i=0; i<RARRAY(ary1)->len; i++) {
+ if (!rb_eql(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
+ return Qfalse;
}
- return LONG2FIX(h);
+ return Qtrue;
}
/*
@@ -2729,7 +2533,16 @@ static VALUE
rb_ary_hash(ary)
VALUE ary;
{
- return rb_exec_recursive(recursive_hash, ary, 0);
+ long i, h;
+ VALUE n;
+
+ h = RARRAY(ary)->len;
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ h = (h << 1) | (h<0 ? 1 : 0);
+ n = rb_hash(RARRAY(ary)->ptr[i]);
+ h ^= NUM2LONG(n);
+ }
+ return LONG2FIX(h);
}
/*
@@ -2761,29 +2574,6 @@ rb_ary_includes(ary, item)
}
-static VALUE recursive_cmp _((VALUE, VALUE, int));
-static VALUE
-recursive_cmp(ary1, ary2, recur)
- VALUE ary1;
- VALUE ary2;
- int recur;
-{
- long i, len;
-
- if (recur) return Qnil;
- len = RARRAY(ary1)->len;
- if (len > RARRAY(ary2)->len) {
- len = RARRAY(ary2)->len;
- }
- for (i=0; i<len; i++) {
- VALUE v = rb_funcall(rb_ary_elt(ary1, i), id_cmp, 1, rb_ary_elt(ary2, i));
- if (v != INT2FIX(0)) {
- return v;
- }
- }
- return Qundef;
-}
-
/*
* call-seq:
* array <=> other_array -> -1, 0, +1
@@ -2808,13 +2598,19 @@ VALUE
rb_ary_cmp(ary1, ary2)
VALUE ary1, ary2;
{
- long len;
- VALUE v;
+ long i, len;
ary2 = to_ary(ary2);
- if (ary1 == ary2) return INT2FIX(0);
- v = rb_exec_recursive(recursive_cmp, ary1, ary2);
- if (v != Qundef) return v;
+ len = RARRAY(ary1)->len;
+ if (len > RARRAY(ary2)->len) {
+ len = RARRAY(ary2)->len;
+ }
+ for (i=0; i<len; i++) {
+ VALUE v = rb_funcall(rb_ary_elt(ary1, i), id_cmp, 1, rb_ary_elt(ary2, i));
+ if (v != INT2FIX(0)) {
+ return v;
+ }
+ }
len = RARRAY(ary1)->len - RARRAY(ary2)->len;
if (len == 0) return INT2FIX(0);
if (len > 0) return INT2FIX(1);
@@ -3054,7 +2850,6 @@ rb_ary_compact(ary)
* array.nitems -> int
*
* Returns the number of non-<code>nil</code> elements in _self_.
- *
* May be zero.
*
* [ 1, nil, 3, nil, 5 ].nitems #=> 3
@@ -3067,692 +2862,111 @@ rb_ary_nitems(ary)
long n = 0;
VALUE *p, *pend;
- for (p = RARRAY(ary)->ptr, pend = p + RARRAY(ary)->len; p < pend; p++) {
+ p = RARRAY(ary)->ptr;
+ pend = p + RARRAY(ary)->len;
+
+ while (p < pend) {
if (!NIL_P(*p)) n++;
+ p++;
}
return LONG2NUM(n);
}
-/*
- * call-seq:
- * array.count -> int
- * array.count(obj) -> int
- * array.count { |item| block } -> int
- *
- * Returns the number of elements. If an argument is given, counts
- * the number of elements which equals to <i>obj</i>. If a block is
- * given, counts the number of elements yielding a true value.
- *
- * ary = [1, 2, 4, 2]
- * ary.count # => 4
- * ary.count(2) # => 2
- * ary.count{|x|x%2==0} # => 3
- *
- */
-
-static VALUE
-rb_ary_count(argc, argv, ary)
- int argc;
- VALUE *argv;
+static long
+flatten(ary, idx, ary2, memo)
VALUE ary;
+ long idx;
+ VALUE ary2, memo;
{
- long n = 0;
-
- if (argc == 0) {
- VALUE *p, *pend;
-
- if (!rb_block_given_p())
- return LONG2NUM(RARRAY_LEN(ary));
+ VALUE id;
+ long i = idx;
+ long n, lim = idx + RARRAY(ary2)->len;
- for (p = RARRAY_PTR(ary), pend = p + RARRAY_LEN(ary); p < pend; p++) {
- if (RTEST(rb_yield(*p))) n++;
- }
+ id = rb_obj_id(ary2);
+ if (rb_ary_includes(memo, id)) {
+ rb_raise(rb_eArgError, "tried to flatten recursive array");
}
- else {
- VALUE obj, *p, *pend;
+ rb_ary_push(memo, id);
+ rb_ary_splice(ary, idx, 1, ary2);
+ while (i < lim) {
+ VALUE tmp;
- rb_scan_args(argc, argv, "1", &obj);
- if (rb_block_given_p()) {
- rb_warn("given block not used");
- }
- for (p = RARRAY_PTR(ary), pend = p + RARRAY_LEN(ary); p < pend; p++) {
- if (rb_equal(*p, obj)) n++;
- }
- }
-
- return LONG2NUM(n);
-}
-
-static VALUE
-flatten(ary, level, modified)
- VALUE ary;
- int level;
- int *modified;
-{
- long i = 0;
- VALUE stack, result, tmp, elt;
- st_table *memo;
- st_data_t id;
-
- stack = ary_new(0, ARY_DEFAULT_SIZE);
- result = ary_new(0, RARRAY_LEN(ary));
- memo = st_init_numtable();
- st_insert(memo, (st_data_t)ary, (st_data_t)Qtrue);
- *modified = 0;
-
- while (1) {
- while (i < RARRAY(ary)->len) {
- elt = RARRAY(ary)->ptr[i++];
- tmp = rb_check_array_type(elt);
- if (RBASIC(result)->klass) {
- rb_raise(rb_eRuntimeError, "flatten reentered");
- }
- if (NIL_P(tmp) || (level >= 0 && RARRAY(stack)->len / 2 >= level)) {
- rb_ary_push(result, elt);
- }
- else {
- *modified = 1;
- id = (st_data_t)tmp;
- if (st_lookup(memo, id, 0)) {
- st_free_table(memo);
- rb_raise(rb_eArgError, "tried to flatten recursive array");
- }
- st_insert(memo, id, (st_data_t)Qtrue);
- rb_ary_push(stack, ary);
- rb_ary_push(stack, LONG2NUM(i));
- ary = tmp;
- i = 0;
- }
- }
- if (RARRAY(stack)->len == 0) {
- break;
+ tmp = rb_check_array_type(rb_ary_elt(ary, i));
+ if (!NIL_P(tmp)) {
+ n = flatten(ary, i, tmp, memo);
+ i += n; lim += n;
}
- id = (st_data_t)ary;
- st_delete(memo, &id, 0);
- tmp = rb_ary_pop(stack);
- i = NUM2LONG(tmp);
- ary = rb_ary_pop(stack);
+ i++;
}
+ rb_ary_pop(memo);
- st_free_table(memo);
-
- RBASIC(result)->klass = rb_class_of(ary);
- return result;
+ return lim - idx - 1; /* returns number of increased items */
}
/*
* call-seq:
* array.flatten! -> array or nil
- * array.flatten!(level) -> array or nil
*
* Flattens _self_ in place.
* Returns <code>nil</code> if no modifications were made (i.e.,
- * <i>array</i> contains no subarrays.) If the optional <i>level</i>
- * argument determines the level of recursion to flatten.
+ * <i>array</i> contains no subarrays.)
*
* a = [ 1, 2, [3, [4, 5] ] ]
* a.flatten! #=> [1, 2, 3, 4, 5]
* a.flatten! #=> nil
* a #=> [1, 2, 3, 4, 5]
- * a = [ 1, 2, [3, [4, 5] ] ]
- * a.flatten!(1) #=> [1, 2, 3, [4, 5]]
*/
static VALUE
-rb_ary_flatten_bang(argc, argv, ary)
- int argc;
- VALUE *argv;
+rb_ary_flatten_bang(ary)
VALUE ary;
{
- int mod = 0, level = -1;
- VALUE result, lv;
+ long i = 0;
+ int mod = 0;
+ VALUE memo = Qnil;
- rb_scan_args(argc, argv, "01", &lv);
- if (!NIL_P(lv)) level = NUM2INT(lv);
- if (level == 0) return ary;
+ while (i<RARRAY(ary)->len) {
+ VALUE ary2 = RARRAY(ary)->ptr[i];
+ VALUE tmp;
- result = flatten(ary, level, &mod);
+ tmp = rb_check_array_type(ary2);
+ if (!NIL_P(tmp)) {
+ if (NIL_P(memo)) {
+ memo = rb_ary_new();
+ }
+ i += flatten(ary, i, tmp, memo);
+ mod = 1;
+ }
+ i++;
+ }
if (mod == 0) return Qnil;
- rb_ary_replace(ary, result);
-
return ary;
}
/*
* call-seq:
* array.flatten -> an_array
- * array.flatten(level) -> an_array
*
* Returns a new array that is a one-dimensional flattening of this
* array (recursively). That is, for every element that is an array,
- * extract its elements into the new array. If the optional
- * <i>level</i> argument determines the level of recursion to flatten.
+ * extract its elements into the new array.
*
* s = [ 1, 2, 3 ] #=> [1, 2, 3]
* t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]]
* a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]
- * a.flatten #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- * a = [ 1, 2, [3, [4, 5] ] ]
- * a.flatten(1) #=> [1, 2, 3, [4, 5]]
+ * a.flatten #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10
*/
static VALUE
-rb_ary_flatten(argc, argv, ary)
- int argc;
- VALUE *argv;
+rb_ary_flatten(ary)
VALUE ary;
{
- int mod = 0, level = -1;
- VALUE result, lv;
-
- rb_scan_args(argc, argv, "01", &lv);
- if (!NIL_P(lv)) level = NUM2INT(lv);
- if (level == 0) return ary;
-
- result = flatten(ary, level, &mod);
- if (OBJ_TAINTED(ary)) OBJ_TAINT(result);
-
- return result;
-}
-
-/*
- * call-seq:
- * array.shuffle! -> array or nil
- *
- * Shuffles elements in _self_ in place.
- */
-
-
-static VALUE
-rb_ary_shuffle_bang(ary)
- VALUE ary;
-{
- long i = RARRAY(ary)->len;
-
- rb_ary_modify(ary);
- while (i) {
- long j = rb_genrand_real()*i;
- VALUE tmp = RARRAY(ary)->ptr[--i];
- RARRAY(ary)->ptr[i] = RARRAY(ary)->ptr[j];
- RARRAY(ary)->ptr[j] = tmp;
- }
- return ary;
-}
-
-
-/*
- * call-seq:
- * array.shuffle -> an_array
- *
- * Returns a new array with elements of this array shuffled.
- *
- * a = [ 1, 2, 3 ] #=> [1, 2, 3]
- * a.shuffle #=> [2, 3, 1]
- */
-
-static VALUE
-rb_ary_shuffle(VALUE ary)
-{
ary = rb_ary_dup(ary);
- rb_ary_shuffle_bang(ary);
+ rb_ary_flatten_bang(ary);
return ary;
}
-/*
- * call-seq:
- * array.choice -> obj
- *
- * Choose a random element from an array.
- */
-
-
-static VALUE
-rb_ary_choice(ary)
- VALUE ary;
-{
- long i, j;
-
- i = RARRAY(ary)->len;
- if (i == 0) return Qnil;
- j = rb_genrand_real()*i;
- return RARRAY(ary)->ptr[j];
-}
-
-
-/*
- * call-seq:
- * ary.cycle {|obj| block }
- * ary.cycle(n) {|obj| block }
- *
- * Calls <i>block</i> for each element repeatedly _n_ times or
- * forever if none or nil is given. If a non-positive number is
- * given or the array is empty, does nothing. Returns nil if the
- * loop has finished without getting interrupted.
- *
- * a = ["a", "b", "c"]
- * a.cycle {|x| puts x } # print, a, b, c, a, b, c,.. forever.
- * a.cycle(2) {|x| puts x } # print, a, b, c, a, b, c.
- *
- */
-
-static VALUE
-rb_ary_cycle(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
-{
- long n, i;
- VALUE nv = Qnil;
-
- rb_scan_args(argc, argv, "01", &nv);
-
- RETURN_ENUMERATOR(ary, argc, argv);
- if (NIL_P(nv)) {
- n = -1;
- }
- else {
- n = NUM2LONG(nv);
- if (n <= 0) return Qnil;
- }
-
- while (RARRAY(ary)->len > 0 && (n < 0 || 0 < n--)) {
- for (i=0; i<RARRAY(ary)->len; i++) {
- rb_yield(RARRAY(ary)->ptr[i]);
- }
- }
- return Qnil;
-}
-
-#define tmpbuf(n, size) rb_str_tmp_new((n)*(size))
-
-/*
- * Recursively compute permutations of r elements of the set [0..n-1].
- * When we have a complete permutation of array indexes, copy the values
- * at those indexes into a new array and yield that array.
- *
- * n: the size of the set
- * r: the number of elements in each permutation
- * p: the array (of size r) that we're filling in
- * index: what index we're filling in now
- * used: an array of booleans: whether a given index is already used
- * values: the Ruby array that holds the actual values to permute
- */
-static void
-permute0(n, r, p, index, used, values)
- long n, r, *p, index;
- int *used;
- VALUE values;
-{
- long i,j;
- for (i = 0; i < n; i++) {
- if (used[i] == 0) {
- p[index] = i;
- if (index < r-1) { /* if not done yet */
- used[i] = 1; /* mark index used */
- permute0(n, r, p, index+1, /* recurse */
- used, values);
- used[i] = 0; /* index unused */
- }
- else {
- /* We have a complete permutation of array indexes */
- /* Build a ruby array of the corresponding values */
- /* And yield it to the associated block */
- VALUE result = rb_ary_new2(r);
- VALUE *result_array = RARRAY(result)->ptr;
- const VALUE *values_array = RARRAY(values)->ptr;
-
- for (j = 0; j < r; j++) result_array[j] = values_array[p[j]];
- RARRAY(result)->len = r;
- rb_yield(result);
- }
- }
- }
-}
-
-/*
- * call-seq:
- * ary.permutation { |p| block } -> array
- * ary.permutation -> enumerator
- * ary.permutation(n) { |p| block } -> array
- * ary.permutation(n) -> enumerator
- *
- * When invoked with a block, yield all permutations of length <i>n</i>
- * of the elements of <i>ary</i>, then return the array itself.
- * If <i>n</i> is not specified, yield all permutations of all elements.
- * The implementation makes no guarantees about the order in which
- * the permutations are yielded.
- *
- * When invoked without a block, return an enumerator object instead.
- *
- * Examples:
- *
- * a = [1, 2, 3]
- * a.permutation.to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
- * a.permutation(1).to_a #=> [[1],[2],[3]]
- * a.permutation(2).to_a #=> [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]
- * a.permutation(3).to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
- * a.permutation(0).to_a #=> [[]] # one permutation of length 0
- * a.permutation(4).to_a #=> [] # no permutations of length 4
- */
-
-static VALUE
-rb_ary_permutation(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
-{
- VALUE num;
- long r, n, i;
-
- n = RARRAY(ary)->len; /* Array length */
- RETURN_ENUMERATOR(ary, argc, argv); /* Return enumerator if no block */
- rb_scan_args(argc, argv, "01", &num);
- r = NIL_P(num) ? n : NUM2LONG(num); /* Permutation size from argument */
-
- if (r < 0 || n < r) {
- /* no permutations: yield nothing */
- }
- else if (r == 0) { /* exactly one permutation: the zero-length array */
- rb_yield(rb_ary_new2(0));
- }
- else if (r == 1) { /* this is a special, easy case */
- for (i = 0; i < RARRAY(ary)->len; i++) {
- rb_yield(rb_ary_new3(1, RARRAY(ary)->ptr[i]));
- }
- }
- else { /* this is the general case */
- volatile VALUE t0 = tmpbuf(n,sizeof(long));
- long *p = (long*)RSTRING(t0)->ptr;
- volatile VALUE t1 = tmpbuf(n,sizeof(int));
- int *used = (int*)RSTRING(t1)->ptr;
- VALUE ary0 = ary_make_shared(ary); /* private defensive copy of ary */
-
- for (i = 0; i < n; i++) used[i] = 0; /* initialize array */
-
- permute0(n, r, p, 0, used, ary0); /* compute and yield permutations */
- RB_GC_GUARD(t0);
- RB_GC_GUARD(t1);
- }
- return ary;
-}
-
-static long
-combi_len(n, k)
- long n, k;
-{
- long i, val = 1;
-
- if (k*2 > n) k = n-k;
- if (k == 0) return 1;
- if (k < 0) return 0;
- val = 1;
- for (i=1; i <= k; i++,n--) {
- long m = val;
- val *= n;
- if (val < m) {
- rb_raise(rb_eRangeError, "too big for combination");
- }
- val /= i;
- }
- return val;
-}
-
-/*
- * call-seq:
- * ary.combination(n) { |c| block } -> ary
- * ary.combination(n) -> enumerator
- *
- * When invoked with a block, yields all combinations of length <i>n</i>
- * of elements from <i>ary</i> and then returns <i>ary</i> itself.
- * The implementation makes no guarantees about the order in which
- * the combinations are yielded.
- *
- * When invoked without a block, returns an enumerator object instead.
- *
- * Examples:
- *
- * a = [1, 2, 3, 4]
- * a.combination(1).to_a #=> [[1],[2],[3],[4]]
- * a.combination(2).to_a #=> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
- * a.combination(3).to_a #=> [[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
- * a.combination(4).to_a #=> [[1,2,3,4]]
- * a.combination(0).to_a #=> [[]] # one combination of length 0
- * a.combination(5).to_a #=> [] # no combinations of length 5
- *
- */
-
-static VALUE
-rb_ary_combination(ary, num)
- VALUE ary;
- VALUE num;
-{
- long n, i, len;
-
- n = NUM2LONG(num);
- RETURN_ENUMERATOR(ary, 1, &num);
- len = RARRAY(ary)->len;
- if (n < 0 || len < n) {
- /* yield nothing */
- }
- else if (n == 0) {
- rb_yield(rb_ary_new2(0));
- }
- else if (n == 1) {
- for (i = 0; i < len; i++) {
- rb_yield(rb_ary_new3(1, RARRAY(ary)->ptr[i]));
- }
- }
- else {
- volatile VALUE t0 = tmpbuf(n+1, sizeof(long));
- long *stack = (long*)RSTRING(t0)->ptr;
- long nlen = combi_len(len, n);
- volatile VALUE cc = rb_ary_new2(n);
- VALUE *chosen = RARRAY(cc)->ptr;
- long lev = 0;
-
- RBASIC(cc)->klass = 0;
- MEMZERO(stack, long, n);
- stack[0] = -1;
- for (i = 0; i < nlen; i++) {
- chosen[lev] = RARRAY(ary)->ptr[stack[lev+1]];
- for (lev++; lev < n; lev++) {
- chosen[lev] = RARRAY(ary)->ptr[stack[lev+1] = stack[lev]+1];
- }
- rb_yield(rb_ary_new4(n, chosen));
- do {
- stack[lev--]++;
- } while (lev && (stack[lev+1]+n == len+lev+1));
- }
- }
- return ary;
-}
-
-/*
- * call-seq:
- * ary.product(other_ary, ...)
- *
- * Returns an array of all combinations of elements from all arrays.
- * The length of the returned array is the product of the length
- * of ary and the argument arrays
- *
- * [1,2,3].product([4,5]) # => [[1,4],[1,5],[2,4],[2,5],[3,4],[3,5]]
- * [1,2].product([1,2]) # => [[1,1],[1,2],[2,1],[2,2]]
- * [1,2].product([3,4],[5,6]) # => [[1,3,5],[1,3,6],[1,4,5],[1,4,6],
- * # [2,3,5],[2,3,6],[2,4,5],[2,4,6]]
- * [1,2].product() # => [[1],[2]]
- * [1,2].product([]) # => []
- */
-
-static VALUE
-rb_ary_product(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
-{
- int n = argc+1; /* How many arrays we're operating on */
- volatile VALUE t0 = tmpbuf(n, sizeof(VALUE));
- volatile VALUE t1 = tmpbuf(n, sizeof(int));
- VALUE *arrays = (VALUE*)RSTRING(t0)->ptr; /* The arrays we're computing the product of */
- int *counters = (int*)RSTRING(t1)->ptr; /* The current position in each one */
- VALUE result; /* The array we'll be returning */
- long i,j;
- long resultlen = 1;
-
- RBASIC(t0)->klass = 0;
- RBASIC(t1)->klass = 0;
-
- /* initialize the arrays of arrays */
- arrays[0] = ary;
- for (i = 1; i < n; i++) arrays[i] = to_ary(argv[i-1]);
-
- /* initialize the counters for the arrays */
- for (i = 0; i < n; i++) counters[i] = 0;
-
- /* Compute the length of the result array; return [] if any is empty */
- for (i = 0; i < n; i++) {
- long k = RARRAY(arrays[i])->len, l = resultlen;
- if (k == 0) return rb_ary_new2(0);
- resultlen *= k;
- if (resultlen < k || resultlen < l || resultlen / k != l) {
- rb_raise(rb_eRangeError, "too big to product");
- }
- }
-
- /* Otherwise, allocate and fill in an array of results */
- result = rb_ary_new2(resultlen);
- for (i = 0; i < resultlen; i++) {
- int m;
- /* fill in one subarray */
- VALUE subarray = rb_ary_new2(n);
- for (j = 0; j < n; j++) {
- rb_ary_push(subarray, rb_ary_entry(arrays[j], counters[j]));
- }
-
- /* put it on the result array */
- rb_ary_push(result, subarray);
-
- /*
- * Increment the last counter. If it overflows, reset to 0
- * and increment the one before it.
- */
- m = n-1;
- counters[m]++;
- while (m > 0 && counters[m] == RARRAY(arrays[m])->len) {
- counters[m] = 0;
- m--;
- counters[m]++;
- }
- }
-
- return result;
-}
-
-/*
- * call-seq:
- * ary.take(n) => array
- *
- * Returns first n elements from <i>ary</i>.
- *
- * a = [1, 2, 3, 4, 5, 0]
- * a.take(3) # => [1, 2, 3]
- *
- */
-
-static VALUE
-rb_ary_take(obj, n)
- VALUE obj;
- VALUE n;
-{
- long len = NUM2LONG(n);
- if (len < 0) {
- rb_raise(rb_eArgError, "attempt to take negative size");
- }
-
- return rb_ary_subseq(obj, 0, len);
-}
-
-/*
- * call-seq:
- * ary.take_while {|arr| block } => array
- *
- * Passes elements to the block until the block returns nil or false,
- * then stops iterating and returns an array of all prior elements.
- *
- * a = [1, 2, 3, 4, 5, 0]
- * a.take_while {|i| i < 3 } # => [1, 2]
- *
- */
-
-static VALUE
-rb_ary_take_while(ary)
- VALUE ary;
-{
- long i;
-
- RETURN_ENUMERATOR(ary, 0, 0);
- for (i = 0; i < RARRAY(ary)->len; i++) {
- if (!RTEST(rb_yield(RARRAY(ary)->ptr[i]))) break;
- }
- return rb_ary_take(ary, LONG2FIX(i));
-}
-
-/*
- * call-seq:
- * ary.drop(n) => array
- *
- * Drops first n elements from <i>ary</i>, and returns rest elements
- * in an array.
- *
- * a = [1, 2, 3, 4, 5, 0]
- * a.drop(3) # => [4, 5, 0]
- *
- */
-
-static VALUE
-rb_ary_drop(ary, n)
- VALUE ary;
- VALUE n;
-{
- VALUE result;
- long pos = NUM2LONG(n);
- if (pos < 0) {
- rb_raise(rb_eArgError, "attempt to drop negative size");
- }
-
- result = rb_ary_subseq(ary, pos, RARRAY(ary)->len);
- if (result == Qnil) result = rb_ary_new();
- return result;
-}
-
-/*
- * call-seq:
- * ary.drop_while {|arr| block } => array
- *
- * Drops elements up to, but not including, the first element for
- * which the block returns nil or false and returns an array
- * containing the remaining elements.
- *
- * a = [1, 2, 3, 4, 5, 0]
- * a.drop_while {|i| i < 3 } # => [3, 4, 5, 0]
- *
- */
-
-static VALUE
-rb_ary_drop_while(ary)
- VALUE ary;
-{
- long i;
-
- RETURN_ENUMERATOR(ary, 0, 0);
- for (i = 0; i < RARRAY(ary)->len; i++) {
- if (!RTEST(rb_yield(RARRAY(ary)->ptr[i]))) break;
- }
- return rb_ary_drop(ary, LONG2FIX(i));
-}
-
-
-
/* Arrays are ordered, integer-indexed collections of any object.
* Array indexing starts at 0, as in C or Java. A negative index is
* assumed to be relative to the end of the array---that is, an index of -1
@@ -3790,8 +3004,8 @@ Init_Array()
rb_define_method(rb_cArray, "concat", rb_ary_concat, 1);
rb_define_method(rb_cArray, "<<", rb_ary_push, 1);
rb_define_method(rb_cArray, "push", rb_ary_push_m, -1);
- rb_define_method(rb_cArray, "pop", rb_ary_pop_m, -1);
- rb_define_method(rb_cArray, "shift", rb_ary_shift_m, -1);
+ rb_define_method(rb_cArray, "pop", rb_ary_pop, 0);
+ rb_define_method(rb_cArray, "shift", rb_ary_shift, 0);
rb_define_method(rb_cArray, "unshift", rb_ary_unshift_m, -1);
rb_define_method(rb_cArray, "insert", rb_ary_insert, -1);
rb_define_method(rb_cArray, "each", rb_ary_each, 0);
@@ -3800,9 +3014,8 @@ Init_Array()
rb_define_method(rb_cArray, "length", rb_ary_length, 0);
rb_define_alias(rb_cArray, "size", "length");
rb_define_method(rb_cArray, "empty?", rb_ary_empty_p, 0);
- rb_define_method(rb_cArray, "find_index", rb_ary_index, -1);
- rb_define_method(rb_cArray, "index", rb_ary_index, -1);
- rb_define_method(rb_cArray, "rindex", rb_ary_rindex, -1);
+ rb_define_method(rb_cArray, "index", rb_ary_index, 1);
+ rb_define_method(rb_cArray, "rindex", rb_ary_rindex, 1);
rb_define_method(rb_cArray, "indexes", rb_ary_indexes, -1);
rb_define_method(rb_cArray, "indices", rb_ary_indexes, -1);
rb_define_method(rb_cArray, "join", rb_ary_join_m, -1);
@@ -3846,22 +3059,9 @@ Init_Array()
rb_define_method(rb_cArray, "uniq!", rb_ary_uniq_bang, 0);
rb_define_method(rb_cArray, "compact", rb_ary_compact, 0);
rb_define_method(rb_cArray, "compact!", rb_ary_compact_bang, 0);
- rb_define_method(rb_cArray, "flatten", rb_ary_flatten, -1);
- rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, -1);
+ rb_define_method(rb_cArray, "flatten", rb_ary_flatten, 0);
+ rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, 0);
rb_define_method(rb_cArray, "nitems", rb_ary_nitems, 0);
- rb_define_method(rb_cArray, "count", rb_ary_count, -1);
- rb_define_method(rb_cArray, "shuffle!", rb_ary_shuffle_bang, 0);
- rb_define_method(rb_cArray, "shuffle", rb_ary_shuffle, 0);
- rb_define_method(rb_cArray, "choice", rb_ary_choice, 0);
- rb_define_method(rb_cArray, "cycle", rb_ary_cycle, -1);
- rb_define_method(rb_cArray, "permutation", rb_ary_permutation, -1);
- rb_define_method(rb_cArray, "combination", rb_ary_combination, 1);
- rb_define_method(rb_cArray, "product", rb_ary_product, -1);
-
- rb_define_method(rb_cArray, "take", rb_ary_take, 1);
- rb_define_method(rb_cArray, "take_while", rb_ary_take_while, 0);
- rb_define_method(rb_cArray, "drop", rb_ary_drop, 1);
- rb_define_method(rb_cArray, "drop_while", rb_ary_drop_while, 0);
id_cmp = rb_intern("<=>");
inspect_key = rb_intern("__inspect_key__");
diff --git a/bcc32/Makefile.sub b/bcc32/Makefile.sub
index 713b5c69df..68328e92c1 100644
--- a/bcc32/Makefile.sub
+++ b/bcc32/Makefile.sub
@@ -4,12 +4,8 @@ SHELL = $(COMSPEC)
MKFILES = Makefile
#### Start of system configuration section. ####
-!ifndef OS
OS = bccwin32
-!endif
-!if !defined(RT)
-!error RT not defined. Retry from configure pass.
-!endif
+RT = $(OS)
## variables may be overridden by $(compile_dir)/Makefile
!ifndef srcdir
@@ -141,7 +137,7 @@ STACK = 0x2000000
XCFLAGS = -DRUBY_EXPORT -I. -I$(srcdir) -I$(srcdir)/missing
-ARFLAGS = /a /p32
+ARFLAGS = /a
LD = ilink32 -q -Gn
LDSHARED = $(LD)
XLDFLAGS = -Tpe c0x32.obj
@@ -157,8 +153,8 @@ EXEEXT = .exe
PROGRAM=$(RUBY_INSTALL_NAME)$(EXEEXT)
WPROGRAM=$(RUBYW_INSTALL_NAME)$(EXEEXT)
RUBYDEF = $(RUBY_SO_NAME).def
-MINIRUBY = .\miniruby$(EXEEXT) -I$(srcdir)/lib $(MINIRUBYOPT)
-RUNRUBY = .\$(PROGRAM) "$(srcdir)/runruby.rb" --extout="$(EXTOUT)" --
+MINIRUBY = .\miniruby$(EXEEXT) $(MINIRUBYOPT)
+RUNRUBY = .\ruby$(EXEEXT) "$(srcdir)/runruby.rb" --extout="$(EXTOUT)" --
ORGLIBPATH = $(LIB)
@@ -201,13 +197,7 @@ rubyw: $(WPROGRAM)
!include $(srcdir)/common.mk
-$(MKFILES): $(srcdir)/bcc32/Makefile.sub $(srcdir)/bcc32/configure.bat $(srcdir)/bcc32/setup.mak
- $(COMSPEC) /C $(srcdir:/=\)\bcc32\configure.bat $(configure_args)
- @echo $(MKFILES) should be updated, re-run $(MAKE).
- @$(MAKE) > nul -q -f &&|
-PHONY: nul
- @exit
-|
+PHONY: Makefile
CONFIG_H = ./.config.h.time
@@ -263,7 +253,6 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/bcc32/Makefile.sub
\#define HAVE_STRTOD 1
\#define HAVE_STRTOL 1
\#define HAVE_STRTOUL 1
-\#define HAVE_VSNPRINTF 1
\#define HAVE_ISNAN 1
\#define HAVE_FINITE 1
\#define HAVE_HYPOT 1
@@ -283,9 +272,6 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/bcc32/Makefile.sub
\#define RSHIFT(x,y) ((x)>>(int)y)
\#define FILE_COUNT level
\#define FILE_READPTR curp
-\#define RUBY_SETJMP(env) _setjmp(env)
-\#define RUBY_LONGJMP(env,val) longjmp(env,val)
-\#define RUBY_JMP_BUF jmp_buf
\#define inline __inline
\#define NEED_IO_SEEK_BETWEEN_RW 1
\#define STACK_GROW_DIRECTION -1
@@ -294,12 +280,9 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/bcc32/Makefile.sub
\#define RUBY_LIB "/lib/ruby/$(MAJOR).$(MINOR)"
\#define RUBY_SITE_LIB "/lib/ruby/site_ruby"
\#define RUBY_SITE_LIB2 "/lib/ruby/site_ruby/$(MAJOR).$(MINOR)"
-\#define RUBY_VENDOR_LIB "/lib/ruby/vendor_ruby"
-\#define RUBY_VENDOR_LIB2 "/lib/ruby/vendor_ruby/$(MAJOR).$(MINOR)"
\#define RUBY_PLATFORM "$(ARCH)-$(OS)"
\#define RUBY_ARCHLIB "/lib/ruby/$(MAJOR).$(MINOR)/$(ARCH)-$(OS)"
\#define RUBY_SITE_ARCHLIB "/lib/ruby/site_ruby/$(MAJOR).$(MINOR)/$(ARCH)-$(OS)"
-\#define RUBY_VENDOR_ARCHLIB "/lib/ruby/vendor_ruby/$(MAJOR).$(MINOR)/$(ARCH)-$(OS)"
|
@exit > $@
@@ -353,7 +336,7 @@ s,@RANLIB@,,;t t
s,@AR@,$(AR),;t t
s,@ARFLAGS@,$(ARFLAGS) ,;t t
s,@LN_S@,$(LN_S),;t t
-s,@SET_MAKE@,MFLAGS = -$$(MAKEFLAGS),;t t
+s,@SET_MAKE@,$(SET_MAKE),;t t
s,@CP@,copy > nul,;t t
s,@LIBOBJS@, acosh.obj crypt.obj erf.obj win32.obj,;t t
s,@ALLOCA@,$(ALLOCA),;t t
@@ -405,14 +388,13 @@ s,@COMPILE_CXX@,$$(CXX) $$(INCFLAGS) $$(CXXFLAGS) $$(CPPFLAGS) -P -c $$(<:/=\),;
s,@COMPILE_RULES@,{$$(srcdir)}.%s{}.%s: {$$(topdir)}.%s{}.%s: {$$(hdrdir)}.%s{}.%s: .%s.%s:,;t t
s,@RULE_SUBST@,{.;$$(VPATH)}%s,;t t
s,@COMMON_LIBS@,m advapi32 avicap32 avifil32 cap comctl32 comdlg32 dlcapi gdi32 glu32 imagehlp imm32 inetmib1 kernel32 loadperf lsapi32 lz32 mapi32 mgmtapi mpr msacm32 msvfw32 nddeapi netapi32 ole32 oleaut32 oledlg olepro32 opengl32 pdh pkpd32 rasapi32 rasdlg rassapi rpcrt4 setupapi shell32 shfolder snmpapi sporder tapi32 url user32 vdmdbg version win32spl winmm wintrust wsock32,;t t
-s,@COMMON_MACROS@,WIN32_LEAN_AND_MEAN WIN32,;t t
+s,@COMMON_MACROS@,WIN32_LEAN_AND_MEAN,;t t
s,@COMMON_HEADERS@,winsock2.h windows.h,;t t
s,@TRY_LINK@,$$(CC) -oconftest $$(INCFLAGS) -I$$(hdrdir) $$(CPPFLAGS) $$(CFLAGS) $$(LIBPATH) $$(LDFLAGS) $$(src) $$(LOCAL_LIBS) $$(LIBS),;t t
s,@EXPORT_PREFIX@,_,;t t
s,@arch@,$(ARCH)-$(OS),;t t
s,@sitearch@,$(ARCH)-$(OS),;t t
s,@sitedir@,$${prefix}/lib/ruby/site_ruby,;t t
-s,@vendordir@,$${prefix}/lib/ruby/vendor_ruby,;t t
s,@configure_args@,--enable-shared $(configure_args),;t t
s,@configure_input@,$$configure_input,;t t
s,@srcdir@,$(srcdir),;t t
@@ -467,46 +449,14 @@ post-install-doc::
@$(NULLCMD)
clean-local::
- @$(RM) $(WINMAINOBJ) ext\extinit.c ext\extinit.$(OBJEXT) *.tds *.il? $(RUBY_SO_NAME).lib
+ @$(RM) ext\extinit.c ext\extinit.$(OBJEXT) *.tds *.il? $(RUBY_SO_NAME).lib
@$(RM) $(RUBY_INSTALL_NAME).res $(RUBYW_INSTALL_NAME).res $(RUBY_SO_NAME).res
- @$(RM) *.map *.pdb *.ilk *.exp $(RUBYDEF)
distclean-local::
@$(RM) ext\config.cache $(RBCONFIG:/=\)
+ @$(RM) *.map *.pdb *.ilk *.exp $(RUBYDEF)
@$(RM) $(RUBY_INSTALL_NAME).rc $(RUBYW_INSTALL_NAME).rc $(RUBY_SO_NAME).rc
-update-rubyspec:
- @echo SPEC_EXISTS=0 > $@.mk
- @if exist $(srcdir:/=\)\rubyspec\nul echo SPEC_EXISTS=1 >> $@.mk
- @type >> $@.mk &&|
-$()update-rubyspec:
-$() @del $@.mk
-$()!if $$(SPEC_EXISTS)
-$() cd $(srcdir:/=\)\rubyspec\mspec
-$() git pull
-$() cd ..\spec\rubyspec
-$() git pull
-$()!else
-$() git clone $(MSPEC_GIT_URL) $(srcdir)/rubyspec/mspec
-$() git clone $(RUBYSPEC_GIT_URL) $(srcdir)/rubyspec/spec/rubyspec
-$()!endif
-|
- @$(MAKE) -$(MAKEFLAGS)$(MFLAGS) -f $@.mk
-
-test-rubyspec:
- @echo SPEC_EXISTS=0 > $@.mk
- @if exist $(srcdir:/=\)\rubyspec\nul echo SPEC_EXISTS=1 >> $@.mk
- @type >> $@.mk &&|
-$()test-rubyspec:
-$()!if $$(SPEC_EXISTS)
-$() $(RUNRUBY) $(srcdir)/rubyspec/mspec/bin/mspec -r$(srcdir)/ext/purelib.rb $(srcdir)/rubyspec/spec/rubyspec/$(MAJOR).$(MINOR)
-$()!else
-$() @echo No rubyspec here. put rubyspec to srcdir first.
-$() @cd $(srcdir:/=\)\rubyspec
-$()!endif
-|
- @$(MAKE) -$(MAKEFLAGS) -f $@.mk
-
ext/extinit.obj: ext/extinit.c $(SETUP)
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -o$@ -c ext/extinit.c
diff --git a/bcc32/configure.bat b/bcc32/configure.bat
index 95575cbc60..143ad947f0 100755
--- a/bcc32/configure.bat
+++ b/bcc32/configure.bat
@@ -6,110 +6,70 @@
echo> ~tmp~.mak ####
echo>> ~tmp~.mak conf = %0
echo>> ~tmp~.mak $(conf:\=/): nul
-echo>> ~tmp~.mak @del ~setup~.mak
+echo>> ~tmp~.mak @del ~tmp~.mak
echo>> ~tmp~.mak @-$(MAKE) -l$(MAKEFLAGS) -f $(@D)setup.mak \
-if exist pathlist.tmp del pathlist.tmp
-if exist confargs.mk del confargs.mk
:loop
if "%1" == "" goto :end
if "%1" == "--prefix" goto :prefix
-if "%1" == "prefix" goto :prefix
if "%1" == "--srcdir" goto :srcdir
if "%1" == "srcdir" goto :srcdir
if "%1" == "--target" goto :target
if "%1" == "target" goto :target
if "%1" == "--with-static-linked-ext" goto :extstatic
if "%1" == "--program-suffix" goto :suffix
-if "%1" == "RUBY_SUFFIX" goto :suffix
-if "%1" == "--program-name" goto :installname
-if "%1" == "--install-name" goto :installname
-if "%1" == "RUBY_INSTALL_NAME" goto :installname
-if "%1" == "--so-name" goto :soname
-if "%1" == "RUBY_SO_NAME" goto :soname
+if "%1" == "--program-name" goto :progname
if "%1" == "--enable-install-doc" goto :enable-rdoc
if "%1" == "--disable-install-doc" goto :disable-rdoc
if "%1" == "--extout" goto :extout
-if "%1" == "EXTOUT" goto :extout
-if "%1" == "--path" goto :path
if "%1" == "-h" goto :help
if "%1" == "--help" goto :help
- echo>>confargs.tmp %1 \
+ echo>> ~tmp~.mak "%1" \
shift
goto :loop
:srcdir
- echo>> ~tmp~.mak -Dsrcdir=%2 \
- echo>>confargs.tmp --srcdir=%2 \
+ echo>> ~tmp~.mak -D"srcdir=%2" \
shift
shift
goto :loop
:prefix
- echo>> ~tmp~.mak -Dprefix=%2 \
- echo>>confargs.tmp %1=%2 \
+ echo>> ~tmp~.mak -D"prefix=%2" \
shift
shift
goto :loop
:suffix
- echo>>confargs.mk !ifndef RUBY_SUFFIX
- echo>>confargs.mk RUBY_SUFFIX = %2
- echo>>confargs.mk !endif
- echo>>confargs.tmp %1=%2 \
+ echo>> ~tmp~.mak -D"RUBY_SUFFIX=%2" \
shift
shift
goto :loop
:installname
- echo>>confargs.mk !ifndef RUBY_INSTALL_NAME
- echo>>confargs.mk RUBY_INSTALL_NAME = %2
- echo>>confargs.mk !endif
- echo>>confargs.tmp %1=%2 \
+ echo>> ~tmp~.mak -D"RUBY_INSTALL_NAME=%2" \
shift
shift
goto :loop
:soname
- echo>>confargs.mk !ifndef RUBY_SO_NAME
- echo>>confargs.mk RUBY_SO_NAME = %2
- echo>>confargs.mk !endif
- echo>>confargs.tmp %1=%2 \
+ echo>> ~tmp~.mak -D"RUBY_SO_NAME=%2" \
shift
shift
goto :loop
:target
- echo>> ~tmp~.mak %2 \
- echo>>confargs.tmp --target=%2 \
+ echo>> ~tmp~.mak "%2" \
shift
shift
goto :loop
:extstatic
- echo>>confargs.mk !ifndef EXTSTATIC
- echo>>confargs.mk EXTSTATIC = static
- echo>>confargs.mk !endif
- echo>>confargs.tmp %1 \
+ echo>> ~tmp~.mak -D"EXTSTATIC=static" \
shift
goto :loop
:enable-rdoc
- echo>>confargs.mk !ifndef RDOCTARGET
- echo>>confargs.mk RDOCTARGET = install-doc
- echo>>confargs.mk !endif
- echo>>confargs.tmp %1 \
+ echo>> ~tmp~.mak -D"RDOCTARGET=install-doc" \
shift
goto :loop
:disable-rdoc
- echo>>confargs.mk !ifndef RDOCTARGET
- echo>>confargs.mk RDOCTARGET = install-nodoc
- echo>>confargs.mk !endif
- echo>>confargs.tmp %1 \
+ echo>> ~tmp~.mak -D"RDOCTARGET=install-nodoc" \
shift
goto :loop
:extout
- echo>>confargs.mk !ifndef EXTOUT
- echo>>confargs.mk EXTOUT = %2
- echo>>confargs.mk !endif
- echo>>confargs.tmp %1=%2 \
- shift
- shift
-goto :loop
-:path
- echo>>pathlist.tmp %2;\
- echo>>confargs.tmp %1=%2 \
+ echo>> ~tmp~.mak -D"EXTOUT=%2" \
shift
shift
goto :loop
@@ -123,30 +83,10 @@ goto :loop
echo --target=TARGET configure for TARGET [i386-bccwin32]
echo Optional Package:
echo --with-static-linked-ext link external modules statically
- echo --disable-install-doc install rdoc indexes during install
- del *.tmp
+ echo --enable-install-doc install rdoc indexes during install
del ~tmp~.mak
goto :exit
:end
-echo>> ~tmp~.mak -Dbcc32dir=$(@D)
-if not exist confargs.tmp goto :noconfargs
- echo>>confargs.mk configure_args = \
- type>>confargs.mk confargs.tmp
- echo.>>confargs.mk
- echo>>confargs.mk ####
-:noconfargs
-if not exist pathlist.tmp goto :nopathlist
- echo>>confargs.mk pathlist = \
- type>>confargs.mk pathlist.tmp
- echo.>>confargs.mk
- echo>>confargs.mk ####
- echo>>confargs.mk PATH = $(pathlist:;=/bin;)$(PATH)
- echo>>confargs.mk INCLUDE = $(pathlist:;=/include;)
- echo>>confargs.mk LIB = $(pathlist:;=/lib;)
-:nopathlist
-if exist confargs.mk copy confargs.mk ~setup~.mak > nul
-type>>~setup~.mak ~tmp~.mak
-del *.tmp > nul
-del ~tmp~.mak > nul
-make -s -f ~setup~.mak
+echo>> ~tmp~.mak -Dbcc32dir="$(@D)"
+make -s -f ~tmp~.mak
:exit
diff --git a/bcc32/setup.mak b/bcc32/setup.mak
index 483292ed51..b7a2539d0a 100644
--- a/bcc32/setup.mak
+++ b/bcc32/setup.mak
@@ -30,9 +30,7 @@ i586-$(OS): -prologue- -i586- -epilogue-
i686-$(OS): -prologue- -i686- -epilogue-
alpha-$(OS): -prologue- -alpha- -epilogue-
--prologue-: -basic-vars- -version- -system-vars-
-
--basic-vars-: nul
+-prologue-: nul
@echo Creating $(MAKEFILE)
@type > $(MAKEFILE) &&|
\#\#\# Makefile for ruby $(OS) \#\#\#
@@ -42,68 +40,36 @@ $(BANG)endif
$(BANG)ifndef prefix
prefix = $(prefix:\=/)
$(BANG)endif
-|
-!if exist(confargs.mk)
- @type confargs.mk >> $(MAKEFILE)
- @del confargs.mk
+$(BANG)ifndef EXTSTATIC
+EXTSTATIC = $(EXTSTATIC)
+$(BANG)endif
+!if defined(RDOCTARGET)
+$(BANG)ifndef RDOCTARGET
+RDOCTARGET = $(RDOCTARGET)
+$(BANG)endif
!endif
-
--system-vars-: -runtime- -bormm-
-
--bormm-: nul
- @-ilink32 -q -Gn -x usebormm.lib > nul
- @-if exist usebormm.tds $(APPEND) MEMLIB = usebormm.lib
- @if exist usebormm.* del usebormm.*
-
--osname-: nul
- @echo OS = >>$(MAKEFILE)
-
--runtime-: nul
- type > conftest.c &&|
-\#include <stdio.h>
-int main(){printf("");return 0;}
-|
- bcc32 conftest.c cw32i.lib > nul
- tdump conftest.exe < nul > conftest.i
- grep "^Imports from CC" conftest.i > conftest.c
- cpp32 -P- -DFile=\# -DImports=RTNAME -Dfrom== conftest.c > nul
- $(MAKE) > nul -DBANG=$(BANG) -f &&|
--runtime-: nul
-$(BANG)include conftest.i
-RT = $$(RTNAME:.DLL=)
-OS = $$(RT:CC32=)
--runtime-:
- del conftest.*
-$(BANG)if "$$(OS)" == "50"
- echo OS = bccwin32 >> $(MAKEFILE)
-$(BANG)else
- echo OS = bccwin32_$$(OS) >> $(MAKEFILE)
+!if defined(EXTOUT)
+$(BANG)ifndef EXTOUT
+EXTOUT = $(EXTOUT)
$(BANG)endif
+!endif
|
- @echo RT = $$(OS) >> $(MAKEFILE)
+ @type > usebormm.bat &&|
+@echo off
+ilink32 -Gn -x usebormm.lib > nul
+if exist usebormm.tds echo MEMLIB = usebormm.lib
+|
+ @usebormm.bat >> $(MAKEFILE)
+ @del usebormm.*
--version-: nul
@cpp32 -I$(srcdir) -P- -o$(MAKEFILE) > nul &&|
\#include "version.h"
MAJOR = RUBY_VERSION_MAJOR
MINOR = RUBY_VERSION_MINOR
TEENY = RUBY_VERSION_TEENY
-
-BORLANDC = __BORLANDC__
|
- @$(MAKE) > nul -DBANG=$(BANG) -f &&,
--version-: nul
-$(BANG)include $(MAKEFILE)
-$(BANG)include $(MAKEFILE).i
--version-:
+ @type $(MAKEFILE).i >> $(MAKEFILE)
@del $(MAKEFILE).i
- @type >> $(MAKEFILE) &&|
-MAJOR = $$(MAJOR)
-MINOR = $$(MINOR)
-TEENY = $$(TEENY)
-BORLANDC = $$(BORLANDC)
-|
-,
-generic-: nul
!if defined(PROCESSOR_ARCHITECTURE) || defined(PROCESSOR_LEVEL)
@@ -118,6 +84,7 @@ $(BANG)ifndef PROCESSOR_LEVEL
PROCESSOR_LEVEL = $(PROCESSOR_LEVEL)
$(BANG)endif
!endif
+
|
!endif
@@ -150,6 +117,8 @@ $(BANG)endif
-epilogue-: nul
@type >> $(MAKEFILE) &&|
+\# OS = $(OS)
+\# RT = $(RT)
\# RUBY_INSTALL_NAME = ruby
\# RUBY_SO_NAME = $$(RT)-$$(RUBY_INSTALL_NAME)$$(MAJOR)$$(MINOR)
\# CFLAGS = -q $$(DEBUGFLAGS) $$(OPTFLAGS) $$(PROCESSOR_FLAG) -w- -wsus -wcpt -wdup -wext -wrng -wrpt -wzdi
@@ -160,4 +129,5 @@ $(BANG)endif
\# EXTLIBS = cw32.lib import32.lib user32.lib kernel32.lib
$(BANG)include $$(srcdir)/bcc32/Makefile.sub
|
+ @$(srcdir:/=\)\win32\rm.bat config.h config.status
@echo type "`$(MAKE)'" to make ruby for $(OS).
diff --git a/bignum.c b/bignum.c
index 7f14aee709..547759f099 100644
--- a/bignum.c
+++ b/bignum.c
@@ -11,10 +11,8 @@
**********************************************************************/
#include "ruby.h"
-#include "rubysig.h"
#include <math.h>
-#include <float.h>
#include <ctype.h>
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
@@ -38,21 +36,7 @@ VALUE rb_cBignum;
#define BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1)))
#define BDIGMAX ((BDIGIT)-1)
-#define BIGZEROP(x) (RBIGNUM(x)->len == 0 || \
- (BDIGITS(x)[0] == 0 && \
- (RBIGNUM(x)->len == 1 || bigzero_p(x))))
-
-static int bigzero_p(VALUE);
-static int
-bigzero_p(x)
- VALUE x;
-{
- long i;
- for (i = 0; i < RBIGNUM(x)->len; ++i) {
- if (BDIGITS(x)[i]) return 0;
- }
- return 1;
-}
+#define BIGZEROP(x) (RBIGNUM(x)->len == 0 || (RBIGNUM(x)->len == 1 && BDIGITS(x)[0] == 0))
static VALUE
bignew_1(klass, len, sign)
@@ -119,15 +103,13 @@ bigtrunc(x)
long len = RBIGNUM(x)->len;
BDIGIT *ds = BDIGITS(x);
- if (len == 0) return x;
while (--len && !ds[len]);
RBIGNUM(x)->len = ++len;
return x;
}
static VALUE
-bigfixize(x)
- VALUE x;
+bigfixize(VALUE x)
{
long len = RBIGNUM(x)->len;
BDIGIT *ds = BDIGITS(x);
@@ -150,8 +132,7 @@ bigfixize(x)
}
static VALUE
-bignorm(x)
- VALUE x;
+bignorm(VALUE x)
{
if (!FIXNUM_P(x) && TYPE(x) == T_BIGNUM) {
x = bigfixize(bigtrunc(x));
@@ -463,15 +444,8 @@ rb_cstr_to_inum(str, base, badcheck)
break;
}
if (*str == '0') { /* squeeze preceeding 0s */
- int us = 0;
- while ((c = *++str) == '0' || c == '_') {
- if (c == '_') {
- if (++us >= 2)
- break;
- } else
- us = 0;
- }
- if (!(c = *str) || ISSPACE(c)) --str;
+ while (*++str == '0');
+ if (!*str) --str;
}
c = *str;
c = conv_digit(c);
@@ -513,11 +487,10 @@ rb_cstr_to_inum(str, base, badcheck)
for (i=len;i--;) zds[i]=0;
while ((c = *str++) != 0) {
if (c == '_') {
- if (nondigit) {
- if (badcheck) goto bad;
- break;
+ if (badcheck) {
+ if (nondigit) goto bad;
+ nondigit = c;
}
- nondigit = c;
continue;
}
else if ((c = conv_digit(c)) < 0) {
@@ -579,7 +552,7 @@ rb_str_to_inum(str, base, badcheck)
s = p;
}
}
- return rb_cstr_to_inum(s, base, badcheck);
+ return rb_cstr_to_inum(s, base, badcheck);
}
#if HAVE_LONG_LONG
@@ -641,7 +614,7 @@ rb_ll2inum(n)
}
#endif /* HAVE_LONG_LONG */
-
+
VALUE
rb_cstr2inum(str, base)
const char *str;
@@ -678,9 +651,6 @@ rb_big2str0(x, base, trim)
if (BIGZEROP(x)) {
return rb_str_new2("0");
}
- if (i >= LONG_MAX/SIZEOF_BDIGITS/CHAR_BIT) {
- rb_raise(rb_eRangeError, "bignum too big to convert into `string'");
- }
j = SIZEOF_BDIGITS*CHAR_BIT*i;
switch (base) {
case 2: break;
@@ -721,7 +691,6 @@ rb_big2str0(x, base, trim)
s = RSTRING(ss)->ptr;
s[0] = RBIGNUM(x)->sign ? '+' : '-';
- TRAP_BEG;
while (i && j > 1) {
long k = i;
BDIGIT_DBL num = 0;
@@ -736,7 +705,7 @@ rb_big2str0(x, base, trim)
while (k--) {
s[--j] = ruby_digitmap[num % base];
num /= base;
- if (!trim && j <= 1) break;
+ if (!trim && j < 1) break;
if (trim && i == 0 && num == 0) break;
}
}
@@ -751,7 +720,6 @@ rb_big2str0(x, base, trim)
RSTRING(ss)->len = i;
}
s[RSTRING(ss)->len] = '\0';
- TRAP_END;
return ss;
}
@@ -765,10 +733,10 @@ rb_big2str(VALUE x, int base)
/*
* call-seq:
* big.to_s(base=10) => string
- *
+ *
* Returns a string containing the representation of <i>big</i> radix
* <i>base</i> (2 through 36).
- *
+ *
* 12345654321.to_s #=> "12345654321"
* 12345654321.to_s(2) #=> "1011011111110110111011110000110001"
* 12345654321.to_s(8) #=> "133766736061"
@@ -812,15 +780,15 @@ big2ulong(x, type)
}
unsigned long
-rb_big2ulong_pack(x)
- VALUE x;
-{
+rb_big2ulong_pack(x)
+ VALUE x;
+{
unsigned long num = big2ulong(x, "unsigned long");
if (!RBIGNUM(x)->sign) {
return -num;
}
return num;
-}
+}
unsigned long
rb_big2ulong(x)
@@ -938,8 +906,8 @@ rb_dbl2big(d)
return bignorm(dbl2big(d));
}
-static double
-big2dbl(x)
+double
+rb_big2dbl(x)
VALUE x;
{
double d = 0.0;
@@ -949,30 +917,21 @@ big2dbl(x)
while (i--) {
d = ds[i] + BIGRAD*d;
}
- if (!RBIGNUM(x)->sign) d = -d;
- return d;
-}
-
-double
-rb_big2dbl(x)
- VALUE x;
-{
- double d = big2dbl(x);
-
if (isinf(d)) {
rb_warn("Bignum out of Float range");
d = HUGE_VAL;
}
+ if (!RBIGNUM(x)->sign) d = -d;
return d;
}
/*
* call-seq:
* big.to_f -> float
- *
+ *
* Converts <i>big</i> to a <code>Float</code>. If <i>big</i> doesn't
* fit in a <code>Float</code>, the result is infinity.
- *
+ *
*/
static VALUE
@@ -985,11 +944,11 @@ rb_big_to_f(x)
/*
* call-seq:
* big <=> numeric => -1, 0, +1
- *
+ *
* Comparison---Returns -1, 0, or +1 depending on whether <i>big</i> is
* less than, equal to, or greater than <i>numeric</i>. This is the
* basis for the tests in <code>Comparable</code>.
- *
+ *
*/
static VALUE
@@ -1030,11 +989,11 @@ rb_big_cmp(x, y)
/*
* call-seq:
* big == obj => true or false
- *
+ *
* Returns <code>true</code> only if <i>obj</i> has the same value
* as <i>big</i>. Contrast this with <code>Bignum#eql?</code>, which
* requires <i>obj</i> to be a <code>Bignum</code>.
- *
+ *
* 68719476736 == 68719476736.0 #=> true
*/
@@ -1069,11 +1028,11 @@ rb_big_eq(x, y)
/*
* call-seq:
* big.eql?(obj) => true or false
- *
+ *
* Returns <code>true</code> only if <i>obj</i> is a
* <code>Bignum</code> with the same value as <i>big</i>. Contrast this
* with <code>Bignum#==</code>, which performs type conversions.
- *
+ *
* 68719476736.eql?(68719476736.0) #=> false
*/
@@ -1114,7 +1073,7 @@ rb_big_uminus(x)
* length, the result acts as if it had an infinite number of one
* bits to the left. In hex representations, this is displayed
* as two periods to the left of the digits.
- *
+ *
* sprintf("%X", ~0x1122334455) #=> "..FEEDDCCBBAA"
*/
@@ -1145,7 +1104,7 @@ bigsub(x, y)
BDIGIT *zds;
BDIGIT_DBL_SIGNED num;
long i = RBIGNUM(x)->len;
-
+
/* if x is larger than y, swap */
if (RBIGNUM(x)->len < RBIGNUM(y)->len) {
z = x; x = y; y = z; /* swap x y */
@@ -1166,11 +1125,11 @@ bigsub(x, y)
z = bignew(RBIGNUM(x)->len, z==0);
zds = BDIGITS(z);
- for (i = 0, num = 0; i < RBIGNUM(y)->len; i++) {
+ for (i = 0, num = 0; i < RBIGNUM(y)->len; i++) {
num += (BDIGIT_DBL_SIGNED)BDIGITS(x)[i] - BDIGITS(y)[i];
zds[i] = BIGLO(num);
num = BIGDN(num);
- }
+ }
while (num && i < RBIGNUM(x)->len) {
num += BDIGITS(x)[i];
zds[i++] = BIGLO(num);
@@ -1180,7 +1139,7 @@ bigsub(x, y)
zds[i] = BDIGITS(x)[i];
i++;
}
-
+
return z;
}
@@ -1311,7 +1270,7 @@ rb_big_mul0(x, y)
zds = BDIGITS(z);
while (j--) zds[j] = 0;
for (i = 0; i < RBIGNUM(x)->len; i++) {
- BDIGIT_DBL dd = BDIGITS(x)[i];
+ BDIGIT_DBL dd = BDIGITS(x)[i];
if (dd == 0) continue;
n = 0;
for (j = 0; j < RBIGNUM(y)->len; j++) {
@@ -1388,7 +1347,7 @@ bigdivrem(x, y, divp, modp)
dd = 0;
q = yds[ny-1];
- while ((q & (1U<<(BITSPERDIG-1))) == 0) {
+ while ((q & (1<<(BITSPERDIG-1))) == 0) {
q <<= 1;
dd++;
}
@@ -1512,6 +1471,9 @@ rb_big_div(x, y)
case T_BIGNUM:
break;
+ case T_FLOAT:
+ return rb_float_new(rb_big2dbl(x) / RFLOAT(y)->value);
+
default:
return rb_num_coerce_bin(x, y);
}
@@ -1554,9 +1516,9 @@ rb_big_modulo(x, y)
/*
* call-seq:
* big.remainder(numeric) => number
- *
+ *
* Returns the remainder after dividing <i>big</i> by <i>numeric</i>.
- *
+ *
* -1234567890987654321.remainder(13731) #=> -6966
* -1234567890987654321.remainder(13731.24) #=> -9906.22531493148
*/
@@ -1582,27 +1544,6 @@ rb_big_remainder(x, y)
return bignorm(z);
}
-static int
-bdigbitsize(BDIGIT x)
-{
- int size = 1;
- int nb = BITSPERDIG / 2;
- BDIGIT bits = (~0 << nb);
-
- if (!x) return 0;
- while (x > 1) {
- if (x & bits) {
- size += nb;
- x >>= nb;
- }
- x &= ~bits;
- nb /= 2;
- bits >>= nb;
- }
-
- return size;
-}
-
static VALUE big_lshift _((VALUE, unsigned long));
static VALUE big_rshift _((VALUE, unsigned long));
@@ -1620,9 +1561,9 @@ static VALUE big_shift(x, n)
/*
* call-seq:
* big.divmod(numeric) => array
- *
+ *
* See <code>Numeric#divmod</code>.
- *
+ *
*/
VALUE
rb_big_divmod(x, y)
@@ -1649,51 +1590,22 @@ rb_big_divmod(x, y)
/*
* call-seq:
* big.quo(numeric) -> float
- * big.fdiv(numeric) -> float
- *
+ *
* Returns the floating point result of dividing <i>big</i> by
* <i>numeric</i>.
- *
+ *
* -1234567890987654321.quo(13731) #=> -89910996357705.5
* -1234567890987654321.quo(13731.24) #=> -89909424858035.7
- *
+ *
*/
static VALUE
rb_big_quo(x, y)
VALUE x, y;
{
- double dx = big2dbl(x);
+ double dx = rb_big2dbl(x);
double dy;
- if (isinf(dx)) {
-#define DBL_BIGDIG ((DBL_MANT_DIG + BITSPERDIG) / BITSPERDIG)
- VALUE z;
- int ex, ey;
-
- ex = (RBIGNUM(bigtrunc(x))->len - 1) * BITSPERDIG;
- ex += bdigbitsize(BDIGITS(x)[RBIGNUM(x)->len - 1]);
- ex -= 2 * DBL_BIGDIG * BITSPERDIG;
- if (ex) x = big_shift(x, ex);
-
- switch (TYPE(y)) {
- case T_FIXNUM:
- y = rb_int2big(FIX2LONG(y));
- case T_BIGNUM: {
- ey = (RBIGNUM(bigtrunc(y))->len - 1) * BITSPERDIG;
- ey += bdigbitsize(BDIGITS(y)[RBIGNUM(y)->len - 1]);
- ey -= DBL_BIGDIG * BITSPERDIG;
- if (ey) y = big_shift(y, ey);
- bignum:
- bigdivrem(x, y, &z, 0);
- return rb_float_new(ldexp(big2dbl(z), ex - ey));
- }
- case T_FLOAT:
- y = dbl2big(ldexp(frexp(RFLOAT(y)->value, &ey), DBL_MANT_DIG));
- ey -= DBL_MANT_DIG;
- goto bignum;
- }
- }
switch (TYPE(y)) {
case T_FIXNUM:
dy = (double)FIX2LONG(y);
@@ -1713,52 +1625,6 @@ rb_big_quo(x, y)
return rb_float_new(dx / dy);
}
-static VALUE
-bigsqr(x)
- VALUE x;
-{
- long len = RBIGNUM(x)->len, k = len / 2, i;
- VALUE a, b, a2, z;
- BDIGIT_DBL num;
-
- if (len < 4000 / BITSPERDIG) {
- return rb_big_mul0(x, x);
- }
-
- a = bignew(len - k, 1);
- MEMCPY(BDIGITS(a), BDIGITS(x) + k, BDIGIT, len - k);
- b = bignew(k, 1);
- MEMCPY(BDIGITS(b), BDIGITS(x), BDIGIT, k);
-
- a2 = bigtrunc(bigsqr(a));
- z = bigsqr(b);
- REALLOC_N(RBIGNUM(z)->digits, BDIGIT, (len = 2 * k + RBIGNUM(a2)->len) + 1);
- while (RBIGNUM(z)->len < 2 * k) BDIGITS(z)[RBIGNUM(z)->len++] = 0;
- MEMCPY(BDIGITS(z) + 2 * k, BDIGITS(a2), BDIGIT, RBIGNUM(a2)->len);
- RBIGNUM(z)->len = len;
- a2 = bigtrunc(rb_big_mul0(a, b));
- len = RBIGNUM(a2)->len;
- TRAP_BEG;
- for (i = 0, num = 0; i < len; i++) {
- num += (BDIGIT_DBL)BDIGITS(z)[i + k] + ((BDIGIT_DBL)BDIGITS(a2)[i] << 1);
- BDIGITS(z)[i + k] = BIGLO(num);
- num = BIGDN(num);
- }
- TRAP_END;
- if (num) {
- len = RBIGNUM(z)->len;
- for (i += k; i < len && num; ++i) {
- num += (BDIGIT_DBL)BDIGITS(z)[i];
- BDIGITS(z)[i] = BIGLO(num);
- num = BIGDN(num);
- }
- if (num) {
- BDIGITS(z)[RBIGNUM(z)->len++] = BIGLO(num);
- }
- }
- return bigtrunc(z);
-}
-
/*
* call-seq:
* big ** exponent #=> numeric
@@ -1778,7 +1644,7 @@ rb_big_pow(x, y)
{
double d;
long yy;
-
+
if (y == INT2FIX(0)) return INT2FIX(1);
switch (TYPE(y)) {
case T_FLOAT:
@@ -1793,8 +1659,7 @@ rb_big_pow(x, y)
case T_FIXNUM:
yy = FIX2LONG(y);
if (yy > 0) {
- VALUE z = 0;
- long mask;
+ VALUE z = x;
const long BIGLEN_LIMIT = 1024*1024 / SIZEOF_BDIGITS;
if ((RBIGNUM(x)->len > BIGLEN_LIMIT) ||
@@ -1803,11 +1668,16 @@ rb_big_pow(x, y)
d = (double)yy;
break;
}
- for (mask = FIXNUM_MAX + 1; mask; mask >>= 1) {
- if (z) z = bigtrunc(bigsqr(z));
- if (yy & mask) {
- z = z ? bigtrunc(rb_big_mul0(z, x)) : x;
+ for (;;) {
+ yy -= 1;
+ if (yy == 0) break;
+ while (yy % 2 == 0) {
+ yy /= 2;
+ x = rb_big_mul0(x, x);
+ bigtrunc(x);
}
+ z = rb_big_mul0(z, x);
+ bigtrunc(z);
}
return bignorm(z);
}
@@ -2032,7 +1902,7 @@ rb_big_lshift(x, y)
if (!NIL_P(t)) return t;
neg = 1;
}
- shift = big2ulong(y, "long");
+ shift = big2ulong(y, "long", Qtrue);
break;
}
y = rb_to_int(y);
@@ -2101,7 +1971,7 @@ rb_big_rshift(x, y)
else {
neg = 1;
}
- shift = big2ulong(y, "long");
+ shift = big2ulong(y, "long", Qtrue);
break;
}
y = rb_to_int(y);
@@ -2159,20 +2029,20 @@ big_rshift(x, shift)
/*
* call-seq:
* big[n] -> 0, 1
- *
+ *
* Bit Reference---Returns the <em>n</em>th bit in the (assumed) binary
* representation of <i>big</i>, where <i>big</i>[0] is the least
* significant bit.
- *
+ *
* a = 9**15
* 50.downto(0) do |n|
* print a[n]
* end
- *
+ *
* <em>produces:</em>
- *
+ *
* 000101110110100000111000011110010100111100010111001
- *
+ *
*/
static VALUE
@@ -2191,7 +2061,7 @@ rb_big_aref(x, y)
out_of_range:
return RBIGNUM(x)->sign ? INT2FIX(0) : INT2FIX(1);
}
- shift = big2ulong(y, "long");
+ shift = big2ulong(y, "long", Qfalse);
}
else {
i = NUM2LONG(y);
@@ -2263,9 +2133,9 @@ rb_big_coerce(x, y)
/*
* call-seq:
* big.abs -> aBignum
- *
+ *
* Returns the absolute value of <i>big</i>.
- *
+ *
* -1234567890987654321.abs #=> 1234567890987654321
*/
@@ -2293,7 +2163,7 @@ rb_big_rand(max, rand_buf)
}
v = bignew(len,1);
len--;
- BDIGITS(v)[len] = BDIGITS(max)[len] * rand_buf[len];
+ BDIGITS(v)[len] = BDIGITS(max)[len] * rand_buf[len];
while (len--) {
BDIGITS(v)[len] = ((BDIGIT)~0) * rand_buf[len];
}
@@ -2304,10 +2174,10 @@ rb_big_rand(max, rand_buf)
/*
* call-seq:
* big.size -> integer
- *
+ *
* Returns the number of bytes in the machine representation of
* <i>big</i>.
- *
+ *
* (256**10 - 1).size #=> 12
* (256**20 - 1).size #=> 20
* (256**40 - 1).size #=> 40
@@ -2327,15 +2197,15 @@ rb_big_size(big)
* Fixnum. When a calculation involving
* Bignum objects returns a result that will fit in a
* Fixnum, the result is automatically converted.
- *
+ *
* For the purposes of the bitwise operations and <code>[]</code>, a
* Bignum is treated as if it were an infinite-length
* bitstring with 2's complement representation.
- *
+ *
* While Fixnum values are immediate, Bignum
* objects are not---assignment and parameter passing work with
* references to objects, not the objects themselves.
- *
+ *
*/
void
@@ -2356,7 +2226,6 @@ Init_Bignum()
rb_define_method(rb_cBignum, "modulo", rb_big_modulo, 1);
rb_define_method(rb_cBignum, "remainder", rb_big_remainder, 1);
rb_define_method(rb_cBignum, "quo", rb_big_quo, 1);
- rb_define_method(rb_cBignum, "fdiv", rb_big_quo, 1);
rb_define_method(rb_cBignum, "**", rb_big_pow, 1);
rb_define_method(rb_cBignum, "&", rb_big_and, 1);
rb_define_method(rb_cBignum, "|", rb_big_or, 1);
diff --git a/class.c b/class.c
index 096c7fbdf1..80dc9e4b2d 100644
--- a/class.c
+++ b/class.c
@@ -48,23 +48,13 @@ rb_class_new(super)
return rb_class_boot(super);
}
-struct clone_method_data {
- st_table *tbl;
- VALUE klass;
-};
-
static int
-clone_method(mid, body, data)
+clone_method(mid, body, tbl)
ID mid;
NODE *body;
- struct clone_method_data *data;
+ st_table *tbl;
{
- NODE *fbody = body->nd_body;
-
- if (fbody && nd_type(fbody) == NODE_SCOPE) {
- fbody = rb_copy_node_scope(fbody, ruby_cref);
- }
- st_insert(data->tbl, mid, (st_data_t)NEW_METHOD(fbody, body->nd_noex));
+ st_insert(tbl, mid, (st_data_t)NEW_METHOD(body->nd_body, body->nd_noex));
return ST_CONTINUE;
}
@@ -75,8 +65,7 @@ rb_mod_init_copy(clone, orig)
{
rb_obj_init_copy(clone, orig);
if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
- RBASIC(clone)->klass = RBASIC(orig)->klass;
- RBASIC(clone)->klass = rb_singleton_class_clone(clone);
+ RBASIC(clone)->klass = rb_singleton_class_clone(orig);
}
RCLASS(clone)->super = RCLASS(orig)->super;
if (RCLASS(orig)->iv_tbl) {
@@ -89,12 +78,9 @@ rb_mod_init_copy(clone, orig)
st_delete(RCLASS(clone)->iv_tbl, (st_data_t*)&id, 0);
}
if (RCLASS(orig)->m_tbl) {
- struct clone_method_data data;
-
- data.tbl = RCLASS(clone)->m_tbl = st_init_numtable();
- data.klass = (VALUE)clone;
-
- st_foreach(RCLASS(orig)->m_tbl, clone_method, (st_data_t)&data);
+ RCLASS(clone)->m_tbl = st_init_numtable();
+ st_foreach(RCLASS(orig)->m_tbl, clone_method,
+ (st_data_t)RCLASS(clone)->m_tbl);
}
return clone;
@@ -140,22 +126,9 @@ rb_singleton_class_clone(obj)
if (RCLASS(klass)->iv_tbl) {
clone->iv_tbl = st_copy(RCLASS(klass)->iv_tbl);
}
- {
- struct clone_method_data data;
-
- data.tbl = clone->m_tbl = st_init_numtable();
- switch (TYPE(obj)) {
- case T_CLASS:
- case T_MODULE:
- data.klass = obj;
- break;
- default:
- data.klass = 0;
- break;
- }
-
- st_foreach(RCLASS(klass)->m_tbl, clone_method, (st_data_t)&data);
- }
+ clone->m_tbl = st_init_numtable();
+ st_foreach(RCLASS(klass)->m_tbl, clone_method,
+ (st_data_t)clone->m_tbl);
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
FL_SET(clone, FL_SINGLETON);
return (VALUE)clone;
diff --git a/common.mk b/common.mk
index bf49aade4a..f751fecfb5 100644
--- a/common.mk
+++ b/common.mk
@@ -2,12 +2,7 @@ bin: $(PROGRAM) $(WPROGRAM)
lib: $(LIBRUBY)
dll: $(LIBRUBY_SO)
-RUBYLIB = -
-RUBYOPT = -
-
-SPEC_GIT_BASE = git://github.com/rubyspec
-MSPEC_GIT_URL = $(SPEC_GIT_BASE)/mspec.git
-RUBYSPEC_GIT_URL = $(SPEC_GIT_BASE)/rubyspec.git
+RUBYOPT =
STATIC_RUBY = static-ruby
@@ -28,7 +23,6 @@ OBJS = array.$(OBJEXT) \
dir.$(OBJEXT) \
dln.$(OBJEXT) \
enum.$(OBJEXT) \
- enumerator.$(OBJEXT) \
error.$(OBJEXT) \
eval.$(OBJEXT) \
file.$(OBJEXT) \
@@ -62,15 +56,11 @@ OBJS = array.$(OBJEXT) \
SCRIPT_ARGS = --dest-dir="$(DESTDIR)" \
--extout="$(EXTOUT)" \
+ --make="$(MAKE)" \
--mflags="$(MFLAGS)" \
--make-flags="$(MAKEFLAGS)"
EXTMK_ARGS = $(SCRIPT_ARGS) --extension $(EXTS) --extstatic $(EXTSTATIC) --
-INSTRUBY_ARGS = $(SCRIPT_ARGS) \
- --data-mode=$(INSTALL_DATA_MODE) \
- --prog-mode=$(INSTALL_PROG_MODE) \
- --installed-list $(INSTALLED_LIST)
-INSTALL_PROG_MODE = 0755
-INSTALL_DATA_MODE = 0644
+INSTRUBY_ARGS = $(SCRIPT_ARGS) --installed-list $(INSTALLED_LIST)
PRE_LIBRUBY_UPDATE = $(MINIRUBY) -e 'ARGV[1] or File.unlink(ARGV[0]) rescue nil' -- \
$(LIBRUBY_EXTS) $(LIBRUBY_SO_UPDATE)
@@ -79,7 +69,7 @@ TESTSDIR = $(srcdir)/test
TESTWORKDIR = testwork
all: $(MKFILES) $(PREP) $(RBCONFIG) $(LIBRUBY)
- @$(MINIRUBY) $(srcdir)/ext/extmk.rb --make="$(MAKE)" $(EXTMK_ARGS)
+ @$(MINIRUBY) $(srcdir)/ext/extmk.rb $(EXTMK_ARGS)
prog: $(PROGRAM) $(WPROGRAM)
miniruby$(EXEEXT): config.status $(LIBRUBY_A) $(MAINOBJ) $(MINIOBJS) $(OBJS) $(DMYEXT)
@@ -106,68 +96,65 @@ install-all: install-nodoc install-doc
install-nodoc: pre-install-nodoc do-install-nodoc post-install-nodoc
pre-install-nodoc:: pre-install-local pre-install-ext
do-install-nodoc:
- $(MINIRUBY) $(srcdir)/instruby.rb --make="$(MAKE)" $(INSTRUBY_ARGS) --mantype="$(MANTYPE)"
+ $(MINIRUBY) $(srcdir)/instruby.rb $(INSTRUBY_ARGS) --mantype="$(MANTYPE)"
post-install-nodoc:: post-install-local post-install-ext
install-local: pre-install-local do-install-local post-install-local
pre-install-local:: pre-install-bin pre-install-lib pre-install-man
do-install-local:
- $(MINIRUBY) $(srcdir)/instruby.rb --make="$(MAKE)" $(INSTRUBY_ARGS) --install=local --mantype="$(MANTYPE)"
-loadpath: $(PREP)
- $(MINIRUBY) -e 'p $$:'
-
+ $(MINIRUBY) $(srcdir)/instruby.rb $(INSTRUBY_ARGS) --install=local --mantype="$(MANTYPE)"
post-install-local:: post-install-bin post-install-lib post-install-man
install-ext: pre-install-ext do-install-ext post-install-ext
pre-install-ext:: pre-install-ext-arch pre-install-ext-comm
do-install-ext:
- $(MINIRUBY) $(srcdir)/instruby.rb --make="$(MAKE)" $(INSTRUBY_ARGS) --install=ext
+ $(MINIRUBY) $(srcdir)/instruby.rb $(INSTRUBY_ARGS) --install=ext
post-install-ext:: post-install-ext-arch post-install-ext-comm
install-arch: pre-install-arch do-install-arch post-install-arch
pre-install-arch:: pre-install-bin pre-install-ext-arch
do-install-arch:
- $(MINIRUBY) $(srcdir)/instruby.rb --make="$(MAKE)" $(INSTRUBY_ARGS) --install=bin --install=ext-arch
+ $(MINIRUBY) $(srcdir)/instruby.rb $(INSTRUBY_ARGS) --install=bin --install=ext-arch
post-install-arch:: post-install-bin post-install-ext-arch
install-comm: pre-install-comm do-install-comm post-install-comm
pre-install-comm:: pre-install-lib pre-install-ext-comm pre-install-man
do-install-comm:
- $(MINIRUBY) $(srcdir)/instruby.rb --make="$(MAKE)" $(INSTRUBY_ARGS) --install=lib --install=ext-comm --install=man
+ $(MINIRUBY) $(srcdir)/instruby.rb $(INSTRUBY_ARGS) --install=lib --install=ext-comm --install=man
post-install-comm:: post-install-lib post-install-ext-comm post-install-man
install-bin: pre-install-bin do-install-bin post-install-bin
pre-install-bin:: install-prereq
do-install-bin:
- $(MINIRUBY) $(srcdir)/instruby.rb --make="$(MAKE)" $(INSTRUBY_ARGS) --install=bin
+ $(MINIRUBY) $(srcdir)/instruby.rb $(INSTRUBY_ARGS) --install=bin
post-install-bin::
@$(NULLCMD)
install-lib: pre-install-lib do-install-lib post-install-lib
pre-install-lib:: install-prereq
do-install-lib:
- $(MINIRUBY) $(srcdir)/instruby.rb --make="$(MAKE)" $(INSTRUBY_ARGS) --install=lib
+ $(MINIRUBY) $(srcdir)/instruby.rb $(INSTRUBY_ARGS) --install=lib
post-install-lib::
@$(NULLCMD)
install-ext-comm: pre-install-ext-comm do-install-ext-comm post-install-ext-comm
pre-install-ext-comm:: install-prereq
do-install-ext-comm:
- $(MINIRUBY) $(srcdir)/instruby.rb --make="$(MAKE)" $(INSTRUBY_ARGS) --install=ext-comm
+ $(MINIRUBY) $(srcdir)/instruby.rb $(INSTRUBY_ARGS) --install=ext-comm
post-install-ext-comm::
@$(NULLCMD)
install-ext-arch: pre-install-ext-arch do-install-ext-arch post-install-ext-arch
pre-install-ext-arch:: install-prereq
do-install-ext-arch:
- $(MINIRUBY) $(srcdir)/instruby.rb --make="$(MAKE)" $(INSTRUBY_ARGS) --install=ext-arch
+ $(MINIRUBY) $(srcdir)/instruby.rb $(INSTRUBY_ARGS) --install=ext-arch
post-install-ext-arch::
@$(NULLCMD)
install-man: pre-install-man do-install-man post-install-man
pre-install-man:: install-prereq
do-install-man:
- $(MINIRUBY) $(srcdir)/instruby.rb --make="$(MAKE)" $(INSTRUBY_ARGS) --install=man --mantype="$(MANTYPE)"
+ $(MINIRUBY) $(srcdir)/instruby.rb $(INSTRUBY_ARGS) --install=man --mantype="$(MANTYPE)"
post-install-man::
@$(NULLCMD)
@@ -180,42 +167,42 @@ what-where-nodoc: no-install-nodoc
no-install-nodoc: pre-no-install-nodoc dont-install-nodoc post-no-install-nodoc
pre-no-install-nodoc:: pre-no-install-local pre-no-install-ext
dont-install-nodoc:
- $(MINIRUBY) $(srcdir)/instruby.rb -n --make="$(MAKE)" $(INSTRUBY_ARGS) --mantype="$(MANTYPE)"
+ $(MINIRUBY) $(srcdir)/instruby.rb -n $(INSTRUBY_ARGS) --mantype="$(MANTYPE)"
post-no-install-nodoc:: post-no-install-local post-no-install-ext
what-where-local: no-install-local
no-install-local: pre-no-install-local dont-install-local post-no-install-local
pre-no-install-local:: pre-no-install-bin pre-no-install-lib pre-no-install-man
dont-install-local:
- $(MINIRUBY) $(srcdir)/instruby.rb -n --make="$(MAKE)" $(INSTRUBY_ARGS) --install=local --mantype="$(MANTYPE)"
+ $(MINIRUBY) $(srcdir)/instruby.rb -n $(INSTRUBY_ARGS) --install=local --mantype="$(MANTYPE)"
post-no-install-local:: post-no-install-bin post-no-install-lib post-no-install-man
what-where-ext: no-install-ext
no-install-ext: pre-no-install-ext dont-install-ext post-no-install-ext
pre-no-install-ext:: pre-no-install-ext-arch pre-no-install-ext-comm
dont-install-ext:
- $(MINIRUBY) $(srcdir)/instruby.rb -n --make="$(MAKE)" $(INSTRUBY_ARGS) --install=ext
+ $(MINIRUBY) $(srcdir)/instruby.rb -n $(INSTRUBY_ARGS) --install=ext
post-no-install-ext:: post-no-install-ext-arch post-no-install-ext-comm
what-where-arch: no-install-arch
no-install-arch: pre-no-install-arch dont-install-arch post-no-install-arch
pre-no-install-arch:: pre-no-install-bin pre-no-install-ext-arch
dont-install-arch:
- $(MINIRUBY) $(srcdir)/instruby.rb -n --make="$(MAKE)" $(INSTRUBY_ARGS) --install=bin --install=ext-arch
+ $(MINIRUBY) $(srcdir)/instruby.rb -n $(INSTRUBY_ARGS) --install=bin --install=ext-arch
post-no-install-arch:: post-no-install-lib post-no-install-man post-no-install-ext-arch
what-where-comm: no-install-comm
no-install-comm: pre-no-install-comm dont-install-comm post-no-install-comm
pre-no-install-comm:: pre-no-install-lib pre-no-install-ext-comm pre-no-install-man
dont-install-comm:
- $(MINIRUBY) $(srcdir)/instruby.rb -n --make="$(MAKE)" $(INSTRUBY_ARGS) --install=lib --install=ext-comm --install=man
+ $(MINIRUBY) $(srcdir)/instruby.rb -n $(INSTRUBY_ARGS) --install=lib --install=ext-comm --install=man
post-no-install-comm:: post-no-install-lib post-no-install-ext-comm post-no-install-man
what-where-bin: no-install-bin
no-install-bin: pre-no-install-bin dont-install-bin post-no-install-bin
pre-no-install-bin:: install-prereq
dont-install-bin:
- $(MINIRUBY) $(srcdir)/instruby.rb -n --make="$(MAKE)" $(INSTRUBY_ARGS) --install=bin
+ $(MINIRUBY) $(srcdir)/instruby.rb -n $(INSTRUBY_ARGS) --install=bin
post-no-install-bin::
@$(NULLCMD)
@@ -223,7 +210,7 @@ what-where-lib: no-install-lib
no-install-lib: pre-no-install-lib dont-install-lib post-no-install-lib
pre-no-install-lib:: install-prereq
dont-install-lib:
- $(MINIRUBY) $(srcdir)/instruby.rb -n --make="$(MAKE)" $(INSTRUBY_ARGS) --install=lib
+ $(MINIRUBY) $(srcdir)/instruby.rb -n $(INSTRUBY_ARGS) --install=lib
post-no-install-lib::
@$(NULLCMD)
@@ -231,7 +218,7 @@ what-where-ext-comm: no-install-ext-comm
no-install-ext-comm: pre-no-install-ext-comm dont-install-ext-comm post-no-install-ext-comm
pre-no-install-ext-comm:: install-prereq
dont-install-ext-comm:
- $(MINIRUBY) $(srcdir)/instruby.rb -n --make="$(MAKE)" $(INSTRUBY_ARGS) --install=ext-comm
+ $(MINIRUBY) $(srcdir)/instruby.rb -n $(INSTRUBY_ARGS) --install=ext-comm
post-no-install-ext-comm::
@$(NULLCMD)
@@ -239,7 +226,7 @@ what-where-ext-arch: no-install-ext-arch
no-install-ext-arch: pre-no-install-ext-arch dont-install-ext-arch post-no-install-ext-arch
pre-no-install-ext-arch:: install-prereq
dont-install-ext-arch:
- $(MINIRUBY) $(srcdir)/instruby.rb -n --make="$(MAKE)" $(INSTRUBY_ARGS) --install=ext-arch
+ $(MINIRUBY) $(srcdir)/instruby.rb -n $(INSTRUBY_ARGS) --install=ext-arch
post-no-install-ext-arch::
@$(NULLCMD)
@@ -247,14 +234,14 @@ what-where-man: no-install-man
no-install-man: pre-no-install-man dont-install-man post-no-install-man
pre-no-install-man:: install-prereq
dont-install-man:
- $(MINIRUBY) $(srcdir)/instruby.rb -n --make="$(MAKE)" $(INSTRUBY_ARGS) --install=man --mantype="$(MANTYPE)"
+ $(MINIRUBY) $(srcdir)/instruby.rb -n $(INSTRUBY_ARGS) --install=man --mantype="$(MANTYPE)"
post-no-install-man::
@$(NULLCMD)
install-doc: rdoc pre-install-doc do-install-doc post-install-doc
pre-install-doc:: install-prereq
do-install-doc: $(PROGRAM)
- $(MINIRUBY) $(srcdir)/instruby.rb --make="$(MAKE)" $(INSTRUBY_ARGS) --install=rdoc --rdoc-output="$(RDOCOUT)"
+ $(MINIRUBY) $(srcdir)/instruby.rb $(INSTRUBY_ARGS) --install=rdoc --rdoc-output="$(RDOCOUT)"
post-install-doc::
@$(NULLCMD)
@@ -266,38 +253,30 @@ what-where-doc: no-install-doc
no-install-doc: pre-no-install-doc dont-install-doc post-no-install-doc
pre-no-install-doc:: install-prereq
dont-install-doc::
- $(MINIRUBY) $(srcdir)/instruby.rb -n --make="$(MAKE)" $(INSTRUBY_ARGS) --install=rdoc --rdoc-output="$(RDOCOUT)"
+ $(MINIRUBY) $(srcdir)/instruby.rb -n $(INSTRUBY_ARGS) --install=rdoc --rdoc-output="$(RDOCOUT)"
post-no-install-doc::
@$(NULLCMD)
-CLEAR_INSTALLED_LIST = clear-installed-list
-
-install-prereq: $(CLEAR_INSTALLED_LIST)
-
-clear-installed-list:
+install-prereq:
@exit > $(INSTALLED_LIST)
clean: clean-ext clean-local
clean-local::
- @$(RM) $(OBJS) $(MINIOBJS) $(MAINOBJ) $(LIBRUBY_A) $(LIBRUBY_SO) $(LIBRUBY) $(LIBRUBY_ALIASES)
+ @$(RM) $(OBJS) $(MAINOBJ) $(WINMAINOBJ) $(LIBRUBY_A) $(LIBRUBY_SO) $(LIBRUBY) $(LIBRUBY_ALIASES)
@$(RM) $(PROGRAM) $(WPROGRAM) miniruby$(EXEEXT) dmyext.$(OBJEXT) $(ARCHFILE) .*.time
- @$(RM) y.tab.c y.output
clean-ext:
- @-$(MINIRUBY) $(srcdir)/ext/extmk.rb --make="$(MAKE)" $(EXTMK_ARGS) clean
+ @-$(MINIRUBY) $(srcdir)/ext/extmk.rb $(EXTMK_ARGS) clean
distclean: distclean-ext distclean-local
distclean-local:: clean-local
@$(RM) $(MKFILES) config.h rbconfig.rb
@$(RM) config.cache config.log config.status
- @$(RM) *~ *.bak *.stackdump core *.core gmon.out $(PREP)
+ @$(RM) *~ *.bak *.stackdump core *.core gmon.out y.tab.c y.output $(PREP)
distclean-ext:
- @-$(MINIRUBY) $(srcdir)/ext/extmk.rb --make="$(MAKE)" $(EXTMK_ARGS) distclean
+ @-$(MINIRUBY) $(srcdir)/ext/extmk.rb $(EXTMK_ARGS) distclean
-realclean:: realclean-ext realclean-local
-realclean-local:: distclean-local
+realclean:: distclean
@$(RM) parse.c lex.c
-realclean-ext::
- @-$(MINIRUBY) $(srcdir)/ext/extmk.rb --make="$(MAKE)" $(EXTMK_ARGS) realclean
check: test test-all
@@ -308,7 +287,7 @@ test-all:
$(RUNRUBY) "$(srcdir)/test/runner.rb" --basedir="$(TESTSDIR)" --runner=$(TESTUI) $(TESTS)
extconf:
- $(MINIRUBY) -run -e mkdir -- -p "$(EXTCONFDIR)"
+ $(MINIRUBY) -I$(srcdir)/lib -run -e mkdir -- -p "$(EXTCONFDIR)"
$(RUNRUBY) -C "$(EXTCONFDIR)" $(EXTCONF) $(EXTCONFARGS)
$(RBCONFIG): $(srcdir)/mkconfig.rb config.status $(PREP)
@@ -362,8 +341,7 @@ array.$(OBJEXT): {$(VPATH)}array.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}util.h {$(VPATH)}st.h
bignum.$(OBJEXT): {$(VPATH)}bignum.c {$(VPATH)}ruby.h config.h \
- {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
- {$(VPATH)}rubysig.h
+ {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h
class.$(OBJEXT): {$(VPATH)}class.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}rubysig.h {$(VPATH)}node.h {$(VPATH)}st.h
@@ -375,13 +353,13 @@ dir.$(OBJEXT): {$(VPATH)}dir.c {$(VPATH)}ruby.h config.h \
dln.$(OBJEXT): {$(VPATH)}dln.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}dln.h
-dmydln.$(OBJEXT): {$(VPATH)}dmydln.c dln.$(OBJEXT)
+dmydln.$(OBJEXT): {$(VPATH)}dmydln.c {$(VPATH)}dln.c {$(VPATH)}ruby.h \
+ config.h {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
+ {$(VPATH)}dln.h
dmyext.$(OBJEXT): {$(VPATH)}dmyext.c
enum.$(OBJEXT): {$(VPATH)}enum.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}node.h {$(VPATH)}util.h
-enumerator.$(OBJEXT): {$(VPATH)}enumerator.c {$(VPATH)}ruby.h config.h \
- {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h
error.$(OBJEXT): {$(VPATH)}error.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}env.h {$(VPATH)}st.h
diff --git a/configure.in b/configure.in
index 5633bc3c44..fc64335a06 100644
--- a/configure.in
+++ b/configure.in
@@ -44,20 +44,10 @@ fi
GNU_LD=$rb_cv_prog_gnu_ld
AC_SUBST(GNU_LD)])
-unset GREP_OPTIONS
rb_version=`grep RUBY_VERSION $srcdir/version.h`
MAJOR=`expr "$rb_version" : '#define RUBY_VERSION "\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*"'`
MINOR=`expr "$rb_version" : '#define RUBY_VERSION "[0-9][0-9]*\.\([0-9][0-9]*\)\.[0-9][0-9]*"'`
TEENY=`expr "$rb_version" : '#define RUBY_VERSION "[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)"'`
-if test "$MAJOR" = ""; then
- AC_MSG_ERROR(could not determine MAJOR number from version.h)
-fi
-if test "$MINOR" = ""; then
- AC_MSG_ERROR(could not determine MINOR number from version.h)
-fi
-if test "$TEENY" = ""; then
- AC_MSG_ERROR(could not determine TEENY number from version.h)
-fi
AC_SUBST(MAJOR)
AC_SUBST(MINOR)
AC_SUBST(TEENY)
@@ -85,7 +75,6 @@ AC_CANONICAL_TARGET
target_os=`echo $target_os | sed 's/linux-gnu$/linux/;s/linux-gnu/linux-/'`
ac_install_sh='' # unusable for extension libraries.
-ifelse(currently,disabled, [
dnl checks for fat-binary
AC_ARG_ENABLE(fat-binary,
[ --enable-fat-binary=ARCHS
@@ -139,7 +128,6 @@ if test "$fat_binary" != no; then
done
AC_DEFINE(NEXT_FAT_BINARY)
fi
-], [fat_binary=no])
case $target_cpu in
i?86) frame_address=yes;;
@@ -246,12 +234,7 @@ else
fi
dnl check for large file stuff
-mv confdefs.h confdefs1.h
-: > confdefs.h
AC_SYS_LARGEFILE
-mv confdefs.h largefile.h
-mv confdefs1.h confdefs.h
-cat largefile.h >> confdefs.h
AC_CHECK_TYPES([long long, off_t])
@@ -382,35 +365,23 @@ case "$target_os" in
nextstep*) ;;
openstep*) ;;
rhapsody*) ;;
-darwin*) LIBS="-lobjc $LIBS"
- CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE"
- AC_TRY_CPP([#include <AvailabilityMacros.h>
- #if MAC_OS_X_VERSION_MAX_ALLOWED <= 1040
- #error pre OS X 10.4
- [!<===== pre OS X 10.4 =====>]
- #endif
- ],
- [
- test "x$target_cpu" = xpowerpc && ac_cv_header_ucontext_h=no
- ],
- [
- AC_DEFINE(BROKEN_SETREUID, 1)
- AC_DEFINE(BROKEN_SETREGID, 1)
- ])
- ;;
+darwin*) LIBS="-lobjc $LIBS";;
hpux*) LIBS="-lm $LIBS"
ac_cv_c_inline=no;;
human*) ac_cv_func_getpgrp_void=yes
ac_cv_func_setitimer=no
;;
beos*) ac_cv_func_link=no;;
-cygwin*) ;;
+cygwin*) rb_cv_have_daylight=no
+ ac_cv_var_tzname=no
+ ac_cv_func__setjmp=no
+ ac_cv_func_setitimer=no
+ ;;
mingw*) if test "$with_winsock2" = yes; then
LIBS="-lws2_32 $LIBS"
else
LIBS="-lwsock32 $LIBS"
fi
- LIBS="-lshell32 $LIBS"
ac_cv_header_a_out_h=no
ac_cv_header_pwd_h=no
ac_cv_header_utime_h=no
@@ -449,8 +420,6 @@ msdosdjgpp*) LIBS="-lm $LIBS"
ac_cv_func_setrlimit=no
;;
bsdi*) LIBS="-lm $LIBS"
- AC_DEFINE(BROKEN_SETREUID, 1)
- AC_DEFINE(BROKEN_SETREGID, 1)
ac_cv_sizeof_rlim_t=8;;
freebsd*) LIBS="-lm $LIBS"
AC_CACHE_CHECK([whether -lxpg4 has to be linked],
@@ -501,7 +470,6 @@ esac
AC_CHECK_LIB(crypt, crypt)
AC_CHECK_LIB(dl, dlopen) # Dynamic linking for SunOS/Solaris and SYSV
AC_CHECK_LIB(dld, shl_load) # Dynamic linking for HP-UX
-AC_CHECK_LIB(rt, clock_gettime) # GNU/Linux
case "$target_cpu" in
alpha*) case "$target_os"::"$GCC" in
@@ -560,90 +528,18 @@ esac
AC_FUNC_MEMCMP
AC_FUNC_FSEEKO
AC_CHECK_FUNCS(ftello)
-
-# http://sources.redhat.com/ml/libc-hacker/2005-08/msg00008.html
-# Debian GNU/Linux Etch's libc6.1 2.3.6.ds1-13etch5 has this problem.
-# Debian GNU/Linux Lenny's libc6.1 2.7-10 has no problem.
-AC_CACHE_CHECK(for broken erfc of glibc-2.3.6 on IA64, rb_broken_glibc_ia64_erfc,
- [AC_TRY_RUN([
-#include <math.h>
-int
-main()
-{
- erfc(10000.0);
- return 0;
-}
-],
- rb_broken_glibc_ia64_erfc=no,
- rb_broken_glibc_ia64_erfc=yes,
- rb_broken_glibc_ia64_erfc=no)])
-case $rb_broken_glibc_ia64_erfc in
- yes) ac_cv_func_erf=no;;
-esac
-
AC_REPLACE_FUNCS(dup2 memmove strcasecmp strncasecmp strerror strftime\
strchr strstr strtoul crypt flock vsnprintf\
isnan finite isinf hypot acosh erf)
AC_CHECK_FUNCS(fmod killpg wait4 waitpid syscall chroot fsync getcwd eaccess\
- truncate ftruncate chsize times utimes fcntl lockf lstat symlink link\
+ truncate chsize times utimes fcntl lockf lstat symlink link\
readlink setitimer setruid seteuid setreuid setresuid\
setproctitle setrgid setegid setregid setresgid issetugid pause\
lchown lchmod getpgrp setpgrp getpgid setpgid initgroups\
getgroups setgroups getpriority getrlimit setrlimit sysconf\
group_member dlopen sigprocmask\
- sigaction sigsetjmp _setjmp _longjmp setsid telldir seekdir fchmod\
- mktime timegm gettimeofday\
- cosh sinh tanh round setuid setgid setenv unsetenv)
-
-AC_CACHE_CHECK(for __builtin_setjmp, ac_cv_func___builtin_setjmp,
-[AC_TRY_LINK([@%:@include <setjmp.h>
- jmp_buf jb; void t(v) int v; {__builtin_longjmp(jb, v);}],
- [__builtin_setjmp(jb);],
- [ac_cv_func___builtin_setjmp=yes],
- [ac_cv_func___builtin_setjmp=no])
-])
-
-test x$ac_cv_func__longjmp = xno && ac_cv_func__setjmp=no
-
-AC_MSG_CHECKING(for setjmp type)
-AC_ARG_WITH(setjmp-type,
- [ --with-setjmp-type select setjmp type], [
- case $withval in
- __builtin_setjmp) setjmp_prefix=__builtin_;;
- _setjmp) setjmp_prefix=_;;
- sigsetjmp) setjmp_prefix=sig;;
- setjmp) setjmp_prefix=;;
- '') unset setjmp_prefix;;
- *) AC_MSG_ERROR(invalid setjmp type: $withval);;
- esac], [unset setjmp_prefix])
-if test ${setjmp_prefix+set}; then
- if test "${setjmp_prefix}" && eval test '$ac_cv_func_'${setjmp_prefix}setjmp = no; then
- AC_MSG_ERROR(${setjmp_prefix}setjmp is not available)
- fi
-elif test "$ac_cv_func___builtin_setjmp" = yes; then
- setjmp_prefix=__builtin_
-elif test "$ac_cv_func__setjmp" = yes; then
- setjmp_prefix=_
-elif test "$ac_cv_func_sigsetjmp" = yes; then
- case $target_os in
- solaris*|cygwin*)
- setjmp_prefix=;;
- *)
- setjmp_prefix=sig;;
- esac
-else
- setjmp_prefix=
-fi
-if test x$setjmp_prefix = xsig; then
- setjmp_sigmask=yes
-else
- unset setjmp_sigmask
-fi
-AC_MSG_RESULT(${setjmp_prefix}setjmp)
-AC_DEFINE_UNQUOTED([RUBY_SETJMP(env)], [${setjmp_prefix}setjmp(env${setjmp_sigmask+,0})])
-AC_DEFINE_UNQUOTED([RUBY_LONGJMP(env,val)], [${setjmp_prefix}longjmp(env,val)])
-AC_DEFINE_UNQUOTED(RUBY_JMP_BUF, ${setjmp_sigmask+${setjmp_prefix}}jmp_buf)
-
+ sigaction _setjmp setsid telldir seekdir fchmod mktime timegm\
+ cosh sinh tanh setuid setgid setenv unsetenv)
AC_ARG_ENABLE(setreuid,
[ --enable-setreuid use setreuid()/setregid() according to need even if obsolete.],
[use_setreuid=$enableval])
@@ -669,50 +565,6 @@ AC_CACHE_CHECK(for external int daylight, rb_cv_have_daylight,
if test "$rb_cv_have_daylight" = yes; then
AC_DEFINE(HAVE_DAYLIGHT)
fi
-AC_DEFUN([RUBY_CHECK_VARTYPE], [dnl
-AC_CACHE_CHECK([for external $1], rb_cv_var_$1,
- [rb_cv_var_$1=no
- AC_TRY_COMPILE([
-#ifndef _XOPEN_SOURCE
-#define _XOPEN_SOURCE 1
-#endif
-$2
-;
-const volatile void *volatile t;],
- [t = &(&$1)[0];],
- [for t in $3; do
- AC_TRY_COMPILE([
-#ifndef _XOPEN_SOURCE
-#define _XOPEN_SOURCE 1
-#endif
-$2
-;
-extern $t $1;
-const volatile void *volatile t;],
- [t = &(&$1)[0];],
- [rb_cv_var_$1=$t; break])
- done])])
-if test "[$rb_cv_var_]$1" != no; then
- AC_DEFINE([HAVE_VAR_]m4_toupper($1))
- AC_DEFINE_UNQUOTED([TYPEOF_VAR_]m4_toupper($1), $rb_cv_var_$1)
-fi])
-RUBY_CHECK_VARTYPE(timezone, [@%:@include <time.h>], [long int])
-RUBY_CHECK_VARTYPE(altzone, [@%:@include <time.h>], [long int])
-if test "$rb_cv_var_timezone" = no; then
- AC_CHECK_FUNCS(timezone)
- if test "$ac_cv_func_timezone" = yes; then
- AC_CACHE_CHECK([whether timezone requires zero arguments], rb_cv_func_timezone_void,
- [AC_TRY_COMPILE([@%:@include <time.h>],
- [(void)timezone(0, 0);],
- [rb_cv_func_timezone_void=no],
- [rb_cv_func_timezone_void=yes])]
- )
- if test $rb_cv_func_timezone_void = yes; then
- AC_DEFINE(TIMEZONE_VOID)
- fi
- fi
-fi
-
AC_CACHE_CHECK(for negative time_t for gmtime(3), rb_cv_negative_time_t,
[AC_TRY_RUN([
#include <time.h>
@@ -754,7 +606,6 @@ fi
if test "$ac_cv_func_sigprocmask" = yes && test "$ac_cv_func_sigaction" = yes; then
AC_DEFINE(POSIX_SIGNAL)
else
- AC_CHECK_FUNCS(sigsetmask)
AC_CACHE_CHECK(for BSD signal semantics, rb_cv_bsd_signal,
[AC_TRY_RUN([
#include <stdio.h>
@@ -777,7 +628,7 @@ main()
],
rb_cv_bsd_signal=yes,
rb_cv_bsd_signal=no,
- rb_cv_bsd_signal=$ac_cv_func_sigsetmask)])
+ rb_cv_bsd_signal=no)])
if test "$rb_cv_bsd_signal" = yes; then
AC_DEFINE(BSD_SIGNAL)
fi
@@ -1113,7 +964,7 @@ AC_SUBST(DLEXT2)dnl
AC_SUBST(LIBEXT)dnl
STATIC=
-: ${LIBPATHFLAG=' -L%s'}
+: ${LIBPATHFLAG=' -L"%s"'}
: ${PATHFLAG=''}
if test "$with_dln_a_out" != yes; then
@@ -1138,23 +989,11 @@ if test "$with_dln_a_out" != yes; then
esac
fi
-
- AC_ARG_ENABLE(rpath,
- [ --disable-rpath embed run path into extension libraries.],
- [enable_rpath=$enableval], [enable_rpath="$rb_cv_binary_elf"])
- if test "$enable_rpath" = yes; then
- LIBPATHFLAG=" -L%1\$-s"
- RPATHFLAG=" ${linker_flag}-R%1\$-s"
- fi
-
case "$target_os" in
hpux*) DLDFLAGS="$DLDFLAGS -E"
: ${LDSHARED='ld -b'}
XLDFLAGS="$XLDFLAGS -Wl,-E"
: ${LIBPATHENV=SHLIB_PATH}
- if test "$rb_cv_prog_gnu_ld" = no; then
- RPATHFLAG=' +b %1$-s'
- fi
rb_cv_dlopen=yes;;
solaris*) if test "$GCC" = yes; then
: ${LDSHARED='$(CC) -shared'}
@@ -1189,7 +1028,7 @@ if test "$with_dln_a_out" != yes; then
rb_cv_dlopen=yes ;;
interix*) : ${LDSHARED="$CC -shared"}
XLDFLAGS="$XLDFLAGS -Wl,-E"
- LIBPATHFLAG=" -L%1\$-s"
+ LIBPATHFLAG=" -L'%1\$-s'"
rb_cv_dlopen=yes ;;
freebsd*|dragonfly*) : ${LDSHARED="$CC -shared"}
if test "$rb_cv_binary_elf" = yes; then
@@ -1220,11 +1059,11 @@ if test "$with_dln_a_out" != yes; then
aix*) if test "$GCC" = yes; then
: ${LDSHARED='$(CC) -shared'}
else
- : ${LDSHARED='$(CC)'}
+ : ${LDSHARED='/usr/ccs/bin/ld'}
fi
- LDSHARED="$LDSHARED ${linker_flag}-G"
- DLDFLAGS='-eInit_$(TARGET)'
- XLDFLAGS="${linker_flag}-bE:ruby.imp ${linker_flag}-brtl"
+ DLDFLAGS="${linker_flag}-G"' -eInit_$(TARGET)'
+ LDFLAGS="${LDFLAGS} ${linker_flag}-brtl"
+ XLDFLAGS="${linker_flag}-bE:ruby.imp"
: ${ARCHFILE="ruby.imp"}
TRY_LINK='$(CC) $(LDFLAGS) -oconftest $(INCFLAGS) -I$(hdrdir) $(CPPFLAGS)'
TRY_LINK="$TRY_LINK"' $(CFLAGS) $(src) $(LIBPATH) $(LOCAL_LIBS) $(LIBS)'
@@ -1264,6 +1103,14 @@ if test "$with_dln_a_out" != yes; then
*) : ${LDSHARED='ld'} ;;
esac
AC_MSG_RESULT($rb_cv_dlopen)
+
+ AC_ARG_ENABLE(rpath,
+ [ --disable-rpath embed run path into extension libraries.],
+ [enable_rpath=$enableval], [enable_rpath="$rb_cv_binary_elf"])
+ if test "$enable_rpath" = yes; then
+ LIBPATHFLAG=" -L'%1\$-s'"
+ RPATHFLAG=" ${linker_flag}-R'%1\$-s'"
+ fi
fi
AC_SUBST(LINK_SO)
AC_SUBST(LIBPATHFLAG)
@@ -1350,7 +1197,7 @@ case "$target_os" in
human*)
AC_CHECK_LIB(signal, _harderr)
AC_CHECK_LIB(hmem, hmemset)
- AC_CHECK_FUNCS(select)
+ AC_CHECK_FUNCS(select gettimeofday)
AC_CACHE_CHECK(whether PD libc _dtos18 fail to convert big number,
rb_cv_missing__dtos18,
[AC_TRY_RUN(
@@ -1423,10 +1270,9 @@ if test x"$cross_compiling" = xyes; then
PREP=fake.rb
RUNRUBY='$(MINIRUBY) -I`cd $(srcdir)/lib; pwd`'
else
- MINIRUBY='./miniruby$(EXEEXT) -I$(srcdir)/lib'
- MINIRUBY="$MINIRUBY"' -I$(EXTOUT)/common -I./- -r$(srcdir)/ext/purelib.rb'
+ MINIRUBY='./miniruby$(EXEEXT)'
PREP='miniruby$(EXEEXT)'
- RUNRUBY='$(MINIRUBY) $(srcdir)/runruby.rb --extout=$(EXTOUT)'
+ RUNRUBY='$(MINIRUBY) $(srcdir)/runruby.rb --extout=$(EXTOUT) --'
fi
AC_SUBST(MINIRUBY)
AC_SUBST(PREP)
@@ -1513,7 +1359,7 @@ if test "$enable_shared" = 'yes'; then
LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).sl.$(MAJOR).$(MINOR) lib$(RUBY_SO_NAME).sl'
;;
aix*)
- LIBRUBY_DLDFLAGS="${linker_flag}-bnoentry $XLDFLAGS"
+ LIBRUBY_DLDFLAGS="${linker_flag}-G ${linker_flag}-bnoentry $XLDFLAGS"
LIBRUBYARG_SHARED='-L${libdir} -l${RUBY_SO_NAME}'
SOLIBS='-lm -lc'
;;
@@ -1615,6 +1461,7 @@ case "$target_os" in
LIBRUBY_SO='cyg$(RUBY_SO_NAME)'${MAJOR}${MINOR}.dll
LIBRUBY='lib$(RUBY_SO_NAME).dll.a'
fi
+ AC_LIBOBJ([strftime])
;;
mingw*)
RUBY_SO_NAME=${rb_cv_msvcrt}-'$(RUBY_INSTALL_NAME)'${MAJOR}${MINOR}
@@ -1656,13 +1503,6 @@ case "$build_os" in
*msdosdjgpp*) FIRSTMAKEFILE=GNUmakefile:djgpp/GNUmakefile.in;;
esac
-CPPFLAGS="$CPPFLAGS "'$(DEFS)'
-test -z "$CFLAGS" || CFLAGS="$CFLAGS "; CFLAGS="$CFLAGS"'${cflags}'
-test -z "$CPPFLAGS" || CPPFLAGS="$CPPFLAGS "; CPPFLAGS="$CPPFLAGS"'${cppflags}'
-AC_SUBST(cppflags, [])dnl
-AC_SUBST(cflags, ['${optflags} ${debugflags}'])dnl
-AC_SUBST(optflags)dnl
-AC_SUBST(debugflags)dnl
AC_SUBST(XCFLAGS)dnl
AC_SUBST(XLDFLAGS)dnl
AC_SUBST(LIBRUBY_LDSHARED)
@@ -1707,53 +1547,37 @@ case "$target_os" in
rubyw_install_name="$RUBYW_INSTALL_NAME"
;;
esac
-RUBY_LIB_PREFIX=`eval echo \\"${libdir}/ruby\\"`
-
-AC_ARG_WITH(sitedir,
- [ --with-sitedir=DIR site libraries in DIR [[LIBDIR/ruby/site_ruby]]],
- [sitedir=$withval],
- [sitedir='${libdir}/ruby/site_ruby'])
-SITE_DIR=`eval echo \\"${sitedir}\\"`
-
case "$target_os" in
cygwin*|mingw*|*djgpp*|os2-emx*)
- RUBY_LIB_PREFIX="`eval echo "$RUBY_LIB_PREFIX" | sed 's|^NONE/|/|;s|^'"$prefix"'/|/|'`"
- RUBY_SITE_LIB_PATH="`eval echo "$SITE_DIR" | sed 's|^NONE/|/|;s|^'"$prefix"'/|/|'`"
+ RUBY_LIB_PREFIX="/lib/ruby"
;;
*)
- RUBY_LIB_PREFIX="`eval echo \\"$RUBY_LIB_PREFIX\\" | sed 's|^NONE/|'"$prefix"'/|'`"
- RUBY_SITE_LIB_PATH="`eval echo \\"$SITE_DIR\\" | sed 's|^NONE/|'"$prefix"'/|'`"
+ RUBY_LIB_PREFIX="${prefix}/lib/ruby"
;;
esac
RUBY_LIB_PATH="${RUBY_LIB_PREFIX}/${MAJOR}.${MINOR}"
-RUBY_SITE_LIB_PATH2="${RUBY_SITE_LIB_PATH}/${MAJOR}.${MINOR}"
-AC_DEFINE_UNQUOTED(RUBY_LIB, "${RUBY_LIB_PATH}")
-AC_DEFINE_UNQUOTED(RUBY_SITE_LIB, "${RUBY_SITE_LIB_PATH}")
-AC_DEFINE_UNQUOTED(RUBY_SITE_LIB2, "${RUBY_SITE_LIB_PATH2}")
-
-AC_ARG_WITH(vendordir,
- [ --with-vendordir=DIR vendor libraries in DIR [[LIBDIR/ruby/vendor_ruby]]],
- [vendordir=$withval],
- [vendordir='${libdir}/ruby/vendor_ruby'])
-VENDOR_DIR=`eval echo \\"${vendordir}\\"`
+AC_ARG_WITH(sitedir,
+ [ --with-sitedir=DIR site libraries in DIR [PREFIX/lib/ruby/site_ruby]],
+ [sitedir=$withval],
+ [sitedir='${prefix}/lib/ruby/site_ruby'])
+SITE_DIR=`eval echo \\"${sitedir}\\"`
case "$target_os" in
cygwin*|mingw*|*djgpp*|os2-emx*)
- RUBY_VENDOR_LIB_PATH="`eval echo "$VENDOR_DIR" | sed 's|^NONE/|/|;s|^'"$prefix"'/|/|'`"
- ;;
+ RUBY_SITE_LIB_PATH="`expr "$SITE_DIR" : "$prefix\(/.*\)"`" ||
+ RUBY_SITE_LIB_PATH="$SITE_DIR";;
*)
- RUBY_VENDOR_LIB_PATH="`eval echo \\"$VENDOR_DIR\\" | sed 's|^NONE/|'"$prefix"'/|'`"
- ;;
+ RUBY_SITE_LIB_PATH="$SITE_DIR";;
esac
-RUBY_VENDOR_LIB_PATH2="${RUBY_VENDOR_LIB_PATH}/${MAJOR}.${MINOR}"
+RUBY_SITE_LIB_PATH2="${RUBY_SITE_LIB_PATH}/${MAJOR}.${MINOR}"
-AC_DEFINE_UNQUOTED(RUBY_VENDOR_LIB, "${RUBY_VENDOR_LIB_PATH}")
-AC_DEFINE_UNQUOTED(RUBY_VENDOR_LIB2, "${RUBY_VENDOR_LIB_PATH2}")
+AC_DEFINE_UNQUOTED(RUBY_LIB, "${RUBY_LIB_PATH}")
+AC_DEFINE_UNQUOTED(RUBY_SITE_LIB, "${RUBY_SITE_LIB_PATH}")
+AC_DEFINE_UNQUOTED(RUBY_SITE_LIB2, "${RUBY_SITE_LIB_PATH2}")
AC_SUBST(arch)dnl
AC_SUBST(sitearch)dnl
AC_SUBST(sitedir)dnl
-AC_SUBST(vendordir)dnl
configure_args=$ac_configure_args
AC_SUBST(configure_args)dnl
@@ -1766,8 +1590,6 @@ if test "$fat_binary" != no ; then
AC_DEFINE_UNQUOTED(RUBY_SITE_THIN_ARCHLIB,
"${RUBY_SITE_LIB_PATH}/" __ARCHITECTURE__ "-${target_os}")
- AC_DEFINE_UNQUOTED(RUBY_VENDOR_THIN_ARCHLIB,
- "${RUBY_VENDOR_LIB_PATH}/" __ARCHITECTURE__ "-${target_os}")
AC_DEFINE_UNQUOTED(RUBY_PLATFORM, __ARCHITECTURE__ "-${target_os}")
else
arch="${target_cpu}-${target_os}"
@@ -1775,13 +1597,12 @@ else
fi
case "$target_os" in
- mingw*) sitearch="$target_cpu-$rb_cv_msvcrt" ;;
+ mingw*) sitearch="i386-$rb_cv_msvcrt" ;;
*) sitearch="${arch}" ;;
esac
AC_DEFINE_UNQUOTED(RUBY_ARCHLIB, "${RUBY_LIB_PATH}/${arch}")
AC_DEFINE_UNQUOTED(RUBY_SITE_ARCHLIB, "${RUBY_SITE_LIB_PATH2}/${sitearch}")
-AC_DEFINE_UNQUOTED(RUBY_VENDOR_ARCHLIB, "${RUBY_VENDOR_LIB_PATH2}/${sitearch}")
AC_ARG_WITH(search-path,
[ --with-search-path=DIR specify the additional search path],
@@ -1818,8 +1639,7 @@ else
echo "creating config.h"
tr -d '\015' < confdefs.h > config.h
fi
-tr -d '\015' < largefile.h > confdefs.h
-rm largefile.h
+: > confdefs.h
AC_CONFIG_FILES($FIRSTMAKEFILE)
AC_CONFIG_FILES(Makefile, [{
diff --git a/defines.h b/defines.h
index f39097fea4..6b1fd68740 100644
--- a/defines.h
+++ b/defines.h
@@ -102,16 +102,6 @@ void xfree _((void*));
#endif
#endif
-#if defined(__NeXT__) || defined(__APPLE__)
-/* Do not trust WORDS_BIGENDIAN from configure since -arch compiler flag may
- result in a different endian. Instead trust __BIG_ENDIAN__ and
- __LITTLE_ENDIAN__ which are set correctly by -arch. */
-#undef WORDS_BIGENDIAN
-#ifdef __BIG_ENDIAN__
-#define WORDS_BIGENDIAN
-#endif
-#endif
-
#ifdef __NeXT__
/* NextStep, OpenStep, Rhapsody */
#ifndef S_IRUSR
@@ -165,6 +155,13 @@ void xfree _((void*));
#ifndef S_ISREG
#define S_ISREG(mode) (((mode) & (0170000)) == (0100000))
#endif
+/* Do not trust WORDS_BIGENDIAN from configure since -arch compiler flag may
+ result in a different endian. Instead trust __BIG_ENDIAN__ and
+ __LITTLE_ENDIAN__ which are set correctly by -arch. */
+#undef WORDS_BIGENDIAN
+#ifdef __BIG_ENDIAN__
+#define WORDS_BIGENDIAN
+#endif
#ifndef __APPLE__
/* NextStep, OpenStep (but not Rhapsody) */
#ifndef GETPGRP_VOID
@@ -254,14 +251,6 @@ void rb_ia64_flushrs(void);
#define ENV_IGNORECASE
#endif
-#ifndef CASEFOLD_FILESYSTEM
-# if defined DOSISH || defined __VMS
-# define CASEFOLD_FILESYSTEM 1
-# else
-# define CASEFOLD_FILESYSTEM 0
-# endif
-#endif
-
#ifndef DLEXT_MAXLEN
#define DLEXT_MAXLEN 4
#endif
diff --git a/dir.c b/dir.c
index c2c3f9452f..0dd12ffd7d 100644
--- a/dir.c
+++ b/dir.c
@@ -268,7 +268,7 @@ fnmatch_helper(pcur, scur, flags)
const char *t;
if (ISEND(s))
RETURN(FNM_NOMATCH);
- if ((t = bracket(p + 1, s, flags)) != 0) {
+ if (t = bracket(p + 1, s, flags)) {
p = t;
Inc(s);
continue;
@@ -473,9 +473,9 @@ dir_inspect(dir)
{
struct dir_data *dirp;
- Data_Get_Struct(dir, struct dir_data, dirp);
+ GetDIR(dir, dirp);
if (dirp->path) {
- const char *c = rb_obj_classname(dir);
+ char *c = rb_obj_classname(dir);
int len = strlen(c) + strlen(dirp->path) + 4;
VALUE s = rb_str_new(0, len);
snprintf(RSTRING_PTR(s), len+1, "#<%s:%s>", c, dirp->path);
@@ -499,7 +499,7 @@ dir_path(dir)
{
struct dir_data *dirp;
- Data_Get_Struct(dir, struct dir_data, dirp);
+ GetDIR(dir, dirp);
if (!dirp->path) return Qnil;
return rb_str_new2(dirp->path);
}
@@ -562,7 +562,6 @@ dir_each(dir)
struct dir_data *dirp;
struct dirent *dp;
- RETURN_ENUMERATOR(dir, 0, 0);
GetDIR(dir, dirp);
rewinddir(dirp->dir);
for (dp = readdir(dirp->dir); dp != NULL; dp = readdir(dirp->dir)) {
@@ -1009,7 +1008,7 @@ has_magic(s, flags)
register const char *p = s;
register char c;
- while ((c = *p++) != 0) {
+ while (c = *p++) {
switch (c) {
case '*':
case '?':
@@ -1042,7 +1041,7 @@ find_dirsep(const char *s, int flags)
register char c;
int open = 0;
- while ((c = *p++) != 0) {
+ while (c = *p++) {
switch (c) {
case '[':
open = 1;
@@ -1815,7 +1814,6 @@ dir_foreach(io, dirname)
{
VALUE dir;
- RETURN_ENUMERATOR(io, 1, &dirname);
dir = dir_open_dir(dirname);
rb_ensure(dir_each, dir, dir_close, dir);
return Qnil;
@@ -1972,7 +1970,6 @@ Init_Dir()
rb_define_method(rb_cDir,"initialize", dir_initialize, 1);
rb_define_method(rb_cDir,"path", dir_path, 0);
- rb_define_method(rb_cDir,"inspect", dir_inspect, 0);
rb_define_method(rb_cDir,"read", dir_read, 0);
rb_define_method(rb_cDir,"each", dir_each, 0);
rb_define_method(rb_cDir,"rewind", dir_rewind, 0);
diff --git a/dln.c b/dln.c
index 5ba25b6415..9fd605e32e 100644
--- a/dln.c
+++ b/dln.c
@@ -81,28 +81,19 @@ char *getenv();
# include "macruby_private.h"
#endif
-#if defined(__APPLE__) && defined(__MACH__) /* Mac OS X */
-# if defined(HAVE_DLOPEN)
- /* Mac OS X with dlopen (10.3 or later) */
-# define MACOSX_DLOPEN
-# else
-# define MACOSX_DYLD
-# endif
-#endif
-
#ifdef __BEOS__
# include <image.h>
#endif
#ifndef NO_DLN_LOAD
-#if defined(HAVE_DLOPEN) && !defined(USE_DLN_A_OUT) && !defined(_AIX) && !defined(MACOSX_DYLD) && !defined(_UNICOSMP)
+#if defined(HAVE_DLOPEN) && !defined(USE_DLN_A_OUT) && !defined(_AIX) && !defined(__APPLE__) && !defined(_UNICOSMP)
/* dynamic load with dlopen() */
# define USE_DLN_DLOPEN
#endif
#ifndef FUNCNAME_PATTERN
-# if defined(__hp9000s300) || (defined(__NetBSD__) && !defined(__ELF__)) || defined(__BORLANDC__) || (defined(__FreeBSD__) && !defined(__ELF__)) || (defined(__OpenBSD__) && !defined(__ELF__)) || defined(NeXT) || defined(__WATCOMC__) || defined(MACOSX_DYLD)
+# if defined(__hp9000s300) || (defined(__NetBSD__) && !defined(__ELF__)) || defined(__BORLANDC__) || (defined(__FreeBSD__) && !defined(__ELF__)) || (defined(__OpenBSD__) && !defined(__ELF__)) || defined(NeXT) || defined(__WATCOMC__) || defined(__APPLE__)
# define FUNCNAME_PATTERN "_Init_%s"
# else
# define FUNCNAME_PATTERN "Init_%s"
@@ -645,7 +636,7 @@ load_1(fd, disp, need_init)
long disp;
const char *need_init;
{
- static const char *libc = LIBC_NAME;
+ static char *libc = LIBC_NAME;
struct exec hdr;
struct relocation_info *reloc = NULL;
long block = 0;
@@ -1150,7 +1141,7 @@ dln_sym(name)
#endif
#endif
#else
-#ifdef MACOSX_DYLD
+#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif
#endif
@@ -1412,7 +1403,7 @@ dln_load(file)
}
#endif /* _AIX */
-#if defined(NeXT) || defined(MACOSX_DYLD)
+#if defined(NeXT) || defined(__APPLE__)
#define DLN_DEFINED
/*----------------------------------------------------
By SHIROYAMA Takayuki Psi@fortune.nest.or.jp
@@ -1536,7 +1527,7 @@ dln_load(file)
}
#endif /* __BEOS__*/
-#ifdef __MACOS__ /* Mac OS 9 or before */
+#ifdef __MACOS__
# define DLN_DEFINED
{
OSErr err;
@@ -1689,31 +1680,31 @@ static char fbuf[MAXPATHLEN];
static char *
dln_find_1(fname, path, exe_flag)
- const char *fname;
- const char *path;
+ char *fname;
+ char *path;
int exe_flag; /* non 0 if looking for executable. */
{
- register const char *dp;
- register const char *ep;
+ register char *dp;
+ register char *ep;
register char *bp;
struct stat st;
#ifdef __MACOS__
const char* mac_fullpath;
#endif
- if (!fname) return (char *)fname;
- if (fname[0] == '/') return (char *)fname;
+ if (!fname) return fname;
+ if (fname[0] == '/') return fname;
if (strncmp("./", fname, 2) == 0 || strncmp("../", fname, 3) == 0)
- return (char *)fname;
- if (exe_flag && strchr(fname, '/')) return (char *)fname;
+ return fname;
+ if (exe_flag && strchr(fname, '/')) return fname;
#ifdef DOSISH
- if (fname[0] == '\\') return (char *)fname;
+ if (fname[0] == '\\') return fname;
# ifdef DOSISH_DRIVE_LETTER
- if (strlen(fname) > 2 && fname[1] == ':') return (char *)fname;
+ if (strlen(fname) > 2 && fname[1] == ':') return fname;
# endif
if (strncmp(".\\", fname, 2) == 0 || strncmp("..\\", fname, 3) == 0)
- return (char *)fname;
- if (exe_flag && strchr(fname, '\\')) return (char *)fname;
+ return fname;
+ if (exe_flag && strchr(fname, '\\')) return fname;
#endif
for (dp = path;; dp = ++ep) {
@@ -1781,9 +1772,26 @@ dln_find_1(fname, path, exe_flag)
}
memcpy(bp, fname, i + 1);
+#ifndef __MACOS__
+ if (stat(fbuf, &st) == 0) {
+ if (exe_flag == 0) return fbuf;
+ /* looking for executable */
+ if (!S_ISDIR(st.st_mode) && eaccess(fbuf, X_OK) == 0)
+ return fbuf;
+ }
+#else
+ if (mac_fullpath = _macruby_exist_file_in_libdir_as_posix_name(fbuf)) {
+ if (exe_flag == 0) return mac_fullpath;
+ /* looking for executable */
+ if (stat(mac_fullpath, &st) == 0) {
+ if (!S_ISDIR(st.st_mode) && eaccess(mac_fullpath, X_OK) == 0)
+ return mac_fullpath;
+ }
+ }
+#endif
#if defined(DOSISH)
if (exe_flag) {
- static const char extension[][5] = {
+ static const char *extension[] = {
#if defined(MSDOS)
".com", ".exe", ".bat",
#if defined(DJGPP)
@@ -1796,10 +1804,11 @@ dln_find_1(fname, path, exe_flag)
".r", ".R", ".x", ".X", ".bat", ".BAT",
/* __human68k__ */
#endif
+ (char *) NULL
};
int j;
- for (j = 0; j < sizeof(extension) / sizeof(extension[0]); j++) {
+ for (j = 0; extension[j]; j++) {
if (fspace < strlen(extension[j])) {
fprintf(stderr, "openpath: pathname too long (ignored)\n");
fprintf(stderr, "\tDirectory \"%.*s\"\n", (int) (bp - fbuf), fbuf);
@@ -1816,28 +1825,9 @@ dln_find_1(fname, path, exe_flag)
#endif
}
- goto next;
}
#endif /* MSDOS or _WIN32 or __human68k__ or __EMX__ */
-#ifndef __MACOS__
- if (stat(fbuf, &st) == 0) {
- if (exe_flag == 0) return fbuf;
- /* looking for executable */
- if (!S_ISDIR(st.st_mode) && eaccess(fbuf, X_OK) == 0)
- return fbuf;
- }
-#else
- if (mac_fullpath = _macruby_exist_file_in_libdir_as_posix_name(fbuf)) {
- if (exe_flag == 0) return mac_fullpath;
- /* looking for executable */
- if (stat(mac_fullpath, &st) == 0) {
- if (!S_ISDIR(st.st_mode) && eaccess(mac_fullpath, X_OK) == 0)
- return mac_fullpath;
- }
- }
-#endif
-
next:
/* if not, and no other alternatives, life is bleak */
if (*ep == '\0') {
diff --git a/enum.c b/enum.c
index df35c2fe03..2a29272ae9 100644
--- a/enum.c
+++ b/enum.c
@@ -15,43 +15,7 @@
#include "util.h"
VALUE rb_mEnumerable;
-static ID id_each, id_eqq, id_cmp, id_size;
-
-struct iter_method_arg {
- VALUE obj;
- ID mid;
- int argc;
- VALUE *argv;
-};
-
-static VALUE iterate_method _((VALUE obj));
-static VALUE
-iterate_method(obj)
- VALUE obj;
-{
- struct iter_method_arg *arg;
-
- arg = (struct iter_method_arg *)obj;
- return rb_funcall2(arg->obj, arg->mid, arg->argc, arg->argv);
-}
-
-VALUE
-rb_block_call(obj, mid, argc, argv, bl_proc, data2)
- VALUE obj;
- ID mid;
- int argc;
- VALUE *argv;
- VALUE (*bl_proc) (ANYARGS);
- VALUE data2;
-{
- struct iter_method_arg arg;
-
- arg.obj = obj;
- arg.mid = mid;
- arg.argc = argc;
- arg.argv = argv;
- return rb_iterate(iterate_method, (VALUE)&arg, bl_proc, data2);
-}
+static ID id_each, id_eqq, id_cmp;
VALUE
rb_each(obj)
@@ -84,18 +48,18 @@ grep_iter_i(i, arg)
* call-seq:
* enum.grep(pattern) => array
* enum.grep(pattern) {| obj | block } => array
- *
+ *
* Returns an array of every element in <i>enum</i> for which
* <code>Pattern === element</code>. If the optional <em>block</em> is
* supplied, each matching element is passed to it, and the block's
* result is stored in the output array.
- *
+ *
* (1..100).grep 38..44 #=> [38, 39, 40, 41, 42, 43, 44]
* c = IO.constants
* c.grep(/SEEK/) #=> ["SEEK_END", "SEEK_SET", "SEEK_CUR"]
* res = c.grep(/SEEK/) {|v| IO.const_get(v) }
* res #=> [2, 0, 1]
- *
+ *
*/
static VALUE
@@ -109,99 +73,10 @@ enum_grep(obj, pat)
arg[1] = ary;
rb_iterate(rb_each, obj, rb_block_given_p() ? grep_iter_i : grep_i, (VALUE)arg);
-
+
return ary;
}
-static VALUE count_i _((VALUE, VALUE));
-static VALUE
-count_i(i, memop)
- VALUE i, memop;
-{
- VALUE *memo = (VALUE*)memop;
-
- if (rb_equal(i, memo[1])) {
- memo[0]++;
- }
- return Qnil;
-}
-
-static VALUE count_iter_i _((VALUE, VALUE));
-static VALUE
-count_iter_i(i, memop)
- VALUE i, memop;
-{
- VALUE *memo = (VALUE*)memop;
-
- if (RTEST(rb_yield(i))) {
- memo[0]++;
- }
- return Qnil;
-}
-
-static VALUE count_all_i _((VALUE, VALUE));
-static VALUE
-count_all_i(i, memop)
- VALUE i, memop;
-{
- VALUE *memo = (VALUE*)memop;
-
- memo[0]++;
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.count => int
- * enum.count(item) => int
- * enum.count {| obj | block } => int
- *
- * Returns the number of items in <i>enum</i>, where #size is called
- * if it responds to it, otherwise the items are counted through
- * enumeration. If an argument is given, counts the number of items
- * in <i>enum</i>, for which equals to <i>item</i>. If a block is
- * given, counts the number of elements yielding a true value.
- *
- * ary = [1, 2, 4, 2]
- * ary.count # => 4
- * ary.count(2) # => 2
- * ary.count{|x|x%2==0} # => 3
- *
- */
-
-static VALUE
-enum_count(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
-{
- VALUE memo[2]; /* [count, condition value] */
- rb_block_call_func *func;
-
- if (argc == 0) {
- if (rb_block_given_p()) {
- func = count_iter_i;
- }
- else {
- if (rb_respond_to(obj, id_size)) {
- return rb_funcall(obj, id_size, 0, 0);
- }
- func = count_all_i;
- }
- }
- else {
- rb_scan_args(argc, argv, "1", &memo[1]);
- if (rb_block_given_p()) {
- rb_warn("given block not used");
- }
- func = count_i;
- }
-
- memo[0] = 0;
- rb_block_call(obj, id_each, 0, 0, func, (VALUE)&memo);
- return INT2NUM(memo[0]);
-}
-
static VALUE
find_i(i, memo)
VALUE i;
@@ -218,15 +93,15 @@ find_i(i, memo)
* call-seq:
* enum.detect(ifnone = nil) {| obj | block } => obj or nil
* enum.find(ifnone = nil) {| obj | block } => obj or nil
- *
+ *
* Passes each entry in <i>enum</i> to <em>block</em>. Returns the
* first for which <em>block</em> is not <code>false</code>. If no
* object matches, calls <i>ifnone</i> and returns its result when it
* is specified, or returns <code>nil</code>
- *
+ *
* (1..10).detect {|i| i % 5 == 0 and i % 7 == 0 } #=> nil
* (1..100).detect {|i| i % 5 == 0 and i % 7 == 0 } #=> 35
- *
+ *
*/
static VALUE
@@ -239,7 +114,6 @@ enum_find(argc, argv, obj)
VALUE if_none;
rb_scan_args(argc, argv, "01", &if_none);
- RETURN_ENUMERATOR(obj, argc, argv);
rb_iterate(rb_each, obj, find_i, (VALUE)&memo);
if (memo != Qundef) {
return memo;
@@ -250,81 +124,6 @@ enum_find(argc, argv, obj)
return Qnil;
}
-static VALUE find_index_i _((VALUE, VALUE));
-static VALUE
-find_index_i(i, memop)
- VALUE i;
- VALUE memop;
-{
- VALUE *memo = (VALUE*)memop;
-
- if (rb_equal(i, memo[2])) {
- memo[0] = UINT2NUM(memo[1]);
- rb_iter_break();
- }
- memo[1]++;
- return Qnil;
-}
-
-static VALUE find_index_iter_i _((VALUE, VALUE));
-static VALUE
-find_index_iter_i(i, memop)
- VALUE i;
- VALUE memop;
-{
- VALUE *memo = (VALUE*)memop;
-
- if (RTEST(rb_yield(i))) {
- memo[0] = UINT2NUM(memo[1]);
- rb_iter_break();
- }
- memo[1]++;
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.find_index(value) => int or nil
- * enum.find_index {| obj | block } => int or nil
- *
- * Compares each entry in <i>enum</i> with <em>value</em> or passes
- * to <em>block</em>. Returns the index for the first for which the
- * evaluated value is non-false. If no object matches, returns
- * <code>nil</code>
- *
- * (1..10).find_index {|i| i % 5 == 0 and i % 7 == 0 } #=> nil
- * (1..100).find_index {|i| i % 5 == 0 and i % 7 == 0 } #=> 34
- * (1..100).find_index(50) #=> 49
- *
- */
-
-static VALUE
-enum_find_index(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
-{
- VALUE memo[3]; /* [return value, current index, condition value] */
- rb_block_call_func *func;
-
- if (argc == 0) {
- RETURN_ENUMERATOR(obj, 0, 0);
- func = find_index_iter_i;
- }
- else {
- rb_scan_args(argc, argv, "1", &memo[2]);
- if (rb_block_given_p()) {
- rb_warn("given block not used");
- }
- func = find_index_i;
- }
-
- memo[0] = Qnil;
- memo[1] = 0;
- rb_block_call(obj, id_each, 0, 0, func, (VALUE)memo);
- return memo[0];
-}
-
static VALUE
find_all_i(i, ary)
VALUE i, ary;
@@ -339,13 +138,13 @@ find_all_i(i, ary)
* call-seq:
* enum.find_all {| obj | block } => array
* enum.select {| obj | block } => array
- *
+ *
* Returns an array containing all elements of <i>enum</i> for which
* <em>block</em> is not <code>false</code> (see also
* <code>Enumerable#reject</code>).
- *
+ *
* (1..10).find_all {|i| i % 3 == 0 } #=> [3, 6, 9]
- *
+ *
*/
static VALUE
@@ -353,8 +152,7 @@ enum_find_all(obj)
VALUE obj;
{
VALUE ary = rb_ary_new();
-
- RETURN_ENUMERATOR(obj, 0, 0);
+
rb_iterate(rb_each, obj, find_all_i, ary);
return ary;
@@ -373,12 +171,12 @@ reject_i(i, ary)
/*
* call-seq:
* enum.reject {| obj | block } => array
- *
+ *
* Returns an array for all elements of <i>enum</i> for which
* <em>block</em> is false (see also <code>Enumerable#find_all</code>).
- *
+ *
* (1..10).reject {|i| i % 3 == 0 } #=> [1, 2, 4, 5, 7, 8, 10]
- *
+ *
*/
static VALUE
@@ -386,8 +184,7 @@ enum_reject(obj)
VALUE obj;
{
VALUE ary = rb_ary_new();
-
- RETURN_ENUMERATOR(obj, 0, 0);
+
rb_iterate(rb_each, obj, reject_i, ary);
return ary;
@@ -415,13 +212,13 @@ collect_all(i, ary)
* call-seq:
* enum.collect {| obj | block } => array
* enum.map {| obj | block } => array
- *
+ *
* Returns a new array with the results of running <em>block</em> once
* for every element in <i>enum</i>.
- *
+ *
* (1..4).collect {|i| i*i } #=> [1, 4, 9, 16]
* (1..4).collect { "cat" } #=> ["cat", "cat", "cat", "cat"]
- *
+ *
*/
static VALUE
@@ -439,135 +236,80 @@ enum_collect(obj)
* call-seq:
* enum.to_a => array
* enum.entries => array
- *
+ *
* Returns an array containing the items in <i>enum</i>.
- *
+ *
* (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7]
* { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]]
*/
static VALUE
-enum_to_a(argc, argv, obj)
- int argc;
- VALUE *argv;
+enum_to_a(obj)
VALUE obj;
{
VALUE ary = rb_ary_new();
- rb_block_call(obj, id_each, argc, argv, collect_all, ary);
+ rb_iterate(rb_each, obj, collect_all, ary);
return ary;
}
-static VALUE inject_i _((VALUE, VALUE));
-static VALUE
-inject_i(i, p)
- VALUE i;
- VALUE p;
-{
- VALUE *memo = (VALUE *)p;
- if (memo[0] == Qundef) {
- memo[0] = i;
- }
- else {
- memo[0] = rb_yield_values(2, memo[0], i);
- }
- return Qnil;
-}
-
-static VALUE inject_op_i _((VALUE, VALUE));
static VALUE
-inject_op_i(i, p)
+inject_i(i, memo)
VALUE i;
- VALUE p;
+ VALUE *memo;
{
- VALUE *memo = (VALUE *)p;
-
- if (memo[0] == Qundef) {
- memo[0] = i;
+ if (*memo == Qundef) {
+ *memo = i;
}
else {
- memo[0] = rb_funcall(memo[0], (ID)memo[1], 1, i);
+ *memo = rb_yield_values(2, *memo, i);
}
return Qnil;
}
/*
* call-seq:
- * enum.inject(initial, sym) => obj
- * enum.inject(sym) => obj
* enum.inject(initial) {| memo, obj | block } => obj
* enum.inject {| memo, obj | block } => obj
- *
- * enum.reduce(initial, sym) => obj
- * enum.reduce(sym) => obj
- * enum.reduce(initial) {| memo, obj | block } => obj
- * enum.reduce {| memo, obj | block } => obj
- *
- * Combines all elements of <i>enum</i> by applying a binary
- * operation, specified by a block or a symbol that names a
- * method or operator.
- *
- * If you specify a block, then for each element in <i>enum<i>
- * the block is passed an accumulator value (<i>memo</i>) and the element.
- * If you specify a symbol instead, then each element in the collection
- * will be passed to the named method of <i>memo</i>.
- * In either case, the result becomes the new value for <i>memo</i>.
- * At the end of the iteration, the final value of <i>memo</i> is the
- * return value fo the method.
- *
- * If you do not explicitly specify an <i>initial</i> value for <i>memo</i>,
- * then uses the first element of collection is used as the initial value
- * of <i>memo</i>.
- *
- * Examples:
- *
+ *
+ * Combines the elements of <i>enum</i> by applying the block to an
+ * accumulator value (<i>memo</i>) and each element in turn. At each
+ * step, <i>memo</i> is set to the value returned by the block. The
+ * first form lets you supply an initial value for <i>memo</i>. The
+ * second form uses the first element of the collection as a the
+ * initial value (and skips that element while iterating).
+ *
* # Sum some numbers
- * (5..10).reduce(:+) #=> 45
- * # Same using a block and inject
- * (5..10).inject {|sum, n| sum + n } #=> 45
+ * (5..10).inject {|sum, n| sum + n } #=> 45
* # Multiply some numbers
- * (5..10).reduce(1, :*) #=> 151200
- * # Same using a block
- * (5..10).inject(1) {|product, n| product * n } #=> 151200
+ * (5..10).inject(1) {|product, n| product * n } #=> 151200
+ *
* # find the longest word
* longest = %w{ cat sheep bear }.inject do |memo,word|
* memo.length > word.length ? memo : word
* end
- * longest #=> "sheep"
- *
+ * longest #=> "sheep"
+ *
+ * # find the length of the longest word
+ * longest = %w{ cat sheep bear }.inject(0) do |memo,word|
+ * memo >= word.length ? memo : word.length
+ * end
+ * longest #=> 5
+ *
*/
+
static VALUE
enum_inject(argc, argv, obj)
int argc;
- VALUE *argv;
- VALUE obj;
+ VALUE *argv, obj;
{
- VALUE memo[2];
- rb_block_call_func *iter = inject_i;
-
- switch (rb_scan_args(argc, argv, "02", &memo[0], &memo[1])) {
- case 0:
- memo[0] = Qundef;
- break;
- case 1:
- if (rb_block_given_p()) {
- break;
- }
- memo[1] = (VALUE)rb_to_id(memo[0]);
- memo[0] = Qundef;
- iter = inject_op_i;
- break;
- case 2:
- if (rb_block_given_p()) {
- rb_warning("given block not used");
- }
- memo[1] = (VALUE)rb_to_id(memo[1]);
- iter = inject_op_i;
- break;
- }
- rb_block_call(obj, id_each, 0, 0, iter, (VALUE)memo);
- if (memo[0] == Qundef) return Qnil;
- return memo[0];
+ VALUE memo = Qundef;
+
+ if (rb_scan_args(argc, argv, "01", &memo) == 0)
+ memo = Qundef;
+ rb_iterate(rb_each, obj, inject_i, (VALUE)&memo);
+ if (memo == Qundef) return Qnil;
+ return memo;
}
static VALUE
@@ -586,13 +328,13 @@ partition_i(i, ary)
/*
* call-seq:
* enum.partition {| obj | block } => [ true_array, false_array ]
- *
+ *
* Returns two arrays, the first containing the elements of
* <i>enum</i> for which the block evaluates to true, the second
* containing the rest.
- *
+ *
* (1..6).partition {|i| (i&1).zero?} #=> [[2, 4, 6], [1, 3, 5]]
- *
+ *
*/
static VALUE
@@ -601,8 +343,6 @@ enum_partition(obj)
{
VALUE ary[2];
- RETURN_ENUMERATOR(obj, 0, 0);
-
ary[0] = rb_ary_new();
ary[1] = rb_ary_new();
rb_iterate(rb_each, obj, partition_i, (VALUE)ary);
@@ -610,111 +350,11 @@ enum_partition(obj)
return rb_assoc_new(ary[0], ary[1]);
}
-static VALUE
-group_by_i(i, hash)
- VALUE i;
- VALUE hash;
-{
- VALUE group = rb_yield(i);
- VALUE values;
-
- values = rb_hash_aref(hash, group);
- if (NIL_P(values)) {
- values = rb_ary_new3(1, i);
- rb_hash_aset(hash, group, values);
- }
- else {
- rb_ary_push(values, i);
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.group_by {| obj | block } => a_hash
- *
- * Returns a hash, which keys are evaluated result from the
- * block, and values are arrays of elements in <i>enum</i>
- * corresponding to the key.
- *
- * (1..6).group_by {|i| i%3} #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]}
- *
- */
-
-static VALUE
-enum_group_by(obj)
- VALUE obj;
-{
- VALUE hash;
-
- RETURN_ENUMERATOR(obj, 0, 0);
-
- hash = rb_hash_new();
- rb_block_call(obj, id_each, 0, 0, group_by_i, hash);
-
- return hash;
-}
-
-static VALUE
-first_i(i, ary)
- VALUE i;
- VALUE *ary;
-{
- if (NIL_P(ary[0])) {
- ary[1] = i;
- rb_iter_break();
- }
- else {
- long n = NUM2LONG(ary[0]);
-
- if (n <= 0) {
- rb_iter_break();
- }
- rb_ary_push(ary[1], i);
- n--;
- ary[0] = INT2NUM(n);
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.first -> obj or nil
- * enum.first(n) -> an_array
- *
- * Returns the first element, or the first +n+ elements, of the enumerable.
- * If the enumerable is empty, the first form returns <code>nil</code>, and the
- * second form returns an empty array.
- *
- */
-
-static VALUE
-enum_first(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
-{
- VALUE n, ary[2];
-
- if (argc == 0) {
- ary[0] = ary[1] = Qnil;
- }
- else {
- rb_scan_args(argc, argv, "01", &n);
- ary[0] = n;
- ary[1] = rb_ary_new2(NUM2LONG(n));
- }
- rb_block_call(obj, id_each, 0, 0, first_i, (VALUE)ary);
-
- return ary[1];
-}
-
-
/*
* call-seq:
* enum.sort => array
* enum.sort {| a, b | block } => array
- *
+ *
* Returns an array containing the items in <i>enum</i> sorted,
* either according to their own <code><=></code> method, or by using
* the results of the supplied block. The block should return -1, 0, or
@@ -722,7 +362,7 @@ enum_first(argc, argv, obj)
* Ruby 1.8, the method <code>Enumerable#sort_by</code> implements a
* built-in Schwartzian Transform, useful when key computation or
* comparison is expensive..
- *
+ *
* %w(rhea kea flea).sort #=> ["flea", "kea", "rhea"]
* (1..10).sort {|a,b| b <=> a} #=> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
*/
@@ -731,7 +371,7 @@ static VALUE
enum_sort(obj)
VALUE obj;
{
- return rb_ary_sort(enum_to_a(0, 0, obj));
+ return rb_ary_sort(enum_to_a(obj));
}
static VALUE
@@ -751,70 +391,65 @@ sort_by_i(i, ary)
}
static int
-sort_by_cmp(aa, bb, data)
+sort_by_cmp(aa, bb)
NODE **aa, **bb;
- void *data;
{
VALUE a = aa[0]->u1.value;
VALUE b = bb[0]->u1.value;
- VALUE ary = (VALUE)data;
- if (RBASIC(ary)->klass) {
- rb_raise(rb_eRuntimeError, "sort_by reentered");
- }
return rb_cmpint(rb_funcall(a, id_cmp, 1, b), a, b);
}
/*
* call-seq:
* enum.sort_by {| obj | block } => array
- *
+ *
* Sorts <i>enum</i> using a set of keys generated by mapping the
* values in <i>enum</i> through the given block.
- *
+ *
* %w{ apple pear fig }.sort_by {|word| word.length}
#=> ["fig", "pear", "apple"]
- *
+ *
* The current implementation of <code>sort_by</code> generates an
* array of tuples containing the original collection element and the
* mapped value. This makes <code>sort_by</code> fairly expensive when
* the keysets are simple
- *
+ *
* require 'benchmark'
* include Benchmark
- *
+ *
* a = (1..100000).map {rand(100000)}
- *
+ *
* bm(10) do |b|
* b.report("Sort") { a.sort }
* b.report("Sort by") { a.sort_by {|a| a} }
* end
- *
+ *
* <em>produces:</em>
- *
+ *
* user system total real
* Sort 0.180000 0.000000 0.180000 ( 0.175469)
* Sort by 1.980000 0.040000 2.020000 ( 2.013586)
- *
+ *
* However, consider the case where comparing the keys is a non-trivial
* operation. The following code sorts some files on modification time
* using the basic <code>sort</code> method.
- *
+ *
* files = Dir["*"]
* sorted = files.sort {|a,b| File.new(a).mtime <=> File.new(b).mtime}
* sorted #=> ["mon", "tues", "wed", "thurs"]
- *
+ *
* This sort is inefficient: it generates two new <code>File</code>
* objects during every comparison. A slightly better technique is to
* use the <code>Kernel#test</code> method to generate the modification
* times directly.
- *
+ *
* files = Dir["*"]
* sorted = files.sort { |a,b|
* test(?M, a) <=> test(?M, b)
* }
* sorted #=> ["mon", "tues", "wed", "thurs"]
- *
+ *
* This still generates many unnecessary <code>Time</code> objects. A
* more efficient technique is to cache the sort keys (modification
* times in this case) before the sort. Perl users often call this
@@ -822,14 +457,14 @@ sort_by_cmp(aa, bb, data)
* construct a temporary array, where each element is an array
* containing our sort key along with the filename. We sort this array,
* and then extract the filename from the result.
- *
+ *
* sorted = Dir["*"].collect { |f|
* [test(?M, f), f]
* }.sort.collect { |f| f[1] }
* sorted #=> ["mon", "tues", "wed", "thurs"]
- *
+ *
* This is exactly what <code>sort_by</code> does internally.
- *
+ *
* sorted = Dir["*"].sort_by {|f| test(?M, f)}
* sorted #=> ["mon", "tues", "wed", "thurs"]
*/
@@ -841,8 +476,6 @@ enum_sort_by(obj)
VALUE ary;
long i;
- RETURN_ENUMERATOR(obj, 0, 0);
-
if (TYPE(obj) == T_ARRAY) {
ary = rb_ary_new2(RARRAY(obj)->len);
}
@@ -852,8 +485,7 @@ enum_sort_by(obj)
RBASIC(ary)->klass = 0;
rb_iterate(rb_each, obj, sort_by_i, ary);
if (RARRAY(ary)->len > 1) {
- qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE),
- sort_by_cmp, (void *)ary);
+ qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), sort_by_cmp, 0);
}
if (RBASIC(ary)->klass) {
rb_raise(rb_eRuntimeError, "sort_by reentered");
@@ -866,11 +498,11 @@ enum_sort_by(obj)
}
static VALUE
-all_i(i, memo)
+all_iter_i(i, memo)
VALUE i;
VALUE *memo;
{
- if (!RTEST(i)) {
+ if (!RTEST(rb_yield(i))) {
*memo = Qfalse;
rb_iter_break();
}
@@ -878,28 +510,32 @@ all_i(i, memo)
}
static VALUE
-all_iter_i(i, memo)
+all_i(i, memo)
VALUE i;
VALUE *memo;
{
- return all_i(rb_yield(i), memo);
+ if (!RTEST(i)) {
+ *memo = Qfalse;
+ rb_iter_break();
+ }
+ return Qnil;
}
/*
* call-seq:
* enum.all? [{|obj| block } ] => true or false
- *
+ *
* Passes each element of the collection to the given block. The method
* returns <code>true</code> if the block never returns
* <code>false</code> or <code>nil</code>. If the block is not given,
* Ruby adds an implicit block of <code>{|obj| obj}</code> (that is
* <code>all?</code> will return <code>true</code> only if none of the
* collection members are <code>false</code> or <code>nil</code>.)
- *
+ *
* %w{ ant bear cat}.all? {|word| word.length >= 3} #=> true
* %w{ ant bear cat}.all? {|word| word.length >= 4} #=> false
* [ nil, true, 99 ].all? #=> false
- *
+ *
*/
static VALUE
@@ -913,11 +549,11 @@ enum_all(obj)
}
static VALUE
-any_i(i, memo)
+any_iter_i(i, memo)
VALUE i;
VALUE *memo;
{
- if (RTEST(i)) {
+ if (RTEST(rb_yield(i))) {
*memo = Qtrue;
rb_iter_break();
}
@@ -925,17 +561,21 @@ any_i(i, memo)
}
static VALUE
-any_iter_i(i, memo)
+any_i(i, memo)
VALUE i;
VALUE *memo;
{
- return any_i(rb_yield(i), memo);
+ if (RTEST(i)) {
+ *memo = Qtrue;
+ rb_iter_break();
+ }
+ return Qnil;
}
/*
* call-seq:
* enum.any? [{|obj| block } ] => true or false
- *
+ *
* Passes each element of the collection to the given block. The method
* returns <code>true</code> if the block ever returns a value other
* than <code>false</code> or <code>nil</code>. If the block is not
@@ -943,11 +583,11 @@ any_iter_i(i, memo)
* is <code>any?</code> will return <code>true</code> if at least one
* of the collection members is not <code>false</code> or
* <code>nil</code>.
- *
+ *
* %w{ ant bear cat}.any? {|word| word.length >= 3} #=> true
* %w{ ant bear cat}.any? {|word| word.length >= 4} #=> true
* [ nil, true, 99 ].any? #=> true
- *
+ *
*/
static VALUE
@@ -961,105 +601,6 @@ enum_any(obj)
}
static VALUE
-one_i(i, memo)
- VALUE i;
- VALUE *memo;
-{
- if (RTEST(i)) {
- if (*memo == Qundef) {
- *memo = Qtrue;
- }
- else if (*memo == Qtrue) {
- *memo = Qfalse;
- rb_iter_break();
- }
- }
- return Qnil;
-}
-
-static VALUE
-one_iter_i(i, memo)
- VALUE i;
- VALUE *memo;
-{
- return one_i(rb_yield(i), memo);
-}
-
-/*
- * call-seq:
- * enum.one? [{|obj| block }] => true or false
- *
- * Passes each element of the collection to the given block. The method
- * returns <code>true</code> if the block returns <code>true</code>
- * exactly once. If the block is not given, <code>one?</code> will return
- * <code>true</code> only if exactly one of the collection members is
- * true.
- *
- * %w{ant bear cat}.one? {|word| word.length == 4} #=> true
- * %w{ant bear cat}.one? {|word| word.length > 4} #=> false
- * %w{ant bear cat}.one? {|word| word.length < 4} #=> false
- * [ nil, true, 99 ].one? #=> false
- * [ nil, true, false ].one? #=> true
- *
- */
-
-static VALUE
-enum_one(obj)
- VALUE obj;
-{
- VALUE result = Qundef;
-
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? one_iter_i : one_i, (VALUE)&result);
- if (result == Qundef) return Qfalse;
- return result;
-}
-
-static VALUE
-none_i(i, memo)
- VALUE i;
- VALUE *memo;
-{
- if (RTEST(i)) {
- *memo = Qfalse;
- rb_iter_break();
- }
- return Qnil;
-}
-
-static VALUE
-none_iter_i(i, memo)
- VALUE i;
- VALUE *memo;
-{
- return none_i(rb_yield(i), memo);
-}
-
-/*
- * call-seq:
- * enum.none? [{|obj| block }] => true or false
- *
- * Passes each element of the collection to the given block. The method
- * returns <code>true</code> if the block never returns <code>true</code>
- * for all elements. If the block is not given, <code>none?</code> will return
- * <code>true</code> only if none of the collection members is true.
- *
- * %w{ant bear cat}.none? {|word| word.length == 5} #=> true
- * %w{ant bear cat}.none? {|word| word.length >= 4} #=> false
- * [].none? #=> true
- * [nil].none? #=> true
- * [nil,false].none? #=> true
- */
-static VALUE
-enum_none(obj)
- VALUE obj;
-{
- VALUE result = Qtrue;
-
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? none_iter_i : none_i, (VALUE)&result);
- return result;
-}
-
-static VALUE
min_i(i, memo)
VALUE i;
VALUE *memo;
@@ -1102,11 +643,11 @@ min_ii(i, memo)
* call-seq:
* enum.min => obj
* enum.min {| a,b | block } => obj
- *
+ *
* Returns the object in <i>enum</i> with the minimum value. The
* first form assumes all objects implement <code>Comparable</code>;
* the second uses the block to return <em>a <=> b</em>.
- *
+ *
* a = %w(albatross dog horse)
* a.min #=> "albatross"
* a.min {|a,b| a.length <=> b.length } #=> "dog"
@@ -1127,11 +668,11 @@ enum_min(obj)
* call-seq:
* enum.max => obj
* enum.max {| a,b | block } => obj
- *
+ *
* Returns the object in <i>enum</i> with the maximum value. The
* first form assumes all objects implement <code>Comparable</code>;
* the second uses the block to return <em>a <=> b</em>.
- *
+ *
* a = %w(albatross dog horse)
* a.max #=> "horse"
* a.max {|a,b| a.length <=> b.length } #=> "albatross"
@@ -1179,15 +720,15 @@ max_ii(i, memo)
* call-seq:
* enum.max => obj
* enum.max {|a,b| block } => obj
- *
+ *
* Returns the object in _enum_ with the maximum value. The
* first form assumes all objects implement <code>Comparable</code>;
* the second uses the block to return <em>a <=> b</em>.
- *
+ *
* a = %w(albatross dog horse)
* a.max #=> "horse"
* a.max {|a,b| a.length <=> b.length } #=> "albatross"
- */
+ */
static VALUE
enum_max(obj)
@@ -1201,240 +742,6 @@ enum_max(obj)
}
static VALUE
-minmax_i(i, memo)
- VALUE i;
- VALUE *memo;
-{
- int n;
-
- if (memo[0] == Qundef) {
- memo[0] = i;
- memo[1] = i;
- }
- else {
- n = rb_cmpint(rb_funcall(i, id_cmp, 1, memo[0]), i, memo[0]);
- if (n < 0) {
- memo[0] = i;
- }
- n = rb_cmpint(rb_funcall(i, id_cmp, 1, memo[1]), i, memo[1]);
- if (n > 0) {
- memo[1] = i;
- }
- }
- return Qnil;
-}
-
-static VALUE
-minmax_ii(i, memo)
- VALUE i;
- VALUE *memo;
-{
- int n;
-
- if (memo[0] == Qundef) {
- memo[0] = i;
- memo[1] = i;
- }
- else {
- VALUE ary = memo[2];
-
- RARRAY(ary)->ptr[0] = i;
- RARRAY(ary)->ptr[1] = memo[0];
- n = rb_cmpint(rb_yield(ary), i, memo[0]);
- if (n < 0) {
- memo[0] = i;
- }
- RARRAY(ary)->ptr[0] = i;
- RARRAY(ary)->ptr[1] = memo[1];
- n = rb_cmpint(rb_yield(ary), i, memo[1]);
- if (n > 0) {
- memo[1] = i;
- }
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.minmax => [min,max]
- * enum.minmax {|a,b| block } => [min,max]
- *
- * Returns two elements array which contains the minimum and the
- * maximum value in the enumerable. The first form assumes all
- * objects implement <code>Comparable</code>; the second uses the
- * block to return <em>a <=> b</em>.
- *
- * a = %w(albatross dog horse)
- * a.minmax #=> ["albatross", "horse"]
- * a.minmax {|a,b| a.length <=> b.length } #=> ["dog", "albatross"]
- */
-
-static VALUE
-enum_minmax(obj)
- VALUE obj;
-{
- VALUE result[3];
- VALUE ary = rb_ary_new3(2, Qnil, Qnil);
-
- result[0] = Qundef;
- if (rb_block_given_p()) {
- result[2] = ary;
- rb_block_call(obj, id_each, 0, 0, minmax_ii, (VALUE)result);
- }
- else {
- rb_block_call(obj, id_each, 0, 0, minmax_i, (VALUE)result);
- }
- if (result[0] != Qundef) {
- RARRAY(ary)->ptr[0] = result[0];
- RARRAY(ary)->ptr[1] = result[1];
- }
- return ary;
-}
-
-static VALUE
-min_by_i(i, memo)
- VALUE i;
- VALUE *memo;
-{
- VALUE v;
-
- v = rb_yield(i);
- if (memo[0] == Qundef) {
- memo[0] = v;
- memo[1] = i;
- }
- else if (rb_cmpint(rb_funcall(v, id_cmp, 1, memo[0]), v, memo[0]) < 0) {
- memo[0] = v;
- memo[1] = i;
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.min_by {| obj| block } => obj
- *
- * Returns the object in <i>enum</i> that gives the minimum
- * value from the given block.
- *
- * a = %w(albatross dog horse)
- * a.min_by {|x| x.length } #=> "dog"
- */
-
-static VALUE
-enum_min_by(obj)
- VALUE obj;
-{
- VALUE memo[2];
-
- RETURN_ENUMERATOR(obj, 0, 0);
-
- memo[0] = Qundef;
- memo[1] = Qnil;
- rb_block_call(obj, id_each, 0, 0, min_by_i, (VALUE)memo);
- return memo[1];
-}
-
-static VALUE
-max_by_i(i, memo)
- VALUE i;
- VALUE *memo;
-{
- VALUE v;
-
- v = rb_yield(i);
- if (memo[0] == Qundef) {
- memo[0] = v;
- memo[1] = i;
- }
- else if (rb_cmpint(rb_funcall(v, id_cmp, 1, memo[0]), v, memo[0]) > 0) {
- memo[0] = v;
- memo[1] = i;
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.max_by {| obj| block } => obj
- *
- * Returns the object in <i>enum</i> that gives the maximum
- * value from the given block.
- *
- * a = %w(albatross dog horse)
- * a.max_by {|x| x.length } #=> "albatross"
- */
-
-static VALUE
-enum_max_by(obj)
- VALUE obj;
-{
- VALUE memo[2];
-
- RETURN_ENUMERATOR(obj, 0, 0);
-
- memo[0] = Qundef;
- memo[1] = Qnil;
- rb_block_call(obj, id_each, 0, 0, max_by_i, (VALUE)memo);
- return memo[1];
-}
-
-static VALUE
-minmax_by_i(i, memo)
- VALUE i;
- VALUE *memo;
-{
- VALUE v;
-
- v = rb_yield(i);
- if (memo[0] == Qundef) {
- memo[0] = v;
- memo[1] = v;
- memo[2] = i;
- memo[3] = i;
- }
- else {
- if (rb_cmpint(rb_funcall(v, id_cmp, 1, memo[0]), v, memo[0]) < 0) {
- memo[0] = v;
- memo[2] = i;
- }
- if (rb_cmpint(rb_funcall(v, id_cmp, 1, memo[1]), v, memo[1]) > 0) {
- memo[1] = v;
- memo[3] = i;
- }
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.minmax_by {| obj| block } => [min, max]
- *
- * Returns two elements array array containing the objects in
- * <i>enum</i> that gives the minimum and maximum values respectively
- * from the given block.
- *
- * a = %w(albatross dog horse)
- * a.minmax_by {|x| x.length } #=> ["dog", "albatross"]
- */
-
-static VALUE
-enum_minmax_by(obj)
- VALUE obj;
-{
- VALUE memo[4];
-
- RETURN_ENUMERATOR(obj, 0, 0);
-
- memo[0] = Qundef;
- memo[1] = Qundef;
- memo[2] = Qnil;
- memo[3] = Qnil;
- rb_block_call(obj, id_each, 0, 0, minmax_by_i, (VALUE)memo);
- return rb_assoc_new(memo[2], memo[3]);
-}
-
-static VALUE
member_i(item, memo)
VALUE item;
VALUE *memo;
@@ -1450,13 +757,13 @@ member_i(item, memo)
* call-seq:
* enum.include?(obj) => true or false
* enum.member?(obj) => true or false
- *
+ *
* Returns <code>true</code> if any member of <i>enum</i> equals
* <i>obj</i>. Equality is tested using <code>==</code>.
- *
+ *
* IO.constants.include? "SEEK_SET" #=> true
* IO.constants.include? "SEEK_NO_FURTHER" #=> false
- *
+ *
*/
static VALUE
@@ -1484,56 +791,29 @@ each_with_index_i(val, memo)
/*
* call-seq:
* enum.each_with_index {|obj, i| block } -> enum
- *
+ *
* Calls <em>block</em> with two arguments, the item and its index, for
* each item in <i>enum</i>.
- *
+ *
* hash = Hash.new
* %w(cat dog wombat).each_with_index {|item, index|
* hash[item] = index
* }
* hash #=> {"cat"=>0, "wombat"=>2, "dog"=>1}
- *
+ *
*/
static VALUE
enum_each_with_index(obj)
VALUE obj;
{
- VALUE memo;
+ VALUE memo = 0;
- RETURN_ENUMERATOR(obj, 0, 0);
-
- memo = 0;
+ rb_need_block();
rb_iterate(rb_each, obj, each_with_index_i, (VALUE)&memo);
return obj;
}
-/*
- * call-seq:
- * enum.reverse_each {|item| block }
- *
- * Traverses <i>enum</i> in reverse order.
- */
-
-static VALUE
-enum_reverse_each(int argc, VALUE *argv, VALUE obj)
-{
- VALUE ary;
- long i;
-
- RETURN_ENUMERATOR(obj, argc, argv);
-
- ary = enum_to_a(argc, argv, obj);
-
- for (i = RARRAY_LEN(ary); --i >= 0; ) {
- rb_yield(RARRAY_PTR(ary)[i]);
- }
-
- return obj;
-}
-
-
static VALUE
zip_i(val, memo)
VALUE val;
@@ -1563,7 +843,7 @@ zip_i(val, memo)
* call-seq:
* enum.zip(arg, ...) => array
* enum.zip(arg, ...) {|arr| block } => nil
- *
+ *
* Converts any arguments to arrays, then merges elements of
* <i>enum</i> with corresponding elements from each argument. This
* generates a sequence of <code>enum#size</code> <em>n</em>-element
@@ -1572,14 +852,14 @@ zip_i(val, memo)
* <code>nil</code> values are supplied. If a block given, it is
* invoked for each output array, otherwise an array of arrays is
* returned.
- *
+ *
* a = [ 4, 5, 6 ]
* b = [ 7, 8, 9 ]
- *
+ *
* (1..3).zip(a, b) #=> [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
* "cat\ndog".zip([1]) #=> [["cat\n", 1], ["dog", nil]]
* (1..3).zip #=> [[1], [2], [3]]
- *
+ *
*/
static VALUE
@@ -1604,227 +884,6 @@ enum_zip(argc, argv, obj)
return result;
}
-static VALUE
-take_i(i, arg)
- VALUE i;
- VALUE *arg;
-{
- if (arg[1]-- == 0) rb_iter_break();
- rb_ary_push(arg[0], i);
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.take(n) => array
- *
- * Returns first n elements from <i>enum</i>.
- *
- * a = [1, 2, 3, 4, 5, 0]
- * a.take(3) # => [1, 2, 3]
- *
- */
-
-static VALUE
-enum_take(obj, n)
- VALUE obj;
- VALUE n;
-{
- VALUE args[2];
- long len = NUM2LONG(n);
-
- if (len < 0) {
- rb_raise(rb_eArgError, "attempt to take negative size");
- }
-
- args[1] = len;
- args[0] = rb_ary_new();
- rb_block_call(obj, id_each, 0, 0, take_i, (VALUE)args);
- return args[0];
-}
-
-
-static VALUE
-take_while_i(i, ary)
- VALUE i;
- VALUE *ary;
-{
- if (!RTEST(rb_yield(i))) rb_iter_break();
- rb_ary_push(*ary, i);
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.take_while {|arr| block } => array
- *
- * Passes elements to the block until the block returns nil or false,
- * then stops iterating and returns an array of all prior elements.
- *
- * a = [1, 2, 3, 4, 5, 0]
- * a.take_while {|i| i < 3 } # => [1, 2]
- *
- */
-
-static VALUE
-enum_take_while(obj)
- VALUE obj;
-{
- VALUE ary;
-
- RETURN_ENUMERATOR(obj, 0, 0);
- ary = rb_ary_new();
- rb_block_call(obj, id_each, 0, 0, take_while_i, (VALUE)&ary);
- return ary;
-}
-
-static VALUE
-drop_i(i, arg)
- VALUE i;
- VALUE *arg;
-{
- if (arg[1] == 0) {
- rb_ary_push(arg[0], i);
- }
- else {
- arg[1]--;
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.drop(n) => array
- *
- * Drops first n elements from <i>enum</i>, and returns rest elements
- * in an array.
- *
- * a = [1, 2, 3, 4, 5, 0]
- * a.drop(3) # => [4, 5, 0]
- *
- */
-
-static VALUE
-enum_drop(obj, n)
- VALUE obj;
- VALUE n;
-{
- VALUE args[2];
- long len = NUM2LONG(n);
-
- if (len < 0) {
- rb_raise(rb_eArgError, "attempt to drop negative size");
- }
-
- args[1] = len;
- args[0] = rb_ary_new();
- rb_block_call(obj, id_each, 0, 0, drop_i, (VALUE)args);
- return args[0];
-}
-
-
-static VALUE
-drop_while_i(i, args)
- VALUE i;
- VALUE *args;
-{
- if (!args[1] && !RTEST(rb_yield(i))) {
- args[1] = Qtrue;
- }
- if (args[1]) {
- rb_ary_push(args[0], i);
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.drop_while {|arr| block } => array
- *
- * Drops elements up to, but not including, the first element for
- * which the block returns nil or false and returns an array
- * containing the remaining elements.
- *
- * a = [1, 2, 3, 4, 5, 0]
- * a.drop_while {|i| i < 3 } # => [3, 4, 5, 0]
- *
- */
-
-static VALUE
-enum_drop_while(obj)
- VALUE obj;
-{
- VALUE args[2];
-
- RETURN_ENUMERATOR(obj, 0, 0);
- args[0] = rb_ary_new();
- args[1] = Qfalse;
- rb_block_call(obj, id_each, 0, 0, drop_while_i, (VALUE)args);
- return args[0];
-}
-
-static VALUE
-cycle_i(i, ary)
- VALUE i;
- VALUE ary;
-{
- rb_ary_push(ary, i);
- rb_yield(i);
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.cycle {|obj| block }
- * enum.cycle(n) {|obj| block }
- *
- * Calls <i>block</i> for each element of <i>enum</i> repeatedly _n_
- * times or forever if none or nil is given. If a non-positive
- * number is given or the collection is empty, does nothing. Returns
- * nil if the loop has finished without getting interrupted.
- *
- * Enumerable#cycle saves elements in an internal array so changes
- * to <i>enum</i> after the first pass have no effect.
- *
- * a = ["a", "b", "c"]
- * a.cycle {|x| puts x } # print, a, b, c, a, b, c,.. forever.
- * a.cycle(2) {|x| puts x } # print, a, b, c, a, b, c.
- *
- */
-
-static VALUE
-enum_cycle(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
-{
- VALUE ary;
- VALUE nv = Qnil;
- long n, i, len;
-
- rb_scan_args(argc, argv, "01", &nv);
-
- RETURN_ENUMERATOR(obj, argc, argv);
- if (NIL_P(nv)) {
- n = -1;
- }
- else {
- n = NUM2LONG(nv);
- if (n <= 0) return Qnil;
- }
- ary = rb_ary_new();
- RBASIC(ary)->klass = 0;
- rb_block_call(obj, id_each, 0, 0, cycle_i, ary);
- len = RARRAY(ary)->len;
- if (len == 0) return Qnil;
- while (n < 0 || 0 < --n) {
- for (i=0; i<len; i++) {
- rb_yield(RARRAY(ary)->ptr[i]);
- }
- }
- return Qnil; /* not reached */
-}
-
/*
* The <code>Enumerable</code> mixin provides collection classes with
* several traversal and searching methods, and with the ability to
@@ -1841,51 +900,32 @@ Init_Enumerable()
{
rb_mEnumerable = rb_define_module("Enumerable");
- rb_define_method(rb_mEnumerable, "to_a", enum_to_a, -1);
- rb_define_method(rb_mEnumerable, "entries", enum_to_a, -1);
-
- rb_define_method(rb_mEnumerable, "sort", enum_sort, 0);
- rb_define_method(rb_mEnumerable, "sort_by", enum_sort_by, 0);
- rb_define_method(rb_mEnumerable, "grep", enum_grep, 1);
- rb_define_method(rb_mEnumerable, "count", enum_count, -1);
- rb_define_method(rb_mEnumerable, "find", enum_find, -1);
- rb_define_method(rb_mEnumerable, "detect", enum_find, -1);
- rb_define_method(rb_mEnumerable, "find_index", enum_find_index, -1);
- rb_define_method(rb_mEnumerable, "find_all", enum_find_all, 0);
- rb_define_method(rb_mEnumerable, "select", enum_find_all, 0);
- rb_define_method(rb_mEnumerable, "reject", enum_reject, 0);
- rb_define_method(rb_mEnumerable, "collect", enum_collect, 0);
- rb_define_method(rb_mEnumerable, "map", enum_collect, 0);
- rb_define_method(rb_mEnumerable, "inject", enum_inject, -1);
- rb_define_method(rb_mEnumerable, "reduce", enum_inject, -1);
- rb_define_method(rb_mEnumerable, "partition", enum_partition, 0);
- rb_define_method(rb_mEnumerable, "group_by", enum_group_by, 0);
- rb_define_method(rb_mEnumerable, "first", enum_first, -1);
- rb_define_method(rb_mEnumerable, "all?", enum_all, 0);
- rb_define_method(rb_mEnumerable, "any?", enum_any, 0);
- rb_define_method(rb_mEnumerable, "one?", enum_one, 0);
- rb_define_method(rb_mEnumerable, "none?", enum_none, 0);
- rb_define_method(rb_mEnumerable, "min", enum_min, 0);
- rb_define_method(rb_mEnumerable, "max", enum_max, 0);
- rb_define_method(rb_mEnumerable, "minmax", enum_minmax, 0);
- rb_define_method(rb_mEnumerable, "min_by", enum_min_by, 0);
- rb_define_method(rb_mEnumerable, "max_by", enum_max_by, 0);
- rb_define_method(rb_mEnumerable, "minmax_by", enum_minmax_by, 0);
- rb_define_method(rb_mEnumerable, "member?", enum_member, 1);
- rb_define_method(rb_mEnumerable, "include?", enum_member, 1);
- rb_define_method(rb_mEnumerable, "each_with_index", enum_each_with_index, 0);
- rb_define_method(rb_mEnumerable, "enum_with_index", enum_each_with_index, 0);
- rb_define_method(rb_mEnumerable, "reverse_each", enum_reverse_each, -1);
+ rb_define_method(rb_mEnumerable,"to_a", enum_to_a, 0);
+ rb_define_method(rb_mEnumerable,"entries", enum_to_a, 0);
+
+ rb_define_method(rb_mEnumerable,"sort", enum_sort, 0);
+ rb_define_method(rb_mEnumerable,"sort_by", enum_sort_by, 0);
+ rb_define_method(rb_mEnumerable,"grep", enum_grep, 1);
+ rb_define_method(rb_mEnumerable,"find", enum_find, -1);
+ rb_define_method(rb_mEnumerable,"detect", enum_find, -1);
+ rb_define_method(rb_mEnumerable,"find_all", enum_find_all, 0);
+ rb_define_method(rb_mEnumerable,"select", enum_find_all, 0);
+ rb_define_method(rb_mEnumerable,"reject", enum_reject, 0);
+ rb_define_method(rb_mEnumerable,"collect", enum_collect, 0);
+ rb_define_method(rb_mEnumerable,"map", enum_collect, 0);
+ rb_define_method(rb_mEnumerable,"inject", enum_inject, -1);
+ rb_define_method(rb_mEnumerable,"partition", enum_partition, 0);
+ rb_define_method(rb_mEnumerable,"all?", enum_all, 0);
+ rb_define_method(rb_mEnumerable,"any?", enum_any, 0);
+ rb_define_method(rb_mEnumerable,"min", enum_min, 0);
+ rb_define_method(rb_mEnumerable,"max", enum_max, 0);
+ rb_define_method(rb_mEnumerable,"member?", enum_member, 1);
+ rb_define_method(rb_mEnumerable,"include?", enum_member, 1);
+ rb_define_method(rb_mEnumerable,"each_with_index", enum_each_with_index, 0);
rb_define_method(rb_mEnumerable, "zip", enum_zip, -1);
- rb_define_method(rb_mEnumerable, "take", enum_take, 1);
- rb_define_method(rb_mEnumerable, "take_while", enum_take_while, 0);
- rb_define_method(rb_mEnumerable, "drop", enum_drop, 1);
- rb_define_method(rb_mEnumerable, "drop_while", enum_drop_while, 0);
- rb_define_method(rb_mEnumerable, "cycle", enum_cycle, -1);
id_eqq = rb_intern("===");
id_each = rb_intern("each");
id_cmp = rb_intern("<=>");
- id_size = rb_intern("size");
}
diff --git a/enumerator.c b/enumerator.c
deleted file mode 100644
index f95d931b62..0000000000
--- a/enumerator.c
+++ /dev/null
@@ -1,450 +0,0 @@
-/************************************************
-
- enumerator.c - provides Enumerator class
-
- $Author$
-
- Copyright (C) 2001-2003 Akinori MUSHA
-
- $Idaemons: /home/cvs/rb/enumerator/enumerator.c,v 1.1.1.1 2001/07/15 10:12:48 knu Exp $
- $RoughId: enumerator.c,v 1.6 2003/07/27 11:03:24 nobu Exp $
- $Id$
-
-************************************************/
-
-#include "ruby.h"
-
-/*
- * Document-class: Enumerable::Enumerator
- *
- * A class which provides a method `each' to be used as an Enumerable
- * object.
- */
-VALUE rb_cEnumerator;
-static VALUE sym_each;
-
-VALUE rb_eStopIteration;
-
-struct enumerator {
- VALUE obj;
- ID meth;
- VALUE proc;
- VALUE args;
- rb_block_call_func *iter;
-};
-
-static void enumerator_mark _((void *));
-static void
-enumerator_mark(p)
- void *p;
-{
- struct enumerator *ptr = p;
- rb_gc_mark(ptr->obj);
- rb_gc_mark(ptr->args);
-}
-
-static struct enumerator *
-enumerator_ptr(obj)
- VALUE obj;
-{
- struct enumerator *ptr;
-
- Data_Get_Struct(obj, struct enumerator, ptr);
- if (RDATA(obj)->dmark != enumerator_mark) {
- rb_raise(rb_eTypeError,
- "wrong argument type %s (expected Enumerable::Enumerator)",
- rb_obj_classname(obj));
- }
- if (!ptr || ptr->obj == Qundef) {
- rb_raise(rb_eArgError, "uninitialized enumerator");
- }
- return ptr;
-}
-
-/*
- * call-seq:
- * obj.to_enum(method = :each, *args)
- * obj.enum_for(method = :each, *args)
- *
- * Returns Enumerable::Enumerator.new(self, method, *args).
- *
- * e.g.:
- *
- * str = "xyz"
- *
- * enum = str.enum_for(:each_byte)
- * a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
- *
- * # protects an array from being modified
- * a = [1, 2, 3]
- * some_method(a.to_enum)
- *
- */
-static VALUE
-obj_to_enum(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
-{
- VALUE meth = sym_each;
-
- if (argc > 0) {
- --argc;
- meth = *argv++;
- }
- return rb_enumeratorize(obj, meth, argc, argv);
-}
-
-static VALUE
-each_slice_i(val, memo)
- VALUE val;
- VALUE *memo;
-{
- VALUE ary = memo[0];
- VALUE v = Qnil;
- long size = (long)memo[1];
-
- rb_ary_push(ary, val);
-
- if (RARRAY_LEN(ary) == size) {
- v = rb_yield(ary);
- memo[0] = rb_ary_new2(size);
- }
-
- return v;
-}
-
-/*
- * call-seq:
- * e.each_slice(n) {...}
- * e.each_slice(n)
- *
- * Iterates the given block for each slice of <n> elements. If no
- * block is given, returns an enumerator.
- *
- * e.g.:
- * (1..10).each_slice(3) {|a| p a}
- * # outputs below
- * [1, 2, 3]
- * [4, 5, 6]
- * [7, 8, 9]
- * [10]
- *
- */
-static VALUE
-enum_each_slice(obj, n)
- VALUE obj, n;
-{
- long size = NUM2LONG(n);
- VALUE args[2], ary;
-
- if (size <= 0) rb_raise(rb_eArgError, "invalid slice size");
- RETURN_ENUMERATOR(obj, 1, &n);
- args[0] = rb_ary_new2(size);
- args[1] = (VALUE)size;
-
- rb_block_call(obj, SYM2ID(sym_each), 0, 0, each_slice_i, (VALUE)args);
-
- ary = args[0];
- if (RARRAY_LEN(ary) > 0) rb_yield(ary);
-
- return Qnil;
-}
-
-static VALUE
-each_cons_i(val, memo)
- VALUE val;
- VALUE *memo;
-{
- VALUE ary = memo[0];
- VALUE v = Qnil;
- long size = (long)memo[1];
-
- if (RARRAY_LEN(ary) == size) {
- rb_ary_shift(ary);
- }
- rb_ary_push(ary, val);
- if (RARRAY_LEN(ary) == size) {
- v = rb_yield(rb_ary_dup(ary));
- }
- return v;
-}
-
-/*
- * call-seq:
- * each_cons(n) {...}
- * each_cons(n)
- *
- * Iterates the given block for each array of consecutive <n>
- * elements. If no block is given, returns an enumerator.a
- *
- * e.g.:
- * (1..10).each_cons(3) {|a| p a}
- * # outputs below
- * [1, 2, 3]
- * [2, 3, 4]
- * [3, 4, 5]
- * [4, 5, 6]
- * [5, 6, 7]
- * [6, 7, 8]
- * [7, 8, 9]
- * [8, 9, 10]
- *
- */
-static VALUE
-enum_each_cons(obj, n)
- VALUE obj, n;
-{
- long size = NUM2LONG(n);
- VALUE args[2];
-
- if (size <= 0) rb_raise(rb_eArgError, "invalid size");
- RETURN_ENUMERATOR(obj, 1, &n);
- args[0] = rb_ary_new2(size);
- args[1] = (VALUE)size;
-
- rb_block_call(obj, SYM2ID(sym_each), 0, 0, each_cons_i, (VALUE)args);
-
- return Qnil;
-}
-
-static VALUE enumerator_allocate _((VALUE));
-static VALUE
-enumerator_allocate(klass)
- VALUE klass;
-{
- struct enumerator *ptr;
- VALUE enum_obj;
-
- enum_obj = Data_Make_Struct(klass, struct enumerator,
- enumerator_mark, -1, ptr);
- ptr->obj = Qundef;
-
- return enum_obj;
-}
-
-static VALUE enumerator_each_i _((VALUE, VALUE));
-static VALUE
-enumerator_each_i(v, enum_obj)
- VALUE v;
- VALUE enum_obj;
-{
- return rb_yield(v);
-}
-
-static VALUE
-enumerator_init(enum_obj, obj, meth, argc, argv)
- VALUE enum_obj;
- VALUE obj;
- VALUE meth;
- int argc;
- VALUE *argv;
-{
- struct enumerator *ptr;
-
- Data_Get_Struct(enum_obj, struct enumerator, ptr);
-
- if (!ptr) {
- rb_raise(rb_eArgError, "unallocated enumerator");
- }
-
- ptr->obj = obj;
- ptr->meth = rb_to_id(meth);
- ptr->iter = enumerator_each_i;
- if (argc) ptr->args = rb_ary_new4(argc, argv);
-
- return enum_obj;
-}
-
-/*
- * call-seq:
- * Enumerable::Enumerator.new(obj, method = :each, *args)
- *
- * Creates a new Enumerable::Enumerator object, which is to be
- * used as an Enumerable object using the given object's given
- * method with the given arguments.
- *
- * Use of this method is discouraged. Use Kernel#enum_for() instead.
- */
-static VALUE
-enumerator_initialize(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
-{
- VALUE recv, meth = sym_each;
-
- if (argc == 0)
- rb_raise(rb_eArgError, "wrong number of argument (0 for 1)");
- recv = *argv++;
- if (--argc) {
- meth = *argv++;
- --argc;
- }
- return enumerator_init(obj, recv, meth, argc, argv);
-}
-
-/* :nodoc: */
-static VALUE
-enumerator_init_copy(obj, orig)
- VALUE obj;
- VALUE orig;
-{
- struct enumerator *ptr0, *ptr1;
-
- ptr0 = enumerator_ptr(orig);
-
- Data_Get_Struct(obj, struct enumerator, ptr1);
-
- if (!ptr1) {
- rb_raise(rb_eArgError, "unallocated enumerator");
- }
-
- ptr1->obj = ptr0->obj;
- ptr1->meth = ptr0->meth;
- ptr1->iter = ptr0->iter;
- ptr1->args = ptr0->args;
-
- return obj;
-}
-
-VALUE
-rb_enumeratorize(obj, meth, argc, argv)
- VALUE obj;
- VALUE meth;
- int argc;
- VALUE *argv;
-{
- return enumerator_init(enumerator_allocate(rb_cEnumerator), obj, meth, argc, argv);
-}
-
-/*
- * call-seq:
- * enum.each {...}
- *
- * Iterates the given block using the object and the method specified
- * in the first place. If no block is given, returns self.
- *
- */
-static VALUE
-enumerator_each(obj)
- VALUE obj;
-{
- struct enumerator *e;
- int argc = 0;
- VALUE *argv = 0;
-
- if (!rb_block_given_p()) return obj;
- e = enumerator_ptr(obj);
- if (e->args) {
- argc = RARRAY_LEN(e->args);
- argv = RARRAY_PTR(e->args);
- }
- return rb_block_call(e->obj, e->meth, argc, argv, e->iter, (VALUE)e);
-}
-
-static VALUE
-enumerator_with_index_i(val, memo)
- VALUE val;
- VALUE *memo;
-{
- val = rb_yield_values(2, val, INT2FIX(*memo));
- ++*memo;
- return val;
-}
-
-/*
- * call-seq:
- * e.with_index {|(*args), idx| ... }
- * e.with_index
- *
- * Iterates the given block for each elements with an index, which
- * start from 0. If no block is given, returns an enumerator.
- *
- */
-static VALUE
-enumerator_with_index(obj)
- VALUE obj;
-{
- struct enumerator *e = enumerator_ptr(obj);
- VALUE memo = 0;
- int argc = 0;
- VALUE *argv = 0;
-
- RETURN_ENUMERATOR(obj, 0, 0);
- if (e->args) {
- argc = RARRAY_LEN(e->args);
- argv = RARRAY_PTR(e->args);
- }
- return rb_block_call(e->obj, e->meth, argc, argv,
- enumerator_with_index_i, (VALUE)&memo);
-}
-
-/*
- * call-seq:
- * e.next => object
- *
- * Returns the next object in the enumerator, and move the internal
- * position forward. When the position reached at the end, internal
- * position is rewinded then StopIteration is raised.
- *
- * Note that enumeration sequence by next method does not affect other
- * non-external enumeration methods, unless underlying iteration
- * methods itself has side-effect, e.g. IO#each_line.
- *
- * Caution: Calling this method causes the "generator" library to be
- * loaded.
- */
-
-static VALUE
-enumerator_next(obj)
- VALUE obj;
-{
- rb_require("generator");
- return rb_funcall(obj, rb_intern("next"), 0, 0);
-}
-
-/*
- * call-seq:
- * e.rewind => e
- *
- * Rewinds the enumeration sequence by the next method.
- */
-
-static VALUE
-enumerator_rewind(obj)
- VALUE obj;
-{
- rb_require("generator");
- return rb_funcall(obj, rb_intern("rewind"), 0, 0);
-}
-
-void
-Init_Enumerator()
-{
- rb_define_method(rb_mKernel, "to_enum", obj_to_enum, -1);
- rb_define_method(rb_mKernel, "enum_for", obj_to_enum, -1);
-
- rb_define_method(rb_mEnumerable, "each_slice", enum_each_slice, 1);
- rb_define_method(rb_mEnumerable, "enum_slice", enum_each_slice, 1);
- rb_define_method(rb_mEnumerable, "each_cons", enum_each_cons, 1);
- rb_define_method(rb_mEnumerable, "enum_cons", enum_each_cons, 1);
-
- rb_cEnumerator = rb_define_class_under(rb_mEnumerable, "Enumerator", rb_cObject);
- rb_include_module(rb_cEnumerator, rb_mEnumerable);
-
- rb_define_alloc_func(rb_cEnumerator, enumerator_allocate);
- rb_define_method(rb_cEnumerator, "initialize", enumerator_initialize, -1);
- rb_define_method(rb_cEnumerator, "initialize_copy", enumerator_init_copy, 1);
- rb_define_method(rb_cEnumerator, "each", enumerator_each, 0);
- rb_define_method(rb_cEnumerator, "each_with_index", enumerator_with_index, 0);
- rb_define_method(rb_cEnumerator, "with_index", enumerator_with_index, 0);
- rb_define_method(rb_cEnumerator, "next", enumerator_next, 0);
- rb_define_method(rb_cEnumerator, "rewind", enumerator_rewind, 0);
-
- rb_eStopIteration = rb_define_class("StopIteration", rb_eIndexError);
-
- sym_each = ID2SYM(rb_intern("each"));
-
- rb_provide("enumerator.so"); /* for backward compatibility */
-}
diff --git a/error.c b/error.c
index a991f55e57..608d1fa558 100644
--- a/error.c
+++ b/error.c
@@ -29,7 +29,7 @@
#define EXIT_SUCCESS 0
#endif
-extern const char *ruby_description;
+extern const char ruby_version[], ruby_release_date[], ruby_platform[];
int ruby_nerrs;
@@ -208,7 +208,8 @@ rb_bug(fmt, va_alist)
va_init_list(args, fmt);
vfprintf(out, fmt, args);
va_end(args);
- fprintf(out, "\n%s\n\n", ruby_description);
+ fprintf(out, "\nruby %s (%s) [%s]\n\n",
+ ruby_version, ruby_release_date, ruby_platform);
}
abort();
}
@@ -257,7 +258,7 @@ rb_check_type(x, t)
if (TYPE(x) != t) {
while (type->type >= 0) {
if (type->type == t) {
- const char *etype;
+ char *etype;
if (NIL_P(x)) {
etype = "nil";
@@ -333,7 +334,7 @@ rb_exc_new3(etype, str)
VALUE etype, str;
{
StringValue(str);
- return rb_funcall(etype, rb_intern("new"), 1, str);
+ return rb_exc_new(etype, RSTRING(str)->ptr, RSTRING(str)->len);
}
/*
@@ -498,7 +499,7 @@ rb_check_backtrace(bt)
VALUE bt;
{
long i;
- static const char err[] = "backtrace must be Array of String";
+ static char *err = "backtrace must be Array of String";
if (!NIL_P(bt)) {
int t = TYPE(bt);
@@ -727,7 +728,7 @@ name_err_mesg_to_str(obj)
mesg = ptr[0];
if (NIL_P(mesg)) return Qnil;
else {
- const char *desc = 0;
+ char *desc = 0;
VALUE d = 0, args[3];
obj = ptr[1];
@@ -881,7 +882,7 @@ syserr_initialize(argc, argv, self)
#if !defined(_WIN32) && !defined(__VMS)
char *strerror();
#endif
- const char *err;
+ char *err;
VALUE mesg, error;
VALUE klass = rb_obj_class(self);
@@ -951,16 +952,18 @@ syserr_eqq(self, exc)
VALUE self, exc;
{
VALUE num, e;
- ID en = rb_intern("errno");
- if (!rb_obj_is_kind_of(exc, rb_eSystemCallError)) {
- if (!rb_respond_to(exc, en)) return Qfalse;
- }
- else if (self == rb_eSystemCallError) return Qtrue;
+ if (!rb_obj_is_kind_of(exc, rb_eSystemCallError)) return Qfalse;
+ if (self == rb_eSystemCallError) return Qtrue;
- num = rb_attr_get(exc, en);
+ num = rb_attr_get(exc, rb_intern("errno"));
if (NIL_P(num)) {
- num = rb_funcall(exc, en, 0, 0);
+ VALUE klass = CLASS_OF(exc);
+
+ while (TYPE(klass) == T_ICLASS || FL_TEST(klass, FL_SINGLETON)) {
+ klass = (VALUE)RCLASS(klass)->super;
+ }
+ num = rb_const_get(klass, rb_intern("Errno"));
}
e = rb_const_get(self, rb_intern("Errno"));
if (FIXNUM_P(num) ? num == e : rb_equal(num, e))
diff --git a/eval.c b/eval.c
index 1df4d28841..7911ce8bfa 100644
--- a/eval.c
+++ b/eval.c
@@ -72,8 +72,6 @@ char *strrchr _((const char*,const char));
#include <unistd.h>
#endif
-#include <time.h>
-
#ifdef __BEOS__
#include <net/socket.h>
#endif
@@ -195,11 +193,14 @@ static int volatile freebsd_clear_carry_flag = 0;
POST_GETCONTEXT, \
(j)->status)
#else
-# define ruby_setjmp(just_before_setjmp, env) \
- ((just_before_setjmp), RUBY_SETJMP(env))
-# define ruby_longjmp(env,val) RUBY_LONGJMP(env,val)
-# ifdef __CYGWIN__
-int _setjmp(), _longjmp();
+# if !defined(setjmp) && defined(HAVE__SETJMP)
+# define ruby_setjmp(just_before_setjmp, env) \
+ ((just_before_setjmp), _setjmp(env))
+# define ruby_longjmp(env,val) _longjmp(env,val)
+# else
+# define ruby_setjmp(just_before_setjmp, env) \
+ ((just_before_setjmp), setjmp(env))
+# define ruby_longjmp(env,val) longjmp(env,val)
# endif
#endif
@@ -452,8 +453,7 @@ rb_define_alloc_func(klass, func)
VALUE (*func) _((VALUE));
{
Check_Type(klass, T_CLASS);
- rb_add_method(rb_singleton_class(klass), ID_ALLOCATOR, NEW_CFUNC(func, 0),
- NOEX_PRIVATE);
+ rb_add_method(CLASS_OF(klass), ID_ALLOCATOR, NEW_CFUNC(func, 0), NOEX_PRIVATE);
}
void
@@ -461,7 +461,7 @@ rb_undef_alloc_func(klass)
VALUE klass;
{
Check_Type(klass, T_CLASS);
- rb_add_method(rb_singleton_class(klass), ID_ALLOCATOR, 0, NOEX_UNDEF);
+ rb_add_method(CLASS_OF(klass), ID_ALLOCATOR, 0, NOEX_UNDEF);
}
static NODE*
@@ -469,16 +469,16 @@ search_method(klass, id, origin)
VALUE klass, *origin;
ID id;
{
- st_data_t body;
+ NODE *body;
if (!klass) return 0;
- while (!st_lookup(RCLASS(klass)->m_tbl, id, &body)) {
+ while (!st_lookup(RCLASS(klass)->m_tbl, id, (st_data_t *)&body)) {
klass = RCLASS(klass)->super;
if (!klass) return 0;
}
if (origin) *origin = klass;
- return (NODE *)body;
+ return body;
}
static NODE*
@@ -489,7 +489,7 @@ rb_get_method_body(klassp, idp, noexp)
{
ID id = *idp;
VALUE klass = *klassp;
- VALUE origin = 0;
+ VALUE origin;
NODE * volatile body;
struct cache_entry *ent;
@@ -557,8 +557,7 @@ remove_method(klass, mid)
VALUE klass;
ID mid;
{
- st_data_t data;
- NODE *body = 0;
+ NODE *body;
if (klass == rb_cObject) {
rb_secure(4);
@@ -570,14 +569,8 @@ remove_method(klass, mid)
if (mid == __id__ || mid == __send__ || mid == init) {
rb_warn("removing `%s' may cause serious problem", rb_id2name(mid));
}
- if (st_lookup(RCLASS(klass)->m_tbl, mid, &data)) {
- body = (NODE *)data;
- if (!body || !body->nd_body) body = 0;
- else {
- st_delete(RCLASS(klass)->m_tbl, &mid, &data);
- }
- }
- if (!body) {
+ if (!st_delete(RCLASS(klass)->m_tbl, &mid, (st_data_t *)&body) ||
+ !body->nd_body) {
rb_name_error(mid, "method `%s' not defined in %s",
rb_id2name(mid), rb_class2name(klass));
}
@@ -760,7 +753,7 @@ static struct SCOPE *top_scope;
static unsigned long frame_unique = 0;
#define PUSH_FRAME() do { \
- volatile struct FRAME _frame; \
+ struct FRAME _frame; \
_frame.prev = ruby_frame; \
_frame.tmp = 0; \
_frame.node = ruby_current_node; \
@@ -1029,7 +1022,7 @@ static struct tag *prot_tag;
#define PROT_LAMBDA INT2FIX(2) /* 5 */
#define PROT_YIELD INT2FIX(3) /* 7 */
-#define EXEC_TAG() ruby_setjmp(((void)0), prot_tag->buf)
+#define EXEC_TAG() (FLUSH_REGISTER_WINDOWS, ruby_setjmp(((void)0), prot_tag->buf))
#define JUMP_TAG(st) do { \
ruby_frame = prot_tag->frame; \
@@ -1057,7 +1050,7 @@ VALUE ruby_class;
static VALUE ruby_wrapper; /* security wrapper */
#define PUSH_CLASS(c) do { \
- volatile VALUE _class = ruby_class; \
+ VALUE _class = ruby_class; \
ruby_class = (c)
#define POP_CLASS() ruby_class = _class; \
@@ -1105,8 +1098,8 @@ static void scope_dup _((struct SCOPE *));
} while (0)
static VALUE rb_eval _((VALUE,NODE*));
-static VALUE eval _((VALUE,VALUE,VALUE,const char*,int));
-static NODE *compile _((VALUE, const char*, int));
+static VALUE eval _((VALUE,VALUE,VALUE,char*,int));
+static NODE *compile _((VALUE, char*, int));
static VALUE rb_yield_0 _((VALUE, VALUE, VALUE, int, int));
@@ -1115,7 +1108,6 @@ static VALUE rb_yield_0 _((VALUE, VALUE, VALUE, int, int));
#define YIELD_PUBLIC_DEF 4
#define YIELD_FUNC_AVALUE 1
#define YIELD_FUNC_SVALUE 2
-#define YIELD_FUNC_LAMBDA 3
static VALUE rb_call _((VALUE,VALUE,ID,int,const VALUE*,int,VALUE));
static VALUE module_setup _((VALUE,NODE*));
@@ -1229,7 +1221,7 @@ error_print()
{
VALUE errat = Qnil; /* OK */
volatile VALUE eclass, e;
- const char *einfo;
+ char *einfo;
long elen;
if (NIL_P(ruby_errinfo)) return;
@@ -1290,7 +1282,7 @@ error_print()
long len = elen;
if (RSTRING(epath)->ptr[0] == '#') epath = 0;
- if ((tail = memchr(einfo, '\n', elen)) != 0) {
+ if (tail = memchr(einfo, '\n', elen)) {
len = tail - einfo;
tail++; /* skip newline */
}
@@ -1301,9 +1293,8 @@ error_print()
warn_print2(RSTRING(epath)->ptr, RSTRING(epath)->len);
warn_print(")\n");
}
- if (tail && elen>len+1) {
+ if (tail) {
warn_print2(tail, elen-len-1);
- if (einfo[elen-1] != '\n') warn_print2("\n", 1);
}
}
}
@@ -1311,7 +1302,6 @@ error_print()
if (!NIL_P(errat)) {
long i;
struct RArray *ep = RARRAY(errat);
- int truncate = eclass == rb_eSysStackError;
#define TRACE_MAX (TRACE_HEAD+TRACE_TAIL+5)
#define TRACE_HEAD 8
@@ -1322,7 +1312,7 @@ error_print()
if (TYPE(ep->ptr[i]) == T_STRING) {
warn_printf("\tfrom %s\n", RSTRING(ep->ptr[i])->ptr);
}
- if (truncate && i == TRACE_HEAD && ep->len > TRACE_MAX) {
+ if (i == TRACE_HEAD && ep->len > TRACE_MAX) {
warn_printf("\t ... %ld levels...\n",
ep->len - TRACE_HEAD - TRACE_TAIL);
i = ep->len - TRACE_TAIL;
@@ -1443,6 +1433,9 @@ int ruby_in_eval;
static void rb_thread_cleanup _((void));
static void rb_thread_wait_other_threads _((void));
+static int thread_set_raised();
+static int thread_reset_raised();
+
static int thread_no_ensure _((void));
static VALUE exception_error;
@@ -1461,10 +1454,8 @@ error_handle(ex)
int ex;
{
int status = EXIT_FAILURE;
- rb_thread_t th = curr_thread;
- if (rb_thread_set_raised(th))
- return EXIT_FAILURE;
+ if (thread_set_raised()) return EXIT_FAILURE;
switch (ex & TAG_MASK) {
case 0:
status = EXIT_SUCCESS;
@@ -1517,7 +1508,7 @@ error_handle(ex)
rb_bug("Unknown longjmp status %d", ex);
break;
}
- rb_thread_reset_raised(th);
+ thread_reset_raised();
return status;
}
@@ -2033,7 +2024,7 @@ void
rb_frozen_class_p(klass)
VALUE klass;
{
- const char *desc = "something(?!)";
+ char *desc = "something(?!)";
if (OBJ_FROZEN(klass)) {
if (FL_TEST(klass, FL_SINGLETON))
@@ -2071,7 +2062,7 @@ rb_undef(klass, id)
}
body = search_method(klass, id, &origin);
if (!body || !body->nd_body) {
- const char *s0 = " class";
+ char *s0 = " class";
VALUE c = klass;
if (FL_TEST(c, FL_SINGLETON)) {
@@ -2162,10 +2153,9 @@ rb_alias(klass, name, def)
VALUE klass;
ID name, def;
{
- VALUE origin = 0;
+ VALUE origin;
NODE *orig, *body, *node;
VALUE singleton = 0;
- st_data_t data;
rb_frozen_class_p(klass);
if (name == def) return;
@@ -2193,8 +2183,7 @@ rb_alias(klass, name, def)
}
rb_clear_cache_by_id(name);
- if (RTEST(ruby_verbose) && st_lookup(RCLASS(klass)->m_tbl, name, &data)) {
- node = (NODE *)data;
+ if (RTEST(ruby_verbose) && st_lookup(RCLASS(klass)->m_tbl, name, (st_data_t *)&node)) {
if (node->nd_cnt == 0 && node->nd_body) {
rb_warning("discarding old %s", rb_id2name(name));
}
@@ -2202,9 +2191,6 @@ rb_alias(klass, name, def)
st_insert(RCLASS(klass)->m_tbl, name,
(st_data_t)NEW_METHOD(NEW_FBODY(body, def, origin),
NOEX_WITH_SAFE(orig->nd_noex)));
-
- if (!ruby_running) return;
-
if (singleton) {
rb_funcall(singleton, singleton_added, 1, ID2SYM(name));
}
@@ -2243,8 +2229,8 @@ rb_mod_alias_method(mod, newname, oldname)
return mod;
}
-NODE *
-rb_copy_node_scope(node, rval)
+static NODE*
+copy_node_scope(node, rval)
NODE *node;
NODE *rval;
{
@@ -2323,9 +2309,9 @@ rb_copy_node_scope(node, rval)
#define MATCH_DATA *rb_svar(node->nd_cnt)
-static const char* is_defined _((VALUE, NODE*, char*));
+static char* is_defined _((VALUE, NODE*, char*));
-static const char*
+static char*
arg_defined(self, node, buf, type)
VALUE self;
NODE *node;
@@ -2352,7 +2338,7 @@ arg_defined(self, node, buf, type)
return type;
}
-static const char*
+static char*
is_defined(self, node, buf)
VALUE self;
NODE *node; /* OK */
@@ -2445,8 +2431,6 @@ is_defined(self, node, buf)
case NODE_ATTRSET:
case NODE_OP_ASGN1:
case NODE_OP_ASGN2:
- case NODE_OP_ASGN_OR:
- case NODE_OP_ASGN_AND:
case NODE_MASGN:
case NODE_LASGN:
case NODE_DASGN:
@@ -2672,27 +2656,27 @@ set_trace_func(obj, trace)
return trace;
}
-static const char *
+static char *
get_event_name(rb_event_t event)
{
switch (event) {
- case RUBY_EVENT_LINE:
+ case RUBY_EVENT_LINE:
return "line";
- case RUBY_EVENT_CLASS:
+ case RUBY_EVENT_CLASS:
return "class";
- case RUBY_EVENT_END:
+ case RUBY_EVENT_END:
return "end";
- case RUBY_EVENT_CALL:
+ case RUBY_EVENT_CALL:
return "call";
- case RUBY_EVENT_RETURN:
+ case RUBY_EVENT_RETURN:
return "return";
- case RUBY_EVENT_C_CALL:
+ case RUBY_EVENT_C_CALL:
return "c-call";
- case RUBY_EVENT_C_RETURN:
+ case RUBY_EVENT_C_RETURN:
return "c-return";
- case RUBY_EVENT_RAISE:
+ case RUBY_EVENT_RAISE:
return "raise";
- default:
+ default:
return "unknown";
}
}
@@ -2709,8 +2693,7 @@ call_trace_func(event, node, self, id, klass)
struct FRAME *prev;
NODE *node_save;
VALUE srcfile;
- const char *event_name;
- rb_thread_t th = curr_thread;
+ char *event_name;
if (!trace_func) return;
if (tracing) return;
@@ -2742,7 +2725,7 @@ call_trace_func(event, node, self, id, klass)
}
}
PUSH_TAG(PROT_NONE);
- raised = rb_thread_reset_raised(th);
+ raised = thread_reset_raised();
if ((state = EXEC_TAG()) == 0) {
srcfile = rb_str_new2(ruby_sourcefile?ruby_sourcefile:"(ruby)");
event_name = get_event_name(event);
@@ -2754,7 +2737,7 @@ call_trace_func(event, node, self, id, klass)
klass),
Qundef, 0);
}
- if (raised) rb_thread_set_raised(th);
+ if (raised) thread_set_raised();
POP_TAG();
POP_FRAME();
@@ -2946,7 +2929,6 @@ rb_eval(self, n)
NODE * volatile node = n;
int state;
volatile VALUE result = Qnil;
- st_data_t data;
#define RETURN(v) do { \
result = (v); \
@@ -3046,16 +3028,13 @@ rb_eval(self, n)
RETURN(Qfalse);
case NODE_IF:
+ EXEC_EVENT_HOOK(RUBY_EVENT_LINE, node, self,
+ ruby_frame->last_func,
+ ruby_frame->last_class);
if (RTEST(rb_eval(self, node->nd_cond))) {
- EXEC_EVENT_HOOK(RUBY_EVENT_LINE, node, self,
- ruby_frame->last_func,
- ruby_frame->last_class);
node = node->nd_body;
}
else {
- EXEC_EVENT_HOOK(RUBY_EVENT_LINE, node, self,
- ruby_frame->last_func,
- ruby_frame->last_class);
node = node->nd_else;
}
goto again;
@@ -3923,7 +3902,7 @@ rb_eval(self, n)
case NODE_DEFN:
if (node->nd_defn) {
NODE *body, *defn;
- VALUE origin = 0;
+ VALUE origin;
int noex;
if (NIL_P(ruby_class)) {
@@ -3957,7 +3936,7 @@ rb_eval(self, n)
noex |= NOEX_NOSUPER;
}
- defn = rb_copy_node_scope(node->nd_defn, ruby_cref);
+ defn = copy_node_scope(node->nd_defn, ruby_cref);
rb_add_method(ruby_class, node->nd_mid, defn, noex);
if (scope_vmode == SCOPE_MODFUNC) {
rb_add_method(rb_singleton_class(ruby_class),
@@ -3985,8 +3964,7 @@ rb_eval(self, n)
if (OBJ_FROZEN(recv)) rb_error_frozen("object");
klass = rb_singleton_class(recv);
- if (st_lookup(RCLASS(klass)->m_tbl, node->nd_mid, &data)) {
- body = (NODE *)data;
+ if (st_lookup(RCLASS(klass)->m_tbl, node->nd_mid, (st_data_t *)&body)) {
if (ruby_safe_level >= 4) {
rb_raise(rb_eSecurityError, "redefining method prohibited");
}
@@ -3994,7 +3972,7 @@ rb_eval(self, n)
rb_warning("redefine %s", rb_id2name(node->nd_mid));
}
}
- defn = rb_copy_node_scope(node->nd_defn, ruby_cref);
+ defn = copy_node_scope(node->nd_defn, ruby_cref);
rb_add_method(klass, node->nd_mid, defn,
NOEX_PUBLIC|(body?body->nd_noex&NOEX_UNDEF:0));
result = Qnil;
@@ -4138,7 +4116,7 @@ rb_eval(self, n)
case NODE_DEFINED:
{
char buf[20];
- const char *desc = is_defined(self, node->nd_head, buf);
+ char *desc = is_defined(self, node->nd_head, buf);
if (desc) result = rb_str_new2(desc);
else result = Qnil;
@@ -4235,7 +4213,7 @@ rb_obj_respond_to(obj, id, priv)
int n = 0;
args[n++] = ID2SYM(id);
if (priv) args[n++] = Qtrue;
- return RTEST(rb_funcall2(obj, respond_to, n, args));
+ return rb_funcall2(obj, respond_to, n, args);
}
}
@@ -4573,9 +4551,8 @@ rb_longjmp(tag, mesg)
VALUE mesg;
{
VALUE at;
- rb_thread_t th = curr_thread;
- if (rb_thread_set_raised(th)) {
+ if (thread_set_raised()) {
ruby_errinfo = exception_error;
JUMP_TAG(TAG_FATAL);
}
@@ -4589,9 +4566,6 @@ rb_longjmp(tag, mesg)
at = get_backtrace(mesg);
if (NIL_P(at)) {
at = make_backtrace();
- if (OBJ_FROZEN(mesg)) {
- mesg = rb_obj_dup(mesg);
- }
set_backtrace(mesg, at);
}
}
@@ -4617,7 +4591,7 @@ rb_longjmp(tag, mesg)
ruby_errinfo = mesg;
}
else if (status) {
- rb_thread_reset_raised(th);
+ thread_reset_raised();
JUMP_TAG(status);
}
}
@@ -4632,20 +4606,11 @@ rb_longjmp(tag, mesg)
if (!prot_tag) {
error_print();
}
- rb_thread_raised_clear(th);
+ thread_reset_raised();
JUMP_TAG(tag);
}
void
-rb_exc_jump(mesg)
- VALUE mesg;
-{
- rb_thread_raised_clear(rb_curr_thread);
- ruby_errinfo = mesg;
- JUMP_TAG(TAG_RAISE);
-}
-
-void
rb_exc_raise(mesg)
VALUE mesg;
{
@@ -4662,8 +4627,7 @@ rb_exc_fatal(mesg)
void
rb_interrupt()
{
- static const char fmt[1] = {'\0'};
- rb_raise(rb_eInterrupt, fmt);
+ rb_raise(rb_eInterrupt, "");
}
/*
@@ -4819,7 +4783,7 @@ proc_jump_error(state, result)
VALUE result;
{
char mesg[32];
- const char *statement;
+ char *statement;
switch (state) {
case TAG_BREAK:
@@ -4933,7 +4897,7 @@ rb_yield_0(val, self, klass, flags, avalue)
VALUE val, self, klass; /* OK */
int flags, avalue;
{
- NODE *node, *var;
+ NODE *node;
volatile VALUE result = Qnil;
volatile VALUE old_cref;
volatile VALUE old_wrapper;
@@ -4975,35 +4939,27 @@ rb_yield_0(val, self, klass, flags, avalue)
self = block->self;
}
node = block->body;
- var = block->var;
- if (var) {
+ if (block->var) {
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
- NODE *bvar = NULL;
- block_var:
- if (var == (NODE*)1) { /* no parameter || */
+ if (block->var == (NODE*)1) { /* no parameter || */
if (lambda && RARRAY(val)->len != 0) {
rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
RARRAY(val)->len);
}
}
- else if (var == (NODE*)2) {
+ else if (block->var == (NODE*)2) {
if (TYPE(val) == T_ARRAY && RARRAY(val)->len != 0) {
rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
RARRAY(val)->len);
}
}
- else if (!bvar && nd_type(var) == NODE_BLOCK_PASS) {
- bvar = var->nd_body;
- var = var->nd_args;
- goto block_var;
- }
- else if (nd_type(var) == NODE_MASGN) {
+ else if (nd_type(block->var) == NODE_MASGN) {
if (!avalue) {
- val = svalue_to_mrhs(val, var->nd_head);
+ val = svalue_to_mrhs(val, block->var->nd_head);
}
- massign(self, var, val, lambda);
+ massign(self, block->var, val, lambda);
}
else {
int len = 0;
@@ -5024,21 +4980,13 @@ rb_yield_0(val, self, klass, flags, avalue)
val = Qnil;
multi_values:
{
- ruby_current_node = var;
+ ruby_current_node = block->var;
rb_warn("multiple values for a block parameter (%d for 1)\n\tfrom %s:%d",
len, cnode->nd_file, nd_line(cnode));
ruby_current_node = cnode;
}
}
- assign(self, var, val, lambda);
- }
- if (bvar) {
- VALUE blk;
- if (flags & YIELD_PROC_CALL)
- blk = block->block_obj;
- else
- blk = rb_block_proc();
- assign(self, bvar, blk, 0);
+ assign(self, block->var, val, lambda);
}
}
POP_TAG();
@@ -5055,18 +5003,12 @@ rb_yield_0(val, self, klass, flags, avalue)
if ((state = EXEC_TAG()) == 0) {
redo:
if (nd_type(node) == NODE_CFUNC || nd_type(node) == NODE_IFUNC) {
- switch (node->nd_state) {
- case YIELD_FUNC_LAMBDA:
- if (!avalue) {
- val = rb_ary_new3(1, val);
- }
- break;
- case YIELD_FUNC_AVALUE:
+ if (node->nd_state == YIELD_FUNC_AVALUE) {
if (!avalue) {
val = svalue_to_avalue(val);
}
- break;
- default:
+ }
+ else {
if (avalue) {
val = avalue_to_svalue(val);
}
@@ -5204,16 +5146,6 @@ rb_yield_splat(values)
return rb_yield_0(values, 0, 0, 0, avalue);
}
-static VALUE
-loop_i()
-{
- for (;;) {
- rb_yield_0(Qundef, 0, 0, 0, Qfalse);
- CHECK_INTS;
- }
- return Qnil;
-}
-
/*
* call-seq:
* loop {|| block }
@@ -5226,14 +5158,15 @@ loop_i()
* break if !line or line =~ /^qQ/
* # ...
* end
- *
- * StopIteration raised in the block breaks the loop.
*/
static VALUE
rb_f_loop()
{
- rb_rescue2(loop_i, (VALUE)0, 0, 0, rb_eStopIteration, (VALUE)0);
+ for (;;) {
+ rb_yield_0(Qundef, 0, 0, 0, Qfalse);
+ CHECK_INTS;
+ }
return Qnil; /* dummy */
}
@@ -5478,7 +5411,7 @@ rb_rescue2(b_proc, data1, r_proc, data2, va_alist)
if (handle) break;
handle = Qfalse;
va_init_list(args, data2);
- while ((eclass = va_arg(args, VALUE)) != 0) {
+ while (eclass = va_arg(args, VALUE)) {
if (rb_obj_is_kind_of(ruby_errinfo, eclass)) {
handle = Qtrue;
break;
@@ -5557,7 +5490,7 @@ rb_ensure(b_proc, data1, e_proc, data2)
POP_TAG();
retval = prot_tag ? prot_tag->retval : Qnil; /* save retval */
if (!thread_no_ensure()) {
- (*e_proc)(data2);
+ (*e_proc)(data2);
}
if (prot_tag) return_value(retval);
if (state) JUMP_TAG(state);
@@ -5593,11 +5526,18 @@ rb_with_disable_interrupt(proc, data)
static void
stack_check()
{
- rb_thread_t th = rb_curr_thread;
+ static int overflowing = 0;
- if (!rb_thread_raised_p(th, RAISED_STACKOVERFLOW) && ruby_stack_check()) {
- rb_thread_raised_set(th, RAISED_STACKOVERFLOW);
- rb_exc_raise(sysstack_error);
+ if (!overflowing && ruby_stack_check()) {
+ int state;
+ overflowing = 1;
+ PUSH_TAG(PROT_NONE);
+ if ((state = EXEC_TAG()) == 0) {
+ rb_exc_raise(sysstack_error);
+ }
+ POP_TAG();
+ overflowing = 0;
+ JUMP_TAG(state);
}
}
@@ -5646,7 +5586,7 @@ rb_method_missing(argc, argv, obj)
{
ID id;
VALUE exc = rb_eNoMethodError;
- const char *format = 0;
+ char *format = 0;
NODE *cnode = ruby_current_node;
if (argc == 0 || !SYMBOL_P(argv[0])) {
@@ -5836,7 +5776,8 @@ rb_call0(klass, recv, id, oid, argc, argv, body, flags)
TMP_PROTECT;
volatile int safe = -1;
- if (NOEX_SAFE(flags) > ruby_safe_level && NOEX_SAFE(flags) > 2) {
+ if (NOEX_SAFE(flags) > ruby_safe_level &&
+ ruby_safe_level == 0 && NOEX_SAFE(flags) > 2) {
rb_raise(rb_eSecurityError, "calling insecure method: %s",
rb_id2name(id));
}
@@ -5939,7 +5880,7 @@ rb_call0(klass, recv, id, oid, argc, argv, body, flags)
}
result = proc_invoke(body->nd_cval, rb_ary_new4(argc, argv), recv, klass);
if (event_hooks) {
- EXEC_EVENT_HOOK(RUBY_EVENT_RETURN, ruby_current_node, recv, id, klass);
+ EXEC_EVENT_HOOK(RUBY_EVENT_RETURN, body, recv, id, klass);
}
break;
@@ -6062,7 +6003,7 @@ rb_call0(klass, recv, id, oid, argc, argv, body, flags)
}
POP_TAG();
if (event_hooks) {
- EXEC_EVENT_HOOK(RUBY_EVENT_RETURN, ruby_current_node, recv, id, klass);
+ EXEC_EVENT_HOOK(RUBY_EVENT_RETURN, body, recv, id, klass);
}
POP_VARS();
POP_CLASS();
@@ -6446,16 +6387,10 @@ rb_frame_last_func()
return ruby_frame->last_func;
}
-ID
-rb_frame_this_func()
-{
- return ruby_frame->orig_func;
-}
-
static NODE*
compile(src, file, line)
VALUE src;
- const char *file;
+ char *file;
int line;
{
NODE *node;
@@ -6475,7 +6410,7 @@ compile(src, file, line)
static VALUE
eval(self, src, scope, file, line)
VALUE self, src, scope;
- const char *file;
+ char *file;
int line;
{
struct BLOCK *data = NULL;
@@ -6589,17 +6524,16 @@ eval(self, src, scope, file, line)
if (state) {
if (state == TAG_RAISE) {
if (strcmp(file, "(eval)") == 0) {
- VALUE mesg, errat, bt2;
+ VALUE mesg, errat;
errat = get_backtrace(ruby_errinfo);
- mesg = rb_attr_get(ruby_errinfo, rb_intern("mesg"));
- if (!NIL_P(errat) && TYPE(errat) == T_ARRAY &&
- (bt2 = backtrace(-2), RARRAY_LEN(bt2) > 0)) {
+ mesg = rb_attr_get(ruby_errinfo, rb_intern("mesg"));
+ if (!NIL_P(errat) && TYPE(errat) == T_ARRAY) {
if (!NIL_P(mesg) && TYPE(mesg) == T_STRING) {
rb_str_update(mesg, 0, 0, rb_str_new2(": "));
- rb_str_update(mesg, 0, 0, RARRAY_PTR(errat)[0]);
+ rb_str_update(mesg, 0, 0, RARRAY(errat)->ptr[0]);
}
- RARRAY_PTR(errat)[0] = RARRAY_PTR(bt2)[0];
+ RARRAY(errat)->ptr[0] = RARRAY(backtrace(-2))->ptr[0];
}
}
rb_exc_raise(ruby_errinfo);
@@ -6636,7 +6570,7 @@ rb_f_eval(argc, argv, self)
VALUE self;
{
VALUE src, scope, vfile, vline;
- const char *file = "(eval)";
+ char *file = "(eval)";
int line = 1;
rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline);
@@ -6753,28 +6687,12 @@ yield_under_i(self)
return rb_yield_0(self, self, ruby_class, YIELD_PUBLIC_DEF, Qfalse);
}
-static VALUE
-yield_args_under_i(vinfo)
- VALUE vinfo;
-{
- VALUE *info = (VALUE *)vinfo;
-
- return rb_yield_0(info[0], info[1], ruby_class, YIELD_PUBLIC_DEF, Qtrue);
-}
-
/* block eval under the class/module context */
static VALUE
-yield_under(under, self, args)
- VALUE under, self, args;
+yield_under(under, self)
+ VALUE under, self;
{
- if (args == Qundef) {
- return exec_under(yield_under_i, under, 0, self);
- }
- else {
- VALUE info[2] = { args, self };
-
- return exec_under(yield_args_under_i, under, 0, (VALUE)info);
- }
+ return exec_under(yield_under_i, under, 0, self);
}
static VALUE
@@ -6787,10 +6705,10 @@ specific_eval(argc, argv, klass, self)
if (argc > 0) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
}
- return yield_under(klass, self, Qundef);
+ return yield_under(klass, self);
}
else {
- const char *file = "(eval)";
+ char *file = "(eval)";
int line = 1;
if (argc == 0) {
@@ -6859,41 +6777,6 @@ rb_obj_instance_eval(argc, argv, self)
/*
* call-seq:
- * obj.instance_exec(arg...) {|var...| block } => obj
- *
- * Executes the given block within the context of the receiver
- * (_obj_). In order to set the context, the variable +self+ is set
- * to _obj_ while the code is executing, giving the code access to
- * _obj_'s instance variables. Arguments are passed as block parameters.
- *
- * class KlassWithSecret
- * def initialize
- * @secret = 99
- * end
- * end
- * k = KlassWithSecret.new
- * k.instance_exec(5) {|x| @secret+x } #=> 104
- */
-
-VALUE
-rb_obj_instance_exec(argc, argv, self)
- int argc;
- VALUE *argv;
- VALUE self;
-{
- VALUE klass;
-
- if (SPECIAL_CONST_P(self)) {
- klass = Qnil;
- }
- else {
- klass = rb_singleton_class(self);
- }
- return yield_under(klass, self, rb_ary_new4(argc, argv));
-}
-
-/*
- * call-seq:
* mod.class_eval(string [, filename [, lineno]]) => obj
* mod.module_eval {|| block } => obj
*
@@ -6925,35 +6808,6 @@ rb_mod_module_eval(argc, argv, mod)
return specific_eval(argc, argv, mod, mod);
}
-/*
- * call-seq:
- * mod.module_exec(arg...) {|var...| block } => obj
- * mod.class_exec(arg...) {|var...| block } => obj
- *
- * Evaluates the given block in the context of the class/module.
- * The method defined in the block will belong to the receiver.
- *
- * class Thing
- * end
- * Thing.class_exec{
- * def hello() "Hello there!" end
- * }
- * puts Thing.new.hello()
- *
- * <em>produces:</em>
- *
- * Hello there!
- */
-
-VALUE
-rb_mod_module_exec(argc, argv, mod)
- int argc;
- VALUE *argv;
- VALUE mod;
-{
- return yield_under(mod, mod, rb_ary_new4(argc, argv));
-}
-
VALUE rb_load_path;
NORETURN(static void load_failed _((VALUE)));
@@ -6971,6 +6825,7 @@ rb_load(fname, wrap)
volatile VALUE self = ruby_top_self;
NODE *volatile last_node;
NODE *saved_cref = ruby_cref;
+ TMP_PROTECT;
if (wrap && ruby_safe_level >= 4) {
StringValue(fname);
@@ -7315,7 +7170,7 @@ search_required(fname, featurep, path)
#else
rb_str_cat2(tmp, DLEXT);
OBJ_FREEZE(tmp);
- if ((*path = rb_find_file(tmp)) != 0) {
+ if (*path = rb_find_file(tmp)) {
return 's';
}
#endif
@@ -8115,37 +7970,6 @@ rb_exec_end_proc()
ruby_safe_level = safe;
}
-/*
- * call-seq:
- * __method__ => symbol
- *
- * Returns the name of the current method as a Symbol.
- * If called from inside of an aliased method it will return the original
- * nonaliased name.
- * If called outside of a method, it returns <code>nil</code>.
- *
- * def foo
- * __method__
- * end
- * alias bar foo
- *
- * foo # => :foo
- * bar # => :foo
- *
- */
-
-static VALUE
-rb_f_method_name()
-{
- struct FRAME* prev = ruby_frame->prev;
- if (prev && prev->orig_func) {
- return ID2SYM(prev->orig_func);
- }
- else {
- return Qnil;
- }
-}
-
void
Init_eval()
{
@@ -8167,11 +7991,11 @@ Init_eval()
__id__ = rb_intern("__id__");
__send__ = rb_intern("__send__");
- rb_global_variable((void *)&top_scope);
- rb_global_variable((void *)&ruby_eval_tree_begin);
+ rb_global_variable((VALUE*)&top_scope);
+ rb_global_variable((VALUE*)&ruby_eval_tree_begin);
- rb_global_variable((void *)&ruby_eval_tree);
- rb_global_variable((void *)&ruby_dyna_vars);
+ rb_global_variable((VALUE*)&ruby_eval_tree);
+ rb_global_variable((VALUE*)&ruby_dyna_vars);
rb_define_virtual_variable("$@", errat_getter, errat_setter);
rb_define_hooked_variable("$!", &ruby_errinfo, 0, errinfo_setter);
@@ -8184,7 +8008,7 @@ Init_eval()
rb_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1);
respond_to = rb_intern("respond_to?");
- rb_global_variable((void *)&basic_respond_to);
+ rb_global_variable((VALUE*)&basic_respond_to);
basic_respond_to = rb_method_node(rb_cObject, respond_to);
rb_define_global_function("raise", rb_f_raise, -1);
@@ -8202,12 +8026,9 @@ Init_eval()
rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */
rb_define_global_function("local_variables", rb_f_local_variables, 0);
- rb_define_global_function("__method__", rb_f_method_name, 0);
-
rb_define_method(rb_mKernel, "send", rb_f_send, -1);
rb_define_method(rb_mKernel, "__send__", rb_f_send, -1);
rb_define_method(rb_mKernel, "instance_eval", rb_obj_instance_eval, -1);
- rb_define_method(rb_mKernel, "instance_exec", rb_obj_instance_exec, -1);
rb_define_private_method(rb_cModule, "append_features", rb_mod_append_features, 1);
rb_define_private_method(rb_cModule, "extend_object", rb_mod_extend_object, 1);
@@ -8223,9 +8044,7 @@ Init_eval()
rb_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1);
rb_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1);
rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1);
- rb_define_method(rb_cModule, "module_exec", rb_mod_module_exec, -1);
rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1);
- rb_define_method(rb_cModule, "class_exec", rb_mod_module_exec, -1);
rb_undef_method(rb_cClass, "module_function");
@@ -8514,42 +8333,20 @@ proc_clone(self)
* MISSING: documentation
*/
-#define PROC_TSHIFT (FL_USHIFT+1)
-#define PROC_TMASK (FL_USER1|FL_USER2|FL_USER3)
-#define PROC_TMAX (PROC_TMASK >> PROC_TSHIFT)
-
-static int proc_get_safe_level(VALUE);
-
static VALUE
proc_dup(self)
VALUE self;
{
struct BLOCK *orig, *data;
VALUE bind;
- int safe = proc_get_safe_level(self);
Data_Get_Struct(self, struct BLOCK, orig);
bind = Data_Make_Struct(rb_obj_class(self),struct BLOCK,blk_mark,blk_free,data);
blk_dup(data, orig);
- if (safe > PROC_TMAX) safe = PROC_TMAX;
- FL_SET(bind, (safe << PROC_TSHIFT) & PROC_TMASK);
return bind;
}
-VALUE
-rb_block_dup(self, klass, cref)
- VALUE self, klass, cref;
-{
- struct BLOCK *block;
- VALUE obj = proc_dup(self);
- Data_Get_Struct(obj, struct BLOCK, block);
- block->klass = klass;
- block->cref = NEW_NODE(nd_type(block->cref), cref, block->cref->u2.node,
- block->cref->u3.node);
- return obj;
-}
-
/*
* call-seq:
* binding -> a_binding
@@ -8607,34 +8404,9 @@ rb_f_binding(self)
return bind;
}
-/*
- * call-seq:
- * binding.eval(string [, filename [,lineno]]) => obj
- *
- * Evaluates the Ruby expression(s) in <em>string</em>, in the
- * <em>binding</em>'s context. If the optional <em>filename</em> and
- * <em>lineno</em> parameters are present, they will be used when
- * reporting syntax errors.
- *
- * def getBinding(param)
- * return binding
- * end
- * b = getBinding("hello")
- * b.eval("param") #=> "hello"
- */
-
-static VALUE
-bind_eval(argc, argv, bindval)
- int argc;
- VALUE *argv;
- VALUE bindval;
-{
- VALUE args[4];
-
- rb_scan_args(argc, argv, "12", &args[0], &args[2], &args[3]);
- args[1] = bindval;
- return rb_f_eval(argc+1, args, Qnil /* self will be searched in eval */);
-}
+#define PROC_TSHIFT (FL_USHIFT+1)
+#define PROC_TMASK (FL_USER1|FL_USER2|FL_USER3)
+#define PROC_TMAX (PROC_TMASK >> PROC_TSHIFT)
#define SAFE_LEVEL_MAX PROC_TMASK
@@ -8797,12 +8569,13 @@ proc_invoke(proc, args, self, klass)
volatile VALUE old_wrapper = ruby_wrapper;
volatile int pcall, avalue = Qtrue;
volatile VALUE tmp = args;
- VALUE bvar = Qnil;
if (rb_block_given_p() && ruby_frame->last_func) {
if (klass != ruby_frame->last_class)
klass = rb_obj_class(proc);
- bvar = rb_block_proc();
+ rb_warning("block for %s#%s is useless",
+ rb_class2name(klass),
+ rb_id2name(ruby_frame->last_func));
}
Data_Get_Struct(proc, struct BLOCK, data);
@@ -8818,7 +8591,6 @@ proc_invoke(proc, args, self, klass)
/* PUSH BLOCK from data */
old_block = ruby_block;
_block = *data;
- _block.block_obj = bvar;
if (self != Qundef) _block.frame.self = self;
if (klass) _block.frame.last_class = klass;
_block.frame.argc = RARRAY(tmp)->len;
@@ -8839,8 +8611,7 @@ proc_invoke(proc, args, self, klass)
state = EXEC_TAG();
if (state == 0) {
proc_set_safe_level(proc);
- result = rb_yield_0(args, self, (self!=Qundef)?CLASS_OF(self):0,
- pcall | YIELD_PROC_CALL, avalue);
+ result = rb_yield_0(args, self, (self!=Qundef)?CLASS_OF(self):0, pcall, avalue);
}
else if (TAG_DST()) {
result = prot_tag->retval;
@@ -8909,8 +8680,8 @@ proc_invoke(proc, args, self, klass)
* from prog.rb:5
*/
-VALUE
-rb_proc_call(proc, args)
+static VALUE
+proc_call(proc, args)
VALUE proc, args; /* OK */
{
return proc_invoke(proc, args, Qundef, 0);
@@ -8944,36 +8715,30 @@ proc_arity(proc)
VALUE proc;
{
struct BLOCK *data;
- NODE *var, *list;
+ NODE *list;
int n;
Data_Get_Struct(proc, struct BLOCK, data);
- var = data->var;
- if (var == 0) {
+ if (data->var == 0) {
if (data->body && nd_type(data->body) == NODE_IFUNC &&
data->body->nd_cfnc == bmcall) {
return method_arity(data->body->nd_tval);
}
return INT2FIX(-1);
}
- if (var == (NODE*)1) return INT2FIX(0);
- if (var == (NODE*)2) return INT2FIX(0);
- if (nd_type(var) == NODE_BLOCK_ARG) {
- var = var->nd_args;
- if (var == (NODE*)1) return INT2FIX(0);
- if (var == (NODE*)2) return INT2FIX(0);
- }
- switch (nd_type(var)) {
+ if (data->var == (NODE*)1) return INT2FIX(0);
+ if (data->var == (NODE*)2) return INT2FIX(0);
+ switch (nd_type(data->var)) {
default:
return INT2FIX(1);
case NODE_MASGN:
- list = var->nd_head;
+ list = data->var->nd_head;
n = 0;
while (list) {
n++;
list = list->nd_next;
}
- if (var->nd_args) return INT2FIX(-n-1);
+ if (data->var->nd_args) return INT2FIX(-n-1);
return INT2FIX(n);
}
}
@@ -9021,7 +8786,7 @@ proc_to_s(self)
{
struct BLOCK *data;
NODE *node;
- const char *cname = rb_obj_classname(self);
+ char *cname = rb_obj_classname(self);
const int w = (sizeof(VALUE) * CHAR_BIT) / 4;
long len = strlen(cname)+6+w; /* 6:tags 16:addr */
VALUE str;
@@ -9235,7 +9000,6 @@ mnew(klass, obj, id, mklass)
(FL_TEST(rklass, FL_SINGLETON) || TYPE(rklass) == T_ICLASS)) {
rklass = RCLASS(rklass)->super;
}
- if (TYPE(klass) == T_ICLASS) klass = RBASIC(klass)->klass;
method = Data_Make_Struct(mklass, struct METHOD, bm_mark, free, data);
data->klass = klass;
data->recv = obj;
@@ -9335,57 +9099,6 @@ method_unbind(obj)
/*
* call-seq:
- * meth.receiver => object
- *
- * Returns the bound receiver of the method object.
- */
-
-static VALUE
-method_receiver(obj)
- VALUE obj;
-{
- struct METHOD *data;
-
- Data_Get_Struct(obj, struct METHOD, data);
- return data->recv;
-}
-
-/*
- * call-seq:
- * meth.name => string
- *
- * Returns the name of the method.
- */
-
-static VALUE
-method_name(obj)
- VALUE obj;
-{
- struct METHOD *data;
-
- Data_Get_Struct(obj, struct METHOD, data);
- return rb_str_new2(rb_id2name(data->oid));
-}
-
-/*
- * call-seq:
- * meth.owner => class_or_module
- *
- * Returns the class or module that defines the method.
- */
-
-static VALUE
-method_owner(obj)
- VALUE obj;
-{
- struct METHOD *data;
-
- Data_Get_Struct(obj, struct METHOD, data);
- return data->klass;
-}
-
-/*
- * call-seq:
* obj.method(sym) => method
*
* Looks up the named method as a receiver in <i>obj</i>, returning a
@@ -9412,7 +9125,7 @@ method_owner(obj)
* m.call #=> "Hello, @iv = Fred"
*/
-VALUE
+static VALUE
rb_obj_method(obj, vid)
VALUE obj;
VALUE vid;
@@ -9479,29 +9192,6 @@ method_clone(self)
return clone;
}
-VALUE
-rb_method_dup(self, klass, cref)
- VALUE self;
- VALUE klass;
- VALUE cref;
-{
- VALUE clone;
- struct METHOD *orig, *data;
-
- Data_Get_Struct(self, struct METHOD, orig);
- clone = Data_Make_Struct(CLASS_OF(self),struct METHOD, bm_mark, free, data);
- *data = *orig;
- data->rklass = klass;
- if (data->body->nd_rval) {
- NODE *tmp = NEW_NODE(nd_type(data->body->u2.node), cref,
- data->body->u2.node->u2.node,
- data->body->u2.node->u3.node);
- data->body = NEW_NODE(nd_type(data->body), data->body->u1.node, tmp,
- data->body->u3.node);
- }
- return clone;
-}
-
/*
* call-seq:
* meth.call(args, ...) => obj
@@ -9755,7 +9445,7 @@ method_inspect(method)
struct METHOD *data;
VALUE str;
const char *s;
- const char *sharp = "#";
+ char *sharp = "#";
Data_Get_Struct(method, struct METHOD, data);
str = rb_str_buf_new2("#<");
@@ -9784,8 +9474,12 @@ method_inspect(method)
else {
rb_str_buf_cat2(str, rb_class2name(data->rklass));
if (data->rklass != data->klass) {
+ VALUE klass = data -> klass;
+ if (TYPE(klass) == T_ICLASS) {
+ klass = RBASIC(klass)->klass;
+ }
rb_str_buf_cat2(str, "(");
- rb_str_buf_cat2(str, rb_class2name(data->klass));
+ rb_str_buf_cat2(str, rb_class2name(klass));
rb_str_buf_cat2(str, ")");
}
}
@@ -9834,8 +9528,7 @@ rb_proc_new(func, val)
VALUE proc = rb_iterate((VALUE(*)_((VALUE)))mproc, 0, func, val);
Data_Get_Struct(proc, struct BLOCK, data);
- data->body->nd_state = YIELD_FUNC_LAMBDA;
- data->flags |= BLOCK_LAMBDA;
+ data->body->nd_state = YIELD_FUNC_AVALUE;
return proc;
}
@@ -9994,17 +9687,12 @@ Init_Proc()
rb_define_method(rb_eLocalJumpError, "reason", localjump_reason, 0);
rb_global_variable(&exception_error);
- exception_error = rb_exc_new3(rb_eFatal,
- rb_obj_freeze(rb_str_new2("exception reentered")));
- OBJ_TAINT(exception_error);
- OBJ_FREEZE(exception_error);
+ exception_error = rb_exc_new2(rb_eFatal, "exception reentered");
rb_eSysStackError = rb_define_class("SystemStackError", rb_eStandardError);
rb_global_variable(&sysstack_error);
- sysstack_error = rb_exc_new3(rb_eSysStackError,
- rb_obj_freeze(rb_str_new2("stack level too deep")));
+ sysstack_error = rb_exc_new2(rb_eSysStackError, "stack level too deep");
OBJ_TAINT(sysstack_error);
- OBJ_FREEZE(sysstack_error);
rb_cProc = rb_define_class("Proc", rb_cObject);
rb_undef_alloc_func(rb_cProc);
@@ -10012,9 +9700,9 @@ Init_Proc()
rb_define_method(rb_cProc, "clone", proc_clone, 0);
rb_define_method(rb_cProc, "dup", proc_dup, 0);
- rb_define_method(rb_cProc, "call", rb_proc_call, -2);
+ rb_define_method(rb_cProc, "call", proc_call, -2);
rb_define_method(rb_cProc, "arity", proc_arity, 0);
- rb_define_method(rb_cProc, "[]", rb_proc_call, -2);
+ rb_define_method(rb_cProc, "[]", proc_call, -2);
rb_define_method(rb_cProc, "==", proc_eq, 1);
rb_define_method(rb_cProc, "to_s", proc_to_s, 0);
rb_define_method(rb_cProc, "to_proc", proc_to_self, 0);
@@ -10034,9 +9722,6 @@ Init_Proc()
rb_define_method(rb_cMethod, "inspect", method_inspect, 0);
rb_define_method(rb_cMethod, "to_s", method_inspect, 0);
rb_define_method(rb_cMethod, "to_proc", method_proc, 0);
- rb_define_method(rb_cMethod, "receiver", method_receiver, 0);
- rb_define_method(rb_cMethod, "name", method_name, 0);
- rb_define_method(rb_cMethod, "owner", method_owner, 0);
rb_define_method(rb_cMethod, "unbind", method_unbind, 0);
rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
@@ -10048,8 +9733,6 @@ Init_Proc()
rb_define_method(rb_cUnboundMethod, "arity", method_arity, 0);
rb_define_method(rb_cUnboundMethod, "inspect", method_inspect, 0);
rb_define_method(rb_cUnboundMethod, "to_s", method_inspect, 0);
- rb_define_method(rb_cUnboundMethod, "name", method_name, 0);
- rb_define_method(rb_cUnboundMethod, "owner", method_owner, 0);
rb_define_method(rb_cUnboundMethod, "bind", umethod_bind, 1);
rb_define_method(rb_cModule, "instance_method", rb_mod_method, 1);
}
@@ -10097,7 +9780,6 @@ Init_Binding()
rb_undef_method(CLASS_OF(rb_cBinding), "new");
rb_define_method(rb_cBinding, "clone", proc_clone, 0);
rb_define_method(rb_cBinding, "dup", proc_dup, 0);
- rb_define_method(rb_cBinding, "eval", bind_eval, -1);
rb_define_global_function("binding", rb_f_binding, 0);
}
@@ -10182,9 +9864,10 @@ extern VALUE rb_last_status;
# endif
#endif
+#define THREAD_RAISED 0x200 /* temporary flag */
#define THREAD_TERMINATING 0x400 /* persistent flag */
-#define THREAD_NO_ENSURE 0x800 /* persistent flag */
-#define THREAD_FLAGS_MASK 0xfc00 /* mask for persistent flags */
+#define THREAD_NO_ENSURE 0x800 /* persistent flag */
+#define THREAD_FLAGS_MASK 0xc00 /* mask for persistent flags */
#define FOREACH_THREAD_FROM(f,x) x = f; do { x = x->next;
#define END_FOREACH_FROM(f,x) } while (x != f)
@@ -10236,25 +9919,19 @@ struct thread_status_t {
(dst)->join = (src)->join, \
0)
-int
-rb_thread_set_raised(th)
- rb_thread_t th;
+static int
+thread_set_raised()
{
- if (th->flags & RAISED_EXCEPTION) {
- return 1;
- }
- th->flags |= RAISED_EXCEPTION;
+ if (curr_thread->flags & THREAD_RAISED) return 1;
+ curr_thread->flags |= THREAD_RAISED;
return 0;
}
-int
-rb_thread_reset_raised(th)
- rb_thread_t th;
+static int
+thread_reset_raised()
{
- if (!(th->flags & RAISED_EXCEPTION)) {
- return 0;
- }
- th->flags &= ~RAISED_EXCEPTION;
+ if (!(curr_thread->flags & THREAD_RAISED)) return 0;
+ curr_thread->flags &= ~THREAD_RAISED;
return 1;
}
@@ -10365,13 +10042,6 @@ static double
timeofday()
{
struct timeval tv;
-#ifdef CLOCK_MONOTONIC
- struct timespec tp;
-
- if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
- return (double)tp.tv_sec + (double)tp.tv_nsec * 1e-9;
- }
-#endif
gettimeofday(&tv, NULL);
return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
}
@@ -10548,7 +10218,7 @@ rb_thread_save_context(th)
rb_thread_t th;
{
VALUE *pos;
- size_t len;
+ int len;
static VALUE tval;
len = ruby_stack_length(&pos);
@@ -10652,7 +10322,7 @@ rb_thread_switch(n)
}
#define THREAD_SAVE_CONTEXT(th) \
- (rb_thread_switch(ruby_setjmp(rb_thread_save_context(th), (th)->context)))
+ (rb_thread_switch((FLUSH_REGISTER_WINDOWS, ruby_setjmp(rb_thread_save_context(th), (th)->context))))
NORETURN(static void rb_thread_restore_context _((rb_thread_t,int)));
NORETURN(NOINLINE(static void rb_thread_restore_context_0(rb_thread_t,int,void*)));
@@ -10957,7 +10627,6 @@ rb_thread_schedule()
}
#endif
rb_thread_pending = 0;
- rb_gc_finalize_deferred();
if (curr_thread == curr_thread->next
&& curr_thread->status == THREAD_RUNNABLE)
return;
@@ -11400,7 +11069,7 @@ rb_thread_join(th, limit)
if (!rb_thread_dead(th)) return Qfalse;
}
- if (!NIL_P(th->errinfo) && (th->flags & RAISED_EXCEPTION)) {
+ if (!NIL_P(th->errinfo) && (th->flags & THREAD_RAISED)) {
VALUE oldbt = get_backtrace(th->errinfo);
VALUE errat = make_backtrace();
VALUE errinfo = rb_obj_dup(th->errinfo);
@@ -12007,6 +11676,15 @@ rb_thread_abort_exc_set(thread, val)
}
+enum rb_thread_status
+rb_thread_status(thread)
+ VALUE thread;
+{
+ rb_thread_t th = rb_thread_check(thread);
+ return th->status;
+}
+
+
/*
* call-seq:
* thr.group => thgrp or nil
@@ -12100,7 +11778,7 @@ rb_thread_alloc(klass)
return th;
}
-static int thread_init;
+static int thread_init = 0;
#if defined(_THREAD_SAFE)
static void
@@ -12113,12 +11791,19 @@ catch_timer(sig)
/* cause EINTR */
}
+static int time_thread_alive_p = 0;
static pthread_t time_thread;
static void*
thread_timer(dummy)
void *dummy;
{
+#ifdef _THREAD_SAFE
+#define test_cancel() pthread_testcancel()
+#else
+#define test_cancel() /* void */
+#endif
+
sigset_t all_signals;
sigfillset(&all_signals);
@@ -12128,11 +11813,14 @@ thread_timer(dummy)
#ifdef HAVE_NANOSLEEP
struct timespec req, rem;
+ test_cancel();
req.tv_sec = 0;
req.tv_nsec = 10000000;
nanosleep(&req, &rem);
#else
struct timeval tv;
+
+ test_cancel();
tv.tv_sec = 0;
tv.tv_usec = 10000;
select(0, NULL, NULL, NULL, &tv);
@@ -12144,6 +11832,7 @@ thread_timer(dummy)
}
}
}
+#undef test_cancel
}
void
@@ -12155,6 +11844,26 @@ void
rb_thread_stop_timer()
{
}
+
+void
+rb_child_atfork()
+{
+ time_thread_alive_p = 0;
+}
+
+void
+rb_thread_cancel_timer()
+{
+#ifdef _THREAD_SAFE
+ if( time_thread_alive_p )
+ {
+ pthread_cancel( time_thread );
+ pthread_join( time_thread, NULL );
+ time_thread_alive_p = 0;
+ }
+ thread_init = 0;
+#endif
+}
#elif defined(HAVE_SETITIMER)
static void
catch_timer(sig)
@@ -12192,8 +11901,19 @@ rb_thread_stop_timer()
tval.it_value = tval.it_interval;
setitimer(ITIMER_VIRTUAL, &tval, NULL);
}
+
+void
+rb_thread_cancel_timer()
+{
+}
+
#else /* !(_THREAD_SAFE || HAVE_SETITIMER) */
int rb_thread_tick = THREAD_TICK;
+
+void
+rb_thread_cancel_timer()
+{
+}
#endif
static VALUE
@@ -12224,6 +11944,8 @@ rb_thread_start_0(fn, arg, th)
#ifdef _THREAD_SAFE
pthread_create(&time_thread, 0, thread_timer, 0);
+ time_thread_alive_p = 1;
+ pthread_atfork(0, 0, rb_child_atfork);
#else
rb_thread_start_timer();
#endif
@@ -12276,7 +11998,7 @@ rb_thread_start_0(fn, arg, th)
}
if (state && status != THREAD_TO_KILL && !NIL_P(ruby_errinfo)) {
- th->flags |= RAISED_EXCEPTION;
+ th->flags |= THREAD_RAISED;
if (state == TAG_FATAL) {
/* fatal error within this thread, need to stop whole script */
main_thread->errinfo = ruby_errinfo;
@@ -12313,7 +12035,7 @@ rb_thread_create(fn, arg)
VALUE (*fn)();
void *arg;
{
- Init_stack((void *)&arg);
+ Init_stack((VALUE*)&arg);
return rb_thread_start_0(fn, arg, rb_thread_alloc(rb_cThread));
}
@@ -12488,13 +12210,13 @@ rb_thread_value(thread)
*/
static VALUE
-rb_thread_status(thread)
+rb_thread_status_name(thread)
VALUE thread;
{
rb_thread_t th = rb_thread_check(thread);
if (rb_thread_dead(th)) {
- if (!NIL_P(th->errinfo) && (th->flags & RAISED_EXCEPTION))
+ if (!NIL_P(th->errinfo) && (th->flags & THREAD_RAISED))
return Qnil;
return Qfalse;
}
@@ -12948,7 +12670,7 @@ static VALUE
rb_thread_inspect(thread)
VALUE thread;
{
- const char *cname = rb_obj_classname(thread);
+ char *cname = rb_obj_classname(thread);
rb_thread_t th = rb_thread_check(thread);
const char *status = thread_status_name(th->status);
VALUE str;
@@ -13303,109 +13025,6 @@ thgroup_add(group, thread)
}
-/* variables for recursive traversals */
-static ID recursive_key;
-
-static VALUE
-recursive_check(hash, obj)
- VALUE hash;
- VALUE obj;
-{
- if (NIL_P(hash) || TYPE(hash) != T_HASH) {
- return Qfalse;
- }
- else {
- VALUE list = rb_hash_aref(hash, ID2SYM(rb_frame_last_func()));
-
- if (NIL_P(list) || TYPE(list) != T_HASH)
- return Qfalse;
- if (NIL_P(rb_hash_lookup(list, obj)))
- return Qfalse;
- return Qtrue;
- }
-}
-
-static VALUE
-recursive_push(hash, obj)
- VALUE hash;
- VALUE obj;
-{
- VALUE list, sym;
-
- sym = ID2SYM(rb_frame_last_func());
- if (NIL_P(hash) || TYPE(hash) != T_HASH) {
- hash = rb_hash_new();
- rb_thread_local_aset(rb_thread_current(), recursive_key, hash);
- list = Qnil;
- }
- else {
- list = rb_hash_aref(hash, sym);
- }
- if (NIL_P(list) || TYPE(list) != T_HASH) {
- list = rb_hash_new();
- rb_hash_aset(hash, sym, list);
- }
- rb_hash_aset(list, obj, Qtrue);
- return hash;
-}
-
-static void
-recursive_pop(hash, obj)
- VALUE hash;
- VALUE obj;
-{
- VALUE list, sym;
-
- sym = ID2SYM(rb_frame_last_func());
- if (NIL_P(hash) || TYPE(hash) != T_HASH) {
- VALUE symname;
- VALUE thrname;
- symname = rb_inspect(sym);
- thrname = rb_inspect(rb_thread_current());
-
- rb_raise(rb_eTypeError, "invalid inspect_tbl hash for %s in %s",
- StringValuePtr(symname), StringValuePtr(thrname));
- }
- list = rb_hash_aref(hash, sym);
- if (NIL_P(list) || TYPE(list) != T_HASH) {
- VALUE symname = rb_inspect(sym);
- VALUE thrname = rb_inspect(rb_thread_current());
- rb_raise(rb_eTypeError, "invalid inspect_tbl list for %s in %s",
- StringValuePtr(symname), StringValuePtr(thrname));
- }
- rb_hash_delete(list, obj);
-}
-
-VALUE
-rb_exec_recursive(func, obj, arg)
- VALUE (*func) _((VALUE, VALUE, int));
- VALUE obj;
- VALUE arg;
-{
- VALUE hash = rb_thread_local_aref(rb_thread_current(), recursive_key);
- VALUE objid = rb_obj_id(obj);
-
- if (recursive_check(hash, objid)) {
- return (*func) (obj, arg, Qtrue);
- }
- else {
- VALUE result = Qundef;
- int state;
-
- hash = recursive_push(hash, objid);
- PUSH_TAG(PROT_NONE);
- if ((state = EXEC_TAG()) == 0) {
- result = (*func) (obj, arg, Qfalse);
- }
- POP_TAG();
- recursive_pop(hash, objid);
- if (state)
- JUMP_TAG(state);
- return result;
- }
-}
-
-
/*
* +Thread+ encapsulates the behavior of a thread of
* execution, including the main thread of the Ruby script.
@@ -13420,7 +13039,6 @@ Init_Thread()
{
VALUE cThGroup;
- recursive_key = rb_intern("__recursive_key__");
rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
rb_cThread = rb_define_class("Thread", rb_cObject);
rb_undef_alloc_func(rb_cThread);
@@ -13453,7 +13071,7 @@ Init_Thread()
rb_define_method(rb_cThread, "terminate!", rb_thread_kill_bang, 0);
rb_define_method(rb_cThread, "exit!", rb_thread_kill_bang, 0);
rb_define_method(rb_cThread, "value", rb_thread_value, 0);
- rb_define_method(rb_cThread, "status", rb_thread_status, 0);
+ rb_define_method(rb_cThread, "status", rb_thread_status_name, 0);
rb_define_method(rb_cThread, "join", rb_thread_join_m, -1);
rb_define_method(rb_cThread, "alive?", rb_thread_alive_p, 0);
rb_define_method(rb_cThread, "stop?", rb_thread_stop_p, 0);
diff --git a/ext/Win32API/lib/win32/registry.rb b/ext/Win32API/lib/win32/registry.rb
index 9a2f3827b7..2671551a33 100644
--- a/ext/Win32API/lib/win32/registry.rb
+++ b/ext/Win32API/lib/win32/registry.rb
@@ -493,7 +493,7 @@ module Win32
# utility functions
#
def self.expand_environ(str)
- str.gsub(/%([^%]+)%/) { ENV[$1] || ENV[$1.upcase] || $& }
+ str.gsub(/%([^%]+)%/) { ENV[$1] || $& }
end
@@type2name = { }
diff --git a/ext/Win32API/lib/win32/resolv.rb b/ext/Win32API/lib/win32/resolv.rb
index 92336fac28..6534d20760 100644
--- a/ext/Win32API/lib/win32/resolv.rb
+++ b/ext/Win32API/lib/win32/resolv.rb
@@ -11,7 +11,7 @@ module Win32
def self.get_hosts_path
path = get_hosts_dir
- path = File.expand_path('hosts', path)
+ path = File.join(path.gsub(/\\/, File::SEPARATOR), 'hosts')
File.exist?(path) ? path : nil
end
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 636c0907d6..a4b769e8cf 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -586,22 +586,19 @@ BigDecimal_to_f(VALUE self)
{
ENTER(1);
Real *p;
- double d;
+ double d, d2;
S_LONG e;
- char *buf;
GUARD_OBJ(p,GetVpValue(self,1));
if(VpVtoD(&d, &e, p)!=1) return rb_float_new(d);
- buf = ALLOCA_N(char,(unsigned int)VpNumOfChars(p,"E"));
- VpToString(p, buf, 0, 0);
errno = 0;
- d = strtod(buf, 0);
- if(errno == ERANGE) {
+ d2 = pow(10.0,(double)e);
+ if((errno == ERANGE && e>0) || (d2>1.0 && (fabs(d) > (DBL_MAX / d2)))) {
VpException(VP_EXCEPTION_OVERFLOW,"BigDecimal to Float conversion",0);
if(d>0.0) return rb_float_new(DBL_MAX);
else return rb_float_new(-DBL_MAX);
}
- return rb_float_new(d);
+ return rb_float_new(d*d2);
}
/* The coerce method provides support for Ruby type coercion. It is not
@@ -1054,7 +1051,7 @@ static VALUE
BigDecimal_remainder(VALUE self, VALUE r) /* remainder */
{
VALUE f;
- Real *d,*rv=0;
+ Real *d,*rv;
f = BigDecimal_divremain(self,r,&d,&rv);
if(f!=(VALUE)0) return f;
return ToValue(rv);
@@ -1508,7 +1505,7 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
} else if(*psz=='+') {
fPlus = 2; psz++;
}
- while((ch=*psz++)!=0) {
+ while(ch=*psz++) {
if(ISSPACE(ch)) continue;
if(!ISDIGIT(ch)) {
if(ch=='F' || ch=='f') fmt = 1; /* F format */
@@ -1965,27 +1962,17 @@ static int gfCheckVal = 1; /* Value checking flag in VpNmlz() */
static U_LONG gnPrecLimit = 0; /* Global upper limit of the precision newly allocated */
static U_LONG gfRoundMode = VP_ROUND_HALF_UP; /* Mode for general rounding operation */
-#ifndef BASE_FIG
static U_LONG BASE_FIG = 4; /* =log10(BASE) */
static U_LONG BASE = 10000L; /* Base value(value must be 10**BASE_FIG) */
/* The value of BASE**2 + BASE must be represented */
/* within one U_LONG. */
static U_LONG HALF_BASE = 5000L;/* =BASE/2 */
+static S_LONG DBLE_FIG = 8; /* figure of double */
static U_LONG BASE1 = 1000L; /* =BASE/10 */
-#else
-#ifndef BASE
-#error BASE_FIG is defined but BASE is not
-#endif
-#define HALF_BASE (BASE/2)
-#define BASE1 (BASE/10)
-#endif
-#ifndef DBLE_FIG
-#define DBLE_FIG (DBL_DIG+1) /* figure of double */
-#endif
static Real *VpConstOne; /* constant 1.0 */
static Real *VpPt5; /* constant 0.5 */
-#define maxnr 100UL /* Maximum iterations for calcurating sqrt. */
+static U_LONG maxnr = 100; /* Maximum iterations for calcurating sqrt. */
/* used in VpSqrt() */
/* ETC */
@@ -2102,8 +2089,8 @@ VpSetRoundMode(unsigned long n)
* (to let the compiler know they may be changed in outside
* (... but not actually..)).
*/
-volatile const double gZero_ABCED9B1_CE73__00400511F31D = 0.0;
-volatile const double gOne_ABCED9B4_CE73__00400511F31D = 1.0;
+volatile double gZero_ABCED9B1_CE73__00400511F31D = 0.0;
+volatile double gOne_ABCED9B4_CE73__00400511F31D = 1.0;
static double
Zero(void)
{
@@ -2375,15 +2362,16 @@ VpNumOfChars(Real *vp,const char *pszFmt)
VP_EXPORT U_LONG
VpInit(U_LONG BaseVal)
{
+ U_LONG w;
+ double v;
+
/* Setup +/- Inf NaN -0 */
VpGetDoubleNaN();
VpGetDoublePosInf();
VpGetDoubleNegInf();
VpGetDoubleNegZero();
-#ifndef BASE_FIG
if(BaseVal <= 0) {
- U_LONG w;
/* Base <= 0, then determine Base by calcuration. */
BASE = 1;
while(
@@ -2400,8 +2388,6 @@ VpInit(U_LONG BaseVal)
BASE1 = BASE / 10;
BASE_FIG = 0;
while(BaseVal /= 10) ++BASE_FIG;
-#endif
-
/* Allocates Vp constants. */
VpConstOne = VpAlloc((U_LONG)1, "1");
VpPt5 = VpAlloc((U_LONG)1, ".5");
@@ -2410,6 +2396,15 @@ VpInit(U_LONG BaseVal)
gnAlloc = 0;
#endif /* _DEBUG */
+ /* Determine # of digits available in one 'double'. */
+
+ v = 1.0;
+ DBLE_FIG = 0;
+ while(v + 1.0 > 1.0) {
+ ++DBLE_FIG;
+ v /= 10;
+ }
+
#ifdef _DEBUG
if(gfDebug) {
printf("VpInit: BaseVal = %lu\n", BaseVal);
@@ -2512,7 +2507,7 @@ VpAlloc(U_LONG mx, const char *szVal)
psz = ALLOCA_N(char,strlen(szVal)+1);
i = 0;
ipn = 0;
- while((psz[i]=szVal[ipn])!=0) {
+ while(psz[i]=szVal[ipn]) {
if(ISDIGIT(psz[i])) ++ni;
if(psz[i]=='_') {
if(ni>0) {ipn++;continue;}
@@ -2555,7 +2550,7 @@ VpAlloc(U_LONG mx, const char *szVal)
else if(szVal[i] == '+') ++i;
/* Skip digits */
ni = 0; /* digits in mantissa */
- while((v = szVal[i]) != 0) {
+ while(v = szVal[i]) {
if(!ISDIGIT(v)) break;
++i;
++ni;
@@ -2569,7 +2564,7 @@ VpAlloc(U_LONG mx, const char *szVal)
if(szVal[i] == '.') { /* xxx. */
++i;
ipf = i;
- while((v = szVal[i]) != 0) { /* get fraction part. */
+ while(v = szVal[i]) { /* get fraction part. */
if(!ISDIGIT(v)) break;
++i;
++nf;
@@ -2587,7 +2582,7 @@ VpAlloc(U_LONG mx, const char *szVal)
ipe = i;
v = szVal[i];
if((v == '-') ||(v == '+')) ++i;
- while((v=szVal[i])!=0) {
+ while(v=szVal[i]) {
if(!ISDIGIT(v)) break;
++i;
++ne;
@@ -4439,7 +4434,7 @@ VpLeftRound(Real *y, int f, int nf)
if(!VpHasVal(y)) return 0; /* Unable to round */
v = y->frac[0];
nf -= VpExponent(y)*BASE_FIG;
- while((v /= 10) != 0) nf--;
+ while(v=v/10) nf--;
nf += (BASE_FIG-1);
return VpMidRound(y,f,nf);
}
diff --git a/ext/bigdecimal/extconf.rb b/ext/bigdecimal/extconf.rb
index 0c8b98e4a3..a68a656044 100644
--- a/ext/bigdecimal/extconf.rb
+++ b/ext/bigdecimal/extconf.rb
@@ -1,10 +1,2 @@
require 'mkmf'
-
-base_fig = 0
-src = "(BASE * (BASE+1)) / BASE == (BASE+1)"
-while try_static_assert(src, nil, "-DBASE=10#{'0'*base_fig}UL")
- base_fig += 1
-end
-$defs << "-DBASE=1#{'0'*base_fig}UL" << "-DBASE_FIG=#{base_fig}"
-
create_makefile('bigdecimal')
diff --git a/ext/curses/extconf.rb b/ext/curses/extconf.rb
index 0124bbbf4a..01fe971093 100644
--- a/ext/curses/extconf.rb
+++ b/ext/curses/extconf.rb
@@ -20,7 +20,7 @@ end
if make
for f in %w(beep bkgd bkgdset curs_set deleteln doupdate flash getbkgd getnstr init isendwin keyname keypad resizeterm scrl set setscrreg ungetch wattroff wattron wattrset wbkgd wbkgdset wdeleteln wgetnstr wresize wscrl wsetscrreg def_prog_mode reset_prog_mode timeout wtimeout nodelay init_color wcolor_set)
- have_func(f) || (have_macro(f, curses) && $defs.push(format("-DHAVE_%s", f.upcase)))
+ have_func(f)
end
flag = "-D_XOPEN_SOURCE_EXTENDED"
src = "int test_var[(sizeof(char*)>sizeof(int))*2-1];"
diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c
index 0247387fdc..69b7a6e7a7 100644
--- a/ext/dbm/dbm.c
+++ b/ext/dbm/dbm.c
@@ -812,7 +812,5 @@ Init_dbm()
#ifdef DB_VERSION_STRING
rb_define_const(rb_cDBM, "VERSION", rb_str_new2(DB_VERSION_STRING));
-#else
- rb_define_const(rb_cDBM, "VERSION", rb_str_new2("unknown"));
#endif
}
diff --git a/ext/dl/dl.c b/ext/dl/dl.c
index f65247be86..5ba3646ea3 100644
--- a/ext/dl/dl.c
+++ b/ext/dl/dl.c
@@ -522,15 +522,12 @@ rb_str_to_ptr(VALUE self)
{
char *ptr;
int len;
- VALUE p;
len = RSTRING(self)->len;
ptr = (char*)dlmalloc(len + 1);
memcpy(ptr, RSTRING(self)->ptr, len);
ptr[len] = '\0';
- p = rb_dlptr_new((void*)ptr,len,dlfree);
- OBJ_INFECT(p, self);
- return p;
+ return rb_dlptr_new((void*)ptr,len,dlfree);
}
VALUE
@@ -548,18 +545,13 @@ rb_ary_to_ptr(int argc, VALUE argv[], VALUE self)
ptr = rb_ary2cary(0, self, &size);
break;
}
- if (ptr) {
- VALUE p = rb_dlptr_new(ptr, size, dlfree);
- OBJ_INFECT(p, self);
- return p;
- }
- return Qnil;
+ return ptr ? rb_dlptr_new(ptr, size, dlfree) : Qnil;
}
VALUE
rb_io_to_ptr(VALUE self)
{
- rb_io_t *fptr;
+ OpenFile *fptr;
FILE *fp;
GetOpenFile(self, fptr);
@@ -571,7 +563,7 @@ rb_io_to_ptr(VALUE self)
VALUE
rb_dl_dlopen(int argc, VALUE argv[], VALUE self)
{
- rb_secure(2);
+ rb_secure(4);
return rb_class_new_instance(argc, argv, rb_cDLHandle);
}
diff --git a/ext/dl/ptr.c b/ext/dl/ptr.c
index 01eb31da20..5112151733 100644
--- a/ext/dl/ptr.c
+++ b/ext/dl/ptr.c
@@ -4,22 +4,30 @@
#include <ruby.h>
#include <ctype.h>
-#include "st.h"
+#include <version.h> /* for ruby version code */
#include "dl.h"
VALUE rb_cDLPtrData;
VALUE rb_mDLMemorySpace;
-static st_table* st_memory_table;
+static VALUE DLMemoryTable;
#ifndef T_SYMBOL
# define T_SYMBOL T_FIXNUM
#endif
+#if RUBY_VERSION_CODE < 171
+static VALUE
+rb_hash_delete(VALUE hash, VALUE key)
+{
+ return rb_funcall(hash, rb_intern("delete"), 1, key);
+}
+#endif
+
static void
rb_dlmem_delete(void *ptr)
{
rb_secure(4);
- st_delete(st_memory_table, (st_data_t*)&ptr, NULL);
+ rb_hash_delete(DLMemoryTable, DLLONG2NUM(ptr));
}
static void
@@ -29,7 +37,7 @@ rb_dlmem_aset(void *ptr, VALUE obj)
rb_dlmem_delete(ptr);
}
else{
- st_insert(st_memory_table, (st_data_t)ptr, (st_data_t)obj);
+ rb_hash_aset(DLMemoryTable, DLLONG2NUM(ptr), DLLONG2NUM(obj));
}
}
@@ -38,8 +46,8 @@ rb_dlmem_aref(void *ptr)
{
VALUE val;
- if(!st_lookup(st_memory_table, (st_data_t)ptr, &val)) return Qnil;
- return val == Qundef ? Qnil : val;
+ val = rb_hash_aref(DLMemoryTable, DLLONG2NUM(ptr));
+ return val == Qnil ? Qnil : (VALUE)DLNUM2LONG(val);
}
void
@@ -336,7 +344,7 @@ rb_dlptr_to_array(int argc, VALUE argv[], VALUE self)
n = data->size / sizeof(void*);
break;
case 'S': case 's':
- n = data->size / sizeof(char*);
+ for (n=0; ((void**)(data->ptr))[n]; n++) {};
break;
default:
n = 0;
@@ -1002,18 +1010,20 @@ rb_dlptr_size(int argc, VALUE argv[], VALUE self)
}
}
-static int
-dlmem_each_i(void* key, VALUE value, void* arg)
+static VALUE
+dlmem_each_i(VALUE assoc, void *data)
{
- VALUE vkey = DLLONG2NUM(key);
- rb_yield(rb_assoc_new(vkey, value));
+ VALUE key, val;
+ key = rb_ary_entry(assoc, 0);
+ val = rb_ary_entry(assoc, 1);
+ rb_yield(rb_assoc_new(key,(VALUE)DLNUM2LONG(val)));
return Qnil;
}
VALUE
rb_dlmem_each(VALUE self)
{
- st_foreach(st_memory_table, dlmem_each_i, 0);
+ rb_iterate(rb_each, DLMemoryTable, dlmem_each_i, 0);
return Qnil;
}
@@ -1052,7 +1062,7 @@ Init_dlptr()
rb_define_method(rb_cDLPtrData, "size=", rb_dlptr_size, -1);
rb_mDLMemorySpace = rb_define_module_under(rb_mDL, "MemorySpace");
- st_memory_table = st_init_numtable();
- rb_define_const(rb_mDLMemorySpace, "MemoryTable", Qnil); /* historical */
+ DLMemoryTable = rb_hash_new();
+ rb_define_const(rb_mDLMemorySpace, "MemoryTable", DLMemoryTable);
rb_define_module_function(rb_mDLMemorySpace, "each", rb_dlmem_each, 0);
}
diff --git a/ext/dl/sym.c b/ext/dl/sym.c
index 933fb7f4f0..01e0474f58 100644
--- a/ext/dl/sym.c
+++ b/ext/dl/sym.c
@@ -492,7 +492,6 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
rb_raise(rb_eDLTypeError, "unexpected type of argument #%d", i);
}
}
- rb_check_safe_obj(pval);
Data_Get_Struct(pval, struct ptr_data, data);
ANY2P(args[i]) = DLVOIDP(data->ptr);
}
diff --git a/ext/enumerator/.cvsignore b/ext/enumerator/.cvsignore
new file mode 100644
index 0000000000..fc802ff1c2
--- /dev/null
+++ b/ext/enumerator/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+mkmf.log
diff --git a/ext/enumerator/enumerator.c b/ext/enumerator/enumerator.c
new file mode 100644
index 0000000000..1c6e1d1ace
--- /dev/null
+++ b/ext/enumerator/enumerator.c
@@ -0,0 +1,298 @@
+/************************************************
+
+ enumerator.c - provides Enumerator class
+
+ $Author$
+
+ Copyright (C) 2001-2003 Akinori MUSHA
+
+ $Idaemons: /home/cvs/rb/enumerator/enumerator.c,v 1.1.1.1 2001/07/15 10:12:48 knu Exp $
+ $RoughId: enumerator.c,v 1.6 2003/07/27 11:03:24 nobu Exp $
+ $Id$
+
+************************************************/
+
+#include "ruby.h"
+#include "node.h"
+
+/*
+ * Document-class: Enumerable::Enumerator
+ *
+ * A class which provides a method `each' to be used as an Enumerable
+ * object.
+ */
+static VALUE rb_cEnumerator;
+static ID sym_each, sym_each_with_index, sym_each_slice, sym_each_cons;
+static ID id_new, id_enum_obj, id_enum_method, id_enum_args;
+
+/*
+ * call-seq:
+ * obj.to_enum(method = :each, *args)
+ * obj.enum_for(method = :each, *args)
+ *
+ * Returns Enumerable::Enumerator.new(self, method, *args).
+ *
+ * e.g.:
+ * str = "xyz"
+ *
+ * enum = str.enum_for(:each_byte)
+ * a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
+ *
+ * # protects an array from being modified
+ * a = [1, 2, 3]
+ * some_method(a.to_enum)
+ *
+ */
+static VALUE
+obj_to_enum(obj, enum_args)
+ VALUE obj, enum_args;
+{
+ rb_ary_unshift(enum_args, obj);
+
+ return rb_apply(rb_cEnumerator, id_new, enum_args);
+}
+
+/*
+ * call-seq:
+ * enum_with_index
+ *
+ * Returns Enumerable::Enumerator.new(self, :each_with_index).
+ *
+ */
+static VALUE
+enumerator_enum_with_index(obj)
+ VALUE obj;
+{
+ return rb_funcall(rb_cEnumerator, id_new, 2, obj, sym_each_with_index);
+}
+
+static VALUE
+each_slice_i(val, memo)
+ VALUE val;
+ NODE *memo;
+{
+ VALUE ary = memo->u1.value;
+ long size = memo->u3.cnt;
+
+ rb_ary_push(ary, val);
+
+ if (RARRAY(ary)->len == size) {
+ rb_yield(ary);
+ memo->u1.value = rb_ary_new2(size);
+ }
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * e.each_slice(n) {...}
+ *
+ * Iterates the given block for each slice of <n> elements.
+ *
+ * e.g.:
+ * (1..10).each_slice(3) {|a| p a}
+ * # outputs below
+ * [1, 2, 3]
+ * [4, 5, 6]
+ * [7, 8, 9]
+ * [10]
+ *
+ */
+static VALUE
+enum_each_slice(obj, n)
+ VALUE obj, n;
+{
+ long size = NUM2LONG(n);
+ NODE *memo;
+ VALUE ary;
+
+ if (size <= 0) rb_raise(rb_eArgError, "invalid slice size");
+
+ memo = rb_node_newnode(NODE_MEMO, rb_ary_new2(size), 0, size);
+
+ rb_iterate(rb_each, obj, each_slice_i, (VALUE)memo);
+
+ ary = memo->u1.value;
+ if (RARRAY(ary)->len > 0) rb_yield(ary);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * e.enum_slice(n)
+ *
+ * Returns Enumerable::Enumerator.new(self, :each_slice, n).
+ *
+ */
+static VALUE
+enumerator_enum_slice(obj, n)
+ VALUE obj, n;
+{
+ return rb_funcall(rb_cEnumerator, id_new, 3, obj, sym_each_slice, n);
+}
+
+static VALUE
+each_cons_i(val, memo)
+ VALUE val;
+ NODE *memo;
+{
+ VALUE ary = memo->u1.value;
+ long size = memo->u3.cnt;
+
+ if (RARRAY(ary)->len == size) {
+ rb_ary_shift(ary);
+ }
+ rb_ary_push(ary, val);
+ if (RARRAY(ary)->len == size) {
+ rb_yield(rb_ary_dup(ary));
+ }
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * each_cons(n) {...}
+ *
+ * Iterates the given block for each array of consecutive <n>
+ * elements.
+ *
+ * e.g.:
+ * (1..10).each_cons(3) {|a| p a}
+ * # outputs below
+ * [1, 2, 3]
+ * [2, 3, 4]
+ * [3, 4, 5]
+ * [4, 5, 6]
+ * [5, 6, 7]
+ * [6, 7, 8]
+ * [7, 8, 9]
+ * [8, 9, 10]
+ *
+ */
+static VALUE
+enum_each_cons(obj, n)
+ VALUE obj, n;
+{
+ long size = NUM2LONG(n);
+ NODE *memo;
+
+ if (size <= 0) rb_raise(rb_eArgError, "invalid size");
+ memo = rb_node_newnode(NODE_MEMO, rb_ary_new2(size), 0, size);
+
+ rb_iterate(rb_each, obj, each_cons_i, (VALUE)memo);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * e.enum_cons(n)
+ *
+ * Returns Enumerable::Enumerator.new(self, :each_cons, n).
+ *
+ */
+static VALUE
+enumerator_enum_cons(obj, n)
+ VALUE obj, n;
+{
+ return rb_funcall(rb_cEnumerator, id_new, 3, obj, sym_each_cons, n);
+}
+
+/*
+ * call-seq:
+ * Enumerable::Enumerator.new(obj, method = :each, *args)
+ *
+ * Creates a new Enumerable::Enumerator object, which is to be
+ * used as an Enumerable object using the given object's given
+ * method with the given arguments.
+ *
+ * e.g.:
+ * str = "xyz"
+ *
+ * enum = Enumerable::Enumerator.new(str, :each_byte)
+ * a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
+ *
+ */
+static VALUE
+enumerator_initialize(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
+{
+ VALUE enum_obj, enum_method, enum_args;
+
+ rb_scan_args(argc, argv, "11*", &enum_obj, &enum_method, &enum_args);
+
+ if (enum_method == Qnil)
+ enum_method = sym_each;
+
+ rb_ivar_set(obj, id_enum_obj, enum_obj);
+ rb_ivar_set(obj, id_enum_method, enum_method);
+ rb_ivar_set(obj, id_enum_args, enum_args);
+
+ return Qnil;
+}
+
+static VALUE
+enumerator_iter(memo)
+ NODE *memo;
+{
+ return rb_apply(memo->u1.value, memo->u2.id, memo->u3.value);
+}
+
+/*
+ * call-seq:
+ * enum.each {...}
+ *
+ * Iterates the given block using the object and the method specified
+ * in the first place.
+ *
+ */
+static VALUE
+enumerator_each(obj)
+ VALUE obj;
+{
+ VALUE val;
+
+ obj = (VALUE)rb_node_newnode(NODE_MEMO,
+ rb_ivar_get(obj, id_enum_obj),
+ rb_to_id(rb_ivar_get(obj, id_enum_method)),
+ rb_ivar_get(obj, id_enum_args));
+ val = rb_iterate((VALUE (*)_((VALUE)))enumerator_iter, obj, rb_yield, 0);
+ return val;
+}
+
+void
+Init_enumerator()
+{
+ VALUE rb_mEnumerable;
+
+ rb_define_method(rb_mKernel, "to_enum", obj_to_enum, -2);
+ rb_define_method(rb_mKernel, "enum_for", obj_to_enum, -2);
+
+ rb_mEnumerable = rb_path2class("Enumerable");
+
+ rb_define_method(rb_mEnumerable, "enum_with_index", enumerator_enum_with_index, 0);
+ rb_define_method(rb_mEnumerable, "each_slice", enum_each_slice, 1);
+ rb_define_method(rb_mEnumerable, "enum_slice", enumerator_enum_slice, 1);
+ rb_define_method(rb_mEnumerable, "each_cons", enum_each_cons, 1);
+ rb_define_method(rb_mEnumerable, "enum_cons", enumerator_enum_cons, 1);
+
+ rb_cEnumerator = rb_define_class_under(rb_mEnumerable, "Enumerator", rb_cObject);
+ rb_include_module(rb_cEnumerator, rb_mEnumerable);
+
+ rb_define_method(rb_cEnumerator, "initialize", enumerator_initialize, -1);
+ rb_define_method(rb_cEnumerator, "each", enumerator_each, 0);
+
+ sym_each = ID2SYM(rb_intern("each"));
+ sym_each_with_index = ID2SYM(rb_intern("each_with_index"));
+ sym_each_slice = ID2SYM(rb_intern("each_slice"));
+ sym_each_cons = ID2SYM(rb_intern("each_cons"));
+
+ id_new = rb_intern("new");
+ id_enum_obj = rb_intern("enum_obj");
+ id_enum_method = rb_intern("enum_method");
+ id_enum_args = rb_intern("enum_args");
+}
diff --git a/ext/enumerator/enumerator.txt b/ext/enumerator/enumerator.txt
new file mode 100644
index 0000000000..64c7d50226
--- /dev/null
+++ b/ext/enumerator/enumerator.txt
@@ -0,0 +1,102 @@
+.\" enumerator.txt - -*- Indented-Text -*-
+$Idaemons: /home/cvs/rb/enumerator/enumerator.txt,v 1.2 2001/07/15 10:19:24 knu Exp $
+$RoughId: enumerator.txt,v 1.5 2003/02/20 12:24:51 knu Exp $
+$Id$
+
+** Enumerable::Enumerator(Class)
+
+A class which provides a method `each' to be used as an Enumerable
+object.
+
+Superclass: Object
+
+Mix-ins: Enumerable
+
+require 'enumerator'
+
+Class Methods:
+
+ new(obj, method = :each, *args)
+
+ Creates a new Enumerable::Enumerator object, which is to be
+ used as an Enumerable object using the given object's given
+ method with the given arguments.
+
+ e.g.:
+ str = "xyz"
+
+ enum = Enumerable::Enumerator.new(str, :each_byte)
+ a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
+
+Methods:
+
+ each {...}
+
+ Iterates the given block using the object and the method
+ specified in the first place.
+
+
+Requiring this module also adds some methods to the Object class:
+
+ to_enum(method = :each, *args)
+ enum_for(method = :each, *args)
+
+ Returns Enumerable::Enumerator.new(self, method, *args).
+
+ e.g.:
+ str = "xyz"
+
+ enum = str.enum_for(:each_byte)
+ a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
+
+ # protects an array from being modified
+ a = [1, 2, 3]
+ some_method(a.to_enum)
+
+And the Enumerable module.
+
+ each_slice(n) {...}
+
+ Iterates the given block for each slice of <n> elements.
+
+ e.g.:
+ (1..10).each_slice(3) {|a| p a}
+ # outputs below
+ [1, 2, 3]
+ [4, 5, 6]
+ [7, 8, 9]
+ [10]
+
+ enum_slice(n)
+
+ Returns Enumerable::Enumerator.new(self, :each_slice, n).
+
+ each_cons(n) {...}
+
+ Iterates the given block for each array of consecutive <n>
+ elements.
+
+ e.g.:
+ (1..10).each_cons(3) {|a| p a}
+ # outputs below
+ [1, 2, 3]
+ [2, 3, 4]
+ [3, 4, 5]
+ [4, 5, 6]
+ [5, 6, 7]
+ [6, 7, 8]
+ [7, 8, 9]
+ [8, 9, 10]
+
+ enum_cons(n)
+
+ Returns Enumerable::Enumerator.new(self, :each_cons, n).
+
+ enum_with_index
+
+ Returns Enumerable::Enumerator.new(self, :each_with_index).
+
+-------------------------------------------------------
+Local variables:
+fill-column: 70
+end:
diff --git a/ext/enumerator/extconf.rb b/ext/enumerator/extconf.rb
new file mode 100644
index 0000000000..94e2ee38b2
--- /dev/null
+++ b/ext/enumerator/extconf.rb
@@ -0,0 +1,2 @@
+require 'mkmf'
+create_makefile('enumerator')
diff --git a/ext/etc/etc.c b/ext/etc/etc.c
index ecb9e16411..486963378b 100644
--- a/ext/etc/etc.c
+++ b/ext/etc/etc.c
@@ -35,8 +35,6 @@ char *getenv();
char *getlogin();
/* Returns the short user name of the currently logged in user.
- * Unfortunately, it is often rather easy to fool getlogin().
- * Avoid getlogin() for security-related purposes.
*
* e.g.
* Etc.getlogin -> 'guest'
diff --git a/ext/extmk.rb b/ext/extmk.rb
index 64746552c1..cf7944679c 100644
--- a/ext/extmk.rb
+++ b/ext/extmk.rb
@@ -79,7 +79,7 @@ def extract_makefile(makefile, keep = true)
$static ||= m[/^EXTSTATIC[ \t]*=[ \t]*(\S+)/, 1] || false
/^STATIC_LIB[ \t]*=[ \t]*\S+/ =~ m or $static = nil
$preload = Shellwords.shellwords(m[/^preload[ \t]*=[ \t]*(.*)/, 1] || "")
- $DLDFLAGS += " " + (m[/^dldflags[ \t]*=[ \t]*(.*)/, 1] || "")
+ $DLDFLAGS += " " + (m[/^DLDFLAGS[ \t]*=[ \t]*(.*)/, 1] || "")
if s = m[/^LIBS[ \t]*=[ \t]*(.*)/, 1]
s.sub!(/^#{Regexp.quote($LIBRUBYARG)} */, "")
s.sub!(/ *#{Regexp.quote($LIBS)}$/, "")
@@ -135,6 +135,7 @@ def extmake(target)
"topdir" => $topdir,
}
mkconfig = {
+ "top_srcdir" => ($hdrdir == top_srcdir) ? top_srcdir : "$(topdir)"+top_srcdir[2..-1],
"hdrdir" => "$(top_srcdir)",
"srcdir" => "$(top_srcdir)/ext/#{$mdir}",
"topdir" => $topdir,
@@ -298,7 +299,7 @@ def parse_args()
$mflags.unshift(*rest) unless rest.empty?
def $mflags.set?(flag)
- grep(/\A-(?!-).*#{flag.chr}/i) { return true }
+ grep(/\A-(?!-).*#{'%c' % flag}/i) { return true }
false
end
def $mflags.defined?(var)
@@ -325,9 +326,9 @@ parse_args()
if target = ARGV.shift and /^[a-z-]+$/ =~ target
$mflags.push(target)
+ target = target.sub(/^(dist|real)(?=(?:clean)?$)/, '')
case target
- when /^(dist|real)?(clean)$/
- target = $2
+ when /clean/
$ignore ||= true
$clean = $1 ? $1[0] : true
when /^install\b/
@@ -354,16 +355,12 @@ elsif sep = config_string('BUILD_FILE_SEPARATOR')
else
$ruby = '$(topdir)/miniruby' + EXEEXT
end
-$ruby << " -I'$(topdir)'"
-unless CROSS_COMPILING
- $ruby << " -I'$(top_srcdir)/lib'"
- $ruby << " -I'$(extout)/$(arch)' -I'$(extout)/common'" if $extout
- $ruby << " -I./- -I'$(top_srcdir)/ext' -rpurelib.rb"
- ENV["RUBYLIB"] = "-"
- ENV["RUBYOPT"] = "-rpurelib.rb"
-end
+$ruby << " -I'$(topdir)' -I'$(top_srcdir)/lib'"
+$ruby << " -I'$(extout)/$(arch)' -I'$(extout)/common'" if $extout
+$ruby << " -I'$(hdrdir)/ext' -rpurelib.rb"
$config_h = '$(topdir)/config.h'
-$mflags << "ruby=#$ruby"
+ENV["RUBYLIB"] = "-"
+ENV["RUBYOPT"] = "-rpurelib.rb"
MTIMES = [__FILE__, 'rbconfig.rb', srcdir+'/lib/mkmf.rb'].collect {|f| File.mtime(f)}
@@ -458,16 +455,7 @@ if $ignore
Dir.chdir ".."
if $clean
Dir.rmdir('ext') rescue nil
- if $extout
- FileUtils.rm_rf([extout+"/common", extout+"/include/ruby", extout+"/rdoc"])
- FileUtils.rm_rf(extout+"/"+CONFIG["arch"])
- if $clean != true
- FileUtils.rm_rf(extout+"/include/"+CONFIG["arch"])
- FileUtils.rm_f($mflags.defined?("INSTALLED_LIST")||ENV["INSTALLED_LIST"]||".installed.list")
- Dir.rmdir(extout+"/include") rescue nil
- Dir.rmdir(extout) rescue nil
- end
- end
+ FileUtils.rm_rf(extout) if $extout
end
exit
end
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index d989b97df2..65fed33bd2 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -43,11 +43,7 @@
*
* == Examples
*
- * 1. Simple conversion between two charsets.
- *
- * converted_text = Iconv.conv('iso-8859-15', 'utf-8', text)
- *
- * 2. Instantiate a new Iconv and use method Iconv#iconv.
+ * 1. Instantiate a new Iconv and use method Iconv#iconv.
*
* cd = Iconv.new(to, from)
* begin
@@ -57,16 +53,20 @@
* cd.close
* end
*
- * 3. Invoke Iconv.open with a block.
+ * 2. Invoke Iconv.open with a block.
*
* Iconv.open(to, from) do |cd|
* input.each { |s| output << cd.iconv(s) }
* output << cd.iconv(nil)
* end
*
- * 4. Shorthand for (3).
+ * 3. Shorthand for (2).
*
* Iconv.iconv(to, from, *input.to_a)
+ *
+ * 4. Simple conversion between two charsets.
+ *
+ * converted_text = Iconv.new('iso-8859-15', 'utf-8').iconv(text)
*/
/* Invalid value for iconv_t is -1 but 0 for VALUE, I hope VALUE is
@@ -101,7 +101,7 @@ static void iconv_dfree _((void *cd));
static VALUE iconv_free _((VALUE cd));
static VALUE iconv_try _((iconv_t cd, const char **inptr, size_t *inlen, char **outptr, size_t *outlen));
static VALUE rb_str_derive _((VALUE str, const char* ptr, int len));
-static VALUE iconv_convert _((iconv_t cd, VALUE str, long start, long length, struct iconv_env_t* env));
+static VALUE iconv_convert _((iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* env));
static VALUE iconv_s_allocate _((VALUE klass));
static VALUE iconv_initialize _((VALUE self, VALUE to, VALUE from));
static VALUE iconv_s_open _((VALUE self, VALUE to, VALUE from));
@@ -170,7 +170,7 @@ iconv_create
}
if (cd == (iconv_t)-1) {
int inval = errno == EINVAL;
- const char *s = inval ? "invalid encoding " : "iconv";
+ char *s = inval ? "invalid encoding " : "iconv";
volatile VALUE msg = rb_str_new(0, strlen(s) + RSTRING(to)->len +
RSTRING(from)->len + 8);
@@ -362,13 +362,13 @@ rb_str_derive
static VALUE
iconv_convert
#ifdef HAVE_PROTOTYPES
- (iconv_t cd, VALUE str, long start, long length, struct iconv_env_t* env)
+ (iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* env)
#else /* HAVE_PROTOTYPES */
(cd, str, start, length, env)
iconv_t cd;
VALUE str;
- long start;
- long length;
+ int start;
+ int length;
struct iconv_env_t *env;
#endif /* HAVE_PROTOTYPES */
{
@@ -417,9 +417,14 @@ iconv_convert
slen = RSTRING(str)->len;
inptr = RSTRING(str)->ptr;
- inptr += start;
- if (length < 0 || length > start + slen)
- length = slen - start;
+ if (start < 0 ? (start += slen) < 0 : start >= slen)
+ length = 0;
+ else if (length < 0 && (length += slen + 1) < 0)
+ length = 0;
+ else if ((length -= start) < 0)
+ length = 0;
+ else
+ inptr += start;
}
instart = inptr;
inlen = length;
@@ -601,7 +606,7 @@ iconv_s_convert
}
/*
- * Document-method: Iconv::iconv
+ * Document-method: iconv
* call-seq: Iconv.iconv(to, from, *strs)
*
* Shorthand for
@@ -710,7 +715,7 @@ iconv_finish
}
/*
- * Document-method: Iconv#iconv
+ * Document-method: iconv
* call-seq: iconv(str, start=0, length=-1)
*
* Converts string and returns the result.
@@ -749,22 +754,14 @@ iconv_iconv
{
VALUE str, n1, n2;
VALUE cd = check_iconv(self);
- long start = 0, length = 0, slen = 0;
+ n1 = n2 = Qnil;
rb_scan_args(argc, argv, "12", &str, &n1, &n2);
- if (!NIL_P(str)) slen = RSTRING_LEN(StringValue(str));
- if (argc != 2 || !RTEST(rb_range_beg_len(n1, &start, &length, slen, 0))) {
- if (NIL_P(n1) || ((start = NUM2LONG(n1)) < 0 ? (start += slen) >= 0 : start < slen)) {
- if (NIL_P(n2)) {
- length = -1;
- }
- else if ((length = NUM2LONG(n2)) >= slen - start) {
- length = slen - start;
- }
- }
- }
- return iconv_convert(VALUE2ICONV(cd), str, start, length, NULL);
+ return iconv_convert(VALUE2ICONV(cd), str,
+ NIL_P(n1) ? 0 : NUM2INT(n1),
+ NIL_P(n2) ? -1 : NUM2INT(n2),
+ NULL);
}
/*
@@ -828,7 +825,7 @@ iconv_failure_inspect
VALUE self;
#endif /* HAVE_PROTOTYPES */
{
- const char *cname = rb_class2name(CLASS_OF(self));
+ char *cname = rb_class2name(CLASS_OF(self));
VALUE success = rb_attr_get(self, rb_success);
VALUE failed = rb_attr_get(self, rb_failed);
VALUE str = rb_str_buf_cat2(rb_str_new2("#<"), cname);
diff --git a/ext/io/wait/wait.c b/ext/io/wait/wait.c
index 02cb54a014..61d6527b36 100644
--- a/ext/io/wait/wait.c
+++ b/ext/io/wait/wait.c
@@ -56,7 +56,7 @@ static VALUE
io_ready_p(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
FILE *fp;
ioctl_arg n;
@@ -84,7 +84,7 @@ io_wait(argc, argv, io)
VALUE *argv;
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
fd_set rd;
FILE *fp;
int fd;
diff --git a/ext/openssl/extconf.rb b/ext/openssl/extconf.rb
index 02e06b7149..98921bc468 100644
--- a/ext/openssl/extconf.rb
+++ b/ext/openssl/extconf.rb
@@ -59,8 +59,6 @@ unless have_header("openssl/conf_api.h")
exit 1
end
-%w"rb_str_set_len rb_block_call".each {|func| have_func(func, "ruby.h")}
-
message "=== Checking for OpenSSL features... ===\n"
have_func("ERR_peek_last_error")
have_func("BN_mod_add")
@@ -83,8 +81,6 @@ have_func("HMAC_CTX_cleanup")
have_func("HMAC_CTX_copy")
have_func("HMAC_CTX_init")
have_func("PEM_def_callback")
-have_func("PKCS5_PBKDF2_HMAC")
-have_func("PKCS5_PBKDF2_HMAC_SHA1")
have_func("X509V3_set_nconf")
have_func("X509V3_EXT_nconf_nid")
have_func("X509_CRL_add0_revoked")
@@ -94,7 +90,6 @@ have_func("X509_CRL_sort")
have_func("X509_STORE_get_ex_data")
have_func("X509_STORE_set_ex_data")
have_func("OBJ_NAME_do_all_sorted")
-have_func("SSL_SESSION_get_id")
have_func("OPENSSL_cleanse")
if try_compile("#define FOO(a, ...) foo(a, ##__VA_ARGS__)\n int x(){FOO(1);FOO(1,2);FOO(1,2,3);}\n")
$defs.push("-DHAVE_VA_ARGS_MACRO")
diff --git a/ext/openssl/lib/net/ftptls.rb b/ext/openssl/lib/net/ftptls.rb
index a21c1f6c3c..f433457923 100644
--- a/ext/openssl/lib/net/ftptls.rb
+++ b/ext/openssl/lib/net/ftptls.rb
@@ -29,23 +29,13 @@ require 'net/ftp'
module Net
class FTPTLS < FTP
- def connect(host, port=FTP_PORT)
- @hostname = host
- super
- end
-
def login(user = "anonymous", passwd = nil, acct = nil)
- store = OpenSSL::X509::Store.new
- store.set_default_paths
ctx = OpenSSL::SSL::SSLContext.new('SSLv23')
- ctx.cert_store = store
- ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
ctx.key = nil
ctx.cert = nil
voidcmd("AUTH TLS")
@sock = OpenSSL::SSL::SSLSocket.new(@sock, ctx)
@sock.connect
- @sock.post_connection_check(@hostname)
super(user, passwd, acct)
voidcmd("PBSZ 0")
end
diff --git a/ext/openssl/lib/net/telnets.rb b/ext/openssl/lib/net/telnets.rb
index 2b69280432..a872f41e6a 100644
--- a/ext/openssl/lib/net/telnets.rb
+++ b/ext/openssl/lib/net/telnets.rb
@@ -134,9 +134,6 @@ module Net
@sock.verify_callback = @options['VerifyCallback']
@sock.verify_depth = @options['VerifyDepth']
@sock.connect
- if @options['VerifyMode'] != OpenSSL::SSL::VERIFY_NONE
- @sock.post_connection_check(@options['Host'])
- end
@ssl = true
end
''
diff --git a/ext/openssl/lib/openssl.rb b/ext/openssl/lib/openssl.rb
index f10985ed2c..24a9eed136 100644
--- a/ext/openssl/lib/openssl.rb
+++ b/ext/openssl/lib/openssl.rb
@@ -19,7 +19,6 @@ require 'openssl.so'
require 'openssl/bn'
require 'openssl/cipher'
require 'openssl/digest'
-require 'openssl/pkcs7'
require 'openssl/ssl'
require 'openssl/x509'
diff --git a/ext/openssl/lib/openssl/cipher.rb b/ext/openssl/lib/openssl/cipher.rb
index 290e9c1d2d..049533d06b 100644
--- a/ext/openssl/lib/openssl/cipher.rb
+++ b/ext/openssl/lib/openssl/cipher.rb
@@ -19,7 +19,7 @@
#require 'openssl'
module OpenSSL
- class Cipher
+ module Cipher
%w(AES CAST5 BF DES IDEA RC2 RC4 RC5).each{|name|
klass = Class.new(Cipher){
define_method(:initialize){|*args|
@@ -41,25 +41,18 @@ module OpenSSL
const_set("AES#{keylen}", klass)
}
- # Generate, set, and return a random key.
- # You must call cipher.encrypt or cipher.decrypt before calling this method.
- def random_key
- str = OpenSSL::Random.random_bytes(self.key_len)
- self.key = str
- return str
- end
-
- # Generate, set, and return a random iv.
- # You must call cipher.encrypt or cipher.decrypt before calling this method.
- def random_iv
- str = OpenSSL::Random.random_bytes(self.iv_len)
- self.iv = str
- return str
- end
-
- # This class is only provided for backwards compatibility. Use OpenSSL::Digest in the future.
- class Cipher < Cipher
- # add warning
+ class Cipher
+ def random_key
+ str = OpenSSL::Random.random_bytes(self.key_len)
+ self.key = str
+ return str
+ end
+
+ def random_iv
+ str = OpenSSL::Random.random_bytes(self.iv_len)
+ self.iv = str
+ return str
+ end
end
end # Cipher
end # OpenSSL
diff --git a/ext/openssl/lib/openssl/digest.rb b/ext/openssl/lib/openssl/digest.rb
index 4810f0121b..b3e4484805 100644
--- a/ext/openssl/lib/openssl/digest.rb
+++ b/ext/openssl/lib/openssl/digest.rb
@@ -19,17 +19,13 @@
#require 'openssl'
module OpenSSL
- class Digest
+ module Digest
alg = %w(DSS DSS1 MD2 MD4 MD5 MDC2 RIPEMD160 SHA SHA1)
if OPENSSL_VERSION_NUMBER > 0x00908000
alg += %w(SHA224 SHA256 SHA384 SHA512)
end
- def self.digest(name, data)
- super(data, name)
- end
-
alg.each{|name|
klass = Class.new(Digest){
define_method(:initialize){|*data|
@@ -48,14 +44,6 @@ module OpenSSL
const_set(name, klass)
}
- # This class is only provided for backwards compatibility. Use OpenSSL::Digest in the future.
- class Digest < Digest
- def initialize(*args)
- # add warning
- super(*args)
- end
- end
-
end # Digest
end # OpenSSL
diff --git a/ext/openssl/lib/openssl/pkcs7.rb b/ext/openssl/lib/openssl/pkcs7.rb
deleted file mode 100644
index 1f88c1de5e..0000000000
--- a/ext/openssl/lib/openssl/pkcs7.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-=begin
-= $RCSfile$ -- PKCS7
-
-= Licence
- This program is licenced under the same licence as Ruby.
- (See the file 'LICENCE'.)
-
-= Version
- $Id: digest.rb 12148 2007-04-05 05:59:22Z technorama $
-=end
-
-module OpenSSL
- class PKCS7
- # This class is only provided for backwards compatibility. Use OpenSSL::PKCS7 in the future.
- class PKCS7 < PKCS7
- def initialize(*args)
- super(*args)
-
- warn("Warning: OpenSSL::PKCS7::PKCS7 is deprecated after Ruby 1.9; use OpenSSL::PKCS7 instead")
- end
- end
-
- end # PKCS7
-end # OpenSSL
-
diff --git a/ext/openssl/lib/openssl/ssl.rb b/ext/openssl/lib/openssl/ssl.rb
index f722cb0c45..ef7415f478 100644
--- a/ext/openssl/lib/openssl/ssl.rb
+++ b/ext/openssl/lib/openssl/ssl.rb
@@ -20,33 +20,6 @@ require "fcntl"
module OpenSSL
module SSL
- class SSLContext
- DEFAULT_PARAMS = {
- :ssl_version => "SSLv23",
- :verify_mode => OpenSSL::SSL::VERIFY_PEER,
- :ciphers => "ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW",
- :options => OpenSSL::SSL::OP_ALL,
- }
-
- DEFAULT_CERT_STORE = OpenSSL::X509::Store.new
- DEFAULT_CERT_STORE.set_default_paths
- if defined?(OpenSSL::X509::V_FLAG_CRL_CHECK_ALL)
- DEFAULT_CERT_STORE.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL
- end
-
- def set_params(params={})
- params = DEFAULT_PARAMS.merge(params)
- self.ssl_version = params.delete(:ssl_version)
- params.each{|name, value| self.__send__("#{name}=", value) }
- if self.verify_mode != OpenSSL::SSL::VERIFY_NONE
- unless self.ca_file or self.ca_path or self.cert_store
- self.cert_store = DEFAULT_CERT_STORE
- end
- end
- return params
- end
- end
-
module SocketForwarder
def addr
to_io.addr
@@ -86,49 +59,36 @@ module OpenSSL
end
end
- def verify_certificate_identity(cert, hostname)
- should_verify_common_name = true
- cert.extensions.each{|ext|
- next if ext.oid != "subjectAltName"
- ext.value.split(/,\s+/).each{|general_name|
- if /\ADNS:(.*)/ =~ general_name
- should_verify_common_name = false
- reg = Regexp.escape($1).gsub(/\\\*/, "[^.]+")
- return true if /\A#{reg}\z/i =~ hostname
- elsif /\AIP Address:(.*)/ =~ general_name
- should_verify_common_name = false
- return true if $1 == hostname
- end
- }
- }
- if should_verify_common_name
- cert.subject.to_a.each{|oid, value|
- if oid == "CN"
- reg = Regexp.escape(value).gsub(/\\\*/, "[^.]+")
- return true if /\A#{reg}\z/i =~ hostname
- end
- }
- end
- return false
- end
- module_function :verify_certificate_identity
-
class SSLSocket
include Buffering
include SocketForwarder
include Nonblock
def post_connection_check(hostname)
- unless OpenSSL::SSL.verify_certificate_identity(peer_cert, hostname)
- raise SSLError, "hostname was not match with the server certificate"
+ check_common_name = true
+ cert = peer_cert
+ cert.extensions.each{|ext|
+ next if ext.oid != "subjectAltName"
+ ext.value.split(/,\s+/).each{|general_name|
+ if /\ADNS:(.*)/ =~ general_name
+ check_common_name = false
+ reg = Regexp.escape($1).gsub(/\\\*/, "[^.]+")
+ return true if /\A#{reg}\z/i =~ hostname
+ elsif /\AIP Address:(.*)/ =~ general_name
+ check_common_name = false
+ return true if $1 == hostname
+ end
+ }
+ }
+ if check_common_name
+ cert.subject.to_a.each{|oid, value|
+ if oid == "CN"
+ reg = Regexp.escape(value).gsub(/\\\*/, "[^.]+")
+ return true if /\A#{reg}\z/i =~ hostname
+ end
+ }
end
- return true
- end
-
- def session
- SSL::Session.new(self)
- rescue SSL::Session::SessionError
- nil
+ raise SSLError, "hostname not match"
end
end
@@ -154,10 +114,6 @@ module OpenSSL
@svr.listen(backlog)
end
- def shutdown(how=Socket::SHUT_RDWR)
- @svr.shutdown(how)
- end
-
def accept
sock = @svr.accept
begin
diff --git a/ext/openssl/openssl_missing.c b/ext/openssl/openssl_missing.c
index 724f36b8ae..f77731ed65 100644
--- a/ext/openssl/openssl_missing.c
+++ b/ext/openssl/openssl_missing.c
@@ -22,15 +22,17 @@
#include "openssl_missing.h"
#if !defined(HAVE_HMAC_CTX_COPY)
-void
+int
HMAC_CTX_copy(HMAC_CTX *out, HMAC_CTX *in)
{
- if (!out || !in) return;
+ if (!out || !in) return 0;
memcpy(out, in, sizeof(HMAC_CTX));
- EVP_MD_CTX_copy(&out->md_ctx, &in->md_ctx);
- EVP_MD_CTX_copy(&out->i_ctx, &in->i_ctx);
- EVP_MD_CTX_copy(&out->o_ctx, &in->o_ctx);
+ if (!EVP_MD_CTX_copy(&out->md_ctx, &in->md_ctx)
+ || !EVP_MD_CTX_copy(&out->i_ctx, &in->i_ctx)
+ || !EVP_MD_CTX_copy(&out->o_ctx, &in->o_ctx))
+ return 0;
+ return 1;
}
#endif /* HAVE_HMAC_CTX_COPY */
#endif /* NO_HMAC */
diff --git a/ext/openssl/openssl_missing.h b/ext/openssl/openssl_missing.h
index 5a71f73c64..e8c75ca42c 100644
--- a/ext/openssl/openssl_missing.h
+++ b/ext/openssl/openssl_missing.h
@@ -15,10 +15,6 @@
extern "C" {
#endif
-#ifndef TYPEDEF_D2I_OF
-typedef char *d2i_of_void();
-#endif
-
/*
* These functions are not included in headers of OPENSSL <= 0.9.6b
*/
@@ -60,33 +56,14 @@ typedef char *d2i_of_void();
(char *(*)())d2i_PKCS7_RECIP_INFO, (char *)ri)
#endif
-#if !defined(HAVE_EVP_MD_CTX_INIT)
void HMAC_CTX_init(HMAC_CTX *ctx);
-#endif
-
-#if !defined(HAVE_HMAC_CTX_COPY)
-void HMAC_CTX_copy(HMAC_CTX *out, HMAC_CTX *in);
-#endif
-
-#if !defined(HAVE_HMAC_CTX_CLEANUP)
+int HMAC_CTX_copy(HMAC_CTX *out, HMAC_CTX *in);
void HMAC_CTX_cleanup(HMAC_CTX *ctx);
-#endif
-#if !defined(HAVE_EVP_MD_CTX_CREATE)
EVP_MD_CTX *EVP_MD_CTX_create(void);
-#endif
-
-#if !defined(HAVE_EVP_MD_CTX_INIT)
void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
-#endif
-
-#if !defined(HAVE_EVP_MD_CTX_CLEANUP)
int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
-#endif
-
-#if !defined(HAVE_EVP_MD_CTX_DESTROY)
void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
-#endif
#if !defined(HAVE_EVP_CIPHER_CTX_COPY)
int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, EVP_CIPHER_CTX *in);
@@ -130,54 +107,19 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, EVP_CIPHER_CTX *in);
#define OPENSSL_cleanse(p, l) memset(p, 0, l)
#endif
-#if !defined(HAVE_X509_STORE_SET_EX_DATA)
void *X509_STORE_get_ex_data(X509_STORE *str, int idx);
int X509_STORE_set_ex_data(X509_STORE *str, int idx, void *data);
-#endif
-
-#if !defined(HAVE_X509_CRL_SET_VERSION)
int X509_CRL_set_version(X509_CRL *x, long version);
-#endif
-
-#if !defined(HAVE_X509_CRL_SET_ISSUER_NAME)
int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name);
-#endif
-
-#if !defined(HAVE_X509_CRL_SORT)
int X509_CRL_sort(X509_CRL *c);
-#endif
-
-#if !defined(HAVE_X509_CRL_ADD0_REVOKED)
int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev);
-#endif
-
-#if !defined(HAVE_BN_MOD_SQR)
int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
-#endif
-
-#if !defined(HAVE_BN_MOD_ADD)
int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
-#endif
-
-#if !defined(HAVE_BN_MOD_SUB)
int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
-#endif
-
-#if !defined(HAVE_BN_RAND_RANGE)
int BN_rand_range(BIGNUM *r, BIGNUM *range);
-#endif
-
-#if !defined(HAVE_BN_PSEUDO_RAND_RANGE)
int BN_pseudo_rand_range(BIGNUM *r, BIGNUM *range);
-#endif
-
-#if !defined(HAVE_CONF_GET1_DEFAULT_CONFIG_FILE)
char *CONF_get1_default_config_file(void);
-#endif
-
-#if !defined(HAVE_PEM_DEF_CALLBACK)
int PEM_def_callback(char *buf, int num, int w, void *key);
-#endif
#if defined(__cplusplus)
}
diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c
index 53f476fd65..a98f2641cc 100644
--- a/ext/openssl/ossl.c
+++ b/ext/openssl/ossl.c
@@ -59,7 +59,7 @@ ossl_x509_ary2sk0(VALUE ary)
sk = sk_X509_new_null();
if (!sk) ossl_raise(eOSSLError, NULL);
- for (i = 0; i < RARRAY_LEN(ary); i++) {
+ for (i = 0; i < RARRAY(ary)->len; i++) {
val = rb_ary_entry(ary, i);
if (!rb_obj_is_kind_of(val, cX509Cert)) {
sk_X509_pop_free(sk, X509_free);
@@ -131,7 +131,7 @@ ossl_buf2str(char *buf, int len)
int status = 0;
str = rb_protect((VALUE(*)_((VALUE)))ossl_str_new, len, &status);
- if(!NIL_P(str)) memcpy(RSTRING_PTR(str), buf, len);
+ if(!NIL_P(str)) memcpy(RSTRING(str)->ptr, buf, len);
OPENSSL_free(buf);
if(status) rb_jump_tag(status);
@@ -170,7 +170,7 @@ ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
rflag = flag ? Qtrue : Qfalse;
pass = rb_protect(ossl_pem_passwd_cb0, rflag, &status);
if (status) return -1; /* exception was raised. */
- len = RSTRING_LEN(pass);
+ len = RSTRING(pass)->len;
if (len < 4) { /* 4 is OpenSSL hardcoded limit */
rb_warning("password must be longer than 4 bytes");
continue;
@@ -179,7 +179,7 @@ ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
rb_warning("password must be shorter then %d bytes", max_len-1);
continue;
}
- memcpy(buf, RSTRING_PTR(pass), len);
+ memcpy(buf, RSTRING(pass)->ptr, len);
break;
}
return len;
@@ -310,14 +310,6 @@ ossl_raise(VALUE exc, const char *fmt, ...)
rb_exc_raise(rb_exc_new(exc, buf, len));
}
-/*
- * call-seq:
- * OpenSSL.errors -> [String...]
- *
- * See any remaining errors held in queue.
- *
- * Any errors you see here are probably due to a bug in ruby's OpenSSL implementation.
- */
VALUE
ossl_get_errors()
{
@@ -353,23 +345,12 @@ ossl_debug(const char *fmt, ...)
}
#endif
-/*
- * call-seq:
- * OpenSSL.debug -> true | false
- */
static VALUE
ossl_debug_get(VALUE self)
{
return dOSSL;
}
-/*
- * call-seq:
- * OpenSSL.debug = boolean -> boolean
- *
- * Turns on or off CRYPTO_MEM_CHECK.
- * Also shows some debugging message on stderr.
- */
static VALUE
ossl_debug_set(VALUE self, VALUE val)
{
@@ -446,8 +427,8 @@ Init_openssl()
/*
* Verify callback Proc index for ext-data
*/
- if ((ossl_verify_cb_idx = X509_STORE_CTX_get_ex_new_index(0, "ossl_verify_cb_idx", 0, 0, 0)) < 0)
- ossl_raise(eOSSLError, "X509_STORE_CTX_get_ex_new_index");
+ ossl_verify_cb_idx =
+ X509_STORE_CTX_get_ex_new_index(0, "ossl_verify_cb_idx", 0, 0, 0);
/*
* Init debug core
@@ -473,7 +454,6 @@ Init_openssl()
Init_ossl_ns_spki();
Init_ossl_pkcs12();
Init_ossl_pkcs7();
- Init_ossl_pkcs5();
Init_ossl_pkey();
Init_ossl_rand();
Init_ossl_ssl();
diff --git a/ext/openssl/ossl.h b/ext/openssl/ossl.h
index 3cc30ae2e8..598bfb69da 100644
--- a/ext/openssl/ossl.h
+++ b/ext/openssl/ossl.h
@@ -17,11 +17,6 @@
extern "C" {
#endif
-#if 0
- mOSSL = rb_define_module("OpenSSL");
- mX509 = rb_define_module_under(mOSSL, "X509");
-#endif
-
/*
* OpenSSL has defined RFILE and Ruby has defined RFILE - so undef it!
*/
@@ -45,12 +40,8 @@ extern "C" {
#endif
#if defined(_WIN32)
+# define OpenFile WINAPI_OpenFile
# define OSSL_NO_CONF_API 1
-# ifdef USE_WINSOCK2
-# include <winsock2.h>
-# else
-# include <winsock.h>
-# endif
#endif
#include <errno.h>
#include <openssl/err.h>
@@ -73,6 +64,9 @@ extern "C" {
# define OSSL_OCSP_ENABLED
# include <openssl/ocsp.h>
#endif
+#if defined(_WIN32)
+# undef OpenFile
+#endif
/*
* Common Module
@@ -123,10 +117,11 @@ VALUE ossl_x509crl_sk2ary(STACK_OF(X509_CRL) *crl);
VALUE ossl_buf2str(char *buf, int len);
#define ossl_str_adjust(str, p) \
do{\
- int len = RSTRING_LEN(str);\
- int newlen = (p) - (unsigned char*)RSTRING_PTR(str);\
+ int len = RSTRING(str)->len;\
+ int newlen = (p) - (unsigned char*)RSTRING(str)->ptr;\
assert(newlen <= len);\
- rb_str_set_len(str, newlen);\
+ RSTRING(str)->len = newlen;\
+ RSTRING(str)->ptr[newlen] = 0;\
}while(0)
/*
diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c
index 8ceea95021..3614f470d9 100644
--- a/ext/openssl/ossl_asn1.c
+++ b/ext/openssl/ossl_asn1.c
@@ -214,7 +214,7 @@ obj_to_asn1bstr(VALUE obj, long unused_bits)
StringValue(obj);
if(!(bstr = ASN1_BIT_STRING_new()))
ossl_raise(eASN1Error, NULL);
- ASN1_BIT_STRING_set(bstr, RSTRING_PTR(obj), RSTRING_LEN(obj));
+ ASN1_BIT_STRING_set(bstr, RSTRING(obj)->ptr, RSTRING(obj)->len);
bstr->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
bstr->flags |= ASN1_STRING_FLAG_BITS_LEFT|(unused_bits&0x07);
@@ -229,7 +229,7 @@ obj_to_asn1str(VALUE obj)
StringValue(obj);
if(!(str = ASN1_STRING_new()))
ossl_raise(eASN1Error, NULL);
- ASN1_STRING_set(str, RSTRING_PTR(obj), RSTRING_LEN(obj));
+ ASN1_STRING_set(str, RSTRING(obj)->ptr, RSTRING(obj)->len);
return str;
}
@@ -253,8 +253,8 @@ obj_to_asn1obj(VALUE obj)
ASN1_OBJECT *a1obj;
StringValue(obj);
- a1obj = OBJ_txt2obj(RSTRING_PTR(obj), 0);
- if(!a1obj) a1obj = OBJ_txt2obj(RSTRING_PTR(obj), 1);
+ a1obj = OBJ_txt2obj(RSTRING(obj)->ptr, 0);
+ if(!a1obj) a1obj = OBJ_txt2obj(RSTRING(obj)->ptr, 1);
if(!a1obj) ossl_raise(eASN1Error, "invalid OBJECT ID");
return a1obj;
@@ -295,7 +295,7 @@ obj_to_asn1derstr(VALUE obj)
str = ossl_to_der(obj);
if(!(a1str = ASN1_STRING_new()))
ossl_raise(eASN1Error, NULL);
- ASN1_STRING_set(a1str, RSTRING_PTR(str), RSTRING_LEN(str));
+ ASN1_STRING_set(a1str, RSTRING(str)->ptr, RSTRING(str)->len);
return a1str;
}
@@ -445,7 +445,7 @@ decode_time(unsigned char* der, int length)
/********/
typedef struct {
- const char *name;
+ char *name;
VALUE *klass;
} ossl_asn1_info_t;
@@ -678,7 +678,7 @@ static VALUE
join_der(VALUE enumerable)
{
VALUE str = rb_str_new(0, 0);
- rb_block_call(enumerable, rb_intern("each"), 0, 0, join_der_i, str);
+ rb_iterate(rb_each, enumerable, join_der_i, str);
return str;
}
@@ -699,13 +699,13 @@ ossl_asn1data_to_der(VALUE self)
tag = ossl_asn1_tag(self);
tag_class = ossl_asn1_tag_class(self);
- if((length = ASN1_object_size(1, RSTRING_LEN(value), tag)) <= 0)
+ if((length = ASN1_object_size(1, RSTRING(value)->len, tag)) <= 0)
ossl_raise(eASN1Error, NULL);
der = rb_str_new(0, length);
- p = RSTRING_PTR(der);
- ASN1_put_object(&p, is_cons, RSTRING_LEN(value), tag, tag_class);
- memcpy(p, RSTRING_PTR(value), RSTRING_LEN(value));
- p += RSTRING_LEN(value);
+ p = RSTRING(der)->ptr;
+ ASN1_put_object(&p, is_cons, RSTRING(value)->len, tag, tag_class);
+ memcpy(p, RSTRING(value)->ptr, RSTRING(value)->len);
+ p += RSTRING(value)->len;
ossl_str_adjust(der, p);
return der;
@@ -824,8 +824,8 @@ ossl_asn1_traverse(VALUE self, VALUE obj)
obj = ossl_to_der_if_possible(obj);
tmp = rb_str_new4(StringValue(obj));
- p = RSTRING_PTR(tmp);
- ossl_asn1_decode0(&p, RSTRING_LEN(tmp), &offset, 0, 0, 1);
+ p = RSTRING(tmp)->ptr;
+ ossl_asn1_decode0(&p, RSTRING(tmp)->len, &offset, 0, 0, 1);
return Qnil;
}
@@ -840,8 +840,8 @@ ossl_asn1_decode(VALUE self, VALUE obj)
obj = ossl_to_der_if_possible(obj);
tmp = rb_str_new4(StringValue(obj));
- p = RSTRING_PTR(tmp);
- ary = ossl_asn1_decode0(&p, RSTRING_LEN(tmp), &offset, 0, 1, 0);
+ p = RSTRING(tmp)->ptr;
+ ary = ossl_asn1_decode0(&p, RSTRING(tmp)->len, &offset, 0, 1, 0);
ret = rb_ary_entry(ary, 0);
return ret;
@@ -857,8 +857,8 @@ ossl_asn1_decode_all(VALUE self, VALUE obj)
obj = ossl_to_der_if_possible(obj);
tmp = rb_str_new4(StringValue(obj));
- p = RSTRING_PTR(tmp);
- ret = ossl_asn1_decode0(&p, RSTRING_LEN(tmp), &offset, 0, 0, 0);
+ p = RSTRING(tmp)->ptr;
+ ret = ossl_asn1_decode0(&p, RSTRING(tmp)->len, &offset, 0, 0, 0);
return ret;
}
@@ -973,21 +973,21 @@ ossl_asn1cons_to_der(VALUE self)
explicit = ossl_asn1_is_explicit(self);
value = join_der(ossl_asn1_get_value(self));
- seq_len = ASN1_object_size(1, RSTRING_LEN(value), tag);
+ seq_len = ASN1_object_size(1, RSTRING(value)->len, tag);
length = ASN1_object_size(1, seq_len, tn);
str = rb_str_new(0, length);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(tc == V_ASN1_UNIVERSAL)
- ASN1_put_object(&p, 1, RSTRING_LEN(value), tn, tc);
+ ASN1_put_object(&p, 1, RSTRING(value)->len, tn, tc);
else{
if(explicit){
ASN1_put_object(&p, 1, seq_len, tn, tc);
- ASN1_put_object(&p, 1, RSTRING_LEN(value), tag, V_ASN1_UNIVERSAL);
+ ASN1_put_object(&p, 1, RSTRING(value)->len, tag, V_ASN1_UNIVERSAL);
}
- else ASN1_put_object(&p, 1, RSTRING_LEN(value), tn, tc);
+ else ASN1_put_object(&p, 1, RSTRING(value)->len, tn, tc);
}
- memcpy(p, RSTRING_PTR(value), RSTRING_LEN(value));
- p += RSTRING_LEN(value);
+ memcpy(p, RSTRING(value)->ptr, RSTRING(value)->len);
+ p += RSTRING(value)->len;
ossl_str_adjust(str, p);
return str;
@@ -1007,7 +1007,7 @@ ossl_asn1obj_s_register(VALUE self, VALUE oid, VALUE sn, VALUE ln)
StringValue(sn);
StringValue(ln);
- if(!OBJ_create(RSTRING_PTR(oid), RSTRING_PTR(sn), RSTRING_PTR(ln)))
+ if(!OBJ_create(RSTRING(oid)->ptr, RSTRING(sn)->ptr, RSTRING(ln)->ptr))
ossl_raise(eASN1Error, NULL);
return Qtrue;
@@ -1112,9 +1112,9 @@ Init_ossl_asn1()
}
cASN1Data = rb_define_class_under(mASN1, "ASN1Data", rb_cObject);
- rb_attr(cASN1Data, rb_intern("value"), 1, 1, 0);
- rb_attr(cASN1Data, rb_intern("tag"), 1, 1, 0);
- rb_attr(cASN1Data, rb_intern("tag_class"), 1, 1, 0);
+ rb_attr(cASN1Data, rb_intern("value"), 1, 1, Qtrue);
+ rb_attr(cASN1Data, rb_intern("tag"), 1, 1, Qtrue);
+ rb_attr(cASN1Data, rb_intern("tag_class"), 1, 1, Qtrue);
rb_define_method(cASN1Data, "initialize", ossl_asn1data_initialize, 3);
rb_define_method(cASN1Data, "to_der", ossl_asn1data_to_der, 0);
@@ -1166,5 +1166,5 @@ do{\
rb_define_method(cASN1ObjectId, "oid", ossl_asn1obj_get_oid, 0);
rb_define_alias(cASN1ObjectId, "short_name", "sn");
rb_define_alias(cASN1ObjectId, "long_name", "ln");
- rb_attr(cASN1BitString, rb_intern("unused_bits"), 1, 1, 0);
+ rb_attr(cASN1BitString, rb_intern("unused_bits"), 1, 1, Qtrue);
}
diff --git a/ext/openssl/ossl_bio.c b/ext/openssl/ossl_bio.c
index 6db1fb9a62..9c9aa24197 100644
--- a/ext/openssl/ossl_bio.c
+++ b/ext/openssl/ossl_bio.c
@@ -19,29 +19,16 @@ ossl_obj2bio(VALUE obj)
BIO *bio;
if (TYPE(obj) == T_FILE) {
- rb_io_t *fptr;
- FILE *fp;
- int fd;
-
+ OpenFile *fptr;
GetOpenFile(obj, fptr);
rb_io_check_readable(fptr);
- if ((fd = dup(FPTR_TO_FD(fptr))) < 0){
- rb_sys_fail(0);
- }
- if (!(fp = fdopen(fd, "r"))){
- close(fd);
- rb_sys_fail(0);
- }
- if (!(bio = BIO_new_fp(fp, BIO_CLOSE))){
- fclose(fp);
- ossl_raise(eOSSLError, NULL);
- }
- }
+ bio = BIO_new_fp(fptr->f, BIO_NOCLOSE);
+ }
else {
StringValue(obj);
- bio = BIO_new_mem_buf(RSTRING_PTR(obj), RSTRING_LEN(obj));
- if (!bio) ossl_raise(eOSSLError, NULL);
+ bio = BIO_new_mem_buf(RSTRING(obj)->ptr, RSTRING(obj)->len);
}
+ if (!bio) ossl_raise(eOSSLError, NULL);
return bio;
}
diff --git a/ext/openssl/ossl_bn.c b/ext/openssl/ossl_bn.c
index 6856476261..cc7689eef5 100644
--- a/ext/openssl/ossl_bn.c
+++ b/ext/openssl/ossl_bn.c
@@ -40,7 +40,7 @@ VALUE eBNError;
* Public
*/
VALUE
-ossl_bn_new(const BIGNUM *bn)
+ossl_bn_new(BIGNUM *bn)
{
BIGNUM *newbn;
VALUE obj;
@@ -100,13 +100,6 @@ ossl_bn_alloc(VALUE klass)
return obj;
}
-/*
- * call-seq:
- * BN.new => aBN
- * BN.new(bn) => aBN
- * BN.new(string) => aBN
- * BN.new(string, 0 | 2 | 10 | 16) => aBN
- */
static VALUE
ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
{
@@ -131,22 +124,22 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
switch (base) {
case 0:
- if (!BN_mpi2bn(RSTRING_PTR(str), RSTRING_LEN(str), bn)) {
+ if (!BN_mpi2bn(RSTRING(str)->ptr, RSTRING(str)->len, bn)) {
ossl_raise(eBNError, NULL);
}
break;
case 2:
- if (!BN_bin2bn(RSTRING_PTR(str), RSTRING_LEN(str), bn)) {
+ if (!BN_bin2bn(RSTRING(str)->ptr, RSTRING(str)->len, bn)) {
ossl_raise(eBNError, NULL);
}
break;
case 10:
- if (!BN_dec2bn(&bn, RSTRING_PTR(str))) {
+ if (!BN_dec2bn(&bn, RSTRING(str)->ptr)) {
ossl_raise(eBNError, NULL);
}
break;
case 16:
- if (!BN_hex2bn(&bn, RSTRING_PTR(str))) {
+ if (!BN_hex2bn(&bn, RSTRING(str)->ptr)) {
ossl_raise(eBNError, NULL);
}
break;
@@ -156,19 +149,6 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
return self;
}
-/*
- * call-seq:
- * bn.to_s => string
- * bn.to_s(base) => string
- *
- * === Parameters
- * * +base+ - integer
- * * * Valid values:
- * * * * 0 - MPI
- * * * * 2 - binary
- * * * * 10 - the default
- * * * * 16 - hex
- */
static VALUE
ossl_bn_to_s(int argc, VALUE *argv, VALUE self)
{
@@ -185,13 +165,13 @@ ossl_bn_to_s(int argc, VALUE *argv, VALUE self)
case 0:
len = BN_bn2mpi(bn, NULL);
str = rb_str_new(0, len);
- if (BN_bn2mpi(bn, RSTRING_PTR(str)) != len)
+ if (BN_bn2mpi(bn, RSTRING(str)->ptr) != len)
ossl_raise(eBNError, NULL);
break;
case 2:
len = BN_num_bytes(bn);
str = rb_str_new(0, len);
- if (BN_bn2bin(bn, RSTRING_PTR(str)) != len)
+ if (BN_bn2bin(bn, RSTRING(str)->ptr) != len)
ossl_raise(eBNError, NULL);
break;
case 10:
@@ -209,10 +189,6 @@ ossl_bn_to_s(int argc, VALUE *argv, VALUE self)
return str;
}
-/*
- * call-seq:
- * bn.to_i => integer
- */
static VALUE
ossl_bn_to_i(VALUE self)
{
@@ -257,11 +233,6 @@ ossl_bn_coerce(VALUE self, VALUE other)
}
#define BIGNUM_BOOL1(func) \
- /* \
- * call-seq: \
- * bn.##func -> true | false \
- * \
- */ \
static VALUE \
ossl_bn_##func(VALUE self) \
{ \
@@ -277,11 +248,6 @@ BIGNUM_BOOL1(is_one);
BIGNUM_BOOL1(is_odd);
#define BIGNUM_1c(func) \
- /* \
- * call-seq: \
- * bn.##func -> aBN \
- * \
- */ \
static VALUE \
ossl_bn_##func(VALUE self) \
{ \
@@ -301,11 +267,6 @@ BIGNUM_BOOL1(is_odd);
BIGNUM_1c(sqr);
#define BIGNUM_2(func) \
- /* \
- * call-seq: \
- * bn.##func(bn2) -> aBN \
- * \
- */ \
static VALUE \
ossl_bn_##func(VALUE self, VALUE other) \
{ \
@@ -326,11 +287,6 @@ BIGNUM_2(add);
BIGNUM_2(sub);
#define BIGNUM_2c(func) \
- /* \
- * call-seq: \
- * bn.##func(bn2) -> aBN \
- * \
- */ \
static VALUE \
ossl_bn_##func(VALUE self, VALUE other) \
{ \
@@ -354,10 +310,6 @@ BIGNUM_2c(gcd);
BIGNUM_2c(mod_sqr);
BIGNUM_2c(mod_inverse);
-/*
- * call-seq:
- * bn1 / bn2 => [result, remainder]
- */
static VALUE
ossl_bn_div(VALUE self, VALUE other)
{
@@ -385,11 +337,6 @@ ossl_bn_div(VALUE self, VALUE other)
}
#define BIGNUM_3c(func) \
- /* \
- * call-seq: \
- * bn.##func(bn1, bn2) -> aBN \
- * \
- */ \
static VALUE \
ossl_bn_##func(VALUE self, VALUE other1, VALUE other2) \
{ \
@@ -413,11 +360,6 @@ BIGNUM_3c(mod_mul);
BIGNUM_3c(mod_exp);
#define BIGNUM_BIT(func) \
- /* \
- * call-seq: \
- * bn.##func(bit) -> self \
- * \
- */ \
static VALUE \
ossl_bn_##func(VALUE self, VALUE bit) \
{ \
@@ -432,10 +374,6 @@ BIGNUM_BIT(set_bit);
BIGNUM_BIT(clear_bit);
BIGNUM_BIT(mask_bits);
-/*
- * call-seq:
- * bn.bit_set?(bit) => true | false
- */
static VALUE
ossl_bn_is_bit_set(VALUE self, VALUE bit)
{
@@ -451,11 +389,6 @@ ossl_bn_is_bit_set(VALUE self, VALUE bit)
}
#define BIGNUM_SHIFT(func) \
- /* \
- * call-seq: \
- * bn.##func(bits) -> aBN \
- * \
- */ \
static VALUE \
ossl_bn_##func(VALUE self, VALUE bits) \
{ \
@@ -477,32 +410,7 @@ ossl_bn_is_bit_set(VALUE self, VALUE bit)
BIGNUM_SHIFT(lshift);
BIGNUM_SHIFT(rshift);
-#define BIGNUM_SELF_SHIFT(func) \
- /* \
- * call-seq: \
- * bn.##func!(bits) -> self \
- * \
- */ \
- static VALUE \
- ossl_bn_self_##func(VALUE self, VALUE bits) \
- { \
- BIGNUM *bn; \
- int b; \
- b = NUM2INT(bits); \
- GetBN(self, bn); \
- if (!BN_##func(bn, bn, b)) \
- ossl_raise(eBNError, NULL); \
- return self; \
- }
-BIGNUM_SELF_SHIFT(lshift);
-BIGNUM_SELF_SHIFT(rshift);
-
#define BIGNUM_RAND(func) \
- /* \
- * call-seq: \
- * BN.##func(bits [, fill [, odd]]) -> aBN \
- * \
- */ \
static VALUE \
ossl_bn_s_##func(int argc, VALUE *argv, VALUE klass) \
{ \
@@ -515,7 +423,7 @@ BIGNUM_SELF_SHIFT(rshift);
bottom = (odd == Qtrue) ? 1 : 0; \
/* FALLTHROUGH */ \
case 2: \
- top = NUM2INT(fill); \
+ top = FIX2INT(fill); \
} \
b = NUM2INT(bits); \
if (!(result = BN_new())) { \
@@ -532,11 +440,6 @@ BIGNUM_RAND(rand);
BIGNUM_RAND(pseudo_rand);
#define BIGNUM_RAND_RANGE(func) \
- /* \
- * call-seq: \
- * BN.##func(range) -> aBN \
- * \
- */ \
static VALUE \
ossl_bn_s_##func##_range(VALUE klass, VALUE range) \
{ \
@@ -555,16 +458,6 @@ BIGNUM_RAND(pseudo_rand);
BIGNUM_RAND_RANGE(rand);
BIGNUM_RAND_RANGE(pseudo_rand);
-/*
- * call-seq:
- * BN.generate_prime(bits, [, safe [, add [, rem]]]) => bn
- *
- * === Parameters
- * * +bits+ - integer
- * * +safe+ - boolean
- * * +add+ - BN
- * * +rem+ - BN
- */
static VALUE
ossl_bn_s_generate_prime(int argc, VALUE *argv, VALUE klass)
{
@@ -580,8 +473,12 @@ ossl_bn_s_generate_prime(int argc, VALUE *argv, VALUE klass)
safe = 0;
}
if (!NIL_P(vadd)) {
+ if (NIL_P(vrem)) {
+ ossl_raise(rb_eArgError,
+ "if ADD is specified, REM must be also given");
+ }
add = GetBNPtr(vadd);
- rem = NIL_P(vrem) ? NULL : GetBNPtr(vrem);
+ rem = GetBNPtr(vrem);
}
if (!(result = BN_new())) {
ossl_raise(eBNError, NULL);
@@ -592,15 +489,10 @@ ossl_bn_s_generate_prime(int argc, VALUE *argv, VALUE klass)
}
WrapBN(klass, obj, result);
- return obj;
+ return obj;
}
#define BIGNUM_NUM(func) \
- /* \
- * call-seq: \
- * bn.##func -> integer \
- * \
- */ \
static VALUE \
ossl_bn_##func(VALUE self) \
{ \
@@ -630,11 +522,6 @@ ossl_bn_copy(VALUE self, VALUE other)
}
#define BIGNUM_CMP(func) \
- /* \
- * call-seq: \
- * bn.##func(bn2) -> integer \
- * \
- */ \
static VALUE \
ossl_bn_##func(VALUE self, VALUE other) \
{ \
@@ -654,14 +541,6 @@ ossl_bn_eql(VALUE self, VALUE other)
return Qfalse;
}
-/*
- * call-seq:
- * bn.prime? => true | false
- * bn.prime?(checks) => true | false
- *
- * === Parameters
- * * +checks+ - integer
- */
static VALUE
ossl_bn_is_prime(int argc, VALUE *argv, VALUE self)
{
@@ -685,16 +564,6 @@ ossl_bn_is_prime(int argc, VALUE *argv, VALUE self)
return Qnil;
}
-/*
- * call-seq:
- * bn.prime_fasttest? => true | false
- * bn.prime_fasttest?(checks) => true | false
- * bn.prime_fasttest?(checks, trial_div) => true | false
- *
- * === Parameters
- * * +checks+ - integer
- * * +trial_div+ - boolean
- */
static VALUE
ossl_bn_is_prime_fasttest(int argc, VALUE *argv, VALUE self)
{
@@ -807,10 +676,8 @@ Init_ossl_bn()
rb_define_method(cBN, "bit_set?", ossl_bn_is_bit_set, 1);
rb_define_method(cBN, "mask_bits!", ossl_bn_mask_bits, 1);
rb_define_method(cBN, "<<", ossl_bn_lshift, 1);
- rb_define_method(cBN, ">>", ossl_bn_rshift, 1);
- rb_define_method(cBN, "lshift!", ossl_bn_self_lshift, 1);
- rb_define_method(cBN, "rshift!", ossl_bn_self_rshift, 1);
/* lshift1 - DON'T IMPL. */
+ rb_define_method(cBN, ">>", ossl_bn_rshift, 1);
/* rshift1 - DON'T IMPL. */
/*
diff --git a/ext/openssl/ossl_bn.h b/ext/openssl/ossl_bn.h
index d6c396227b..12aa484873 100644
--- a/ext/openssl/ossl_bn.h
+++ b/ext/openssl/ossl_bn.h
@@ -14,12 +14,9 @@
extern VALUE cBN;
extern VALUE eBNError;
-extern BN_CTX *ossl_bn_ctx;
-
-VALUE ossl_bn_new(const BIGNUM *);
+VALUE ossl_bn_new(BIGNUM *);
BIGNUM *GetBNPtr(VALUE);
void Init_ossl_bn(void);
-
#endif /* _OSS_BN_H_ */
diff --git a/ext/openssl/ossl_cipher.c b/ext/openssl/ossl_cipher.c
index b680dc6e64..57b7976617 100644
--- a/ext/openssl/ossl_cipher.c
+++ b/ext/openssl/ossl_cipher.c
@@ -26,6 +26,7 @@
/*
* Classes
*/
+VALUE mCipher;
VALUE cCipher;
VALUE eCipherError;
@@ -83,14 +84,6 @@ ossl_cipher_alloc(VALUE klass)
return obj;
}
-/*
- * call-seq:
- * Cipher.new(string) -> cipher
- *
- * The string must contain a valid cipher name like "AES-128-CBC" or "3DES".
- *
- * A list of cipher names is available by calling OpenSSL::Cipher.ciphers.
- */
static VALUE
ossl_cipher_initialize(VALUE self, VALUE str)
{
@@ -131,12 +124,6 @@ add_cipher_name_to_ary(const OBJ_NAME *name, VALUE ary)
return NULL;
}
-/*
- * call-seq:
- * Cipher.ciphers -> array[string...]
- *
- * Returns the names of all available ciphers in an array.
- */
static VALUE
ossl_s_ciphers(VALUE self)
{
@@ -154,12 +141,6 @@ ossl_s_ciphers(VALUE self)
#endif
}
-/*
- * call-seq:
- * cipher.reset -> self
- *
- * Internally calls EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, -1).
- */
static VALUE
ossl_cipher_reset(VALUE self)
{
@@ -186,23 +167,22 @@ ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
* We deprecated the arguments for this method, but we decided
* keeping this behaviour for backward compatibility.
*/
- char *cname = rb_class2name(rb_obj_class(self));
- rb_warn("argumtents for %s#encrypt and %s#decrypt were deprecated; "
- "use %s#pkcs5_keyivgen to derive key and IV",
- cname, cname, cname);
StringValue(pass);
GetCipher(self, ctx);
if (NIL_P(init_v)) memcpy(iv, "OpenSSL for Ruby rulez!", sizeof(iv));
else{
+ char *cname = rb_class2name(rb_obj_class(self));
+ rb_warning("key derivation by %s#encrypt is deprecated; "
+ "use %s::pkcs5_keyivgen instead", cname, cname);
StringValue(init_v);
- if (EVP_MAX_IV_LENGTH > RSTRING_LEN(init_v)) {
+ if (EVP_MAX_IV_LENGTH > RSTRING(init_v)->len) {
memset(iv, 0, EVP_MAX_IV_LENGTH);
- memcpy(iv, RSTRING_PTR(init_v), RSTRING_LEN(init_v));
+ memcpy(iv, RSTRING(init_v)->ptr, RSTRING(init_v)->len);
}
- else memcpy(iv, RSTRING_PTR(init_v), sizeof(iv));
+ else memcpy(iv, RSTRING(init_v)->ptr, sizeof(iv));
}
EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), EVP_md5(), iv,
- RSTRING_PTR(pass), RSTRING_LEN(pass), 1, key, NULL);
+ RSTRING(pass)->ptr, RSTRING(pass)->len, 1, key, NULL);
p_key = key;
p_iv = iv;
}
@@ -216,54 +196,18 @@ ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
return self;
}
-/*
- * call-seq:
- * cipher.encrypt -> self
- *
- * Make sure to call .encrypt or .decrypt before using any of the following methods:
- * * [key=, iv=, random_key, random_iv, pkcs5_keyivgen]
- *
- * Internally calls EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, 1).
- */
static VALUE
ossl_cipher_encrypt(int argc, VALUE *argv, VALUE self)
{
return ossl_cipher_init(argc, argv, self, 1);
}
-/*
- * call-seq:
- * cipher.decrypt -> self
- *
- * Make sure to call .encrypt or .decrypt before using any of the following methods:
- * * [key=, iv=, random_key, random_iv, pkcs5_keyivgen]
- *
- * Internally calls EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, 0).
- */
static VALUE
ossl_cipher_decrypt(int argc, VALUE *argv, VALUE self)
{
return ossl_cipher_init(argc, argv, self, 0);
}
-/*
- * call-seq:
- * cipher.pkcs5_keyivgen(pass [, salt [, iterations [, digest]]] ) -> nil
- *
- * Generates and sets the key/iv based on a password.
- *
- * WARNING: This method is only PKCS5 v1.5 compliant when using RC2, RC4-40, or DES
- * with MD5 or SHA1. Using anything else (like AES) will generate the key/iv using an
- * OpenSSL specific method. Use a PKCS5 v2 key generation method instead.
- *
- * === Parameters
- * +salt+ must be an 8 byte string if provided.
- * +iterations+ is a integer with a default of 2048.
- * +digest+ is a Digest object that defaults to 'MD5'
- *
- * A minimum of 1000 iterations is recommended.
- *
- */
static VALUE
ossl_cipher_pkcs5_keyivgen(int argc, VALUE *argv, VALUE self)
{
@@ -277,15 +221,15 @@ ossl_cipher_pkcs5_keyivgen(int argc, VALUE *argv, VALUE self)
StringValue(vpass);
if(!NIL_P(vsalt)){
StringValue(vsalt);
- if(RSTRING_LEN(vsalt) != PKCS5_SALT_LEN)
+ if(RSTRING(vsalt)->len != PKCS5_SALT_LEN)
rb_raise(eCipherError, "salt must be an 8-octet string");
- salt = RSTRING_PTR(vsalt);
+ salt = RSTRING(vsalt)->ptr;
}
iter = NIL_P(viter) ? 2048 : NUM2INT(viter);
digest = NIL_P(vdigest) ? EVP_md5() : GetDigestPtr(vdigest);
GetCipher(self, ctx);
EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), digest, salt,
- RSTRING_PTR(vpass), RSTRING_LEN(vpass), iter, key, iv);
+ RSTRING(vpass)->ptr, RSTRING(vpass)->len, iter, key, iv);
if (EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, -1) != 1)
ossl_raise(eCipherError, NULL);
OPENSSL_cleanse(key, sizeof key);
@@ -294,75 +238,39 @@ ossl_cipher_pkcs5_keyivgen(int argc, VALUE *argv, VALUE self)
return Qnil;
}
-
-/*
- * call-seq:
- * cipher << data -> string
- *
- * === Parameters
- * +data+ is a nonempty string.
- *
- * This method is deprecated and not available in 1.9.x or later.
- */
-static VALUE
-ossl_cipher_update_deprecated(VALUE self, VALUE data)
-{
- char *cname;
-
- cname = rb_class2name(rb_obj_class(self));
- rb_warning("%s#<< is deprecated; use %s#update instead", cname, cname);
- return rb_funcall(self, rb_intern("update"), 1, data);
-}
-
-
-/*
- * call-seq:
- * cipher.update(data [, buffer]) -> string or buffer
- *
- * === Parameters
- * +data+ is a nonempty string.
- * +buffer+ is an optional string to store the result.
- */
static VALUE
-ossl_cipher_update(int argc, VALUE *argv, VALUE self)
+ossl_cipher_update(VALUE self, VALUE data)
{
EVP_CIPHER_CTX *ctx;
char *in;
int in_len, out_len;
- VALUE data, str;
-
- rb_scan_args(argc, argv, "11", &data, &str);
+ VALUE str;
StringValue(data);
- in = RSTRING_PTR(data);
- if ((in_len = RSTRING_LEN(data)) == 0)
+ in = RSTRING(data)->ptr;
+ if ((in_len = RSTRING(data)->len) == 0)
rb_raise(rb_eArgError, "data must not be empty");
GetCipher(self, ctx);
- out_len = in_len+EVP_CIPHER_CTX_block_size(ctx);
-
- if (NIL_P(str)) {
- str = rb_str_new(0, out_len);
- } else {
- StringValue(str);
- rb_str_resize(str, out_len);
- }
-
- if (!EVP_CipherUpdate(ctx, RSTRING_PTR(str), &out_len, in, in_len))
+ str = rb_str_new(0, in_len+EVP_CIPHER_CTX_block_size(ctx));
+ if (!EVP_CipherUpdate(ctx, RSTRING(str)->ptr, &out_len, in, in_len))
ossl_raise(eCipherError, NULL);
- assert(out_len < RSTRING_LEN(str));
- rb_str_set_len(str, out_len);
+ assert(out_len < RSTRING(str)->len);
+ RSTRING(str)->len = out_len;
+ RSTRING(str)->ptr[out_len] = 0;
return str;
}
-/*
- * call-seq:
- * cipher.final -> aString
- *
- * Returns the remaining data held in the cipher object. Further calls to update() or final() will return garbage.
- *
- * See EVP_CipherFinal_ex for further information.
- */
+static VALUE
+ossl_cipher_update_deprecated(VALUE self, VALUE data)
+{
+ char *cname;
+
+ cname = rb_class2name(rb_obj_class(self));
+ rb_warning("%s#<< is deprecated; use %s#update instead", cname, cname);
+ return ossl_cipher_update(self, data);
+}
+
static VALUE
ossl_cipher_final(VALUE self)
{
@@ -372,20 +280,15 @@ ossl_cipher_final(VALUE self)
GetCipher(self, ctx);
str = rb_str_new(0, EVP_CIPHER_CTX_block_size(ctx));
- if (!EVP_CipherFinal_ex(ctx, RSTRING_PTR(str), &out_len))
+ if (!EVP_CipherFinal_ex(ctx, RSTRING(str)->ptr, &out_len))
ossl_raise(eCipherError, NULL);
- assert(out_len <= RSTRING_LEN(str));
- rb_str_set_len(str, out_len);
+ assert(out_len <= RSTRING(str)->len);
+ RSTRING(str)->len = out_len;
+ RSTRING(str)->ptr[out_len] = 0;
return str;
}
-/*
- * call-seq:
- * cipher.name -> string
- *
- * Returns the name of the cipher which may differ slightly from the original name provided.
- */
static VALUE
ossl_cipher_name(VALUE self)
{
@@ -396,14 +299,6 @@ ossl_cipher_name(VALUE self)
return rb_str_new2(EVP_CIPHER_name(EVP_CIPHER_CTX_cipher(ctx)));
}
-/*
- * call-seq:
- * cipher.key = string -> string
- *
- * Sets the cipher key.
- *
- * Only call this method after calling cipher.encrypt or cipher.decrypt.
- */
static VALUE
ossl_cipher_set_key(VALUE self, VALUE key)
{
@@ -412,23 +307,15 @@ ossl_cipher_set_key(VALUE self, VALUE key)
StringValue(key);
GetCipher(self, ctx);
- if (RSTRING_LEN(key) < EVP_CIPHER_CTX_key_length(ctx))
+ if (RSTRING(key)->len < EVP_CIPHER_CTX_key_length(ctx))
ossl_raise(eCipherError, "key length too short");
- if (EVP_CipherInit_ex(ctx, NULL, NULL, RSTRING_PTR(key), NULL, -1) != 1)
+ if (EVP_CipherInit_ex(ctx, NULL, NULL, RSTRING(key)->ptr, NULL, -1) != 1)
ossl_raise(eCipherError, NULL);
return key;
}
-/*
- * call-seq:
- * cipher.iv = string -> string
- *
- * Sets the cipher iv.
- *
- * Only call this method after calling cipher.encrypt or cipher.decrypt.
- */
static VALUE
ossl_cipher_set_iv(VALUE self, VALUE iv)
{
@@ -437,32 +324,20 @@ ossl_cipher_set_iv(VALUE self, VALUE iv)
StringValue(iv);
GetCipher(self, ctx);
- if (RSTRING_LEN(iv) < EVP_CIPHER_CTX_iv_length(ctx))
+ if (RSTRING(iv)->len < EVP_CIPHER_CTX_iv_length(ctx))
ossl_raise(eCipherError, "iv length too short");
- if (EVP_CipherInit_ex(ctx, NULL, NULL, NULL, RSTRING_PTR(iv), -1) != 1)
+ if (EVP_CipherInit_ex(ctx, NULL, NULL, NULL, RSTRING(iv)->ptr, -1) != 1)
ossl_raise(eCipherError, NULL);
return iv;
}
-
-/*
- * call-seq:
- * cipher.key_length = integer -> integer
- *
- * Sets the key length of the cipher. If the cipher is a fixed length cipher then attempting to set the key
- * length to any value other than the fixed value is an error.
- *
- * Under normal circumstances you do not need to call this method (and probably shouldn't).
- *
- * See EVP_CIPHER_CTX_set_key_length for further information.
- */
static VALUE
ossl_cipher_set_key_length(VALUE self, VALUE key_length)
{
- int len = NUM2INT(key_length);
EVP_CIPHER_CTX *ctx;
+ int len = NUM2INT(key_length);
GetCipher(self, ctx);
if (EVP_CIPHER_CTX_set_key_length(ctx, len) != 1)
@@ -471,16 +346,6 @@ ossl_cipher_set_key_length(VALUE self, VALUE key_length)
return key_length;
}
-/*
- * call-seq:
- * cipher.padding = integer -> integer
- *
- * Enables or disables padding. By default encryption operations are padded using standard block padding and the
- * padding is checked and removed when decrypting. If the pad parameter is zero then no padding is performed, the
- * total amount of data encrypted or decrypted must then be a multiple of the block size or an error will occur.
- *
- * See EVP_CIPHER_CTX_set_padding for further information.
- */
static VALUE
ossl_cipher_set_padding(VALUE self, VALUE padding)
{
@@ -509,27 +374,6 @@ CIPHER_0ARG_INT(key_length)
CIPHER_0ARG_INT(iv_length)
CIPHER_0ARG_INT(block_size)
-#if 0
-/*
- * call-seq:
- * cipher.key_length -> integer
- *
- */
-static VALUE ossl_cipher_key_length() { }
-/*
- * call-seq:
- * cipher.iv_length -> integer
- *
- */
-static VALUE ossl_cipher_iv_length() { }
-/*
- * call-seq:
- * cipher.block_size -> integer
- *
- */
-static VALUE ossl_cipher_block_size() { }
-#endif
-
/*
* INIT
*/
@@ -539,21 +383,21 @@ Init_ossl_cipher(void)
#if 0 /* let rdoc know about mOSSL */
mOSSL = rb_define_module("OpenSSL");
#endif
- cCipher = rb_define_class_under(mOSSL, "Cipher", rb_cObject);
- eCipherError = rb_define_class_under(cCipher, "CipherError", eOSSLError);
+
+ mCipher = rb_define_module_under(mOSSL, "Cipher");
+ eCipherError = rb_define_class_under(mOSSL, "CipherError", eOSSLError);
+ cCipher = rb_define_class_under(mCipher, "Cipher", rb_cObject);
rb_define_alloc_func(cCipher, ossl_cipher_alloc);
rb_define_copy_func(cCipher, ossl_cipher_copy);
- rb_define_module_function(cCipher, "ciphers", ossl_s_ciphers, 0);
+ rb_define_module_function(mCipher, "ciphers", ossl_s_ciphers, 0);
rb_define_method(cCipher, "initialize", ossl_cipher_initialize, 1);
rb_define_method(cCipher, "reset", ossl_cipher_reset, 0);
rb_define_method(cCipher, "encrypt", ossl_cipher_encrypt, -1);
rb_define_method(cCipher, "decrypt", ossl_cipher_decrypt, -1);
rb_define_method(cCipher, "pkcs5_keyivgen", ossl_cipher_pkcs5_keyivgen, -1);
- rb_define_method(cCipher, "update", ossl_cipher_update, -1);
-#if RUBY_VERSION_CODE < 190
+ rb_define_method(cCipher, "update", ossl_cipher_update, 1);
rb_define_method(cCipher, "<<", ossl_cipher_update_deprecated, 1);
-#endif
rb_define_method(cCipher, "final", ossl_cipher_final, 0);
rb_define_method(cCipher, "name", ossl_cipher_name, 0);
rb_define_method(cCipher, "key=", ossl_cipher_set_key, 1);
@@ -564,4 +408,3 @@ Init_ossl_cipher(void)
rb_define_method(cCipher, "block_size", ossl_cipher_block_size, 0);
rb_define_method(cCipher, "padding=", ossl_cipher_set_padding, 1);
}
-
diff --git a/ext/openssl/ossl_cipher.h b/ext/openssl/ossl_cipher.h
index bed4fa853b..63c7a875e8 100644
--- a/ext/openssl/ossl_cipher.h
+++ b/ext/openssl/ossl_cipher.h
@@ -11,6 +11,7 @@
#if !defined(_OSSL_CIPHER_H_)
#define _OSSL_CIPHER_H_
+extern VALUE mCipher;
extern VALUE cCipher;
extern VALUE eCipherError;
diff --git a/ext/openssl/ossl_config.c b/ext/openssl/ossl_config.c
index cc8e324029..f1d6a98253 100644
--- a/ext/openssl/ossl_config.c
+++ b/ext/openssl/ossl_config.c
@@ -171,16 +171,16 @@ ossl_config_add_value(VALUE self, VALUE section, VALUE name, VALUE value)
StringValue(name);
StringValue(value);
GetConfig(self, conf);
- if(!(sv = _CONF_get_section(conf, RSTRING_PTR(section)))){
- if(!(sv = _CONF_new_section(conf, RSTRING_PTR(section)))){
+ if(!(sv = _CONF_get_section(conf, RSTRING(section)->ptr))){
+ if(!(sv = _CONF_new_section(conf, RSTRING(section)->ptr))){
ossl_raise(eConfigError, NULL);
}
}
if(!(cv = OPENSSL_malloc(sizeof(CONF_VALUE)))){
ossl_raise(eConfigError, NULL);
}
- cv->name = BUF_strdup(RSTRING_PTR(name));
- cv->value = BUF_strdup(RSTRING_PTR(value));
+ cv->name = BUF_strdup(RSTRING(name)->ptr);
+ cv->value = BUF_strdup(RSTRING(value)->ptr);
if(!cv->name || !cv->value || !_CONF_add_string(conf, sv, cv)){
OPENSSL_free(cv->name);
OPENSSL_free(cv->value);
@@ -201,7 +201,7 @@ ossl_config_get_value(VALUE self, VALUE section, VALUE name)
StringValue(section);
StringValue(name);
GetConfig(self, conf);
- str = NCONF_get_string(conf, RSTRING_PTR(section), RSTRING_PTR(name));
+ str = NCONF_get_string(conf, RSTRING(section)->ptr, RSTRING(name)->ptr);
if(!str){
ERR_clear_error();
return Qnil;
@@ -249,7 +249,7 @@ ossl_config_set_section(VALUE self, VALUE section, VALUE hash)
arg[0] = self;
arg[1] = section;
- rb_block_call(hash, rb_intern("each"), 0, 0, set_conf_section_i, (VALUE)arg);
+ rb_iterate(rb_each, hash, set_conf_section_i, (VALUE)arg);
return hash;
}
diff --git a/ext/openssl/ossl_digest.c b/ext/openssl/ossl_digest.c
index 879d399fe7..4096b097a2 100644
--- a/ext/openssl/ossl_digest.c
+++ b/ext/openssl/ossl_digest.c
@@ -24,6 +24,7 @@
/*
* Classes
*/
+VALUE mDigest;
VALUE cDigest;
VALUE eDigestError;
@@ -35,23 +36,11 @@ static VALUE ossl_digest_alloc(VALUE klass);
const EVP_MD *
GetDigestPtr(VALUE obj)
{
- const EVP_MD *md;
-
- if (TYPE(obj) == T_STRING) {
- const char *name = STR2CSTR(obj);
-
- md = EVP_get_digestbyname(name);
- if (!md)
- ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name);
- } else {
- EVP_MD_CTX *ctx;
-
- SafeGetDigest(obj, ctx);
+ EVP_MD_CTX *ctx;
- md = EVP_MD_CTX_md(ctx);
- }
+ SafeGetDigest(obj, ctx);
- return md;
+ return EVP_MD_CTX_md(ctx); /*== ctx->digest*/
}
VALUE
@@ -62,6 +51,7 @@ ossl_digest_new(const EVP_MD *md)
ret = ossl_digest_alloc(cDigest);
GetDigest(ret, ctx);
+ EVP_MD_CTX_init(ctx);
EVP_DigestInit_ex(ctx, md, NULL);
return ret;
@@ -79,18 +69,14 @@ ossl_digest_alloc(VALUE klass)
ctx = EVP_MD_CTX_create();
if (ctx == NULL)
ossl_raise(rb_eRuntimeError, "EVP_MD_CTX_create() failed");
+ EVP_MD_CTX_init(ctx);
obj = Data_Wrap_Struct(klass, 0, EVP_MD_CTX_destroy, ctx);
-
+
return obj;
}
VALUE ossl_digest_update(VALUE, VALUE);
-/*
- * call-seq:
- * Digest.new(string) -> digest
- *
- */
static VALUE
ossl_digest_initialize(int argc, VALUE *argv, VALUE self)
{
@@ -100,9 +86,14 @@ ossl_digest_initialize(int argc, VALUE *argv, VALUE self)
VALUE type, data;
rb_scan_args(argc, argv, "11", &type, &data);
- md = GetDigestPtr(type);
+ StringValue(type);
if (!NIL_P(data)) StringValue(data);
-
+ name = StringValuePtr(type);
+
+ md = EVP_get_digestbyname(name);
+ if (!md) {
+ ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name);
+ }
GetDigest(self, ctx);
EVP_DigestInit_ex(ctx, md, NULL);
@@ -127,11 +118,6 @@ ossl_digest_copy(VALUE self, VALUE other)
return self;
}
-/*
- * call-seq:
- * digest.reset -> self
- *
- */
static VALUE
ossl_digest_reset(VALUE self)
{
@@ -143,11 +129,6 @@ ossl_digest_reset(VALUE self)
return self;
}
-/*
- * call-seq:
- * digest.update(string) -> aString
- *
- */
VALUE
ossl_digest_update(VALUE self, VALUE data)
{
@@ -155,77 +136,126 @@ ossl_digest_update(VALUE self, VALUE data)
StringValue(data);
GetDigest(self, ctx);
- EVP_DigestUpdate(ctx, RSTRING_PTR(data), RSTRING_LEN(data));
+ EVP_DigestUpdate(ctx, RSTRING(data)->ptr, RSTRING(data)->len);
return self;
}
-/*
- * call-seq:
- * digest.finish -> aString
- *
- */
+static void
+digest_final(EVP_MD_CTX *ctx, char **buf, int *buf_len)
+{
+ EVP_MD_CTX final;
+
+ if (!EVP_MD_CTX_copy(&final, ctx)) {
+ ossl_raise(eDigestError, NULL);
+ }
+ if (!(*buf = OPENSSL_malloc(EVP_MD_CTX_size(&final)))) {
+ EVP_MD_CTX_cleanup(&final);
+ ossl_raise(eDigestError, "Cannot allocate mem for digest");
+ }
+ EVP_DigestFinal_ex(&final, *buf, buf_len);
+ EVP_MD_CTX_cleanup(&final);
+}
+
static VALUE
-ossl_digest_finish(int argc, VALUE *argv, VALUE self)
+ossl_digest_digest(VALUE self)
{
EVP_MD_CTX *ctx;
- VALUE str;
+ char *buf;
+ int buf_len;
+ VALUE digest;
+
+ GetDigest(self, ctx);
+ digest_final(ctx, &buf, &buf_len);
+ digest = ossl_buf2str(buf, buf_len);
+
+ return digest;
+}
- rb_scan_args(argc, argv, "01", &str);
+static VALUE
+ossl_digest_hexdigest(VALUE self)
+{
+ EVP_MD_CTX *ctx;
+ char *buf, *hexbuf;
+ int buf_len;
+ VALUE hexdigest;
GetDigest(self, ctx);
-
- if (NIL_P(str)) {
- str = rb_str_new(NULL, EVP_MD_CTX_size(ctx));
- } else {
- StringValue(str);
- rb_str_resize(str, EVP_MD_CTX_size(ctx));
+ digest_final(ctx, &buf, &buf_len);
+ if (string2hex(buf, buf_len, &hexbuf, NULL) != 2 * buf_len) {
+ OPENSSL_free(buf);
+ ossl_raise(eDigestError, "Memory alloc error");
}
+ OPENSSL_free(buf);
+ hexdigest = ossl_buf2str(hexbuf, 2 * buf_len);
- EVP_DigestFinal_ex(ctx, RSTRING_PTR(str), NULL);
+ return hexdigest;
+}
- return str;
+static VALUE
+ossl_digest_s_digest(VALUE klass, VALUE str, VALUE data)
+{
+ VALUE obj = rb_class_new_instance(1, &str, klass);
+
+ ossl_digest_update(obj, data);
+
+ return ossl_digest_digest(obj);
}
-/*
- * call-seq:
- * digest.name -> string
- *
- */
static VALUE
-ossl_digest_name(VALUE self)
+ossl_digest_s_hexdigest(VALUE klass, VALUE str, VALUE data)
+{
+ VALUE obj = rb_class_new_instance(1, &str, klass);
+
+ ossl_digest_update(obj, data);
+
+ return ossl_digest_hexdigest(obj);
+}
+
+static VALUE
+ossl_digest_equal(VALUE self, VALUE other)
{
EVP_MD_CTX *ctx;
+ VALUE str1, str2;
+ if (rb_obj_is_kind_of(other, cDigest) == Qtrue) {
+ str2 = ossl_digest_digest(other);
+ } else {
+ StringValue(other);
+ str2 = other;
+ }
GetDigest(self, ctx);
+ if (RSTRING(str2)->len == EVP_MD_CTX_size(ctx)) {
+ str1 = ossl_digest_digest(self);
+ } else {
+ str1 = ossl_digest_hexdigest(self);
+ }
+ if (RSTRING(str1)->len == RSTRING(str2)->len
+ && rb_str_cmp(str1, str2) == 0) {
+ return Qtrue;
+ }
- return rb_str_new2(EVP_MD_name(EVP_MD_CTX_md(ctx)));
+ return Qfalse;
}
-/*
- * call-seq:
- * digest.digest_size -> integer
- *
- * Returns the output size of the digest.
- */
static VALUE
-ossl_digest_size(VALUE self)
+ossl_digest_name(VALUE self)
{
EVP_MD_CTX *ctx;
GetDigest(self, ctx);
- return INT2NUM(EVP_MD_CTX_size(ctx));
+ return rb_str_new2(EVP_MD_name(EVP_MD_CTX_md(ctx)));
}
static VALUE
-ossl_digest_block_length(VALUE self)
+ossl_digest_size(VALUE self)
{
EVP_MD_CTX *ctx;
GetDigest(self, ctx);
- return INT2NUM(EVP_MD_CTX_block_size(ctx));
+ return INT2NUM(EVP_MD_CTX_size(ctx));
}
/*
@@ -234,26 +264,35 @@ ossl_digest_block_length(VALUE self)
void
Init_ossl_digest()
{
- rb_require("openssl");
- rb_require("digest");
-
#if 0 /* let rdoc know about mOSSL */
mOSSL = rb_define_module("OpenSSL");
#endif
- cDigest = rb_define_class_under(mOSSL, "Digest", rb_path2class("Digest::Class"));
- eDigestError = rb_define_class_under(cDigest, "DigestError", eOSSLError);
+ mDigest = rb_define_module_under(mOSSL, "Digest");
+
+ eDigestError = rb_define_class_under(mDigest, "DigestError", eOSSLError);
+
+ cDigest = rb_define_class_under(mDigest, "Digest", rb_cObject);
rb_define_alloc_func(cDigest, ossl_digest_alloc);
-
+ rb_define_singleton_method(cDigest, "digest", ossl_digest_s_digest, 2);
+ rb_define_singleton_method(cDigest, "hexdigest", ossl_digest_s_hexdigest, 2);
+
rb_define_method(cDigest, "initialize", ossl_digest_initialize, -1);
- rb_define_copy_func(cDigest, ossl_digest_copy);
rb_define_method(cDigest, "reset", ossl_digest_reset, 0);
+
+ rb_define_copy_func(cDigest, ossl_digest_copy);
+
+ rb_define_method(cDigest, "digest", ossl_digest_digest, 0);
+ rb_define_method(cDigest, "hexdigest", ossl_digest_hexdigest, 0);
+ rb_define_alias(cDigest, "inspect", "hexdigest");
+ rb_define_alias(cDigest, "to_s", "hexdigest");
+
rb_define_method(cDigest, "update", ossl_digest_update, 1);
rb_define_alias(cDigest, "<<", "update");
- rb_define_private_method(cDigest, "finish", ossl_digest_finish, -1);
- rb_define_method(cDigest, "digest_length", ossl_digest_size, 0);
- rb_define_method(cDigest, "block_length", ossl_digest_block_length, 0);
-
+
+ rb_define_method(cDigest, "==", ossl_digest_equal, 1);
+
rb_define_method(cDigest, "name", ossl_digest_name, 0);
+ rb_define_method(cDigest, "size", ossl_digest_size, 0);
}
diff --git a/ext/openssl/ossl_digest.h b/ext/openssl/ossl_digest.h
index 8cc5b1bc56..8a1f7964f2 100644
--- a/ext/openssl/ossl_digest.h
+++ b/ext/openssl/ossl_digest.h
@@ -11,6 +11,7 @@
#if !defined(_OSSL_DIGEST_H_)
#define _OSSL_DIGEST_H_
+extern VALUE mDigest;
extern VALUE cDigest;
extern VALUE eDigestError;
diff --git a/ext/openssl/ossl_engine.c b/ext/openssl/ossl_engine.c
index cd835d1237..71586e3620 100644
--- a/ext/openssl/ossl_engine.c
+++ b/ext/openssl/ossl_engine.c
@@ -40,7 +40,7 @@ VALUE eEngineError;
*/
#define OSSL_ENGINE_LOAD_IF_MATCH(x) \
do{\
- if(!strcmp(#x, RSTRING_PTR(name))){\
+ if(!strcmp(#x, RSTRING(name)->ptr)){\
ENGINE_load_##x();\
return Qtrue;\
}\
@@ -75,7 +75,7 @@ ossl_engine_s_load(int argc, VALUE *argv, VALUE klass)
OSSL_ENGINE_LOAD_IF_MATCH(openbsd_dev_crypto);
#endif
OSSL_ENGINE_LOAD_IF_MATCH(openssl);
- rb_warning("no such builtin loader for `%s'", RSTRING_PTR(name));
+ rb_warning("no such builtin loader for `%s'", RSTRING(name)->ptr);
return Qnil;
#endif /* HAVE_ENGINE_LOAD_BUILTIN_ENGINES */
}
@@ -112,7 +112,7 @@ ossl_engine_s_by_id(VALUE klass, VALUE id)
StringValue(id);
ossl_engine_s_load(1, &id, klass);
- if(!(e = ENGINE_by_id(RSTRING_PTR(id))))
+ if(!(e = ENGINE_by_id(RSTRING(id)->ptr)))
ossl_raise(eEngineError, NULL);
WrapEngine(klass, obj, e);
if(rb_block_given_p()) rb_yield(obj);
@@ -281,8 +281,8 @@ ossl_engine_ctrl_cmd(int argc, VALUE *argv, VALUE self)
rb_scan_args(argc, argv, "11", &cmd, &val);
StringValue(cmd);
if (!NIL_P(val)) StringValue(val);
- ret = ENGINE_ctrl_cmd_string(e, RSTRING_PTR(cmd),
- NIL_P(val) ? NULL : RSTRING_PTR(val), 0);
+ ret = ENGINE_ctrl_cmd_string(e, RSTRING(cmd)->ptr,
+ NIL_P(val) ? NULL : RSTRING(val)->ptr, 0);
if (!ret) ossl_raise(eEngineError, NULL);
return self;
diff --git a/ext/openssl/ossl_hmac.c b/ext/openssl/ossl_hmac.c
index ef77d6c427..312343e03d 100644
--- a/ext/openssl/ossl_hmac.c
+++ b/ext/openssl/ossl_hmac.c
@@ -57,12 +57,6 @@ ossl_hmac_alloc(VALUE klass)
return obj;
}
-
-/*
- * call-seq:
- * HMAC.new(key, digest) -> hmac
- *
- */
static VALUE
ossl_hmac_initialize(VALUE self, VALUE key, VALUE digest)
{
@@ -70,7 +64,7 @@ ossl_hmac_initialize(VALUE self, VALUE key, VALUE digest)
StringValue(key);
GetHMAC(self, ctx);
- HMAC_Init_ex(ctx, RSTRING_PTR(key), RSTRING_LEN(key),
+ HMAC_Init_ex(ctx, RSTRING(key)->ptr, RSTRING(key)->len,
GetDigestPtr(digest), NULL);
return self;
@@ -87,15 +81,12 @@ ossl_hmac_copy(VALUE self, VALUE other)
GetHMAC(self, ctx1);
SafeGetHMAC(other, ctx2);
- HMAC_CTX_copy(ctx1, ctx2);
+ if (!HMAC_CTX_copy(ctx1, ctx2)) {
+ ossl_raise(eHMACError, NULL);
+ }
return self;
}
-/*
- * call-seq:
- * hmac.update(string) -> self
- *
- */
static VALUE
ossl_hmac_update(VALUE self, VALUE data)
{
@@ -103,7 +94,7 @@ ossl_hmac_update(VALUE self, VALUE data)
StringValue(data);
GetHMAC(self, ctx);
- HMAC_Update(ctx, RSTRING_PTR(data), RSTRING_LEN(data));
+ HMAC_Update(ctx, RSTRING(data)->ptr, RSTRING(data)->len);
return self;
}
@@ -113,7 +104,9 @@ hmac_final(HMAC_CTX *ctx, char **buf, int *buf_len)
{
HMAC_CTX final;
- HMAC_CTX_copy(&final, ctx);
+ if (!HMAC_CTX_copy(&final, ctx)) {
+ ossl_raise(eHMACError, NULL);
+ }
if (!(*buf = OPENSSL_malloc(HMAC_size(&final)))) {
HMAC_CTX_cleanup(&final);
OSSL_Debug("Allocating %d mem", HMAC_size(&final));
@@ -123,11 +116,6 @@ hmac_final(HMAC_CTX *ctx, char **buf, int *buf_len)
HMAC_CTX_cleanup(&final);
}
-/*
- * call-seq:
- * hmac.digest -> aString
- *
- */
static VALUE
ossl_hmac_digest(VALUE self)
{
@@ -143,11 +131,6 @@ ossl_hmac_digest(VALUE self)
return digest;
}
-/*
- * call-seq:
- * hmac.hexdigest -> aString
- *
- */
static VALUE
ossl_hmac_hexdigest(VALUE self)
{
@@ -168,27 +151,6 @@ ossl_hmac_hexdigest(VALUE self)
return hexdigest;
}
-/*
- * call-seq:
- * hmac.reset -> self
- *
- */
-static VALUE
-ossl_hmac_reset(VALUE self)
-{
- HMAC_CTX *ctx;
-
- GetHMAC(self, ctx);
- HMAC_Init_ex(ctx, NULL, 0, NULL, NULL);
-
- return self;
-}
-
-/*
- * call-seq:
- * HMAC.digest(digest, key, data) -> aString
- *
- */
static VALUE
ossl_hmac_s_digest(VALUE klass, VALUE digest, VALUE key, VALUE data)
{
@@ -197,17 +159,12 @@ ossl_hmac_s_digest(VALUE klass, VALUE digest, VALUE key, VALUE data)
StringValue(key);
StringValue(data);
- buf = HMAC(GetDigestPtr(digest), RSTRING_PTR(key), RSTRING_LEN(key),
- RSTRING_PTR(data), RSTRING_LEN(data), NULL, &buf_len);
+ buf = HMAC(GetDigestPtr(digest), RSTRING(key)->ptr, RSTRING(key)->len,
+ RSTRING(data)->ptr, RSTRING(data)->len, NULL, &buf_len);
return rb_str_new(buf, buf_len);
}
-/*
- * call-seq:
- * HMAC.digest(digest, key, data) -> aString
- *
- */
static VALUE
ossl_hmac_s_hexdigest(VALUE klass, VALUE digest, VALUE key, VALUE data)
{
@@ -218,8 +175,8 @@ ossl_hmac_s_hexdigest(VALUE klass, VALUE digest, VALUE key, VALUE data)
StringValue(key);
StringValue(data);
- buf = HMAC(GetDigestPtr(digest), RSTRING_PTR(key), RSTRING_LEN(key),
- RSTRING_PTR(data), RSTRING_LEN(data), NULL, &buf_len);
+ buf = HMAC(GetDigestPtr(digest), RSTRING(key)->ptr, RSTRING(key)->len,
+ RSTRING(data)->ptr, RSTRING(data)->len, NULL, &buf_len);
if (string2hex(buf, buf_len, &hexbuf, NULL) != 2 * buf_len) {
ossl_raise(eHMACError, "Cannot convert buf to hexbuf");
}
@@ -249,7 +206,6 @@ Init_ossl_hmac()
rb_define_method(cHMAC, "initialize", ossl_hmac_initialize, 2);
rb_define_copy_func(cHMAC, ossl_hmac_copy);
- rb_define_method(cHMAC, "reset", ossl_hmac_reset, 0);
rb_define_method(cHMAC, "update", ossl_hmac_update, 1);
rb_define_alias(cHMAC, "<<", "update");
rb_define_method(cHMAC, "digest", ossl_hmac_digest, 0);
diff --git a/ext/openssl/ossl_ns_spki.c b/ext/openssl/ossl_ns_spki.c
index 738a203d93..66e28374cc 100644
--- a/ext/openssl/ossl_ns_spki.c
+++ b/ext/openssl/ossl_ns_spki.c
@@ -62,9 +62,9 @@ ossl_spki_initialize(int argc, VALUE *argv, VALUE self)
return self;
}
StringValue(buffer);
- if (!(spki = NETSCAPE_SPKI_b64_decode(RSTRING_PTR(buffer), -1))) {
- p = RSTRING_PTR(buffer);
- if (!(spki = d2i_NETSCAPE_SPKI(NULL, &p, RSTRING_LEN(buffer)))) {
+ if (!(spki = NETSCAPE_SPKI_b64_decode(RSTRING(buffer)->ptr, -1))) {
+ p = RSTRING(buffer)->ptr;
+ if (!(spki = d2i_NETSCAPE_SPKI(NULL, &p, RSTRING(buffer)->len))) {
ossl_raise(eSPKIError, NULL);
}
}
@@ -87,7 +87,7 @@ ossl_spki_to_der(VALUE self)
if ((len = i2d_NETSCAPE_SPKI(spki, NULL)) <= 0)
ossl_raise(eX509CertError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if (i2d_NETSCAPE_SPKI(spki, &p) <= 0)
ossl_raise(eX509CertError, NULL);
ossl_str_adjust(str, p);
@@ -183,8 +183,8 @@ ossl_spki_set_challenge(VALUE self, VALUE str)
StringValue(str);
GetSPKI(self, spki);
- if (!ASN1_STRING_set(spki->spkac->challenge, RSTRING_PTR(str),
- RSTRING_LEN(str))) {
+ if (!ASN1_STRING_set(spki->spkac->challenge, RSTRING(str)->ptr,
+ RSTRING(str)->len)) {
ossl_raise(eSPKIError, NULL);
}
diff --git a/ext/openssl/ossl_ocsp.c b/ext/openssl/ossl_ocsp.c
index 1e8e5903bd..b5ea9dadf5 100644
--- a/ext/openssl/ossl_ocsp.c
+++ b/ext/openssl/ossl_ocsp.c
@@ -109,9 +109,9 @@ ossl_ocspreq_initialize(int argc, VALUE *argv, VALUE self)
if(!NIL_P(arg)){
arg = ossl_to_der_if_possible(arg);
StringValue(arg);
- p = (unsigned char*)RSTRING_PTR(arg);
+ p = (unsigned char*)RSTRING(arg)->ptr;
if(!d2i_OCSP_REQUEST((OCSP_REQUEST**)&DATA_PTR(self), &p,
- RSTRING_LEN(arg))){
+ RSTRING(arg)->len)){
ossl_raise(eOCSPError, "cannot load DER encoded request");
}
}
@@ -134,7 +134,7 @@ ossl_ocspreq_add_nonce(int argc, VALUE *argv, VALUE self)
else{
StringValue(val);
GetOCSPReq(self, req);
- ret = OCSP_request_add1_nonce(req, RSTRING_PTR(val), RSTRING_LEN(val));
+ ret = OCSP_request_add1_nonce(req, RSTRING(val)->ptr, RSTRING(val)->len);
}
if(!ret) ossl_raise(eOCSPError, NULL);
@@ -265,7 +265,7 @@ ossl_ocspreq_to_der(VALUE self)
if((len = i2d_OCSP_REQUEST(req, NULL)) <= 0)
ossl_raise(eOCSPError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_OCSP_REQUEST(req, &p) <= 0)
ossl_raise(eOCSPError, NULL);
ossl_str_adjust(str, p);
@@ -316,9 +316,9 @@ ossl_ocspres_initialize(int argc, VALUE *argv, VALUE self)
if(!NIL_P(arg)){
arg = ossl_to_der_if_possible(arg);
StringValue(arg);
- p = RSTRING_PTR(arg);
+ p = RSTRING(arg)->ptr;
if(!d2i_OCSP_RESPONSE((OCSP_RESPONSE**)&DATA_PTR(self), &p,
- RSTRING_LEN(arg))){
+ RSTRING(arg)->len)){
ossl_raise(eOCSPError, "cannot load DER encoded response");
}
}
@@ -377,7 +377,7 @@ ossl_ocspres_to_der(VALUE self)
if((len = i2d_OCSP_RESPONSE(res, NULL)) <= 0)
ossl_raise(eOCSPError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_OCSP_RESPONSE(res, NULL) <= 0)
ossl_raise(eOCSPError, NULL);
ossl_str_adjust(str, p);
@@ -436,7 +436,7 @@ ossl_ocspbres_add_nonce(int argc, VALUE *argv, VALUE self)
else{
StringValue(val);
GetOCSPBasicRes(self, bs);
- ret = OCSP_basic_add1_nonce(bs, RSTRING_PTR(val), RSTRING_LEN(val));
+ ret = OCSP_basic_add1_nonce(bs, RSTRING(val)->ptr, RSTRING(val)->len);
}
if(!ret) ossl_raise(eOCSPError, NULL);
@@ -461,8 +461,8 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
if(!NIL_P(ext)){
/* All ary's members should be X509Extension */
Check_Type(ext, T_ARRAY);
- for (i = 0; i < RARRAY_LEN(ext); i++)
- OSSL_Check_Kind(RARRAY_PTR(ext)[i], cX509Ext);
+ for (i = 0; i < RARRAY(ext)->len; i++)
+ OSSL_Check_Kind(RARRAY(ext)->ptr[i], cX509Ext);
}
error = 0;
@@ -490,8 +490,8 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
X509_EXTENSION *x509ext;
sk_X509_EXTENSION_pop_free(single->singleExtensions, X509_EXTENSION_free);
single->singleExtensions = NULL;
- for(i = 0; i < RARRAY_LEN(ext); i++){
- x509ext = DupX509ExtPtr(RARRAY_PTR(ext)[i]);
+ for(i = 0; i < RARRAY(ext)->len; i++){
+ x509ext = DupX509ExtPtr(RARRAY(ext)->ptr[i]);
if(!OCSP_SINGLERESP_add_ext(single, x509ext, -1)){
X509_EXTENSION_free(x509ext);
error = 1;
diff --git a/ext/openssl/ossl_pkcs12.c b/ext/openssl/ossl_pkcs12.c
index 2ec69ba8db..e7d9954c5a 100644
--- a/ext/openssl/ossl_pkcs12.c
+++ b/ext/openssl/ossl_pkcs12.c
@@ -30,6 +30,7 @@
/*
* Classes
*/
+VALUE mPKCS12;
VALUE cPKCS12;
VALUE ePKCS12Error;
@@ -48,85 +49,32 @@ ossl_pkcs12_s_allocate(VALUE klass)
return obj;
}
-/*
- * call-seq:
- * PKCS12.create(pass, name, key, cert [, ca, [, key_pbe [, cert_pbe [, key_iter [, mac_iter [, keytype]]]]]])
- *
- * === Parameters
- * * +pass+ - string
- * * +name+ - A string describing the key.
- * * +key+ - Any PKey.
- * * +cert+ - A X509::Certificate.
- * * * The public_key portion of the certificate must contain a valid public key.
- * * * The not_before and not_after fields must be filled in.
- * * +ca+ - An optional array of X509::Certificate's.
- * * +key_pbe+ - string
- * * +cert_pbe+ - string
- * * +key_iter+ - integer
- * * +mac_iter+ - integer
- * * +keytype+ - An integer representing an MSIE specific extension.
- *
- * Any optional arguments may be supplied as nil to preserve the OpenSSL defaults.
- *
- * See the OpenSSL documentation for PKCS12_create().
- */
static VALUE
ossl_pkcs12_s_create(int argc, VALUE *argv, VALUE self)
{
- VALUE pass, name, pkey, cert, ca, key_nid, cert_nid, key_iter, mac_iter, keytype;
+ VALUE pass, name, pkey, cert, ca;
VALUE obj;
char *passphrase, *friendlyname;
EVP_PKEY *key;
X509 *x509;
STACK_OF(X509) *x509s;
- int nkey = 0, ncert = 0, kiter = 0, miter = 0, ktype = 0;
PKCS12 *p12;
- rb_scan_args(argc, argv, "46", &pass, &name, &pkey, &cert, &ca, &key_nid, &cert_nid, &key_iter, &mac_iter, &keytype);
+ rb_scan_args(argc, argv, "41", &pass, &name, &pkey, &cert, &ca);
passphrase = NIL_P(pass) ? NULL : StringValuePtr(pass);
friendlyname = NIL_P(name) ? NULL : StringValuePtr(name);
key = GetPKeyPtr(pkey);
x509 = GetX509CertPtr(cert);
x509s = NIL_P(ca) ? NULL : ossl_x509_ary2sk(ca);
-/* TODO: make a VALUE to nid function */
- if (!NIL_P(key_nid)) {
- if ((nkey = OBJ_txt2nid(StringValuePtr(key_nid))) == NID_undef)
- rb_raise(rb_eArgError, "Unknown PBE algorithm %s", StringValuePtr(key_nid));
- }
- if (!NIL_P(cert_nid)) {
- if ((ncert = OBJ_txt2nid(StringValuePtr(cert_nid))) == NID_undef)
- rb_raise(rb_eArgError, "Unknown PBE algorithm %s", StringValuePtr(cert_nid));
- }
- if (!NIL_P(key_iter))
- kiter = NUM2INT(key_iter);
- if (!NIL_P(mac_iter))
- miter = NUM2INT(mac_iter);
- if (!NIL_P(keytype))
- ktype = NUM2INT(keytype);
-
p12 = PKCS12_create(passphrase, friendlyname, key, x509, x509s,
- nkey, ncert, kiter, miter, ktype);
+ 0, 0, 0, 0, 0);
sk_X509_pop_free(x509s, X509_free);
if(!p12) ossl_raise(ePKCS12Error, NULL);
WrapPKCS12(cPKCS12, obj, p12);
- ossl_pkcs12_set_key(obj, pkey);
- ossl_pkcs12_set_cert(obj, cert);
- ossl_pkcs12_set_ca_certs(obj, ca);
-
return obj;
}
-/*
- * call-seq:
- * PKCS12.new -> pkcs12
- * PKCS12.new(str) -> pkcs12
- * PKCS12.new(str, pass) -> pkcs12
- *
- * === Parameters
- * * +str+ - Must be a DER encoded PKCS12 string.
- * * +pass+ - string
- */
static VALUE
ossl_pkcs12_initialize(int argc, VALUE *argv, VALUE self)
{
@@ -146,7 +94,7 @@ ossl_pkcs12_initialize(int argc, VALUE *argv, VALUE self)
pkey = cert = ca = Qnil;
if(!PKCS12_parse((PKCS12*)DATA_PTR(self), passphrase, &key, &x509, &x509s))
- ossl_raise(ePKCS12Error, "PKCS12_parse");
+ ossl_raise(ePKCS12Error, NULL);
pkey = rb_protect((VALUE(*)_((VALUE)))ossl_pkey_new, (VALUE)key,
&st); /* NO DUP */
if(st) goto err;
@@ -181,7 +129,7 @@ ossl_pkcs12_to_der(VALUE self)
if((len = i2d_PKCS12(p12, NULL)) <= 0)
ossl_raise(ePKCS12Error, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_PKCS12(p12, &p) <= 0)
ossl_raise(ePKCS12Error, NULL);
ossl_str_adjust(str, p);
@@ -192,14 +140,10 @@ ossl_pkcs12_to_der(VALUE self)
void
Init_ossl_pkcs12()
{
- /*
- * Defines a file format commonly used to store private keys with
- * accompanying public key certificates, protected with a password-based
- * symmetric key.
- */
- cPKCS12 = rb_define_class_under(mOSSL, "PKCS12", rb_cObject);
- ePKCS12Error = rb_define_class_under(cPKCS12, "PKCS12Error", eOSSLError);
- rb_define_singleton_method(cPKCS12, "create", ossl_pkcs12_s_create, -1);
+ mPKCS12 = rb_define_module_under(mOSSL, "PKCS12");
+ cPKCS12 = rb_define_class_under(mPKCS12, "PKCS12", rb_cObject);
+ ePKCS12Error = rb_define_class_under(mPKCS12, "PKCS12Error", eOSSLError);
+ rb_define_module_function(mPKCS12, "create", ossl_pkcs12_s_create, -1);
rb_define_alloc_func(cPKCS12, ossl_pkcs12_s_allocate);
rb_attr(cPKCS12, rb_intern("key"), 1, 0, Qfalse);
diff --git a/ext/openssl/ossl_pkcs12.h b/ext/openssl/ossl_pkcs12.h
index 24d25d00bb..01dde2bc30 100644
--- a/ext/openssl/ossl_pkcs12.h
+++ b/ext/openssl/ossl_pkcs12.h
@@ -6,6 +6,7 @@
#if !defined(_OSSL_PKCS12_H_)
#define _OSSL_PKCS12_H_
+extern VALUE mPKCS12;
extern VALUE cPKCS12;
extern VALUE ePKCS12Error;
diff --git a/ext/openssl/ossl_pkcs5.c b/ext/openssl/ossl_pkcs5.c
deleted file mode 100644
index 007889fc94..0000000000
--- a/ext/openssl/ossl_pkcs5.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * $Id$
- * Copyright (C) 2007 Technorama Ltd. <oss-ruby@technorama.net>
- */
-#include "ossl.h"
-
-VALUE mPKCS5;
-VALUE ePKCS5;
-
-/*
- * call-seq:
- * PKCS5.pbkdf2_hmac(pass, salt, iter, keylen, digest) => string
- *
- * === Parameters
- * * +pass+ - string
- * * +salt+ - string
- * * +iter+ - integer - should be greater than 1000. 2000 is better.
- * * +keylen+ - integer
- * * +digest+ - a string or OpenSSL::Digest object.
- *
- * Available in OpenSSL 0.9.9?.
- *
- * Digests other than SHA1 may not be supported by other cryptography libraries.
- */
-static VALUE
-ossl_pkcs5_pbkdf2_hmac(VALUE self, VALUE pass, VALUE salt, VALUE iter, VALUE keylen, VALUE digest)
-{
-#ifdef HAVE_PKCS5_PBKDF2_HMAC
- VALUE str;
- const EVP_MD *md;
- int len = NUM2INT(keylen);
-
- StringValue(pass);
- StringValue(salt);
- md = GetDigestPtr(digest);
-
- str = rb_str_new(0, len);
-
- if (PKCS5_PBKDF2_HMAC(RSTRING_PTR(pass), RSTRING_LEN(pass), RSTRING_PTR(salt), RSTRING_LEN(salt), NUM2INT(iter), md, len, RSTRING_PTR(str)) != 1)
- ossl_raise(ePKCS5, "PKCS5_PBKDF2_HMAC");
-
- return str;
-#else
- rb_notimplement();
-#endif
-}
-
-
-/*
- * call-seq:
- * PKCS5.pbkdf2_hmac_sha1(pass, salt, iter, keylen) => string
- *
- * === Parameters
- * * +pass+ - string
- * * +salt+ - string
- * * +iter+ - integer - should be greater than 1000. 2000 is better.
- * * +keylen+ - integer
- *
- * This method is available almost any version OpenSSL.
- *
- * Conforms to rfc2898.
- */
-static VALUE
-ossl_pkcs5_pbkdf2_hmac_sha1(VALUE self, VALUE pass, VALUE salt, VALUE iter, VALUE keylen)
-{
-#ifdef HAVE_PKCS5_PBKDF2_HMAC_SHA1
- VALUE str;
- int len = NUM2INT(keylen);
-
- StringValue(pass);
- StringValue(salt);
-
- str = rb_str_new(0, len);
-
- if (PKCS5_PBKDF2_HMAC_SHA1(RSTRING_PTR(pass), RSTRING_LEN(pass), RSTRING_PTR(salt), RSTRING_LEN(salt), NUM2INT(iter), len, RSTRING_PTR(str)) != 1)
- ossl_raise(ePKCS5, "PKCS5_PBKDF2_HMAC_SHA1");
-
- return str;
-#else
- rb_notimplement();
-#endif
-}
-
-void
-Init_ossl_pkcs5()
-{
- /*
- * Password-based Encryption
- *
- */
- mPKCS5 = rb_define_module_under(mOSSL, "PKCS5");
- ePKCS5 = rb_define_class_under(mPKCS5, "PKCS5Error", eOSSLError);
-
- rb_define_module_function(mPKCS5, "pbkdf2_hmac", ossl_pkcs5_pbkdf2_hmac, 5);
- rb_define_module_function(mPKCS5, "pbkdf2_hmac_sha1", ossl_pkcs5_pbkdf2_hmac_sha1, 4);
-}
diff --git a/ext/openssl/ossl_pkcs7.c b/ext/openssl/ossl_pkcs7.c
index 6918844779..0fcabd7777 100644
--- a/ext/openssl/ossl_pkcs7.c
+++ b/ext/openssl/ossl_pkcs7.c
@@ -71,6 +71,7 @@
/*
* Classes
*/
+VALUE mPKCS7;
VALUE cPKCS7;
VALUE cPKCS7Signer;
VALUE cPKCS7Recipient;
@@ -133,8 +134,7 @@ DupPKCS7RecipientPtr(VALUE obj)
}
/*
- * call-seq:
- * PKCS7.read_smime(string) => pkcs7
+ * Private
*/
static VALUE
ossl_pkcs7_s_read_smime(VALUE klass, VALUE arg)
@@ -156,10 +156,6 @@ ossl_pkcs7_s_read_smime(VALUE klass, VALUE arg)
return ret;
}
-/*
- * call-seq:
- * PKCS7.write_smime(pkcs7 [, data [, flags]]) => string
- */
static VALUE
ossl_pkcs7_s_write_smime(int argc, VALUE *argv, VALUE klass)
{
@@ -191,10 +187,6 @@ ossl_pkcs7_s_write_smime(int argc, VALUE *argv, VALUE klass)
return str;
}
-/*
- * call-seq:
- * PKCS7.sign(cert, key, data, [, certs [, flags]]) => pkcs7
- */
static VALUE
ossl_pkcs7_s_sign(int argc, VALUE *argv, VALUE klass)
{
@@ -234,10 +226,6 @@ ossl_pkcs7_s_sign(int argc, VALUE *argv, VALUE klass)
return ret;
}
-/*
- * call-seq:
- * PKCS7.encrypt(certs, data, [, cipher [, flags]]) => pkcs7
- */
static VALUE
ossl_pkcs7_s_encrypt(int argc, VALUE *argv, VALUE klass)
{
@@ -299,13 +287,6 @@ ossl_pkcs7_alloc(VALUE klass)
return obj;
}
-/*
- * call-seq:
- * PKCS7.new => pkcs7
- * PKCS7.new(string) => pkcs7
- *
- * Many methods in this class aren't documented.
- */
static VALUE
ossl_pkcs7_initialize(int argc, VALUE *argv, VALUE self)
{
@@ -354,7 +335,7 @@ static int
ossl_pkcs7_sym2typeid(VALUE sym)
{
int i, ret = Qnil;
- const char *s;
+ char *s;
static struct {
const char *name;
@@ -383,10 +364,6 @@ ossl_pkcs7_sym2typeid(VALUE sym)
return ret;
}
-/*
- * call-seq:
- * pkcs7.type = type => type
- */
static VALUE
ossl_pkcs7_set_type(VALUE self, VALUE type)
{
@@ -399,10 +376,6 @@ ossl_pkcs7_set_type(VALUE self, VALUE type)
return type;
}
-/*
- * call-seq:
- * pkcs7.type => string or nil
- */
static VALUE
ossl_pkcs7_get_type(VALUE self)
{
@@ -610,7 +583,7 @@ ossl_pkcs7_set_certificates(VALUE self, VALUE ary)
certs = pkcs7_get_certs_or_crls(self, 1);
while((cert = sk_X509_pop(certs))) X509_free(cert);
- rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_certs_i, self);
+ rb_iterate(rb_each, ary, ossl_pkcs7_set_certs_i, self);
return ary;
}
@@ -650,7 +623,7 @@ ossl_pkcs7_set_crls(VALUE self, VALUE ary)
crls = pkcs7_get_certs_or_crls(self, 0);
while((crl = sk_X509_CRL_pop(crls))) X509_CRL_free(crl);
- rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_crls_i, self);
+ rb_iterate(rb_each, ary, ossl_pkcs7_set_crls_i, self);
return ary;
}
@@ -778,7 +751,7 @@ ossl_pkcs7_to_der(VALUE self)
if((len = i2d_PKCS7(pkcs7, NULL)) <= 0)
ossl_raise(ePKCS7Error, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_PKCS7(pkcs7, &p) <= 0)
ossl_raise(ePKCS7Error, NULL);
ossl_str_adjust(str, p);
@@ -953,12 +926,15 @@ ossl_pkcs7ri_get_enc_key(VALUE self)
void
Init_ossl_pkcs7()
{
- cPKCS7 = rb_define_class_under(mOSSL, "PKCS7", rb_cObject);
- ePKCS7Error = rb_define_class_under(cPKCS7, "PKCS7Error", eOSSLError);
- rb_define_singleton_method(cPKCS7, "read_smime", ossl_pkcs7_s_read_smime, 1);
- rb_define_singleton_method(cPKCS7, "write_smime", ossl_pkcs7_s_write_smime, -1);
- rb_define_singleton_method(cPKCS7, "sign", ossl_pkcs7_s_sign, -1);
- rb_define_singleton_method(cPKCS7, "encrypt", ossl_pkcs7_s_encrypt, -1);
+ mPKCS7 = rb_define_module_under(mOSSL, "PKCS7");
+
+ ePKCS7Error = rb_define_class_under(mPKCS7, "PKCS7Error", eOSSLError);
+
+ cPKCS7 = rb_define_class_under(mPKCS7, "PKCS7", rb_cObject);
+ rb_define_singleton_method(mPKCS7, "read_smime", ossl_pkcs7_s_read_smime, 1);
+ rb_define_singleton_method(mPKCS7, "write_smime", ossl_pkcs7_s_write_smime, -1);
+ rb_define_singleton_method(mPKCS7, "sign", ossl_pkcs7_s_sign, -1);
+ rb_define_singleton_method(mPKCS7, "encrypt", ossl_pkcs7_s_encrypt, -1);
rb_attr(cPKCS7, rb_intern("data"), 1, 0, Qfalse);
rb_attr(cPKCS7, rb_intern("error_string"), 1, 1, Qfalse);
rb_define_alloc_func(cPKCS7, ossl_pkcs7_alloc);
@@ -988,8 +964,8 @@ Init_ossl_pkcs7()
rb_define_alias(cPKCS7, "to_s", "to_pem");
rb_define_method(cPKCS7, "to_der", ossl_pkcs7_to_der, 0);
- cPKCS7Signer = rb_define_class_under(cPKCS7, "SignerInfo", rb_cObject);
- rb_define_const(cPKCS7, "Signer", cPKCS7Signer);
+ cPKCS7Signer = rb_define_class_under(mPKCS7, "SignerInfo", rb_cObject);
+ rb_define_const(mPKCS7, "Signer", cPKCS7Signer);
rb_define_alloc_func(cPKCS7Signer, ossl_pkcs7si_alloc);
rb_define_method(cPKCS7Signer, "initialize", ossl_pkcs7si_initialize,3);
rb_define_method(cPKCS7Signer, "issuer", ossl_pkcs7si_get_issuer, 0);
@@ -997,14 +973,14 @@ Init_ossl_pkcs7()
rb_define_method(cPKCS7Signer, "serial", ossl_pkcs7si_get_serial,0);
rb_define_method(cPKCS7Signer,"signed_time",ossl_pkcs7si_get_signed_time,0);
- cPKCS7Recipient = rb_define_class_under(cPKCS7,"RecipientInfo",rb_cObject);
+ cPKCS7Recipient = rb_define_class_under(mPKCS7,"RecipientInfo",rb_cObject);
rb_define_alloc_func(cPKCS7Recipient, ossl_pkcs7ri_alloc);
rb_define_method(cPKCS7Recipient, "initialize", ossl_pkcs7ri_initialize,1);
rb_define_method(cPKCS7Recipient, "issuer", ossl_pkcs7ri_get_issuer,0);
rb_define_method(cPKCS7Recipient, "serial", ossl_pkcs7ri_get_serial,0);
rb_define_method(cPKCS7Recipient, "enc_key", ossl_pkcs7ri_get_enc_key,0);
-#define DefPKCS7Const(x) rb_define_const(cPKCS7, #x, INT2NUM(PKCS7_##x))
+#define DefPKCS7Const(x) rb_define_const(mPKCS7, #x, INT2NUM(PKCS7_##x))
DefPKCS7Const(TEXT);
DefPKCS7Const(NOCERTS);
diff --git a/ext/openssl/ossl_pkcs7.h b/ext/openssl/ossl_pkcs7.h
index 371c421103..f5942d65db 100644
--- a/ext/openssl/ossl_pkcs7.h
+++ b/ext/openssl/ossl_pkcs7.h
@@ -11,6 +11,7 @@
#if !defined(_OSSL_PKCS7_H_)
#define _OSSL_PKCS7_H_
+extern VALUE mPKCS7;
extern VALUE cPKCS7;
extern VALUE cPKCS7Signer;
extern VALUE cPKCS7Recipient;
diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c
index b295cfc25e..d54f5b938e 100644
--- a/ext/openssl/ossl_pkey.c
+++ b/ext/openssl/ossl_pkey.c
@@ -55,10 +55,6 @@ ossl_pkey_new(EVP_PKEY *pkey)
case EVP_PKEY_DH:
return ossl_dh_new(pkey);
#endif
-#if !defined(OPENSSL_NO_EC) && (OPENSSL_VERSION_NUMBER >= 0x0090802fL)
- case EVP_PKEY_EC:
- return ossl_ec_new(pkey);
-#endif
default:
ossl_raise(ePKeyError, "unsupported key type");
}
@@ -72,7 +68,7 @@ ossl_pkey_new_from_file(VALUE filename)
EVP_PKEY *pkey;
SafeStringValue(filename);
- if (!(fp = fopen(RSTRING_PTR(filename), "r"))) {
+ if (!(fp = fopen(RSTRING(filename)->ptr, "r"))) {
ossl_raise(ePKeyError, "%s", strerror(errno));
}
@@ -112,7 +108,7 @@ EVP_PKEY *
DupPKeyPtr(VALUE obj)
{
EVP_PKEY *pkey;
-
+
SafeGetPKey(obj, pkey);
CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
@@ -173,12 +169,13 @@ ossl_pkey_sign(VALUE self, VALUE digest, VALUE data)
GetPKey(self, pkey);
EVP_SignInit(&ctx, GetDigestPtr(digest));
StringValue(data);
- EVP_SignUpdate(&ctx, RSTRING_PTR(data), RSTRING_LEN(data));
+ EVP_SignUpdate(&ctx, RSTRING(data)->ptr, RSTRING(data)->len);
str = rb_str_new(0, EVP_PKEY_size(pkey)+16);
- if (!EVP_SignFinal(&ctx, RSTRING_PTR(str), &buf_len, pkey))
+ if (!EVP_SignFinal(&ctx, RSTRING(str)->ptr, &buf_len, pkey))
ossl_raise(ePKeyError, NULL);
- assert(buf_len <= RSTRING_LEN(str));
- rb_str_set_len(str, buf_len);
+ assert(buf_len <= RSTRING(str)->len);
+ RSTRING(str)->len = buf_len;
+ RSTRING(str)->ptr[buf_len] = 0;
return str;
}
@@ -193,8 +190,8 @@ ossl_pkey_verify(VALUE self, VALUE digest, VALUE sig, VALUE data)
EVP_VerifyInit(&ctx, GetDigestPtr(digest));
StringValue(sig);
StringValue(data);
- EVP_VerifyUpdate(&ctx, RSTRING_PTR(data), RSTRING_LEN(data));
- switch (EVP_VerifyFinal(&ctx, RSTRING_PTR(sig), RSTRING_LEN(sig), pkey)) {
+ EVP_VerifyUpdate(&ctx, RSTRING(data)->ptr, RSTRING(data)->len);
+ switch (EVP_VerifyFinal(&ctx, RSTRING(sig)->ptr, RSTRING(sig)->len, pkey)) {
case 0:
return Qfalse;
case 1:
@@ -230,11 +227,10 @@ Init_ossl_pkey()
id_private_q = rb_intern("private?");
/*
- * INIT rsa, dsa, dh, ec
+ * INIT rsa, dsa
*/
Init_ossl_rsa();
Init_ossl_dsa();
Init_ossl_dh();
- Init_ossl_ec();
}
diff --git a/ext/openssl/ossl_pkey.h b/ext/openssl/ossl_pkey.h
index 67ff1fddd0..880a104675 100644
--- a/ext/openssl/ossl_pkey.h
+++ b/ext/openssl/ossl_pkey.h
@@ -77,24 +77,7 @@ extern DH *OSSL_DEFAULT_DH_1024;
VALUE ossl_dh_new(EVP_PKEY *);
void Init_ossl_dh(void);
-/*
- * EC
- */
-extern VALUE cEC;
-extern VALUE eECError;
-extern VALUE cEC_GROUP;
-extern VALUE eEC_GROUP;
-extern VALUE cEC_POINT;
-extern VALUE eEC_POINT;
-VALUE ossl_ec_new(EVP_PKEY *);
-void Init_ossl_ec(void);
-
-
#define OSSL_PKEY_BN(keytype, name) \
-/* \
- * call-seq: \
- * key.##name -> aBN \
- */ \
static VALUE ossl_##keytype##_get_##name(VALUE self) \
{ \
EVP_PKEY *pkey; \
@@ -106,10 +89,6 @@ static VALUE ossl_##keytype##_get_##name(VALUE self) \
return Qnil; \
return ossl_bn_new(bn); \
} \
-/* \
- * call-seq: \
- * key.##name = bn -> bn \
- */ \
static VALUE ossl_##keytype##_set_##name(VALUE self, VALUE bignum) \
{ \
EVP_PKEY *pkey; \
diff --git a/ext/openssl/ossl_pkey_dh.c b/ext/openssl/ossl_pkey_dh.c
index 02c3d99ed8..e16ede8bba 100644
--- a/ext/openssl/ossl_pkey_dh.c
+++ b/ext/openssl/ossl_pkey_dh.c
@@ -99,15 +99,6 @@ dh_generate(int size, int gen)
return dh;
}
-/*
- * call-seq:
- * DH.generate(size [, generator]) -> dh
- *
- * === Parameters
- * * +size+ is an integer representing the desired key size. Keys smaller than 1024 should be considered insecure.
- * * +generator+ is a small number > 1, typically 2 or 5.
- *
- */
static VALUE
ossl_dh_s_generate(int argc, VALUE *argv, VALUE klass)
{
@@ -116,9 +107,9 @@ ossl_dh_s_generate(int argc, VALUE *argv, VALUE klass)
VALUE size, gen, obj;
if (rb_scan_args(argc, argv, "11", &size, &gen) == 2) {
- g = NUM2INT(gen);
+ g = FIX2INT(gen);
}
- dh = dh_generate(NUM2INT(size), g);
+ dh = dh_generate(FIX2INT(size), g);
obj = dh_instance(klass, dh);
if (obj == Qfalse) {
DH_free(dh);
@@ -128,21 +119,6 @@ ossl_dh_s_generate(int argc, VALUE *argv, VALUE klass)
return obj;
}
-/*
- * call-seq:
- * DH.new([size [, generator] | string]) -> dh
- *
- * === Parameters
- * * +size+ is an integer representing the desired key size. Keys smaller than 1024 should be considered insecure.
- * * +generator+ is a small number > 1, typically 2 or 5.
- * * +string+ contains the DER or PEM encoded key.
- *
- * === Examples
- * * DH.new -> dh
- * * DH.new(1024) -> dh
- * * DH.new(1024, 5) -> dh
- * * DH.new(File.read('key.pem')) -> dh
- */
static VALUE
ossl_dh_initialize(int argc, VALUE *argv, VALUE self)
{
@@ -158,7 +134,7 @@ ossl_dh_initialize(int argc, VALUE *argv, VALUE self)
}
else if (FIXNUM_P(arg)) {
if (!NIL_P(gen)) {
- g = NUM2INT(gen);
+ g = FIX2INT(gen);
}
if (!(dh = dh_generate(FIX2INT(arg), g))) {
ossl_raise(eDHError, NULL);
@@ -182,26 +158,19 @@ ossl_dh_initialize(int argc, VALUE *argv, VALUE self)
return self;
}
-/*
- * call-seq:
- * dh.public? -> true | false
- *
- */
static VALUE
ossl_dh_is_public(VALUE self)
{
EVP_PKEY *pkey;
GetPKeyDH(self, pkey);
-
+ /*
+ * Do we need to check dhp->dh->public_pkey?
+ * return Qtrue;
+ */
return (pkey->pkey.dh->pub_key) ? Qtrue : Qfalse;
}
-/*
- * call-seq:
- * dh.private? -> true | false
- *
- */
static VALUE
ossl_dh_is_private(VALUE self)
{
@@ -212,11 +181,6 @@ ossl_dh_is_private(VALUE self)
return (DH_PRIVATE(pkey->pkey.dh)) ? Qtrue : Qfalse;
}
-/*
- * call-seq:
- * dh.to_pem -> aString
- *
- */
static VALUE
ossl_dh_export(VALUE self)
{
@@ -237,11 +201,6 @@ ossl_dh_export(VALUE self)
return str;
}
-/*
- * call-seq:
- * dh.to_der -> aString
- *
- */
static VALUE
ossl_dh_to_der(VALUE self)
{
@@ -254,7 +213,7 @@ ossl_dh_to_der(VALUE self)
if((len = i2d_DHparams(pkey->pkey.dh, NULL)) <= 0)
ossl_raise(eDHError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_DHparams(pkey->pkey.dh, &p) < 0)
ossl_raise(eDHError, NULL);
ossl_str_adjust(str, p);
@@ -263,9 +222,6 @@ ossl_dh_to_der(VALUE self)
}
/*
- * call-seq:
- * dh.params -> hash
- *
* Stores all parameters of key to the hash
* INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
* Don't use :-)) (I's up to you)
@@ -289,9 +245,6 @@ ossl_dh_get_params(VALUE self)
}
/*
- * call-seq:
- * dh.to_text -> aString
- *
* Prints all parameters of key to buffer
* INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
* Don't use :-)) (I's up to you)
@@ -317,10 +270,7 @@ ossl_dh_to_text(VALUE self)
}
/*
- * call-seq:
- * dh.public_key -> aDH
- *
- * Makes new instance DH PUBLIC_KEY from PRIVATE_KEY
+ * Makes new instance DH PUBLIC_KEY from PRIVATE_KEY
*/
static VALUE
ossl_dh_to_public_key(VALUE self)
@@ -340,11 +290,6 @@ ossl_dh_to_public_key(VALUE self)
return obj;
}
-/*
- * call-seq:
- * dh.check_params -> true | false
- *
- */
static VALUE
ossl_dh_check_params(VALUE self)
{
@@ -362,11 +307,6 @@ ossl_dh_check_params(VALUE self)
return codes == 0 ? Qtrue : Qfalse;
}
-/*
- * call-seq:
- * dh.generate_key -> self
- *
- */
static VALUE
ossl_dh_generate_key(VALUE self)
{
@@ -381,18 +321,6 @@ ossl_dh_generate_key(VALUE self)
return self;
}
-/*
- * call-seq:
- * dh.compute_key(pub_bn) -> aString
- *
- * === Parameters
- * * +pub_bn+ is a OpenSSL::BN.
- *
- * Returns aString containing a shared secret computed from the other parties public value.
- *
- * See DH_compute_key() for further information.
- *
- */
static VALUE
ossl_dh_compute_key(VALUE self, VALUE pub)
{
@@ -407,10 +335,11 @@ ossl_dh_compute_key(VALUE self, VALUE pub)
pub_key = GetBNPtr(pub);
len = DH_size(dh);
str = rb_str_new(0, len);
- if ((len = DH_compute_key(RSTRING_PTR(str), pub_key, dh)) < 0) {
+ if ((len = DH_compute_key(RSTRING(str)->ptr, pub_key, dh)) < 0) {
ossl_raise(eDHError, NULL);
}
- rb_str_set_len(str, len);
+ RSTRING(str)->len = len;
+ RSTRING(str)->ptr[len] = 0;
return str;
}
@@ -438,7 +367,7 @@ static unsigned char DEFAULT_DH_512_PRIM[] = {
};
static unsigned char DEFAULT_DH_512_GEN[] = { 0x02 };
DH *OSSL_DEFAULT_DH_512 = NULL;
-
+
/*
* -----BEGIN DH PARAMETERS-----
* MIGHAoGBAJ0lOVy0VIr/JebWn0zDwY2h+rqITFOpdNr6ugsgvkDXuucdcChhYExJ
@@ -477,7 +406,7 @@ ossl_create_dh(unsigned char *p, size_t plen, unsigned char *g, size_t glen)
dh->g = BN_bin2bn(g, glen, NULL);
if (dh->p == NULL || dh->g == NULL){
DH_free(dh);
- ossl_raise(eDHError, NULL);
+ ossl_raise(eDHError, NULL);
}
return dh;
@@ -524,9 +453,11 @@ Init_ossl_dh()
}
#else /* defined NO_DH */
+# warning >>> OpenSSL is compiled without DH support <<<
void
Init_ossl_dh()
{
+ rb_warning("OpenSSL is compiled without DH support");
}
#endif /* NO_DH */
diff --git a/ext/openssl/ossl_pkey_dsa.c b/ext/openssl/ossl_pkey_dsa.c
index d9c7fcbe78..fdf23aa496 100644
--- a/ext/openssl/ossl_pkey_dsa.c
+++ b/ext/openssl/ossl_pkey_dsa.c
@@ -99,18 +99,10 @@ dsa_generate(int size)
return dsa;
}
-/*
- * call-seq:
- * DSA.generate(size) -> dsa
- *
- * === Parameters
- * * +size+ is an integer representing the desired key size.
- *
- */
static VALUE
ossl_dsa_s_generate(VALUE klass, VALUE size)
{
- DSA *dsa = dsa_generate(NUM2INT(size)); /* err handled by dsa_instance */
+ DSA *dsa = dsa_generate(FIX2INT(size)); /* err handled by dsa_instance */
VALUE obj = dsa_instance(klass, dsa);
if (obj == Qfalse) {
@@ -121,22 +113,6 @@ ossl_dsa_s_generate(VALUE klass, VALUE size)
return obj;
}
-/*
- * call-seq:
- * DSA.new([size | string [, pass]) -> dsa
- *
- * === Parameters
- * * +size+ is an integer representing the desired key size.
- * * +string+ contains a DER or PEM encoded key.
- * * +pass+ is a string that contains a optional password.
- *
- * === Examples
- * * DSA.new -> dsa
- * * DSA.new(1024) -> dsa
- * * DSA.new(File.read('dsa.pem')) -> dsa
- * * DSA.new(File.read('dsa.pem'), 'mypassword') -> dsa
- *
- */
static VALUE
ossl_dsa_initialize(int argc, VALUE *argv, VALUE self)
{
@@ -187,11 +163,6 @@ ossl_dsa_initialize(int argc, VALUE *argv, VALUE self)
return self;
}
-/*
- * call-seq:
- * dsa.public? -> true | false
- *
- */
static VALUE
ossl_dsa_is_public(VALUE self)
{
@@ -199,14 +170,13 @@ ossl_dsa_is_public(VALUE self)
GetPKeyDSA(self, pkey);
+ /*
+ * Do we need to check dsap->dsa->public_pkey?
+ * return Qtrue;
+ */
return (pkey->pkey.dsa->pub_key) ? Qtrue : Qfalse;
}
-/*
- * call-seq:
- * dsa.private? -> true | false
- *
- */
static VALUE
ossl_dsa_is_private(VALUE self)
{
@@ -217,19 +187,6 @@ ossl_dsa_is_private(VALUE self)
return (DSA_PRIVATE(self, pkey->pkey.dsa)) ? Qtrue : Qfalse;
}
-/*
- * call-seq:
- * dsa.to_pem([cipher, password]) -> aString
- *
- * === Parameters
- * +cipher+ is an OpenSSL::Cipher.
- * +password+ is a string containing your password.
- *
- * === Examples
- * * DSA.to_pem -> aString
- * * DSA.to_pem(cipher, 'mypassword') -> aString
- *
- */
static VALUE
ossl_dsa_export(int argc, VALUE *argv, VALUE self)
{
@@ -267,11 +224,6 @@ ossl_dsa_export(int argc, VALUE *argv, VALUE self)
return str;
}
-/*
- * call-seq:
- * dsa.to_der -> aString
- *
- */
static VALUE
ossl_dsa_to_der(VALUE self)
{
@@ -289,7 +241,7 @@ ossl_dsa_to_der(VALUE self)
if((len = i2d_func(pkey->pkey.dsa, NULL)) <= 0)
ossl_raise(eDSAError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_func(pkey->pkey.dsa, &p) < 0)
ossl_raise(eDSAError, NULL);
ossl_str_adjust(str, p);
@@ -298,9 +250,6 @@ ossl_dsa_to_der(VALUE self)
}
/*
- * call-seq:
- * dsa.params -> hash
- *
* Stores all parameters of key to the hash
* INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
* Don't use :-)) (I's up to you)
@@ -325,9 +274,6 @@ ossl_dsa_get_params(VALUE self)
}
/*
- * call-seq:
- * dsa.to_text -> aString
- *
* Prints all parameters of key to buffer
* INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
* Don't use :-)) (I's up to you)
@@ -353,9 +299,6 @@ ossl_dsa_to_text(VALUE self)
}
/*
- * call-seq:
- * dsa.public_key -> aDSA
- *
* Makes new instance DSA PUBLIC_KEY from PRIVATE_KEY
*/
static VALUE
@@ -378,11 +321,6 @@ ossl_dsa_to_public_key(VALUE self)
#define ossl_dsa_buf_size(pkey) (DSA_size((pkey)->pkey.dsa)+16)
-/*
- * call-seq:
- * dsa.syssign(string) -> aString
- *
- */
static VALUE
ossl_dsa_sign(VALUE self, VALUE data)
{
@@ -396,20 +334,16 @@ ossl_dsa_sign(VALUE self, VALUE data)
ossl_raise(eDSAError, "Private DSA key needed!");
}
str = rb_str_new(0, ossl_dsa_buf_size(pkey));
- if (!DSA_sign(0, RSTRING_PTR(data), RSTRING_LEN(data), RSTRING_PTR(str),
+ if (!DSA_sign(0, RSTRING(data)->ptr, RSTRING(data)->len, RSTRING(str)->ptr,
&buf_len, pkey->pkey.dsa)) { /* type is ignored (0) */
ossl_raise(eDSAError, NULL);
}
- rb_str_set_len(str, buf_len);
+ RSTRING(str)->len = buf_len;
+ RSTRING(str)->ptr[buf_len] = 0;
return str;
}
-/*
- * call-seq:
- * dsa.sysverify(digest, sig) -> true | false
- *
- */
static VALUE
ossl_dsa_verify(VALUE self, VALUE digest, VALUE sig)
{
@@ -420,8 +354,8 @@ ossl_dsa_verify(VALUE self, VALUE digest, VALUE sig)
StringValue(digest);
StringValue(sig);
/* type is ignored (0) */
- ret = DSA_verify(0, RSTRING_PTR(digest), RSTRING_LEN(digest),
- RSTRING_PTR(sig), RSTRING_LEN(sig), pkey->pkey.dsa);
+ ret = DSA_verify(0, RSTRING(digest)->ptr, RSTRING(digest)->len,
+ RSTRING(sig)->ptr, RSTRING(sig)->len, pkey->pkey.dsa);
if (ret < 0) {
ossl_raise(eDSAError, NULL);
}
@@ -477,8 +411,12 @@ Init_ossl_dsa()
}
#else /* defined NO_DSA */
+# warning >>> OpenSSL is compiled without DSA support <<<
+
void
Init_ossl_dsa()
{
+ rb_warning("OpenSSL is compiled without DSA support");
}
+
#endif /* NO_DSA */
diff --git a/ext/openssl/ossl_pkey_ec.c b/ext/openssl/ossl_pkey_ec.c
deleted file mode 100644
index 210054121d..0000000000
--- a/ext/openssl/ossl_pkey_ec.c
+++ /dev/null
@@ -1,1582 +0,0 @@
-/*
- * Copyright (C) 2006-2007 Technorama Ltd. <oss-ruby@technorama.net>
- */
-
-#include "ossl.h"
-
-#if !defined(OPENSSL_NO_EC) && (OPENSSL_VERSION_NUMBER >= 0x0090802fL)
-
-typedef struct {
- EC_GROUP *group;
- int dont_free;
-} ossl_ec_group;
-
-typedef struct {
- EC_POINT *point;
- int dont_free;
-} ossl_ec_point;
-
-
-#define EXPORT_PEM 0
-#define EXPORT_DER 1
-
-
-#define GetPKeyEC(obj, pkey) do { \
- GetPKey(obj, pkey); \
- if (EVP_PKEY_type(pkey->type) != EVP_PKEY_EC) { \
- ossl_raise(rb_eRuntimeError, "THIS IS NOT A EC PKEY!"); \
- } \
-} while (0)
-
-#define SafeGet_ec_group(obj, group) do { \
- OSSL_Check_Kind(obj, cEC_GROUP); \
- Data_Get_Struct(obj, ossl_ec_group, group); \
-} while(0)
-
-#define Get_EC_KEY(obj, key) do { \
- EVP_PKEY *pkey; \
- GetPKeyEC(obj, pkey); \
- key = pkey->pkey.ec; \
-} while(0)
-
-#define Require_EC_KEY(obj, key) do { \
- Get_EC_KEY(obj, key); \
- if (key == NULL) \
- rb_raise(eECError, "EC_KEY is not initialized"); \
-} while(0)
-
-#define SafeRequire_EC_KEY(obj, key) do { \
- OSSL_Check_Kind(obj, cEC); \
- Require_EC_KEY(obj, key); \
-} while (0)
-
-#define Get_EC_GROUP(obj, g) do { \
- ossl_ec_group *ec_group; \
- Data_Get_Struct(obj, ossl_ec_group, ec_group); \
- if (ec_group == NULL) \
- rb_raise(eEC_GROUP, "missing ossl_ec_group structure"); \
- g = ec_group->group; \
-} while(0)
-
-#define Require_EC_GROUP(obj, group) do { \
- Get_EC_GROUP(obj, group); \
- if (group == NULL) \
- rb_raise(eEC_GROUP, "EC_GROUP is not initialized"); \
-} while(0)
-
-#define SafeRequire_EC_GROUP(obj, group) do { \
- OSSL_Check_Kind(obj, cEC_GROUP); \
- Require_EC_GROUP(obj, group); \
-} while(0)
-
-#define Get_EC_POINT(obj, p) do { \
- ossl_ec_point *ec_point; \
- Data_Get_Struct(obj, ossl_ec_point, ec_point); \
- if (ec_point == NULL) \
- rb_raise(eEC_POINT, "missing ossl_ec_point structure"); \
- p = ec_point->point; \
-} while(0)
-
-#define Require_EC_POINT(obj, point) do { \
- Get_EC_POINT(obj, point); \
- if (point == NULL) \
- rb_raise(eEC_POINT, "EC_POINT is not initialized"); \
-} while(0)
-
-#define SafeRequire_EC_POINT(obj, point) do { \
- OSSL_Check_Kind(obj, cEC_POINT); \
- Require_EC_POINT(obj, point); \
-} while(0)
-
-VALUE cEC;
-VALUE eECError;
-VALUE cEC_GROUP;
-VALUE eEC_GROUP;
-VALUE cEC_POINT;
-VALUE eEC_POINT;
-
-static ID s_GFp;
-static ID s_GFp_simple;
-static ID s_GFp_mont;
-static ID s_GFp_nist;
-static ID s_GF2m;
-static ID s_GF2m_simple;
-
-static ID ID_uncompressed;
-static ID ID_compressed;
-static ID ID_hybrid;
-
-static VALUE ec_instance(VALUE klass, EC_KEY *ec)
-{
- EVP_PKEY *pkey;
- VALUE obj;
-
- if (!ec) {
- return Qfalse;
- }
- if (!(pkey = EVP_PKEY_new())) {
- return Qfalse;
- }
- if (!EVP_PKEY_assign_EC_KEY(pkey, ec)) {
- EVP_PKEY_free(pkey);
- return Qfalse;
- }
- WrapPKey(klass, obj, pkey);
-
- return obj;
-}
-
-VALUE ossl_ec_new(EVP_PKEY *pkey)
-{
- VALUE obj;
-
- if (!pkey) {
- obj = ec_instance(cEC, EC_KEY_new());
- } else {
- if (EVP_PKEY_type(pkey->type) != EVP_PKEY_EC) {
- ossl_raise(rb_eTypeError, "Not a EC key!");
- }
- WrapPKey(cEC, obj, pkey);
- }
- if (obj == Qfalse) {
- ossl_raise(eECError, NULL);
- }
-
- return obj;
-}
-
-
-/* call-seq:
- * OpenSSL::PKey::EC.new()
- * OpenSSL::PKey::EC.new(ec_key)
- * OpenSSL::PKey::EC.new(ec_group)
- * OpenSSL::PKey::EC.new("secp112r1")
- * OpenSSL::PKey::EC.new(pem_string)
- * OpenSSL::PKey::EC.new(der_string)
- *
- * See the OpenSSL documentation for:
- * EC_KEY_*
- */
-static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
-{
- EVP_PKEY *pkey;
- EC_KEY *ec = NULL;
- VALUE arg, pass;
- VALUE group = Qnil;
-
- GetPKey(self, pkey);
- if (pkey->pkey.ec)
- rb_raise(eECError, "EC_KEY already initialized");
-
- rb_scan_args(argc, argv, "02", &arg, &pass);
-
- if (NIL_P(arg)) {
- ec = EC_KEY_new();
- } else {
- if (rb_obj_is_kind_of(arg, cEC)) {
- EC_KEY *other_ec = NULL;
-
- SafeRequire_EC_KEY(arg, other_ec);
- ec = EC_KEY_dup(other_ec);
- } else if (rb_obj_is_kind_of(arg, cEC_GROUP)) {
- ec = EC_KEY_new();
- group = arg;
- } else {
- BIO *in = ossl_obj2bio(arg);
-
- ec = PEM_read_bio_ECPrivateKey(in, NULL, NULL, NULL);
- if (!ec) {
- BIO_reset(in);
- ec = PEM_read_bio_EC_PUBKEY(in, NULL, NULL, NULL);
- }
- if (!ec) {
- BIO_reset(in);
- ec = d2i_ECPrivateKey_bio(in, NULL);
- }
- if (!ec) {
- BIO_reset(in);
- ec = d2i_EC_PUBKEY_bio(in, NULL);
- }
-
- BIO_free(in);
-
- if (ec == NULL) {
- const char *name = STR2CSTR(arg);
- int nid = OBJ_sn2nid(name);
-
- if (nid == NID_undef)
- ossl_raise(eECError, "unknown curve name (%s)\n", name);
-
- if ((ec = EC_KEY_new_by_curve_name(nid)) == NULL)
- ossl_raise(eECError, "unable to create curve (%s)\n", name);
-
- EC_KEY_set_asn1_flag(ec, OPENSSL_EC_NAMED_CURVE);
- EC_KEY_set_conv_form(ec, POINT_CONVERSION_UNCOMPRESSED);
- }
- }
- }
-
- if (ec == NULL)
- ossl_raise(eECError, NULL);
-
- if (!EVP_PKEY_assign_EC_KEY(pkey, ec)) {
- EC_KEY_free(ec);
- ossl_raise(eECError, "EVP_PKEY_assign_EC_KEY");
- }
-
- rb_iv_set(self, "@group", Qnil);
-
- if (!NIL_P(group))
- rb_funcall(self, rb_intern("group="), 1, arg);
-
- return self;
-}
-
-/*
- * call-seq:
- * key.group => group
- *
- * Returns a constant <code>OpenSSL::EC::Group</code> that is tied to the key.
- * Modifying the returned group can make the key invalid.
- */
-static VALUE ossl_ec_key_get_group(VALUE self)
-{
- VALUE group_v;
- EC_KEY *ec;
- ossl_ec_group *ec_group;
- EC_GROUP *group;
-
- Require_EC_KEY(self, ec);
-
- group_v = rb_iv_get(self, "@group");
- if (!NIL_P(group_v))
- return group_v;
-
- if ((group = (EC_GROUP *)EC_KEY_get0_group(ec)) != NULL) {
- group_v = rb_obj_alloc(cEC_GROUP);
- SafeGet_ec_group(group_v, ec_group);
- ec_group->group = group;
- ec_group->dont_free = 1;
- rb_iv_set(group_v, "@key", self);
- rb_iv_set(self, "@group", group_v);
- return group_v;
- }
-
- return Qnil;
-}
-
-/*
- * call-seq:
- * key.group = group => group
- *
- * Returns the same object passed, not the group object associated with the key.
- * If you wish to access the group object tied to the key call key.group after setting
- * the group.
- *
- * Setting the group will immediately destroy any previously assigned group object.
- * The group is internally copied by OpenSSL. Modifying the original group after
- * assignment will not effect the internal key structure.
- * (your changes may be lost). BE CAREFUL.
- *
- * EC_KEY_set_group calls EC_GROUP_free(key->group) then EC_GROUP_dup(), not EC_GROUP_copy.
- * This documentation is accurate for OpenSSL 0.9.8b.
- */
-static VALUE ossl_ec_key_set_group(VALUE self, VALUE group_v)
-{
- VALUE old_group_v;
- EC_KEY *ec;
- EC_GROUP *group;
-
- Require_EC_KEY(self, ec);
- SafeRequire_EC_GROUP(group_v, group);
-
- old_group_v = rb_iv_get(self, "@group");
- if (!NIL_P(old_group_v)) {
- ossl_ec_group *old_ec_group;
- SafeGet_ec_group(old_group_v, old_ec_group);
-
- old_ec_group->group = NULL;
- old_ec_group->dont_free = 0;
- rb_iv_set(old_group_v, "@key", Qnil);
- }
-
- rb_iv_set(self, "@group", Qnil);
-
- if (EC_KEY_set_group(ec, group) != 1)
- ossl_raise(eECError, "EC_KEY_set_group");
-
- return group_v;
-}
-
-/*
- * call-seq:
- * key.private_key => OpenSSL::BN
- *
- * See the OpenSSL documentation for EC_KEY_get0_private_key()
- */
-static VALUE ossl_ec_key_get_private_key(VALUE self)
-{
- EC_KEY *ec;
- const BIGNUM *bn;
-
- Require_EC_KEY(self, ec);
-
- if ((bn = EC_KEY_get0_private_key(ec)) == NULL)
- return Qnil;
-
- return ossl_bn_new(bn);
-}
-
-/*
- * call-seq:
- * key.private_key = openssl_bn
- *
- * See the OpenSSL documentation for EC_KEY_set_private_key()
- */
-static VALUE ossl_ec_key_set_private_key(VALUE self, VALUE private_key)
-{
- EC_KEY *ec;
- BIGNUM *bn = NULL;
-
- Require_EC_KEY(self, ec);
- if (!NIL_P(private_key))
- bn = GetBNPtr(private_key);
-
- switch (EC_KEY_set_private_key(ec, bn)) {
- case 1:
- break;
- case 0:
- if (bn == NULL)
- break;
- default:
- ossl_raise(eECError, "EC_KEY_set_private_key");
- }
-
- return private_key;
-}
-
-
-static VALUE ossl_ec_point_dup(const EC_POINT *point, VALUE group_v)
-{
- VALUE obj;
- const EC_GROUP *group;
- ossl_ec_point *new_point;
-
- obj = rb_obj_alloc(cEC_POINT);
- Data_Get_Struct(obj, ossl_ec_point, new_point);
-
- SafeRequire_EC_GROUP(group_v, group);
-
- new_point->point = EC_POINT_dup(point, group);
- if (new_point->point == NULL)
- ossl_raise(eEC_POINT, "EC_POINT_dup");
- rb_iv_set(obj, "@group", group_v);
-
- return obj;
-}
-
-/*
- * call-seq:
- * key.public_key => OpenSSL::PKey::EC::Point
- *
- * See the OpenSSL documentation for EC_KEY_get0_public_key()
- */
-static VALUE ossl_ec_key_get_public_key(VALUE self)
-{
- EC_KEY *ec;
- const EC_POINT *point;
- VALUE group;
-
- Require_EC_KEY(self, ec);
-
- if ((point = EC_KEY_get0_public_key(ec)) == NULL)
- return Qnil;
-
- group = rb_funcall(self, rb_intern("group"), 0);
- if (NIL_P(group))
- ossl_raise(eECError, "EC_KEY_get0_get0_group (has public_key but no group???");
-
- return ossl_ec_point_dup(point, group);
-}
-
-/*
- * call-seq:
- * key.public_key = ec_point
- *
- * See the OpenSSL documentation for EC_KEY_set_public_key()
- */
-static VALUE ossl_ec_key_set_public_key(VALUE self, VALUE public_key)
-{
- EC_KEY *ec;
- EC_POINT *point = NULL;
-
- Require_EC_KEY(self, ec);
- if (!NIL_P(public_key))
- SafeRequire_EC_POINT(public_key, point);
-
- switch (EC_KEY_set_public_key(ec, point)) {
- case 1:
- break;
- case 0:
- if (point == NULL)
- break;
- default:
- ossl_raise(eECError, "EC_KEY_set_public_key");
- }
-
- return public_key;
-}
-
-/*
- * call-seq:
- * key.public_key? => true or false
- *
- * Both public_key? and private_key? may return false at the same time unlike other PKey classes.
- */
-static VALUE ossl_ec_key_is_public_key(VALUE self)
-{
- EC_KEY *ec;
-
- Require_EC_KEY(self, ec);
-
- return (EC_KEY_get0_public_key(ec) ? Qtrue : Qfalse);
-}
-
-/*
- * call-seq:
- * key.private_key? => true or false
- *
- * Both public_key? and private_key? may return false at the same time unlike other PKey classes.
- */
-static VALUE ossl_ec_key_is_private_key(VALUE self)
-{
- EC_KEY *ec;
-
- Require_EC_KEY(self, ec);
-
- return (EC_KEY_get0_private_key(ec) ? Qtrue : Qfalse);
-}
-
-static VALUE ossl_ec_key_to_string(VALUE self, int format)
-{
- EC_KEY *ec;
- BIO *out;
- int i = -1;
- int private = 0;
- EVP_CIPHER *cipher = NULL;
- char *password = NULL;
- VALUE str;
-
- Require_EC_KEY(self, ec);
-
- if (EC_KEY_get0_public_key(ec) == NULL)
- rb_raise(eECError, "can't export - no public key set");
-
- if (EC_KEY_check_key(ec) != 1)
- ossl_raise(eECError, "can't export - EC_KEY_check_key failed");
-
- if (EC_KEY_get0_private_key(ec))
- private = 1;
-
- if (!(out = BIO_new(BIO_s_mem())))
- ossl_raise(eECError, "BIO_new(BIO_s_mem())");
-
- switch(format) {
- case EXPORT_PEM:
- if (private) {
- if (cipher || password)
-/* BUG: finish cipher/password key export */
- rb_notimplement();
- i = PEM_write_bio_ECPrivateKey(out, ec, cipher, NULL, 0, NULL, password);
- } else {
- if (cipher || password)
- rb_raise(rb_eArgError, "encryption is not supported when exporting this key type");
-
- i = PEM_write_bio_EC_PUBKEY(out, ec);
- }
-
- break;
- case EXPORT_DER:
- if (private) {
- if (cipher || password)
- rb_raise(rb_eArgError, "encryption is not supported when exporting this key type");
-
- i = i2d_ECPrivateKey_bio(out, ec);
- } else {
- if (cipher || password)
- rb_raise(rb_eArgError, "encryption is not supported when exporting this key type");
-
- i = i2d_EC_PUBKEY_bio(out, ec);
- }
-
- break;
- default:
- BIO_free(out);
- rb_raise(rb_eRuntimeError, "unknown format (internal error)");
- }
-
- if (i != 1) {
- BIO_free(out);
- ossl_raise(eECError, "outlen=%d", i);
- }
-
- str = ossl_membio2str(out);
-
- return str;
-}
-
-/*
- * call-seq:
- * key.to_pem => String
- *
- * See the OpenSSL documentation for PEM_write_bio_ECPrivateKey()
- */
-static VALUE ossl_ec_key_to_pem(VALUE self)
-{
- return ossl_ec_key_to_string(self, EXPORT_PEM);
-}
-
-/*
- * call-seq:
- * key.to_der => String
- *
- * See the OpenSSL documentation for i2d_ECPrivateKey_bio()
- */
-static VALUE ossl_ec_key_to_der(VALUE self)
-{
- return ossl_ec_key_to_string(self, EXPORT_DER);
-}
-
-/*
- * call-seq:
- * key.to_text => String
- *
- * See the OpenSSL documentation for EC_KEY_print()
- */
-static VALUE ossl_ec_key_to_text(VALUE self)
-{
- EC_KEY *ec;
- BIO *out;
- VALUE str;
-
- Require_EC_KEY(self, ec);
- if (!(out = BIO_new(BIO_s_mem()))) {
- ossl_raise(eECError, "BIO_new(BIO_s_mem())");
- }
- if (!EC_KEY_print(out, ec, 0)) {
- BIO_free(out);
- ossl_raise(eECError, "EC_KEY_print");
- }
- str = ossl_membio2str(out);
-
- return str;
-}
-
-/*
- * call-seq:
- * key.generate_key => self
- *
- * See the OpenSSL documentation for EC_KEY_generate_key()
- */
-static VALUE ossl_ec_key_generate_key(VALUE self)
-{
- EC_KEY *ec;
-
- Require_EC_KEY(self, ec);
-
- if (EC_KEY_generate_key(ec) != 1)
- ossl_raise(eECError, "EC_KEY_generate_key");
-
- return self;
-}
-
-/*
- * call-seq:
- * key.check_key => true
- *
- * Raises an exception if the key is invalid.
- *
- * See the OpenSSL documentation for EC_KEY_check_key()
- */
-static VALUE ossl_ec_key_check_key(VALUE self)
-{
- EC_KEY *ec;
-
- Require_EC_KEY(self, ec);
-
- if (EC_KEY_check_key(ec) != 1)
- ossl_raise(eECError, "EC_KEY_check_key");
-
- return Qtrue;
-}
-
-/*
- * call-seq:
- * key.dh_compute_key(pubkey) => String
- *
- * See the OpenSSL documentation for ECDH_compute_key()
- */
-static VALUE ossl_ec_key_dh_compute_key(VALUE self, VALUE pubkey)
-{
- EC_KEY *ec;
- EC_POINT *point;
- int buf_len;
- VALUE str;
-
- Require_EC_KEY(self, ec);
- SafeRequire_EC_POINT(pubkey, point);
-
-/* BUG: need a way to figure out the maximum string size */
- buf_len = 1024;
- str = rb_str_new(0, buf_len);
-/* BUG: take KDF as a block */
- buf_len = ECDH_compute_key(RSTRING_PTR(str), buf_len, point, ec, NULL);
- if (buf_len < 0)
- ossl_raise(eECError, "ECDH_compute_key");
-
- rb_str_resize(str, buf_len);
-
- return str;
-}
-
-/* sign_setup */
-
-/*
- * call-seq:
- * key.dsa_sign_asn1(data) => String
- *
- * See the OpenSSL documentation for ECDSA_sign()
- */
-static VALUE ossl_ec_key_dsa_sign_asn1(VALUE self, VALUE data)
-{
- EC_KEY *ec;
- unsigned int buf_len;
- VALUE str;
-
- Require_EC_KEY(self, ec);
- StringValue(data);
-
- if (EC_KEY_get0_private_key(ec) == NULL)
- ossl_raise(eECError, "Private EC key needed!");
-
- str = rb_str_new(0, ECDSA_size(ec) + 16);
- if (ECDSA_sign(0, (unsigned char *) RSTRING_PTR(data), RSTRING_LEN(data), (unsigned char *) RSTRING_PTR(str), &buf_len, ec) != 1)
- ossl_raise(eECError, "ECDSA_sign");
-
- rb_str_resize(str, buf_len);
-
- return str;
-}
-
-/*
- * call-seq:
- * key.dsa_verify(data, sig) => true or false
- *
- * See the OpenSSL documentation for ECDSA_verify()
- */
-static VALUE ossl_ec_key_dsa_verify_asn1(VALUE self, VALUE data, VALUE sig)
-{
- EC_KEY *ec;
-
- Require_EC_KEY(self, ec);
- StringValue(data);
- StringValue(sig);
-
- switch (ECDSA_verify(0, (unsigned char *) RSTRING_PTR(data), RSTRING_LEN(data), (unsigned char *) RSTRING_PTR(sig), RSTRING_LEN(sig), ec)) {
- case 1: return Qtrue;
- case 0: return Qfalse;
- default: break;
- }
-
- ossl_raise(eECError, "ECDSA_verify");
-}
-
-static void ossl_ec_group_free(ossl_ec_group *ec_group)
-{
- if (!ec_group->dont_free && ec_group->group)
- EC_GROUP_clear_free(ec_group->group);
- free(ec_group);
-}
-
-static VALUE ossl_ec_group_alloc(VALUE klass)
-{
- ossl_ec_group *ec_group;
- VALUE obj;
-
- obj = Data_Make_Struct(klass, ossl_ec_group, 0, ossl_ec_group_free, ec_group);
-
- return obj;
-}
-
-/* call-seq:
- * OpenSSL::PKey::EC::Group.new("secp112r1")
- * OpenSSL::PKey::EC::Group.new(ec_group)
- * OpenSSL::PKey::EC::Group.new(pem_string)
- * OpenSSL::PKey::EC::Group.new(der_string)
- * OpenSSL::PKey::EC::Group.new(pem_file)
- * OpenSSL::PKey::EC::Group.new(der_file)
- * OpenSSL::PKey::EC::Group.new(:GFp_simple)
- * OpenSSL::PKey::EC::Group.new(:GFp_mult)
- * OpenSSL::PKey::EC::Group.new(:GFp_nist)
- * OpenSSL::PKey::EC::Group.new(:GF2m_simple)
- * OpenSSL::PKey::EC::Group.new(:GFp, bignum_p, bignum_a, bignum_b)
- * OpenSSL::PKey::EC::Group.new(:GF2m, bignum_p, bignum_a, bignum_b)
- *
- * See the OpenSSL documentation for EC_GROUP_*
- */
-static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
-{
- VALUE arg1, arg2, arg3, arg4;
- ossl_ec_group *ec_group;
- EC_GROUP *group = NULL;
-
- Data_Get_Struct(self, ossl_ec_group, ec_group);
- if (ec_group->group != NULL)
- rb_raise(rb_eRuntimeError, "EC_GROUP is already initialized");
-
- switch (rb_scan_args(argc, argv, "13", &arg1, &arg2, &arg3, &arg4)) {
- case 1:
- if (SYMBOL_P(arg1)) {
- const EC_METHOD *method = NULL;
- ID id = SYM2ID(arg1);
-
- if (id == s_GFp_simple) {
- method = EC_GFp_simple_method();
- } else if (id == s_GFp_mont) {
- method = EC_GFp_mont_method();
- } else if (id == s_GFp_nist) {
- method = EC_GFp_nist_method();
- } else if (id == s_GF2m_simple) {
- method = EC_GF2m_simple_method();
- }
-
- if (method) {
- if ((group = EC_GROUP_new(method)) == NULL)
- ossl_raise(eEC_GROUP, "EC_GROUP_new");
- } else {
- rb_raise(rb_eArgError, "unknown symbol, must be :GFp_simple, :GFp_mont, :GFp_nist or :GF2m_simple");
- }
- } else if (rb_obj_is_kind_of(arg1, cEC_GROUP)) {
- const EC_GROUP *arg1_group;
-
- SafeRequire_EC_GROUP(arg1, arg1_group);
- if ((group = EC_GROUP_dup(arg1_group)) == NULL)
- ossl_raise(eEC_GROUP, "EC_GROUP_dup");
- } else {
- BIO *in = ossl_obj2bio(arg1);
-
- group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL);
- if (!group) {
- BIO_reset(in);
- group = d2i_ECPKParameters_bio(in, NULL);
- }
-
- BIO_free(in);
-
- if (!group) {
- const char *name = STR2CSTR(arg1);
- int nid = OBJ_sn2nid(name);
-
- if (nid == NID_undef)
- ossl_raise(eEC_GROUP, "unknown curve name (%s)", name);
-
- group = EC_GROUP_new_by_curve_name(nid);
- if (group == NULL)
- ossl_raise(eEC_GROUP, "unable to create curve (%s)", name);
-
- EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
- EC_GROUP_set_point_conversion_form(group, POINT_CONVERSION_UNCOMPRESSED);
- }
- }
-
- break;
- case 4:
- if (SYMBOL_P(arg1)) {
- ID id = SYM2ID(arg1);
- EC_GROUP *(*new_curve)(const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *) = NULL;
- const BIGNUM *p = GetBNPtr(arg2);
- const BIGNUM *a = GetBNPtr(arg3);
- const BIGNUM *b = GetBNPtr(arg4);
-
- if (id == s_GFp) {
- new_curve = EC_GROUP_new_curve_GFp;
- } else if (id == s_GF2m) {
- new_curve = EC_GROUP_new_curve_GF2m;
- } else {
- rb_raise(rb_eArgError, "unknown symbol, must be :GFp or :GF2m");
- }
-
- if ((group = new_curve(p, a, b, ossl_bn_ctx)) == NULL)
- ossl_raise(eEC_GROUP, "EC_GROUP_new_by_GF*");
- } else {
- rb_raise(rb_eArgError, "unknown argument, must be :GFp or :GF2m");
- }
-
- break;
- default:
- rb_raise(rb_eArgError, "wrong number of arguments");
- }
-
- if (group == NULL)
- ossl_raise(eEC_GROUP, "");
-
- ec_group->group = group;
-
- return self;
-}
-
-/* call-seq:
- * group1 == group2 => true | false
- *
- */
-static VALUE ossl_ec_group_eql(VALUE a, VALUE b)
-{
- EC_GROUP *group1 = NULL, *group2 = NULL;
-
- Require_EC_GROUP(a, group1);
- SafeRequire_EC_GROUP(b, group2);
-
- if (EC_GROUP_cmp(group1, group2, ossl_bn_ctx) == 1)
- return Qfalse;
-
- return Qtrue;
-}
-
-/* call-seq:
- * group.generator => ec_point
- *
- * See the OpenSSL documentation for EC_GROUP_get0_generator()
- */
-static VALUE ossl_ec_group_get_generator(VALUE self)
-{
- VALUE point_obj;
- EC_GROUP *group = NULL;
-
- Require_EC_GROUP(self, group);
-
- point_obj = ossl_ec_point_dup(EC_GROUP_get0_generator(group), self);
-
- return point_obj;
-}
-
-/* call-seq:
- * group.set_generator(generator, order, cofactor) => self
- *
- * See the OpenSSL documentation for EC_GROUP_set_generator()
- */
-static VALUE ossl_ec_group_set_generator(VALUE self, VALUE generator, VALUE order, VALUE cofactor)
-{
- EC_GROUP *group = NULL;
- const EC_POINT *point;
- const BIGNUM *o, *co;
-
- Require_EC_GROUP(self, group);
- SafeRequire_EC_POINT(generator, point);
- o = GetBNPtr(order);
- co = GetBNPtr(cofactor);
-
- if (EC_GROUP_set_generator(group, point, o, co) != 1)
- ossl_raise(eEC_GROUP, "EC_GROUP_set_generator");
-
- return self;
-}
-
-/* call-seq:
- * group.get_order => order_bn
- *
- * See the OpenSSL documentation for EC_GROUP_get_order()
- */
-static VALUE ossl_ec_group_get_order(VALUE self)
-{
- VALUE bn_obj;
- BIGNUM *bn;
- EC_GROUP *group = NULL;
-
- Require_EC_GROUP(self, group);
-
- bn_obj = ossl_bn_new(NULL);
- bn = GetBNPtr(bn_obj);
-
- if (EC_GROUP_get_order(group, bn, ossl_bn_ctx) != 1)
- ossl_raise(eEC_GROUP, "EC_GROUP_get_order");
-
- return bn_obj;
-}
-
-/* call-seq:
- * group.get_cofactor => cofactor_bn
- *
- * See the OpenSSL documentation for EC_GROUP_get_cofactor()
- */
-static VALUE ossl_ec_group_get_cofactor(VALUE self)
-{
- VALUE bn_obj;
- BIGNUM *bn;
- EC_GROUP *group = NULL;
-
- Require_EC_GROUP(self, group);
-
- bn_obj = ossl_bn_new(NULL);
- bn = GetBNPtr(bn_obj);
-
- if (EC_GROUP_get_cofactor(group, bn, ossl_bn_ctx) != 1)
- ossl_raise(eEC_GROUP, "EC_GROUP_get_cofactor");
-
- return bn_obj;
-}
-
-/* call-seq:
- * group.curve_name => String
- *
- * See the OpenSSL documentation for EC_GROUP_get_curve_name()
- */
-static VALUE ossl_ec_group_get_curve_name(VALUE self)
-{
- EC_GROUP *group = NULL;
- int nid;
-
- Get_EC_GROUP(self, group);
- if (group == NULL)
- return Qnil;
-
- nid = EC_GROUP_get_curve_name(group);
-
-/* BUG: an nid or asn1 object should be returned, maybe. */
- return rb_str_new2(OBJ_nid2sn(nid));
-}
-
-/* call-seq:
- * EC.builtin_curves => [[name, comment], ...]
- *
- * See the OpenSSL documentation for EC_builtin_curves()
- */
-static VALUE ossl_s_builtin_curves(VALUE self)
-{
- EC_builtin_curve *curves = NULL;
- int n;
- int crv_len = EC_get_builtin_curves(NULL, 0);
- VALUE ary, ret;
-
- curves = ALLOCA_N(EC_builtin_curve, crv_len);
- if (curves == NULL)
- return Qnil;
- if (!EC_get_builtin_curves(curves, crv_len))
- ossl_raise(rb_eRuntimeError, "EC_get_builtin_curves");
-
- ret = rb_ary_new2(crv_len);
-
- for (n = 0; n < crv_len; n++) {
- const char *sname = OBJ_nid2sn(curves[n].nid);
- const char *comment = curves[n].comment;
-
- ary = rb_ary_new2(2);
- rb_ary_push(ary, rb_str_new2(sname));
- rb_ary_push(ary, comment ? rb_str_new2(comment) : Qnil);
- rb_ary_push(ret, ary);
- }
-
- return ret;
-}
-
-/* call-seq:
- * group.asn1_flag => Fixnum
- *
- * See the OpenSSL documentation for EC_GROUP_get_asn1_flag()
- */
-static VALUE ossl_ec_group_get_asn1_flag(VALUE self)
-{
- EC_GROUP *group = NULL;
- int flag;
-
- Require_EC_GROUP(self, group);
-
- flag = EC_GROUP_get_asn1_flag(group);
-
- return INT2FIX(flag);
-}
-
-/* call-seq:
- * group.asn1_flag = Fixnum => Fixnum
- *
- * See the OpenSSL documentation for EC_GROUP_set_asn1_flag()
- */
-static VALUE ossl_ec_group_set_asn1_flag(VALUE self, VALUE flag_v)
-{
- EC_GROUP *group = NULL;
-
- Require_EC_GROUP(self, group);
-
- EC_GROUP_set_asn1_flag(group, NUM2INT(flag_v));
-
- return flag_v;
-}
-
-/* call-seq:
- * group.point_conversion_form => :uncompressed | :compressed | :hybrid
- *
- * See the OpenSSL documentation for EC_GROUP_get_point_conversion_form()
- */
-static VALUE ossl_ec_group_get_point_conversion_form(VALUE self)
-{
- EC_GROUP *group = NULL;
- point_conversion_form_t form;
- VALUE ret;
-
- Require_EC_GROUP(self, group);
-
- form = EC_GROUP_get_point_conversion_form(group);
-
- switch (form) {
- case POINT_CONVERSION_UNCOMPRESSED: ret = ID_uncompressed; break;
- case POINT_CONVERSION_COMPRESSED: ret = ID_compressed; break;
- case POINT_CONVERSION_HYBRID: ret = ID_hybrid; break;
- default: rb_raise(eEC_GROUP, "unsupported point conversion form: %d, this module should be updated", form);
- }
-
- return ID2SYM(ret);
-}
-
-/* call-seq:
- * group.point_conversion_form = form => form
- *
- * See the OpenSSL documentation for EC_GROUP_set_point_conversion_form()
- */
-static VALUE ossl_ec_group_set_point_conversion_form(VALUE self, VALUE form_v)
-{
- EC_GROUP *group = NULL;
- point_conversion_form_t form;
- ID form_id = SYM2ID(form_v);
-
- Require_EC_GROUP(self, group);
-
- if (form_id == ID_uncompressed) {
- form = POINT_CONVERSION_UNCOMPRESSED;
- } else if (form_id == ID_compressed) {
- form = POINT_CONVERSION_COMPRESSED;
- } else if (form_id == ID_hybrid) {
- form = POINT_CONVERSION_HYBRID;
- } else {
- rb_raise(rb_eArgError, "form must be :compressed, :uncompressed, or :hybrid");
- }
-
- EC_GROUP_set_point_conversion_form(group, form);
-
- return form_v;
-}
-
-/* call-seq:
- * group.seed => String or nil
- *
- * See the OpenSSL documentation for EC_GROUP_get0_seed()
- */
-static VALUE ossl_ec_group_get_seed(VALUE self)
-{
- EC_GROUP *group = NULL;
- size_t seed_len;
-
- Require_EC_GROUP(self, group);
-
- seed_len = EC_GROUP_get_seed_len(group);
-
- if (seed_len == 0)
- return Qnil;
-
- return rb_str_new(EC_GROUP_get0_seed(group), seed_len);
-}
-
-/* call-seq:
- * group.seed = seed => seed
- *
- * See the OpenSSL documentation for EC_GROUP_set_seed()
- */
-static VALUE ossl_ec_group_set_seed(VALUE self, VALUE seed)
-{
- EC_GROUP *group = NULL;
-
- Require_EC_GROUP(self, group);
- StringValue(seed);
-
- if (EC_GROUP_set_seed(group, RSTRING_PTR(seed), RSTRING_LEN(seed)) != RSTRING_LEN(seed))
- ossl_raise(eEC_GROUP, "EC_GROUP_set_seed");
-
- return seed;
-}
-
-/* get/set curve GFp, GF2m */
-
-/* call-seq:
- * group.degree => Fixnum
- *
- * See the OpenSSL documentation for EC_GROUP_get_degree()
- */
-static VALUE ossl_ec_group_get_degree(VALUE self)
-{
- EC_GROUP *group = NULL;
-
- Require_EC_GROUP(self, group);
-
- return INT2NUM(EC_GROUP_get_degree(group));
-}
-
-static VALUE ossl_ec_group_to_string(VALUE self, int format)
-{
- EC_GROUP *group;
- BIO *out;
- int i = -1;
- VALUE str;
-
- Get_EC_GROUP(self, group);
-
- if (!(out = BIO_new(BIO_s_mem())))
- ossl_raise(eEC_GROUP, "BIO_new(BIO_s_mem())");
-
- switch(format) {
- case EXPORT_PEM:
- i = PEM_write_bio_ECPKParameters(out, group);
- break;
- case EXPORT_DER:
- i = i2d_ECPKParameters_bio(out, group);
- break;
- default:
- BIO_free(out);
- rb_raise(rb_eRuntimeError, "unknown format (internal error)");
- }
-
- if (i != 1) {
- BIO_free(out);
- ossl_raise(eECError, NULL);
- }
-
- str = ossl_membio2str(out);
-
- return str;
-}
-
-/* call-seq:
- * group.to_pem => String
- *
- * See the OpenSSL documentation for PEM_write_bio_ECPKParameters()
- */
-static VALUE ossl_ec_group_to_pem(VALUE self)
-{
- return ossl_ec_group_to_string(self, EXPORT_PEM);
-}
-
-/* call-seq:
- * group.to_der => String
- *
- * See the OpenSSL documentation for i2d_ECPKParameters_bio()
- */
-static VALUE ossl_ec_group_to_der(VALUE self)
-{
- return ossl_ec_group_to_string(self, EXPORT_DER);
-}
-
-/* call-seq:
- * group.to_text => String
- *
- * See the OpenSSL documentation for ECPKParameters_print()
- */
-static VALUE ossl_ec_group_to_text(VALUE self)
-{
- EC_GROUP *group;
- BIO *out;
- VALUE str;
-
- Require_EC_GROUP(self, group);
- if (!(out = BIO_new(BIO_s_mem()))) {
- ossl_raise(eEC_GROUP, "BIO_new(BIO_s_mem())");
- }
- if (!ECPKParameters_print(out, group, 0)) {
- BIO_free(out);
- ossl_raise(eEC_GROUP, NULL);
- }
- str = ossl_membio2str(out);
-
- return str;
-}
-
-
-static void ossl_ec_point_free(ossl_ec_point *ec_point)
-{
- if (!ec_point->dont_free && ec_point->point)
- EC_POINT_clear_free(ec_point->point);
- free(ec_point);
-}
-
-static VALUE ossl_ec_point_alloc(VALUE klass)
-{
- ossl_ec_point *ec_point;
- VALUE obj;
-
- obj = Data_Make_Struct(klass, ossl_ec_point, 0, ossl_ec_point_free, ec_point);
-
- return obj;
-}
-
-/*
- * call-seq:
- * OpenSSL::PKey::EC::Point.new(point)
- * OpenSSL::PKey::EC::Point.new(group)
- * OpenSSL::PKey::EC::Point.new(group, bn)
- *
- * See the OpenSSL documentation for EC_POINT_*
- */
-static VALUE ossl_ec_point_initialize(int argc, VALUE *argv, VALUE self)
-{
- ossl_ec_point *ec_point;
- EC_POINT *point = NULL;
- VALUE arg1, arg2;
- VALUE group_v = Qnil;
- const EC_GROUP *group = NULL;
-
- Data_Get_Struct(self, ossl_ec_point, ec_point);
- if (ec_point->point)
- rb_raise(eEC_POINT, "EC_POINT already initialized");
-
- switch (rb_scan_args(argc, argv, "11", &arg1, &arg2)) {
- case 1:
- if (rb_obj_is_kind_of(arg1, cEC_POINT)) {
- const EC_POINT *arg_point;
-
- group_v = rb_iv_get(arg1, "@group");
- SafeRequire_EC_GROUP(group_v, group);
- SafeRequire_EC_POINT(arg1, arg_point);
-
- point = EC_POINT_dup(arg_point, group);
- } else if (rb_obj_is_kind_of(arg1, cEC_GROUP)) {
- group_v = arg1;
- SafeRequire_EC_GROUP(group_v, group);
-
- point = EC_POINT_new(group);
- } else {
- rb_raise(eEC_POINT, "wrong argument type: must be OpenSSL::PKey::EC::Point or OpenSSL::Pkey::EC::Group");
- }
-
- break;
- case 2:
- if (!rb_obj_is_kind_of(arg1, cEC_GROUP))
- rb_raise(rb_eArgError, "1st argument must be OpenSSL::PKey::EC::Group");
- group_v = arg1;
- SafeRequire_EC_GROUP(group_v, group);
-
- if (rb_obj_is_kind_of(arg2, cBN)) {
- const BIGNUM *bn = GetBNPtr(arg2);
-
- point = EC_POINT_bn2point(group, bn, NULL, ossl_bn_ctx);
- } else {
- BIO *in = ossl_obj2bio(arg1);
-
-/* BUG: finish me */
-
- BIO_free(in);
-
- if (point == NULL) {
- ossl_raise(eEC_POINT, "unknown type for 2nd arg");
- }
- }
- break;
- default:
- rb_raise(rb_eArgError, "wrong number of arguments");
- }
-
- if (point == NULL)
- ossl_raise(eEC_POINT, NULL);
-
- if (NIL_P(group_v))
- rb_raise(rb_eRuntimeError, "missing group (internal error)");
-
- ec_point->point = point;
-
- rb_iv_set(self, "@group", group_v);
-
- return self;
-}
-
-/*
- * call-seq:
- * point1 == point2 => true | false
- *
- */
-static VALUE ossl_ec_point_eql(VALUE a, VALUE b)
-{
- EC_POINT *point1, *point2;
- VALUE group_v1 = rb_iv_get(a, "@group");
- VALUE group_v2 = rb_iv_get(b, "@group");
- const EC_GROUP *group;
-
- if (ossl_ec_group_eql(group_v1, group_v2) == Qfalse)
- return Qfalse;
-
- Require_EC_POINT(a, point1);
- SafeRequire_EC_POINT(b, point2);
- SafeRequire_EC_GROUP(group_v1, group);
-
- if (EC_POINT_cmp(group, point1, point2, ossl_bn_ctx) == 1)
- return Qfalse;
-
- return Qtrue;
-}
-
-/*
- * call-seq:
- * point.infinity? => true | false
- *
- */
-static VALUE ossl_ec_point_is_at_infinity(VALUE self)
-{
- EC_POINT *point;
- VALUE group_v = rb_iv_get(self, "@group");
- const EC_GROUP *group;
-
- Require_EC_POINT(self, point);
- SafeRequire_EC_GROUP(group_v, group);
-
- switch (EC_POINT_is_at_infinity(group, point)) {
- case 1: return Qtrue;
- case 0: return Qfalse;
- default: ossl_raise(cEC_POINT, "EC_POINT_is_at_infinity");
- }
-}
-
-/*
- * call-seq:
- * point.on_curve? => true | false
- *
- */
-static VALUE ossl_ec_point_is_on_curve(VALUE self)
-{
- EC_POINT *point;
- VALUE group_v = rb_iv_get(self, "@group");
- const EC_GROUP *group;
-
- Require_EC_POINT(self, point);
- SafeRequire_EC_GROUP(group_v, group);
-
- switch (EC_POINT_is_on_curve(group, point, ossl_bn_ctx)) {
- case 1: return Qtrue;
- case 0: return Qfalse;
- default: ossl_raise(cEC_POINT, "EC_POINT_is_on_curve");
- }
-}
-
-/*
- * call-seq:
- * point.make_affine! => self
- *
- */
-static VALUE ossl_ec_point_make_affine(VALUE self)
-{
- EC_POINT *point;
- VALUE group_v = rb_iv_get(self, "@group");
- const EC_GROUP *group;
-
- Require_EC_POINT(self, point);
- SafeRequire_EC_GROUP(group_v, group);
-
- if (EC_POINT_make_affine(group, point, ossl_bn_ctx) != 1)
- ossl_raise(cEC_POINT, "EC_POINT_make_affine");
-
- return self;
-}
-
-/*
- * call-seq:
- * point.invert! => self
- *
- */
-static VALUE ossl_ec_point_invert(VALUE self)
-{
- EC_POINT *point;
- VALUE group_v = rb_iv_get(self, "@group");
- const EC_GROUP *group;
-
- Require_EC_POINT(self, point);
- SafeRequire_EC_GROUP(group_v, group);
-
- if (EC_POINT_invert(group, point, ossl_bn_ctx) != 1)
- ossl_raise(cEC_POINT, "EC_POINT_invert");
-
- return self;
-}
-
-/*
- * call-seq:
- * point.set_to_infinity! => self
- *
- */
-static VALUE ossl_ec_point_set_to_infinity(VALUE self)
-{
- EC_POINT *point;
- VALUE group_v = rb_iv_get(self, "@group");
- const EC_GROUP *group;
-
- Require_EC_POINT(self, point);
- SafeRequire_EC_GROUP(group_v, group);
-
- if (EC_POINT_set_to_infinity(group, point) != 1)
- ossl_raise(cEC_POINT, "EC_POINT_set_to_infinity");
-
- return self;
-}
-
-/*
- * call-seq:
- * point.to_bn => OpenSSL::BN
- *
- * See the OpenSSL documentation for EC_POINT_point2bn()
- */
-static VALUE ossl_ec_point_to_bn(VALUE self)
-{
- EC_POINT *point;
- VALUE bn_obj;
- VALUE group_v = rb_iv_get(self, "@group");
- const EC_GROUP *group;
- point_conversion_form_t form;
- BIGNUM *bn;
-
- Require_EC_POINT(self, point);
- SafeRequire_EC_GROUP(group_v, group);
-
- form = EC_GROUP_get_point_conversion_form(group);
-
- bn_obj = rb_obj_alloc(cBN);
- bn = GetBNPtr(bn_obj);
-
- if (EC_POINT_point2bn(group, point, form, bn, ossl_bn_ctx) == NULL)
- ossl_raise(eEC_POINT, "EC_POINT_point2bn");
-
- return bn_obj;
-}
-
-static void no_copy(VALUE klass)
-{
- rb_undef_method(klass, "copy");
- rb_undef_method(klass, "clone");
- rb_undef_method(klass, "dup");
- rb_undef_method(klass, "initialize_copy");
-}
-
-void Init_ossl_ec()
-{
-#ifdef DONT_NEED_RDOC_WORKAROUND
- mOSSL = rb_define_module("OpenSSL");
- mPKey = rb_define_module_under(mOSSL, "PKey");
-#endif
-
- eECError = rb_define_class_under(mPKey, "ECError", ePKeyError);
-
- cEC = rb_define_class_under(mPKey, "EC", cPKey);
- cEC_GROUP = rb_define_class_under(cEC, "Group", rb_cObject);
- cEC_POINT = rb_define_class_under(cEC, "Point", rb_cObject);
- eEC_GROUP = rb_define_class_under(cEC_GROUP, "Error", eOSSLError);
- eEC_POINT = rb_define_class_under(cEC_POINT, "Error", eOSSLError);
-
- s_GFp = rb_intern("GFp");
- s_GF2m = rb_intern("GF2m");
- s_GFp_simple = rb_intern("GFp_simple");
- s_GFp_mont = rb_intern("GFp_mont");
- s_GFp_nist = rb_intern("GFp_nist");
- s_GF2m_simple = rb_intern("GF2m_simple");
-
- ID_uncompressed = rb_intern("uncompressed");
- ID_compressed = rb_intern("compressed");
- ID_hybrid = rb_intern("hybrid");
-
-#ifdef OPENSSL_EC_NAMED_CURVE
- rb_define_const(cEC, "NAMED_CURVE", ULONG2NUM(OPENSSL_EC_NAMED_CURVE));
-#endif
-
- rb_define_singleton_method(cEC, "builtin_curves", ossl_s_builtin_curves, 0);
-
- rb_define_method(cEC, "initialize", ossl_ec_key_initialize, -1);
-/* copy/dup/cmp */
-
- rb_define_method(cEC, "group", ossl_ec_key_get_group, 0);
- rb_define_method(cEC, "group=", ossl_ec_key_set_group, 1);
- rb_define_method(cEC, "private_key", ossl_ec_key_get_private_key, 0);
- rb_define_method(cEC, "private_key=", ossl_ec_key_set_private_key, 1);
- rb_define_method(cEC, "public_key", ossl_ec_key_get_public_key, 0);
- rb_define_method(cEC, "public_key=", ossl_ec_key_set_public_key, 1);
- rb_define_method(cEC, "private_key?", ossl_ec_key_is_private_key, 0);
- rb_define_method(cEC, "public_key?", ossl_ec_key_is_public_key, 0);
-/* rb_define_method(cEC, "", ossl_ec_key_get_, 0);
- rb_define_method(cEC, "=", ossl_ec_key_set_ 1);
- set/get enc_flags
- set/get _conv_from
- set/get asn1_flag (can use ruby to call self.group.asn1_flag)
- set/get precompute_mult
-*/
- rb_define_method(cEC, "generate_key", ossl_ec_key_generate_key, 0);
- rb_define_method(cEC, "check_key", ossl_ec_key_check_key, 0);
-
- rb_define_method(cEC, "dh_compute_key", ossl_ec_key_dh_compute_key, 1);
- rb_define_method(cEC, "dsa_sign_asn1", ossl_ec_key_dsa_sign_asn1, 1);
- rb_define_method(cEC, "dsa_verify_asn1", ossl_ec_key_dsa_verify_asn1, 2);
-/* do_sign/do_verify */
-
- rb_define_method(cEC, "to_pem", ossl_ec_key_to_pem, 0);
- rb_define_method(cEC, "to_der", ossl_ec_key_to_der, 0);
- rb_define_method(cEC, "to_text", ossl_ec_key_to_text, 0);
-
-
- rb_define_alloc_func(cEC_GROUP, ossl_ec_group_alloc);
- rb_define_method(cEC_GROUP, "initialize", ossl_ec_group_initialize, -1);
- rb_define_method(cEC_GROUP, "eql?", ossl_ec_group_eql, 1);
- rb_define_alias(cEC_GROUP, "==", "eql?");
-/* copy/dup/cmp */
-
- rb_define_method(cEC_GROUP, "generator", ossl_ec_group_get_generator, 0);
- rb_define_method(cEC_GROUP, "set_generator", ossl_ec_group_set_generator, 3);
- rb_define_method(cEC_GROUP, "order", ossl_ec_group_get_order, 0);
- rb_define_method(cEC_GROUP, "cofactor", ossl_ec_group_get_cofactor, 0);
-
- rb_define_method(cEC_GROUP, "curve_name", ossl_ec_group_get_curve_name, 0);
-/* rb_define_method(cEC_GROUP, "curve_name=", ossl_ec_group_set_curve_name, 1); */
-
- rb_define_method(cEC_GROUP, "asn1_flag", ossl_ec_group_get_asn1_flag, 0);
- rb_define_method(cEC_GROUP, "asn1_flag=", ossl_ec_group_set_asn1_flag, 1);
-
- rb_define_method(cEC_GROUP, "point_conversion_form", ossl_ec_group_get_point_conversion_form, 0);
- rb_define_method(cEC_GROUP, "point_conversion_form=", ossl_ec_group_set_point_conversion_form, 1);
-
- rb_define_method(cEC_GROUP, "seed", ossl_ec_group_get_seed, 0);
- rb_define_method(cEC_GROUP, "seed=", ossl_ec_group_set_seed, 1);
-
-/* get/set GFp, GF2m */
-
- rb_define_method(cEC_GROUP, "degree", ossl_ec_group_get_degree, 0);
-
-/* check* */
-
-
- rb_define_method(cEC_GROUP, "to_pem", ossl_ec_group_to_pem, 0);
- rb_define_method(cEC_GROUP, "to_der", ossl_ec_group_to_der, 0);
- rb_define_method(cEC_GROUP, "to_text", ossl_ec_group_to_text, 0);
-
-
- rb_define_alloc_func(cEC_POINT, ossl_ec_point_alloc);
- rb_define_method(cEC_POINT, "initialize", ossl_ec_point_initialize, -1);
- rb_attr(cEC_POINT, rb_intern("group"), 1, 0, 0);
- rb_define_method(cEC_POINT, "eql?", ossl_ec_point_eql, 1);
- rb_define_alias(cEC_POINT, "==", "eql?");
-
- rb_define_method(cEC_POINT, "infinity?", ossl_ec_point_is_at_infinity, 0);
- rb_define_method(cEC_POINT, "on_curve?", ossl_ec_point_is_on_curve, 0);
- rb_define_method(cEC_POINT, "make_affine!", ossl_ec_point_make_affine, 0);
- rb_define_method(cEC_POINT, "invert!", ossl_ec_point_invert, 0);
- rb_define_method(cEC_POINT, "set_to_infinity!", ossl_ec_point_set_to_infinity, 0);
-/* all the other methods */
-
- rb_define_method(cEC_POINT, "to_bn", ossl_ec_point_to_bn, 0);
-
- no_copy(cEC);
- no_copy(cEC_GROUP);
- no_copy(cEC_POINT);
-}
-
-#else /* defined NO_EC */
-void Init_ossl_ec()
-{
-}
-#endif /* NO_EC */
diff --git a/ext/openssl/ossl_pkey_rsa.c b/ext/openssl/ossl_pkey_rsa.c
index 9ac69e7ded..0afdcf8d01 100644
--- a/ext/openssl/ossl_pkey_rsa.c
+++ b/ext/openssl/ossl_pkey_rsa.c
@@ -84,19 +84,9 @@ rsa_generate(int size, int exp)
NULL);
}
-/*
- * call-seq:
- * RSA.generate(size [, exponent]) -> rsa
- *
- * === Parameters
- * * +size+ is an integer representing the desired key size. Keys smaller than 1024 should be considered insecure.
- * * +exponent+ is an odd number normally 3, 17, or 65537.
- *
- */
static VALUE
ossl_rsa_s_generate(int argc, VALUE *argv, VALUE klass)
{
-/* why does this method exist? why can't initialize take an optional exponent? */
RSA *rsa;
VALUE size, exp;
VALUE obj;
@@ -114,20 +104,6 @@ ossl_rsa_s_generate(int argc, VALUE *argv, VALUE klass)
return obj;
}
-/*
- * call-seq:
- * RSA.new([size | encoded_key] [, pass]) -> rsa
- *
- * === Parameters
- * * +size+ is an integer representing the desired key size.
- * * +encoded_key+ is a string containing PEM or DER encoded key.
- * * +pass+ is an optional string with the password to decrypt the encoded key.
- *
- * === Examples
- * * RSA.new(2048) -> rsa
- * * RSA.new(File.read("rsa.pem")) -> rsa
- * * RSA.new(File.read("rsa.pem"), "mypassword") -> rsa
- */
static VALUE
ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
{
@@ -181,13 +157,6 @@ ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
return self;
}
-/*
- * call-seq:
- * rsa.public? -> true
- *
- * The return value is always true since every private key is also a public key.
- *
- */
static VALUE
ossl_rsa_is_public(VALUE self)
{
@@ -195,16 +164,12 @@ ossl_rsa_is_public(VALUE self)
GetPKeyRSA(self, pkey);
/*
- * This method should check for n and e. BUG.
+ * SURPRISE! :-))
+ * Every key is public at the same time!
*/
return Qtrue;
}
-/*
- * call-seq:
- * rsa.private? -> true | false
- *
- */
static VALUE
ossl_rsa_is_private(VALUE self)
{
@@ -215,18 +180,6 @@ ossl_rsa_is_private(VALUE self)
return (RSA_PRIVATE(self, pkey->pkey.rsa)) ? Qtrue : Qfalse;
}
-/*
- * call-seq:
- * rsa.to_pem([cipher, pass]) -> aString
- *
- * === Parameters
- * * +cipher+ is a Cipher object.
- * * +pass+ is a string.
- *
- * === Examples
- * * rsa.to_pem -> aString
- * * rsa.to_pem(cipher, pass) -> aString
- */
static VALUE
ossl_rsa_export(int argc, VALUE *argv, VALUE self)
{
@@ -266,11 +219,6 @@ ossl_rsa_export(int argc, VALUE *argv, VALUE self)
return str;
}
-/*
- * call-seq:
- * rsa.to_der -> aString
- *
- */
static VALUE
ossl_rsa_to_der(VALUE self)
{
@@ -288,7 +236,7 @@ ossl_rsa_to_der(VALUE self)
if((len = i2d_func(pkey->pkey.rsa, NULL)) <= 0)
ossl_raise(eRSAError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_func(pkey->pkey.rsa, &p) < 0)
ossl_raise(eRSAError, NULL);
ossl_str_adjust(str, p);
@@ -298,11 +246,6 @@ ossl_rsa_to_der(VALUE self)
#define ossl_rsa_buf_size(pkey) (RSA_size((pkey)->pkey.rsa)+16)
-/*
- * call-seq:
- * rsa.public_encrypt(string [, padding]) -> aString
- *
- */
static VALUE
ossl_rsa_public_encrypt(int argc, VALUE *argv, VALUE self)
{
@@ -315,20 +258,16 @@ ossl_rsa_public_encrypt(int argc, VALUE *argv, VALUE self)
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
StringValue(buffer);
str = rb_str_new(0, ossl_rsa_buf_size(pkey));
- buf_len = RSA_public_encrypt(RSTRING_LEN(buffer), RSTRING_PTR(buffer),
- RSTRING_PTR(str), pkey->pkey.rsa,
+ buf_len = RSA_public_encrypt(RSTRING(buffer)->len, RSTRING(buffer)->ptr,
+ RSTRING(str)->ptr, pkey->pkey.rsa,
pad);
if (buf_len < 0) ossl_raise(eRSAError, NULL);
- rb_str_set_len(str, buf_len);
+ RSTRING(str)->len = buf_len;
+ RSTRING(str)->ptr[buf_len] = 0;
return str;
}
-/*
- * call-seq:
- * rsa.public_decrypt(string [, padding]) -> aString
- *
- */
static VALUE
ossl_rsa_public_decrypt(int argc, VALUE *argv, VALUE self)
{
@@ -341,20 +280,16 @@ ossl_rsa_public_decrypt(int argc, VALUE *argv, VALUE self)
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
StringValue(buffer);
str = rb_str_new(0, ossl_rsa_buf_size(pkey));
- buf_len = RSA_public_decrypt(RSTRING_LEN(buffer), RSTRING_PTR(buffer),
- RSTRING_PTR(str), pkey->pkey.rsa,
+ buf_len = RSA_public_decrypt(RSTRING(buffer)->len, RSTRING(buffer)->ptr,
+ RSTRING(str)->ptr, pkey->pkey.rsa,
pad);
if (buf_len < 0) ossl_raise(eRSAError, NULL);
- rb_str_set_len(str, buf_len);
+ RSTRING(str)->len = buf_len;
+ RSTRING(str)->ptr[buf_len] = 0;
return str;
}
-/*
- * call-seq:
- * rsa.private_encrypt(string [, padding]) -> aString
- *
- */
static VALUE
ossl_rsa_private_encrypt(int argc, VALUE *argv, VALUE self)
{
@@ -370,21 +305,16 @@ ossl_rsa_private_encrypt(int argc, VALUE *argv, VALUE self)
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
StringValue(buffer);
str = rb_str_new(0, ossl_rsa_buf_size(pkey));
- buf_len = RSA_private_encrypt(RSTRING_LEN(buffer), RSTRING_PTR(buffer),
- RSTRING_PTR(str), pkey->pkey.rsa,
+ buf_len = RSA_private_encrypt(RSTRING(buffer)->len, RSTRING(buffer)->ptr,
+ RSTRING(str)->ptr, pkey->pkey.rsa,
pad);
if (buf_len < 0) ossl_raise(eRSAError, NULL);
- rb_str_set_len(str, buf_len);
+ RSTRING(str)->len = buf_len;
+ RSTRING(str)->ptr[buf_len] = 0;
return str;
}
-
-/*
- * call-seq:
- * rsa.private_decrypt(string [, padding]) -> aString
- *
- */
static VALUE
ossl_rsa_private_decrypt(int argc, VALUE *argv, VALUE self)
{
@@ -400,19 +330,17 @@ ossl_rsa_private_decrypt(int argc, VALUE *argv, VALUE self)
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
StringValue(buffer);
str = rb_str_new(0, ossl_rsa_buf_size(pkey));
- buf_len = RSA_private_decrypt(RSTRING_LEN(buffer), RSTRING_PTR(buffer),
- RSTRING_PTR(str), pkey->pkey.rsa,
+ buf_len = RSA_private_decrypt(RSTRING(buffer)->len, RSTRING(buffer)->ptr,
+ RSTRING(str)->ptr, pkey->pkey.rsa,
pad);
if (buf_len < 0) ossl_raise(eRSAError, NULL);
- rb_str_set_len(str, buf_len);
+ RSTRING(str)->len = buf_len;
+ RSTRING(str)->ptr[buf_len] = 0;
return str;
}
/*
- * call-seq:
- * rsa.params -> hash
- *
* Stores all parameters of key to the hash
* INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
* Don't use :-)) (I's up to you)
@@ -440,9 +368,6 @@ ossl_rsa_get_params(VALUE self)
}
/*
- * call-seq:
- * rsa.to_text -> aString
- *
* Prints all parameters of key to buffer
* INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
* Don't use :-)) (It's up to you)
@@ -468,9 +393,6 @@ ossl_rsa_to_text(VALUE self)
}
/*
- * call-seq:
- * rsa.public_key -> aRSA
- *
* Makes new instance RSA PUBLIC_KEY from PRIVATE_KEY
*/
static VALUE
@@ -493,6 +415,7 @@ ossl_rsa_to_public_key(VALUE self)
/*
* TODO: Test me
+extern BN_CTX *ossl_bn_ctx;
static VALUE
ossl_rsa_blinding_on(VALUE self)
@@ -585,9 +508,11 @@ Init_ossl_rsa()
}
#else /* defined NO_RSA */
+# warning >>> OpenSSL is compiled without RSA support <<<
void
Init_ossl_rsa()
{
+ rb_warning("OpenSSL is compiled without RSA support");
}
#endif /* NO_RSA */
diff --git a/ext/openssl/ossl_rand.c b/ext/openssl/ossl_rand.c
index ad830fbc98..71bb3bedd5 100644
--- a/ext/openssl/ossl_rand.c
+++ b/ext/openssl/ossl_rand.c
@@ -27,150 +27,84 @@ VALUE eRandomError;
/*
* Private
*/
-
-/*
- * call-seq:
- * seed(str) -> str
- *
- */
static VALUE
ossl_rand_seed(VALUE self, VALUE str)
{
StringValue(str);
- RAND_seed(RSTRING_PTR(str), RSTRING_LEN(str));
+ RAND_seed(RSTRING(str)->ptr, RSTRING(str)->len);
return str;
}
-/*
- * call-seq:
- * add(str, entropy) -> self
- *
- */
-static VALUE
-ossl_rand_add(VALUE self, VALUE str, VALUE entropy)
-{
- StringValue(str);
- RAND_add(RSTRING_PTR(str), RSTRING_LEN(str), NUM2DBL(entropy));
-
- return self;
-}
-
-/*
- * call-seq:
- * load_random_file(filename) -> true
- *
- */
static VALUE
ossl_rand_load_file(VALUE self, VALUE filename)
{
SafeStringValue(filename);
- if(!RAND_load_file(RSTRING_PTR(filename), -1)) {
+ if(!RAND_load_file(RSTRING(filename)->ptr, -1)) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
}
-/*
- * call-seq:
- * write_random_file(filename) -> true
- *
- */
static VALUE
ossl_rand_write_file(VALUE self, VALUE filename)
{
SafeStringValue(filename);
- if (RAND_write_file(RSTRING_PTR(filename)) == -1) {
+ if (RAND_write_file(RSTRING(filename)->ptr) == -1) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
}
-/*
- * call-seq:
- * random_bytes(length) -> aString
- *
- */
static VALUE
ossl_rand_bytes(VALUE self, VALUE len)
{
VALUE str;
- int n = NUM2INT(len);
-
- str = rb_str_new(0, n);
- if (!RAND_bytes(RSTRING_PTR(str), n)) {
+
+ str = rb_str_new(0, FIX2INT(len));
+ if (!RAND_bytes(RSTRING(str)->ptr, FIX2INT(len))) {
ossl_raise(eRandomError, NULL);
}
return str;
}
-/*
- * call-seq:
- * pseudo_bytes(length) -> aString
- *
- */
static VALUE
ossl_rand_pseudo_bytes(VALUE self, VALUE len)
{
VALUE str;
- int n = NUM2INT(len);
- str = rb_str_new(0, n);
- if (!RAND_pseudo_bytes(RSTRING_PTR(str), n)) {
+ str = rb_str_new(0, FIX2INT(len));
+ if (!RAND_pseudo_bytes(RSTRING(str)->ptr, FIX2INT(len))) {
ossl_raise(eRandomError, NULL);
}
return str;
}
-/*
- * call-seq:
- * egd(filename) -> true
- *
- */
static VALUE
ossl_rand_egd(VALUE self, VALUE filename)
{
SafeStringValue(filename);
- if(!RAND_egd(RSTRING_PTR(filename))) {
+ if(!RAND_egd(RSTRING(filename)->ptr)) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
}
-/*
- * call-seq:
- * egd_bytes(filename, length) -> true
- *
- */
static VALUE
ossl_rand_egd_bytes(VALUE self, VALUE filename, VALUE len)
{
- long n = NUM2INT(len);
-
SafeStringValue(filename);
- if (!RAND_egd_bytes(RSTRING_PTR(filename), n)) {
+ if (!RAND_egd_bytes(RSTRING(filename)->ptr, FIX2INT(len))) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
}
-/*
- * call-seq:
- * status? => true | false
- *
- * Return true if the PRNG has been seeded with enough data, false otherwise.
- */
-static VALUE
-ossl_rand_status(VALUE self)
-{
- return RAND_status() ? Qtrue : Qfalse;
-}
-
#define DEFMETH(class, name, func, argc) \
rb_define_method(class, name, func, argc); \
rb_define_singleton_method(class, name, func, argc);
@@ -190,13 +124,11 @@ Init_ossl_rand()
eRandomError = rb_define_class_under(mRandom, "RandomError", eOSSLError);
DEFMETH(mRandom, "seed", ossl_rand_seed, 1);
- DEFMETH(mRandom, "random_add", ossl_rand_add, 2);
DEFMETH(mRandom, "load_random_file", ossl_rand_load_file, 1);
DEFMETH(mRandom, "write_random_file", ossl_rand_write_file, 1);
DEFMETH(mRandom, "random_bytes", ossl_rand_bytes, 1);
DEFMETH(mRandom, "pseudo_bytes", ossl_rand_pseudo_bytes, 1);
DEFMETH(mRandom, "egd", ossl_rand_egd, 1);
DEFMETH(mRandom, "egd_bytes", ossl_rand_egd_bytes, 2);
- DEFMETH(mRandom, "status?", ossl_rand_status, 0)
}
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 01b86fec27..8e632b526b 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -3,7 +3,6 @@
* 'OpenSSL for Ruby' project
* Copyright (C) 2000-2002 GOTOU Yuuzou <gotoyuzo@notwork.org>
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
- * Copyright (C) 2001-2007 Technorama Ltd. <oss-ruby@technorama.net>
* All rights reserved.
*/
/*
@@ -31,6 +30,9 @@ VALUE eSSLError;
VALUE cSSLContext;
VALUE cSSLSocket;
+/*
+ * SSLContext class
+ */
#define ossl_sslctx_set_cert(o,v) rb_iv_set((o),"@cert",(v))
#define ossl_sslctx_set_key(o,v) rb_iv_set((o),"@key",(v))
#define ossl_sslctx_set_client_ca(o,v) rb_iv_set((o),"@client_ca",(v))
@@ -63,12 +65,11 @@ VALUE cSSLSocket;
#define ossl_sslctx_get_tmp_dh_cb(o) rb_iv_get((o),"@tmp_dh_callback")
#define ossl_sslctx_get_sess_id_ctx(o) rb_iv_get((o),"@session_id_context")
-static const char *ossl_sslctx_attrs[] = {
+static char *ossl_sslctx_attrs[] = {
"cert", "key", "client_ca", "ca_file", "ca_path",
"timeout", "verify_mode", "verify_depth",
"verify_callback", "options", "cert_store", "extra_chain_cert",
"client_cert_cb", "tmp_dh_callback", "session_id_context",
- "session_get_cb", "session_new_cb", "session_remove_cb",
};
#define ossl_ssl_get_io(o) rb_iv_get((o),"@io")
@@ -85,10 +86,8 @@ static const char *ossl_sslctx_attrs[] = {
#define ossl_ssl_set_key(o,v) rb_iv_set((o),"@key",(v))
#define ossl_ssl_set_tmp_dh(o,v) rb_iv_set((o),"@tmp_dh",(v))
-static const char *ossl_ssl_attr_readers[] = { "io", "context", };
-static const char *ossl_ssl_attrs[] = { "sync_close", };
-
-ID ID_callback_state;
+static char *ossl_ssl_attr_readers[] = { "io", "context", };
+static char *ossl_ssl_attrs[] = { "sync_close", };
/*
* SSLContext class
@@ -142,13 +141,22 @@ ossl_sslctx_s_alloc(VALUE klass)
}
static VALUE
-ossl_sslctx_set_ssl_version(VALUE self, VALUE ssl_method)
+ossl_sslctx_initialize(int argc, VALUE *argv, VALUE self)
{
+ VALUE ssl_method;
SSL_METHOD *method = NULL;
- const char *s;
+ SSL_CTX *ctx;
int i;
+ char *s;
- SSL_CTX *ctx;
+ for(i = 0; i < numberof(ossl_sslctx_attrs); i++){
+ char buf[32];
+ snprintf(buf, sizeof(buf), "@%s", ossl_sslctx_attrs[i]);
+ rb_iv_set(self, buf, Qnil);
+ }
+ if (rb_scan_args(argc, argv, "01", &ssl_method) == 0){
+ return self;
+ }
if(TYPE(ssl_method) == T_SYMBOL)
s = rb_id2name(SYM2ID(ssl_method));
else
@@ -167,33 +175,6 @@ ossl_sslctx_set_ssl_version(VALUE self, VALUE ssl_method)
ossl_raise(eSSLError, "SSL_CTX_set_ssl_version:");
}
- return ssl_method;
-}
-
-/*
- * call-seq:
- * SSLContext.new => ctx
- * SSLContext.new(:TLSv1) => ctx
- * SSLContext.new("SSLv23_client") => ctx
- *
- * You can get a list of valid methods with OpenSSL::SSL::SSLContext::METHODS
- */
-static VALUE
-ossl_sslctx_initialize(int argc, VALUE *argv, VALUE self)
-{
- VALUE ssl_method;
- int i;
-
- for(i = 0; i < numberof(ossl_sslctx_attrs); i++){
- char buf[32];
- snprintf(buf, sizeof(buf), "@%s", ossl_sslctx_attrs[i]);
- rb_iv_set(self, buf, Qnil);
- }
- if (rb_scan_args(argc, argv, "01", &ssl_method) == 0){
- return self;
- }
- ossl_sslctx_set_ssl_version(self, ssl_method);
-
return self;
}
@@ -270,8 +251,6 @@ ossl_tmp_dh_callback(SSL *ssl, int is_export, int keylength)
static DH*
ossl_default_tmp_dh_callback(SSL *ssl, int is_export, int keylength)
{
- rb_warning("using default DH parameters.");
-
switch(keylength){
case 512:
return OSSL_DEFAULT_DH_512;
@@ -295,143 +274,6 @@ ossl_ssl_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
}
static VALUE
-ossl_call_session_get_cb(VALUE ary)
-{
- VALUE ssl_obj, sslctx_obj, cb, ret;
-
- Check_Type(ary, T_ARRAY);
- ssl_obj = rb_ary_entry(ary, 0);
-
- sslctx_obj = rb_iv_get(ssl_obj, "@context");
- if (NIL_P(sslctx_obj)) return Qnil;
- cb = rb_iv_get(sslctx_obj, "@session_get_cb");
- if (NIL_P(cb)) return Qnil;
-
- return rb_funcall(cb, rb_intern("call"), 1, ary);
-}
-
-/* this method is currently only called for servers (in OpenSSL <= 0.9.8e) */
-static SSL_SESSION *
-ossl_sslctx_session_get_cb(SSL *ssl, unsigned char *buf, int len, int *copy)
-{
- VALUE ary, ssl_obj, ret_obj;
- SSL_SESSION *sess;
- void *ptr;
- int state = 0;
-
- OSSL_Debug("SSL SESSION get callback entered");
- if ((ptr = SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx)) == NULL)
- return NULL;
- ssl_obj = (VALUE)ptr;
- ary = rb_ary_new2(2);
- rb_ary_push(ary, ssl_obj);
- rb_ary_push(ary, rb_str_new(buf, len));
-
- ret_obj = rb_protect((VALUE(*)_((VALUE)))ossl_call_session_get_cb, ary, &state);
- if (state) {
- rb_ivar_set(ssl_obj, ID_callback_state, INT2NUM(state));
- return NULL;
- }
- if (!rb_obj_is_instance_of(ret_obj, cSSLSession))
- return NULL;
-
- SafeGetSSLSession(ret_obj, sess);
- *copy = 1;
-
- return sess;
-}
-
-static VALUE
-ossl_call_session_new_cb(VALUE ary)
-{
- VALUE ssl_obj, sslctx_obj, cb, ret;
-
- Check_Type(ary, T_ARRAY);
- ssl_obj = rb_ary_entry(ary, 0);
-
- sslctx_obj = rb_iv_get(ssl_obj, "@context");
- if (NIL_P(sslctx_obj)) return Qnil;
- cb = rb_iv_get(sslctx_obj, "@session_new_cb");
- if (NIL_P(cb)) return Qnil;
-
- return rb_funcall(cb, rb_intern("call"), 1, ary);
-}
-
-/* return 1 normal. return 0 removes the session */
-static int
-ossl_sslctx_session_new_cb(SSL *ssl, SSL_SESSION *sess)
-{
- VALUE ary, ssl_obj, sess_obj, ret_obj;
- void *ptr;
- int state = 0;
-
- OSSL_Debug("SSL SESSION new callback entered");
-
- if ((ptr = SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx)) == NULL)
- return 1;
- ssl_obj = (VALUE)ptr;
- sess_obj = rb_obj_alloc(cSSLSession);
- CRYPTO_add(&sess->references, 1, CRYPTO_LOCK_SSL_SESSION);
- DATA_PTR(sess_obj) = sess;
-
- ary = rb_ary_new2(2);
- rb_ary_push(ary, ssl_obj);
- rb_ary_push(ary, sess_obj);
-
- ret_obj = rb_protect((VALUE(*)_((VALUE)))ossl_call_session_new_cb, ary, &state);
- if (state) {
- rb_ivar_set(ssl_obj, ID_callback_state, INT2NUM(state));
- return 0; /* what should be returned here??? */
- }
-
- return RTEST(ret_obj) ? 1 : 0;
-}
-
-static VALUE
-ossl_call_session_remove_cb(VALUE ary)
-{
- VALUE sslctx_obj, cb, ret;
-
- Check_Type(ary, T_ARRAY);
- sslctx_obj = rb_ary_entry(ary, 0);
-
- cb = rb_iv_get(sslctx_obj, "@session_remove_cb");
- if (NIL_P(cb)) return Qnil;
-
- return rb_funcall(cb, rb_intern("call"), 1, ary);
-}
-
-static void
-ossl_sslctx_session_remove_cb(SSL_CTX *ctx, SSL_SESSION *sess)
-{
- VALUE ary, sslctx_obj, sess_obj, ret_obj;
- void *ptr;
- int state = 0;
-
- OSSL_Debug("SSL SESSION remove callback entered");
-
- if ((ptr = SSL_CTX_get_ex_data(ctx, ossl_ssl_ex_ptr_idx)) == NULL)
- return;
- sslctx_obj = (VALUE)ptr;
- sess_obj = rb_obj_alloc(cSSLSession);
- CRYPTO_add(&sess->references, 1, CRYPTO_LOCK_SSL_SESSION);
- DATA_PTR(sess_obj) = sess;
-
- ary = rb_ary_new2(2);
- rb_ary_push(ary, sslctx_obj);
- rb_ary_push(ary, sess_obj);
-
- ret_obj = rb_protect((VALUE(*)_((VALUE)))ossl_call_session_new_cb, ary, &state);
- if (state) {
-/*
- the SSL_CTX is frozen, nowhere to save state.
- there is no common accessor method to check it either.
- rb_ivar_set(sslctx_obj, ID_callback_state, INT2NUM(state));
-*/
- }
-}
-
-static VALUE
ossl_sslctx_add_extra_chain_cert_i(VALUE i, VALUE arg)
{
X509 *x509;
@@ -446,14 +288,6 @@ ossl_sslctx_add_extra_chain_cert_i(VALUE i, VALUE arg)
return i;
}
-/*
- * call-seq:
- * ctx.setup => Qtrue # first time
- * ctx.setup => nil # thereafter
- *
- * This method is called automatically when a new SSLSocket is created.
- * Normally you do not need to call this method (unless you are writing an extension in C).
- */
static VALUE
ossl_sslctx_setup(VALUE self)
{
@@ -473,10 +307,10 @@ ossl_sslctx_setup(VALUE self)
SSL_CTX_set_tmp_dh_callback(ctx, ossl_tmp_dh_callback);
}
else{
+ rb_warning("using default DH parameters.");
SSL_CTX_set_tmp_dh_callback(ctx, ossl_default_tmp_dh_callback);
}
#endif
- SSL_CTX_set_ex_data(ctx, ossl_ssl_ex_ptr_idx, (void*)self);
val = ossl_sslctx_get_cert_store(self);
if(!NIL_P(val)){
@@ -493,7 +327,7 @@ ossl_sslctx_setup(VALUE self)
val = ossl_sslctx_get_extra_cert(self);
if(!NIL_P(val)){
- rb_block_call(val, rb_intern("each"), 0, 0, ossl_sslctx_add_extra_chain_cert_i, self);
+ rb_iterate(rb_each, val, ossl_sslctx_add_extra_chain_cert_i, self);
}
/* private key may be bundled in certificate file. */
@@ -518,8 +352,8 @@ ossl_sslctx_setup(VALUE self)
val = ossl_sslctx_get_client_ca(self);
if(!NIL_P(val)){
if(TYPE(val) == T_ARRAY){
- for(i = 0; i < RARRAY_LEN(val); i++){
- client_ca = GetX509CertPtr(RARRAY_PTR(val)[i]);
+ for(i = 0; i < RARRAY(val)->len; i++){
+ client_ca = GetX509CertPtr(RARRAY(val)->ptr[i]);
if (!SSL_CTX_add_client_CA(ctx, client_ca)){
/* Copies X509_NAME => FREE it. */
ossl_raise(eSSLError, "SSL_CTX_add_client_CA");
@@ -563,24 +397,12 @@ ossl_sslctx_setup(VALUE self)
val = ossl_sslctx_get_sess_id_ctx(self);
if (!NIL_P(val)){
StringValue(val);
- if (!SSL_CTX_set_session_id_context(ctx, RSTRING_PTR(val),
- RSTRING_LEN(val))){
- ossl_raise(eSSLError, "SSL_CTX_set_session_id_context:");
+ if (!SSL_CTX_set_session_id_context(ctx, RSTRING(val)->ptr,
+ RSTRING(val)->len)){
+ ossl_raise(eSSLError, "SSL_CTX_set_session_id_context:");
}
}
- if (RTEST(rb_iv_get(self, "@session_get_cb"))) {
- SSL_CTX_sess_set_get_cb(ctx, ossl_sslctx_session_get_cb);
- OSSL_Debug("SSL SESSION get callback added");
- }
- if (RTEST(rb_iv_get(self, "@session_new_cb"))) {
- SSL_CTX_sess_set_new_cb(ctx, ossl_sslctx_session_new_cb);
- OSSL_Debug("SSL SESSION new callback added");
- }
- if (RTEST(rb_iv_get(self, "@session_remove_cb"))) {
- SSL_CTX_sess_set_remove_cb(ctx, ossl_sslctx_session_remove_cb);
- OSSL_Debug("SSL SESSION remove callback added");
- }
return Qtrue;
}
@@ -600,10 +422,6 @@ ossl_ssl_cipher_to_ary(SSL_CIPHER *cipher)
return ary;
}
-/*
- * call-seq:
- * ctx.ciphers => [[name, version, bits, alg_bits], ...]
- */
static VALUE
ossl_sslctx_get_ciphers(VALUE self)
{
@@ -632,12 +450,6 @@ ossl_sslctx_get_ciphers(VALUE self)
return ary;
}
-/*
- * call-seq:
- * ctx.ciphers = "cipher1:cipher2:..."
- * ctx.ciphers = [name, ...]
- * ctx.ciphers = [[name, version, bits, alg_bits], ...]
- */
static VALUE
ossl_sslctx_set_ciphers(VALUE self, VALUE v)
{
@@ -650,12 +462,12 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
return v;
else if (TYPE(v) == T_ARRAY) {
str = rb_str_new(0, 0);
- for (i = 0; i < RARRAY_LEN(v); i++) {
+ for (i = 0; i < RARRAY(v)->len; i++) {
elem = rb_ary_entry(v, i);
if (TYPE(elem) == T_ARRAY) elem = rb_ary_entry(elem, 0);
elem = rb_String(elem);
rb_str_append(str, elem);
- if (i < RARRAY_LEN(v)-1) rb_str_cat2(str, ":");
+ if (i < RARRAY(v)->len-1) rb_str_cat2(str, ":");
}
} else {
str = v;
@@ -667,173 +479,13 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
ossl_raise(eSSLError, "SSL_CTX is not initialized.");
return Qnil;
}
- if (!SSL_CTX_set_cipher_list(ctx, RSTRING_PTR(str))) {
+ if (!SSL_CTX_set_cipher_list(ctx, RSTRING(str)->ptr)) {
ossl_raise(eSSLError, "SSL_CTX_set_cipher_list:");
}
return v;
}
-
-/*
- * call-seq:
- * ctx.session_add(session) -> true | false
- *
- */
-static VALUE
-ossl_sslctx_session_add(VALUE self, VALUE arg)
-{
- SSL_CTX *ctx;
- SSL_SESSION *sess;
-
- Data_Get_Struct(self, SSL_CTX, ctx);
- SafeGetSSLSession(arg, sess);
-
- return SSL_CTX_add_session(ctx, sess) == 1 ? Qtrue : Qfalse;
-}
-
-/*
- * call-seq:
- * ctx.session_remove(session) -> true | false
- *
- */
-static VALUE
-ossl_sslctx_session_remove(VALUE self, VALUE arg)
-{
- SSL_CTX *ctx;
- SSL_SESSION *sess;
-
- Data_Get_Struct(self, SSL_CTX, ctx);
- SafeGetSSLSession(arg, sess);
-
- return SSL_CTX_remove_session(ctx, sess) == 1 ? Qtrue : Qfalse;
-}
-
-/*
- * call-seq:
- * ctx.session_cache_mode -> integer
- *
- */
-static VALUE
-ossl_sslctx_get_session_cache_mode(VALUE self)
-{
- SSL_CTX *ctx;
-
- Data_Get_Struct(self, SSL_CTX, ctx);
-
- return LONG2NUM(SSL_CTX_get_session_cache_mode(ctx));
-}
-
-/*
- * call-seq:
- * ctx.session_cache_mode=(integer) -> integer
- *
- */
-static VALUE
-ossl_sslctx_set_session_cache_mode(VALUE self, VALUE arg)
-{
- SSL_CTX *ctx;
-
- Data_Get_Struct(self, SSL_CTX, ctx);
-
- SSL_CTX_set_session_cache_mode(ctx, NUM2LONG(arg));
-
- return arg;
-}
-
-/*
- * call-seq:
- * ctx.session_cache_size -> integer
- *
- */
-static VALUE
-ossl_sslctx_get_session_cache_size(VALUE self)
-{
- SSL_CTX *ctx;
-
- Data_Get_Struct(self, SSL_CTX, ctx);
-
- return LONG2NUM(SSL_CTX_sess_get_cache_size(ctx));
-}
-
-/*
- * call-seq:
- * ctx.session_cache_size=(integer) -> integer
- *
- */
-static VALUE
-ossl_sslctx_set_session_cache_size(VALUE self, VALUE arg)
-{
- SSL_CTX *ctx;
-
- Data_Get_Struct(self, SSL_CTX, ctx);
-
- SSL_CTX_sess_set_cache_size(ctx, NUM2LONG(arg));
-
- return arg;
-}
-
-/*
- * call-seq:
- * ctx.session_cache_stats -> Hash
- *
- */
-static VALUE
-ossl_sslctx_get_session_cache_stats(VALUE self)
-{
- SSL_CTX *ctx;
- VALUE hash;
-
- Data_Get_Struct(self, SSL_CTX, ctx);
-
- hash = rb_hash_new();
- rb_hash_aset(hash, ID2SYM(rb_intern("cache_num")), LONG2NUM(SSL_CTX_sess_number(ctx)));
- rb_hash_aset(hash, ID2SYM(rb_intern("connect")), LONG2NUM(SSL_CTX_sess_connect(ctx)));
- rb_hash_aset(hash, ID2SYM(rb_intern("connect_good")), LONG2NUM(SSL_CTX_sess_connect_good(ctx)));
- rb_hash_aset(hash, ID2SYM(rb_intern("connect_renegotiate")), LONG2NUM(SSL_CTX_sess_connect_renegotiate(ctx)));
- rb_hash_aset(hash, ID2SYM(rb_intern("accept")), LONG2NUM(SSL_CTX_sess_accept(ctx)));
- rb_hash_aset(hash, ID2SYM(rb_intern("accept_good")), LONG2NUM(SSL_CTX_sess_accept_good(ctx)));
- rb_hash_aset(hash, ID2SYM(rb_intern("accept_renegotiate")), LONG2NUM(SSL_CTX_sess_accept_renegotiate(ctx)));
- rb_hash_aset(hash, ID2SYM(rb_intern("cache_hits")), LONG2NUM(SSL_CTX_sess_hits(ctx)));
- rb_hash_aset(hash, ID2SYM(rb_intern("cb_hits")), LONG2NUM(SSL_CTX_sess_cb_hits(ctx)));
- rb_hash_aset(hash, ID2SYM(rb_intern("cache_misses")), LONG2NUM(SSL_CTX_sess_misses(ctx)));
- rb_hash_aset(hash, ID2SYM(rb_intern("cache_full")), LONG2NUM(SSL_CTX_sess_cache_full(ctx)));
- rb_hash_aset(hash, ID2SYM(rb_intern("timeouts")), LONG2NUM(SSL_CTX_sess_timeouts(ctx)));
-
- return hash;
-}
-
-
-/*
- * call-seq:
- * ctx.flush_sessions(time | nil) -> self
- *
- */
-static VALUE
-ossl_sslctx_flush_sessions(int argc, VALUE *argv, VALUE self)
-{
- VALUE arg1;
- SSL_CTX *ctx;
- time_t tm = 0;
- int cb_state;
-
- rb_scan_args(argc, argv, "01", &arg1);
-
- Data_Get_Struct(self, SSL_CTX, ctx);
-
- if (NIL_P(arg1)) {
- tm = time(0);
- } else if (rb_obj_is_instance_of(arg1, rb_cTime)) {
- tm = NUM2LONG(rb_funcall(arg1, rb_intern("to_i"), 0));
- } else {
- rb_raise(rb_eArgError, "arg must be Time or nil");
- }
-
- SSL_CTX_flush_sessions(ctx, tm);
-
- return self;
-}
-
/*
* SSLSocket class
*/
@@ -859,20 +511,6 @@ ossl_ssl_s_alloc(VALUE klass)
return Data_Wrap_Struct(klass, 0, ossl_ssl_free, NULL);
}
-/*
- * call-seq:
- * SSLSocket.new(io) => aSSLSocket
- * SSLSocket.new(io, ctx) => aSSLSocket
- *
- * === Parameters
- * * +io+ is a real ruby IO object. Not an IO like object that responds to read/write.
- * * +ctx+ is an OpenSSLSSL::SSLContext.
- *
- * The OpenSSL::Buffering module provides additional IO methods.
- *
- * This method will freeze the SSLContext if one is provided;
- * however, session management is still allowed in the frozen SSLContext.
- */
static VALUE
ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)
{
@@ -898,7 +536,7 @@ ossl_ssl_setup(VALUE self)
VALUE io, v_ctx, cb;
SSL_CTX *ctx;
SSL *ssl;
- rb_io_t *fptr;
+ OpenFile *fptr;
Data_Get_Struct(self, SSL, ssl);
if(!ssl){
@@ -915,7 +553,7 @@ ossl_ssl_setup(VALUE self)
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
rb_io_check_writable(fptr);
- SSL_set_fd(ssl, TO_SOCKET(FPTR_TO_FD(fptr)));
+ SSL_set_fd(ssl, TO_SOCKET(fileno(fptr->f)));
SSL_set_ex_data(ssl, ossl_ssl_ex_ptr_idx, (void*)self);
cb = ossl_sslctx_get_verify_cb(v_ctx);
SSL_set_ex_data(ssl, ossl_ssl_ex_vcb_idx, (void*)cb);
@@ -929,85 +567,61 @@ ossl_ssl_setup(VALUE self)
}
#ifdef _WIN32
-#define ssl_get_error(ssl, ret) (errno = WSAGetLastError(), SSL_get_error(ssl, ret))
+#define ssl_get_error(ssl, ret) \
+ (errno = WSAGetLastError(), SSL_get_error(ssl, ret))
#else
#define ssl_get_error(ssl, ret) SSL_get_error(ssl, ret)
#endif
static VALUE
-ossl_start_ssl(VALUE self, int (*func)(), const char *funcname)
+ossl_start_ssl(VALUE self, int (*func)())
{
SSL *ssl;
- rb_io_t *fptr;
- int ret, ret2;
- VALUE cb_state;
-
- rb_ivar_set(self, ID_callback_state, Qnil);
+ OpenFile *fptr;
+ int ret;
Data_Get_Struct(self, SSL, ssl);
GetOpenFile(ossl_ssl_get_io(self), fptr);
for(;;){
if((ret = func(ssl)) > 0) break;
- switch((ret2 = ssl_get_error(ssl, ret))){
+ switch(ssl_get_error(ssl, ret)){
case SSL_ERROR_WANT_WRITE:
- rb_io_wait_writable(FPTR_TO_FD(fptr));
+ rb_io_wait_writable(fileno(fptr->f));
continue;
case SSL_ERROR_WANT_READ:
- rb_io_wait_readable(FPTR_TO_FD(fptr));
+ rb_io_wait_readable(fileno(fptr->f));
continue;
case SSL_ERROR_SYSCALL:
- if (errno) rb_sys_fail(funcname);
- ossl_raise(eSSLError, "%s SYSCALL returned=%d errno=%d state=%s", funcname, ret2, errno, SSL_state_string_long(ssl));
+ if (errno) rb_sys_fail(0);
default:
- ossl_raise(eSSLError, "%s returned=%d errno=%d state=%s", funcname, ret2, errno, SSL_state_string_long(ssl));
+ ossl_raise(eSSLError, NULL);
}
}
- cb_state = rb_ivar_get(self, ID_callback_state);
- if (!NIL_P(cb_state))
- rb_jump_tag(NUM2INT(cb_state));
-
return self;
}
-/*
- * call-seq:
- * ssl.connect => self
- */
static VALUE
ossl_ssl_connect(VALUE self)
{
ossl_ssl_setup(self);
- return ossl_start_ssl(self, SSL_connect, "SSL_connect");
+ return ossl_start_ssl(self, SSL_connect);
}
-/*
- * call-seq:
- * ssl.accept => self
- */
static VALUE
ossl_ssl_accept(VALUE self)
{
ossl_ssl_setup(self);
- return ossl_start_ssl(self, SSL_accept, "SSL_accept");
+ return ossl_start_ssl(self, SSL_accept);
}
-/*
- * call-seq:
- * ssl.sysread(length) => string
- * ssl.sysread(length, buffer) => buffer
- *
- * === Parameters
- * * +length+ is a positive integer.
- * * +buffer+ is a string used to store the result.
- */
static VALUE
ossl_ssl_read(int argc, VALUE *argv, VALUE self)
{
SSL *ssl;
int ilen, nread = 0;
VALUE len, str;
- rb_io_t *fptr;
+ OpenFile *fptr;
rb_scan_args(argc, argv, "11", &len, &str);
ilen = NUM2INT(len);
@@ -1023,19 +637,19 @@ ossl_ssl_read(int argc, VALUE *argv, VALUE self)
GetOpenFile(ossl_ssl_get_io(self), fptr);
if (ssl) {
if(SSL_pending(ssl) <= 0)
- rb_thread_wait_fd(FPTR_TO_FD(fptr));
+ rb_thread_wait_fd(fileno(fptr->f));
for (;;){
- nread = SSL_read(ssl, RSTRING_PTR(str), RSTRING_LEN(str));
+ nread = SSL_read(ssl, RSTRING(str)->ptr, RSTRING(str)->len);
switch(ssl_get_error(ssl, nread)){
case SSL_ERROR_NONE:
goto end;
case SSL_ERROR_ZERO_RETURN:
rb_eof_error();
case SSL_ERROR_WANT_WRITE:
- rb_io_wait_writable(FPTR_TO_FD(fptr));
+ rb_io_wait_writable(fileno(fptr->f));
continue;
case SSL_ERROR_WANT_READ:
- rb_io_wait_readable(FPTR_TO_FD(fptr));
+ rb_io_wait_readable(fileno(fptr->f));
continue;
case SSL_ERROR_SYSCALL:
if(ERR_peek_error() == 0 && nread == 0) rb_eof_error();
@@ -1052,22 +666,19 @@ ossl_ssl_read(int argc, VALUE *argv, VALUE self)
}
end:
- rb_str_set_len(str, nread);
+ RSTRING(str)->len = nread;
+ RSTRING(str)->ptr[nread] = 0;
OBJ_TAINT(str);
return str;
}
-/*
- * call-seq:
- * ssl.syswrite(string) => integer
- */
static VALUE
ossl_ssl_write(VALUE self, VALUE str)
{
SSL *ssl;
int nwrite = 0;
- rb_io_t *fptr;
+ OpenFile *fptr;
StringValue(str);
Data_Get_Struct(self, SSL, ssl);
@@ -1075,15 +686,15 @@ ossl_ssl_write(VALUE self, VALUE str)
if (ssl) {
for (;;){
- nwrite = SSL_write(ssl, RSTRING_PTR(str), RSTRING_LEN(str));
+ nwrite = SSL_write(ssl, RSTRING(str)->ptr, RSTRING(str)->len);
switch(ssl_get_error(ssl, nwrite)){
case SSL_ERROR_NONE:
goto end;
case SSL_ERROR_WANT_WRITE:
- rb_io_wait_writable(FPTR_TO_FD(fptr));
+ rb_io_wait_writable(fileno(fptr->f));
continue;
case SSL_ERROR_WANT_READ:
- rb_io_wait_readable(FPTR_TO_FD(fptr));
+ rb_io_wait_readable(fileno(fptr->f));
continue;
case SSL_ERROR_SYSCALL:
if (errno) rb_sys_fail(0);
@@ -1102,10 +713,6 @@ ossl_ssl_write(VALUE self, VALUE str)
return INT2NUM(nwrite);
}
-/*
- * call-seq:
- * ssl.sysclose => nil
- */
static VALUE
ossl_ssl_close(VALUE self)
{
@@ -1119,10 +726,6 @@ ossl_ssl_close(VALUE self)
return Qnil;
}
-/*
- * call-seq:
- * ssl.cert => cert or nil
- */
static VALUE
ossl_ssl_get_cert(VALUE self)
{
@@ -1147,10 +750,6 @@ ossl_ssl_get_cert(VALUE self)
return ossl_x509_new(cert);
}
-/*
- * call-seq:
- * ssl.peer_cert => cert or nil
- */
static VALUE
ossl_ssl_get_peer_cert(VALUE self)
{
@@ -1176,10 +775,6 @@ ossl_ssl_get_peer_cert(VALUE self)
return obj;
}
-/*
- * call-seq:
- * ssl.peer_cert_chain => [cert, ...] or nil
- */
static VALUE
ossl_ssl_get_peer_cert_chain(VALUE self)
{
@@ -1206,10 +801,6 @@ ossl_ssl_get_peer_cert_chain(VALUE self)
return ary;
}
-/*
- * call-seq:
- * ssl.cipher => [name, version, bits, alg_bits]
- */
static VALUE
ossl_ssl_get_cipher(VALUE self)
{
@@ -1226,10 +817,6 @@ ossl_ssl_get_cipher(VALUE self)
return ossl_ssl_cipher_to_ary(cipher);
}
-/*
- * call-seq:
- * ssl.state => string
- */
static VALUE
ossl_ssl_get_state(VALUE self)
{
@@ -1249,10 +836,6 @@ ossl_ssl_get_state(VALUE self)
return ret;
}
-/*
- * call-seq:
- * ssl.pending => integer
- */
static VALUE
ossl_ssl_pending(VALUE self)
{
@@ -1267,83 +850,15 @@ ossl_ssl_pending(VALUE self)
return INT2NUM(SSL_pending(ssl));
}
-/*
- * call-seq:
- * ssl.session_reused? -> true | false
- *
- */
-static VALUE
-ossl_ssl_session_reused(VALUE self)
-{
- SSL *ssl;
-
- Data_Get_Struct(self, SSL, ssl);
- if (!ssl) {
- rb_warning("SSL session is not started yet.");
- return Qnil;
- }
-
- switch(SSL_session_reused(ssl)) {
- case 1: return Qtrue;
- case 0: return Qfalse;
- default: ossl_raise(eSSLError, "SSL_session_reused");
- }
-}
-
-/*
- * call-seq:
- * ssl.session = session -> session
- *
- */
-static VALUE
-ossl_ssl_set_session(VALUE self, VALUE arg1)
-{
- SSL *ssl;
- SSL_SESSION *sess;
-
-/* why is ossl_ssl_setup delayed? */
- ossl_ssl_setup(self);
-
- Data_Get_Struct(self, SSL, ssl);
- if (!ssl) {
- rb_warning("SSL session is not started yet.");
- return Qnil;
- }
-
- SafeGetSSLSession(arg1, sess);
-
- if (SSL_set_session(ssl, sess) != 1)
- ossl_raise(eSSLError, "SSL_set_session");
-
- return arg1;
-}
-
-static VALUE
-ossl_ssl_get_verify_result(VALUE self)
-{
- SSL *ssl;
-
- Data_Get_Struct(self, SSL, ssl);
- if (!ssl) {
- rb_warning("SSL session is not started yet.");
- return Qnil;
- }
-
- return INT2FIX(SSL_get_verify_result(ssl));
-}
-
void
Init_ossl_ssl()
{
int i;
- VALUE ary;
#if 0 /* let rdoc know about mOSSL */
mOSSL = rb_define_module("OpenSSL");
#endif
- ID_callback_state = rb_intern("@callback_state");
-
ossl_ssl_ex_vcb_idx = SSL_get_ex_new_index(0,"ossl_ssl_ex_vcb_idx",0,0,0);
ossl_ssl_ex_store_p = SSL_get_ex_new_index(0,"ossl_ssl_ex_store_p",0,0,0);
ossl_ssl_ex_ptr_idx = SSL_get_ex_new_index(0,"ossl_ssl_ex_ptr_idx",0,0,0);
@@ -1355,60 +870,16 @@ Init_ossl_ssl()
mSSL = rb_define_module_under(mOSSL, "SSL");
eSSLError = rb_define_class_under(mSSL, "SSLError", eOSSLError);
- Init_ossl_ssl_session();
-
- /* class SSLContext
- *
- * The following attributes are available but don't show up in rdoc.
- * All attributes must be set before calling SSLSocket.new(io, ctx).
- * * ssl_version, cert, key, client_ca, ca_file, ca_path, timeout,
- * * verify_mode, verify_depth client_cert_cb, tmp_dh_callback,
- * * session_id_context, session_add_cb, session_new_cb, session_remove_cb
- */
+ /* class SSLContext */
cSSLContext = rb_define_class_under(mSSL, "SSLContext", rb_cObject);
rb_define_alloc_func(cSSLContext, ossl_sslctx_s_alloc);
for(i = 0; i < numberof(ossl_sslctx_attrs); i++)
rb_attr(cSSLContext, rb_intern(ossl_sslctx_attrs[i]), 1, 1, Qfalse);
- rb_define_alias(cSSLContext, "ssl_timeout", "timeout");
rb_define_method(cSSLContext, "initialize", ossl_sslctx_initialize, -1);
- rb_define_method(cSSLContext, "ssl_version=", ossl_sslctx_set_ssl_version, 1);
rb_define_method(cSSLContext, "ciphers", ossl_sslctx_get_ciphers, 0);
rb_define_method(cSSLContext, "ciphers=", ossl_sslctx_set_ciphers, 1);
- rb_define_method(cSSLContext, "setup", ossl_sslctx_setup, 0);
-
-
- rb_define_const(cSSLContext, "SESSION_CACHE_OFF", LONG2FIX(SSL_SESS_CACHE_OFF));
- rb_define_const(cSSLContext, "SESSION_CACHE_CLIENT", LONG2FIX(SSL_SESS_CACHE_CLIENT)); /* doesn't actually do anything in 0.9.8e */
- rb_define_const(cSSLContext, "SESSION_CACHE_SERVER", LONG2FIX(SSL_SESS_CACHE_SERVER));
- rb_define_const(cSSLContext, "SESSION_CACHE_BOTH", LONG2FIX(SSL_SESS_CACHE_BOTH)); /* no different than CACHE_SERVER in 0.9.8e */
- rb_define_const(cSSLContext, "SESSION_CACHE_NO_AUTO_CLEAR", LONG2FIX(SSL_SESS_CACHE_NO_AUTO_CLEAR));
- rb_define_const(cSSLContext, "SESSION_CACHE_NO_INTERNAL_LOOKUP", LONG2FIX(SSL_SESS_CACHE_NO_INTERNAL_LOOKUP));
- rb_define_const(cSSLContext, "SESSION_CACHE_NO_INTERNAL_STORE", LONG2FIX(SSL_SESS_CACHE_NO_INTERNAL_STORE));
- rb_define_const(cSSLContext, "SESSION_CACHE_NO_INTERNAL", LONG2FIX(SSL_SESS_CACHE_NO_INTERNAL));
- rb_define_method(cSSLContext, "session_add", ossl_sslctx_session_add, 1);
- rb_define_method(cSSLContext, "session_remove", ossl_sslctx_session_remove, 1);
- rb_define_method(cSSLContext, "session_cache_mode", ossl_sslctx_get_session_cache_mode, 0);
- rb_define_method(cSSLContext, "session_cache_mode=", ossl_sslctx_set_session_cache_mode, 1);
- rb_define_method(cSSLContext, "session_cache_size", ossl_sslctx_get_session_cache_size, 0);
- rb_define_method(cSSLContext, "session_cache_size=", ossl_sslctx_set_session_cache_size, 1);
- rb_define_method(cSSLContext, "session_cache_stats", ossl_sslctx_get_session_cache_stats, 0);
- rb_define_method(cSSLContext, "flush_sessions", ossl_sslctx_flush_sessions, -1);
-
- ary = rb_ary_new2(numberof(ossl_ssl_method_tab));
- for (i = 0; i < numberof(ossl_ssl_method_tab); i++) {
- rb_ary_push(ary, ID2SYM(rb_intern(ossl_ssl_method_tab[i].name)));
- }
- rb_obj_freeze(ary);
- /* holds a list of available SSL/TLS methods */
- rb_define_const(cSSLContext, "METHODS", ary);
-
- /* class SSLSocket
- *
- * The following attributes are available but don't show up in rdoc.
- * * io, context, sync_close
- *
- */
+ /* class SSLSocket */
cSSLSocket = rb_define_class_under(mSSL, "SSLSocket", rb_cObject);
rb_define_alloc_func(cSSLSocket, ossl_ssl_s_alloc);
for(i = 0; i < numberof(ossl_ssl_attr_readers); i++)
@@ -1428,9 +899,6 @@ Init_ossl_ssl()
rb_define_method(cSSLSocket, "cipher", ossl_ssl_get_cipher, 0);
rb_define_method(cSSLSocket, "state", ossl_ssl_get_state, 0);
rb_define_method(cSSLSocket, "pending", ossl_ssl_pending, 0);
- rb_define_method(cSSLSocket, "session_reused?", ossl_ssl_session_reused, 0);
- rb_define_method(cSSLSocket, "session=", ossl_ssl_set_session, 1);
- rb_define_method(cSSLSocket, "verify_result", ossl_ssl_get_verify_result, 0);
#define ossl_ssl_def_const(x) rb_define_const(mSSL, #x, INT2FIX(SSL_##x))
@@ -1466,9 +934,6 @@ Init_ossl_ssl()
ossl_ssl_def_const(OP_NO_SSLv2);
ossl_ssl_def_const(OP_NO_SSLv3);
ossl_ssl_def_const(OP_NO_TLSv1);
-#if defined(SSL_OP_NO_TICKET)
- ossl_ssl_def_const(OP_NO_TICKET);
-#endif
ossl_ssl_def_const(OP_PKCS1_CHECK_1);
ossl_ssl_def_const(OP_PKCS1_CHECK_2);
ossl_ssl_def_const(OP_NETSCAPE_CA_DN_BUG);
diff --git a/ext/openssl/ossl_ssl.h b/ext/openssl/ossl_ssl.h
index 487f41216c..5929eef856 100644
--- a/ext/openssl/ossl_ssl.h
+++ b/ext/openssl/ossl_ssl.h
@@ -11,26 +11,11 @@
#if !defined(_OSSL_SSL_H_)
#define _OSSL_SSL_H_
-#define GetSSLSession(obj, sess) do { \
- Data_Get_Struct(obj, SSL_SESSION, sess); \
- if (!sess) { \
- ossl_raise(rb_eRuntimeError, "SSL Session wasn't initialized."); \
- } \
-} while (0)
-
-#define SafeGetSSLSession(obj, sess) do { \
- OSSL_Check_Kind(obj, cSSLSession); \
- GetSSLSession(obj, sess); \
-} while (0)
-
extern VALUE mSSL;
extern VALUE eSSLError;
extern VALUE cSSLSocket;
extern VALUE cSSLContext;
-extern VALUE cSSLSession;
void Init_ossl_ssl(void);
-void Init_ossl_ssl_session(void);
#endif /* _OSSL_SSL_H_ */
-
diff --git a/ext/openssl/ossl_ssl_session.c b/ext/openssl/ossl_ssl_session.c
deleted file mode 100644
index 63c2bbb87a..0000000000
--- a/ext/openssl/ossl_ssl_session.c
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Copyright (C) 2004-2007 Technorama Ltd. <oss-ruby@technorama.net>
- */
-
-#include "ossl.h"
-
-#define GetSSLSession(obj, sess) do { \
- Data_Get_Struct(obj, SSL_SESSION, sess); \
- if (!sess) { \
- ossl_raise(rb_eRuntimeError, "SSL Session wasn't initialized."); \
- } \
-} while (0)
-
-#define SafeGetSSLSession(obj, sess) do { \
- OSSL_Check_Kind(obj, cSSLSession); \
- GetSSLSession(obj, sess); \
-} while (0)
-
-
-VALUE cSSLSession;
-static VALUE eSSLSession;
-
-static VALUE ossl_ssl_session_alloc(VALUE klass)
-{
- return Data_Wrap_Struct(klass, 0, SSL_SESSION_free, NULL);
-}
-
-/*
- * call-seq:
- * Session.new(SSLSocket | string) => session
- *
- * === Parameters
- * +SSLSocket+ is an OpenSSL::SSL::SSLSocket
- * +string+ must be a DER or PEM encoded Session.
-*/
-static VALUE ossl_ssl_session_initialize(VALUE self, VALUE arg1)
-{
- SSL_SESSION *ctx = NULL;
- VALUE obj;
- unsigned char *p;
-
- if (RDATA(self)->data)
- ossl_raise(eSSLSession, "SSL Session already initialized");
-
- if (rb_obj_is_instance_of(arg1, cSSLSocket)) {
- SSL *ssl;
-
- Data_Get_Struct(arg1, SSL, ssl);
-
- if (!ssl || (ctx = SSL_get1_session(ssl)) == NULL)
- ossl_raise(eSSLSession, "no session available");
- } else {
- BIO *in = ossl_obj2bio(arg1);
-
- ctx = PEM_read_bio_SSL_SESSION(in, NULL, NULL, NULL);
-
- if (!ctx) {
- BIO_reset(in);
- ctx = d2i_SSL_SESSION_bio(in, NULL);
- }
-
- BIO_free(in);
-
- if (!ctx)
- ossl_raise(rb_eArgError, "unknown type");
- }
-
- /* should not happen */
- if (ctx == NULL)
- ossl_raise(eSSLSession, "ctx not set - internal error");
-
- RDATA(self)->data = ctx;
-
- return self;
-}
-
-/*
- * call-seq:
- * session1 == session2 -> boolean
- *
-*/
-static VALUE ossl_ssl_session_eq(VALUE val1, VALUE val2)
-{
- SSL_SESSION *ctx1, *ctx2;
-
- GetSSLSession(val1, ctx1);
- SafeGetSSLSession(val2, ctx2);
-
- switch (SSL_SESSION_cmp(ctx1, ctx2)) {
- case 0: return Qtrue;
- default: return Qfalse;
- }
-}
-
-/*
- * call-seq:
- * session.time -> Time
- *
-*/
-static VALUE ossl_ssl_session_get_time(VALUE self)
-{
- SSL_SESSION *ctx;
- time_t t;
-
- GetSSLSession(self, ctx);
-
- t = SSL_SESSION_get_time(ctx);
-
- if (t == 0)
- return Qnil;
-
- return rb_funcall(rb_cTime, rb_intern("at"), 1, LONG2NUM(t));
-}
-
-/*
- * call-seq:
- * session.timeout -> integer
- *
- * How long until the session expires in seconds.
- *
-*/
-static VALUE ossl_ssl_session_get_timeout(VALUE self)
-{
- SSL_SESSION *ctx;
- time_t t;
-
- GetSSLSession(self, ctx);
-
- t = SSL_SESSION_get_timeout(ctx);
-
- return ULONG2NUM(t);
-}
-
-#define SSLSESSION_SET_TIME(func) \
- static VALUE ossl_ssl_session_set_##func(VALUE self, VALUE time_v) \
- { \
- SSL_SESSION *ctx; \
- time_t t; \
- \
- GetSSLSession(self, ctx); \
- \
- if (rb_obj_is_instance_of(time_v, rb_cTime)) { \
- time_v = rb_funcall(time_v, rb_intern("to_i"), 0); \
- } else if (FIXNUM_P(time_v)) { \
- ; \
- } else { \
- rb_raise(rb_eArgError, "unknown type"); \
- } \
- \
- t = NUM2ULONG(time_v); \
- \
- SSL_SESSION_set_##func(ctx, t); \
- \
- return ossl_ssl_session_get_##func(self); \
- }
-
-SSLSESSION_SET_TIME(time)
-SSLSESSION_SET_TIME(timeout)
-
-#ifdef HAVE_SSL_SESSION_GET_ID
-/*
- * call-seq:
- * session.id -> aString
- *
- * Returns the Session ID.
-*/
-static VALUE ossl_ssl_session_get_id(VALUE self)
-{
- SSL_SESSION *ctx;
- const unsigned char *p = NULL;
- unsigned int i = 0;
-
- GetSSLSession(self, ctx);
-
- p = SSL_SESSION_get_id(ctx, &i);
-
- return rb_str_new((const char *) p, i);
-}
-#endif
-
-/*
- * call-seq:
- * session.to_der -> aString
- *
- * Returns an ASN1 encoded String that contains the Session object.
-*/
-static VALUE ossl_ssl_session_to_der(VALUE self)
-{
- SSL_SESSION *ctx;
- unsigned char buf[1024*10], *p;
- int len;
-
- GetSSLSession(self, ctx);
-
- p = buf;
- len = i2d_SSL_SESSION(ctx, &p);
-
- if (len <= 0)
- ossl_raise(eSSLSession, "i2d_SSL_SESSION");
- else if (len >= sizeof(buf))
- ossl_raise(eSSLSession, "i2d_SSL_SESSION too large");
-
- return rb_str_new((const char *) p, len);
-}
-
-/*
- * call-seq:
- * session.to_pem -> String
- *
- * Returns a PEM encoded String that contains the Session object.
-*/
-static VALUE ossl_ssl_session_to_pem(VALUE self)
-{
- SSL_SESSION *ctx;
- BIO *out;
- BUF_MEM *buf;
- VALUE str;
- int i;
-
- GetSSLSession(self, ctx);
-
- if (!(out = BIO_new(BIO_s_mem()))) {
- ossl_raise(eSSLSession, "BIO_s_mem()");
- }
-
- if (!(i=PEM_write_bio_SSL_SESSION(out, ctx))) {
- BIO_free(out);
- ossl_raise(eSSLSession, "SSL_SESSION_print()");
- }
-
- BIO_get_mem_ptr(out, &buf);
- str = rb_str_new(buf->data, buf->length);
- BIO_free(out);
-
- return str;
-}
-
-
-/*
- * call-seq:
- * session.to_text -> String
- *
- * Shows everything in the Session object.
-*/
-static VALUE ossl_ssl_session_to_text(VALUE self)
-{
- SSL_SESSION *ctx;
- BIO *out;
- BUF_MEM *buf;
- VALUE str;
-
- GetSSLSession(self, ctx);
-
- if (!(out = BIO_new(BIO_s_mem()))) {
- ossl_raise(eSSLSession, "BIO_s_mem()");
- }
-
- if (!SSL_SESSION_print(out, ctx)) {
- BIO_free(out);
- ossl_raise(eSSLSession, "SSL_SESSION_print()");
- }
-
- BIO_get_mem_ptr(out, &buf);
- str = rb_str_new(buf->data, buf->length);
- BIO_free(out);
-
- return str;
-}
-
-
-void Init_ossl_ssl_session(void)
-{
-#if 0 /* let rdoc know about mOSSL */
- mOSSL = rb_define_module("OpenSSL");
- mSSL = rb_define_module_under(mOSSL, "SSL");
-#endif
- cSSLSession = rb_define_class_under(mSSL, "Session", rb_cObject);
- eSSLSession = rb_define_class_under(cSSLSession, "SessionError", eOSSLError);
-
- rb_define_alloc_func(cSSLSession, ossl_ssl_session_alloc);
- rb_define_method(cSSLSession, "initialize", ossl_ssl_session_initialize, 1);
-
- rb_define_method(cSSLSession, "==", ossl_ssl_session_eq, 1);
-
- rb_define_method(cSSLSession, "time", ossl_ssl_session_get_time, 0);
- rb_define_method(cSSLSession, "time=", ossl_ssl_session_set_time, 1);
- rb_define_method(cSSLSession, "timeout", ossl_ssl_session_get_timeout, 0);
- rb_define_method(cSSLSession, "timeout=", ossl_ssl_session_set_timeout, 1);
-
-#ifdef HAVE_SSL_SESSION_GET_ID
- rb_define_method(cSSLSession, "id", ossl_ssl_session_get_id, 0);
-#else
- rb_undef_method(cSSLSession, "id");
-#endif
- rb_define_method(cSSLSession, "to_der", ossl_ssl_session_to_der, 0);
- rb_define_method(cSSLSession, "to_pem", ossl_ssl_session_to_pem, 0);
- rb_define_method(cSSLSession, "to_text", ossl_ssl_session_to_text, 0);
-}
diff --git a/ext/openssl/ossl_x509attr.c b/ext/openssl/ossl_x509attr.c
index ca1c59aba9..7b88e294a9 100644
--- a/ext/openssl/ossl_x509attr.c
+++ b/ext/openssl/ossl_x509attr.c
@@ -84,10 +84,6 @@ ossl_x509attr_alloc(VALUE klass)
return obj;
}
-/*
- * call-seq:
- * Attribute.new(oid [, value]) => attr
- */
static VALUE
ossl_x509attr_initialize(int argc, VALUE *argv, VALUE self)
{
@@ -99,9 +95,9 @@ ossl_x509attr_initialize(int argc, VALUE *argv, VALUE self)
if(rb_scan_args(argc, argv, "11", &oid, &value) == 1){
oid = ossl_to_der_if_possible(oid);
StringValue(oid);
- p = RSTRING_PTR(oid);
+ p = RSTRING(oid)->ptr;
if(!d2i_X509_ATTRIBUTE((X509_ATTRIBUTE**)&DATA_PTR(self),
- &p, RSTRING_LEN(oid))){
+ &p, RSTRING(oid)->len)){
ossl_raise(eX509AttrError, NULL);
}
return self;
@@ -112,10 +108,6 @@ ossl_x509attr_initialize(int argc, VALUE *argv, VALUE self)
return self;
}
-/*
- * call-seq:
- * attr.oid = string => string
- */
static VALUE
ossl_x509attr_set_oid(VALUE self, VALUE oid)
{
@@ -133,10 +125,6 @@ ossl_x509attr_set_oid(VALUE self, VALUE oid)
return oid;
}
-/*
- * call-seq:
- * attr.oid => string
- */
static VALUE
ossl_x509attr_get_oid(VALUE self)
{
@@ -168,10 +156,6 @@ ossl_x509attr_get_oid(VALUE self)
# define OSSL_X509ATTR_SET_SINGLE(attr) ((attr)->set = 0)
#endif
-/*
- * call-seq:
- * attr.value = asn1 => asn1
- */
static VALUE
ossl_x509attr_set_value(VALUE self, VALUE value)
{
@@ -195,10 +179,6 @@ ossl_x509attr_set_value(VALUE self, VALUE value)
return value;
}
-/*
- * call-seq:
- * attr.value => asn1
- */
static VALUE
ossl_x509attr_get_value(VALUE self)
{
@@ -212,7 +192,7 @@ ossl_x509attr_get_value(VALUE self)
if(OSSL_X509ATTR_IS_SINGLE(attr)){
length = i2d_ASN1_TYPE(attr->value.single, NULL);
str = rb_str_new(0, length);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
i2d_ASN1_TYPE(attr->value.single, &p);
ossl_str_adjust(str, p);
}
@@ -220,7 +200,7 @@ ossl_x509attr_get_value(VALUE self)
length = i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, NULL,
i2d_ASN1_TYPE, V_ASN1_SET, V_ASN1_UNIVERSAL, 0);
str = rb_str_new(0, length);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, &p,
i2d_ASN1_TYPE, V_ASN1_SET, V_ASN1_UNIVERSAL, 0);
ossl_str_adjust(str, p);
@@ -230,10 +210,6 @@ ossl_x509attr_get_value(VALUE self)
return asn1;
}
-/*
- * call-seq:
- * attr.to_der => string
- */
static VALUE
ossl_x509attr_to_der(VALUE self)
{
@@ -246,10 +222,10 @@ ossl_x509attr_to_der(VALUE self)
if((len = i2d_X509_ATTRIBUTE(attr, NULL)) <= 0)
ossl_raise(eX509AttrError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_X509_ATTRIBUTE(attr, &p) <= 0)
ossl_raise(eX509AttrError, NULL);
- rb_str_set_len(str, p - (unsigned char*)RSTRING_PTR(str));
+ RSTRING(str)->len = p - (unsigned char*)RSTRING(str)->ptr;
return str;
}
diff --git a/ext/openssl/ossl_x509cert.c b/ext/openssl/ossl_x509cert.c
index b97f27ffa9..fc587a31f3 100644
--- a/ext/openssl/ossl_x509cert.c
+++ b/ext/openssl/ossl_x509cert.c
@@ -63,7 +63,7 @@ ossl_x509_new_from_file(VALUE filename)
VALUE obj;
SafeStringValue(filename);
- if (!(fp = fopen(RSTRING_PTR(filename), "r"))) {
+ if (!(fp = fopen(RSTRING(filename)->ptr, "r"))) {
ossl_raise(eX509CertError, "%s", strerror(errno));
}
x509 = PEM_read_X509(fp, NULL, NULL, NULL);
@@ -125,11 +125,6 @@ ossl_x509_alloc(VALUE klass)
return obj;
}
-/*
- * call-seq:
- * Certificate.new => cert
- * Certificate.new(string) => cert
- */
static VALUE
ossl_x509_initialize(int argc, VALUE *argv, VALUE self)
{
@@ -174,10 +169,6 @@ ossl_x509_copy(VALUE self, VALUE other)
return self;
}
-/*
- * call-seq:
- * cert.to_der => string
- */
static VALUE
ossl_x509_to_der(VALUE self)
{
@@ -190,7 +181,7 @@ ossl_x509_to_der(VALUE self)
if ((len = i2d_X509(x509, NULL)) <= 0)
ossl_raise(eX509CertError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if (i2d_X509(x509, &p) <= 0)
ossl_raise(eX509CertError, NULL);
ossl_str_adjust(str, p);
@@ -198,10 +189,6 @@ ossl_x509_to_der(VALUE self)
return str;
}
-/*
- * call-seq:
- * cert.to_pem => string
- */
static VALUE
ossl_x509_to_pem(VALUE self)
{
@@ -222,10 +209,6 @@ ossl_x509_to_pem(VALUE self)
return str;
}
-/*
- * call-seq:
- * cert.to_text => string
- */
static VALUE
ossl_x509_to_text(VALUE self)
{
@@ -269,10 +252,6 @@ ossl_x509_to_req(VALUE self)
}
#endif
-/*
- * call-seq:
- * cert.version => integer
- */
static VALUE
ossl_x509_get_version(VALUE self)
{
@@ -283,10 +262,6 @@ ossl_x509_get_version(VALUE self)
return LONG2NUM(X509_get_version(x509));
}
-/*
- * call-seq:
- * cert.version = integer => integer
- */
static VALUE
ossl_x509_set_version(VALUE self, VALUE version)
{
@@ -304,10 +279,6 @@ ossl_x509_set_version(VALUE self, VALUE version)
return version;
}
-/*
- * call-seq:
- * cert.serial => integer
- */
static VALUE
ossl_x509_get_serial(VALUE self)
{
@@ -318,10 +289,6 @@ ossl_x509_get_serial(VALUE self)
return asn1integer_to_num(X509_get_serialNumber(x509));
}
-/*
- * call-seq:
- * cert.serial = integer => integer
- */
static VALUE
ossl_x509_set_serial(VALUE self, VALUE num)
{
@@ -335,10 +302,6 @@ ossl_x509_set_serial(VALUE self, VALUE num)
return num;
}
-/*
- * call-seq:
- * cert.signature_algorithm => string
- */
static VALUE
ossl_x509_get_signature_algorithm(VALUE self)
{
@@ -359,10 +322,6 @@ ossl_x509_get_signature_algorithm(VALUE self)
return str;
}
-/*
- * call-seq:
- * cert.subject => name
- */
static VALUE
ossl_x509_get_subject(VALUE self)
{
@@ -377,10 +336,6 @@ ossl_x509_get_subject(VALUE self)
return ossl_x509name_new(name);
}
-/*
- * call-seq:
- * cert.subject = name => name
- */
static VALUE
ossl_x509_set_subject(VALUE self, VALUE subject)
{
@@ -394,10 +349,6 @@ ossl_x509_set_subject(VALUE self, VALUE subject)
return subject;
}
-/*
- * call-seq:
- * cert.issuer => name
- */
static VALUE
ossl_x509_get_issuer(VALUE self)
{
@@ -412,10 +363,6 @@ ossl_x509_get_issuer(VALUE self)
return ossl_x509name_new(name);
}
-/*
- * call-seq:
- * cert.issuer = name => name
- */
static VALUE
ossl_x509_set_issuer(VALUE self, VALUE issuer)
{
@@ -429,10 +376,6 @@ ossl_x509_set_issuer(VALUE self, VALUE issuer)
return issuer;
}
-/*
- * call-seq:
- * cert.not_before => time
- */
static VALUE
ossl_x509_get_not_before(VALUE self)
{
@@ -447,10 +390,6 @@ ossl_x509_get_not_before(VALUE self)
return asn1time_to_time(asn1time);
}
-/*
- * call-seq:
- * cert.not_before = time => time
- */
static VALUE
ossl_x509_set_not_before(VALUE self, VALUE time)
{
@@ -466,10 +405,6 @@ ossl_x509_set_not_before(VALUE self, VALUE time)
return time;
}
-/*
- * call-seq:
- * cert.not_after => time
- */
static VALUE
ossl_x509_get_not_after(VALUE self)
{
@@ -484,10 +419,6 @@ ossl_x509_get_not_after(VALUE self)
return asn1time_to_time(asn1time);
}
-/*
- * call-seq:
- * cert.not_before = time => time
- */
static VALUE
ossl_x509_set_not_after(VALUE self, VALUE time)
{
@@ -503,10 +434,6 @@ ossl_x509_set_not_after(VALUE self, VALUE time)
return time;
}
-/*
- * call-seq:
- * cert.public_key => key
- */
static VALUE
ossl_x509_get_public_key(VALUE self)
{
@@ -521,10 +448,6 @@ ossl_x509_get_public_key(VALUE self)
return ossl_pkey_new(pkey); /* NO DUP - OK */
}
-/*
- * call-seq:
- * cert.public_key = key => key
- */
static VALUE
ossl_x509_set_public_key(VALUE self, VALUE key)
{
@@ -538,10 +461,6 @@ ossl_x509_set_public_key(VALUE self, VALUE key)
return key;
}
-/*
- * call-seq:
- * cert.sign(key, digest) => self
- */
static VALUE
ossl_x509_sign(VALUE self, VALUE key, VALUE digest)
{
@@ -560,9 +479,6 @@ ossl_x509_sign(VALUE self, VALUE key, VALUE digest)
}
/*
- * call-seq:
- * cert.verify(key) => true | false
- *
* Checks that cert signature is made with PRIVversion of this PUBLIC 'key'
*/
static VALUE
@@ -585,9 +501,6 @@ ossl_x509_verify(VALUE self, VALUE key)
}
/*
- * call-seq:
- * cert.check_private_key(key)
- *
* Checks if 'key' is PRIV key for this cert
*/
static VALUE
@@ -608,8 +521,7 @@ ossl_x509_check_private_key(VALUE self, VALUE key)
}
/*
- * call-seq:
- * cert.extensions => [extension...]
+ * Gets X509v3 extensions as array of X509Ext objects
*/
static VALUE
ossl_x509_get_extensions(VALUE self)
@@ -634,8 +546,7 @@ ossl_x509_get_extensions(VALUE self)
}
/*
- * call-seq:
- * cert.extensions = [ext...] => [ext...]
+ * Sets X509_EXTENSIONs
*/
static VALUE
ossl_x509_set_extensions(VALUE self, VALUE ary)
@@ -646,14 +557,14 @@ ossl_x509_set_extensions(VALUE self, VALUE ary)
Check_Type(ary, T_ARRAY);
/* All ary's members should be X509Extension */
- for (i=0; i<RARRAY_LEN(ary); i++) {
- OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
}
GetX509(self, x509);
sk_X509_EXTENSION_pop_free(x509->cert_info->extensions, X509_EXTENSION_free);
x509->cert_info->extensions = NULL;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- ext = DupX509ExtPtr(RARRAY_PTR(ary)[i]);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ ext = DupX509ExtPtr(RARRAY(ary)->ptr[i]);
if (!X509_add_ext(x509, ext, -1)) { /* DUPs ext - FREE it */
X509_EXTENSION_free(ext);
@@ -665,10 +576,6 @@ ossl_x509_set_extensions(VALUE self, VALUE ary)
return ary;
}
-/*
- * call-seq:
- * cert.add_extension(extension) => extension
- */
static VALUE
ossl_x509_add_extension(VALUE self, VALUE extension)
{
diff --git a/ext/openssl/ossl_x509crl.c b/ext/openssl/ossl_x509crl.c
index be9ddacf48..0dc22416e7 100644
--- a/ext/openssl/ossl_x509crl.c
+++ b/ext/openssl/ossl_x509crl.c
@@ -287,14 +287,14 @@ ossl_x509crl_set_revoked(VALUE self, VALUE ary)
Check_Type(ary, T_ARRAY);
/* All ary members should be X509 Revoked */
- for (i=0; i<RARRAY_LEN(ary); i++) {
- OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Rev);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Rev);
}
GetX509CRL(self, crl);
sk_X509_REVOKED_pop_free(crl->crl->revoked, X509_REVOKED_free);
crl->crl->revoked = NULL;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- rev = DupX509RevokedPtr(RARRAY_PTR(ary)[i]);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ rev = DupX509RevokedPtr(RARRAY(ary)->ptr[i]);
if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
ossl_raise(eX509CRLError, NULL);
}
@@ -461,14 +461,14 @@ ossl_x509crl_set_extensions(VALUE self, VALUE ary)
Check_Type(ary, T_ARRAY);
/* All ary members should be X509 Extensions */
- for (i=0; i<RARRAY_LEN(ary); i++) {
- OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
}
GetX509CRL(self, crl);
sk_X509_EXTENSION_pop_free(crl->crl->extensions, X509_EXTENSION_free);
crl->crl->extensions = NULL;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- ext = DupX509ExtPtr(RARRAY_PTR(ary)[i]);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ ext = DupX509ExtPtr(RARRAY(ary)->ptr[i]);
if(!X509_CRL_add_ext(crl, ext, -1)) { /* DUPs ext - FREE it */
X509_EXTENSION_free(ext);
ossl_raise(eX509CRLError, NULL);
diff --git a/ext/openssl/ossl_x509ext.c b/ext/openssl/ossl_x509ext.c
index aa9366f901..31ffec48fa 100644
--- a/ext/openssl/ossl_x509ext.c
+++ b/ext/openssl/ossl_x509ext.c
@@ -229,23 +229,23 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
StringValue(value);
if(NIL_P(critical)) critical = Qfalse;
- nid = OBJ_ln2nid(RSTRING_PTR(oid));
- if(!nid) nid = OBJ_sn2nid(RSTRING_PTR(oid));
- if(!nid) ossl_raise(eX509ExtError, "unknown OID `%s'", RSTRING_PTR(oid));
+ nid = OBJ_ln2nid(RSTRING(oid)->ptr);
+ if(!nid) nid = OBJ_sn2nid(RSTRING(oid)->ptr);
+ if(!nid) ossl_raise(eX509ExtError, "unknown OID `%s'", RSTRING(oid)->ptr);
valstr = rb_str_new2(RTEST(critical) ? "critical," : "");
rb_str_append(valstr, value);
GetX509ExtFactory(self, ctx);
#ifdef HAVE_X509V3_EXT_NCONF_NID
rconf = rb_iv_get(self, "@config");
conf = NIL_P(rconf) ? NULL : GetConfigPtr(rconf);
- ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING_PTR(valstr));
+ ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING(valstr)->ptr);
#else
if (!empty_lhash) empty_lhash = lh_new(NULL, NULL);
- ext = X509V3_EXT_conf_nid(empty_lhash, ctx, nid, RSTRING_PTR(valstr));
+ ext = X509V3_EXT_conf_nid(empty_lhash, ctx, nid, RSTRING(valstr)->ptr);
#endif
if (!ext){
ossl_raise(eX509ExtError, "%s = %s",
- RSTRING_PTR(oid), RSTRING_PTR(value));
+ RSTRING(oid)->ptr, RSTRING(value)->ptr);
}
WrapX509Ext(cX509Ext, obj, ext);
@@ -280,9 +280,9 @@ ossl_x509ext_initialize(int argc, VALUE *argv, VALUE self)
if(rb_scan_args(argc, argv, "12", &oid, &value, &critical) == 1){
oid = ossl_to_der_if_possible(oid);
StringValue(oid);
- p = RSTRING_PTR(oid);
+ p = RSTRING(oid)->ptr;
if(!d2i_X509_EXTENSION((X509_EXTENSION**)&DATA_PTR(self),
- &p, RSTRING_LEN(oid)))
+ &p, RSTRING(oid)->len))
ossl_raise(eX509ExtError, NULL);
return self;
}
@@ -319,14 +319,14 @@ ossl_x509ext_set_value(VALUE self, VALUE data)
data = ossl_to_der_if_possible(data);
StringValue(data);
- if(!(s = OPENSSL_malloc(RSTRING_LEN(data))))
+ if(!(s = OPENSSL_malloc(RSTRING(data)->len)))
ossl_raise(eX509ExtError, "malloc error");
- memcpy(s, RSTRING_PTR(data), RSTRING_LEN(data));
+ memcpy(s, RSTRING(data)->ptr, RSTRING(data)->len);
if(!(asn1s = ASN1_OCTET_STRING_new())){
free(s);
ossl_raise(eX509ExtError, NULL);
}
- if(!M_ASN1_OCTET_STRING_set(asn1s, s, RSTRING_LEN(data))){
+ if(!M_ASN1_OCTET_STRING_set(asn1s, s, RSTRING(data)->len)){
free(s);
ASN1_OCTET_STRING_free(asn1s);
ossl_raise(eX509ExtError, NULL);
@@ -409,7 +409,7 @@ ossl_x509ext_to_der(VALUE obj)
if((len = i2d_X509_EXTENSION(ext, NULL)) <= 0)
ossl_raise(eX509ExtError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_X509_EXTENSION(ext, &p) < 0)
ossl_raise(eX509ExtError, NULL);
ossl_str_adjust(str, p);
diff --git a/ext/openssl/ossl_x509name.c b/ext/openssl/ossl_x509name.c
index b4434d2a34..076d61fb96 100644
--- a/ext/openssl/ossl_x509name.c
+++ b/ext/openssl/ossl_x509name.c
@@ -109,13 +109,6 @@ ossl_x509name_init_i(VALUE i, VALUE args)
return Qnil;
}
-/*
- * call-seq:
- * X509::Name.new => name
- * X509::Name.new(string) => name
- * X509::Name.new(dn) => name
- * X509::Name.new(dn, template) => name
- */
static VALUE
ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
{
@@ -132,14 +125,14 @@ ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
VALUE args;
if(NIL_P(template)) template = OBJECT_TYPE_TEMPLATE;
args = rb_ary_new3(2, self, template);
- rb_block_call(tmp, rb_intern("each"), 0, 0, ossl_x509name_init_i, args);
+ rb_iterate(rb_each, tmp, ossl_x509name_init_i, args);
}
else{
unsigned char *p;
VALUE str = ossl_to_der_if_possible(arg);
StringValue(str);
- p = RSTRING_PTR(str);
- if(!d2i_X509_NAME((X509_NAME**)&DATA_PTR(self), &p, RSTRING_LEN(str))){
+ p = RSTRING(str)->ptr;
+ if(!d2i_X509_NAME((X509_NAME**)&DATA_PTR(self), &p, RSTRING(str)->len)){
ossl_raise(eX509NameError, NULL);
}
}
@@ -148,10 +141,6 @@ ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
return self;
}
-/*
- * call-seq:
- * name.add_entry(oid, value [, type]) => self
- */
static
VALUE ossl_x509name_add_entry(int argc, VALUE *argv, VALUE self)
{
@@ -163,8 +152,8 @@ VALUE ossl_x509name_add_entry(int argc, VALUE *argv, VALUE self)
StringValue(value);
if(NIL_P(type)) type = rb_aref(OBJECT_TYPE_TEMPLATE, oid);
GetX509Name(self, name);
- if (!X509_NAME_add_entry_by_txt(name, RSTRING_PTR(oid), NUM2INT(type),
- RSTRING_PTR(value), RSTRING_LEN(value), -1, 0)) {
+ if (!X509_NAME_add_entry_by_txt(name, RSTRING(oid)->ptr, NUM2INT(type),
+ RSTRING(value)->ptr, RSTRING(value)->len, -1, 0)) {
ossl_raise(eX509NameError, NULL);
}
@@ -186,14 +175,9 @@ ossl_x509name_to_s_old(VALUE self)
return str;
}
-/*
- * call-seq:
- * name.to_s => string
- * name.to_s(integer) => string
- */
static VALUE
ossl_x509name_to_s(int argc, VALUE *argv, VALUE self)
-{
+{
X509_NAME *name;
VALUE flag, str;
BIO *out;
@@ -215,10 +199,6 @@ ossl_x509name_to_s(int argc, VALUE *argv, VALUE self)
return str;
}
-/*
- * call-seq:
- * name.to_a => [[name, data, type], ...]
- */
static VALUE
ossl_x509name_to_a(VALUE self)
{
@@ -286,10 +266,6 @@ ossl_x509name_eql(VALUE self, VALUE other)
return (result == 0) ? Qtrue : Qfalse;
}
-/*
- * call-seq:
- * name.hash => integer
- */
static VALUE
ossl_x509name_hash(VALUE self)
{
@@ -303,10 +279,6 @@ ossl_x509name_hash(VALUE self)
return ULONG2NUM(hash);
}
-/*
- * call-seq:
- * name.to_der => string
- */
static VALUE
ossl_x509name_to_der(VALUE self)
{
@@ -319,7 +291,7 @@ ossl_x509name_to_der(VALUE self)
if((len = i2d_X509_NAME(name, NULL)) <= 0)
ossl_raise(eX509NameError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_X509_NAME(name, &p) <= 0)
ossl_raise(eX509NameError, NULL);
ossl_str_adjust(str, p);
diff --git a/ext/openssl/ossl_x509req.c b/ext/openssl/ossl_x509req.c
index 13a42dddaf..d644250433 100644
--- a/ext/openssl/ossl_x509req.c
+++ b/ext/openssl/ossl_x509req.c
@@ -171,7 +171,7 @@ ossl_x509req_to_der(VALUE self)
if ((len = i2d_X509_REQ(req, NULL)) <= 0)
ossl_raise(eX509CertError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if (i2d_X509_REQ(req, &p) <= 0)
ossl_raise(eX509ReqError, NULL);
ossl_str_adjust(str, p);
@@ -403,14 +403,14 @@ ossl_x509req_set_attributes(VALUE self, VALUE ary)
VALUE item;
Check_Type(ary, T_ARRAY);
- for (i=0;i<RARRAY_LEN(ary); i++) {
- OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Attr);
+ for (i=0;i<RARRAY(ary)->len; i++) {
+ OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Attr);
}
GetX509Req(self, req);
sk_X509_ATTRIBUTE_pop_free(req->req_info->attributes, X509_ATTRIBUTE_free);
req->req_info->attributes = NULL;
- for (i=0;i<RARRAY_LEN(ary); i++) {
- item = RARRAY_PTR(ary)[i];
+ for (i=0;i<RARRAY(ary)->len; i++) {
+ item = RARRAY(ary)->ptr[i];
attr = DupX509AttrPtr(item);
if (!X509_REQ_add1_attr(req, attr)) {
ossl_raise(eX509ReqError, NULL);
diff --git a/ext/openssl/ossl_x509revoked.c b/ext/openssl/ossl_x509revoked.c
index d0f816bad4..3ccac8d26a 100644
--- a/ext/openssl/ossl_x509revoked.c
+++ b/ext/openssl/ossl_x509revoked.c
@@ -175,14 +175,14 @@ ossl_x509revoked_set_extensions(VALUE self, VALUE ary)
VALUE item;
Check_Type(ary, T_ARRAY);
- for (i=0; i<RARRAY_LEN(ary); i++) {
- OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
}
GetX509Rev(self, rev);
sk_X509_EXTENSION_pop_free(rev->extensions, X509_EXTENSION_free);
rev->extensions = NULL;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- item = RARRAY_PTR(ary)[i];
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ item = RARRAY(ary)->ptr[i];
ext = DupX509ExtPtr(item);
if(!X509_REVOKED_add_ext(rev, ext, -1)) {
ossl_raise(eX509RevError, NULL);
diff --git a/ext/openssl/ossl_x509store.c b/ext/openssl/ossl_x509store.c
index 769ce8a91a..cea845a1cc 100644
--- a/ext/openssl/ossl_x509store.c
+++ b/ext/openssl/ossl_x509store.c
@@ -118,18 +118,11 @@ ossl_x509store_set_vfy_cb(VALUE self, VALUE cb)
return cb;
}
-
-/*
- * call-seq:
- * X509::Store.new => store
- *
- */
static VALUE
ossl_x509store_initialize(int argc, VALUE *argv, VALUE self)
{
X509_STORE *store;
-/* BUG: This method takes any number of arguments but appears to ignore them. */
GetX509Store(self, store);
X509_STORE_set_verify_cb_func(store, ossl_verify_cb);
ossl_x509store_set_vfy_cb(self, Qnil);
@@ -213,7 +206,7 @@ ossl_x509store_add_file(VALUE self, VALUE file)
if(file != Qnil){
Check_SafeStr(file);
- path = RSTRING_PTR(file);
+ path = RSTRING(file)->ptr;
}
GetX509Store(self, store);
lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
@@ -234,7 +227,7 @@ ossl_x509store_add_path(VALUE self, VALUE dir)
if(dir != Qnil){
Check_SafeStr(dir);
- path = RSTRING_PTR(dir);
+ path = RSTRING(dir)->ptr;
}
GetX509Store(self, store);
lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());
@@ -458,7 +451,7 @@ ossl_x509stctx_set_error(VALUE self, VALUE err)
X509_STORE_CTX *ctx;
GetX509StCtx(self, ctx);
- X509_STORE_CTX_set_error(ctx, NUM2INT(err));
+ X509_STORE_CTX_set_error(ctx, FIX2INT(err));
return err;
}
@@ -557,10 +550,6 @@ ossl_x509stctx_set_trust(VALUE self, VALUE trust)
return trust;
}
-/*
- * call-seq:
- * storectx.time = time => time
- */
static VALUE
ossl_x509stctx_set_time(VALUE self, VALUE time)
{
diff --git a/ext/openssl/ruby_missing.h b/ext/openssl/ruby_missing.h
index 64b76f26b4..4bd08890f8 100644
--- a/ext/openssl/ruby_missing.h
+++ b/ext/openssl/ruby_missing.h
@@ -9,33 +9,10 @@
* (See the file 'LICENCE'.)
*/
#if !defined(_OSSL_RUBY_MISSING_H_)
-#define _OSSL_RUBY_MISSING_H_
+#define _OSS_RUBY_MISSING_H_
#define rb_define_copy_func(klass, func) \
rb_define_method(klass, "initialize_copy", func, 1)
+#endif /* _OSS_RUBY_MISSING_H_ */
-#ifndef GetReadFile
-#define FPTR_TO_FD(fptr) (fptr->fd)
-#else
-#define FPTR_TO_FD(fptr) (fileno(GetReadFile(fptr)))
-#endif
-
-#ifndef HAVE_RB_IO_T
-#define rb_io_t OpenFile
-#endif
-
-#ifndef HAVE_RB_STR_SET_LEN
-/* these methods should probably be backported to 1.8 */
-#define rb_str_set_len(str, length) do { \
- RSTRING(str)->ptr[length] = 0; \
- RSTRING(str)->len = length; \
-} while(0)
-#endif /* ! HAVE_RB_STR_SET_LEN */
-
-#ifndef HAVE_RB_BLOCK_CALL
-/* the openssl module doesn't use arg[3-4] and arg2 is always rb_each */
-#define rb_block_call(arg1, arg2, arg3, arg4, arg5, arg6) rb_iterate(rb_each, arg1, arg5, arg6)
-#endif /* ! HAVE_RB_BLOCK_CALL */
-
-#endif /* _OSSL_RUBY_MISSING_H_ */
diff --git a/ext/pty/expect_sample.rb b/ext/pty/expect_sample.rb
index 2a2e29f866..bf8a2352fe 100644
--- a/ext/pty/expect_sample.rb
+++ b/ext/pty/expect_sample.rb
@@ -15,6 +15,10 @@ PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
$expect_verbose = false
+ r_f.expect(/^Name.*: /) do
+ w_f.print "ftp\n"
+ end
+
if !ENV['USER'].nil?
username = ENV['USER']
elsif !ENV['LOGNAME'].nil?
@@ -23,16 +27,19 @@ PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
username = 'guest'
end
- r_f.expect(/^(Name).*: |(word):|> /) do
- w_f.puts($1 ? "ftp" : $2 ? "#{username}@" : "cd pub/ruby")
+ r_f.expect('word:') do
+ w_f.print username+"@\n"
+ end
+ r_f.expect("> ") do
+ w_f.print "cd pub/ruby\n"
end
r_f.expect("> ") do
w_f.print "dir\n"
end
- r_f.expect(/[^\-]> /) do |output|
+ r_f.expect("> ") do |output|
for x in output[0].split("\n")
- if x =~ /(ruby.*?\.tar\.gz)/ then
+ if x =~ /(ruby.*\.tar\.gz)/ then
fnames.push $1
end
end
diff --git a/ext/pty/lib/expect.rb b/ext/pty/lib/expect.rb
index 08191b05b9..aa9ab895d3 100644
--- a/ext/pty/lib/expect.rb
+++ b/ext/pty/lib/expect.rb
@@ -10,7 +10,7 @@ class IO
e_pat = pat
end
while true
- if !IO.select([self],nil,nil,timeout) or eof? then
+ if IO.select([self],nil,nil,timeout).nil? then
result = nil
break
end
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index 939335242f..206d4cd131 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -39,10 +39,10 @@
#if !defined(HAVE_OPENPTY)
#if defined(__hpux)
-static const
-char MasterDevice[] = "/dev/ptym/pty%s",
- SlaveDevice[] = "/dev/pty/tty%s",
- *const deviceNo[] = {
+static
+char *MasterDevice = "/dev/ptym/pty%s",
+ *SlaveDevice = "/dev/pty/tty%s",
+ *deviceNo[] = {
"p0","p1","p2","p3","p4","p5","p6","p7",
"p8","p9","pa","pb","pc","pd","pe","pf",
"q0","q1","q2","q3","q4","q5","q6","q7",
@@ -62,10 +62,10 @@ char MasterDevice[] = "/dev/ptym/pty%s",
0,
};
#elif defined(_IBMESA) /* AIX/ESA */
-static const
-char MasterDevice[] = "/dev/ptyp%s",
- SlaveDevice[] = "/dev/ttyp%s",
- *const deviceNo[] = {
+static
+char *MasterDevice = "/dev/ptyp%s",
+ *SlaveDevice = "/dev/ttyp%s",
+ *deviceNo[] = {
"00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f",
"10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f",
"20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f",
@@ -84,10 +84,10 @@ char MasterDevice[] = "/dev/ptyp%s",
"f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff",
};
#elif !defined(HAVE_PTSNAME)
-static const
-char MasterDevice[] = "/dev/pty%s",
- SlaveDevice[] = "/dev/tty%s",
- *const deviceNo[] = {
+static
+char *MasterDevice = "/dev/pty%s",
+ *SlaveDevice = "/dev/tty%s",
+ *deviceNo[] = {
"p0","p1","p2","p3","p4","p5","p6","p7",
"p8","p9","pa","pb","pc","pd","pe","pf",
"q0","q1","q2","q3","q4","q5","q6","q7",
@@ -101,6 +101,8 @@ char MasterDevice[] = "/dev/pty%s",
#endif
#endif /* !defined(HAVE_OPENPTY) */
+static char SlaveName[DEVICELEN];
+
#ifndef HAVE_SETEUID
# ifdef HAVE_SETREUID
# define seteuid(e) setreuid(-1, (e))
@@ -153,15 +155,17 @@ pty_syswait(info)
cpid = rb_waitpid(info->child_pid, &status, WUNTRACED);
if (cpid == -1) return Qnil;
-#if defined(WIFSTOPPED)
-#elif defined(IF_STOPPED)
-#define WIFSTOPPED(status) IF_STOPPED(status)
-#else
----->> Either IF_STOPPED or WIFSTOPPED is needed <<----
-#endif /* WIFSTOPPED | IF_STOPPED */
+#if defined(IF_STOPPED)
+ if (IF_STOPPED(status)) { /* suspend */
+ raise_from_wait("stopped", info);
+ }
+#elif defined(WIFSTOPPED)
if (WIFSTOPPED(status)) { /* suspend */
raise_from_wait("stopped", info);
}
+#else
+---->> Either IF_STOPPED or WIFSTOPPED is needed <<----
+#endif /* WIFSTOPPED | IF_STOPPED */
else if (kill(info->child_pid, 0) == 0) {
raise_from_wait("changed", info);
}
@@ -172,7 +176,7 @@ pty_syswait(info)
}
}
-static void getDevice _((int*, int*, char [DEVICELEN]));
+static void getDevice _((int*, int*));
struct exec_info {
int argc;
@@ -190,11 +194,10 @@ pty_exec(v)
}
static void
-establishShell(argc, argv, info, SlaveName)
+establishShell(argc, argv, info)
int argc;
VALUE *argv;
struct pty_info *info;
- char SlaveName[DEVICELEN];
{
int i,master,slave;
char *p, tmp, *getenv();
@@ -220,7 +223,7 @@ establishShell(argc, argv, info, SlaveName)
argc = 1;
argv = &v;
}
- getDevice(&master, &slave, SlaveName);
+ getDevice(&master,&slave);
info->thread = rb_thread_current();
if((i = fork()) < 0) {
@@ -304,9 +307,8 @@ pty_finalize_syswait(info)
}
static int
-get_device_once(master, slave, SlaveName, fail)
+get_device_once(master, slave, fail)
int *master, *slave, fail;
- char SlaveName[DEVICELEN];
{
#if defined HAVE_OPENPTY
/*
@@ -329,7 +331,7 @@ get_device_once(master, slave, SlaveName, fail)
}
*slave = open(name, O_RDWR);
- strncpy(SlaveName, name, sizeof SlaveName);
+ strcpy(SlaveName, name);
return 0;
#else /* HAVE__GETPTY */
@@ -357,7 +359,7 @@ get_device_once(master, slave, SlaveName, fail)
#endif
*master = i;
*slave = j;
- strncpy(SlaveName, pn, sizeof SlaveName);
+ strcpy(SlaveName, pn);
return 0;
#if defined I_PUSH && !defined linux
}
@@ -376,10 +378,10 @@ get_device_once(master, slave, SlaveName, fail)
char MasterName[DEVICELEN];
for (p = deviceNo; *p != NULL; p++) {
- snprintf(MasterName, sizeof MasterName, MasterDevice, *p);
+ sprintf(MasterName,MasterDevice,*p);
if ((i = open(MasterName,O_RDWR,0)) >= 0) {
*master = i;
- snprintf(SlaveName, sizeof SlaveName, SlaveDevice, *p);
+ sprintf(SlaveName,SlaveDevice,*p);
if ((j = open(SlaveName,O_RDWR,0)) >= 0) {
*slave = j;
chown(SlaveName, getuid(), getgid());
@@ -396,13 +398,12 @@ get_device_once(master, slave, SlaveName, fail)
}
static void
-getDevice(master, slave, slavename)
+getDevice(master, slave)
int *master, *slave;
- char slavename[DEVICELEN];
{
- if (get_device_once(master, slave, slavename, 0)) {
+ if (get_device_once(master, slave, 0)) {
rb_gc();
- get_device_once(master, slave, slavename, 1);
+ get_device_once(master, slave, 1);
}
}
@@ -416,15 +417,14 @@ pty_getpty(argc, argv, self)
VALUE res;
struct pty_info info;
struct pty_info thinfo;
- rb_io_t *wfptr,*rfptr;
+ OpenFile *wfptr,*rfptr;
VALUE rport = rb_obj_alloc(rb_cFile);
VALUE wport = rb_obj_alloc(rb_cFile);
- char SlaveName[DEVICELEN];
MakeOpenFile(rport, rfptr);
MakeOpenFile(wport, wfptr);
- establishShell(argc, argv, &info, SlaveName);
+ establishShell(argc, argv, &info);
rfptr->mode = rb_io_mode_flags("r");
rfptr->f = fdopen(info.fd, "r");
diff --git a/ext/purelib.rb b/ext/purelib.rb
index dbe514c34a..10ee06176c 100644
--- a/ext/purelib.rb
+++ b/ext/purelib.rb
@@ -1,10 +1,3 @@
-nul = nil
-$:.each_with_index {|path, index|
- if /\A(?:\.\/)*-\z/ =~ path
- nul = index
- break
- end
-}
-if nul
+if nul = $:.index("-")
$:[nul..-1] = ["."]
end
diff --git a/ext/readline/extconf.rb b/ext/readline/extconf.rb
index b820c0b32f..b57a36f3a5 100644
--- a/ext/readline/extconf.rb
+++ b/ext/readline/extconf.rb
@@ -42,9 +42,9 @@ else
end
end
-have_func("rl_filename_completion_function")
-have_func("rl_username_completion_function")
-have_func("rl_completion_matches")
+have_readline_var("rl_filename_completion_function")
+have_readline_var("rl_username_completion_function")
+have_readline_var("rl_completion_matches")
have_readline_var("rl_deprep_term_function")
have_readline_var("rl_completion_append_character")
have_readline_var("rl_basic_word_break_characters")
@@ -59,6 +59,7 @@ have_func("rl_cleanup_after_signal")
have_func("rl_clear_signals")
have_func("rl_vi_editing_mode")
have_func("rl_emacs_editing_mode")
+have_func("rl_clear_signals")
have_func("replace_history_entry")
have_func("remove_history")
create_makefile("readline")
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index c9acaadac9..559e1c677b 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -42,32 +42,17 @@ static ID completion_proc, completion_case_fold;
# define rl_completion_matches completion_matches
#endif
+static int readline_event(void);
static char **readline_attempted_completion_function(const char *text,
int start, int end);
-#ifdef HAVE_RL_EVENT_HOOK
-#ifdef DOSISH
-#define BUSY_WAIT 1
-#else
-#define BUSY_WAIT 0
-#endif
-
-static int readline_event(void);
static int
readline_event()
{
-#if BUSY_WAIT
+ CHECK_INTS;
rb_thread_schedule();
-#else
- fd_set rset;
-
- FD_ZERO(&rset);
- FD_SET(fileno(rl_instream), &rset);
- rb_thread_select(fileno(rl_instream) + 1, &rset, NULL, NULL, NULL);
return 0;
-#endif
}
-#endif
static VALUE
readline_readline(argc, argv, self)
@@ -79,7 +64,7 @@ readline_readline(argc, argv, self)
char *prompt = NULL;
char *buff;
int status;
- rb_io_t *ofp, *ifp;
+ OpenFile *ofp, *ifp;
rb_secure(4);
if (rb_scan_args(argc, argv, "02", &tmp, &add_hist) > 0) {
diff --git a/ext/socket/addrinfo.h b/ext/socket/addrinfo.h
index e93adafba6..a22615ee00 100644
--- a/ext/socket/addrinfo.h
+++ b/ext/socket/addrinfo.h
@@ -61,15 +61,10 @@
#undef NI_NUMERICSERV
#undef NI_DGRAM
-#undef addrinfo
#define addrinfo addrinfo__compat
-#undef getaddrinfo
#define getaddrinfo getaddrinfo__compat
-#undef getnameinfo
#define getnameinfo getnameinfo__compat
-#undef freehostent
#define freehostent freehostent__compat
-#undef freeaddrinfo
#define freeaddrinfo freeaddrinfo__compat
#ifndef __P
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 6dc4f832ac..4c23a1c178 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -244,7 +244,7 @@ init_sock(sock, fd)
VALUE sock;
int fd;
{
- rb_io_t *fp;
+ OpenFile *fp;
MakeOpenFile(sock, fp);
fp->f = rb_fdopen(fd, "r");
@@ -259,7 +259,7 @@ static VALUE
bsock_s_for_fd(klass, fd)
VALUE klass, fd;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
VALUE sock = init_sock(rb_obj_alloc(klass), NUM2INT(fd));
GetOpenFile(sock, fptr);
@@ -275,7 +275,7 @@ bsock_shutdown(argc, argv, sock)
{
VALUE howto;
int how;
- rb_io_t *fptr;
+ OpenFile *fptr;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(sock)) {
rb_raise(rb_eSecurityError, "Insecure: can't shutdown socket");
@@ -300,7 +300,7 @@ static VALUE
bsock_close_read(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(sock)) {
rb_raise(rb_eSecurityError, "Insecure: can't close socket");
@@ -319,7 +319,7 @@ static VALUE
bsock_close_write(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(sock)) {
rb_raise(rb_eSecurityError, "Insecure: can't close socket");
@@ -384,7 +384,7 @@ bsock_setsockopt(sock, lev, optname, val)
VALUE sock, lev, optname, val;
{
int level, option;
- rb_io_t *fptr;
+ OpenFile *fptr;
int i;
char *v;
int vlen;
@@ -467,7 +467,7 @@ bsock_getsockopt(sock, lev, optname)
int level, option;
socklen_t len;
char *buf;
- rb_io_t *fptr;
+ OpenFile *fptr;
level = NUM2INT(lev);
option = NUM2INT(optname);
@@ -491,7 +491,7 @@ bsock_getsockname(sock)
{
char buf[1024];
socklen_t len = sizeof buf;
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(sock, fptr);
if (getsockname(fileno(fptr->f), (struct sockaddr*)buf, &len) < 0)
@@ -505,7 +505,7 @@ bsock_getpeername(sock)
{
char buf[1024];
socklen_t len = sizeof buf;
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(sock, fptr);
if (getpeername(fileno(fptr->f), (struct sockaddr*)buf, &len) < 0)
@@ -521,7 +521,7 @@ bsock_send(argc, argv, sock)
{
VALUE mesg, to;
VALUE flags;
- rb_io_t *fptr;
+ OpenFile *fptr;
FILE *f;
int fd, n;
@@ -574,7 +574,7 @@ s_recvfrom(sock, argc, argv, from)
VALUE *argv;
enum sock_recv_type from;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
VALUE str;
char buf[1024];
socklen_t alen = sizeof buf;
@@ -644,7 +644,7 @@ s_recvfrom(sock, argc, argv, from)
static VALUE
s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
{
- rb_io_t *fptr;
+ OpenFile *fptr;
VALUE str;
char buf[1024];
socklen_t alen = sizeof buf;
@@ -893,10 +893,10 @@ port_str(port, pbuf, len)
}
#ifndef NI_MAXHOST
-# define NI_MAXHOST 1025
+# define 1025
#endif
#ifndef NI_MAXSERV
-# define NI_MAXSERV 32
+# define 32
#endif
static struct addrinfo*
@@ -1350,7 +1350,7 @@ static VALUE
socks_s_close(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(sock)) {
rb_raise(rb_eSecurityError, "Insecure: can't close socket");
@@ -1464,26 +1464,8 @@ tcp_svr_init(argc, argv, sock)
return init_inetsock(sock, Qnil, arg1, Qnil, Qnil, INET_SERVER);
}
-static void
-make_fd_nonblock(int fd)
-{
- int flags;
-#ifdef F_GETFL
- flags = fcntl(fd, F_GETFL);
- if (flags == -1) {
- rb_sys_fail(0);
- }
-#else
- flags = 0;
-#endif
- flags |= O_NONBLOCK;
- if (fcntl(fd, F_SETFL, flags) == -1) {
- rb_sys_fail(0);
- }
-}
-
static VALUE
-s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
+s_accept_nonblock(VALUE klass, OpenFile *fptr, struct sockaddr *sockaddr, socklen_t *len)
{
int fd2;
@@ -1493,7 +1475,6 @@ s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen
if (fd2 < 0) {
rb_sys_fail("accept(2)");
}
- make_fd_nonblock(fd2);
return init_sock(rb_obj_alloc(klass), fd2);
}
@@ -1542,7 +1523,7 @@ static VALUE
tcp_accept(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct sockaddr_storage from;
socklen_t fromlen;
@@ -1565,7 +1546,7 @@ tcp_accept(sock)
* serv = TCPServer.new(2202)
* begin
* sock = serv.accept_nonblock
- * rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
+ * rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
* IO.select([serv])
* retry
* end
@@ -1585,7 +1566,7 @@ static VALUE
tcp_accept_nonblock(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct sockaddr_storage from;
socklen_t fromlen;
@@ -1599,7 +1580,7 @@ static VALUE
tcp_sysaccept(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct sockaddr_storage from;
socklen_t fromlen;
@@ -1630,7 +1611,7 @@ init_unixsock(sock, path, server)
{
struct sockaddr_un sockaddr;
int fd, status;
- rb_io_t *fptr;
+ OpenFile *fptr;
SafeStringValue(path);
fd = ruby_socket(AF_UNIX, SOCK_STREAM, 0);
@@ -1682,7 +1663,7 @@ static VALUE
ip_addr(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct sockaddr_storage addr;
socklen_t len = sizeof addr;
@@ -1697,7 +1678,7 @@ static VALUE
ip_peeraddr(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct sockaddr_storage addr;
socklen_t len = sizeof addr;
@@ -1778,7 +1759,7 @@ static VALUE
udp_connect(sock, host, port)
VALUE sock, host, port;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct udp_arg arg;
VALUE ret;
@@ -1796,7 +1777,7 @@ static VALUE
udp_bind(sock, host, port)
VALUE sock, host, port;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct addrinfo *res0, *res;
rb_secure(3);
@@ -1821,7 +1802,7 @@ udp_send(argc, argv, sock)
VALUE sock;
{
VALUE mesg, flags, host, port;
- rb_io_t *fptr;
+ OpenFile *fptr;
FILE *f;
int n;
struct addrinfo *res0, *res;
@@ -1920,7 +1901,7 @@ static VALUE
unix_path(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(sock, fptr);
if (fptr->path == 0) {
@@ -1967,7 +1948,7 @@ unix_send_io(sock, val)
{
#if defined(HAVE_SENDMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS)
int fd;
- rb_io_t *fptr;
+ OpenFile *fptr;
struct msghdr msg;
struct iovec vec[1];
char buf[1];
@@ -1975,12 +1956,12 @@ unix_send_io(sock, val)
#if FD_PASSING_BY_MSG_CONTROL
struct {
struct cmsghdr hdr;
- char pad[8+sizeof(int)+8];
+ int fd;
} cmsg;
#endif
if (rb_obj_is_kind_of(val, rb_cIO)) {
- rb_io_t *valfptr;
+ OpenFile *valfptr;
GetOpenFile(val, valfptr);
fd = fileno(valfptr->f);
}
@@ -2005,13 +1986,12 @@ unix_send_io(sock, val)
#if FD_PASSING_BY_MSG_CONTROL
msg.msg_control = (caddr_t)&cmsg;
- msg.msg_controllen = CMSG_LEN(sizeof(int));
+ msg.msg_controllen = CMSG_SPACE(sizeof(int));
msg.msg_flags = 0;
- MEMZERO((char*)&cmsg, char, sizeof(cmsg));
cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int));
cmsg.hdr.cmsg_level = SOL_SOCKET;
cmsg.hdr.cmsg_type = SCM_RIGHTS;
- *(int *)CMSG_DATA(&cmsg.hdr) = fd;
+ cmsg.fd = fd;
#else
msg.msg_accrights = (caddr_t)&fd;
msg.msg_accrightslen = sizeof(fd);
@@ -2048,7 +2028,7 @@ unix_recv_io(argc, argv, sock)
{
#if defined(HAVE_RECVMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS)
VALUE klass, mode;
- rb_io_t *fptr;
+ OpenFile *fptr;
struct msghdr msg;
struct iovec vec[2];
char buf[1];
@@ -2057,7 +2037,7 @@ unix_recv_io(argc, argv, sock)
#if FD_PASSING_BY_MSG_CONTROL
struct {
struct cmsghdr hdr;
- char pad[8+sizeof(int)+8];
+ int fd;
} cmsg;
#endif
@@ -2086,7 +2066,7 @@ unix_recv_io(argc, argv, sock)
cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int));
cmsg.hdr.cmsg_level = SOL_SOCKET;
cmsg.hdr.cmsg_type = SCM_RIGHTS;
- *(int *)CMSG_DATA(&cmsg.hdr) = -1;
+ cmsg.fd = -1;
#else
msg.msg_accrights = (caddr_t)&fd;
msg.msg_accrightslen = sizeof(fd);
@@ -2099,22 +2079,22 @@ unix_recv_io(argc, argv, sock)
#if FD_PASSING_BY_MSG_CONTROL
if (msg.msg_controllen != CMSG_SPACE(sizeof(int))) {
rb_raise(rb_eSocket,
- "file descriptor was not passed (msg_controllen=%d, %d expected)",
+ "file descriptor was not passed (msg_controllen : %d != %d)",
msg.msg_controllen, CMSG_SPACE(sizeof(int)));
}
- if (cmsg.hdr.cmsg_len != CMSG_LEN(sizeof(int))) {
+ if (cmsg.hdr.cmsg_len != CMSG_SPACE(0) + sizeof(int)) {
rb_raise(rb_eSocket,
- "file descriptor was not passed (cmsg_len=%d, %d expected)",
- cmsg.hdr.cmsg_len, CMSG_LEN(sizeof(int)));
+ "file descriptor was not passed (cmsg_len : %d != %d)",
+ cmsg.hdr.cmsg_len, CMSG_SPACE(0) + sizeof(int));
}
if (cmsg.hdr.cmsg_level != SOL_SOCKET) {
rb_raise(rb_eSocket,
- "file descriptor was not passed (cmsg_level=%d, %d expected)",
+ "file descriptor was not passed (cmsg_level : %d != %d)",
cmsg.hdr.cmsg_level, SOL_SOCKET);
}
if (cmsg.hdr.cmsg_type != SCM_RIGHTS) {
rb_raise(rb_eSocket,
- "file descriptor was not passed (cmsg_type=%d, %d expected)",
+ "file descriptor was not passed (cmsg_type : %d != %d)",
cmsg.hdr.cmsg_type, SCM_RIGHTS);
}
#else
@@ -2126,7 +2106,7 @@ unix_recv_io(argc, argv, sock)
#endif
#if FD_PASSING_BY_MSG_CONTROL
- fd = *(int *)CMSG_DATA(&cmsg.hdr);
+ fd = cmsg.fd;
#endif
if (klass == Qnil)
@@ -2152,7 +2132,7 @@ static VALUE
unix_accept(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct sockaddr_un from;
socklen_t fromlen;
@@ -2175,7 +2155,7 @@ unix_accept(sock)
* serv = UNIXServer.new("/tmp/sock")
* begin
* sock = serv.accept_nonblock
- * rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
+ * rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
* IO.select([serv])
* retry
* end
@@ -2195,7 +2175,7 @@ static VALUE
unix_accept_nonblock(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct sockaddr_un from;
socklen_t fromlen;
@@ -2209,7 +2189,7 @@ static VALUE
unix_sysaccept(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct sockaddr_un from;
socklen_t fromlen;
@@ -2231,7 +2211,7 @@ static VALUE
unix_addr(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct sockaddr_un addr;
socklen_t len = sizeof addr;
@@ -2246,7 +2226,7 @@ static VALUE
unix_peeraddr(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct sockaddr_un addr;
socklen_t len = sizeof addr;
@@ -2526,7 +2506,7 @@ static VALUE
sock_connect(sock, addr)
VALUE sock, addr;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
int fd;
StringValue(addr);
@@ -2582,7 +2562,7 @@ static VALUE
sock_connect_nonblock(sock, addr)
VALUE sock, addr;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
int n;
StringValue(addr);
@@ -2680,7 +2660,7 @@ static VALUE
sock_bind(sock, addr)
VALUE sock, addr;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
StringValue(addr);
GetOpenFile(sock, fptr);
@@ -2764,7 +2744,7 @@ static VALUE
sock_listen(sock, log)
VALUE sock, log;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
int backlog;
rb_secure(4);
@@ -2921,7 +2901,7 @@ sock_recvfrom(argc, argv, sock)
* client, client_sockaddr = socket.accept
* begin
* pair = client.recvfrom_nonblock(20)
- * rescue Errno::EAGAIN, Errno::EWOULDBLOCK
+ * rescue Errno::EAGAIN
* IO.select([client])
* retry
* end
@@ -3040,7 +3020,7 @@ static VALUE
sock_accept(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
VALUE sock2;
char buf[1024];
socklen_t len = sizeof buf;
@@ -3072,7 +3052,7 @@ sock_accept(sock)
* socket.listen(5)
* begin
* client_socket, client_sockaddr = socket.accept_nonblock
- * rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
+ * rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
* IO.select([socket])
* retry
* end
@@ -3103,7 +3083,7 @@ static VALUE
sock_accept_nonblock(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
VALUE sock2;
char buf[1024];
socklen_t len = sizeof buf;
@@ -3156,7 +3136,7 @@ static VALUE
sock_sysaccept(sock)
VALUE sock;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
VALUE sock2;
char buf[1024];
socklen_t len = sizeof buf;
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 537fc19a4e..a64aaf837c 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -14,7 +14,6 @@
#include "ruby.h"
#include "rubyio.h"
-#include "re.h"
#if defined(HAVE_FCNTL_H) || defined(_WIN32)
#include <fcntl.h>
#elif defined(HAVE_SYS_FCNTL_H)
@@ -137,7 +136,6 @@ check_modifiable(ptr)
static VALUE strio_s_allocate _((VALUE));
static VALUE strio_s_open _((int, VALUE *, VALUE));
-static void strio_init _((int, VALUE *, struct StringIO *));
static VALUE strio_initialize _((int, VALUE *, VALUE));
static VALUE strio_finalize _((VALUE));
static VALUE strio_self _((VALUE));
@@ -163,7 +161,6 @@ static VALUE strio_rewind _((VALUE));
static VALUE strio_seek _((int, VALUE *, VALUE));
static VALUE strio_get_sync _((VALUE));
static VALUE strio_each_byte _((VALUE));
-static VALUE strio_each_char _((VALUE));
static VALUE strio_getc _((VALUE));
static VALUE strio_ungetc _((VALUE, VALUE));
static VALUE strio_readchar _((VALUE));
@@ -220,24 +217,13 @@ strio_initialize(argc, argv, self)
VALUE self;
{
struct StringIO *ptr = check_strio(self);
+ VALUE string, mode;
+ int trunc = Qfalse;
if (!ptr) {
DATA_PTR(self) = ptr = strio_alloc();
}
rb_call_super(0, 0);
- strio_init(argc, argv, ptr);
- return self;
-}
-
-static void
-strio_init(argc, argv, ptr)
- int argc;
- VALUE *argv;
- struct StringIO *ptr;
-{
- VALUE string, mode;
- int trunc = Qfalse;
-
switch (rb_scan_args(argc, argv, "02", &string, &mode)) {
case 2:
if (FIXNUM_P(mode)) {
@@ -269,6 +255,7 @@ strio_init(argc, argv, ptr)
break;
}
ptr->string = string;
+ return self;
}
static VALUE
@@ -583,8 +570,7 @@ strio_reopen(argc, argv, self)
if (argc == 1 && TYPE(*argv) != T_STRING) {
return strio_copy(self, *argv);
}
- strio_init(argc, argv, StringIO(self));
- return self;
+ return strio_initialize(argc, argv, self);
}
/*
@@ -659,9 +645,6 @@ strio_seek(argc, argv, self)
rb_scan_args(argc, argv, "11", NULL, &whence);
offset = NUM2LONG(argv[0]);
- if (CLOSED(ptr)) {
- rb_raise(rb_eIOError, "closed stream");
- }
switch (NIL_P(whence) ? 0 : NUM2LONG(whence)) {
case 0:
break;
@@ -672,7 +655,7 @@ strio_seek(argc, argv, self)
offset += RSTRING(ptr->string)->len;
break;
default:
- error_inval("invalid whence");
+ rb_raise(rb_eArgError, "invalid whence %ld", NUM2LONG(whence));
}
if (offset < 0) {
error_inval(0);
@@ -712,14 +695,11 @@ strio_each_byte(self)
VALUE self;
{
struct StringIO *ptr = readable(StringIO(self));
-
- RETURN_ENUMERATOR(self, 0, 0);
-
- while (ptr->pos < RSTRING_LEN(ptr->string)) {
- char c = RSTRING_PTR(ptr->string)[ptr->pos++];
+ while (ptr->pos < RSTRING(ptr->string)->len) {
+ char c = RSTRING(ptr->string)->ptr[ptr->pos++];
rb_yield(CHR2FIX(c));
}
- return self;
+ return Qnil;
}
/*
@@ -808,41 +788,6 @@ strio_readchar(self)
return c;
}
-/*
- * call-seq:
- * strio.each_char {|char| block } -> strio
- *
- * See IO#each_char.
- */
-static VALUE
-strio_each_char(self)
- VALUE self;
-{
- struct StringIO *sio;
- VALUE str;
- const char *ptr;
- size_t len;
-
- RETURN_ENUMERATOR(self, 0, 0);
-
- sio = readable(StringIO(self));
- str = sio->string;
- ptr = RSTRING_PTR(str);
- len = RSTRING_LEN(str);
-
- while (sio->pos < len) {
- int pos = sio->pos;
- char c = ptr[pos];
- int n = mbclen(c);
-
- if (len < pos + n) n = len - pos;
-
- sio->pos += n;
- rb_yield(rb_str_substr(str, pos, n));
- }
- return self;
-}
-
static void
bm_init_skip(skip, pat, m)
long *skip;
@@ -990,7 +935,7 @@ strio_readline(argc, argv, self)
VALUE *argv;
VALUE self;
{
- VALUE line = strio_gets(argc, argv, self);
+ VALUE line = strio_getline(argc, argv, readable(StringIO(self)));
if (NIL_P(line)) rb_eof_error();
return line;
}
@@ -1011,8 +956,6 @@ strio_each(argc, argv, self)
struct StringIO *ptr = StringIO(self);
VALUE line;
- RETURN_ENUMERATOR(self, argc, argv);
-
while (!NIL_P(line = strio_getline(argc, argv, readable(ptr)))) {
rb_yield(line);
}
@@ -1336,17 +1279,11 @@ Init_stringio()
rb_define_method(StringIO, "path", strio_path, 0);
rb_define_method(StringIO, "each", strio_each, -1);
- rb_define_method(StringIO, "each_line", strio_each, -1);
- rb_define_method(StringIO, "lines", strio_each, -1);
rb_define_method(StringIO, "each_byte", strio_each_byte, 0);
- rb_define_method(StringIO, "bytes", strio_each_byte, 0);
- rb_define_method(StringIO, "each_char", strio_each_char, 0);
- rb_define_method(StringIO, "chars", strio_each_char, 0);
+ rb_define_method(StringIO, "each_line", strio_each, -1);
rb_define_method(StringIO, "getc", strio_getc, 0);
- rb_define_method(StringIO, "getbyte", strio_getc, 0);
rb_define_method(StringIO, "ungetc", strio_ungetc, 1);
rb_define_method(StringIO, "readchar", strio_readchar, 0);
- rb_define_method(StringIO, "readbyte", strio_readchar, 0);
rb_define_method(StringIO, "gets", strio_gets, -1);
rb_define_method(StringIO, "readline", strio_readline, -1);
rb_define_method(StringIO, "readlines", strio_readlines, -1);
diff --git a/ext/syck/rubyext.c b/ext/syck/rubyext.c
index 76e8279601..078de4f78d 100644
--- a/ext/syck/rubyext.c
+++ b/ext/syck/rubyext.c
@@ -268,13 +268,9 @@ rb_syck_mktime(str, len)
{
char padded[] = "000000";
char *end = ptr + 1;
- char *p = end;
while ( isdigit( *end ) ) end++;
- if (end - p < sizeof(padded)) {
- MEMCPY(padded, ptr + 1, char, end - (ptr + 1));
- p = padded;
- }
- usec = strtol(p, NULL, 10);
+ MEMCPY(padded, ptr + 1, char, end - (ptr + 1));
+ usec = strtol(padded, NULL, 10);
}
else
{
@@ -917,6 +913,7 @@ static VALUE
syck_resolver_initialize( self )
VALUE self;
{
+ VALUE tags = rb_hash_new();
rb_ivar_set(self, s_tags, rb_hash_new());
return self;
}
@@ -951,6 +948,7 @@ VALUE
syck_resolver_detect_implicit( self, val )
VALUE self, val;
{
+ char *type_id;
return rb_str_new2( "" );
}
@@ -1306,6 +1304,7 @@ syck_genericresolver_node_import( self, node )
break;
case syck_seq_kind:
+ rb_iv_set(obj, "@kind", sym_seq);
v = rb_ary_new2( syck_seq_count( n ) );
for ( i = 0; i < syck_seq_count( n ); i++ )
{
@@ -1316,10 +1315,10 @@ syck_genericresolver_node_import( self, node )
style = sym_inline;
}
obj = rb_funcall( cSeq, s_new, 3, t, v, style );
- rb_iv_set(obj, "@kind", sym_seq);
break;
case syck_map_kind:
+ rb_iv_set(obj, "@kind", sym_map);
v = rb_hash_new();
for ( i = 0; i < syck_map_count( n ); i++ )
{
@@ -1330,7 +1329,6 @@ syck_genericresolver_node_import( self, node )
style = sym_inline;
}
obj = rb_funcall( cMap, s_new, 3, t, v, style );
- rb_iv_set(obj, "@kind", sym_map);
break;
}
@@ -2026,6 +2024,7 @@ syck_emitter_emit( argc, argv, self )
VALUE self;
{
VALUE oid, proc;
+ char *anchor_name;
SyckEmitter *emitter;
struct emitter_xtra *bonus;
SYMID symple;
@@ -2281,6 +2280,7 @@ Init_syck()
*/
cScalar = rb_define_class_under( rb_syck, "Scalar", cNode );
rb_define_alloc_func( cScalar, syck_scalar_alloc );
+ rb_define_attr( cNode, "value", 1, 0 );
rb_define_method( cScalar, "initialize", syck_scalar_initialize, 3 );
rb_define_method( cScalar, "value=", syck_scalar_value_set, 1 );
rb_define_method( cScalar, "style=", syck_scalar_style_set, 1 );
diff --git a/ext/syslog/syslog.c b/ext/syslog/syslog.c
index ecc49318f7..477489ddfe 100644
--- a/ext/syslog/syslog.c
+++ b/ext/syslog/syslog.c
@@ -22,7 +22,6 @@ static void syslog_write(int pri, int argc, VALUE *argv)
{
VALUE str;
- rb_secure(4);
if (argc < 1) {
rb_raise(rb_eArgError, "no log message supplied");
}
@@ -39,7 +38,6 @@ static void syslog_write(int pri, int argc, VALUE *argv)
/* Syslog module methods */
static VALUE mSyslog_close(VALUE self)
{
- rb_secure(4);
if (!syslog_opened) {
rb_raise(rb_eRuntimeError, "syslog not opened");
}
@@ -134,7 +132,6 @@ static VALUE mSyslog_get_mask(VALUE self)
static VALUE mSyslog_set_mask(VALUE self, VALUE mask)
{
- rb_secure(4);
if (!syslog_opened) {
rb_raise(rb_eRuntimeError, "must open syslog before setting log mask");
}
diff --git a/ext/syslog/syslog.txt b/ext/syslog/syslog.txt
index 35bd4cb057..9aed35133d 100644
--- a/ext/syslog/syslog.txt
+++ b/ext/syslog/syslog.txt
@@ -7,10 +7,7 @@ Amos Gouaux, University of Texas at Dallas
<amos+ruby@utdallas.edu>
&
Akinori MUSHA
-<knu@iDaemons.org>
-
-Contact:
- - Akinori MUSHA <knu@iDaemons.org> (current maintainer)
+<knu@ruby-lang.org>
** Syslog(Module)
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index 68f172220a..43dfc348ed 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -12,6 +12,9 @@
#include <ruby.h>
#include <intern.h>
#include <rubysig.h>
+#include <node.h>
+
+enum rb_thread_status rb_thread_status _((VALUE));
static VALUE rb_cMutex;
static VALUE rb_cConditionVariable;
@@ -21,12 +24,11 @@ static VALUE rb_cSizedQueue;
static VALUE set_critical(VALUE value);
static VALUE
-thread_exclusive(VALUE (*func)(ANYARGS), VALUE arg)
+thread_exclusive_do(void)
{
- VALUE critical = rb_thread_critical;
-
rb_thread_critical = 1;
- return rb_ensure(func, arg, set_critical, (VALUE)critical);
+
+ return rb_yield(Qundef);
}
/*
@@ -41,7 +43,7 @@ thread_exclusive(VALUE (*func)(ANYARGS), VALUE arg)
static VALUE
rb_thread_exclusive(void)
{
- return thread_exclusive(rb_yield, Qundef);
+ return rb_ensure(thread_exclusive_do, Qundef, set_critical, rb_thread_critical);
}
typedef struct _Entry {
@@ -145,7 +147,7 @@ shift_list(List *list)
VALUE value;
entry = list->entries;
- if (!entry) return Qnil;
+ if (!entry) return Qundef;
list->entries = entry->next;
if (entry == list->last_entry) {
@@ -227,7 +229,9 @@ wake_one(List *list)
waking = Qnil;
while (list->entries && !RTEST(waking)) {
- waking = wake_thread(shift_list(list));
+ waking = shift_list(list);
+ if (waking == Qundef) break;
+ waking = wake_thread(waking);
}
return waking;
@@ -258,19 +262,27 @@ wait_list_cleanup(List *list)
return Qnil;
}
-static VALUE
+static void
wait_list(List *list)
{
- return rb_ensure(wait_list_inner, (VALUE)list, wait_list_cleanup, (VALUE)list);
+ rb_ensure(wait_list_inner, (VALUE)list, wait_list_cleanup, (VALUE)list);
}
static void
-kill_waiting_threads(List *waiting)
+assert_no_survivors(List *waiting, const char *label, void *addr)
{
Entry *entry;
+ VALUE ths = 0;
for (entry = waiting->entries; entry; entry = entry->next) {
- rb_thread_kill(entry->value);
+ if (RTEST(wake_thread(entry->value))) {
+ if (!ths) ths = rb_ary_new();
+ rb_ary_push(ths, entry->value);
+ }
+ }
+ if (ths) {
+ rb_bug("%s %p freed with live thread(s) %s waiting",
+ label, addr, RSTRING_PTR(rb_inspect(ths)));
}
}
@@ -322,7 +334,7 @@ finalize_mutex(Mutex *mutex)
static void
free_mutex(Mutex *mutex)
{
- kill_waiting_threads(&mutex->waiting);
+ assert_no_survivors(&mutex->waiting, "mutex", mutex);
finalize_mutex(mutex);
xfree(mutex);
}
@@ -410,8 +422,9 @@ lock_mutex(Mutex *mutex)
mutex->owner = current;
}
else {
+ push_list(&mutex->waiting, current);
do {
- wait_list(&mutex->waiting);
+ rb_thread_stop();
rb_thread_critical = 1;
if (!MUTEX_LOCKED_P(mutex)) {
mutex->owner = current;
@@ -433,6 +446,22 @@ rb_mutex_lock(VALUE self)
return self;
}
+static VALUE
+relock_mutex(Mutex *mutex)
+{
+ VALUE current = rb_thread_current();
+
+ switch (rb_thread_status(current)) {
+ case THREAD_RUNNABLE:
+ case THREAD_STOPPED:
+ lock_mutex(mutex);
+ break;
+ default:
+ break;
+ }
+ return Qundef;
+}
+
/*
* Document-method: unlock
*
@@ -465,8 +494,10 @@ set_critical(VALUE value)
static VALUE
unlock_mutex(Mutex *mutex)
{
- VALUE waking = thread_exclusive(unlock_mutex_inner, (VALUE)mutex);
+ VALUE waking;
+ rb_thread_critical = 1;
+ waking = rb_ensure(unlock_mutex_inner, (VALUE)mutex, set_critical, 0);
if (!RTEST(waking)) {
return Qfalse;
}
@@ -514,9 +545,10 @@ rb_mutex_exclusive_unlock(VALUE self)
VALUE waking;
Data_Get_Struct(self, Mutex, mutex);
- waking = thread_exclusive(rb_mutex_exclusive_unlock_inner, (VALUE)mutex);
+ rb_thread_critical = 1;
+ waking = rb_ensure(rb_mutex_exclusive_unlock_inner, (VALUE)mutex, set_critical, 0);
- if (!RTEST(waking)) {
+ if (waking == Qundef || !RTEST(waking)) {
return Qnil;
}
@@ -591,7 +623,7 @@ finalize_condvar(ConditionVariable *condvar)
static void
free_condvar(ConditionVariable *condvar)
{
- kill_waiting_threads(&condvar->waiting);
+ assert_no_survivors(&condvar->waiting, "condition variable", condvar);
finalize_condvar(condvar);
xfree(condvar);
}
@@ -643,7 +675,7 @@ wait_condvar(ConditionVariable *condvar, Mutex *mutex)
if (RTEST(waking)) {
wake_thread(waking);
}
- rb_ensure(wait_list, (VALUE)&condvar->waiting, lock_mutex, (VALUE)mutex);
+ rb_ensure(wait_list, (VALUE)&condvar->waiting, relock_mutex, (VALUE)mutex);
}
static VALUE
@@ -701,7 +733,8 @@ rb_condvar_broadcast(VALUE self)
Data_Get_Struct(self, ConditionVariable, condvar);
- thread_exclusive(wake_all, (VALUE)&condvar->waiting);
+ rb_thread_critical = 1;
+ rb_ensure(wake_all, (VALUE)&condvar->waiting, set_critical, 0);
rb_thread_schedule();
return self;
@@ -718,8 +751,9 @@ rb_condvar_broadcast(VALUE self)
static void
signal_condvar(ConditionVariable *condvar)
{
- VALUE waking = thread_exclusive(wake_one, (VALUE)&condvar->waiting);
-
+ VALUE waking;
+ rb_thread_critical = 1;
+ waking = rb_ensure(wake_one, (VALUE)&condvar->waiting, set_critical, 0);
if (RTEST(waking)) {
run_thread(waking);
}
@@ -794,9 +828,9 @@ finalize_queue(Queue *queue)
static void
free_queue(Queue *queue)
{
- kill_waiting_threads(&queue->mutex.waiting);
- kill_waiting_threads(&queue->space_available.waiting);
- kill_waiting_threads(&queue->value_available.waiting);
+ assert_no_survivors(&queue->mutex.waiting, "queue", queue);
+ assert_no_survivors(&queue->space_available.waiting, "queue", queue);
+ assert_no_survivors(&queue->value_available.waiting, "queue", queue);
finalize_queue(queue);
xfree(queue);
}
diff --git a/ext/tk/ChangeLog.tkextlib b/ext/tk/ChangeLog.tkextlib
index 8c5d01a954..359b466a32 100644
--- a/ext/tk/ChangeLog.tkextlib
+++ b/ext/tk/ChangeLog.tkextlib
@@ -1,9 +1,3 @@
-2008-05-12 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tkextlib/tkDND/shape.rb: wrong package name.
-
---------------< ... some changes ... >------------------
-
2007-05-26 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib/tcllib/tablelist.rb: fix typo.
diff --git a/ext/tk/MANUAL_tcltklib.eng b/ext/tk/MANUAL_tcltklib.eng
index 6fa775b7de..1db61f228e 100644
--- a/ext/tk/MANUAL_tcltklib.eng
+++ b/ext/tk/MANUAL_tcltklib.eng
@@ -125,24 +125,7 @@ module TclTklib
: Tcl7.6 doesn't have this flag. So PARSE_VARNAME is
: defined as 0.
- module TclTkLib::RELEASE_TYPE
- : Defines release type number of Tcl/Tk
-
- ALPHA
- : ALPHA release
-
- BETA
- : BETA release
-
- FINAL
- : FINAL release
-
[module methods]
- get_version()
- : return an array of major, minor, release-type number,
- : number, release-type name, and patchlevel of current
- : Tcl/Tk library.
-
mainloop(check_root = true)
: Starts the eventloop. If 'check_root' is true, this method
: doesn't return when a root widget exists.
@@ -448,10 +431,6 @@ class TclTkIp
: slave interpreter, same to the TclTkLib module method with
: the same name.
- encoding_table
- : For Ruby m17n. Return encoding relation table between Ruby's
- : Encoding object and Tcl's encoding name.
-
class TkCallbackBreak < StandardError
class TkCallbackContinue < StandardError
: They are exception classes to break or continue the Tk callback
@@ -462,8 +441,5 @@ class TkCallbackContinue < StandardError
: If raise TkCallbackContinue, returns 'continue' code (Then the Tk
: interpreter will break the operateion for the current bindtag and
: starts the operation for the next buindtag for the current event).
- : However, current tcltklib supports Ruby's 'break' and 'next' to
- : get the same effect. That is, those classes are obsolete. Those
- : exist for backward compatibility.
(eof)
diff --git a/ext/tk/MANUAL_tcltklib.eucj b/ext/tk/MANUAL_tcltklib.eucj
index 7df42997b4..5dd36726ba 100644
--- a/ext/tk/MANUAL_tcltklib.eucj
+++ b/ext/tk/MANUAL_tcltklib.eucj
@@ -221,23 +221,7 @@ require "tcltklib" ¤¹¤ë¤È, °Ê²¼¤Î¥â¥¸¥å¡¼¥ë, ¥¯¥é¥¹¤¬ÍøÍѲÄǽ¤Ç¤¹.
: ¤«¤éÃê½Ð¤µ¤ì¤ë¤Ï¤º¤Ç¤¢¤ë¤«¤é¡¤index_name °ú¿ô¤Ï nil ¤È
: ¤»¤Í¤Ð¤Ê¤é¤Ê¤¤¡¥
- ¥â¥¸¥å¡¼¥ë TclTkLib::RELEASE_TYPE
- : Tcl/Tk ¤Î¥ê¥ê¡¼¥¹¥¿¥¤¥×ÈÖ¹æ¤ÎÄêµÁ
-
- Äê¿ô ALPHA
- : ALPHA ¥ê¥ê¡¼¥¹
-
- Äê¿ô BETA
- : BETA ¥ê¥ê¡¼¥¹
-
- Äê¿ô FINAL
- : FINAL ¥ê¥ê¡¼¥¹
-
¥â¥¸¥å¡¼¥ë¥á¥½¥Ã¥É
- get_version()
- : Tcl/Tk ¤Î major, minor, release-type ÈÖ¹æ, release-type ̾,
- : patchlevel ¤òÇÛÎó¤Ë¤·¤ÆÊÖ¤¹¡¥
-
mainloop(check_root = true)
: ¥¤¥Ù¥ó¥È¥ë¡¼¥×¤òµ¯Æ°¤¹¤ë¡¥check_root ¤¬ true ¤Ç¤¢¤ì¤Ð¡¤
: root widget ¤¬Â¸ºß¤¹¤ë¸Â¤ê¡¤¤³¤Î¥á¥½¥Ã¥É¤Ï½ªÎ»¤·¤Ê¤¤¡¥
@@ -559,9 +543,6 @@ require "tcltklib" ¤¹¤ë¤È, °Ê²¼¤Î¥â¥¸¥å¡¼¥ë, ¥¯¥é¥¹¤¬ÍøÍѲÄǽ¤Ç¤¹.
: ¥¹¥ì¡¼¥Ö IP ¤Î¾ì¹ç¤Ë¤ÏÃͤÎÀßÄ꤬µö¤µ¤ì¤Ê¤¤ (̵»ë¤µ¤ì¤ë)¡¥
: ¤½¤ì°Ê³°¤ÎÅÀ¤Ç¤Ï°ú¿ô¤ò´Þ¤á¤Æ TclTkLib ¤ÎƱ̾¥á¥½¥Ã¥É¤ËƱ¤¸¡¥
- encoding_table
- : Ruby m17n ÍÑ¤Ë Ruby ¤È Tk ¤È¤Î´Ö¤Î encoding Âбþɽ¤òÊÖ¤¹¡¥
-
¥¯¥é¥¹ TkCallbackBreak < StandardError
¥¯¥é¥¹ TkCallbackContinue < StandardError
: ¤³¤ì¤é¤Ï¥¤¥Ù¥ó¥È¥³¡¼¥ë¥Ð¥Ã¥¯¤Ë¤ª¤¤¤Æ¡¤¥³¡¼¥ë¥Ð¥Ã¥¯½èÍý¤òŬÀÚ¤ËÃæ
@@ -572,8 +553,5 @@ require "tcltklib" ¤¹¤ë¤È, °Ê²¼¤Î¥â¥¸¥å¡¼¥ë, ¥¯¥é¥¹¤¬ÍøÍѲÄǽ¤Ç¤¹.
: ¥É¤òÊÖ¤¹É¬Íפ¬¤¢¤ë¡¥Ruby ¤Î¼ê³¤­¤¬ÉáÄ̤ËÃͤòÊÖ¤¹¤Î¤Ç¤Ï¡¤¤½¤ì¤¬Éá
: Ä̤ÎÌá¤êÃͤǤ¢¤ë¤Î¤«Èݤ«¤ò¶èÊ̤¬¤Ç¤­¤Ê¤¤¤¿¤á¡¤Î㳰ȯÀ¸¤òÍøÍѤ·¤¿
: ¼ÂÁõ¤ò¹Ô¤Ã¤Æ¤¤¤ë¡¥
- : ¤¿¤À¤·¸½ºß¤Ç¤Ï¡¤¥³¡¼¥ë¥Ð¥Ã¥¯¼ê³¤­¤ò Ruby ¤Î break, next ¤Ç½ªÎ»¤¹
- : ¤ë¤³¤È¤ÇƱÅù¤Î·ë²Ì¤òÆÀ¤ë¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡¥¤½¤ì¤æ¤¨¡¤
- : ¤³¤ì¤é¤ÏɬÍפʤ¤¤â¤Î¤Ç¤Ï¤¢¤ë¤¬¡¤¸ß´¹À­¤Î¤¿¤á¤Ë»Ä¤·¤Æ¤¢¤ë¡¥
(eof)
diff --git a/ext/tk/README.1st b/ext/tk/README.1st
index fce5b0242b..df6c819d26 100644
--- a/ext/tk/README.1st
+++ b/ext/tk/README.1st
@@ -1,6 +1,7 @@
If you want to use Ruby/Tk (tk.rb and so on), you must have tcltklib.so
-which is working correctly. When you have some troubles on compiling,
-please read README.tcltklib and README.ActiveTcl.
+which is working correctly. If you fail to call 'require "tcltklib"',
+you may not have tcltklib.so. When you have some troubles on compiling
+tcltklib, please read README files on tcltklib.
Even if there is a tcltklib.so on your Ruby library directry, it will not
work without Tcl/Tk libraries (e.g. libtcl8.4.so) on your environment.
You must also check that your Tcl/Tk is installed properly.
@@ -8,9 +9,11 @@ You must also check that your Tcl/Tk is installed properly.
--------------------------------------------
( the following is written in EUC-JP )
-Ruby/Tk (tk.rb ¤Ê¤É) ¤ò»È¤¤¤¿¤¤¾ì¹ç¤Ë¤Ï¡¤tcltklib.so ¤¬Àµ¤·¤¯Æ°¤¤¤Æ¤¤¤Ê
-¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡¥¥³¥ó¥Ñ¥¤¥ë»þ¤Ë²¿¤«ÌäÂ꤬À¸¤¸¤¿¾ì¹ç¤Ï¡¤README.tcltklib
-¤ä README.ActiveTcl ¤ò¸«¤Æ¤¯¤À¤µ¤¤¡¥
+Ruby/Tk (tk.rb ¤Ê¤É) ¤ò»È¤¤¤¿¤¤¾ì¹ç¤Ë¤Ï¡¤tcltklib.so ¤¬Àµ¤·¤¯Æ°¤¤¤Æ
+¤¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡¥¤â¤· 'require "tcltklib"' ¤Ë¼ºÇÔ¤¹¤ë¤è¤¦¤Ê¤é¡¤
+tcltklib.so ¤¬¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Æ¤¤¤Ê¤¤¤Î¤«¤â¤·¤ì¤Þ¤»¤ó¡¥tcltklib ¤Î
+¥³¥ó¥Ñ¥¤¥ë»þ¤Ë²¿¤«ÌäÂ꤬À¸¤¸¤Æ¤¤¤ë¾ì¹ç¤Ï¡¤tcltklib ¤Î README ¥Õ¥¡¥¤¥ë
+¤ò¸«¤Æ¤¯¤À¤µ¤¤¡¥
¤¿¤È¤¨ Ruby ¤Î¥é¥¤¥Ö¥é¥ê¥Ç¥£¥ì¥¯¥È¥ê¤Ë tcltklib.so ¤¬Â¸ºß¤·¤Æ¤¤¤¿¤È¤·¤Æ
¤â¡¤¼Â¹Ô´Ä¶­¤Ë Tcl/Tk ¥é¥¤¥Ö¥é¥ê (libtcl8.4.so ¤Ê¤É) ¤¬¤Ê¤±¤ì¤Ðµ¡Ç½¤·¤Þ
¤»¤ó¡¥Tcl/Tk ¤¬Àµ¤·¤¯¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Æ¤¤¤ë¤«¤â¥Á¥§¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡¥
diff --git a/ext/tk/README.tcltklib b/ext/tk/README.tcltklib
index 8c6dd5178f..e939ba1f51 100644
--- a/ext/tk/README.tcltklib
+++ b/ext/tk/README.tcltklib
@@ -5,14 +5,10 @@ Tcl/Tk libraries or header files are installed but are not found, you can
give the information by arguments of the 'configure' script. Please give
some or all of the following options.
- --with-tcltkversion=<version>
- force version of Tcl/Tk libaray
- (e.g. libtcl8.4g.so ==> --with-tcltkversion=8.4g)
-
--with-tcllib=<libname> (e.g. libtcl8.4.so ==> --with-tcllib=tcl8.4)
--with-tklib=<libname> (e.g. libtk8.4.so ==> --with-tklib=tk8.4)
- --enable-tcltk-stubs (if you force to enable stubs)
+ --enable-tcltk_stubs (if you force to enable stubs)
--with-tcl-dir=<path>
equal to "--with-tcl-include=<path>/include --with-tcl-lib=<path>/lib"
@@ -20,18 +16,18 @@ some or all of the following options.
--with-tk-dir=<path>
equal to "--with-tk-include=<path>/include --with-tk-lib=<path>/lib"
- --with-tcl-include=<dir> the directry contains 'tcl.h'
- --with-tk-include=<dir> the directry contains 'tk.h'
+ --with-tcl-include=<dir> the directry containts 'tcl.h'
+ --with-tk-include=<dir> the directry containts 'tk.h'
- --with-tcl-lib=<dir> the directry contains 'libtcl<version>.so'
- --with-tk-lib=<dir> the directry contains 'libtk<version>.so'
+ --with-tcl-lib=<dir> the directry containts 'libtcl<version>.so'
+ --with-tk-lib=<dir> the directry containts 'libtk<version>.so'
--enable-mac-tcltk-framework (MacOS X) use Tcl/Tk framework
(Obsolete. Please use '--enable-tcltk-framework'.)
--enable-tcltk-framework use Tcl/Tk framework
- --with-tcltk-framework=<dir> the directory contains Tcl/Tk framework;
+ --with-tcltk-framework=<dir> the directory containts Tcl/Tk framework;
"<dir>/Tcl.framework" and "<dir>/Tk.framework".
When this option is given, it is assumed that
--enable-tcltk-framework option is given also.
@@ -50,8 +46,8 @@ some or all of the following options.
--with-X11-dir=<path>
equal to "--with-X11-include=<path>/include --with-X11-lib=<path>/lib"
- --with-X11-include=<dir> the directry contais X11 header files
- --with-X11-lib=<dir> the directry contais X11 libraries
+ --with-X11-include=<dir> the directry contains X11 header files
+ --with-X11-lib=<dir> the directry contains X11 libraries
If you forgot to give the options when do 'configure' on toplevel
diff --git a/ext/tk/extconf.rb b/ext/tk/extconf.rb
index 4807ea7b40..5ed86a8b76 100644
--- a/ext/tk/extconf.rb
+++ b/ext/tk/extconf.rb
@@ -2,8 +2,7 @@
require 'mkmf'
-#is_win32 = (/mswin32|mingw|cygwin|bccwin32/ =~ RUBY_PLATFORM)
-is_win32 = (/mswin|mingw|cygwin|bccwin|wince/ =~ RUBY_PLATFORM)
+is_win32 = (/mswin32|mingw|cygwin|bccwin32/ =~ RUBY_PLATFORM)
#is_macosx = (/darwin/ =~ RUBY_PLATFORM)
def find_framework(tcl_hdr, tk_hdr)
@@ -40,68 +39,18 @@ unless is_win32
have_library("m", "log")
end
-tk_idir, tk_ldir = dir_config("tk")
-tcl_idir, tcl_ldir = dir_config("tcl")
-x11_idir, x11_ldir = dir_config("X11")
-
-tk_ldir2 = with_config("tk-lib")
-tcl_ldir2 = with_config("tcl-lib")
-x11_ldir2 = with_config("X11-lib")
-
-tk_ldir_list = [tk_ldir2, tk_ldir]
-tcl_ldir_list = [tcl_ldir2, tcl_ldir]
+dir_config("tk")
+dir_config("tcl")
+dir_config("X11")
tklib = with_config("tklib")
tcllib = with_config("tcllib")
stubs = enable_config("tcltk_stubs") || with_config("tcltk_stubs")
-tcltk_version = with_config("tcltkversion")
-
use_X = with_config("X11", (! is_win32))
-def check_tcltk_version(version)
- return [nil, nil] unless version
-
- version = version.strip
-
- tclver = version.dup
- tkver = version.dup
-
- major = dot = minor = dot = plvl = ext = nil
-
- if version =~ /^(\d)(\.?)(\d)(\.?)(\d*)(.*)$/
- major = $1; minor_dot = $2; minor = $3; plvl_dot = $4; plvl = $5; ext = $6
- dot = ! minor_dot.empty?
- if plvl_dot.empty? && ! plvl.empty?
- minor << plvl
- end
- elsif version =~ /^(\d)(\.?)(\d?)(.*)$/
- major = $1; minor_dot = $2; minor = $3; ext = $4
- dot = ! minor_dot.empty?
- else # unknown -> believe user
- return [tclver, tkver]
- end
-
- # check Tcl7.6 / Tk4.2 ?
- if major == "7" # Tcl7.6 ( not support Tclversion < 7.6 )
- # Tk4.2
- tkver = "4" + ((dot)? ".": "") + ((minor.empty)? "": "2") + ext
- elsif major == "4" # Tk4.2 ( not support Tkversion < 4.2 )
- # Tcl7.6
- tclver = "7" + ((dot)? ".": "") + ((minor.empty)? "": "6") + ext
- end
-
- [tclver, tkver]
-end
-
-def find_tcl(tcllib, stubs, version, *opt_paths)
- default_paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
- default_paths << "/Tcl/lib" # default for ActiveTcl
-
- if (paths = opt_paths.compact).empty?
- paths = default_paths
- end
-
+def find_tcl(tcllib, stubs)
+ paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
if stubs
func = "Tcl_InitStubs"
lib = "tclstub"
@@ -109,42 +58,22 @@ def find_tcl(tcllib, stubs, version, *opt_paths)
func = "Tcl_FindExecutable"
lib = "tcl"
end
-
- if version && ! version.empty?
- versions = [version]
- else
- versions = %w[8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6]
- end
-
if tcllib
- st = find_library(tcllib, func, *paths)
+ find_library(tcllib, func, *paths)
+ elsif find_library(lib, func, *paths)
+ true
else
- st = versions.find { |ver|
- find_library("#{lib}#{ver}", func, *paths) or
- find_library("#{lib}#{ver.delete('.')}", func, *paths) or
- find_library("#{lib}#{ver}g", func, *paths) or
- find_library("#{lib}#{ver.delete('.')}g", func, *paths) or
- find_library("tcl#{ver}", func, *paths) or
- find_library("tcl#{ver.delete('.')}", func, *paths) or
- find_library("tcl#{ver}g", func, *paths) or
- find_library("tcl#{ver.delete('.')}g", func, *paths)
- } || (!version && find_library(lib, func, *paths))
- end
-
- unless st
- puts("Warning:: cannot find Tcl library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options.")
+ %w[8.5 8.4 8.3 8.2 8.1 8.0 7.6].find { |ver|
+ find_library("#{lib}#{ver}", func, *paths) or
+ find_library("#{lib}#{ver.delete('.')}", func, *paths) or
+ find_library("tcl#{ver}", func, *paths) or
+ find_library("tcl#{ver.delete('.')}", func, *paths)
+ }
end
- st
end
-def find_tk(tklib, stubs, version, *opt_paths)
- default_paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
- default_paths << "/Tcl/lib" # default for ActiveTcl
-
- if (paths = opt_paths.compact).empty?
- paths = default_paths
- end
-
+def find_tk(tklib, stubs)
+ paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
if stubs
func = "Tk_InitStubs"
lib = "tkstub"
@@ -152,45 +81,20 @@ def find_tk(tklib, stubs, version, *opt_paths)
func = "Tk_Init"
lib = "tk"
end
-
- if version && ! version.empty?
- versions = [version]
- else
- versions = %w[8.6 8.5 8.4 8.3 8.2 8.1 8.0 4.2]
- end
-
if tklib
- st = find_library(tklib, func, *paths)
+ find_library(tklib, func, *paths)
+ elsif find_library(lib, func, *paths)
+ true
else
- st = versions.find { |ver|
- find_library("#{lib}#{ver}", func, *paths) or
- find_library("#{lib}#{ver.delete('.')}", func, *paths) or
- find_library("#{lib}#{ver}g", func, *paths) or
- find_library("#{lib}#{ver.delete('.')}g", func, *paths) or
- find_library("tk#{ver}", func, *paths) or
- find_library("tk#{ver.delete('.')}", func, *paths) or
- find_library("tk#{ver}g", func, *paths) or
- find_library("tk#{ver.delete('.')}g", func, *paths)
- } || (!version && find_library(lib, func, *paths))
- end
-
- unless st
- puts("Warning:: cannot find Tk library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options.")
+ %w[8.5 8.4 8.3 8.2 8.1 8.0 4.2].find { |ver|
+ find_library("#{lib}#{ver}", func, *paths) or
+ find_library("#{lib}#{ver.delete('.')}", func, *paths) or
+ find_library("tk#{ver}", func, *paths) or
+ find_library("tk#{ver.delete('.')}", func, *paths)
+ }
end
- st
end
-def find_X11(*opt_paths)
- default_paths =
- [ "/usr/X11/lib", "/usr/lib/X11", "/usr/X11R6/lib", "/usr/openwin/lib" ]
- paths = opt_paths.compact.concat(default_paths)
- st = find_library("X11", "XOpenDisplay", *paths)
- unless st
- puts("Warning:: cannot find X11 library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options. If your Tcl/Tk don't require X11, please try --without-X11.")
- end
- st
-end
-
def pthread_check()
tcl_major_ver = nil
tcl_minor_ver = nil
@@ -369,13 +273,13 @@ EOF
end
end
-tclver, tkver = check_tcltk_version(tcltk_version)
-
-if have_header("tcl.h") && have_header("tk.h") &&
- ( tcltk_framework ||
- ( ( !use_X || find_X11(x11_ldir2, x11_ldir) ) &&
- find_tcl(tcllib, stubs, tclver, *tcl_ldir_list) &&
- find_tk(tklib, stubs, tkver, *tk_ldir_list) ) )
+if tcltk_framework ||
+ (have_header("tcl.h") && have_header("tk.h") &&
+ ( !use_X || find_library("X11", "XOpenDisplay",
+ "/usr/X11/lib", "/usr/lib/X11",
+ "/usr/X11R6/lib", "/usr/openwin/lib")) &&
+ find_tcl(tcllib, stubs) &&
+ find_tk(tklib, stubs))
$CPPFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS' if stubs
$CPPFLAGS += ' -D_WIN32' if /cygwin/ =~ RUBY_PLATFORM
@@ -402,11 +306,7 @@ if have_header("tcl.h") && have_header("tk.h") &&
$INSTALLFILES ||= []
$INSTALLFILES << ["lib/tkextlib/SUPPORT_STATUS", "$(RUBYLIBDIR)", "lib"]
- have_func("rb_hash_lookup", "ruby.h")
-
# create
- $defs << %[-DRUBY_VERSION=\\"#{RUBY_VERSION}\\"]
- $defs << %[-DRUBY_RELEASE_DATE=\\"#{RUBY_RELEASE_DATE}\\"]
create_makefile("tcltklib")
end
end
diff --git a/ext/tk/lib/multi-tk.rb b/ext/tk/lib/multi-tk.rb
index ec718678f0..78ed1aa6ee 100644
--- a/ext/tk/lib/multi-tk.rb
+++ b/ext/tk/lib/multi-tk.rb
@@ -114,14 +114,7 @@ MultiTkIp_OK.freeze
class MultiTkIp
BASE_DIR = File.dirname(__FILE__)
- WITH_RUBY_VM = Object.const_defined?(:VM) && ::VM.class == Class
- WITH_ENCODING = Object.const_defined?(:Encoding) && ::Encoding.class == Class
-
- (@@SLAVE_IP_ID = ['slave'.freeze, '0'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
+ @@SLAVE_IP_ID = ['slave'.freeze, '0'.taint].freeze
@@IP_TABLE = {}.taint unless defined?(@@IP_TABLE)
@@ -133,18 +126,14 @@ class MultiTkIp
unless defined?(@@TK_CMD_TBL)
@@TK_CMD_TBL = Object.new.taint
- # @@TK_CMD_TBL.instance_variable_set('@tbl', {}.taint)
- @@TK_CMD_TBL.instance_variable_set('@tbl', Hash.new{|hash,key|
- fail IndexError,
- "unknown command ID '#{key}'"
- }.taint)
+ @@TK_CMD_TBL.instance_variable_set('@tbl', {}.taint)
class << @@TK_CMD_TBL
allow = [
- '__send__', '__id__', 'freeze', 'inspect', 'kind_of?', 'object_id',
+ '__send__', '__id__', 'freeze', 'inspect', 'kind_of?',
'[]', '[]=', 'delete', 'each', 'has_key?'
]
- instance_methods.each{|m| undef_method(m) unless allow.index(m.to_s)}
+ instance_methods.each{|m| undef_method(m) unless allow.index(m)}
def kind_of?(klass)
@tbl.kind_of?(klass)
@@ -217,7 +206,7 @@ class MultiTkIp
def initialize(ip, cmd)
@ip = ip
@cmd = cmd
- self.freeze
+ freeze
end
attr_reader :ip, :cmd
def inspect
@@ -584,11 +573,7 @@ class MultiTkIp
# raise exception
begin
bt = _toUTF8(e.backtrace.join("\n"))
- if MultiTkIp::WITH_ENCODING
- bt.force_encoding('utf-8')
- else
- bt.instance_variable_set(:@encoding, 'utf-8')
- end
+ bt.instance_variable_set(:@encoding, 'utf-8')
rescue Exception
bt = e.backtrace.join("\n")
end
@@ -710,11 +695,6 @@ class MultiTkIp
######################################
- unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD
- ### Ruby 1.9 !!!!!!!!!!!!!!!!!!!!!!!!!!
- RUN_EVENTLOOP_ON_MAIN_THREAD = false
- end
-
if self.const_defined? :DEFAULT_MASTER_NAME
name = DEFAULT_MASTER_NAME.to_s
else
@@ -743,41 +723,7 @@ class MultiTkIp
fail ArgumentError, "expecting a Hash object for the 2nd argument"
end
- if !WITH_RUBY_VM || RUN_EVENTLOOP_ON_MAIN_THREAD ### check Ruby 1.9 !!!!!!!
- @interp = TclTkIp.new(name, _keys2opts(keys))
- else ### Ruby 1.9 !!!!!!!!!!!
- @interp_thread = Thread.new{
- current = Thread.current
- current[:interp] = interp = TclTkIp.new(name, _keys2opts(keys))
- #sleep
- current[:mutex] = mutex = Mutex.new
- current[:root_check] = cond_var = ConditionVariable.new
-
- begin
- current[:status] = interp.mainloop(true)
- rescue Exception=>e
- current[:status] = e
- ensure
- mutex.synchronize{ cond_var.broadcast }
- end
- current[:status] = interp.mainloop(false)
- }
- until @interp_thread[:interp]
- Thread.pass
- end
- # INTERP_THREAD.run
- @interp = @interp_thread[:interp]
-
- def self.mainloop(check_root = true)
- begin
- TclTkLib.set_eventloop_window_mode(true)
- @interp_thread.value
- ensure
- TclTkLib.set_eventloop_window_mode(false)
- end
- end
- end
-
+ @interp = TclTkIp.new(name, _keys2opts(keys))
@ip_name = nil
@callback_status = [].taint
@@ -907,26 +853,22 @@ class MultiTkIp
Thread.new{
current = Thread.current
loop {
- mtx, cond, ret, table, script = @init_ip_env_queue.deq
- begin
+ mtx, ret, table, script = @init_ip_env_queue.deq
+ begin
ret[0] = table.each{|tg, ip| ip._init_ip_env(script) }
rescue Exception => e
ret[0] = e
ensure
- mtx.synchronize{ cond.signal }
+ mtx.unlock
end
- mtx = cond = ret = table = script = nil # clear variables for GC
}
}
def self.__init_ip_env__(table, script)
ret = []
- mtx = (Thread.current[:MultiTk_ip_Mutex] ||= Mutex.new)
- cond = (Thread.current[:MultiTk_ip_CondVar] ||= ConditionVariable.new)
- mtx.synchronize{
- @init_ip_env_queue.enq([mtx, cond, ret, table, script])
- cond.wait(mtx)
- }
+ mtx = Mutex.new.lock
+ @init_ip_env_queue.enq([mtx, ret, table, script])
+ mtx.lock
if ret[0].kind_of?(Exception)
raise ret[0]
else
@@ -1005,11 +947,9 @@ class MultiTkIp
private :_parse_slaveopts
def _create_slave_ip_name
- @@SLAVE_IP_ID.mutex.synchronize{
- name = @@SLAVE_IP_ID.join('')
- @@SLAVE_IP_ID[1].succ!
- name.freeze
- }
+ name = @@SLAVE_IP_ID.join('')
+ @@SLAVE_IP_ID[1].succ!
+ name.freeze
end
private :_create_slave_ip_name
@@ -1266,20 +1206,7 @@ class MultiTkIp
if safeip == nil
# create master-ip
- unless WITH_RUBY_VM
- @interp = TclTkIp.new(name, _keys2opts(tk_opts))
- else ### Ruby 1.9 !!!!!!!!!!!
- @interp_thread = Thread.new{
- Thread.current[:interp] = interp = TclTkIp.new(name, _keys2opts(tk_opts))
- #sleep
- TclTkLib.mainloop(true)
- }
- until @interp_thread[:interp]
- Thread.pass
- end
- # INTERP_THREAD.run
- @interp = @interp_thread[:interp]
- end
+ @interp = TclTkIp.new(name, _keys2opts(tk_opts))
@ip_name = nil
if safe
@@ -1294,8 +1221,6 @@ class MultiTkIp
@safe_base = true
@interp, @ip_name = master.__create_safe_slave_obj(safe_opts,
name, tk_opts)
- # @interp_thread = nil if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!
- @interp_thread = nil unless WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!!
if safe
safe = master.safe_level if safe < master.safe_level
@safe_level = [safe]
@@ -1304,8 +1229,6 @@ class MultiTkIp
end
else
@interp, @ip_name = master.__create_trusted_slave_obj(name, tk_opts)
- # @interp_thread = nil if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!
- @interp_thread = nil unless WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!!
if safe
safe = master.safe_level if safe < master.safe_level
@safe_level = [safe]
@@ -1340,11 +1263,11 @@ class MultiTkIp
@@DEFAULT_MASTER.assign_receiver_and_watchdog(self)
@@IP_TABLE[@threadgroup] = self
+ _init_ip_internal(@@INIT_IP_ENV, @@ADD_TK_PROCS)
@@TK_TABLE_LIST.size.times{
(tbl = {}).tainted? || tbl.taint
@tk_table_list << tbl
}
- _init_ip_internal(@@INIT_IP_ENV, @@ADD_TK_PROCS)
class << self
undef :instance_eval
@@ -1422,13 +1345,8 @@ class << MultiTkIp
alias __new new
private :__new
- def new_master(safe=nil, keys={})
- if MultiTkIp::WITH_RUBY_VM
- #### TODO !!!!!!
- fail RuntimeError,
- 'sorry, still not support multiple master-interpreters on Ruby VM'
- end
+ def new_master(safe=nil, keys={})
if safe.kind_of?(Hash)
keys = safe
elsif safe.kind_of?(Integer)
@@ -1645,13 +1563,8 @@ class MultiTkIp
return if slave?
names.each{|name|
name = name.to_s
-
- return if @interp.deleted?
@interp._invoke('rename', name, '')
-
- return if @interp.deleted?
@interp._invoke('interp', 'slaves').split.each{|slave|
- return if @interp.deleted?
@interp._invoke('interp', 'alias', slave, name, '') rescue nil
}
}
@@ -1701,16 +1614,11 @@ class MultiTkIp
id = @@TK_TABLE_LIST.size
obj = Object.new
@@TK_TABLE_LIST << obj
- obj.instance_variable_set(:@id, id)
- obj.instance_variable_set(:@mutex, Mutex.new)
- obj.instance_eval{
- def self.mutex
- @mutex
- end
+ obj.instance_eval <<-EOD
def self.method_missing(m, *args)
- MultiTkIp.tk_object_table(@id).__send__(m, *args)
+ MultiTkIp.tk_object_table(#{id}).__send__(m, *args)
end
- }
+ EOD
obj.freeze
@@IP_TABLE.each{|tg, ip| ip._add_new_tables }
return obj
@@ -2430,11 +2338,6 @@ end
class MultiTkIp
def mainloop(check_root = true, restart_on_dead = true)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
-
- if WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!!
- return @interp_thread.value if @interp_thread
- end
-
#return self if self.slave?
#return self if self != @@DEFAULT_MASTER
if self != @@DEFAULT_MASTER
@@ -2843,10 +2746,9 @@ class MultiTkIp
i = -1
brace = 1
str.each_byte {|c|
- c = c.chr
i += 1
- brace += 1 if c == '{'
- brace -= 1 if c == '}'
+ brace += 1 if c == ?{
+ brace -= 1 if c == ?}
break if brace == 0
}
if i == 0
@@ -3285,44 +3187,15 @@ end
# encoding convert
-class << MultiTkIp
- def encoding_table
- __getip.encoding_table
- end
-end
class MultiTkIp
- def encoding_table
- @interp.encoding_table
- end
-
- def force_default_encoding=(mode)
+ def encoding
raise SecurityError, "no permission to manipulate" unless self.manipulable?
- @interp.force_default_encoding = mode
+ @interp.encoding
end
- def force_default_encoding?
- raise SecurityError, "no permission to manipulate" unless self.manipulable?
- @interp.force_default_encoding?
- end
-
- def default_encoding=(enc)
- raise SecurityError, "no permission to manipulate" unless self.manipulable?
- @interp.default_encoding = enc
- end
-
def encoding=(enc)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.encoding = enc
end
- def encoding_name
- raise SecurityError, "no permission to manipulate" unless self.manipulable?
- @interp.encoding_name
- end
- def encoding_obj
- raise SecurityError, "no permission to manipulate" unless self.manipulable?
- @interp.encoding_obj
- end
- alias encoding encoding_name
- alias default_encoding encoding_name
def encoding_convertfrom(str, enc=None)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@@ -3339,30 +3212,13 @@ end
# remove methods for security
-if MultiTkIp::WITH_RUBY_VM &&
- ! MultiTkIp::RUN_EVENTLOOP_ON_MAIN_THREAD ### check Ruby 1.9 !!!!!!!
- class MultiTkIp
- INTERP_THREAD = @@DEFAULT_MASTER.instance_variable_get('@interp_thread')
- INTERP_MUTEX = INTERP_THREAD[:mutex]
- INTERP_ROOT_CHECK = INTERP_THREAD[:root_check]
- end
- module TkCore
- INTERP_THREAD = MultiTkIp::INTERP_THREAD
- INTERP_MUTEX = MultiTkIp::INTERP_MUTEX
- INTERP_ROOT_CHECK = MultiTkIp::INTERP_ROOT_CHECK
- end
- class MultiTkIp
- remove_const(:INTERP_THREAD)
- remove_const(:INTERP_MUTEX)
- remove_const(:INTERP_ROOT_CHECK)
- end
-end
-
class MultiTkIp
# undef_method :instance_eval
undef_method :instance_variable_get
undef_method :instance_variable_set
end
+
+
# end of MultiTkIp definition
# defend against modification
diff --git a/ext/tk/lib/tcltk.rb b/ext/tk/lib/tcltk.rb
index 7f6f41605d..1a6694dbff 100644
--- a/ext/tk/lib/tcltk.rb
+++ b/ext/tk/lib/tcltk.rb
@@ -265,7 +265,7 @@ class TclTkWidget < TclTkCommand
# (used in TclTkInterpreter#initialize())
# need two arguments
- fail("invalid # of parameter") if args.size != 2
+ fail("illegal # of parameter") if args.size != 2
# ip: interpreter(TclTkIp)
# exp: tcl/tk representation
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index c5d5b804d2..32b5e20bc5 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -1,5 +1,6 @@
#
# tk.rb - Tk interface module using tcltklib
+# $Date$
# by Yukihiro Matsumoto <matz@netlab.jp>
# use Shigehiro's tcltklib
@@ -9,9 +10,6 @@ require 'tkutil'
# autoload
require 'tk/autoload'
-# for Mutex
-require 'thread'
-
class TclTkIp
# backup original (without encoding) _eval and _invoke
alias _eval_without_enc _eval
@@ -39,12 +37,7 @@ module TkComm
#Tk_CMDTBL = {}
#Tk_WINDOWS = {}
- Tk_IDs = ["00000".taint, "00000".taint] # [0]-cmdid, [1]-winid
- Tk_IDs.instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
+ Tk_IDs = ["00000".taint, "00000".taint].freeze # [0]-cmdid, [1]-winid
# for backward compatibility
Tk_CMDTBL = Object.new
@@ -225,9 +218,7 @@ module TkComm
TkCore::INTERP.tk_windows[val]?
TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val)
when /\Ai(_\d+_)?\d+\z/
- TkImage::Tk_IMGTBL.mutex.synchronize{
- TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val
- }
+ TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val
when /\A-?\d+\.?\d*(e[-+]?\d+)?\z/
val.to_f
when /\\ /
@@ -344,8 +335,6 @@ if USE_TCLs_LIST_FUNCTIONS
if dst_enc != true && dst_enc != false
if (s_enc = s.instance_variable_get(:@encoding))
s_enc = s_enc.to_s
- elsif TkCore::WITH_ENCODING
- s_enc = s.encoding.name
else
s_enc = sys_enc
end
@@ -358,20 +347,11 @@ if USE_TCLs_LIST_FUNCTIONS
if sys_enc && dst_enc
dst.map!{|s| _toUTF8(s)}
ret = TkCore::INTERP._merge_tklist(*dst)
- if TkCore::WITH_ENCODING
- if dst_enc.kind_of?(String)
- ret = _fromUTF8(ret, dst_enc)
- ret.force_encoding(dst_enc)
- else
- ret.force_encoding('utf-8')
- end
- else # without encoding
- if dst_enc.kind_of?(String)
- ret = _fromUTF8(ret, dst_enc)
- ret.instance_variable_set(:@encoding, dst_enc)
- else
- ret.instance_variable_set(:@encoding, 'utf-8')
- end
+ if dst_enc.kind_of?(String)
+ ret = _fromUTF8(ret, dst_enc)
+ ret.instance_variable_set(:@encoding, dst_enc)
+ else
+ ret.instance_variable_set(:@encoding, 'utf-8')
end
ret
else
@@ -431,6 +411,46 @@ else
tk_split_sublist(token, depth - 1)
}
end
+=begin
+ def tk_split_list(str)
+ return [] if str == ""
+ idx = str.index('{')
+ while idx and idx > 0 and str[idx-1] == ?\\
+ idx = str.index('{', idx+1)
+ end
+ unless idx
+ list = tk_tcl2ruby(str)
+ unless Array === list
+ list = [list]
+ end
+ return list
+ end
+
+ list = tk_tcl2ruby(str[0,idx])
+ list = [] if list == ""
+ str = str[idx+1..-1]
+ i = -1
+ escape = false
+ brace = 1
+ str.each_byte {|c|
+ i += 1
+ brace += 1 if c == ?{ && !escape
+ brace -= 1 if c == ?} && !escape
+ escape = (c == ?\\)
+ break if brace == 0
+ }
+ if str.size == i + 1
+ return tk_split_list(str[0, i])
+ end
+ if str[0, i] == ' '
+ list.push ' '
+ else
+ list.push tk_split_list(str[0, i])
+ end
+ list += tk_split_list(str[i+1..-1])
+ list
+ end
+=end
def tk_split_simplelist(str, src_enc=true, dst_enc=true)
return [] if str == ""
@@ -581,9 +601,7 @@ end
end
def image_obj(val)
if val =~ /^i(_\d+_)?\d+$/
- TkImage::Tk_IMGTBL.mutex.synchronize{
- TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val
- }
+ TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val
else
val
end
@@ -765,17 +783,15 @@ end
id = "c" + TkCore::INTERP._ip_id_ + TkComm::Tk_IDs[0]
end
def _next_cmd_id
- TkComm::Tk_IDs.mutex.synchronize{
- id = _curr_cmd_id
- #Tk_IDs[0] += 1
- TkComm::Tk_IDs[0].succ!
- id
- }
+ id = _curr_cmd_id
+ #Tk_IDs[0] += 1
+ TkComm::Tk_IDs[0].succ!
+ id
end
private :_curr_cmd_id, :_next_cmd_id
module_function :_curr_cmd_id, :_next_cmd_id
- def TkComm.install_cmd(cmd, local_cmdtbl=nil)
+ def install_cmd(cmd)
return '' if cmd == ''
begin
ns = TkCore::INTERP._invoke_without_enc('namespace', 'current')
@@ -794,15 +810,6 @@ end
@cmdtbl = [] unless defined? @cmdtbl
@cmdtbl.taint unless @cmdtbl.tainted?
@cmdtbl.push id
-
- if local_cmdtbl && local_cmdtbl.kind_of?(Array)
- begin
- local_cmdtbl << id
- rescue Exception
- # ignore
- end
- end
-
#return Kernel.format("rb_out %s", id);
if ns
'rb_out' << TkCore::INTERP._ip_id_ << ' ' << ns << ' ' << id
@@ -810,30 +817,14 @@ end
'rb_out' << TkCore::INTERP._ip_id_ << ' ' << id
end
end
- def TkComm.uninstall_cmd(id, local_cmdtbl=nil)
+ def uninstall_cmd(id)
#id = $1 if /rb_out\S* (c(_\d+_)?\d+)/ =~ id
id = $4 if id =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/
-
- if local_cmdtbl && local_cmdtbl.kind_of?(Array)
- begin
- local_cmdtbl.delete(id)
- rescue Exception
- # ignore
- end
- end
- @cmdtbl.delete(id)
-
#Tk_CMDTBL.delete(id)
TkCore::INTERP.tk_cmd_tbl.delete(id)
end
# private :install_cmd, :uninstall_cmd
- # module_function :install_cmd, :uninstall_cmd
- def install_cmd(cmd)
- TkComm.install_cmd(cmd, @cmdtbl)
- end
- def uninstall_cmd(id)
- TkComm.uninstall_cmd(id, @cmdtbl)
- end
+ module_function :install_cmd, :uninstall_cmd
=begin
def install_win(ppath,name=nil)
@@ -865,10 +856,8 @@ end
return TkCore::INTERP.tk_windows[@path] = self
end
else
- Tk_IDs.mutex.synchronize{
- name = "w" + TkCore::INTERP._ip_id_ + Tk_IDs[1]
- Tk_IDs[1].succ!
- }
+ name = "w" + TkCore::INTERP._ip_id_ + Tk_IDs[1]
+ Tk_IDs[1].succ!
end
if !ppath or ppath == '.'
@path = '.' + name
@@ -947,12 +936,7 @@ module TkComm
def _bindinfo(what, context=nil)
if context
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- enum_obj = tk_call_without_enc(*what+["<#{tk_event_sequence(context)}>"]).each_line
- else
- enum_obj = tk_call_without_enc(*what+["<#{tk_event_sequence(context)}>"])
- end
- enum_obj.collect {|cmdline|
+ tk_call_without_enc(*what+["<#{tk_event_sequence(context)}>"]) .collect {|cmdline|
=begin
if cmdline =~ /^rb_out\S* (c(?:_\d+_)?\d+)\s+(.*)$/
#[Tk_CMDTBL[$1], $2]
@@ -1098,14 +1082,6 @@ module TkCore
include TkComm
extend TkComm
- WITH_RUBY_VM = Object.const_defined?(:VM) && ::VM.class == Class
- WITH_ENCODING = Object.const_defined?(:Encoding) && ::Encoding.class == Class
-
- unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD
- ### Ruby 1.9 !!!!!!!!!!!!!!!!!!!!!!!!!!
- RUN_EVENTLOOP_ON_MAIN_THREAD = false
- end
-
unless self.const_defined? :INTERP
if self.const_defined? :IP_NAME
name = IP_NAME.to_s
@@ -1123,49 +1099,14 @@ module TkCore
opts = ''
end
- if !WITH_RUBY_VM || RUN_EVENTLOOP_ON_MAIN_THREAD ### check Ruby 1.9 !!!!!!!
- INTERP = TclTkIp.new(name, opts)
- else
- INTERP_MUTEX = Mutex.new
- INTERP_ROOT_CHECK = ConditionVariable.new
- INTERP_THREAD = Thread.new{
- begin
- Thread.current[:interp] = interp = TclTkIp.new(name, opts)
- rescue => e
- Thread.current[:interp] = e
- raise e
- end
- Thread.current[:status] = nil
- #sleep
-
- begin
- Thread.current[:status] = TclTkLib.mainloop(true)
- rescue Exception=>e
- Thread.current[:status] = e
- ensure
- INTERP_MUTEX.synchronize{ INTERP_ROOT_CHECK.broadcast }
- end
- Thread.current[:status] = TclTkLib.mainloop(false)
- }
-
- until INTERP_THREAD[:interp]
- Thread.pass
- end
- # INTERP_THREAD.run
- raise INTERP_THREAD[:interp] if INTERP_THREAD[:interp].kind_of? Exception
-
- INTERP = INTERP_THREAD[:interp]
- end
+ INTERP = TclTkIp.new(name, opts)
def INTERP.__getip
self
end
INTERP.instance_eval{
- # @tk_cmd_tbl = {}.taint
- @tk_cmd_tbl = Hash.new{|hash, key|
- fail IndexError, "unknown command ID '#{key}'"
- }.taint
+ @tk_cmd_tbl = {}.taint
def @tk_cmd_tbl.[]=(idx,val)
if self.has_key?(idx) && Thread.current.group != ThreadGroup::Default
fail SecurityError,"cannot change the entried command"
@@ -1216,10 +1157,6 @@ module TkCore
class Tk_OBJECT_TABLE
def initialize(id)
@id = id
- @mutex = Mutex.new
- end
- def mutex
- @mutex
end
def method_missing(m, *args, &b)
TkCore::INTERP.tk_object_table(@id).__send__(m, *args, &b)
@@ -1298,7 +1235,7 @@ module TkCore
}) << ' %W')
INTERP.add_tk_procs(TclTkLib::FINALIZE_PROC_NAME, '',
- "catch { bind all <#{WIDGET_DESTROY_HOOK}> {} }")
+ "bind all <#{WIDGET_DESTROY_HOOK}> {}")
INTERP.add_tk_procs('rb_out', 'ns args', <<-'EOL')
if [regexp {^::} $ns] {
@@ -1405,11 +1342,7 @@ module TkCore
"\n---< backtrace of Ruby side >-----\n" +
_toUTF8(e.backtrace.join("\n")) +
"\n---< backtrace of Tk side >-------"
- if TkCore::WITH_ENCODING
- msg.force_encoding('utf-8')
- else
- msg.instance_variable_set(:@encoding, 'utf-8')
- end
+ msg.instance_variable_set(:@encoding, 'utf-8')
rescue Exception
msg = e.class.inspect + ': ' + e.message + "\n" +
"\n---< backtrace of Ruby side >-----\n" +
@@ -1465,13 +1398,6 @@ module TkCore
end
def after(ms, cmd=Proc.new)
- cmdid = install_cmd(proc{ret = cmd.call;uninstall_cmd(cmdid); ret})
- after_id = tk_call_without_enc("after",ms,cmdid)
- after_id.instance_variable_set('@cmdid', cmdid)
- after_id
- end
-=begin
- def after(ms, cmd=Proc.new)
crit_bup = Thread.critical
Thread.critical = true
@@ -1494,16 +1420,8 @@ module TkCore
# tk_call("after",ms,cmdid)
# end
end
-=end
def after_idle(cmd=Proc.new)
- cmdid = install_cmd(proc{ret = cmd.call;uninstall_cmd(cmdid); ret})
- after_id = tk_call_without_enc('after','idle',cmdid)
- after_id.instance_variable_set('@cmdid', cmdid)
- after_id
- end
-=begin
- def after_idle(cmd=Proc.new)
crit_bup = Thread.critical
Thread.critical = true
@@ -1514,15 +1432,9 @@ module TkCore
tk_call_without_enc('after','idle',cmdid)
end
-=end
def after_cancel(afterId)
tk_call_without_enc('after','cancel',afterId)
- if (cmdid = afterId.instance_variable_get('@cmdid'))
- afterId.instance_variable_set('@cmdid', nil)
- uninstall_cmd(cmdid)
- end
- afterId
end
def windowingsystem
@@ -1642,27 +1554,7 @@ module TkCore
end
def mainloop(check_root = true)
- if !TkCore::WITH_RUBY_VM || TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
- TclTkLib.mainloop(check_root)
- else ### Ruby 1.9 !!!!!
- begin
- TclTkLib.set_eventloop_window_mode(true)
- if check_root
- INTERP_MUTEX.synchronize{
- INTERP_ROOT_CHECK.wait(INTERP_MUTEX)
- status = INTERP_THREAD[:status]
- if status
- INTERP_THREAD[:status] = nil
- raise status if status.kind_of?(Exception)
- end
- }
- else
- INTERP_THREAD.value
- end
- ensure
- TclTkLib.set_eventloop_window_mode(false)
- end
- end
+ TclTkLib.mainloop(check_root)
end
def mainloop_thread?
@@ -1670,12 +1562,7 @@ module TkCore
# nil : there is no mainloop
# false : mainloop is running on the other thread
# ( At then, it is dangerous to call Tk interpreter directly. )
- if !TkCore::WITH_RUBY_VM || TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
- ### Ruby 1.9 !!!!!!!!!!!
- TclTkLib.mainloop_thread?
- else
- Thread.current == INTERP_THREAD
- end
+ TclTkLib.mainloop_thread?
end
def mainloop_exist?
@@ -2027,7 +1914,7 @@ module Tk
end
def root
- Tk::Root.new
+ TkRoot.new
end
def Tk.load_tclscript(file, enc=nil)
@@ -2143,27 +2030,6 @@ module Tk
tk_call_without_enc('destroy', '.')
end
- ################################################
-
- def Tk.sleep(ms = nil, id = nil)
- if id
- var = (id.kind_of?(TkVariable))? id: TkVarAccess.new(id.to_s)
- else
- var = TkVariable.new
- end
-
- var.value = tk_call_without_enc('after', ms, proc{ var.value = 0 }) if ms
- var.thread_wait
- ms
- end
-
- def Tk.wakeup(id)
- ((id.kind_of?(TkVariable))? id: TkVarAccess.new(id.to_s)).value = 0
- nil
- end
-
- ################################################
-
def Tk.pack(*args)
TkPack.configure(*args)
end
@@ -2339,431 +2205,15 @@ end
# convert kanji string to/from utf-8
###########################################
if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK)
- module Tk
- module Encoding
- extend Encoding
-
- TkCommandNames = ['encoding'.freeze].freeze
-
- #############################################
-
- if TkCore::WITH_ENCODING ### Ruby 1.9
- RubyEncoding = ::Encoding
-
- # for saving GC cost
- #ENCNAMES_CMD = ['encoding'.freeze, 'names'.freeze]
- BINARY_NAME = 'binary'.freeze
- UTF8_NAME = 'utf-8'.freeze
- DEFAULT_EXTERNAL_NAME = RubyEncoding.default_external.name.freeze
-
- BINARY = RubyEncoding.find(BINARY_NAME)
- UNKNOWN = RubyEncoding.find('ASCII-8BIT')
-
- ### start of creating ENCODING_TABLE
- ENCODING_TABLE = TkCore::INTERP.encoding_table
-=begin
- ENCODING_TABLE = {
- 'binary' => BINARY,
- # 'UNKNOWN-8BIT' => UNKNOWN,
- }
-
- list = TkCore::INTERP._invoke_without_enc(ENCNAMES_CMD[0],
- ENCNAMES_CMD[1])
- TkCore::INTERP._split_tklist(list).each{|name|
- begin
- enc = RubyEncoding.find(name)
- rescue ArgumentError
- case name
- when 'identity'
- enc = BINARY
- when 'shiftjis'
- enc = RubyEncoding.find('Shift_JIS')
- when 'unicode'
- enc = RubyEncoding.find('UTF-8')
- #if Tk.tk_call('set', 'tcl_platform(byteOrder)') =='littleEndian'
- # enc = RubyEncoding.find('UTF-16LE')
- #else
- # enc = RubyEncoding.find('UTF-16BE')
- #end
- when 'symbol'
- # single byte data
- enc = RubyEncoding.find('ASCII-8BIT') ### ???
- else
- # unsupported on Ruby, but supported on Tk
- enc = TkCore::INTERP.create_dummy_encoding_for_tk(name)
- end
- end
- ENCODING_TABLE[name.freeze] = enc
- }
-=end
-=begin
- def ENCODING_TABLE.get_name(enc)
- orig_enc = enc
-
- # unles enc, use system default
- # 1st: Ruby/Tk default encoding
- # 2nd: Tcl/Tk default encoding
- # 3rd: Ruby's default_external
- enc ||= TkCore::INTERP.encoding
- enc ||= TclTkLib.encoding_system
- enc ||= DEFAULT_EXTERNAL_NAME
-
- if enc.kind_of?(RubyEncoding)
- # Ruby's Encoding object
- if (name = self.key(enc))
- return name
- end
-
- # Is it new ?
- list = TkCore::INTERP._invoke_without_enc(ENCNAMES_CMD[0],
- ENCNAMES_CMD[1])
- TkComm.simplelist(list).each{|name|
- if ((enc == RubyEncoding.find(name)) rescue false)
- # new relation!! update table
- self[name.freeze] = enc
- return name
- end
- }
- else
- # String or Symbol ?
- if self[name = enc.to_s]
- return name
- end
-
- # Is it new ?
- if (enc_obj = (RubyEncoding.find(name) rescue false))
- list = TkCore::INTERP._invoke_without_enc(ENCNAMES_CMD[0],
- ENCNAMES_CMD[1])
- if TkComm.simplelist(list).index(name)
- # Tk's encoding name ?
- self[name.freeze] = enc_obj # new relation!! update table
- return name
- else
- # Ruby's encoding name ?
- if (name = self.key(enc_obj))
- return name
- end
- end
- end
- end
-
- fail ArgumentError, "unsupported Tk encoding '#{orig_enc}'"
- end
-
- def ENCODING_TABLE.get_obj(enc)
- # returns the encoding object.
- # If 'enc' is the encoding name on Tk only, it returns nil.
- ((obj = self[self.get_name(enc)]).kind_of?(RubyEncoding))? obj: nil
- end
-=end
- ### end of creating ENCODING_TABLE
-
- end
-
- #############################################
-
- if TkCore::WITH_ENCODING
- ################################
- ### Ruby 1.9
- ################################
- def force_default_encoding(mode)
- TkCore::INTERP.force_default_encoding = mode
- end
-
- def force_default_encoding?
- TkCore::INTERP.force_default_encoding?
- end
-
- def default_encoding=(enc)
- TkCore::INTERP.default_encoding = Tk::Encoding::ENCODING_TABLE.get_name(enc)
- end
-
- def encoding=(enc)
- TkCore::INTERP.encoding = Tk::Encoding::ENCODING_TABLE.get_name(enc)
- end
-
- def encoding_name
- Tk::Encoding::ENCODING_TABLE.get_name(TkCore::INTERP.encoding)
- end
- def encoding_obj
- Tk::Encoding::ENCODING_TABLE.get_obj(TkCore::INTERP.encoding)
- end
- alias encoding encoding_name
- alias default_encoding encoding_name
-
- def tk_encoding_names
- TkComm.simplelist(TkCore::INTERP._invoke_without_enc(Tk::Encoding::ENCNAMES_CMD[0], Tk::Encoding::ENCNAMES_CMD[1]))
- end
- def encoding_names
- self.tk_encoding_names.find_all{|name|
- Tk::Encoding::ENCODING_TABLE.get_name(name) rescue false
- }
- end
- def encoding_objs
- self.tk_encoding_names.map!{|name|
- Tk::Encoding::ENCODING_TABLE.get_obj(name) rescue nil
- }.compact
- end
-
- def encoding_system=(enc)
- TclTkLib.encoding_system = Tk::Encoding::ENCODING_TABLE.get_name(enc)
- end
-
- def encoding_system_name
- Tk::Encoding::ENCODING_TABLE.get_name(TclTkLib.encoding_system)
- end
- def encoding_system_obj
- Tk::Encoding::ENCODING_TABLE.get_obj(TclTkLib.encoding_system)
- end
- alias encoding_system encoding_system_name
-
- ################################
- else
- ################################
- ### Ruby 1.8-
- ################################
- def force_default_encoding=(mode)
- true
- end
-
- def force_default_encoding?
- true
- end
-
- def default_encoding=(enc)
- TkCore::INTERP.default_encoding = enc
- end
-
- def encoding=(enc)
- TkCore::INTERP.encoding = enc
- end
-
- def encoding_obj
- TkCore::INTERP.encoding
- end
- def encoding_name
- TkCore::INTERP.encoding
- end
- alias encoding encoding_name
- alias default_encoding encoding_name
-
- def tk_encoding_names
- TkComm.simplelist(Tk.tk_call('encoding', 'names'))
- end
- def encoding_objs
- self.tk_encoding_names
- end
- def encoding_names
- self.tk_encoding_names
- end
-
- def encoding_system=(enc)
- TclTkLib.encoding_system = enc
- end
-
- def encoding_system_name
- TclTkLib.encoding_system
- end
- def encoding_system_obj
- TclTkLib.encoding_system
- end
- alias encoding_system encoding_system_name
-
- ################################
- end
-
- def encoding_convertfrom(str, enc=nil)
- enc = encoding_system_name unless enc
- str = str.dup
- if TkCore::WITH_ENCODING
- if str.kind_of?(Tk::EncodedString)
- str.__instance_variable_set('@encoding', nil)
- else
- str.instance_variable_set('@encoding', nil)
- end
- str.force_encoding('binary')
- else
- str.instance_variable_set('@encoding', 'binary')
- end
- ret = TkCore::INTERP._invoke_without_enc('encoding', 'convertfrom',
- enc, str)
- if TkCore::WITH_ENCODING
- ret.force_encoding('utf-8')
- else
- Tk::UTF8_String.new(ret)
- end
- ret
- end
- alias encoding_convert_from encoding_convertfrom
-
- def encoding_convertto(str, enc=nil)
- # str must be a UTF-8 string
- enc = encoding_system_name unless enc
- ret = TkCore::INTERP._invoke_without_enc('encoding', 'convertto',
- enc, str)
- #ret.instance_variable_set('@encoding', 'binary')
- if TkCore::WITH_ENCODING
- #ret.force_encoding(Tk::Encoding::ENCODING_TABLE.get_obj('binary'))
- ret.force_encoding(Tk::Encoding::ENCODING_TABLE.get_obj(enc))
- end
- ret
- end
- alias encoding_convert_to encoding_convertto
-
- def encoding_dirs
- # Tcl8.5 feature
- TkComm.simplelist(Tk.tk_call_without_enc('encoding', 'dirs'))
- end
-
- def encoding_dirs=(dir_list) # an array or a Tcl's list string
- # Tcl8.5 feature
- Tk.tk_call_without_enc('encoding', 'dirs', dir_list)
- end
- end
-
- extend Encoding
- end
-
class TclTkIp
- def force_default_encoding=(mode)
- @force_default_encoding = (mode)? true: false
- end
-
- def force_default_encoding?
- @force_default_encoding ||= false
- end
-
- def default_encoding=(name)
- name = name.name if name.kind_of?(::Encoding) if Tk::WITH_ENCODING
- @encoding = name
- end
-
# from tkencoding.rb by ttate@jaist.ac.jp
- #attr_accessor :encoding
- def encoding=(name)
- self.force_default_encoding = true # for comaptibility
- self.default_encoding = name
- end
-
- def encoding_name
- (@encoding)? @encoding.dup: nil
- end
- alias encoding encoding_name
- alias default_encoding encoding_name
-
- def encoding_obj
- if Tk::WITH_ENCODING
- Tk::Encoding.tcl2rb_encoding(@encoding)
- else
- (@encoding)? @encoding.dup: nil
- end
- end
-
- alias __toUTF8 _toUTF8
- alias __fromUTF8 _fromUTF8
-
- if Object.const_defined?(:Encoding) && ::Encoding.class == Class
- # with Encoding (Ruby 1.9+)
- #
- # use functions on Tcl as default.
- # but when unsupported encoding on Tcl, use methods on Ruby.
- #
- def _toUTF8(str, enc = nil)
- if enc
- # use given encoding
- begin
- enc_name = Tk::Encoding::ENCODING_TABLE.get_name(enc)
- rescue
- # unknown encoding for Tk -> try to convert encoding on Ruby
- str = str.dup.force_encoding(enc)
- str.encode!(Tk::Encoding::UTF8_NAME) # modify self !!
- return str # if no error, probably succeed converting
- end
- end
-
- enc_name ||= str.instance_variable_get(:@encoding)
-
- enc_name ||=
- Tk::Encoding::ENCODING_TABLE.get_name(str.encoding) rescue nil
-
- unless enc_name
- # str.encoding isn't supported by Tk -> try to convert on Ruby
- begin
- return str.encode(Tk::Encoding::UTF8_NAME) # new string
- rescue
- # error -> ignore, try to use default encoding of Ruby/Tk
- end
- end
-
- #enc_name ||=
- # Tk::Encoding::ENCODING_TABLE.get_name(Tk.encoding) rescue nil
- enc_name ||= Tk::Encoding::ENCODING_TABLE.get_name(nil)
-
- # is 'binary' encoding?
- if enc_name == Tk::Encoding::BINARY_NAME
- return str.dup.force_encoding(Tk::Encoding::BINARY_NAME)
- end
-
- # force default encoding?
- if ! str.kind_of?(Tk::EncodedString) && self.force_default_encoding?
- enc_name = Tk::Encoding::ENCODING_TABLE.get_name(Tk.default_encoding)
- end
-
- encstr = __toUTF8(str, enc_name)
- encstr.force_encoding(Tk::Encoding::UTF8_NAME)
- encstr
- end
- def _fromUTF8(str, enc = nil)
- # str must be UTF-8 or binary.
- enc_name = str.instance_variable_get(:@encoding)
- enc_name ||=
- Tk::Encoding::ENCODING_TABLE.get_name(str.encoding) rescue nil
-
- # is 'binary' encoding?
- if enc_name == Tk::Encoding::BINARY_NAME
- return str.dup.force_encoding(Tk::Encoding::BINARY_NAME)
- end
-
- # get target encoding name (if enc == nil, use default encoding)
- begin
- enc_name = Tk::Encoding::ENCODING_TABLE.get_name(enc)
- rescue
- # then, enc != nil
- # unknown encoding for Tk -> try to convert encoding on Ruby
- str = str.dup.force_encoding(Tk::Encoding::UTF8_NAME)
- str.encode!(enc) # modify self !!
- return str # if no error, probably succeed converting
- end
-
- encstr = __fromUTF8(str, enc_name)
- encstr.force_encoding(Tk::Encoding::ENCODING_TABLE.get_obj(enc_name))
- encstr
- end
- ###
- else
- # without Encoding (Ruby 1.8)
- def _toUTF8(str, encoding = nil)
- __toUTF8(str, encoding)
- end
- def _fromUTF8(str, encoding = nil)
- __fromUTF8(str, encoding)
- end
- ###
- end
+ attr_accessor :encoding
alias __eval _eval
alias __invoke _invoke
- def _eval(cmd)
- _fromUTF8(__eval(_toUTF8(cmd)))
- end
-
- def _invoke(*cmds)
- _fromUTF8(__invoke(*(cmds.collect{|cmd| _toUTF8(cmd)})))
- end
-
- alias _eval_with_enc _eval
- alias _invoke_with_enc _invoke
+ alias __toUTF8 _toUTF8
+ alias __fromUTF8 _fromUTF8
=begin
#### --> definition is moved to TclTkIp module
@@ -2814,6 +2264,17 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK)
end
=end
+ def _eval(cmd)
+ _fromUTF8(__eval(_toUTF8(cmd)))
+ end
+
+ def _invoke(*cmds)
+ _fromUTF8(__invoke(*(cmds.collect{|cmd| _toUTF8(cmd)})))
+ end
+
+ alias _eval_with_enc _eval
+ alias _invoke_with_enc _invoke
+
=begin
def _eval(cmd)
if defined?(@encoding) && @encoding != 'utf-8'
@@ -2870,213 +2331,126 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK)
module TclTkLib
class << self
- def force_default_encoding=(mode)
- TkCore::INTERP.force_default_encoding = mode
+ alias _encoding encoding
+ alias _encoding= encoding=
+ def encoding=(name)
+ TkCore::INTERP.encoding = name
end
-
- def force_default_encoding?
- TkCore::INTERP.force_default_encoding?
+ def encoding
+ TkCore::INTERP.encoding
end
+ end
+ end
- def default_encoding=(name)
- TkCore::INTERP.default_encoding = name
- end
+ module Tk
+ module Encoding
+ extend Encoding
+
+ TkCommandNames = ['encoding'.freeze].freeze
- alias _encoding encoding
- alias _encoding= encoding=
def encoding=(name)
- name = name.name if name.kind_of?(::Encoding) if Tk::WITH_ENCODING
TkCore::INTERP.encoding = name
end
- def encoding_name
+ def encoding
TkCore::INTERP.encoding
end
- alias encoding encoding_name
- alias default_encoding encoding_name
- def encoding_obj
- if Tk::WITH_ENCODING
- Tk::Encoding.tcl2rb_encoding(TkCore::INTERP.encoding)
- else
- TkCore::INTERP.encoding
- end
+ def encoding_names
+ TkComm.simplelist(Tk.tk_call('encoding', 'names'))
end
- end
- end
- # estimate encoding
- unless TkCore::WITH_ENCODING
- case $KCODE
- when /^e/i # EUC
- Tk.encoding = 'euc-jp'
- Tk.encoding_system = 'euc-jp'
- when /^s/i # SJIS
- begin
- if Tk.encoding_system == 'cp932'
- Tk.encoding = 'cp932'
- else
- Tk.encoding = 'shiftjis'
- Tk.encoding_system = 'shiftjis'
- end
- rescue StandardError, NameError
- Tk.encoding = 'shiftjis'
- Tk.encoding_system = 'shiftjis'
- end
- when /^u/i # UTF8
- Tk.encoding = 'utf-8'
- Tk.encoding_system = 'utf-8'
- else # NONE
- if defined? DEFAULT_TK_ENCODING
- Tk.encoding_system = DEFAULT_TK_ENCODING
- end
- begin
- Tk.encoding = Tk.encoding_system
- rescue StandardError, NameError
- Tk.encoding = 'utf-8'
- Tk.encoding_system = 'utf-8'
+ def encoding_system
+ Tk.tk_call('encoding', 'system')
end
- end
- else ### Ruby 1.9 !!!!!!!!!!!!
- loc_enc_obj = ::Encoding.find(::Encoding.locale_charmap)
- ext_enc_obj = ::Encoding.default_external
- tksys_enc_name = Tk::Encoding::ENCODING_TABLE.get_name(Tk.encoding_system)
- # p [Tk.encoding, Tk.encoding_system, loc_enc_obj, ext_enc_obj]
+ def encoding_system=(enc)
+ Tk.tk_call('encoding', 'system', enc)
+ end
-=begin
- if ext_enc_obj == Tk::Encoding::UNKNOWN
- if defind? DEFAULT_TK_ENCODING
- if DEFAULT_TK_ENCODING.kind_of?(::Encoding)
- tk_enc_name = DEFAULT_TK_ENCODING.name
- tksys_enc_name = DEFAULT_TK_ENCODING.name
- else
- tk_enc_name = DEFAULT_TK_ENCODING
- tksys_enc_name = DEFAULT_TK_ENCODING
- end
- else
- tk_enc_name = loc_enc_obj.name
- tksys_enc_name = loc_enc_obj.name
+ def encoding_convertfrom(str, enc=nil)
+ # str is an usual enc string or a Tcl's internal string expression
+ # in enc (which is returned from 'encoding_convertto' method).
+ # the return value is a UTF-8 string.
+ enc = encoding_system unless enc
+ ret = TkCore::INTERP.__invoke('encoding', 'convertfrom', enc, str)
+ ret.instance_variable_set('@encoding', 'utf-8')
+ ret
end
- else
- tk_enc_name = ext_enc_obj.name
- tksys_enc_name = ext_enc_obj.name
- end
+ alias encoding_convert_from encoding_convertfrom
- # Tk.encoding = tk_enc_name
- Tk.default_encoding = tk_enc_name
- Tk.encoding_system = tksys_enc_name
-=end
+ def encoding_convertto(str, enc=nil)
+ # str must be a UTF-8 string.
+ # The return value is a Tcl's internal string expression in enc.
+ # To get an usual enc string, use Tk.fromUTF8(ret_val, enc).
+ enc = encoding_system unless enc
+ ret = TkCore::INTERP.__invoke('encoding', 'convertto', enc, str)
+ ret.instance_variable_set('@encoding', 'binary')
+ ret
+ end
+ alias encoding_convert_to encoding_convertto
- if ext_enc_obj == Tk::Encoding::UNKNOWN
- if loc_enc_obj == Tk::Encoding::UNKNOWN
- # use Tk.encoding_system
- else
- # use locale_charmap
- begin
- loc_enc_name = Tk::Encoding::ENCODING_TABLE.get_name(loc_enc_obj)
- if loc_enc_name && loc_enc_name != tksys_enc_name
- # use locale_charmap
- Tk.encoding_system = loc_enc_name
- else
- # use Tk.encoding_system
- end
- rescue ArgumentError
- # unsupported encoding on Tk -> use Tk.encoding_system
- end
+ def encoding_dirs
+ # Tcl8.5 feature
+ TkComm.simplelist(Tk.tk_call_without_enc('encoding', 'dirs'))
end
- else
- begin
- ext_enc_name = Tk::Encoding::ENCODING_TABLE.get_name(ext_enc_obj)
- if ext_enc_name && ext_enc_name != tksys_enc_name
- # use default_external
- Tk.encoding_system = ext_enc_name
- else
- # use Tk.encoding_system
- end
- rescue ArgumentError
- # unsupported encoding on Tk -> use Tk.encoding_system
+
+ def encoding_dirs=(dir_list) # an array or a Tcl's list string
+ # Tcl8.5 feature
+ Tk.tk_call_without_enc('encoding', 'dirs', dir_list)
end
end
- # setup Tk.encoding
- enc_name = nil
+ extend Encoding
+ end
+ # estimate encoding
+ case $KCODE
+ when /^e/i # EUC
+ Tk.encoding = 'euc-jp'
+ Tk.encoding_system = 'euc-jp'
+ when /^s/i # SJIS
begin
- default_def = DEFAULT_TK_ENCODING
- if ::Encoding.find(default_def.to_s) != Tk::Encoding::UNKNOWN
- enc_name = Tk::Encoding::ENCODING_TABLE.get_name(default_def)
- end
- rescue NameError
- # ignore
- enc_name = nil
- rescue ArgumentError
- enc_name = nil
- fail ArgumentError,
- "DEFAULT_TK_ENCODING has an unknown encoding #{default_def}"
- end
-
- unless enc_name
- if ext_enc_obj == Tk::Encoding::UNKNOWN
- if loc_enc_obj == Tk::Encoding::UNKNOWN
- # use Tk.encoding_system
- enc_name = tksys_enc_name
- else
- # use locale_charmap
- begin
- loc_enc_name = Tk::Encoding::ENCODING_TABLE.get_name(loc_enc_obj)
- if loc_enc_name && loc_enc_name != tksys_enc_name
- # use locale_charmap
- enc_name = loc_enc_name
- else
- # use Tk.encoding_system
- enc_name = tksys_enc_name
- end
- rescue ArgumentError
- # unsupported encoding on Tk -> use Tk.encoding_system
- enc_name = tksys_enc_name
- end
- end
+ if Tk.encoding_system == 'cp932'
+ Tk.encoding = 'cp932'
else
- begin
- ext_enc_name = Tk::Encoding::ENCODING_TABLE.get_name(ext_enc_obj)
- if ext_enc_name && ext_enc_name != tksys_enc_name
- # use default_external
- enc_name = ext_enc_name
- else
- # use Tk.encoding_system
- enc_name = tksys_enc_name
- end
- rescue ArgumentError
- # unsupported encoding on Tk -> use Tk.encoding_system
- enc_name = tksys_enc_name
- end
+ Tk.encoding = 'shiftjis'
+ Tk.encoding_system = 'shiftjis'
end
+ rescue StandardError, NameError
+ Tk.encoding = 'shiftjis'
+ Tk.encoding_system = 'shiftjis'
+ end
+ when /^u/i # UTF8
+ Tk.encoding = 'utf-8'
+ Tk.encoding_system = 'utf-8'
+ else # NONE
+ if defined? DEFAULT_TK_ENCODING
+ Tk.encoding_system = DEFAULT_TK_ENCODING
+ end
+ begin
+ Tk.encoding = Tk.encoding_system
+ rescue StandardError, NameError
+ Tk.encoding = 'utf-8'
+ Tk.encoding_system = 'utf-8'
end
-
- Tk.default_encoding = (enc_name)? enc_name: tksys_enc_name
end
else
# dummy methods
- module Tk
- module Encoding
- extend Encoding
+ class TclTkIp
+ attr_accessor :encoding
- def force_default_encoding=(mode)
- nil
- end
+ alias __eval _eval
+ alias __invoke _invoke
- def force_default_encoding?
- nil
- end
+ alias _eval_with_enc _eval
+ alias _invoke_with_enc _invoke
+ end
- def default_encoding=(enc)
- nil
- end
- def default_encoding
- nil
- end
+ module Tk
+ module Encoding
+ extend Encoding
def encoding=(name)
nil
@@ -3113,16 +2487,6 @@ else
extend Encoding
end
-
- class TclTkIp
- attr_accessor :encoding
-
- alias __eval _eval
- alias __invoke _invoke
-
- alias _eval_with_enc _eval
- alias _invoke_with_enc _invoke
- end
end
@@ -3245,15 +2609,7 @@ module TkTreatFont
next
else
fnt = hash_kv(fnt) if fnt.kind_of?(Hash)
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- tk_call(*(__config_cmd << "-#{optkey}" << fnt))
- else
- begin
- tk_call(*(__config_cmd << "-#{optkey}" << fnt))
- rescue
- # ignore
- end
- end
+ tk_call(*(__config_cmd << "-#{optkey}" << fnt))
end
end
next
@@ -3307,15 +2663,7 @@ module TkTreatFont
fobj = fontobj # create a new TkFont object
else
ltn = hash_kv(ltn) if ltn.kind_of?(Hash)
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- tk_call(*(__config_cmd << "-#{optkey}" << ltn))
- else
- begin
- tk_call(*(__config_cmd << "-#{optkey}" << ltn))
- rescue => e
- # ignore
- end
- end
+ tk_call(*(__config_cmd << "-#{optkey}" << ltn))
next
end
@@ -3367,15 +2715,7 @@ module TkTreatFont
fobj = fontobj # create a new TkFont object
else
knj = hash_kv(knj) if knj.kind_of?(Hash)
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- tk_call(*(__config_cmd << "-#{optkey}" << knj))
- else
- begin
- tk_call(*(__config_cmd << "-#{optkey}" << knj))
- rescue => e
- # ignore
- end
- end
+ tk_call(*(__config_cmd << "-#{optkey}" << knj))
next
end
@@ -3476,14 +2816,6 @@ module TkConfigMethod
include TkUtil
include TkTreatFont
- def TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- @mode || false
- end
- def TkConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode)
- fail SecurityError, "can't change the mode" if $SAFE>=4
- @mode = (mode)? true: false
- end
-
def __cget_cmd
[self.path, 'cget']
end
@@ -3505,11 +2837,6 @@ module TkConfigMethod
end
private :__configinfo_struct
- def __optkey_aliases
- {}
- end
- private :__optkey_aliases
-
def __numval_optkeys
[]
end
@@ -3616,7 +2943,7 @@ module TkConfigMethod
val
end
- def __cget_core(slot)
+ def cget(slot)
orig_slot = slot
slot = slot.to_s
@@ -3624,11 +2951,6 @@ module TkConfigMethod
fail ArgumentError, "Invalid option `#{orig_slot.inspect}'"
end
- alias_name, real_name = __optkey_aliases.find{|k, v| k.to_s == slot}
- if real_name
- slot = real_name.to_s
- end
-
if ( method = _symbolkey2str(__val2ruby_optkeys())[slot] )
optval = tk_call_without_enc(*(__cget_cmd << "-#{slot}"))
begin
@@ -3697,41 +3019,11 @@ module TkConfigMethod
tk_tcl2ruby(tk_call_without_enc(*(__cget_cmd << "-#{slot}")), true)
end
end
- private :__cget_core
- def cget(slot)
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- __cget_core(slot)
- else
- begin
- __cget_core(slot)
- rescue => e
- if current_configinfo.has_key?(slot.to_s)
- # error on known option
- fail e
- else
- # unknown option
- nil
- end
- end
- end
- end
- def cget_strict(slot)
- # never use TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- __cget_core(slot)
- end
-
- def __configure_core(slot, value=None)
+ def configure(slot, value=None)
if slot.kind_of? Hash
slot = _symbolkey2str(slot)
- __optkey_aliases.each{|alias_name, real_name|
- alias_name = alias_name.to_s
- if slot.has_key?(alias_name)
- slot[real_name.to_s] = slot.delete(alias_name)
- end
- }
-
__methodcall_optkeys.each{|key, method|
value = slot.delete(key.to_s)
self.__send__(method, value) if value
@@ -3768,11 +3060,6 @@ module TkConfigMethod
fail ArgumentError, "Invalid option `#{orig_slot.inspect}'"
end
- alias_name, real_name = __optkey_aliases.find{|k, v| k.to_s == slot}
- if real_name
- slot = real_name.to_s
- end
-
if ( conf = __keyonly_optkeys.find{|k, v| k.to_s == slot} )
defkey, undefkey = conf
if value
@@ -3796,55 +3083,12 @@ module TkConfigMethod
end
self
end
- private :__configure_core
-
- def __check_available_configure_options(keys)
- availables = self.current_configinfo.keys
-
- # add non-standard keys
- availables |= __font_optkeys.map{|k|
- [k.to_s, "latin#{k}", "ascii#{k}", "kanji#{k}"]
- }.flatten
- availables |= __methodcall_optkeys.keys.map{|k| k.to_s}
- availables |= __keyonly_optkeys.keys.map{|k| k.to_s}
-
- keys = _symbolkey2str(keys)
- keys.delete_if{|k, v| !(availables.include?(k))}
- end
-
- def configure(slot, value=None)
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- __configure_core(slot, value)
- else
- if slot.kind_of?(Hash)
- begin
- __configure_core(slot)
- rescue
- slot = __check_available_configure_options(slot)
- __configure_core(slot) unless slot.empty?
- end
- else
- begin
- __configure_core(slot, value)
- rescue => e
- if current_configinfo.has_key?(slot.to_s)
- # error on known option
- fail e
- else
- # unknown option
- nil
- end
- end
- end
- end
- self
- end
def configure_cmd(slot, value)
configure(slot, install_cmd(value))
end
- def __configinfo_core(slot = nil)
+ def configinfo(slot = nil)
if TkComm::GET_CONFIGINFO_AS_ARRAY
if (slot &&
slot.to_s =~ /^(|latin|ascii|kanji)(#{__font_optkeys.join('|')})$/)
@@ -3855,10 +3099,6 @@ module TkConfigMethod
conf[__configinfo_struct[:key]][1..-1]
if ( ! __configinfo_struct[:alias] \
|| conf.size > __configinfo_struct[:alias] + 1 )
- fnt = conf[__configinfo_struct[:default_value]]
- if TkFont.is_system_font?(fnt)
- conf[__configinfo_struct[:default_value]] = TkNamedFont.new(fnt)
- end
conf[__configinfo_struct[:current_value]] = fontobj(fontkey)
elsif ( __configinfo_struct[:alias] \
&& conf.size == __configinfo_struct[:alias] + 1 \
@@ -3870,12 +3110,6 @@ module TkConfigMethod
else
if slot
slot = slot.to_s
-
- alias_name, real_name = __optkey_aliases.find{|k, v| k.to_s == slot}
- if real_name
- slot = real_name.to_s
- end
-
case slot
when /^(#{__val2ruby_optkeys().keys.join('|')})$/
method = _symbolkey2str(__val2ruby_optkeys())[slot]
@@ -4201,11 +3435,6 @@ module TkConfigMethod
fontconf = ret.assoc(optkey)
if fontconf && fontconf.size > 2
ret.delete_if{|inf| inf[0] =~ /^(|latin|ascii|kanji)#{optkey}$/}
- fnt = fontconf[__configinfo_struct[:default_value]]
- if TkFont.is_system_font?(fnt)
- fontconf[__configinfo_struct[:default_value]] \
- = TkNamedFont.new(fnt)
- end
fontconf[__configinfo_struct[:current_value]] = fontobj(optkey)
ret.push(fontconf)
end
@@ -4230,10 +3459,6 @@ module TkConfigMethod
if ( ! __configinfo_struct[:alias] \
|| conf.size > __configinfo_struct[:alias] + 1 )
- fnt = conf[__configinfo_struct[:default_value]]
- if TkFont.is_system_font?(fnt)
- conf[__configinfo_struct[:default_value]] = TkNamedFont.new(fnt)
- end
conf[__configinfo_struct[:current_value]] = fontobj(fontkey)
{ conf.shift => conf }
elsif ( __configinfo_struct[:alias] \
@@ -4249,12 +3474,6 @@ module TkConfigMethod
else
if slot
slot = slot.to_s
-
- alias_name, real_name = __optkey_aliases.find{|k, v| k.to_s == slot}
- if real_name
- slot = real_name.to_s
- end
-
case slot
when /^(#{__val2ruby_optkeys().keys.join('|')})$/
method = _symbolkey2str(__val2ruby_optkeys())[slot]
@@ -4587,11 +3806,6 @@ module TkConfigMethod
ret.delete('latin' << optkey)
ret.delete('ascii' << optkey)
ret.delete('kanji' << optkey)
- fnt = fontconf[__configinfo_struct[:default_value]]
- if TkFont.is_system_font?(fnt)
- fontconf[__configinfo_struct[:default_value]] \
- = TkNamedFont.new(fnt)
- end
fontconf[__configinfo_struct[:current_value]] = fontobj(optkey)
ret[optkey] = fontconf
end
@@ -4606,19 +3820,6 @@ module TkConfigMethod
end
end
end
- private :__configinfo_core
-
- def configinfo(slot = nil)
- if slot && TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- begin
- __configinfo_core(slot)
- rescue
- Array.new(__configinfo_struct.values.max).unshift(slot.to_s)
- end
- else
- __configinfo_core(slot)
- end
- end
def current_configinfo(slot = nil)
if TkComm::GET_CONFIGINFO_AS_ARRAY
@@ -4718,12 +3919,7 @@ class TkObject<TkKernel
begin
cget(name)
rescue
- if self.kind_of?(TkWindow)
- fail NameError,
- "unknown option '#{id}' for #{self.inspect} (deleted widget?)"
- else
- super(id, *args)
- end
+ super(id, *args)
# fail NameError,
# "undefined local variable or method `#{name}' for #{self.to_s}",
# error_at
@@ -4778,15 +3974,6 @@ end
class TkWindow<TkObject
include TkWinfo
extend TkBindCore
- include Tk::Wm_for_General
-
- @@WIDGET_INSPECT_FULL = false
- def TkWindow._widget_inspect_full_?
- @@WIDGET_INSPECT_FULL
- end
- def TkWindow._widget_inspect_full_=(mode)
- @@WIDGET_INSPECT_FULL = (mode && true) || false
- end
TkCommandNames = [].freeze
## ==> If TkCommandNames[0] is a string (not a null string),
@@ -4850,13 +4037,6 @@ class TkWindow<TkObject
fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey)
}
- __optkey_aliases.each{|alias_name, real_name|
- alias_name = alias_name.to_s
- if keys.has_key?(alias_name)
- keys[real_name.to_s] = keys.delete(alias_name)
- end
- }
-
__methodcall_optkeys.each{|key|
key = key.to_s
methodkeys[key] = keys.delete(key) if keys.key?(key)
@@ -4889,48 +4069,13 @@ class TkWindow<TkObject
end
if keys and keys != None
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- tk_call_without_enc(cmd, @path, *hash_kv(keys, true))
- else
- begin
- tk_call_without_enc(cmd, @path, *hash_kv(keys, true))
- rescue => e
- tk_call_without_enc(cmd, @path)
- keys = __check_available_configure_options(keys)
- unless keys.empty?
- begin
- # try to configure
- configure(keys)
- rescue
- # fail => includes options adaptable when creattion only?
- begin
- tk_call_without_enc('destroy', @path)
- rescue
- # cannot rescue options error
- fail e
- else
- # re-create widget
- tk_call_without_enc(cmd, @path, *hash_kv(keys, true))
- end
- end
- end
- end
- end
+ tk_call_without_enc(cmd, @path, *hash_kv(keys, true))
else
tk_call_without_enc(cmd, @path)
end
end
private :create_self
- def inspect
- if @@WIDGET_INSPECT_FULL
- super
- else
- str = super
- str[0..(str.index(' '))] << '@path=' << @path.inspect << '>'
- end
- end
-
def exist?
TkWinfo.exist?(self)
end
@@ -5052,15 +4197,6 @@ class TkWindow<TkObject
self
end
- def grid_anchor(anchor=None)
- if anchor == None
- TkGrid.anchor(self)
- else
- TkGrid.anchor(self, anchor)
- self
- end
- end
-
def grid_forget
#tk_call('grid', 'forget', epath)
TkGrid.forget(self)
@@ -5092,14 +4228,12 @@ class TkWindow<TkObject
TkGrid.columnconfigure(self, index, keys)
end
alias grid_columnconfigure grid_columnconfig
- alias grid_column grid_columnconfig
def grid_rowconfig(index, keys)
#tk_call('grid', 'rowconfigure', epath, index, *hash_kv(keys))
TkGrid.rowconfigure(self, index, keys)
end
alias grid_rowconfigure grid_rowconfig
- alias grid_row grid_rowconfig
def grid_columnconfiginfo(index, slot=nil)
#if slot
@@ -5342,13 +4476,11 @@ class TkWindow<TkObject
end
children.each{|path, obj|
- obj.instance_eval{
- if defined?(@cmdtbl)
- for id in @cmdtbl
- uninstall_cmd id
- end
+ if defined?(@cmdtbl)
+ for id in @cmdtbl
+ uninstall_cmd id
end
- }
+ end
TkCore::INTERP.tk_windows.delete(path)
}
@@ -5453,7 +4585,7 @@ class TkWindow<TkObject
bindtags(bindtags().unshift(tag))
end
end
-TkWidget = TkWindow
+
# freeze core modules
#TclTkLib.freeze
@@ -5466,7 +4598,7 @@ TkWidget = TkWindow
#Tk.freeze
module Tk
- RELEASE_DATE = '2008-05-23'.freeze
+ RELEASE_DATE = '2007-01-26'.freeze
autoload :AUTO_PATH, 'tk/variable'
autoload :TCL_PACKAGE_PATH, 'tk/variable'
diff --git a/ext/tk/lib/tk/autoload.rb b/ext/tk/lib/tk/autoload.rb
index 0773f7708d..6b3773f4ea 100644
--- a/ext/tk/lib/tk/autoload.rb
+++ b/ext/tk/lib/tk/autoload.rb
@@ -1,19 +1,9 @@
#
# autoload
#
-############################################
-# geometry manager
-module Tk
- autoload :Grid, 'tk/grid'
- def Grid(*args); TkGrid.configure(*args); end
-
- autoload :Pack, 'tk/pack'
- def Pack(*args); TkPack.configure(*args); end
-
- autoload :Place, 'tk/place'
- def Place(*args); TkPlace.configure(*args); end
-end
+#######################
+# geometry manager
autoload :TkGrid, 'tk/grid'
def TkGrid(*args); TkGrid.configure(*args); end
@@ -24,117 +14,19 @@ autoload :TkPlace, 'tk/place'
def TkPlace(*args); TkPlace.configure(*args); end
-############################################
-# classes on Tk module
-module Tk
- autoload :Button, 'tk/button'
-
- autoload :Canvas, 'tk/canvas'
-
- autoload :CheckButton, 'tk/checkbutton'
- autoload :Checkbutton, 'tk/checkbutton'
-
- autoload :Entry, 'tk/entry'
-
- autoload :Frame, 'tk/frame'
-
- autoload :Label, 'tk/label'
-
- autoload :LabelFrame, 'tk/labelframe'
- autoload :Labelframe, 'tk/labelframe'
-
- autoload :Listbox, 'tk/listbox'
-
- autoload :Menu, 'tk/menu'
- autoload :MenuClone, 'tk/menu'
- autoload :CloneMenu, 'tk/menu'
- autoload :SystemMenu, 'tk/menu'
- autoload :SysMenu_Help, 'tk/menu'
- autoload :SysMenu_System, 'tk/menu'
- autoload :SysMenu_Apple, 'tk/menu'
- autoload :Menubutton, 'tk/menu'
- autoload :MenuButton, 'tk/menu'
- autoload :OptionMenubutton, 'tk/menu'
- autoload :OptionMenBbutton, 'tk/menu'
-
- autoload :Message, 'tk/message'
-
- autoload :PanedWindow, 'tk/panedwindow'
- autoload :Panedwindow, 'tk/panedwindow'
-
- autoload :RadioButton, 'tk/radiobutton'
- autoload :Radiobutton, 'tk/radiobutton'
-
- autoload :Root, 'tk/root'
-
- autoload :Scale, 'tk/scale'
-
- autoload :Scrollbar, 'tk/scrollbar'
- autoload :XScrollbar, 'tk/scrollbar'
- autoload :YScrollbar, 'tk/scrollbar'
-
- autoload :Spinbox, 'tk/spinbox'
-
- autoload :Text, 'tk/text'
-
- autoload :Toplevel, 'tk/toplevel'
-end
-
-
-############################################
-# sub-module of Tk
-module Tk
- autoload :Clock, 'tk/clock'
-
- autoload :OptionObj, 'tk/optionobj'
-
- autoload :X_Scrollable, 'tk/scrollable'
- autoload :Y_Scrollable, 'tk/scrollable'
- autoload :Scrollable, 'tk/scrollable'
-
- autoload :Wm, 'tk/wm'
- autoload :Wm_for_General, 'tk/wm'
-
- autoload :MacResource, 'tk/macpkg'
-
- autoload :WinDDE, 'tk/winpkg'
- autoload :WinRegistry, 'tk/winpkg'
-
- autoload :ValidateConfigure, 'tk/validation'
- autoload :ItemValidateConfigure, 'tk/validation'
-
- autoload :EncodedString, 'tk/encodedstr'
- def Tk.EncodedString(str, enc = nil); Tk::EncodedString.new(str, enc); end
-
- autoload :BinaryString, 'tk/encodedstr'
- def Tk.BinaryString(str); Tk::BinaryString.new(str); end
-
- autoload :UTF8_String, 'tk/encodedstr'
- def Tk.UTF8_String(str); Tk::UTF8_String.new(str); end
-
-end
-
-
-############################################
-# toplevel classes/modules (fixed)
+#######################
+# others
autoload :TkBgError, 'tk/bgerror'
autoload :TkBindTag, 'tk/bindtag'
autoload :TkBindTagAll, 'tk/bindtag'
autoload :TkDatabaseClass, 'tk/bindtag'
+autoload :TkButton, 'tk/button'
+
autoload :TkConsole, 'tk/console'
-autoload :TkcItem, 'tk/canvas'
-autoload :TkcArc, 'tk/canvas'
-autoload :TkcBitmap, 'tk/canvas'
-autoload :TkcImage, 'tk/canvas'
-autoload :TkcLine, 'tk/canvas'
-autoload :TkcOval, 'tk/canvas'
-autoload :TkcPolygon, 'tk/canvas'
-autoload :TkcRectangle, 'tk/canvas'
-autoload :TkcText, 'tk/canvas'
-autoload :TkcWindow, 'tk/canvas'
+autoload :TkCanvas, 'tk/canvas'
autoload :TkcTagAccess, 'tk/canvastag'
autoload :TkcTag, 'tk/canvastag'
@@ -144,6 +36,9 @@ autoload :TkcTagAll, 'tk/canvastag'
autoload :TkcTagCurrent, 'tk/canvastag'
autoload :TkcTagGroup, 'tk/canvastag'
+autoload :TkCheckButton, 'tk/checkbutton'
+autoload :TkCheckbutton, 'tk/checkbutton'
+
autoload :TkClipboard, 'tk/clipboard'
autoload :TkComposite, 'tk/composite'
@@ -157,10 +52,14 @@ autoload :TkWarning, 'tk/dialog'
autoload :TkWarning2, 'tk/dialog'
autoload :TkWarningObj, 'tk/dialog'
+autoload :TkEntry, 'tk/entry'
+
autoload :TkEvent, 'tk/event'
autoload :TkFont, 'tk/font'
-autoload :TkNamedFont, 'tk/font'
+autoload :TkTreatTagFont, 'tk/font'
+
+autoload :TkFrame, 'tk/frame'
autoload :TkImage, 'tk/image'
autoload :TkBitmapImage, 'tk/image'
@@ -172,12 +71,30 @@ autoload :TkTreatItemFont, 'tk/itemfont'
autoload :TkKinput, 'tk/kinput'
+autoload :TkLabel, 'tk/label'
+
+autoload :TkLabelFrame, 'tk/labelframe'
+autoload :TkLabelframe, 'tk/labelframe'
+
+autoload :TkListbox, 'tk/listbox'
+
+autoload :TkMacResource, 'tk/macpkg'
+
+autoload :TkMenu, 'tk/menu'
+autoload :TkMenuClone, 'tk/menu'
autoload :TkSystemMenu, 'tk/menu'
+autoload :TkSysMenu_Help, 'tk/menu'
+autoload :TkSysMenu_System, 'tk/menu'
+autoload :TkSysMenu_Apple, 'tk/menu'
+autoload :TkMenubutton, 'tk/menu'
+autoload :TkOptionMenubutton, 'tk/menu'
autoload :TkMenubar, 'tk/menubar'
autoload :TkMenuSpec, 'tk/menuspec'
+autoload :TkMessage, 'tk/message'
+
autoload :TkManageFocus, 'tk/mngfocus'
autoload :TkMsgCatalog, 'tk/msgcat'
@@ -193,46 +110,53 @@ autoload :TkPackage, 'tk/package'
autoload :TkPalette, 'tk/palette'
+autoload :TkPanedWindow, 'tk/panedwindow'
+autoload :TkPanedwindow, 'tk/panedwindow'
+
+autoload :TkRadioButton, 'tk/radiobutton'
+autoload :TkRadiobutton, 'tk/radiobutton'
+
autoload :TkRoot, 'tk/root'
+autoload :TkScale, 'tk/scale'
+
+autoload :TkScrollbar, 'tk/scrollbar'
+autoload :TkXScrollbar, 'tk/scrollbar'
+autoload :TkYScrollbar, 'tk/scrollbar'
+
autoload :TkScrollbox, 'tk/scrollbox'
autoload :TkSelection, 'tk/selection'
+autoload :TkSpinbox, 'tk/spinbox'
+
autoload :TkTreatTagFont, 'tk/tagfont'
+autoload :TkText, 'tk/text'
+
autoload :TkTextImage, 'tk/textimage'
-autoload :TktImage, 'tk/textimage'
autoload :TkTextMark, 'tk/textmark'
autoload :TkTextNamedMark, 'tk/textmark'
autoload :TkTextMarkInsert, 'tk/textmark'
autoload :TkTextMarkCurrent, 'tk/textmark'
autoload :TkTextMarkAnchor, 'tk/textmark'
-autoload :TktMark, 'tk/textmark'
-autoload :TktNamedMark, 'tk/textmark'
-autoload :TktMarkInsert, 'tk/textmark'
-autoload :TktMarkCurrent, 'tk/textmark'
-autoload :TktMarkAnchor, 'tk/textmark'
autoload :TkTextTag, 'tk/texttag'
autoload :TkTextNamedTag, 'tk/texttag'
autoload :TkTextTagSel, 'tk/texttag'
-autoload :TktTag, 'tk/texttag'
-autoload :TktNamedTag, 'tk/texttag'
-autoload :TktTagSel, 'tk/texttag'
autoload :TkTextWindow, 'tk/textwindow'
-autoload :TktWindow, 'tk/textwindow'
autoload :TkAfter, 'tk/timer'
autoload :TkTimer, 'tk/timer'
autoload :TkRTTimer, 'tk/timer'
+autoload :TkToplevel, 'tk/toplevel'
+
autoload :TkTextWin, 'tk/txtwin_abst'
autoload :TkValidation, 'tk/validation'
-autoload :TkValidateCommand, 'tk/validation'
autoload :TkVariable, 'tk/variable'
autoload :TkVarAccess, 'tk/variable'
@@ -242,173 +166,31 @@ autoload :TkNamedVirtualEvent,'tk/virtevent'
autoload :TkWinfo, 'tk/winfo'
+autoload :TkWinDDE, 'tk/winpkg'
+autoload :TkWinRegistry, 'tk/winpkg'
+
autoload :TkXIM, 'tk/xim'
-############################################
-# toplevel classes/modules (switchable)
+#######################
+# sub-module of Tk
module Tk
- @TOPLEVEL_ALIAS_TABLE = {}
- @TOPLEVEL_ALIAS_TABLE[:Tk] = {
- :TkButton => 'tk/button',
-
- :TkCanvas => 'tk/canvas',
-
- :TkCheckButton => 'tk/checkbutton',
- :TkCheckbutton => 'tk/checkbutton',
-
- # :TkDialog => 'tk/dialog',
- # :TkDialog2 => 'tk/dialog',
- # :TkDialogObj => 'tk/dialog',
- # :TkWarning => 'tk/dialog',
- # :TkWarning2 => 'tk/dialog',
- # :TkWarningObj => 'tk/dialog',
-
- :TkEntry => 'tk/entry',
-
- :TkFrame => 'tk/frame',
-
- :TkLabel => 'tk/label',
-
- :TkLabelFrame => 'tk/labelframe',
- :TkLabelframe => 'tk/labelframe',
-
- :TkListbox => 'tk/listbox',
-
- :TkMacResource => 'tk/macpkg',
-
- :TkMenu => 'tk/menu',
- :TkMenuClone => 'tk/menu',
- :TkCloneMenu => 'tk/menu',
- # :TkSystemMenu => 'tk/menu',
- :TkSysMenu_Help => 'tk/menu',
- :TkSysMenu_System => 'tk/menu',
- :TkSysMenu_Apple => 'tk/menu',
- :TkMenubutton => 'tk/menu',
- :TkMenuButton => 'tk/menu',
- :TkOptionMenubutton => 'tk/menu',
- :TkOptionMenuButton => 'tk/menu',
-
- :TkMessage => 'tk/message',
-
- :TkPanedWindow => 'tk/panedwindow',
- :TkPanedwindow => 'tk/panedwindow',
-
- :TkRadioButton => 'tk/radiobutton',
- :TkRadiobutton => 'tk/radiobutton',
-
- # :TkRoot => 'tk/root',
-
- :TkScale => 'tk/scale',
-
- :TkScrollbar => 'tk/scrollbar',
- :TkXScrollbar => 'tk/scrollbar',
- :TkYScrollbar => 'tk/scrollbar',
-
- :TkSpinbox => 'tk/spinbox',
-
- :TkText => 'tk/text',
-
- :TkToplevel => 'tk/toplevel',
-
- :TkWinDDE => 'tk/winpkg',
- :TkWinRegistry => 'tk/winpkg',
- }
-
- @TOPLEVEL_ALIAS_OWNER = {}
-
- @TOPLEVEL_ALIAS_SETUP_PROC = {}
-
- @current_default_widget_set = nil
-end
-
-
-############################################
-# methods to control default widget set
-############################################
-
-class << Tk
- def default_widget_set
- @current_default_widget_set
- end
-
- def default_widget_set=(target)
- target = target.to_sym
- return target if target == @current_default_widget_set
-
- if (cmd = @TOPLEVEL_ALIAS_SETUP_PROC[target])
- cmd.call(target)
- end
-
- _replace_toplevel_aliases(target)
- end
-
- def __set_toplevel_aliases__(target, obj, *symbols)
- @TOPLEVEL_ALIAS_TABLE[target = target.to_sym] ||= {}
- symbols.each{|sym|
- @TOPLEVEL_ALIAS_TABLE[target][sym = sym.to_sym] = obj
- # if @current_default_widget_set == target
- if @TOPLEVEL_ALIAS_OWNER[sym] == target
- Object.class_eval{remove_const sym} if Object.const_defined?(sym)
- Object.const_set(sym, obj)
- end
- }
- end
-
- ###################################
- private
- def _replace_toplevel_aliases(target)
- # check already autoloaded
- if (table = @TOPLEVEL_ALIAS_TABLE[current = @current_default_widget_set])
- table.each{|sym, file|
- if !Object.autoload?(sym) && Object.const_defined?(sym) &&
- @TOPLEVEL_ALIAS_TABLE[current][sym].kind_of?(String)
- # autoload -> class
- @TOPLEVEL_ALIAS_TABLE[current][sym] = Object.const_get(sym)
- end
- }
- end
-
- # setup autoloads
- @TOPLEVEL_ALIAS_TABLE[target].each{|sym, file|
- Object.class_eval{remove_const sym} if Object.const_defined?(sym)
- if file.kind_of?(String)
- # file => autoload target file
- Object.autoload(sym, file)
- else
- # file => loaded class object
- Object.const_set(sym, file)
- end
- @TOPLEVEL_ALIAS_OWNER[sym] = target
- }
-
- # update current alias
- @current_default_widget_set = target
- end
-end
-
-############################################
-# setup default widget set => :Tk
-Tk.default_widget_set = :Tk
+ autoload :Clock, 'tk/clock'
+ autoload :OptionObj, 'tk/optionobj'
+ autoload :X_Scrollable, 'tk/scrollable'
+ autoload :Y_Scrollable, 'tk/scrollable'
+ autoload :Scrollable, 'tk/scrollable'
+ autoload :Wm, 'tk/wm'
+ autoload :ValidateConfigure, 'tk/validation'
+ autoload :ItemValidateConfigure, 'tk/validation'
-############################################
-# depend on the version of Tcl/Tk
-# major, minor, type, type_name, patchlevel = TclTkLib.get_version
+ autoload :EncodedString, 'tk/encodedstr'
+ def Tk.EncodedString(str, enc = nil); Tk::EncodedString.new(str, enc); end
-############################################
-# Ttk (Tile) support
-=begin
-if major > 8 ||
- (major == 8 && minor > 5) ||
- (major == 8 && minor == 5 && type >= TclTkLib::RELEASE_TYPE::BETA)
- # Tcl/Tk 8.5 beta or later
- Object.autoload :Ttk, 'tkextlib/tile'
- Tk.autoload :Tile, 'tkextlib/tile'
+ autoload :BinaryString, 'tk/encodedstr'
+ def Tk.BinaryString(str); Tk::BinaryString.new(str); end
- require 'tk/ttk_selector'
+ autoload :UTF8_String, 'tk/encodedstr'
+ def Tk.UTF8_String(str); Tk::UTF8_String.new(str); end
end
-=end
-Object.autoload :Ttk, 'tkextlib/tile'
-Tk.autoload :Tile, 'tkextlib/tile'
-require 'tk/ttk_selector'
diff --git a/ext/tk/lib/tk/bindtag.rb b/ext/tk/lib/tk/bindtag.rb
index 88c8367a88..9023a08e06 100644
--- a/ext/tk/lib/tk/bindtag.rb
+++ b/ext/tk/lib/tk/bindtag.rb
@@ -8,64 +8,30 @@ class TkBindTag
#BTagID_TBL = {}
BTagID_TBL = TkCore::INTERP.create_table
+ Tk_BINDTAG_ID = ["btag".freeze, "00000".taint].freeze
- (Tk_BINDTAG_ID = ["btag".freeze, "00000".taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- BTagID_TBL.mutex.synchronize{ BTagID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ BTagID_TBL.clear }
def TkBindTag.id2obj(id)
- BTagID_TBL.mutex.synchronize{
- (BTagID_TBL[id])? BTagID_TBL[id]: id
- }
+ BTagID_TBL[id]? BTagID_TBL[id]: id
end
-=begin
def TkBindTag.new_by_name(name, *args, &b)
- BTagID_TBL.mutex.synchronize{
- return BTagID_TBL[name] if BTagID_TBL[name]
- }
-
+ return BTagID_TBL[name] if BTagID_TBL[name]
self.new.instance_eval{
- BTagID_TBL.mutex.synchronize{
- BTagID_TBL.delete @id
- @id = name
- BTagID_TBL[@id] = self
- }
+ BTagID_TBL.delete @id
+ @id = name
+ BTagID_TBL[@id] = self
bind(*args, &b) if args != []
self
}
end
-=end
- def TkBindTag.new_by_name(name, *args, &b)
- obj = nil
- BTagID_TBL.mutex.synchronize{
- if BTagID_TBL[name]
- obj = BTagID_TBL[name]
- else
- (obj = BTagID_TBL[name] = self.allocate).instance_eval{
- @id = name
- }
- end
- }
- bind(*args, &b) if obj && args != []
- obj
- end
def initialize(*args, &b)
- Tk_BINDTAG_ID.mutex.synchronize{
- # @id = Tk_BINDTAG_ID.join('')
- @id = Tk_BINDTAG_ID.join(TkCore::INTERP._ip_id_)
- Tk_BINDTAG_ID[1].succ!
- }
- BTagID_TBL.mutex.synchronize{
- BTagID_TBL[@id] = self
- }
+ # @id = Tk_BINDTAG_ID.join('')
+ @id = Tk_BINDTAG_ID.join(TkCore::INTERP._ip_id_)
+ Tk_BINDTAG_ID[1].succ!
+ BTagID_TBL[@id] = self
bind(*args, &b) if args != []
end
@@ -97,37 +63,14 @@ end
class TkDatabaseClass<TkBindTag
-=begin
def self.new(name, *args, &b)
- BTagID_TBL.mutex.synchronize{
- return BTagID_TBL[name] if BTagID_TBL[name]
- }
+ return BTagID_TBL[name] if BTagID_TBL[name]
super(name, *args, &b)
end
def initialize(name, *args, &b)
@id = name
- BTagID_TBL.mutex.synchronize{
- BTagID_TBL[@id] = self
- }
- bind(*args, &b) if args != []
- end
-=end
- def self.new(name, *args, &b)
- BTagID_TBL.mutex.synchronize{
- if BTagID_TBL[name]
- BTagID_TBL[name]
- else
- BTagID_TBL[name] = self.allocate.instance_eval{
- initialize(name, *args, &b)
- self
- }
- end
- }
- end
-
- def initialize(name, *args, &b)
- @id = name
+ BTagID_TBL[@id] = self
bind(*args, &b) if args != []
end
diff --git a/ext/tk/lib/tk/button.rb b/ext/tk/lib/tk/button.rb
index 770a5785bb..407a47c400 100644
--- a/ext/tk/lib/tk/button.rb
+++ b/ext/tk/lib/tk/button.rb
@@ -4,7 +4,7 @@
require 'tk'
require 'tk/label'
-class Tk::Button<Tk::Label
+class TkButton<TkLabel
TkCommandNames = ['button'.freeze].freeze
WidgetClassName = 'Button'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -25,6 +25,3 @@ class Tk::Button<Tk::Label
self
end
end
-
-#TkButton = Tk::Button unless Object.const_defined? :TkButton
-Tk.__set_toplevel_aliases__(:Tk, Tk::Button, :TkButton)
diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb
index 36ea008a17..c30fd79bb9 100644
--- a/ext/tk/lib/tk/canvas.rb
+++ b/ext/tk/lib/tk/canvas.rb
@@ -1,5 +1,6 @@
#
# tk/canvas.rb - Tk canvas classes
+# $Date$
# by Yukihiro Matsumoto <matz@caelum.co.jp>
#
require 'tk'
@@ -39,7 +40,7 @@ module TkCanvasItemConfig
private :__item_pathname
end
-class Tk::Canvas<TkWindow
+class TkCanvas<TkWindow
include TkCanvasItemConfig
include Tk::Scrollable
@@ -168,8 +169,6 @@ class Tk::Canvas<TkWindow
#tk_tcl2ruby(tk_send_without_enc('canvasy', screen_y, *args))
number(tk_send_without_enc('canvasy', screen_y, *args))
end
- alias canvas_x canvasx
- alias canvas_y canvasy
def coords(tag, *args)
if args == []
@@ -187,17 +186,11 @@ class Tk::Canvas<TkWindow
end
def delete(*args)
- tbl = nil
- TkcItem::CItemID_TBL.mutex.synchronize{
- tbl = TkcItem::CItemID_TBL[self.path]
- }
- if tbl
+ if TkcItem::CItemID_TBL[self.path]
args.each{|tag|
find('withtag', tag).each{|item|
if item.kind_of?(TkcItem)
- TkcItem::CItemID_TBL.mutex.synchronize{
- tbl.delete(item.id)
- }
+ TkcItem::CItemID_TBL[self.path].delete(item.id)
end
}
}
@@ -580,10 +573,6 @@ class Tk::Canvas<TkWindow
end
end
-#TkCanvas = Tk::Canvas unless Object.const_defined? :TkCanvas
-Tk.__set_toplevel_aliases__(:Tk, Tk::Canvas, :TkCanvas)
-
-
class TkcItem<TkObject
extend Tk
include TkcTagAccess
@@ -592,12 +581,9 @@ class TkcItem<TkObject
CItemTypeName = nil
CItemTypeToClass = {}
-
CItemID_TBL = TkCore::INTERP.create_table
- TkCore::INTERP.init_ip_env{
- CItemID_TBL.mutex.synchronize{ CItemID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ CItemID_TBL.clear }
def TkcItem.type2class(type)
CItemTypeToClass[type]
@@ -605,13 +591,8 @@ class TkcItem<TkObject
def TkcItem.id2obj(canvas, id)
cpath = canvas.path
- CItemID_TBL.mutex.synchronize{
- if CItemID_TBL[cpath]
- CItemID_TBL[cpath][id]? CItemID_TBL[cpath][id]: id
- else
- id
- end
- }
+ return id unless CItemID_TBL[cpath]
+ CItemID_TBL[cpath][id]? CItemID_TBL[cpath][id]: id
end
########################################
@@ -644,13 +625,6 @@ class TkcItem<TkObject
fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey)
}
- __item_optkey_aliases(nil).each{|alias_name, real_name|
- alias_name = alias_name.to_s
- if keys.has_key?(alias_name)
- keys[real_name.to_s] = keys.delete(alias_name)
- end
- }
-
__item_methodcall_optkeys(nil).each{|key|
key = key.to_s
methodkeys[key] = keys.delete(key) if keys.key?(key)
@@ -684,17 +658,15 @@ class TkcItem<TkObject
########################################
def initialize(parent, *args)
- #unless parent.kind_of?(Tk::Canvas)
- # fail ArgumentError, "expect Tk::Canvas for 1st argument"
+ #unless parent.kind_of?(TkCanvas)
+ # fail ArgumentError, "expect TkCanvas for 1st argument"
#end
@parent = @c = parent
@path = parent.path
@id = create_self(*args) # an integer number as 'canvas item id'
- CItemID_TBL.mutex.synchronize{
- CItemID_TBL[@path] = {} unless CItemID_TBL[@path]
- CItemID_TBL[@path][@id] = self
- }
+ CItemID_TBL[@path] = {} unless CItemID_TBL[@path]
+ CItemID_TBL[@path][@id] = self
end
def create_self(*args)
self.class.create(@c, *args) # return an integer number as 'canvas item id'
@@ -715,9 +687,7 @@ class TkcItem<TkObject
def delete
@c.delete @id
- CItemID_TBL.mutex.synchronize{
- CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path]
- }
+ CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path]
self
end
alias remove delete
diff --git a/ext/tk/lib/tk/canvastag.rb b/ext/tk/lib/tk/canvastag.rb
index 49796d80b2..a5650ee68b 100644
--- a/ext/tk/lib/tk/canvastag.rb
+++ b/ext/tk/lib/tk/canvastag.rb
@@ -63,9 +63,6 @@ module TkcTagAccess
def cget(option)
@c.itemcget(@id, option)
end
- def cget_strict(option)
- @c.itemcget_strict(@id, option)
- end
def configure(key, value=None)
@c.itemconfigure(@id, key, value)
@@ -202,26 +199,14 @@ class TkcTag<TkObject
include TkcTagAccess
CTagID_TBL = TkCore::INTERP.create_table
+ Tk_CanvasTag_ID = ['ctag'.freeze, '00000'.taint].freeze
- (Tk_CanvasTag_ID = ['ctag'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- CTagID_TBL.mutex.synchronize{ CTagID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ CTagID_TBL.clear }
def TkcTag.id2obj(canvas, id)
cpath = canvas.path
- CTagID_TBL.mutex.synchronize{
- if CTagID_TBL[cpath]
- CTagID_TBL[cpath][id]? CTagID_TBL[cpath][id]: id
- else
- id
- end
- }
+ return id unless CTagID_TBL[cpath]
+ CTagID_TBL[cpath][id]? CTagID_TBL[cpath][id]: id
end
def initialize(parent, mode=nil, *args)
@@ -230,15 +215,11 @@ class TkcTag<TkObject
#end
@c = parent
@cpath = parent.path
- Tk_CanvasTag_ID.mutex.synchronize{
- # @path = @id = Tk_CanvasTag_ID.join('')
- @path = @id = Tk_CanvasTag_ID.join(TkCore::INTERP._ip_id_)
- Tk_CanvasTag_ID[1].succ!
- }
- CTagID_TBL.mutex.synchronize{
- CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
- CTagID_TBL[@cpath][@id] = self
- }
+ # @path = @id = Tk_CanvasTag_ID.join('')
+ @path = @id = Tk_CanvasTag_ID.join(TkCore::INTERP._ip_id_)
+ CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
+ CTagID_TBL[@cpath][@id] = self
+ Tk_CanvasTag_ID[1].succ!
if mode
tk_call_without_enc(@c.path, "addtag", @id, mode, *args)
end
@@ -257,9 +238,7 @@ class TkcTag<TkObject
def delete
@c.delete @id
- CTagID_TBL.mutex.synchronize{
- CTagID_TBL[@cpath].delete(@id) if CTagID_TBL[@cpath]
- }
+ CTagID_TBL[@cpath].delete(@id) if CTagID_TBL[@cpath]
self
end
alias remove delete
@@ -309,38 +288,23 @@ class TkcTag<TkObject
end
class TkcTagString<TkcTag
- def self.new(parent, name, mode=nil, *args)
- obj = nil
- CTagID_TBL.mutex.synchronize{
- if CTagID_TBL[parent.path] && CTagID_TBL[parent.path][name]
- obj = CTagID_TBL[parent.path][name]
- else
- # super(parent, name, *args)
- (obj = self.allocate).instance_eval{
- @c = parent
- @cpath = parent.path
- @path = @id = name
- CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
- CTagID_TBL[@cpath][@id] = self
- }
- end
- }
- if obj && mode
- tk_call_without_enc(@c.path, "addtag", @id, mode, *args)
+ def self.new(parent, name, *args)
+ if CTagID_TBL[parent.path] && CTagID_TBL[parent.path][name]
+ return CTagID_TBL[parent.path][name]
+ else
+ super(parent, name, *args)
end
- obj
end
def initialize(parent, name, mode=nil, *args)
- # dummy:: not called by 'new' method
-
#unless parent.kind_of?(TkCanvas)
# fail ArgumentError, "expect TkCanvas for 1st argument"
#end
@c = parent
@cpath = parent.path
@path = @id = name
-
+ CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
+ CTagID_TBL[@cpath][@id] = self
if mode
tk_call_without_enc(@c.path, "addtag", @id, mode, *args)
end
@@ -348,11 +312,7 @@ class TkcTagString<TkcTag
end
TkcNamedTag = TkcTagString
-class TkcTagAll<TkcTagString
- def self.new(parent)
- super(parent, 'all')
- end
-=begin
+class TkcTagAll<TkcTag
def initialize(parent)
#unless parent.kind_of?(TkCanvas)
# fail ArgumentError, "expect TkCanvas for 1st argument"
@@ -360,19 +320,12 @@ class TkcTagAll<TkcTagString
@c = parent
@cpath = parent.path
@path = @id = 'all'
- CTagID_TBL.mutex.synchronize{
- CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
- CTagID_TBL[@cpath][@id] = self
- }
+ CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
+ CTagID_TBL[@cpath][@id] = self
end
-=end
end
-class TkcTagCurrent<TkcTagString
- def self.new(parent)
- super(parent, 'current')
- end
-=begin
+class TkcTagCurrent<TkcTag
def initialize(parent)
#unless parent.kind_of?(TkCanvas)
# fail ArgumentError, "expect TkCanvas for 1st argument"
@@ -380,21 +333,13 @@ class TkcTagCurrent<TkcTagString
@c = parent
@cpath = parent.path
@path = @id = 'current'
- CTagID_TBL.mutex.synchronize{
- CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
- CTagID_TBL[@cpath][@id] = self
- }
+ CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
+ CTagID_TBL[@cpath][@id] = self
end
-=end
end
class TkcGroup<TkcTag
- (Tk_cGroup_ID = ['tkcg'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
+ Tk_cGroup_ID = ['tkcg'.freeze, '00000'.taint].freeze
#def create_self(parent, *args)
def initialize(parent, *args)
#unless parent.kind_of?(TkCanvas)
@@ -402,15 +347,11 @@ class TkcGroup<TkcTag
#end
@c = parent
@cpath = parent.path
- Tk_cGroup_ID.mutex.synchronize{
- # @path = @id = Tk_cGroup_ID.join('')
- @path = @id = Tk_cGroup_ID.join(TkCore::INTERP._ip_id_)
- Tk_cGroup_ID[1].succ!
- }
- CTagID_TBL.mutex.synchronize{
- CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
- CTagID_TBL[@cpath][@id] = self
- }
+ # @path = @id = Tk_cGroup_ID.join('')
+ @path = @id = Tk_cGroup_ID.join(TkCore::INTERP._ip_id_)
+ CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
+ CTagID_TBL[@cpath][@id] = self
+ Tk_cGroup_ID[1].succ!
include(*args) if args != []
end
#private :create_self
diff --git a/ext/tk/lib/tk/checkbutton.rb b/ext/tk/lib/tk/checkbutton.rb
index b1186a87ed..d76d99c0f2 100644
--- a/ext/tk/lib/tk/checkbutton.rb
+++ b/ext/tk/lib/tk/checkbutton.rb
@@ -4,7 +4,7 @@
require 'tk'
require 'tk/radiobutton'
-class Tk::CheckButton<Tk::RadioButton
+class TkCheckButton<TkRadioButton
TkCommandNames = ['checkbutton'.freeze].freeze
WidgetClassName = 'Checkbutton'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -22,9 +22,4 @@ class Tk::CheckButton<Tk::RadioButton
self
end
end
-
-Tk::Checkbutton = Tk::CheckButton
-#TkCheckButton = Tk::CheckButton unless Object.const_defined? :TkCheckButton
-#TkCheckbutton = Tk::Checkbutton unless Object.const_defined? :TkCheckbutton
-Tk.__set_toplevel_aliases__(:Tk, Tk::CheckButton,
- :TkCheckButton, :TkCheckbutton)
+TkCheckbutton = TkCheckButton
diff --git a/ext/tk/lib/tk/composite.rb b/ext/tk/lib/tk/composite.rb
index 883d43c3ea..eaed8ed363 100644
--- a/ext/tk/lib/tk/composite.rb
+++ b/ext/tk/lib/tk/composite.rb
@@ -34,8 +34,7 @@ module TkComposite
if klass
# WidgetClassName is a known class
- #if klass <= TkFrame || klass < TkComposite
- if klass <= TkFrame || klass < Tk::Frame || klass < TkComposite
+ if klass <= TkFrame || klass < TkComposite
# klass is valid for the base frame
if self.class <= klass
# use my classname
@@ -51,8 +50,7 @@ module TkComposite
else
# klass is invalid for the base frame
- #if self.class < TkFrame || self.class.superclass < TkComposite
- if self.class < TkFrame || self.class.superclass < Tk::Frame || self.class.superclass < TkComposite
+ if self.class < TkFrame || self.class.superclass < TkComposite
# my class name is valid for the base frame -> use my classname
base_class_name = self.class.name
if base_class_name == ''
@@ -71,8 +69,7 @@ module TkComposite
else
# no valid WidgetClassName
- #if self.class < TkFrame || self.class.superclass < TkComposite
- if self.class < TkFrame || self.class.superclass < Tk::Frame || self.class.superclass < TkComposite
+ if self.class < TkFrame || self.class.superclass < TkComposite
# my class name is valid for the base frame -> use my classname
base_class_name = self.class.name
if base_class_name == ''
@@ -111,12 +108,8 @@ module TkComposite
end
if base_class_name
- # @frame = Tk::Frame.new(parent, :class=>base_class_name)
- # --> use current TkFrame class
@frame = TkFrame.new(parent, :class=>base_class_name)
else
- # @frame = Tk::Frame.new(parent)
- # --> use current TkFrame class
@frame = TkFrame.new(parent)
end
@path = @epath = @frame.path
@@ -140,11 +133,6 @@ module TkComposite
def initialize_composite(*args) end
private :initialize_composite
- def inspect
- str = super
- str.chop << ' @epath=' << @epath.inspect << '>'
- end
-
def option_methods(*opts)
opts.each{|m_set, m_cget, m_info|
m_set = m_set.to_s
@@ -181,57 +169,6 @@ module TkComposite
delegate_alias(option, option, *wins)
end
- def __cget_delegates(slot)
- slot = slot.to_s
-
- if @option_methods.include?(slot)
- if @option_methods[slot][:cget]
- return self.__send__(@option_methods[slot][:cget])
- else
- if @option_setting[slot]
- return @option_setting[slot]
- else
- return ''
- end
- end
- end
-
- tbl = @delegates[slot]
- tbl = @delegates['DEFAULT'] unless tbl
-
- begin
- if tbl
- opt, wins = tbl[-1]
- opt = slot if opt == 'DEFAULT'
- if wins && wins[-1]
- # return wins[-1].cget(opt)
- return wins[-1].cget_strict(opt)
- end
- end
- rescue
- end
-
- return None
- end
- private :__cget_delegates
-
- def cget(slot)
- if (ret = __cget_delegates(slot)) == None
- super(slot)
- else
- ret
- end
- end
-
- def cget_strict(slot)
- if (ret = __cget_delegates(slot)) == None
- super(slot)
- else
- ret
- end
- end
-
-=begin
def cget(slot)
slot = slot.to_s
@@ -263,7 +200,6 @@ module TkComposite
super(slot)
end
-=end
def configure(slot, value=None)
if slot.kind_of? Hash
diff --git a/ext/tk/lib/tk/encodedstr.rb b/ext/tk/lib/tk/encodedstr.rb
index 02de0b0d85..797e514a4c 100644
--- a/ext/tk/lib/tk/encodedstr.rb
+++ b/ext/tk/lib/tk/encodedstr.rb
@@ -70,89 +70,13 @@ module Tk
# @encoding = ( enc ||
# ((self.class::Encoding)?
# self.class::Encoding : Tk.encoding_system) )
- enc ||= (self.class::Encoding)?
+ @encoding = ( enc ||
+ ((self.class::Encoding)?
self.class::Encoding :
- ((Tk.encoding)? Tk.encoding : Tk.encoding_system)
- if TkCore::WITH_ENCODING
- unless encobj = Tk::Encoding::ENCODING_TABLE.get_obj(enc)
- fail ArgumentError, "unsupported Tk encoding '#{enc}'"
- end
- self.force_encoding(encobj)
- else
- @encoding = enc
- end
- end
-
- if TkCore::WITH_ENCODING
- alias encoding_obj encoding
- alias __encoding encoding
- def encoding
- Tk::Encoding::ENCODING_TABLE.get_name(super())
- end
- else
- def encoding
- @encoding
- end
- alias encoding_obj encoding
+ ((Tk.encoding)? Tk.encoding : Tk.encoding_system) ) )
end
- if TkCore::WITH_ENCODING
- # wrapper methods for compatibility
- alias __instance_variable_get instance_variable_get
- alias __instance_variable_set instance_variable_set
- alias __instance_eval instance_eval
- alias __instance_variables instance_variables
-
- def instance_variable_get(key)
- if (key.to_s == '@encoding')
- self.encoding
- else
- super(key)
- end
- end
-
- def instance_variable_set(key, value)
- if (key.to_s == '@encoding')
- if value
- self.force_encoding(value)
- else
- self.force_encoding(Tk::Encoding::UNKNOWN)
- end
- value
- else
- super(key, value)
- end
- end
-
- def instance_eval(*args, &b)
- old_enc = @encoding = self.encoding
-
- ret = super(*args, &b)
-
- if @encoding
- if @encoding != old_enc
- # modified by user
- self.force_encoding(@encoding)
- end
- remove_instance_variable(:@encoding)
- else
- begin
- remove_instance_variable(:@encoding)
- # user sets to nil -> use current default
- self.force_encoding(Tk.encoding)
- rescue NameError
- # removed by user -> ignore, because user don't use @encoding
- end
- end
- ret
- end
- end
-
- def instance_variables
- ret = super()
- ret << :@encoding # fake !!
- ret
- end
+ attr_reader :encoding
end
# def Tk.EncodedString(str, enc = nil)
# Tk::EncodedString.new(str, enc)
diff --git a/ext/tk/lib/tk/entry.rb b/ext/tk/lib/tk/entry.rb
index 8ce8def1e7..4ac3f28229 100644
--- a/ext/tk/lib/tk/entry.rb
+++ b/ext/tk/lib/tk/entry.rb
@@ -1,5 +1,6 @@
#
# tk/entry.rb - Tk entry classes
+# $Date$
# by Yukihiro Matsumoto <matz@caelum.co.jp>
require 'tk'
@@ -7,7 +8,7 @@ require 'tk/label'
require 'tk/scrollable'
require 'tk/validation'
-class Tk::Entry<Tk::Label
+class TkEntry<TkLabel
include X_Scrollable
include TkValidation
@@ -114,6 +115,3 @@ class Tk::Entry<Tk::Label
val
end
end
-
-#TkEntry = Tk::Entry unless Object.const_defined? :TkEntry
-Tk.__set_toplevel_aliases__(:Tk, Tk::Entry, :TkEntry)
diff --git a/ext/tk/lib/tk/event.rb b/ext/tk/lib/tk/event.rb
index d8aad6248b..70a1e38bbe 100644
--- a/ext/tk/lib/tk/event.rb
+++ b/ext/tk/lib/tk/event.rb
@@ -39,9 +39,7 @@ module TkEvent
RESIZEREQ = 0x200000
CIRCREQ = 0x400000
- MWHEEL = KEY
-
- STRING_DATA = 0x80000000 # special flag for 'data' field
+ MWHEEL = 0x10000000
ALL = 0xFFFFFFFF
@@ -157,7 +155,7 @@ module TkEvent
'borderwidth' => (Grp::CREATE|Grp::CONFIG),
'button' => Grp::BUTTON,
'count' => Grp::EXPOSE,
- 'data' => (Grp::VIRTUAL|Grp::STRING_DATA),
+ 'data' => Grp::VIRTUAL,
'delta' => Grp::MWHEEL,
'detail' => (Grp::FOCUS|Grp::CROSSING),
'focus' => Grp::CROSSING,
@@ -225,8 +223,7 @@ module TkEvent
rescue
next
end
- # next if !val || val == '??'
- next if !val || (val == '??' && (flag & Grp::STRING_DATA))
+ next if !val || val == '??'
fields[key] = val
}
@@ -301,65 +298,34 @@ module TkEvent
[ ?b, ?n, :num ],
[ ?c, ?n, :count ],
[ ?d, ?s, :detail ],
- # ?e
[ ?f, ?b, :focus ],
- # ?g
[ ?h, ?n, :height ],
[ ?i, ?s, :win_hex ],
- # ?j
[ ?k, ?n, :keycode ],
- # ?l
[ ?m, ?s, :mode ],
- # ?n
[ ?o, ?b, :override ],
[ ?p, ?s, :place ],
- # ?q
- # ?r
[ ?s, ?x, :state ],
[ ?t, ?n, :time ],
- # ?u
- [ ?v, ?n, :value_mask ],
[ ?w, ?n, :width ],
[ ?x, ?n, :x ],
[ ?y, ?n, :y ],
- # ?z
[ ?A, ?s, :char ],
[ ?B, ?n, :borderwidth ],
- # ?C
[ ?D, ?n, :wheel_delta ],
[ ?E, ?b, :send_event ],
- # ?F
- # ?G
- # ?H
- # ?I
- # ?J
[ ?K, ?s, :keysym ],
- # ?L
- # ?M
[ ?N, ?n, :keysym_num ],
- # ?O
[ ?P, ?s, :property ],
- # ?Q
[ ?R, ?s, :rootwin_id ],
[ ?S, ?s, :subwindow ],
[ ?T, ?n, :type ],
- # ?U
- # ?V
[ ?W, ?w, :widget ],
[ ?X, ?n, :x_root ],
[ ?Y, ?n, :y_root ],
- # ?Z
nil
]
- # [ <'%' subst-key str>, <proc type char>, <instance var (accessor) name>]
- # the subst-key string will be converted to a bytecode (128+idx).
- LONGKEY_TBL = [
- # for example, for %CTT and %CST subst-key on tkdnd-2.0
- # ['CTT', ?l, :drop_target_type],
- # ['CST', ?l, :drop_source_type],
- ]
-
# [ <proc type char>, <proc/method to convert tcl-str to ruby-obj>]
PROC_TBL = [
[ ?n, TkComm.method(:num_or_str) ],
@@ -379,24 +345,6 @@ module TkEvent
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
# setup tables to be used by scan_args, _get_subst_key, _get_all_subst_keys
#
# _get_subst_key() and _get_all_subst_keys() generates key-string
@@ -409,8 +357,7 @@ module TkEvent
# ( which are Tcl strings ) to ruby objects based on the key string
# that is generated by _get_subst_key() or _get_all_subst_keys().
#
- _setup_subst_table(KEY_TBL, PROC_TBL)
- # _setup_subst_table(KEY_TBL, LONGKEY_TBL, PROC_TBL) # if use longname-keys
+ _setup_subst_table(KEY_TBL, PROC_TBL);
#
# NOTE: The order of parameters which passed to callback procedure is
@@ -458,7 +405,6 @@ module TkEvent
extra_args_tbl = klass._get_extra_args_tbl
if args.compact.size > 0
- args.map!{|arg| klass._sym2subst(arg)}
args = args.join(' ')
keys = klass._get_subst_key(args)
diff --git a/ext/tk/lib/tk/font.rb b/ext/tk/lib/tk/font.rb
index 62d628c132..ab58ac5762 100644
--- a/ext/tk/lib/tk/font.rb
+++ b/ext/tk/lib/tk/font.rb
@@ -11,18 +11,13 @@ class TkFont
TkCommandNames = ['font'.freeze].freeze
- (Tk_FontID = ["@font".freeze, "00000".taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
+ Tk_FontID = ["@font".freeze, "00000".taint].freeze
Tk_FontNameTBL = TkCore::INTERP.create_table
Tk_FontUseTBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
- Tk_FontNameTBL.mutex.synchronize{ Tk_FontNameTBL.clear }
- Tk_FontUseTBL.mutex.synchronize{ Tk_FontUseTBL.clear }
+ Tk_FontNameTBL.clear
+ Tk_FontUseTBL.clear
}
# option_type : default => string
@@ -36,26 +31,13 @@ class TkFont
MetricType = Hash.new(?n)
MetricType['fixed'] = ?b
- # system font names
- SYSTEM_FONT_NAMES = []
- def SYSTEM_FONT_NAMES.add(font_names)
- (@mutex ||= Mutex.new).synchronize{
- self.replace(self | font_names.map{|name| name.to_s})
- }
- end
- def SYSTEM_FONT_NAMES.include?(name)
- (@mutex ||= Mutex.new).synchronize{
- super(name.to_s)
- }
- end
-
# set default font
case Tk::TK_VERSION
- when /^4\..*/
+ when /^4\.*/
DEFAULT_LATIN_FONT_NAME = 'a14'.freeze
DEFAULT_KANJI_FONT_NAME = 'k14'.freeze
- when /^8\.[0-4]/
+ when /^8\.*/
if JAPANIZED_TK
begin
fontnames = tk_call('font', 'names')
@@ -121,15 +103,6 @@ class TkFont
DEFAULT_LATIN_FONT_NAME = ltn.freeze
DEFAULT_KANJI_FONT_NAME = knj.freeze
- when /^8\.[5-9]/, /^9\..*/
- if tk_call('font', 'names') =~ /\bTkDefaultFont\b/
- DEFAULT_LATIN_FONT_NAME = 'TkDefaultFont'.freeze
- DEFAULT_KANJI_FONT_NAME = 'TkDefaultFont'.freeze
- else
- DEFAULT_LATIN_FONT_NAME = 'Helvetica'.freeze
- DEFAULT_KANJI_FONT_NAME = 'mincho'.freeze
- end
-
else # unknown version
DEFAULT_LATIN_FONT_NAME = 'Helvetica'.freeze
DEFAULT_KANJI_FONT_NAME = 'mincho'.freeze
@@ -148,7 +121,6 @@ class TkFont
unless compound.kind_of?(TkFont)
fail ArgumentError, "a TkFont object is expected for the 1st argument"
end
-
@compound = compound
case type
when 'kanji', 'latin', 'ascii'
@@ -173,9 +145,6 @@ class TkFont
def font
@compound.__send__(@type + '_font_id')
end
- alias font_id font
- alias name font
- alias to_s font
def [](slot)
@compound.__send__(@type + '_configinfo', slot)
@@ -194,14 +163,6 @@ class TkFont
###################################
# class methods
###################################
- def TkFont.is_system_font?(fnt)
- # true --> system font which is available on the current system
- # false --> not system font (or unknown system font)
- # nil --> system font name, but not available on the current system
- fnt = fnt.to_s
- SYSTEM_FONT_NAMES.include?(fnt) && self.names.index(fnt) && true
- end
-
def TkFont.actual(fnt, option=nil)
fnt = '{}' if fnt == ''
if fnt.kind_of?(TkFont)
@@ -210,9 +171,6 @@ class TkFont
actual_core(fnt, nil, option)
end
end
- def TkFont.actual_hash(fnt, option=nil)
- Hash[TkFont.actual_hash(fnt, option)]
- end
def TkFont.actual_displayof(fnt, win, option=nil)
fnt = '{}' if fnt == ''
@@ -223,9 +181,6 @@ class TkFont
actual_core(fnt, win, option)
end
end
- def TkFont.actual_hash_displayof(fnt, option=nil)
- Hash[TkFont.actual_hash_displayof(fnt, option)]
- end
def TkFont.configure(fnt, slot, value=None)
if fnt.kind_of?(TkFont)
@@ -279,33 +234,6 @@ class TkFont
metrics_core(fnt, nil, option)
end
end
- def TkFont.metrics_hash(fnt, option=nil)
- if option
- val = TkFont.metrics(fnt, option)
- case TkFont::MetricsType[option.to_s]
- when ?n
- val = TkComm::num_or_str(val)
- when ?b
- val = TkComm::bool(val)
- else
- # do nothing
- end
- return val
- end
-
- h = Hash[TkFont.metrics(fnt)]
- h.keys.each{|k|
- case TkFont::MetricsType[k.to_s]
- when ?n
- h[k] = TkComm::num_or_str(h[k])
- when ?b
- h[k] = TkComm::bool(h[k])
- else
- # do nothing
- end
- }
- h
- end
def TkFont.metrics_displayof(fnt, win, option=nil)
fnt = '{}' if fnt == ''
@@ -316,40 +244,13 @@ class TkFont
metrics_core(fnt, win, option)
end
end
- def TkFont.metrics_hash_displayof(fnt, win, option=nil)
- if option
- val = TkFont.metrics_displayof(fnt, win, option)
- case TkFont::MetricsType[option.to_s]
- when ?n
- val = TkComm::num_or_str(val)
- when ?b
- val = TkComm::bool(val)
- else
- # do nothing
- end
- return val
- end
-
- h = Hash[TkFont.metrics_displayof(fnt, win, option)]
- h.keys.each{|k|
- case TkFont::MetricsType[k.to_s]
- when ?n
- h[k] = TkComm::num_or_str(h[k])
- when ?b
- h[k] = TkComm::bool(h[k])
- else
- # do nothing
- end
- }
- h
- end
def TkFont.families(win=nil)
case (Tk::TK_VERSION)
- when /^4\..*/
+ when /^4\.*/
['fixed']
- when /^8\..*/
+ when /^8\.*/
if win
tk_split_simplelist(tk_call('font', 'families', '-displayof', win))
else
@@ -360,16 +261,13 @@ class TkFont
def TkFont.names
case (Tk::TK_VERSION)
- when /^4\..*/
+ when /^4\.*/
r = ['fixed']
r += ['a14', 'k14'] if JAPANIZED_TK
- Tk_FontNameTBL.mutex.synchronize{
- Tk_FontNameTBL.each_value{|obj| r.push(obj)}
- }
- #r | []
- r.uniq
+ Tk_FontNameTBL.each_value{|obj| r.push(obj)}
+ r | []
- when /^8\..*/
+ when /^8\.*/
tk_split_simplelist(tk_call('font', 'names'))
end
@@ -387,15 +285,10 @@ class TkFont
end
def TkFont.get_obj(name)
- name = name.to_s
if name =~ /^(@font[0-9]+)(|c|l|k)$/
- Tk_FontNameTBL.mutex.synchronize{
- Tk_FontNameTBL[$1]
- }
+ Tk_FontNameTBL[$1]
else
- Tk_FontNameTBL.mutex.synchronize{
- Tk_FontNameTBL[name]
- }
+ nil
end
end
@@ -405,7 +298,7 @@ class TkFont
path = [win, tag, key].join(';')
case (Tk::TK_VERSION)
- when /^4\..*/
+ when /^4\.*/
regexp = /^-(|kanji)#{key} /
conf_list = tk_split_simplelist(tk_call(*args)).
@@ -431,7 +324,7 @@ class TkFont
TkFont.new(ltn, knj).call_font_configure([path, key], *args)
- when /^8\.[0-4]/
+ when /^8\.*/
regexp = /^-#{key} /
conf_list = tk_split_simplelist(tk_call(*args)).
@@ -467,66 +360,26 @@ class TkFont
compound = []
end
if compound == []
- if TkFont.is_system_font?(fnt)
- TkNamedFont.new(fnt).call_font_configure([path, key], *args)
- else
- TkFont.new(fnt).call_font_configure([path, key], *args)
- end
+ TkFont.new(fnt).call_font_configure([path, key], *args)
else
TkFont.new(compound[0],
compound[1]).call_font_configure([path, key], *args)
end
end
-
- when /^8\.[5-9]/, /^9\..*/
- regexp = /^-#{key} /
-
- conf_list = tk_split_simplelist(tk_call(*args)).
- find_all{|prop| prop =~ regexp}.
- collect{|prop| tk_split_simplelist(prop)}
-
- if conf_list.size == 0
- raise RuntimeError, "the widget may not support 'font' option"
- end
-
- args << {}
-
- optkey = "-#{key}"
-
- info = conf_list.find{|conf| conf[0] == optkey}
- fnt = info[-1]
- fnt = nil if fnt == [] || fnt == ""
-
- unless fnt
- # create dummy
- # TkFont.new(nil, nil).call_font_configure([path, key], *args)
- dummy_fnt = TkFont.allocate
- dummy_fnt.instance_eval{ init_dummy_fontobj() }
- dummy_fnt
- else
- if TkFont.is_system_font?(fnt)
- TkNamedFont.new(fnt).call_font_configure([path, key], *args)
- else
- TkFont.new(fnt).call_font_configure([path, key], *args)
- end
- end
end
end
def TkFont.used_on(path=nil)
- Tk_FontUseTBL.mutex.synchronize{
- if path
- Tk_FontUseTBL[path]
- else
- # Tk_FontUseTBL.values | []
- Tk_FontUseTBL.values.uniq
- end
- }
+ if path
+ Tk_FontUseTBL[path]
+ else
+ Tk_FontUseTBL.values | []
+ end
end
def TkFont.failsafe(font)
begin
- if /^8\..*/ === Tk::TK_VERSION && JAPANIZED_TK
+ if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
tk_call('font', 'failsafe', font)
end
rescue
@@ -539,20 +392,15 @@ class TkFont
private
###################################
def init_dummy_fontobj
- Tk_FontID.mutex.synchronize{
- @id = Tk_FontID.join(TkCore::INTERP._ip_id_)
- Tk_FontID[1].succ!
- }
- Tk_FontNameTBL.mutex.synchronize{
- Tk_FontNameTBL[@id] = self
- }
+ @id = Tk_FontID.join(TkCore::INTERP._ip_id_)
+ Tk_FontID[1].succ!
+ Tk_FontNameTBL[@id] = self
- # @latin_desscendant = nil
- # @kanji_desscendant = nil
- @descendant = [nil, nil] # [latin, kanji]
+ @latin_desscendant = nil
+ @kanji_desscendant = nil
case (Tk::TK_VERSION)
- when /^4\..*/
+ when /^4\.*/
@latinfont = ""
@kanjifont = ""
if JAPANIZED_TK
@@ -588,23 +436,13 @@ class TkFont
ltn = '{}' if ltn == ''
knj = '{}' if knj == ''
- Tk_FontID.mutex.synchronize{
- # @id = Tk_FontID.join('')
- @id = Tk_FontID.join(TkCore::INTERP._ip_id_)
- Tk_FontID[1].succ!
- }
- Tk_FontNameTBL.mutex.synchronize{
- Tk_FontNameTBL[@id] = self
- }
-
- # @latin_desscendant = nil
- # @kanji_desscendant = nil
- @descendant = [nil, nil] # [latin, kanji]
+ # @id = Tk_FontID.join('')
+ @id = Tk_FontID.join(TkCore::INTERP._ip_id_)
+ Tk_FontID[1].succ!
+ Tk_FontNameTBL[@id] = self
- # @latinfont = @id + 'l'
- # @kanjifont = @id + 'k'
- # @compoundfont = @id + 'c'
- # @fontslot = {}
+ @latin_desscendant = nil
+ @kanji_desscendant = nil
if knj.kind_of?(Hash) && !keys
keys = knj
@@ -636,7 +474,7 @@ class TkFont
if ltn
if JAPANIZED_TK && !knj
- if Tk::TK_VERSION =~ /^4..*/
+ if Tk::TK_VERSION =~ /^4.*/
knj = DEFAULT_KANJI_FONT_NAME
else
knj = ltn
@@ -787,14 +625,9 @@ class TkFont
if JAPANIZED_TK
@compoundfont = [[@latinfont], [@kanjifont]]
@fontslot = {'font'=>@latinfont, 'kanjifont'=>@kanjifont}
- # @fontslot.clear
- # @fontslot['font'] = @latinfont
- # @fontslot['kanjifont'] = @kanjifont
else
@compoundfont = @latinfont
@fontslot = {'font'=>@latinfont}
- # @fontslot.clear
- # @fontslot['font'] = @latinfont
end
end
@@ -920,7 +753,6 @@ class TkFont
end
@fontslot = {'font'=>@compoundfont}
- # @fontslot['font'] = @compoundfont
begin
tk_call('font', 'create', @compoundfont,
'-compound', [@latinfont, @kanjifont], *hash_kv(keys))
@@ -1001,7 +833,6 @@ class TkFont
end
@fontslot = {'font'=>@compoundfont}
- # @fontslot['font'] = @compoundfont
tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
end
end
@@ -1056,39 +887,25 @@ class TkFont
keys = _symbolkey2str(args.pop).update(fontslot)
args.concat(hash_kv(keys))
- begin
- tk_call(*args)
- rescue => e
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- fail e
- end
- end
- Tk_FontUseTBL.mutex.synchronize{
- Tk_FontUseTBL[[win, tag, optkey].join(';')] = self
- }
+ tk_call(*args)
+ Tk_FontUseTBL[[win, tag, optkey].join(';')] = self
self
end
def used
ret = []
- table = nil
- Tk_FontUseTBL.mutex.synchronize{
- table = Tk_FontUseTBL.clone # to avoid deadlock
- }
- table.each{|key,value|
+ Tk_FontUseTBL.each{|key,value|
next unless self == value
if key.include?(';')
win, tag, optkey = key.split(';')
winobj = tk_tcl2ruby(win)
- #if winobj.kind_of? TkText
- if winobj.kind_of?(TkText) || winobj.kind_of?(Tk::Text)
+ if winobj.kind_of? TkText
if optkey
ret.push([winobj, winobj.tagid2obj(tag), optkey])
else
ret.push([winobj, winobj.tagid2obj(tag)])
end
- #elsif winobj.kind_of? TkCanvas
- elsif winobj.kind_of?(TkCanvas) || winobj.kind_of?(Tk::Canvas)
+ elsif winobj.kind_of? TkCanvas
if (tagobj = TkcTag.id2obj(winobj, tag)).kind_of? TkcTag
if optkey
ret.push([winobj, tagobj, optkey])
@@ -1108,8 +925,7 @@ class TkFont
ret.push([winobj, tag])
end
end
- #elsif winobj.kind_of? TkMenu
- elsif winobj.kind_of?(TkMenu) || winobj.kind_of?(Tk::Menu)
+ elsif winobj.kind_of? TkMenu
if optkey
ret.push([winobj, tag, optkey])
else
@@ -1141,8 +957,6 @@ class TkFont
@compoundfont
end
alias font_id font
- alias name font
- alias to_s font
def latin_font_id
@latinfont
@@ -1150,18 +964,11 @@ class TkFont
def latin_font
# @latinfont
- if @descendant[0] # [0] -> latin
- @descendant[0]
- else
- @descendant[0] = DescendantFont.new(self, 'latin')
- end
-=begin
if @latin_descendant
@latin_descendant
else
@latin_descendant = DescendantFont.new(self, 'latin')
end
-=end
end
alias latinfont latin_font
@@ -1171,87 +978,50 @@ class TkFont
def kanji_font
# @kanjifont
- if @descendant[1] # [1] -> kanji
- @descendant[1]
- else
- @descendant[1] = DescendantFont.new(self, 'kanji')
- end
-=begin
if @kanji_descendant
@kanji_descendant
else
@kanji_descendant = DescendantFont.new(self, 'kanji')
end
-=end
end
alias kanjifont kanji_font
def actual(option=nil)
actual_core(@compoundfont, nil, option)
end
- def actual_hash(option=nil)
- Hash[actual(option)]
- end
def actual_displayof(win, option=nil)
win = '.' unless win
actual_core(@compoundfont, win, option)
end
- def actual_hash_displayof(win, option=nil)
- Hash[actual_displayof(win, option)]
- end
def latin_actual(option=nil)
- if @latinfont == nil
- actual_core(@compoundfont, nil, option) # use @compoundfont
- else
- actual_core(@latinfont, nil, option)
- end
- end
- def latin_actual_hash(option=nil)
- Hash[latin_actual(option)]
+ actual_core(@latinfont, nil, option)
end
def latin_actual_displayof(win, option=nil)
win = '.' unless win
- if @latinfont == nil
- actual_core(@compoundfont, win, option) # use @compoundfont
- else
- actual_core(@latinfont, win, option)
- end
- end
- def latin_actual_hash_displayof(win, option=nil)
- Hash[latin_actual_displayof(win, option)]
+ actual_core(@latinfont, win, option)
end
def kanji_actual(option=nil)
#if JAPANIZED_TK
- if @kanjifont == nil
- actual_core(@compoundfont, nil, option) # use @compoundfont
- elsif @kanjifont != ""
+ if @kanjifont != ""
actual_core(@kanjifont, nil, option)
else
actual_core_tk4x(nil, nil, option)
end
end
- def kanji_actual_hash(option=nil)
- Hash[kanji_actual(option)]
- end
def kanji_actual_displayof(win, option=nil)
#if JAPANIZED_TK
- if @kanjifont == nil
- actual_core(@compoundfont, nil, option) # use @compoundfont
- elsif @kanjifont != ""
+ if @kanjifont != ""
win = '.' unless win
actual_core(@kanjifont, win, option)
else
actual_core_tk4x(nil, win, option)
end
end
- def kanji_actual_hash_displayof(win, option=nil)
- Hash[kanji_actual_displayof(win, option)]
- end
def [](slot)
configinfo slot
@@ -1295,15 +1065,10 @@ class TkFont
configinfo(slot)
end
end
- def latin_current_configinfo(slot=nil)
- Hash[latin_configinfo(slot)]
- end
def kanji_configure(slot, value=None)
#if JAPANIZED_TK
- if @kanjifont == nil
- configure_core(@compoundfont, slot, value) # use @compoundfont
- elsif @kanjifont != ""
+ if @kanjifont != ""
configure_core(@kanjifont, slot, value)
configure('size'=>configinfo('size')) # to reflect new configuration
else
@@ -1315,18 +1080,13 @@ class TkFont
def kanji_configinfo(slot=nil)
#if JAPANIZED_TK
- if @kanjifont == nil
- configure_core(@compoundfont, slot) # use @compoundfont
- elsif @kanjifont != ""
+ if @kanjifont != ""
configinfo_core(@kanjifont, slot)
else
#[]
configinfo(slot)
end
end
- def kanji_current_configinfo(slot=nil)
- Hash[kanji_configinfo(slot)]
- end
def replace(ltn, knj=None)
knj = ltn if knj == None
@@ -1336,30 +1096,12 @@ class TkFont
end
def latin_replace(ltn)
- if @latinfont
- latin_replace_core(ltn)
- reset_pointadjust
- else
- # not compound font -> copy properties of ltn
- latinkeys = {}
- begin
- actual_core(ltn).each{|key,val| latinkeys[key] = val}
- rescue
- latinkeys = {}
- end
- begin
- tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys))
- rescue
- # not exist? (deleted?) -> create font
- tk_call('font', 'create', @compoundfont, *hash_kv(latinkeys))
- end
- end
-
+ latin_replace_core(ltn)
+ reset_pointadjust
self
end
def kanji_replace(knj)
- return self unless @kanjifont # ignore
kanji_replace_core(knj)
reset_pointadjust
self
@@ -1377,215 +1119,41 @@ class TkFont
def metrics(option=nil)
metrics_core(@compoundfont, nil, option)
end
- def metrics_hash(option=nil)
- if option
- val = metrics(option)
- case TkFont::MetricsType[option.to_s]
- when ?n
- val = TkComm::num_or_str(val)
- when ?b
- val = TkComm::bool(val)
- else
- # do nothing
- end
- return val
- end
-
- h = Hash[metrics(option)]
- h.keys.each{|k|
- case TkFont::MetricsType[k.to_s]
- when ?n
- h[k] = TkComm::num_or_str(h[k])
- when ?b
- h[k] = TkComm::bool(h[k])
- else
- # do nothing
- end
- }
- h
- end
def metrics_displayof(win, option=nil)
win = '.' unless win
metrics_core(@compoundfont, win, option)
end
- def metrics_hash_displayof(win, option=nil)
- if option
- val = metrics_displayof(win, option)
- case TkFont::MetricsType[option.to_s]
- when ?n
- val = TkComm::num_or_str(val)
- when ?b
- val = TkComm::bool(val)
- else
- # do nothing
- end
- return val
- end
-
- h = Hash[metrics_displayof(win, option)]
- h.keys.each{|k|
- case TkFont::MetricsType[k.to_s]
- when ?n
- h[k] = TkComm::num_or_str(h[k])
- when ?b
- h[k] = TkComm::bool(h[k])
- else
- # do nothing
- end
- }
- h
- end
def latin_metrics(option=nil)
- if @latinfont == nil
- metrics_core(@compoundfont, nil, option) # use @compoundfont
- else
- metrics_core(@latinfont, nil, option)
- end
- end
- def latin_metrics_hash(option=nil)
- if option
- val = latin_metrics(option)
- case TkFont::MetricsType[option.to_s]
- when ?n
- val = TkComm::num_or_str(val)
- when ?b
- val = TkComm::bool(val)
- else
- # do nothing
- end
- return val
- end
-
- h = Hash[latin_metrics(option)]
- h.keys.each{|k|
- case TkFont::MetricsType[k.to_s]
- when ?n
- h[k] = TkComm::num_or_str(h[k])
- when ?b
- h[k] = TkComm::bool(h[k])
- else
- # do nothing
- end
- }
- h
+ metrics_core(@latinfont, nil, option)
end
def latin_metrics_displayof(win, option=nil)
win = '.' unless win
- if @latinfont == nil
- metrics_core(@compoundfont, win, option) # use @compoundfont
- else
- metrics_core(@latinfont, win, option)
- end
- end
- def latin_metrics_hash_displayof(win, option=nil)
- if option
- val = latin_metrics_displayof(win, option)
- case TkFont::MetricsType[option.to_s]
- when ?n
- val = TkComm::num_or_str(val)
- when ?b
- val = TkComm::bool(val)
- else
- # do nothing
- end
- return val
- end
-
- h = Hash[latin_metrics_displayof(win, option)]
- h.keys.each{|k|
- case TkFont::MetricsType[k.to_s]
- when ?n
- h[k] = TkComm::num_or_str(h[k])
- when ?b
- h[k] = TkComm::bool(h[k])
- else
- # do nothing
- end
- }
- h
+ metrics_core(@latinfont, win, option)
end
def kanji_metrics(option=nil)
- if @latinfont == nil
- metrics_core(@compoundfont, nil, option) # use @compoundfont
- elsif JAPANIZED_TK
+ if JAPANIZED_TK
metrics_core(@kanjifont, nil, option)
else
metrics_core_tk4x(nil, nil, option)
end
end
- def kanji_metrics_hash(option=nil)
- if option
- val = kanji_metrics(option)
- case TkFont::MetricsType[option.to_s]
- when ?n
- val = TkComm::num_or_str(val)
- when ?b
- val = TkComm::bool(val)
- else
- # do nothing
- end
- return val
- end
-
- h = Hash[kanji_metrics(option)]
- h.keys.each{|k|
- case TkFont::MetricsType[k.to_s]
- when ?n
- h[k] = TkComm::num_or_str(h[k])
- when ?b
- h[k] = TkComm::bool(h[k])
- else
- # do nothing
- end
- }
- h
- end
def kanji_metrics_displayof(win, option=nil)
- win = '.' unless win
- if @latinfont == nil
- metrics_core(@compoundfont, win, option) # use @compoundfont
- elsif JAPANIZED_TK
+ if JAPANIZED_TK
+ win = '.' unless win
metrics_core(@kanjifont, win, option)
else
metrics_core_tk4x(nil, win, option)
end
end
- def kanji_metrics_hash_displayof(win, option=nil)
- if option
- val = kanji_metrics_displayof(win, option)
- case TkFont::MetricsType[option.to_s]
- when ?n
- val = TkComm::num_or_str(val)
- when ?b
- val = TkComm::bool(val)
- else
- # do nothing
- end
- return val
- end
-
- h = Hash[kanji_metrics_displayof(win, option)]
- h.keys.each{|k|
- case TkFont::MetricsType[k.to_s]
- when ?n
- h[k] = TkComm::num_or_str(h[k])
- when ?b
- h[k] = TkComm::bool(h[k])
- else
- # do nothing
- end
- }
- h
- end
def reset_pointadjust
begin
- if /^8\..*/ === Tk::TK_VERSION && JAPANIZED_TK
+ if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
configure('pointadjust' => latin_actual.assoc('size')[1].to_f /
kanji_actual.assoc('size')[1].to_f )
end
@@ -1598,7 +1166,7 @@ class TkFont
# private alias
###################################
case (Tk::TK_VERSION)
- when /^4\..*/
+ when /^4\.*/
alias create_latinfont create_latinfont_tk4x
alias create_kanjifont create_kanjifont_tk4x
alias create_compoundfont create_compoundfont_tk4x
@@ -1903,44 +1471,32 @@ module TkFont::CoreMethods
end
def delete_core_tk4x
- TkFont::Tk_FontNameTBL.mutex.synchronize{
- TkFont::Tk_FontNameTBL.delete(@id)
- }
- TkFont::Tk_FontUseTBL.mutex.synchronize{
- TkFont::Tk_FontUseTBL.delete_if{|key,value| value == self}
- }
+ TkFont::Tk_FontNameTBL.delete(@id)
+ TkFont::Tk_FontUseTBL.delete_if{|key,value| value == self}
end
def delete_core_tk8x
begin
- tk_call('font', 'delete', @latinfont) if @latinfont
+ tk_call('font', 'delete', @latinfont)
rescue
end
begin
- tk_call('font', 'delete', @kanjifont) if @kanjifont
+ tk_call('font', 'delete', @kanjifont)
rescue
end
begin
- tk_call('font', 'delete', @compoundfont) if @compoundfont
+ tk_call('font', 'delete', @compoundfont)
rescue
end
- TkFont::Tk_FontNameTBL.mutex.synchronize{
- TkFont::Tk_FontNameTBL.delete(@id)
- }
- TkFont::Tk_FontUseTBL.mutex.synchronize{
- TkFont::Tk_FontUseTBL.delete_if{|key,value| value == self}
- }
+ TkFont::Tk_FontNameTBL.delete(@id)
+ TkFont::Tk_FontUseTBL.delete_if{|key,value| value == self}
end
def latin_replace_core_tk4x(ltn)
create_latinfont_tk4x(ltn)
@compoundfont[0] = [@latinfont] if JAPANIZED_TK
@fontslot['font'] = @latinfont
- table = nil
- TkFont::Tk_FontUseTBL.mutex.synchronize{
- table = TkFont::Tk_FontUseTBL.clone
- }
- table.each{|w, fobj|
+ TkFont::Tk_FontUseTBL.dup.each{|w, fobj|
if self == fobj
begin
if w.include?(';')
@@ -1948,14 +1504,11 @@ module TkFont::CoreMethods
optkey = 'font' if optkey == nil || optkey == ''
winobj = tk_tcl2ruby(win)
# winobj.tagfont_configure(tag, {'font'=>@latinfont})
- #if winobj.kind_of? TkText
- if winobj.kind_of?(TkText) || winobj.kind_of?(Tk::Text)
+ if winobj.kind_of? TkText
tk_call(win, 'tag', 'configure', tag, "-#{optkey}", @latinfont)
- #elsif winobj.kind_of? TkCanvas
- elsif winobj.kind_of?(TkCanvas) || winobj.kind_of?(Tk::Canvas)
+ elsif winobj.kind_of? TkCanvas
tk_call(win, 'itemconfigure', tag, "-#{optkey}", @latinfont)
- #elsif winobj.kind_of? TkMenu
- elsif winobj.kind_of?(TkMenu) || winobj.kind_of?(Tk::Menu)
+ elsif winobj.kind_of? TkMenu
tk_call(win, 'entryconfigure', tag, "-#{optkey}", @latinfont)
else
raise RuntimeError, "unknown widget type"
@@ -1965,9 +1518,7 @@ module TkFont::CoreMethods
tk_call(w, 'configure', '-font', @latinfont)
end
rescue
- TkFont::Tk_FontUseTBL.mutex.synchronize{
- TkFont::Tk_FontUseTBL.delete(w)
- }
+ TkFont::Tk_FontUseTBL.delete(w)
end
end
}
@@ -1980,11 +1531,7 @@ module TkFont::CoreMethods
create_kanjifont_tk4x(knj)
@compoundfont[1] = [@kanjifont]
@fontslot['kanjifont'] = @kanjifont
- table = nil
- TkFont::Tk_FontUseTBL.mutex.synchronize{
- table = TkFont::Tk_FontUseTBL.clone
- }
- table.dup.each{|w, fobj|
+ TkFont::Tk_FontUseTBL.dup.each{|w, fobj|
if self == fobj
begin
if w.include?(';')
@@ -1992,14 +1539,11 @@ module TkFont::CoreMethods
optkey = 'kanjifont' unless optkey
winobj = tk_tcl2ruby(win)
# winobj.tagfont_configure(tag, {'kanjifont'=>@kanjifont})
- #if winobj.kind_of? TkText
- if winobj.kind_of?(TkText) || winobj.kind_of?(Tk::Text)
+ if winobj.kind_of? TkText
tk_call(win, 'tag', 'configure', tag, "-#{optkey}", @kanjifont)
- #elsif winobj.kind_of? TkCanvas
- elsif winobj.kind_of?(TkCanvas) || winobj.kind_of?(Tk::Canvas)
+ elsif winobj.kind_of? TkCanvas
tk_call(win, 'itemconfigure', tag, "-#{optkey}", @kanjifont)
- #elsif winobj.kind_of? TkMenu
- elsif winobj.kind_of?(TkMenu) || winobj.kind_of?(Tk::Menu)
+ elsif winobj.kind_of? TkMenu
tk_call(win, 'entryconfigure', tag, "-#{optkey}", @latinfont)
else
raise RuntimeError, "unknown widget type"
@@ -2009,9 +1553,7 @@ module TkFont::CoreMethods
tk_call(w, 'configure', '-kanjifont', @kanjifont)
end
rescue
- Tk_FontUseTBL.mutex.synchronize{
- TkFont::Tk_FontUseTBL.delete(w)
- }
+ TkFont::Tk_FontUseTBL.delete(w)
end
end
}
@@ -2076,11 +1618,8 @@ module TkFont::CoreMethods
rescue
latinkeys = {}
end
- begin
+ if latinkeys != {}
tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys))
- rescue
- # not exist? (deleted?) -> create font
- tk_call('font', 'create', @compoundfont, *hash_kv(latinkeys))
end
end
self
@@ -2172,13 +1711,6 @@ module TkFont::CoreMethods
r = []
while key=l.shift
r.push [key[1..-1], l.shift.to_i]
-=begin
- if key == '-fixed' # boolean value
- r.push [key[1..-1], bool(l.shift)]
- else
- r.push [key[1..-1], l.shift.to_i]
- end
-=end
end
r
end
@@ -2188,7 +1720,7 @@ module TkFont::CoreMethods
# private alias
###################################
case (Tk::TK_VERSION)
- when /^4\..*/
+ when /^4\.*/
alias actual_core actual_core_tk4x
alias configure_core configure_core_tk4x
alias configinfo_core configinfo_core_tk4x
@@ -2228,117 +1760,3 @@ class TkFont
include TkFont::CoreMethods
extend TkFont::CoreMethods
end
-
-class TkNamedFont < TkFont
- # for built-in named fonts
- def TkNamedFont.find(name)
- name = name.to_s
- unless (obj = Tk_FontNameTBL[name])
- obj = self.new(name) if TkFont.is_system_font?(name)
- end
- obj
- end
-
- def TkNamedFont.new(name, keys=nil)
- name = name.to_s
- obj = nil
- Tk_FontNameTBL.mutex.synchronize{
- unless (obj = Tk_FontNameTBL[name])
- (obj = self.allocate).instance_eval{
- @id = @compoundfont = name.to_s
- @latinfont = nil
- @kanjifont = nil
- @descendant = [self, self] # [latin, kanji] : dummy
- Tk_FontNameTBL[@id] = self
- }
- end
- }
- obj.instance_eval{ initialize(name, keys) }
- obj
- end
-
- ###########################
- private
- ###########################
- def initialize(name, keys=nil)
- @id = @compoundfont = name.to_s
-
- # if not exist named font, create it.
- begin
- if keys
- tk_call('font', 'configure', @compoundfont, keys)
- else
- tk_call('font', 'configure', @compoundfont)
- end
- rescue
- # the named font doesn't exist -> create
- if keys
- tk_call('font', 'create', @compoundfont, keys)
- else
- tk_call('font', 'create', @compoundfont)
- end
- end
- end
-
- def create_latinfont(fnt)
- # ignore
- end
- def create_kanjifont(fnt)
- # ignore
- end
- def create_compoundfont(ltn, knj, keys)
- # ignore
- end
-
- ###########################
- public
- ###########################
- def latin_font_id
- @compoundfont
- end
- def kanji_font_id
- @compoundfont
- end
-end
-
-#######################################
-# define system font names
-#######################################
-if Tk::TCL_MAJOR_VERSION > 8 ||
- (Tk::TCL_MAJOR_VERSION == 8 && Tk::TCL_MINOR_VERSION >= 5)
- # add standard fonts of Tcl/Tk 8.5+
- TkFont::SYSTEM_FONT_NAMES.add [
- 'TkDefaultFont', 'TkTextFont', 'TkFixedFont', 'TkMenuFont',
- 'TkHeadingFont', 'TkCaptionFont', 'TkSmallCaptionFont',
- 'TkIconFont', 'TkTooltipFont'
- ]
-end
-
-# platform-specific fonts
-# -- windows
-TkFont::SYSTEM_FONT_NAMES.add [
- 'ansifixed', 'ansi', 'device', 'oemfixed', 'systemfixed', 'system'
-]
-
-# -- macintosh, macosx
-TkFont::SYSTEM_FONT_NAMES.add ['system', 'application']
-
-if Tk::TCL_MAJOR_VERSION > 8 ||
- (Tk::TCL_MAJOR_VERSION == 8 && Tk::TCL_MINOR_VERSION >= 5)
- TkFont::SYSTEM_FONT_NAMES.add ['menu']
-end
-
-# -- macosx (Aqua theme)
-if Tk::TCL_MAJOR_VERSION > 8 ||
- (Tk::TCL_MAJOR_VERSION == 8 && Tk::TCL_MINOR_VERSION >= 5)
- TkFont::SYSTEM_FONT_NAMES.add [
- 'systemSystemFont', 'systemEmphasizedSystemFont',
- 'systemSmallSystemFont', 'systemSmallEmphasizedSystemFont',
- 'systemApplicationFont', 'systemLabelFont', 'systemViewsFont',
- 'systemMenuTitleFont', 'systemMenuItemFont', 'systemMenuItemMarkFont',
- 'systemMenuItemCmdKeyFont', 'systemWindowTitleFont',
- 'systemPushButtonFont', 'systemUtilityWindowTitleFont',
- 'systemAlertHeaderFont', 'systemToolbarFont', 'systemMiniSystemFont',
- 'systemDetailSystemFont', 'systemDetailEmphasizedSystemFont'
- ]
-end
diff --git a/ext/tk/lib/tk/frame.rb b/ext/tk/lib/tk/frame.rb
index 263b160f29..6636fef5b5 100644
--- a/ext/tk/lib/tk/frame.rb
+++ b/ext/tk/lib/tk/frame.rb
@@ -3,7 +3,7 @@
#
require 'tk'
-class Tk::Frame<TkWindow
+class TkFrame<TkWindow
TkCommandNames = ['frame'.freeze].freeze
WidgetClassName = 'Frame'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -126,6 +126,3 @@ class Tk::Frame<TkWindow
end
end
end
-
-#TkFrame = Tk::Frame unless Object.const_defined? :TkFrame
-Tk.__set_toplevel_aliases__(:Tk, Tk::Frame, :TkFrame)
diff --git a/ext/tk/lib/tk/grid.rb b/ext/tk/lib/tk/grid.rb
index 0dfd7263a7..10fdf3569b 100644
--- a/ext/tk/lib/tk/grid.rb
+++ b/ext/tk/lib/tk/grid.rb
@@ -22,7 +22,6 @@ module TkGrid
list(tk_call_without_enc('grid', 'bbox', *args))
end
-=begin
def configure(win, *args)
if args[-1].kind_of?(Hash)
opts = args.pop
@@ -54,48 +53,6 @@ module TkGrid
tk_call_without_enc('grid', 'configure', *params)
end
end
-=end
- def configure(*args)
- if args[-1].kind_of?(Hash)
- opts = args.pop
- else
- opts = {}
- end
- fail ArgumentError, 'no widget is given' if args.empty?
- params = []
- args.flatten(1).each{|win|
- case win
- when '-', ?- # RELATIVE PLACEMENT (increase columnspan)
- params.push('-')
- when /^-+$/ # RELATIVE PLACEMENT (increase columnspan)
- params.concat(win.to_s.split(//))
- when '^', ?^ # RELATIVE PLACEMENT (increase rowspan)
- params.push('^')
- when /^\^+$/ # RELATIVE PLACEMENT (increase rowspan)
- params.concat(win.to_s.split(//))
- when 'x', :x, ?x, nil, '' # RELATIVE PLACEMENT (empty column)
- params.push('x')
- when /^x+$/ # RELATIVE PLACEMENT (empty column)
- params.concat(win.to_s.split(//))
- else
- params.push(_epath(win))
- end
- }
- opts.each{|k, v|
- params.push("-#{k}")
- params.push(_epath(v)) # have to use 'epath' (hash_kv() is unavailable)
- }
- if Tk::TCL_MAJOR_VERSION < 8 ||
- (Tk::TCL_MAJOR_VERSION == 8 && Tk::TCL_MINOR_VERSION <= 3)
- if params[0] == '-' || params[0] == 'x' || params[0] == '^'
- tk_call_without_enc('grid', *params)
- else
- tk_call_without_enc('grid', 'configure', *params)
- end
- else
- tk_call_without_enc('grid', 'configure', *params)
- end
- end
alias grid configure
def columnconfigure(master, index, args)
@@ -104,14 +61,12 @@ module TkGrid
tk_call_without_enc("grid", 'columnconfigure',
master, index, *hash_kv(args))
end
- alias column columnconfigure
def rowconfigure(master, index, args)
# master = master.epath if master.kind_of?(TkObject)
master = _epath(master)
tk_call_without_enc("grid", 'rowconfigure', master, index, *hash_kv(args))
end
- alias row rowconfigure
def columnconfiginfo(master, index, slot=nil)
# master = master.epath if master.kind_of?(TkObject)
@@ -234,10 +189,10 @@ module TkGrid
list(tk_call_without_enc('grid', 'slaves', master, *hash_kv(args)))
end
- module_function :anchor, :bbox, :add, :forget, :propagate, :info
+ module_function :bbox, :forget, :propagate, :info
module_function :remove, :size, :slaves, :location
module_function :grid, :configure, :columnconfigure, :rowconfigure
- module_function :column, :row, :columnconfiginfo, :rowconfiginfo
+ module_function :columnconfiginfo, :rowconfiginfo
end
=begin
def TkGrid(win, *args)
diff --git a/ext/tk/lib/tk/image.rb b/ext/tk/lib/tk/image.rb
index dffdc19644..35e2c4e394 100644
--- a/ext/tk/lib/tk/image.rb
+++ b/ext/tk/lib/tk/image.rb
@@ -10,16 +10,9 @@ class TkImage<TkObject
TkCommandNames = ['image'.freeze].freeze
Tk_IMGTBL = TkCore::INTERP.create_table
+ Tk_Image_ID = ['i'.freeze, '00000'.taint].freeze
- (Tk_Image_ID = ['i'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- Tk_IMGTBL.mutex.synchronize{ Tk_IMGTBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ Tk_IMGTBL.clear }
def self.new(keys=nil)
if keys.kind_of?(Hash)
@@ -34,10 +27,7 @@ class TkImage<TkObject
obj = name
else
name = _get_eval_string(name)
- obj = nil
- Tk_IMGTBL.mutex.synchronize{
- obj = Tk_IMGTBL[name]
- }
+ obj = Tk_IMGTBL[name]
end
if obj
if !(keys[:without_creating] || keys['without_creating'])
@@ -53,13 +43,7 @@ class TkImage<TkObject
end
end
end
- (obj = self.allocate).instance_eval{
- Tk_IMGTBL.mutex.synchronize{
- initialize(keys)
- Tk_IMGTBL[@path] = self
- }
- }
- obj
+ super(keys)
end
def initialize(keys=nil)
@@ -71,22 +55,19 @@ class TkImage<TkObject
without_creating = keys.delete('without_creating')
end
unless @path
- Tk_Image_ID.mutex.synchronize{
- # @path = Tk_Image_ID.join('')
- @path = Tk_Image_ID.join(TkCore::INTERP._ip_id_)
- Tk_Image_ID[1].succ!
- }
+ # @path = Tk_Image_ID.join('')
+ @path = Tk_Image_ID.join(TkCore::INTERP._ip_id_)
+ Tk_Image_ID[1].succ!
end
unless without_creating
tk_call_without_enc('image', 'create',
@type, @path, *hash_kv(keys, true))
end
+ Tk_IMGTBL[@path] = self
end
def delete
- Tk_IMGTBL.mutex.synchronize{
- Tk_IMGTBL.delete(@id) if @id
- }
+ Tk_IMGTBL.delete(@id) if @id
tk_call_without_enc('image', 'delete', @path)
self
end
@@ -104,10 +85,8 @@ class TkImage<TkObject
end
def TkImage.names
- Tk_IMGTBL.mutex.synchronize{
- Tk.tk_call_without_enc('image', 'names').split.collect!{|id|
- (Tk_IMGTBL[id])? Tk_IMGTBL[id] : id
- }
+ Tk.tk_call_without_enc('image', 'names').split.collect!{|id|
+ (Tk_IMGTBL[id])? Tk_IMGTBL[id] : id
}
end
@@ -156,7 +135,7 @@ class TkPhotoImage<TkImage
self
end
- def cget_strict(option)
+ def cget(option)
case option.to_s
when 'data', 'file'
tk_send 'cget', '-' << option.to_s
@@ -164,23 +143,6 @@ class TkPhotoImage<TkImage
tk_tcl2ruby(tk_send('cget', '-' << option.to_s))
end
end
- def cget(option)
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- cget_strict(option)
- else
- begin
- cget_strict(option)
- rescue => e
- if current_configinfo.has_key?(option.to_s)
- # error on known option
- fail e
- else
- # unknown option
- nil
- end
- end
- end
- end
def copy(src, *opts)
if opts.size == 0
diff --git a/ext/tk/lib/tk/itemconfig.rb b/ext/tk/lib/tk/itemconfig.rb
index 9c6a98d0f8..a7885e74f3 100644
--- a/ext/tk/lib/tk/itemconfig.rb
+++ b/ext/tk/lib/tk/itemconfig.rb
@@ -8,11 +8,6 @@ require 'tk/itemfont.rb'
module TkItemConfigOptkeys
include TkUtil
- def __item_optkey_aliases(id)
- {}
- end
- private :__item_optkey_aliases
-
def __item_numval_optkeys(id)
[]
end
@@ -120,14 +115,6 @@ module TkItemConfigMethod
include TkTreatItemFont
include TkItemConfigOptkeys
- def TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- @mode || false
- end
- def TkItemConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode)
- fail SecurityError, "can't change the mode" if $SAFE>=4
- @mode = (mode)? true: false
- end
-
def __item_cget_cmd(id)
# maybe need to override
[self.path, 'itemcget', id]
@@ -162,7 +149,7 @@ module TkItemConfigMethod
################################################
- def __itemcget_core(tagOrId, option)
+ def itemcget(tagOrId, option)
orig_opt = option
option = option.to_s
@@ -170,11 +157,6 @@ module TkItemConfigMethod
fail ArgumentError, "Invalid option `#{orig_opt.inspect}'"
end
- alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == option}
- if real_name
- option = real_name.to_s
- end
-
if ( method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[option] )
optval = tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}"))
begin
@@ -242,45 +224,11 @@ module TkItemConfigMethod
tk_tcl2ruby(tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}")), true)
end
end
- private :__itemcget_core
-
- def itemcget(tagOrId, option)
- unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- __itemcget_core(tagOrId, option)
- else
- begin
- __itemcget_core(tagOrId, option)
- rescue => e
- begin
- if __current_itemconfiginfo(tagOrId).has_key?(option.to_s)
- # not tag error & option is known -> error on known option
- fail e
- else
- # not tag error & option is unknown
- nil
- end
- rescue
- fail e # tag error
- end
- end
- end
- end
- def itemcget_strict(tagOrId, option)
- # never use TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- __itemcget_core(tagOrId, option)
- end
- def __itemconfigure_core(tagOrId, slot, value=None)
+ def itemconfigure(tagOrId, slot, value=None)
if slot.kind_of? Hash
slot = _symbolkey2str(slot)
- __item_optkey_aliases(tagid(tagOrId)).each{|alias_name, real_name|
- alias_name = alias_name.to_s
- if slot.has_key?(alias_name)
- slot[real_name.to_s] = slot.delete(alias_name)
- end
- }
-
__item_methodcall_optkeys(tagid(tagOrId)).each{|key, method|
value = slot.delete(key.to_s)
self.__send__(method, tagOrId, value) if value
@@ -317,11 +265,6 @@ module TkItemConfigMethod
fail ArgumentError, "Invalid option `#{orig_slot.inspect}'"
end
- alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
- if real_name
- slot = real_name.to_s
- end
-
if ( conf = __item_keyonly_optkeys(tagid(tagOrId)).find{|k, v| k.to_s == slot } )
defkey, undefkey = conf
if value
@@ -345,56 +288,6 @@ module TkItemConfigMethod
end
self
end
- private :__itemconfigure_core
-
- def __check_available_itemconfigure_options(tagOrId, keys)
- id = tagid(tagOrId)
-
- availables = self.__current_itemconfiginfo(id).keys
-
- # add non-standard keys
- availables |= __font_optkeys.map{|k|
- [k.to_s, "latin#{k}", "ascii#{k}", "kanji#{k}"]
- }.flatten
- availables |= __item_methodcall_optkeys(id).keys.map{|k| k.to_s}
- availables |= __item_keyonly_optkeys(id).keys.map{|k| k.to_s}
-
- keys = _symbolkey2str(keys)
-
- keys.delete_if{|k, v| !(availables.include?(k))}
- end
-
- def itemconfigure(tagOrId, slot, value=None)
- unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- __itemconfigure_core(tagOrId, slot, value)
- else
- if slot.kind_of?(Hash)
- begin
- __itemconfigure_core(tagOrId, slot)
- rescue
- slot = __check_available_itemconfigure_options(tagOrId, slot)
- __itemconfigure_core(tagOrId, slot) unless slot.empty?
- end
- else
- begin
- __itemconfigure_core(tagOrId, slot, value)
- rescue => e
- begin
- if __current_itemconfiginfo(tagOrId).has_key?(slot.to_s)
- # not tag error & option is known -> error on known option
- fail e
- else
- # not tag error & option is unknown
- nil
- end
- rescue
- fail e # tag error
- end
- end
- end
- end
- self
- end
def __itemconfiginfo_core(tagOrId, slot = nil)
if TkComm::GET_CONFIGINFO_AS_ARRAY
@@ -406,10 +299,6 @@ module TkItemConfigMethod
conf[__item_configinfo_struct(tagid(tagOrId))[:key]][1..-1]
if ( ! __item_configinfo_struct(tagid(tagOrId))[:alias] \
|| conf.size > __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
- fnt = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
- if TkFont.is_system_font?(fnt)
- conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkNamedFont.new(fnt)
- end
conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = tagfontobj(tagid(tagOrId), fontkey)
elsif ( __item_configinfo_struct(tagid(tagOrId))[:alias] \
&& conf.size == __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 \
@@ -421,12 +310,6 @@ module TkItemConfigMethod
else
if slot
slot = slot.to_s
-
- alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
- if real_name
- slot = real_name.to_s
- end
-
case slot
when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot]
@@ -752,10 +635,6 @@ module TkItemConfigMethod
fontconf = ret.assoc(optkey)
if fontconf && fontconf.size > 2
ret.delete_if{|inf| inf[0] =~ /^(|latin|ascii|kanji)#{optkey}$/}
- fnt = fontconf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
- if TkFont.is_system_font?(fnt)
- fontconf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkNamedFont.new(fnt)
- end
fontconf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = tagfontobj(tagid(tagOrId), optkey)
ret.push(fontconf)
end
@@ -779,11 +658,7 @@ module TkItemConfigMethod
if ( ! __item_configinfo_struct(tagid(tagOrId))[:alias] \
|| conf.size > __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
- fnt = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
- if TkFont.is_system_font?(fnt)
- conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkNamedFont.new(fnt)
- end
- conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = tagfontobj(tagid(tagOrId), fontkey)
+ conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = fontobj(tagid(tagOrId), fontkey)
{ conf.shift => conf }
elsif ( __item_configinfo_struct(tagid(tagOrId))[:alias] \
&& conf.size == __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
@@ -798,12 +673,6 @@ module TkItemConfigMethod
else
if slot
slot = slot.to_s
-
- alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
- if real_name
- slot = real_name.to_s
- end
-
case slot
when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot]
@@ -1137,10 +1006,6 @@ module TkItemConfigMethod
ret.delete('latin' << optkey)
ret.delete('ascii' << optkey)
ret.delete('kanji' << optkey)
- fnt = fontconf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
- if TkFont.is_system_font?(fnt)
- fontconf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkNamedFont.new(fnt)
- end
fontconf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = tagfontobj(tagid(tagOrId), optkey)
ret[optkey] = fontconf
end
@@ -1158,24 +1023,10 @@ module TkItemConfigMethod
private :__itemconfiginfo_core
def itemconfiginfo(tagOrId, slot = nil)
- if slot && TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- begin
- __itemconfiginfo_core(tagOrId, slot)
- rescue => e
- begin
- __itemconfiginfo_core(tagOrId)
- # not tag error -> option is unknown
- Array.new(__item_configinfo_struct.values.max).unshift(slot.to_s)
- rescue
- fail e # tag error
- end
- end
- else
- __itemconfiginfo_core(tagOrId, slot)
- end
+ __itemconfiginfo_core(tagOrId, slot)
end
- def __current_itemconfiginfo(tagOrId, slot = nil)
+ def current_itemconfiginfo(tagOrId, slot = nil)
if TkComm::GET_CONFIGINFO_AS_ARRAY
if slot
org_slot = slot
@@ -1197,7 +1048,6 @@ module TkItemConfigMethod
ret[conf[0]] = conf[-1]
end
}
-
ret
end
else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
@@ -1208,8 +1058,4 @@ module TkItemConfigMethod
ret
end
end
-
- def current_itemconfiginfo(tagOrId, slot = nil)
- __current_itemconfiginfo(tagOrId, slot)
- end
end
diff --git a/ext/tk/lib/tk/itemfont.rb b/ext/tk/lib/tk/itemfont.rb
index 4c5c917c57..ab9e3ff6c9 100644
--- a/ext/tk/lib/tk/itemfont.rb
+++ b/ext/tk/lib/tk/itemfont.rb
@@ -94,16 +94,7 @@ module TkTreatItemFont
*(__item_config_cmd(tagid(tagOrId)) << {}))
next
else
- fnt = hash_kv(fnt) if fnt.kind_of?(Hash)
- unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << fnt))
- else
- begin
- tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << fnt))
- rescue => e
- # ignore
- end
- end
+ tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << fnt))
end
end
next
@@ -156,16 +147,7 @@ module TkTreatItemFont
elsif Tk::JAPANIZED_TK
fobj = fontobj # create a new TkFont object
else
- ltn = hash_kv(ltn) if ltn.kind_of?(Hash)
- unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << ltn))
- else
- begin
- tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << ltn))
- rescue => e
- # ignore
- end
- end
+ tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << ltn))
next
end
@@ -216,16 +198,7 @@ module TkTreatItemFont
elsif Tk::JAPANIZED_TK
fobj = fontobj # create a new TkFont object
else
- knj = hash_kv(knj) if knj.kind_of?(Hash)
- unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << knj))
- else
- begin
- tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << knj))
- rescue => e
- # ignore
- end
- end
+ tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << knj))
next
end
diff --git a/ext/tk/lib/tk/label.rb b/ext/tk/lib/tk/label.rb
index 80b3d778f1..8b45db9b30 100644
--- a/ext/tk/lib/tk/label.rb
+++ b/ext/tk/lib/tk/label.rb
@@ -3,7 +3,7 @@
#
require 'tk'
-class Tk::Label<TkWindow
+class TkLabel<TkWindow
TkCommandNames = ['label'.freeze].freeze
WidgetClassName = 'Label'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -16,6 +16,3 @@ class Tk::Label<TkWindow
#end
#private :create_self
end
-
-#TkLabel = Tk::Label unless Object.const_defined? :TkLabel
-Tk.__set_toplevel_aliases__(:Tk, Tk::Label, :TkLabel)
diff --git a/ext/tk/lib/tk/labelframe.rb b/ext/tk/lib/tk/labelframe.rb
index 995b5b7e72..73d5603200 100644
--- a/ext/tk/lib/tk/labelframe.rb
+++ b/ext/tk/lib/tk/labelframe.rb
@@ -4,7 +4,7 @@
require 'tk'
require 'tk/frame'
-class Tk::LabelFrame<Tk::Frame
+class TkLabelFrame<TkFrame
TkCommandNames = ['labelframe'.freeze].freeze
WidgetClassName = 'Labelframe'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -22,8 +22,4 @@ class Tk::LabelFrame<Tk::Frame
end
private :__val2ruby_optkeys
end
-
-Tk::Labelframe = Tk::LabelFrame
-#TkLabelFrame = Tk::LabelFrame unless Object.const_defined? :TkLabelFrame
-#TkLabelframe = Tk::Labelframe unless Object.const_defined? :TkLabelframe
-Tk.__set_toplevel_aliases__(:Tk, Tk::LabelFrame, :TkLabelFrame, :TkLabelframe)
+TkLabelframe = TkLabelFrame
diff --git a/ext/tk/lib/tk/listbox.rb b/ext/tk/lib/tk/listbox.rb
index bb039ffb0e..41d02d279e 100644
--- a/ext/tk/lib/tk/listbox.rb
+++ b/ext/tk/lib/tk/listbox.rb
@@ -15,7 +15,7 @@ module TkListItemConfig
private :__item_listval_optkeys
end
-class Tk::Listbox<TkTextWin
+class TkListbox<TkTextWin
include TkListItemConfig
include Scrollable
@@ -277,6 +277,3 @@ class Tk::Listbox<TkTextWin
end
=end
end
-
-#TkListbox = Tk::Listbox unless Object.const_defined? :TkListbox
-Tk.__set_toplevel_aliases__(:Tk, Tk::Listbox, :TkListbox)
diff --git a/ext/tk/lib/tk/macpkg.rb b/ext/tk/lib/tk/macpkg.rb
index 67b0a4bb60..1802073f46 100644
--- a/ext/tk/lib/tk/macpkg.rb
+++ b/ext/tk/lib/tk/macpkg.rb
@@ -20,14 +20,9 @@ module Tk
end
end
-module Tk::MacResource
-end
-#TkMacResource = Tk::MacResource
-Tk.__set_toplevel_aliases__(:Tk, Tk::MacResource, :TkMacResource)
-
-module Tk::MacResource
+module TkMacResource
extend Tk
- extend Tk::MacResource
+ extend TkMacResource
TkCommandNames = ['resource'.freeze].freeze
diff --git a/ext/tk/lib/tk/menu.rb b/ext/tk/lib/tk/menu.rb
index 3ae0548dd1..ddddc8e53e 100644
--- a/ext/tk/lib/tk/menu.rb
+++ b/ext/tk/lib/tk/menu.rb
@@ -34,16 +34,15 @@ module TkMenuEntryConfig
private :__item_val2ruby_optkeys
alias entrycget itemcget
- alias entrycget_strict itemcget_strict
alias entryconfigure itemconfigure
alias entryconfiginfo itemconfiginfo
alias current_entryconfiginfo current_itemconfiginfo
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
end
-class Tk::Menu<TkWindow
+class TkMenu<TkWindow
include Wm
include TkMenuEntryConfig
extend TkMenuSpec
@@ -141,9 +140,9 @@ class Tk::Menu<TkWindow
type = keys.delete('type') if keys.has_key?('type')
if keys.empty?
- Tk::MenuClone.new(self, parent, type)
+ TkMenuClone.new(self, parent, type)
else
- Tk::MenuClone.new(self, parent, type, keys)
+ TkMenuClone.new(self, parent, type, keys)
end
end
@@ -203,9 +202,6 @@ class Tk::Menu<TkWindow
tk_send_without_enc('unpost')
self
end
- def xposition(index)
- number(tk_send_without_enc('xposition', _get_eval_enc_str(index)))
- end
def yposition(index)
number(tk_send_without_enc('yposition', _get_eval_enc_str(index)))
end
@@ -385,11 +381,8 @@ class Tk::Menu<TkWindow
=end
end
-#TkMenu = Tk::Menu unless Object.const_defined? :TkMenu
-Tk.__set_toplevel_aliases__(:Tk, Tk::Menu, :TkMenu)
-
-class Tk::MenuClone<Tk::Menu
+class TkMenuClone<TkMenu
=begin
def initialize(parent, type=None)
widgetname = nil
@@ -443,12 +436,9 @@ class Tk::MenuClone<Tk::Menu
@src_menu
end
end
-Tk::CloneMenu = Tk::MenuClone
-#TkMenuClone = Tk::MenuClone unless Object.const_defined? :TkMenuClone
-#TkCloneMenu = Tk::CloneMenu unless Object.const_defined? :TkCloneMenu
-Tk.__set_toplevel_aliases__(:Tk, Tk::MenuClone, :TkMenuClone, :TkCloneMenu)
+TkCloneMenu = TkMenuClone
-module Tk::SystemMenu
+module TkSystemMenu
def initialize(parent, keys=nil)
if parent.kind_of? Hash
keys = _symbolkey2str(parent)
@@ -471,60 +461,38 @@ module Tk::SystemMenu
end
end
end
-TkSystemMenu = Tk::SystemMenu
-class Tk::SysMenu_Help<Tk::Menu
+class TkSysMenu_Help<TkMenu
# for all platform
- include Tk::SystemMenu
+ include TkSystemMenu
SYSMENU_NAME = 'help'
end
-#TkSysMenu_Help = Tk::SysMenu_Help unless Object.const_defined? :TkSysMenu_Help
-Tk.__set_toplevel_aliases__(:Tk, Tk::SysMenu_Help, :TkSysMenu_Help)
-class Tk::SysMenu_System<Tk::Menu
+class TkSysMenu_System<TkMenu
# for Windows
- include Tk::SystemMenu
+ include TkSystemMenu
SYSMENU_NAME = 'system'
end
-#TkSysMenu_System = Tk::SysMenu_System unless Object.const_defined? :TkSysMenu_System
-Tk.__set_toplevel_aliases__(:Tk, Tk::SysMenu_System, :TkSysMenu_System)
-class Tk::SysMenu_Apple<Tk::Menu
+class TkSysMenu_Apple<TkMenu
# for Machintosh
- include Tk::SystemMenu
+ include TkSystemMenu
SYSMENU_NAME = 'apple'
end
-#TkSysMenu_Apple = Tk::SysMenu_Apple unless Object.const_defined? :TkSysMenu_Apple
-Tk.__set_toplevel_aliases__(:Tk, Tk::SysMenu_Apple, :TkSysMenu_Apple)
-class Tk::Menubutton<Tk::Label
+class TkMenubutton<TkLabel
TkCommandNames = ['menubutton'.freeze].freeze
WidgetClassName = 'Menubutton'.freeze
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
if keys and keys != None
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- # tk_call_without_enc('menubutton', @path, *hash_kv(keys, true))
- tk_call_without_enc(self.class::TkCommandNames[0], @path,
- *hash_kv(keys, true))
- else
- begin
- tk_call_without_enc(self.class::TkCommandNames[0], @path,
- *hash_kv(keys, true))
- rescue
- tk_call_without_enc(self.class::TkCommandNames[0], @path)
- keys = __check_available_configure_options(keys)
- unless keys.empty?
- tk_call_without_enc('destroy', @path) rescue nil
- tk_call_without_enc(self.class::TkCommandNames[0], @path,
- *hash_kv(keys, true))
- end
- end
- end
+ # tk_call_without_enc('menubutton', @path, *hash_kv(keys, true))
+ tk_call_without_enc(self.class::TkCommandNames[0], @path,
+ *hash_kv(keys, true))
else
# tk_call_without_enc('menubutton', @path)
tk_call_without_enc(self.class::TkCommandNames[0], @path)
@@ -538,13 +506,10 @@ class Tk::Menubutton<Tk::Label
private :__boolval_optkeys
end
-Tk::MenuButton = Tk::Menubutton
-#TkMenubutton = Tk::Menubutton unless Object.const_defined? :TkMenubutton
-#TkMenuButton = Tk::MenuButton unless Object.const_defined? :TkMenuButton
-Tk.__set_toplevel_aliases__(:Tk, Tk::Menubutton, :TkMenubutton, :TkMenuButton)
+TkMenuButton = TkMenubutton
-class Tk::OptionMenubutton<Tk::Menubutton
+class TkOptionMenubutton<TkMenubutton
TkCommandNames = ['tk_optionMenu'.freeze].freeze
class OptionMenu<TkMenu
@@ -631,9 +596,6 @@ class Tk::OptionMenubutton<Tk::Menubutton
@menu.delete(index, last)
self
end
- def xposition(index)
- @menu.xposition(index)
- end
def yposition(index)
@menu.yposition(index)
end
@@ -643,9 +605,6 @@ class Tk::OptionMenubutton<Tk::Menubutton
def menucget(key)
@menu.cget(key)
end
- def menucget_strict(key)
- @menu.cget_strict(key)
- end
def menuconfigure(key, val=None)
@menu.configure(key, val)
self
@@ -659,9 +618,6 @@ class Tk::OptionMenubutton<Tk::Menubutton
def entrycget(index, key)
@menu.entrycget(index, key)
end
- def entrycget_strict(index, key)
- @menu.entrycget_strict(index, key)
- end
def entryconfigure(index, key, val=None)
@menu.entryconfigure(index, key, val)
self
@@ -673,9 +629,4 @@ class Tk::OptionMenubutton<Tk::Menubutton
@menu.current_entryconfiginfo(index, key)
end
end
-
-Tk::OptionMenuButton = Tk::OptionMenubutton
-#TkOptionMenubutton = Tk::OptionMenubutton unless Object.const_defined? :TkOptionMenubutton
-#TkOptionMenuButton = Tk::OptionMenuButton unless Object.const_defined? :TkOptionMenuButton
-Tk.__set_toplevel_aliases__(:Tk, Tk::OptionMenubutton,
- :TkOptionMenubutton, :TkOptionMenuButton)
+TkOptionMenuButton = TkOptionMenubutton
diff --git a/ext/tk/lib/tk/menubar.rb b/ext/tk/lib/tk/menubar.rb
index ef9da809b9..392b6fbd4e 100644
--- a/ext/tk/lib/tk/menubar.rb
+++ b/ext/tk/lib/tk/menubar.rb
@@ -89,7 +89,7 @@ require 'tk/frame'
require 'tk/composite'
require 'tk/menuspec'
-class TkMenubar<Tk::Frame
+class TkMenubar<TkFrame
include TkComposite
include TkMenuSpec
diff --git a/ext/tk/lib/tk/menuspec.rb b/ext/tk/lib/tk/menuspec.rb
index 2a2eb9ba3c..118a4f42b1 100644
--- a/ext/tk/lib/tk/menuspec.rb
+++ b/ext/tk/lib/tk/menuspec.rb
@@ -61,12 +61,8 @@ module TkMenuSpec
tearoff = orig_opts.delete('tearoff') if orig_opts.key?('tearoff')
if menu_name
- #menu = Tk::Menu.new(parent, :widgetname=>menu_name, :tearoff=>tearoff)
- # --> use current TkMenu class
menu = TkMenu.new(parent, :widgetname=>menu_name, :tearoff=>tearoff)
else
- #menu = Tk::Menu.new(parent, :tearoff=>tearoff)
- # --> use current TkMenu class
menu = TkMenu.new(parent, :tearoff=>tearoff)
end
@@ -154,22 +150,21 @@ module TkMenuSpec
def _use_menubar?(parent)
use_menubar = false
- if parent.kind_of?(Tk::Root) || parent.kind_of?(Tk::Toplevel)
- true
- elsif parent.current_configinfo.has_key?('menu')
- true
+ if parent.kind_of?(TkRoot) || parent.kind_of?(TkToplevel)
+ return true
else
- false
+ begin
+ parent.cget('menu')
+ return true
+ rescue
+ end
end
+ false
end
private :_use_menubar?
def _create_menu_for_menubar(parent)
- #unless (mbar = parent.menu).kind_of?(TkMenu)
- # --> use current TkMenu class
- mbar = parent.menu
- unless mbar.kind_of?(Tk::Menu) || mbar.kind_of?(TkMenu)
- #mbar = Tk::Menu.new(parent, :tearoff=>false)
+ unless (mbar = parent.menu).kind_of?(TkMenu)
mbar = TkMenu.new(parent, :tearoff=>false)
parent.menu(mbar)
end
@@ -195,6 +190,7 @@ module TkMenuSpec
if _use_menubar?(parent)
# menubar by menu entries
+
mbar = _create_menu_for_menubar(parent)
menu_name = nil
@@ -225,8 +221,6 @@ module TkMenuSpec
else
# menubar by menubuttons
- #mbtn = Tk::Menubutton.new(parent)
- # --> use current TkMenubutton class
mbtn = TkMenubutton.new(parent)
menu_name = nil
diff --git a/ext/tk/lib/tk/message.rb b/ext/tk/lib/tk/message.rb
index 946b68c704..79121bebb3 100644
--- a/ext/tk/lib/tk/message.rb
+++ b/ext/tk/lib/tk/message.rb
@@ -4,7 +4,7 @@
require 'tk'
require 'tk/label'
-class Tk::Message<Tk::Label
+class TkMessage<TkLabel
TkCommandNames = ['message'.freeze].freeze
WidgetClassName = 'Message'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -17,6 +17,3 @@ class Tk::Message<Tk::Label
#end
private :create_self
end
-
-#TkMessage = Tk::Message unless Object.const_defined? :TkMessage
-Tk.__set_toplevel_aliases__(:Tk, Tk::Message, :TkMessage)
diff --git a/ext/tk/lib/tk/msgcat.rb b/ext/tk/lib/tk/msgcat.rb
index 162953f425..061e43fd89 100644
--- a/ext/tk/lib/tk/msgcat.rb
+++ b/ext/tk/lib/tk/msgcat.rb
@@ -74,11 +74,7 @@ class TkMsgCatalog < TkObject
"\n---< backtrace of Ruby side >-----\n" +
_toUTF8(e.backtrace.join("\n")) +
"\n---< backtrace of Tk side >-------"
- if TkCore::WITH_ENCODING
- msg.force_encoding('utf-8')
- else
- msg.instance_variable_set(:@encoding, 'utf-8')
- end
+ msg.instance_variable_set(:@encoding, 'utf-8')
rescue Exception
msg = e.class.inspect + ': ' + e.message + "\n" +
"\n---< backtrace of Ruby side >-----\n" +
diff --git a/ext/tk/lib/tk/namespace.rb b/ext/tk/lib/tk/namespace.rb
index 20a8d65215..5bf6474c5b 100644
--- a/ext/tk/lib/tk/namespace.rb
+++ b/ext/tk/lib/tk/namespace.rb
@@ -12,24 +12,17 @@ class TkNamespace < TkObject
].freeze
Tk_Namespace_ID_TBL = TkCore::INTERP.create_table
-
- (Tk_Namespace_ID = ["ns".freeze, "00000".taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
+ Tk_Namespace_ID = ["ns".freeze, "00000".taint].freeze
Tk_NsCode_RetObjID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
- Tk_Namespace_ID_TBL.mutex.synchronize{ Tk_Namespace_ID_TBL.clear }
- Tk_NsCode_RetObjID_TBL.mutex.synchronize{ Tk_NsCode_RetObjID_TBL.clear }
+ Tk_Namespace_ID_TBL.clear
+ Tk_NsCode_RetObjID_TBL.clear
}
def TkNamespace.id2obj(id)
- Tk_Namespace_ID_TBL.mutex.synchronize{
- Tk_Namespace_ID_TBL[id]? Tk_Namespace_ID_TBL[id]: id
- }
+ Tk_Namespace_ID_TBL[id]? Tk_Namespace_ID_TBL[id]: id
end
#####################################
@@ -72,27 +65,11 @@ class TkNamespace < TkObject
def cget(slot)
if slot == :namespace || slot == 'namespace'
ns = super(slot)
- Tk_Namespace_ID_TBL.mutex.synchronize{
- if TkNamespace::Tk_Namespace_ID_TBL.key?(ns)
- TkNamespace::Tk_Namespace_ID_TBL[ns]
- else
- ns
- end
- }
- else
- super(slot)
- end
- end
- def cget_strict(slot)
- if slot == :namespace || slot == 'namespace'
- ns = super(slot)
- Tk_Namespace_ID_TBL.mutex.synchronize{
- if TkNamespace::Tk_Namespace_ID_TBL.key?(ns)
- TkNamespace::Tk_Namespace_ID_TBL[ns]
- else
- ns
- end
- }
+ if TkNamespace::Tk_Namespace_ID_TBL.key?(ns)
+ TkNamespace::Tk_Namespace_ID_TBL[ns]
+ else
+ ns
+ end
else
super(slot)
end
@@ -102,11 +79,9 @@ class TkNamespace < TkObject
if slot
if slot == :namespace || slot == 'namespace'
val = super(slot)
- Tk_Namespace_ID_TBL.mutex.synchronize{
- if TkNamespace::Tk_Namespace_ID_TBL.key?(val)
- val = TkNamespace::Tk_Namespace_ID_TBL[val]
- end
- }
+ if TkNamespace::Tk_Namespace_ID_TBL.key?(val)
+ val = TkNamespace::Tk_Namespace_ID_TBL[val]
+ end
else
val = super(slot)
end
@@ -121,23 +96,19 @@ class TkNamespace < TkObject
info = super()
if TkComm::GET_CONFIGINFO_AS_ARRAY
- Tk_Namespace_ID_TBL.mutex.synchronize{
- info.map!{|inf|
- if inf[0] == 'namespace' &&
- TkNamespace::Tk_Namespace_ID_TBL.key?(inf[-1])
- [inf[0], TkNamespace::Tk_Namespace_ID_TBL[inf[-1]]]
- else
- inf
- end
- }
+ info.map!{|inf|
+ if inf[0] == 'namespace' &&
+ TkNamespace::Tk_Namespace_ID_TBL.key?(inf[-1])
+ [inf[0], TkNamespace::Tk_Namespace_ID_TBL[inf[-1]]]
+ else
+ inf
+ end
}
else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
val = info['namespace']
- Tk_Namespace_ID_TBL.mutex.synchronize{
- if TkNamespace::Tk_Namespace_ID_TBL.key?(val)
- info['namespace'] = TkNamespace::Tk_Namespace_ID_TBL[val]
- end
- }
+ if TkNamespace::Tk_Namespace_ID_TBL.key?(val)
+ info['namespace'] = TkNamespace::Tk_Namespace_ID_TBL[val]
+ end
end
info
@@ -244,11 +215,9 @@ class TkNamespace < TkObject
def initialize(name = nil, parent = nil)
unless name
- Tk_Namespace_ID.mutex.synchronize{
- # name = Tk_Namespace_ID.join('')
- name = Tk_Namespace_ID.join(TkCore::INTERP._ip_id_)
- Tk_Namespace_ID[1].succ!
- }
+ # name = Tk_Namespace_ID.join('')
+ name = Tk_Namespace_ID.join(TkCore::INTERP._ip_id_)
+ Tk_Namespace_ID[1].succ!
end
name = __tk_call('namespace', 'current') if name == ''
if parent
@@ -283,9 +252,7 @@ class TkNamespace < TkObject
# create namespace
__tk_call('namespace', 'eval', @fullname, '')
- Tk_Namespace_ID_TBL.mutex.synchronize{
- Tk_Namespace_ID_TBL[@fullname] = self
- }
+ Tk_Namespace_ID_TBL[@fullname] = self
end
def self.children(*args)
@@ -293,13 +260,11 @@ class TkNamespace < TkObject
# <pattern> must be glob-style pattern
tk_split_simplelist(tk_call('namespace', 'children', *args)).collect{|ns|
# ns is fullname
- Tk_Namespace_ID_TBL.mutex.synchronize{
- if Tk_Namespace_ID_TBL.key?(ns)
- Tk_Namespace_ID_TBL[ns]
- else
- ns
- end
- }
+ if Tk_Namespace_ID_TBL.key?(ns)
+ Tk_Namespace_ID_TBL[ns]
+ else
+ ns
+ end
}
end
def children(pattern=None)
@@ -325,24 +290,14 @@ class TkNamespace < TkObject
def code(script = Proc.new)
if script.kind_of?(String)
cmd = proc{|*args|
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- obj = ScopeArgs.new(@fullname,*args)
- ret = obj.instance_exec(obj, script)
- else
- ret = ScopeArgs.new(@fullname,*args).instance_eval(script)
- end
+ ret = ScopeArgs.new(@fullname,*args).instance_eval(script)
id = ret.object_id
TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
id
}
elsif script.kind_of?(Proc)
cmd = proc{|*args|
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- obj = ScopeArgs.new(@fullname,*args)
- ret = obj.instance_exec(obj, &script)
- else
- ret = ScopeArgs.new(@fullname,*args).instance_eval(&script)
- end
+ ret = ScopeArgs.new(@fullname,*args).instance_eval(&script)
id = ret.object_id
TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
id
@@ -364,13 +319,11 @@ class TkNamespace < TkObject
def self.current
ns = self.current_path
- Tk_Namespace_ID_TBL.mutex.synchronize{
- if Tk_Namespace_ID_TBL.key?(ns)
- Tk_Namespace_ID_TBL[ns]
- else
- ns
- end
- }
+ if Tk_Namespace_ID_TBL.key?(ns)
+ Tk_Namespace_ID_TBL[ns]
+ else
+ ns
+ end
end
def current_namespace
# ns_tk_call('namespace', 'current')
@@ -382,13 +335,11 @@ class TkNamespace < TkObject
def self.delete(*ns_list)
tk_call('namespace', 'delete', *ns_list)
ns_list.each{|ns|
- Tk_Namespace_ID_TBL.mutex.synchronize{
- if ns.kind_of?(TkNamespace)
- Tk_Namespace_ID_TBL.delete(ns.path)
- else
- Tk_Namespace_ID_TBL.delete(ns.to_s)
- end
- }
+ if ns.kind_of?(TkNamespace)
+ Tk_Namespace_ID_TBL.delete(ns.path)
+ else
+ Tk_Namespace_ID_TBL.delete(ns.to_s)
+ end
}
end
def delete
@@ -420,7 +371,7 @@ class TkNamespace < TkObject
def self.eval(namespace, cmd = Proc.new, *args)
#tk_call('namespace', 'eval', namespace, cmd, *args)
- TkNamespace.new(namespace).eval(cmd, *args)
+ TkNamespace.new(namespece).eval(cmd, *args)
end
=begin
def eval(cmd = Proc.new, *args)
@@ -493,13 +444,11 @@ class TkNamespace < TkObject
def self.parent(namespace=None)
ns = tk_call('namespace', 'parent', namespace)
- Tk_Namespace_ID_TBL.mutex.synchronize{
- if Tk_Namespace_ID_TBL.key?(ns)
- Tk_Namespace_ID_TBL[ns]
- else
- ns
- end
- }
+ if Tk_Namespace_ID_TBL.key?(ns)
+ Tk_Namespace_ID_TBL[ns]
+ else
+ ns
+ end
end
def parent
tk_call('namespace', 'parent', @fullname)
diff --git a/ext/tk/lib/tk/optiondb.rb b/ext/tk/lib/tk/optiondb.rb
index 186811d37d..a806f3971d 100644
--- a/ext/tk/lib/tk/optiondb.rb
+++ b/ext/tk/lib/tk/optiondb.rb
@@ -8,11 +8,7 @@ module TkOptionDB
extend Tk
TkCommandNames = ['option'.freeze].freeze
- (CmdClassID = ['CMD_CLASS'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
+ CmdClassID = ['CMD_CLASS'.freeze, '00000'.taint].freeze
module Priority
WidgetDefault = 20
@@ -254,10 +250,8 @@ module TkOptionDB
def __create_new_class(klass, func, safe = 4, add = false, parent = nil)
if klass.kind_of?(TkWindow)
carrier = klass.path
- CmdClassID.mutex.synchronize{
- klass = CmdClassID.join(TkCore::INTERP._ip_id_)
- CmdClassID[1].succ!
- }
+ klass = CmdClassID.join(TkCore::INTERP._ip_id_)
+ CmdClassID[1].succ!
parent = nil # ignore parent
else
klass = klass.to_s if klass.kind_of?(Symbol)
@@ -318,7 +312,7 @@ module TkOptionDB
:singleton_methods, :remove_const, :remove_method, :undef_method,
:to_s, :inspect, :display, :method, :methods, :respond_to?,
:instance_variable_get, :instance_variable_set, :instance_method,
- :instance_eval, :instance_exec, :instance_variables, :kind_of?, :is_a?,
+ :instance_eval, :instance_variables, :kind_of?, :is_a?,
:private_methods, :protected_methods, :public_methods ].each{|m|
alias_method(m, :__null_method)
}
@@ -368,7 +362,7 @@ module TkOptionDB
def new_proc_class_random(klass, func, safe = 4, add = false, &b)
eval_under_random_base(){
- TkOptionDB.new_proc_class(klass, func, safe, add, self, &b)
+ TkOption.new_proc_class(klass, func, safe, add, self, &b)
}
end
module_function :new_proc_class_random
diff --git a/ext/tk/lib/tk/pack.rb b/ext/tk/lib/tk/pack.rb
index 220a38e524..8fab363121 100644
--- a/ext/tk/lib/tk/pack.rb
+++ b/ext/tk/lib/tk/pack.rb
@@ -9,7 +9,6 @@ module TkPack
TkCommandNames = ['pack'.freeze].freeze
-=begin
def configure(win, *args)
if args[-1].kind_of?(Hash)
opts = args.pop
@@ -30,22 +29,6 @@ module TkPack
}
tk_call_without_enc("pack", 'configure', *params)
end
-=end
- def configure(*args)
- if args[-1].kind_of?(Hash)
- opts = args.pop
- else
- opts = {}
- end
- fail ArgumentError, 'no widget is given' if args.empty?
- params = []
- args.flatten(1).each{|win| params.push(_epath(win))}
- opts.each{|k, v|
- params.push("-#{k}")
- params.push(_epath(v)) # have to use 'epath' (hash_kv() is unavailable)
- }
- tk_call_without_enc("pack", 'configure', *params)
- end
alias pack configure
def forget(*args)
diff --git a/ext/tk/lib/tk/package.rb b/ext/tk/lib/tk/package.rb
index 0c329732f5..d1eb27674d 100644
--- a/ext/tk/lib/tk/package.rb
+++ b/ext/tk/lib/tk/package.rb
@@ -136,8 +136,4 @@ module TkPackage
def vsatisfies(version1, version2)
bool(tk_call('package', 'vsatisfies', version1, version2))
end
-
- def prefer(setting = None)
- tk_call('package', 'prefer', setting)
- end
end
diff --git a/ext/tk/lib/tk/palette.rb b/ext/tk/lib/tk/palette.rb
index 2d08d50f6a..2b6fdf5d90 100644
--- a/ext/tk/lib/tk/palette.rb
+++ b/ext/tk/lib/tk/palette.rb
@@ -15,7 +15,7 @@ module TkPalette
].freeze
def TkPalette.set(*args)
- args = args[0].to_a.flatten if args[0].kind_of? Hash
+ args = args.to_a.flatten if args.kind_of? Hash
tk_call('tk_setPalette', *args)
end
def TkPalette.setPalette(*args)
diff --git a/ext/tk/lib/tk/panedwindow.rb b/ext/tk/lib/tk/panedwindow.rb
index 030144e677..c6cf3cd11f 100644
--- a/ext/tk/lib/tk/panedwindow.rb
+++ b/ext/tk/lib/tk/panedwindow.rb
@@ -3,7 +3,7 @@
#
require 'tk'
-class Tk::PanedWindow<TkWindow
+class TkPanedWindow<TkWindow
TkCommandNames = ['panedwindow'.freeze].freeze
WidgetClassName = 'Panedwindow'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -76,32 +76,11 @@ class Tk::PanedWindow<TkWindow
self
end
- def panecget_strict(win, key)
+ def panecget(win, key)
# win = win.epath if win.kind_of?(TkObject)
win = _epath(win)
tk_tcl2ruby(tk_send_without_enc('panecget', win, "-#{key}"))
end
- def panecget(win, key)
- unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- panecget_strict(win, key)
- else
- begin
- panecget_strict(win, key)
- rescue => e
- begin
- if current_paneconfiginfo(win).has_key?(option.to_s)
- # not tag error & option is known -> error on known option
- fail e
- else
- # not tag error & option is unknown
- nil
- end
- rescue
- fail e # tag error
- end
- end
- end
- end
def paneconfigure(win, key, value=nil)
# win = win.epath if win.kind_of?(TkObject)
@@ -250,9 +229,4 @@ class Tk::PanedWindow<TkWindow
list(tk_send_without_enc('panes'))
end
end
-
-Tk::Panedwindow = Tk::PanedWindow
-#TkPanedWindow = Tk::PanedWindow unless Object.const_defined? :TkPanedWindow
-#TkPanedwindow = Tk::Panedwindow unless Object.const_defined? :TkPanedwindow
-Tk.__set_toplevel_aliases__(:Tk, Tk::PanedWindow,
- :TkPanedWindow, :TkPanedwindow)
+TkPanedwindow = TkPanedWindow
diff --git a/ext/tk/lib/tk/radiobutton.rb b/ext/tk/lib/tk/radiobutton.rb
index 1f864ec06b..f8f67d709a 100644
--- a/ext/tk/lib/tk/radiobutton.rb
+++ b/ext/tk/lib/tk/radiobutton.rb
@@ -4,7 +4,7 @@
require 'tk'
require 'tk/button'
-class Tk::RadioButton<Tk::Button
+class TkRadioButton<TkButton
TkCommandNames = ['radiobutton'.freeze].freeze
WidgetClassName = 'Radiobutton'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -63,9 +63,4 @@ class Tk::RadioButton<Tk::Button
end
end
end
-
-Tk::Radiobutton = Tk::RadioButton
-#TkRadioButton = Tk::RadioButton unless Object.const_defined? :TkRadioButton
-#TkRadiobutton = Tk::Radiobutton unless Object.const_defined? :TkRadiobutton
-Tk.__set_toplevel_aliases__(:Tk, Tk::RadioButton,
- :TkRadioButton, :TkRadiobutton)
+TkRadiobutton = TkRadioButton
diff --git a/ext/tk/lib/tk/root.rb b/ext/tk/lib/tk/root.rb
index 7237b4c614..0e5584c7c1 100644
--- a/ext/tk/lib/tk/root.rb
+++ b/ext/tk/lib/tk/root.rb
@@ -5,7 +5,7 @@ require 'tk'
require 'tk/wm'
require 'tk/menuspec'
-class Tk::Root<TkWindow
+class TkRoot<TkWindow
include Wm
include TkMenuSpec
@@ -14,7 +14,28 @@ class Tk::Root<TkWindow
end
private :__methodcall_optkeys
- def Root.new(keys=nil, &b)
+=begin
+ ROOT = []
+ def TkRoot.new(keys=nil)
+ if ROOT[0]
+ Tk_WINDOWS["."] = ROOT[0]
+ return ROOT[0]
+ end
+ new = super(:without_creating=>true, :widgetname=>'.')
+ if keys # wm commands
+ keys.each{|k,v|
+ if v.kind_of? Array
+ new.send(k,*v)
+ else
+ new.send(k,v)
+ end
+ }
+ end
+ ROOT[0] = new
+ Tk_WINDOWS["."] = new
+ end
+=end
+ def TkRoot.new(keys=nil, &b)
unless TkCore::INTERP.tk_windows['.']
TkCore::INTERP.tk_windows['.'] =
super(:without_creating=>true, :widgetname=>'.'){}
@@ -41,13 +62,7 @@ class Tk::Root<TkWindow
}
end
- if block_given?
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- root.instance_exec(root, &b)
- else
- root.instance_eval(&b)
- end
- end
+ root.instance_eval(&b) if block_given?
root
end
@@ -87,9 +102,7 @@ class Tk::Root<TkWindow
self.menu
end
- def Root.destroy
+ def TkRoot.destroy
TkCore::INTERP._invoke('destroy', '.')
end
end
-
-TkRoot = Tk::Root unless Object.const_defined? :TkRoot
diff --git a/ext/tk/lib/tk/scale.rb b/ext/tk/lib/tk/scale.rb
index 7e758d92f4..0b703aa055 100644
--- a/ext/tk/lib/tk/scale.rb
+++ b/ext/tk/lib/tk/scale.rb
@@ -3,7 +3,7 @@
#
require 'tk'
-class Tk::Scale<TkWindow
+class TkScale<TkWindow
TkCommandNames = ['scale'.freeze].freeze
WidgetClassName = 'Scale'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -14,31 +14,9 @@ class Tk::Scale<TkWindow
cmd = keys.delete('command')
keys['command'] = proc{|val| cmd.call(val.to_f)}
end
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- #tk_call_without_enc('scale', @path, *hash_kv(keys, true))
- tk_call_without_enc(self.class::TkCommandNames[0], @path,
- *hash_kv(keys, true))
- else
- begin
- tk_call_without_enc(self.class::TkCommandNames[0], @path,
- *hash_kv(keys, true))
- rescue
- tk_call_without_enc(self.class::TkCommandNames[0], @path)
- keys = __check_available_configure_options(keys)
- unless keys.empty?
- begin
- tk_call_without_enc('destroy', @path)
- rescue
- # cannot destroy
- configure(keys)
- else
- # re-create widget
- tk_call_without_enc(self.class::TkCommandNames[0], @path,
- *hash_kv(keys, true))
- end
- end
- end
- end
+ #tk_call_without_enc('scale', @path, *hash_kv(keys, true))
+ tk_call_without_enc(self.class::TkCommandNames[0], @path,
+ *hash_kv(keys, true))
else
#tk_call_without_enc('scale', @path)
tk_call_without_enc(self.class::TkCommandNames[0], @path)
@@ -106,6 +84,3 @@ class Tk::Scale<TkWindow
val
end
end
-
-#TkScale = Tk::Scale unless Object.const_defined? :TkScale
-Tk.__set_toplevel_aliases__(:Tk, Tk::Scale, :TkScale)
diff --git a/ext/tk/lib/tk/scrollbar.rb b/ext/tk/lib/tk/scrollbar.rb
index 87db46a9f9..70aadfdd4c 100644
--- a/ext/tk/lib/tk/scrollbar.rb
+++ b/ext/tk/lib/tk/scrollbar.rb
@@ -3,7 +3,7 @@
#
require 'tk'
-class Tk::Scrollbar<TkWindow
+class TkScrollbar<TkWindow
TkCommandNames = ['scrollbar'.freeze].freeze
WidgetClassName = 'Scrollbar'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -19,31 +19,9 @@ class Tk::Scrollbar<TkWindow
}
if keys and keys != None
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- #tk_call_without_enc('scrollbar', @path, *hash_kv(keys, true))
- tk_call_without_enc(self.class::TkCommandNames[0], @path,
- *hash_kv(keys, true))
- else
- begin
- tk_call_without_enc(self.class::TkCommandNames[0], @path,
- *hash_kv(keys, true))
- rescue
- tk_call_without_enc(self.class::TkCommandNames[0], @path)
- keys = __check_available_configure_options(keys)
- unless keys.empty?
- begin
- tk_call_without_enc('destroy', @path)
- rescue
- # cannot destroy
- configure(keys)
- else
- # re-create widget
- tk_call_without_enc(self.class::TkCommandNames[0], @path,
- *hash_kv(keys, true))
- end
- end
- end
- end
+ #tk_call_without_enc('scrollbar', @path, *hash_kv(keys, true))
+ tk_call_without_enc(self.class::TkCommandNames[0], @path,
+ *hash_kv(keys, true))
else
#tk_call_without_enc('scrollbar', @path)
tk_call_without_enc(self.class::TkCommandNames[0], @path)
@@ -125,33 +103,9 @@ class Tk::Scrollbar<TkWindow
def activate(element=None)
tk_send_without_enc('activate', element)
end
-
- def moveto(fraction)
- tk_send_without_enc('moveto', fraction)
- self
- end
-
- def scroll(*args)
- tk_send_without_enc('scroll', *args)
- self
- end
-
- def scroll_units(num)
- scroll(num, 'units')
- self
- end
-
- def scroll_pages(num)
- scroll(num, 'pages')
- self
- end
end
-#TkScrollbar = Tk::Scrollbar unless Object.const_defined? :TkScrollbar
-Tk.__set_toplevel_aliases__(:Tk, Tk::Scrollbar, :TkScrollbar)
-
-
-class Tk::XScrollbar<Tk::Scrollbar
+class TkXScrollbar<TkScrollbar
def create_self(keys)
keys = {} unless keys
keys['orient'] = 'horizontal'
@@ -160,11 +114,7 @@ class Tk::XScrollbar<Tk::Scrollbar
private :create_self
end
-#TkXScrollbar = Tk::XScrollbar unless Object.const_defined? :TkXScrollbar
-Tk.__set_toplevel_aliases__(:Tk, Tk::XScrollbar, :TkXScrollbar)
-
-
-class Tk::YScrollbar<Tk::Scrollbar
+class TkYScrollbar<TkScrollbar
def create_self(keys)
keys = {} unless keys
keys['orient'] = 'vertical'
@@ -172,6 +122,3 @@ class Tk::YScrollbar<Tk::Scrollbar
end
private :create_self
end
-
-#TkYScrollbar = Tk::YScrollbar unless Object.const_defined? :TkYScrollbar
-Tk.__set_toplevel_aliases__(:Tk, Tk::YScrollbar, :TkYScrollbar)
diff --git a/ext/tk/lib/tk/scrollbox.rb b/ext/tk/lib/tk/scrollbox.rb
index d20742a666..fd04057fb6 100644
--- a/ext/tk/lib/tk/scrollbox.rb
+++ b/ext/tk/lib/tk/scrollbox.rb
@@ -1,19 +1,16 @@
#
# tk/scrollbox.rb - Tk Listbox with Scrollbar
# as an example of Composite Widget
+# $Date$
# by Yukihiro Matsumoto <matz@netlab.co.jp>
#
require 'tk'
require 'tk/listbox'
-class TkScrollbox<Tk::Listbox
+class TkScrollbox<TkListbox
include TkComposite
def initialize_composite(keys=nil)
- #list = Tk::Listbox.new(@frame)
- # -> use current TkListbox class
list = TkListbox.new(@frame)
- #scroll = Tk::Scrollbar.new(@frame)
- # -> use current TkScrollbar class
scroll = TkScrollbar.new(@frame)
@path = list.path
diff --git a/ext/tk/lib/tk/spinbox.rb b/ext/tk/lib/tk/spinbox.rb
index 34dc1904f7..9a10977d12 100644
--- a/ext/tk/lib/tk/spinbox.rb
+++ b/ext/tk/lib/tk/spinbox.rb
@@ -1,11 +1,12 @@
#
# tk/spinbox.rb - Tk spinbox classes
+# $Date$
# by Yukihiro Matsumoto <matz@caelum.co.jp>
#
require 'tk'
require 'tk/entry'
-class Tk::Spinbox<Tk::Entry
+class TkSpinbox<TkEntry
TkCommandNames = ['spinbox'.freeze].freeze
WidgetClassName = 'Spinbox'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -37,24 +38,6 @@ class Tk::Spinbox<Tk::Entry
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@@ -114,6 +97,3 @@ class Tk::Spinbox<Tk::Entry
_fromUTF8(tk_send_without_enc('set', _get_eval_enc_str(str)))
end
end
-
-#TkSpinbox = Tk::Spinbox unless Object.const_defined? :TkSpinbox
-Tk.__set_toplevel_aliases__(:Tk, Tk::Spinbox, :TkSpinbox)
diff --git a/ext/tk/lib/tk/text.rb b/ext/tk/lib/tk/text.rb
index 4ec82bed1d..49d4b5625b 100644
--- a/ext/tk/lib/tk/text.rb
+++ b/ext/tk/lib/tk/text.rb
@@ -1,5 +1,6 @@
#
# tk/text.rb - Tk text classes
+# $Date$
# by Yukihiro Matsumoto <matz@caelum.co.jp>
require 'tk'
require 'tk/itemfont'
@@ -32,40 +33,34 @@ module TkTextTagConfig
def tag_cget(tagOrId, option)
itemcget(['tag', tagOrId], option)
end
- def tag_cget_strict(tagOrId, option)
- itemcget_strict(['tag', tagOrId], option)
- end
def tag_configure(tagOrId, slot, value=None)
itemconfigure(['tag', tagOrId], slot, value)
end
def tag_configinfo(tagOrId, slot=nil)
- itemconfiginfo(['tag', tagOrId], slot)
+ itemconfigure(['tag', tagOrId], slot)
end
def current_tag_configinfo(tagOrId, slot=nil)
- current_itemconfiginfo(['tag', tagOrId], slot)
+ itemconfigure(['tag', tagOrId], slot)
end
def window_cget(tagOrId, option)
itemcget(['window', tagOrId], option)
end
- def window_cget_strict(tagOrId, option)
- itemcget_strict(['window', tagOrId], option)
- end
def window_configure(tagOrId, slot, value=None)
itemconfigure(['window', tagOrId], slot, value)
end
def window_configinfo(tagOrId, slot=nil)
- itemconfiginfo(['window', tagOrId], slot)
+ itemconfigure(['window', tagOrId], slot)
end
def current_window_configinfo(tagOrId, slot=nil)
- current_itemconfiginfo(['window', tagOrId], slot)
+ itemconfigure(['window', tagOrId], slot)
end
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
end
-class Tk::Text<TkTextWin
+class TkText<TkTextWin
ItemConfCMD = ['tag'.freeze, 'configure'.freeze].freeze
#include TkTreatTextTagFont
include TkTextTagConfig
@@ -79,9 +74,9 @@ class Tk::Text<TkTextWin
mod = mod.to_s
if mod =~ /^\s*[+-]?\d/
- Tk::Text::IndexString.new(String.new(id) << ' + ' << mod)
+ TkText::IndexString.new(String.new(id) << ' + ' << mod)
else
- Tk::Text::IndexString.new(String.new(id) << ' ' << mod)
+ TkText::IndexString.new(String.new(id) << ' ' << mod)
end
end
@@ -90,20 +85,20 @@ class Tk::Text<TkTextWin
mod = mod.to_s
if mod =~ /^\s*[+-]?\d/
- Tk::Text::IndexString.new(String.new(id) << ' - ' << mod)
+ TkText::IndexString.new(String.new(id) << ' - ' << mod)
elsif mod =~ /^\s*[-]\s+(\d.*)$/
- Tk::Text::IndexString.new(String.new(id) << ' - -' << $1)
+ TkText::IndexString.new(String.new(id) << ' - -' << $1)
else
- Tk::Text::IndexString.new(String.new(id) << ' ' << mod)
+ TkText::IndexString.new(String.new(id) << ' ' << mod)
end
end
def chars(mod)
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
- Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' chars')
+ TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' chars')
else
- Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' chars')
+ TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' chars')
end
end
alias char chars
@@ -112,9 +107,9 @@ class Tk::Text<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
- Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' display chars')
+ TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' display chars')
else
- Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' display chars')
+ TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' display chars')
end
end
alias display_char display_chars
@@ -123,9 +118,9 @@ class Tk::Text<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
- Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' any chars')
+ TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' any chars')
else
- Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' any chars')
+ TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' any chars')
end
end
alias any_char any_chars
@@ -134,9 +129,9 @@ class Tk::Text<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
- Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' indices')
+ TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' indices')
else
- Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' indices')
+ TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' indices')
end
end
@@ -144,9 +139,9 @@ class Tk::Text<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
- Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' display indices')
+ TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' display indices')
else
- Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' display indices')
+ TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' display indices')
end
end
@@ -154,18 +149,18 @@ class Tk::Text<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
- Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' any indices')
+ TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' any indices')
else
- Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' any indices')
+ TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' any indices')
end
end
def lines(mod)
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
- Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' lines')
+ TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' lines')
else
- Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' lines')
+ TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' lines')
end
end
alias line lines
@@ -174,9 +169,9 @@ class Tk::Text<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
- Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' display_lines')
+ TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' display_lines')
else
- Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' display lines')
+ TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' display lines')
end
end
alias display_line display_lines
@@ -185,43 +180,43 @@ class Tk::Text<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
- Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' any_lines')
+ TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' any_lines')
else
- Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' any lines')
+ TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' any lines')
end
end
alias any_line any_lines
def linestart
- Tk::Text::IndexString.new(String.new(id) << ' linestart')
+ TkText::IndexString.new(String.new(id) << ' linestart')
end
def lineend
- Tk::Text::IndexString.new(String.new(id) << ' lineend')
+ TkText::IndexString.new(String.new(id) << ' lineend')
end
def display_linestart
# Tk8.5 feature
- Tk::Text::IndexString.new(String.new(id) << ' display linestart')
+ TkText::IndexString.new(String.new(id) << ' display linestart')
end
def display_lineend
# Tk8.5 feature
- Tk::Text::IndexString.new(String.new(id) << ' display lineend')
+ TkText::IndexString.new(String.new(id) << ' display lineend')
end
def wordstart
- Tk::Text::IndexString.new(String.new(id) << ' wordstart')
+ TkText::IndexString.new(String.new(id) << ' wordstart')
end
def wordend
- Tk::Text::IndexString.new(String.new(id) << ' wordend')
+ TkText::IndexString.new(String.new(id) << ' wordend')
end
def display_wordstart
# Tk8.5 feature
- Tk::Text::IndexString.new(String.new(id) << ' display wordstart')
+ TkText::IndexString.new(String.new(id) << ' display wordstart')
end
def display_wordend
# Tk8.5 feature
- Tk::Text::IndexString.new(String.new(id) << ' display wordend')
+ TkText::IndexString.new(String.new(id) << ' display wordend')
end
end
@@ -256,11 +251,7 @@ class Tk::Text<TkTextWin
def self.new(*args, &block)
obj = super(*args){}
obj.init_instance_variable
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- obj.instance_exec(obj, &block) if defined? yield
- else
- obj.instance_eval(&block) if defined? yield
- end
+ obj.instance_eval(&block) if defined? yield
obj
end
@@ -270,12 +261,8 @@ class Tk::Text<TkTextWin
end
def __destroy_hook__
- TkTextTag::TTagID_TBL.mutex.synchronize{
- TkTextTag::TTagID_TBL.delete(@path)
- }
- TkTextTag::TMarkID_TBL.mutex.synchronize{
- TkTextMark::TMarkID_TBL.delete(@path)
- }
+ TkTextTag::TTagID_TBL.delete(@path)
+ TkTextMark::TMarkID_TBL.delete(@path)
end
def create_self(keys)
@@ -298,16 +285,16 @@ class Tk::Text<TkTextWin
private :__strval_optkeys
def self.at(x, y)
- Tk::Text::IndexString.at(x, y)
+ TkText::IndexString.at(x, y)
end
def at(x, y)
- Tk::Text::IndexString.at(x, y)
+ TkText::IndexString.at(x, y)
end
def index(idx)
- Tk::Text::IndexString.new(tk_send_without_enc('index',
- _get_eval_enc_str(idx)))
+ TkText::IndexString.new(tk_send_without_enc('index',
+ _get_eval_enc_str(idx)))
end
def get_displaychars(*index)
@@ -409,7 +396,7 @@ class Tk::Text<TkTextWin
end
alias previous_mark mark_previous
- def image_cget_strict(index, slot)
+ def image_cget(index, slot)
case slot.to_s
when 'text', 'label', 'show', 'data', 'file'
_fromUTF8(tk_send_without_enc('image', 'cget',
@@ -421,28 +408,6 @@ class Tk::Text<TkTextWin
end
end
- def image_cget(index, slot)
- unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- image_cget_strict(index, slot)
- else
- begin
- image_cget_strict(index, slot)
- rescue => e
- begin
- if current_image_configinfo(index).has_key?(slot.to_s)
- # not tag error & option is known -> error on known option
- fail e
- else
- # not tag error & option is unknown
- nil
- end
- rescue
- fail e # tag error
- end
- end
- end
- end
-
def image_configure(index, slot, value=None)
if slot.kind_of?(Hash)
_fromUTF8(tk_send_without_enc('image', 'configure',
@@ -748,17 +713,15 @@ class Tk::Text<TkTextWin
def tag_delete(*tags)
tk_send_without_enc('tag', 'delete',
*(tags.collect{|tag| _get_eval_enc_str(tag)}))
- TkTextTag::TTagID_TBL.mutex.synchronize{
- if TkTextTag::TTagID_TBL[@path]
- tags.each{|tag|
- if tag.kind_of?(TkTextTag)
- TkTextTag::TTagID_TBL[@path].delete(tag.id)
- else
- TkTextTag::TTagID_TBL[@path].delete(tag)
- end
- }
- end
- }
+ if TkTextTag::TTagID_TBL[@path]
+ tags.each{|tag|
+ if tag.kind_of?(TkTextTag)
+ TkTextTag::TTagID_TBL[@path].delete(tag.id)
+ else
+ TkTextTag::TTagID_TBL[@path].delete(tag)
+ end
+ }
+ end
self
end
alias deltag tag_delete
@@ -1005,7 +968,7 @@ class Tk::Text<TkTextWin
false, true)
r = []
while key=l.shift
- r.push [Tk::Text::IndexString.new(key), Tk::Text::IndexString.new(l.shift)]
+ r.push [TkText::IndexString.new(key), TkText::IndexString.new(l.shift)]
end
r
end
@@ -1015,7 +978,7 @@ class Tk::Text<TkTextWin
_get_eval_enc_str(tag),
_get_eval_enc_str(first),
_get_eval_enc_str(last))).collect{|idx|
- Tk::Text::IndexString.new(idx)
+ TkText::IndexString.new(idx)
}
end
@@ -1024,7 +987,7 @@ class Tk::Text<TkTextWin
_get_eval_enc_str(tag),
_get_eval_enc_str(first),
_get_eval_enc_str(last))).collect{|idx|
- Tk::Text::IndexString.new(idx)
+ TkText::IndexString.new(idx)
}
end
@@ -1220,11 +1183,6 @@ class Tk::Text<TkTextWin
end
def _ktext_length(txt)
- if TkCore::WITH_ENCODING ### Ruby 1.9 !!!!!!!!!!!!!
- return txt.length
- end
- ###########################
-
if $KCODE !~ /n/i
return txt.gsub(/[^\Wa-zA-Z_\d]/, ' ').length
end
@@ -1274,7 +1232,7 @@ class Tk::Text<TkTextWin
if ret == ""
nil
else
- Tk::Text::IndexString.new(ret)
+ TkText::IndexString.new(ret)
end
end
@@ -1309,7 +1267,7 @@ class Tk::Text<TkTextWin
if ret == ""
nil
else
- Tk::Text::IndexString.new(ret)
+ TkText::IndexString.new(ret)
end
end
@@ -1498,10 +1456,10 @@ class Tk::Text<TkTextWin
# retrieve index
idx = str.index(/ /, i)
if idx
- result.push(Tk::Text::IndexString.new(str[i..(idx-1)]))
+ result.push(TkText::IndexString.new(str[i..(idx-1)]))
i = idx + 1
else
- result.push(Tk::Text::IndexString.new(str[i..-1]))
+ result.push(TkText::IndexString.new(str[i..-1]))
break
end
end
@@ -1569,17 +1527,13 @@ class Tk::Text<TkTextWin
end
end
-#TkText = Tk::Text unless Object.const_defined? :TkText
-Tk.__set_toplevel_aliases__(:Tk, Tk::Text, :TkText)
-
-
#######################################
-class Tk::Text::Peer < Tk::Text
+class TkText::Peer < TkText
# Tk8.5 feature
def initialize(text, parent=nil, keys={})
- unless text.kind_of?(Tk::Text)
- fail ArgumentError, "Tk::Text is expected for 1st argument"
+ unless text.kind_of?(TkText)
+ fail ArgumentError, "TkText is expected for 1st argument"
end
@src_text = text
super(parent, keys)
diff --git a/ext/tk/lib/tk/textimage.rb b/ext/tk/lib/tk/textimage.rb
index fb306a9c17..a29b23c7dd 100644
--- a/ext/tk/lib/tk/textimage.rb
+++ b/ext/tk/lib/tk/textimage.rb
@@ -5,11 +5,11 @@ require 'tk'
require 'tk/text'
class TkTextImage<TkObject
- include Tk::Text::IndexModMethods
+ include TkText::IndexModMethods
def initialize(parent, index, keys)
- #unless parent.kind_of?(Tk::Text)
- # fail ArgumentError, "expect Tk::Text for 1st argument"
+ #unless parent.kind_of?(TkText)
+ # fail ArgumentError, "expect TkText for 1st argument"
#end
@t = parent
if index == 'end' || index == :end
@@ -34,7 +34,7 @@ class TkTextImage<TkObject
end
def id
- Tk::Text::IndexString.new(@id)
+ TkText::IndexString.new(@id)
end
def mark
@path
@@ -52,10 +52,6 @@ class TkTextImage<TkObject
@t.image_cget(@index, slot)
end
- def cget_strict(slot)
- @t.image_cget_strict(@index, slot)
- end
-
def configure(slot, value=None)
@t.image_configure(@index, slot, value)
self
@@ -84,5 +80,3 @@ class TkTextImage<TkObject
value
end
end
-
-TktImage = TkTextImage
diff --git a/ext/tk/lib/tk/textmark.rb b/ext/tk/lib/tk/textmark.rb
index 72c1ce1ab4..650d95af70 100644
--- a/ext/tk/lib/tk/textmark.rb
+++ b/ext/tk/lib/tk/textmark.rb
@@ -5,54 +5,38 @@ require 'tk'
require 'tk/text'
class TkTextMark<TkObject
- include Tk::Text::IndexModMethods
+ include TkText::IndexModMethods
TMarkID_TBL = TkCore::INTERP.create_table
+ Tk_TextMark_ID = ['mark'.freeze, '00000'.taint].freeze
- (Tk_TextMark_ID = ['mark'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- TMarkID_TBL.mutex.synchronize{ TMarkID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ TMarkID_TBL.clear }
def TkTextMark.id2obj(text, id)
tpath = text.path
- TMarkID_TBL.mutex.synchronize{
- if TMarkID_TBL[tpath]
- TMarkID_TBL[tpath][id]? TMarkID_TBL[tpath][id]: id
- else
- id
- end
- }
+ return id unless TMarkID_TBL[tpath]
+ TMarkID_TBL[tpath][id]? TMarkID_TBL[tpath][id]: id
end
def initialize(parent, index)
- #unless parent.kind_of?(Tk::Text)
- # fail ArgumentError, "expect Tk::Text for 1st argument"
+ #unless parent.kind_of?(TkText)
+ # fail ArgumentError, "expect TkText for 1st argument"
#end
@parent = @t = parent
@tpath = parent.path
- Tk_TextMark_ID.mutex.synchronize{
- # @path = @id = Tk_TextMark_ID.join('')
- @path = @id = Tk_TextMark_ID.join(TkCore::INTERP._ip_id_).freeze
- Tk_TextMark_ID[1].succ!
- }
- TMarkID_TBL.mutex.synchronize{
- TMarkID_TBL[@id] = self
- TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
- TMarkID_TBL[@tpath][@id] = self
- }
+ # @path = @id = Tk_TextMark_ID.join('')
+ @path = @id = Tk_TextMark_ID.join(TkCore::INTERP._ip_id_).freeze
+ TMarkID_TBL[@id] = self
+ TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
+ TMarkID_TBL[@tpath][@id] = self
+ Tk_TextMark_ID[1].succ!
tk_call_without_enc(@t.path, 'mark', 'set', @id,
_get_eval_enc_str(index))
@t._addtag id, self
end
def id
- Tk::Text::IndexString.new(@id)
+ TkText::IndexString.new(@id)
end
def exist?
@@ -65,15 +49,15 @@ class TkTextMark<TkObject
end
=begin
- # move to Tk::Text::IndexModMethods module
+ # move to TkText::IndexModMethods module
def +(mod)
return chars(mod) if mod.kind_of?(Numeric)
mod = mod.to_s
if mod =~ /^\s*[+-]?\d/
- Tk::Text::IndexString.new(@id + ' + ' + mod)
+ TkText::IndexString.new(@id + ' + ' + mod)
else
- Tk::Text::IndexString.new(@id + ' ' + mod)
+ TkText::IndexString.new(@id + ' ' + mod)
end
end
@@ -82,11 +66,11 @@ class TkTextMark<TkObject
mod = mod.to_s
if mod =~ /^\s*[+-]?\d/
- Tk::Text::IndexString.new(@id + ' - ' + mod)
+ TkText::IndexString.new(@id + ' - ' + mod)
elsif mod =~ /^\s*[-]\s+(\d.*)$/
- Tk::Text::IndexString.new(@id + ' - -' + $1)
+ TkText::IndexString.new(@id + ' - -' + $1)
else
- Tk::Text::IndexString.new(@id + ' ' + mod)
+ TkText::IndexString.new(@id + ' ' + mod)
end
end
=end
@@ -137,68 +121,46 @@ class TkTextMark<TkObject
end
end
end
-TktMark = TkTextMark
class TkTextNamedMark<TkTextMark
- def self.new(parent, name, index=nil)
- TMarkID_TBL.mutex.synchronize{
- if TMarkID_TBL[parent.path] && TMarkID_TBL[parent.path][name]
- obj = TMarkID_TBL[parent.path][name]
- else
- # super(parent, name, *args)
- (obj = self.allocate).instance_eval{
- @parent = @t = parent
- @tpath = parent.path
- @path = @id = name
- TMarkID_TBL[@id] = self
- TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
- TMarkID_TBL[@tpath][@id] = self unless TMarkID_TBL[@tpath][@id]
- @t._addtag @id, self
- }
- obj
- end
-
- if obj && index
- tk_call_without_enc(parent.path, 'mark', 'set', name,
- _get_eval_enc_str(index))
- end
- obj
- }
+ def self.new(parent, name, *args)
+ if TMarkID_TBL[parent.path] && TMarkID_TBL[parent.path][name]
+ return TMarkID_TBL[parent.path][name]
+ else
+ super(parent, name, *args)
+ end
end
def initialize(parent, name, index=nil)
- # dummy:: not called by 'new' method
-
- #unless parent.kind_of?(Tk::Text)
- # fail ArgumentError, "expect Tk::Text for 1st argument"
+ #unless parent.kind_of?(TkText)
+ # fail ArgumentError, "expect TkText for 1st argument"
#end
@parent = @t = parent
@tpath = parent.path
@path = @id = name
+ TMarkID_TBL[@id] = self
+ TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
+ TMarkID_TBL[@tpath][@id] = self unless TMarkID_TBL[@tpath][@id]
tk_call_without_enc(@t.path, 'mark', 'set', @id,
_get_eval_enc_str(index)) if index
- @t._addtag @id, self
+ @t._addtag id, self
end
end
-TktNamedMark = TkTextNamedMark
class TkTextMarkInsert<TkTextNamedMark
def self.new(parent,*args)
super(parent, 'insert', *args)
end
end
-TktMarkInsert = TkTextMarkInsert
class TkTextMarkCurrent<TkTextNamedMark
def self.new(parent,*args)
super(parent, 'current', *args)
end
end
-TktMarkCurrent = TkTextMarkCurrent
class TkTextMarkAnchor<TkTextNamedMark
def self.new(parent,*args)
super(parent, 'anchor', *args)
end
end
-TktMarkAnchor = TkTextMarkAnchor
diff --git a/ext/tk/lib/tk/texttag.rb b/ext/tk/lib/tk/texttag.rb
index b08d923ea1..cc2c56210f 100644
--- a/ext/tk/lib/tk/texttag.rb
+++ b/ext/tk/lib/tk/texttag.rb
@@ -7,29 +7,17 @@ require 'tk/tagfont'
class TkTextTag<TkObject
include TkTreatTagFont
- include Tk::Text::IndexModMethods
+ include TkText::IndexModMethods
TTagID_TBL = TkCore::INTERP.create_table
+ Tk_TextTag_ID = ['tag'.freeze, '00000'.taint].freeze
- (Tk_TextTag_ID = ['tag'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- TTagID_TBL.mutex.synchronize{ TTagID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ TTagID_TBL.clear }
def TkTextTag.id2obj(text, id)
tpath = text.path
- TTagID_TBL.mutex.synchronize{
- if TTagID_TBL[tpath]
- TTagID_TBL[tpath][id]? TTagID_TBL[tpath][id]: id
- else
- id
- end
- }
+ return id unless TTagID_TBL[tpath]
+ TTagID_TBL[tpath][id]? TTagID_TBL[tpath][id]: id
end
def initialize(parent, *args)
@@ -38,16 +26,12 @@ class TkTextTag<TkObject
#end
@parent = @t = parent
@tpath = parent.path
- Tk_TextTag_ID.mutex.synchronize{
- # @path = @id = Tk_TextTag_ID.join('')
- @path = @id = Tk_TextTag_ID.join(TkCore::INTERP._ip_id_).freeze
- Tk_TextTag_ID[1].succ!
- }
- TTagID_TBL.mutex.synchronize{
- TTagID_TBL[@id] = self
- TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
- TTagID_TBL[@tpath][@id] = self
- }
+ # @path = @id = Tk_TextTag_ID.join('')
+ @path = @id = Tk_TextTag_ID.join(TkCore::INTERP._ip_id_).freeze
+ # TTagID_TBL[@id] = self
+ TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
+ TTagID_TBL[@tpath][@id] = self
+ Tk_TextTag_ID[1].succ!
#tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
if args != []
keys = args.pop
@@ -63,7 +47,7 @@ class TkTextTag<TkObject
end
def id
- Tk::Text::IndexString.new(@id)
+ TkText::IndexString.new(@id)
end
def exist?
@@ -76,11 +60,11 @@ class TkTextTag<TkObject
end
def first
- Tk::Text::IndexString.new(@id + '.first')
+ TkText::IndexString.new(@id + '.first')
end
def last
- Tk::Text::IndexString.new(@id + '.last')
+ TkText::IndexString.new(@id + '.last')
end
def add(*indices)
@@ -99,7 +83,7 @@ class TkTextTag<TkObject
l = tk_split_simplelist(tk_call_without_enc(@t.path, 'tag', 'ranges', @id))
r = []
while key=l.shift
- r.push [Tk::Text::IndexString.new(key), Tk::Text::IndexString.new(l.shift)]
+ r.push [TkText::IndexString.new(key), TkText::IndexString.new(l.shift)]
end
r
end
@@ -108,7 +92,7 @@ class TkTextTag<TkObject
simplelist(tk_call_without_enc(@t.path, 'tag', 'nextrange', @id,
_get_eval_enc_str(first),
_get_eval_enc_str(last))).collect{|idx|
- Tk::Text::IndexString.new(idx)
+ TkText::IndexString.new(idx)
}
end
@@ -116,7 +100,7 @@ class TkTextTag<TkObject
simplelist(tk_call_without_enc(@t.path, 'tag', 'prevrange', @id,
_get_eval_enc_str(first),
_get_eval_enc_str(last))).collect{|idx|
- Tk::Text::IndexString.new(idx)
+ TkText::IndexString.new(idx)
}
end
@@ -132,9 +116,6 @@ class TkTextTag<TkObject
def cget(key)
@t.tag_cget @id, key
end
- def cget_strict(key)
- @t.tag_cget_strict @id, key
- end
=begin
def cget(key)
case key.to_s
@@ -240,58 +221,40 @@ class TkTextTag<TkObject
def destroy
tk_call_without_enc(@t.path, 'tag', 'delete', @id)
- TTagID_TBL.mutex.synchronize{
- TTagID_TBL[@tpath].delete(@id) if TTagID_TBL[@tpath]
- }
+ TTagID_TBL[@tpath].delete(@id) if TTagID_TBL[@tpath]
self
end
end
-TktTag = TkTextTag
class TkTextNamedTag<TkTextTag
def self.new(parent, name, *args)
- tagobj = nil
- TTagID_TBL.mutex.synchronize{
- if TTagID_TBL[parent.path] && TTagID_TBL[parent.path][name]
- tagobj = TTagID_TBL[parent.path][name]
- else
- # super(parent, name, *args)
- (tagobj = self.allocate).instance_eval{
- @parent = @t = parent
- @tpath = parent.path
- @path = @id = name
- TTagID_TBL[@id] = self
- TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
- TTagID_TBL[@tpath][@id] = self unless TTagID_TBL[@tpath][@id]
- @t._addtag @id, self
- }
- end
- }
-
- if args != []
- keys = args.pop
- if keys.kind_of?(Hash)
- tagobj.add(*args) if args != []
- tagobj.configure(keys)
- else
- args.push keys
- tagobj.add(*args)
+ if TTagID_TBL[parent.path] && TTagID_TBL[parent.path][name]
+ tagobj = TTagID_TBL[parent.path][name]
+ if args != []
+ keys = args.pop
+ if keys.kind_of?(Hash)
+ tagobj.add(*args) if args != []
+ tagobj.configure(keys)
+ else
+ args.push keys
+ tagobj.add(*args)
+ end
end
+ return tagobj
+ else
+ super(parent, name, *args)
end
-
- tagobj
end
def initialize(parent, name, *args)
- # dummy:: not called by 'new' method
-
- #unless parent.kind_of?(Tk::Text)
- # fail ArgumentError, "expect Tk::Text for 1st argument"
+ #unless parent.kind_of?(TkText)
+ # fail ArgumentError, "expect TkText for 1st argument"
#end
@parent = @t = parent
@tpath = parent.path
@path = @id = name
-
+ TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
+ TTagID_TBL[@tpath][@id] = self unless TTagID_TBL[@tpath][@id]
#if mode
# tk_call @t.path, "addtag", @id, *args
#end
@@ -305,14 +268,12 @@ class TkTextNamedTag<TkTextTag
add(*args)
end
end
- @t._addtag @id, self
+ @t._addtag id, self
end
end
-TktNamedTag = TkTextNamedTag
class TkTextTagSel<TkTextNamedTag
def self.new(parent, *args)
super(parent, 'sel', *args)
end
end
-TktTagSel = TkTextTagSel
diff --git a/ext/tk/lib/tk/textwindow.rb b/ext/tk/lib/tk/textwindow.rb
index 004422e4f3..605c40addd 100644
--- a/ext/tk/lib/tk/textwindow.rb
+++ b/ext/tk/lib/tk/textwindow.rb
@@ -5,11 +5,11 @@ require 'tk'
require 'tk/text'
class TkTextWindow<TkObject
- include Tk::Text::IndexModMethods
+ include TkText::IndexModMethods
def initialize(parent, index, keys = {})
- #unless parent.kind_of?(Tk::Text)
- # fail ArgumentError, "expect Tk::Text for 1st argument"
+ #unless parent.kind_of?(TkText)
+ # fail ArgumentError, "expect TkText for 1st argument"
#end
@t = parent
if index == 'end' || index == :end
@@ -55,7 +55,7 @@ class TkTextWindow<TkObject
end
def id
- Tk::Text::IndexString.new(_epath(@id))
+ TkText::IndexString.new(_epath(@id))
end
def mark
@path
@@ -72,9 +72,6 @@ class TkTextWindow<TkObject
def cget(slot)
@t.window_cget(@index, slot)
end
- def cget_strict(slot)
- @t.window_cget_strict(@index, slot)
- end
def configure(slot, value=None)
if slot.kind_of?(Hash)
@@ -150,5 +147,3 @@ class TkTextWindow<TkObject
value
end
end
-
-TktWindow = TkTextWindow
diff --git a/ext/tk/lib/tk/timer.rb b/ext/tk/lib/tk/timer.rb
index 91840d0575..47f2b79350 100644
--- a/ext/tk/lib/tk/timer.rb
+++ b/ext/tk/lib/tk/timer.rb
@@ -11,12 +11,7 @@ class TkTimer
TkCommandNames = ['after'.freeze].freeze
- (Tk_CBID = ['a'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
+ Tk_CBID = ['a'.freeze, '00000'.taint].freeze
Tk_CBTBL = {}.taint
TkCore::INTERP.add_tk_procs('rb_after', 'id', <<-'EOL')
@@ -101,9 +96,9 @@ class TkTimer
return self
end
@after_script = "rb_after #{@id}"
+ @after_id = tk_call_without_enc('after', sleep, @after_script)
@current_args = args
@current_script = [sleep, @after_script]
- @after_id = tk_call_without_enc('after', sleep, @after_script)
self
end
@@ -111,8 +106,7 @@ class TkTimer
if @running == false || @proc_max == 0 || @do_loop == 0
Tk_CBTBL.delete(@id) ;# for GC
@running = false
- # @wait_var.value = 0
- __at_end__
+ @wait_var.value = 0
return
end
if @current_pos >= @proc_max
@@ -121,8 +115,7 @@ class TkTimer
else
Tk_CBTBL.delete(@id) ;# for GC
@running = false
- # @wait_var.value = 0
- __at_end__
+ @wait_var.value = 0
return
end
end
@@ -145,16 +138,12 @@ class TkTimer
end
def initialize(*args, &b)
- Tk_CBID.mutex.synchronize{
- # @id = Tk_CBID.join('')
- @id = Tk_CBID.join(TkCore::INTERP._ip_id_)
- Tk_CBID[1].succ!
- }
+ # @id = Tk_CBID.join('')
+ @id = Tk_CBID.join(TkCore::INTERP._ip_id_)
+ Tk_CBID[1].succ!
@wait_var = TkVariable.new(0)
- @at_end_proc = nil
-
@cb_cmd = TkCore::INTERP.get_cb_entry(self.method(:do_callback))
@set_next = true
@@ -214,12 +203,6 @@ class TkTimer
attr_accessor :loop_exec
- def __at_end__
- @at_end_proc.call(self) if @at_end_proc
- @wait_var.value = 0 # for wait
- end
- private :__at_end__
-
def cb_call
@cb_cmd.call
end
@@ -437,8 +420,7 @@ class TkTimer
def cancel
@running = false
- # @wait_var.value = 0
- __at_end__
+ @wait_var.value = 0
tk_call 'after', 'cancel', @after_id if @after_id
@after_id = nil
@@ -482,21 +464,6 @@ class TkTimer
end
end
- def at_end(*arg, &b)
- if arg.empty?
- if b
- @at_end_proc = b
- else
- # no proc
- return @at_end_proc
- end
- else
- fail ArgumentError, "wrong number of arguments" if arg.length != 1 || b
- @at_end_proc = arg[0]
- end
- self
- end
-
def wait(on_thread = true, check_root = false)
if $SAFE >= 4
fail SecurityError, "can't wait timer at $SAFE >= 4"
@@ -595,8 +562,7 @@ class TkRTTimer < TkTimer
if @running == false || @proc_max == 0 || @do_loop == 0
Tk_CBTBL.delete(@id) ;# for GC
@running = false
- # @wait_var.value = 0
- __at_end__
+ @wait_var.value = 0
return
end
if @current_pos >= @proc_max
@@ -605,8 +571,7 @@ class TkRTTimer < TkTimer
else
Tk_CBTBL.delete(@id) ;# for GC
@running = false
- # @wait_var.value = 0
- __at_end__
+ @wait_var.value = 0
return
end
end
diff --git a/ext/tk/lib/tk/toplevel.rb b/ext/tk/lib/tk/toplevel.rb
index bd6e8307f5..5e199e1330 100644
--- a/ext/tk/lib/tk/toplevel.rb
+++ b/ext/tk/lib/tk/toplevel.rb
@@ -5,7 +5,7 @@ require 'tk'
require 'tk/wm'
require 'tk/menuspec'
-class Tk::Toplevel<TkWindow
+class TkToplevel<TkWindow
include Wm
include TkMenuSpec
@@ -72,7 +72,7 @@ class Tk::Toplevel<TkWindow
conf_methods = _symbolkey2str(__methodcall_optkeys())
- keys.each{|k,v| # k is a String
+ keys.each{|k,v|
if conf_methods.key?(k)
wm_cmds[conf_methods[k]] = v
elsif Wm.method_defined?(k)
@@ -117,10 +117,9 @@ class Tk::Toplevel<TkWindow
end
if @classname.kind_of? TkBindTag
@db_class = @classname
- keys['class'] = @classname = @classname.id
+ @classname = @classname.id
elsif @classname
@db_class = TkDatabaseClass.new(@classname)
- keys['class'] = @classname
else
@db_class = self.class
@classname = @db_class::WidgetClassName
@@ -166,10 +165,9 @@ class Tk::Toplevel<TkWindow
end
if @classname.kind_of? TkBindTag
@db_class = @classname
- keys['class'] = @classname = @classname.id
+ @classname = @classname.id
elsif @classname
@db_class = TkDatabaseClass.new(@classname)
- keys['class'] = @classname
else
@db_class = self.class
@classname = @db_class::WidgetClassName
@@ -257,6 +255,3 @@ class Tk::Toplevel<TkWindow
end
end
end
-
-#TkToplevel = Tk::Toplevel unless Object.const_defined? :TkToplevel
-Tk.__set_toplevel_aliases__(:Tk, Tk::Toplevel, :TkToplevel)
diff --git a/ext/tk/lib/tk/ttk_selector.rb b/ext/tk/lib/tk/ttk_selector.rb
deleted file mode 100644
index 72ed637a38..0000000000
--- a/ext/tk/lib/tk/ttk_selector.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-#
-# ttk_selector
-#
-######################################
-# toplevel classes/modules
-module Tk
- @TOPLEVEL_ALIAS_TABLE[:Ttk] = {
- :TkButton => 'tkextlib/tile/tbutton',
-
- :TkCheckbutton => 'tkextlib/tile/tcheckbutton',
- :TkCheckButton => 'tkextlib/tile/tcheckbutton',
-
- # :TkDialog => 'tkextlib/tile/dialog',
-
- :TkEntry => 'tkextlib/tile/tentry',
-
- :TkCombobox => 'tkextlib/tile/tcombobox',
-
- :TkFrame => 'tkextlib/tile/tframe',
-
- :TkLabel => 'tkextlib/tile/tlabel',
-
- :TkLabelframe => 'tkextlib/tile/tlabelframe',
- :TkLabelFrame => 'tkextlib/tile/tlabelframe',
-
- :TkMenubutton => 'tkextlib/tile/tmenubutton',
- :TkMenuButton => 'tkextlib/tile/tmenubutton',
-
- :TkNotebook => 'tkextlib/tile/tnotebook',
-
- # :TkPaned => 'tkextlib/tile/tpaned',
- :TkPanedwindow => 'tkextlib/tile/tpaned',
- :TkPanedWindow => 'tkextlib/tile/tpaned',
-
- :TkProgressbar => 'tkextlib/tile/tprogressbar',
-
- :TkRadiobutton => 'tkextlib/tile/tradiobutton',
- :TkRadioButton => 'tkextlib/tile/tradiobutton',
-
- :TkScale => 'tkextlib/tile/tscale',
- # :TkProgress => 'tkextlib/tile/tscale',
-
- :TkScrollbar => 'tkextlib/tile/tscrollbar',
- :TkXScrollbar => 'tkextlib/tile/tscrollbar',
- :TkYScrollbar => 'tkextlib/tile/tscrollbar',
-
- :TkSeparator => 'tkextlib/tile/tseparator',
-
- :TkSizeGrip => 'tkextlib/tile/sizegrip',
- :TkSizegrip => 'tkextlib/tile/sizegrip',
-
- # :TkSquare => 'tkextlib/tile/tsquare',
-
- :TkTreeview => 'tkextlib/tile/treeview',
- }
- @TOPLEVEL_ALIAS_TABLE[:Tile] = @TOPLEVEL_ALIAS_TABLE[:Ttk]
-
- ################################################
- # register some Ttk widgets as default
- # (Ttk is a standard library on Tcl/Tk8.5+)
- @TOPLEVEL_ALIAS_TABLE[:Ttk].each{|sym, file|
- unless Object.autoload?(sym) || Object.const_defined?(sym)
- Object.autoload(sym, file)
- end
- }
-
- ################################################
-
- @TOPLEVEL_ALIAS_SETUP_PROC[:Tile] =
- @TOPLEVEL_ALIAS_SETUP_PROC[:Ttk] = proc{|mod|
- unless Tk.autoload?(:Tile) || Tk.const_defined?(:Tile)
- Object.autoload :Ttk, 'tkextlib/tile'
- Tk.autoload :Tile, 'tkextlib/tile'
- end
- }
-end
diff --git a/ext/tk/lib/tk/validation.rb b/ext/tk/lib/tk/validation.rb
index 60bd433cdc..0c5b5c61b9 100644
--- a/ext/tk/lib/tk/validation.rb
+++ b/ext/tk/lib/tk/validation.rb
@@ -50,8 +50,7 @@ module Tk
key2class.each{|key, klass|
if keys[key].kind_of?(Array)
cmd, *args = keys[key]
- #keys[key] = klass.new(cmd, args.join(' '))
- keys[key] = klass.new(cmd, *args)
+ keys[key] = klass.new(cmd, args.join(' '))
# elsif keys[key].kind_of?(Proc) || keys[key].kind_of?(Method)
elsif TkComm._callback_entry?(keys[key])
keys[key] = klass.new(keys[key])
@@ -152,8 +151,7 @@ module Tk
key2class.each{|key, klass|
if keys[key].kind_of?(Array)
cmd, *args = keys[key]
- #keys[key] = klass.new(cmd, args.join(' '))
- keys[key] = klass.new(cmd, *args)
+ keys[key] = klass.new(cmd, args.join(' '))
# elsif keys[key].kind_of?(Proc) || keys[key].kind_of?(Method)
elsif TkComm._callback_entry?(keys[key])
keys[key] = klass.new(keys[key])
@@ -251,24 +249,6 @@ class TkValidateCommand
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
#
@@ -297,7 +277,6 @@ class TkValidateCommand
extra_args_tbl = klass._get_extra_args_tbl
if args.compact.size > 0
- args.map!{|arg| klass._sym2subst(arg)}
args = args.join(' ')
keys = klass._get_subst_key(args)
if cmd.kind_of?(String)
diff --git a/ext/tk/lib/tk/variable.rb b/ext/tk/lib/tk/variable.rb
index f738a96ee7..e5cacadc1a 100644
--- a/ext/tk/lib/tk/variable.rb
+++ b/ext/tk/lib/tk/variable.rb
@@ -16,22 +16,11 @@ class TkVariable
#TkVar_ID_TBL = {}
TkVar_CB_TBL = TkCore::INTERP.create_table
TkVar_ID_TBL = TkCore::INTERP.create_table
- (Tk_VARIABLE_ID = ["v".freeze, "00000".taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
- TkCore::INTERP.init_ip_env{
- TkVar_CB_TBL.mutex.synchronize{ TkVar_CB_TBL.clear }
- TkVar_ID_TBL.mutex.synchronize{ TkVar_ID_TBL.clear }
- }
-
- major, minor, type, type_name, patchlevel = TclTkLib.get_version
- USE_OLD_TRACE_OPTION_STYLE = (major < 8) || (major == 8 && minor < 4)
+ Tk_VARIABLE_ID = ["v".freeze, "00000".taint].freeze
#TkCore::INTERP.add_tk_procs('rb_var', 'args',
# "ruby [format \"TkVariable.callback %%Q!%s!\" $args]")
- TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL')
+TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL')
if {[set st [catch {eval {ruby_cmd TkVariable callback} $args} ret]] != 0} {
set idx [string first "\n\n" $ret]
if {$idx > 0} {
@@ -55,10 +44,10 @@ class TkVariable
def TkVariable.callback(id, name1, name2, op)
#name1,name2,op = tk_split_list(args)
#name1,name2,op = tk_split_simplelist(args)
- if cb_obj = TkVar_CB_TBL[id]
+ if TkVar_CB_TBL[id]
#_get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2,op))
begin
- _get_eval_string(cb_obj.trace_callback(name2, op))
+ _get_eval_string(TkVar_CB_TBL[id].trace_callback(name2, op))
rescue SystemExit
exit(0)
rescue Interrupt
@@ -70,11 +59,7 @@ class TkVariable
"\n---< backtrace of Ruby side >-----\n" +
_toUTF8(e.backtrace.join("\n")) +
"\n---< backtrace of Tk side >-------"
- if TkCore::WITH_ENCODING
- msg.force_encoding('utf-8')
- else
- msg.instance_variable_set(:@encoding, 'utf-8')
- end
+ msg.instance_variable_set(:@encoding, 'utf-8')
rescue Exception
msg = e.class.inspect + ': ' + e.message + "\n" +
"\n---< backtrace of Ruby side >-----\n" +
@@ -282,15 +267,11 @@ class TkVariable
def initialize(val="", type=nil)
# @id = Tk_VARIABLE_ID.join('')
begin
- Tk_VARIABLE_ID.mutex.synchronize{
- @id = Tk_VARIABLE_ID.join(TkCore::INTERP._ip_id_)
- Tk_VARIABLE_ID[1].succ!
- }
+ @id = Tk_VARIABLE_ID.join(TkCore::INTERP._ip_id_)
+ Tk_VARIABLE_ID[1].succ!
end until INTERP._invoke_without_enc('info', 'globals', @id).empty?
- TkVar_ID_TBL.mutex.synchronize{
- TkVar_ID_TBL[@id] = self
- }
+ TkVar_ID_TBL[@id] = self
@var = @id
@elem = nil
@@ -1282,101 +1263,56 @@ end
end
end
- def _check_trace_opt(opts)
- if opts.kind_of?(Array)
- opt_str = opts.map{|s| s.to_s}.join(' ')
- else
- opt_str = opts.to_s
- end
-
- fail ArgumentError, 'null trace option' if opt_str.empty?
-
- if opt_str =~ /[^arwu\s]/
- # new format (Tcl/Tk8.4+?)
- if opts.kind_of?(Array)
- opt_ary = opts.map{|opt| opt.to_s.strip}
- else
- opt_ary = opt_str.split(/\s+|\|/)
- opt_ary.delete('')
- end
- if USE_OLD_TRACE_OPTION_STYLE
- opt_ary.uniq.map{|opt|
- case opt
- when 'array'
- 'a'
- when 'read'
- 'r'
- when 'write'
- 'w'
- when 'unset'
- 'u'
- else
- fail ArgumentError, "unsupported trace option '#{opt}' on Tcl/Tk#{Tk::TCL_PATCHLEVEL}"
- end
- }.join
- else
- opt_ary
- end
- else
- # old format
- opt_ary = opt_str.delete('^arwu').split(//).uniq
- if USE_OLD_TRACE_OPTION_STYLE
- opt_ary.join
- else
- opt_ary.map{|c|
- case c
- when 'a'
- 'array'
- when 'r'
- 'read'
- when 'w'
- 'write'
- when 'u'
- 'unset'
- end
- }
- end
- end
- end
- private :_check_trace_opt
-
def trace(opts, cmd = Proc.new)
- opts = _check_trace_opt(opts)
- (@trace_var ||= []).unshift([opts,cmd])
-
+ @trace_var = [] if @trace_var == nil
+ #opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
+ opts = opts.to_s
+ opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
+ @trace_var.unshift([opts,cmd])
if @trace_opts == nil
TkVar_CB_TBL[@id] = self
- @trace_opts = opts
- if USE_OLD_TRACE_OPTION_STYLE
- Tk.tk_call_without_enc('trace', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
- else
+ @trace_opts = opts.dup
+ Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
+ 'rb_var ' << @id)
+=begin
+ if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
+ # TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'add', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
+ @id, @trace_opts, 'rb_var')
+ else
+ # TCL_VERSION <= 8.3
+ Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var')
end
+=end
else
newopts = @trace_opts.dup
- if USE_OLD_TRACE_OPTION_STYLE
- opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
- if newopts != @trace_opts
- Tk.tk_call_without_enc('trace', 'vdelete',
- @id, @trace_opts, 'rb_var ' << @id)
- @trace_opts.replace(newopts)
- Tk.tk_call_without_enc('trace', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
- end
- else
- newopts |= opts
- unless (newopts - @trace_opts).empty?
+ #opts.each_byte{|c| newopts += c.chr unless newopts.index(c)}
+ opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
+ if newopts != @trace_opts
+ Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts,
+ 'rb_var ' << @id)
+ @trace_opts.replace(newopts)
+ Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
+ 'rb_var ' << @id)
+=begin
+ if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
+ # TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'remove', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
+ @id, @trace_opts, 'rb_var')
@trace_opts.replace(newopts)
Tk.tk_call_without_enc('trace', 'add', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
+ @id, @trace_opts, 'rb_var')
+ else
+ # TCL_VERSION <= 8.3
+ Tk.tk_call_without_enc('trace', 'vdelete',
+ @id, @trace_opts, 'rb_var')
+ @trace_opts.replace(newopts)
+ Tk.tk_call_without_enc('trace', 'variable',
+ @id, @trace_opts, 'rb_var')
end
+=end
end
end
-
self
end
@@ -1385,54 +1321,65 @@ end
fail(RuntimeError,
"invalid for a TkVariable which denotes an element of Tcl's array")
end
-
- opts = _check_trace_opt(opts)
-
- ((@trace_elem ||= {})[elem] ||= []).unshift([opts,cmd])
-
+ @trace_elem = {} if @trace_elem == nil
+ @trace_elem[elem] = [] if @trace_elem[elem] == nil
+ opts = opts.to_s
+ opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
+ @trace_elem[elem].unshift([opts,cmd])
if @trace_opts == nil
TkVar_CB_TBL[@id] = self
- @trace_opts = opts
- if USE_OLD_TRACE_OPTION_STYLE
+ @trace_opts = opts.dup
+ Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
+ 'rb_var ' << @id)
+=begin
+ if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
+ # TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'add', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
+ @id, @trace_opts, 'rb_var')
else
+ # TCL_VERSION <= 8.3
Tk.tk_call_without_enc('trace', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
+ @id, @trace_opts, 'rb_var')
end
+=end
else
newopts = @trace_opts.dup
- if USE_OLD_TRACE_OPTION_STYLE
- opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
- if newopts != @trace_opts
- Tk.tk_call_without_enc('trace', 'vdelete',
- @id, @trace_opts, 'rb_var ' << @id)
- @trace_opts.replace(newopts)
- Tk.tk_call_without_enc('trace', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
- end
- else
- newopts |= opts
- unless (newopts - @trace_opts).empty?
+ # opts.each_byte{|c| newopts += c.chr unless newopts.index(c)}
+ opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
+ if newopts != @trace_opts
+ Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts,
+ 'rb_var ' << @id)
+ @trace_opts.replace(newopts)
+ Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
+ 'rb_var ' << @id)
+=begin
+ if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
+ # TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'remove', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
+ @id, @trace_opts, 'rb_var')
@trace_opts.replace(newopts)
Tk.tk_call_without_enc('trace', 'add', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
+ @id, @trace_opts, 'rb_var')
+ else
+ # TCL_VERSION <= 8.3
+ Tk.tk_call_without_enc('trace', 'vdelete',
+ @id, @trace_opts, 'rb_var')
+ @trace_opts.replace(newopts)
+ Tk.tk_call_without_enc('trace', 'variable',
+ @id, @trace_opts, 'rb_var')
end
+=end
end
end
-
self
end
- def trace_info
+ def trace_vinfo
return [] unless @trace_var
@trace_var.dup
end
- alias trace_vinfo trace_info
- def trace_info_for_element(elem)
+ def _trace_vinfo_for_element(elem)
if @elem
fail(RuntimeError,
"invalid for a TkVariable which denotes an element of Tcl's array")
@@ -1441,180 +1388,141 @@ end
return [] unless @trace_elem[elem]
@trace_elem[elem].dup
end
- alias trace_vinfo_for_element trace_info_for_element
- def trace_remove(opts,cmd)
+ def trace_vdelete(opts,cmd)
return self unless @trace_var.kind_of? Array
-
- opts = _check_trace_opt(opts)
-
+ opts = opts.to_s
+ opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
idx = -1
- if USE_OLD_TRACE_OPTION_STYLE
- newopts = ''
- @trace_var.each_with_index{|e, i|
- if idx < 0 && e[1] == cmd
- diff = false
- ['a', 'r', 'w', 'u'].each{|c|
- break if (diff = e[0].index(c) ^ opts.index(c))
- }
- unless diff
- #find
- idx = i
- next
- end
- end
- e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
- }
- else
- newopts = []
- @trace_var.each_with_index{|e, i|
- if idx < 0 && e[1] == cmd &&
- e[0].size == opts.size && (e[0] - opts).empty?
- # find
- idx = i
- next
- end
- newopts |= e[0]
- }
- end
-
+ newopts = ''
+ @trace_var.each_with_index{|e,i|
+ if idx < 0 && e[0] == opts && e[1] == cmd
+ idx = i
+ next
+ end
+ # e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
+ e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
+ }
if idx >= 0
@trace_var.delete_at(idx)
else
return self
end
- (@trace_elem ||= {}).each{|elem|
+ @trace_elem.each{|elem|
@trace_elem[elem].each{|e|
- if USE_OLD_TRACE_OPTION_STYLE
- e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
- else
- newopts |= e[0]
- end
+ # e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
+ e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
}
}
- if USE_OLD_TRACE_OPTION_STYLE
- diff = false
- @trace_opts.each_byte{|c| break if (diff = ! newopts.index(c))}
- if diff
+ newopts = newopts.to_s
+ newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('')
+ if newopts != @trace_opts
+ Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts,
+ 'rb_var ' << @id)
+=begin
+ if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
+ # TCL_VERSION >= 8.4
+ Tk.tk_call_without_enc('trace', 'remove', 'variable',
+ @id, @trace_opts, 'rb_var')
+ else
+ # TCL_VERSION <= 8.3
Tk.tk_call_without_enc('trace', 'vdelete',
- @id, @trace_opts, 'rb_var ' << @id)
- @trace_opts.replace(newopts)
- unless @trace_opts.empty?
- Tk.tk_call_without_enc('trace', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
- end
+ @id, @trace_opts, 'rb_var')
end
- else
- unless (@trace_opts - newopts).empty?
- Tk.tk_call_without_enc('trace', 'remove', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
- @trace_opts.replace(newopts)
- unless @trace_opts.empty?
+=end
+ @trace_opts.replace(newopts)
+ if @trace_opts != ''
+ Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
+ 'rb_var ' << @id)
+=begin
+ if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
+ # TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'add', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
+ @id, @trace_opts, 'rb_var')
+ else
+ # TCL_VERSION <= 8.3
+ Tk.tk_call_without_enc('trace', 'variable',
+ @id, @trace_opts, 'rb_var')
end
+=end
end
end
self
end
- alias trace_delete trace_remove
- alias trace_vdelete trace_remove
- def trace_remove_for_element(elem,opts,cmd)
+ def trace_vdelete_for_element(elem,opts,cmd)
if @elem
fail(RuntimeError,
"invalid for a TkVariable which denotes an element of Tcl's array")
end
return self unless @trace_elem.kind_of? Hash
return self unless @trace_elem[elem].kind_of? Array
-
- opts = _check_trace_opt(opts)
-
+ opts = opts.to_s
+ opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
idx = -1
- if USE_OLD_TRACE_OPTION_STYLE
- @trace_elem[elem].each_with_index{|e, i|
- if idx < 0 && e[1] == cmd
- diff = false
- ['a', 'r', 'w', 'u'].each{|c|
- break if (diff = e[0].index(c) ^ opts.index(c))
- }
- unless diff
- #find
- idx = i
- next
- end
- end
- }
- else
- @trace_elem[elem].each_with_index{|e, i|
- if idx < 0 && e[1] == cmd &&
- e[0].size == opts.size && (e[0] - opts).empty?
- # find
- idx = i
- next
- end
- }
- end
-
+ @trace_elem[elem].each_with_index{|e,i|
+ if idx < 0 && e[0] == opts && e[1] == cmd
+ idx = i
+ next
+ end
+ }
if idx >= 0
@trace_elem[elem].delete_at(idx)
else
return self
end
- if USE_OLD_TRACE_OPTION_STYLE
- newopts = ''
- @trace_var.each{|e|
- e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
- }
- @trace_elem.each{|elem|
- @trace_elem[elem].each{|e|
- e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
- }
- }
- else
- newopts = []
- @trace_var.each{|e|
- newopts |= e[0]
- }
- @trace_elem.each{|elem|
- @trace_elem[elem].each{|e|
- e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
- }
+ newopts = ''
+ @trace_var.each{|e|
+ # e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
+ e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
+ }
+ @trace_elem.each{|elem|
+ @trace_elem[elem].each{|e|
+ # e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
+ e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
}
- end
+ }
- if USE_OLD_TRACE_OPTION_STYLE
- diff = false
- @trace_opts.each_byte{|c| break if (diff = ! newopts.index(c))}
- if diff
+ newopts = newopts.to_s
+ newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('')
+ if newopts != @trace_opts
+ Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts,
+ 'rb_var ' << @id)
+=begin
+ if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
+ # TCL_VERSION >= 8.4
+ Tk.tk_call_without_enc('trace', 'remove', 'variable',
+ @id, @trace_opts, 'rb_var')
+ else
+ # TCL_VERSION <= 8.3
Tk.tk_call_without_enc('trace', 'vdelete',
- @id, @trace_opts, 'rb_var ' << @id)
- @trace_opts.replace(newopts)
- unless @trace_opts.empty?
- Tk.tk_call_without_enc('trace', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
- end
+ @id, @trace_opts, 'rb_var')
end
- else
- unless (@trace_opts - newopts).empty?
- Tk.tk_call_without_enc('trace', 'remove', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
- @trace_opts.replace(newopts)
- unless @trace_opts.empty?
+=end
+ @trace_opts.replace(newopts)
+ if @trace_opts != ''
+ Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
+ 'rb_var ' << @id)
+=begin
+ if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
+ # TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'add', 'variable',
- @id, @trace_opts, 'rb_var ' << @id)
+ @id, @trace_opts, 'rb_var')
+ else
+ # TCL_VERSION <= 8.3
+ Tk.tk_call_without_enc('trace', 'variable', @id,
+ @trace_opts, 'rb_var')
end
+=end
end
end
self
end
- alias trace_delete_for_element trace_remove_for_element
- alias trace_vdelete_for_element trace_remove_for_element
end
class TkVarAccess<TkVariable
@@ -1624,23 +1532,12 @@ class TkVarAccess<TkVariable
return name
end
- name = name.to_s
- v = nil
- TkVar_ID_TBL.mutex.synchronize{
- if v = TkVar_ID_TBL[name]
- v.value = args[0] unless args.empty?
- return v
- else
- (v = self.allocate).instance_eval{
- @id = name
- TkVar_ID_TBL[@id] = self
- @var = @id
- }
- end
- }
+ if v = TkVar_ID_TBL[name]
+ v.value = args[0] unless args.empty?
+ return v
+ end
- v.instance_eval{ initialize(name, *args) }
- v
+ super(name, *args)
end
def self.new_hash(name, *args)
@@ -1652,38 +1549,27 @@ class TkVarAccess<TkVariable
return name
end
- name = name.to_s
- v = nil
- TkVar_ID_TBL.mutex.synchronize{
- if v = TkVar_ID_TBL[name]
- unless v.is_hash?
- fail ArgumentError, "already exist as a scalar variable"
- end
- v.value = args[0] unless args.empty?
- return v
- else
- (v = self.allocate).instance_eval{
- @id = name
- TkVar_ID_TBL[@id] = self
- @var = @id
- }
+ if v = TkVar_ID_TBL[name]
+ unless v.is_hash?
+ fail ArgumentError, "already exist as a scalar variable"
end
- }
+ v.value = args[0] unless args.empty?
+ return v
+ end
INTERP._invoke_without_enc('global', name)
if args.empty? && INTERP._invoke_without_enc('array', 'exist', name) == '0'
- v.instance_eval{ initialize(name, {}) } # force creating
+ self.new(name, {}) # force creating
else
- v.instance_eval{ initialize(name, *args) }
+ self.new(name, *args)
end
- v
end
def initialize(varname, val=nil)
- # @id = varname
- # TkVar_ID_TBL[@id] = self
+ @id = varname
+ TkVar_ID_TBL[@id] = self
- # @var = @id
+ @var = @id
@elem = nil
@def_default = false
diff --git a/ext/tk/lib/tk/virtevent.rb b/ext/tk/lib/tk/virtevent.rb
index ae31ac1f8f..d47e80aecd 100644
--- a/ext/tk/lib/tk/virtevent.rb
+++ b/ext/tk/lib/tk/virtevent.rb
@@ -9,17 +9,10 @@ class TkVirtualEvent<TkObject
TkCommandNames = ['event'.freeze].freeze
- (TkVirtualEventID = ["VirtEvent".freeze, "00000".taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
+ TkVirtualEventID = ["VirtEvent".freeze, "00000".taint].freeze
TkVirtualEventTBL = TkCore::INTERP.create_table
- TkCore::INTERP.init_ip_env{
- TkVirtualEventTBL.mutex.synchronize{ TkVirtualEventTBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ TkVirtualEventTBL.clear }
class PreDefVirtEvent<self
def self.new(event, *sequences)
@@ -28,30 +21,22 @@ class TkVirtualEvent<TkObject
elsif event !~ /^<.*>$/
event = '<' + event + '>'
end
- TkVirtualEvent::TkVirtualEventTBL.mutex.synchronize{
- if TkVirtualEvent::TkVirtualEventTBL.has_key?(event)
- TkVirtualEvent::TkVirtualEventTBL[event]
- else
- # super(event, *sequences)
- (obj = self.allocate).instance_eval{
- initialize(event, *sequences)
- TkVirtualEvent::TkVirtualEventTBL[@id] = self
- }
- end
- }
+ if TkVirtualEvent::TkVirtualEventTBL.has_key?(event)
+ TkVirtualEvent::TkVirtualEventTBL[event]
+ else
+ super(event, *sequences)
+ end
end
def initialize(event, *sequences)
@path = @id = event
- _add_sequences(sequences)
+ TkVirtualEvent::TkVirtualEventTBL[@id] = self
+ add(*sequences)
end
end
def TkVirtualEvent.getobj(event)
- obj = nil
- TkVirtualEventTBL.mutex.synchronize{
- obj = TkVirtualEventTBL[event]
- }
+ obj = TkVirtualEventTBL[event]
if obj
obj
else
@@ -70,31 +55,19 @@ class TkVirtualEvent<TkObject
end
def initialize(*sequences)
- TkVirtualEventID.mutex.synchronize{
- # @path = @id = '<' + TkVirtualEventID.join('') + '>'
- @path = @id = '<' + TkVirtualEventID.join(TkCore::INTERP._ip_id_) + '>'
- TkVirtualEventID[1].succ!
- }
- _add_sequences(sequences)
+ # @path = @id = '<' + TkVirtualEventID.join('') + '>'
+ @path = @id = '<' + TkVirtualEventID.join(TkCore::INTERP._ip_id_) + '>'
+ TkVirtualEventID[1].succ!
+ add(*sequences)
end
- def _add_sequences(seq_ary)
- unless seq_ary.empty?
+ def add(*sequences)
+ if sequences != []
tk_call_without_enc('event', 'add', "<#{@id}>",
- *(seq_ary.collect{|seq|
+ *(sequences.collect{|seq|
"<#{tk_event_sequence(seq)}>"
}) )
- end
- self
- end
- private :_add_sequences
-
- def add(*sequences)
- if sequences != []
- _add_sequences(sequences)
- TkVirtualEventTBL.mutex.synchronize{
- TkVirtualEventTBL[@id] = self
- }
+ TkVirtualEventTBL[@id] = self
end
self
end
@@ -102,26 +75,20 @@ class TkVirtualEvent<TkObject
def delete(*sequences)
if sequences == []
tk_call_without_enc('event', 'delete', "<#{@id}>")
- TkVirtualEventTBL.mutex.synchronize{
- TkVirtualEventTBL.delete(@id)
- }
+ TkVirtualEventTBL.delete(@id)
else
tk_call_without_enc('event', 'delete', "<#{@id}>",
*(sequences.collect{|seq|
"<#{tk_event_sequence(seq)}>"
}) )
- if tk_call_without_enc('event','info',"<#{@id}>").empty?
- TkVirtualEventTBL.mutex.synchronize{
- TkVirtualEventTBL.delete(@id)
- }
- end
+ TkVirtualEventTBL.delete(@id) if info == []
end
self
end
def info
tk_call_without_enc('event','info',"<#{@id}>").split(/\s+/).collect!{|seq|
- lst = seq.scan(/<*[^<>]+>*/).collect!{|subseq|
+ l = seq.scan(/<*[^<>]+>*/).collect!{|subseq|
case (subseq)
when /^<<[^<>]+>>$/
TkVirtualEvent.getobj(subseq[1..-2])
@@ -131,7 +98,7 @@ class TkVirtualEvent<TkObject
subseq.split('')
end
}.flatten
- (lst.size == 1) ? lst[0] : lst
+ (l.size == 1) ? l[0] : l
}
end
end
diff --git a/ext/tk/lib/tk/winpkg.rb b/ext/tk/lib/tk/winpkg.rb
index 89fb391c77..737fb959b5 100644
--- a/ext/tk/lib/tk/winpkg.rb
+++ b/ext/tk/lib/tk/winpkg.rb
@@ -7,14 +7,9 @@
#
require 'tk'
-module Tk::WinDDE
-end
-#TkWinDDE = Tk::WinDDE
-Tk.__set_toplevel_aliases__(:Tk, Tk::WinDDE, :TkWinDDE)
-
-module Tk::WinDDE
+module TkWinDDE
extend Tk
- extend Tk::WinDDE
+ extend TkWinDDE
TkCommandNames = ['dde'.freeze].freeze
@@ -90,14 +85,9 @@ module Tk::WinDDE
:poke, :request, :services, :eval
end
-module Tk::WinRegistry
-end
-#TkWinRegistry = Tk::WinRegistry
-Tk.__set_toplevel_aliases__(:Tk, Tk::WinRegistry, :TkWinRegistry)
-
-module Tk::WinRegistry
+module TkWinRegistry
extend Tk
- extend Tk::WinRegistry
+ extend TkWinRegistry
TkCommandNames = ['registry'.freeze].freeze
diff --git a/ext/tk/lib/tk/wm.rb b/ext/tk/lib/tk/wm.rb
index 0394296189..1f432a3848 100644
--- a/ext/tk/lib/tk/wm.rb
+++ b/ext/tk/lib/tk/wm.rb
@@ -5,407 +5,273 @@ require 'tk'
module Tk
module Wm
- #include TkComm
- extend TkCore
+ include TkComm
TkCommandNames = ['wm'.freeze].freeze
TOPLEVEL_METHODCALL_OPTKEYS = {}
- def Wm.aspect(win, *args)
+ def aspect(*args)
if args.length == 0
- list(tk_call_without_enc('wm', 'aspect', win.epath))
+ list(tk_call_without_enc('wm', 'aspect', path))
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
- tk_call('wm', 'aspect', win.epath, *args)
- win
+ tk_call('wm', 'aspect', path, *args)
+ self
end
end
- def aspect(*args)
- Wm.aspect(self, *args)
- end
- alias wm_aspect aspect
TOPLEVEL_METHODCALL_OPTKEYS['aspect'] = 'aspect'
- def Wm.attributes(win, slot=nil,value=TkComm::None)
+ def attributes(slot=nil,value=None)
if slot == nil
- lst = tk_split_list(tk_call('wm', 'attributes', win.epath))
+ lst = tk_split_list(tk_call('wm', 'attributes', path))
info = {}
while key = lst.shift
info[key[1..-1]] = lst.shift
end
info
elsif slot.kind_of? Hash
- tk_call('wm', 'attributes', win.epath, *hash_kv(slot))
- win
- elsif value == TkComm::None
- tk_call('wm', 'attributes', win.epath, "-#{slot}")
+ tk_call('wm', 'attributes', path, *hash_kv(slot))
+ self
+ elsif value == None
+ tk_call('wm', 'attributes', path, "-#{slot}")
else
- tk_call('wm', 'attributes', win.epath, "-#{slot}", value)
- win
+ tk_call('wm', 'attributes', path, "-#{slot}", value)
+ self
end
end
- def attributes(slot=nil,value=TkComm::None)
- Wm.attributes(self, slot, value)
- end
- alias wm_attributes attributes
TOPLEVEL_METHODCALL_OPTKEYS['attributes'] = 'attributes'
- def Wm.client(win, name=TkComm::None)
- if name == TkComm::None
- tk_call('wm', 'client', win.epath)
+ def client(name=None)
+ if name == None
+ tk_call('wm', 'client', path)
else
name = '' if name == nil
- tk_call('wm', 'client', win.epath, name)
- win
+ tk_call('wm', 'client', path, name)
+ self
end
end
- def client(name=TkComm::None)
- Wm.client(self, name)
- end
- alias wm_client client
TOPLEVEL_METHODCALL_OPTKEYS['client'] = 'client'
- def Wm.colormapwindows(win, *args)
+ def colormapwindows(*args)
if args.size == 0
- list(tk_call_without_enc('wm', 'colormapwindows', win.epath))
+ list(tk_call_without_enc('wm', 'colormapwindows', path))
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
- tk_call_without_enc('wm', 'colormapwindows', win.epath, *args)
- win
+ tk_call_without_enc('wm', 'colormapwindows', path, *args)
+ self
end
end
- def colormapwindows(*args)
- Wm.colormapwindows(self, *args)
- end
- alias wm_colormapwindows colormapwindows
TOPLEVEL_METHODCALL_OPTKEYS['colormapwindows'] = 'colormapwindows'
- def Wm.command(win, value=nil)
+ def wm_command(value=nil)
if value
- tk_call('wm', 'command', epath, value)
- win
+ tk_call('wm', 'command', path, value)
+ self
else
- #procedure(tk_call('wm', 'command', epath))
- tk_call('wm', 'command', epath)
+ #procedure(tk_call('wm', 'command', path))
+ tk_call('wm', 'command', path)
end
end
- def wm_command(value=nil)
- Wm.command(self, value)
- end
TOPLEVEL_METHODCALL_OPTKEYS['wm_command'] = 'wm_command'
- def Wm.deiconify(win, ex = true)
+ def deiconify(ex = true)
if ex
- tk_call_without_enc('wm', 'deiconify', win.epath)
+ tk_call_without_enc('wm', 'deiconify', path)
else
- Wm.iconify(win)
+ self.iconify
end
- win
+ self
end
- def deiconify(ex = true)
- Wm.deiconify(self, ex)
- end
- alias wm_deiconify deiconify
- def Wm.focusmodel(win, mode = nil)
+ def focusmodel(mode = nil)
if mode
- tk_call_without_enc('wm', 'focusmodel', win.epath, mode)
- win
+ tk_call_without_enc('wm', 'focusmodel', path, mode)
+ self
else
- tk_call_without_enc('wm', 'focusmodel', win.epath)
+ tk_call_without_enc('wm', 'focusmodel', path)
end
end
- def focusmodel(mode = nil)
- Wm.focusmodel(self, mode)
- end
- alias wm_focusmodel focusmodel
TOPLEVEL_METHODCALL_OPTKEYS['focusmodel'] = 'focusmodel'
- def Wm.forget(win)
- # Tcl/Tk 8.5+
- # work with dockable frames
- tk_call_without_enc('wm', 'forget', win.epath)
- win
- end
- def wm_forget
- Wm.forget(self)
- end
-
- def Wm.frame(win)
- tk_call_without_enc('wm', 'frame', win.epath)
- end
def frame
- Wm.frame(self)
+ tk_call_without_enc('wm', 'frame', path)
end
- alias wm_frame frame
- def Wm.geometry(win, geom=nil)
+ def geometry(geom=nil)
if geom
- tk_call_without_enc('wm', 'geometry', win.epath, geom)
- win
+ tk_call_without_enc('wm', 'geometry', path, geom)
+ self
else
- tk_call_without_enc('wm', 'geometry', win.epath)
+ tk_call_without_enc('wm', 'geometry', path)
end
end
- def geometry(geom=nil)
- Wm.geometry(self, geom)
- end
- alias wm_geometry geometry
TOPLEVEL_METHODCALL_OPTKEYS['geometry'] = 'geometry'
- def Wm.grid(win, *args)
+ def wm_grid(*args)
if args.size == 0
- list(tk_call_without_enc('wm', 'grid', win.epath))
+ list(tk_call_without_enc('wm', 'grid', path))
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
- tk_call_without_enc('wm', 'grid', win.epath, *args)
- win
+ tk_call_without_enc('wm', 'grid', path, *args)
+ self
end
end
- def wm_grid(*args)
- Wm.grid(self, *args)
- end
TOPLEVEL_METHODCALL_OPTKEYS['wm_grid'] = 'wm_grid'
- def Wm.group(win, leader = nil)
+ def group(leader = nil)
if leader
- tk_call('wm', 'group', win.epath, leader)
- win
+ tk_call('wm', 'group', path, leader)
+ self
else
- window(tk_call('wm', 'group', win.epath))
+ window(tk_call('wm', 'group', path))
end
end
- def group(leader = nil)
- Wm.group(self, leader)
- end
- alias wm_group group
TOPLEVEL_METHODCALL_OPTKEYS['group'] = 'group'
- def Wm.iconbitmap(win, bmp=nil)
+ def iconbitmap(bmp=nil)
if bmp
- tk_call_without_enc('wm', 'iconbitmap', win.epath, bmp)
- win
+ tk_call_without_enc('wm', 'iconbitmap', path, bmp)
+ self
else
- image_obj(tk_call_without_enc('wm', 'iconbitmap', win.epath))
+ image_obj(tk_call_without_enc('wm', 'iconbitmap', path))
end
end
- def iconbitmap(bmp=nil)
- Wm.iconbitmap(self, bmp)
- end
- alias wm_iconbitmap iconbitmap
TOPLEVEL_METHODCALL_OPTKEYS['iconbitmap'] = 'iconbitmap'
- def Wm.iconphoto(win, *imgs)
+ def iconphoto(*imgs)
if imgs.empty?
- win.instance_eval{
- @wm_iconphoto = nil unless defined? @wm_iconphoto
- return @wm_iconphoto
- }
+ @wm_iconphoto = nil unless defined? @wm_iconphoto
+ return @wm_iconphoto
end
imgs = imgs[0] if imgs.length == 1 && imgs[0].kind_of?(Array)
- tk_call_without_enc('wm', 'iconphoto', win.epath, *imgs)
- win.instance_eval{ @wm_iconphoto = imgs }
- win
- end
- def iconphoto(*imgs)
- Wm.iconphoto(self, *imgs)
+ tk_call_without_enc('wm', 'iconphoto', path, *imgs)
+ @wm_iconphoto = imgs
+ self
end
- alias wm_iconphoto iconphoto
TOPLEVEL_METHODCALL_OPTKEYS['iconphoto'] = 'iconphoto'
- def Wm.iconphoto_default(win, *imgs)
- imgs = imgs[0] if imgs.length == 1 && imgs[0].kind_of?(Array)
- tk_call_without_enc('wm', 'iconphoto', win.epath, '-default', *imgs)
- win
- end
def iconphoto_default(*imgs)
- Wm.iconphoto_default(self, *imgs)
+ imgs = imgs[0] if imgs.length == 1 && imgs[0].kind_of?(Array)
+ tk_call_without_enc('wm', 'iconphoto', path, '-default', *imgs)
+ self
end
- alias wm_iconphoto_default iconphoto_default
- def Wm.iconify(win, ex = true)
+ def iconify(ex = true)
if ex
- tk_call_without_enc('wm', 'iconify', win.epath)
+ tk_call_without_enc('wm', 'iconify', path)
else
- Wm.deiconify(win)
+ self.deiconify
end
- win
- end
- def iconify(ex = true)
- Wm.iconify(self, ex)
+ self
end
- alias wm_iconify iconify
- def Wm.iconmask(win, bmp=nil)
+ def iconmask(bmp=nil)
if bmp
- tk_call_without_enc('wm', 'iconmask', win.epath, bmp)
- win
+ tk_call_without_enc('wm', 'iconmask', path, bmp)
+ self
else
- image_obj(tk_call_without_enc('wm', 'iconmask', win.epath))
+ image_obj(tk_call_without_enc('wm', 'iconmask', path))
end
end
- def iconmask(bmp=nil)
- Wm.iconmask(self, bmp)
- end
- alias wm_iconmask iconmask
TOPLEVEL_METHODCALL_OPTKEYS['iconmask'] = 'iconmask'
- def Wm.iconname(win, name=nil)
+ def iconname(name=nil)
if name
- tk_call('wm', 'iconname', win.epath, name)
- win
+ tk_call('wm', 'iconname', path, name)
+ self
else
- tk_call('wm', 'iconname', win.epath)
+ tk_call('wm', 'iconname', path)
end
end
- def iconname(name=nil)
- Wm.iconname(self, name)
- end
- alias wm_iconname iconname
TOPLEVEL_METHODCALL_OPTKEYS['iconname'] = 'iconname'
- def Wm.iconposition(win, *args)
+ def iconposition(*args)
if args.size == 0
- list(tk_call_without_enc('wm', 'iconposition', win.epath))
+ list(tk_call_without_enc('wm', 'iconposition', path))
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
- tk_call_without_enc('wm', 'iconposition', win.epath, *args)
- win
+ tk_call_without_enc('wm', 'iconposition', path, *args)
+ self
end
end
- def iconposition(*args)
- Wm.iconposition(self, *args)
- end
- alias wm_iconposition iconposition
TOPLEVEL_METHODCALL_OPTKEYS['iconposition'] = 'iconposition'
- def Wm.iconwindow(win, iconwin = nil)
- if iconwin
- tk_call_without_enc('wm', 'iconwindow', win.epath, iconwin)
- win
+ def iconwindow(win = nil)
+ if win
+ tk_call_without_enc('wm', 'iconwindow', path, win)
+ self
else
- w = tk_call_without_enc('wm', 'iconwindow', win.epath)
+ w = tk_call_without_enc('wm', 'iconwindow', path)
(w == '')? nil: window(w)
end
end
- def iconwindow(iconwin = nil)
- Wm.iconwindow(self, iconwin)
- end
- alias wm_iconwindow iconwindow
TOPLEVEL_METHODCALL_OPTKEYS['iconwindow'] = 'iconwindow'
- def Wm.manage(win)
- # Tcl/Tk 8.5+ feature
- tk_call_without_enc('wm', 'manage', win.epath)
- win
- end
- def wm_manage
- Wm.manage(self)
- end
-=begin
- def Wm.manage(win, use_id = nil)
- # Tcl/Tk 8.5+ feature
- # --------------------------------------------------------------
- # In the future release, I want to support to embed the 'win'
- # into the container which has window-id 'use-id'.
- # It may give users frexibility on controlling their GUI.
- # However, it may be difficult for current Tcl/Tk (Tcl/Tk8.5.1),
- # because it seems to require to modify Tcl/Tk's source code.
- # --------------------------------------------------------------
- if use_id
- tk_call_without_enc('wm', 'manage', win.epath, '-use', use_id)
- else
- tk_call_without_enc('wm', 'manage', win.epath)
- end
- win
- end
-=end
-
- def Wm.maxsize(win, *args)
+ def maxsize(*args)
if args.size == 0
- list(tk_call_without_enc('wm', 'maxsize', win.epath))
+ list(tk_call_without_enc('wm', 'maxsize', path))
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
- tk_call_without_enc('wm', 'maxsize', win.epath, *args)
- win
+ tk_call_without_enc('wm', 'maxsize', path, *args)
+ self
end
end
- def maxsize(*args)
- Wm.maxsize(self, *args)
- end
- alias wm_maxsize maxsize
TOPLEVEL_METHODCALL_OPTKEYS['maxsize'] = 'maxsize'
- def Wm.minsize(win, *args)
+ def minsize(*args)
if args.size == 0
- list(tk_call_without_enc('wm', 'minsize', win.epath))
+ list(tk_call_without_enc('wm', 'minsize', path))
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
- tk_call_without_enc('wm', 'minsize', win.path, *args)
- win
+ tk_call_without_enc('wm', 'minsize', path, *args)
+ self
end
end
- def minsize(*args)
- Wm.minsize(self, *args)
- end
- alias wm_minsize minsize
TOPLEVEL_METHODCALL_OPTKEYS['minsize'] = 'minsize'
- def Wm.overrideredirect(win, mode=TkComm::None)
- if mode == TkComm::None
- bool(tk_call_without_enc('wm', 'overrideredirect', win.epath))
+ def overrideredirect(mode=None)
+ if mode == None
+ bool(tk_call_without_enc('wm', 'overrideredirect', path))
else
- tk_call_without_enc('wm', 'overrideredirect', win.epath, mode)
- win
+ tk_call_without_enc('wm', 'overrideredirect', path, mode)
+ self
end
end
- def overrideredirect(mode=TkComm::None)
- Wm.overrideredirect(self, mode)
- end
- alias wm_overrideredirect overrideredirect
TOPLEVEL_METHODCALL_OPTKEYS['overrideredirect'] = 'overrideredirect'
- def Wm.positionfrom(win, who=TkComm::None)
- if who == TkComm::None
- r = tk_call_without_enc('wm', 'positionfrom', win.epath)
+ def positionfrom(who=None)
+ if who == None
+ r = tk_call_without_enc('wm', 'positionfrom', path)
(r == "")? nil: r
else
- tk_call_without_enc('wm', 'positionfrom', win.epath, who)
- win
+ tk_call_without_enc('wm', 'positionfrom', path, who)
+ self
end
end
- def positionfrom(who=TkComm::None)
- Wm.positionfrom(self, who)
- end
- alias wm_positionfrom positionfrom
TOPLEVEL_METHODCALL_OPTKEYS['positionfrom'] = 'positionfrom'
- def Wm.protocol(win, name=nil, cmd=nil, &b)
+ def protocol(name=nil, cmd=nil, &b)
if cmd
- tk_call_without_enc('wm', 'protocol', win.epath, name, cmd)
- win
+ tk_call_without_enc('wm', 'protocol', path, name, cmd)
+ self
elsif b
- tk_call_without_enc('wm', 'protocol', win.epath, name, proc(&b))
- win
+ tk_call_without_enc('wm', 'protocol', path, name, proc(&b))
+ self
elsif name
- result = tk_call_without_enc('wm', 'protocol', win.epath, name)
+ result = tk_call_without_enc('wm', 'protocol', path, name)
(result == "")? nil : tk_tcl2ruby(result)
else
- tk_split_simplelist(tk_call_without_enc('wm', 'protocol', win.epath))
+ tk_split_simplelist(tk_call_without_enc('wm', 'protocol', path))
end
end
- def protocol(name=nil, cmd=nil, &b)
- Wm.protocol(self, name, cmd, &b)
- end
- alias wm_protocol protocol
- def Wm.protocols(win, kv=nil)
+ def protocols(kv=nil)
unless kv
ret = {}
- Wm.protocol(win).each{|name|
- ret[name] = Wm.protocol(win, name)
+ self.protocol.each{|name|
+ ret[name] = self.protocol(name)
}
return ret
end
@@ -413,140 +279,82 @@ module Tk
unless kv.kind_of?(Hash)
fail ArgumentError, 'expect a hash of protocol=>command'
end
- kv.each{|k, v| Wm.protocol(win, k, v)}
- win
+ kv.each{|k, v| self.protocol(k, v)}
+ self
end
- def protocols(kv=nil)
- Wm.protocols(self, kv)
- end
- alias wm_protocols protocols
TOPLEVEL_METHODCALL_OPTKEYS['protocols'] = 'protocols'
- def Wm.resizable(win, *args)
+ def resizable(*args)
if args.length == 0
- list(tk_call_without_enc('wm', 'resizable', win.epath)).map!{|e| bool(e)}
+ list(tk_call_without_enc('wm', 'resizable', path)).collect{|e| bool(e)}
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
- tk_call_without_enc('wm', 'resizable', win.epath, *args)
- win
+ tk_call_without_enc('wm', 'resizable', path, *args)
+ self
end
end
- def resizable(*args)
- Wm.resizable(self, *args)
- end
- alias wm_resizable resizable
TOPLEVEL_METHODCALL_OPTKEYS['resizable'] = 'resizable'
- def Wm.sizefrom(win, who=TkComm::None)
- if who == TkComm::None
- r = tk_call_without_enc('wm', 'sizefrom', win.epath)
+ def sizefrom(who=None)
+ if who == None
+ r = tk_call_without_enc('wm', 'sizefrom', path)
(r == "")? nil: r
else
- tk_call_without_enc('wm', 'sizefrom', win.epath, who)
- win
+ tk_call_without_enc('wm', 'sizefrom', path, who)
+ self
end
end
- def sizefrom(who=TkComm::None)
- Wm.sizefrom(self, who)
- end
- alias wm_sizefrom sizefrom
TOPLEVEL_METHODCALL_OPTKEYS['sizefrom'] = 'sizefrom'
- def Wm.stackorder(win)
- list(tk_call('wm', 'stackorder', win.epath))
- end
def stackorder
- Wm.stackorder(self)
+ list(tk_call('wm', 'stackorder', path))
end
- alias wm_stackorder stackorder
- def Wm.stackorder_isabove(win, target)
- bool(tk_call('wm', 'stackorder', win.epath, 'isabove', target))
- end
- def Wm.stackorder_is_above(win, target)
- Wm.stackorder_isabove(win, target)
- end
- def stackorder_isabove(target)
- Wm.stackorder_isabove(self, target)
+ def stackorder_isabove(win)
+ bool(tk_call('wm', 'stackorder', path, 'isabove', win))
end
- alias stackorder_is_above stackorder_isabove
- alias wm_stackorder_isabove stackorder_isabove
- alias wm_stackorder_is_above stackorder_isabove
- def Wm.stackorder_isbelow(win, target)
- bool(tk_call('wm', 'stackorder', win.epath, 'isbelow', target))
+ def stackorder_isbelow(win)
+ bool(tk_call('wm', 'stackorder', path, 'isbelow', win))
end
- def Wm.stackorder_is_below(win, target)
- Wm.stackorder_isbelow(win, target)
- end
- def stackorder_isbelow(target)
- Wm.stackorder_isbelow(self, target)
- end
- alias stackorder_is_below stackorder_isbelow
- alias wm_stackorder_isbelow stackorder_isbelow
- alias wm_stackorder_is_below stackorder_isbelow
- def Wm.state(win, st=nil)
+ def state(st=nil)
if st
- tk_call_without_enc('wm', 'state', win.epath, st)
- win
+ tk_call_without_enc('wm', 'state', path, st)
+ self
else
- tk_call_without_enc('wm', 'state', win.epath)
+ tk_call_without_enc('wm', 'state', path)
end
end
- def state(st=nil)
- Wm.state(self, st)
- end
- alias wm_state state
TOPLEVEL_METHODCALL_OPTKEYS['state'] = 'state'
- def Wm.title(win, str=nil)
+ def title(str=nil)
if str
- tk_call('wm', 'title', win.epath, str)
- win
+ tk_call('wm', 'title', path, str)
+ self
else
- tk_call('wm', 'title', win.epath)
+ tk_call('wm', 'title', path)
end
end
- def title(str=nil)
- Wm.title(self, str)
- end
- alias wm_title title
TOPLEVEL_METHODCALL_OPTKEYS['title'] = 'title'
- def Wm.transient(win, master=nil)
+ def transient(master=nil)
if master
- tk_call_without_enc('wm', 'transient', win.epath, master)
- win
+ tk_call_without_enc('wm', 'transient', path, master)
+ self
else
- window(tk_call_without_enc('wm', 'transient', win.epath))
+ window(tk_call_without_enc('wm', 'transient', path))
end
end
- def transient(master=nil)
- Wm.transient(self, master)
- end
- alias wm_transient transient
TOPLEVEL_METHODCALL_OPTKEYS['transient'] = 'transient'
- def Wm.withdraw(win, ex = true)
+ def withdraw(ex = true)
if ex
- tk_call_without_enc('wm', 'withdraw', win.epath)
+ tk_call_without_enc('wm', 'withdraw', path)
else
- Wm.deiconify(win)
+ self.deiconify
end
- win
+ self
end
- def withdraw(ex = true)
- Wm.withdraw(self, ex)
- end
- alias wm_withdraw withdraw
- end
-
- module Wm_for_General
- Wm.instance_methods.each{|m|
- if (m = m.to_s) =~ /^wm_(.*)$/
- eval "def #{m}(*args, &b); Tk::Wm.#{$1}(self, *args, &b); end"
- end
- }
end
end
diff --git a/ext/tk/lib/tkextlib/SUPPORT_STATUS b/ext/tk/lib/tkextlib/SUPPORT_STATUS
index cfbe274c86..15925cba72 100644
--- a/ext/tk/lib/tkextlib/SUPPORT_STATUS
+++ b/ext/tk/lib/tkextlib/SUPPORT_STATUS
@@ -83,7 +83,7 @@ BLT 2.4z http://sourceforge.net/projects/blt
TkTreeCtrl CVS/Hd(2005-12-02)
http://sourceforge.net/projects/tktreectrl ==> treectrl
-Tile 0.8.0/8.5.1
+Tile 0.7.8
http://sourceforge.net/projects/tktable ==> tile
diff --git a/ext/tk/lib/tkextlib/blt/bitmap.rb b/ext/tk/lib/tkextlib/blt/bitmap.rb
index 23c6d2d064..31cf8d4229 100644
--- a/ext/tk/lib/tkextlib/blt/bitmap.rb
+++ b/ext/tk/lib/tkextlib/blt/bitmap.rb
@@ -13,16 +13,7 @@ module Tk::BLT
TkCommandNames = ['::blt::bitmap'.freeze].freeze
BITMAP_ID_TBL = TkCore::INTERP.create_table
-
- (BITMAP_ID = ['blt_bitmap_id'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- BITMAP_ID_TBL.mutex.synchronize{ BITMAP_ID_TBL.clear }
- }
+ BITMAP_ID = ['blt_bitmap_id'.freeze, '00000'.taint].freeze
def self.data(name)
dat = tk_simple_list(tk_call('::blt::bitmap', 'data', name))
@@ -73,13 +64,9 @@ module Tk::BLT
if name
@id = name
else
- BITMAP_ID.mutex.synchronize{
- @id = BITMAP_ID.join(TkCore::INTERP._ip_id_)
- BITMAP_ID[1].succ!
- }
- BITMAP_ID_TBL.mutex.synchronize{
- BITMAP_ID_TBL[@id] = self
- }
+ @id = BITMAP_ID.join(TkCore::INTERP._ip_id_)
+ BITMAP_ID[1].succ!
+ BITMAP_ID_TBL[@id] = self
end
@path = @id
diff --git a/ext/tk/lib/tkextlib/blt/busy.rb b/ext/tk/lib/tkextlib/blt/busy.rb
index 2f807fcd9c..4726e466f4 100644
--- a/ext/tk/lib/tkextlib/blt/busy.rb
+++ b/ext/tk/lib/tkextlib/blt/busy.rb
@@ -19,7 +19,7 @@ module Tk::BLT
class Shield < TkWindow
def self.shield_path(win)
win = window(win) unless win.kind_of?(TkWindow)
- if win.kind_of?(Tk::Toplevel)
+ if win.kind_of?(TkToplevel)
win.path + '._Busy'
else
win.path + '_Busy'
diff --git a/ext/tk/lib/tkextlib/blt/component.rb b/ext/tk/lib/tkextlib/blt/component.rb
index b2005b2f2b..ad78a5430b 100644
--- a/ext/tk/lib/tkextlib/blt/component.rb
+++ b/ext/tk/lib/tkextlib/blt/component.rb
@@ -85,9 +85,6 @@ module Tk::BLT
def axis_cget(id, option)
ret = itemcget(['axis', tagid(id)], option)
end
- def axis_cget_strict(id, option)
- ret = itemcget_strict(['axis', tagid(id)], option)
- end
def axis_configure(*args)
slot = args.pop
if slot.kind_of?(Hash)
@@ -121,9 +118,6 @@ module Tk::BLT
def crosshairs_cget(option)
itemcget('crosshairs', option)
end
- def crosshairs_cget_strict(option)
- itemcget_strict('crosshairs', option)
- end
def crosshairs_configure(slot, value=None)
itemconfigure('crosshairs', slot, value)
end
@@ -137,9 +131,6 @@ module Tk::BLT
def element_cget(id, option)
itemcget(['element', tagid(id)], option)
end
- def element_cget_strict(id, option)
- itemcget_strict(['element', tagid(id)], option)
- end
def element_configure(*args)
slot = args.pop
if slot.kind_of?(Hash)
@@ -161,9 +152,6 @@ module Tk::BLT
def bar_cget(id, option)
itemcget(['bar', tagid(id)], option)
end
- def bar_cget_strict(id, option)
- itemcget_strict(['bar', tagid(id)], option)
- end
def bar_configure(*args)
slot = args.pop
if slot.kind_of?(Hash)
@@ -185,9 +173,6 @@ module Tk::BLT
def line_cget(id, option)
itemcget(['line', tagid(id)], option)
end
- def line_cget_strict(id, option)
- itemcget_strict(['line', tagid(id)], option)
- end
def line_configure(*args)
slot = args.pop
if slot.kind_of?(Hash)
@@ -209,9 +194,6 @@ module Tk::BLT
def gridline_cget(option)
itemcget('grid', option)
end
- def gridline_cget_strict(option)
- itemcget_strict('grid', option)
- end
def gridline_configure(slot, value=None)
itemconfigure('grid', slot, value)
end
@@ -225,9 +207,6 @@ module Tk::BLT
def legend_cget(option)
itemcget('legend', option)
end
- def legend_cget_strict(option)
- itemcget_strict('legend', option)
- end
def legend_configure(slot, value=None)
itemconfigure('legend', slot, value)
end
@@ -241,9 +220,6 @@ module Tk::BLT
def pen_cget(id, option)
itemcget(['pen', tagid(id)], option)
end
- def pen_cget_strict(id, option)
- itemcget_strict(['pen', tagid(id)], option)
- end
def pen_configure(*args)
slot = args.pop
if slot.kind_of?(Hash)
@@ -265,9 +241,6 @@ module Tk::BLT
def postscript_cget(option)
itemcget('postscript', option)
end
- def postscript_cget_strict(option)
- itemcget_strict('postscript', option)
- end
def postscript_configure(slot, value=None)
itemconfigure('postscript', slot, value)
end
@@ -281,9 +254,6 @@ module Tk::BLT
def marker_cget(id, option)
itemcget(['marker', tagid(id)], option)
end
- def marker_cget_strict(id, option)
- itemcget_strict(['marker', tagid(id)], option)
- end
def marker_configure(*args)
slot = args.pop
if slot.kind_of?(Hash)
@@ -303,12 +273,11 @@ module Tk::BLT
end
alias __itemcget itemcget
- alias __itemcget_strict itemcget_strict
alias __itemconfiginfo itemconfiginfo
alias __current_itemconfiginfo current_itemconfiginfo
private :__itemcget, :__itemconfiginfo, :__current_itemconfiginfo
- def itemcget_strict(tagOrId, option)
+ def itemcget(tagOrId, option)
ret = __itemcget(tagid(tagOrId), option)
if option == 'bindtags' || option == :bindtags
ret.collect{|tag| TkBindTag.id2obj(tag)}
@@ -316,27 +285,6 @@ module Tk::BLT
ret
end
end
- def itemcget(tagOrId, option)
- unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- itemcget_strict(tagOrId, option)
- else
- begin
- itemcget_strict(tagOrId, option)
- rescue => e
- begin
- if current_itemconfiginfo(tagOrId).has_key?(option.to_s)
- # error on known option
- fail e
- else
- # unknown option
- nil
- end
- rescue
- fail e # tag error
- end
- end
- end
- end
def itemconfiginfo(tagOrId, slot = nil)
ret = __itemconfiginfo(tagid(tagOrId), slot)
@@ -373,30 +321,19 @@ module Tk::BLT
ret
end
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
#################
class Axis < TkObject
- (OBJ_ID = ['blt_chart_axis'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- AxisID_TBL = TkCore::INTERP.create_table
-
- TkCore::INTERP.init_ip_env{
- AxisID_TBL.mutex.synchronize{ AxisID_TBL.clear }
- }
+ OBJ_ID = ['blt_chart_axis'.freeze, '00000'.taint].freeze
+ OBJ_TBL={}
def self.id2obj(chart, id)
cpath = chart.path
- AxisID_TBL.mutex.synchronize{
- return id unless AxisID_TBL[cpath]
- AxisID_TBL[cpath][id]? AxisID_TBL[cpath][id]: id
- }
+ return id unless OBJ_TBL[cpath]
+ OBJ_TBL[cpath][id]? OBJ_TBL[cpath][id]: id
end
def self.new(chart, axis=nil, keys={})
@@ -404,48 +341,12 @@ module Tk::BLT
keys = axis
axis = nil
end
- if keys
- keys = _symbolkey2str(keys)
- not_create = keys.delete('without_creating')
- else
- not_create = false
- end
-
- obj = nil
- AxisID_TBL.mutex.synchronize{
- chart_path = chart.path
- AxisID_TBL[chart_path] ||= {}
- if axis && AxisID_TBL[chart_path][axis]
- obj = AxisID_TBL[chart_path][axis]
- else
- (obj = self.allocate).instance_eval{
- if axis
- @axis = @id = axis.to_s
- else
- OBJ_ID.mutex.synchronize{
- @axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
- OBJ_ID[1].succ!
- }
- end
- @path = @id
- @parent = @chart = chart
- @cpath = @chart.path
- Axis::AxisID_TBL[@cpath][@axis] = self
- unless not_create
- tk_call(@chart, 'axis', 'create', @axis, keys)
- return obj
- end
- }
- end
- }
-
- obj.configure(keys) if obj && ! keys.empty?
- obj
+ OBJ_TBL[chart.path] = {} unless OBJ_TBL[chart.path]
+ return OBJ_TBL[chart.path][axis] if axis && OBJ_TBL[chart.path][axis]
+ super(chart, axis, keys)
end
def initialize(chart, axis=nil, keys={})
- # dummy:: not called by 'new' method
-
if axis.kind_of?(Hash)
keys = axis
axis = nil
@@ -453,15 +354,13 @@ module Tk::BLT
if axis
@axis = @id = axis.to_s
else
- OBJ_ID.mutex.synchronize{
- @axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
- OBJ_ID[1].succ!
- }
+ @axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
+ OBJ_ID[1].succ!
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
- # Axis::AxisID_TBL[@cpath][@axis] = self
+ Axis::OBJ_TBL[@cpath][@axis] = self
keys = _symbolkey2str(keys)
unless keys.delete('without_creating')
# @chart.axis_create(@axis, keys)
@@ -480,9 +379,6 @@ module Tk::BLT
def cget(option)
@chart.axis_cget(@id, option)
end
- def cget_strict(option)
- @chart.axis_cget_strict(@id, option)
- end
def configure(key, value=None)
@chart.axis_configure(@id, key, value)
self
@@ -542,34 +438,17 @@ module Tk::BLT
#################
class Crosshairs < TkObject
- CrosshairsID_TBL = TkCore::INTERP.create_table
-
- TkCore::INTERP.init_ip_env{
- CrosshairsID_TBL.mutex.synchronize{ CrosshairsID_TBL.clear }
- }
+ OBJ_TBL={}
def self.new(chart, keys={})
- obj = nil
- CrosshairsID_TBL.mutex.synchronize{
- unless (obj = CrosshairsID_TBL[chart.path])
- (obj = self.allocate).instance_eval{
- @parent = @chart = chart
- @cpath = @chart.path
- @path = @id = 'crosshairs'
- Crosshairs::CrosshairsID_TBL[@cpath] = self
- }
- end
- }
- chart.crosshair_configure(keys) if obj && ! keys.empty?
- obj
+ return OBJ_TBL[chart.path] if OBJ_TBL[chart.path]
+ super(chart, keys)
end
def initialize(chart, keys={})
- # dummy:: not called by 'new' method
-
@parent = @chart = chart
@cpath = @chart.path
- # Crosshairs::CrosshairsID_TBL[@cpath] = self
+ Crosshairs::OBJ_TBL[@cpath] = self
@chart.crosshair_configure(keys) unless keys.empty?
@path = @id = 'crosshairs'
end
@@ -585,9 +464,6 @@ module Tk::BLT
def cget(option)
@chart.crosshair_cget(option)
end
- def cget_strict(option)
- @chart.crosshair_cget_strict(option)
- end
def configure(key, value=None)
@chart.crosshair_configure(key, value)
self
@@ -624,18 +500,12 @@ module Tk::BLT
ElementTypeName = 'element'
ElementTypeToClass = { ElementTypeName=>self }
-
ElementID_TBL = TkCore::INTERP.create_table
- TkCore::INTERP.init_ip_env{
- ElementID_TBL.mutex.synchronize{ ElementID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ ElementID_TBL.clear }
- (OBJ_ID = ['blt_chart_element'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
+ OBJ_ID = ['blt_chart_element'.freeze, '00000'.taint].freeze
+ OBJ_TBL={}
def Element.type2class(type)
ElementTypeToClass[type]
@@ -643,10 +513,8 @@ module Tk::BLT
def Element.id2obj(chart, id)
cpath = chart.path
- ElementID_TBL.mutex.synchronize{
- return id unless ElementID_TBL[cpath]
- ElementID_TBL[cpath][id]? ElementID_TBL[cpath][id]: id
- }
+ return id unless OBJ_TBL[cpath]
+ OBJ_TBL[cpath][id]? OBJ_TBL[cpath][id]: id
end
def self.new(chart, element=nil, keys={})
@@ -654,49 +522,14 @@ module Tk::BLT
keys = element
element = nil
end
- if keys
- keys = _symbolkey2str(keys)
- not_create = keys.delete('without_creating')
- else
- not_create = false
+ OBJ_TBL[chart.path] = {} unless OBJ_TBL[chart.path]
+ if element && OBJ_TBL[chart.path][element]
+ return OBJ_TBL[chart.path][element]
end
-
- obj = nil
- ElementID_TBL.mutex.synchronize{
- chart_path = chart.path
- ElementID_TBL[chart_path] ||= {}
- if element && ElementID_TBL[chart_path][element]
- obj = ElementID_TBL[chart_path][element]
- else
- (obj = self.allocate).instance_eval{
- if element
- @element = @id = element.to_s
- else
- OBJ_ID.mutex.synchronize{
- @element = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
- OBJ_ID[1].succ!
- }
- end
- @path = @id
- @parent = @chart = chart
- @cpath = @chart.path
- @typename = self.class::ElementTypeName
- Element::ElementID_TBL[@cpath][@element] = self
- unless not_create
- tk_call(@chart, @typename, 'create', @element, keys)
- return obj
- end
- }
- end
- }
-
- obj.configure(keys) if obj && ! keys.empty?
- obj
+ super(chart, element, keys)
end
def initialize(chart, element=nil, keys={})
- # dummy:: not called by 'new' method
-
if element.kind_of?(Hash)
keys = element
element = nil
@@ -704,16 +537,14 @@ module Tk::BLT
if element
@element = @id = element.to_s
else
- OBJ_ID.mutex.synchronize{
- @element = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
- OBJ_ID[1].succ!
- }
+ @element = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
+ OBJ_ID[1].succ!
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
@typename = self.class::ElementTypeName
- # Element::ElementID_TBL[@cpath][@element] = self
+ Element::OBJ_TBL[@cpath][@element] = self
keys = _symbolkey2str(keys)
unless keys.delete('without_creating')
# @chart.element_create(@element, keys)
@@ -733,9 +564,6 @@ module Tk::BLT
# @chart.element_cget(@id, option)
@chart.__send__(@typename + '_cget', @id, option)
end
- def cget_strict(option)
- @chart.__send__(@typename + '_cget_strict', @id, option)
- end
def configure(key, value=None)
# @chart.element_configure(@id, key, value)
@chart.__send__(@typename + '_configure', @id, key, value)
@@ -794,33 +622,17 @@ module Tk::BLT
#################
class GridLine < TkObject
- GridLineID_TBL = TkCore::INTERP.create_table
- TkCore::INTERP.init_ip_env{
- GridLineID_TBL.mutex.synchronize{ GridLineID_TBL.clear }
- }
+ OBJ_TBL={}
def self.new(chart, keys={})
- obj = nil
- GridLineID_TBL.mutex.synchronize{
- unless (obj = GridLineID_TBL[chart.path])
- (obj = self.allocate).instance_eval{
- @parent = @chart = chart
- @cpath = @chart.path
- @path = @id = 'grid'
- GridLine::GridLineID_TBL[@cpath] = self
- }
- end
- }
- chart.gridline_configure(keys) if obj && ! keys.empty?
- obj
+ return OBJ_TBL[chart.path] if OBJ_TBL[chart.path]
+ super(chart, keys)
end
def initialize(chart, keys={})
- # dummy:: not called by 'new' method
-
@parent = @chart = chart
@cpath = @chart.path
- # GridLine::GridLineID_TBL[@cpath] = self
+ GridLine::OBJ_TBL[@cpath] = self
@chart.gridline_configure(keys) unless keys.empty?
@path = @id = 'grid'
end
@@ -836,9 +648,6 @@ module Tk::BLT
def cget(option)
@chart.gridline_cget(option)
end
- def cget_strict(option)
- @chart.gridline_cget_strict(option)
- end
def configure(key, value=None)
@chart.gridline_configure(key, value)
self
@@ -867,35 +676,18 @@ module Tk::BLT
#################
class Legend < TkObject
- LegendID_TBL = TkCore::INTERP.create_table
-
- TkCore::INTERP.init_ip_env{
- LegendID_TBL.mutex.synchronize{ LegendID_TBL.clear }
- }
+ OBJ_TBL={}
def self.new(chart, keys={})
- obj = nil
- LegenedID_TBL.mutex.synchronize{
- unless (obj = LegenedID_TBL[chart.path])
- (obj = self.allocate).instance_eval{
- @parent = @chart = chart
- @cpath = @chart.path
- @path = @id = 'crosshairs'
- Legend::LegenedID_TBL[@cpath] = self
- }
- end
- }
- chart.legend_configure(keys) if obj && ! keys.empty?
- obj
+ return OBJ_TBL[chart.path] if OBJ_TBL[chart.path]
+ super(chart, keys)
end
def initialize(chart, keys={})
- # dummy:: not called by 'new' method
-
@parent = @chart = chart
@cpath = @chart.path
- # Legend::LegendID_TBL[@cpath] = self
- @chart.legend_configure(keys) unless keys.empty?
+ Crosshairs::OBJ_TBL[@cpath] = self
+ @chart.crosshair_configure(keys) unless keys.empty?
@path = @id = 'legend'
end
@@ -910,9 +702,6 @@ module Tk::BLT
def cget(option)
@chart.legend_cget(option)
end
- def cget_strict(option)
- @chart.legend_cget_strict(option)
- end
def configure(key, value=None)
@chart.legend_configure(key, value)
self
@@ -940,24 +729,13 @@ module Tk::BLT
#################
class Pen < TkObject
- (OBJ_ID = ['blt_chart_pen'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- PenID_TBL = TkCore::INTERP.create_table
-
- TkCore::INTERP.init_ip_env{
- PenID_TBL.mutex.synchronize{ PenID_TBL.clear }
- }
+ OBJ_ID = ['blt_chart_pen'.freeze, '00000'.taint].freeze
+ OBJ_TBL={}
def self.id2obj(chart, id)
cpath = chart.path
- PenID_TBL.mutex.synchronize{
- return id unless PenID_TBL[cpath]
- PenID_TBL[cpath][id]? PenID_TBL[cpath][id]: id
- }
+ return id unless OBJ_TBL[cpath]
+ OBJ_TBL[cpath][id]? OBJ_TBL[cpath][id]: id
end
def self.new(chart, pen=nil, keys={})
@@ -965,43 +743,9 @@ module Tk::BLT
keys = pen
pen = nil
end
- if keys
- keys = _symbolkey2str(keys)
- not_create = keys.delete('without_creating')
- else
- not_create = false
- end
-
- obj = nil
- PenID_TBL.mutex.synchronize{
- chart_path = chart.path
- PenID_TBL[chart_path] ||= {}
- if pen && PenID_TBL[chart_path][pen]
- obj = PenID_TBL[chart_path][pen]
- else
- (obj = self.allocate).instance_eval{
- if pen
- @pen = @id = pen.to_s
- else
- OBJ_ID.mutex.synchronize{
- @pen = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
- OBJ_ID[1].succ!
- }
- end
- @path = @id
- @parent = @chart = chart
- @cpath = @chart.path
- Pen::PenID_TBL[@cpath][@pen] = self
- unless not_create
- tk_call(@chart, 'pen', 'create', @pen, keys)
- return obj
- end
- }
- end
- }
-
- obj.configure(keys) if obj && ! keys.empty?
- obj
+ OBJ_TBL[chart.path] = {} unless OBJ_TBL[chart.path]
+ return OBJ_TBL[chart.path][pen] if pen && OBJ_TBL[chart.path][pen]
+ super(chart, pen, keys)
end
def initialize(chart, pen=nil, keys={})
@@ -1012,15 +756,13 @@ module Tk::BLT
if pen
@pen = @id = pen.to_s
else
- OBJ_ID.mutex.synchronize{
- @pen = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
- OBJ_ID[1].succ!
- }
+ @pen = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
+ OBJ_ID[1].succ!
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
- Pen::PenID_TBL[@cpath][@pen] = self
+ Pen::OBJ_TBL[@cpath][@pen] = self
keys = _symbolkey2str(keys)
unless keys.delete('without_creating')
# @chart.pen_create(@pen, keys)
@@ -1039,9 +781,6 @@ module Tk::BLT
def cget(option)
@chart.pen_cget(@id, option)
end
- def cget_strict(option)
- @chart.pen_cget_strict(@id, option)
- end
def configure(key, value=None)
@chart.pen_configure(@id, key, value)
self
@@ -1066,34 +805,17 @@ module Tk::BLT
#################
class Postscript < TkObject
- PostscriptID_TBL = TkCore::INTERP.create_table
-
- TkCore::INTERP.init_ip_env{
- PostscriptID_TBL.mutex.synchronize{ PostscriptID_TBL.clear }
- }
+ OBJ_TBL={}
def self.new(chart, keys={})
- obj = nil
- PostscriptID_TBL.mutex.synchronize{
- unless (obj = PostscriptID_TBL[chart.path])
- (obj = self.allocate).instance_eval{
- @parent = @chart = chart
- @cpath = @chart.path
- @path = @id = 'postscript'
- Postscript::PostscriptID_TBL[@cpath] = self
- }
- end
- }
- chart.postscript_configure(keys) if obj && ! keys.empty?
- obj
+ return OBJ_TBL[chart.path] if OBJ_TBL[chart.path]
+ super(chart, keys)
end
def initialize(chart, keys={})
- # dummy:: not called by 'new' method
-
@parent = @chart = chart
@cpath = @chart.path
- # Postscript::PostscriptID_TBL[@cpath] = self
+ Postscript::OBJ_TBL[@cpath] = self
@chart.postscript_configure(keys) unless keys.empty?
@path = @id = 'postscript'
end
@@ -1109,9 +831,6 @@ module Tk::BLT
def cget(option)
@chart.postscript_cget(option)
end
- def cget_strict(option)
- @chart.postscript_cget_strict(option)
- end
def configure(key, value=None)
@chart.postscript_configure(key, value)
self
@@ -1151,9 +870,7 @@ module Tk::BLT
MarkerTypeToClass = {}
MarkerID_TBL = TkCore::INTERP.create_table
- TkCore::INTERP.init_ip_env{
- MarkerID_TBL.mutex.synchronize{ MarkerID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ MarkerID_TBL.clear }
def Marker.type2class(type)
MarkerTypeToClass[type]
@@ -1161,13 +878,8 @@ module Tk::BLT
def Marker.id2obj(chart, id)
cpath = chart.path
- MarkerID_TBL.mutex.synchronize{
- if MarkerID_TBL[cpath]
- MarkerID_TBL[cpath][id]? MarkerID_TBL[cpath][id]: id
- else
- id
- end
- }
+ return id unless MarkerID_TBL[cpath]
+ MarkerID_TBL[cpath][id]? MarkerID_TBL[cpath][id]: id
end
def self._parse_create_args(keys)
@@ -1190,13 +902,6 @@ module Tk::BLT
fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey)
}
- __item_optkey_aliases(nil).each{|alias_name, real_name|
- alias_name = alias_name.to_s
- if keys.has_key?(alias_name)
- keys[real_name.to_s] = keys.delete(alias_name)
- end
- }
-
__item_methodcall_optkeys(nil).each{|key|
key = key.to_s
methodkeys[key] = keys.delete(key) if keys.key?(key)
@@ -1238,10 +943,10 @@ module Tk::BLT
@parent = @chart = chart
@cpath = chart.path
@id = id
- Tk::BLT::PlotComponent::Marker::MarkerID_TBL.mutex.synchronize{
- Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] ||= {}
- Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath][@id] = self
- }
+ unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath]
+ Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] = {}
+ end
+ Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath][@id] = self
}
obj
end
@@ -1251,10 +956,10 @@ module Tk::BLT
@cpath = parent.path
@path = @id = create_self(*args) # an integer number as 'item id'
- Tk::BLT::PlotComponent::Marker::MarkerID_TBL.mutex.synchronize{
- Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] ||= {}
- Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath][@id] = self
- }
+ unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath]
+ Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] = {}
+ end
+ Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath][@id] = self
end
def create_self(*args)
self.class.create(@chart, *args) # return an integer as 'item id'
@@ -1272,9 +977,6 @@ module Tk::BLT
def cget(option)
@chart.marker_cget(@id, option)
end
- def cget_strict(option)
- @chart.marker_cget_strict(@id, option)
- end
def configure(key, value=None)
@chart.marker_configure(@id, key, value)
self
@@ -1335,14 +1037,14 @@ module Tk::BLT
#################
def __destroy_hook__
- Axis::AxisID_TBL.delete(@path)
- Crosshairs::CrosshairsID_TBL.delete(@path)
- Element::ElementID_TBL.delete(@path)
- GridLine::GridLineID_TBL.delete(@path)
- Legend::LegendID_TBL.delete(@path)
- Pen::PenID_TBL.delete(@path)
- Postscript::PostscriptID_TBL.delete(@path)
- Marker::MarkerID_TBL.delete(@path)
+ Axis::OBJ_TBL.delete(@path)
+ Crosshairs::OBJ_TBL.delete(@path)
+ Element::OBJ_TBL.delete(@path)
+ GridLine::OBJ_TBL.delete(@path)
+ Legend::OBJ_TBL.delete(@path)
+ Pen::OBJ_TBL.delete(@path)
+ Postscript::OBJ_TBL.delete(@path)
+ Marker::OBJ_TBL.delete(@path)
super()
end
@@ -1857,9 +1559,6 @@ module Tk::BLT
def xaxis_cget(option)
itemcget('xaxis', option)
end
- def xaxis_cget_strict(option)
- itemcget_strict('xaxis', option)
- end
def xaxis_configure(slot, value=None)
if slot.kind_of?(Hash)
slot = _symbolkey2str(slot)
@@ -1929,9 +1628,6 @@ module Tk::BLT
def x2axis_cget(option)
itemcget('x2axis', option)
end
- def x2axis_cget_strict(option)
- itemcget_strict('x2axis', option)
- end
def x2axis_configure(slot, value=None)
if slot.kind_of?(Hash)
slot = _symbolkey2str(slot)
@@ -2001,9 +1697,6 @@ module Tk::BLT
def yaxis_cget(option)
itemcget('yaxis', option)
end
- def yaxis_cget_strict(option)
- itemcget_strict('yaxis', option)
- end
def yaxis_configure(slot, value=None)
if slot.kind_of?(Hash)
slot = _symbolkey2str(slot)
@@ -2073,9 +1766,6 @@ module Tk::BLT
def y2axis_cget(option)
itemcget('y2axis', option)
end
- def y2axis_cget_strict(option)
- itemcget_strict('y2axis', option)
- end
def y2axis_configure(slot, value=None)
if slot.kind_of?(Hash)
slot = _symbolkey2str(slot)
diff --git a/ext/tk/lib/tkextlib/blt/dragdrop.rb b/ext/tk/lib/tkextlib/blt/dragdrop.rb
index 201548504a..68fb9e591a 100644
--- a/ext/tk/lib/tkextlib/blt/dragdrop.rb
+++ b/ext/tk/lib/tkextlib/blt/dragdrop.rb
@@ -81,24 +81,6 @@ module Tk::BLT
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL)
def self.ret_val(val)
@@ -125,24 +107,6 @@ module Tk::BLT
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL)
def self.ret_val(val)
@@ -181,24 +145,6 @@ module Tk::BLT
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL)
end
diff --git a/ext/tk/lib/tkextlib/blt/eps.rb b/ext/tk/lib/tkextlib/blt/eps.rb
index 0dba87a7cc..586a42470c 100644
--- a/ext/tk/lib/tkextlib/blt/eps.rb
+++ b/ext/tk/lib/tkextlib/blt/eps.rb
@@ -14,7 +14,7 @@ module Tk::BLT
end
end
-class Tk::Canvas
+class TkCanvas
alias __BLT_EPS_item_strval_optkeys __item_strval_optkeys
def __item_strval_optkeys(id)
__BLT_EPS_item_strval_optkeys(id) + [
diff --git a/ext/tk/lib/tkextlib/blt/htext.rb b/ext/tk/lib/tkextlib/blt/htext.rb
index 0d9cb30185..a0cf3dc036 100644
--- a/ext/tk/lib/tkextlib/blt/htext.rb
+++ b/ext/tk/lib/tkextlib/blt/htext.rb
@@ -22,7 +22,6 @@ module Tk::BLT
WidgetClassNames[WidgetClassName] = self
alias window_cget itemcget
- alias window_cget_strict itemcget_strict
alias window_configure itemconfigure
alias window_configuinfo itemconfiginfo
alias current_window_configuinfo current_itemconfiginfo
diff --git a/ext/tk/lib/tkextlib/blt/table.rb b/ext/tk/lib/tkextlib/blt/table.rb
index dfa10269ed..0be9d8d42a 100644
--- a/ext/tk/lib/tkextlib/blt/table.rb
+++ b/ext/tk/lib/tkextlib/blt/table.rb
@@ -29,9 +29,6 @@ module Tk::BLT
def blt_table_cget(*args)
Tk::BLT::Table.cget(self, *args)
end
- def blt_table_cget_strict(*args)
- Tk::BLT::Table.cget_strict(self, *args)
- end
def blt_table_configure(*args)
Tk::BLT::Table.configure(self, *args)
@@ -95,9 +92,6 @@ module Tk::BLT
def blt_table_itemcget(*args)
Tk::BLT::Table.itemcget(self, *args)
end
- def blt_table_itemcget_strict(*args)
- Tk::BLT::Table.itemcget_strict(self, *args)
- end
def blt_table_itemconfigure(*args)
Tk::BLT::Table.itemconfigure(self, *args)
@@ -142,13 +136,12 @@ class << Tk::BLT::Table
private :__item_pathname
alias __itemcget itemcget
- alias __itemcget_strict itemcget_strict
alias __itemconfigure itemconfigure
alias __itemconfiginfo itemconfiginfo
alias __current_itemconfiginfo current_itemconfiginfo
- private :__itemcget, :__itemcget_strict
- private :__itemconfigure, :__itemconfiginfo, :__current_itemconfiginfo
+ private :__itemcget, :__itemconfigure
+ private :__itemconfiginfo, :__current_itemconfiginfo
def __boolval_optkeys
super() << 'propagate'
@@ -183,9 +176,6 @@ class << Tk::BLT::Table
def cget(container, option)
__itemcget([container], option)
end
- def cget_strict(container, option)
- __itemcget_strict([container], option)
- end
def configure(container, *args)
__itemconfigure([container], *args)
@@ -202,9 +192,6 @@ class << Tk::BLT::Table
def itemcget(container, item, option)
__itemcget([container, tagid(item)], option)
end
- def itemcget_strict(container, item, option)
- __itemcget_strict([container, tagid(item)], option)
- end
def itemconfigure(container, *args)
if args[-1].kind_of?(Hash)
diff --git a/ext/tk/lib/tkextlib/blt/tabset.rb b/ext/tk/lib/tkextlib/blt/tabset.rb
index ca81ad8f95..c26b6ee001 100644
--- a/ext/tk/lib/tkextlib/blt/tabset.rb
+++ b/ext/tk/lib/tkextlib/blt/tabset.rb
@@ -12,26 +12,14 @@ module Tk::BLT
include TkTreatItemFont
TabID_TBL = TkCore::INTERP.create_table
+ TabsetTab_ID = ['blt_tabset_tab'.freeze, '00000'.taint].freeze
- (TabsetTab_ID = ['blt_tabset_tab'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- TabID_TBL.mutex.synchronize{ TabID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ TabID_TBL.clear }
def self.id2obj(tabset, id)
tpath = tabset.path
- TabID_TBL.mutex.synchronize{
- if TabID_TBL[tpath]
- TabID_TBL[tpath][id]? TabID_TBL[tpath]: id
- else
- id
- end
- }
+ return id unless TabID_TBL[tpath]
+ TabID_TBL[tpath][id]? TabID_TBL[tpath]: id
end
def self.new(parent, pos=nil, name=nil, keys={})
@@ -44,20 +32,12 @@ module Tk::BLT
keys = name
name = nil
end
- obj = nil
- TabID_TBL.mutex.synchronize{
- if name && TabID_TBL[parent.path] && TabID_TBL[parent.path][name]
- obj = TabID_TBL[parent.path][name]
- obj.configure if keys && ! keys.empty?
- else
- (obj = self.allocate).instance_eval{
- initialize(parent, pos, name, keys)
- TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath]
- TabID_TBL[@tpath][@id] = self
- }
- end
- }
- obj
+
+ if name && TabID_TBL[parent.path] && TabID_TBL[parent.path][name]
+ TabID_TBL[parent.path][name]
+ else
+ super(parent, pos, name, keys)
+ end
end
def initialize(parent, pos, name, keys)
@@ -65,6 +45,9 @@ module Tk::BLT
@tpath = parent.path
if name
@path = @id = name
+ TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath]
+ TabID_TBL[@tpath][@id] = self
+
unless (list(tk_call(@tpath, 'tab', 'names', @id)).empty?)
if pos
idx = tk_call(@tpath, 'index', '-name', @id)
@@ -75,18 +58,18 @@ module Tk::BLT
end
end
tk_call(@tpath, 'tab', 'configure', @id, keys)
- else
- pos = 'end' unless pos
- tk_call(@tpath, 'insert', pos, @id, keys)
+ return
end
+
else
- TabsetTab_ID.mutex.synchronize{
- @path = @id = TabsetTab_ID.join(TkCore::INTERP._ip_id_)
- TabsetTab_ID[1].succ!
- }
- pos = 'end' unless pos
- tk_call(@tpath, 'insert', pos, @id, keys)
+ @path = @id = TabsetTab_ID.join(TkCore::INTERP._ip_id_)
+ TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath]
+ TabID_TBL[@tpath][@id] = self
+ TabsetTab_ID[1].succ!
end
+
+ pos = 'end' unless pos
+ tk_call(@tpath, 'insert', pos, @id, keys)
end
#def bind(context, cmd=Proc.new, *args)
@@ -128,9 +111,6 @@ module Tk::BLT
def cget(*args)
@t.tab_cget(@id, *args)
end
- def cget_strict(*args)
- @t.tab_cget_strict(@id, *args)
- end
def configure(*args)
@t.tab_configure(@id, *args)
end
@@ -143,9 +123,7 @@ module Tk::BLT
def delete()
@t.delete(@id)
- TabID_TBL.mutex.synchronize{
- TabID_TBL[@tpath].delete(@id)
- }
+ TabID_TBL[@tpath].delete(@id)
self
end
@@ -206,9 +184,7 @@ module Tk::BLT
WidgetClassNames[WidgetClassName] = self
def __destroy_hook__
- Tk::BLT::Tabset::Tab::TabID_TBL.mutex.synchronize{
- Tk::BLT::Tabset::Tab::TabID_TBL.delete(@path)
- }
+ Tk::BLT::Tabset::Tab::TabID_TBL.delete(@path)
end
########################################
@@ -243,7 +219,6 @@ module Tk::BLT
private :__item_pathname
alias tab_cget itemcget
- alias tab_cget_strict itemcget_strict
alias tab_configure itemconfigure
alias tab_configinfo itemconfiginfo
alias current_tab_configinfo current_itemconfiginfo
@@ -316,15 +291,11 @@ module Tk::BLT
def delete(first, last=None)
tk_send('delete', tagindex(first), tagindex(last))
if first.kind_of?(Tk::BLT::Tabset::Tab)
- TabID_TBL.mutex.synchronize{
- TabID_TBL[@path].delete(first.id)
- }
+ TabID_TBL[@path].delete(first.id)
end
# middle tabs of the range are unknown
if last.kind_of?(Tk::BLT::Tabset::Tab)
- TabID_TBL.mutex.synchronize{
- TabID_TBL[@path].delete(last.id)
- }
+ TabID_TBL[@path].delete(last.id)
end
self
end
diff --git a/ext/tk/lib/tkextlib/blt/ted.rb b/ext/tk/lib/tkextlib/blt/ted.rb
index 670265fc78..39495842b4 100644
--- a/ext/tk/lib/tkextlib/blt/ted.rb
+++ b/ext/tk/lib/tkextlib/blt/ted.rb
@@ -30,14 +30,11 @@ module Tk::BLT
end
private :__item_config_cmd
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
def cget(master, option)
- itemcget(master, option)
- end
- def cget_strict(master, option)
- itemcget_strict(master, option)
+ itemconfigure(master, slot, value)
end
def configure(master, slot, value=None)
itemconfigure(master, slot, value)
diff --git a/ext/tk/lib/tkextlib/blt/tile/button.rb b/ext/tk/lib/tkextlib/blt/tile/button.rb
index 2e0863cfbe..dd715c8b98 100644
--- a/ext/tk/lib/tkextlib/blt/tile/button.rb
+++ b/ext/tk/lib/tkextlib/blt/tile/button.rb
@@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
- class Button < Tk::Button
+ class Button < TkButton
TkCommandNames = ['::blt::tile::button'.freeze].freeze
end
end
diff --git a/ext/tk/lib/tkextlib/blt/tile/checkbutton.rb b/ext/tk/lib/tkextlib/blt/tile/checkbutton.rb
index da230b5925..ad58999d86 100644
--- a/ext/tk/lib/tkextlib/blt/tile/checkbutton.rb
+++ b/ext/tk/lib/tkextlib/blt/tile/checkbutton.rb
@@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
- class CheckButton < Tk::CheckButton
+ class CheckButton < TkCheckButton
TkCommandNames = ['::blt::tile::checkbutton'.freeze].freeze
end
Checkbutton = CheckButton
diff --git a/ext/tk/lib/tkextlib/blt/tile/frame.rb b/ext/tk/lib/tkextlib/blt/tile/frame.rb
index 5434af4b72..10469fd35f 100644
--- a/ext/tk/lib/tkextlib/blt/tile/frame.rb
+++ b/ext/tk/lib/tkextlib/blt/tile/frame.rb
@@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
- class Frame < Tk::Frame
+ class Frame < TkFrame
TkCommandNames = ['::blt::tile::frame'.freeze].freeze
end
end
diff --git a/ext/tk/lib/tkextlib/blt/tile/label.rb b/ext/tk/lib/tkextlib/blt/tile/label.rb
index f370c1403b..ec67babd58 100644
--- a/ext/tk/lib/tkextlib/blt/tile/label.rb
+++ b/ext/tk/lib/tkextlib/blt/tile/label.rb
@@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
- class Label < Tk::Label
+ class Label < TkLabel
TkCommandNames = ['::blt::tile::label'.freeze].freeze
end
end
diff --git a/ext/tk/lib/tkextlib/blt/tile/radiobutton.rb b/ext/tk/lib/tkextlib/blt/tile/radiobutton.rb
index 814f9a5cc4..2316923b19 100644
--- a/ext/tk/lib/tkextlib/blt/tile/radiobutton.rb
+++ b/ext/tk/lib/tkextlib/blt/tile/radiobutton.rb
@@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
- class RadioButton < Tk::RadioButton
+ class RadioButton < TkRadioButton
TkCommandNames = ['::blt::tile::radiobutton'.freeze].freeze
end
Radiobutton = RadioButton
diff --git a/ext/tk/lib/tkextlib/blt/tile/scrollbar.rb b/ext/tk/lib/tkextlib/blt/tile/scrollbar.rb
index 2ae871d518..ba3bf316f0 100644
--- a/ext/tk/lib/tkextlib/blt/tile/scrollbar.rb
+++ b/ext/tk/lib/tkextlib/blt/tile/scrollbar.rb
@@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
- class Scrollbar < Tk::Scrollbar
+ class Scrollbar < TkScrollbar
TkCommandNames = ['::blt::tile::scrollbar'.freeze].freeze
end
end
diff --git a/ext/tk/lib/tkextlib/blt/tile/toplevel.rb b/ext/tk/lib/tkextlib/blt/tile/toplevel.rb
index 76d5f86b1b..6cc2c91415 100644
--- a/ext/tk/lib/tkextlib/blt/tile/toplevel.rb
+++ b/ext/tk/lib/tkextlib/blt/tile/toplevel.rb
@@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
- class Toplevel < Tk::Toplevel
+ class Toplevel < TkToplevel
TkCommandNames = ['::blt::tile::toplevel'.freeze].freeze
end
end
diff --git a/ext/tk/lib/tkextlib/blt/tree.rb b/ext/tk/lib/tkextlib/blt/tree.rb
index 77b85f1717..07dc7ef7e8 100644
--- a/ext/tk/lib/tkextlib/blt/tree.rb
+++ b/ext/tk/lib/tkextlib/blt/tree.rb
@@ -12,77 +12,53 @@ module Tk::BLT
###################################
- class Node < TkObject
+ class Node < TkObject
TreeNodeID_TBL = TkCore::INTERP.create_table
-
- TkCore::INTERP.init_ip_env{
- TreeNodeID_TBL.mutex.synchronize{ TreeNodeID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ TreeNodeID_TBL.clear }
def self.id2obj(tree, id)
tpath = tree.path
- TreeNodeID_TBL.mutex.synchronize{
- if TreeNodeID_TBL[tpath]
- if TreeNodeID_TBL[tpath][id]
- TreeNodeID_TBL[tpath][id]
- else
- begin
- # self.new(tree, nil, 'node'=>Integer(id))
- id = Integer(id)
- if bool(tk_call(@tpath, 'exists', id))
- (obj = self.allocate).instance_eval{
- @parent = @tree = tree
- @tpath = tpath
- @path = @id = id
- TreeNodeID_TBL[@tpath] = {} unless TreeNodeID_TBL[@tpath]
- TreeNodeID_TBL[@tpath][@id] = self
- }
- obj
- else
- id
- end
- rescue
- id
- end
- end
- else
+ return id unless TreeNodeID_TBL[tpath]
+ if TreeNodeID_TBL[tpath][id]
+ TreeNodeID_TBL[tpath][id]
+ else
+ begin
+ self.new(tree, nil, 'node'=>Integer(id))
+ rescue
id
end
- }
+ end
end
def self.new(tree, parent, keys={})
keys = _symbolkey2str(keys)
tpath = tree.path
- TreeNodeID_TBL.mutex.synchronize{
- TreeNodeID_TBL[tpath] ||= {}
- if (id = keys['node']) && (obj = TreeNodeID_TBL[tpath][id])
- keys.delete('node')
- tk_call(tree.path, 'move', id, parent, keys) if parent
- return obj
- end
+ if (id = keys['node']) && (obj = TreeNodeID_TBL[tpath][id])
+ keys.delete('node')
+ tk_call(tree.path, 'move', id, parent, keys) if parent
+ return obj
+ end
- (obj = self.allocate).instance_eval{
- initialize(tree, parent, keys)
- TreeNodeID_TBL[tpath][@id] = self
- }
- obj
- }
+ super(tree, parent, keys)
end
def initialize(tree, parent, keys={})
@parent = @tree = tree
@tpath = @parent.path
+ parent = tk_call(@tpath, 'root') unless parent
+
if (id = keys['node']) && bool(tk_call(@tpath, 'exists', id))
@path = @id = id
keys.delete('node')
tk_call(@tpath, 'move', @id, parent, keys) if parent
else
- parent = tk_call(@tpath, 'root') unless parent
@path = @id = tk_call(@tpath, 'insert', parent, keys)
end
+
+ TreeNodeID_TBL[@tpath] = {} unless TreeNodeID_TBL[@tpath]
+ TreeNodeID_TBL[@tpath][@id] = self
end
def id
@@ -267,42 +243,17 @@ module Tk::BLT
class Tag < TkObject
TreeTagID_TBL = TkCore::INTERP.create_table
-
- TkCore::INTERP.init_ip_env{
- TreeTagID_TBL.mutex.synchronize{ TreeTagID_TBL.clear }
- }
-
- (TreeTag_ID = ['blt_tree_tag'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
+ TkCore::INTERP.init_ip_env{ TreeTagID_TBL.clear }
+ TreeTag_ID = ['blt_tree_tag'.freeze, '00000'.taint].freeze
def self.id2obj(tree, id)
tpath = tree.path
- TreeTagID_TBL.mutex.synchronize{
- if TreeTagID_TBL[tpath]
- if TreeTagID_TBL[tpath][id]
- TreeTagID_TBL[tpath][id]
- else
- begin
- # self.new(tree, id)
- (obj = self.allocate).instance_eval{
- @parent = @tree = tree
- @tpath = @parent.path
- @path = @id = id.dup.freeze if id
- TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
- TreeTagID_TBL[@tpath][@id] = self
- }
- obj
- rescue
- id
- end
- end
- else
- id
- end
- }
+ return id unless TreeTagID_TBL[tpath]
+ if TreeTagID_TBL[tpath][id]
+ TreeTagID_TBL[tpath][id]
+ else
+ self.new(tree, id)
+ end
end
def initialize(tree, tag_str = nil)
@@ -312,15 +263,12 @@ module Tk::BLT
if tag_str
@path = @id = tag_str.dup.freeze
else
- TreeTag_ID.mutex.synchronize{
- @path = @id = TreeTag_ID.join(TkCore::INTERP._ip_id_)
- TreeTag_ID[1].succ!
- }
+ @path = @id = TreeTag_ID.join(TkCore::INTERP._ip_id_)
+ TreeTagID_TBL[@id] = self
+ TreeTag_ID[1].succ!
end
- TreeTagID_TBL.mutex.synchronize{
- TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
- TreeTagID_TBL[@tpath][@id] = self
- }
+ TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
+ TreeTagID_TBL[@tpath][@id] = self
end
def id
@@ -339,9 +287,7 @@ module Tk::BLT
def forget()
tk_call(@tpath, 'tag', 'forget', @id)
- TreeTagID_TBL.mutex.synchronize{
- TreeTagID_TBL[@tpath].delete(@id)
- }
+ TreeTagID_TBL[@tpath].delete(@id)
self
end
@@ -366,63 +312,44 @@ module Tk::BLT
class Notify < TkObject
NotifyID_TBL = TkCore::INTERP.create_table
-
- TkCore::INTERP.init_ip_env{
- NotifyID_TBL.mutex.synchronize{ NotifyID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ NotifyID_TBL.clear }
def self.id2obj(tree, id)
tpath = tree.path
- NotifyID_TBL.mutex.synchronize{
- if NotifyID_TBL[tpath]
- if NotifyID_TBL[tpath][id]
- NotifyID_TBL[tpath][id]
- else
- (obj = self.allocate).instance_eval{
- @parent = @tree = tree
- @tpath = @parent.path
- @path = @id = id
- NotifyID_TBL[@tpath] ||= {}
- NotifyID_TBL[@tpath][@id] = self
- }
- obj
- end
- else
- return id
+ return id unless NotifyID_TBL[tpath]
+ if NotifyID_TBL[tpath][id]
+ NotifyID_TBL[tpath][id]
+ else
+ begin
+ self.new([tree, id])
+ rescue
+ id
end
- }
+ end
end
def self.new(tree, *args, &b)
- NotifyID_TBL.mutex.synchronize{
- if tree.kind_of?(Array)
- # not create
- tpath = tree[0].path
- NotifyID_TBL[tpath] ||= {}
- unless (obj = NotifyID_TBL[tpath][tree[1]])
- (NotifyID_TBL[tpath][tree[1]] =
- obj = self.allocate).instance_eval{
- @parent = @tree = tree[0]
- @tpath = @parent.path
- @path = @id = tree[1]
- }
- end
+ if tree.kind_of?(Array)
+ # not create
+ if obj = NotifyID_TBL[tree[0].path][tree[1]]
return obj
+ else
+ return super(false, tree[0], tree[1])
end
+ end
- (obj = self.allocate).instance_eval{
- initialize(tree, *args, &b)
- NotifyID_TBL[@tpath] ||= {}
- NotifyID_TBL[@tpath][@id] = self
- }
- return obj
- }
+ super(true, tree, *args, &b)
end
- def initialize(tree, *args, &b)
+ def initialize(create, tree, *args, &b)
@parent = @tree = tree
@tpath = @parent.path
+ unless create
+ @path = @id = args[0]
+ return
+ end
+
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
if TkComm._callback_entry?(args[0])
cmd = args.shift
@@ -451,9 +378,7 @@ module Tk::BLT
def delete()
tk_call(@tpath, 'notify', 'delete', @id)
- NotifyID_TBL.mutex.synchronize{
- NotifyID_TBL[@tpath].delete(@id)
- }
+ NotifyID_TBL[tpath].delete(@id)
self
end
@@ -470,69 +395,44 @@ module Tk::BLT
class Trace < TkObject
TraceID_TBL = TkCore::INTERP.create_table
-
- TkCore::INTERP.init_ip_env{
- TraceID_TBL.mutex.synchronize{ TraceID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ TraceID_TBL.clear }
def self.id2obj(tree, id)
tpath = tree.path
- TraceID_TBL.mutex.synchronize{
- if TraceID_TBL[tpath]
- if TraceID_TBL[tpath][id]
- TraceID_TBL[tpath][id]
- else
- begin
- # self.new([tree, id])
- (obj = self.allocate).instance_eval{
- @parent = @tree = tree
- @tpath = @parent.path
- @path = @id = node # == traceID
- TraceID_TBL[@tpath] ||= {}
- TraceID_TBL[@tpath][@id] = self
- }
- obj
- rescue
- id
- end
- end
- else
+ return id unless TraceID_TBL[tpath]
+ if TraceID_TBL[tpath][id]
+ TraceID_TBL[tpath][id]
+ else
+ begin
+ self.new([tree, id])
+ rescue
id
end
- }
+ end
end
def self.new(tree, *args, &b)
- TraceID_TBL.mutex.synchronize{
- if tree.kind_of?(Array)
- # not create
- tpath = tree[0].path
- TraceID_TBL[tpath] ||= {}
- unless (obj = TraceID_TBL[tpath][tree[1]])
- (TraceID_TBL[tpath][tree[1]] =
- obj = self.allocate).instance_eval{
- @parent = @tree = tree
- @tpath = @parent.path
- @path = @id = tree[1] # == traceID
- }
- end
+ if tree.kind_of?(Array)
+ # not create
+ if obj = TraceID_TBL[tree[0].path][tree[1]]
return obj
+ else
+ return super(false, tree[0], tree[1])
end
+ end
- # super(true, tree, *args, &b)
- (obj = self.allocate).instance_eval{
- initialize(tree, *args, &b)
- TraceID_TBL[@tpath] ||= {}
- TraceID_TBL[@tpath][@id] = self
- }
- return obj
- }
+ super(true, tree, *args, &b)
end
- def initialize(tree, node, key, opts, cmd=nil, &b)
+ def initialize(create, tree, node, key, opts, cmd=nil, &b)
@parent = @tree = tree
@tpath = @parent.path
+ unless create
+ @path = @id = node # == traceID
+ return
+ end
+
if !cmd
if b
cmd = Proc.new(&b)
@@ -559,9 +459,7 @@ module Tk::BLT
def delete()
tk_call(@tpath, 'trace', 'delete', @id)
- TraceID_TBL.mutex.synchronize{
- TraceID_TBL[tpath].delete(@id)
- }
+ TraceID_TBL[tpath].delete(@id)
self
end
@@ -577,12 +475,7 @@ module Tk::BLT
###################################
TreeID_TBL = TkCore::INTERP.create_table
-
- (Tree_ID = ['blt_tree'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
+ Tree_ID = ['blt_tree'.freeze, '00000'.taint].freeze
def __keyonly_optkeys
{
@@ -605,9 +498,7 @@ module Tk::BLT
end
def self.id2obj(id)
- TreeID_TBL.mutex.synchronize{
- TreeID_TBL[id]? TreeID_TBL[id]: id
- }
+ TreeID_TBL[id]? TreeID_TBL[id]: id
end
def self.names(pat = None)
@@ -622,45 +513,27 @@ module Tk::BLT
end
def self.new(name = nil)
- TreeID_TBL.mutex.synchronize{
- if name && TreeID_TBL[name]
- TreeID_TBL[name]
- else
- (obj = self.allocate).instance_eval{
- initialize(name)
- TreeID_TBL[@id] = self
- }
- obj
- end
- }
+ return TreeID_TBL[name] if name && TreeID_TBL[name]
+ super(name)
end
def initialzie(name = nil)
if name
@path = @id = name
else
- Tree_ID.mutex.synchronize{
- @path = @id = Tree_ID.join(TkCore::INTERP._ip_id_)
- Tree_ID[1].succ!
- }
+ @path = @id = Tree_ID.join(TkCore::INTERP._ip_id_)
+ TreeID_TBL[@id] = self
+ Tree_ID[1].succ!
end
-
+ TreeID_TBL[@id] = self
tk_call('::blt::tree', 'create', @id)
end
def __destroy_hook__
- Tk::BLT::Tree::Node::TreeNodeID_TBL.mutex.synchronize{
- Tk::BLT::Tree::Node::TreeNodeID_TBL.delete(@path)
- }
- Tk::BLT::Tree::Tag::TreeTagID_TBL.mutex.synchronize{
- Tk::BLT::Tree::Tag::TreeTagID_TBL.delete(@path)
- }
- Tk::BLT::Tree::Notify::NotifyID_TBL.mutex.synchronize{
- Tk::BLT::Tree::Notify::NotifyID_TBL.delete(@path)
- }
- Tk::BLT::Tree::Trace::TraceID_TBL.mutex.synchronize{
- Tk::BLT::Tree::Trace::TraceID_TBL.delete(@path)
- }
+ Tk::BLT::Tree::Node::TreeNodeID_TBL.delete(@path)
+ Tk::BLT::Tree::Tag::TreeTagID_TBL.delete(@path)
+ Tk::BLT::Tree::Notify::NotifyID_TBL.delete(@path)
+ Tk::BLT::Tree::Trace::TraceID_TBL.delete(@path)
end
def tagid(tag)
@@ -719,14 +592,12 @@ module Tk::BLT
def delete(*nodes)
tk_call('::blt::tree', 'delete', *(nodes.collect{|node| tagid(node)}))
- Tk::BLT::Tree::Node::TreeNodeID_TBL.mutex.synchronize{
- nodes.each{|node|
- if node.kind_of?(Tk::BLT::Tree::Node)
- Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.id)
- else
- Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.to_s)
- end
- }
+ nodes.each{|node|
+ if node.kind_of?(Tk::BLT::Tree::Node)
+ Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.id)
+ else
+ Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.to_s)
+ end
}
self
end
@@ -857,9 +728,7 @@ module Tk::BLT
id.delete
else
tk_call(@path, 'notify', 'delete', id)
- Tk::BLT::Tree::Notify::NotifyID_TBL.mutex.synchronize{
- Tk::BLT::Tree::Notify::NotifyID_TBL[@path].delete(id.to_s)
- }
+ Tk::BLT::Tree::Notify::NotifyID_TBL[@path].delete(id.to_s)
end
self
end
@@ -966,9 +835,7 @@ module Tk::BLT
def tag_forget(tag)
tag = tag.id if tag.kind_of?(Tk::BLT::Tree::Tag)
tk_call(@path, 'tag', 'forget', tag)
- TreeTagID_TBL.mutex.synchronize{
- TreeTagID_TBL[@path].delete(tag)
- }
+ TreeTagID_TBL[@path].delete(tag)
self
end
@@ -1022,9 +889,7 @@ module Tk::BLT
def trace_delete(*args)
args = args.collect{|id| tagid(id)}
tk_call(@path, 'trace', 'delete', *args)
- Tk::BLT::Tree::Trace::TraceID_TBL.mutex.synchronize{
- args.each{|id| Tk::BLT::Tree::Trace::TraceID_TBL[@path].delete(id.to_s)}
- }
+ args.each{|id| Tk::BLT::Tree::Trace::TraceID_TBL[@path].delete(id.to_s)}
self
end
diff --git a/ext/tk/lib/tkextlib/blt/treeview.rb b/ext/tk/lib/tkextlib/blt/treeview.rb
index c5a5697186..0343d28b9c 100644
--- a/ext/tk/lib/tkextlib/blt/treeview.rb
+++ b/ext/tk/lib/tkextlib/blt/treeview.rb
@@ -98,9 +98,6 @@ module Tk::BLT::Treeview::ConfigMethod
def column_cget(name, option)
itemcget(['column', name], option)
end
- def column_cget_strict(name, option)
- itemcget_strict(['column', name], option)
- end
def column_configure(name, slot, value=None)
itemconfigure(['column', name], slot, value)
end
@@ -114,9 +111,6 @@ module Tk::BLT::Treeview::ConfigMethod
def button_cget(option)
itemcget('button', option)
end
- def button_cget_strict(option)
- itemcget_strict('button', option)
- end
def button_configure(slot, value=None)
itemconfigure('button', slot, value)
end
@@ -135,14 +129,6 @@ module Tk::BLT::Treeview::ConfigMethod
ret
end
end
- def entry_cget_strict(option)
- ret = itemcget_strict('entry', option)
- if option == 'bindtags' || option == :bindtags
- ret.collect{|tag| TkBindTag.id2obj(tag)}
- else
- ret
- end
- end
def entry_configure(slot, value=None)
itemconfigure('entry', slot, value)
end
@@ -184,9 +170,6 @@ module Tk::BLT::Treeview::ConfigMethod
def sort_cget(option)
itemcget('sort', option)
end
- def sort_cget_strict(option)
- itemcget_strict('sort', option)
- end
def sort_configure(slot, value=None)
itemconfigure('sort', slot, value)
end
@@ -200,9 +183,6 @@ module Tk::BLT::Treeview::ConfigMethod
def text_cget(option)
itemcget('text', option)
end
- def text_cget_strict(option)
- itemcget_strict('text', option)
- end
def text_configure(slot, value=None)
itemconfigure('text', slot, value)
end
@@ -213,8 +193,8 @@ module Tk::BLT::Treeview::ConfigMethod
current_itemconfiginfo('text', slot)
end
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
end
class Tk::BLT::Treeview
@@ -259,24 +239,6 @@ class Tk::BLT::Treeview
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@@ -311,12 +273,8 @@ class Tk::BLT::Treeview
########################
def __destroy_hook__
- Tk::BLT::Treeview::Node::TreeNodeID_TBL.mutex.synchronize{
- Tk::BLT::Treeview::Node::TreeNodeID_TBL.delete(@path)
- }
- Tk::BLT::Treeview::Tag::TreeTagID_TBL.mutex.synchronize{
- Tk::BLT::Treeview::Tag::TreeTagID_TBL.delete(@path)
- }
+ Tk::BLT::Treeview::Node::TreeNodeID_TBL.delete(@path)
+ Tk::BLT::Treeview::Tag::TreeTagID_TBL.delete(@path)
end
def tagid(tag)
@@ -514,24 +472,6 @@ class Tk::BLT::Treeview
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@@ -547,8 +487,7 @@ class Tk::BLT::Treeview
def _find_exec_flag_value(val)
if val.kind_of?(Array)
cmd, *args = val
- #FindExecFlagValue.new(cmd, args.join(' '))
- FindExecFlagValue.new(cmd, *args)
+ FindExecFlagValue.new(cmd, args.join(' '))
elsif TkComm._callback_entry?(val)
FindExecFlagValue.new(val)
else
@@ -1028,47 +967,22 @@ class Tk::BLT::Treeview::Node < TkObject
include Tk::BLT::Treeview::TagOrID_Methods
TreeNodeID_TBL = TkCore::INTERP.create_table
+ TreeNode_ID = ['blt_treeview_node'.freeze, '00000'.taint].freeze
- (TreeNode_ID = ['blt_treeview_node'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- TreeNodeID_TBL.mutex.synchronize{ TreeNodeID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ TreeNodeID_TBL.clear }
def self.id2obj(tree, id)
tpath = tree.path
- TreeNodeID_TBL.mutex.synchronize{
- if TreeNodeID_TBL[tpath]
- if TreeNodeID_TBL[tpath][id]
- TreeNodeID_TBL[tpath][id]
- else
- begin
- # self.new(tree, nil, nil, 'node'=>Integer(id))
- unless (tk_call(@tpath, 'get', id)).empty?
- id = Integer(id)
- (obj = self.allocate).instance_eval{
- @parent = @tree = tree
- @tpath = @parent.path
- @path = @id = id
- TreeNodeID_TBL[@tpath] ||= {}
- TreeNodeID_TBL[@tpath][@id] = self
- }
- obj
- else
- id
- end
- rescue
- id
- end
- end
- else
+ return id unless TreeNodeID_TBL[tpath]
+ if TreeNodeID_TBL[tpath][id]
+ TreeNodeID_TBL[tpath][id]
+ else
+ begin
+ self.new(tree, nil, nil, 'node'=>Integer(id))
+ rescue
id
end
- }
+ end
end
def self.new(tree, pos, parent=nil, keys={})
@@ -1080,21 +994,13 @@ class Tk::BLT::Treeview::Node < TkObject
keys = _symbolkey2str(keys)
tpath = tree.path
- TreeNodeID_TBL.mutex.synchronize{
- TreeNodeID_TBL[tpath] ||= {}
- if (id = keys['node']) && (obj = TreeNodeID_TBL[tpath][id])
- keys.delete('node')
- tk_call(tree.path, 'move', id, pos, parent) if parent
- return obj
- end
+ if (id = keys['node']) && (obj = TreeNodeID_TBL[tpath][id])
+ keys.delete('node')
+ tk_call(tree.path, 'move', id, pos, parent) if parent
+ return obj
+ end
- #super(tree, pos, parent, keys)
- (obj = self.allocate).instance_eval{
- initialize(tree, pos, parent, keys)
- TreeNodeID_TBL[tpath][@id] = self
- }
- obj
- }
+ super(tree, pos, parent, keys)
end
def initialize(tree, pos, parent, keys)
@@ -1102,18 +1008,11 @@ class Tk::BLT::Treeview::Node < TkObject
@tpath = @parent.path
if (id = keys['node'])
- # if tk_call(@tpath, 'get', id).empty?
- # fail RuntimeError, "not exist the node '#{id}'"
- # end
@path = @id = id
tk_call(@tpath, 'move', @id, pos, tagid(parent)) if parent
- configure(keys) if keys && ! keys.empty?
else
- name = nil
- TreeNode_ID.mutex.synchronize{
- name = TreeNode_ID.join(TkCore::INTERP._ip_id_).freeze
- TreeNode_ID[1].succ!
- }
+ name = TreeNode_ID.join(TkCore::INTERP._ip_id_).freeze
+ TreeNode_ID[1].succ!
at = keys.delete['at']
@@ -1136,6 +1035,9 @@ class Tk::BLT::Treeview::Node < TkObject
end
@path = @id
end
+
+ TreeNodeID_TBL[@tpath] = {} unless TreeNodeID_TBL[@tpath]
+ TreeNodeID_TBL[@tpath][@id] = self
end
def id
@@ -1149,66 +1051,37 @@ class Tk::BLT::Treeview::Tag < TkObject
include Tk::BLT::Treeview::TagOrID_Methods
TreeTagID_TBL = TkCore::INTERP.create_table
+ TreeTag_ID = ['blt_treeview_tag'.freeze, '00000'.taint].freeze
- (TreeTag_ID = ['blt_treeview_tag'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- TreeTagID_TBL.mutex.synchronize{ TreeTagID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ TreeTagID_TBL.clear }
- def self.id2obj(tree, name)
+ def self.id2obj(tree, id)
tpath = tree.path
- TreeTagID_TBL.mutex.synchronize{
- if TreeTagID_TBL[tpath]
- if TreeTagID_TBL[tpath][name]
- TreeTagID_TBL[tpath][name]
- else
- #self.new(tree, name)
- (obj = self.allocate).instance_eval{
- @parent = @tree = tree
- @tpath = @parent.path
- @path = @id = name
- TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
- TreeTagID_TBL[@tpath][@id] = self
- }
- obj
- end
- else
+ return id unless TreeTagID_TBL[tpath]
+ if TreeTagID_TBL[tpath][id]
+ TreeTagID_TBL[tpath][id]
+ else
+ begin
+ self.new(tree, nil, nil, 'name'=>Integer(id))
+ rescue
id
end
- }
+ end
end
def self.new_by_name(tree, name, *ids)
- TreeTagID_TBL.mutex.synchronize{
- unless (obj = TreeTagID_TBL[tree.path][name])
- (obj = self.allocate).instance_eval{
- initialize(tree, name, ids)
- TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
- TreeTagID_TBL[@tpath][@id] = self
- }
- end
- obj
- }
+ if (obj = TreeTagID_TBL[tree.path][name])
+ return obj
+ end
+ new([tree, name], ids)
end
def self.new(tree, *ids)
- TreeTagID_TBL.mutex.synchronize{
- (obj = self.allocate).instance_eval{
- if tree.kind_of?(Array)
- initialize(tree[0], tree[1], ids)
- else
- initialize(tree, nil, ids)
- end
- TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
- TreeTagID_TBL[@tpath][@id] = self
- }
- obj
- }
+ if tree.kind_of?(Array)
+ super(tree[0], tree[1], ids)
+ else
+ super(tree, nil, ids)
+ end
end
def initialize(tree, name, ids)
@@ -1218,12 +1091,13 @@ class Tk::BLT::Treeview::Tag < TkObject
if name
@path = @id = name
else
- TreeTag_ID.mutex.synchronize{
- @path = @id = TreeTag_ID.join(TkCore::INTERP._ip_id_).freeze
- TreeTag_ID[1].succ!
- }
+ @path = @id = TreeTag_ID.join(TkCore::INTERP._ip_id_).freeze
+ TreeTag_ID[1].succ!
end
+ TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
+ TreeTagID_TBL[@tpath][@id] = self
+
unless ids.empty?
tk_call(@tpath, 'tag', 'add', @id, *(ids.collect{|id| tagid(id)}))
end
diff --git a/ext/tk/lib/tkextlib/blt/unix_dnd.rb b/ext/tk/lib/tkextlib/blt/unix_dnd.rb
index 445002d7a5..3130c1e56f 100644
--- a/ext/tk/lib/tkextlib/blt/unix_dnd.rb
+++ b/ext/tk/lib/tkextlib/blt/unix_dnd.rb
@@ -30,14 +30,11 @@ module Tk::BLT
end
private :__item_config_cmd
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
def cget(win, option)
- itemcget(['cget', win], option)
- end
- def cget_strict(win, option)
- itemcget_strict(['cget', win], option)
+ itemconfigure(['cget', win], slot, value)
end
def configure(win, slot, value=None)
itemconfigure(['configure', win], slot, value)
@@ -49,11 +46,8 @@ module Tk::BLT
current_itemconfiginfo(['configure', win], slot)
end
- def token_cget(win, option)
- itemcget(['token', 'cget', win], option)
- end
- def token_cget_strict(win, option)
- itemcget_strict(['token', 'cget', win], option)
+ def tokwn_cget(win, option)
+ itemconfigure(['token', 'cget', win], slot, value)
end
def token_configure(win, slot, value=None)
itemconfigure(['token', 'configure', win], slot, value)
diff --git a/ext/tk/lib/tkextlib/blt/vector.rb b/ext/tk/lib/tkextlib/blt/vector.rb
index 76c12a24e8..540b6b9102 100644
--- a/ext/tk/lib/tkextlib/blt/vector.rb
+++ b/ext/tk/lib/tkextlib/blt/vector.rb
@@ -23,17 +23,14 @@ module Tk::BLT
end
def self.names(pat=None)
- list = simplelist(tk_call('::blt::vector', 'names', pat))
- TkVar_ID_TBL.mutex.synchronize{
- list.collect{|name|
- if TkVar_ID_TBL[name]
- TkVar_ID_TBL[name]
- elsif name[0..1] == '::' && TkVar_ID_TBL[name[2..-1]]
- TkVar_ID_TBL[name[2..-1]]
- else
- name
- end
- }
+ simplelist(tk_call('::blt::vector', 'names', pat)).collect{|name|
+ if TkVar_ID_TBL[name]
+ TkVar_ID_TBL[name]
+ elsif name[0..1] == '::' && TkVar_ID_TBL[name[2..-1]]
+ TkVar_ID_TBL[name[2..-1]]
+ else
+ name
+ end
}
end
@@ -56,9 +53,7 @@ module Tk::BLT
"#auto", *hash_kv(keys))
end
- TkVar_ID_TBL.mutex.synchronize{
- TkVar_ID_TBL[@id] = self
- }
+ TkVar_ID_TBL[@id] = self
@def_default = false
@default_val = nil
@@ -226,21 +221,13 @@ module Tk::BLT
class VectorAccess < Vector
def self.new(name)
- TkVar_ID_TBL.mutex.synchronize{
- if TkVar_ID_TBL[name]
- TkVar_ID_TBL[name]
- else
- (obj = self.allocate).instance_eval{
- initialize(name)
- TkVar_ID_TBL[@id] = self
- }
- obj
- end
- }
+ return TkVar_ID_TBL[name] if TkVar_ID_TBL[name]
+ super(name, size=nil, keys={})
end
def initialize(vec_name)
@id = vec_name
+ TkVar_ID_TBL[@id] = self
@def_default = false
@default_val = nil
diff --git a/ext/tk/lib/tkextlib/blt/watch.rb b/ext/tk/lib/tkextlib/blt/watch.rb
index 219ff78e97..ae5e50f126 100644
--- a/ext/tk/lib/tkextlib/blt/watch.rb
+++ b/ext/tk/lib/tkextlib/blt/watch.rb
@@ -13,23 +13,11 @@ module Tk::BLT
TkCommandNames = ['::blt::watch'.freeze].freeze
WATCH_ID_TBL = TkCore::INTERP.create_table
-
- (BLT_WATCH_ID = ['blt_watch_id'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- WATCH_ID_TBL.mutex.synchronize{ WATCH_ID_TBL.clear }
- }
+ BLT_WATCH_ID = ['blt_watch_id'.freeze, '00000'.taint].freeze
def self.names(state = None)
- lst = tk_split_list(tk_call('::blt::watch', 'names', state))
- WATCH_ID_TBL.mutex.synchronize{
- lst.collect{|name|
- WATCH_ID_TBL[name] || name
- }
+ tk_split_list(tk_call('::blt::watch', 'names', state)).collect{|name|
+ WATCH_ID_TBL[name] || name
}
end
@@ -57,17 +45,13 @@ module Tk::BLT
if name
@id = name.to_s
else
- BLT_WATCH_ID.mutex.synchronize{
- @id = BLT_WATCH_ID.join(TkCore::INTERP._ip_id_)
- BLT_WATCH_ID[1].succ!
- }
+ @id = BLT_WATCH_ID.join(TkCore::INTERP._ip_id_)
+ BLT_WATCH_ID[1].succ!
end
@path = @id
- WATCH_ID_TBL.mutex.synchronize{
- WATCH_ID_TBL[@id] = self
- }
+ WATCH_ID_TBL[@id] = self
tk_call('::blt::watch', 'create', @id, *hash_kv(keys))
end
@@ -146,7 +130,7 @@ module Tk::BLT
end
end
end
- def cget_strict(key)
+ def cget(key)
key = key.to_s
begin
info.assoc(key)[1]
@@ -154,22 +138,5 @@ module Tk::BLT
fail ArgumentError, "unknown option '#{key}'"
end
end
- def cget(key)
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- cget_strict(key)
- else
- begin
- cget_strict(key)
- rescue => e
- if current_configinfo.has_key?(key.to_s)
- # error on known option
- fail e
- else
- # unknown option
- nil
- end
- end
- end
- end
end
end
diff --git a/ext/tk/lib/tkextlib/bwidget/button.rb b/ext/tk/lib/tkextlib/bwidget/button.rb
index 8f3087d098..4a9d4a7948 100644
--- a/ext/tk/lib/tkextlib/bwidget/button.rb
+++ b/ext/tk/lib/tkextlib/bwidget/button.rb
@@ -9,7 +9,7 @@ require 'tkextlib/bwidget.rb'
module Tk
module BWidget
- class Button < Tk::Button
+ class Button < TkButton
end
end
end
diff --git a/ext/tk/lib/tkextlib/bwidget/buttonbox.rb b/ext/tk/lib/tkextlib/bwidget/buttonbox.rb
index 8d6d212189..ef999239f9 100644
--- a/ext/tk/lib/tkextlib/bwidget/buttonbox.rb
+++ b/ext/tk/lib/tkextlib/bwidget/buttonbox.rb
@@ -31,7 +31,7 @@ class Tk::BWidget::ButtonBox
name = tagOrId[:name]
return index(name) unless name.empty?
end
- if tagOrId.kind_of?(Tk::Button)
+ if tagOrId.kind_of?(TkButton)
return index(tagOrId[:text])
end
# index(tagOrId.to_s)
@@ -40,13 +40,7 @@ class Tk::BWidget::ButtonBox
def add(keys={}, &b)
win = window(tk_send('add', *hash_kv(keys)))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
@@ -60,7 +54,7 @@ class Tk::BWidget::ButtonBox
name = idx[:name]
idx = name unless name.empty?
end
- if idx.kind_of?(Tk::Button)
+ if idx.kind_of?(TkButton)
idx = idx[:text]
end
number(tk_send('index', idx.to_s))
@@ -68,13 +62,7 @@ class Tk::BWidget::ButtonBox
def insert(idx, keys={}, &b)
win = window(tk_send('insert', tagid(idx), *hash_kv(keys)))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
diff --git a/ext/tk/lib/tkextlib/bwidget/combobox.rb b/ext/tk/lib/tkextlib/bwidget/combobox.rb
index 1c58a4ccb0..31f71c3aaf 100644
--- a/ext/tk/lib/tkextlib/bwidget/combobox.rb
+++ b/ext/tk/lib/tkextlib/bwidget/combobox.rb
@@ -25,13 +25,7 @@ class Tk::BWidget::ComboBox
def get_listbox(&b)
win = window(tk_send_without_enc('getlistbox'))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
diff --git a/ext/tk/lib/tkextlib/bwidget/dialog.rb b/ext/tk/lib/tkextlib/bwidget/dialog.rb
index 291ca4a962..2790d88d24 100644
--- a/ext/tk/lib/tkextlib/bwidget/dialog.rb
+++ b/ext/tk/lib/tkextlib/bwidget/dialog.rb
@@ -59,13 +59,6 @@ class Tk::BWidget::Dialog
end
end
- def cget_strict(slot)
- if slot.to_s == 'relative'
- super('parent')
- else
- super(slot)
- end
- end
def cget(slot)
if slot.to_s == 'relative'
super('parent')
@@ -110,7 +103,7 @@ class Tk::BWidget::Dialog
name = tagOrId[:name]
return index(name) unless name.empty?
end
- if tagOrId.kind_of?(Tk::Button)
+ if tagOrId.kind_of?(TkButton)
return index(tagOrId[:text])
end
# index(tagOrId.to_s)
@@ -119,37 +112,19 @@ class Tk::BWidget::Dialog
def add(keys={}, &b)
win = window(tk_send('add', *hash_kv(keys)))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
def get_frame(&b)
win = window(tk_send('getframe'))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
def get_buttonbox(&b)
win = window(@path + '.bbox')
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
diff --git a/ext/tk/lib/tkextlib/bwidget/dynamichelp.rb b/ext/tk/lib/tkextlib/bwidget/dynamichelp.rb
index 846e58062d..224304f2ab 100644
--- a/ext/tk/lib/tkextlib/bwidget/dynamichelp.rb
+++ b/ext/tk/lib/tkextlib/bwidget/dynamichelp.rb
@@ -34,13 +34,6 @@ module Tk::BWidget::DynamicHelp
['DynamicHelp::configure']
end
- def self.cget_strict(slot)
- slot = slot.to_s
- info = {}
- self.current_configinfo.each{|k,v| info[k.to_s] = v if k.to_s == slot}
- fail RuntimeError, "unknown option \"-#{slot}\"" if info.empty?
- info.values[0]
- end
def self.cget(slot)
self.current_configinfo(slot).values[0]
end
diff --git a/ext/tk/lib/tkextlib/bwidget/entry.rb b/ext/tk/lib/tkextlib/bwidget/entry.rb
index a56890f4e3..aafb4aa7ff 100644
--- a/ext/tk/lib/tkextlib/bwidget/entry.rb
+++ b/ext/tk/lib/tkextlib/bwidget/entry.rb
@@ -9,7 +9,7 @@ require 'tkextlib/bwidget.rb'
module Tk
module BWidget
- class Entry < Tk::Entry
+ class Entry < TkEntry
end
end
end
diff --git a/ext/tk/lib/tkextlib/bwidget/label.rb b/ext/tk/lib/tkextlib/bwidget/label.rb
index 88a504aa50..ce10ecaf8b 100644
--- a/ext/tk/lib/tkextlib/bwidget/label.rb
+++ b/ext/tk/lib/tkextlib/bwidget/label.rb
@@ -9,7 +9,7 @@ require 'tkextlib/bwidget.rb'
module Tk
module BWidget
- class Label < Tk::Label
+ class Label < TkLabel
end
end
end
diff --git a/ext/tk/lib/tkextlib/bwidget/labelentry.rb b/ext/tk/lib/tkextlib/bwidget/labelentry.rb
index 95b40946a6..931feb9b48 100644
--- a/ext/tk/lib/tkextlib/bwidget/labelentry.rb
+++ b/ext/tk/lib/tkextlib/bwidget/labelentry.rb
@@ -11,7 +11,7 @@ require 'tkextlib/bwidget/entry'
module Tk
module BWidget
- class LabelEntry < Tk::Entry
+ class LabelEntry < TkEntry
end
end
end
diff --git a/ext/tk/lib/tkextlib/bwidget/labelframe.rb b/ext/tk/lib/tkextlib/bwidget/labelframe.rb
index dc221806e4..f7b267eebb 100644
--- a/ext/tk/lib/tkextlib/bwidget/labelframe.rb
+++ b/ext/tk/lib/tkextlib/bwidget/labelframe.rb
@@ -40,13 +40,7 @@ class Tk::BWidget::LabelFrame
end
def get_frame(&b)
win = window(tk_send_without_enc('getframe'))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
end
diff --git a/ext/tk/lib/tkextlib/bwidget/listbox.rb b/ext/tk/lib/tkextlib/bwidget/listbox.rb
index 093fcb6fb3..1267500661 100644
--- a/ext/tk/lib/tkextlib/bwidget/listbox.rb
+++ b/ext/tk/lib/tkextlib/bwidget/listbox.rb
@@ -211,26 +211,14 @@ class Tk::BWidget::ListBox::Item
include TkTreatTagFont
ListItem_TBL = TkCore::INTERP.create_table
+ ListItem_ID = ['bw:item'.freeze, '00000'.taint].freeze
- (ListItem_ID = ['bw:item'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- ListItem_TBL.mutex.synchronize{ ListItem_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ ListItem_TBL.clear }
def self.id2obj(lbox, id)
lpath = lbox.path
- ListItem_TBL.mutex.synchronize{
- if ListItem_TBL[lpath]
- ListItem_TBL[lpath][id]? ListItem_TBL[lpath][id]: id
- else
- id
- end
- }
+ return id unless ListItem_TBL[lpath]
+ ListItem_TBL[lpath][id]? ListItem_TBL[lpath][id]: id
end
def initialize(lbox, *args)
@@ -262,17 +250,13 @@ class Tk::BWidget::ListBox::Item
if keys.key?('itemname')
@path = @id = keys.delete('itemname')
else
- ListItem_ID.mutex.synchronize{
- @path = @id = ListItem_ID.join(TkCore::INTERP._ip_id_)
- ListItem_ID[1].succ!
- }
+ @path = @id = ListItem_ID.join(TkCore::INTERP._ip_id_)
+ ListItem_ID[1].succ!
end
- ListItem_TBL.mutex.synchronize{
- ListItem_TBL[@id] = self
- ListItem_TBL[@lpath] = {} unless ListItem_TBL[@lpath]
- ListItem_TBL[@lpath][@id] = self
- }
+ ListItem_TBL[@id] = self
+ ListItem_TBL[@lpath] = {} unless ListItem_TBL[@lpath]
+ ListItem_TBL[@lpath][@id] = self
@listbox.insert(index, @id, keys)
end
@@ -297,9 +281,6 @@ class Tk::BWidget::ListBox::Item
def cget(key)
@listbox.itemcget(@id, key)
end
- def cget_strict(key)
- @listbox.itemcget_strict(@id, key)
- end
def configure(key, val=None)
@listbox.itemconfigure(@id, key, val)
diff --git a/ext/tk/lib/tkextlib/bwidget/mainframe.rb b/ext/tk/lib/tkextlib/bwidget/mainframe.rb
index de66eaf81e..c54e878557 100644
--- a/ext/tk/lib/tkextlib/bwidget/mainframe.rb
+++ b/ext/tk/lib/tkextlib/bwidget/mainframe.rb
@@ -41,73 +41,37 @@ class Tk::BWidget::MainFrame
def add_indicator(keys={}, &b)
win = window(tk_send('addindicator', *hash_kv(keys)))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
def add_toolbar(&b)
win = window(tk_send('addtoolbar'))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
def get_frame(&b)
win = window(tk_send('getframe'))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
def get_indicator(idx, &b)
win = window(tk_send('getindicator', idx))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
def get_menu(menu_id, &b)
win = window(tk_send('getmenu', menu_id))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
def get_toolbar(idx, &b)
win = window(tk_send('gettoolbar', idx))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
diff --git a/ext/tk/lib/tkextlib/bwidget/messagedlg.rb b/ext/tk/lib/tkextlib/bwidget/messagedlg.rb
index b88461baf7..9c946d0630 100644
--- a/ext/tk/lib/tkextlib/bwidget/messagedlg.rb
+++ b/ext/tk/lib/tkextlib/bwidget/messagedlg.rb
@@ -65,17 +65,6 @@ class Tk::BWidget::MessageDlg
end
@keys[slot]
end
- def cget_strict(slot)
- slot = slot.to_s
- if slot == 'relative'
- slot = 'parent'
- end
- if winfo_exist?
- val = super(slot)
- @keys[slot] = val
- end
- @keys[slot]
- end
def configure(slot, value=None)
if winfo_exist?
@@ -184,9 +173,6 @@ class Tk::BWidget::MessageDlg
end
def create
- # return the index of the pressed button, or nil if it is destroyed
- ret = num_or_str(tk_call(self.class::TkCommandNames[0],
- @path, *hash_kv(@keys)))
- (ret < 0)? nil: ret
+ num_or_str(tk_call(self.class::TkCommandNames[0], @path, *hash_kv(@keys)))
end
end
diff --git a/ext/tk/lib/tkextlib/bwidget/notebook.rb b/ext/tk/lib/tkextlib/bwidget/notebook.rb
index 423943619c..5146d4915d 100644
--- a/ext/tk/lib/tkextlib/bwidget/notebook.rb
+++ b/ext/tk/lib/tkextlib/bwidget/notebook.rb
@@ -89,13 +89,7 @@ class Tk::BWidget::NoteBook
def add(page, &b)
win = window(tk_send('add', tagid(page)))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
@@ -111,13 +105,7 @@ class Tk::BWidget::NoteBook
def get_frame(page, &b)
win = window(tk_send('getframe', tagid(page)))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
@@ -127,13 +115,7 @@ class Tk::BWidget::NoteBook
def insert(index, page, keys={}, &b)
win = window(tk_send('insert', index, tagid(page), *hash_kv(keys)))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
diff --git a/ext/tk/lib/tkextlib/bwidget/pagesmanager.rb b/ext/tk/lib/tkextlib/bwidget/pagesmanager.rb
index fbc2c11255..fc01284be6 100644
--- a/ext/tk/lib/tkextlib/bwidget/pagesmanager.rb
+++ b/ext/tk/lib/tkextlib/bwidget/pagesmanager.rb
@@ -26,13 +26,7 @@ class Tk::BWidget::PagesManager
def add(page, &b)
win = window(tk_send('add', tagid(page)))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
@@ -48,13 +42,7 @@ class Tk::BWidget::PagesManager
def get_frame(page, &b)
win = window(tk_send('getframe', tagid(page)))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
diff --git a/ext/tk/lib/tkextlib/bwidget/panedwindow.rb b/ext/tk/lib/tkextlib/bwidget/panedwindow.rb
index 4d979fd523..19982c6095 100644
--- a/ext/tk/lib/tkextlib/bwidget/panedwindow.rb
+++ b/ext/tk/lib/tkextlib/bwidget/panedwindow.rb
@@ -25,13 +25,7 @@ class Tk::BWidget::PanedWindow
def get_frame(idx, &b)
win = window(tk_send_without_enc('getframe', idx))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
end
diff --git a/ext/tk/lib/tkextlib/bwidget/panelframe.rb b/ext/tk/lib/tkextlib/bwidget/panelframe.rb
index 84bae0768b..13f8817d74 100644
--- a/ext/tk/lib/tkextlib/bwidget/panelframe.rb
+++ b/ext/tk/lib/tkextlib/bwidget/panelframe.rb
@@ -36,13 +36,7 @@ class Tk::BWidget::PanelFrame
def get_frame(&b)
win = window(tk_send_without_enc('getframe'))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
diff --git a/ext/tk/lib/tkextlib/bwidget/progressdlg.rb b/ext/tk/lib/tkextlib/bwidget/progressdlg.rb
index 32600255d5..fbf00f3b00 100644
--- a/ext/tk/lib/tkextlib/bwidget/progressdlg.rb
+++ b/ext/tk/lib/tkextlib/bwidget/progressdlg.rb
@@ -51,8 +51,4 @@ class Tk::BWidget::ProgressDlg
def value= (val)
@keys['variable'].value = val
end
-
- def create
- window(tk_call(self.class::TkCommandNames[0], @path, *hash_kv(@keys)))
- end
end
diff --git a/ext/tk/lib/tkextlib/bwidget/scrollableframe.rb b/ext/tk/lib/tkextlib/bwidget/scrollableframe.rb
index 010c960ec5..a3986681a5 100644
--- a/ext/tk/lib/tkextlib/bwidget/scrollableframe.rb
+++ b/ext/tk/lib/tkextlib/bwidget/scrollableframe.rb
@@ -23,13 +23,7 @@ class Tk::BWidget::ScrollableFrame
def get_frame(&b)
win = window(tk_send_without_enc('getframe'))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
diff --git a/ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb b/ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb
index 3599fd8459..e9e53235b7 100644
--- a/ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb
+++ b/ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb
@@ -21,13 +21,7 @@ class Tk::BWidget::ScrolledWindow
def get_frame(&b)
win = window(tk_send_without_enc('getframe'))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
diff --git a/ext/tk/lib/tkextlib/bwidget/selectcolor.rb b/ext/tk/lib/tkextlib/bwidget/selectcolor.rb
index 0f9014f8de..742a84cd84 100644
--- a/ext/tk/lib/tkextlib/bwidget/selectcolor.rb
+++ b/ext/tk/lib/tkextlib/bwidget/selectcolor.rb
@@ -10,11 +10,6 @@ require 'tkextlib/bwidget/messagedlg'
module Tk
module BWidget
class SelectColor < Tk::BWidget::MessageDlg
- class Dialog < Tk::BWidget::SelectColor
- end
- class Menubutton < Tk::Menubutton
- end
- MenuButton = Menubutton
end
end
end
@@ -48,26 +43,3 @@ class Tk::BWidget::SelectColor
tk_call('SelectColor::setcolor', idx, color)
end
end
-
-class Tk::BWidget::SelectColor::Dialog
- def create_self(keys)
- super(keys)
- @keys['type'] = 'dialog'
- end
-
- def create
- @keys['type'] = 'dialog' # 'dialog' type returns color
- tk_call(Tk::BWidget::SelectColor::TkCommandNames[0],
- @path, *hash_kv(@keys))
- end
-end
-
-class Tk::BWidget::SelectColor::Menubutton
- def create_self(keys)
- keys = {} unless keys
- keys = _symbolkey2str(keys)
- keys['type'] = 'menubutton' # 'toolbar' type returns widget path
- window(tk_call(Tk::BWidget::SelectColor::TkCommandNames[0],
- @path, *hash_kv(keys)))
- end
-end
diff --git a/ext/tk/lib/tkextlib/bwidget/selectfont.rb b/ext/tk/lib/tkextlib/bwidget/selectfont.rb
index e53eb3b5bc..478787602a 100644
--- a/ext/tk/lib/tkextlib/bwidget/selectfont.rb
+++ b/ext/tk/lib/tkextlib/bwidget/selectfont.rb
@@ -66,7 +66,7 @@ class Tk::BWidget::SelectFont::Dialog
end
def create
- @keys['type'] = 'dialog' # 'dialog' type returns font name
+ @keys['type'] = 'dialog'
tk_call(Tk::BWidget::SelectFont::TkCommandNames[0], @path, *hash_kv(@keys))
end
end
@@ -79,8 +79,7 @@ class Tk::BWidget::SelectFont::Toolbar
def create_self(keys)
keys = {} unless keys
keys = _symbolkey2str(keys)
- keys['type'] = 'toolbar' # 'toolbar' type returns widget path
- window(tk_call(Tk::BWidget::SelectFont::TkCommandNames[0],
- @path, *hash_kv(keys)))
+ keys['type'] = 'toolbar'
+ tk_call(Tk::BWidget::SelectFont::TkCommandNames[0], @path, *hash_kv(keys))
end
end
diff --git a/ext/tk/lib/tkextlib/bwidget/spinbox.rb b/ext/tk/lib/tkextlib/bwidget/spinbox.rb
index 48358baa5c..ca4c046e5c 100644
--- a/ext/tk/lib/tkextlib/bwidget/spinbox.rb
+++ b/ext/tk/lib/tkextlib/bwidget/spinbox.rb
@@ -10,7 +10,7 @@ require 'tkextlib/bwidget/entry'
module Tk
module BWidget
- class SpinBox < Tk::Entry
+ class SpinBox < TkEntry
end
end
end
diff --git a/ext/tk/lib/tkextlib/bwidget/statusbar.rb b/ext/tk/lib/tkextlib/bwidget/statusbar.rb
index 39c678d37e..df16e4c0b7 100644
--- a/ext/tk/lib/tkextlib/bwidget/statusbar.rb
+++ b/ext/tk/lib/tkextlib/bwidget/statusbar.rb
@@ -36,13 +36,7 @@ class Tk::BWidget::StatusBar
def get_frame(&b)
win = window(tk_send_without_enc('getframe'))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
diff --git a/ext/tk/lib/tkextlib/bwidget/titleframe.rb b/ext/tk/lib/tkextlib/bwidget/titleframe.rb
index 68534e66e9..f519490430 100644
--- a/ext/tk/lib/tkextlib/bwidget/titleframe.rb
+++ b/ext/tk/lib/tkextlib/bwidget/titleframe.rb
@@ -21,13 +21,7 @@ class Tk::BWidget::TitleFrame
def get_frame(&b)
win = window(tk_send_without_enc('getframe'))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
end
diff --git a/ext/tk/lib/tkextlib/bwidget/tree.rb b/ext/tk/lib/tkextlib/bwidget/tree.rb
index aed4512a73..e7178debe2 100644
--- a/ext/tk/lib/tkextlib/bwidget/tree.rb
+++ b/ext/tk/lib/tkextlib/bwidget/tree.rb
@@ -263,26 +263,14 @@ class Tk::BWidget::Tree::Node
include TkTreatTagFont
TreeNode_TBL = TkCore::INTERP.create_table
+ TreeNode_ID = ['bw:node'.freeze, '00000'.taint].freeze
- (TreeNode_ID = ['bw:node'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- TreeNode_TBL.mutex.synchronize{ TreeNode_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ TreeNode_TBL.clear }
def self.id2obj(tree, id)
tpath = tree.path
- TreeNode_TBL.mutex.synchronize{
- if TreeNode_TBL[tpath]
- TreeNode_TBL[tpath][id]? TreeNode_TBL[tpath][id]: id
- else
- id
- end
- }
+ return id unless TreeNode_TBL[tpath]
+ TreeNode_TBL[tpath][id]? TreeNode_TBL[tpath][id]: id
end
def initialize(tree, *args)
@@ -323,17 +311,13 @@ class Tk::BWidget::Tree::Node
if keys.key?('nodename')
@path = @id = keys.delete('nodename')
else
- TreeNode_ID.mutex.synchronize{
- @path = @id = TreeNode_ID.join(TkCore::INTERP._ip_id_)
- TreeNode_ID[1].succ!
- }
+ @path = @id = TreeNode_ID.join(TkCore::INTERP._ip_id_)
+ TreeNode_ID[1].succ!
end
- TreeNode_TBL.mutex.synchronize{
- TreeNode_TBL[@id] = self
- TreeNode_TBL[@tpath] = {} unless TreeNode_TBL[@tpath]
- TreeNode_TBL[@tpath][@id] = self
- }
+ TreeNode_TBL[@id] = self
+ TreeNode_TBL[@tpath] = {} unless TreeNode_TBL[@tpath]
+ TreeNode_TBL[@tpath][@id] = self
@tree.insert(index, parent, @id, keys)
end
@@ -358,9 +342,6 @@ class Tk::BWidget::Tree::Node
def cget(key)
@tree.itemcget(@id, key)
end
- def cget_strict(key)
- @tree.itemcget_strict(@id, key)
- end
def configure(key, val=None)
@tree.itemconfigure(@id, key, val)
diff --git a/ext/tk/lib/tkextlib/bwidget/widget.rb b/ext/tk/lib/tkextlib/bwidget/widget.rb
index a93364b567..568e503a8b 100644
--- a/ext/tk/lib/tkextlib/bwidget/widget.rb
+++ b/ext/tk/lib/tkextlib/bwidget/widget.rb
@@ -29,13 +29,6 @@ module Tk::BWidget::Widget
['Widget::configure']
end
- def self.cget_strict(slot)
- slot = slot.to_s
- info = {}
- self.current_configinfo.each{|k,v| info[k.to_s] = v if k.to_s == slot}
- fail RuntimeError, "unknown option \"-#{slot}\"" if info.empty?
- info.values[0]
- end
def self.cget(slot)
self.current_configinfo(slot).values[0]
end
@@ -50,13 +43,7 @@ module Tk::BWidget::Widget
def self.create(klass, path, rename=None, &b)
win = window(tk_call('Widget::create', klass, path, rename))
- if b
- if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- win.instance_exec(self, &b)
- else
- win.instance_eval(&b)
- end
- end
+ win.instance_eval(&b) if b
win
end
@@ -112,11 +99,8 @@ module Tk::BWidget::Widget
tk_call('Widget::setoption', win, option, value)
end
- def self.sub_cget_strict(win, subwidget)
- tk_call('Widget::subcget', win, subwidget)
- end
def self.sub_cget(win, subwidget)
- self.sub_cget_strict(win, subwidget)
+ tk_call('Widget::subcget', win, subwidget)
end
def self.sync_options(klass, subclass, subpath, options)
diff --git a/ext/tk/lib/tkextlib/itcl/incr_tcl.rb b/ext/tk/lib/tkextlib/itcl/incr_tcl.rb
index 2b75d62eb9..07abf3a7bf 100644
--- a/ext/tk/lib/tkextlib/itcl/incr_tcl.rb
+++ b/ext/tk/lib/tkextlib/itcl/incr_tcl.rb
@@ -40,22 +40,16 @@ module Tk
class ItclObject < TkObject
ITCL_CLASSNAME = ''.freeze
- (ITCL_OBJ_ID = ['itclobj'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
+ ITCL_OBJ_ID = ['itclobj'.freeze, '00000'.taint].freeze
ITCL_OBJ_TBL = {}.taint
def initialize(*args)
if (@klass = self.class::ITCL_CLASSNAME).empty?
fail RuntimeError, 'unknown itcl class (abstract class?)'
end
- Tk::Itcl::ItclObject::ITCL_OBJ_ID.mutex.synchronize{
- @id = Tk::Itcl::ItclObject::TCL_OBJ_ID.join(TkCore::INTERP._ip_id_)
- Tk::Itcl::ItclObject::ITCL_OBJ_ID[1].succ!
- }
+ @id = Tk::Itcl::ItclObject::TCL_OBJ_ID.join(TkCore::INTERP._ip_id_)
@path = @id
+ Tk::Itcl::ItclObject::ITCL_OBJ_ID[1].succ!
end
def self.call_proc(name, *args)
diff --git a/ext/tk/lib/tkextlib/itk/incr_tk.rb b/ext/tk/lib/tkextlib/itk/incr_tk.rb
index e06deb552c..0626536e36 100644
--- a/ext/tk/lib/tkextlib/itk/incr_tk.rb
+++ b/ext/tk/lib/tkextlib/itk/incr_tk.rb
@@ -145,16 +145,9 @@ module Tk
private :__config_cmd
ComponentID_TBL = TkCore::INTERP.create_table
+ Itk_Component_ID = ['itk:component'.freeze, '00000'.taint].freeze
- (Itk_Component_ID = ['itk:component'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- ComponentID_TBL.mutex.synchronize{ ComponentID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ ComponentID_TBL.clear }
def self.id2obj(master, id)
if master.kind_of?(TkObject)
@@ -162,13 +155,8 @@ module Tk
else
master = master.to_s
end
- ComponentID_TBL.mutex.synchronize{
- if ComponentID_TBL.key?(master)
- (ComponentID_TBL[master].key?(id))? ComponentID_TBL[master][id]: id
- else
- id
- end
- }
+ return id unless ComponentID_TBL.key?(master)
+ (ComponentID_TBL.key?(id))? ComponentID_TBL[master][id]: id
end
def self.new(master, component=nil)
@@ -183,21 +171,17 @@ module Tk
elsif component
component = component.to_s
else
- Itk_Component_ID.mutex.synchronize{
- component = Itk_Component_ID.join(TkCore::INTERP._ip_id_)
- Itk_Component_ID[1].succ!
- }
+ component = Itk_Component_ID.join(TkCore::INTERP._ip_id_)
+ Itk_Component_ID[1].succ!
end
- ComponentID_TBL.mutex.synchronize{
- if ComponentID_TBL.key?(master)
- if ComponentID_TBL[master].key?(component)
- return ComponentID_TBL[master][component]
- end
- else
- ComponentID_TBL[master] = {}
+ if ComponentID_TBL.key?(master)
+ if ComponentID_TBL[master].key?(component)
+ return ComponentID_TBL[master][component]
end
- }
+ else
+ ComponentID_TBL[master] = {}
+ end
super(master, component)
end
@@ -206,9 +190,7 @@ module Tk
@master = master
@component = component
- ComponentID_TBL.mutex.synchronize{
- ComponentID_TBL[@master][@component] = self
- }
+ ComponentID_TBL[@master][@component] = self
begin
@widget = window(tk_call(@master, 'component', @component))
diff --git a/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb b/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb
index 05d58c386f..a055e07ac9 100644
--- a/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb
@@ -47,13 +47,12 @@ class Tk::Iwidgets::Buttonbox
end
alias buttoncget itemcget
- alias buttoncget_strict itemcget_strict
alias buttonconfigure itemconfigure
alias buttonconfiginfo itemconfiginfo
alias current_buttonconfiginfo current_itemconfiginfo
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
####################################
diff --git a/ext/tk/lib/tkextlib/iwidgets/calendar.rb b/ext/tk/lib/tkextlib/iwidgets/calendar.rb
index 8495f0e29b..0152f8593a 100644
--- a/ext/tk/lib/tkextlib/iwidgets/calendar.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/calendar.rb
@@ -45,25 +45,6 @@ class Tk::Iwidgets::Calendar
class ValidateArgs < TkUtil::CallbackSubst
KEY_TBL = [ [?d, ?s, :date], nil ]
PROC_TBL = [ [?s, TkComm.method(:string) ], nil ]
-
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
diff --git a/ext/tk/lib/tkextlib/iwidgets/checkbox.rb b/ext/tk/lib/tkextlib/iwidgets/checkbox.rb
index c85d356c55..46ca389db2 100644
--- a/ext/tk/lib/tkextlib/iwidgets/checkbox.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/checkbox.rb
@@ -47,13 +47,12 @@ class Tk::Iwidgets::Checkbox
end
alias buttoncget itemcget
- alias buttoncget_strict itemcget_strict
alias buttonconfigure itemconfigure
alias buttonconfiginfo itemconfiginfo
alias current_buttonconfiginfo current_itemconfiginfo
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
####################################
@@ -86,24 +85,12 @@ class Tk::Iwidgets::Checkbox
self
end
- def get_tags
- simplelist(tk_call_without_enc(@path, 'get'))
- end
-
- def get_objs
- simplelist(tk_call_without_enc(@path, 'get')).collect{|id|
+ def get(idx)
+ simplelist(tk_call(@path, 'get', index(idx))).collect{|id|
Tk::Itk::Component.id2obj(self, id)
}
end
- def get(idx=nil)
- if idx
- bool(tk_call_without_enc(@path, 'get', index(idx)))
- else
- get_tags
- end
- end
-
def index(idx)
number(tk_call(@path, 'index', tagid(idx)))
end
diff --git a/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb b/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb
index 8d43cc07ab..d6c668621d 100644
--- a/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb
@@ -47,13 +47,12 @@ class Tk::Iwidgets::Dialogshell
end
alias buttoncget itemcget
- alias buttoncget_strict itemcget_strict
alias buttonconfigure itemconfigure
alias buttonconfiginfo itemconfiginfo
alias current_buttonconfiginfo current_itemconfiginfo
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
####################################
diff --git a/ext/tk/lib/tkextlib/iwidgets/entryfield.rb b/ext/tk/lib/tkextlib/iwidgets/entryfield.rb
index d53df216bf..6aa933ce06 100644
--- a/ext/tk/lib/tkextlib/iwidgets/entryfield.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/entryfield.rb
@@ -42,25 +42,6 @@ class Tk::Iwidgets::Entryfield
[ ?w, TkComm.method(:window) ],
nil
]
-
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
end
diff --git a/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb b/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb
index d9220fecbf..4cc6aeecbd 100644
--- a/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb
@@ -30,25 +30,6 @@ class Tk::Iwidgets::Hierarchy
class ValidateArgs < TkUtil::CallbackSubst
KEY_TBL = [ [?n, ?s, :node], nil ]
PROC_TBL = [ [?s, TkComm.method(:string) ], nil ]
-
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@@ -76,24 +57,6 @@ class Tk::Iwidgets::Hierarchy
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@@ -115,25 +78,6 @@ class Tk::Iwidgets::Hierarchy
nil
]
PROC_TBL = [ [ ?s, TkComm.method(:string) ], nil ]
-
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@@ -263,7 +207,7 @@ class Tk::Iwidgets::Hierarchy
self
end
- # based on Tk::Text widget
+ # based on TkText widget
def bbox(index)
list(tk_send_without_enc('bbox', _get_eval_enc_str(index)))
diff --git a/ext/tk/lib/tkextlib/iwidgets/menubar.rb b/ext/tk/lib/tkextlib/iwidgets/menubar.rb
index 5aaefbe50d..dea3d34c2a 100644
--- a/ext/tk/lib/tkextlib/iwidgets/menubar.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/menubar.rb
@@ -62,13 +62,12 @@ class Tk::Iwidgets::Menubar
end
alias menucget itemcget
- alias menucget_strict itemcget_strict
alias menuconfigure itemconfigure
alias menuconfiginfo itemconfiginfo
alias current_menuconfiginfo current_itemconfiginfo
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
####################################
diff --git a/ext/tk/lib/tkextlib/iwidgets/messagebox.rb b/ext/tk/lib/tkextlib/iwidgets/messagebox.rb
index 98ac32900c..2bbbec7666 100644
--- a/ext/tk/lib/tkextlib/iwidgets/messagebox.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/messagebox.rb
@@ -47,13 +47,12 @@ class Tk::Iwidgets::Messagebox
private :__item_boolval_optkeys
alias typecget itemcget
- alias typecget_strict itemcget_strict
alias typeconfigure itemconfigure
alias typeconfiginfo itemconfiginfo
alias current_typeconfiginfo current_itemconfiginfo
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
####################################
diff --git a/ext/tk/lib/tkextlib/iwidgets/notebook.rb b/ext/tk/lib/tkextlib/iwidgets/notebook.rb
index 03b50633df..0f9d713ea1 100644
--- a/ext/tk/lib/tkextlib/iwidgets/notebook.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/notebook.rb
@@ -42,13 +42,12 @@ class Tk::Iwidgets::Notebook
end
alias pagecget itemcget
- alias pagecget_strict itemcget_strict
alias pageconfigure itemconfigure
alias pageconfiginfo itemconfiginfo
alias current_pageconfiginfo current_itemconfiginfo
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
####################################
@@ -147,12 +146,7 @@ class Tk::Iwidgets::Notebook
def view(*idxs)
if idxs.size == 0
- idx = num_or_str(tk_send_without_enc('view'))
- if idx.kind_of?(Fixnum) && idx < 0
- nil
- else
- idx
- end
+ window(tk_send_without_enc('view'))
else
tk_send_without_enc('view', *idxs)
self
@@ -166,8 +160,8 @@ class Tk::Iwidgets::Notebook
end
alias xview_moveto view_moveto
alias yview_moveto view_moveto
- def view_scroll(index, what='pages')
- view('scroll', index, what)
+ def view_scroll(*idxs)
+ view('scroll', *idxs)
end
alias xview_scroll view_scroll
alias yview_scroll view_scroll
diff --git a/ext/tk/lib/tkextlib/iwidgets/panedwindow.rb b/ext/tk/lib/tkextlib/iwidgets/panedwindow.rb
index 3bf73d69fe..035df0a5b8 100644
--- a/ext/tk/lib/tkextlib/iwidgets/panedwindow.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/panedwindow.rb
@@ -42,13 +42,12 @@ class Tk::Iwidgets::Panedwindow
end
alias panecget itemcget
- alias panecget_strict itemcget_strict
alias paneconfigure itemconfigure
alias paneconfiginfo itemconfiginfo
alias current_paneconfiginfo current_itemconfiginfo
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
####################################
diff --git a/ext/tk/lib/tkextlib/iwidgets/radiobox.rb b/ext/tk/lib/tkextlib/iwidgets/radiobox.rb
index e9d9521252..1a2821bd6a 100644
--- a/ext/tk/lib/tkextlib/iwidgets/radiobox.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/radiobox.rb
@@ -47,13 +47,12 @@ class Tk::Iwidgets::Radiobox
end
alias buttoncget itemcget
- alias buttoncget_strict itemcget_strict
alias buttonconfigure itemconfigure
alias buttonconfiginfo itemconfiginfo
alias current_buttonconfiginfo current_itemconfiginfo
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
####################################
@@ -86,13 +85,10 @@ class Tk::Iwidgets::Radiobox
self
end
- def get_tag
- ((tag = tk_call_without_enc(@path, 'get')).empty?)? nil: tag
- end
- alias get get_tag
-
- def get_obj
- (tag = get_tag)? Tk::Itk::Component.id2obj(self, tag): nil
+ def get(idx)
+ simplelist(tk_call(@path, 'get', index(idx))).collect{|id|
+ Tk::Itk::Component.id2obj(self, id)
+ }
end
def index(idx)
diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb
index 67ad67d07e..407c8f2aad 100644
--- a/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb
@@ -37,7 +37,7 @@ class Tk::Iwidgets::Scrolledcanvas
end
def method_missing(id, *args)
- if @canvas.respond_to?(id)
+ if @canvas.methods.include?(id.id2name)
@canvas.__send__(id, *args)
else
super(id, *args)
@@ -171,16 +171,10 @@ class Tk::Iwidgets::Scrolledcanvas
end
def delete(*args)
- tbl = nil
- TkcItem::CItemID_TBL.mutex.synchronize{
- tbl = TkcItem::CItemID_TBL[self.path]
- }
- if tbl
+ if TkcItem::CItemID_TBL[self.path]
find('withtag', *args).each{|item|
if item.kind_of?(TkcItem)
- TkcItem::CItemID_TBL.mutex.synchronize{
- tbl.delete(item.id)
- }
+ TkcItem::CItemID_TBL[self.path].delete(item.id)
end
}
end
diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb
index 7543d557e3..cd1f6f0f79 100644
--- a/ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb
@@ -42,7 +42,7 @@ class Tk::Iwidgets::Scrolledlistbox
end
def method_missing(id, *args)
- if @listbox.respond_to?(id)
+ if @listbox.methods.include?(id.id2name)
@listbox.__send__(id, *args)
else
super(id, *args)
diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb
index d6436d202a..fdafc8dc7f 100644
--- a/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb
@@ -37,7 +37,7 @@ class Tk::Iwidgets::Scrolledtext
end
def method_missing(id, *args)
- if @text.respond_to?(id)
+ if @text.methods.include?(id.id2name)
@text.__send__(id, *args)
else
super(id, *args)
@@ -116,7 +116,7 @@ class Tk::Iwidgets::Scrolledtext
get('-displaychars', *index)
end
- def image_cget_strict(index, slot)
+ def image_cget(index, slot)
case slot.to_s
when 'text', 'label', 'show', 'data', 'file'
_fromUTF8(tk_send_without_enc('image', 'cget',
@@ -127,27 +127,6 @@ class Tk::Iwidgets::Scrolledtext
"-#{slot}")))
end
end
- def image_cget(index, slot)
- unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- image_cget_strict(index, slot)
- else
- begin
- image_cget_strict(index, slot)
- rescue => e
- begin
- if current_image_configinfo.has_key?(slot.to_s)
- # error on known option
- fail e
- else
- # unknown option
- nil
- end
- rescue
- fail e # tag error
- end
- end
- end
- end
def image_configure(index, slot, value=None)
if slot.kind_of? Hash
@@ -343,11 +322,6 @@ class Tk::Iwidgets::Scrolledtext
def _ktext_length(txt)
- if TkCore::WITH_ENCODING ### Ruby 1.9 !!!!!!!!!!!!!
- return txt.length
- end
- ###########################
-
if $KCODE !~ /n/i
return txt.gsub(/[^\Wa-zA-Z_\d]/, ' ').length
end
diff --git a/ext/tk/lib/tkextlib/iwidgets/selectionbox.rb b/ext/tk/lib/tkextlib/iwidgets/selectionbox.rb
index bf9b5ec30a..bb81fcca5e 100644
--- a/ext/tk/lib/tkextlib/iwidgets/selectionbox.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/selectionbox.rb
@@ -59,7 +59,7 @@ class Tk::Iwidgets::Selectionbox
self
end
- # based on Tk::Listbox ( and TkTextWin )
+ # based on TkListbox ( and TkTextWin )
def curselection
list(tk_send_without_enc('curselection'))
end
diff --git a/ext/tk/lib/tkextlib/iwidgets/selectiondialog.rb b/ext/tk/lib/tkextlib/iwidgets/selectiondialog.rb
index f772ecf8c2..ab790e97a6 100644
--- a/ext/tk/lib/tkextlib/iwidgets/selectiondialog.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/selectiondialog.rb
@@ -49,7 +49,7 @@ class Tk::Iwidgets::Selectiondialog
self
end
- # based on Tk::Listbox ( and TkTextWin )
+ # based on TkListbox ( and TkTextWin )
def curselection
list(tk_send_without_enc('curselection'))
end
diff --git a/ext/tk/lib/tkextlib/iwidgets/spinner.rb b/ext/tk/lib/tkextlib/iwidgets/spinner.rb
index aeee5c9038..174b9bd506 100644
--- a/ext/tk/lib/tkextlib/iwidgets/spinner.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/spinner.rb
@@ -37,25 +37,6 @@ class Tk::Iwidgets::Spinner
[ ?w, TkComm.method(:window) ],
nil
]
-
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
end
diff --git a/ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb b/ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb
index dbb90e5102..0d9715f87b 100644
--- a/ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb
@@ -47,13 +47,12 @@ class Tk::Iwidgets::Tabnotebook
end
alias pagecget itemcget
- alias pagecget_strict itemcget_strict
alias pageconfigure itemconfigure
alias pageconfiginfo itemconfiginfo
alias current_pageconfiginfo current_itemconfiginfo
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
####################################
@@ -117,11 +116,6 @@ class Tk::Iwidgets::Tabnotebook
self
end
- def show_tab(idx)
- @tabset.show_tab(idx)
- self
- end
-
def scrollcommand(cmd=Proc.new)
configure_cmd 'scrollcommand', cmd
self
@@ -153,12 +147,7 @@ class Tk::Iwidgets::Tabnotebook
def view(*index)
if index.size == 0
- idx = num_or_str(tk_send_without_enc('view'))
- if idx.kind_of?(Fixnum) && idx < 0
- nil
- else
- idx
- end
+ window(tk_send_without_enc('view'))
else
tk_send_without_enc('view', *index)
self
@@ -172,8 +161,8 @@ class Tk::Iwidgets::Tabnotebook
end
alias xview_moveto view_moveto
alias yview_moveto view_moveto
- def view_scroll(index, what='pages')
- view('scroll', index, what)
+ def view_scroll(*index)
+ view('scroll', *index)
end
alias xview_scroll view_scroll
alias yview_scroll view_scroll
diff --git a/ext/tk/lib/tkextlib/iwidgets/tabset.rb b/ext/tk/lib/tkextlib/iwidgets/tabset.rb
index 300ba9dee0..54e56d0514 100644
--- a/ext/tk/lib/tkextlib/iwidgets/tabset.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/tabset.rb
@@ -42,13 +42,12 @@ class Tk::Iwidgets::Tabset
end
alias tabcget itemcget
- alias tabcget_strict itemcget_strict
alias tabconfigure itemconfigure
alias tabconfiginfo itemconfiginfo
alias current_tabconfiginfo current_itemconfiginfo
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
####################################
@@ -97,48 +96,4 @@ class Tk::Iwidgets::Tabset
tk_call(@path, 'select', index(idx))
self
end
-
- def show_tab(idx)
- if index(idx) == 0
- self.start = 0
- return
- end
-
- reutrn unless @canvas ||= self.winfo_children[0]
-
- delta = 1 if (delta = cget(:gap)) == 'overlap' ||
- (delta = self.winfo_pixels(delta) + 1) <= 0
-
- case cget(:tabpos)
- when 's', 'n'
- if (head = tabcget(idx, :left)) < 0
- self.start -= head
- return
- end
- tabs_size = @canvas.winfo_width
- tab_start, tab_end = @canvas .
- find_overlapping(head, 0, head + delta, @canvas.winfo_height) .
- find_all{|id| @canvas.itemtype(id) == TkcPolygon} .
- map!{|id| bbox = @canvas.bbox(id); [bbox[0], bbox[2]]} . max
-
- when 'e', 'w'
- if (head = tabcget(idx, :top)) < 0
- self.start -= head
- return
- end
- tabs_size = @canvas.winfo_height
- tab_start, tab_end = @canvas .
- find_overlapping(0, head, @canvas.winfo_width, head + delta) .
- find_all{|id| @canvas.itemtype(id) == TkcPolygon} .
- map!{|id| bbox = @canvas.bbox(id); [bbox[1], bbox[3]]} . max
- end
-
- if (size = tab_end - tab_start + 1) > tabs_size
- self.start -= tab_start
- elsif head + size > tabs_size
- self.start -= head + size - tabs_size
- end
-
- self
- end
end
diff --git a/ext/tk/lib/tkextlib/tcllib/autoscroll.rb b/ext/tk/lib/tkextlib/tcllib/autoscroll.rb
index 7db3c2e2b7..6940a9174c 100644
--- a/ext/tk/lib/tkextlib/tcllib/autoscroll.rb
+++ b/ext/tk/lib/tkextlib/tcllib/autoscroll.rb
@@ -108,7 +108,7 @@ module Tk
end
end
-class Tk::Scrollbar
+class TkScrollbar
def autoscroll
# Arranges for the already existing scrollbar to be mapped
# and unmapped as needed.
diff --git a/ext/tk/lib/tkextlib/tcllib/ctext.rb b/ext/tk/lib/tkextlib/tcllib/ctext.rb
index 9014037f3d..70a45dd8e7 100644
--- a/ext/tk/lib/tkextlib/tcllib/ctext.rb
+++ b/ext/tk/lib/tkextlib/tcllib/ctext.rb
@@ -15,7 +15,7 @@ TkPackage.require('ctext')
module Tk
module Tcllib
- class CText < Tk::Text
+ class CText < TkText
PACKAGE_NAME = 'ctext'.freeze
def self.package_name
PACKAGE_NAME
diff --git a/ext/tk/lib/tkextlib/tcllib/datefield.rb b/ext/tk/lib/tkextlib/tcllib/datefield.rb
index 2244dd7a9a..bd84488101 100644
--- a/ext/tk/lib/tkextlib/tcllib/datefield.rb
+++ b/ext/tk/lib/tkextlib/tcllib/datefield.rb
@@ -24,7 +24,7 @@ TkPackage.require('datefield')
module Tk
module Tcllib
- class Datefield < Tk::Entry
+ class Datefield < TkEntry
PACKAGE_NAME = 'datefield'.freeze
def self.package_name
PACKAGE_NAME
diff --git a/ext/tk/lib/tkextlib/tcllib/getstring.rb b/ext/tk/lib/tkextlib/tcllib/getstring.rb
index fc5d8b26d9..bf5e54e8cf 100644
--- a/ext/tk/lib/tkextlib/tcllib/getstring.rb
+++ b/ext/tk/lib/tkextlib/tcllib/getstring.rb
@@ -87,7 +87,7 @@ class Tk::Tcllib::GetString_Dialog
@variable.value
end
- def cget_strict(slot)
+ def cget(slot)
slot = slot.to_s
if slot == 'text'
@text
@@ -95,9 +95,6 @@ class Tk::Tcllib::GetString_Dialog
@keys[slot]
end
end
- def cget(slot)
- cget_strict(slot)
- end
def configure(slot, value=None)
if slot.kind_of?(Hash)
diff --git a/ext/tk/lib/tkextlib/tcllib/ico.rb b/ext/tk/lib/tkextlib/tcllib/ico.rb
index 8c92926a4c..3beeb11a4d 100644
--- a/ext/tk/lib/tkextlib/tcllib/ico.rb
+++ b/ext/tk/lib/tkextlib/tcllib/ico.rb
@@ -94,10 +94,8 @@ class Tk::Tcllib::ICO
if keys.key?('name')
@path = keys['name'].to_s
else
- Tk_Image_ID.mutex.synchronize{
- @path = Tk_Image_ID.join(TkCore::INTERP._ip_id_)
- Tk_Image_ID[1].succ!
- }
+ @path = Tk_Image_ID.join(TkCore::INTERP._ip_id_)
+ Tk_Image_ID[1].succ!
end
tk_call_without_enc('::ico::getIcon', file, index, '-name', @path,
'-format', 'image', *hash_kv(keys, true))
diff --git a/ext/tk/lib/tkextlib/tcllib/ip_entry.rb b/ext/tk/lib/tkextlib/tcllib/ip_entry.rb
index c4b8240c04..8c9e0bd683 100644
--- a/ext/tk/lib/tkextlib/tcllib/ip_entry.rb
+++ b/ext/tk/lib/tkextlib/tcllib/ip_entry.rb
@@ -18,7 +18,7 @@ TkPackage.require('ipentry')
module Tk
module Tcllib
- class IP_Entry < Tk::Entry
+ class IP_Entry < TkEntry
PACKAGE_NAME = 'ipentry'.freeze
def self.package_name
PACKAGE_NAME
diff --git a/ext/tk/lib/tkextlib/tcllib/plotchart.rb b/ext/tk/lib/tkextlib/tcllib/plotchart.rb
index 06ab20f3e6..f5f344ceb3 100644
--- a/ext/tk/lib/tkextlib/tcllib/plotchart.rb
+++ b/ext/tk/lib/tkextlib/tcllib/plotchart.rb
@@ -225,7 +225,7 @@ module Tk::Tcllib::Plotchart
end
############################
- class XYPlot < Tk::Canvas
+ class XYPlot < TkCanvas
include ChartMethod
TkCommandNames = [
@@ -247,7 +247,7 @@ module Tk::Tcllib::Plotchart
@xaxis = args.shift
@yaxis = args.shift
- if parent.kind_of?(Tk::Canvas)
+ if parent.kind_of?(TkCanvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
@@ -265,9 +265,7 @@ module Tk::Tcllib::Plotchart
private :_create_chart
def __destroy_hook__
- Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.mutex.synchronize{
- Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path)
- }
+ Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path)
end
def plot(series, x, y)
@@ -339,7 +337,7 @@ module Tk::Tcllib::Plotchart
end
############################
- class PolarPlot < Tk::Canvas
+ class PolarPlot < TkCanvas
include ChartMethod
TkCommandNames = [
@@ -358,7 +356,7 @@ module Tk::Tcllib::Plotchart
@radius_data = args.shift
- if parent.kind_of?(Tk::Canvas)
+ if parent.kind_of?(TkCanvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
@@ -376,9 +374,7 @@ module Tk::Tcllib::Plotchart
private :_create_chart
def __destroy_hook__
- Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.mutex.synchronize{
- Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path)
- }
+ Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path)
end
def plot(series, radius, angle)
@@ -399,7 +395,7 @@ module Tk::Tcllib::Plotchart
Polarplot = PolarPlot
############################
- class IsometricPlot < Tk::Canvas
+ class IsometricPlot < TkCanvas
include ChartMethod
TkCommandNames = [
@@ -434,7 +430,7 @@ module Tk::Tcllib::Plotchart
@stepsize = args.shift
end
- if parent.kind_of?(Tk::Canvas)
+ if parent.kind_of?(TkCanvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
@@ -479,7 +475,7 @@ module Tk::Tcllib::Plotchart
Isometricplot = IsometricPlot
############################
- class Plot3D < Tk::Canvas
+ class Plot3D < TkCanvas
include ChartMethod
TkCommandNames = [
@@ -504,7 +500,7 @@ module Tk::Tcllib::Plotchart
@yaxis = args.shift
@zaxis = args.shift
- if parent.kind_of?(Tk::Canvas)
+ if parent.kind_of?(TkCanvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
@@ -561,7 +557,7 @@ module Tk::Tcllib::Plotchart
end
############################
- class Piechart < Tk::Canvas
+ class Piechart < TkCanvas
include ChartMethod
TkCommandNames = [
@@ -570,7 +566,7 @@ module Tk::Tcllib::Plotchart
].freeze
def initialize(*args) # args := ([parent] [, keys])
- if args[0].kind_of?(Tk::Canvas)
+ if args[0].kind_of?(TkCanvas)
parent = args.shift
@path = parent.path
else
@@ -592,7 +588,7 @@ module Tk::Tcllib::Plotchart
end
############################
- class Barchart < Tk::Canvas
+ class Barchart < TkCanvas
include ChartMethod
TkCommandNames = [
@@ -630,7 +626,7 @@ module Tk::Tcllib::Plotchart
@series_size = args.shift
end
- if parent.kind_of?(Tk::Canvas)
+ if parent.kind_of?(TkCanvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
@@ -649,9 +645,7 @@ module Tk::Tcllib::Plotchart
private :_create_chart
def __destroy_hook__
- Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.mutex.synchronize{
- Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path)
- }
+ Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path)
end
def plot(series, dat, col=None)
@@ -678,7 +672,7 @@ module Tk::Tcllib::Plotchart
end
############################
- class Timechart < Tk::Canvas
+ class Timechart < TkCanvas
include ChartMethod
TkCommandNames = [
@@ -705,7 +699,7 @@ module Tk::Tcllib::Plotchart
@time_end = args.shift
@items = args.shift
- if parent.kind_of?(Tk::Canvas)
+ if parent.kind_of?(TkCanvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
@@ -739,7 +733,7 @@ module Tk::Tcllib::Plotchart
end
############################
- class Gnattchart < Tk::Canvas
+ class Gnattchart < TkCanvas
include ChartMethod
TkCommandNames = [
@@ -778,7 +772,7 @@ module Tk::Tcllib::Plotchart
@text_width = None
end
- if parent.kind_of?(Tk::Canvas)
+ if parent.kind_of?(TkCanvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
@@ -840,38 +834,23 @@ module Tk::Tcllib::Plotchart
############################
class PlotSeries < TkObject
SeriesID_TBL = TkCore::INTERP.create_table
-
- (Series_ID = ['series'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
- TkCore::INTERP.init_ip_env{
- SeriesID_TBL.mutex.synchronize{ SeriesID_TBL.clear }
- }
+ Series_ID = ['series'.freeze, '00000'.taint].freeze
+ TkCore::INTERP.init_ip_env{ SeriesID_TBL.clear }
def self.id2obj(chart, id)
path = chart.path
- SeriesID_TBL.mutex.synchronize{
- if SeriesID_TBL[path]
- SeriesID_TBL[path][id]? SeriesID_TBL[path][id]: id
- else
- id
- end
- }
+ return id unless SeriesID_TBL[path]
+ SeriesID_TBL[path][id]? SeriesID_TBL[path][id]: id
end
def initialize(chart, keys=nil)
@parent = @chart_obj = chart
@ppath = @chart_obj.path
- Series_ID.mutex.synchronize{
- @path = @series = @id = Series_ID.join(TkCore::INTERP._ip_id_)
- Series_ID[1].succ!
- }
- SeriesID_TBL.mutex.synchronize{
- SeriesID_TBL[@ppath] ||= {}
- SeriesID_TBL[@ppath][@id] = self
- }
+ @path = @series = @id = Series_ID.join(TkCore::INTERP._ip_id_)
+ # SeriesID_TBL[@id] = self
+ SeriesID_TBL[@ppath] = {} unless SeriesID_TBL[@ppath]
+ SeriesID_TBL[@ppath][@id] = self
+ Series_ID[1].succ!
dataconfig(keys) if keys.kind_of?(Hash)
end
diff --git a/ext/tk/lib/tkextlib/tcllib/swaplist.rb b/ext/tk/lib/tkextlib/tcllib/swaplist.rb
index 1c813e36da..97de0a27c1 100644
--- a/ext/tk/lib/tkextlib/tcllib/swaplist.rb
+++ b/ext/tk/lib/tkextlib/tcllib/swaplist.rb
@@ -90,7 +90,7 @@ class Tk::Tcllib::Swaplist_Dialog
end
alias selected value
- def cget_strict(slot)
+ def cget(slot)
slot = slot.to_s
if slot == 'complete_list'
@complete_list
@@ -100,9 +100,6 @@ class Tk::Tcllib::Swaplist_Dialog
@keys[slot]
end
end
- def cget(slot)
- cget_strict(slot)
- end
def configure(slot, value=None)
if slot.kind_of?(Hash)
diff --git a/ext/tk/lib/tkextlib/tcllib/tablelist_core.rb b/ext/tk/lib/tkextlib/tcllib/tablelist_core.rb
index d7a6c97210..a939a58331 100644
--- a/ext/tk/lib/tkextlib/tcllib/tablelist_core.rb
+++ b/ext/tk/lib/tkextlib/tcllib/tablelist_core.rb
@@ -70,9 +70,6 @@ module Tk::Tcllib::TablelistItemConfig
def cell_cget(tagOrId, option)
itemcget(['cell', tagOrId], option)
end
- def cell_cget_strict(tagOrId, option)
- itemcget_strict(['cell', tagOrId], option)
- end
def cell_configure(tagOrId, slot, value=None)
itemconfigure(['cell', tagOrId], slot, value)
end
@@ -83,7 +80,6 @@ module Tk::Tcllib::TablelistItemConfig
current_itemconfiginfo(['cell', tagOrId], slot)
end
alias cellcget cell_cget
- alias cellcget_strict cell_cget_strict
alias cellconfigure cell_configure
alias cellconfiginfo cell_configinfo
alias current_cellconfiginfo current_cell_configinfo
@@ -91,9 +87,6 @@ module Tk::Tcllib::TablelistItemConfig
def column_cget(tagOrId, option)
itemcget(['column', tagOrId], option)
end
- def column_cget_strict(tagOrId, option)
- itemcget_strict(['column', tagOrId], option)
- end
def column_configure(tagOrId, slot, value=None)
itemconfigure(['column', tagOrId], slot, value)
end
@@ -104,7 +97,6 @@ module Tk::Tcllib::TablelistItemConfig
current_itemconfiginfo(['column', tagOrId], slot)
end
alias columncget column_cget
- alias columncget_strict column_cget_strict
alias columnconfigure column_configure
alias columnconfiginfo column_configinfo
alias current_columnconfiginfo current_column_configinfo
@@ -112,9 +104,6 @@ module Tk::Tcllib::TablelistItemConfig
def row_cget(tagOrId, option)
itemcget(['row', tagOrId], option)
end
- def row_cget_strict(tagOrId, option)
- itemcget_strict(['row', tagOrId], option)
- end
def row_configure(tagOrId, slot, value=None)
itemconfigure(['row', tagOrId], slot, value)
end
@@ -125,13 +114,12 @@ module Tk::Tcllib::TablelistItemConfig
current_itemconfiginfo(['row', tagOrId], slot)
end
alias rowcget row_cget
- alias rowcget_strict row_cget_strict
alias rowconfigure row_configure
alias rowconfiginfo row_configinfo
alias current_rowconfiginfo current_row_configinfo
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
end
class Tk::Tcllib::Tablelist
diff --git a/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb b/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb
index b366e0198b..92dde65ce7 100644
--- a/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb
+++ b/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb
@@ -125,9 +125,7 @@ module Tk::Tcllib::Tkpiechart
def delete
tk_call_without_enc('::stooop::delete', @tag_key)
- CItemID_TBL.mutex.synchronize{
- CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path]
- }
+ CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path]
self
end
@@ -186,10 +184,8 @@ module Tk::Tcllib::Tkpiechart
@id = "slices(#{@tag_key})"
@tag = TkcNamedTag.new(@pie.canvas, @id)
- CItemID_TBL.mutex.synchronize{
- CItemID_TBL[@path] = {} unless CItemID_TBL[@path]
- CItemID_TBL[@path][@id] = self
- }
+ CItemID_TBL[@path] = {} unless CItemID_TBL[@path]
+ CItemID_TBL[@path][@id] = self
end
def tag_key
@@ -204,9 +200,7 @@ module Tk::Tcllib::Tkpiechart
def delete
tk_call_without_enc('pie::deleteSlice', @pie.tag_key, @tag_key)
- CItemID_TBL.mutex.synchronize{
- CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path]
- }
+ CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path]
@pie._delete_slice(self)
self
end
diff --git a/ext/tk/lib/tkextlib/tile.rb b/ext/tk/lib/tkextlib/tile.rb
index 60ea012cc0..acc7bebe4e 100644
--- a/ext/tk/lib/tkextlib/tile.rb
+++ b/ext/tk/lib/tkextlib/tile.rb
@@ -4,7 +4,6 @@
#
require 'tk'
-require 'tk/ttk_selector'
# call setup script for general 'tkextlib' libraries
require 'tkextlib/setup.rb'
@@ -16,66 +15,33 @@ require 'tkextlib/tile/setup.rb'
# TkPackage.require('tile', '0.4')
# TkPackage.require('tile', '0.6')
# TkPackage.require('tile', '0.7')
-if Tk::TK_MAJOR_VERSION > 8 ||
- (Tk::TK_MAJOR_VERSION == 8 && Tk::TK_MINOR_VERSION >= 5)
- TkPackage.require('tile') # for compatibility (version check of 'tile')
- verstr = TkPackage.require('Ttk')
-else
- verstr = TkPackage.require('tile')
-end
-
+verstr = TkPackage.require('tile')
ver = verstr.split('.')
-if ver[0].to_i == 0
- # Tile extension package
- if ver[1].to_i <= 4
- # version 0.4 or former
- module Tk
- module Tile
- USE_TILE_NAMESPACE = true
- USE_TTK_NAMESPACE = false
- TILE_SPEC_VERSION_ID = 0
- end
- end
- elsif ver[1].to_i <= 6
- # version 0.5 -- version 0.6
- module Tk
- module Tile
- USE_TILE_NAMESPACE = true
- USE_TTK_NAMESPACE = true
- TILE_SPEC_VERSION_ID = 5
- end
- end
- elsif ver[1].to_i <= 7
- module Tk
- module Tile
- USE_TILE_NAMESPACE = false
- USE_TTK_NAMESPACE = true
- TILE_SPEC_VERSION_ID = 7
- end
- end
- else
- # version 0.8 or later
- module Tk
- module Tile
- USE_TILE_NAMESPACE = false
- USE_TTK_NAMESPACE = true
- TILE_SPEC_VERSION_ID = 8
- end
+if ver[0].to_i == 0 && ver[1].to_i <= 4
+ # version 0.4 or former
+ module Tk
+ module Tile
+ USE_TILE_NAMESPACE = true
+ USE_TTK_NAMESPACE = false
+ TILE_SPEC_VERSION_ID = 0
end
end
-
- module Tk::Tile
- PACKAGE_NAME = 'tile'.freeze
+elsif ver[0].to_i == 0 && ver[1].to_i <= 6
+ # version 0.5 -- version 0.6
+ module Tk
+ module Tile
+ USE_TILE_NAMESPACE = true
+ USE_TTK_NAMESPACE = true
+ TILE_SPEC_VERSION_ID = 5
+ end
end
else
- # Ttk package merged Tcl/Tk core (Tcl/Tk 8.5+)
+ # version 0.7 or later
module Tk
module Tile
USE_TILE_NAMESPACE = false
USE_TTK_NAMESPACE = true
- TILE_SPEC_VERSION_ID = 8
-
- PACKAGE_NAME = 'Ttk'.freeze
+ TILE_SPEC_VERSION_ID = 7
end
end
end
@@ -85,114 +51,30 @@ module Tk
module Tile
TkComm::TkExtlibAutoloadModule.unshift(self)
+ PACKAGE_NAME = 'tile'.freeze
def self.package_name
PACKAGE_NAME
end
def self.package_version
begin
- TkPackage.require(PACKAGE_NAME)
+ TkPackage.require('tile')
rescue
''
end
end
def self.__Import_Tile_Widgets__!
- warn 'Warning: "Tk::Tile::__Import_Tile_Widgets__!" is obsolete.' <<
- ' To control default widget set, use "Tk.default_widget_set = :Ttk"'
Tk.tk_call('namespace', 'import', '-force', 'ttk::*')
end
- def self.__define_LoadImages_proc_for_compatibility__!
- # Ttk 8.5 (Tile 0.8) lost 'LoadImages' utility procedure.
- # So, some old scripts doen't work, because those scripts use the
- # procedure to define local styles.
- # Of course, rewriting such Tcl/Tk scripts isn't difficult for
- # Tcl/Tk users. However, it may be troublesome for Ruby/Tk users
- # who use such Tcl/Tk scripts as it is.
- # This method may help Ruby/Tk users who don't want to modify old
- # Tcl/Tk scripts for the latest version of Ttk (Tile) extension.
- # This method defines a comaptible 'LoadImages' procedure on the
- # Tcl/Tk interpreter working under Ruby/Tk.
- # Please give attention to use this method. It may conflict with
- # some definitions on Tcl/Tk scripts.
- klass_name = self.name
- proc_name = 'LoadImages'
- if Tk::Tile::USE_TTK_NAMESPACE
- ns_list = ['::tile']
- if Tk.info(:commands, "::ttk::#{proc_name}").empty?
- ns_list << '::ttk'
- end
- else # Tk::Tile::USE_TILE_NAMESPACE
- ns_list = ['::ttk']
- if Tk.info(:commands, "::tile::#{proc_name}").empty?
- ns_list << '::tile'
- end
- end
-
- ns_list.each{|ns|
- cmd = "#{ns}::#{proc_name}"
- unless Tk.info(:commands, cmd).empty?
- #fail RuntimeError, "can't define '#{cmd}' command (already exist)"
-
- # do nothing !!!
- warn "Warning: can't define '#{cmd}' command (already exist)" if $DEBUG
- next
- end
- TkNamespace.eval(ns){
- TkCore::INTERP.add_tk_procs(proc_name, 'imgdir {patterns {*.gif}}',
- <<-'EOS')
- foreach pattern $patterns {
- foreach file [glob -directory $imgdir $pattern] {
- set img [file tail [file rootname $file]]
- if {![info exists images($img)]} {
- set images($img) [image create photo -file $file]
- }
- }
- }
- return [array get images]
- EOS
- }
+ def self.load_images(imgdir, pat=TkComm::None)
+ images = Hash[*TkComm.simplelist(Tk.tk_call('::tile::LoadImages',
+ imgdir, pat))]
+ images.keys.each{|k|
+ images[k] = TkPhotoImage.new(:imagename=>images[k],
+ :without_creating=>true)
}
- end
-
- def self.load_images(imgdir, pat=nil)
- if Tk::Tile::TILE_SPEC_VERSION_ID < 8
- if Tk::Tile::USE_TTK_NAMESPACE
- cmd = '::ttk::LoadImages'
- else # Tk::Tile::USE_TILE_NAMESPACE
- cmd = '::tile::LoadImages'
- end
- pat ||= TkComm::None
- images = Hash[*TkComm.simplelist(Tk.tk_call(cmd, imgdir, pat))]
- images.keys.each{|k|
- images[k] = TkPhotoImage.new(:imagename=>images[k],
- :without_creating=>true)
- }
- else ## TILE_SPEC_VERSION_ID >= 8
- pat ||= '*.gif'
- if pat.kind_of?(Array)
- pat_list = pat
- else
- pat_list = [ pat ]
- end
- Dir.chdir(imgdir){
- pat_list.each{|pat|
- Dir.glob(pat).each{|f|
- img = File.basename(f, '.*')
- unless TkComm.bool(Tk.info('exists', "images(#{img})"))
- Tk.tk_call('set', "images(#{img})",
- Tk.tk_call('image', 'create', 'photo', '-file', f))
- end
- }
- }
- }
- images = Hash[*TkComm.simplelist(Tk.tk_call('array', 'get', 'images'))]
- images.keys.each{|k|
- images[k] = TkPhotoImage.new(:imagename=>images[k],
- :without_creating=>true)
- }
- end
images
end
@@ -201,53 +83,12 @@ module Tk
args.map!{|arg| TkComm._get_eval_string(arg)}.join('.')
end
- def self.themes(glob_ptn = nil)
- if TILE_SPEC_VERSION_ID < 8 && Tk.info(:commands, '::ttk::themes').empty?
- fail RuntimeError, 'not support glob option' if glob_ptn
- cmd = ['::tile::availableThemes']
- else
- glob_ptn = '*' unless glob_ptn
- cmd = ['::ttk::themes', glob_ptn]
- end
-
- begin
- TkComm.simplelist(Tk.tk_call_without_enc(*cmd))
- rescue
- TkComm.simplelist(Tk.tk_call('lsearch', '-all', '-inline',
- Tk::Tile::Style.theme_names,
- glob_ptn))
- end
- end
-
- def self.set_theme(theme)
- if TILE_SPEC_VERSION_ID < 8 && Tk.info(:commands, '::ttk::setTheme').empty?
- cmd = '::tile::setTheme'
- else
- cmd = '::ttk::setTheme'
- end
-
- begin
- Tk.tk_call_without_enc(cmd, theme)
- rescue
- Tk::Tile::Style.theme_use(theme)
- end
- end
-
module KeyNav
- if Tk::Tile::TILE_SPEC_VERSION_ID < 8
- def self.enableMnemonics(w)
- Tk.tk_call('::keynav::enableMnemonics', w)
- end
- def self.defaultButton(w)
- Tk.tk_call('::keynav::defaultButton', w)
- end
- else # dummy
- def self.enableMnemonics(w)
- ""
- end
- def self.defaultButton(w)
- ""
- end
+ def self.enableMnemonics(w)
+ Tk.tk_call('::keynav::enableMnemonics', w)
+ end
+ def self.defaultButton(w)
+ Tk.tk_call('::keynav::defaultButton', w)
end
end
@@ -262,12 +103,6 @@ module Tk
Menu = 'TkMenuFont'
SmallCaption = 'TkSmallCaptionFont'
Icon = 'TkIconFont'
-
- TkFont::SYSTEM_FONT_NAMES.add [
- 'TkDefaultFont', 'TkTextFont', 'TkHeadingFont',
- 'TkCaptionFont', 'TkTooltipFont', 'TkFixedFont',
- 'TkMenuFont', 'TkSmallCaptionFont', 'TkIconFont'
- ]
end
module ParseStyleLayout
@@ -306,7 +141,7 @@ module Tk
end
private :__val2ruby_optkeys
- def ttk_instate(state, script=nil, &b)
+ def instate(state, script=nil, &b)
if script
tk_send('instate', state, script)
elsif b
@@ -315,30 +150,19 @@ module Tk
bool(tk_send('instate', state))
end
end
- alias tile_instate ttk_instate
- def ttk_state(state=nil)
+ def state(state=nil)
if state
tk_send('state', state)
else
list(tk_send('state'))
end
end
- alias tile_state ttk_state
- def ttk_identify(x, y)
+ def identify(x, y)
ret = tk_send_without_enc('identify', x, y)
(ret.empty?)? nil: ret
end
- alias tile_identify ttk_identify
-
- # remove instate/state/identify method
- # to avoid the conflict with widget options
- if Tk.const_defined?(:USE_OBSOLETE_TILE_STATE_METHOD) && Tk::USE_OBSOLETE_TILE_STATE_METHOD
- alias instate ttk_instate
- alias state ttk_state
- alias identify ttk_identify
- end
end
######################################
@@ -364,24 +188,18 @@ module Tk
autoload :TLabelframe, 'tkextlib/tile/tlabelframe'
autoload :Labelframe, 'tkextlib/tile/tlabelframe'
- autoload :TLabelFrame, 'tkextlib/tile/tlabelframe'
- autoload :LabelFrame, 'tkextlib/tile/tlabelframe'
autoload :TLabel, 'tkextlib/tile/tlabel'
autoload :Label, 'tkextlib/tile/tlabel'
autoload :TMenubutton, 'tkextlib/tile/tmenubutton'
autoload :Menubutton, 'tkextlib/tile/tmenubutton'
- autoload :TMenuButton, 'tkextlib/tile/tmenubutton'
- autoload :MenuButton, 'tkextlib/tile/tmenubutton'
autoload :TNotebook, 'tkextlib/tile/tnotebook'
autoload :Notebook, 'tkextlib/tile/tnotebook'
autoload :TPaned, 'tkextlib/tile/tpaned'
autoload :Paned, 'tkextlib/tile/tpaned'
- autoload :PanedWindow, 'tkextlib/tile/tpaned'
- autoload :Panedwindow, 'tkextlib/tile/tpaned'
autoload :TProgressbar, 'tkextlib/tile/tprogressbar'
autoload :Progressbar, 'tkextlib/tile/tprogressbar'
@@ -398,8 +216,6 @@ module Tk
autoload :TScrollbar, 'tkextlib/tile/tscrollbar'
autoload :Scrollbar, 'tkextlib/tile/tscrollbar'
- autoload :XScrollbar, 'tkextlib/tile/tscrollbar'
- autoload :YScrollbar, 'tkextlib/tile/tscrollbar'
autoload :TSeparator, 'tkextlib/tile/tseparator'
autoload :Separator, 'tkextlib/tile/tseparator'
@@ -407,13 +223,8 @@ module Tk
autoload :TSquare, 'tkextlib/tile/tsquare'
autoload :Square, 'tkextlib/tile/tsquare'
- autoload :SizeGrip, 'tkextlib/tile/sizegrip'
- autoload :Sizegrip, 'tkextlib/tile/sizegrip'
-
autoload :Treeview, 'tkextlib/tile/treeview'
autoload :Style, 'tkextlib/tile/style'
end
end
-
-Ttk = Tk::Tile
diff --git a/ext/tk/lib/tkextlib/tile/dialog.rb b/ext/tk/lib/tkextlib/tile/dialog.rb
index ef2d1fe577..b10378d7de 100644
--- a/ext/tk/lib/tkextlib/tile/dialog.rb
+++ b/ext/tk/lib/tkextlib/tile/dialog.rb
@@ -54,21 +54,9 @@ class Tk::Tile::Dialog
window(tk_call_without_enc('::ttk::dialog::clientframe', @path))
end
- def cget_strict(slot)
- @keys[slot.to_s]
- end
- def cget(slot)
- @keys[slot.to_s]
- end
-=begin
def cget(slot)
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- cget_strict(slot)
- else
- cget_strict(slot) rescue nil
- end
+ @keys[slot]
end
-=end
def configure(slot, value=None)
if slot.kind_of?(Hash)
diff --git a/ext/tk/lib/tkextlib/tile/sizegrip.rb b/ext/tk/lib/tkextlib/tile/sizegrip.rb
index c5068919a4..ea796583b0 100644
--- a/ext/tk/lib/tkextlib/tile/sizegrip.rb
+++ b/ext/tk/lib/tkextlib/tile/sizegrip.rb
@@ -9,13 +9,9 @@ module Tk
module Tile
class SizeGrip < TkWindow
end
- Sizegrip = SizeGrip
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Sizegrip, :TkSizegrip, :TkSizeGrip)
-
-
class Tk::Tile::SizeGrip < TkWindow
include Tk::Tile::TileWidget
diff --git a/ext/tk/lib/tkextlib/tile/style.rb b/ext/tk/lib/tkextlib/tile/style.rb
index ca7ee99c32..59bc4b0d78 100644
--- a/ext/tk/lib/tkextlib/tile/style.rb
+++ b/ext/tk/lib/tkextlib/tile/style.rb
@@ -17,145 +17,6 @@ module Tk::Tile::Style
end
class << Tk::Tile::Style
- if Tk::Tile::TILE_SPEC_VERSION_ID < 8
- TkCommandNames = ['style'.freeze].freeze
-
- # --- Tk::Tile::Style.__define_wrapper_proc_for_compatibility__! ---
- # On Ttk (Tile) extension, 'style' command has imcompatible changes
- # depend on the version of the extention. It requires modifying the
- # Tcl/Tk scripts to define local styles. The rule for modification
- # is a simple one. But, if users want to keep compatibility between
- # versions of the extension, they will have to contrive to do that.
- # It may be troublesome, especially for Ruby/Tk users.
- # This method may help such work. This method make some definitions
- # on the Tcl/Tk interpreter to work with different version of style
- # command format. Please give attention to use this method. It may
- # conflict with some definitions on Tcl/Tk scripts.
- if Tk::Tile::TILE_SPEC_VERSION_ID < 7
- def __define_wrapper_proc_for_compatibility__!
- __define_themes_and_setTheme_proc__!
-
- unless Tk.info(:commands, '::ttk::style').empty?
- # fail RuntimeError,
- # "can't define '::ttk::style' command (already exist)"
-
- # do nothing !!!
- warn "Warning: can't define '::ttk::style' command (already exist)" if $DEBUG
- return
- end
- TkCore::INTERP.add_tk_procs('::ttk::style', 'args', <<-'EOS')
- if [string equal [lrange $args 0 1] {element create}] {
- if [string equal [lindex $args 3] image] {
- set spec [lindex $args 4]
- set map [lrange $spec 1 end]
- if [llength $map] {
- # return [eval [concat [list ::style element create [lindex $args 2] image [lindex $spec 0] -map $map] [lrange $args 5 end]]]
- return [uplevel 1 [list ::style element create [lindex $args 2] image [lindex $spec 0] -map $map] [lrange $args 5 end]]
- }
- }
- }
- # return [eval "::style $args"]
- return [uplevel 1 ::style $args]
- EOS
- #########################
- end
- else ### TILE_SPEC_VERSION_ID == 7
- def __define_wrapper_proc_for_compatibility__!
- __define_themes_and_setTheme_proc__!
-
- unless Tk.info(:commands, '::ttk::style').empty?
- # fail RuntimeError,
- # "can't define '::ttk::style' command (already exist)"
-
- # do nothing !!!
- warn "Warning: can't define '::ttk::style' command (already exist)" if $DEBUG
- return
- end
- TkCore::INTERP.add_tk_procs('::ttk::style', 'args', <<-'EOS')
- if [string equal [lrange $args 0 1] {element create}] {
- if [string equal [lindex $args 3] image] {
- set spec [lindex $args 4]
- set map [lrange $spec 1 end]
- if [llength $map] {
- # return [eval [concat [list ::style element create [lindex $args 2] image [lindex $spec 0] -map $map] [lrange $args 5 end]]]
- return [uplevel 1 [list ::style element create [lindex $args 2] image [lindex $spec 0] -map $map] [lrange $args 5 end]]]
- }
- }
- } elseif [string equal [lindex $args 0] default] {
- # return [eval "::style [lreplace $args 0 0 configure]"]
- return [uplevel 1 ::style [lreplace $args 0 0 configure]]
- }
- # return [eval "::style $args"]
- return [uplevel 1 ::style $args]
- EOS
- #########################
- end
- end
- else ### TILE_SPEC_VERSION_ID >= 8
- TkCommandNames = ['::ttk::style'.freeze].freeze
-
- def __define_wrapper_proc_for_compatibility__!
- __define_themes_and_setTheme_proc__!
-
- unless Tk.info(:commands, '::style').empty?
- # fail RuntimeError, "can't define '::style' command (already exist)"
-
- # do nothing !!!
- warn "Warning: can't define '::style' command (already exist)" if $DEBUG
- return
- end
- TkCore::INTERP.add_tk_procs('::style', 'args', <<-'EOS')
- if [string equal [lrange $args 0 1] {element create}] {
- if [string equal [lindex $args 3] image] {
- set name [lindex $args 4]
- set opts [lrange $args 5 end]
- set idx [lsearch $opts -map]
- if {$idx >= 0 && [expr $idx % 2 == 0]} {
- # return [eval [concat [list ::ttk::style element create [lindex $args 2] image [concat $name [lindex $opts [expr $idx + 1]]]] [lreplace $opts $idx [expr $idx + 1]]]]
- return [uplevel 1 [list ::ttk::style element create [lindex $args 2] image [concat $name [lindex $opts [expr $idx + 1]]]] [lreplace $opts $idx [expr $idx + 1]]]
- }
- }
- } elseif [string equal [lindex $args 0] default] {
- # return [eval "::ttk::style [lreplace $args 0 0 configure]"]
- return [uplevel 1 ::ttk::style [lreplace $args 0 0 configure]]
- }
- # return [eval "::ttk::style $args"]
- return [uplevel 1 ::ttk::style $args]
- EOS
- #########################
- end
- end
-
- def __define_themes_and_setTheme_proc__!
- TkCore::INTERP.add_tk_procs('::ttk::themes', '{ptn *}', <<-'EOS')
- #set themes [list]
- set themes [::ttk::style theme names]
- foreach pkg [lsearch -inline -all -glob [package names] ttk::theme::$ptn] {
- set theme [namespace tail $pkg]
- if {[lsearch -exact $themes $theme] < 0} {
- lappend themes $theme
- }
- }
- foreach pkg [lsearch -inline -all -glob [package names] tile::theme::$ptn] {
- set theme [namespace tail $pkg]
- if {[lsearch -exact $themes $theme] < 0} {
- lappend themes $theme
- }
- }
- return $themes
- EOS
- #########################
- TkCore::INTERP.add_tk_procs('::ttk::setTheme', 'theme', <<-'EOS')
- variable currentTheme
- if {[lsearch -exact [::ttk::style theme names] $theme] < 0} {
- package require [lsearch -inline -regexp [package names] (ttk|tile)::theme::$theme]
- }
- ::ttk::style theme use $theme
- set currentTheme $theme
- EOS
- end
- private :__define_themes_and_setTheme_proc__!
-
def configure(style=nil, keys=nil)
if style.kind_of?(Hash)
keys = style
@@ -170,9 +31,9 @@ class << Tk::Tile::Style
end
if keys && keys != None
- tk_call(TkCommandNames[0], sub_cmd, style, *hash_kv(keys))
+ tk_call('style', sub_cmd, style, *hash_kv(keys))
else
- tk_call(TkCommandNames[0], sub_cmd, style)
+ tk_call('style', sub_cmd, style)
end
end
alias default configure
@@ -185,33 +46,14 @@ class << Tk::Tile::Style
style = '.' unless style
if keys && keys != None
- if keys.kind_of?(Hash)
- tk_call(TkCommandNames[0], 'map', style, *hash_kv(keys))
- else
- simplelist(tk_call(TkCommandNames[0], 'map', style, '-' << keys.to_s))
- end
+ tk_call('style', 'map', style, *hash_kv(keys))
else
- ret = {}
- Hash[*(simplelist(tk_call(TkCommandNames[0], 'map', style)))].each{|k, v|
- ret[k[1..-1]] = list(v)
- }
- ret
+ tk_call('style', 'map', style)
end
end
- alias map_configure map
-
- def map_configinfo(style=nil, key=None)
- style = '.' unless style
- map(style, key)
- end
-
- def map_default_configinfo(key=None)
- map('.', key)
- end
def lookup(style, opt, state=None, fallback_value=None)
- tk_call(TkCommandNames[0], 'lookup', style,
- '-' << opt.to_s, state, fallback_value)
+ tk_call('style', 'lookup', style, '-' << opt.to_s, state, fallback_value)
end
include Tk::Tile::ParseStyleLayout
@@ -224,93 +66,42 @@ class << Tk::Tile::Style
style = '.' unless style
if spec
- tk_call(TkCommandNames[0], 'layout', style, spec)
+ tk_call('style', 'layout', style, spec)
else
- _style_layout(list(tk_call(TkCommandNames[0], 'layout', style)))
+ _style_layout(list(tk_call('style', 'layout', style)))
end
end
def element_create(name, type, *args)
- if type == 'image' || type == :image
- element_create_image(name, *args)
- else
- tk_call(TkCommandNames[0], 'element', 'create', name, type, *args)
- end
- end
-
- def element_create_image(name, *args)
- fail ArgumentError, 'Must supply a base image' unless (spec = args.shift)
- if (opts = args.shift)
- if opts.kind_of?(Hash)
- opts = _symbolkey2str(opts)
- else
- fail ArgumentError, 'bad option'
- end
- end
- fail ArgumentError, 'too many arguments' unless args.empty?
-
- if spec.kind_of?(Array)
- # probably, command format is tile 0.8+ (Tcl/Tk8.5+) style
- if Tk::Tile::TILE_SPEC_VERSION_ID >= 8
- if opts
- tk_call(TkCommandNames[0],
- 'element', 'create', name, 'image', spec, opts)
- else
- tk_call(TkCommandNames[0], 'element', 'create', name, 'image', spec)
- end
- else
- fail ArgumentError, 'illegal arguments' if opts.key?('map')
- base = spec.shift
- opts['map'] = spec
- tk_call(TkCommandNames[0],
- 'element', 'create', name, 'image', base, opts)
- end
- else
- # probably, command format is tile 0.7.8 or older style
- if Tk::Tile::TILE_SPEC_VERSION_ID >= 8
- spec = [spec, *(opts.delete('map'))] if opts.key?('map')
- end
- if opts
- tk_call(TkCommandNames[0],
- 'element', 'create', name, 'image', spec, opts)
- else
- tk_call(TkCommandNames[0], 'element', 'create', name, 'image', spec)
- end
- end
+ tk_call('style', 'element', 'create', name, type, *args)
end
def element_names()
- list(tk_call(TkCommandNames[0], 'element', 'names'))
+ list(tk_call('style', 'element', 'names'))
end
def element_options(elem)
- simplelist(tk_call(TkCommandNames[0], 'element', 'options', elem))
+ simplelist(tk_call('style', 'element', 'options', elem))
end
def theme_create(name, keys=nil)
- name = name.to_s
if keys && keys != None
- tk_call(TkCommandNames[0], 'theme', 'create', name, *hash_kv(keys))
+ tk_call('style', 'theme', 'create', name, *hash_kv(keys))
else
- tk_call(TkCommandNames[0], 'theme', 'create', name)
+ tk_call('style', 'theme', 'create', name)
end
- name
end
def theme_settings(name, cmd=nil, &b)
- name = name.to_s
cmd = Proc.new(&b) if !cmd && b
- tk_call(TkCommandNames[0], 'theme', 'settings', name, cmd)
- name
+ tk_call('style', 'theme', 'settings', name, cmd)
end
def theme_names()
- list(tk_call(TkCommandNames[0], 'theme', 'names'))
+ list(tk_call('style', 'theme', 'names'))
end
def theme_use(name)
- name = name.to_s
- tk_call(TkCommandNames[0], 'theme', 'use', name)
- name
+ tk_call('style', 'theme', 'use', name)
end
end
diff --git a/ext/tk/lib/tkextlib/tile/tbutton.rb b/ext/tk/lib/tkextlib/tile/tbutton.rb
index 5d7db10fe9..1142a27100 100644
--- a/ext/tk/lib/tkextlib/tile/tbutton.rb
+++ b/ext/tk/lib/tkextlib/tile/tbutton.rb
@@ -7,16 +7,13 @@ require 'tkextlib/tile.rb'
module Tk
module Tile
- class TButton < Tk::Button
+ class TButton < TkButton
end
Button = TButton
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Button, :TkButton)
-
-
-class Tk::Tile::TButton < Tk::Button
+class Tk::Tile::TButton < TkButton
include Tk::Tile::TileWidget
if Tk::Tile::USE_TTK_NAMESPACE
diff --git a/ext/tk/lib/tkextlib/tile/tcheckbutton.rb b/ext/tk/lib/tkextlib/tile/tcheckbutton.rb
index 172225fcec..fce799683d 100644
--- a/ext/tk/lib/tkextlib/tile/tcheckbutton.rb
+++ b/ext/tk/lib/tkextlib/tile/tcheckbutton.rb
@@ -7,7 +7,7 @@ require 'tkextlib/tile.rb'
module Tk
module Tile
- class TCheckButton < Tk::CheckButton
+ class TCheckButton < TkCheckButton
end
TCheckbutton = TCheckButton
CheckButton = TCheckButton
@@ -15,11 +15,7 @@ module Tk
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Checkbutton,
- :TkCheckbutton, :TkCheckButton)
-
-
-class Tk::Tile::TCheckButton < Tk::CheckButton
+class Tk::Tile::TCheckButton < TkCheckButton
include Tk::Tile::TileWidget
if Tk::Tile::USE_TTK_NAMESPACE
diff --git a/ext/tk/lib/tkextlib/tile/tcombobox.rb b/ext/tk/lib/tkextlib/tile/tcombobox.rb
index b64372f1c9..e8e042fbd9 100644
--- a/ext/tk/lib/tkextlib/tile/tcombobox.rb
+++ b/ext/tk/lib/tkextlib/tile/tcombobox.rb
@@ -13,9 +13,6 @@ module Tk
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Combobox, :TkCombobox)
-
-
class Tk::Tile::TCombobox < Tk::Tile::TEntry
include Tk::Tile::TileWidget
diff --git a/ext/tk/lib/tkextlib/tile/tentry.rb b/ext/tk/lib/tkextlib/tile/tentry.rb
index 0bea98dcd9..4d57ce7756 100644
--- a/ext/tk/lib/tkextlib/tile/tentry.rb
+++ b/ext/tk/lib/tkextlib/tile/tentry.rb
@@ -7,16 +7,13 @@ require 'tkextlib/tile.rb'
module Tk
module Tile
- class TEntry < Tk::Entry
+ class TEntry < TkEntry
end
Entry = TEntry
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Entry, :TkEntry)
-
-
-class Tk::Tile::TEntry < Tk::Entry
+class Tk::Tile::TEntry < TkEntry
include Tk::Tile::TileWidget
if Tk::Tile::USE_TTK_NAMESPACE
@@ -27,11 +24,6 @@ class Tk::Tile::TEntry < Tk::Entry
WidgetClassName = 'TEntry'.freeze
WidgetClassNames[WidgetClassName] = self
- def __optkey_aliases
- {:vcmd=>:validatecommand, :invcmd=>:invalidcommand}
- end
- private :__optkey_aliases
-
def __boolval_optkeys
super() << 'exportselection'
end
diff --git a/ext/tk/lib/tkextlib/tile/tframe.rb b/ext/tk/lib/tkextlib/tile/tframe.rb
index 3b5f98bb6e..691c9c42af 100644
--- a/ext/tk/lib/tkextlib/tile/tframe.rb
+++ b/ext/tk/lib/tkextlib/tile/tframe.rb
@@ -7,16 +7,13 @@ require 'tkextlib/tile.rb'
module Tk
module Tile
- class TFrame < Tk::Frame
+ class TFrame < TkFrame
end
Frame = TFrame
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Frame, :TkFrame)
-
-
-class Tk::Tile::TFrame < Tk::Frame
+class Tk::Tile::TFrame < TkFrame
include Tk::Tile::TileWidget
if Tk::Tile::USE_TTK_NAMESPACE
diff --git a/ext/tk/lib/tkextlib/tile/tlabel.rb b/ext/tk/lib/tkextlib/tile/tlabel.rb
index 7d074d3842..4111d1906a 100644
--- a/ext/tk/lib/tkextlib/tile/tlabel.rb
+++ b/ext/tk/lib/tkextlib/tile/tlabel.rb
@@ -7,16 +7,13 @@ require 'tkextlib/tile.rb'
module Tk
module Tile
- class TLabel < Tk::Label
+ class TLabel < TkLabel
end
Label = TLabel
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Label, :TkLabel)
-
-
-class Tk::Tile::TLabel < Tk::Label
+class Tk::Tile::TLabel < TkLabel
include Tk::Tile::TileWidget
if Tk::Tile::USE_TTK_NAMESPACE
diff --git a/ext/tk/lib/tkextlib/tile/tlabelframe.rb b/ext/tk/lib/tkextlib/tile/tlabelframe.rb
index cff66d8658..8981232b25 100644
--- a/ext/tk/lib/tkextlib/tile/tlabelframe.rb
+++ b/ext/tk/lib/tkextlib/tile/tlabelframe.rb
@@ -9,16 +9,10 @@ module Tk
module Tile
class TLabelframe < Tk::Tile::TFrame
end
- TLabelFrame = TLabelframe
- Labelframe = TLabelframe
- LabelFrame = TLabelframe
+ Labelframe = TLabelframe
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Labelframe,
- :TkLabelframe, :TkLabelFrame)
-
-
class Tk::Tile::TLabelframe < Tk::Tile::TFrame
include Tk::Tile::TileWidget
diff --git a/ext/tk/lib/tkextlib/tile/tmenubutton.rb b/ext/tk/lib/tkextlib/tile/tmenubutton.rb
index 7c6ab28e52..4b81fa1c81 100644
--- a/ext/tk/lib/tkextlib/tile/tmenubutton.rb
+++ b/ext/tk/lib/tkextlib/tile/tmenubutton.rb
@@ -7,19 +7,13 @@ require 'tkextlib/tile.rb'
module Tk
module Tile
- class TMenubutton < Tk::Menubutton
+ class TMenubutton < TkMenubutton
end
- TMenuButton = TMenubutton
- Menubutton = TMenubutton
- MenuButton = TMenubutton
+ Menubutton = TMenubutton
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Menubutton,
- :TkMenubutton, :TkMenuButton)
-
-
-class Tk::Tile::TMenubutton < Tk::Menubutton
+class Tk::Tile::TMenubutton < TkMenubutton
include Tk::Tile::TileWidget
if Tk::Tile::USE_TTK_NAMESPACE
diff --git a/ext/tk/lib/tkextlib/tile/tnotebook.rb b/ext/tk/lib/tkextlib/tile/tnotebook.rb
index 4d65e363da..a928e64b61 100644
--- a/ext/tk/lib/tkextlib/tile/tnotebook.rb
+++ b/ext/tk/lib/tkextlib/tile/tnotebook.rb
@@ -13,9 +13,6 @@ module Tk
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Notebook, :TkNotebook)
-
-
class Tk::Tile::TNotebook < TkWindow
################################
include TkItemConfigMethod
@@ -41,34 +38,12 @@ class Tk::Tile::TNotebook < TkWindow
private :__item_methodcall_optkeys
#alias tabcget itemcget
- #alias tabcget_strict itemcget_strict
alias tabconfigure itemconfigure
alias tabconfiginfo itemconfiginfo
alias current_tabconfiginfo current_itemconfiginfo
- def tabcget_strict(tagOrId, option)
- tabconfigure(tagOrId, option)[-1]
- end
def tabcget(tagOrId, option)
- unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- tabcget_strict(tagOrId, option)
- else
- begin
- tabcget_strict(tagOrId, option)
- rescue => e
- begin
- if current_tabconfiginfo(tagOrId).has_key?(option.to_s)
- # not tag error & option is known -> error on known option
- fail e
- else
- # not tag error & option is unknown
- nil
- end
- rescue
- fail e # tag error
- end
- end
- end
+ tabconfigure(tagOrId, option)[-1]
end
################################
@@ -99,9 +74,9 @@ class Tk::Tile::TNotebook < TkWindow
def add(child, keys=nil)
if keys && keys != None
- tk_send('add', _epath(child), *hash_kv(keys))
+ tk_send_without_enc('add', _epath(child), *hash_kv(keys))
else
- tk_send('add', _epath(child))
+ tk_send_without_enc('add', _epath(child))
end
self
end
diff --git a/ext/tk/lib/tkextlib/tile/tpaned.rb b/ext/tk/lib/tkextlib/tile/tpaned.rb
index d96ff43973..11178b19d3 100644
--- a/ext/tk/lib/tkextlib/tile/tpaned.rb
+++ b/ext/tk/lib/tkextlib/tile/tpaned.rb
@@ -9,23 +9,15 @@ module Tk
module Tile
class TPaned < TkWindow
end
- PanedWindow = Panedwindow = Paned = TPaned
+ Paned = TPaned
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Panedwindow,
- :TkPanedwindow, :TkPanedWindow)
-
-
class Tk::Tile::TPaned < TkWindow
include Tk::Tile::TileWidget
if Tk::Tile::USE_TTK_NAMESPACE
- if Tk::Tile::TILE_SPEC_VERSION_ID < 8
- TkCommandNames = ['::ttk::paned'.freeze].freeze
- else
- TkCommandNames = ['::ttk::panedwindow'.freeze].freeze
- end
+ TkCommandNames = ['::ttk::paned'.freeze].freeze
else
TkCommandNames = ['::tpaned'.freeze].freeze
end
@@ -36,21 +28,9 @@ class Tk::Tile::TPaned < TkWindow
[self::WidgetClassName, *(args.map!{|a| _get_eval_string(a)})].join('.')
end
- def add(*args)
- keys = args.pop
- fail ArgumentError, "no window in arguments" unless keys
-
- if keys && keys.kind_of?(Hash)
- fail ArgumentError, "no window in arguments" if args == []
- opts = hash_kv(keys)
- else
- args.push(keys) if keys
- opts = []
- end
-
- args.each{|win|
- tk_send_without_enc('add', _epath(win), *opts)
- }
+ def add(win, keys)
+ win = _epath(win)
+ tk_send_without_enc('add', win, *hash_kv(keys))
self
end
@@ -66,33 +46,10 @@ class Tk::Tile::TPaned < TkWindow
self
end
- def panecget_strict(pane, slot)
+ def panecget(pane, slot)
pane = _epath(pane)
tk_tcl2ruby(tk_send_without_enc('pane', pane, "-#{slot}"))
end
- alias pane_cget_strict panecget_strict
-
- def panecget(pane, slot)
- unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- panecget_strict(pane, slot)
- else
- begin
- panecget_strict(pane, slot)
- rescue => e
- begin
- if current_paneconfiginfo(pane).has_key?(slot.to_s)
- # not tag error & option is known -> error on known option
- fail e
- else
- # not tag error & option is unknown
- nil
- end
- rescue
- fail e # tag error
- end
- end
- end
- end
alias pane_cget panecget
def paneconfigure(pane, key, value=nil)
diff --git a/ext/tk/lib/tkextlib/tile/tprogressbar.rb b/ext/tk/lib/tkextlib/tile/tprogressbar.rb
index f786d370dd..36c1c75c23 100644
--- a/ext/tk/lib/tkextlib/tile/tprogressbar.rb
+++ b/ext/tk/lib/tkextlib/tile/tprogressbar.rb
@@ -13,9 +13,6 @@ module Tk
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Progressbar, :TkProgressbar)
-
-
class Tk::Tile::TProgressbar
include Tk::Tile::TileWidget
diff --git a/ext/tk/lib/tkextlib/tile/tradiobutton.rb b/ext/tk/lib/tkextlib/tile/tradiobutton.rb
index d653a6d256..e2f614cb97 100644
--- a/ext/tk/lib/tkextlib/tile/tradiobutton.rb
+++ b/ext/tk/lib/tkextlib/tile/tradiobutton.rb
@@ -7,7 +7,7 @@ require 'tkextlib/tile.rb'
module Tk
module Tile
- class TRadioButton < Tk::RadioButton
+ class TRadioButton < TkRadioButton
end
TRadiobutton = TRadioButton
RadioButton = TRadioButton
@@ -15,11 +15,7 @@ module Tk
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Radiobutton,
- :TkRadiobutton, :TkRadioButton)
-
-
-class Tk::Tile::TRadioButton < Tk::RadioButton
+class Tk::Tile::TRadioButton < TkRadioButton
include Tk::Tile::TileWidget
if Tk::Tile::USE_TTK_NAMESPACE
diff --git a/ext/tk/lib/tkextlib/tile/treeview.rb b/ext/tk/lib/tkextlib/tile/treeview.rb
index c978a1a07b..68e478896c 100644
--- a/ext/tk/lib/tkextlib/tile/treeview.rb
+++ b/ext/tk/lib/tkextlib/tile/treeview.rb
@@ -12,9 +12,6 @@ module Tk
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Treeview, :TkTreeview)
-
-
module Tk::Tile::TreeviewConfig
include TkItemConfigMethod
@@ -33,12 +30,6 @@ module Tk::Tile::TreeviewConfig
else
if slot
slot = slot.to_s
-
- alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
- if real_name
- slot = real_name.to_s
- end
-
case slot
when /^(#{__tile_specific_item_optkeys(tagid(tagOrId)).join('|')})$/
begin
@@ -204,12 +195,6 @@ module Tk::Tile::TreeviewConfig
else
if slot
slot = slot.to_s
-
- alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
- if real_name
- slot = real_name.to_s
- end
-
case slot
when /^(#{__tile_specific_item_optkeys(tagid(tagOrId)).join('|')})$/
begin
@@ -393,7 +378,7 @@ module Tk::Tile::TreeviewConfig
when :item, 'item'
['width']
when :column, 'column'
- super(id[1]) + ['minwidth']
+ super(id[1])
when :tag, 'tag'
super(id[1])
when :heading, 'heading'
@@ -425,7 +410,7 @@ module Tk::Tile::TreeviewConfig
when :item, 'item'
['open']
when :column, 'column'
- super(id[1]) + ['stretch']
+ super(id[1])
when :tag, 'tag'
super(id[1])
when :heading, 'heading'
@@ -520,21 +505,17 @@ module Tk::Tile::TreeviewConfig
end
alias __itemcget itemcget
- alias __itemcget_strict itemcget_strict
alias __itemconfigure itemconfigure
alias __itemconfiginfo itemconfiginfo
alias __current_itemconfiginfo current_itemconfiginfo
- private :__itemcget, :__itemcget_strict
- private :__itemconfigure, :__itemconfiginfo, :__current_itemconfiginfo
+ private :__itemcget, :__itemconfigure
+ private :__itemconfiginfo, :__current_itemconfiginfo
# Treeview Item
def itemcget(tagOrId, option)
__itemcget([:item, tagOrId], option)
end
- def itemcget_strict(tagOrId, option)
- __itemcget_strict([:item, tagOrId], option)
- end
def itemconfigure(tagOrId, slot, value=None)
__itemconfigure([:item, tagOrId], slot, value)
end
@@ -549,9 +530,6 @@ module Tk::Tile::TreeviewConfig
def columncget(tagOrId, option)
__itemcget([:column, tagOrId], option)
end
- def columncget_strict(tagOrId, option)
- __itemcget_strict([:column, tagOrId], option)
- end
def columnconfigure(tagOrId, slot, value=None)
__itemconfigure([:column, tagOrId], slot, value)
end
@@ -562,13 +540,12 @@ module Tk::Tile::TreeviewConfig
__current_itemconfiginfo([:column, tagOrId], slot)
end
alias column_cget columncget
- alias column_cget_strict columncget_strict
alias column_configure columnconfigure
alias column_configinfo columnconfiginfo
alias current_column_configinfo current_columnconfiginfo
# Treeview Heading
- def headingcget_strict(tagOrId, option)
+ def headingcget(tagOrId, option)
if __tile_specific_item_optkeys([:heading, tagOrId]).index(option.to_s)
begin
# On tile-0.7.{2-8}, 'state' options has no '-' at its head.
@@ -578,28 +555,7 @@ module Tk::Tile::TreeviewConfig
tk_call(*(__item_cget_cmd([:heading, tagOrId]) << "-#{option}"))
end
else
- __itemcget_strict([:heading, tagOrId], option)
- end
- end
- def headingcget(tagOrId, option)
- unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- headingcget_strict(tagOrId, option)
- else
- begin
- headingcget_strict(tagOrId, option)
- rescue => e
- begin
- if current_headingconfiginfo(tagOrId).has_key?(option.to_s)
- # not tag error & option is known -> error on known option
- fail e
- else
- # not tag error & option is unknown
- nil
- end
- rescue
- fail e # tag error
- end
- end
+ __itemcget([:heading, tagOrId], option)
end
end
def headingconfigure(tagOrId, slot, value=None)
@@ -631,7 +587,6 @@ module Tk::Tile::TreeviewConfig
__current_itemconfiginfo([:heading, tagOrId], slot)
end
alias heading_cget headingcget
- alias heading_cget_strict headingcget_strict
alias heading_configure headingconfigure
alias heading_configinfo headingconfiginfo
alias current_heading_configinfo current_headingconfiginfo
@@ -640,9 +595,6 @@ module Tk::Tile::TreeviewConfig
def tagcget(tagOrId, option)
__itemcget([:tag, tagOrId], option)
end
- def tagcget_strict(tagOrId, option)
- __itemcget_strict([:tag, tagOrId], option)
- end
def tagconfigure(tagOrId, slot, value=None)
__itemconfigure([:tag, tagOrId], slot, value)
end
@@ -653,7 +605,6 @@ module Tk::Tile::TreeviewConfig
__current_itemconfiginfo([:tag, tagOrId], slot)
end
alias tag_cget tagcget
- alias tag_cget_strict tagcget_strict
alias tag_configure tagconfigure
alias tag_configinfo tagconfiginfo
alias current_tag_configinfo current_tagconfiginfo
@@ -663,43 +614,30 @@ end
class Tk::Tile::Treeview::Item < TkObject
ItemID_TBL = TkCore::INTERP.create_table
-
- TkCore::INTERP.init_ip_env{
- Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
- Tk::Tile::Treeview::Item::ItemID_TBL.clear
- }
- }
+ TkCore::INTERP.init_ip_env{ Tk::Tile::Treeview::Item::ItemID_TBL.clear }
def self.id2obj(tree, id)
tpath = tree.path
- Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
- if Tk::Tile::Treeview::Item::ItemID_TBL[tpath]
- (Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id])? \
- Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id]: id
- else
- id
- end
- }
+ return id unless Tk::Tile::Treeview::Item::ItemID_TBL[tpath]
+ (Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id])? \
+ Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id]: id
end
def self.assign(tree, id)
tpath = tree.path
- obj = nil
- Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
- if Tk::Tile::Treeview::Item::ItemID_TBL[tpath] &&
- Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id]
- return Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id]
- end
+ if Tk::Tile::Treeview::Item::ItemID_TBL[tpath] &&
+ Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id]
+ return Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id]
+ end
- obj = self.allocate
- obj.instance_eval{
- @parent = @t = tree
- @tpath = tpath
- @path = @id = id
- }
- Tk::Tile::Treeview::Item::ItemID_TBL[tpath] ||= {}
- Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id] = obj
+ obj = self.allocate
+ obj.instance_eval{
+ @parent = @t = tree
+ @tpath = tpath
+ @path = @id = id
}
+ ItemID_TBL[tpath] = {} unless ItemID_TBL[tpath]
+ Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id] = obj
obj
end
@@ -728,10 +666,8 @@ class Tk::Tile::Treeview::Item < TkObject
@parent = @t = tree
@tpath = tree.path
@path = @id = _insert_item(@t, parent_item, idx, keys)
- Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
- ItemID_TBL[@tpath] = {} unless ItemID_TBL[@tpath]
- ItemID_TBL[@tpath][@id] = self
- }
+ ItemID_TBL[@tpath] = {} unless ItemID_TBL[@tpath]
+ ItemID_TBL[@tpath][@id] = self
end
def id
@id
@@ -740,9 +676,6 @@ class Tk::Tile::Treeview::Item < TkObject
def cget(option)
@t.itemcget(@id, option)
end
- def cget_strict(option)
- @t.itemcget_strict(@id, option)
- end
def configure(key, value=None)
@t.itemconfigure(@id, key, value)
@@ -868,35 +801,22 @@ end
class Tk::Tile::Treeview::Root < Tk::Tile::Treeview::Item
def self.new(tree, keys = {})
tpath = tree.path
- obj = nil
- Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
- if Tk::Tile::Treeview::Item::ItemID_TBL[tpath] &&
- Tk::Tile::Treeview::Item::ItemID_TBL[tpath]['']
- obj = Tk::Tile::Treeview::Item::ItemID_TBL[tpath]['']
- else
- #super(tree, keys)
- (obj = self.allocate).instance_eval{
- @parent = @t = tree
- @tpath = tree.path
- @path = @id = ''
- Tk::Tile::Treeview::Item::ItemID_TBL[@tpath] ||= {}
- Tk::Tile::Treeview::Item::ItemID_TBL[@tpath][@id] = self
- }
- end
- }
- obj.configure(keys) if keys && ! keys.empty?
- obj
+ if Tk::Tile::Treeview::Item::ItemID_TBL[tpath] &&
+ Tk::Tile::Treeview::Item::ItemID_TBL[tpath]['']
+ Tk::Tile::Treeview::Item::ItemID_TBL[tpath]['']
+ else
+ super(tree, keys)
+ end
end
def initialize(tree, keys = {})
- # dummy:: not called by 'new' method
@parent = @t = tree
@tpath = tree.path
@path = @id = ''
- Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
- Tk::Tile::Treeview::Item::ItemID_TBL[@tpath] ||= {}
- Tk::Tile::Treeview::Item::ItemID_TBL[@tpath][@id] = self
- }
+ unless Tk::Tile::Treeview::Item::ItemID_TBL[@tpath]
+ Tk::Tile::Treeview::Item::ItemID_TBL[@tpath] = {}
+ end
+ Tk::Tile::Treeview::Item::ItemID_TBL[@tpath][@id] = self
end
end
@@ -906,42 +826,24 @@ class Tk::Tile::Treeview::Tag < TkObject
include TkTreatTagFont
TagID_TBL = TkCore::INTERP.create_table
+ Tag_ID = ['tile_treeview_tag'.freeze, '00000'.taint].freeze
- (Tag_ID = ['tile_treeview_tag'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- Tk::Tile::Treeview::Tag::TagID_TBL.mutex.synchronize{
- Tk::Tile::Treeview::Tag::TagID_TBL.clear
- }
- }
+ TkCore::INTERP.init_ip_env{ Tk::Tile::Treeview::Tag::TagID_TBL.clear }
def self.id2obj(tree, id)
tpath = tree.path
- Tk::Tile::Treeview::Tag::TagID_TBL.mutex.synchronize{
- if Tk::Tile::Treeview::Tag::TagID_TBL[tpath]
- (Tk::Tile::Treeview::Tag::TagID_TBL[tpath][id])? \
- Tk::Tile::Treeview::Tag::TagID_TBL[tpath][id]: id
- else
- id
- end
- }
+ return id unless Tk::Tile::Treeview::Tag::TagID_TBL[tpath]
+ (Tk::Tile::Treeview::Tag::TagID_TBL[tpath][id])? \
+ Tk::Tile::Treeview::Tag::TagID_TBL[tpath][id]: id
end
def initialize(tree, keys=nil)
@parent = @t = tree
@tpath = tree.path
- Tag_ID.mutex.synchronize{
- @path = @id = Tag_ID.join(TkCore::INTERP._ip_id_)
- Tag_ID[1].succ!
- }
- TagID_TBL.mutex.synchronize{
- TagID_TBL[@tpath] = {} unless TagID_TBL[@tpath]
- TagID_TBL[@tpath][@id] = self
- }
+ @path = @id = Tag_ID.join(TkCore::INTERP._ip_id_)
+ TagID_TBL[@tpath] = {} unless TagID_TBL[@tpath]
+ TagID_TBL[@tpath][@id] = self
+ Tag_ID[1].succ!
if keys && keys != None
tk_call_without_enc(@tpath, 'tag', 'configure', *hash_kv(keys, true))
end
@@ -982,9 +884,6 @@ class Tk::Tile::Treeview::Tag < TkObject
def cget(option)
@t.tagcget(@id, option)
end
- def cget_strict(option)
- @t.tagcget_strict(@id, option)
- end
def configure(key, value=None)
@t.tagconfigure(@id, key, value)
@@ -1017,12 +916,8 @@ class Tk::Tile::Treeview < TkWindow
WidgetClassNames[WidgetClassName] = self
def __destroy_hook__
- Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
- Tk::Tile::Treeview::Item::ItemID_TBL.delete(@path)
- }
- Tk::Tile::Treeview::Tag::ItemID_TBL.mutex.synchronize{
- Tk::Tile::Treeview::Tag::ItemID_TBL.delete(@path)
- }
+ Tk::Tile::Treeview::Item::ItemID_TBL.delete(@path)
+ Tk::Tile::Treeview::Tag::ItemID_TBL.delete(@path)
end
def self.style(*args)
diff --git a/ext/tk/lib/tkextlib/tile/tscale.rb b/ext/tk/lib/tkextlib/tile/tscale.rb
index 2c46fd9bd4..7ec72e3515 100644
--- a/ext/tk/lib/tkextlib/tile/tscale.rb
+++ b/ext/tk/lib/tkextlib/tile/tscale.rb
@@ -7,7 +7,7 @@ require 'tkextlib/tile.rb'
module Tk
module Tile
- class TScale < Tk::Scale
+ class TScale < TkScale
end
Scale = TScale
@@ -17,10 +17,7 @@ module Tk
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Scale, :TkScale)
-
-
-class Tk::Tile::TScale < Tk::Scale
+class Tk::Tile::TScale < TkScale
include Tk::Tile::TileWidget
if Tk::Tile::USE_TTK_NAMESPACE
diff --git a/ext/tk/lib/tkextlib/tile/tscrollbar.rb b/ext/tk/lib/tkextlib/tile/tscrollbar.rb
index 163b8f4713..bd49ae18e3 100644
--- a/ext/tk/lib/tkextlib/tile/tscrollbar.rb
+++ b/ext/tk/lib/tkextlib/tile/tscrollbar.rb
@@ -7,16 +7,13 @@ require 'tkextlib/tile.rb'
module Tk
module Tile
- class TScrollbar < Tk::Scrollbar
+ class TScrollbar < TkScrollbar
end
Scrollbar = TScrollbar
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Scrollbar, :TkScrollbar)
-
-
-class Tk::Tile::TScrollbar < Tk::Scrollbar
+class Tk::Tile::TScrollbar < TkScrollbar
include Tk::Tile::TileWidget
if Tk::Tile::USE_TTK_NAMESPACE
@@ -31,24 +28,3 @@ class Tk::Tile::TScrollbar < Tk::Scrollbar
[self::WidgetClassName, *(args.map!{|a| _get_eval_string(a)})].join('.')
end
end
-
-class Tk::Tile::XScrollbar < Tk::Tile::TScrollbar
- def create_self(keys)
- keys = {} unless keys
- keys['orient'] = 'horizontal'
- super(keys)
- end
- private :create_self
-end
-
-class Tk::Tile::YScrollbar < Tk::Tile::TScrollbar
- def create_self(keys)
- keys = {} unless keys
- keys['orient'] = 'vertical'
- super(keys)
- end
- private :create_self
-end
-
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::XScrollbar, :TkXScrollbar)
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::YScrollbar, :TkYScrollbar)
diff --git a/ext/tk/lib/tkextlib/tile/tseparator.rb b/ext/tk/lib/tkextlib/tile/tseparator.rb
index 30fae2c525..ca731d4e5b 100644
--- a/ext/tk/lib/tkextlib/tile/tseparator.rb
+++ b/ext/tk/lib/tkextlib/tile/tseparator.rb
@@ -13,9 +13,6 @@ module Tk
end
end
-Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Separator, :TkSeparator)
-
-
class Tk::Tile::TSeparator < TkWindow
include Tk::Tile::TileWidget
diff --git a/ext/tk/lib/tkextlib/tkDND/shape.rb b/ext/tk/lib/tkextlib/tkDND/shape.rb
index d44068ed33..570c93b0d9 100644
--- a/ext/tk/lib/tkextlib/tkDND/shape.rb
+++ b/ext/tk/lib/tkextlib/tkDND/shape.rb
@@ -11,15 +11,15 @@ require 'tkextlib/setup.rb'
# call setup script
require 'tkextlib/tkDND/setup.rb'
-# TkPackage.require('Shape', '0.3')
-TkPackage.require('Shape')
+# TkPackage.require('shape', '0.3')
+TkPackage.require('shape')
module Tk
module TkDND
module Shape
extend TkCore
- PACKAGE_NAME = 'Shape'.freeze
+ PACKAGE_NAME = 'shape'.freeze
def self.package_name
PACKAGE_NAME
end
@@ -27,28 +27,26 @@ module Tk
=begin
def self.package_version
begin
- TkPackage.require('Shape')
+ TkPackage.require('shape')
rescue
''
end
end
=end
- class << self
- def package_version
- Tk.tk_call('set', 'shape_version')
- end
- alias shape_version package_version
+ def self.package_version
+ Tk.tk_call('set', 'shape_version')
+ end
+ alias shape_version package_version
- def package_patchlevel
- Tk.tk_call('set', 'shape_patchLevel')
- end
- alias shape_patchlevel package_patchlevel
+ def self.package_patchlevel
+ Tk.tk_call('set', 'shape_patchlevel')
+ end
+ alias shape_patchlevel package_patchlevel
- def version
- tk_call('shape', 'version')
- end
- alias xshape_version version
+ def self.version
+ tk_call('shape', 'version')
end
+ alias xshape_version version
############################
diff --git a/ext/tk/lib/tkextlib/tkDND/tkdnd.rb b/ext/tk/lib/tkextlib/tkDND/tkdnd.rb
index 9a9b2dc42c..a040532eb6 100644
--- a/ext/tk/lib/tkextlib/tkDND/tkdnd.rb
+++ b/ext/tk/lib/tkextlib/tkDND/tkdnd.rb
@@ -57,24 +57,6 @@ module Tk
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
# setup tables
_setup_subst_table(KEY_TBL, PROC_TBL);
end
diff --git a/ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb b/ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb
index d893a83cf2..8527f61df1 100644
--- a/ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb
+++ b/ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb
@@ -39,10 +39,7 @@ class Tk::HTML_Widget::ClippingWindow
WidgetClassNames[WidgetClassName] = self
HtmlClip_TBL = TkCore::INTERP.create_table
-
- TkCore::INTERP.init_ip_env{
- HtmlClip_TBL.mutex.synchronize{ HtmlClip_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ HtmlClip_TBL.clear }
def self.new(parent, keys={})
if parent.kind_of?(Hash)
@@ -57,9 +54,7 @@ class Tk::HTML_Widget::ClippingWindow
else
ppath = ''
end
- HtmlClip_TBL.mutex.synchronize{
- return HtmlClip_TBL[ppath] if HtmlClip_TBL[ppath]
- }
+ return HtmlClip_TBL[ppath] if HtmlClip_TBL[ppath]
widgetname = keys.delete('widgetname')
if widgetname =~ /^(.*)\.[^.]+$/
@@ -67,9 +62,7 @@ class Tk::HTML_Widget::ClippingWindow
if ppath2[0] != ?.
ppath2 = ppath + '.' + ppath2
end
- HtmlClip_TBL.mutex.synchronize{
- return HtmlClip_TBL[ppath2] if HtmlClip_TBL[ppath2]
- }
+ return HtmlClip_TBL[ppath2] if HtmlClip_TBL[ppath2]
ppath = ppath2
end
@@ -86,9 +79,7 @@ class Tk::HTML_Widget::ClippingWindow
@parent = parent
@ppath = parent.path
@path = @id = @ppath + '.x'
- HtmlClip_TBL.mutex.synchronize{
- HtmlClip_TBL[@ppath] = self
- }
+ HtmlClip_TBL[@ppath] = self
end
def method_missing(m, *args, &b)
diff --git a/ext/tk/lib/tkextlib/tktable/tktable.rb b/ext/tk/lib/tkextlib/tktable/tktable.rb
index f6cf24b40f..4edaabc847 100644
--- a/ext/tk/lib/tkextlib/tktable/tktable.rb
+++ b/ext/tk/lib/tkextlib/tktable/tktable.rb
@@ -77,9 +77,6 @@ module Tk::TkTable::ConfigMethod
def tag_cget(tagOrId, option)
itemcget(['tag', tagid(tagOrId)], option)
end
- def tag_cget_strict(tagOrId, option)
- itemcget_strict(['tag', tagid(tagOrId)], option)
- end
def tag_configure(tagOrId, slot, value=None)
itemconfigure(['tag', tagid(tagOrId)], slot, value)
end
@@ -93,9 +90,6 @@ module Tk::TkTable::ConfigMethod
def window_cget(tagOrId, option)
itemcget(['window', tagid(tagOrId)], option)
end
- def window_cget_strict(tagOrId, option)
- itemcget_strict(['window', tagid(tagOrId)], option)
- end
def window_configure(tagOrId, slot, value=None)
if slot == :window || slot == 'window'
value = _epath(value)
@@ -114,8 +108,8 @@ module Tk::TkTable::ConfigMethod
current_itemconfiginfo(['window', tagid(tagOrId)], slot)
end
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
end
#####################################################
@@ -124,39 +118,23 @@ class Tk::TkTable::CellTag
include TkTreatTagFont
CellTagID_TBL = TkCore::INTERP.create_table
+ CellTag_ID = ['tktbl:celltag'.freeze, '00000'.taint].freeze
- (CellTag_ID = ['tktbl:celltag'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- CellTagID_TBL.mutex.synchronize{ CellTagID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ CellTagID_TBL.clear }
def self.id2obj(table, id)
tpath = table.path
- CellTagID_TBL.mutex.synchronize{
- if CellTagID_TBL[tpath]
- CellTagID_TBL[tpath][id]? CellTagID_TBL[tpath][id] : id
- else
- id
- end
- }
+ return id unless CellTagID_TBL[tpath]
+ CellTagID_TBL[tpath][id]? CellTagID_TBL[tpath][id] : id
end
def initialize(parent, keys=nil)
@parent = @t = parent
@tpath - parent.path
- CellTag_ID.mutex.synchronize{
- @path = @id = CellTag_ID.join(TkCore::INTERP._ip_id_)
- CellTag_ID[1].succ!
- }
- CellTagID_TBL.mutex.synchronize{
- CellTagID_TBL[@tpath] = {} unless CellTagID_TBL[@tpath]
- CellTagID_TBL[@tpath][@id] = self
- }
+ @path = @id = CellTag_ID.join(TkCore::INTERP._ip_id_)
+ CellTagID_TBL[@tpath] = {} unless CellTagID_TBL[@tpath]
+ CellTagID_TBL[@tpath][@id] = self
+ CellTag_ID[1].succ!
configure(keys) if keys
end
@@ -166,9 +144,7 @@ class Tk::TkTable::CellTag
def destroy
tk_call(@tpath, 'tag', 'delete', @id)
- CellTagID_TBL.mutex.synchronize{
- CellTagID_TBL[@tpath].delete(@id) if CellTagID_TBL[@tpath]
- }
+ CellTagID_TBL[@tpath].delete(@id) if CellTagID_TBL[@tpath]
self
end
alias delete destroy
@@ -200,9 +176,6 @@ class Tk::TkTable::CellTag
def cget(key)
@t.tag_cget(@id, key)
end
- def cget_strict(key)
- @t.tag_cget_strict(@id, key)
- end
def configure(key, val=None)
@t.tag_configure(@id, key, val)
end
@@ -216,35 +189,22 @@ end
class Tk::TkTable::NamedCellTag < Tk::TkTable::CellTag
def self.new(parent, name, keys=nil)
- obj = nil
- CellTagID_TBL.mutex.synchronize{
- if CellTagID_TBL[parent.path] && CellTagID_TBL[parent.path][name]
- obj = CellTagID_TBL[parent.path][name]
- else
- #super(parent, name, keys)
- (obj = self.allocate).instance_eval{
- @parent = @t = parent
- @tpath = parent.path
- @path = @id = name
- CellTagID_TBL[@tpath] = {} unless CellTagID_TBL[@tpath]
- CellTagID_TBL[@tpath][@id] = self
- }
- end
- }
- obj.configure(keys) if keys && ! keys.empty?
- obj
+ if CellTagID_TBL[parent.path] && CellTagID_TBL[parent.path][name]
+ cell = CellTagID_TBL[parent.path][name]
+ cell.configure(keys) if keys
+ return cell
+ else
+ super(parent, name, keys)
+ end
end
def initialize(parent, name, keys=nil)
- # dummy:: not called by 'new' method
@parent = @t = parent
- @tpath = parent.path
+ @tpath - parent.path
@path = @id = name
- CellTagID_TBL.mutex.synchronize{
- CellTagID_TBL[@tpath] = {} unless CellTagID_TBL[@tpath]
- CellTagID_TBL[@tpath][@id] = self
- }
- configure(keys) if keys && ! keys.empty?
+ CellTagID_TBL[@tpath] = {} unless CellTagID_TBL[@tpath]
+ CellTagID_TBL[@tpath][@id] = self
+ configure(keys) if keys
end
end
@@ -260,9 +220,7 @@ class Tk::TkTable
include Tk::ValidateConfigure
def __destroy_hook__
- Tk::TkTable::CelTag::CellTagID_TBL.mutex.synchronize{
- Tk::TkTable::CelTag::CellTagID_TBL.delete(@path)
- }
+ Tk::TkTable::CelTag::CellTagID_TBL.delete(@path)
end
def __boolval_optkeys
@@ -300,24 +258,6 @@ class Tk::TkTable
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@@ -351,24 +291,6 @@ class Tk::TkTable
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@@ -400,24 +322,6 @@ class Tk::TkTable
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@@ -452,24 +356,6 @@ class Tk::TkTable
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
end
@@ -860,17 +746,15 @@ class Tk::TkTable
end
def tagid2obj(tagid)
- Tk::TkTable::CellTag::CellTagID_TBL.mutex.synchronize{
- if Tk::TkTable::CellTag::CellTagID_TBL.key?(@path)
- if Tk::TkTable::CellTag::CellTagID_TBL[@path].key?(tagid)
- Tk::TkTable::CellTag::CellTagID_TBL[@path][tagid]
- else
- tagid
- end
+ if Tk::TkTable::CellTag::CellTagID_TBL.key?(@path)
+ if Tk::TkTable::CellTag::CellTagID_TBL[@path].key?(tagid)
+ Tk::TkTable::CellTag::CellTagID_TBL[@path][tagid]
else
tagid
end
- }
+ else
+ tagid
+ end
end
def tag_cell(tag, *cells)
@@ -891,15 +775,13 @@ class Tk::TkTable
end
def tag_delete(tag)
tk_send('tag', 'delete', tagid(tag))
- Tk::TkTable::CellTag::CellTagID_TBL.mutex.synchronize{
- if Tk::TkTable::CellTag::CellTagID_TBL[@path]
- if tag.kind_of? Tk::TkTable::CellTag
- Tk::TkTable::CellTag::CellTagID_TBL[@path].delete(tag.id)
- else
- Tk::TkTable::CellTag::CellTagID_TBL[@path].delete(tag)
- end
+ if Tk::TkTable::CellTag::CellTagID_TBL[@path]
+ if tag.kind_of? Tk::TkTable::CellTag
+ Tk::TkTable::CellTag::CellTagID_TBL[@path].delete(tag.id)
+ else
+ Tk::TkTable::CellTag::CellTagID_TBL[@path].delete(tag)
end
- }
+ end
self
end
def tag_exist?(tag)
diff --git a/ext/tk/lib/tkextlib/tktrans/tktrans.rb b/ext/tk/lib/tkextlib/tktrans/tktrans.rb
index e051c09211..665c57af0c 100644
--- a/ext/tk/lib/tkextlib/tktrans/tktrans.rb
+++ b/ext/tk/lib/tkextlib/tktrans/tktrans.rb
@@ -39,7 +39,7 @@ class TkWindow
end
end
-class Tk::Root
+class TkRoot
undef tktrans_set_image, tktrans_get_image
def tktrans_set_image(img)
@@ -51,7 +51,7 @@ class Tk::Root
end
end
-class Tk::Toplevel
+class TkToplevel
undef tktrans_set_image, tktrans_get_image
def tktrans_set_image(img)
diff --git a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb
index e10e6e299e..12f7cffabf 100644
--- a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb
+++ b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb
@@ -137,24 +137,6 @@ class Tk::TreeCtrl::NotifyEvent
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
# setup tables to be used by scan_args, _get_subst_key, _get_all_subst_keys
#
# _get_subst_key() and _get_all_subst_keys() generates key-string
@@ -417,9 +399,6 @@ module Tk::TreeCtrl::ConfigMethod
def column_cget(tagOrId, option)
itemcget(['column', tagOrId], option)
end
- def column_cget_strict(tagOrId, option)
- itemcget_strict(['column', tagOrId], option)
- end
def column_configure(tagOrId, slot, value=None)
itemconfigure(['column', tagOrId], slot, value)
end
@@ -433,9 +412,6 @@ module Tk::TreeCtrl::ConfigMethod
def column_dragcget(option)
itemcget(['column', 'drag'], option)
end
- def column_dragcget_strict(option)
- itemcget_strict(['column', 'drag'], option)
- end
def column_dragconfigure(slot, value=None)
itemconfigure(['column', 'drag'], slot, value)
end
@@ -449,9 +425,6 @@ module Tk::TreeCtrl::ConfigMethod
def debug_cget(option)
itemcget('debug', option)
end
- def debug_cget_strict(option)
- itemcget_strict('debug', option)
- end
def debug_configure(slot, value=None)
itemconfigure('debug', slot, value)
end
@@ -465,9 +438,6 @@ module Tk::TreeCtrl::ConfigMethod
def dragimage_cget(option)
itemcget('dragimage', option)
end
- def dragimage_cget_strict(option)
- itemcget_strict('dragimage', option)
- end
def dragimage_configure(slot, value=None)
itemconfigure('dragimage', slot, value)
end
@@ -481,9 +451,6 @@ module Tk::TreeCtrl::ConfigMethod
def element_cget(tagOrId, option)
itemcget(['element', tagOrId], option)
end
- def element_cget_strict(tagOrId, option)
- itemcget_strict(['element', tagOrId], option)
- end
def element_configure(tagOrId, slot, value=None)
itemconfigure(['element', tagOrId], slot, value)
end
@@ -497,9 +464,6 @@ module Tk::TreeCtrl::ConfigMethod
def item_cget(tagOrId, option)
itemcget(['item', tagOrId], option)
end
- def item_cget_strict(tagOrId, option)
- itemcget_strict(['item', tagOrId], option)
- end
def item_configure(tagOrId, slot, value=None)
itemconfigure(['item', tagOrId], slot, value)
end
@@ -513,9 +477,6 @@ module Tk::TreeCtrl::ConfigMethod
def item_element_cget(item, column, elem, option)
itemcget([['item', 'element'], [item, column, elem]], option)
end
- def item_element_cget_strict(item, column, elem, option)
- itemcget_strict([['item', 'element'], [item, column, elem]], option)
- end
def item_element_configure(item, column, elem, slot, value=None)
itemconfigure([['item', 'element'], [item, column, elem]], slot, value)
end
@@ -529,9 +490,6 @@ module Tk::TreeCtrl::ConfigMethod
def marquee_cget(option)
itemcget('marquee', option)
end
- def marquee_cget_strict(option)
- itemcget_strict('marquee', option)
- end
def marquee_configure(slot, value=None)
itemconfigure('marquee', slot, value)
end
@@ -544,19 +502,7 @@ module Tk::TreeCtrl::ConfigMethod
def notify_cget(win, pattern, option)
pattern = "<#{pattern}>"
- # "notify" doesn't have cget subcommand.
- current_itemconfiginfo(['notify', [win, pattern]])[option.to_s]
- end
- def notify_cget_strict(win, pattern, option)
- pattern = "<#{pattern}>"
- # "notify" doesn't have cget subcommand.
- info = current_itemconfiginfo(['notify', [win, pattern]])
- option = option.to_s
- unless info.has_key?(option)
- fail RuntimeError, "unknown option \"#{option}\""
- else
- info[option]
- end
+ itemconfigure(['notify', [win, pattern]], option)
end
def notify_configure(win, pattern, slot, value=None)
pattern = "<#{pattern}>"
@@ -566,17 +512,11 @@ module Tk::TreeCtrl::ConfigMethod
pattern = "<#{pattern}>"
itemconfiginfo(['notify', [win, pattern]], slot)
end
- def current_notify_configinfo(tagOrId, slot=nil)
- pattern = "<#{pattern}>"
- current_itemconfiginfo(['notify', [win, pattern]], slot)
- end
+ alias current_notify_configinfo notify_configinfo
def style_cget(tagOrId, option)
itemcget(['style', tagOrId], option)
end
- def style_cget_strict(tagOrId, option)
- itemcget_strict(['style', tagOrId], option)
- end
def style_configure(tagOrId, slot, value=None)
itemconfigure(['style', tagOrId], slot, value)
end
@@ -587,8 +527,8 @@ module Tk::TreeCtrl::ConfigMethod
current_itemconfiginfo(['style', tagOrId], slot)
end
- private :itemcget, :itemcget_strict
- private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemconfigure
+ private :itemconfiginfo, :current_itemconfiginfo
end
##############################################
@@ -604,18 +544,10 @@ class Tk::TreeCtrl
#########################
def __destroy_hook__
- Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.mutex.synchronize{
- Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.delete(@path)
- }
- Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.mutex.synchronize{
- Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.delete(@path)
- }
- Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.mutex.synchronize{
- Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.delete(@path)
- }
- Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.mutex.synchronize{
- Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.delete(@path)
- }
+ Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.delete(@path)
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.delete(@path)
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.delete(@path)
+ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.delete(@path)
end
#########################
@@ -706,11 +638,9 @@ class Tk::TreeCtrl
end
def column_delete(idx)
- Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.mutex.synchronize{
- if Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[self.path]
- Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[self.path].delete(idx)
- end
- }
+ if Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[self.path]
+ Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[self.path].delete(idx)
+ end
tk_send('column', 'delete', idx)
self
end
@@ -820,13 +750,11 @@ class Tk::TreeCtrl
end
def element_delete(*elems)
- Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.mutex.synchronize{
- if Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[self.path]
- elems.each{|elem|
- Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[self.path].delete(elem)
- }
- end
- }
+ if Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[self.path]
+ elems.each{|elem|
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[self.path].delete(elem)
+ }
+ end
tk_send('element', 'delete', *elems)
self
end
@@ -957,25 +885,22 @@ class Tk::TreeCtrl
def _erase_children(item)
item_children(item).each{|i| _erase_children(i)}
- # table is already locked
Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path].delete(item)
end
private :_erase_children
def item_delete(first, last=None)
- Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.mutex.synchronize{
- if Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path]
- if first == 'all' || first == :all || last == 'all' || last == :all
- Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path].clear
- elsif last == None
- _erase_children(first)
- else
- self.range(first, last).each{|id|
- _erase_children(id)
- }
- end
+ if Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path]
+ if first == 'all' || first == :all || last == 'all' || last == :all
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path].clear
+ elsif last == None
+ _erase_children(first)
+ else
+ self.range(first, last).each{|id|
+ _erase_children(id)
+ }
end
- }
+ end
tk_send('item', 'delete', first, last)
self
end
@@ -1595,13 +1520,11 @@ class Tk::TreeCtrl
end
def style_delete(*args)
- Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.mutex.synchronize{
- if Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[self.path]
- args.each{|sty|
- Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[self.path].delete(sty)
- }
- end
- }
+ if Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[self.path]
+ args.each{|sty|
+ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[self.path].delete(sty)
+ }
+ end
tk_send('style', 'delete', *args)
self
end
@@ -1685,29 +1608,15 @@ end
class Tk::TreeCtrl::Column < TkObject
TreeCtrlColumnID_TBL = TkCore::INTERP.create_table
+ TreeCtrlColumnID = ['treectrl_column'.freeze, '00000'.taint].freeze
- (TreeCtrlColumnID = ['treectrl_column'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.mutex.synchronize{
- Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.clear
- }
- }
+ TkCore::INTERP.init_ip_env{Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.clear}
def self.id2obj(tree, id)
tpath = tree.path
- Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.mutex.synchronize{
- if Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath]
- Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath][id]? \
- Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath][id] : id
- else
- id
- end
- }
+ return id unless Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath]
+ Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath][id]? \
+ Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath][id] : id
end
def initialize(parent, keys={})
@@ -1716,19 +1625,17 @@ class Tk::TreeCtrl::Column < TkObject
keys = _symbolkey2str(keys)
- Tk::TreeCtrl::Column::TreeCtrlColumnID.mutex.synchronize{
- @path = @id =
- keys.delete('tag') ||
- Tk::TreeCtrl::Column::TreeCtrlColumnID.join(TkCore::INTERP._ip_id_)
- Tk::TreeCtrl::Column::TreeCtrlColumnID[1].succ!
- }
+ @path = @id =
+ keys.delete('tag') ||
+ Tk::TreeCtrl::Column::TreeCtrlColumnID.join(TkCore::INTERP._ip_id_)
keys['tag'] = @id
- Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.mutex.synchronize{
- Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath] ||= {}
- Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath][@id] = self
- }
+ unless Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath]
+ Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath] = {}
+ end
+ Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath][@id] = self
+ Tk::TreeCtrl::Column::TreeCtrlColumnID[1].succ!
@tree.column_create(keys)
end
@@ -1744,9 +1651,6 @@ class Tk::TreeCtrl::Column < TkObject
def cget(opt)
@tree.column_cget(@tree.column_index(@id), opt)
end
- def cget_strict(opt)
- @tree.column_cget_strict(@tree.column_index(@id), opt)
- end
def configure(*args)
@tree.column_configure(@tree.column_index(@id), *args)
@@ -1788,18 +1692,11 @@ end
class Tk::TreeCtrl::Element < TkObject
TreeCtrlElementID_TBL = TkCore::INTERP.create_table
-
- (TreeCtrlElementID = ['treectrl_element'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
+ TreeCtrlElementID = ['treectrl_element'.freeze, '00000'.taint].freeze
TreeCtrlElemTypeToClass = {}
TkCore::INTERP.init_ip_env{
- Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.mutex.synchronize{
- Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.clear
- }
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.clear
}
def self.type2class(type)
@@ -1808,30 +1705,22 @@ class Tk::TreeCtrl::Element < TkObject
def self.id2obj(tree, id)
tpath = tree.path
- Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.mutex.synchronize{
- if Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath]
- Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath][id]? \
+ return id unless Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath]
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath][id]? \
Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath][id] : id
- else
- id
- end
- }
end
def initialize(parent, type, keys=nil)
@tree = parent
@tpath = parent.path
@type = type.to_s
- Tk::TreeCtrl::Element::TreeCtrlElementID.mutex.synchronize{
- @path = @id =
- Tk::TreeCtrl::Element::TreeCtrlElementID.join(TkCore::INTERP._ip_id_)
- Tk::TreeCtrl::Element::TreeCtrlElementID[1].succ!
- }
-
- Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.mutex.synchronize{
- Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath] ||= {}
- Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath][@id] = self
- }
+ @path = @id =
+ Tk::TreeCtrl::Element::TreeCtrlElementID.join(TkCore::INTERP._ip_id_)
+ unless Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath]
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath] = {}
+ end
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath][@id] = self
+ Tk::TreeCtrl::Element::TreeCtrlElementID[1].succ!
@tree.element_create(@id, @type, keys)
end
@@ -1847,9 +1736,6 @@ class Tk::TreeCtrl::Element < TkObject
def cget(opt)
@tree.element_cget(@id, opt)
end
- def cget_strict(opt)
- @tree.element_cget_strict(@id, opt)
- end
def configure(*args)
@tree.element_configure(@id, *args)
@@ -1914,22 +1800,13 @@ end
class Tk::TreeCtrl::Item < TkObject
TreeCtrlItemID_TBL = TkCore::INTERP.create_table
- TkCore::INTERP.init_ip_env{
- Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.mutex.synchronize{
- Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.clear
- }
- }
+ TkCore::INTERP.init_ip_env{Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.clear}
def self.id2obj(tree, id)
tpath = tree.path
- Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.mutex.synchronize{
- if Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath]
- Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath][id]? \
- Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath][id] : id
- else
- id
- end
- }
+ return id unless Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath]
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath][id]? \
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath][id] : id
end
def initialize(parent, keys={})
@@ -1937,10 +1814,10 @@ class Tk::TreeCtrl::Item < TkObject
@tpath = parent.path
@path = @id = @tree.item_create(keys)
- Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.mutex.synchronize{
- Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath] ||= {}
- Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath][@id] = self
- }
+ unless Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath]
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath] = {}
+ end
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath][@id] = self
end
def id
@@ -1981,9 +1858,6 @@ class Tk::TreeCtrl::Item < TkObject
def cget(opt)
@tree.item_cget(@id, opt)
end
- def cget_strict(opt)
- @tree.item_cget_strict(@id, opt)
- end
def configure(*args)
@tree.item_configure(@id, *args)
@@ -2017,9 +1891,6 @@ class Tk::TreeCtrl::Item < TkObject
def element_cget(opt)
@tree.item_element_cget(@id, opt)
end
- def element_cget_strict(opt)
- @tree.item_element_cget_strict(@id, opt)
- end
def element_configure(*args)
@tree.item_element_configure(@id, *args)
@@ -2217,45 +2088,27 @@ end
class Tk::TreeCtrl::Style < TkObject
TreeCtrlStyleID_TBL = TkCore::INTERP.create_table
+ TreeCtrlStyleID = ['treectrl_style'.freeze, '00000'.taint].freeze
- (TreeCtrlStyleID = ['treectrl_style'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.mutex.synchronize{
- Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.clear
- }
- }
+ TkCore::INTERP.init_ip_env{ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.clear }
def self.id2obj(tree, id)
tpath = tree.path
- Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.mutex.synchronize{
- if Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath]
- Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath][id]? \
- Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath][id] : id
- else
- id
- end
- }
+ return id unless Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath]
+ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath][id]? \
+ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath][id] : id
end
def initialize(parent, keys=nil)
@tree = parent
@tpath = parent.path
-
- Tk::TreeCtrl::Style::TreeCtrlStyleID.mutex.synchronize{
- @path = @id =
- Tk::TreeCtrl::Style::TreeCtrlStyleID.join(TkCore::INTERP._ip_id_)
- Tk::TreeCtrl::Style::TreeCtrlStyleID[1].succ!
- }
-
- Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.mutex.synchronize{
- Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath] ||= {}
- Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath][@id] = self
- }
+ @path = @id =
+ Tk::TreeCtrl::Style::TreeCtrlStyleID.join(TkCore::INTERP._ip_id_)
+ unless Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath]
+ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath] = {}
+ end
+ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath][@id] = self
+ Tk::TreeCtrl::Style::TreeCtrlStyleID[1].succ!
@tree.style_create(@id, keys)
end
@@ -2271,9 +2124,6 @@ class Tk::TreeCtrl::Style < TkObject
def cget(opt)
@tree.style_cget(@id, opt)
end
- def cget_strict(opt)
- @tree.style_cget_strict(@id, opt)
- end
def configure(*args)
@tree.style_configure(@id, *args)
diff --git a/ext/tk/lib/tkextlib/version.rb b/ext/tk/lib/tkextlib/version.rb
index 434ed11a2e..c7816fd4a5 100644
--- a/ext/tk/lib/tkextlib/version.rb
+++ b/ext/tk/lib/tkextlib/version.rb
@@ -2,5 +2,5 @@
# release date of tkextlib
#
module Tk
- Tkextlib_RELEASE_DATE = '2008-05-23'.freeze
+ Tkextlib_RELEASE_DATE = '2007-05-26'.freeze
end
diff --git a/ext/tk/lib/tkextlib/vu/pie.rb b/ext/tk/lib/tkextlib/vu/pie.rb
index c1fb6857bf..78f3fa54da 100644
--- a/ext/tk/lib/tkextlib/vu/pie.rb
+++ b/ext/tk/lib/tkextlib/vu/pie.rb
@@ -116,26 +116,13 @@ end
class Tk::Vu::PieSlice
SliceID_TBL = TkCore::INTERP.create_table
-
- (Pie_Slice_ID = ['vu:pie'.freeze, '00000'.taint]).instance_eval{
- @mutex = Mutex.new
- def mutex; @mutex; end
- freeze
- }
-
- TkCore::INTERP.init_ip_env{
- SliceID_TBL.mutex.synchronize{ SliceID_TBL.clear }
- }
+ Pie_Slice_ID = ['vu:pie'.freeze, '00000'.taint].freeze
+ TkCore::INTERP.init_ip_env{ SliceID_TBL.clear }
def self.id2obj(pie, id)
pie_path = pie.path
- SliceID_TBL.mutex.synchronize{
- if SliceID_TBL[pie_path]
- SliceID_TBL[pie_path][id]? SliceID_TBL[pie_path][id]: id
- else
- id
- end
- }
+ return id unless SliceID_TBL[pie_path]
+ SliceID_TBL[pie_path][id]? SliceID_TBL[pie_path][id]: id
end
def initialize(parent, *args)
@@ -144,14 +131,10 @@ class Tk::Vu::PieSlice
end
@parent = @pie = parent
@ppath = parent.path
- Pie_Slice_ID.mutex.synchronize{
- @path = @id = Pie_Slice_ID.join(TkCore::INTERP._ip_id_)
- Pie_Slice_ID[1].succ!
- }
- SliceID_TBL.mutex.synchronize{
- SliceID_TBL[@ppath] = {} unless SliceID_TBL[@ppath]
- SliceID_TBL[@ppath][@id] = self
- }
+ @path = @id = Pie_Slice_ID.join(TkCore::INTERP._ip_id_)
+ SliceID_TBL[@ppath] = {} unless SliceID_TBL[@ppath]
+ SliceID_TBL[@ppath][@id] = self
+ Pie_Slice_ID[1].succ!
if args[-1].kind_of?(Hash)
keys = args.unshift
@@ -177,10 +160,6 @@ class Tk::Vu::PieSlice
@pie.itemcget(@id, slot)
end
- def cget_strict(slot)
- @pie.itemcget_strict(@id, slot)
- end
-
def configure(*args)
@pie.itemconfigure(@id, *args)
self
@@ -230,48 +209,22 @@ end
class Tk::Vu::NamedPieSlice
def self.new(parent, name, *args)
- obj = nil
- SliceID_TBL.mutex.synchronize{
- if SliceID_TBL[parent.path] && SliceID_TBL[parent.path][name]
- obj = SliceID_TBL[parent.path][name]
- else
- #super(parent, name, *args)
- unless parent.kind_of?(Tk::Vu::Pie)
- fail ArgumentError, "expect a Tk::Vu::Pie instance for 1st argument"
- end
- obj = self.allocate
- obj.instance_eval{
- @parent = @pie = parent
- @ppath = parent.path
- @path = @id = name.to_s
- SliceID_TBL[@ppath] = {} unless SliceID_TBL[@ppath]
- SliceID_TBL[@ppath][@id] = self
- }
- end
- }
- obj.instance_eval{
- if args[-1].kind_of?(Hash)
- keys = args.unshift
- end
- @pie.set(@id, *args)
- configure(keys)
- }
-
- obj
+ if SliceID_TBL[parent.path] && SliceID_TBL[parent.path][name]
+ return SliceID_TBL[parent.path][name]
+ else
+ super(parent, name, *args)
+ end
end
def initialize(parent, name, *args)
- # dummy:: not called by 'new' method
unless parent.kind_of?(Tk::Vu::Pie)
fail ArgumentError, "expect a Tk::Vu::Pie instance for 1st argument"
end
@parent = @pie = parent
@ppath = parent.path
@path = @id = name.to_s
- SliceID_TBL.mutex.synchronize{
- SliceID_TBL[@ppath] = {} unless SliceID_TBL[@ppath]
- SliceID_TBL[@ppath][@id] = self
- }
+ SliceID_TBL[@ppath] = {} unless SliceID_TBL[@ppath]
+ SliceID_TBL[@ppath][@id] = self
if args[-1].kind_of?(Hash)
keys = args.unshift
diff --git a/ext/tk/lib/tkextlib/vu/spinbox.rb b/ext/tk/lib/tkextlib/vu/spinbox.rb
index a7e40ea319..b6499645a3 100644
--- a/ext/tk/lib/tkextlib/vu/spinbox.rb
+++ b/ext/tk/lib/tkextlib/vu/spinbox.rb
@@ -17,6 +17,6 @@ end
module Tk
module Vu
- Spinbox = Tk::Spinbox
+ Spinbox = TkSpinbox
end
end
diff --git a/ext/tk/lib/tkextlib/winico/winico.rb b/ext/tk/lib/tkextlib/winico/winico.rb
index 00316fd441..c53a3ff48c 100644
--- a/ext/tk/lib/tkextlib/winico/winico.rb
+++ b/ext/tk/lib/tkextlib/winico/winico.rb
@@ -34,15 +34,10 @@ end
class Tk::Winico
WinicoID_TBL = TkCore::INTERP.create_table
-
- TkCore::INTERP.init_ip_env{
- WinicoID_TBL.mutex.synchronize{ WinicoID_TBL.clear }
- }
+ TkCore::INTERP.init_ip_env{ WinicoID_TBL.clear }
def self.id2obj(id)
- WinicoID_TBL.mutex.synchronize{
- (WinicoID_TBL.key?(id))? WinicoID_TBL[id] : id
- }
+ (WinicoID_TBL.key?(id))? WinicoID_TBL[id] : id
end
def self.info
@@ -86,9 +81,7 @@ class Tk::Winico
"must be given proper information from where loading icons"
end
@path = @id
- WinicoID_TBL.mutex.synchronize{
- WinicoID_TBL[@id] = self
- }
+ WinicoID_TBL[@id] = self
end
def id
@@ -103,9 +96,7 @@ class Tk::Winico
def delete
tk_call('winico', 'delete', @id)
- WinicoID_TBL.mutex.synchronize{
- WinicoID_TBL.delete(@id)
- }
+ WinicoID_TBL.delete(@id)
self
end
alias destroy delete
@@ -135,39 +126,15 @@ class Tk::Winico
[ ?n, TkComm.method(:number) ],
[ ?s, TkComm.method(:string) ],
[ ?x, proc{|id|
- Tk::Winico::WinicoID_TBL.mutex.synchronize{
- if Tk::Winico::WinicoID_TBL.key?(id)
- obj = Tk::Winico::WinicoID_TBL[id]
- else
- # Tk::Winico.new(nil, nil, id)
- obj = Tk::Winico.allocate
- obj.instance_eval{ @path = @id = id }
- Tk::Winico::WinicoID_TBL[id] = obj
- end
- obj
- }
+ if Tk::Winico::WinicoID_TBL.key?(id)
+ Tk::Winico::WinicoID_TBL[id]
+ else
+ Tk::Winico.new(nil, nil, id)
+ end
} ],
nil
]
-=begin
- # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
- KEY_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
- end
- inf
- }
-
- PROC_TBL.map!{|inf|
- if inf.kind_of?(Array)
- inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
- end
- inf
- }
-=end
-
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@@ -187,8 +154,7 @@ class Tk::Winico
Winico_callback._config_keys.each{|k|
if keys[k].kind_of?(Array)
cmd, *args = keys[k]
- #keys[k] = Winico_callback.new(cmd, args.join(' '))
- keys[k] = Winico_callback.new(cmd, *args)
+ keys[k] = Winico_callback.new(cmd, args.join(' '))
# elsif keys[k].kind_of?(Proc)
elsif TkComm._callback_entry?(keys[k])
keys[k] = Winico_callback.new(keys[k])
@@ -204,8 +170,7 @@ class Tk::Winico
Winico_callback._config_keys.each{|k|
if keys[k].kind_of?(Array)
cmd, *args = keys[k]
- #keys[k] = Winico_callback.new(cmd, args.join(' '))
- keys[k] = Winico_callback.new(cmd, *args)
+ keys[k] = Winico_callback.new(cmd, args.join(' '))
# elsif keys[k].kind_of?(Proc)
elsif TkComm._callback_entry?(keys[k])
keys[k] = Winico_callback.new(keys[k])
diff --git a/ext/tk/sample/binstr_usage.rb b/ext/tk/sample/binstr_usage.rb
index be8399ba51..91692856f9 100644
--- a/ext/tk/sample/binstr_usage.rb
+++ b/ext/tk/sample/binstr_usage.rb
@@ -16,7 +16,7 @@ to avoid such troubles. Please see the source code of this sample. \
A Tk::BinaryString instance is used to create the image for the center button.
EOM
-ImgFile=[File.dirname(__FILE__), 'images','tcllogo.gif'].join(File::Separator)
+ImgFile=['images','tcllogo.gif'].join(File::Separator)
ph1 = TkPhotoImage.new(:file=>ImgFile)
p ph1.configinfo
@@ -28,18 +28,12 @@ ph2 = TkPhotoImage.new(:data=>b_str)
p ph2.configinfo
p ph2.data(:grayscale=>true)
-ph3 = TkPhotoImage.new(:palette=>256)
-ph3.put(ph2.data)
-
-ph4 = TkPhotoImage.new()
-ph4.put(ph2.data(:grayscale=>true))
-
-#p [b_str.encoding, b_str.rb_encoding]
+ph3 = TkPhotoImage.new()
+ph3.put(ph2.data(:grayscale=>true))
f = TkFrame.new.pack
TkButton.new(:parent=>f, :image=>ph1, :command=>proc{exit}).pack(:side=>:left)
TkButton.new(:parent=>f, :image=>ph2, :command=>proc{exit}).pack(:side=>:left)
TkButton.new(:parent=>f, :image=>ph3, :command=>proc{exit}).pack(:side=>:left)
-TkButton.new(:parent=>f, :image=>ph4, :command=>proc{exit}).pack(:side=>:left)
Tk.mainloop
diff --git a/ext/tk/sample/demos-en/anilabel.rb b/ext/tk/sample/demos-en/anilabel.rb
index 0b9bc7357e..f063bc53a4 100644
--- a/ext/tk/sample/demos-en/anilabel.rb
+++ b/ext/tk/sample/demos-en/anilabel.rb
@@ -15,10 +15,8 @@ $anilabel_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($anilabel_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($anilabel_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -27,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($anilabel_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -45,8 +43,8 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# create frame for label demo
-f_left = TkLabelFrame.new(base_frame, :text=>'Scrolling Texts')
-f_right = TkLabelFrame.new(base_frame, :text=>'GIF Image')
+f_left = TkLabelFrame.new($anilabel_demo, :text=>'Scrolling Texts')
+f_right = TkLabelFrame.new($anilabel_demo, :text=>'GIF Image')
Tk.pack(f_left, f_right, 'side'=>'left', 'expand'=>'yes', 'fill'=>'both',
'padx'=>10, 'pady'=>10)
diff --git a/ext/tk/sample/demos-en/aniwave.rb b/ext/tk/sample/demos-en/aniwave.rb
index 63a04a7b98..ebe27b875f 100644
--- a/ext/tk/sample/demos-en/aniwave.rb
+++ b/ext/tk/sample/demos-en/aniwave.rb
@@ -16,10 +16,8 @@ $aniwave_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($aniwave_demo).pack(:fill=>:both, :expand=>true)
-
# create label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($aniwave_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -28,7 +26,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# create frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($aniwave_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -60,7 +58,6 @@ class AnimatedWaveDemo
@backupCoords = []
n = 0
(-10..300).step(5){|n| @waveCoords << [n, 100]; @backupCoords << [n, 100] }
- n = 305
@waveCoords << [n, 0]; @backupCoords << [n, 0]
@waveCoords << [n+5, 200]; @backupCoords << [n+5, 200]
@coordsLen = @waveCoords.length
@@ -115,4 +112,4 @@ class AnimatedWaveDemo
end
# Start the animation processing
-AnimatedWaveDemo.new(base_frame, :left).move
+AnimatedWaveDemo.new($aniwave_demo, :left).move
diff --git a/ext/tk/sample/demos-en/arrow.rb b/ext/tk/sample/demos-en/arrow.rb
index 055cd2af3c..b62e1966eb 100644
--- a/ext/tk/sample/demos-en/arrow.rb
+++ b/ext/tk/sample/demos-en/arrow.rb
@@ -77,19 +77,11 @@ def arrowSetup(c)
'arrow'=>'both', 'arrowshape'=>v.smallTips)
TkcText.new(c, v.x2-5*v.b, tmp+5, 'text'=>v.b, 'anchor'=>'n')
- if $tk_version =~ /^4.*/
- TkcText.new(c, v.x1, 310, 'text'=>"'width'=>#{v.width}", 'anchor'=>'w',
- 'font'=>'-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*')
- TkcText.new(c, v.x1, 330,
- 'text'=>"'arrowshape'=>[#{v.a}, #{v.b}, #{v.c}]",'anchor'=>'w',
- 'font'=>'-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*')
- else
- TkcText.new(c, v.x1, 310, 'text'=>"'width'=>#{v.width}", 'anchor'=>'w',
- 'font'=>'Helvetica 18')
- TkcText.new(c, v.x1, 330,
- 'text'=>"'arrowshape'=>[#{v.a}, #{v.b}, #{v.c}]",
- 'anchor'=>'w', 'font'=>'Helvetica 18')
- end
+ TkcText.new(c, v.x1, 310, 'text'=>"'width'=>#{v.width}", 'anchor'=>'w',
+ 'font'=>'-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*')
+ TkcText.new(c, v.x1, 330,
+ 'text'=>"'arrowshape'=>[#{v.a}, #{v.b}, #{v.c}]", 'anchor'=>'w',
+ 'font'=>'-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*')
v.count += 1
end
@@ -107,16 +99,14 @@ $arrow_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($arrow_demo).pack(:fill=>:both, :expand=>true)
-
# label
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
+TkLabel.new($arrow_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
'text'=>"This widget allows you to experiment with different widths and arrowhead shapes for lines in canvases. To change the line width or the shape of the arrowhead, drag any of the three boxes attached to the oversized arrow. The arrows on the right give examples at normal scale. The text at the bottom shows the configuration options as you'd enter them for a canvas line item."){
pack('side'=>'top')
}
# frame
-$arrow_buttons = TkFrame.new(base_frame) {|frame|
+$arrow_buttons = TkFrame.new($arrow_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -134,7 +124,7 @@ $arrow_buttons = TkFrame.new(base_frame) {|frame|
$arrow_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# canvas
-$arrow_canvas = TkCanvas.new(base_frame, 'width'=>500, 'height'=>350,
+$arrow_canvas = TkCanvas.new($arrow_demo, 'width'=>500, 'height'=>350,
'relief'=>'sunken', 'borderwidth'=>2)
$arrow_canvas.pack('expand'=>'yes', 'fill'=>'both')
diff --git a/ext/tk/sample/demos-en/bind.rb b/ext/tk/sample/demos-en/bind.rb
index 665592a2bc..aabe7f0849 100644
--- a/ext/tk/sample/demos-en/bind.rb
+++ b/ext/tk/sample/demos-en/bind.rb
@@ -19,10 +19,8 @@ $bind_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($bind_demo).pack(:fill=>:both, :expand=>true)
-
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($bind_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -45,14 +43,14 @@ def tag_binding_for_bind_demo(tag, enter_style, leave_style)
end
# text
-txt = TkText.new(base_frame){|t|
+TkText.new($bind_demo){|t|
#
setgrid 'true'
- #width 60
- #height 24
+ width 60
+ height 24
font $font
wrap 'word'
- TkScrollbar.new(base_frame) {|s|
+ TkScrollbar.new($bind_demo) {|s|
pack('side'=>'right', 'fill'=>'y')
command proc{|*args| t.yview(*args)}
t.yscrollcommand proc{|first,last| s.set first,last}
@@ -96,32 +94,35 @@ txt = TkText.new(base_frame){|t|
}
d1.bind('1',
proc{
- eval_samplecode(`cat #{[$demo_dir,'items.rb'].join(File::Separator)}`, 'items.rb')
+ eval(`cat #{[$demo_dir,'items.rb'].join(File::Separator)}`,
+ _null_binding)
})
d2.bind('1',
proc{
- eval_samplecode(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)}`, 'plot.rb')
+ eval(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)}`,
+ _null_binding)
})
d3.bind('1',
proc{
- eval_samplecode(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)}`, 'ctext.rb')
+ eval(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)}`,
+ _null_binding)
})
d4.bind('1',
proc{
- eval_samplecode(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)}`, 'arrow.rb')
+ eval(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)}`,
+ _null_binding)
})
d5.bind('1',
proc{
- eval_samplecode(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)}`, 'ruler.rb')
+ eval(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)}`,
+ _null_binding)
})
d6.bind('1',
proc{
- eval_samplecode(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)}`, 'cscroll.rb')
+ eval(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)}`,
+ _null_binding)
})
TkTextMarkInsert.new(t, '0.0')
configure('state','disabled')
}
-
-txt.width 60
-txt.height 24
diff --git a/ext/tk/sample/demos-en/bitmap.rb b/ext/tk/sample/demos-en/bitmap.rb
index 133adb0543..7fd551c7a5 100644
--- a/ext/tk/sample/demos-en/bitmap.rb
+++ b/ext/tk/sample/demos-en/bitmap.rb
@@ -21,7 +21,7 @@ def bitmapRow(w,*args)
TkFrame.new(row){|base|
pack('side'=>'left', 'fill'=>'both', 'pady'=>'.25c', 'padx'=>'.25c')
TkLabel.new(base, 'text'=>bitmap, 'width'=>9).pack('side'=>'bottom')
- Tk::Label.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom')
+ TkLabel.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom')
}
end
}
@@ -40,16 +40,14 @@ $bitmap_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($bitmap_demo).pack(:fill=>:both, :expand=>true)
-
# label
-TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
+TkLabel.new($bitmap_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
'text'=>"This window displays all of Tk's built-in bitmaps, along with the names you can use for them in Tcl scripts."){
pack('side'=>'top')
}
# frame
-$bitmap_buttons = TkFrame.new(base_frame) {|frame|
+$bitmap_buttons = TkFrame.new($bitmap_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -67,7 +65,7 @@ $bitmap_buttons = TkFrame.new(base_frame) {|frame|
$bitmap_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
-TkFrame.new(base_frame){|f|
+TkFrame.new($bitmap_demo){|f|
bitmapRow(f,'error','gray25','gray50','hourglass')
bitmapRow(f,'info','question','questhead','warning')
pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both')
diff --git a/ext/tk/sample/demos-en/button.rb b/ext/tk/sample/demos-en/button.rb
index 5c03bd499b..6614d99c92 100644
--- a/ext/tk/sample/demos-en/button.rb
+++ b/ext/tk/sample/demos-en/button.rb
@@ -29,7 +29,7 @@ msg = TkLabel.new($button_demo) {
msg.pack('side'=>'top')
# frame
-$button_buttons = Tk::Frame.new($button_demo) {|frame|
+$button_buttons = TkFrame.new($button_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
diff --git a/ext/tk/sample/demos-en/check.rb b/ext/tk/sample/demos-en/check.rb
index 2951962a79..971a8fea73 100644
--- a/ext/tk/sample/demos-en/check.rb
+++ b/ext/tk/sample/demos-en/check.rb
@@ -19,10 +19,8 @@ $check_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($check_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($check_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -36,7 +34,7 @@ brakes = TkVariable.new(0)
sober = TkVariable.new(0)
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($check_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -56,7 +54,7 @@ TkFrame.new(base_frame) {|frame|
TkButton.new(frame) {
text 'See Variables'
command proc{
- showVars(base_frame,
+ showVars($check_demo,
['wipers', wipers], ['brakes', brakes], ['sober', sober])
}
}.pack('side'=>'left', 'expand'=>'yes')
@@ -65,8 +63,8 @@ TkFrame.new(base_frame) {|frame|
# checkbutton
-[ TkCheckButton.new(base_frame, 'text'=>'Wipers OK', 'variable'=>wipers),
- TkCheckButton.new(base_frame, 'text'=>'Brakes OK', 'variable'=>brakes),
- TkCheckButton.new(base_frame, 'text'=>'Driver Sober', 'variable'=>sober)
+[ TkCheckButton.new($check_demo, 'text'=>'Wipers OK', 'variable'=>wipers),
+ TkCheckButton.new($check_demo, 'text'=>'Brakes OK', 'variable'=>brakes),
+ TkCheckButton.new($check_demo, 'text'=>'Driver Sober', 'variable'=>sober)
].each{|w| w.relief('flat'); w.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w')}
diff --git a/ext/tk/sample/demos-en/check2.rb b/ext/tk/sample/demos-en/check2.rb
index faea748a87..97d61fba0c 100644
--- a/ext/tk/sample/demos-en/check2.rb
+++ b/ext/tk/sample/demos-en/check2.rb
@@ -15,10 +15,8 @@ $check2_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($check2_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($check2_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -33,7 +31,7 @@ brakes = TkVariable.new(0)
sober = TkVariable.new(0)
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($check2_demo) {|frame|
TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2),
:columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
TkGrid('x',
@@ -61,15 +59,15 @@ TkFrame.new(base_frame) {|frame|
# checkbutton
-TkCheckButton.new(base_frame, :text=>'Safety Check', :variable=>safety,
+TkCheckButton.new($check2_demo, :text=>'Safety Check', :variable=>safety,
:relief=>:flat, :onvalue=>'all', :offvalue=>'none',
:tristatevalue=>'partial'){
pack('side'=>'top', 'pady'=>2, 'anchor'=>'w')
}
-[ TkCheckButton.new(base_frame, 'text'=>'Wipers OK', 'variable'=>wipers),
- TkCheckButton.new(base_frame, 'text'=>'Brakes OK', 'variable'=>brakes),
- TkCheckButton.new(base_frame, 'text'=>'Driver Sober', 'variable'=>sober)
+[ TkCheckButton.new($check2_demo, 'text'=>'Wipers OK', 'variable'=>wipers),
+ TkCheckButton.new($check2_demo, 'text'=>'Brakes OK', 'variable'=>brakes),
+ TkCheckButton.new($check2_demo, 'text'=>'Driver Sober', 'variable'=>sober)
].each{|w|
w.relief('flat')
w.pack('side'=>'top', 'padx'=>15, 'pady'=>2, 'anchor'=>'w')
diff --git a/ext/tk/sample/demos-en/clrpick.rb b/ext/tk/sample/demos-en/clrpick.rb
index 431439d55d..9486fde314 100644
--- a/ext/tk/sample/demos-en/clrpick.rb
+++ b/ext/tk/sample/demos-en/clrpick.rb
@@ -4,8 +4,6 @@
#
# widget demo prompts the user to select a color (called by 'widget')
#
-# Note: don't support ttk_wrapper. work with standard widgets only.
-#
# toplevel widget
if defined?($clrpick_demo) && $clrpick_demo
@@ -20,18 +18,13 @@ $clrpick_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($clrpick_demo).pack(:fill=>:both, :expand=>true)
-
# label
-#TkLabel.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
-Tk::Label.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
+TkLabel.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
'text'=>"Press the buttons below to choose the foreground and background colors for the widgets in this window.").pack('side'=>'top')
# frame
-#TkFrame.new($clrpick_demo) {|frame|
-Tk::Frame.new($clrpick_demo) {|frame|
- # TkButton.new(frame) {
- Tk::Button.new(frame) {
+TkFrame.new($clrpick_demo) {|frame|
+ TkButton.new(frame) {
text 'Dismiss'
command proc{
tmppath = $clrpick_demo
@@ -40,23 +33,20 @@ Tk::Frame.new($clrpick_demo) {|frame|
}
}.pack('side'=>'left', 'expand'=>'yes')
- # TkButton.new(frame) {
- Tk::Button.new(frame) {
+ TkButton.new(frame) {
text 'Show Code'
command proc{showCode 'clrpick'}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# button
-# TkButton.new($clrpick_demo, 'text'=>'Set background color ...') {|b|
-Tk::Button.new($clrpick_demo, 'text'=>'Set background color ...') {|b|
+TkButton.new($clrpick_demo, 'text'=>'Set background color ...') {|b|
command(proc{setColor $clrpick_demo, b, 'background',
['background', 'highlightbackground']})
pack('side'=>'top', 'anchor'=>'c', 'pady'=>'2m')
}
-# TkButton.new($clrpick_demo, 'text'=>'Set foreground color ...') {|b|
-Tk::Button.new($clrpick_demo, 'text'=>'Set foreground color ...') {|b|
+TkButton.new($clrpick_demo, 'text'=>'Set foreground color ...') {|b|
command(proc{setColor $clrpick_demo, b, 'foreground', ['foreground']})
pack('side'=>'top', 'anchor'=>'c', 'pady'=>'2m')
}
diff --git a/ext/tk/sample/demos-en/colors.rb b/ext/tk/sample/demos-en/colors.rb
index 4300a660ae..66fb0afa36 100644
--- a/ext/tk/sample/demos-en/colors.rb
+++ b/ext/tk/sample/demos-en/colors.rb
@@ -20,10 +20,8 @@ $colors_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($colors_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($colors_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -32,7 +30,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($colors_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -51,7 +49,7 @@ TkFrame.new(base_frame) {|frame|
# frame
colors_lbox = nil
-TkFrame.new(base_frame, 'borderwidth'=>10) {|w|
+TkFrame.new($colors_demo, 'borderwidth'=>10) {|w|
s = TkScrollbar.new(w)
colors_lbox = TkListbox.new(w) {
setgrid 1
@@ -64,15 +62,7 @@ TkFrame.new(base_frame, 'borderwidth'=>10) {|w|
colors_lbox.pack('side'=>'left', 'expand'=>1, 'fill'=>'both')
}.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'y')
-#colors_lbox.bind('Double-1', proc{TkPalette.setPalette TkSelection.get})
-colors_lbox.bind('Double-1', proc{
- begin
- TkPalette.setPalette TkSelection.get
- rescue => e
- p e
- Tk.tk_call_without_enc('destroy', '.___tk_set_palette')
- end
- })
+colors_lbox.bind('Double-1', proc{TkPalette.setPalette TkSelection.get})
ins_data = [
'gray60','gray70','gray80','gray85','gray90','gray95',
diff --git a/ext/tk/sample/demos-en/combo.rb b/ext/tk/sample/demos-en/combo.rb
deleted file mode 100644
index 0907d9e8ec..0000000000
--- a/ext/tk/sample/demos-en/combo.rb
+++ /dev/null
@@ -1,96 +0,0 @@
-# combo.rb --
-#
-# This demonstration script creates several combobox widgets.
-#
-# based on "Id: combo.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($combo_demo) && $combo_demo
- $combo_demo.destroy
- $combo_demo = nil
-end
-
-$combo_demo = TkToplevel.new {|w|
- title("Combobox Demonstration")
- iconname("combo")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($combo_demo).pack(:fill=>:both, :expand=>true)
-
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'5i', :justify=>:left,
- :text=><<EOL).pack(:side=>:top, :fill=>:x)
-Three different combo-boxes are displayed below. \
-You can add characters to the first \
-one by pointing, clicking and typing, just as with an entry; pressing \
-Return will cause the current value to be added to the list that is \
-selectable from the drop-down list, and you can choose other values \
-by pressing the Down key, using the arrow keys to pick another one, \
-and pressing Return again. The second combo-box is fixed to a \
-particular value, and cannot be modified at all. The third one only \
-allows you to select values from its drop-down list of Australian \
-cities.
-EOL
-
-## variables
-firstValue = TkVariable.new
-secondValue = TkVariable.new
-ozCity = TkVariable.new
-
-## See Code / Dismiss buttons
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'See Variables',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{
- showVars(base_frame,
- ['firstVariable', firstValue],
- ['secondVariable', secondValue],
- ['ozCity', ozCity])
- }),
- Ttk::Button.new(frame, :text=>'See Code',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'combo'}),
- Ttk::Button.new(frame, :text=>'Dismiss',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $combo_demo.destroy
- $combo_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
-
-australianCities = [
- 'Canberra', 'Sydney', 'Melbourne', 'Perth', 'Adelaide', 'Brisbane',
- 'Hobart', 'Darwin', 'Alice Springs'
-]
-
-
-secondValue.value = 'unchangable'
-ozCity.value = 'Sydney'
-
-Tk.pack(Ttk::Labelframe.new(frame, :text=>'Fully Editable'){|f|
- Ttk::Combobox.new(f, :textvariable=>firstValue){|b|
- b.bind('Return', '%W'){|w|
- w.values <<= w.value unless w.values.include?(w.value)
- }
- }.pack(:pady=>5, :padx=>10)
- },
-
- Ttk::LabelFrame.new(frame, :text=>'Disabled'){|f|
- Ttk::Combobox.new(f, :textvariable=>secondValue, :state=>:disabled) .
- pack(:pady=>5, :padx=>10)
- },
-
- Ttk::LabelFrame.new(frame, :text=>'Defined List Only'){|f|
- Ttk::Combobox.new(f, :textvariable=>ozCity, :state=>:readonly,
- :values=>australianCities) .
- pack(:pady=>5, :padx=>10)
- },
-
- :side=>:top, :pady=>5, :padx=>10)
diff --git a/ext/tk/sample/demos-en/cscroll.rb b/ext/tk/sample/demos-en/cscroll.rb
index 259ed3bd8c..0838dfbe08 100644
--- a/ext/tk/sample/demos-en/cscroll.rb
+++ b/ext/tk/sample/demos-en/cscroll.rb
@@ -19,16 +19,14 @@ $cscroll_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($cscroll_demo).pack(:fill=>:both, :expand=>true)
-
# label
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i',
+TkLabel.new($cscroll_demo, 'font'=>$font, 'wraplength'=>'4i',
'justify'=>'left', 'text'=>"This window displays a canvas widget that can be scrolled either using the scrollbars or by dragging with button 2 in the canvas. If you click button 1 on one of the rectangles, its indices will be printed on stdout."){
pack('side'=>'top')
}
# frame
-$cscroll_buttons = TkFrame.new(base_frame) {|frame|
+$cscroll_buttons = TkFrame.new($cscroll_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -47,7 +45,7 @@ $cscroll_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
unless $tk_version =~ /^4\.[01]/
- $cscroll_grid = TkFrame.new(base_frame) {
+ $cscroll_grid = TkFrame.new($cscroll_demo) {
pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>1)
}
TkGrid.rowconfigure($cscroll_grid, 0, 'weight'=>1, 'minsize'=>0)
@@ -55,7 +53,7 @@ unless $tk_version =~ /^4\.[01]/
end
# canvas
-$cscroll_canvas = TkCanvas.new(base_frame,
+$cscroll_canvas = TkCanvas.new($cscroll_demo,
'relief'=>'sunken', 'borderwidth'=>2,
'scrollregion'=>['-11c', '-11c', '50c', '20c']
) {|c|
@@ -66,7 +64,7 @@ $cscroll_canvas = TkCanvas.new(base_frame,
'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
end
- TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}) {|vs|
+ TkScrollbar.new($cscroll_demo, 'command'=>proc{|*args| c.yview(*args)}) {|vs|
c.yscrollcommand(proc{|first,last| vs.set first,last})
if $tk_version =~ /^4\.[01]/
pack('side'=>'right', 'fill'=>'y')
@@ -76,7 +74,7 @@ $cscroll_canvas = TkCanvas.new(base_frame,
end
}
- TkScrollbar.new(base_frame, 'orient'=>'horiz',
+ TkScrollbar.new($cscroll_demo, 'orient'=>'horiz',
'command'=>proc{|*args| c.xview(*args)}) {|hs|
c.xscrollcommand(proc{|first,last| hs.set first,last})
if $tk_version =~ /^4\.[01]/
diff --git a/ext/tk/sample/demos-en/ctext.rb b/ext/tk/sample/demos-en/ctext.rb
index 01374b0321..dbb5e32638 100644
--- a/ext/tk/sample/demos-en/ctext.rb
+++ b/ext/tk/sample/demos-en/ctext.rb
@@ -19,10 +19,8 @@ $ctext_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($ctext_demo).pack(:fill=>:both, :expand=>true)
-
# label
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
+TkLabel.new($ctext_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
'text'=>"This window displays a string of text to demonstrate the text facilities of canvas widgets. You can click in the boxes to adjust the position of the text relative to its positioning point or change its justification. The text also supports the following simple bindings for editing:
1. You can point, click, and type.
2. You can also select with button 1.
@@ -35,7 +33,7 @@ TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
}
# frame
-$ctext_buttons = TkFrame.new(base_frame) {|frame|
+$ctext_buttons = TkFrame.new($ctext_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -53,33 +51,24 @@ $ctext_buttons = TkFrame.new(base_frame) {|frame|
$ctext_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# canvas
-$ctext_canvas = TkCanvas.new(base_frame, 'relief'=>'flat',
+$ctext_canvas = TkCanvas.new($ctext_demo, 'relief'=>'flat',
'borderwidth'=>0, 'width'=>500, 'height'=>350)
$ctext_canvas.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both')
# font
-if $tk_version =~ /^4.*/
- textFont = '-*-Helvetica-Medium-R-Normal--*-240-*-*-*-*-*-*'
-else
- textFont = 'Helvetica 24'
-end
+textFont = '-*-Helvetica-Medium-R-Normal--*-240-*-*-*-*-*-*'
# canvas
TkcRectangle.new($ctext_canvas, 245, 195, 255, 205,
'outline'=>'black', 'fill'=>'red')
-ctag_text_param = {
- 'text'=>"This is just a string of text to demonstrate the text facilities of canvas widgets. Bindings have been been defined to support editing (see above).",
- 'width'=>440, 'anchor'=>'n', 'justify'=>'left'
-}
-if $tk_version =~ /^4.*/
- ctag_text_param['font'] = '-*-Helvetica-Medium-R-Normal--*-240-*-*-*-*-*-*'
-else
- ctag_text_param['font'] = 'Helvetica 24'
-end
-
$ctag_text = TkcTag.new($ctext_canvas)
-$ctag_text.withtag(TkcText.new($ctext_canvas, 250, 200, ctag_text_param))
+$ctag_text.withtag(TkcText.new($ctext_canvas, 250, 200,
+ 'text'=>"This is just a string of text to demonstrate the text facilities of canvas widgets. Bindings have been been defined to support editing (see above).",
+ 'width'=>440, 'anchor'=>'n',
+ 'font'=>'-*-Helvetica-Medium-R-Normal--*-240-*-*-*-*-*-*',
+ 'kanjifont'=>'-*--24-*-jisx0208.1983-0',
+ 'justify'=>'left') )
$ctag_text.bind('1', proc{|x,y| textB1Press $ctext_canvas,x,y}, "%x %y")
$ctag_text.bind('B1-Motion', proc{|x,y| textB1Move $ctext_canvas,x,y}, "%x %y")
@@ -121,14 +110,9 @@ mkTextConfig $ctext_canvas, x+60, y+60, 'anchor', 'nw', color
item = TkcRectangle.new($ctext_canvas, x+40, y+40, x+50, y+50,
'outline'=>'black', 'fill'=>'red')
item.bind('1', proc{$ctag_text.configure 'anchor', 'center'})
-if $tk_version =~ /^4.*/
- TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Text Position',
- 'font'=>'-*-times-medium-r-normal--*-240-*-*-*-*-*-*',
- 'anchor'=>'s', 'fill'=>'brown')
-else
- TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Text Position',
- 'font'=>'Times 24', 'anchor'=>'s', 'fill'=>'brown')
-end
+TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Text Position', 'anchor'=>'s',
+ 'font'=>'-*-times-medium-r-normal--*-240-*-*-*-*-*-*',
+ 'fill'=>'brown')
# Lastly, create some items that allow the text's justification to be
# changed.
@@ -139,14 +123,9 @@ color = 'SeaGreen2'
mkTextConfig $ctext_canvas, x, y, 'justify', 'left', color
mkTextConfig $ctext_canvas, x+30, y, 'justify', 'center', color
mkTextConfig $ctext_canvas, x+60, y, 'justify', 'right', color
-if $tk_version =~ /^4.*/
- TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Justification',
- 'font'=>'-*-times-medium-r-normal--*-240-*-*-*-*-*-*',
- 'anchor'=>'s', 'fill'=>'brown')
-else
- TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Justification',
- 'font'=>'Times 24', 'anchor'=>'s', 'fill'=>'brown')
-end
+TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Justification', 'anchor'=>'s',
+ 'font'=>'-*-times-medium-r-normal--*-240-*-*-*-*-*-*',
+ 'fill'=>'brown')
$ctext_canvas.itembind('config', 'Enter', proc{textEnter $ctext_canvas})
$ctext_canvas.itembind('config', 'Leave',
diff --git a/ext/tk/sample/demos-en/entry1.rb b/ext/tk/sample/demos-en/entry1.rb
index 6f5b10fb71..29bc693395 100644
--- a/ext/tk/sample/demos-en/entry1.rb
+++ b/ext/tk/sample/demos-en/entry1.rb
@@ -15,10 +15,8 @@ $entry1_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($entry1_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($entry1_demo) {
font $font
wraplength '5i'
justify 'left'
@@ -27,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($entry1_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -44,9 +42,9 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
#
-e1 = TkEntry.new(base_frame, 'relief'=>'sunken')
-e2 = TkEntry.new(base_frame, 'relief'=>'sunken')
-e3 = TkEntry.new(base_frame, 'relief'=>'sunken')
+e1 = TkEntry.new($entry1_demo, 'relief'=>'sunken')
+e2 = TkEntry.new($entry1_demo, 'relief'=>'sunken')
+e3 = TkEntry.new($entry1_demo, 'relief'=>'sunken')
[e1,e2,e3].each{|w| w.pack('side'=>'top', 'padx'=>10, 'pady'=>5, 'fill'=>'x')}
#
diff --git a/ext/tk/sample/demos-en/entry2.rb b/ext/tk/sample/demos-en/entry2.rb
index d67d04b56d..d4e58d7dd5 100644
--- a/ext/tk/sample/demos-en/entry2.rb
+++ b/ext/tk/sample/demos-en/entry2.rb
@@ -19,10 +19,8 @@ $entry2_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($entry2_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($entry2_demo) {
font $font
wraplength '5i'
justify 'left'
@@ -31,7 +29,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($entry2_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -48,7 +46,7 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
-TkFrame.new(base_frame, 'borderwidth'=>10) {|w|
+TkFrame.new($entry2_demo, 'borderwidth'=>10) {|w|
# entry 1
s1 = TkScrollbar.new(w, 'relief'=>'sunken', 'orient'=>'horiz')
e1 = TkEntry.new(w, 'relief'=>'sunken') {
diff --git a/ext/tk/sample/demos-en/entry3.rb b/ext/tk/sample/demos-en/entry3.rb
index f7df3a5653..415b45f86c 100644
--- a/ext/tk/sample/demos-en/entry3.rb
+++ b/ext/tk/sample/demos-en/entry3.rb
@@ -17,9 +17,7 @@ $entry3_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($entry3_demo).pack(:fill=>:both, :expand=>true)
-
-TkLabel.new(base_frame,
+TkLabel.new($entry3_demo,
:font=>$font, :wraplength=>'5i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
Four different entries are displayed below. You can add characters \
@@ -30,13 +28,13 @@ problem. The second only accepts strings with fewer than ten \
characters and sounds the bell when an attempt to go over the limit \
is made. The third accepts US phone numbers, mapping letters to \
their digit equivalent and sounding the bell on encountering an \
-invalid character or if trying to type over a character that is not \
+illegal character or if trying to type over a character that is not \
a digit. The fourth is a password field that accepts up to eight \
characters (silently ignoring further ones), and displaying them as \
asterisk characters.
EOL
-TkFrame.new(base_frame){|f|
+TkFrame.new($entry3_demo){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{
@@ -62,41 +60,23 @@ TkFrame.new(base_frame){|f|
# count - Counter to control the number of times flashed
def focusAndFlash(widget, fg, bg, count=5)
return if count <= 0
- if fg && !fg.empty? && bg && !bg.empty?
- TkTimer.new(200, count,
- proc{widget.configure(:foreground=>bg, :background=>fg)},
- proc{widget.configure(:foreground=>fg, :background=>bg)}
- ).start
- else
- # TkTimer.new(150, 3){Tk.bell}.start
- Tk.bell
- TkTimer.new(200, count,
- proc{widget.configure(:foreground=>'white',
- :background=>'black')},
- proc{widget.configure(:foreground=>'black',
- :background=>'white')}
- ).at_end{begin
- widget.configure(:foreground=>fg,
- :background=>bg)
- rescue
- # ignore
- end}.start
- end
+ TkTimer.new(200, count,
+ proc{widget.configure(:foreground=>bg, :background=>fg)},
+ proc{widget.configure(:foreground=>fg, :background=>bg)}
+ ).start
widget.focus(true)
end
-l1 = TkLabelFrame.new(base_frame, :text=>"Integer Entry")
+l1 = TkLabelFrame.new($entry3_demo, :text=>"Integer Entry")
TkEntry.new(l1, :validate=>:focus,
:vcmd=>[
proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P'
]) {|e|
- fg = e.foreground
- bg = e.background
- invalidcommand [proc{|w| focusAndFlash(w, fg, bg)}, '%W']
+ invalidcommand [proc{|w| focusAndFlash(w, e.fg, e.bg)}, '%W']
pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
}
-l2 = TkLabelFrame.new(base_frame, :text=>"Length-Constrained Entry")
+l2 = TkLabelFrame.new($entry3_demo, :text=>"Length-Constrained Entry")
TkEntry.new(l2, :validate=>:key, :invcmd=>proc{Tk.bell},
:vcmd=>[proc{|s| s.length < 10}, '%P']
).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
@@ -178,14 +158,14 @@ def validatePhoneChange(widget, vmode, idx, char)
widget.insert(idx, $phoneNumberMap[char] || char)
Tk.after_idle(proc{phoneSkipRight(widget, -1)})
return true
- # Tk.update(true) # <- Don't work 'update' inter validation callback.
- # It depends on Tcl/Tk side (tested on Tcl/Tk8.5a1).
+ # Tk.update(true) # Don't work 'update' inter validation callback.
+ # It depends on Tcl/Tk side (tested on Tcl/Tk8.5a1).
end
return false
end
-l3 = TkLabelFrame.new(base_frame, :text=>"US Phone-Number Entry")
+l3 = TkLabelFrame.new($entry3_demo, :text=>"US Phone-Number Entry")
TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell},
:textvariable=>entry3content,
:vcmd=>[
@@ -204,14 +184,14 @@ TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell},
pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
}
-l4 = TkLabelFrame.new(base_frame, :text=>"Password Entry")
+l4 = TkLabelFrame.new($entry3_demo, :text=>"Password Entry")
TkEntry.new(l4, :validate=>:key, :show=>'*',
:vcmd=>[
proc{|s| s.length <= 8},
'%P'
]).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
-TkFrame.new(base_frame){|f|
+TkFrame.new($entry3_demo){|f|
lower
TkGrid.configure(l1, l2, :in=>f, :padx=>'3m', :pady=>'1m', :sticky=>:ew)
TkGrid.configure(l3, l4, :in=>f, :padx=>'3m', :pady=>'1m', :sticky=>:ew)
diff --git a/ext/tk/sample/demos-en/filebox.rb b/ext/tk/sample/demos-en/filebox.rb
index 676c347409..36b19de557 100644
--- a/ext/tk/sample/demos-en/filebox.rb
+++ b/ext/tk/sample/demos-en/filebox.rb
@@ -17,14 +17,12 @@ $filebox_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($filebox_demo).pack(:fill=>:both, :expand=>true)
-
# label
-TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
+TkLabel.new($filebox_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
'text'=>"Enter a file name in the entry box or click on the \"Browse\" buttons to select a file name using the file selection dialog.").pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($filebox_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -42,7 +40,7 @@ TkFrame.new(base_frame) {|frame|
# frame
['open', 'save'].each{|type|
- TkFrame.new(base_frame) {|f|
+ TkFrame.new($filebox_demo) {|f|
TkLabel.new(f, 'text'=>"Select a file to #{type}: ", 'anchor'=>'e')\
.pack('side'=>'left')
@@ -50,7 +48,7 @@ TkFrame.new(base_frame) {|frame|
pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x')
TkButton.new(f, 'text'=>'Browse ...',
- 'command'=>proc{fileDialog base_frame,e,type})\
+ 'command'=>proc{fileDialog $filebox_demo,e,type})\
.pack('side'=>'left')
}
@@ -60,7 +58,7 @@ TkFrame.new(base_frame) {|frame|
$tk_strictMotif = TkVarAccess.new('tk_strictMotif')
if ($tk_platform['platform'] == 'unix')
- TkCheckButton.new(base_frame,
+ TkCheckButton.new($filebox_demo,
'text'=>'Use Motif Style Dialog',
'variable'=>$tk_strictMotif,
'onvalue'=>1, 'offvalue'=>0 ).pack('anchor'=>'c')
@@ -93,10 +91,7 @@ def fileDialog(w,ent,operation)
if file != ""
ent.delete 0, 'end'
ent.insert 0, file
- # ent.xview 'end'
- Tk.update_idletasks # need this for Tk::Tile::Entry
- # (to find right position of 'xview').
- ent.xview(ent.index('end'))
+ ent.xview 'end'
end
end
diff --git a/ext/tk/sample/demos-en/floor.rb b/ext/tk/sample/demos-en/floor.rb
index 7023f2a72e..53adcf96b6 100644
--- a/ext/tk/sample/demos-en/floor.rb
+++ b/ext/tk/sample/demos-en/floor.rb
@@ -1590,16 +1590,14 @@ $floor_demo = TkToplevel.new {|w|
minsize(100,100)
}
-base_frame = TkFrame.new($floor_demo).pack(:fill=>:both, :expand=>true)
-
# label
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left',
+TkLabel.new($floor_demo, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left',
'text'=>"This window contains a canvas widget showing the floorplan of Digital Equipment Corporation's Western Research Laboratory. It has three levels. At any given time one of the levels is active, meaning that you can see its room structure. To activate a level, click the left mouse button anywhere on it. As the mouse moves over the active level, the room under the mouse lights up and its room number appears in the \"Room:\" entry. You can also type a room number in the entry and the room will light up."){
pack('side'=>'top')
}
# frame
-$floor_buttons = TkFrame.new(base_frame) {|frame|
+$floor_buttons = TkFrame.new($floor_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -1622,17 +1620,17 @@ $floorItems = {}
# canvas
if $tk_version =~ /^4\.[01]/
- $floor_canvas_frame = TkFrame.new(base_frame,'bd'=>2,'relief'=>'sunken',
+ $floor_canvas_frame = TkFrame.new($floor_demo,'bd'=>2,'relief'=>'sunken',
'highlightthickness'=>2)
$floor_canvas = TkCanvas.new($floor_canvas_frame,
'width'=>900, 'height'=>500, 'borderwidth'=>0,
'highlightthickness'=>0) {|c|
- TkScrollbar.new(base_frame, 'orient'=>'horiz',
+ TkScrollbar.new($floor_demo, 'orient'=>'horiz',
'command'=>proc{|*args| c.xview(*args)}){|hs|
c.xscrollcommand(proc{|first,last| hs.set first,last})
pack('side'=>'bottom', 'fill'=>'x')
}
- TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}){|vs|
+ TkScrollbar.new($floor_demo, 'command'=>proc{|*args| c.yview(*args)}){|vs|
c.yscrollcommand(proc{|first,last| vs.set first,last})
pack('side'=>'right', 'fill'=>'y')
}
@@ -1641,7 +1639,7 @@ if $tk_version =~ /^4\.[01]/
$floor_canvas.pack('expand'=>'yes', 'fill'=>'both')
else
- TkFrame.new(base_frame) {|f|
+ TkFrame.new($floor_demo) {|f|
pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes')
h = TkScrollbar.new(f, 'highlightthickness'=>0, 'orient'=>'horizontal')
diff --git a/ext/tk/sample/demos-en/floor2.rb b/ext/tk/sample/demos-en/floor2.rb
index 88b07aeee4..efaf9e250d 100644
--- a/ext/tk/sample/demos-en/floor2.rb
+++ b/ext/tk/sample/demos-en/floor2.rb
@@ -1590,16 +1590,14 @@ $floor2_demo = TkToplevel.new {|w|
minsize(100,100)
}
-base_frame = TkFrame.new($floor2_demo).pack(:fill=>:both, :expand=>true)
-
# label
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left',
+TkLabel.new($floor2_demo, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left',
'text'=>"This window contains a canvas widget showing the floorplan of Digital Equipment Corporation's Western Research Laboratory. It has three levels. At any given time one of the levels is active, meaning that you can see its room structure. To activate a level, click the left mouse button anywhere on it. As the mouse moves over the active level, the room under the mouse lights up and its room number appears in the \"Room:\" entry. You can also type a room number in the entry and the room will light up."){
pack('side'=>'top')
}
# frame
-$floor2_buttons = TkFrame.new(base_frame) {|frame|
+$floor2_buttons = TkFrame.new($floor2_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -1622,17 +1620,17 @@ $floorItems2 = {}
# canvas
if $tk_version =~ /^4\.[01]/
- $floor2_canvas_frame = TkFrame.new(base_frame,'bd'=>2,'relief'=>'sunken',
+ $floor2_canvas_frame = TkFrame.new($floor2_demo,'bd'=>2,'relief'=>'sunken',
'highlightthickness'=>2)
$floor2_canvas = TkCanvas.new($floor2_canvas_frame,
'width'=>900, 'height'=>500, 'borderwidth'=>0,
'highlightthickness'=>0) {|c|
- TkScrollbar.new(base_frame, 'orient'=>'horiz',
+ TkScrollbar.new($floor2_demo, 'orient'=>'horiz',
'command'=>proc{|*args| c.xview(*args)}){|hs|
c.xscrollcommand(proc{|first,last| hs.set first,last})
pack('side'=>'bottom', 'fill'=>'x')
}
- TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}){|vs|
+ TkScrollbar.new($floor2_demo, 'command'=>proc{|*args| c.yview(*args)}){|vs|
c.yscrollcommand(proc{|first,last| vs.set first,last})
pack('side'=>'right', 'fill'=>'y')
}
@@ -1641,7 +1639,7 @@ if $tk_version =~ /^4\.[01]/
$floor2_canvas.pack('expand'=>'yes', 'fill'=>'both')
else
- TkFrame.new(base_frame) {|f|
+ TkFrame.new($floor2_demo) {|f|
pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes')
h = TkScrollbar.new(f, 'highlightthickness'=>0, 'orient'=>'horizontal')
diff --git a/ext/tk/sample/demos-en/form.rb b/ext/tk/sample/demos-en/form.rb
index 3119752b1c..dbb14302dc 100644
--- a/ext/tk/sample/demos-en/form.rb
+++ b/ext/tk/sample/demos-en/form.rb
@@ -15,10 +15,8 @@ $form_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($form_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($form_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -27,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top', 'fill'=>'x')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($form_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -46,7 +44,7 @@ TkFrame.new(base_frame) {|frame|
# entry
form_data = []
(1..5).each{|i|
- f = TkFrame.new(base_frame, 'bd'=>2)
+ f = TkFrame.new($form_demo, 'bd'=>2)
e = TkEntry.new(f, 'relief'=>'sunken', 'width'=>40)
l = TkLabel.new(f)
e.pack('side'=>'right')
diff --git a/ext/tk/sample/demos-en/goldberg.rb b/ext/tk/sample/demos-en/goldberg.rb
index c6fa37c09c..8d3f6d14f7 100644
--- a/ext/tk/sample/demos-en/goldberg.rb
+++ b/ext/tk/sample/demos-en/goldberg.rb
@@ -54,8 +54,6 @@ $goldberg_demo = TkToplevel.new {|w|
# positionWindow(w)
}
-base_frame = TkFrame.new($goldberg_demo).pack(:fill=>:both, :expand=>true)
-
=begin
# label
msg = TkLabel.new($goldberg_demo) {
@@ -177,8 +175,7 @@ class TkGoldberg_Demo
do_ctrl_frame
do_detail_frame
- # msg = TkLabel.new(@parent, :bg=>@C['bg'], :fg=>'white') {
- msg = Tk::Label.new(@parent, :bg=>@C['bg'], :fg=>'white') {
+ msg = TkLabel.new(@parent, :bg=>@C['bg'], :fg=>'white') {
font 'Arial 10'
wraplength 600
justify 'left'
@@ -188,8 +185,7 @@ class TkGoldberg_Demo
frame = TkFrame.new(@parent, :bg=>@C['bg'])
- # TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
- Tk::Button.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
+ TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
text 'Dismiss'
command proc{
tmppath = $goldberg_demo
@@ -198,14 +194,12 @@ class TkGoldberg_Demo
}
}.pack('side'=>'left')
- # TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
- Tk::Button.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
+ TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
text 'See Code'
command proc{showCode 'goldberg'}
}.pack('side'=>'left', 'padx'=>5)
- # @show = TkButton.new(frame, :text=>'>>', :command=>proc{show_ctrl},
- @show = Tk::Button.new(frame, :text=>'>>', :command=>proc{show_ctrl},
+ @show = TkButton.new(frame, :text=>'>>', :command=>proc{show_ctrl},
:bg=>@C['bg'], :activebackground=>@C['bg'])
@show.pack('side'=>'left')
frame.place(:in=>@canvas, :relx=>1, :rely=>0, :anchor=>:ne)
@@ -214,11 +208,10 @@ class TkGoldberg_Demo
end
def do_ctrl_frame
- @start = Tk::Button.new(@parent, :text=>'Start', :bd=>6,
+ @start = TkButton.new(@parent, :text=>'Start', :bd=>6,
:command=>proc{do_button(0)})
- if font = @start['font']
- @start.font(font.weight('bold'))
- end
+ @start.font(@start['font'].weight('bold'))
+ font = @start['font']
@pause = TkCheckbutton.new(@parent, :text=>'Pause', :font=>font,
:command=>proc{do_button(1)}, :relief=>:raised,
@@ -2003,4 +1996,4 @@ class TkGoldberg_Demo
end
end
-TkGoldberg_Demo.new(base_frame)
+TkGoldberg_Demo.new($goldberg_demo)
diff --git a/ext/tk/sample/demos-en/hello b/ext/tk/sample/demos-en/hello
index 5e86ad7e3e..f06eabe518 100644
--- a/ext/tk/sample/demos-en/hello
+++ b/ext/tk/sample/demos-en/hello
@@ -1,9 +1,9 @@
#!/usr/bin/env ruby
require 'tk'
-#unless /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
-# require 'tkencoding'
-#end
+unless /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
+ require 'tkencoding'
+end
TkButton.new(nil,
'text'=>"Hello Ruby world!",
diff --git a/ext/tk/sample/demos-en/hscale.rb b/ext/tk/sample/demos-en/hscale.rb
index e660216967..14e395b61a 100644
--- a/ext/tk/sample/demos-en/hscale.rb
+++ b/ext/tk/sample/demos-en/hscale.rb
@@ -11,9 +11,8 @@ $hscale_demo = TkToplevel.new {|w|
}
positionWindow($hscale_demo)
-base_frame = TkFrame.new($hscale_demo).pack(:fill=>:both, :expand=>true)
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($hscale_demo) {
font $font
wraplength '3.5i'
justify 'left'
@@ -21,7 +20,7 @@ msg = TkLabel.new(base_frame) {
}
msg.pack('side'=>'top')
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($hscale_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc {
@@ -37,18 +36,7 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
-
-def setWidth(w, width)
- width = width + 21
- x2 = width - 30
- if x2 < 21
- x2 = 21
- end
- w.coords 'poly',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
- w.coords 'line',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
-end
-
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($hscale_demo) {|frame|
canvas = TkCanvas.new(frame) {|c|
width 50
height 50
@@ -73,3 +61,14 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'expand'=>'yes', 'anchor'=>'n')
scale.set 75
}.pack('side'=>'top', 'fill'=>'x')
+
+
+def setWidth(w, width)
+ width = width + 21
+ x2 = width - 30
+ if x2 < 21
+ x2 = 21
+ end
+ w.coords 'poly',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
+ w.coords 'line',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
+end
diff --git a/ext/tk/sample/demos-en/icon.rb b/ext/tk/sample/demos-en/icon.rb
index a3921d2333..58aca2df07 100644
--- a/ext/tk/sample/demos-en/icon.rb
+++ b/ext/tk/sample/demos-en/icon.rb
@@ -19,10 +19,8 @@ $icon_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($icon_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($icon_demo) {
font $font
wraplength '5i'
justify 'left'
@@ -31,7 +29,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($icon_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -65,18 +63,16 @@ TkBitmapImage.new('file'=>[$demo_dir,'..',
letters = TkVariable.new
# frame
-TkFrame.new(base_frame, 'borderwidth'=>10){|w|
+TkFrame.new($icon_demo, 'borderwidth'=>10){|w|
TkFrame.new(w) {|f|
- # TkRadioButton.new(f){
- Tk::RadioButton.new(f){
+ TkRadioButton.new(f){
bitmap '@' + [$demo_dir,'..',
'images','letters.xbm'].join(File::Separator)
variable letters
value 'full'
}.pack('side'=>'top', 'expand'=>'yes')
- # TkRadioButton.new(f){
- Tk::RadioButton.new(f){
+ TkRadioButton.new(f){
bitmap '@' + [$demo_dir,'..',
'images','noletter.xbm'].join(File::Separator)
variable letters
@@ -85,16 +81,14 @@ TkFrame.new(base_frame, 'borderwidth'=>10){|w|
}.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'5m')
- # TkCheckButton.new(w) {
- Tk::CheckButton.new(w) {
+ TkCheckButton.new(w) {
image flagdown
selectimage flagup
indicatoron 0
selectcolor self['background']
}.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'5m')
- # TkCheckButton.new(w) {
- Tk::CheckButton.new(w) {
+ TkCheckButton.new(w) {
bitmap '@' + [$demo_dir,'..',
'images','letters.xbm'].join(File::Separator)
indicatoron 0
diff --git a/ext/tk/sample/demos-en/image1.rb b/ext/tk/sample/demos-en/image1.rb
index a9072bb308..05c9705c9c 100644
--- a/ext/tk/sample/demos-en/image1.rb
+++ b/ext/tk/sample/demos-en/image1.rb
@@ -18,10 +18,8 @@ $image1_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($image1_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($image1_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -30,7 +28,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($image1_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -56,10 +54,7 @@ TkPhotoImage.new('file'=>[$demo_dir,'..',
'images','earthris.gif'].join(File::Separator))
# label
-#[ TkLabel.new(base_frame, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'),
-# TkLabel.new(base_frame, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken')
-#].each{|w| w.pack('side'=>'top', 'padx'=>'.5m', 'pady'=>'.5m')}
-[ Tk::Label.new(base_frame, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'),
- Tk::Label.new(base_frame, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken')
+[ TkLabel.new($image1_demo, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'),
+ TkLabel.new($image1_demo, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken')
].each{|w| w.pack('side'=>'top', 'padx'=>'.5m', 'pady'=>'.5m')}
diff --git a/ext/tk/sample/demos-en/image2.rb b/ext/tk/sample/demos-en/image2.rb
index 1975dd6b02..1aff7173be 100644
--- a/ext/tk/sample/demos-en/image2.rb
+++ b/ext/tk/sample/demos-en/image2.rb
@@ -19,10 +19,8 @@ $image2_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($image2_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($image2_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -31,7 +29,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($image2_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -55,21 +53,21 @@ $dirName = TkVariable.new([$demo_dir,'..','images'].join(File::Separator))
$image2a = TkPhotoImage.new
#
-TkLabel.new(base_frame, 'text'=>'Directory:')\
+TkLabel.new($image2_demo, 'text'=>'Directory:')\
.pack('side'=>'top', 'anchor'=>'w')
-image2_e = TkEntry.new(base_frame) {
+image2_e = TkEntry.new($image2_demo) {
width 30
textvariable $dirName
}.pack('side'=>'top', 'anchor'=>'w')
-TkFrame.new(base_frame, 'height'=>'3m', 'width'=>20)\
+TkFrame.new($image2_demo, 'height'=>'3m', 'width'=>20)\
.pack('side'=>'top', 'anchor'=>'w')
-TkLabel.new(base_frame, 'text'=>'File:')\
+TkLabel.new($image2_demo, 'text'=>'File:')\
.pack('side'=>'top', 'anchor'=>'w')
-TkFrame.new(base_frame){|w|
+TkFrame.new($image2_demo){|w|
s = TkScrollbar.new(w)
l = TkListbox.new(w) {
width 20
@@ -88,9 +86,9 @@ TkFrame.new(base_frame){|w|
}.pack('side'=>'top', 'anchor'=>'w')
# image
-[ TkFrame.new(base_frame, 'height'=>'3m', 'width'=>20),
- TkLabel.new(base_frame, 'text'=>'Image:'),
- TkLabel.new(base_frame, 'image'=>$image2a)
+[ TkFrame.new($image2_demo, 'height'=>'3m', 'width'=>20),
+ TkLabel.new($image2_demo, 'text'=>'Image:'),
+ TkLabel.new($image2_demo, 'image'=>$image2a)
].each{|w| w.pack('side'=>'top', 'anchor'=>'w')}
#
diff --git a/ext/tk/sample/demos-en/image3.rb b/ext/tk/sample/demos-en/image3.rb
index 43afab7ecd..e46d3796f2 100644
--- a/ext/tk/sample/demos-en/image3.rb
+++ b/ext/tk/sample/demos-en/image3.rb
@@ -19,29 +19,27 @@ $image3_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($image3_demo).pack(:fill=>:both, :expand=>true)
-
#
-def loadDir3(w)
+def loadDir(w)
w.delete(0,'end')
Dir.glob([$dirName,'*'].join(File::Separator)).sort.each{|f|
w.insert('end',File.basename(f))
}
end
-# selectAndLoadDir3 --
+# selectAndLoadDir --
# This procedure pops up a dialog to ask for a directory to load into
# the listobx and (if the user presses OK) reloads the directory
# listbox from the directory named in the demo's entry.
#
# Arguments:
# w - Name of the toplevel window of the demo.
-def selectAndLoadDir3(w, lbox)
+def selectAndLoadDir(w, lbox)
dir = Tk.chooseDirectory(:initialdir=>$dirName.value,
:parent=>w, :mustexist=>true)
if dir.length > 0
$dirName.value = dir
- loadDir3(lbox)
+ loadDir(lbox)
end
end
@@ -51,7 +49,7 @@ end
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($image3_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -60,7 +58,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($image3_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -88,11 +86,11 @@ end
$image3a = TkPhotoImage.new
#
-image3_f = TkFrame.new(base_frame).pack(:fill=>:both, :expand=>true)
+image3_f = TkFrame.new($image3_demo).pack(:fill=>:both, :expand=>true)
-image3_df = TkLabelFrame.new(base_frame, :text=>'Directory:')
+image3_df = TkLabelFrame.new($image3_demo, :text=>'Directory:')
-image3_ff = TkLabelFrame.new(base_frame, :text=>'File:',
+image3_ff = TkLabelFrame.new($image3_demo, :text=>'File:',
:padx=>'2m', :pady=>'2m')
image3_lbx = TkListbox.new(image3_ff, :width=>20, :height=>10) {
pack(:side=>:left, :fill=>:y, :expand=>true)
@@ -104,17 +102,16 @@ image3_lbx = TkListbox.new(image3_ff, :width=>20, :height=>10) {
image3_ent = TkEntry.new(image3_df, :width=>30, :textvariable=>$dirName){
pack(:side=>:left, :fill=>:both, :padx=>'2m', :pady=>'2m', :expand=>true)
- bind('Return', proc{loadDir3(image3_lbx)})
+ bind('Return', proc{loadDir(image3_lbx)})
}
TkButton.new(image3_df, :pady=>0, :padx=>'2m', :text=>"Select Dir.",
- :command=>proc{selectAndLoadDir3(image3_ent, image3_lbx)}) {
+ :command=>proc{selectAndLoadDir(image3_ent, image3_lbx)}) {
pack(:side=>:left, :fill=>:y, :padx=>[0, '2m'], :pady=>'2m')
}
-image3_if = TkLabelFrame.new(base_frame, :text=>'Image:') {|f|
- # TkLabel.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m')
- Tk::Label.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m')
+image3_if = TkLabelFrame.new($image3_demo, :text=>'Image:') {|f|
+ TkLabel.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m')
}
Tk.grid(image3_df, '-',
diff --git a/ext/tk/sample/demos-en/items.rb b/ext/tk/sample/demos-en/items.rb
index 3fd44fd4f4..8ab7668a07 100644
--- a/ext/tk/sample/demos-en/items.rb
+++ b/ext/tk/sample/demos-en/items.rb
@@ -19,10 +19,8 @@ $items_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($items_demo).pack(:fill=>:both, :expand=>true)
-
# label
-TkLabel.new(base_frame) {
+TkLabel.new($items_demo) {
font $font
wraplength '5i'
justify 'left'
@@ -30,7 +28,7 @@ TkLabel.new(base_frame) {
}.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($items_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -48,7 +46,7 @@ TkFrame.new(base_frame) {|frame|
# frame
cvs = nil
-TkFrame.new(base_frame) {|cf|
+TkFrame.new($items_demo) {|cf|
# canvas
cvs = TkCanvas.new(cf) {|c|
focus
@@ -96,13 +94,8 @@ TkcLine.new(cvs, '0c', '16c', '30c', '16c', 'width'=>2)
TkcLine.new(cvs, '10c', '0c', '10c', '24c', 'width'=>2)
TkcLine.new(cvs, '20c', '0c', '20c', '24c', 'width'=>2)
-if $tk_version =~ /^4.*/
- font1 = '-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*'
- font2 = '-Adobe-Helvetica-Bold-R-Normal--*-240-*-*-*-*-*-*'
-else
- font1 = 'Helvetica 12'
- font2 = 'Helvetica 24 bold'
-end
+font1 = '-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*'
+font2 = '-Adobe-Helvetica-Bold-R-Normal--*-240-*-*-*-*-*-*'
if TkWinfo.depth($root).to_i > 1
blue = 'DeepSkyBlue3'
red = 'red'
diff --git a/ext/tk/sample/demos-en/knightstour.rb b/ext/tk/sample/demos-en/knightstour.rb
deleted file mode 100644
index 618fce5f02..0000000000
--- a/ext/tk/sample/demos-en/knightstour.rb
+++ /dev/null
@@ -1,271 +0,0 @@
-# Based on the widget demo of Tcl/Tk8.5.2
-# The following is the original copyright text.
-#----------------------------------------------------------------------------
-# Copyright (C) 2008 Pat Thoyts <patthoyts@users.sourceforge.net>
-#
-# Calculate a Knight's tour of a chessboard.
-#
-# This uses Warnsdorff's rule to calculate the next square each
-# time. This specifies that the next square should be the one that
-# has the least number of available moves.
-#
-# Using this rule it is possible to get to a position where
-# there are no squares available to move into. In this implementation
-# this occurs when the starting square is d6.
-#
-# To solve this fault an enhancement to the rule is that if we
-# have a choice of squares with an equal score, we should choose
-# the one nearest the edge of the board.
-#
-# If the call to the Edgemost function is commented out you can see
-# this occur.
-#
-# You can drag the knight to a specific square to start if you wish.
-# If you let it repeat then it will choose random start positions
-# for each new tour.
-#----------------------------------------------------------------------------
-require 'tk'
-
-class Knights_Tour
- # Return a list of accessible squares from a given square
- def valid_moves(square)
- moves = []
- [
- [-1,-2], [-2,-1], [-2,1], [-1,2], [1,2], [2,1], [2,-1], [1,-2]
- ].each{|col_delta, row_delta|
- col = (square % 8) + col_delta
- row = (square.div(8)) + row_delta
- moves << (row * 8 + col) if row > -1 && row < 8 && col > -1 && col < 8
- }
- moves
- end
-
- # Return the number of available moves for this square
- def check_square(square)
- valid_moves(square).find_all{|pos| ! @visited.include?(pos)}.length
- end
-
- # Select the next square to move to. Returns -1 if there are no available
- # squares remaining that we can move to.
- def next_square(square)
- minimum = 9
- nxt = -1
- valid_moves(square).each{|pos|
- unless @visited.include?(pos)
- cnt = check_square(pos)
- if cnt < minimum
- minimum = cnt
- nxt = pos
- elsif cnt == minimum
- nxt = edgemost(nxt, pos)
- end
- end
- }
- nxt
- end
-
- # Select the square nearest the edge of the board
- def edgemost(nxt, pos)
- col_A = 3 - ((3.5 - nxt % 8).abs.to_i)
- col_B = 3 - ((3.5 - pos % 8).abs.to_i)
- row_A = 3 - ((3.5 - nxt.div(8)).abs.to_i)
- row_B = 3 - ((3.5 - pos.div(8)).abs.to_i)
- (col_A * row_A < col_B * row_B)? nxt : pos
- end
-
- # Display a square number as a standard chess square notation.
- def _N(square)
- '%c%d' % [(97 + square % 8), (square.div(8) + 1)]
- end
-
- # Perform a Knight's move and schedule the next move.
- def move_piece(last, square)
- @log.insert(:end, "#{@visited.length}. #{_N last} -> #{_N square}\n", '')
- @log.see(:end)
- @board.itemconfigure(1+last, :state=>:normal, :outline=>'black')
- @board.itemconfigure(1+square, :state=>:normal, :outline=>'red')
- @knight.coords(@board.coords(1+square)[0..1])
- @visited << square
- if (nxt = next_square(square)) != -1
- @after_id = Tk.after(@delay.numeric){move_piece(square, nxt) rescue nil}
- else
- @start_btn.state :normal
- if @visited.length == 64
- if @initial == square
- @log.insert :end, 'Closed tour!'
- else
- @log.insert :end, "Success\n", {}
- Tk.after(@delay.numeric * 2){tour(rand(64))} if @continuous.bool
- end
- else
- @log.insert :end, "FAILED!\n", {}
- end
- end
- end
-
- # Begin a new tour of the board given a random start position
- def tour(square = nil)
- @visited.clear
- @log.clear
- @start_btn.state :disabled
- 1.upto(64){|n|
- @board.itemconfigure(n, :state=>:disabled, :outline=>'black')
- }
- unless square
- square = @board.find_closest(*(@knight.coords << 0 << 65))[0].to_i - 1
- end
- @initial = square
- Tk.after_idle{ move_piece(@initial, @initial) rescue nil }
- end
-
- def _stop
- Tk.after_cancel(@after_id) rescue nil
- end
-
- def _exit
- _stop
- $knightstour.destroy
- end
-
- def set_delay(new)
- @delay.numeric = new.to_i
- end
-
- def drag_start(w, x, y)
- w.dtag('selected')
- w.addtag('selected', :withtag, 'current')
- @dragging = [x, y]
- end
-
- def drag_motion(w, x, y)
- return unless @dragging
- w.move('selected', x - @dragging[0], y - @dragging[1])
- @dragging = [x, y]
- end
-
- def drag_end(w, x, y)
- square = w.find_closest(x, y, 0, 65)
- w.coords('selected', w.coords(square)[0..1])
- w.dtag('selected')
- @dragging = nil
- end
-
- def make_SeeDismiss
- ## See Code / Dismiss
- frame = Ttk::Frame.new($knightstour)
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'See Code',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'knightstour'}),
- Ttk::Button.new(frame, :text=>'Dismiss',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $knightstour.destroy
- $knightstour = nil
- }),
- :padx=>4, :pady=>4)
- frame.grid_columnconfigure(0, :weight=>1)
- frame
- end
-
- def create_gui(parent = nil)
- $knightstour.destroy rescue nil
- $knightstour = Tk::Toplevel.new(parent, :title=>"Knight's tour")
- $knightstour.withdraw
- base_f = Ttk::Frame.new($knightstour)
- @board = Tk::Canvas.new(base_f, :width=>240, :height=>240)
- @log = Tk::Text.new(base_f, :width=>12, :height=>1,
- :font=>'Arial 8', :background=>'white')
- scr = @log.yscrollbar(Ttk::Scrollbar.new(base_f))
-
- @visited = []
- @delay = TkVariable.new(600)
- @continuous = TkVariable.new(false)
-
- tool_f = Ttk::Frame.new($knightstour)
- label = Ttk::Label.new(tool_f, :text=>'Speed')
- scale = Ttk::Scale.new(tool_f, :from=>8, :to=>2000, :variable=>@delay,
- :command=>proc{|n| set_delay(n)})
- check = Ttk::Checkbutton.new(tool_f, :text=>'Repeat',
- :variable=>@continuous)
- @start_btn = Ttk::Button.new(tool_f, :text=>'Start',
- :command=>proc{tour()})
- @exit_btn = Ttk::Button.new(tool_f, :text=>'Exit',
- :command=>proc{_exit()})
-
- 7.downto(0){|row|
- 0.upto(7){|col|
- if ((col & 1) ^ (row & 1)).zero?
- fill = 'bisque'
- dfill = 'bisque3'
- else
- fill = 'tan3'
- dfill = 'tan4'
- end
- coords = [col * 30 + 4, row * 30 + 4, col * 30 + 30, row * 30 + 30]
- @board.create(TkcRectangle, coords,
- :fill=>fill, :disabledfill=>dfill,
- :width=>2, :state=>:disabled)
- }
- }
-
- @knight_font = TkFont.new(:size=>-24)
- @knight = TkcText.new(@board, 0, 0, :font=>@knight_font,
- :text=>Tk::UTF8_String.new('\u265e'),
- :anchor=>'nw', # :tags=>'knight',
- :fill=>'black', :activefill=>'#600000')
- @knight.coords(@board.coords(rand(64)+1)[0..1])
- @knight.bind('ButtonPress-1', '%W %x %y'){|w,x,y| drag_start(w,x,y)}
- @knight.bind('Motion', '%W %x %y'){|w,x,y| drag_motion(w,x,y)}
- @knight.bind('ButtonRelease-1', '%W %x %y'){|w,x,y| drag_end(w,x,y)}
-
- Tk.grid(@board, @log, scr, :sticky=>'news')
- base_f.grid_rowconfigure(0, :weight=>1)
- base_f.grid_columnconfigure(0, :weight=>1)
-
- Tk.grid(base_f, '-', '-', '-', '-', '-', :sticky=>'news')
- widgets = [label, scale, check, @start_btn]
- sg = nil
- unless $RubyTk_WidgetDemo
- widgets << @exit_btn
- if Tk.windowingsystem != 'aqua'
- #widgets.unshift(Ttk::SizeGrip.new(tool_f))
- Ttk::SizeGrip.new(tool_f).pack(:side=>:right, :anchor=>'se')
- end
- end
- Tk.pack(widgets, :side=>:right)
- if Tk.windowingsystem == 'aqua'
- TkPack.configure(widgets, :padx=>[4, 4], :pady=>[12, 12])
- TkPack.configure(widgets[0], :padx=>[4, 24])
- TkPack.configure(widgets[-1], :padx=>[16, 4])
- end
-
- Tk.grid(tool_f, '-', '-', '-', '-', '-', :sticky=>'ew')
-
- if $RubyTk_WidgetDemo
- Tk.grid(make_SeeDismiss(), '-', '-', '-', '-', '-', :sticky=>'ew')
- end
-
- $knightstour.grid_rowconfigure(0, :weight=>1)
- $knightstour.grid_columnconfigure(0, :weight=>1)
-
- $knightstour.bind('Control-F2'){TkConsole.show}
- $knightstour.bind('Return'){@start_btn.invoke}
- $knightstour.bind('Escape'){@exit_btn.invoke}
- $knightstour.bind('Destroy'){ _stop }
- $knightstour.protocol('WM_DELETE_WINDOW'){ _exit }
-
- $knightstour.deiconify
- $knightstour.tkwait_destroy
- end
-
- def initialize(parent = nil)
- create_gui(parent)
- end
-end
-
-Tk.root.withdraw unless $RubyTk_WidgetDemo
-Thread.new{Tk.mainloop} if __FILE__ == $0
-Knights_Tour.new
diff --git a/ext/tk/sample/demos-en/label.rb b/ext/tk/sample/demos-en/label.rb
index 91e41e4a22..55e07a5ebc 100644
--- a/ext/tk/sample/demos-en/label.rb
+++ b/ext/tk/sample/demos-en/label.rb
@@ -19,10 +19,8 @@ $label_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($label_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($label_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -31,7 +29,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($label_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -49,8 +47,8 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# label demo
-f_left = TkFrame.new(base_frame)
-f_right = TkFrame.new(base_frame)
+f_left = TkFrame.new($label_demo)
+f_right = TkFrame.new($label_demo)
[f_left, f_right].each{|w| w.pack('side'=>'left', 'expand'=>'yes',
'padx'=>10, 'pady'=>10, 'fill'=>'both')}
@@ -61,8 +59,7 @@ f_right = TkFrame.new(base_frame)
TkLabel.new(f_left, 'text'=>'Third label, sunken', 'relief'=>'sunken')
].each{|w| w.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2, 'anchor'=>'w')}
-# TkLabel.new(f_right) {
-Tk::Label.new(f_right) {
+TkLabel.new(f_right) {
bitmap('@' + [$demo_dir,'..','images','face.xbm'].join(File::Separator))
borderwidth 2
relief 'sunken'
diff --git a/ext/tk/sample/demos-en/labelframe.rb b/ext/tk/sample/demos-en/labelframe.rb
index c912ff4c52..842a4f6c04 100644
--- a/ext/tk/sample/demos-en/labelframe.rb
+++ b/ext/tk/sample/demos-en/labelframe.rb
@@ -17,10 +17,8 @@ $labelframe_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($labelframe_demo).pack(:fill=>:both, :expand=>true)
-
# Some information
-TkLabel.new(base_frame,
+TkLabel.new($labelframe_demo,
:font=>$font, :wraplength=>'4i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
Labelframes are used to group related widgets together. \
@@ -31,7 +29,7 @@ which supports a 'labelframe' widget.
EOL
# The bottom buttons
-TkFrame.new(base_frame){|f|
+TkFrame.new($labelframe_demo){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{
@@ -45,7 +43,7 @@ TkFrame.new(base_frame){|f|
}
# Demo area
-w = TkFrame.new(base_frame).pack(:side=>:bottom, :fill=>:both,
+w = TkFrame.new($labelframe_demo).pack(:side=>:bottom, :fill=>:both,
:expand=>true)
# A group of radiobuttons in a labelframe
diff --git a/ext/tk/sample/demos-en/mclist.rb b/ext/tk/sample/demos-en/mclist.rb
deleted file mode 100644
index a849eba515..0000000000
--- a/ext/tk/sample/demos-en/mclist.rb
+++ /dev/null
@@ -1,117 +0,0 @@
-# mclist.rb --
-#
-# This demonstration script creates a toplevel window containing a Ttk
-# tree widget configured as a multi-column listbox.
-#
-# based on "Id: mclist.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($mclist_demo) && $mclist_demo
- $mclist_demo.destroy
- $mclist_demo = nil
-end
-
-$mclist_demo = TkToplevel.new {|w|
- title("Multi-Column List")
- iconname("mclist")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($mclist_demo).pack(:fill=>:both, :expand=>true)
-
-## Explanatory text
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i',
- :justify=>:left, :anchor=>'n', :padding=>[10, 2, 10, 6],
- :text=><<EOL).pack(:fill=>:x)
-Ttk is the new Tk themed widget set. \
-One of the widgets it includes is a tree widget, \
-which can be configured to display multiple columns of informational data \
-without displaying the tree itself. \
-This is a simple way to build a listbox that has multiple columns. \
-Clicking on the heading for a column will sort the data by that column. \
-You can also change the width of the columns \
-by dragging the boundary between them.
-EOL
-
-## See Code / Dismiss
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'See Code',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'mclist'}),
- Ttk::Button.new(frame, :text=>'Dismiss',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $mclist_demo.destroy
- $mclist_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-container = Ttk::Frame.new(base_frame)
-tree = Ttk::Treeview.new(base_frame, :columns=>%w(country capital currency),
- :show=>:headings)
-if Tk.windowingsystem != 'aqua'
- vsb = tree.yscrollbar(Ttk::Scrollbar.new(base_frame))
- hsb = tree.xscrollbar(Ttk::Scrollbar.new(base_frame))
-else
- vsb = tree.yscrollbar(Tk::Scrollbar.new(base_frame))
- hsb = tree.xscrollbar(Tk::Scrollbar.new(base_frame))
-end
-
-container.pack(:fill=>:both, :expand=>true)
-Tk.grid(tree, vsb, :in=>container, :sticky=>'nsew')
-Tk.grid(hsb, :in=>container, :sticky=>'nsew')
-container.grid_columnconfigure(0, :weight=>1)
-container.grid_rowconfigure(0, :weight=>1)
-
-## The data we're going to insert
-data = [
- ['Argentina', 'Buenos Aires', 'ARS'],
- ['Australia', 'Canberra', 'AUD'],
- ['Brazil', 'Brazilia', 'BRL'],
- ['Canada', 'Ottawa', 'CAD'],
- ['China', 'Beijing', 'CNY'],
- ['France', 'Paris', 'EUR'],
- ['Germany', 'Berlin', 'EUR'],
- ['India', 'New Delhi', 'INR'],
- ['Italy', 'Rome', 'EUR'],
- ['Japan', 'Tokyo', 'JPY'],
- ['Mexico', 'Mexico City', 'MXN'],
- ['Russia', 'Moscow', 'RUB'],
- ['South Africa', 'Pretoria', 'ZAR'],
- ['United Kingdom', 'London', 'GBP'],
- ['United States', 'Washington, D.C.', 'USD'],
-]
-
-## Code to insert the data nicely
-font = Ttk::Style.lookup(tree[:style], :font)
-cols = %w(country capital currency)
-cols.zip(%w(Country Capital Currency)).each{|col, name|
- tree.heading_configure(col, :text=>name,
- :command=>proc{sort_by(tree, col, false)})
- tree.column_configure(col, :width=>TkFont.measure(font, name))
-}
-
-data.each{|country, capital, currency|
- #tree.insert('', :end, :values=>[country, capital, currency])
- tree.insert(nil, :end, :values=>[country, capital, currency])
- cols.zip([country, capital, currency]).each{|col, val|
- len = TkFont.measure(font, "#{val} ")
- if tree.column_cget(col, :width) < len
- tree.column_configure(col, :width=>len)
- end
- }
-}
-
-## Code to do the sorting of the tree contents when clicked on
-def sort_by(tree, col, direction)
- tree.children(nil).map!{|row| [tree.get(row, col), row.id]} .
- sort(&((direction)? proc{|x, y| y <=> x}: proc{|x, y| x <=> y})) .
- each_with_index{|info, idx| tree.move(info[1], nil, idx)}
-
- tree.heading_configure(col, :command=>proc{sort_by(tree, col, ! direction)})
-end
diff --git a/ext/tk/sample/demos-en/menu.rb b/ext/tk/sample/demos-en/menu.rb
index bf6c22cb9d..8370d2f5f0 100644
--- a/ext/tk/sample/demos-en/menu.rb
+++ b/ext/tk/sample/demos-en/menu.rb
@@ -15,10 +15,8 @@ $menu_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($menu_demo).pack(:fill=>:both, :expand=>true)
-
# menu frame
-$menu_frame = TkFrame.new(base_frame, 'relief'=>'raised', 'bd'=>2)
+$menu_frame = TkFrame.new($menu_demo, 'relief'=>'raised', 'bd'=>2)
$menu_frame.pack('side'=>'top', 'fill'=>'x')
begin
@@ -28,7 +26,7 @@ rescue
end
# label
-TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
+TkLabel.new($menu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
if $tk_platform['platform'] == 'macintosh' ||
windowingsystem == "classic" || windowingsystem == "aqua"
text("This window contains a menubar with cascaded menus. You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by dragging outside of its bounds and releasing the mouse.")
@@ -38,7 +36,7 @@ TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
}.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menu_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -107,7 +105,7 @@ TkMenubutton.new($menu_frame, 'text'=>'Cascades', 'underline'=>0) {|m|
'accelerator'=>"#{modifier}+G", 'underline'=>6)
$menu_demo.bind("#{modifier}-g", proc{print "Goodbye\n"})
- TkMenu.new(cascade_menu, 'tearoff'=>false) {|cascade_check|
+ TkMenu.new(m, 'tearoff'=>false) {|cascade_check|
cascade_menu.add('cascade', 'label'=>'Check buttons',
'menu'=>cascade_check, 'underline'=>0)
oil = TkVariable.new(0)
@@ -129,7 +127,7 @@ TkMenubutton.new($menu_frame, 'text'=>'Cascades', 'underline'=>0) {|m|
invoke 3
}
- TkMenu.new(cascade_menu, 'tearoff'=>false) {|cascade_radio|
+ TkMenu.new(m, 'tearoff'=>false) {|cascade_radio|
cascade_menu.add('cascade', 'label'=>'Radio buttons',
'menu'=>cascade_radio, 'underline'=>0)
pointSize = TkVariable.new
diff --git a/ext/tk/sample/demos-en/menu84.rb b/ext/tk/sample/demos-en/menu84.rb
index 4029ce5541..cb616d8461 100644
--- a/ext/tk/sample/demos-en/menu84.rb
+++ b/ext/tk/sample/demos-en/menu84.rb
@@ -15,8 +15,6 @@ $menu84_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($menu84_demo).pack(:fill=>:both, :expand=>true)
-
begin
windowingsystem = Tk.windowingsystem()
rescue
@@ -24,7 +22,7 @@ rescue
end
# label
-TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
+TkLabel.new($menu84_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
if $tk_platform['platform'] == 'macintosh' ||
windowingsystem == "classic" || windowingsystem == "aqua"
text("This window contains a menubar with cascaded menus. You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by dragging outside of its bounds and releasing the mouse.")
@@ -35,7 +33,7 @@ TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
menustatus = TkVariable.new(" ")
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menu84_demo) {|frame|
TkLabel.new(frame, 'textvariable'=>menustatus, 'relief'=>'sunken',
'bd'=>1, 'font'=>['Helvetica', '10'],
'anchor'=>'w').pack('side'=>'left', 'padx'=>2,
@@ -45,7 +43,7 @@ TkFrame.new(base_frame) {|frame|
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menu84_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
diff --git a/ext/tk/sample/demos-en/menubu.rb b/ext/tk/sample/demos-en/menubu.rb
index b37367e515..e2ddd07bc6 100644
--- a/ext/tk/sample/demos-en/menubu.rb
+++ b/ext/tk/sample/demos-en/menubu.rb
@@ -37,18 +37,16 @@ $menubu_demo = TkToplevel.new {|w|
positionWindow($menubu_demo)
-base_frame = TkFrame.new($menubu_demo).pack(:fill=>:both, :expand=>true)
-
# version check
if $tk_version.to_f < 8.0
# label
-TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
+TkLabel.new($menubu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
text("This is a demonstration of menubuttons. The \"Below\" menubutton pops its menu below the button; the \"Right\" button pops to the right, etc. There are two option menus directly below this text; one is just a standard menu and the other is a 16-color palette.")
}.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menubu_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -66,7 +64,7 @@ TkFrame.new(base_frame) {|frame|
else ; # Tk8.x
-body = TkFrame.new(base_frame)
+body = TkFrame.new($menubu_demo)
body.pack('expand'=>'yes', 'fill'=>'both')
below = TkMenubutton.new(body) {
@@ -161,7 +159,7 @@ center = TkFrame.new(body) {
grid('row'=>1, 'column'=>1, 'sticky'=>'news')
}
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menubu_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc {
diff --git a/ext/tk/sample/demos-en/msgbox.rb b/ext/tk/sample/demos-en/msgbox.rb
index 62b1f2b985..aab1b619cf 100644
--- a/ext/tk/sample/demos-en/msgbox.rb
+++ b/ext/tk/sample/demos-en/msgbox.rb
@@ -18,14 +18,12 @@ $msgbox_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($msgbox_demo).pack(:fill=>:both, :expand=>true)
-
# label
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
+TkLabel.new($msgbox_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
'text'=>"Choose the icon and type option of the message box. Then press the \"Message Box\" button to see the message box.").pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($msgbox_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -47,8 +45,8 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
-$msgbox_leftframe = TkFrame.new(base_frame)
-$msgbox_rightframe = TkFrame.new(base_frame)
+$msgbox_leftframe = TkFrame.new($msgbox_demo)
+$msgbox_rightframe = TkFrame.new($msgbox_demo)
$msgbox_leftframe .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
'pady'=>'.5c', 'padx'=>'.5c')
$msgbox_rightframe.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
diff --git a/ext/tk/sample/demos-en/msgbox2.rb b/ext/tk/sample/demos-en/msgbox2.rb
deleted file mode 100644
index 6fe6c778b3..0000000000
--- a/ext/tk/sample/demos-en/msgbox2.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-# msgbox2.rb
-#
-# This demonstration script creates message boxes of various type
-#
-# message boxes widget demo (called by 'widget')
-#
-
-# toplevel widget
-if defined?($msgbox2_demo) && $msgbox2_demo
- $msgbox2_demo.destroy
- $msgbox2_demo = nil
-end
-
-# demo toplevel widget
-$msgbox2_demo = TkToplevel.new {|w|
- title("Message Box Demonstration")
- iconname("messagebox")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($msgbox2_demo).pack(:fill=>:both, :expand=>true)
-
-# label
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
- 'text'=>"Choose the icon and type option of the message box. Then press the \"Message Box\" button to see the message box with both of a message and a detail.").pack('side'=>'top')
-
-# frame
-TkFrame.new(base_frame) {|frame|
- TkButton.new(frame) {
- text 'Dismiss'
- command proc{
- tmppath = $msgbox2_demo
- $msgbox2_demo = nil
- tmppath.destroy
- }
- }.pack('side'=>'left', 'expand'=>'yes')
-
- TkButton.new(frame) {
- text 'Show Code'
- command proc{showCode 'msgbox2'}
- }.pack('side'=>'left', 'expand'=>'yes')
-
- TkButton.new(frame) {
- text 'Message Box'
- command proc{showMessageBox $msgbox2_demo}
- }.pack('side'=>'left', 'expand'=>'yes')
-}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
-
-# frame
-$msgbox_leftframe = TkFrame.new(base_frame)
-$msgbox_rightframe = TkFrame.new(base_frame)
-$msgbox_leftframe .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
- 'pady'=>'.5c', 'padx'=>'.5c')
-$msgbox_rightframe.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
- 'pady'=>'.5c', 'padx'=>'.5c')
-
-TkLabel.new($msgbox_leftframe, 'text'=>'Icon').pack('side'=>'top')
-TkFrame.new($msgbox_leftframe, 'relief'=>'ridge', 'bd'=>1, 'height'=>2)\
-.pack('side'=>'top', 'fill'=>'x', 'expand'=>'no')
-
-$msgboxIcon = TkVariable.new('info')
-['error', 'info', 'question', 'warning'].each {|icon|
- TkRadioButton.new($msgbox_leftframe, 'text'=>icon, 'variable'=>$msgboxIcon,
- 'relief'=>'flat', 'value'=>icon, 'width'=>16,
- 'anchor'=>'w').pack('side'=>'top', 'pady'=>2,
- 'anchor'=>'w', 'fill'=>'x')
-}
-
-TkLabel.new($msgbox_rightframe, 'text'=>'Type').pack('side'=>'top')
-TkFrame.new($msgbox_rightframe, 'relief'=>'ridge', 'bd'=>1, 'height'=>2)\
-.pack('side'=>'top', 'fill'=>'x', 'expand'=>'no')
-
-$msgboxType = TkVariable.new('ok')
-['abortretryignore', 'ok', 'okcancel',
- 'retrycancel', 'yesno', 'yesnocancel'].each {|type|
- TkRadioButton.new($msgbox_rightframe, 'text'=>type, 'variable'=>$msgboxType,
- 'relief'=>'flat', 'value'=>type, 'width'=>16,
- 'anchor'=>'w').pack('side'=>'top', 'pady'=>2,
- 'anchor'=>'w', 'fill'=>'x')
-}
-
-def showMessageBox(w)
- button = Tk.messageBox('icon'=>$msgboxIcon.value, 'type'=>$msgboxType.value,
- 'title'=>'Message', 'parent'=>w,
- 'message'=>"\"#{$msgboxType.value}\" Type MessageBox",
- 'detail'=>"This is a \"#{$msgboxType.value}\" type messagebox with the \"#{$msgboxIcon.value}\" icon. Please click one of the following button.")
-
- Tk.messageBox('icon'=>'info', 'type'=>'ok', 'parent'=>w,
- 'message'=>"You have selected \"#{button}\"")
-end
-
diff --git a/ext/tk/sample/demos-en/paned1.rb b/ext/tk/sample/demos-en/paned1.rb
index 26941b84a8..48ba86de02 100644
--- a/ext/tk/sample/demos-en/paned1.rb
+++ b/ext/tk/sample/demos-en/paned1.rb
@@ -16,9 +16,7 @@ $paned1_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($paned1_demo).pack(:fill=>:both, :expand=>true)
-
-TkLabel.new(base_frame,
+TkLabel.new($paned1_demo,
:font=>$font, :wraplength=>'4i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
The sash between the two coloured windows below can be used to divide the area between them. Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.)
@@ -26,7 +24,7 @@ If your Tk library linked to Ruby doesn't include a 'panedwindow', this demo doe
EOL
# The bottom buttons
-TkFrame.new(base_frame){|f|
+TkFrame.new($paned1_demo){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{
@@ -39,9 +37,9 @@ TkFrame.new(base_frame){|f|
}).pack(:side=>:left, :expand=>true)
}
-TkPanedwindow.new(base_frame, :orient=>:horizontal){|f|
- add(Tk::Label.new(f, :text=>"This is the\nleft side", :bg=>'yellow'),
- Tk::Label.new(f, :text=>"This is the\nright side", :bg=>'cyan'))
-
+TkPanedwindow.new($paned1_demo){|f|
pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m')
+
+ add(TkLabel.new(f, :text=>"This is the\nleft side", :bg=>'yellow'),
+ TkLabel.new(f, :text=>"This is the\nright side", :bg=>'cyan'))
}
diff --git a/ext/tk/sample/demos-en/paned2.rb b/ext/tk/sample/demos-en/paned2.rb
index 0e62013886..5911cadab6 100644
--- a/ext/tk/sample/demos-en/paned2.rb
+++ b/ext/tk/sample/demos-en/paned2.rb
@@ -16,9 +16,7 @@ $paned2_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($paned2_demo).pack(:fill=>:both, :expand=>true)
-
-TkLabel.new(base_frame,
+TkLabel.new($paned2_demo,
:font=>$font, :wraplength=>'4i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
The sash between the two scrolled windows below can be used to divide the area between them. Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.)
@@ -26,7 +24,7 @@ If your Tk library linked to Ruby doesn't include a 'panedwindow', this demo doe
EOL
# The bottom buttons
-TkFrame.new(base_frame){|f|
+TkFrame.new($paned2_demo){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{
@@ -63,7 +61,7 @@ paneList.value = [ # ruby's array --> tcl's list
]
# Create the pane itself
-TkPanedwindow.new(base_frame, :orient=>:vertical){|f|
+TkPanedwindow.new($paned2_demo, :orient=>:vertical){|f|
pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m')
add(TkFrame.new(f){|paned2_top|
diff --git a/ext/tk/sample/demos-en/patch_1.1c1 b/ext/tk/sample/demos-en/patch_1.1c1
new file mode 100644
index 0000000000..d3952e71eb
--- /dev/null
+++ b/ext/tk/sample/demos-en/patch_1.1c1
@@ -0,0 +1,93 @@
+--- /usr/src/ruby-1.1c1/lib/tkcanvas.rb Tue Jul 21 18:18:02 1998
++++ tkcanvas.rb Fri Jul 24 20:38:24 1998
+@@ -310,7 +310,7 @@
+ || key == 'latinfont' || key == 'asciifont' )
+ tagfont_configure(tagid(tagOrId), {key=>value})
+ else
+- tk_call 'itemconfigure', tagid(tagOrId), "-#{key}", value
++ tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value
+ end
+ end
+ end
+--- /usr/src/ruby-1.1c1/lib/tkfont.rb Fri Jul 17 23:43:28 1998
++++ tkfont.rb Fri Jul 24 17:46:22 1998
+@@ -42,7 +42,7 @@
+ r | []
+
+ when /^8\.*/
+- list(tk_call('font', 'names'))
++ tk_split_simplelist(tk_call('font', 'names'))
+
+ end
+ end
+@@ -89,10 +89,14 @@
+ if fnt == []
+ TkFont.new(nil, nil).call_font_configure(path, *(args + [{}]))
+ else
+- compound = Hash[*list(tk_call('font', 'configure',
+- fnt))].collect{|key,value|
+- [key[1..-1], value]
+- }.assoc('compound')[1]
++ begin
++ compound = Hash[*list(tk_call('font', 'configure',
++ fnt))].collect{|key,value|
++ [key[1..-1], value]
++ }.assoc('compound')[1]
++ rescue
++ compound = []
++ end
+ if compound == []
+ TkFont.new(fnt, DEFAULT_KANJI_FONT_NAME) \
+ .call_font_configure(path, *(args + [{}]))
+@@ -156,14 +160,19 @@
+ elsif font.kind_of? Array
+ finfo = {}
+ finfo['family'] = font[0].to_s
+- if font[1] && font[1] != '0' && font[1] =~ /^(|\+|-)([0-9]+)$/
+- if $1 == '-'
+- finfo['pixels'] = font[1].to_s
++ if font[1]
++ fsize = font[1].to_s
++ if fsize != '0' && fsize =~ /^(|\+|-)([0-9]+)$/
++ if $1 == '-'
++ finfo['pixels'] = $2
++ else
++ finfo['points'] = $2
++ end
+ else
+- finfo['points'] = font[1].to_s
++ finfo['points'] = '13'
+ end
+ end
+- finfo[2..-1].each{|style|
++ font[2..-1].each{|style|
+ case (style)
+ when 'normal'
+ finfo['weight'] = style
+@@ -199,16 +208,19 @@
+ elsif font.kind_of? Array
+ finfo = {}
+ finfo['family'] = font[0].to_s
+- if font[1] && font[1] != '0' && font[1] =~ /^(|\+|-)([0-9]+)$/
+- if $1 == '-'
+- finfo['pixels'] = $2
++ if font[1]
++ fsize = font[1].to_s
++ if fsize != '0' && fsize =~ /^(|\+|-)([0-9]+)$/
++ if $1 == '-'
++ finfo['pixels'] = $2
++ else
++ finfo['points'] = $2
++ end
+ else
+- finfo['points'] = $2
++ finfo['points'] = '13'
+ end
+- else
+- finfo['points'] = '13'
+ end
+- finfo[2..-1].each{|style|
++ font[2..-1].each{|style|
+ case (style)
+ when 'normal'
+ finfo['weight'] = style
diff --git a/ext/tk/sample/demos-en/pendulum.rb b/ext/tk/sample/demos-en/pendulum.rb
index 5f7d361170..36bb44edec 100644
--- a/ext/tk/sample/demos-en/pendulum.rb
+++ b/ext/tk/sample/demos-en/pendulum.rb
@@ -18,10 +18,8 @@ $pendulum_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($pendulum_demo).pack(:fill=>:both, :expand=>true)
-
# create label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($pendulum_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -30,7 +28,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# create frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($pendulum_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -51,11 +49,9 @@ TkFrame.new(base_frame) {|frame|
class PendulumAnimationDemo
def initialize(frame)
# Create some structural widgets
- @pane = TkPanedWindow.new(frame, :orient=>:horizontal).pack(:fill=>:both, :expand=>true)
-# @pane.add(@lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation'))
-# @pane.add(@lf2 = TkLabelFrame.new(@pane, :text=>'Phase Space'))
- @lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation')
- @lf2 = TkLabelFrame.new(@pane, :text=>'Phase Space')
+ pane = TkPanedWindow.new(frame).pack(:fill=>:both, :expand=>true)
+ pane.add(@lf1 = TkLabelFrame.new(pane, :text=>'Pendulum Simulation'))
+ pane.add(@lf2 = TkLabelFrame.new(pane, :text=>'Phase Space'))
# Create the canvas containing the graphical representation of the
# simulated system.
@@ -103,24 +99,23 @@ class PendulumAnimationDemo
@dTheta = 0.0
@length = 150
+ # init display
+ showPendulum
+
# animation loop
@timer = TkTimer.new(15){ repeat }
# binding
@c.bindtags_unshift(btag = TkBindTag.new)
btag.bind('Destroy'){ @timer.stop }
- btag.bind('1', proc{|x, y| @timer.stop; showPendulum(x.to_i, y.to_i)},
- '%x %y')
- btag.bind('B1-Motion', proc{|x, y| showPendulum(x.to_i, y.to_i)}, '%x %y')
+ btag.bind('1', proc{|x, y| @timer.stop; showPendulum(x, y)}, '%x %y')
+ btag.bind('B1-Motion', proc{|x, y| showPendulum(x, y)}, '%x %y')
btag.bind('ButtonRelease-1',
- proc{|x, y| showPendulum(x.to_i, y.to_i); @timer.start },
- '%x %y')
+ proc{|x, y| showPendulum(x, y); @timer.start }, '%x %y')
- btag.bind('Configure', proc{|w| @plate.coords(0, 25, w.to_i, 25)}, '%w')
+ btag.bind('Configure', proc{|w| @plate.coords(0, 25, w, 25)}, '%w')
@k.bind('Configure', proc{|h, w|
- h = h.to_i
- w = w.to_i
@psh = h/2;
@psw = w/2
@x_axis.coords(2, @psh, w-2, @psh)
@@ -129,14 +124,6 @@ class PendulumAnimationDemo
@label_dtheta.coords(w-6, @psh+4)
}, '%h %w')
- # add
- Tk.update
- @pane.add(@lf1)
- @pane.add(@lf2)
-
- # init display
- showPendulum
-
# animation start
@timer.start(500)
end
@@ -167,10 +154,6 @@ class PendulumAnimationDemo
# rate at which the angle is changing (the first derivative with
# respect to time.)
def showPhase
- unless @psw && @psh
- @psw = @k.width/2
- @psh = @k.height/2
- end
@points << @theta + @psw << -20*@dTheta + @psh
if @points.length > 100
@points = @points[-100..-1]
@@ -237,4 +220,4 @@ class PendulumAnimationDemo
end
# Start the animation processing
-PendulumAnimationDemo.new(base_frame)
+PendulumAnimationDemo.new($pendulum_demo)
diff --git a/ext/tk/sample/demos-en/plot.rb b/ext/tk/sample/demos-en/plot.rb
index 628c9df584..6d01deeef5 100644
--- a/ext/tk/sample/demos-en/plot.rb
+++ b/ext/tk/sample/demos-en/plot.rb
@@ -19,16 +19,14 @@ $plot_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($plot_demo).pack(:fill=>:both, :expand=>true)
-
# label
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
+TkLabel.new($plot_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
'text'=>"This window displays a canvas widget containing a simple 2-dimensional plot. You can doctor the data by dragging any of the points with mouse button 1."){
pack('side'=>'top')
}
# frame
-$plot_buttons = TkFrame.new(base_frame) {|frame|
+$plot_buttons = TkFrame.new($plot_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -49,7 +47,7 @@ $plot_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
plotFont = '-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
# canvas
-$plot_canvas = TkCanvas.new(base_frame,'relief'=>'raised','width'=>450,'height'=>300)
+$plot_canvas = TkCanvas.new($plot_demo,'relief'=>'raised','width'=>450,'height'=>300)
$plot_canvas.pack('side'=>'top', 'fill'=>'x')
# plot
diff --git a/ext/tk/sample/demos-en/puzzle.rb b/ext/tk/sample/demos-en/puzzle.rb
index 43c61f519f..0885cf2975 100644
--- a/ext/tk/sample/demos-en/puzzle.rb
+++ b/ext/tk/sample/demos-en/puzzle.rb
@@ -19,10 +19,8 @@ $puzzle_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($puzzle_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($puzzle_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -31,7 +29,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($puzzle_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -54,27 +52,18 @@ TkFrame.new(base_frame) {|frame|
# scrollbar widget and using its trough color.
begin
if Tk.windowingsystem() == 'aqua'
- frameWidth = 168
- frameHeight = 168
- elsif Tk.default_widget_set == :Ttk
- frameWidth = 148
- frameHeight = 124
+ frameSize = 160
else
- frameWidth = 120
- frameHeight = 120
+ frameSize = 120
end
rescue
- frameWidth = 120
- frameHeight = 120
+ frameSize = 120
end
-
-# depend_on_button_width = true
-depend_on_button_width = false
-s = TkScrollbar.new(base_frame)
-base = TkFrame.new(base_frame) {
- width frameWidth
- height frameHeight
+s = TkScrollbar.new($puzzle_demo)
+base = TkFrame.new($puzzle_demo) {
+ width frameSize
+ height frameSize
borderwidth 2
relief 'sunken'
bg s['troughcolor']
@@ -98,9 +87,6 @@ order = [3,1,6,2,5,7,15,13,4,11,8,9,14,10,12]
text num
highlightthickness 0
command def_puzzleswitch_proc(w, num)
- if depend_on_button_width && (w.winfo_reqwidth * 4 > base.width)
- base.width = w.winfo_reqwidth * 4
- end
}.place('relx'=>$xpos[num], 'rely'=>$ypos[num],
'relwidth'=>0.25, 'relheight'=>0.25)
}
diff --git a/ext/tk/sample/demos-en/radio.rb b/ext/tk/sample/demos-en/radio.rb
index 25cfac2134..96cdc4c54a 100644
--- a/ext/tk/sample/demos-en/radio.rb
+++ b/ext/tk/sample/demos-en/radio.rb
@@ -19,10 +19,8 @@ $radio_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($radio_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($radio_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -35,7 +33,7 @@ size = TkVariable.new
color = TkVariable.new
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($radio_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -54,14 +52,14 @@ TkFrame.new(base_frame) {|frame|
TkButton.new(frame) {
text 'See Variables'
command proc{
- showVars(base_frame, ['size', size], ['color', color])
+ showVars($radio_demo, ['size', size], ['color', color])
}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
-f_left = TkFrame.new(base_frame)
-f_right = TkFrame.new(base_frame)
+f_left = TkFrame.new($radio_demo)
+f_right = TkFrame.new($radio_demo)
f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
diff --git a/ext/tk/sample/demos-en/radio2.rb b/ext/tk/sample/demos-en/radio2.rb
index 6c02aef0cf..2b56ccc9b1 100644
--- a/ext/tk/sample/demos-en/radio2.rb
+++ b/ext/tk/sample/demos-en/radio2.rb
@@ -19,10 +19,8 @@ $radio2_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($radio2_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($radio2_demo) {
font $font
wraplength '5i'
justify 'left'
@@ -36,7 +34,7 @@ color = TkVariable.new
align = TkVariable.new
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($radio2_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -55,18 +53,18 @@ TkFrame.new(base_frame) {|frame|
TkButton.new(frame) {
text 'See Variables'
command proc{
- showVars(base_frame,
+ showVars($radio2_demo,
['size', size], ['color', color], ['compound', align])
}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
-f_left = TkLabelFrame.new(base_frame, 'text'=>'Point Size',
+f_left = TkLabelFrame.new($radio2_demo, 'text'=>'Point Size',
'pady'=>2, 'padx'=>2)
-f_mid = TkLabelFrame.new(base_frame, 'text'=>'Color',
+f_mid = TkLabelFrame.new($radio2_demo, 'text'=>'Color',
'pady'=>2, 'padx'=>2)
-f_right = TkLabelFrame.new(base_frame, 'text'=>'Alignment',
+f_right = TkLabelFrame.new($radio2_demo, 'text'=>'Alignment',
'pady'=>2, 'padx'=>2)
f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
f_mid.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
@@ -92,8 +90,7 @@ f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
}.pack('side'=>'top', 'pady'=>2, 'fill'=>'x')
}
-# label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead',
-label = Tk::Label.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead',
+label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead',
'compound'=>'left')
label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top')
label.height(TkWinfo.reqheight(label))
diff --git a/ext/tk/sample/demos-en/radio3.rb b/ext/tk/sample/demos-en/radio3.rb
index 9c9d75ef4a..70c4abb3b5 100644
--- a/ext/tk/sample/demos-en/radio3.rb
+++ b/ext/tk/sample/demos-en/radio3.rb
@@ -19,10 +19,8 @@ $radio3_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($radio3_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($radio3_demo) {
font $font
wraplength '5i'
justify 'left'
@@ -36,14 +34,14 @@ color = TkVariable.new
align = TkVariable.new
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($radio3_demo) {|frame|
TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2),
:columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
TkGrid('x',
TkButton.new(frame, :text=>'See Variables',
:image=>$image['view'], :compound=>:left,
:command=>proc{
- showVars(base_frame, ['size', size],
+ showVars($radio3_demo, ['size', size],
['color', color], ['compound', align])
}),
TkButton.new(frame, :text=>'See Code',
@@ -63,17 +61,17 @@ TkFrame.new(base_frame) {|frame|
}
# frame
-f_left = TkLabelFrame.new(base_frame, 'text'=>'Point Size',
+f_left = TkLabelFrame.new($radio3_demo, 'text'=>'Point Size',
'pady'=>2, 'padx'=>2)
-f_mid = TkLabelFrame.new(base_frame, 'text'=>'Color',
+f_mid = TkLabelFrame.new($radio3_demo, 'text'=>'Color',
'pady'=>2, 'padx'=>2)
-f_right = TkLabelFrame.new(base_frame, 'text'=>'Alignment',
+f_right = TkLabelFrame.new($radio3_demo, 'text'=>'Alignment',
'pady'=>2, 'padx'=>2)
f_left .grid('column'=>0, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c', 'rowspan'=>2)
f_mid .grid('column'=>1, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c', 'rowspan'=>2)
f_right.grid('column'=>2, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c')
-TkButton.new(base_frame, 'text'=>'Tristate',
+TkButton.new($radio3_demo, 'text'=>'Tristate',
'command'=>proc{size.value = 'multi'; color.value = 'multi'}){
grid('column'=>2, 'row'=>2, 'pady'=>'.5c', 'padx'=>'.5c')
}
@@ -101,8 +99,7 @@ TkButton.new(base_frame, 'text'=>'Tristate',
}.pack('side'=>'top', 'pady'=>2, 'fill'=>'x')
}
-# label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead',
-label = Tk::Label.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead',
+label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead',
'compound'=>'left')
label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top')
label.height(TkWinfo.reqheight(label))
diff --git a/ext/tk/sample/demos-en/rolodex-j b/ext/tk/sample/demos-en/rolodex-j
new file mode 100644
index 0000000000..27e2bc9da0
--- /dev/null
+++ b/ext/tk/sample/demos-en/rolodex-j
@@ -0,0 +1,323 @@
+#!/usr/bin/env ruby
+#
+# rolodex --
+# ¤³¤Î¥¹¥¯¥ê¥×¥È¤Ï Tom LaStrange ¤Î rolodex ¤Î°ìÉô¤Ç¤¹¡£
+#
+# Copyright (C) 1998 by Takaaki Tateishi <ttate@jaist.ac.jp>
+# Time-stamp: "03/08/02 14:02:04 nagai"
+#
+
+require "tk"
+
+Tk.encoding = "euc-jp"
+$font = TkFont.new('k14')
+
+def show_help(topic,x=0,y=0)
+ if( topic.is_a?(TkWindow) )
+ w = TkWinfo.containing(x,y)
+ if( w.is_a?(TkWindow) )
+ if( TkWinfo.exist?(w) )
+ topic = w
+ end
+ end
+ end
+
+ if( $helpTopics.include?(topic) )
+ msg = $helpTopics[topic]
+ else
+ msg = "¤³¤Î¥È¥Ô¥Ã¥¯¤Ë¤Ä¤¤¤Æ¤Î¥Ø¥ë¥×¤Ï¤Þ¤À»ÈÍѤǤ­¤Þ¤»¤ó"
+ end
+ TkDialog.new("title"=>"Rolodex Help",
+ "message"=>"¡Ö#{topic}¡×\n\n#{msg}",
+ "font"=>$font,
+ "default_button"=>0,
+ "buttons"=>["OK"])
+end
+
+def fillCard
+ clearAction
+ $root.frame.entry[1].insert(0, "ΩÀÐ ¹§¾´")
+ $root.frame.entry[2].insert(0, "923-1292 ÀÐÀ")
+ $root.frame.entry[3].insert(0, "ä¸ýÄ® °°Âæ 1-1")
+ $root.frame.entry[4].insert(0, "ËÌΦÀèü²Ê³Øµ»½ÑÂç³Ø±¡Âç³Ø")
+ $root.frame.entry[5].insert(0,"private")
+ $root.frame.entry[6].insert(0,"***-***-****")
+ $root.frame.entry[7].insert(0,"***-***-****")
+end
+
+def addAction
+ for i in 1..7
+ STDERR.print format("%-12s %s\n",
+ RolodexFrame::LABEL[i],
+ $root.frame.entry[i].value)
+ end
+end
+
+def clearAction
+ for i in 1..7
+ $root.frame.entry[i].delete(0,"end")
+ end
+end
+
+def fileAction
+ TkDialog.new("title"=>"File Selection",
+ "message"=>"¤³¤ì¤Ï¥Õ¥¡¥¤¥ëÁªÂò¥À¥¤¥¢¥í¥°¤Î¥À¥ß¡¼¤Ç¤¹¡£\n",
+ "font"=>$font,
+ "default_button"=>0,
+ "buttons"=>["OK"])
+ STDERR.print "dummy file name\n"
+end
+
+def deleteAction
+ result = TkDialog.new("title"=>"Confirm Action",
+ "message"=>"¤è¤í¤·¤¤¤Ç¤¹¤«¡©",
+ "font"=>$font,
+ "default_button"=>0,
+ "buttons"=>["¥­¥ã¥ó¥»¥ë"])
+ if( result.value == 0 )
+ clearAction
+ end
+end
+
+
+class RolodexFrame < TkFrame
+ attr_reader :entry, :label
+
+ LABEL = ["","̾Á°:","½»½ê","","","ÅÅÏÃ(¼«Âð):","ÅÅÏÃ(²ñ¼Ò):","Fax:"]
+
+ def initialize(parent=nil,keys=nil)
+ super(parent,keys)
+ self["relief"] = "flat"
+ @i = []
+ @label = []
+ @entry = []
+ for i in 1..7
+ @i[i] = TkFrame.new(self)
+ @i[i].pack("side"=>"top",
+ "pady"=>2,
+ "anchor"=>"e")
+ @label[i] = TkLabel.new(@i[i],
+ "text"=>LABEL[i],
+ "anchor"=>"e",
+ "font" => $font)
+ @entry[i] = TkEntry.new(@i[i],
+ "width"=>30,
+ "relief"=>"sunken",
+ "font" => $font)
+ @entry[i].pack("side"=>"right")
+ @label[i].pack("side"=>"right")
+ end
+ end
+end
+
+class RolodexButtons < TkFrame
+ attr_reader :clear, :add, :search, :delete
+
+ def initialize(parent,keys=nil)
+ super(parent,keys)
+ @clear = TkButton.new(self,
+ "text" => "¥¯¥ê¥¢¡¼",
+ "font" => $font)
+ @add = TkButton.new(self,
+ "text" => "ÄɲÃ",
+ "font" => $font)
+ @search = TkButton.new(self,
+ "text" => "¸¡º÷",
+ "font" => $font)
+ @delete = TkButton.new(self,
+ "text" => "¾Ãµî",
+ "font" => $font)
+ for w in [@clear,@add,@search,@delete]
+ w.pack("side"=>"left", "padx"=>2)
+ end
+ end
+end
+
+class RolodexMenuFrame < TkFrame
+ attr_reader :file_menu, :help_menu, :file, :help
+
+ def initialize(parent,keys=nil)
+ super(parent,keys)
+ configure("relief"=>"raised",
+ "borderwidth"=>1)
+
+ @file = TkMenubutton.new(self,
+ "text"=> "¥Õ¥¡¥¤¥ë",
+ "font"=> $font,
+ "underline"=>0)
+ @file_menu = TkMenu.new(@file)
+ @file_menu.add("command",
+ "label" => "ÆÉ¤ß¹þ¤ß ...",
+ "font" => $font,
+ "command" => proc{fileAction},
+ "underline" => 0)
+ @file_menu.add("command",
+ "label" => "½ªÎ»",
+ "font" => $font,
+ "command" => proc{$root.destroy},
+ "underline" => 0)
+ @file.menu(@file_menu)
+ @file.pack("side"=>"left")
+
+ @help = TkMenubutton.new(self,
+ "text"=> "¥Ø¥ë¥×",
+ "font"=> $font,
+ "underline"=>0)
+ @help_menu = TkMenu.new(@help)
+ @help_menu.add("command",
+ "label"=> "¥³¥ó¥Æ¥­¥¹¥È¤Ë¤Ä¤¤¤Æ",
+ "font" => $font,
+ "command"=>proc{show_help("¥³¥ó¥Æ¥­¥¹¥È")},
+ "underline"=>3)
+ @help_menu.add("command",
+ "label"=> "¥Ø¥ë¥×¤Ë¤Ä¤¤¤Æ",
+ "font" => $font,
+ "command"=>proc{show_help("¥Ø¥ë¥×")},
+ "underline"=>3)
+ @help_menu.add("command",
+ "label"=> "¥¦¥£¥ó¥É¥¦¤Ë¤Ä¤¤¤Æ",
+ "font" => $font,
+ "command"=>proc{show_help("¥¦¥£¥ó¥É¥¦")},
+ "underline"=>3)
+ @help_menu.add("command",
+ "label"=> "¥­¡¼Áàºî¤Ë¤Ä¤¤¤Æ",
+ "font" => $font,
+ "command"=>proc{show_help("¥­¡¼Áàºî")},
+ "underline"=>3)
+ @help_menu.add("command",
+ "label"=> "¥Ð¡¼¥¸¥ç¥ó¾ðÊó",
+ "font" => $font,
+ "command"=>proc{show_help("¥Ð¡¼¥¸¥ç¥ó¾ðÊó")},
+ "underline"=>3)
+ @help.menu(@help_menu)
+ @help.pack("side"=>"right")
+ end
+end
+
+class Rolodex < TkRoot
+ attr_reader :frame, :buttons, :menu
+
+ def initialize(*args)
+ super(*args)
+ @frame = RolodexFrame.new(self)
+ @frame.pack("side"=>"top",
+ "fill"=>"y",
+ "anchor"=>"center")
+ @buttons = RolodexButtons.new(self)
+ @buttons.pack("side"=>"bottom",
+ "pady"=>2,
+ "anchor"=>"center")
+ @menu = RolodexMenuFrame.new(self)
+ @menu.pack("before"=>@frame,
+ "side"=>"top",
+ "fill"=>"x")
+ end
+end
+
+$root = Rolodex.new
+
+$root.buttons.delete.configure("command"=>proc{deleteAction})
+$root.buttons.add.configure("command"=>proc{addAction})
+$root.buttons.clear.configure("command"=>proc{clearAction})
+$root.buttons.search.configure("command"=>proc{addAction; fillCard})
+
+$root.buttons.clear.configure("text"=> "¥¯¥ê¥¢¡¼ Ctrl+C", "font" => $font)
+$root.bind("Control-c",proc{clearAction})
+
+$root.buttons.add.configure("text"=> "Äɲà Ctrl+A", "font" => $font)
+$root.bind("Control-a",proc{addAction})
+
+$root.buttons.search.configure("text"=> "¸¡º÷ Ctrl+S", "font" => $font)
+$root.bind("Control-s",proc{addAction; fillCard})
+
+$root.buttons.delete.configure("text"=> "¾Ãµî Ctrl+D", "font" => $font)
+$root.bind("Control-d",proc{deleteAction})
+
+$root.menu.file_menu.entryconfigure(1, "accel"=>"Ctrl+F")
+$root.bind("Control-f",proc{fileAction})
+
+$root.menu.file_menu.entryconfigure(2, "accel"=>"Ctrl+Q")
+$root.bind("Control-q",proc{$root.destroy})
+
+$root.frame.entry[1].focus
+
+$root.bind("Any-F1",
+ proc{|event| show_help(event.widget, event.x_root, event.y_root)})
+$root.bind("Any-Help",
+ proc{|event| show_help(event.widget, event.x_root, event.y_root)})
+
+
+$helpTopics = {}
+
+$helpTopics[$root.menu.file] = <<EOF
+¤³¤ì¤Ï¡Ö¥Õ¥¡¥¤¥ë¡×¥á¥Ë¥å¡¼¤Ç¤¹¡£¡ÖÆÉ¤ß¹þ¤ß¡×¤ä¡Ö½ªÎ»¡×¤Ê¤É¤ò
+¹Ô¤Ê¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
+EOF
+
+$helpTopics[$root.menu.file_menu.index(0)] = <<EOF
+¥Õ¥¡¥¤¥ë¤ÎÆÉ¤ß¹þ¤ß¤ò¹Ô¤Ê¤¦¤È¤­¤Ë»È¤¤¤Þ¤¹¡£
+EOF
+
+$helpTopics[$root.menu.file_menu.index(1)] = <<EOF
+¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ò½ªÎ»¤¹¤ë¤È¤­¤Ë»È¤¤¤Þ¤¹¡£
+EOF
+
+$helpTopics[$root.frame.entry[1]] = <<EOF
+̾Á°¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£
+EOF
+
+$helpTopics[$root.frame.entry[2]] = <<EOF
+½»½ê¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£
+EOF
+
+$helpTopics[$root.frame.entry[3]] = <<EOF
+½»½ê¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£
+EOF
+
+$helpTopics[$root.frame.entry[4]] = <<EOF
+½»½ê¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£
+EOF
+
+$helpTopics[$root.frame.entry[5]] = <<EOF
+¼«Âð¤ÎÅÅÏÃÈÖ¹æ¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£¸ø³«\
+¤·¤¿¤¯¤Ê¤¤¤È¤­¤Ï private ¤Èµ­Æþ¤·¤Þ¤¹¡£
+EOF
+
+$helpTopics[$root.frame.entry[6]] = <<EOF
+²ñ¼Ò¤ÎÅÅÏÃÈÖ¹æ¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£
+EOF
+
+$helpTopics[$root.frame.entry[7]] = <<EOF
+FAXÈÖ¹æ¤òµ­Æþ¤¹¤ë¥¨¥ó¥È¥ê¤Ç¤¹¡£
+EOF
+
+$helpTopics["¥³¥ó¥Æ¥­¥¹¥È"] = <<EOF
+Ruby/Tk¤Ç¤Ïgrab¤Îµ¡¹½¤¬¤Ê¤¤¤¿¤á¤³¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï\
+¥³¥ó¥Æ¥­¥¹¥È¥Ø¥ë¥×¤Ï¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£
+¤·¤«¤·Æ±¤¸¤è¤¦¤Ê¸ú²Ì¤òbind¤È¥Þ¥¦¥¹¤Î°ÌÃÖ¤ÎWedget¤òÃΤë\
+¤³¤È¤ÇÆÀ¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
+EOF
+
+$helpTopics["¥Ø¥ë¥×"] = <<EOF
+¥Þ¥¦¥¹¤ò¥¦¥£¥ó¥É¥¦¤Ë¤¢¤ï¤»¤ÆF1¥­¡¼¤ò²¡¤¹¤³¤È¤Ë¤è¤Ã¤Æ\
+¤½¤Î¥Ø¥ë¥×¤ò¸«¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
+EOF
+
+$helpTopics["¥¦¥£¥ó¥É¥¦"] = <<EOF
+¤³¤Î¥¦¥£¥ó¥É¥¦¤Ï¥À¥ß¡¼¤Ç¤¹¡£
+EOF
+
+$helpTopics["¥­¡¼Áàºî"] = <<EOF
+Ctrl+A: ÄɲÃ
+Ctrl+C: ¥¯¥ê¥¢¡¼
+Ctrl+D: ¾Ãµî
+Ctrl+F: ¥Õ¥¡¥¤¥ëÁªÂò
+Ctrl+Q: ½ªÎ»
+Ctrl+S: ¸¡º÷
+EOF
+
+$helpTopics["¥Ð¡¼¥¸¥ç¥ó¾ðÊó"] = <<EOF
+¥Ð¡¼¥¸¥ç¥ó¤Ï 1.0.1e ¤Ç¤¹¡£
+EOF
+
+Tk.mainloop
diff --git a/ext/tk/sample/demos-en/ruler.rb b/ext/tk/sample/demos-en/ruler.rb
index 26cd4f3b1c..4299d57b4f 100644
--- a/ext/tk/sample/demos-en/ruler.rb
+++ b/ext/tk/sample/demos-en/ruler.rb
@@ -32,16 +32,14 @@ $ruler_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($ruler_demo).pack(:fill=>:both, :expand=>true)
-
# label
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
+TkLabel.new($ruler_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
'text'=>"This canvas widget shows a mock-up of a ruler. You can create tab stops by dragging them out of the well to the right of the ruler. You can also drag existing tab stops. If you drag a tab stop far enough up or down so that it turns dim, it will be deleted when you release the mouse button."){
pack('side'=>'top')
}
# frame
-$ruler_buttons = TkFrame.new(base_frame) {|frame|
+$ruler_buttons = TkFrame.new($ruler_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -59,7 +57,7 @@ $ruler_buttons = TkFrame.new(base_frame) {|frame|
$ruler_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# canvas
-$ruler_canvas = TkCanvas.new(base_frame, 'width'=>'14.8c', 'height'=>'2.5c')
+$ruler_canvas = TkCanvas.new($ruler_demo, 'width'=>'14.8c', 'height'=>'2.5c')
$ruler_canvas.pack('side'=>'top', 'fill'=>'x')
#
diff --git a/ext/tk/sample/demos-en/sayings.rb b/ext/tk/sample/demos-en/sayings.rb
index 06ec7c1e75..cef0f4ecf4 100644
--- a/ext/tk/sample/demos-en/sayings.rb
+++ b/ext/tk/sample/demos-en/sayings.rb
@@ -20,10 +20,8 @@ $sayings_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($sayings_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($sayings_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -32,7 +30,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($sayings_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -51,7 +49,7 @@ TkFrame.new(base_frame) {|frame|
# frame
sayings_lbox = nil
-TkFrame.new(base_frame, 'borderwidth'=>10) {|w|
+TkFrame.new($sayings_demo, 'borderwidth'=>10) {|w|
sv = TkScrollbar.new(w)
sh = TkScrollbar.new(w, 'orient'=>'horizontal')
sayings_lbox = TkListbox.new(w) {
diff --git a/ext/tk/sample/demos-en/search.rb b/ext/tk/sample/demos-en/search.rb
index e1fc565e9d..3d3b4aecc8 100644
--- a/ext/tk/sample/demos-en/search.rb
+++ b/ext/tk/sample/demos-en/search.rb
@@ -79,10 +79,8 @@ $search_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($search_demo).pack(:fill=>:both, :expand=>true)
-
# frame
-$search_buttons = TkFrame.new(base_frame) {|frame|
+$search_buttons = TkFrame.new($search_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -100,7 +98,7 @@ $search_buttons = TkFrame.new(base_frame) {|frame|
$search_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
-TkFrame.new(base_frame) {|f|
+TkFrame.new($search_demo) {|f|
TkLabel.new(f, 'text'=>'File name:',
'width'=>13, 'anchor'=>'w').pack('side'=>'left')
$search_fileName = TkVariable.new
@@ -117,7 +115,7 @@ TkFrame.new(base_frame) {|f|
.pack('side'=>'left', 'pady'=>5, 'padx'=>10)
}.pack('side'=>'top', 'fill'=>'x')
-TkFrame.new(base_frame) {|f|
+TkFrame.new($search_demo) {|f|
TkLabel.new(f, 'text'=>'Search string:',
'width'=>13, 'anchor'=>'w').pack('side'=>'left')
$search_searchString = TkVariable.new
@@ -135,14 +133,14 @@ TkFrame.new(base_frame) {|f|
}
}.pack('side'=>'top', 'fill'=>'x')
-$search_text = TkText.new(base_frame, 'setgrid'=>true, 'wrap'=>'word') {|t|
+$search_text = TkText.new($search_demo, 'setgrid'=>true, 'wrap'=>'word') {|t|
$search_Tag = TkTextTag.new(t)
- TkScrollbar.new(base_frame, 'command'=>proc{|*args| t.yview(*args)}) {|sc|
+ TkScrollbar.new($search_demo, 'command'=>proc{|*args| t.yview(*args)}) {|sc|
t.yscrollcommand(proc{|first,last| sc.set first,last})
pack('side'=>'right', 'fill'=>'y')
}
pack('expand'=>'yes', 'fill'=>'both')
-}
+}
# Set up display styles for text highlighting.
@@ -175,13 +173,8 @@ type a string in the lower entry and type <Return> or click on \
\"Load File\". This will cause all of the instances of the string to \
be tagged with the tag \"search\", and it will arrange for the tag\'s \
display attributes to change to make all of the strings blink.")
-$search_text.insert('end', "\
-The current directory to load a file is \"#{Dir.pwd}\".\
-")
$search_text.set_insert '0.0'
$search_fileName.value = ''
$search_searchString.value = ''
-$search_text.width = 60
-$search_text.height = 20
diff --git a/ext/tk/sample/demos-en/spin.rb b/ext/tk/sample/demos-en/spin.rb
index c2a3a8949b..58616b1e02 100644
--- a/ext/tk/sample/demos-en/spin.rb
+++ b/ext/tk/sample/demos-en/spin.rb
@@ -15,9 +15,7 @@ $spin_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($spin_demo).pack(:fill=>:both, :expand=>true)
-
-TkLabel.new(base_frame,
+TkLabel.new($spin_demo,
:font=>$font, :wraplength=>'5i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
Three different spin-boxes are displayed below. \
@@ -36,7 +34,7 @@ this demo doesn't work. Please use later version of Tk \
which supports a 'spinbox' widget.
EOL
-TkFrame.new(base_frame){|f|
+TkFrame.new($spin_demo){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{
@@ -55,11 +53,11 @@ australianCities = [
]
[
- TkSpinbox.new(base_frame, :from=>1, :to=>10, :width=>10, :validate=>:key,
+ TkSpinbox.new($spin_demo, :from=>1, :to=>10, :width=>10, :validate=>:key,
:validatecommand=>[
proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P'
]),
- TkSpinbox.new(base_frame, :from=>0, :to=>3, :increment=>0.5,
+ TkSpinbox.new($spin_demo, :from=>0, :to=>3, :increment=>0.5,
:format=>'%05.2f', :width=>10),
- TkSpinbox.new(base_frame, :values=>australianCities, :width=>10)
+ TkSpinbox.new($spin_demo, :values=>australianCities, :width=>10)
].each{|sbox| sbox.pack(:side=>:top, :pady=>5, :padx=>10)}
diff --git a/ext/tk/sample/demos-en/states.rb b/ext/tk/sample/demos-en/states.rb
index add0e84800..d38c1245af 100644
--- a/ext/tk/sample/demos-en/states.rb
+++ b/ext/tk/sample/demos-en/states.rb
@@ -19,10 +19,8 @@ $states_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($states_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($states_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -31,7 +29,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($states_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -50,7 +48,7 @@ TkFrame.new(base_frame) {|frame|
# frame
states_lbox = nil
-TkFrame.new(base_frame, 'borderwidth'=>'.5c') {|w|
+TkFrame.new($states_demo, 'borderwidth'=>'.5c') {|w|
s = TkScrollbar.new(w)
states_lbox = TkListbox.new(w) {
setgrid 1
diff --git a/ext/tk/sample/demos-en/style.rb b/ext/tk/sample/demos-en/style.rb
index c2fed23926..5ed11aa459 100644
--- a/ext/tk/sample/demos-en/style.rb
+++ b/ext/tk/sample/demos-en/style.rb
@@ -19,10 +19,8 @@ $style_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($style_demo).pack(:fill=>:both, :expand=>true)
-
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($style_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -39,14 +37,13 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# text
-txt = TkText.new(base_frame){|t|
+TkText.new($style_demo){|t|
#
setgrid 'true'
- #width 70
- #height 32
+ width 70
+ height 32
wrap 'word'
- font $font
- TkScrollbar.new(base_frame) {|s|
+ TkScrollbar.new($style_demo) {|s|
pack('side'=>'right', 'fill'=>'y')
command proc{|*args| t.yview(*args)}
t.yscrollcommand proc{|first,last| s.set first,last}
@@ -54,20 +51,11 @@ txt = TkText.new(base_frame){|t|
pack('expand'=>'yes', 'fill'=>'both')
#
- family = 'Courier'
-
- if $tk_version =~ /^4.*/
- style_tag_bold = TkTextTag.new(t, 'font'=>'-*-Courier-Bold-O-Normal--*-120-*-*-*-*-*-*')
- style_tag_big = TkTextTag.new(t, 'font'=>'-*-Courier-Bold-R-Normal--*-140-*-*-*-*-*-*', 'kanjifont'=>$msg_kanji_font)
+ style_tag_bold = TkTextTag.new(t, 'font'=>'-*-Courier-Bold-O-Normal--*-120-*-*-*-*-*-*')
+ style_tag_big = TkTextTag.new(t, 'font'=>'-*-Courier-Bold-R-Normal--*-140-*-*-*-*-*-*', 'kanjifont'=>$msg_kanji_font)
style_tag_verybig = TkTextTag.new(t, 'font'=>'-*-Helvetica-Bold-R-Normal--*-240-*-*-*-*-*-*')
- # style_tag_small = TkTextTag.new(t, 'font'=>'-Adobe-Helvetica-Bold-R-Normal-*-100-*', 'kanjifont'=>$kanji_font)
+# style_tag_small = TkTextTag.new(t, 'font'=>'-Adobe-Helvetica-Bold-R-Normal-*-100-*', 'kanjifont'=>$kanji_font)
style_tag_small = TkTextTag.new(t, 'font'=>'-Adobe-Helvetica-Bold-R-Normal-*-100-*')
- else
- style_tag_bold = TkTextTag.new(t, 'font'=>[family, 12, :bold, :italic])
- style_tag_big = TkTextTag.new(t, 'font'=>[family, 14, :bold])
- style_tag_verybig = TkTextTag.new(t, 'font'=>['Helvetica', 24, :bold])
- style_tag_small = TkTextTag.new(t, 'font'=>'Times 8 bold')
- end
###
# case($tk_version)
# when /^4.*/
@@ -121,13 +109,8 @@ txt = TkText.new(base_frame){|t|
style_tag_overstrike = TkTextTag.new(t, 'overstrike'=>'on')
style_tag_right = TkTextTag.new(t, 'justify'=>'right')
style_tag_center = TkTextTag.new(t, 'justify'=>'center')
- if $tk_version =~ /^4.*/
- style_tag_super = TkTextTag.new(t, 'offset'=>'4p', 'font'=>'-Adobe-Courier-Medium-R-Normal--*-100-*-*-*-*-*-*')
- style_tag_sub = TkTextTag.new(t, 'offset'=>'-2p', 'font'=>'-Adobe-Courier-Medium-R-Normal--*-100-*-*-*-*-*-*')
- else
- style_tag_super = TkTextTag.new(t, 'offset'=>'4p', 'font'=>[family, 10])
- style_tag_sub = TkTextTag.new(t, 'offset'=>'-2p', 'font'=>[family, 10])
- end
+ style_tag_super = TkTextTag.new(t, 'offset'=>'4p', 'font'=>'-Adobe-Courier-Medium-R-Normal--*-100-*-*-*-*-*-*')
+ style_tag_sub = TkTextTag.new(t, 'offset'=>'-2p', 'font'=>'-Adobe-Courier-Medium-R-Normal--*-100-*-*-*-*-*-*')
style_tag_margins = TkTextTag.new(t, 'lmargin1'=>'12m', 'lmargin2'=>'6m',
'rmargin'=>'10m')
style_tag_spacing = TkTextTag.new(t, 'spacing1'=>'10p', 'spacing2'=>'2p',
@@ -149,8 +132,7 @@ available display styles are:
insert('end', " You can choose any X font, ")
insert('end', "large", style_tag_verybig)
insert('end', " or ")
- insert('end', "small", style_tag_small)
- insert('end', ".\n")
+ insert('end', "small.\n")
insert('end', "\n2. Color.", style_tag_big)
insert('end', " You can change either the ")
insert('end', "background", style_tag_color1)
@@ -227,5 +209,3 @@ available display styles are:
}
-txt.width 70
-txt.height 32
diff --git a/ext/tk/sample/demos-en/text.rb b/ext/tk/sample/demos-en/text.rb
index 3ce8cdfda8..4bb4b6bc7e 100644
--- a/ext/tk/sample/demos-en/text.rb
+++ b/ext/tk/sample/demos-en/text.rb
@@ -19,8 +19,6 @@ $text_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($text_demo).pack(:fill=>:both, :expand=>true)
-
# version check
if ((Tk::TK_VERSION.split('.').collect{|n| n.to_i} <=> [8,4]) < 0)
undo_support = false
@@ -29,7 +27,7 @@ else
end
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($text_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -46,7 +44,7 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# text
-TkText.new(base_frame){|t|
+TkText.new($text_demo){|t|
relief 'sunken'
bd 2
setgrid 1
@@ -55,7 +53,7 @@ TkText.new(base_frame){|t|
undo true
autoseparators true
end
- TkScrollbar.new(base_frame) {|s|
+ TkScrollbar.new($text_demo) {|s|
pack('side'=>'right', 'fill'=>'y')
command proc{|*args| t.yview(*args)}
t.yscrollcommand proc{|first,last| s.set first,last}
diff --git a/ext/tk/sample/demos-en/textpeer.rb b/ext/tk/sample/demos-en/textpeer.rb
deleted file mode 100644
index c25ce15e5c..0000000000
--- a/ext/tk/sample/demos-en/textpeer.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-#
-# text widget peering demo (called by 'widget')
-#
-# based on Tcl/Tk8.5.0 widget demos
-
-if defined?($textpeer_demo) && $textpeer_demo
- $textpeer_demo.destroy
- $textpeer_demo = nil
-end
-
-# demo toplevel widget
-$textpeer_demo = TkToplevel.new {|w|
- title("Text Wdget Peering Demonstration")
- iconname("textpeer")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($textpeer_demo).pack(:fill=>:both, :expand=>true)
-
-count = [0]
-
-## Define a widget that we peer from; it won't ever actually be shown though
-first = TkText.new(base_frame, :widgetname=>"text#{count[0] += 1}")
-first.insert :end,"This is a coupled pair of text widgets; they are peers to "
-first.insert :end,"each other. They have the same underlying data model, but "
-first.insert :end,"can show different locations, have different current edit "
-first.insert :end,"locations, and have different selections. You can also "
-first.insert :end,"create additional peers of any of these text widgets using "
-first.insert :end,"the Make Peer button beside the text widget to clone, and "
-first.insert :end,"delete a particular peer widget using the Delete Peer "
-first.insert :end,"button."
-
-Tk.update_idletasks ## for 'first' widget
-
-## Procedures to make and kill clones; most of this is just so that the demo
-## looks nice...
-def makeClone(count, win, txt)
- cnt = (count[0] += 1)
- peer = TkText::Peer.new(txt, win, :widgetname=>"text#{cnt}")
- sbar = TkScrollbar.new(win, :widgetname=>"sb#{cnt}")
- peer.yscrollbar sbar
- b1 = TkButton.new(win, :widgetname=>"clone#{cnt}", :text=>'Make Peer',
- :command=>proc{makeClone(count, win, peer)})
- b2 = TkButton.new(win, :widgetname=>"kill#{cnt}", :text=>'Delete Peer',
- :command=>proc{killClone(win, cnt)})
- row = cnt * 2
- TkGrid.configure(peer, sbar, b1, :sticky=>'nsew', :row=>row)
- TkGrid.configure('^', '^', b2, :sticky=>'nsew', :row=>(row+=1))
- TkGrid.configure(b1, b2, :sticky=>'new')
- TkGrid.rowconfigure(win, b2, :weight=>1)
-end
-
-def killClone(win, cnt)
- Tk.destroy("#{win.path}.text#{cnt}", "#{win.path}.sb#{cnt}",
- "#{win.path}.clone#{cnt}", "#{win.path}.kill#{cnt}")
-end
-
-## Now set up the GUI
-makeClone(count, base_frame, first)
-makeClone(count, base_frame, first)
-first.destroy
-
-## See Code / Dismiss buttons
-TkFrame.new(base_frame){|f|
- TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{
- $textpeer_demo.destroy
- $textpeer_demo = nil
- }).pack(:side=>:left, :expand=>true)
-
- TkButton.new(f, :text=>'See Code', :width=>15, :command=>proc{
- showCode 'textpeer'
- }).pack(:side=>:left, :expand=>true)
-
- TkGrid.configure(f, '-', '-', :sticky=>'ew', :row=>5000)
-}
-TkGrid.columnconfigure(base_frame, 0, :weight=>1)
diff --git a/ext/tk/sample/demos-en/toolbar.rb b/ext/tk/sample/demos-en/toolbar.rb
deleted file mode 100644
index 5cf863717b..0000000000
--- a/ext/tk/sample/demos-en/toolbar.rb
+++ /dev/null
@@ -1,130 +0,0 @@
-# toolbar.rb --
-#
-# This demonstration script creates a toolbar that can be torn off.
-#
-# based on "Id: toolbar.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($toolbar_demo) && $toolbar_demo
- $toolbar_demo.destroy
- $toolbar_demo = nil
-end
-
-$toolbar_demo = TkToplevel.new {|w|
- title("Ttk Menu Buttons")
- iconname("toolbar")
- positionWindow(w)
-}
-
-base_frame = Ttk::Frame.new($toolbar_demo).pack(:fill=>:both, :expand=>true)
-
-if Tk.windowingsystem != 'aqua'
- msg = Ttk::Label.new(base_frame, :wraplength=>'4i',
- :text=>Tk::UTF8_String.new(<<EOL))
-This is a demonstration of how to do \
-a toolbar that is styled correctly \
-and which can be torn off (this feature reqrires Tcl/Tk8.5). \
-The buttons are configured to be \\u201Ctoolbar style\\u201D buttons by \
-telling them that they are to use the Toolbutton style. At the left \
-end of the toolbar is a simple marker that the cursor changes to a \
-movement icon over; drag that away from the toolbar to tear off the \
-whole toolbar into a separate toplevel widget. When the dragged-off \
-toolbar is no longer needed, just close it like any normal toplevel \
-and it will reattach to the window it was torn off from.
-EOL
-else
- msg = Ttk::Label.new(base_frame, :wraplength=>'4i',
- :text=>Tk::UTF8_String.new(<<EOL))
-This is a demonstration of how to do \
-a toolbar that is styled correctly. The buttons are configured to \
-be \\u201Ctoolbar style\\u201D buttons by telling them that they are \
-to use the Toolbutton style.
-EOL
-end
-
-## Set up the toolbar hull
-tbar_base = Tk::Frame.new(base_frame, # Must be a starndard Tk frame!
- :widgetname=>'toolbar') # for window title
-sep = Ttk::Separator.new(base_frame)
-to_base = Ttk::Frame.new(tbar_base, :cursor=>'fleur')
-if Tk.windowingsystem != 'aqua'
- to = Ttk::Separator.new(to_base, :orient=>:vertical)
- to2 = Ttk::Separator.new(to_base, :orient=>:vertical)
- to.pack(:fill=>:y, :expand=>true, :padx=>2, :side=>:left)
- to2.pack(:fill=>:y, :expand=>true, :side=>:left)
-end
-
-contents = Ttk::Frame.new(tbar_base)
-Tk.grid(to_base, contents, :sticky=>'nsew')
-tbar_base.grid_columnconfigure(contents, :weight=>1)
-contents.grid_columnconfigure(1000, :weight=>1)
-
-if Tk.windowingsystem != 'aqua'
- ## Bindings so that the toolbar can be torn off and reattached
- to_base.bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)}
- to. bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)}
- to2. bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)}
- def tbar_base.tearoff(w, x, y)
- on_win = TkWinfo.containing(x, y)
- return unless (on_win && on_win.path =~ /^#{@path}(\.|$)/)
- self.grid_remove
- w.grid_remove
- self.wm_manage
- # self.wm_title('Toolbar') # if you don't want to use its widget name as a window title.
- self.wm_protocol('WM_DELETE_WINDOW'){ self.untearoff(self) }
- end
- def tbar_base.untearoff(w)
- self.wm_forget
- w.grid
- self.grid
- end
-end
-
-## Some content for the rest of the toplevel
-text = TkText.new(base_frame, :width=>40, :height=>10)
-
-## Toolbar contents
-tb_btn = Ttk::Button.new(tbar_base, :text=>'Button', :style=>'Toolbutton',
- :command=>proc{text.insert(:end, "Button Pressed\n")})
-tb_chk = Ttk::Checkbutton.new(tbar_base, :text=>'Check', :style=>'Toolbutton',
- :variable=>(check = TkVariable.new),
- :command=>proc{
- text.insert(:end, "Check is #{check.value}\n")
- })
-tb_mbtn = Ttk::Menubutton.new(tbar_base, :text=>'Menu')
-tb_combo = Ttk::Combobox.new(tbar_base, :value=>TkFont.families,
- :state=>:readonly)
-tb_mbtn.menu(menu = Tk::Menu.new(tb_mbtn))
-menu.add(:command, :label=>'Just', :command=>proc{text.insert(:end, "Just\n")})
-menu.add(:command, :label=>'An', :command=>proc{text.insert(:end, "An\n")})
-menu.add(:command, :label=>'Example',
- :command=>proc{text.insert(:end, "Example\n")})
-tb_combo.bind('<ComboboxSelected>'){ text.font.family = tb_combo.get }
-
-## Arrange contents
-Tk.grid(tb_btn, tb_chk, tb_mbtn, tb_combo,
- :in=>contents, :padx=>2, :sticky=>'ns')
-Tk.grid(tbar_base, :sticky=>'ew')
-Tk.grid(sep, :sticky=>'ew')
-Tk.grid(msg, :sticky=>'ew')
-Tk.grid(text, :sticky=>'nsew')
-base_frame.grid_rowconfigure(text, :weight=>1)
-base_frame.grid_columnconfigure(text, :weight=>1)
-
-## See Code / Dismiss buttons
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'See Code',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'toolbar'}),
- Ttk::Button.new(frame, :text=>'Dismiss',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $toolbar_demo.destroy
- $toolbar_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- Tk.grid(frame, :sticky=>'ew')
-}
diff --git a/ext/tk/sample/demos-en/tree.rb b/ext/tk/sample/demos-en/tree.rb
deleted file mode 100644
index 0c7f0e71a2..0000000000
--- a/ext/tk/sample/demos-en/tree.rb
+++ /dev/null
@@ -1,119 +0,0 @@
-# tree.rb --
-#
-# This demonstration script creates a toplevel window containing a Ttk
-# tree widget.
-#
-# based on "Id: tree.tcl,v 1.4 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($tree_demo) && $tree_demo
- $tree_demo.destroy
- $tree_demo = nil
-end
-
-$tree_demo = TkToplevel.new {|w|
- title("Directory Browser")
- iconname("tree")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($tree_demo).pack(:fill=>:both, :expand=>true)
-
-## Explanatory text
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i',
- :justify=>:left, :anchor=>'n', :padding=>[10, 2, 10, 6],
- :text=><<EOL).pack(:fill=>:x)
-Ttk is the new Tk themed widget set. \
-One of the widgets it includes is a tree widget, \
-which allows the user to browse a hierarchical data-set such as a filesystem. \
-The tree widget not only allows for the tree part itself, \
-but it also supports an arbitrary number of additional columns \
-which can show additional data (in this case, the size of the files \
-found in your filesystem). \
-You can also change the width of the columns \
-by dragging the boundary between them.
-EOL
-
-## See Code / Dismiss
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'See Code',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'tree'}),
- Ttk::Button.new(frame, :text=>'Dismiss',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $tree_demo.destroy
- $tree_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-## Code to populate the roots of the tree (can be more than one on Windows)
-def populate_roots(tree)
- TkComm.simplelist(Tk.tk_call('file', 'volumes')).sort.each{|dir|
- populate_tree(tree, tree.insert(nil, :end, :text=>dir,
- :values=>[dir, 'directory']))
- }
-end
-
-## Code to populate a node of the tree
-def populate_tree(tree, node)
- return if tree.get(node, :type) != 'directory'
-
- path = tree.get(node, :fullpath)
- tree.delete(tree.children(node))
- Dir.glob("#{path}/*").sort.each{|f|
- type = File.ftype(f)
- id = tree.insert(node, :end,
- :text=>File.basename(f), :values=>[f, type]).id
- if type == 'directory'
- ## Make it so that this node is openable
- tree.insert(id, 0, :text=>'dummy')
- tree.itemconfigure(id, :text=>File.basename(f))
- elsif type == 'file'
- size = File.size(f)
- if size >= 1024*1024*1024
- size = '%.1f GB' % (size.to_f/1024/1024/1024)
- elsif size >= 1024*1024
- size = '%.1f MB' % (size.to_f/1024/1024)
- elsif size >= 1024
- size = '%.1f KB' % (size.to_f/1024)
- else
- size = '%.1f bytes' % (size.to_f/1024)
- end
- tree.set(id, :size, size)
- end
- }
-
- # Stop this code from rerunning on the current node
- tree.set(node, :type, 'processed_directory')
-end
-
-## Create the tree and set it up
-tree = Ttk::Treeview.new(base_frame, :columns=>%w(fullpath type size),
- :displaycolumns=>['size'])
-if Tk.windowingsystem != 'aqua'
- vsb = tree.yscrollbar(Ttk::Scrollbar.new(base_frame))
- hsb = tree.xscrollbar(Ttk::Scrollbar.new(base_frame))
-else
- vsb = tree.yscrollbar(Tk::Scrollbar.new(base_frame))
- hsb = tree.xscrollbar(Tk::Scrollbar.new(base_frame))
-end
-
-tree.heading_configure('#0', :text=>'Directory Structure')
-tree.heading_configure('size', :text=>'File Size')
-tree.column_configure('size', :stretch=>0, :width=>70)
-populate_roots(tree)
-tree.bind('<TreeviewOpen>', '%W'){|w| populate_tree(w, w.focus_item)}
-
-## Arrange the tree and its scrollbars in the toplevel
-container = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
-container.lower
-Tk.grid(tree, vsb, :in=>container, :sticky=>'nsew')
-Tk.grid(hsb, :in=>container, :sticky=>'nsew')
-container.grid_columnconfigure(0, :weight=>1)
-container.grid_rowconfigure(0, :weight=>1)
diff --git a/ext/tk/sample/demos-en/ttkbut.rb b/ext/tk/sample/demos-en/ttkbut.rb
deleted file mode 100644
index b5780f589a..0000000000
--- a/ext/tk/sample/demos-en/ttkbut.rb
+++ /dev/null
@@ -1,139 +0,0 @@
-# ttkbut.rb
-#
-# This demonstration script creates a toplevel window containing several
-# simple Ttk widgets, such as labels, labelframes, buttons, checkbuttons and
-# radiobuttons.
-#
-# based on "Id: ttkbut.tcl,v 1.4 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($ttkbut_demo) && $ttkbut_demo
- $ttkbut_demo.destroy
- $ttkbut_demo = nil
-end
-
-$ttkbut_demo = TkToplevel.new {|w|
- title("Simple Ttk Widgets")
- iconname("ttkbut")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($ttkbut_demo).pack(:fill=>:both, :expand=>true)
-
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left,
- :text=><<EOL).pack(:side=>:top, :fill=>:x)
-Ttk is the new Tk themed widget set. This is a Ttk themed label, \
-and below are three groups of Ttk widgets in Ttk labelframes. \
-The first group are all buttons that set the current application theme \
-when pressed. The second group contains three sets of checkbuttons, \
-with a separator widget between the sets. Note that the "Enabled" \
-button controls whether all the other themed widgets in this toplevel are \
-in the disabled state. The third group has a collection of linked \
-radiobuttons.
-EOL
-
-## Add buttons for setting the theme
-buttons = Ttk::Labelframe.new(base_frame, :text=>'Buttons')
-# Ttk::Style.theme_names.each{|theme|
-# Ttk::Button.new(buttons, :text=>theme,
-# :command=>proc{Ttk::Style.theme_use theme}).pack(:pady=>2)
-# }
-Ttk.themes.each{|theme|
- Ttk::Button.new(buttons, :text=>theme,
- :command=>proc{Ttk.set_theme theme}).pack(:pady=>2)
-}
-
-## Helper procedure for the top checkbutton
-def setState(root, value, *excepts)
- return if excepts.member?(root)
-
- ## Non-Ttk widgets (e.g. the toplevel) will fail, so make it silent
- begin
- root.state = value
- rescue
- end
-
- ## Recursively invoke on all children of this root that are in the same
- ## toplevel widget
- root.winfo_children.each{|w|
- setState(w, value, *excepts) if w.winfo_toplevel == root.winfo_toplevel
- }
-end
-
-## Set up the checkbutton group
-checks = Ttk::Labelframe.new(base_frame, :text=>'Checkbuttons')
-enabled = TkVariable.new(true)
-e = Ttk::Checkbutton.new(checks, :text=>'Enabled', :variable=>enabled,
- :command=>proc{
- setState($ttkbut_demo,
- ((enabled.bool)? "!disabled" : "disabled"),
- e)
- })
-
-## See ttk_widget(n) for other possible state flags
-sep1 = Ttk::Separator.new(checks)
-sep2 = Ttk::Separator.new(checks)
-
-cheese = TkVariable.new
-tomato = TkVariable.new
-basil = TkVariable.new
-oregano = TkVariable.new
-
-c1 = Ttk::Checkbutton.new(checks, :text=>'Cheese', :variable=>cheese)
-c2 = Ttk::Checkbutton.new(checks, :text=>'Tomato', :variable=>tomato)
-c3 = Ttk::Checkbutton.new(checks, :text=>'Basil', :variable=>basil)
-c4 = Ttk::Checkbutton.new(checks, :text=>'Oregano', :variable=>oregano)
-
-Tk.pack(e, sep1, c1, c2, sep2, c3, c4, :fill=>:x, :pady=>2)
-
-## Set up the radiobutton group
-radios = Ttk::Labelframe.new(base_frame, :text=>'Radiobuttons')
-
-happyness = TkVariable.new
-
-r1 = Ttk::Radiobutton.new(radios, :variable=>happyness,
- :text=>'Great', :value=>'great')
-r2 = Ttk::Radiobutton.new(radios, :variable=>happyness,
- :text=>'Good', :value=>'good')
-r3 = Ttk::Radiobutton.new(radios, :variable=>happyness,
- :text=>'Ok', :value=>'ok')
-r4 = Ttk::Radiobutton.new(radios, :variable=>happyness,
- :text=>'Poor', :value=>'poor')
-r5 = Ttk::Radiobutton.new(radios, :variable=>happyness,
- :text=>'Awful', :value=>'awful')
-
-Tk.pack(r1, r2, r3, r4, r5, :fill=>:x, :padx=>3, :pady=>2)
-
-## See Code / Dismiss
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'See Variables',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{
- showVars(base_frame, ['enabled', enabled],
- ['cheese', cheese], ['tomato', tomato],
- ['basil', basil], ['oregano', oregano],
- ['happyness', happyness])
- }),
- Ttk::Button.new(frame, :text=>'See Code',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'ttkbut'}),
- Ttk::Button.new(frame, :text=>'Dismiss',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- tmppath = $ttkbut_demo
- $ttkbut_demo = nil
- $showVarsWin[tmppath.path] = nil
- tmppath.destroy
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x, :expand=>true)
-}
-
-## Arrange things neatly
-f = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
-f.lower
-Tk.grid(buttons, checks, radios, :in=>f, :sticky=>'nwe', :pady=>2, :padx=>3)
-f.grid_columnconfigure([0, 1, 2], :weight=>1, :uniform=>:yes)
diff --git a/ext/tk/sample/demos-en/ttkmenu.rb b/ext/tk/sample/demos-en/ttkmenu.rb
deleted file mode 100644
index 75ecdb09c4..0000000000
--- a/ext/tk/sample/demos-en/ttkmenu.rb
+++ /dev/null
@@ -1,85 +0,0 @@
-# ttkmenu.rb --
-#
-# This demonstration script creates a toplevel window containing several Ttk
-# menubutton widgets.
-#
-# based on "Id: ttkmenu.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($ttkmenu_demo) && $ttkmenu_demo
- $ttkmenu_demo.destroy
- $ttkmenu_demo = nil
-end
-
-$ttkmenu_demo = TkToplevel.new {|w|
- title("Ttk Menu Buttons")
- iconname("ttkmenu")
- positionWindow(w)
-}
-
-base_frame = Ttk::Frame.new($ttkmenu_demo).pack(:fill=>:both, :expand=>true)
-
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left,
- :text=><<EOL).pack(:side=>:top, :fill=>:x)
-Ttk is the new Tk themed widget set, \
-and one widget that is available in themed form is the menubutton. \
-Below are some themed menu buttons \
-that allow you to pick the current theme in use. \
-Notice how picking a theme changes the way \
-that the menu buttons themselves look, \
-and that the central menu button is styled differently \
-(in a way that is normally suitable for toolbars). \
-However, there are no themed menus; the standard Tk menus were judged \
-to have a sufficiently good look-and-feel on all platforms, \
-especially as they are implemented as native controls in many places.
-EOL
-
-Ttk::Separator.new(base_frame).pack(:side=>:top, :fill=>:x)
-
-## See Code / Dismiss
-Ttk::Frame.new($ttkmenu_demo) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'See Code',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'ttkmenu'}),
- Ttk::Button.new(frame, :text=>'Dismiss',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $ttkmenu_demo.destroy
- $ttkmenu_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-b1 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:above)
-b2 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:left)
-b3 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:right)
-b4 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:flush,
- :style=>Ttk::Menubutton.style('Toolbutton'))
-b5 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:below)
-
-b1.menu(m1 = Tk::Menu.new(b1, :tearoff=>false))
-b2.menu(m2 = Tk::Menu.new(b2, :tearoff=>false))
-b3.menu(m3 = Tk::Menu.new(b3, :tearoff=>false))
-b4.menu(m4 = Tk::Menu.new(b4, :tearoff=>false))
-b5.menu(m5 = Tk::Menu.new(b5, :tearoff=>false))
-
-Ttk.themes.each{|theme|
- m1.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
- m2.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
- m3.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
- m4.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
- m5.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
-}
-
-f = Ttk::Frame.new(base_frame).pack(:fill=>:x)
-f1 = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
-f.lower
-
-f.grid_anchor(:center)
-TkGrid('x', b1, 'x', :in=>f, :padx=>3, :pady=>2)
-TkGrid(b2, b4, b3, :in=>f, :padx=>3, :pady=>2)
-TkGrid('x', b5, 'x', :in=>f, :padx=>3, :pady=>2)
diff --git a/ext/tk/sample/demos-en/ttknote.rb b/ext/tk/sample/demos-en/ttknote.rb
deleted file mode 100644
index c2a22b447a..0000000000
--- a/ext/tk/sample/demos-en/ttknote.rb
+++ /dev/null
@@ -1,89 +0,0 @@
-# ttknote.rb --
-#
-# This demonstration script creates a toplevel window containing a Ttk
-# notebook widget.
-#
-# based on "Id: ttknote.tcl,v 1.5 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($ttknote_demo) && $ttknote_demo
- $ttknote_demo.destroy
- $ttknote_demo = nil
-end
-
-$ttknote_demo = TkToplevel.new {|w|
- title("Ttk Notebook Widget")
- iconname("ttknote")
- positionWindow(w)
-}
-
-## See Code / Dismiss
-Ttk::Frame.new($ttknote_demo) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'See Code',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'ttknote'}),
- Ttk::Button.new(frame, :text=>'Dismiss',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $ttknote_demo.destroy
- $ttknote_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-base_frame = Ttk::Frame.new($ttknote_demo).pack(:fill=>:both, :expand=>true)
-
-## Make the notebook and set up Ctrl+Tab traversal
-notebook = Ttk::Notebook.new(base_frame).pack(:fill=>:both, :expand=>true,
- :padx=>2, :pady=>3)
-notebook.enable_traversal
-
-## Popuplate the first pane
-f_msg = Ttk::Frame.new(notebook)
-msg_m = Ttk::Label.new(f_msg, :font=>$font, :wraplength=>'4i',
- :justify=>:left, :anchor=>'n', :text=><<EOL)
-Ttk is the new Tk themed widget set. \
-One of the widgets it includes is the notebook widget, \
-which provides a set of tabs that allow the selection of a group of panels, \
-each with distinct content. \
-They are a feature of many modern user interfaces. \
-Not only can the tabs be selected with the mouse, \
-but they can also be switched between using Ctrl+Tab \
-when the notebook page heading itself is selected. \
-Note that the second tab is disabled, and cannot be selected.
-EOL
-neat = TkVariable.new
-after_id = nil
-msg_b = Ttk::Button.new(f_msg, :text=>'Neat!', :underline=>0,
- :command=>proc{
- neat.value = 'Yeah, I know...'
- Tk.after_cancel(after_id) if after_id
- after_id = Tk.after(500){neat.value = ''}
- })
-msg_b.winfo_toplevel.bind('Alt-n'){ msg_b.focus; msg_b.invoke }
-msg_l = Ttk::Label.new(f_msg, :textvariable=>neat)
-notebook.add(f_msg, :text=>'Description', :underline=>0, :padding=>2)
-Tk.grid(msg_m, '-', :sticky=>'new', :pady=>2)
-Tk.grid(msg_b, msg_l, :pady=>[2, 4])
-f_msg.grid_rowconfigure(1, :weight=>1)
-f_msg.grid_columnconfigure([0, 1], :weight=>1, :uniform=>1)
-
-## Populate the second pane. Note that the content doesn't really matter
-f_disabled = Ttk::Frame.new(notebook)
-notebook.add(f_disabled, :text=>'Disabled', :state=>:disabled)
-
-## Popuplate the third pane
-f_editor = Ttk::Frame.new(notebook)
-notebook.add(f_editor, :text=>'Text Editor', :underline=>0)
-editor_t = Tk::Text.new(f_editor, :width=>40, :height=>10, :wrap=>:char)
-if Tk.windowingsystem != 'aqua'
- editor_s = editor_t.yscrollbar(Ttk::Scrollbar.new(f_editor))
-else
- editor_s = editor_t.yscrollbar(Tk::Scrollbar.new(f_editor))
-end
-editor_s.pack(:side=>:right, :fill=>:y, :padx=>[0,2], :pady=>2)
-editor_t.pack(:fill=>:both, :expand=>true, :padx=>[2,0], :pady=>2)
diff --git a/ext/tk/sample/demos-en/ttkpane.rb b/ext/tk/sample/demos-en/ttkpane.rb
deleted file mode 100644
index 56df613db4..0000000000
--- a/ext/tk/sample/demos-en/ttkpane.rb
+++ /dev/null
@@ -1,213 +0,0 @@
-# ttkpane.rb --
-#
-# This demonstration script creates a Ttk pane with some content.
-#
-# based on "Id: ttkpane.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($ttkpane_demo) && $ttkpane_demo
- $ttkpane_demo.destroy
- $ttkpane_demo = nil
-end
-
-$ttkpane_demo = TkToplevel.new {|w|
- title("Themed Nested Panes")
- iconname("ttkpane")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($ttkpane_demo).pack(:fill=>:both, :expand=>true)
-
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left,
- :text=><<EOL).pack(:side=>:top, :fill=>:x)
-This demonstration shows off a nested set of themed paned windows. \
-Their sizes can be changed by grabbing the area \
-between each contained pane and dragging the divider.
-EOL
-
-Ttk::Separator.new(base_frame).pack(:side=>:top, :fill=>:x)
-
-## See Code / Dismiss
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'See Code',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'ttkpane'}),
- Ttk::Button.new(frame, :text=>'Dismiss',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $ttkpane_demo.destroy
- $ttkpane_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
-
-outer = Ttk::Panedwindow.new(frame, :orient=>:horizontal)
-outer.add(in_left = Ttk::Panedwindow.new(outer, :orient=>:vertical))
-outer.add(in_right = Ttk::Panedwindow.new(outer, :orient=>:vertical))
-in_left.add(left_top = Ttk::Labelframe.new(in_left, :text=>'Button'))
-in_left.add(left_bot = Ttk::Labelframe.new(in_left, :text=>'Clocks'))
-in_right.add(right_top = Ttk::Labelframe.new(in_right, :text=>'Progress'))
-in_right.add(right_bot = Ttk::Labelframe.new(in_right, :text=>'Text'))
-if Tk.windowingsystem == 'aqua'
- [left_top, left_bot, right_top, right_bot].each{|w| w.padding(3) }
-end
-
-# Fill the button pane
-Ttk::Button.new(left_top, :text=>'Press Me',
- :command=>proc{
- Tk.messageBox(:type=>'ok', :icon=>'info', :message=>'Ouch!',
- :detail=>'That hurt...', :parent=>base_frame,
- :title=>'Button Pressed')
- }).pack(:padx=>2, :pady=>5)
-
-
-zones_list = [
- [':Europe/Berlin'],
- [':America/Argentina/Buenos_Aires', ':America/Buenos_Aires'],
- [':Africa/Johannesburg'],
- [':Europe/London'],
- [':America/Los_Angeles'],
- [':Europe/Moscow'],
- [':America/New_York'],
- [':Asia/Singapore'],
- [':Australia/Sydney'],
- [':Asia/Tokyo'],
-]
-
-zones = []
-
-# Check tzinfo support
-if $tk_major_ver > 8 || ($tk_major_ver == 8 && $tk_minor_ver >= 5)
- tzinfo = :tcl
-
- # Force a pre-load of all the timezones needed; otherwise can end up
- # poor-looking synch problems!
- zones_list.each{|list|
- list.each{|zone|
- begin
- Tk.tk_call('clock', 'format', '0', '-timezone', zone)
- rescue RuntimeError
- # ignore
- else
- zones << [zone, zone[%r<[^/:]+$>].tr('_', ' ')]
- break
- end
- }
- }
-
-else
- begin
- require 'tzinfo'
- tzinfo = :tzinfo
- rescue Exception
- begin
- require 'tzfile'
- tzinfo = :tzfile
- rescue Exception
- tzinfo = nil
- end
- end
-
- case tzinfo
- when :tzinfo
- zones_list.each{|list|
- list.each{|zone|
- begin
- tz = TZInfo::Timezone.get(zone[%r<[^:]+$>])
- rescue Exception
- # ignore
- else
- zones << [tz, zone[%r<[^/:]+$>].tr('_', ' ')]
- break
- end
- }
- }
-
- when :tzfile
- zones_list.each{|list|
- list.each{|zone|
- begin
- tz = TZFile.create(zone[%r<[^:]+$>])
- rescue Exception
- # ignore
- else
- zones << [tz, zone[%r<[^/:]+$>].tr('_', ' ')]
- break
- end
- }
- }
-
- else
- [ -7, -4, -2, -1, 0, +1, +3, +8, +9, +10 ].each{|zone|
- zones << [zone, 'UTC%+03d00' % zone]
- }
- end
-end
-
-time = TkVariable.new_hash
-
-case tzinfo
-when :tcl
- update_proc = proc{|now, tz, label|
- time[label] = Tk.tk_call('clock', 'format', now.tv_sec,
- '-timezone', tz, '-format', '%T')
- }
-when :tzinfo
- update_proc = proc{|now, tz, label|
- time[label] = tz.utc_to_local(now).strftime('%H:%M:%S')
- }
-when :tzfile
- update_proc = proc{|now, tz, label|
- time[label] = tz.at(now.tv_sec).strftime('%H:%M:%S')
- }
-else
- update_proc = proc{|now, tz, label|
- time[label] = (now + (tz * 3600)).strftime('%H:%M:%S')
- }
-end
-
-# Fill the clocks pane
-zones.each_with_index{|(zone, label), idx|
- Ttk::Separator.new(left_bot).pack(:fill=>:x) if idx > 0
- Ttk::Label.new(left_bot, :text=>label, :anchor=>'w').pack(:fill=>:x)
- Ttk::Label.new(left_bot, :textvariable=>time.ref(label),
- :anchor=>'w').pack(:fill=>:x)
-}
-
-# Timer start
-every = proc{
- now = Time.now.utc
- zones.each{|zone, label| update_proc.call(now, zone, label) }
-}
-TkRTTimer.new(1000, -1, every).start(0, every)
-
-# Fill the progress pane
-Ttk::Progressbar.new(right_top, :mode=>:indeterminate).pack(:fill=>:both, :expand=>true).start
-
-# Fill the text pane
-if Tk.windowingsystem != 'aqua'
- # The trick with the ttk::frame makes the text widget look like it fits with
- # the current Ttk theme despite not being a themed widget itself. It is done
- # by styling the frame like an entry, turning off the border in the text
- # widget, and putting the text widget in the frame with enough space to allow
- # the surrounding border to show through (2 pixels seems to be enough).
- f = Ttk::Frame.new(right_bot, :style=>Ttk::Entry)
- txt = TkText.new(frame, :wrap=>:word, :width=>30, :borderwidth=>0)
- txt.pack(:fill=>:both, :expand=>true, :in=>f, :pady=>2, :padx=>2)
- scr = txt.yscrollbar(Ttk::Scrollbar.new(frame))
- scr.pack(:side=>:right, :fill=>:y, :in=>right_bot)
- f.pack(:fill=>:both, :expand=>true)
- outer.pack(:fill=>:both, :expand=>true)
-else
- txt = TkText.new(frame, :wrap=>:word, :width=>30, :borderwidth=>0)
- scr = txt.yscrollbar(TkScrollbar.new(frame))
- scr.pack(:side=>:right, :fill=>:y, :in=>right_bot)
- txt.pack(:fill=>:both, :expand=>true, :in=>right_bot)
- outer.pack(:fill=>:both, :expand=>true, :padx=>10, :pady=>[6, 10])
-end
diff --git a/ext/tk/sample/demos-en/ttkprogress.rb b/ext/tk/sample/demos-en/ttkprogress.rb
deleted file mode 100644
index 3eb9a64a4a..0000000000
--- a/ext/tk/sample/demos-en/ttkprogress.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-# ttkprogress.rb --
-#
-# This demonstration script creates several progress bar widgets.
-#
-# based on "Id: ttkprogress.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($ttkprogress_demo) && $ttkprogress_demo
- $ttkprogress_demo.destroy
- $ttkprogress_demo = nil
-end
-
-$ttkprogress_demo = TkToplevel.new {|w|
- title("Progress Bar Demonstration")
- iconname("ttkprogress")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($ttkprogress_demo).pack(:fill=>:both, :expand=>true)
-
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left,
- :text=>Tk::UTF8_String.new(<<EOL)).pack(:side=>:top, :fill=>:x)
-Below are two progress bars. \
-The top one is a \\u201Cdeterminate\\u201D progress bar, \
-which is used for showing how far through a defined task the program has got. \
-The bottom one is an \\u201Cindeterminate\\u201D progress bar, \
-which is used to show that the program is busy \
-but does not know how long for. Both are run here in self-animated mode, \
-which can be turned on and off using the buttons underneath.
-EOL
-
-## See Code / Dismiss buttons
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'See Code',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'ttkprogress'}),
- Ttk::Button.new(frame, :text=>'Dismiss',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $ttkprogress_demo.destroy
- $ttkprogress_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
-
-p1 = Ttk::Progressbar.new(frame, :mode=>:determinate)
-p2 = Ttk::Progressbar.new(frame, :mode=>:indeterminate)
-
-start = Ttk::Button.new(frame, :text=>'Start Progress',
- :command=>proc{ p1.start; p2.start })
-stop = Ttk::Button.new(frame, :text=>'Stop Progress',
- :command=>proc{ p1.stop; p2.stop })
-
-Tk.grid(p1, '-', :pady=>5, :padx=>10)
-Tk.grid(p2, '-', :pady=>5, :padx=>10)
-Tk.grid(start, stop, :padx=>10, :pady=>5)
-start.grid_configure(:sticky=>'e')
-stop.grid_configure(:sticky=>'w')
-frame.grid_columnconfigure(:all, :weight=>1)
-
diff --git a/ext/tk/sample/demos-en/twind.rb b/ext/tk/sample/demos-en/twind.rb
index 65ee712ff7..24a4bcf706 100644
--- a/ext/tk/sample/demos-en/twind.rb
+++ b/ext/tk/sample/demos-en/twind.rb
@@ -19,10 +19,8 @@ $twind_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($twind_demo).pack(:fill=>:both, :expand=>true)
-
# frame
-$twind_buttons = TkFrame.new(base_frame) {|frame|
+$twind_buttons = TkFrame.new($twind_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
@@ -41,13 +39,13 @@ $twind_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
$twind_text = nil
-TkFrame.new(base_frame, 'highlightthickness'=>2, 'borderwidth'=>2,
+TkFrame.new($twind_demo, 'highlightthickness'=>2, 'borderwidth'=>2,
'relief'=>'sunken') {|f|
$twind_text = TkText.new(f, 'setgrid'=>'true', 'font'=>$font,
'width'=>'70', 'height'=>35, 'wrap'=>'word',
'highlightthickness'=>0, 'borderwidth'=>0 ){|t|
TkScrollbar.new(f) {|s|
- command proc{|*args| t.yview(*args)}
+ command proc{|*args| t.yview(args)}
t.yscrollcommand proc{|first,last| s.set first,last}
}.pack('side'=>'right', 'fill'=>'y')
}.pack('expand'=>'yes', 'fill'=>'both')
@@ -208,11 +206,7 @@ def textWindPlot (t)
cursor 'top_left_arrow'
}
- if $tk_version =~ /^4.*/
- font = '-Adobe-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
- else
- font = 'Helvetica 18'
- end
+ font = '-Adobe-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
TkcLine.new($twind_plot, 100, 250, 400, 250, 'width'=>2)
TkcLine.new($twind_plot, 100, 250, 100, 50, 'width'=>2)
diff --git a/ext/tk/sample/demos-en/twind2.rb b/ext/tk/sample/demos-en/twind2.rb
index 43990c1151..c42e0999d7 100644
--- a/ext/tk/sample/demos-en/twind2.rb
+++ b/ext/tk/sample/demos-en/twind2.rb
@@ -15,10 +15,8 @@ $twind2_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($twind2_demo).pack(:fill=>:both, :expand=>true)
-
# frame
-$twind2_buttons = TkFrame.new(base_frame) {|frame|
+$twind2_buttons = TkFrame.new($twind2_demo) {|frame|
TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2),
:columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
TkGrid('x',
@@ -40,7 +38,7 @@ $twind2_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
$twind2_text = nil
-TkFrame.new(base_frame, 'highlightthickness'=>2, 'borderwidth'=>2,
+TkFrame.new($twind2_demo, 'highlightthickness'=>2, 'borderwidth'=>2,
'relief'=>'sunken') {|f|
$twind2_text = TkText.new(f, 'setgrid'=>true, 'font'=>$font,
# 'width'=>'70', 'height'=>35, 'wrap'=>'word',
diff --git a/ext/tk/sample/demos-en/unicodeout.rb b/ext/tk/sample/demos-en/unicodeout.rb
index 9c230a2536..07e3bf52b5 100644
--- a/ext/tk/sample/demos-en/unicodeout.rb
+++ b/ext/tk/sample/demos-en/unicodeout.rb
@@ -16,9 +16,7 @@ $unicodeout_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($unicodeout_demo).pack(:fill=>:both, :expand=>true)
-
-TkLabel.new(base_frame,
+TkLabel.new($unicodeout_demo,
:font=>$font, :wraplength=>'5.4i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
This is a sample of Tk's support for languages that use non-Western \
@@ -38,7 +36,7 @@ The strings are converted to the encoded string objects \
And the Tk::UTF8_String objects are passed to the label widgets.
EOL
-TkFrame.new(base_frame){|f|
+TkFrame.new($unicodeout_demo){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{
@@ -51,7 +49,7 @@ TkFrame.new(base_frame){|f|
}).pack(:side=>:left, :expand=>true)
}
-wait_msg = TkLabel.new(base_frame,
+wait_msg = TkLabel.new($unicodeout_demo,
:text=>"Please wait while loading fonts...",
:font=>"Helvetica 12 italic").pack
@@ -65,8 +63,8 @@ class Unicodeout_SampleFrame < TkFrame
# @@font = 'Newspaper 12'
# @@font = '{New century schoolbook} 12'
- def initialize(base)
- super(base)
+ def initialize()
+ super($unicodeout_demo)
grid_columnconfig(1, :weight=>1)
end
@@ -81,7 +79,7 @@ class Unicodeout_SampleFrame < TkFrame
l.grid_config(:padx, '1m')
end
end
-f = Unicodeout_SampleFrame.new(base_frame)
+f = Unicodeout_SampleFrame.new
f.pack(:expand=>true, :fill=>:both, :padx=>'2m', :pady=>'1m')
# Processing when some characters are missing might take a while, so make
diff --git a/ext/tk/sample/demos-en/vscale.rb b/ext/tk/sample/demos-en/vscale.rb
index b05ed12072..636b85813b 100644
--- a/ext/tk/sample/demos-en/vscale.rb
+++ b/ext/tk/sample/demos-en/vscale.rb
@@ -15,9 +15,7 @@ $vscale_demo = TkToplevel.new {|w|
}
positionWindow($vscale_demo)
-base_frame = TkFrame.new($vscale_demo).pack(:fill=>:both, :expand=>true)
-
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($vscale_demo) {
font $font
wraplength '3.5i'
justify 'left'
@@ -25,7 +23,7 @@ msg = TkLabel.new(base_frame) {
}
msg.pack('side'=>'top', 'padx'=>'.5c')
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($vscale_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc {
@@ -41,17 +39,7 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
-def setHeight(w, height)
- height = height + 21
- y2 = height - 30
- if y2 < 21
- y2 = 21
- end
- w.coords 'poly',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20
- w.coords 'line',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20
-end
-
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($vscale_demo) {|frame|
borderwidth 10
canvas = TkCanvas.new(frame) {|c|
width 50
@@ -77,3 +65,14 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'left', 'anchor'=>'ne')
scale.set 75
}.pack
+
+
+def setHeight(w, height)
+ height = height + 21
+ y2 = height - 30
+ if y2 < 21
+ y2 = 21
+ end
+ w.coords 'poly',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20
+ w.coords 'line',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20
+end
diff --git a/ext/tk/sample/demos-en/widget b/ext/tk/sample/demos-en/widget
index 9a0605d8b9..3c50582211 100644
--- a/ext/tk/sample/demos-en/widget
+++ b/ext/tk/sample/demos-en/widget
@@ -14,8 +14,6 @@ require 'tk'
### $DEBUG=1 ##########
-$RubyTk_WidgetDemo = true
-
#----------------------------------------------------------------
# The code below create the main window, consisting of a menu bar
# and a text widget that explains how to use the program, plus lists
@@ -23,8 +21,7 @@ $RubyTk_WidgetDemo = true
#----------------------------------------------------------------
# widget demo directory
-# $demo_dir = File.dirname($0)
-$demo_dir = File.dirname(__FILE__)
+$demo_dir = File.dirname($0)
# root
$root = TkRoot.new{title "Ruby/Tk Widget Demonstration"}
@@ -105,22 +102,14 @@ EOD
end
#
-if $tk_major_ver >= 8
- $root.add_menubar([[['File', 0],
- ['About ... ', proc{aboutBox}, 0, '<F1>'],
- '---',
- ['Quit', proc{exit}, 0, 'Ctrl-Q']
- ]])
-else
- TkMenubar.new($root,
- [[['File', 0],
- ['About ... ', proc{aboutBox}, 0, '<F1>'],
- '---',
- ['Quit', proc{exit}, 0, 'Ctrl-Q']
- ]]).pack('side'=>'top', 'fill'=>'x')
-end
+TkMenubar.new($root,
+ [[['File', 0],
+ ['About ... ', proc{aboutBox}, 0, '<F1>'],
+ '---',
+ ['Quit', proc{exit}, 0, 'Meta-Q']
+ ]]).pack('side'=>'top', 'fill'=>'x')
$root.bind('F1', proc{aboutBox})
-$root.bind('Control-q', proc{exit})
+$root.bind('Meta-q', proc{exit})
=begin
TkFrame.new($root){|frame|
@@ -175,17 +164,12 @@ else
textFrame.pack('expand'=>'yes', 'fill'=>'both')
statusBar = TkFrame.new($root) {|f|
- if $tk_version =~ /^4.*/
- statusfont = '-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*'
- else
- statusfont = 'Helvetica 10'
- end
$statusBarLabel = \
TkLabel.new(f, 'text'=>" ", 'relief'=>'sunken', 'bd'=>1, 'anchor'=>'w',
- 'font'=>statusfont) \
+ 'font'=>'-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*') \
.pack('side'=>'left', 'padx'=>2, 'expand'=>'yes', 'fill'=>'both')
TkLabel.new(f, 'width'=>8, 'relief'=>'sunken', 'bd'=>1, 'anchor'=>'w',
- 'font'=>statusfont) \
+ 'font'=>'-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*') \
.pack('side'=>'left', 'padx'=>2)
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>2)
end
@@ -194,11 +178,7 @@ end
# section titles and demo descriptions. Also define the bindings for
# tags.
-if $tk_version =~ /^4.*/
- tag_title = TkTextTag.new(txt, 'font'=>'-*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-*')
-else
- tag_title = TkTextTag.new(txt, 'font'=>'Helvetica 18 bold')
-end
+tag_title = TkTextTag.new(txt, 'font'=>'-*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-*')
# We put some "space" characters to the left and right of each demo description
# so that the descriptions are highlighted only when the mouse cursor
@@ -267,10 +247,7 @@ the demonstration. Once the demonstration window appears, you can \
click the "See Code" button to see the Ruby/Tk code that created the \
demonstration. If you wish, you can edit the code and click the \
"Rerun Demo" button in the code window to reinvoke the demonstration \
-with the modified code. \
-Don't worry about breaking the source code. \
-Your modifications are not reflected on the original file. \
-Please try many kind of changes.
+with the modified code.
Some demo scripts require the recent version of Tk library \
(e.g. Tk8.4 or later) \
@@ -279,20 +256,6 @@ required by the demo script, the demo doesn't work. \
In such a case, please re-compile tcltklib with the later Tk library \
which supports the required functions.
-If your Tk supports Ttk (Tile) extension (included or installed), \
-please try the demo of Ttk extension (sample/tkextlib/tile/demo.rb) too.
-( Probably, Ttk extension \
-#{
-begin
- require 'tkextlib/tile'
- "is already installed on your environment"
-rescue
- "is not installed on your environment yet"
-end
-}\
-. )
-Ttk extension is a standard feature of Tk8.5 or later.
-
EOT
@@ -326,8 +289,6 @@ txt.insert('end', "13. A simple user interface for viewing images. (if supported
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "14. Labelled frames (if supported)\n", tag_demo, "demo-labelframe")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "15. The simple Themed Tk widgets (require Tile/Ttk extension)\n", tag_demo, "demo-ttkbut")
-txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
txt.insert('end', "Listboxes\n", tag_title)
@@ -338,10 +299,6 @@ txt.insert('end', "2. Colors: change the color scheme for the application.\n", "
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. A collection of famous sayings.\n", tag_demo, "demo-sayings")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "4. A multi-column list of contries. (require Tile/Ttk extension)\n", tag_demo, "demo-mclist")
-txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "5. A directory browser tree. (require Tile/Ttk extension)\n", tag_demo, "demo-tree")
-txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
txt.insert('end', "Entries and Spin-boxes\n", tag_title)
@@ -356,9 +313,7 @@ txt.insert('end',
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. Spin-boxes. (if supported)\n", tag_demo, "demo-spin")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "5. Combo-boxes. (require Tile/Ttk extension)\n", tag_demo, "demo-combo")
-txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "6. Simple Rolodex-like form.\n", tag_demo, "demo-form")
+txt.insert('end', "5. Simple Rolodex-like form.\n", tag_demo, "demo-form")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
@@ -376,8 +331,6 @@ txt.insert('end', "5. A text widget with embedded windows. (if supported)\n", ta
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "6. A search tool built with a text widget.\n", tag_demo, "demo-search")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "7. Peering text widgets. (if supported)\n", tag_demo, "demo-textpeer")
-txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
txt.insert('end', "Canvases\n", tag_title)
@@ -398,43 +351,31 @@ txt.insert('end', "7. A building floor plan. (another way to create canvas items
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "8. A simple scrollable canvas.\n", tag_demo, "demo-cscroll")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "9. A Knight's tour of the chess board. (require Tile/Ttk extension)\n", tag_demo, "demo-knightstour")
-txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
-txt.insert('end', "Scales and Progress Bars\n", tag_title)
+txt.insert('end', "Scales\n", tag_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. Vertical scale.\n", tag_demo.id, "demo-vscale")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. Horizontal scale.\n", tag_demo.id, "demo-hscale")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "3. Progress bar. (require Tile/Ttk extension)\n", tag_demo.id, "demo-ttkprogress")
-txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
-txt.insert('end', "Paned Windows and Notebooks\n", tag_title)
+txt.insert('end', "Paned Windows\n", tag_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. Horizontal paned window. (if supported)\n", tag_demo.id, "demo-paned1")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. Vertical paned window. (if supported)\n", tag_demo.id, "demo-paned2")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "3. Themed nested panes. (require Tile/Ttk extension)\n", tag_demo.id, "demo-ttkpane")
-txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "4. Notebook widget. (require Tile/Ttk extension)\n", tag_demo.id, "demo-ttknote")
-txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
-txt.insert('end', "Menus and Toolbars\n", tag_title)
+txt.insert('end', "Menus\n", tag_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. Menus and cascades.\n", tag_demo, "demo-menu")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. Menus and cascades. (if supported)\n", tag_demo, "demo-menu84")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "3. Menubuttons.\n", tag_demo, "demo-menubu")
-txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "4. Themed menu buttons. (require Tile/Ttk extension)\n", tag_demo, "demo-ttkmenu")
-txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "5. Themed toolbar. (require Tile/Ttk extension)\n", tag_demo, "demo-toolbar")
+txt.insert('end', "3. Menubuttons\n", tag_demo, "demo-menubu")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
@@ -442,11 +383,9 @@ txt.insert('end', "Common Dialogs\n", tag_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. Message boxes.\n", tag_demo, "demo-msgbox")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "2. Message boxes with detail text. (if supported)\n", tag_demo, "demo-msgbox2")
+txt.insert('end', "2. File selection dialog.\n", tag_demo, "demo-filebox")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "3. File selection dialog.\n", tag_demo, "demo-filebox")
-txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "4. Color picker.\n", tag_demo, "demo-clrpick")
+txt.insert('end', "3. Color picker.\n", tag_demo, "demo-clrpick")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
@@ -502,16 +441,11 @@ def showVars1(parent, *args)
end
w = TkToplevel.new(parent) {|w|
title "Variable values"
- base = TkFrame.new(w).pack(:fill=>:both, :expand=>true)
- TkLabel.new(base) {
+ TkLabel.new(w) {
text "Variable values:"
width 20
anchor 'center'
- if $tk_version =~ /^4.*/
- font '-Adobe-helvetica-medium-r-normal--*-180-*-*-*-*-*-*'
- else
- font 'Helvetica 14'
- end
+ font '-Adobe-helvetica-medium-r-normal--*-180-*-*-*-*-*-*'
}.pack('side'=>'top', 'fill'=>'x')
len = 1
args.each{|vnam,vbody|
@@ -525,7 +459,7 @@ def showVars1(parent, *args)
.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x')
}.pack('side'=>'top', 'anchor'=>'w', 'fill'=>'x')
}
- TkButton.new(base) {
+ TkButton.new(w) {
text "OK"
command proc{w.destroy}
}.pack('side'=>'bottom', 'pady'=>2)
@@ -540,12 +474,10 @@ def showVars2(parent, *args)
rescue
end
end
- $showVarsWin[parent.path] = TkToplevel.new(parent) {|top|
+ $showVarsWin[parent.path] = TkToplevel.new(parent) {|w|
title "Variable values"
- base = TkFrame.new(top).pack(:fill=>:both, :expand=>true)
-
- TkLabelFrame.new(base, :text=>"Variable values:",
+ TkLabelFrame.new(w, :text=>"Variable values:",
:font=>{:family=>'Helvetica', :size=>14}){|f|
args.each{|vnam,vbody|
TkGrid(TkLabel.new(f, :text=>"#{vnam}: ", :anchor=>'w'),
@@ -557,15 +489,15 @@ def showVars2(parent, *args)
f.grid_columnconfig(1, :weight=>1)
f.grid_rowconfig(100, :weight=>1)
}
- TkButton.new(base, :text=>"OK", :width=>8, :default=>:active,
- :command=>proc{top.destroy}){|b|
- top.bind('Return', proc{b.invoke})
- top.bind('Escape', proc{b.invoke})
+ TkButton.new(w, :text=>"OK", :width=>8, :default=>:active,
+ :command=>proc{w.destroy}){|b|
+ w.bind('Return', proc{b.invoke})
+ w.bind('Escape', proc{b.invoke})
b.grid(:sticky=>'e', :padx=>4, :pady=>[6, 4])
}
- base.grid_columnconfig(0, :weight=>1)
- base.grid_rowconfig(0, :weight=>1)
+ w.grid_columnconfig(0, :weight=>1)
+ w.grid_rowconfig(0, :weight=>1)
}
end
@@ -659,27 +591,8 @@ def _null_binding
end
private :_null_binding
-def eval_samplecode(code, file=nil)
- #eval(code)
- #_null_binding.pseudo_toplevel_eval{ eval(code) }
- #Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } }
- Thread.new{
- _null_binding.pseudo_toplevel_eval{
- begin
- if file
- eval(code, binding, "(eval:#{file})")
- else
- eval(code)
- end
- rescue Exception=>e
- #p e
- TkBgError.show(e.class.inspect + ': ' + e.message + "\n" +
- "\n---< backtrace of Ruby side >-----\n" +
- e.backtrace.join("\n") +
- "\n---< backtrace of Tk side >-------")
- end
- }
- }
+def eval_samplecode(code)
+ Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } }.run
Tk.update
end
@@ -699,7 +612,7 @@ def invoke(txt, idx)
Tk.update
# eval(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, _null_binding)
# Tk.update
- eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, tag[5..-1] + '.rb')
+ eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join)
txt.cursor(cursor)
$tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
@@ -756,32 +669,20 @@ def showCode1(demo)
if $code_window == nil || TkWinfo.exist?($code_window) == false
$code_window = TkToplevel.new(nil)
f = TkFrame.new($code_window)
-
TkButton.new(f) {
text "Dismiss"
command proc{
$code_window.destroy
$code_window = nil
}
- }.pack('side'=>'right', 'expand'=>'false', 'pady'=>2, 'padx'=>25)
+ }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
TkButton.new(f) {
text "Rerun Demo"
# command proc{eval($code_text.get('1.0','end'), _null_binding)}
- command proc{eval_samplecode($code_text.get('1.0','end'), '<viewer>')}
- }.pack('side'=>'right', 'expand'=>'false', 'pady'=>2)
-
- TkLabel.new(f,'text'=>'line:').pack('side'=>'left')
- linenum =TkLabel.new(f,'text'=>'').pack('side'=>'left')
- TkLabel.new(f,'text'=>' pos:').pack('side'=>'left')
- posnum =TkLabel.new(f,'text'=>'').pack('side'=>'left')
-
- $set_linenum = proc{|w|
- line, pos = w.index('insert').split('.')
- linenum.text = line
- posnum.text = pos
- }
-
- f.pack('side'=>'bottom', 'expand'=>'true', 'fill'=>'x')
+ command proc{eval_samplecode($code_text.get('1.0','end'))}
+ }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
+# f.pack('side'=>'bottom', 'expand'=>'yes', 'fill'=>'x')
+ f.pack('side'=>'bottom', 'fill'=>'x')
if $tk_version =~ /^4\.[01]/
s = TkScrollbar.new($code_window, 'orient'=>'vertical')
@@ -826,21 +727,10 @@ def showCode1(demo)
TkGrid.columnconfigure(f, 0, 'weight'=>1, 'minsize'=>0)
}
end
-
- btag = TkBindTag.new
-
- btag.bind('Key', $set_linenum, '%W')
- btag.bind('Button', $set_linenum, '%W')
-
- btags = $code_text.bindtags
- btags.insert(btags.index($code_text.class) + 1, btag)
- $code_text.bindtags = btags
-
else
$code_window.deiconify
$code_window.raise
end
-
$code_window.title("Demo code: #{file}")
$code_window.iconname(file)
# fid = open(file, 'r')
@@ -851,9 +741,6 @@ def showCode1(demo)
#$code_mark = TkTextMark.new($code_text, '1.0')
#$code_text.set_insert('1.0')
TkTextMarkInsert.new($code_text,'1.0')
-
- $set_linenum.call($code_text)
-
fid.close
end
@@ -874,19 +761,7 @@ def showCode2(demo)
tf.grid_columnconfigure(0, :weight=>1)
bf = TkFrame.new($code_window)
-
- lf = TkFrame.new(bf)
- TkLabel.new(lf, :text=>'line:').pack(:side=>:left)
- linenum =TkLabel.new(lf, :text=>'').pack(:side=>:left)
- TkLabel.new(lf, :text=>' pos:').pack(:side=>:left)
- posnum =TkLabel.new(lf, :text=>'').pack(:side=>:left)
-
- $set_linenum = proc{|w|
- line, pos = w.index('insert').split('.')
- linenum.text = line
- posnum.text = pos
- }
-
+
b_dis = TkButton.new(bf, :text=>'Dismiss', :default=>:active,
:command=>proc{
$code_window.destroy
@@ -899,12 +774,12 @@ def showCode2(demo)
b_run = TkButton.new(bf, :text=>'Rerun Demo',
:command=>proc{
# eval($code_text.get('1.0','end'), _null_binding)
- eval_samplecode($code_text.get('1.0','end'), '<viewer>')
+ eval_samplecode($code_text.get('1.0','end'))
},
:image=>$image['refresh'], :compound=>:left)
- TkGrid(lf, 'x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4])
- bf.grid_columnconfigure(1, :weight=>1)
+ TkGrid('x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4])
+ bf.grid_columnconfigure(0, :weight=>1)
TkGrid(tf, :sticky=>'news')
TkGrid(bf, :sticky=>'ew')
@@ -917,17 +792,6 @@ def showCode2(demo)
$code_window.bindinfo('Return').each{|cmd, arg|
$code_window.bind_append('Escape', cmd, arg)
}
-
- btag = TkBindTag.new
-
- btag.bind('Key', $set_linenum, '%W')
- btag.bind('Button', $set_linenum, '%W')
- btag.bind('Configure', $set_linenum, '%W')
-
- btags = $code_text.bindtags
- btags.insert(btags.index($code_text.class) + 1, btag)
- $code_text.bindtags = btags
-
else
$code_window.deiconify
$code_window.raise
@@ -939,9 +803,6 @@ def showCode2(demo)
$code_text.delete('1.0', 'end')
$code_text.insert('1.0', fid.read)
TkTextMarkInsert.new($code_text,'1.0')
-
- $set_linenum.call($code_text)
-
fid.close
end
@@ -1035,13 +896,12 @@ end
#
def aboutBox
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo',
- 'message'=>"Ruby/Tk widget demonstration Ver.1.7.0-en\n\n" +
+ 'message'=>"Ruby/Tk widget demonstration Ver.1.6.0-en\n\n" +
"based on demos of Tk8.1 -- 8.5 " +
- "( Copyright of Tcl/Tk demos:: " +
+ "( Copyright:: " +
"(c) 1996-1997 Sun Microsystems, Inc. / " +
"(c) 1997-2000 Ajuba Solutions, Inc. / " +
- "(c) 2001-2007 Donal K. Fellows / " +
- "(c) 2002-2007 Daniel A. Steffen )\n\n" +
+ "(c) 2001-2003 Donal K. Fellows )\n\n" +
"Your Ruby & Tk Version ::\n" +
"Ruby#{RUBY_VERSION}(#{RUBY_RELEASE_DATE})[#{RUBY_PLATFORM}] / Tk#{$tk_patchlevel}#{(Tk::JAPANIZED_TK)? '-jp': ''}\n\n" +
"Ruby/Tk release date :: tcltklib #{TclTkLib::RELEASE_DATE}; tk #{Tk::RELEASE_DATE}")
@@ -1063,7 +923,7 @@ ARGV.each{|cmd|
end
#eval(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join,
# _null_binding)
- eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join, cmd + '.rb')
+ eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join)
}
if no_launcher
$root.withdraw # hide root window
diff --git a/ext/tk/sample/demos-jp/anilabel.rb b/ext/tk/sample/demos-jp/anilabel.rb
index aee57f9f6a..97781fbe77 100644
--- a/ext/tk/sample/demos-jp/anilabel.rb
+++ b/ext/tk/sample/demos-jp/anilabel.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# animated label widget demo (called by 'widget')
#
@@ -17,10 +16,8 @@ $anilabel_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($anilabel_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($anilabel_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -29,7 +26,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($anilabel_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -48,8 +45,8 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# label demo Íѥե졼¥àÀ¸À®
-f_left = TkLabelFrame.new(base_frame, :text=>'Scrolling Texts')
-f_right = TkLabelFrame.new(base_frame, :text=>'GIF Image')
+f_left = TkLabelFrame.new($anilabel_demo, :text=>'Scrolling Texts')
+f_right = TkLabelFrame.new($anilabel_demo, :text=>'GIF Image')
Tk.pack(f_left, f_right, 'side'=>'left', 'expand'=>'yes', 'fill'=>'both',
'padx'=>10, 'pady'=>10)
diff --git a/ext/tk/sample/demos-jp/aniwave.rb b/ext/tk/sample/demos-jp/aniwave.rb
index 8fa14f65fe..81e2d76b30 100644
--- a/ext/tk/sample/demos-jp/aniwave.rb
+++ b/ext/tk/sample/demos-jp/aniwave.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# animated wave demo (called by 'widget')
#
@@ -17,10 +16,8 @@ $aniwave_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($aniwave_demo).pack(:fill=>:both, :expand=>true)
-
# create label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($aniwave_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -29,7 +26,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# create frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($aniwave_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -62,7 +59,6 @@ class AnimatedWaveDemo
@backupCoords = []
n = 0
(-10..300).step(5){|n| @waveCoords << [n, 100]; @backupCoords << [n, 100] }
- n = 305
@waveCoords << [n, 0]; @backupCoords << [n, 0]
@waveCoords << [n+5, 200]; @backupCoords << [n+5, 200]
@coordsLen = @waveCoords.length
@@ -117,4 +113,4 @@ class AnimatedWaveDemo
end
# Start the animation processing
-AnimatedWaveDemo.new(base_frame, :left).move
+AnimatedWaveDemo.new($aniwave_demo, :left).move
diff --git a/ext/tk/sample/demos-jp/arrow.rb b/ext/tk/sample/demos-jp/arrow.rb
index 3c49e67b09..477a0abf6f 100644
--- a/ext/tk/sample/demos-jp/arrow.rb
+++ b/ext/tk/sample/demos-jp/arrow.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# arrowhead widget demo (called by 'widget')
#
@@ -74,19 +73,11 @@ def arrowSetup(c)
'arrow'=>'both', 'arrowshape'=>v.smallTips)
TkcText.new(c, v.x2-5*v.b, tmp+5, 'text'=>v.b, 'anchor'=>'n')
- if $tk_version =~ /^4.*/
- TkcText.new(c, v.x1, 310, 'text'=>"'width'=>#{v.width}", 'anchor'=>'w',
- 'font'=>'-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*')
- TkcText.new(c, v.x1, 330,
- 'text'=>"'arrowshape'=>[#{v.a}, #{v.b}, #{v.c}]",'anchor'=>'w',
- 'font'=>'-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*')
- else
- TkcText.new(c, v.x1, 310, 'text'=>"'width'=>#{v.width}", 'anchor'=>'w',
- 'font'=>'Helvetica 18')
- TkcText.new(c, v.x1, 330,
- 'text'=>"'arrowshape'=>[#{v.a}, #{v.b}, #{v.c}]",
- 'anchor'=>'w', 'font'=>'Helvetica 18')
- end
+ TkcText.new(c, v.x1, 310, 'text'=>"'width'=>#{v.width}", 'anchor'=>'w',
+ 'font'=>'-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*')
+ TkcText.new(c, v.x1, 330,
+ 'text'=>"'arrowshape'=>[#{v.a}, #{v.b}, #{v.c}]", 'anchor'=>'w',
+ 'font'=>'-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*')
v.count += 1
end
@@ -104,16 +95,14 @@ $arrow_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($arrow_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
+TkLabel.new($arrow_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
'text'=>"¤³¤Î widget ¤Ç¡¢¥­¥ã¥ó¥Ð¥¹¤Ç»È¤ï¤ì¤ë¥é¥¤¥ó¤Ë¤Ä¤¤¤ÆÍÍ¡¹¤ÊÉý¤äÌð°õ¤ÎƬ¤Î·Á¤ò»î¤·¤Æ¤ß¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£Àþ¤ÎÉý¤äÌð°õ¤Î·Á¤òÊѤ¨¤ë¤Ë¤Ï¡¢³ÈÂ礵¤ì¤¿Ìð°õ¤Ë¤Ä¤¤¤Æ¤¤¤ë 3¤Ä¤Î»Í³Ñ¤ò¥É¥é¥Ã¥°¤·¤Æ¤¯¤À¤µ¤¤¡£±¦Â¦¤ÎÌð°õ¤ÏÉáÄ̤ÎÂ礭¤µ¤Ç¤Î¥µ¥ó¥×¥ë¤ò¼¨¤·¤Æ¤¤¤Þ¤¹¡£²¼¤Î¥Æ¥­¥¹¥È¤Ï¥é¥¤¥ó¥¢¥¤¥Æ¥à¤ËÂФ¹¤ëÀßÄꥪ¥×¥·¥ç¥ó¤Ç¤¹¡£"){
pack('side'=>'top')
}
# frame À¸À®
-$arrow_buttons = TkFrame.new(base_frame) {|frame|
+$arrow_buttons = TkFrame.new($arrow_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -132,7 +121,7 @@ $arrow_buttons = TkFrame.new(base_frame) {|frame|
$arrow_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# canvas ÀßÄê
-$arrow_canvas = TkCanvas.new(base_frame, 'width'=>500, 'height'=>350,
+$arrow_canvas = TkCanvas.new($arrow_demo, 'width'=>500, 'height'=>350,
'relief'=>'sunken', 'borderwidth'=>2)
$arrow_canvas.pack('expand'=>'yes', 'fill'=>'both')
diff --git a/ext/tk/sample/demos-jp/bind.rb b/ext/tk/sample/demos-jp/bind.rb
index a1bcfdd2e7..e1e23b9893 100644
--- a/ext/tk/sample/demos-jp/bind.rb
+++ b/ext/tk/sample/demos-jp/bind.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# text (tag bindings) widget demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $bind_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($bind_demo).pack(:fill=>:both, :expand=>true)
-
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($bind_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -43,14 +40,14 @@ def tag_binding_for_bind_demo(tag, enter_style, leave_style)
end
# text À¸À®
-txt = TkText.new(base_frame){|t|
+TkText.new($bind_demo){|t|
# À¸À®
setgrid 'true'
- #width 60
- #height 24
+ width 60
+ height 24
font $font
wrap 'word'
- TkScrollbar.new(base_frame) {|s|
+ TkScrollbar.new($bind_demo) {|s|
pack('side'=>'right', 'fill'=>'y')
command proc{|*args| t.yview(*args)}
t.yscrollcommand proc{|first,last| s.set first,last}
@@ -94,32 +91,35 @@ txt = TkText.new(base_frame){|t|
}
d1.bind('1',
proc{
- eval_samplecode(`cat #{[$demo_dir,'items.rb'].join(File::Separator)}`, 'items.rb')
+ eval(`cat #{[$demo_dir,'items.rb'].join(File::Separator)}`,
+ _null_binding)
})
d2.bind('1',
proc{
- eval_samplecode(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)}`, 'plot.rb')
+ eval(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)}`,
+ _null_binding)
})
d3.bind('1',
proc{
- eval_samplecode(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)}`, 'ctext.rb')
+ eval(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)}`,
+ _null_binding)
})
d4.bind('1',
proc{
- eval_samplecode(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)}`, 'arrow.rb')
+ eval(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)}`,
+ _null_binding)
})
d5.bind('1',
proc{
- eval_samplecode(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)}`, 'ruler.rb')
+ eval(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)}`,
+ _null_binding)
})
d6.bind('1',
proc{
- eval_samplecode(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)}`, 'cscroll.rb')
+ eval(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)}`,
+ _null_binding)
})
TkTextMarkInsert.new(t, '0.0')
configure('state','disabled')
}
-
-txt.width 60
-txt.height 24
diff --git a/ext/tk/sample/demos-jp/bitmap.rb b/ext/tk/sample/demos-jp/bitmap.rb
index b6b0e54bbe..b71c67d3fd 100644
--- a/ext/tk/sample/demos-jp/bitmap.rb
+++ b/ext/tk/sample/demos-jp/bitmap.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# bitmap widget demo (called by 'widget')
#
@@ -19,7 +18,7 @@ def bitmapRow(w,*args)
TkFrame.new(row){|base|
pack('side'=>'left', 'fill'=>'both', 'pady'=>'.25c', 'padx'=>'.25c')
TkLabel.new(base, 'text'=>bitmap, 'width'=>9).pack('side'=>'bottom')
- Tk::Label.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom')
+ TkLabel.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom')
}
end
}
@@ -38,16 +37,14 @@ $bitmap_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($bitmap_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
+TkLabel.new($bitmap_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
'text'=>"¤³¤Î¥¦¥£¥ó¥É¥¦¤Ë¤Ï¡¢Tk ¤ËÁȤ߹þ¤Þ¤ì¤¿¤¹¤Ù¤Æ¤Î¥Ó¥Ã¥È¥Þ¥Ã¥×¤¬¡¢¤½¤ì¤é¤Î̾Á°¤È¶¦¤Ëɽ¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£Tcl ¤Î¥¹¥¯¥ê¥×¥ÈÃæ¤Ç¤Ï¡¢¤½¤ì¤¾¤ì¤Î̾Á°¤òÍѤ¤¤Æ»²¾È¤·¤Þ¤¹¡£"){
pack('side'=>'top')
}
# frame À¸À®
-$bitmap_buttons = TkFrame.new(base_frame) {|frame|
+$bitmap_buttons = TkFrame.new($bitmap_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -66,7 +63,7 @@ $bitmap_buttons = TkFrame.new(base_frame) {|frame|
$bitmap_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame ÀßÄê
-TkFrame.new(base_frame){|f|
+TkFrame.new($bitmap_demo){|f|
bitmapRow(f,'error','gray25','gray50','hourglass')
bitmapRow(f,'info','question','questhead','warning')
pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both')
diff --git a/ext/tk/sample/demos-jp/button.rb b/ext/tk/sample/demos-jp/button.rb
index 18e42008c9..20f8cae299 100644
--- a/ext/tk/sample/demos-jp/button.rb
+++ b/ext/tk/sample/demos-jp/button.rb
@@ -1,8 +1,6 @@
-# -*- coding: euc-jp -*-
#
# button widget demo (called by 'widget')
#
-#
# toplevel widget ¤¬Â¸ºß¤¹¤ì¤Ðºï½ü¤¹¤ë
if defined?($button_demo) && $button_demo
@@ -27,7 +25,7 @@ msg = TkLabel.new($button_demo) {
msg.pack('side'=>'top')
# frame À¸À®
-$button_buttons = Tk::Frame.new($button_demo) {|frame|
+$button_buttons = TkFrame.new($button_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
diff --git a/ext/tk/sample/demos-jp/check.rb b/ext/tk/sample/demos-jp/check.rb
index b953e7f623..be675b9042 100644
--- a/ext/tk/sample/demos-jp/check.rb
+++ b/ext/tk/sample/demos-jp/check.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# checkbutton widget demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $check_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($check_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($check_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -33,7 +30,7 @@ brakes = TkVariable.new(0)
sober = TkVariable.new(0)
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($check_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -54,7 +51,7 @@ TkFrame.new(base_frame) {|frame|
TkButton.new(frame) {
text 'ÊÑ¿ô»²¾È'
command proc{
- showVars(base_frame,
+ showVars($check_demo,
['wipers', wipers], ['brakes', brakes], ['sober', sober])
}
}.pack('side'=>'left', 'expand'=>'yes')
@@ -63,8 +60,8 @@ TkFrame.new(base_frame) {|frame|
# checkbutton À¸À®
-[ TkCheckButton.new(base_frame, 'text'=>'¥ï¥¤¥Ñ¡¼ OK', 'variable'=>wipers),
- TkCheckButton.new(base_frame, 'text'=>'¥Ö¥ì¡¼¥­ OK', 'variable'=>brakes),
- TkCheckButton.new(base_frame, 'text'=>'±¿Å¾¼ê ÁÇÌÌ', 'variable'=>sober)
+[ TkCheckButton.new($check_demo, 'text'=>'¥ï¥¤¥Ñ¡¼ OK', 'variable'=>wipers),
+ TkCheckButton.new($check_demo, 'text'=>'¥Ö¥ì¡¼¥­ OK', 'variable'=>brakes),
+ TkCheckButton.new($check_demo, 'text'=>'±¿Å¾¼ê ÁÇÌÌ', 'variable'=>sober)
].each{|w| w.relief('flat'); w.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w')}
diff --git a/ext/tk/sample/demos-jp/check2.rb b/ext/tk/sample/demos-jp/check2.rb
index 7f7cb9e932..f681a4d684 100644
--- a/ext/tk/sample/demos-jp/check2.rb
+++ b/ext/tk/sample/demos-jp/check2.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# checkbutton widget demo2 (called by 'widget')
#
@@ -16,10 +15,8 @@ $check2_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($check2_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($check2_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -34,7 +31,7 @@ brakes = TkVariable.new(0)
sober = TkVariable.new(0)
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($check2_demo) {|frame|
TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2),
:columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
TkGrid('x',
@@ -62,15 +59,15 @@ TkFrame.new(base_frame) {|frame|
# checkbutton À¸À®
-TkCheckButton.new(base_frame, :text=>'°ÂÁ´À­¸¡ºº', :variable=>safety,
+TkCheckButton.new($check2_demo, :text=>'°ÂÁ´À­¸¡ºº', :variable=>safety,
:relief=>:flat, :onvalue=>'all', :offvalue=>'none',
:tristatevalue=>'partial'){
pack('side'=>'top', 'pady'=>2, 'anchor'=>'w')
}
-[ TkCheckButton.new(base_frame, 'text'=>'¥ï¥¤¥Ñ¡¼ OK', 'variable'=>wipers),
- TkCheckButton.new(base_frame, 'text'=>'¥Ö¥ì¡¼¥­ OK', 'variable'=>brakes),
- TkCheckButton.new(base_frame, 'text'=>'±¿Å¾¼ê ÁÇÌÌ', 'variable'=>sober)
+[ TkCheckButton.new($check2_demo, 'text'=>'¥ï¥¤¥Ñ¡¼ OK', 'variable'=>wipers),
+ TkCheckButton.new($check2_demo, 'text'=>'¥Ö¥ì¡¼¥­ OK', 'variable'=>brakes),
+ TkCheckButton.new($check2_demo, 'text'=>'±¿Å¾¼ê ÁÇÌÌ', 'variable'=>sober)
].each{|w|
w.relief('flat')
w.pack('side'=>'top', 'padx'=>15, 'pady'=>2, 'anchor'=>'w')
diff --git a/ext/tk/sample/demos-jp/clrpick.rb b/ext/tk/sample/demos-jp/clrpick.rb
index ce6b99ab94..de8cd80fcd 100644
--- a/ext/tk/sample/demos-jp/clrpick.rb
+++ b/ext/tk/sample/demos-jp/clrpick.rb
@@ -1,9 +1,6 @@
-# -*- coding: euc-jp -*-
#
# widget demo prompts the user to select a color (called by 'widget')
#
-# Note: don't support ttk_wrapper. work with standard widgets only.
-#
# toplevel widget ¤¬Â¸ºß¤¹¤ì¤Ðºï½ü¤¹¤ë
if defined?($clrpick_demo) && $clrpick_demo
@@ -19,15 +16,12 @@ $clrpick_demo = TkToplevel.new {|w|
}
# label À¸À®
-#TkLabel.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
-Tk::Label.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
+TkLabel.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
'text'=>"°Ê²¼¤Î¥Ü¥¿¥ó¤ò²¡¤·¤Æ¡¢¤³¤Î¥¦¥£¥ó¥É¥¦¾å¤Ë¤¢¤ë¥¦¥£¥¸¥§¥Ã¥È¤ÎÁ°·Ê¿§¤ÈÇØ·Ê¿§¤òÁªÂò¤·¤Æ²¼¤µ¤¤¡£").pack('side'=>'top')
# frame À¸À®
-# TkFrame.new($clrpick_demo) {|frame|
-Tk::Frame.new($clrpick_demo) {|frame|
- # TkButton.new(frame) {
- Tk::Button.new(frame) {
+TkFrame.new($clrpick_demo) {|frame|
+ TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
command proc{
@@ -37,23 +31,20 @@ Tk::Frame.new($clrpick_demo) {|frame|
}
}.pack('side'=>'left', 'expand'=>'yes')
- # TkButton.new(frame) {
- Tk::Button.new(frame) {
+ TkButton.new(frame) {
text '¥³¡¼¥É»²¾È'
command proc{showCode 'clrpick'}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# button À¸À®
-# TkButton.new($clrpick_demo, 'text'=>'ÇØ·Ê¿§¤òÀßÄê ...') {|b|
-Tk::Button.new($clrpick_demo, 'text'=>'ÇØ·Ê¿§¤òÀßÄê ...') {|b|
+TkButton.new($clrpick_demo, 'text'=>'ÇØ·Ê¿§¤òÀßÄê ...') {|b|
command(proc{setColor $clrpick_demo, b, 'background',
['background', 'highlightbackground']})
pack('side'=>'top', 'anchor'=>'c', 'pady'=>'2m')
}
-# TkButton.new($clrpick_demo, 'text'=>'Á°·Ê¿§¤òÀßÄê ...') {|b|
-Tk::Button.new($clrpick_demo, 'text'=>'Á°·Ê¿§¤òÀßÄê ...') {|b|
+TkButton.new($clrpick_demo, 'text'=>'Á°·Ê¿§¤òÀßÄê ...') {|b|
command(proc{setColor $clrpick_demo, b, 'foreground', ['foreground']})
pack('side'=>'top', 'anchor'=>'c', 'pady'=>'2m')
}
diff --git a/ext/tk/sample/demos-jp/colors.rb b/ext/tk/sample/demos-jp/colors.rb
index 91817a947b..c6128f9c00 100644
--- a/ext/tk/sample/demos-jp/colors.rb
+++ b/ext/tk/sample/demos-jp/colors.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# listbox widget demo 'colors' (called by 'widget')
#
@@ -16,10 +15,8 @@ $colors_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($colors_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($colors_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -28,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($colors_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -48,7 +45,7 @@ TkFrame.new(base_frame) {|frame|
# frame À¸À®
colors_lbox = nil
-TkFrame.new(base_frame, 'borderwidth'=>10) {|w|
+TkFrame.new($colors_demo, 'borderwidth'=>10) {|w|
s = TkScrollbar.new(w)
colors_lbox = TkListbox.new(w) {
setgrid 1
@@ -61,15 +58,7 @@ TkFrame.new(base_frame, 'borderwidth'=>10) {|w|
colors_lbox.pack('side'=>'left', 'expand'=>1, 'fill'=>'both')
}.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'y')
-#colors_lbox.bind('Double-1', proc{TkPalette.setPalette TkSelection.get})
-colors_lbox.bind('Double-1', proc{
- begin
- TkPalette.setPalette TkSelection.get
- rescue => e
- p e
- Tk.tk_call_without_enc('destroy', '.___tk_set_palette')
- end
- })
+colors_lbox.bind('Double-1', proc{TkPalette.setPalette TkSelection.get})
ins_data = [
'gray60','gray70','gray80','gray85','gray90','gray95',
diff --git a/ext/tk/sample/demos-jp/combo.rb b/ext/tk/sample/demos-jp/combo.rb
deleted file mode 100644
index da00d712ba..0000000000
--- a/ext/tk/sample/demos-jp/combo.rb
+++ /dev/null
@@ -1,98 +0,0 @@
-# -*- coding: euc-jp -*-
-#
-# combo.rb --
-#
-# This demonstration script creates several combobox widgets.
-#
-# based on "Id: combo.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($combo_demo) && $combo_demo
- $combo_demo.destroy
- $combo_demo = nil
-end
-
-$combo_demo = TkToplevel.new {|w|
- title("Combobox Demonstration")
- iconname("combo")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($combo_demo).pack(:fill=>:both, :expand=>true)
-
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'5i', :justify=>:left,
- :text=><<EOL).pack(:side=>:top, :fill=>:x)
-°Ê²¼¤Ç¤Ï3¼ïÎà¤Î¥³¥ó¥Ü¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥\
-ºÇ½é¤Î¤â¤Î¤Ï¡¤¥¨¥ó¥È¥ê¥¦¥£¥¸¥§¥Ã¥È¤ÈƱ¤¸Íͤˡ¤\
-¥Ý¥¤¥ó¥È¤·¤¿¤ê¡¤¥¯¥ê¥Ã¥¯¤·¤¿¤ê¡¤¥¿¥¤¥×¤·¤¿¤ê¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¥\
-¤Þ¤¿¡¤Return¥­¡¼¤òÆþÎϤ¹¤ì¤Ð¸½ºß¤ÎÃͤ¬¥ê¥¹¥È¤ËÄɲ䵤졤\
-¥É¥í¥Ã¥×¥À¥¦¥ó¥ê¥¹¥È¤«¤éÁªÂò¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡¥\
-¢­(²¼¸þ¤­Ìð°õ)¥­¡¼¤ò²¡¤·¤ÆÉ½¼¨¤µ¤ì¤¿¥ê¥¹¥È¤«¤é\
-Ìð°õ¥­¡¼¤Ç¾¤Î¸õÊä¤òÁª¤ó¤ÇReturn¥­¡¼¤ò²¡¤»¤Ð¡¤ÃͤòÁªÂò¤Ç¤­¤Þ¤¹¡¥\
-2ÈÖÌܤΥ³¥ó¥Ü¥Ü¥Ã¥¯¥¹¤ÏÆÃÄê¤ÎÃͤ˸ÇÄꤵ¤ì¤Æ¤ª¤ê¡¤°ìÀÚÊѹ¹¤Ç¤­¤Þ¤»¤ó¡¥\
-3ÈÖÌܤΤâ¤Î¤Ï¥ª¡¼¥¹¥È¥é¥ê¥¢¤ÎÅԻԤΥɥí¥Ã¥×¥À¥¦¥ó¥ê¥¹¥È¤«¤é\
-ÁªÂò¤¹¤ë¤³¤È¤À¤±¤¬²Äǽ¤È¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡¥
-EOL
-
-## variables
-firstValue = TkVariable.new
-secondValue = TkVariable.new
-ozCity = TkVariable.new
-
-## See Code / Dismiss buttons
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'ÊÑ¿ô»²¾È',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{
- showVars(base_frame,
- ['firstVariable', firstValue],
- ['secondVariable', secondValue],
- ['ozCity', ozCity])
- }),
- Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'combo'}),
- Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $combo_demo.destroy
- $combo_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
-
-australianCities = [
- '¥­¥ã¥ó¥Ù¥é', '¥·¥É¥Ë¡¼', '¥á¥ë¥Ü¥ë¥ó', '¥Ñ¡¼¥¹', '¥¢¥Ç¥ì¡¼¥É',
- '¥Ö¥ê¥¹¥Ù¡¼¥ó', '¥Û¥Ð¡¼¥È', '¥À¡¼¥¦¥£¥ó', '¥¢¥ê¥¹ ¥¹¥×¥ê¥ó¥°¥¹'
-]
-
-
-secondValue.value = 'Êѹ¹ÉÔ²Ä'
-ozCity.value = '¥·¥É¥Ë¡¼'
-
-Tk.pack(Ttk::Labelframe.new(frame, :text=>'Fully Editable'){|f|
- Ttk::Combobox.new(f, :textvariable=>firstValue){|b|
- b.bind('Return', '%W'){|w|
- w.values <<= w.value unless w.values.include?(w.value)
- }
- }.pack(:pady=>5, :padx=>10)
- },
-
- Ttk::LabelFrame.new(frame, :text=>'Disabled'){|f|
- Ttk::Combobox.new(f, :textvariable=>secondValue, :state=>:disabled) .
- pack(:pady=>5, :padx=>10)
- },
-
- Ttk::LabelFrame.new(frame, :text=>'Defined List Only'){|f|
- Ttk::Combobox.new(f, :textvariable=>ozCity, :state=>:readonly,
- :values=>australianCities) .
- pack(:pady=>5, :padx=>10)
- },
-
- :side=>:top, :pady=>5, :padx=>10)
diff --git a/ext/tk/sample/demos-jp/cscroll.rb b/ext/tk/sample/demos-jp/cscroll.rb
index 845952679a..0d6db69af6 100644
--- a/ext/tk/sample/demos-jp/cscroll.rb
+++ b/ext/tk/sample/demos-jp/cscroll.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# simple scrollable canvas widget demo (called by 'widget')
#
@@ -16,16 +15,14 @@ $cscroll_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($cscroll_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i',
+TkLabel.new($cscroll_demo, 'font'=>$font, 'wraplength'=>'4i',
'justify'=>'left', 'text'=>"¤³¤Î¥¦¥£¥ó¥É¥¦¤Ë¤Ï¥¹¥¯¥í¡¼¥ë¥Ð¡¼¤ä¥Þ¥¦¥¹¤Î¥Ü¥¿¥ó2 ¤Ç¥¹¥¯¥í¡¼¥ë¤Ç¤­¤ë¥­¥ã¥ó¥Ð¥¹ widget ¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£»Í³Ñ¤Î¾å¤Ç¥Ü¥¿¥ó1 ¤ò¥¯¥ê¥Ã¥¯¤¹¤ë¤È¡¢¤½¤Î¥¤¥ó¥Ç¥Ã¥¯¥¹¤¬É¸½à½ÐÎϤ˽ÐÎϤµ¤ì¤Þ¤¹¡£"){
pack('side'=>'top')
}
# frame À¸À®
-$cscroll_buttons = TkFrame.new(base_frame) {|frame|
+$cscroll_buttons = TkFrame.new($cscroll_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -45,7 +42,7 @@ $cscroll_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame ÀßÄê
unless $tk_version =~ /^4\.[01]/
- $cscroll_grid = TkFrame.new(base_frame) {
+ $cscroll_grid = TkFrame.new($cscroll_demo) {
pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>1)
}
TkGrid.rowconfigure($cscroll_grid, 0, 'weight'=>1, 'minsize'=>0)
@@ -53,7 +50,7 @@ unless $tk_version =~ /^4\.[01]/
end
# canvas ÀßÄê
-$cscroll_canvas = TkCanvas.new(base_frame,
+$cscroll_canvas = TkCanvas.new($cscroll_demo,
'relief'=>'sunken', 'borderwidth'=>2,
'scrollregion'=>['-11c', '-11c', '50c', '20c']
) {|c|
@@ -64,7 +61,7 @@ $cscroll_canvas = TkCanvas.new(base_frame,
'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
end
- TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}) {|vs|
+ TkScrollbar.new($cscroll_demo, 'command'=>proc{|*args| c.yview(*args)}) {|vs|
c.yscrollcommand(proc{|first,last| vs.set first,last})
if $tk_version =~ /^4\.[01]/
pack('side'=>'right', 'fill'=>'y')
@@ -74,7 +71,7 @@ $cscroll_canvas = TkCanvas.new(base_frame,
end
}
- TkScrollbar.new(base_frame, 'orient'=>'horiz',
+ TkScrollbar.new($cscroll_demo, 'orient'=>'horiz',
'command'=>proc{|*args| c.xview(*args)}) {|hs|
c.xscrollcommand(proc{|first,last| hs.set first,last})
if $tk_version =~ /^4\.[01]/
diff --git a/ext/tk/sample/demos-jp/ctext.rb b/ext/tk/sample/demos-jp/ctext.rb
index 05ca732cfd..66e1fe8107 100644
--- a/ext/tk/sample/demos-jp/ctext.rb
+++ b/ext/tk/sample/demos-jp/ctext.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# Canvas Text widget demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $ctext_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($ctext_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
+TkLabel.new($ctext_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
'text'=>"¤³¤Î¥¦¥£¥ó¥É¥¦¤Ë¤Ï¥­¥ã¥ó¥Ð¥¹widget¤Î¥Æ¥­¥¹¥Èµ¡Ç½¤ò¥Ç¥â¤¹¤ë¤¿¤á¤Î¥Æ¥­¥¹¥Èʸ»úÎó¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¥Þ¥¦¥¹¤ò»Í³Ñ¤ÎÃæ¤Ë»ý¤Ã¤Æ¤¤¤­¡¢¥¯¥ê¥Ã¥¯¤¹¤ë¤È°ÌÃÖ¤®¤áÍѤÎÅÀ¤«¤é¤ÎÁêÂаÌÃÖ¤òÊѤ¨¤¿¤ê¡¢¹Ô·¤¨¤òÊѤ¨¤¿¤ê¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤Þ¤¿°Ê²¼¤Î¤è¤¦¤ÊÊÔ½¸¤Î¤¿¤á¤Î´Êñ¤Ê¥Ð¥¤¥ó¥Ç¥£¥ó¥°¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Þ¤¹¡£
1. ¥Þ¥¦¥¹¤ò»ý¤Ã¤Æ¤¤¤­¡¢¥¯¥ê¥Ã¥¯¤·¡¢ÆþÎϤǤ­¤Þ¤¹¡£
@@ -31,7 +28,7 @@ TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
}
# frame À¸À®
-$ctext_buttons = TkFrame.new(base_frame) {|frame|
+$ctext_buttons = TkFrame.new($ctext_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -50,33 +47,24 @@ $ctext_buttons = TkFrame.new(base_frame) {|frame|
$ctext_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# canvas À¸À®
-$ctext_canvas = TkCanvas.new(base_frame, 'relief'=>'flat',
+$ctext_canvas = TkCanvas.new($ctext_demo, 'relief'=>'flat',
'borderwidth'=>0, 'width'=>500, 'height'=>350)
$ctext_canvas.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both')
# font ÀßÄê
-if $tk_version =~ /^4.*/
- textFont = '-*-Helvetica-Medium-R-Normal--*-240-*-*-*-*-*-*'
-else
- textFont = 'Helvetica 24'
-end
+textFont = '-*-Helvetica-Medium-R-Normal--*-240-*-*-*-*-*-*'
# canvas ÀßÄê
TkcRectangle.new($ctext_canvas, 245, 195, 255, 205,
'outline'=>'black', 'fill'=>'red')
-ctag_text_param = {
- 'text'=>"¤³¤ì¤Ï¥­¥ã¥ó¥Ð¥¹widget¤Î¥Æ¥­¥¹¥Èµ¡Ç½¤ò¥Ç¥â¤¹¤ë¤¿¤á¤Îʸ»úÎó¤Ç¤¹¡£\n¾å¤Ç½Ò¤Ù¤¿¤è¤¦¤ÊÊÔ½¸¤ò²Äǽ¤È¤¹¤ë¤¿¤á¤Î¥Ð¥¤¥ó¥Ç¥£¥ó¥°¤ò»Ü¤·¤Æ¤¤¤Þ¤¹¡£",
- 'width'=>440, 'anchor'=>'n', 'justify'=>'left'
-}
-if $tk_version =~ /^4.*/
- ctag_text_param['font'] = '-*-Helvetica-Medium-R-Normal--*-240-*-*-*-*-*-*'
- ctag_text_param['kanjifont'] = '-*-r-*--24-*-jisx0208.1983-0'
-else
- ctag_text_param['font'] = 'Helvetica 24'
-end
$ctag_text = TkcTag.new($ctext_canvas)
-$ctag_text.withtag(TkcText.new($ctext_canvas, 250, 200, ctag_text_param))
+$ctag_text.withtag(TkcText.new($ctext_canvas, 250, 200,
+ 'text'=>"¤³¤ì¤Ï¥­¥ã¥ó¥Ð¥¹widget¤Î¥Æ¥­¥¹¥Èµ¡Ç½¤ò¥Ç¥â¤¹¤ë¤¿¤á¤Îʸ»úÎó¤Ç¤¹¡£\n¾å¤Ç½Ò¤Ù¤¿¤è¤¦¤ÊÊÔ½¸¤ò²Äǽ¤È¤¹¤ë¤¿¤á¤Î¥Ð¥¤¥ó¥Ç¥£¥ó¥°¤ò»Ü¤·¤Æ¤¤¤Þ¤¹¡£",
+ 'width'=>440, 'anchor'=>'n',
+ 'font'=>'-*-Helvetica-Medium-R-Normal--*-240-*-*-*-*-*-*',
+ 'kanjifont'=>'-*-r-*--24-*-jisx0208.1983-0',
+ 'justify'=>'left') )
$ctag_text.bind('1', proc{|x,y| textB1Press $ctext_canvas,x,y}, "%x %y")
$ctag_text.bind('B1-Motion', proc{|x,y| textB1Move $ctext_canvas,x,y}, "%x %y")
@@ -118,14 +106,9 @@ mkTextConfig $ctext_canvas, x+60, y+60, 'anchor', 'nw', color
item = TkcRectangle.new($ctext_canvas, x+40, y+40, x+50, y+50,
'outline'=>'black', 'fill'=>'red')
item.bind('1', proc{$ctag_text.configure 'anchor', 'center'})
-if $tk_version =~ /^4.*/
- TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Text Position',
- 'font'=>'-*-times-medium-r-normal--*-240-*-*-*-*-*-*',
- 'anchor'=>'s', 'fill'=>'brown')
-else
- TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Text Position',
- 'font'=>'Times 24', 'anchor'=>'s', 'fill'=>'brown')
-end
+TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Text Position', 'anchor'=>'s',
+ 'font'=>'-*-times-medium-r-normal--*-240-*-*-*-*-*-*',
+ 'fill'=>'brown')
# Lastly, create some items that allow the text's justification to be
# changed.
@@ -136,14 +119,9 @@ color = 'SeaGreen2'
mkTextConfig $ctext_canvas, x, y, 'justify', 'left', color
mkTextConfig $ctext_canvas, x+30, y, 'justify', 'center', color
mkTextConfig $ctext_canvas, x+60, y, 'justify', 'right', color
-if $tk_version =~ /^4.*/
- TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Justification',
- 'font'=>'-*-times-medium-r-normal--*-240-*-*-*-*-*-*',
- 'anchor'=>'s', 'fill'=>'brown')
-else
- TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Justification',
- 'font'=>'Times 24', 'anchor'=>'s', 'fill'=>'brown')
-end
+TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Justification', 'anchor'=>'s',
+ 'font'=>'-*-times-medium-r-normal--*-240-*-*-*-*-*-*',
+ 'fill'=>'brown')
$ctext_canvas.itembind('config', 'Enter', proc{textEnter $ctext_canvas})
$ctext_canvas.itembind('config', 'Leave',
diff --git a/ext/tk/sample/demos-jp/dialog1.rb b/ext/tk/sample/demos-jp/dialog1.rb
index 07e50306ab..0d6181bfc6 100644
--- a/ext/tk/sample/demos-jp/dialog1.rb
+++ b/ext/tk/sample/demos-jp/dialog1.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# a dialog box with a local grab (called by 'widget')
#
diff --git a/ext/tk/sample/demos-jp/dialog2.rb b/ext/tk/sample/demos-jp/dialog2.rb
index f747f8d6a8..a934378dda 100644
--- a/ext/tk/sample/demos-jp/dialog2.rb
+++ b/ext/tk/sample/demos-jp/dialog2.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# a dialog box with a global grab (called by 'widget')
#
diff --git a/ext/tk/sample/demos-jp/entry1.rb b/ext/tk/sample/demos-jp/entry1.rb
index 2be29c18d3..edf3b5f71d 100644
--- a/ext/tk/sample/demos-jp/entry1.rb
+++ b/ext/tk/sample/demos-jp/entry1.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# entry (no scrollbars) widget demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $entry1_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($entry1_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($entry1_demo) {
font $font
wraplength '5i'
justify 'left'
@@ -28,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($entry1_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -46,9 +43,9 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# entry À¸À®
-e1 = TkEntry.new(base_frame, 'relief'=>'sunken')
-e2 = TkEntry.new(base_frame, 'relief'=>'sunken')
-e3 = TkEntry.new(base_frame, 'relief'=>'sunken')
+e1 = TkEntry.new($entry1_demo, 'relief'=>'sunken')
+e2 = TkEntry.new($entry1_demo, 'relief'=>'sunken')
+e3 = TkEntry.new($entry1_demo, 'relief'=>'sunken')
[e1,e2,e3].each{|w| w.pack('side'=>'top', 'padx'=>10, 'pady'=>5, 'fill'=>'x')}
# ½é´üÃÍÁÞÆþ
diff --git a/ext/tk/sample/demos-jp/entry2.rb b/ext/tk/sample/demos-jp/entry2.rb
index 2675b5d324..7d5740e663 100644
--- a/ext/tk/sample/demos-jp/entry2.rb
+++ b/ext/tk/sample/demos-jp/entry2.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# entry (with scrollbars) widget demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $entry2_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($entry2_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($entry2_demo) {
font $font
wraplength '5i'
justify 'left'
@@ -28,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($entry2_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -46,7 +43,7 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame À¸À®
-TkFrame.new(base_frame, 'borderwidth'=>10) {|w|
+TkFrame.new($entry2_demo, 'borderwidth'=>10) {|w|
# entry 1
s1 = TkScrollbar.new(w, 'relief'=>'sunken', 'orient'=>'horiz')
e1 = TkEntry.new(w, 'relief'=>'sunken') {
diff --git a/ext/tk/sample/demos-jp/entry3.rb b/ext/tk/sample/demos-jp/entry3.rb
index 6b9cd4cf37..f57dc13553 100644
--- a/ext/tk/sample/demos-jp/entry3.rb
+++ b/ext/tk/sample/demos-jp/entry3.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
# entry3.rb --
#
# This demonstration script creates several entry widgets whose
@@ -18,9 +17,7 @@ $entry3_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($entry3_demo).pack(:fill=>:both, :expand=>true)
-
-TkLabel.new(base_frame,
+TkLabel.new($entry3_demo,
:font=>$font, :wraplength=>'5i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
°Ê²¼¤Ë¤Ï£´¼ïÎà¤Î¥¨¥ó¥È¥ê¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥³Æ¥¨¥ó¥È¥ê¥Ü¥Ã¥¯¥¹¤Ï¡¤\
@@ -41,7 +38,7 @@ TkLabel.new(base_frame,
ÆþÎϤµ¤ì¤¿Ê¸»ú¤Ï¥¢¥¹¥¿¥ê¥¹¥¯µ­¹æ¤ËÃÖ¤­´¹¤¨¤ÆÉ½¼¨¤µ¤ì¤Þ¤¹¡¥
EOL
-TkFrame.new(base_frame){|f|
+TkFrame.new($entry3_demo){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{
@@ -67,41 +64,23 @@ TkFrame.new(base_frame){|f|
# count - Counter to control the number of times flashed
def focusAndFlash(widget, fg, bg, count=5)
return if count <= 0
- if fg && !fg.empty? && bg && !bg.empty?
- TkTimer.new(200, count,
- proc{widget.configure(:foreground=>bg, :background=>fg)},
- proc{widget.configure(:foreground=>fg, :background=>bg)}
- ).start
- else
- # TkTimer.new(150, 3){Tk.bell}.start
- Tk.bell
- TkTimer.new(200, count,
- proc{widget.configure(:foreground=>'white',
- :background=>'black')},
- proc{widget.configure(:foreground=>'black',
- :background=>'white')}
- ).at_end{begin
- widget.configure(:foreground=>fg,
- :background=>bg)
- rescue
- # ignore
- end}.start
- end
+ TkTimer.new(100, count,
+ proc{widget.configure(:foreground=>bg, :background=>fg)},
+ proc{widget.configure(:foreground=>fg, :background=>bg)}
+ ).start
widget.focus(true)
end
-l1 = TkLabelFrame.new(base_frame, :text=>"À°¿ô¥¨¥ó¥È¥ê")
+l1 = TkLabelFrame.new($entry3_demo, :text=>"À°¿ô¥¨¥ó¥È¥ê")
TkEntry.new(l1, :validate=>:focus,
:vcmd=>[
proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P'
]) {|e|
- fg = e.foreground
- bg = e.background
- invalidcommand [proc{|w| focusAndFlash(w, fg, bg)}, '%W']
+ invalidcommand [proc{|w| focusAndFlash(w, e.fg, e.bg)}, '%W']
pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
}
-l2 = TkLabelFrame.new(base_frame, :text=>"ŤµÀ©ÌóÉÕ¤­¥¨¥ó¥È¥ê")
+l2 = TkLabelFrame.new($entry3_demo, :text=>"ŤµÀ©ÌóÉÕ¤­¥¨¥ó¥È¥ê")
TkEntry.new(l2, :validate=>:key, :invcmd=>proc{Tk.bell},
:vcmd=>[proc{|s| s.length < 10}, '%P']
).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
@@ -182,15 +161,15 @@ def validatePhoneChange(widget, vmode, idx, char)
widget.delete(idx)
widget.insert(idx, $phoneNumberMap[char] || char)
Tk.after_idle(proc{phoneSkipRight(widget, -1)})
- # Tk.update(true) # <- Don't work 'update' inter validation callback.
- # It depends on Tcl/Tk side (tested on Tcl/Tk8.5a1).
+ # Tk.update(true) # Don't work 'update' inter validation callback.
+ # It depends on Tcl/Tk side (tested on Tcl/Tk8.5a1).
return true
end
return false
end
-l3 = TkLabelFrame.new(base_frame, :text=>"ÊÆ¹ñÅÅÏÃÈֹ楨¥ó¥È¥ê")
+l3 = TkLabelFrame.new($entry3_demo, :text=>"ÊÆ¹ñÅÅÏÃÈֹ楨¥ó¥È¥ê")
TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell},
:textvariable=>entry3content,
:vcmd=>[
@@ -209,14 +188,14 @@ TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell},
pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
}
-l4 = TkLabelFrame.new(base_frame, :text=>"¥Ñ¥¹¥ï¡¼¥É¥¨¥ó¥È¥ê")
+l4 = TkLabelFrame.new($entry3_demo, :text=>"¥Ñ¥¹¥ï¡¼¥É¥¨¥ó¥È¥ê")
TkEntry.new(l4, :validate=>:key, :show=>'*',
:vcmd=>[
proc{|s| s.length <= 8},
'%P'
]).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
-TkFrame.new(base_frame){|f|
+TkFrame.new($entry3_demo){|f|
lower
TkGrid.configure(l1, l2, :in=>f, :padx=>'3m', :pady=>'1m', :sticky=>:ew)
TkGrid.configure(l3, l4, :in=>f, :padx=>'3m', :pady=>'1m', :sticky=>:ew)
diff --git a/ext/tk/sample/demos-jp/filebox.rb b/ext/tk/sample/demos-jp/filebox.rb
index b8846d08a0..f3608ab70f 100644
--- a/ext/tk/sample/demos-jp/filebox.rb
+++ b/ext/tk/sample/demos-jp/filebox.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# widget demo prompts the user to select a file (called by 'widget')
#
@@ -16,14 +15,12 @@ $filebox_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($filebox_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
+TkLabel.new($filebox_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
'text'=>"¥¨¥ó¥È¥ê¤Ë¥Õ¥¡¥¤¥ë̾¤òľÀÜÆþÎϤ¹¤ë¤«¡¢\"Browse\" ¥Ü¥¿¥ó¤ò²¡¤·¤Æ¥Õ¥¡¥¤¥ëÁªÂò¥À¥¤¥¢¥í¥°¤«¤é¥Õ¥¡¥¤¥ë̾¤òÁª¤ó¤Ç²¼¤µ¤¤¡£").pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($filebox_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -42,7 +39,7 @@ TkFrame.new(base_frame) {|frame|
# frame À¸À®
['³«¤¯', 'Êݸ'].each{|type|
- TkFrame.new(base_frame) {|f|
+ TkFrame.new($filebox_demo) {|f|
TkLabel.new(f, 'text'=>"¥Õ¥¡¥¤¥ë¤ò#{type}: ", 'anchor'=>'e')\
.pack('side'=>'left')
@@ -50,7 +47,7 @@ TkFrame.new(base_frame) {|frame|
pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x')
TkButton.new(f, 'text'=>'Browse ...',
- 'command'=>proc{fileDialog base_frame,e,type})\
+ 'command'=>proc{fileDialog $filebox_demo,e,type})\
.pack('side'=>'left')
}
@@ -60,7 +57,7 @@ TkFrame.new(base_frame) {|frame|
$tk_strictMotif = TkVarAccess.new('tk_strictMotif')
if ($tk_platform['platform'] == 'unix')
- TkCheckButton.new(base_frame,
+ TkCheckButton.new($filebox_demo,
'text'=>'Motif¥¹¥¿¥¤¥ë¤Î¥À¥¤¥¢¥í¥°¤òÍѤ¤¤ë',
'variable'=>$tk_strictMotif,
'onvalue'=>1, 'offvalue'=>0 ).pack('anchor'=>'c')
@@ -93,10 +90,7 @@ def fileDialog(w,ent,operation)
if file != ""
ent.delete 0, 'end'
ent.insert 0, file
- # ent.xview 'end'
- Tk.update_idletasks # need this for Tk::Tile::Entry
- # (to find right position of 'xview').
- ent.xview(ent.index('end'))
+ ent.xview 'end'
end
end
diff --git a/ext/tk/sample/demos-jp/floor.rb b/ext/tk/sample/demos-jp/floor.rb
index a2ec2e9969..b029580bd6 100644
--- a/ext/tk/sample/demos-jp/floor.rb
+++ b/ext/tk/sample/demos-jp/floor.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# floorDisplay widget demo (called by 'widget')
#
@@ -1587,16 +1586,14 @@ $floor_demo = TkToplevel.new {|w|
minsize(100,100)
}
-base_frame = TkFrame.new($floor_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left',
+TkLabel.new($floor_demo, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left',
'text'=>"¤³¤Î¥¦¥£¥ó¥É¥¦¤Ë¤Ï¥Ç¥£¥¸¥¿¥ë¥¨¥¯¥¤¥Ã¥×¥á¥ó¥È¼Ò¤Î¥¦¥§¥¹¥¿¥ó¥ê¥µ¡¼¥Á¥é¥Ü¥é¥È¥ê (DECWRL) ¤Î´Ö¼è¤ê¤¬½ñ¤«¤ì¤¿¥­¥ã¥ó¥Ð¥¹ widget ¤¬Æþ¤Ã¤Æ¤¤¤Þ¤¹¡£¤³¤ì¤Ï 3³¬·ú¤Æ¤Ç¡¢¾ï¤Ë¤½¤Î¤¦¤Á¤Î1³¬Ê¬¤¬ÁªÂò¡¢¤Ä¤Þ¤ê¤½¤Î´Ö¼è¤ê¤¬É½¼¨¤µ¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£¤¢¤ë³¬¤òÁªÂò¤¹¤ë¤Ë¤Ï¡¢¤½¤Î¾å¤Ç¥Þ¥¦¥¹¤Îº¸¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£¥Þ¥¦¥¹¤¬ÁªÂò¤µ¤ì¤Æ¤¤¤ë³¬¤Î¾å¤òư¤¯¤È¡¢¤½¤Î²¼¤Ë¤¢¤ëÉô²°¤Î¿§¤¬ÊѤï¤ê¡¢Éô²°Èֹ椬¡ÖÉô²°ÈÖ¹æ:¡×¥¨¥ó¥È¥ê¤Ëɽ¼¨¤µ¤ì¤Þ¤¹¡£¤Þ¤¿¡¢¥¨¥ó¥È¥ê¤ËÉô²°ÈÖ¹æ¤ò½ñ¤¯¤È¤½¤ÎÉô²°¤Î¿§¤¬ÊѤï¤ê¤Þ¤¹¡£"){
pack('side'=>'top')
}
# frame À¸À®
-$floor_buttons = TkFrame.new(base_frame) {|frame|
+$floor_buttons = TkFrame.new($floor_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -1620,17 +1617,17 @@ $floorItems = {}
# canvas ÀßÄê
if $tk_version =~ /^4\.[01]/
- $floor_canvas_frame = TkFrame.new(base_frame,'bd'=>2,'relief'=>'sunken',
+ $floor_canvas_frame = TkFrame.new($floor_demo,'bd'=>2,'relief'=>'sunken',
'highlightthickness'=>2)
$floor_canvas = TkCanvas.new($floor_canvas_frame,
'width'=>900, 'height'=>500, 'borderwidth'=>0,
'highlightthickness'=>0) {|c|
- TkScrollbar.new(base_frame, 'orient'=>'horiz',
+ TkScrollbar.new($floor_demo, 'orient'=>'horiz',
'command'=>proc{|*args| c.xview(*args)}){|hs|
c.xscrollcommand(proc{|first,last| hs.set first,last})
pack('side'=>'bottom', 'fill'=>'x')
}
- TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}){|vs|
+ TkScrollbar.new($floor_demo, 'command'=>proc{|*args| c.yview(*args)}){|vs|
c.yscrollcommand(proc{|first,last| vs.set first,last})
pack('side'=>'right', 'fill'=>'y')
}
@@ -1639,7 +1636,7 @@ if $tk_version =~ /^4\.[01]/
$floor_canvas.pack('expand'=>'yes', 'fill'=>'both')
else
- TkFrame.new(base_frame) {|f|
+ TkFrame.new($floor_demo) {|f|
pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes')
h = TkScrollbar.new(f, 'highlightthickness'=>0, 'orient'=>'horizontal')
diff --git a/ext/tk/sample/demos-jp/floor2.rb b/ext/tk/sample/demos-jp/floor2.rb
index d4381c5543..a20b31d45c 100644
--- a/ext/tk/sample/demos-jp/floor2.rb
+++ b/ext/tk/sample/demos-jp/floor2.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# floorDisplay widget demo 2 (called by 'widget')
#
@@ -1587,16 +1586,14 @@ $floor2_demo = TkToplevel.new {|w|
minsize(100,100)
}
-base_frame = TkFrame.new($floor2_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left',
+TkLabel.new($floor2_demo, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left',
'text'=>"¤³¤Î¥¦¥£¥ó¥É¥¦¤Ë¤Ï¥Ç¥£¥¸¥¿¥ë¥¨¥¯¥¤¥Ã¥×¥á¥ó¥È¼Ò¤Î¥¦¥§¥¹¥¿¥ó¥ê¥µ¡¼¥Á¥é¥Ü¥é¥È¥ê (DECWRL) ¤Î´Ö¼è¤ê¤¬½ñ¤«¤ì¤¿¥­¥ã¥ó¥Ð¥¹ widget ¤¬Æþ¤Ã¤Æ¤¤¤Þ¤¹¡£¤³¤ì¤Ï 3³¬·ú¤Æ¤Ç¡¢¾ï¤Ë¤½¤Î¤¦¤Á¤Î1³¬Ê¬¤¬ÁªÂò¡¢¤Ä¤Þ¤ê¤½¤Î´Ö¼è¤ê¤¬É½¼¨¤µ¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£¤¢¤ë³¬¤òÁªÂò¤¹¤ë¤Ë¤Ï¡¢¤½¤Î¾å¤Ç¥Þ¥¦¥¹¤Îº¸¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£¥Þ¥¦¥¹¤¬ÁªÂò¤µ¤ì¤Æ¤¤¤ë³¬¤Î¾å¤òư¤¯¤È¡¢¤½¤Î²¼¤Ë¤¢¤ëÉô²°¤Î¿§¤¬ÊѤï¤ê¡¢Éô²°Èֹ椬¡ÖÉô²°ÈÖ¹æ:¡×¥¨¥ó¥È¥ê¤Ëɽ¼¨¤µ¤ì¤Þ¤¹¡£¤Þ¤¿¡¢¥¨¥ó¥È¥ê¤ËÉô²°ÈÖ¹æ¤ò½ñ¤¯¤È¤½¤ÎÉô²°¤Î¿§¤¬ÊѤï¤ê¤Þ¤¹¡£"){
pack('side'=>'top')
}
# frame À¸À®
-$floor2_buttons = TkFrame.new(base_frame) {|frame|
+$floor2_buttons = TkFrame.new($floor2_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -1620,17 +1617,17 @@ $floorItems2 = {}
# canvas ÀßÄê
if $tk_version =~ /^4\.[01]/
- $floor2_canvas_frame = TkFrame.new(base_frame,'bd'=>2,'relief'=>'sunken',
+ $floor2_canvas_frame = TkFrame.new($floor2_demo,'bd'=>2,'relief'=>'sunken',
'highlightthickness'=>2)
$floor2_canvas = TkCanvas.new($floor2_canvas_frame,
'width'=>900, 'height'=>500, 'borderwidth'=>0,
'highlightthickness'=>0) {|c|
- TkScrollbar.new(base_frame, 'orient'=>'horiz',
+ TkScrollbar.new($floor2_demo, 'orient'=>'horiz',
'command'=>proc{|*args| c.xview(*args)}){|hs|
c.xscrollcommand(proc{|first,last| hs.set first,last})
pack('side'=>'bottom', 'fill'=>'x')
}
- TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}){|vs|
+ TkScrollbar.new($floor2_demo, 'command'=>proc{|*args| c.yview(*args)}){|vs|
c.yscrollcommand(proc{|first,last| vs.set first,last})
pack('side'=>'right', 'fill'=>'y')
}
@@ -1639,7 +1636,7 @@ if $tk_version =~ /^4\.[01]/
$floor2_canvas.pack('expand'=>'yes', 'fill'=>'both')
else
- TkFrame.new(base_frame) {|f|
+ TkFrame.new($floor2_demo) {|f|
pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes')
h = TkScrollbar.new(f, 'highlightthickness'=>0, 'orient'=>'horizontal')
diff --git a/ext/tk/sample/demos-jp/form.rb b/ext/tk/sample/demos-jp/form.rb
index 4de7056764..fe456d3943 100644
--- a/ext/tk/sample/demos-jp/form.rb
+++ b/ext/tk/sample/demos-jp/form.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# form widget demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $form_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($form_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($form_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -28,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top', 'fill'=>'x')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($form_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -48,7 +45,7 @@ TkFrame.new(base_frame) {|frame|
# entry À¸À®
form_data = []
(1..5).each{|i|
- f = TkFrame.new(base_frame, 'bd'=>2)
+ f = TkFrame.new($form_demo, 'bd'=>2)
e = TkEntry.new(f, 'relief'=>'sunken', 'width'=>40)
l = TkLabel.new(f)
e.pack('side'=>'right')
diff --git a/ext/tk/sample/demos-jp/goldberg.rb b/ext/tk/sample/demos-jp/goldberg.rb
index a81c7ec70c..592b69f775 100644
--- a/ext/tk/sample/demos-jp/goldberg.rb
+++ b/ext/tk/sample/demos-jp/goldberg.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# Ruby/Tk Goldverg demo (called by 'widget')
#
@@ -55,8 +54,6 @@ $goldberg_demo = TkToplevel.new {|w|
# positionWindow(w)
}
-base_frame = TkFrame.new($goldberg_demo).pack(:fill=>:both, :expand=>true)
-
=begin
# label
msg = TkLabel.new($goldberg_demo) {
@@ -179,8 +176,7 @@ class TkGoldberg_Demo
do_ctrl_frame
do_detail_frame
- # msg = TkLabel.new(@parent, :bg=>@C['bg'], :fg=>'white') {
- msg = Tk::Label.new(@parent, :bg=>@C['bg'], :fg=>'white') {
+ msg = TkLabel.new(@parent, :bg=>@C['bg'], :fg=>'white') {
font 'Arial 10'
wraplength 600
justify 'left'
@@ -190,8 +186,7 @@ class TkGoldberg_Demo
frame = TkFrame.new(@parent, :bg=>@C['bg'])
- # TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
- Tk::Button.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
+ TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
text 'ÊĤ¸¤ë'
command proc{
tmppath = $goldberg_demo
@@ -200,14 +195,12 @@ class TkGoldberg_Demo
}
}.pack('side'=>'left')
- # TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
- Tk::Button.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
+ TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
text '¥³¡¼¥É»²¾È'
command proc{showCode 'goldberg'}
}.pack('side'=>'left', 'padx'=>5)
- # @show = TkButton.new(frame, :text=>'>>', :command=>proc{show_ctrl},
- @show = Tk::Button.new(frame, :text=>'>>', :command=>proc{show_ctrl},
+ @show = TkButton.new(frame, :text=>'>>', :command=>proc{show_ctrl},
:bg=>@C['bg'], :activebackground=>@C['bg'])
@show.pack('side'=>'left')
frame.place(:in=>@canvas, :relx=>1, :rely=>0, :anchor=>:ne)
@@ -216,11 +209,10 @@ class TkGoldberg_Demo
end
def do_ctrl_frame
- @start = Tk::Button.new(@parent, :text=>'Start', :bd=>6,
+ @start = TkButton.new(@parent, :text=>'Start', :bd=>6,
:command=>proc{do_button(0)})
- if font = @start['font']
- @start.font(font.weight('bold'))
- end
+ @start.font(@start['font'].weight('bold'))
+ font = @start['font']
@pause = TkCheckbutton.new(@parent, :text=>'Pause', :font=>font,
:command=>proc{do_button(1)}, :relief=>:raised,
@@ -2008,4 +2000,4 @@ class TkGoldberg_Demo
end
end
-TkGoldberg_Demo.new(base_frame)
+TkGoldberg_Demo.new($goldberg_demo)
diff --git a/ext/tk/sample/demos-jp/hello b/ext/tk/sample/demos-jp/hello
index 08f154d499..859ebd950e 100644
--- a/ext/tk/sample/demos-jp/hello
+++ b/ext/tk/sample/demos-jp/hello
@@ -1,5 +1,4 @@
#!/usr/bin/env ruby
-# -*- coding: euc-jp -*-
require 'tk'
TkButton.new(nil,
diff --git a/ext/tk/sample/demos-jp/hscale.rb b/ext/tk/sample/demos-jp/hscale.rb
index 5615aa50bd..37d215435c 100644
--- a/ext/tk/sample/demos-jp/hscale.rb
+++ b/ext/tk/sample/demos-jp/hscale.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
require "tkcanvas"
if defined?($hscale_demo) && $hscale_deom
@@ -12,9 +11,8 @@ $hscale_demo = TkToplevel.new {|w|
}
positionWindow($hscale_demo)
-base_frame = TkFrame.new($hscale_demo).pack(:fill=>:both, :expand=>true)
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($hscale_demo) {
font $font
wraplength '3.5i'
justify 'left'
@@ -24,7 +22,7 @@ msg = TkLabel.new(base_frame) {
}
msg.pack('side'=>'top')
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($hscale_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -41,17 +39,7 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
-def setWidth(w, width)
- width = width + 21
- x2 = width - 30
- if x2 < 21
- x2 = 21
- end
- w.coords 'poly',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
- w.coords 'line',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
-end
-
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($hscale_demo) {|frame|
canvas = TkCanvas.new(frame) {|c|
width 50
height 50
@@ -76,3 +64,14 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'expand'=>'yes', 'anchor'=>'n')
scale.set 75
}.pack('side'=>'top', 'fill'=>'x')
+
+
+def setWidth(w, width)
+ width = width + 21
+ x2 = width - 30
+ if x2 < 21
+ x2 = 21
+ end
+ w.coords 'poly',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
+ w.coords 'line',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
+end
diff --git a/ext/tk/sample/demos-jp/icon.rb b/ext/tk/sample/demos-jp/icon.rb
index a2ca6651dc..e4fef5cae7 100644
--- a/ext/tk/sample/demos-jp/icon.rb
+++ b/ext/tk/sample/demos-jp/icon.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# iconic button widget demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $icon_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($icon_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($icon_demo) {
font $font
wraplength '5i'
justify 'left'
@@ -28,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($icon_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -63,18 +60,16 @@ TkBitmapImage.new('file'=>[$demo_dir,'..',
letters = TkVariable.new
# frame À¸À®
-TkFrame.new(base_frame, 'borderwidth'=>10){|w|
+TkFrame.new($icon_demo, 'borderwidth'=>10){|w|
TkFrame.new(w) {|f|
- # TkRadioButton.new(f){
- Tk::RadioButton.new(f){
+ TkRadioButton.new(f){
bitmap '@' + [$demo_dir,'..',
'images','letters.xbm'].join(File::Separator)
variable letters
value 'full'
}.pack('side'=>'top', 'expand'=>'yes')
- # TkRadioButton.new(f){
- Tk::RadioButton.new(f){
+ TkRadioButton.new(f){
bitmap '@' + [$demo_dir,'..',
'images','noletter.xbm'].join(File::Separator)
variable letters
@@ -83,16 +78,14 @@ TkFrame.new(base_frame, 'borderwidth'=>10){|w|
}.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'5m')
- # TkCheckButton.new(w) {
- Tk::CheckButton.new(w) {
+ TkCheckButton.new(w) {
image flagdown
selectimage flagup
indicatoron 0
selectcolor self['background']
}.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'5m')
- # TkCheckButton.new(w) {
- Tk::CheckButton.new(w) {
+ TkCheckButton.new(w) {
bitmap '@' + [$demo_dir,'..',
'images','letters.xbm'].join(File::Separator)
indicatoron 0
diff --git a/ext/tk/sample/demos-jp/image1.rb b/ext/tk/sample/demos-jp/image1.rb
index d9435cc1a2..3d47f844e5 100644
--- a/ext/tk/sample/demos-jp/image1.rb
+++ b/ext/tk/sample/demos-jp/image1.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# two image widgets demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $image1_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($image1_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($image1_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -28,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($image1_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -55,10 +52,7 @@ TkPhotoImage.new('file'=>[$demo_dir,'..',
'images','earthris.gif'].join(File::Separator))
# label À¸À®
-#[ TkLabel.new(base_frame, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'),
-# TkLabel.new(base_frame, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken')
-#].each{|w| w.pack('side'=>'top', 'padx'=>'.5m', 'pady'=>'.5m')}
-[ Tk::Label.new(base_frame, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'),
- Tk::Label.new(base_frame, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken')
+[ TkLabel.new($image1_demo, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'),
+ TkLabel.new($image1_demo, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken')
].each{|w| w.pack('side'=>'top', 'padx'=>'.5m', 'pady'=>'.5m')}
diff --git a/ext/tk/sample/demos-jp/image2.rb b/ext/tk/sample/demos-jp/image2.rb
index 1bb2c9e9c3..e2e2a2b036 100644
--- a/ext/tk/sample/demos-jp/image2.rb
+++ b/ext/tk/sample/demos-jp/image2.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# widget demo 'load image' (called by 'widget')
#
@@ -16,10 +15,8 @@ $image2_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($image2_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($image2_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -28,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($image2_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -53,21 +50,21 @@ $dirName = TkVariable.new([$demo_dir,'..','images'].join(File::Separator))
$image2a = TkPhotoImage.new
# ¥Õ¥¡¥¤¥ë̾ÆþÎÏÉô
-TkLabel.new(base_frame, 'text'=>'¥Ç¥£¥ì¥¯¥È¥ê:')\
+TkLabel.new($image2_demo, 'text'=>'¥Ç¥£¥ì¥¯¥È¥ê:')\
.pack('side'=>'top', 'anchor'=>'w')
-image2_e = TkEntry.new(base_frame) {
+image2_e = TkEntry.new($image2_demo) {
width 30
textvariable $dirName
}.pack('side'=>'top', 'anchor'=>'w')
-TkFrame.new(base_frame, 'height'=>'3m', 'width'=>20)\
+TkFrame.new($image2_demo, 'height'=>'3m', 'width'=>20)\
.pack('side'=>'top', 'anchor'=>'w')
-TkLabel.new(base_frame, 'text'=>'¥Õ¥¡¥¤¥ë:')\
+TkLabel.new($image2_demo, 'text'=>'¥Õ¥¡¥¤¥ë:')\
.pack('side'=>'top', 'anchor'=>'w')
-TkFrame.new(base_frame){|w|
+TkFrame.new($image2_demo){|w|
s = TkScrollbar.new(w)
l = TkListbox.new(w) {
width 20
@@ -86,10 +83,9 @@ TkFrame.new(base_frame){|w|
}.pack('side'=>'top', 'anchor'=>'w')
# image ÇÛÃÖ
-[ TkFrame.new(base_frame, 'height'=>'3m', 'width'=>20),
- TkLabel.new(base_frame, 'text'=>'²èÁü:'),
- # TkLabel.new(base_frame, 'image'=>$image2a)
- Tk::Label.new(base_frame, 'image'=>$image2a)
+[ TkFrame.new($image2_demo, 'height'=>'3m', 'width'=>20),
+ TkLabel.new($image2_demo, 'text'=>'²èÁü:'),
+ TkLabel.new($image2_demo, 'image'=>$image2a)
].each{|w| w.pack('side'=>'top', 'anchor'=>'w')}
# ¥á¥½¥Ã¥ÉÄêµÁ
diff --git a/ext/tk/sample/demos-jp/image3.rb b/ext/tk/sample/demos-jp/image3.rb
index 12b8aafd8e..d9f378c116 100644
--- a/ext/tk/sample/demos-jp/image3.rb
+++ b/ext/tk/sample/demos-jp/image3.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
# image3.rb
#
# This demonstration script creates a simple collection of widgets
@@ -20,8 +19,6 @@ $image3_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($image3_demo).pack(:fill=>:both, :expand=>true)
-
#
def loadDir3(w)
w.delete(0,'end')
@@ -52,7 +49,7 @@ end
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($image3_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -61,7 +58,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($image3_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -90,11 +87,11 @@ end
$image3a = TkPhotoImage.new
#
-image3_f = TkFrame.new(base_frame).pack(:fill=>:both, :expand=>true)
+image3_f = TkFrame.new($image3_demo).pack(:fill=>:both, :expand=>true)
-image3_df = TkLabelFrame.new(base_frame, :text=>'¥Ç¥£¥ì¥¯¥È¥ê:')
+image3_df = TkLabelFrame.new($image3_demo, :text=>'¥Ç¥£¥ì¥¯¥È¥ê:')
-image3_ff = TkLabelFrame.new(base_frame, :text=>'¥Õ¥¡¥¤¥ë:',
+image3_ff = TkLabelFrame.new($image3_demo, :text=>'¥Õ¥¡¥¤¥ë:',
:padx=>'2m', :pady=>'2m')
image3_lbx = TkListbox.new(image3_ff, :width=>20, :height=>10) {
pack(:side=>:left, :fill=>:y, :expand=>true)
@@ -114,9 +111,8 @@ TkButton.new(image3_df, :pady=>0, :padx=>'2m', :text=>"¥Ç¥£¥ì¥¯¥È¥êÁªÂò",
pack(:side=>:left, :fill=>:y, :padx=>[0, '2m'], :pady=>'2m')
}
-image3_if = TkLabelFrame.new(base_frame, :text=>'¥¤¥á¡¼¥¸:') {|f|
- # TkLabel.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m')
- Tk::Label.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m')
+image3_if = TkLabelFrame.new($image3_demo, :text=>'¥¤¥á¡¼¥¸:') {|f|
+ TkLabel.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m')
}
Tk.grid(image3_df, '-',
diff --git a/ext/tk/sample/demos-jp/items.rb b/ext/tk/sample/demos-jp/items.rb
index 64ceeff3ec..38774d10d2 100644
--- a/ext/tk/sample/demos-jp/items.rb
+++ b/ext/tk/sample/demos-jp/items.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# canvas item types widget demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $items_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($items_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-TkLabel.new(base_frame) {
+TkLabel.new($items_demo) {
font $font
wraplength '5i'
justify 'left'
@@ -27,7 +24,7 @@ TkLabel.new(base_frame) {
}.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($items_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -46,7 +43,7 @@ TkFrame.new(base_frame) {|frame|
# frame À¸À®
cvs = nil
-TkFrame.new(base_frame) {|cf|
+TkFrame.new($items_demo) {|cf|
# canvas À¸À®
cvs = TkCanvas.new(cf) {|c|
focus
@@ -94,13 +91,8 @@ TkcLine.new(cvs, '0c', '16c', '30c', '16c', 'width'=>2)
TkcLine.new(cvs, '10c', '0c', '10c', '24c', 'width'=>2)
TkcLine.new(cvs, '20c', '0c', '20c', '24c', 'width'=>2)
-if $tk_version =~ /^4.*/
- font1 = '-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*'
- font2 = '-Adobe-Helvetica-Bold-R-Normal--*-240-*-*-*-*-*-*'
-else
- font1 = 'Helvetica 12'
- font2 = 'Helvetica 24 bold'
-end
+font1 = '-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*'
+font2 = '-Adobe-Helvetica-Bold-R-Normal--*-240-*-*-*-*-*-*'
if TkWinfo.depth($root).to_i > 1
blue = 'DeepSkyBlue3'
red = 'red'
diff --git a/ext/tk/sample/demos-jp/ixset2 b/ext/tk/sample/demos-jp/ixset2
index 5b816e40b1..8947daa4b4 100644
--- a/ext/tk/sample/demos-jp/ixset2
+++ b/ext/tk/sample/demos-jp/ixset2
@@ -1,5 +1,4 @@
#!/usr/bin/env ruby
-# -*- coding: euc-jp -*-
#
# ixset --
# A nice interface to "xset" to change X server settings
diff --git a/ext/tk/sample/demos-jp/knightstour.rb b/ext/tk/sample/demos-jp/knightstour.rb
deleted file mode 100644
index d4595ea441..0000000000
--- a/ext/tk/sample/demos-jp/knightstour.rb
+++ /dev/null
@@ -1,273 +0,0 @@
-# -*- coding: euc-jp -*-
-#
-# Based on the widget demo of Tcl/Tk8.5.2
-# The following is the original copyright text.
-#----------------------------------------------------------------------------
-# Copyright (C) 2008 Pat Thoyts <patthoyts@users.sourceforge.net>
-#
-# Calculate a Knight's tour of a chessboard.
-#
-# This uses Warnsdorff's rule to calculate the next square each
-# time. This specifies that the next square should be the one that
-# has the least number of available moves.
-#
-# Using this rule it is possible to get to a position where
-# there are no squares available to move into. In this implementation
-# this occurs when the starting square is d6.
-#
-# To solve this fault an enhancement to the rule is that if we
-# have a choice of squares with an equal score, we should choose
-# the one nearest the edge of the board.
-#
-# If the call to the Edgemost function is commented out you can see
-# this occur.
-#
-# You can drag the knight to a specific square to start if you wish.
-# If you let it repeat then it will choose random start positions
-# for each new tour.
-#----------------------------------------------------------------------------
-require 'tk'
-
-class Knights_Tour
- # Return a list of accessible squares from a given square
- def valid_moves(square)
- moves = []
- [
- [-1,-2], [-2,-1], [-2,1], [-1,2], [1,2], [2,1], [2,-1], [1,-2]
- ].each{|col_delta, row_delta|
- col = (square % 8) + col_delta
- row = (square.div(8)) + row_delta
- moves << (row * 8 + col) if row > -1 && row < 8 && col > -1 && col < 8
- }
- moves
- end
-
- # Return the number of available moves for this square
- def check_square(square)
- valid_moves(square).find_all{|pos| ! @visited.include?(pos)}.length
- end
-
- # Select the next square to move to. Returns -1 if there are no available
- # squares remaining that we can move to.
- def next_square(square)
- minimum = 9
- nxt = -1
- valid_moves(square).each{|pos|
- unless @visited.include?(pos)
- cnt = check_square(pos)
- if cnt < minimum
- minimum = cnt
- nxt = pos
- elsif cnt == minimum
- nxt = edgemost(nxt, pos)
- end
- end
- }
- nxt
- end
-
- # Select the square nearest the edge of the board
- def edgemost(nxt, pos)
- col_A = 3 - ((3.5 - nxt % 8).abs.to_i)
- col_B = 3 - ((3.5 - pos % 8).abs.to_i)
- row_A = 3 - ((3.5 - nxt.div(8)).abs.to_i)
- row_B = 3 - ((3.5 - pos.div(8)).abs.to_i)
- (col_A * row_A < col_B * row_B)? nxt : pos
- end
-
- # Display a square number as a standard chess square notation.
- def _N(square)
- '%c%d' % [(97 + square % 8), (square.div(8) + 1)]
- end
-
- # Perform a Knight's move and schedule the next move.
- def move_piece(last, square)
- @log.insert(:end, "#{@visited.length}. #{_N last} -> #{_N square}\n", '')
- @log.see(:end)
- @board.itemconfigure(1+last, :state=>:normal, :outline=>'black')
- @board.itemconfigure(1+square, :state=>:normal, :outline=>'red')
- @knight.coords(@board.coords(1+square)[0..1])
- @visited << square
- if (nxt = next_square(square)) != -1
- @after_id = Tk.after(@delay.numeric){move_piece(square, nxt) rescue nil}
- else
- @start_btn.state :normal
- if @visited.length == 64
- if @initial == square
- @log.insert :end, '¼þÍ·(closed tour)À®¸ù¡ª'
- else
- @log.insert :end, "À®¸ù\n", {}
- Tk.after(@delay.numeric * 2){tour(rand(64))} if @continuous.bool
- end
- else
- @log.insert :end, "¼ºÇÔ¡ª\n", {}
- end
- end
- end
-
- # Begin a new tour of the board given a random start position
- def tour(square = nil)
- @visited.clear
- @log.clear
- @start_btn.state :disabled
- 1.upto(64){|n|
- @board.itemconfigure(n, :state=>:disabled, :outline=>'black')
- }
- unless square
- square = @board.find_closest(*(@knight.coords << 0 << 65))[0].to_i - 1
- end
- @initial = square
- Tk.after_idle{ move_piece(@initial, @initial) rescue nil }
- end
-
- def _stop
- Tk.after_cancel(@after_id) rescue nil
- end
-
- def _exit
- _stop
- $knightstour.destroy
- end
-
- def set_delay(new)
- @delay.numeric = new.to_i
- end
-
- def drag_start(w, x, y)
- w.dtag('selected')
- w.addtag('selected', :withtag, 'current')
- @dragging = [x, y]
- end
-
- def drag_motion(w, x, y)
- return unless @dragging
- w.move('selected', x - @dragging[0], y - @dragging[1])
- @dragging = [x, y]
- end
-
- def drag_end(w, x, y)
- square = w.find_closest(x, y, 0, 65)
- w.coords('selected', w.coords(square)[0..1])
- w.dtag('selected')
- @dragging = nil
- end
-
- def make_SeeDismiss
- ## See Code / Dismiss
- frame = Ttk::Frame.new($knightstour)
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'knightstour'}),
- Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $knightstour.destroy
- $knightstour = nil
- }),
- :padx=>4, :pady=>4)
- frame.grid_columnconfigure(0, :weight=>1)
- frame
- end
-
- def create_gui(parent = nil)
- $knightstour.destroy rescue nil
- $knightstour = Tk::Toplevel.new(parent, :title=>"Knight's tour")
- $knightstour.withdraw
- base_f = Ttk::Frame.new($knightstour)
- @board = Tk::Canvas.new(base_f, :width=>240, :height=>240)
- @log = Tk::Text.new(base_f, :width=>12, :height=>1,
- :font=>'Arial 8', :background=>'white')
- scr = @log.yscrollbar(Ttk::Scrollbar.new(base_f))
-
- @visited = []
- @delay = TkVariable.new(600)
- @continuous = TkVariable.new(false)
-
- tool_f = Ttk::Frame.new($knightstour)
- label = Ttk::Label.new(tool_f, :text=>'¼Â¹Ô®ÅÙ')
- scale = Ttk::Scale.new(tool_f, :from=>8, :to=>2000, :variable=>@delay,
- :command=>proc{|n| set_delay(n)})
- check = Ttk::Checkbutton.new(tool_f, :text=>'È¿Éü',
- :variable=>@continuous)
- @start_btn = Ttk::Button.new(tool_f, :text=>'³«»Ï',
- :command=>proc{tour()})
- @exit_btn = Ttk::Button.new(tool_f, :text=>'½ªÎ»',
- :command=>proc{_exit()})
-
- 7.downto(0){|row|
- 0.upto(7){|col|
- if ((col & 1) ^ (row & 1)).zero?
- fill = 'bisque'
- dfill = 'bisque3'
- else
- fill = 'tan3'
- dfill = 'tan4'
- end
- coords = [col * 30 + 4, row * 30 + 4, col * 30 + 30, row * 30 + 30]
- @board.create(TkcRectangle, coords,
- :fill=>fill, :disabledfill=>dfill,
- :width=>2, :state=>:disabled)
- }
- }
-
- @knight_font = TkFont.new(:size=>-24)
- @knight = TkcText.new(@board, 0, 0, :font=>@knight_font,
- :text=>Tk::UTF8_String.new('\u265e'),
- :anchor=>'nw', # :tags=>'knight',
- :fill=>'black', :activefill=>'#600000')
- @knight.coords(@board.coords(rand(64)+1)[0..1])
- @knight.bind('ButtonPress-1', '%W %x %y'){|w,x,y| drag_start(w,x,y)}
- @knight.bind('Motion', '%W %x %y'){|w,x,y| drag_motion(w,x,y)}
- @knight.bind('ButtonRelease-1', '%W %x %y'){|w,x,y| drag_end(w,x,y)}
-
- Tk.grid(@board, @log, scr, :sticky=>'news')
- base_f.grid_rowconfigure(0, :weight=>1)
- base_f.grid_columnconfigure(0, :weight=>1)
-
- Tk.grid(base_f, '-', '-', '-', '-', '-', :sticky=>'news')
- widgets = [label, scale, check, @start_btn]
- sg = nil
- unless $RubyTk_WidgetDemo
- widgets << @exit_btn
- if Tk.windowingsystem != 'aqua'
- #widgets.unshift(Ttk::SizeGrip.new(tool_f))
- Ttk::SizeGrip.new(tool_f).pack(:side=>:right, :anchor=>'se')
- end
- end
- Tk.pack(widgets, :side=>:right)
- if Tk.windowingsystem == 'aqua'
- TkPack.configure(widgets, :padx=>[4, 4], :pady=>[12, 12])
- TkPack.configure(widgets[0], :padx=>[4, 24])
- TkPack.configure(widgets[-1], :padx=>[16, 4])
- end
-
- Tk.grid(tool_f, '-', '-', '-', '-', '-', :sticky=>'ew')
-
- if $RubyTk_WidgetDemo
- Tk.grid(make_SeeDismiss(), '-', '-', '-', '-', '-', :sticky=>'ew')
- end
-
- $knightstour.grid_rowconfigure(0, :weight=>1)
- $knightstour.grid_columnconfigure(0, :weight=>1)
-
- $knightstour.bind('Control-F2'){TkConsole.show}
- $knightstour.bind('Return'){@start_btn.invoke}
- $knightstour.bind('Escape'){@exit_btn.invoke}
- $knightstour.bind('Destroy'){ _stop }
- $knightstour.protocol('WM_DELETE_WINDOW'){ _exit }
-
- $knightstour.deiconify
- $knightstour.tkwait_destroy
- end
-
- def initialize(parent = nil)
- create_gui(parent)
- end
-end
-
-Tk.root.withdraw unless $RubyTk_WidgetDemo
-Thread.new{Tk.mainloop} if __FILE__ == $0
-Knights_Tour.new
diff --git a/ext/tk/sample/demos-jp/label.rb b/ext/tk/sample/demos-jp/label.rb
index 2e6b3e7e57..59626289fc 100644
--- a/ext/tk/sample/demos-jp/label.rb
+++ b/ext/tk/sample/demos-jp/label.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# label widget demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $label_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($label_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($label_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -28,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($label_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -47,8 +44,8 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# label demo Íѥե졼¥àÀ¸À®
-f_left = TkFrame.new(base_frame)
-f_right = TkFrame.new(base_frame)
+f_left = TkFrame.new($label_demo)
+f_right = TkFrame.new($label_demo)
[f_left, f_right].each{|w| w.pack('side'=>'left', 'expand'=>'yes',
'padx'=>10, 'pady'=>10, 'fill'=>'both')}
@@ -59,8 +56,7 @@ f_right = TkFrame.new(base_frame)
TkLabel.new(f_left, 'text'=>'3 ÈÖÌÜ¡£ÄÀ¤ó¤Ç¤¤¤Þ¤¹ ', 'relief'=>'sunken')
].each{|w| w.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2, 'anchor'=>'w')}
-# TkLabel.new(f_right) {
-Tk::Label.new(f_right) {
+TkLabel.new(f_right) {
bitmap('@' + [$demo_dir,'..','images','face.xbm'].join(File::Separator))
borderwidth 2
relief 'sunken'
diff --git a/ext/tk/sample/demos-jp/labelframe.rb b/ext/tk/sample/demos-jp/labelframe.rb
index 11b0d27308..23c974dcc2 100644
--- a/ext/tk/sample/demos-jp/labelframe.rb
+++ b/ext/tk/sample/demos-jp/labelframe.rb
@@ -1,5 +1,3 @@
-# -*- coding: euc-jp -*-
-#
# labelframe.rb
#
# This demonstration script creates a toplevel window containing
@@ -19,10 +17,8 @@ $labelframe_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($labelframe_demo).pack(:fill=>:both, :expand=>true)
-
# Some information
-TkLabel.new(base_frame,
+TkLabel.new($labelframe_demo,
:font=>$font, :wraplength=>'4i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
TkLabelFrame ¥¦¥£¥¸¥§¥Ã¥È¤Ï´ØÏ¢¤¹¤ë widget
@@ -38,7 +34,7 @@ labelframe ¥¦¥£¥¸¥§¥Ã¥È¤ò¼ÂÁõ¤·¤Æ¤¤¤Ê¤¤
EOL
# The bottom buttons
-TkFrame.new(base_frame){|f|
+TkFrame.new($labelframe_demo){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{
@@ -52,7 +48,7 @@ TkFrame.new(base_frame){|f|
}
# Demo area
-w = TkFrame.new(base_frame).pack(:side=>:bottom, :fill=>:both,
+w = TkFrame.new($labelframe_demo).pack(:side=>:bottom, :fill=>:both,
:expand=>true)
# A group of radiobuttons in a labelframe
diff --git a/ext/tk/sample/demos-jp/mclist.rb b/ext/tk/sample/demos-jp/mclist.rb
deleted file mode 100644
index a7834d2668..0000000000
--- a/ext/tk/sample/demos-jp/mclist.rb
+++ /dev/null
@@ -1,121 +0,0 @@
-# -*- coding: euc-jp -*-
-#
-# mclist.rb --
-#
-# This demonstration script creates a toplevel window containing a Ttk
-# tree widget configured as a multi-column listbox.
-#
-# based on "Id: mclist.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($mclist_demo) && $mclist_demo
- $mclist_demo.destroy
- $mclist_demo = nil
-end
-
-$mclist_demo = TkToplevel.new {|w|
- title("Multi-Column List")
- iconname("mclist")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($mclist_demo).pack(:fill=>:both, :expand=>true)
-
-## Explanatory text
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i',
- :justify=>:left, :anchor=>'n', :padding=>[10, 2, 10, 6],
- :text=><<EOL).pack(:fill=>:x)
-Ttk¤È¤Ï¡¤¥Æ¡¼¥Þ»ØÄê²Äǽ¤Ê¿·¤·¤¤¥¦¥£¥¸¥§¥Ã¥È½¸¹ç¤Ç¤¹¡¥\
-Ttk::Treeview¥¦¥£¥¸¥§¥Ã¥È¤Ï\
-Ttk¥¦¥£¥¸¥§¥Ã¥È¥»¥Ã¥È¤Ë´Þ¤Þ¤ì¤ë¥¦¥£¥¸¥§¥Ã¥È¤Î°ì¤Ä¤Ç¡¤\
-¤½¤ì¤¬ÊÝ»ý¤¹¤ëÌÚ¹½Â¤¤Î¥Ç¡¼¥¿¤½¤Î¤â¤Î¤Þ¤Ç¤Ïɽ¼¨¤¹¤ë¤³¤È¤Ê¤¯¡¤\
-¼¨¤·¤¿¤¤¾ðÊó¤ò¥Þ¥ë¥Á¥«¥é¥à¤Çɽ¼¨¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¥
-¤³¤Î¥µ¥ó¥×¥ë¤Ï¡¤Ê£¿ô¤Î¥«¥é¥à¤ò»ý¤Ã¤¿¥ê¥¹¥È¥Ü¥Ã¥¯¥¹¤òºîÀ®¤¹¤ë´Êñ¤ÊÎã¤Ç¤¹¡¥
-³Æ¥«¥é¥à¤Î¥¿¥¤¥È¥ë(heading)¤ò¥¯¥ê¥Ã¥¯¤¹¤ì¤Ð¡¤\
-¤½¤Î¥«¥é¥à¤Î¾ðÊó¤Ë´ð¤Å¤¤¤Æ¥ê¥¹¥È¤ÎʤÙÂØ¤¨¤¬¤Ê¤µ¤ì¤ë¤Ï¤º¤Ç¤¹¡¥\
-¤Þ¤¿¡¤¥«¥é¥à¤Î¥¿¥¤¥È¥ë´Ö¤Î¶èÀÚ¤êÉôʬ¤ò¥É¥é¥Ã¥°¤¹¤ë¤³¤È¤Ç¡¤\
-¥«¥é¥à¤ÎÉý¤òÊѹ¹¤¹¤ë¤³¤È¤â²Äǽ¤Ç¤¹¡¥
-EOL
-
-## See Code / Dismiss
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'mclist'}),
- Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $mclist_demo.destroy
- $mclist_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-container = Ttk::Frame.new(base_frame)
-tree = Ttk::Treeview.new(base_frame, :columns=>%w(country capital currency),
- :show=>:headings)
-if Tk.windowingsystem != 'aquq'
- vsb = tree.yscrollbar(Ttk::Scrollbar.new(base_frame))
- hsb = tree.xscrollbar(Ttk::Scrollbar.new(base_frame))
-else
- vsb = tree.yscrollbar(Tk::Scrollbar.new(base_frame))
- hsb = tree.xscrollbar(Tk::Scrollbar.new(base_frame))
-end
-
-container.pack(:fill=>:both, :expand=>true)
-Tk.grid(tree, vsb, :in=>container, :sticky=>'nsew')
-Tk.grid(hsb, :in=>container, :sticky=>'nsew')
-container.grid_columnconfigure(0, :weight=>1)
-container.grid_rowconfigure(0, :weight=>1)
-
-## The data we're going to insert
-data = [
- ['¥¢¥ë¥¼¥ó¥Á¥ó', '¥Ö¥¨¥Î¥¹¥¢¥¤¥ì¥¹', 'ARS'],
- ['¥ª¡¼¥¹¥È¥é¥ê¥¢', '¥­¥ã¥ó¥Ù¥é', 'AUD'],
- ['¥Ö¥é¥¸¥ë', '¥Ö¥é¥¸¥ê¥¢', 'BRL'],
- ['¥«¥Ê¥À', '¥ª¥¿¥ï', 'CAD'],
- ['Ãæ¹ñ', 'Ë̵þ', 'CNY'],
- ['¥Õ¥é¥ó¥¹', '¥Ñ¥ê', 'EUR'],
- ['¥É¥¤¥Ä', '¥Ù¥ë¥ê¥ó', 'EUR'],
- ['¥¤¥ó¥É', '¥Ë¥å¡¼¥Ç¥ê¡¼', 'INR'],
- ['¥¤¥¿¥ê¥¢', '¥í¡¼¥Þ', 'EUR'],
- ['ÆüËÜ', 'Åìµþ', 'JPY'],
- ['¥á¥­¥·¥³', '¥á¥­¥·¥³¥·¥Æ¥£', 'MXN'],
- ['¥í¥·¥¢', '¥â¥¹¥¯¥ï', 'RUB'],
- ['Æî¥¢¥Õ¥ê¥«', '¥×¥ì¥È¥ê¥¢', 'ZAR'],
- ['±Ñ¹ñ', '¥í¥ó¥É¥ó', 'GBP'],
- ['¥¢¥á¥ê¥«', '¥ï¥·¥ó¥È¥ó D.C.', 'USD'],
-]
-
-## Code to insert the data nicely
-font = Ttk::Style.lookup(tree[:style], :font)
-cols = %w(country capital currency)
-cols.zip(%w(¹ñ̾ ¼óÅÔ Ä̲ß)).each{|col, name|
- tree.heading_configure(col, :text=>name,
- :command=>proc{sort_by(tree, col, false)})
- tree.column_configure(col, :width=>TkFont.measure(font, name))
-}
-
-data.each{|country, capital, currency|
- #tree.insert('', :end, :values=>[country, capital, currency])
- tree.insert(nil, :end, :values=>[country, capital, currency])
- cols.zip([country, capital, currency]).each{|col, val|
- len = TkFont.measure(font, "#{val} ")
- if tree.column_cget(col, :width) < len
- tree.column_configure(col, :width=>len)
- end
- }
-}
-
-## Code to do the sorting of the tree contents when clicked on
-def sort_by(tree, col, direction)
- tree.children(nil).map!{|row| [tree.get(row, col), row.id]} .
- sort(&((direction)? proc{|x, y| y <=> x}: proc{|x, y| x <=> y})) .
- each_with_index{|info, idx| tree.move(info[1], nil, idx)}
-
- tree.heading_configure(col, :command=>proc{sort_by(tree, col, ! direction)})
-end
diff --git a/ext/tk/sample/demos-jp/menu.rb b/ext/tk/sample/demos-jp/menu.rb
index c3d95176b4..add85f7f7b 100644
--- a/ext/tk/sample/demos-jp/menu.rb
+++ b/ext/tk/sample/demos-jp/menu.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# menus widget demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $menu_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($menu_demo).pack(:fill=>:both, :expand=>true)
-
# menu frame À¸À®
-$menu_frame = TkFrame.new(base_frame, 'relief'=>'raised', 'bd'=>2)
+$menu_frame = TkFrame.new($menu_demo, 'relief'=>'raised', 'bd'=>2)
$menu_frame.pack('side'=>'top', 'fill'=>'x')
begin
@@ -29,7 +26,7 @@ rescue
end
# label À¸À®
-TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
+TkLabel.new($menu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
if $tk_platform['platform'] == 'macintosh' ||
windowingsystem == "classic" || windowingsystem == "aqua"
text("¤³¤Î¥¦¥£¥ó¥É¥¦¤ÏÍÍ¡¹¤Ê¥á¥Ë¥å¡¼¤È¥«¥¹¥±¡¼¥É¥á¥Ë¥å¡¼¤«¤é¹½À®¤µ¤ì¤Æ¤¤¤Þ¤¹¡£Command-X ¤òÆþÎϤ¹¤ë¤È¡¢X¤¬¥³¥Þ¥ó¥É¥­¡¼µ­¹æ¤Ë³¤¤¤ÆÉ½¼¨¤µ¤ì¤Æ¤¤¤ëʸ»ú¤Ê¤é¤Ð¡¢¥¢¥¯¥»¥é¥ì¡¼¥¿¤ò»È¤Ã¤¿¹àÌܵ¯Æ°¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¥á¥Ë¥å¡¼Í×ÁÇÃæ¡¢ºÇ¸å¤Î¤â¤Î¤Ï¡¢¤½¤Î¥á¥Ë¥å¡¼¤ÎºÇ½é¤Î¹àÌܤòÁªÂò¤¹¤ë¤³¤È¤ÇÆÈΩ¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£")
@@ -39,7 +36,7 @@ TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
}.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menu_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -110,8 +107,7 @@ TkMenubutton.new($menu_frame, 'text'=>'Cascades', 'underline'=>0) {|m|
'accelerator'=>"#{modifier}+G", 'underline'=>6)
$menu_demo.bind("#{modifier}-g", proc{print "Goodbye(¤µ¤è¤¦¤Ê¤é)\n"})
- # TkMenu.new(m, 'tearoff'=>false) {|cascade_check|
- TkMenu.new(cascade_menu, 'tearoff'=>false) {|cascade_check|
+ TkMenu.new(m, 'tearoff'=>false) {|cascade_check|
cascade_menu.add('cascade', 'label'=>'Check buttons(¥Á¥§¥Ã¥¯¥Ü¥¿¥ó)',
'menu'=>cascade_check, 'underline'=>0)
oil = TkVariable.new(0)
@@ -133,8 +129,7 @@ TkMenubutton.new($menu_frame, 'text'=>'Cascades', 'underline'=>0) {|m|
invoke 3
}
- #TkMenu.new(m, 'tearoff'=>false) {|cascade_radio|
- TkMenu.new(cascade_menu, 'tearoff'=>false) {|cascade_radio|
+ TkMenu.new(m, 'tearoff'=>false) {|cascade_radio|
cascade_menu.add('cascade', 'label'=>'Radio buttons(¥é¥¸¥ª¥Ü¥¿¥ó)',
'menu'=>cascade_radio, 'underline'=>0)
pointSize = TkVariable.new
diff --git a/ext/tk/sample/demos-jp/menu84.rb b/ext/tk/sample/demos-jp/menu84.rb
index a631bacd43..8c2a815d78 100644
--- a/ext/tk/sample/demos-jp/menu84.rb
+++ b/ext/tk/sample/demos-jp/menu84.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# menus widget demo (called by 'widget')
#
@@ -16,8 +15,6 @@ $menu84_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($menu84_demo).pack(:fill=>:both, :expand=>true)
-
begin
windowingsystem = Tk.windowingsystem()
rescue
@@ -25,7 +22,7 @@ rescue
end
# label
-TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
+TkLabel.new($menu84_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
if $tk_platform['platform'] == 'macintosh' ||
windowingsystem == "classic" || windowingsystem == "aqua"
text("¤³¤Î¥¦¥£¥ó¥É¥¦¤Ë¤Ï¥«¥¹¥±¡¼¥É¥á¥Ë¥å¡¼¤ò»ý¤Ä¥á¥Ë¥å¡¼¥Ð¡¼¤¬ÉÕ¤±¤é¤ì¤Æ¤¤¤Þ¤¹¡£Command+x ('x'¤Ï¥³¥Þ¥ó¥É¥­¡¼¥·¥ó¥Ü¥ë¤Ë³¤±¤ÆÉ½¼¨¤µ¤ì¤Æ¤¤¤ëʸ»ú¤Ç¤¹) ¤È¥¿¥¤¥×¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¤â¹àÌܤε¡Ç½¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£ºÇ¸å¤Î¥á¥Ë¥å¡¼¤Ï¡¢¥Þ¥¦¥¹¤Ç¥¦¥£¥ó¥É¥¦¤Î³°¤Ë¥É¥é¥Ã¥°¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¡¢ÆÈΩ¤·¤¿¥Ñ¥ì¥Ã¥È¤È¤Ê¤ë¤è¤¦¤ËÀÚ¤êÊü¤¹¤³¤È¤¬²Äǽ¤Ç¤¹¡£")
@@ -36,7 +33,7 @@ TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
menustatus = TkVariable.new(" ")
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menu84_demo) {|frame|
TkLabel.new(frame, 'textvariable'=>menustatus, 'relief'=>'sunken',
'bd'=>1, 'font'=>['Helvetica', '10'],
'anchor'=>'w').pack('side'=>'left', 'padx'=>2,
@@ -46,7 +43,7 @@ TkFrame.new(base_frame) {|frame|
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menu84_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
diff --git a/ext/tk/sample/demos-jp/menu8x.rb b/ext/tk/sample/demos-jp/menu8x.rb
index 9249f2491a..050f0decb4 100644
--- a/ext/tk/sample/demos-jp/menu8x.rb
+++ b/ext/tk/sample/demos-jp/menu8x.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# menus widget demo (called by 'widget')
#
@@ -16,18 +15,16 @@ $menu8x_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($menu8x_demo).pack(:fill=>:both, :expand=>true)
-
# version check
if $tk_version.to_f < 8.0
# label À¸À®
-TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
+TkLabel.new($menu8x_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
text("¼Â¹Ô¤·¤è¤¦¤È¤·¤¿¥¹¥¯¥ê¥×¥È¤Ï Tk8.0 °Ê¾å¤ÇÍøÍѤǤ­¤ëµ¡Ç½¤òÍøÍѤ·¤Æ¤¤¤ë¤¿¤á¡¢¤¢¤Ê¤¿¤Î Ruby#{VERSION}/Tk#{$tk_version}#{(Tk::JAPANIZED_TK)? 'jp': ''} ¤Ç¤ÏÀµ¾ï¤Ë¼Â¹Ô¤Ç¤­¤Þ¤»¤ó¡£¤è¤Ã¤Æ¥Ç¥â¤Î¼Â¹Ô¤òÃæ»ß¤·¤Þ¤·¤¿¡£¤¿¤À¤·¡¢²¼¤Î¥³¡¼¥É»²¾È¥Ü¥¿¥ó¤ò²¡¤¹¤³¤È¤Ç¡¢¼Â¹Ô¤¬Ãæ»ß¤µ¤ì¤¿¥¹¥¯¥ê¥×¥È¤Î¥½¡¼¥¹¤ò»²¾È¤¹¤ë¤³¤È¤Ï²Äǽ¤Ç¤¹¡£")
}.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menu8x_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -53,7 +50,7 @@ rescue
end
# label À¸À®
-TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
+TkLabel.new($menu8x_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
if $tk_platform['platform'] == 'macintosh' ||
windowingsystem == "classic" || windowingsystem == "aqua"
text("¤³¤Î¥¦¥£¥ó¥É¥¦¤ÏÍÍ¡¹¤Ê¥á¥Ë¥å¡¼¤È¥«¥¹¥±¡¼¥É¥á¥Ë¥å¡¼¤«¤é¹½À®¤µ¤ì¤Æ¤¤¤Þ¤¹¡£Command-X ¤òÆþÎϤ¹¤ë¤È¡¢X¤¬¥³¥Þ¥ó¥É¥­¡¼µ­¹æ¤Ë³¤¤¤ÆÉ½¼¨¤µ¤ì¤Æ¤¤¤ëʸ»ú¤Ê¤é¤Ð¡¢¥¢¥¯¥»¥é¥ì¡¼¥¿¤ò»È¤Ã¤¿¹àÌܵ¯Æ°¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¥á¥Ë¥å¡¼Í×ÁÇÃæ¡¢ºÇ¸å¤Î¤â¤Î¤Ï¡¢¤½¤Î¥á¥Ë¥å¡¼¤ÎºÇ½é¤Î¹àÌܤòÁªÂò¤¹¤ë¤³¤È¤ÇÆÈΩ¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£")
@@ -64,14 +61,14 @@ TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
# ¾õÂÖɽ¼¨¤ÎÀ¸À®
$menu8xstatus = TkVariable.new(" ")
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menu8x_demo) {|frame|
TkLabel.new(frame, 'textvariable'=>$menu8xstatus, 'relief'=>'sunken',
'bd'=>1, 'font'=>['Helvetica', '10'], 'anchor'=>'w')\
.pack('side'=>'left', 'padx'=>2, 'expand'=>'yes', 'fill'=>'both')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>2)
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menu8x_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
diff --git a/ext/tk/sample/demos-jp/menubu.rb b/ext/tk/sample/demos-jp/menubu.rb
index 90dc367305..aa90a3087f 100644
--- a/ext/tk/sample/demos-jp/menubu.rb
+++ b/ext/tk/sample/demos-jp/menubu.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
require "tkcanvas"
def optionMenu(menubutton, varName, firstValue, *rest)
@@ -33,18 +32,16 @@ $menubu_demo = TkToplevel.new {|w|
positionWindow($menubu_demo)
-base_frame = TkFrame.new($menubu_demo).pack(:fill=>:both, :expand=>true)
-
# version check
if $tk_version.to_f < 8.0
# label À¸À®
-TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
+TkLabel.new($menubu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
text("¼Â¹Ô¤·¤è¤¦¤È¤·¤¿¥¹¥¯¥ê¥×¥È¤Ï Tk8.0 °Ê¾å¤ÇÍøÍѤǤ­¤ëµ¡Ç½¤òÍøÍѤ·¤Æ¤¤¤ë¤¿¤á¡¢¤¢¤Ê¤¿¤Î Ruby#{VERSION}/Tk#{$tk_version}#{(Tk::JAPANIZED_TK)? 'jp': ''} ¤Ç¤ÏÀµ¾ï¤Ë¼Â¹Ô¤Ç¤­¤Þ¤»¤ó¡£¤è¤Ã¤Æ¥Ç¥â¤Î¼Â¹Ô¤òÃæ»ß¤·¤Þ¤·¤¿¡£¤¿¤À¤·¡¢²¼¤Î¥³¡¼¥É»²¾È¥Ü¥¿¥ó¤ò²¡¤¹¤³¤È¤Ç¡¢¼Â¹Ô¤¬Ãæ»ß¤µ¤ì¤¿¥¹¥¯¥ê¥×¥È¤Î¥½¡¼¥¹¤ò»²¾È¤¹¤ë¤³¤È¤Ï²Äǽ¤Ç¤¹¡£")
}.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menubu_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -63,7 +60,7 @@ TkFrame.new(base_frame) {|frame|
else ; # Tk8.x
-body = TkFrame.new(base_frame)
+body = TkFrame.new($menubu_demo)
body.pack('expand'=>'yes', 'fill'=>'both')
below = TkMenubutton.new(body) {
@@ -158,7 +155,7 @@ center = TkFrame.new(body) {
grid('row'=>1, 'column'=>1, 'sticky'=>'news')
}
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($menubu_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
diff --git a/ext/tk/sample/demos-jp/msgbox.rb b/ext/tk/sample/demos-jp/msgbox.rb
index 88380e08bd..983e6b6589 100644
--- a/ext/tk/sample/demos-jp/msgbox.rb
+++ b/ext/tk/sample/demos-jp/msgbox.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# message boxes widget demo (called by 'widget')
#
@@ -16,14 +15,12 @@ $msgbox_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($msgbox_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
- 'text'=>"¤Þ¤ºÉ½¼¨¤¹¤ë¥¢¥¤¥³¥ó¤È¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤Î¼ïÎà¤òÁª¤ó¤Ç²¼¤µ¤¤¡£¤½¤Î¸å¤Ë\"¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹\"¥Ü¥¿¥ó¤ò²¡¤¹¤È¡¢»ØÄꤷ¤¿¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£").pack('side'=>'top')
+TkLabel.new($msgbox_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
+ 'text'=>"ɽ¼¨¤¹¤ë¥¢¥¤¥³¥ó¤È¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤Î¼ïÎà¤òÁª¤ó¤Ç²¼¤µ¤¤¡£¤½¤·¤Æ \"¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹\" ¥Ü¥¿¥ó¤ò²¡¤¹¤È¡¢»ØÄꤷ¤¿¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£").pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($msgbox_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -46,8 +43,8 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame À¸À®
-$msgbox_leftframe = TkFrame.new(base_frame)
-$msgbox_rightframe = TkFrame.new(base_frame)
+$msgbox_leftframe = TkFrame.new($msgbox_demo)
+$msgbox_rightframe = TkFrame.new($msgbox_demo)
$msgbox_leftframe .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
'pady'=>'.5c', 'padx'=>'.5c')
$msgbox_rightframe.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
@@ -81,7 +78,7 @@ $msgboxType = TkVariable.new('ok')
def showMessageBox(w)
button = Tk.messageBox('icon'=>$msgboxIcon.value, 'type'=>$msgboxType.value,
'title'=>'Message', 'parent'=>w,
- 'message'=>"¤³¤ì¤Ï\"#{$msgboxType.value}\"¤È¤¤¤¦¼ïÎà¤Î¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤Ç¡¢\"#{$msgboxIcon.value}\"¤Î¥¢¥¤¥³¥ó¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£")
+ 'message'=>"¤³¤ì¤Ï \"#{$msgboxType.value}\" ¤È¤¤¤¦¼ïÎà¤Î¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤Ç¡¢\"#{$msgboxIcon.value}\" ¤Î¥¢¥¤¥³¥ó¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£")
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'parent'=>w,
'message'=>"¤¢¤Ê¤¿¤Ï \"#{button}\" ¤ò²¡¤·¤Þ¤·¤¿¤Í¡£")
diff --git a/ext/tk/sample/demos-jp/msgbox2.rb b/ext/tk/sample/demos-jp/msgbox2.rb
deleted file mode 100644
index d61f25129a..0000000000
--- a/ext/tk/sample/demos-jp/msgbox2.rb
+++ /dev/null
@@ -1,90 +0,0 @@
-# -*- coding: euc-jp -*-
-#
-# message boxes widget demo (called by 'widget')
-#
-
-# toplevel widget ¤¬Â¸ºß¤¹¤ì¤Ðºï½ü¤¹¤ë
-if defined?($msgbox2_demo) && $msgbox2_demo
- $msgbox2_demo.destroy
- $msgbox2_demo = nil
-end
-
-# demo ÍѤΠtoplevel widget ¤òÀ¸À®
-$msgbox2_demo = TkToplevel.new {|w|
- title("Message Box Demonstration")
- iconname("messagebox")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($msgbox2_demo).pack(:fill=>:both, :expand=>true)
-
-# label À¸À®
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
- 'text'=>"¤Þ¤ºÉ½¼¨¤¹¤ë¥¢¥¤¥³¥ó¤È¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤Î¼ïÎà¤òÁª¤ó¤Ç²¼¤µ¤¤¡£¤½¤Î¸å¤Ë\"¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹\"¥Ü¥¿¥ó¤ò²¡¤¹¤È¡¢»ØÄꤵ¤ì¤¿·Á¼°¤Ç¡¢¥á¥Ã¥»¡¼¥¸¤È¾ÜºÙ¥Æ¥­¥¹¥È¤È¤ò»ý¤Ã¤¿¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£").pack('side'=>'top')
-
-# frame À¸À®
-TkFrame.new(base_frame) {|frame|
- TkButton.new(frame) {
- #text 'λ²ò'
- text 'ÊĤ¸¤ë'
- command proc{
- tmppath = $msgbox2_demo
- $msgbox2_demo = nil
- tmppath.destroy
- }
- }.pack('side'=>'left', 'expand'=>'yes')
-
- TkButton.new(frame) {
- text '¥³¡¼¥É»²¾È'
- command proc{showCode 'msgbox2'}
- }.pack('side'=>'left', 'expand'=>'yes')
-
- TkButton.new(frame) {
- text '¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹'
- command proc{showMessageBox $msgbox2_demo}
- }.pack('side'=>'left', 'expand'=>'yes')
-}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
-
-# frame À¸À®
-$msgbox_leftframe = TkFrame.new(base_frame)
-$msgbox_rightframe = TkFrame.new(base_frame)
-$msgbox_leftframe .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
- 'pady'=>'.5c', 'padx'=>'.5c')
-$msgbox_rightframe.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
- 'pady'=>'.5c', 'padx'=>'.5c')
-
-TkLabel.new($msgbox_leftframe, 'text'=>'¥¢¥¤¥³¥ó').pack('side'=>'top')
-TkFrame.new($msgbox_leftframe, 'relief'=>'ridge', 'bd'=>1, 'height'=>2)\
-.pack('side'=>'top', 'fill'=>'x', 'expand'=>'no')
-
-$msgboxIcon = TkVariable.new('info')
-['error', 'info', 'question', 'warning'].each {|icon|
- TkRadioButton.new($msgbox_leftframe, 'text'=>icon, 'variable'=>$msgboxIcon,
- 'relief'=>'flat', 'value'=>icon, 'width'=>16,
- 'anchor'=>'w').pack('side'=>'top', 'pady'=>2,
- 'anchor'=>'w', 'fill'=>'x')
-}
-
-TkLabel.new($msgbox_rightframe, 'text'=>'¼ïÎà').pack('side'=>'top')
-TkFrame.new($msgbox_rightframe, 'relief'=>'ridge', 'bd'=>1, 'height'=>2)\
-.pack('side'=>'top', 'fill'=>'x', 'expand'=>'no')
-
-$msgboxType = TkVariable.new('ok')
-['abortretryignore', 'ok', 'okcancel',
- 'retrycancel', 'yesno', 'yesnocancel'].each {|type|
- TkRadioButton.new($msgbox_rightframe, 'text'=>type, 'variable'=>$msgboxType,
- 'relief'=>'flat', 'value'=>type, 'width'=>16,
- 'anchor'=>'w').pack('side'=>'top', 'pady'=>2,
- 'anchor'=>'w', 'fill'=>'x')
-}
-
-def showMessageBox(w)
- button = Tk.messageBox('icon'=>$msgboxIcon.value, 'type'=>$msgboxType.value,
- 'title'=>'Message', 'parent'=>w,
- 'message'=>"\"#{$msgboxType.value}\"¥¿¥¤¥×¤Î¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹",
- 'detail'=>"¤³¤ì¤Ï\"#{$msgboxType.value}\"¤È¤¤¤¦¼ïÎà¤Î¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤Ç¡¢\"#{$msgboxIcon.value}\"¤Î¥¢¥¤¥³¥ó¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£²¼¤Î¥Ü¥¿¥ó¤Î¤¤¤º¤ì¤«¤òÁªÂò¤·¤Æ¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£")
-
- Tk.messageBox('icon'=>'info', 'type'=>'ok', 'parent'=>w,
- 'message'=>"¤¢¤Ê¤¿¤Ï \"#{button}\" ¤ò²¡¤·¤Þ¤·¤¿¤Í¡£")
-end
-
diff --git a/ext/tk/sample/demos-jp/paned1.rb b/ext/tk/sample/demos-jp/paned1.rb
index f994e83ff1..8d16d03c08 100644
--- a/ext/tk/sample/demos-jp/paned1.rb
+++ b/ext/tk/sample/demos-jp/paned1.rb
@@ -1,5 +1,3 @@
-# -*- coding: euc-jp -*-
-#
# paned1.rb
#
# This demonstration script creates a toplevel window containing
@@ -18,9 +16,7 @@ $paned1_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($paned1_demo).pack(:fill=>:both, :expand=>true)
-
-TkLabel.new(base_frame,
+TkLabel.new($paned1_demo,
:font=>$font, :wraplength=>'4i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
²¼¤Î¿§ÉÕ¤±¤µ¤ì¤¿Æó¤Ä¤Î¥¦¥£¥ó¥É¥¦¤Î´Ö¤Î»ÅÀÚ¤êÏȤϡ¢°ì¤Ä¤ÎÎΰè¤ò¤½¤ì¤¾¤ì¤Î¥¦¥£¥ó¥É¥¦¤Î¤¿¤á¤Ëʬ³ä¤¹¤ë¤¿¤á¤Î¤â¤Î¤Ç¤¹¡£º¸¥Ü¥¿¥ó¤Ç»ÅÀÚ¤ê¤òÁàºî¤¹¤ë¤È¡¢Ê¬³ä¥µ¥¤¥ºÊѹ¹¤ÎÁàºîÅÓÃæ¤Ç¤ÏºÆÉ½¼¨¤Ï¤Ê¤µ¤ì¤º¡¢³ÎÄꤵ¤»¤¿¤È¤­¤Ëɽ¼¨¤¬¹¹¿·¤µ¤ì¤Þ¤¹¡£¥Þ¥¦¥¹¤Ë¤è¤ë»ÅÀÚ¤ê¤ÎÁàºî¤ËÄɿ路¤Æ¥µ¥¤¥º¤òÊѹ¹¤·¤¿É½¼¨¤¬¤Ê¤ï¤ì¤ë¤è¤¦¤Ë¤·¤¿¤¤¾ì¹ç¤Ï¡¢¥Þ¥¦¥¹¤ÎÃæ±û¥Ü¥¿¥ó¤ò»È¤Ã¤Æ¤¯¤À¤µ¤¤¡£
@@ -31,7 +27,7 @@ TkLabel.new(base_frame,
EOL
# The bottom buttons
-TkFrame.new(base_frame){|f|
+TkFrame.new($paned1_demo){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{
@@ -44,9 +40,9 @@ TkFrame.new(base_frame){|f|
}).pack(:side=>:left, :expand=>true)
}
-TkPanedwindow.new(base_frame, :orient=>:horizontal){|f|
- add(Tk::Label.new(f, :text=>"This is the\nleft side", :bg=>'yellow'),
- Tk::Label.new(f, :text=>"This is the\nright side", :bg=>'cyan'))
-
+TkPanedwindow.new($paned1_demo){|f|
pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m')
+
+ add(TkLabel.new(f, :text=>"This is the\nleft side", :bg=>'yellow'),
+ TkLabel.new(f, :text=>"This is the\nright side", :bg=>'cyan'))
}
diff --git a/ext/tk/sample/demos-jp/paned2.rb b/ext/tk/sample/demos-jp/paned2.rb
index cdc8253402..1e82eddda4 100644
--- a/ext/tk/sample/demos-jp/paned2.rb
+++ b/ext/tk/sample/demos-jp/paned2.rb
@@ -1,5 +1,3 @@
-# -*- coding: euc-jp -*-
-#
# paned2.rb --
#
# This demonstration script creates a toplevel window containing
@@ -18,9 +16,7 @@ $paned2_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($paned2_demo).pack(:fill=>:both, :expand=>true)
-
-TkLabel.new(base_frame,
+TkLabel.new($paned2_demo,
:font=>$font, :wraplength=>'4i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
²¼¤Î¥¹¥¯¥í¡¼¥ë¥Ð¡¼ÉÕ¤­¤Î¥¦¥£¥¸¥§¥Ã¥È¤¬ÃÖ¤«¤ì¤¿Æó¤Ä¤Î¥¦¥£¥ó¥É¥¦¤Î´Ö¤Î»ÅÀÚ¤êÏȤϡ¢°ì¤Ä¤ÎÎΰè¤ò¤½¤ì¤¾¤ì¤Î¥¦¥£¥ó¥É¥¦¤Î¤¿¤á¤Ëʬ³ä¤¹¤ë¤¿¤á¤Î¤â¤Î¤Ç¤¹¡£º¸¥Ü¥¿¥ó¤Ç»ÅÀÚ¤ê¤òÁàºî¤¹¤ë¤È¡¢Ê¬³ä¥µ¥¤¥ºÊѹ¹¤ÎÁàºîÅÓÃæ¤Ç¤ÏºÆÉ½¼¨¤Ï¤Ê¤µ¤ì¤º¡¢³ÎÄꤵ¤»¤¿¤È¤­¤Ëɽ¼¨¤¬¹¹¿·¤µ¤ì¤Þ¤¹¡£¥Þ¥¦¥¹¤Ë¤è¤ë»ÅÀÚ¤ê¤ÎÁàºî¤ËÄɿ路¤Æ¥µ¥¤¥º¤òÊѹ¹¤·¤¿É½¼¨¤¬¤Ê¤ï¤ì¤ë¤è¤¦¤Ë¤·¤¿¤¤¾ì¹ç¤Ï¡¢¥Þ¥¦¥¹¤ÎÃæ±û¥Ü¥¿¥ó¤ò»È¤Ã¤Æ¤¯¤À¤µ¤¤¡£
@@ -31,7 +27,7 @@ TkLabel.new(base_frame,
EOL
# The bottom buttons
-TkFrame.new(base_frame){|f|
+TkFrame.new($paned2_demo){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{
@@ -68,7 +64,7 @@ paneList.value = [ # ruby's array --> tcl's list
]
# Create the pane itself
-TkPanedwindow.new(base_frame, :orient=>:vertical){|f|
+TkPanedwindow.new($paned2_demo, :orient=>:vertical){|f|
pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m')
add(TkFrame.new(f){|paned2_top|
diff --git a/ext/tk/sample/demos-jp/pendulum.rb b/ext/tk/sample/demos-jp/pendulum.rb
index b115f5be2c..d703c74d5a 100644
--- a/ext/tk/sample/demos-jp/pendulum.rb
+++ b/ext/tk/sample/demos-jp/pendulum.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# This demonstration illustrates how Tcl/Tk can be used to construct
# simulations of physical systems.
@@ -19,10 +18,8 @@ $pendulum_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($pendulum_demo).pack(:fill=>:both, :expand=>true)
-
# create label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($pendulum_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -31,7 +28,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# create frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($pendulum_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -53,11 +50,9 @@ TkFrame.new(base_frame) {|frame|
class PendulumAnimationDemo
def initialize(frame)
# Create some structural widgets
- @pane = TkPanedWindow.new(frame, :orient=>:horizontal).pack(:fill=>:both, :expand=>true)
-# @pane.add(@lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation'))
-# @pane.add(@lf2 = TkLabelFrame.new(@pane, :text=>'Phase Space'))
- @lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation')
- @lf2 = TkLabelFrame.new(@pane, :text=>'Phase Space')
+ pane = TkPanedWindow.new(frame).pack(:fill=>:both, :expand=>true)
+ pane.add(@lf1 = TkLabelFrame.new(pane, :text=>'Pendulum Simulation'))
+ pane.add(@lf2 = TkLabelFrame.new(pane, :text=>'Phase Space'))
# Create the canvas containing the graphical representation of the
# simulated system.
@@ -105,24 +100,23 @@ class PendulumAnimationDemo
@dTheta = 0.0
@length = 150
+ # init display
+ showPendulum
+
# animation loop
@timer = TkTimer.new(15){ repeat }
# binding
@c.bindtags_unshift(btag = TkBindTag.new)
btag.bind('Destroy'){ @timer.stop }
- btag.bind('1', proc{|x, y| @timer.stop; showPendulum(x.to_i, y.to_i)},
- '%x %y')
- btag.bind('B1-Motion', proc{|x, y| showPendulum(x.to_i, y.to_i)}, '%x %y')
+ btag.bind('1', proc{|x, y| @timer.stop; showPendulum(x, y)}, '%x %y')
+ btag.bind('B1-Motion', proc{|x, y| showPendulum(x, y)}, '%x %y')
btag.bind('ButtonRelease-1',
- proc{|x, y| showPendulum(x.to_i, y.to_i); @timer.start },
- '%x %y')
+ proc{|x, y| showPendulum(x, y); @timer.start }, '%x %y')
- btag.bind('Configure', proc{|w| @plate.coords(0, 25, w.to_i, 25)}, '%w')
+ btag.bind('Configure', proc{|w| @plate.coords(0, 25, w, 25)}, '%w')
@k.bind('Configure', proc{|h, w|
- h = h.to_i
- w = w.to_i
@psh = h/2;
@psw = w/2
@x_axis.coords(2, @psh, w-2, @psh)
@@ -131,14 +125,6 @@ class PendulumAnimationDemo
@label_dtheta.coords(w-6, @psh+4)
}, '%h %w')
- # add
- Tk.update
- @pane.add(@lf1)
- @pane.add(@lf2)
-
- # init display
- showPendulum
-
# animation start
@timer.start(500)
end
@@ -169,10 +155,6 @@ class PendulumAnimationDemo
# rate at which the angle is changing (the first derivative with
# respect to time.)
def showPhase
- unless @psw && @psh
- @psw = @k.width/2
- @psh = @k.height/2
- end
@points << @theta + @psw << -20*@dTheta + @psh
if @points.length > 100
@points = @points[-100..-1]
@@ -239,4 +221,4 @@ class PendulumAnimationDemo
end
# Start the animation processing
-PendulumAnimationDemo.new(base_frame)
+PendulumAnimationDemo.new($pendulum_demo)
diff --git a/ext/tk/sample/demos-jp/plot.rb b/ext/tk/sample/demos-jp/plot.rb
index 9ff71904cd..902b144f72 100644
--- a/ext/tk/sample/demos-jp/plot.rb
+++ b/ext/tk/sample/demos-jp/plot.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# 2-D plot widget demo (called by 'widget')
#
@@ -16,16 +15,14 @@ $plot_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($plot_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
+TkLabel.new($plot_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
'text'=>"¤³¤Î¥¦¥£¥ó¥É¥¦¤Ï´Êñ¤Ê2¼¡¸µ¤Î¥×¥í¥Ã¥È¤ò´Þ¤ó¤À¥­¥ã¥ó¥Ð¥¹ widget¤Ç¤¹¡£É½¼¨¤µ¤ì¤¿ÅÀ¤ò¥Þ¥¦¥¹¥Ü¥¿¥ó1¤Ç¥É¥é¥Ã¥°¤·¤Æ¥Ç¡¼¥¿¤ò¤¤¤¸¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£"){
pack('side'=>'top')
}
# frame À¸À®
-$plot_buttons = TkFrame.new(base_frame) {|frame|
+$plot_buttons = TkFrame.new($plot_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -44,14 +41,10 @@ $plot_buttons = TkFrame.new(base_frame) {|frame|
$plot_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# font ÀßÄê
- if $tk_version =~ /^4.*/
- plotFont = '-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
- else
- font = 'Helvetica 18'
- end
+plotFont = '-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
# canvas ÀßÄê
-$plot_canvas = TkCanvas.new(base_frame,'relief'=>'raised','width'=>450,'height'=>300)
+$plot_canvas = TkCanvas.new($plot_demo,'relief'=>'raised','width'=>450,'height'=>300)
$plot_canvas.pack('side'=>'top', 'fill'=>'x')
# plot À¸À®
diff --git a/ext/tk/sample/demos-jp/puzzle.rb b/ext/tk/sample/demos-jp/puzzle.rb
index 2febc2c55a..ad69775aab 100644
--- a/ext/tk/sample/demos-jp/puzzle.rb
+++ b/ext/tk/sample/demos-jp/puzzle.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# widet demo 'puzzle' (called by 'widget')
#
@@ -16,10 +15,8 @@ $puzzle_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($puzzle_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($puzzle_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -28,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($puzzle_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -53,27 +50,18 @@ TkFrame.new(base_frame) {|frame|
#
begin
if Tk.windowingsystem() == 'aqua'
- frameWidth = 168
- frameHeight = 168
- elsif Tk.default_widget_set == :Ttk
- frameWidth = 148
- frameHeight = 124
+ frameSize = 160
else
- frameWidth = 120
- frameHeight = 120
+ frameSize = 120
end
rescue
- frameWidth = 120
- frameHeight = 120
+ frameSize = 120
end
-
-# depend_on_button_width = true
-depend_on_button_width = false
-s = TkScrollbar.new(base_frame)
-base = TkFrame.new(base_frame) {
- width frameWidth
- height frameHeight
+s = TkScrollbar.new($puzzle_demo)
+base = TkFrame.new($puzzle_demo) {
+ width frameSize
+ height frameSize
borderwidth 2
relief 'sunken'
bg s['troughcolor']
@@ -100,9 +88,6 @@ order = [3,1,6,2,5,7,15,13,4,11,8,9,14,10,12]
text num
highlightthickness 0
command def_puzzleswitch_proc(w, num)
- if depend_on_button_width && (w.winfo_reqwidth * 4 > base.width)
- base.width = w.winfo_reqwidth * 4
- end
}.place('relx'=>$xpos[num], 'rely'=>$ypos[num],
'relwidth'=>0.25, 'relheight'=>0.25)
}
diff --git a/ext/tk/sample/demos-jp/radio.rb b/ext/tk/sample/demos-jp/radio.rb
index a61ad46d9b..5858b4222a 100644
--- a/ext/tk/sample/demos-jp/radio.rb
+++ b/ext/tk/sample/demos-jp/radio.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# radiobutton widget demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $radio_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($radio_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($radio_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -32,7 +29,7 @@ size = TkVariable.new
color = TkVariable.new
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($radio_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -52,14 +49,14 @@ TkFrame.new(base_frame) {|frame|
TkButton.new(frame) {
text 'ÊÑ¿ô»²¾È'
command proc{
- showVars(base_frame, ['size', size], ['color', color])
+ showVars($radio_demo, ['size', size], ['color', color])
}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame À¸À®
-f_left = TkFrame.new(base_frame)
-f_right = TkFrame.new(base_frame)
+f_left = TkFrame.new($radio_demo)
+f_right = TkFrame.new($radio_demo)
f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
diff --git a/ext/tk/sample/demos-jp/radio2.rb b/ext/tk/sample/demos-jp/radio2.rb
index cf53e3e485..5ac877d99a 100644
--- a/ext/tk/sample/demos-jp/radio2.rb
+++ b/ext/tk/sample/demos-jp/radio2.rb
@@ -1,5 +1,3 @@
-# -*- coding: euc-jp -*-
-#
# radio2.rb
#
# This demonstration script creates a toplevel window containing
@@ -21,10 +19,8 @@ $radio2_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($radio2_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($radio2_demo) {
font $font
wraplength '5i'
justify 'left'
@@ -38,7 +34,7 @@ color = TkVariable.new
align = TkVariable.new
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($radio2_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -58,18 +54,18 @@ TkFrame.new(base_frame) {|frame|
TkButton.new(frame) {
text 'ÊÑ¿ô»²¾È'
command proc{
- showVars(base_frame,
+ showVars($radio2_demo,
['size', size], ['color', color], ['compound', align])
}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
-f_left = TkLabelFrame.new(base_frame, 'text'=>'ʸ»ú¥µ¥¤¥º',
+f_left = TkLabelFrame.new($radio2_demo, 'text'=>'ʸ»ú¥µ¥¤¥º',
'pady'=>2, 'padx'=>2)
-f_mid = TkLabelFrame.new(base_frame, 'text'=>'¿§',
+f_mid = TkLabelFrame.new($radio2_demo, 'text'=>'¿§',
'pady'=>2, 'padx'=>2)
-f_right = TkLabelFrame.new(base_frame, 'text'=>'¥Ó¥Ã¥È¥Þ¥Ã¥×ÇÛÃÖ',
+f_right = TkLabelFrame.new($radio2_demo, 'text'=>'¥Ó¥Ã¥È¥Þ¥Ã¥×ÇÛÃÖ',
'pady'=>2, 'padx'=>2)
f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
f_mid.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
@@ -95,8 +91,7 @@ f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
}.pack('side'=>'top', 'pady'=>2, 'fill'=>'x')
}
-# label = TkLabel.new(f_right, 'text'=>'¥é¥Ù¥ë', 'bitmap'=>'questhead',
-label = Tk::Label.new(f_right, 'text'=>'¥é¥Ù¥ë', 'bitmap'=>'questhead',
+label = TkLabel.new(f_right, 'text'=>'¥é¥Ù¥ë', 'bitmap'=>'questhead',
'compound'=>'left')
label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top')
label.height(TkWinfo.reqheight(label))
diff --git a/ext/tk/sample/demos-jp/radio3.rb b/ext/tk/sample/demos-jp/radio3.rb
index 4bbc1b31f5..6e9a0f750b 100644
--- a/ext/tk/sample/demos-jp/radio3.rb
+++ b/ext/tk/sample/demos-jp/radio3.rb
@@ -1,5 +1,3 @@
-# -*- coding: euc-jp -*-
-#
# radio3.rb
#
# This demonstration script creates a toplevel window containing
@@ -21,10 +19,8 @@ $radio3_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($radio3_demo).pack(:fill=>:both, :expand=>true)
-
# label
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($radio3_demo) {
font $font
wraplength '5i'
justify 'left'
@@ -38,14 +34,14 @@ color = TkVariable.new
align = TkVariable.new
# frame
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($radio3_demo) {|frame|
TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2),
:columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
TkGrid('x',
TkButton.new(frame, :text=>'ÊÑ¿ô»²¾È',
:image=>$image['view'], :compound=>:left,
:command=>proc{
- showVars(base_frame, ['size', size],
+ showVars($radio3_demo, ['size', size],
['color', color], ['compound', align])
}),
TkButton.new(frame, :text=>'¥³¡¼¥É»²¾È',
@@ -65,17 +61,17 @@ TkFrame.new(base_frame) {|frame|
}
# frame
-f_left = TkLabelFrame.new(base_frame, 'text'=>'ʸ»ú¥µ¥¤¥º',
+f_left = TkLabelFrame.new($radio3_demo, 'text'=>'ʸ»ú¥µ¥¤¥º',
'pady'=>2, 'padx'=>2)
-f_mid = TkLabelFrame.new(base_frame, 'text'=>'¿§',
+f_mid = TkLabelFrame.new($radio3_demo, 'text'=>'¿§',
'pady'=>2, 'padx'=>2)
-f_right = TkLabelFrame.new(base_frame, 'text'=>'¥Ó¥Ã¥È¥Þ¥Ã¥×ÇÛÃÖ',
+f_right = TkLabelFrame.new($radio3_demo, 'text'=>'¥Ó¥Ã¥È¥Þ¥Ã¥×ÇÛÃÖ',
'pady'=>2, 'padx'=>2)
f_left .grid('column'=>0, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c', 'rowspan'=>2)
f_mid .grid('column'=>1, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c', 'rowspan'=>2)
f_right.grid('column'=>2, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c')
-TkButton.new(base_frame, 'text'=>'¥È¥é¥¤¥¹¥Æ¡¼¥È',
+TkButton.new($radio3_demo, 'text'=>'¥È¥é¥¤¥¹¥Æ¡¼¥È',
'command'=>proc{size.value = 'multi'; color.value = 'multi'}){
grid('column'=>2, 'row'=>2, 'pady'=>'.5c', 'padx'=>'.5c')
}
@@ -103,8 +99,7 @@ TkButton.new(base_frame, 'text'=>'¥È¥é¥¤¥¹¥Æ¡¼¥È',
}.pack('side'=>'top', 'pady'=>2, 'fill'=>'x')
}
-# label = TkLabel.new(f_right, 'text'=>'¥é¥Ù¥ë', 'bitmap'=>'questhead',
-label = Tk::Label.new(f_right, 'text'=>'¥é¥Ù¥ë', 'bitmap'=>'questhead',
+label = TkLabel.new(f_right, 'text'=>'¥é¥Ù¥ë', 'bitmap'=>'questhead',
'compound'=>'left')
label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top')
label.height(TkWinfo.reqheight(label))
diff --git a/ext/tk/sample/demos-jp/rolodex-j b/ext/tk/sample/demos-jp/rolodex-j
index 6c3ea7a484..dcc18cfa51 100644
--- a/ext/tk/sample/demos-jp/rolodex-j
+++ b/ext/tk/sample/demos-jp/rolodex-j
@@ -1,5 +1,4 @@
#!/usr/bin/env ruby
-# -*- coding: euc-jp -*-
#
# rolodex --
# ¤³¤Î¥¹¥¯¥ê¥×¥È¤Ï Tom LaStrange ¤Î rolodex ¤Î°ìÉô¤Ç¤¹¡£
diff --git a/ext/tk/sample/demos-jp/ruler.rb b/ext/tk/sample/demos-jp/ruler.rb
index d6bc9e76d1..94b4c921d3 100644
--- a/ext/tk/sample/demos-jp/ruler.rb
+++ b/ext/tk/sample/demos-jp/ruler.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# ruler widget demo (called by 'widget')
#
@@ -29,16 +28,14 @@ $ruler_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($ruler_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
+TkLabel.new($ruler_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
'text'=>"¤³¤Î¥­¥ã¥ó¥Ð¥¹widget¤Ï¥ë¡¼¥é¡¼¤ÎÌÏ·¿¤Ç¤¹¡£¥ë¡¼¥é¡¼¤Î±¦¤Ë¤¢¤ë¤Î¤Ï¥¿¥Ö¥¹¥È¥Ã¥×¤Î°æ¸Í¤Ç¡¢¤³¤³¤«¤é°ú¤ÃÄ¥¤Ã¤Æ¤¯¤ë¤³¤È¤Ë¤è¤Ã¤Æ¥¿¥Ö¥¹¥È¥Ã¥×¤òºî¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤Þ¤¿¡¢¤¹¤Ç¤Ë¤¢¤ë¥¿¥Ö¥¹¥È¥Ã¥×¤òư¤«¤¹¤³¤È¤â¤Ç¤­¤Þ¤¹¡£¥¿¥Ö¥¹¥È¥Ã¥×¤ò¾åÊý¤Þ¤¿¤Ï²¼Êý¤Ë¤«¤¹¤ì¤ÆÉ½¼¨¤µ¤ì¤ë¤Þ¤Ç¥É¥é¥Ã¥°¤¹¤ë¤È¡¢¥Þ¥¦¥¹¥Ü¥¿¥ó¤òÎ¥¤·¤¿»þ¤Ë¤½¤Î¥¿¥Ö¥¹¥È¥Ã¥×¤Ï¾Ã¤¨¤Þ¤¹¡£"){
pack('side'=>'top')
}
# frame À¸À®
-$ruler_buttons = TkFrame.new(base_frame) {|frame|
+$ruler_buttons = TkFrame.new($ruler_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -57,7 +54,7 @@ $ruler_buttons = TkFrame.new(base_frame) {|frame|
$ruler_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# canvas ÀßÄê
-$ruler_canvas = TkCanvas.new(base_frame, 'width'=>'14.8c', 'height'=>'2.5c')
+$ruler_canvas = TkCanvas.new($ruler_demo, 'width'=>'14.8c', 'height'=>'2.5c')
$ruler_canvas.pack('side'=>'top', 'fill'=>'x')
# ÃÍÀßÄê
diff --git a/ext/tk/sample/demos-jp/sayings.rb b/ext/tk/sample/demos-jp/sayings.rb
index aa24b3a2ad..ce195a0e53 100644
--- a/ext/tk/sample/demos-jp/sayings.rb
+++ b/ext/tk/sample/demos-jp/sayings.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# listbox widget demo 'sayings' (called by 'widget')
#
@@ -16,10 +15,8 @@ $sayings_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($sayings_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($sayings_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -28,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($sayings_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -48,7 +45,7 @@ TkFrame.new(base_frame) {|frame|
# frame À¸À®
sayings_lbox = nil
-TkFrame.new(base_frame, 'borderwidth'=>10) {|w|
+TkFrame.new($sayings_demo, 'borderwidth'=>10) {|w|
sv = TkScrollbar.new(w)
sh = TkScrollbar.new(w, 'orient'=>'horizontal')
sayings_lbox = TkListbox.new(w) {
diff --git a/ext/tk/sample/demos-jp/search.rb b/ext/tk/sample/demos-jp/search.rb
index 9838ff5d19..f5268f987f 100644
--- a/ext/tk/sample/demos-jp/search.rb
+++ b/ext/tk/sample/demos-jp/search.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# Text Search widget demo (called by 'widget')
#
@@ -75,10 +74,8 @@ $search_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($search_demo).pack(:fill=>:both, :expand=>true)
-
# frame À¸À®
-$search_buttons = TkFrame.new(base_frame) {|frame|
+$search_buttons = TkFrame.new($search_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -97,7 +94,7 @@ $search_buttons = TkFrame.new(base_frame) {|frame|
$search_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame À¸À®
-TkFrame.new(base_frame) {|f|
+TkFrame.new($search_demo) {|f|
TkLabel.new(f, 'text'=>'¥Õ¥¡¥¤¥ë̾:',
'width'=>13, 'anchor'=>'w').pack('side'=>'left')
$search_fileName = TkVariable.new
@@ -114,7 +111,7 @@ TkFrame.new(base_frame) {|f|
.pack('side'=>'left', 'pady'=>5, 'padx'=>10)
}.pack('side'=>'top', 'fill'=>'x')
-TkFrame.new(base_frame) {|f|
+TkFrame.new($search_demo) {|f|
TkLabel.new(f, 'text'=>'¸¡º÷ʸ»úÎó:',
'width'=>13, 'anchor'=>'w').pack('side'=>'left')
$search_searchString = TkVariable.new
@@ -132,9 +129,9 @@ TkFrame.new(base_frame) {|f|
}
}.pack('side'=>'top', 'fill'=>'x')
-$search_text = TkText.new(base_frame, 'setgrid'=>true) {|t|
+$search_text = TkText.new($search_demo, 'setgrid'=>true) {|t|
$search_Tag = TkTextTag.new(t)
- TkScrollbar.new(base_frame, 'command'=>proc{|*args| t.yview(*args)}) {|sc|
+ TkScrollbar.new($search_demo, 'command'=>proc{|*args| t.yview(*args)}) {|sc|
t.yscrollcommand(proc{|first,last| sc.set first,last})
pack('side'=>'right', 'fill'=>'y')
}
@@ -171,14 +168,9 @@ $search_text.insert('1.0', "\
¥¨¥ó¥È¥ê¤Ëʸ»úÎó¤òÆþÎϤ·¡¢<¥ê¥¿¡¼¥ó> ¤ò²¡¤¹¤«¡Öȿž¡×¥Ü¥¿¥ó¤ò²¡¤·¤Æ¤¯ \
¤À¤µ¤¤¡£¤¹¤ë¤È¥Õ¥¡¥¤¥ëÃæ¤Î¡¢¸¡º÷ʸ»úÎó¤È°ìÃפ¹¤ëÉôʬ¤ËÁ´¤Æ \"search_Tag\" \
¤È¤¤¤¦¥¿¥°¤¬¤Ä¤±¤é¤ì¡¢¥¿¥°¤Îɽ¼¨Â°À­¤È¤·¤Æ¤½¤Îʸ»úÎó¤¬ÅÀÌǤ¹¤ë¤è¤¦¤Ë \
-ÀßÄꤵ¤ì¤Þ¤¹¡£\n")
-$search_text.insert('end', "\
-¥Õ¥¡¥¤¥ëÆÉ¤ß¹þ¤ß¤Î¥«¥ì¥ó¥È¥Ç¥£¥ì¥¯¥È¥ê¤Ï \"#{Dir.pwd}\" ¤Ç¤¹¡£\
-")
+ÀßÄꤵ¤ì¤Þ¤¹¡£")
$search_text.set_insert '0.0'
$search_fileName.value = ''
$search_searchString.value = ''
-$search_text.width = 60
-$search_text.height = 20
diff --git a/ext/tk/sample/demos-jp/spin.rb b/ext/tk/sample/demos-jp/spin.rb
index 8d4e33cda0..c7b8096723 100644
--- a/ext/tk/sample/demos-jp/spin.rb
+++ b/ext/tk/sample/demos-jp/spin.rb
@@ -1,5 +1,3 @@
-# -*- coding: euc-jp -*-
-#
# spin.rb --
#
# This demonstration script creates several spinbox widgets.
@@ -17,12 +15,10 @@ $spin_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($spin_demo).pack(:fill=>:both, :expand=>true)
-
-TkLabel.new(base_frame,
+TkLabel.new($spin_demo,
:font=>$font, :wraplength=>'5i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
-²¼¤Ë¤Ï£³¼ïÎà¤Î¥¹¥Ô¥ó¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
+²¼¤Ë¤Ï£³¼ïÎà¤Î¥¹¥Ô¥ó¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£\
¤½¤ì¤¾¤ì¡¢¥Þ¥¦¥¹¤ÇÁªÂò¤·¤ÆÊ¸»ú¤òÆþÎϤ¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
ÊÔ½¸Áàºî¤È¤·¤Æ¤Ï¡¢Emacs ·Á¼°¤Î¿¤¯¤Ë²Ã¤¨¤Æ¡¢°ìÈÌŪ¤Ê
Motif ·Á¼°¤Î¥­¡¼Áàºî¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¤¿¤È¤¨¤Ð¡¢
@@ -42,7 +38,7 @@ Backspace ¤È Control-h ¤È¤ÏÆþÎÏ¥«¡¼¥½¥ë¤Îº¸Â¦¤Îʸ»ú¤ò
¤òÁȤ߹ç¤ï¤»¤Æ»î¤¹¤è¤¦¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£
EOL
-TkFrame.new(base_frame){|f|
+TkFrame.new($spin_demo){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{
@@ -61,11 +57,11 @@ australianCities = [
]
[
- TkSpinbox.new(base_frame, :from=>1, :to=>10, :width=>10, :validate=>:key,
+ TkSpinbox.new($spin_demo, :from=>1, :to=>10, :width=>10, :validate=>:key,
:validatecommand=>[
proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P'
]),
- TkSpinbox.new(base_frame, :from=>0, :to=>3, :increment=>0.5,
+ TkSpinbox.new($spin_demo, :from=>0, :to=>3, :increment=>0.5,
:format=>'%05.2f', :width=>10),
- TkSpinbox.new(base_frame, :values=>australianCities, :width=>10)
+ TkSpinbox.new($spin_demo, :values=>australianCities, :width=>10)
].each{|sbox| sbox.pack(:side=>:top, :pady=>5, :padx=>10)}
diff --git a/ext/tk/sample/demos-jp/states.rb b/ext/tk/sample/demos-jp/states.rb
index 5e242b7c38..dfae821261 100644
--- a/ext/tk/sample/demos-jp/states.rb
+++ b/ext/tk/sample/demos-jp/states.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# listbox widget demo 'states' (called by 'widget')
#
@@ -16,10 +15,8 @@ $states_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($states_demo).pack(:fill=>:both, :expand=>true)
-
# label À¸À®
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($states_demo) {
font $font
wraplength '4i'
justify 'left'
@@ -28,7 +25,7 @@ msg = TkLabel.new(base_frame) {
msg.pack('side'=>'top')
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($states_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -48,7 +45,7 @@ TkFrame.new(base_frame) {|frame|
# frame À¸À®
states_lbox = nil
-TkFrame.new(base_frame, 'borderwidth'=>'.5c') {|w|
+TkFrame.new($states_demo, 'borderwidth'=>'.5c') {|w|
s = TkScrollbar.new(w)
states_lbox = TkListbox.new(w) {
setgrid 1
diff --git a/ext/tk/sample/demos-jp/style.rb b/ext/tk/sample/demos-jp/style.rb
index 66b6de0251..59e406bc80 100644
--- a/ext/tk/sample/demos-jp/style.rb
+++ b/ext/tk/sample/demos-jp/style.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# text (display styles) widget demo (called by 'widget')
#
@@ -9,7 +8,6 @@ if defined?($style_demo) && $style_demo
$style_demo = nil
end
-
# demo ÍѤΠtoplevel widget ¤òÀ¸À®
$style_demo = TkToplevel.new {|w|
title("Text Demonstration - Display Styles")
@@ -17,10 +15,8 @@ $style_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($style_demo).pack(:fill=>:both, :expand=>true)
-
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($style_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -37,16 +33,14 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
-
# text À¸À®
-txt = TkText.new(base_frame){|t|
+TkText.new($style_demo){|t|
# À¸À®
setgrid 'true'
- #width 70
- #height 32
+ width 70
+ height 32
wrap 'word'
- font $font
- TkScrollbar.new(base_frame) {|s|
+ TkScrollbar.new($style_demo) {|s|
pack('side'=>'right', 'fill'=>'y')
command proc{|*args| t.yview(*args)}
t.yscrollcommand proc{|first,last| s.set first,last}
@@ -54,20 +48,11 @@ txt = TkText.new(base_frame){|t|
pack('expand'=>'yes', 'fill'=>'both')
# ¥Æ¥­¥¹¥È¥¿¥°ÀßÄê (¥Õ¥©¥ó¥È´ØÏ¢)
- family = 'Courier'
-
- if $tk_version =~ /^4.*/
- style_tag_bold = TkTextTag.new(t, 'font'=>'-*-Courier-Bold-O-Normal--*-120-*-*-*-*-*-*')
- style_tag_big = TkTextTag.new(t, 'font'=>'-*-Courier-Bold-R-Normal--*-140-*-*-*-*-*-*', 'kanjifont'=>$msg_kanji_font)
+ style_tag_bold = TkTextTag.new(t, 'font'=>'-*-Courier-Bold-O-Normal--*-120-*-*-*-*-*-*')
+ style_tag_big = TkTextTag.new(t, 'font'=>'-*-Courier-Bold-R-Normal--*-140-*-*-*-*-*-*', 'kanjifont'=>$msg_kanji_font)
style_tag_verybig = TkTextTag.new(t, 'font'=>'-*-Helvetica-Bold-R-Normal--*-240-*-*-*-*-*-*')
- # style_tag_small = TkTextTag.new(t, 'font'=>'-Adobe-Helvetica-Bold-R-Normal-*-100-*', 'kanjifont'=>$kanji_font)
+# style_tag_small = TkTextTag.new(t, 'font'=>'-Adobe-Helvetica-Bold-R-Normal-*-100-*', 'kanjifont'=>$kanji_font)
style_tag_small = TkTextTag.new(t, 'font'=>'-Adobe-Helvetica-Bold-R-Normal-*-100-*')
- else
- style_tag_bold = TkTextTag.new(t, 'font'=>[family, 12, :bold, :italic])
- style_tag_big = TkTextTag.new(t, 'font'=>[family, 14, :bold])
- style_tag_verybig = TkTextTag.new(t, 'font'=>['Helvetica', 24, :bold])
- style_tag_small = TkTextTag.new(t, 'font'=>'Times 8 bold')
- end
###
# case($tk_version)
# when /^4.*/
@@ -121,13 +106,8 @@ txt = TkText.new(base_frame){|t|
style_tag_overstrike = TkTextTag.new(t, 'overstrike'=>'on')
style_tag_right = TkTextTag.new(t, 'justify'=>'right')
style_tag_center = TkTextTag.new(t, 'justify'=>'center')
- if $tk_version =~ /^4.*/
- style_tag_super = TkTextTag.new(t, 'offset'=>'4p', 'font'=>'-Adobe-Courier-Medium-R-Normal--*-100-*-*-*-*-*-*')
- style_tag_sub = TkTextTag.new(t, 'offset'=>'-2p', 'font'=>'-Adobe-Courier-Medium-R-Normal--*-100-*-*-*-*-*-*')
- else
- style_tag_super = TkTextTag.new(t, 'offset'=>'4p', 'font'=>[family, 10])
- style_tag_sub = TkTextTag.new(t, 'offset'=>'-2p', 'font'=>[family, 10])
- end
+ style_tag_super = TkTextTag.new(t, 'offset'=>'4p', 'font'=>'-Adobe-Courier-Medium-R-Normal--*-100-*-*-*-*-*-*')
+ style_tag_sub = TkTextTag.new(t, 'offset'=>'-2p', 'font'=>'-Adobe-Courier-Medium-R-Normal--*-100-*-*-*-*-*-*')
style_tag_margins = TkTextTag.new(t, 'lmargin1'=>'12m', 'lmargin2'=>'6m',
'rmargin'=>'10m')
style_tag_spacing = TkTextTag.new(t, 'spacing1'=>'10p', 'spacing2'=>'2p',
@@ -266,5 +246,3 @@ spacing3')
}
-txt.width 70
-txt.height 32
diff --git a/ext/tk/sample/demos-jp/tcolor b/ext/tk/sample/demos-jp/tcolor
index 17f7e1347e..c7f7ec7289 100644
--- a/ext/tk/sample/demos-jp/tcolor
+++ b/ext/tk/sample/demos-jp/tcolor
@@ -1,5 +1,4 @@
#!/usr/bin/env ruby
-# -*- coding: euc-jp -*-
#
# tcolor --
# ¤³¤Î¥¹¥¯¥ê¥×¥È¤ÏRGB,HSB,CYM·Á¼°¤ò¥µ¥Ý¡¼¥È¤¹¤ë
diff --git a/ext/tk/sample/demos-jp/text.rb b/ext/tk/sample/demos-jp/text.rb
index 0ae480eb00..0057d5dbdc 100644
--- a/ext/tk/sample/demos-jp/text.rb
+++ b/ext/tk/sample/demos-jp/text.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# text (basic facilities) widget demo (called by 'widget')
#
@@ -16,8 +15,6 @@ $text_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($text_demo).pack(:fill=>:both, :expand=>true)
-
# version check
if ((Tk::TK_VERSION.split('.').collect{|n| n.to_i} <=> [8,4]) < 0)
undo_support = false
@@ -26,7 +23,7 @@ else
end
# frame À¸À®
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($text_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -44,13 +41,13 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# text À¸À®
-TkText.new(base_frame){|t|
+TkText.new($text_demo){|t|
# À¸À®
relief 'sunken'
bd 2
setgrid 1
height 30
- TkScrollbar.new(base_frame) {|s|
+ TkScrollbar.new($text_demo) {|s|
pack('side'=>'right', 'fill'=>'y')
command proc{|*args| t.yview(*args)}
t.yscrollcommand proc{|first,last| s.set first,last}
diff --git a/ext/tk/sample/demos-jp/textpeer.rb b/ext/tk/sample/demos-jp/textpeer.rb
deleted file mode 100644
index 4967a99c92..0000000000
--- a/ext/tk/sample/demos-jp/textpeer.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-# -*- coding: euc-jp -*-
-#
-# text widget peering demo (called by 'widget')
-#
-# based on Tcl/Tk8.5.0 widget demos
-
-if defined?($textpeer_demo) && $textpeer_demo
- $textpeer_demo.destroy
- $textpeer_demo = nil
-end
-
-# demo toplevel widget
-$textpeer_demo = TkToplevel.new {|w|
- title("Text Wdget Peering Demonstration")
- iconname("textpeer")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($textpeer_demo).pack(:fill=>:both, :expand=>true)
-
-count = [0]
-
-## Define a widget that we peer from; it won't ever actually be shown though
-first = TkText.new(base_frame, :widgetname=>"text#{count[0] += 1}")
-first.insert :end,"¤³¤Î¥Ç¥â¤Ï°ì¤Ä¤ÎÁȤòÀ®¤·¤¿¥Æ¥­¥¹¥È¥¦¥£¥¸¥§¥Ã¥È¤ò¼¨¤·¤Þ¤¹¡£"
-first.insert :end,"¤½¤ì¤é¤Î¥Æ¥­¥¹¥È¥¦¥£¥¸¥§¥Ã¥È¤ÏÂÐÅù(¥Ô¥¢;peer)¤Î´Ø·¸¤Ë"
-first.insert :end,"¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£"
-first.insert :end,"¤½¤ì¤é¤Ï¡¢´ðÈפȤʤë¥Ç¡¼¥¿¥â¥Ç¥ë¤Ï¶¦Ä̤Τâ¤Î¤ò»ý¤Á¤Þ¤¹¤¬¡¢"
-first.insert :end,"²èÌÌɽ¼¨°ÌÃÖ¡¢ÊÔ½¸°ÌÃÖ¡¢ÁªÂòÈϰÏ(selection)¤Ë¤Ä¤¤¤Æ¤Ï"
-first.insert :end,"ÆÈΩ¤Ë»ý¤Ä¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£"
-first.insert :end,"³Æ¥Æ¥­¥¹¥È¥¦¥£¥¸¥§¥Ã¥È¤ÎÏÆ¤Ë¤¢¤ë"
-first.insert :end,"¡Ö¥Ô¥¢(peer)¤ÎºîÀ®¡×¥Ü¥¿¥ó¤ò»È¤¨¤Ð¡¢"
-first.insert :end,"¿·¤¿¤Ê¥Ô¥¢¤òÄɲ乤뤳¤È¤¬²Äǽ¤Ç¤¹¡£"
-first.insert :end,"¤Þ¤¿¡Ö¥Ô¥¢(peer)¤Î¾Ãµî¡×¥Ü¥¿¥ó¤ò»È¤¨¤Ð¡¢"
-first.insert :end,"ÆÃÄê¤Î¥Ô¥¢¥¦¥£¥¸¥§¥Ã¥È¤ò¾Ãµî¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£"
-
-Tk.update_idletasks ## for 'first' widget
-
-## Procedures to make and kill clones; most of this is just so that the demo
-## looks nice...
-def makeClone(count, win, txt)
- cnt = (count[0] += 1)
- peer = TkText::Peer.new(txt, win, :widgetname=>"text#{cnt}")
- sbar = TkScrollbar.new(win, :widgetname=>"sb#{cnt}")
- peer.yscrollbar sbar
- b1 = TkButton.new(win, :widgetname=>"clone#{cnt}",
- :text=>'¥Ô¥¢(peer)¤ÎºîÀ®',
- :command=>proc{makeClone(count, win, peer)})
- b2 = TkButton.new(win, :widgetname=>"kill#{cnt}",
- :text=>'¥Ô¥¢(peer)¤Î¾Ãµî',
- :command=>proc{killClone(win, cnt)})
- row = cnt * 2
- TkGrid.configure(peer, sbar, b1, :sticky=>'nsew', :row=>row)
- TkGrid.configure('^', '^', b2, :sticky=>'nsew', :row=>(row+=1))
- TkGrid.configure(b1, b2, :sticky=>'new')
- TkGrid.rowconfigure(win, b2, :weight=>1)
-end
-
-def killClone(win, cnt)
- Tk.destroy("#{win.path}.text#{cnt}", "#{win.path}.sb#{cnt}",
- "#{win.path}.clone#{cnt}", "#{win.path}.kill#{cnt}")
-end
-
-## Now set up the GUI
-makeClone(count, base_frame, first)
-makeClone(count, base_frame, first)
-first.destroy
-
-## See Code / Dismiss buttons
-TkFrame.new(base_frame){|f|
- TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{
- $textpeer_demo.destroy
- $textpeer_demo = nil
- }).pack(:side=>:left, :expand=>true)
-
- TkButton.new(f, :text=>'¥³¡¼¥É»²¾È', :width=>15, :command=>proc{
- showCode 'textpeer'
- }).pack(:side=>:left, :expand=>true)
-
- TkGrid.configure(f, '-', '-', :sticky=>'ew', :row=>5000)
-}
-TkGrid.columnconfigure(base_frame, 0, :weight=>1)
diff --git a/ext/tk/sample/demos-jp/toolbar.rb b/ext/tk/sample/demos-jp/toolbar.rb
deleted file mode 100644
index 9cb3834c34..0000000000
--- a/ext/tk/sample/demos-jp/toolbar.rb
+++ /dev/null
@@ -1,136 +0,0 @@
-# -*- coding: euc-jp -*-
-#
-# toolbar.rb --
-#
-# This demonstration script creates a toolbar that can be torn off.
-#
-# based on "Id: toolbar.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($toolbar_demo) && $toolbar_demo
- $toolbar_demo.destroy
- $toolbar_demo = nil
-end
-
-$toolbar_demo = TkToplevel.new {|w|
- title("Ttk Menu Buttons")
- iconname("toolbar")
- positionWindow(w)
-}
-
-base_frame = Ttk::Frame.new($toolbar_demo).pack(:fill=>:both, :expand=>true)
-
-if Tk.windowingsystem != 'aqua'
- msg = Ttk::Label.new(base_frame, :wraplength=>'4i', :text=><<EOL)
-¤³¤Î¥Ç¥â¤Ç¤Ï¡¤¥Ä¡¼¥ë¥Ð¡¼¤ò¤É¤Î¤è¤¦¤Ë¤·¤ÆÅ¬Àڤ˥ơ¼¥ÞÂбþ¤µ¤»¤ë¤«¡¤\
-¤Þ¤¿¡¤¤É¤Î¤è¤¦¤Ë¤·¤ÆÀÚ¤êÎ¥¤·²Äǽ¤Ë¤¹¤ë¤«¤ò¼¨¤·¤Æ¤¤¤Þ¤¹\
-¡Ê¤¿¤À¤·¡¤¥Ä¡¼¥ë¥Ð¡¼¤ÎÀÚ¤êÎ¥¤·¤Ë¤ÏTcl/Tk8.5°Ê¾å¤Îµ¡Ç½¤¬É¬ÍפǤ¹¡Ë¡¥\
-¥Ä¡¼¥ë¥Ð¡¼¤Î¥Ü¥¿¥ó¤Ï¡¤'Toolbutton'¥¹¥¿¥¤¥ë¤ò»ÈÍѤ¹¤ë¤è¤¦¤ËÌÀ¼¨¤¹¤ë¤³¤È¤Ç¡¤\
-"toolbar style"¥Ü¥¿¥ó¤È¤Ê¤ë¤è¤¦¤Ë°À­ÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡¥\
-¥Ä¡¼¥ë¥Ð¡¼¤Îº¸Ã¼¤Ë¤Ï´Êñ¤Ê¥Þ¡¼¥«¡¼¤¬ÃÖ¤«¤ì¤Æ¤¤¤Þ¤¹¡¥\
-¥Þ¡¼¥«¡¼¾å¤Ë¥Þ¥¦¥¹¥«¡¼¥½¥ë¤¬Íè¤ë¤È°Üư¥¢¥¤¥³¥ó¤Ë¥«¡¼¥½¥ë¤¬ÊѲ½¤·¤Þ¤¹¡¥\
-¤½¤³¤Ç¥Ä¡¼¥ë¥Ð¡¼¤òư¤«¤¹¤è¤¦¤Ë¥É¥é¥Ã¥°¤¹¤ë¤È¡¤\
-¥Ä¡¼¥ë¥Ð¡¼Á´ÂΤòÀÚ¤êÎ¥¤·¤ÆÆÈΩ¤·¤¿¥È¥Ã¥×¥ì¥Ù¥ë¥¦¥£¥¸¥§¥Ã¥È¤Ë\
-¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¥\
-ÀÚ¤êÎ¥¤·¤¿¥Ä¡¼¥ë¥Ð¡¼¤¬ÉÔÍפȤʤä¿»þ¤Ë¤Ï¡¤\
-°ìÈÌŪ¤Ê¥È¥Ã¥×¥ì¥Ù¥ë¥¦¥£¥¸¥§¥Ã¥È¤ÈƱÍͤËñ½ã¤ËÊĤ¸¤ë¤³¤È¤Ç¡¤
-ºÆ¤Ó¸µ¤Î¥¦¥£¥ó¥É¥¦¤ËÄ¥¤êÉÕ¤±¤é¤ì¤ë¤Ç¤·¤ç¤¦¡¥
-EOL
-else
- msg = Ttk::Label.new(base_frame, :wraplength=>'4i', :text=><<EOL)
-¤³¤Î¥Ç¥â¤Ç¤Ï¡¤¥Ä¡¼¥ë¥Ð¡¼¤ò¤É¤Î¤è¤¦¤Ë¤·¤ÆÅ¬Àڤ˥ơ¼¥ÞÂбþ¤µ¤»¤ë¤«¤ò\
-¼¨¤·¤Æ¤¤¤Þ¤¹¡¥\
-¥Ä¡¼¥ë¥Ð¡¼¤Î¥Ü¥¿¥ó¤Ï¡¤'Toolbutton'¥¹¥¿¥¤¥ë¤ò»ÈÍѤ¹¤ë¤è¤¦¤ËÌÀ¼¨¤¹¤ë¤³¤È¤Ç¡¤\
-"toolbar style"¥Ü¥¿¥ó¤È¤Ê¤ë¤è¤¦¤Ë°À­ÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡¥
-EOL
-end
-
-## Set up the toolbar hull
-tbar_base = Tk::Frame.new(base_frame, # Tk ɸ½à¤Î frame ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡¥
- :widgetname=>'toolbar') # ¥¦¥£¥ó¥É¥¦¥¿¥¤¥È¥ëʸ»úÎó¤È¤¹¤ë¤¿¤á¤Ë¡¤¥¦¥£¥¸¥§¥Ã¥È̾¤òÌÀ¼¨¤·¤Æ¤¤¤Þ¤¹¡¥
-sep = Ttk::Separator.new(base_frame)
-to_base = Ttk::Frame.new(tbar_base, :cursor=>'fleur')
-if Tk.windowingsystem != 'aqua'
- to = Ttk::Separator.new(to_base, :orient=>:vertical)
- to2 = Ttk::Separator.new(to_base, :orient=>:vertical)
- to.pack(:fill=>:y, :expand=>true, :padx=>2, :side=>:left)
- to2.pack(:fill=>:y, :expand=>true, :side=>:left)
-end
-
-contents = Ttk::Frame.new(tbar_base)
-Tk.grid(to_base, contents, :sticky=>'nsew')
-tbar_base.grid_columnconfigure(contents, :weight=>1)
-contents.grid_columnconfigure(1000, :weight=>1)
-
-if Tk.windowingsystem != 'aqua'
- ## Bindings so that the toolbar can be torn off and reattached
- to_base.bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)}
- to. bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)}
- to2. bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)}
- def tbar_base.tearoff(w, x, y)
- on_win = TkWinfo.containing(x, y)
- return unless (on_win && on_win.path =~ /^#{@path}(\.|$)/)
- self.grid_remove
- w.grid_remove
- self.wm_manage
- # self.wm_title('Toolbar') # ¤â¤·¥¦¥£¥¸¥§¥Ã¥È̾¤ò¥¦¥£¥ó¥É¥¦¥¿¥¤¥È¥ë¤Ë¤·¤¿¤¯¤Ê¤¤¤Ê¤é¡¤¤³¤³¤ÇÀßÄꤷ¤Æ¤¯¤À¤µ¤¤
- self.wm_protocol('WM_DELETE_WINDOW'){ self.untearoff(self) }
- end
- def tbar_base.untearoff(w)
- self.wm_forget
- w.grid
- self.grid
- end
-end
-
-## Some content for the rest of the toplevel
-text = TkText.new(base_frame, :width=>40, :height=>10)
-
-## Toolbar contents
-tb_btn = Ttk::Button.new(tbar_base, :text=>'¥Ü¥¿¥ó', :style=>'Toolbutton',
- :command=>proc{
- text.insert(:end, "¥Ü¥¿¥ó¤¬²¡¤µ¤ì¤Þ¤·¤¿¡¥\n")
- })
-tb_chk = Ttk::Checkbutton.new(tbar_base, :text=>'¥Á¥§¥Ã¥¯¥Ü¥¿¥ó',
- :style=>'Toolbutton',
- :variable=>(check = TkVariable.new),
- :command=>proc{
- text.insert(:end, "¥Á¥§¥Ã¥¯¥Ü¥¿¥ó¤ÎÃͤÏ#{check.value}¤Ç¤¹¡¥\n")
- })
-tb_mbtn = Ttk::Menubutton.new(tbar_base, :text=>'¥á¥Ë¥å¡¼')
-tb_combo = Ttk::Combobox.new(tbar_base, :value=>TkFont.families,
- :state=>:readonly)
-tb_mbtn.menu(menu = Tk::Menu.new(tb_mbtn))
-menu.add(:command, :label=>'Just', :command=>proc{text.insert(:end, "Just\n")})
-menu.add(:command, :label=>'An', :command=>proc{text.insert(:end, "An\n")})
-menu.add(:command, :label=>'Example',
- :command=>proc{text.insert(:end, "Example\n")})
-tb_combo.bind('<ComboboxSelected>'){ text.font.family = tb_combo.get }
-
-## Arrange contents
-Tk.grid(tb_btn, tb_chk, tb_mbtn, tb_combo,
- :in=>contents, :padx=>2, :sticky=>'ns')
-Tk.grid(tbar_base, :sticky=>'ew')
-Tk.grid(sep, :sticky=>'ew')
-Tk.grid(msg, :sticky=>'ew')
-Tk.grid(text, :sticky=>'nsew')
-base_frame.grid_rowconfigure(text, :weight=>1)
-base_frame.grid_columnconfigure(text, :weight=>1)
-
-## See Code / Dismiss buttons
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'toolbar'}),
- Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $toolbar_demo.destroy
- $toolbar_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- Tk.grid(frame, :sticky=>'ew')
-}
diff --git a/ext/tk/sample/demos-jp/tree.rb b/ext/tk/sample/demos-jp/tree.rb
deleted file mode 100644
index c3b4191144..0000000000
--- a/ext/tk/sample/demos-jp/tree.rb
+++ /dev/null
@@ -1,120 +0,0 @@
-# -*- coding: euc-jp -*-
-#
-# tree.rb --
-#
-# This demonstration script creates a toplevel window containing a Ttk
-# tree widget.
-#
-# based on "Id: tree.tcl,v 1.4 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($tree_demo) && $tree_demo
- $tree_demo.destroy
- $tree_demo = nil
-end
-
-$tree_demo = TkToplevel.new {|w|
- title("Directory Browser")
- iconname("tree")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($tree_demo).pack(:fill=>:both, :expand=>true)
-
-## Explanatory text
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i',
- :justify=>:left, :anchor=>'n', :padding=>[10, 2, 10, 6],
- :text=><<EOL).pack(:fill=>:x)
-Ttk¤È¤Ï¡¤¥Æ¡¼¥Þ»ØÄê²Äǽ¤Ê¿·¤·¤¤¥¦¥£¥¸¥§¥Ã¥È½¸¹ç¤Ç¤¹¡¥\
-¤³¤Î¥µ¥ó¥×¥ë¤Ï¡¤¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Î¤è¤¦¤Ê³¬ÁØÅª¤Ê¥Ç¡¼¥¿½¸¹ç¤ò\
-»²¾È¤Ç¤­¤ë¤è¤¦¤Ë¤·¤¿Ttk::Treeview¥¦¥£¥¸¥§¥Ã¥È¤ò´Þ¤ó¤Ç¤¤¤Þ¤¹¡¥\
-Ttk::Treeview¥¦¥£¥¸¥§¥Ã¥È¤Ï¡¤ÌÚ¹½Â¤¼«ÂΤÎɽ¼¨¤ò²Äǽ¤Ë¤¹¤ë¤À¤±¤Ç¤Ê¤¯¡¤\
-ÄɲþðÊó(¤³¤Î¥µ¥ó¥×¥ë¤Î¾ì¹ç¤Ï¥Õ¥¡¥¤¥ë¥µ¥¤¥º)¤òɽ¼¨¤¹¤ë¤¿¤á¤Ë\
-Ǥ°Õ¤Î¸Ä¿ô¤ÎÄɲå«¥é¥à¤â°·¤¦¤³¤È¤â¤Ç¤­¤Þ¤¹¡¥\
-¤Þ¤¿¡¤¥«¥é¥à¤Î¥¿¥¤¥È¥ë´Ö¤Î¶èÀÚ¤êÉôʬ¤ò¥É¥é¥Ã¥°¤¹¤ë¤³¤È¤Ç¡¤\
-¥«¥é¥à¤ÎÉý¤òÊѹ¹¤¹¤ë¤³¤È¤â²Äǽ¤Ç¤¹¡¥
-EOL
-
-## See Code / Dismiss
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'tree'}),
- Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $tree_demo.destroy
- $tree_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-## Code to populate the roots of the tree (can be more than one on Windows)
-def populate_roots(tree)
- TkComm.simplelist(Tk.tk_call('file', 'volumes')).sort.each{|dir|
- populate_tree(tree, tree.insert(nil, :end, :text=>dir,
- :values=>[dir, 'directory']))
- }
-end
-
-## Code to populate a node of the tree
-def populate_tree(tree, node)
- return if tree.get(node, :type) != 'directory'
-
- path = tree.get(node, :fullpath)
- tree.delete(tree.children(node))
- Dir.glob("#{path}/*").sort.each{|f|
- type = File.ftype(f)
- id = tree.insert(node, :end,
- :text=>File.basename(f), :values=>[f, type]).id
- if type == 'directory'
- ## Make it so that this node is openable
- tree.insert(id, 0, :text=>'dummy')
- tree.itemconfigure(id, :text=>File.basename(f))
- elsif type == 'file'
- size = File.size(f)
- if size >= 1024*1024*1024
- size = '%.1f GB' % (size.to_f/1024/1024/1024)
- elsif size >= 1024*1024
- size = '%.1f MB' % (size.to_f/1024/1024)
- elsif size >= 1024
- size = '%.1f KB' % (size.to_f/1024)
- else
- size = '%.1f bytes' % (size.to_f/1024)
- end
- tree.set(id, :size, size)
- end
- }
-
- # Stop this code from rerunning on the current node
- tree.set(node, :type, 'processed_directory')
-end
-
-## Create the tree and set it up
-tree = Ttk::Treeview.new(base_frame, :columns=>%w(fullpath type size),
- :displaycolumns=>['size'])
-if Tk.windowingsystem != 'aqua'
- vsb = tree.yscrollbar(Ttk::Scrollbar.new(base_frame))
- hsb = tree.xscrollbar(Ttk::Scrollbar.new(base_frame))
-else
- vsb = tree.yscrollbar(Tk::Scrollbar.new(base_frame))
- hsb = tree.xscrollbar(Tk::Scrollbar.new(base_frame))
-end
-
-tree.heading_configure('#0', :text=>'Directory Structure')
-tree.heading_configure('size', :text=>'File Size')
-tree.column_configure('size', :stretch=>0, :width=>70)
-populate_roots(tree)
-tree.bind('<TreeviewOpen>', '%W'){|w| populate_tree(w, w.focus_item)}
-
-## Arrange the tree and its scrollbars in the toplevel
-container = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
-container.lower
-Tk.grid(tree, vsb, :in=>container, :sticky=>'nsew')
-Tk.grid(hsb, :in=>container, :sticky=>'nsew')
-container.grid_columnconfigure(0, :weight=>1)
-container.grid_rowconfigure(0, :weight=>1)
diff --git a/ext/tk/sample/demos-jp/ttkbut.rb b/ext/tk/sample/demos-jp/ttkbut.rb
deleted file mode 100644
index 4d577120bb..0000000000
--- a/ext/tk/sample/demos-jp/ttkbut.rb
+++ /dev/null
@@ -1,145 +0,0 @@
-# -*- coding: euc-jp -*-
-#
-# ttkbut.rb
-#
-# This demonstration script creates a toplevel window containing several
-# simple Ttk widgets, such as labels, labelframes, buttons, checkbuttons and
-# radiobuttons.
-#
-# based on "Id: ttkbut.tcl,v 1.4 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($ttkbut_demo) && $ttkbut_demo
- $ttkbut_demo.destroy
- $ttkbut_demo = nil
-end
-
-$ttkbut_demo = TkToplevel.new {|w|
- title("Simple Ttk Widgets")
- iconname("ttkbut")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($ttkbut_demo).pack(:fill=>:both, :expand=>true)
-
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left,
- :text=><<EOL).pack(:side=>:top, :fill=>:x)
-Ttk¤È¤Ï¡¤¥Æ¡¼¥Þ»ØÄê²Äǽ¤Ê¿·¤·¤¤¥¦¥£¥¸¥§¥Ã¥È½¸¹ç¤Ç¤¹¡¥\
-º£¡¤¤¢¤Ê¤¿¤¬Ìܤˤ·¤Æ¤¤¤ë¤Î¤ÏTtk¤Î¥Æ¡¼¥Þ²½¥é¥Ù¥ë¤Ç¡¤\
-²¼¤Ë¤ÏTtk¤Î¥é¥Ù¥ë¥Õ¥ì¡¼¥à¤ÎÃæ¤Ë»°¤Ä¤Î¥°¥ë¡¼¥×¤ÎTtk¥¦¥£¥¸¥§¥Ã¥È¤¬\
-ɽ¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥
-ºÇ½é¤Î¥°¥ë¡¼¥×¤ÏÁ´¤Æ¥Ü¥¿¥ó¤Ç¤¢¤ê¡¤\
-¤½¤ì¤¾¤ì¥¯¥ê¥Ã¥¯¤¹¤ì¤Ð¸½ºß¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥Æ¡¼¥Þ¤¬ÀßÄꤵ¤ì¤Þ¤¹¡¥
-£²ÈÖÌܤΥ°¥ë¡¼¥×¤Ï»°¤Ä¤Î¥Á¥§¥Ã¥¯¥Ü¥¿¥ó½¸¹ç¤Ç¤¹¡¥\
-³Æ½¸¹ç¤Î´Ö¤Ë¤Ï¡¤¥»¥Ñ¥ì¡¼¥¿¥¦¥£¥¸¥§¥Ã¥È¤¬ÃÖ¤«¤ì¤Æ¤¤¤Þ¤¹¡¥\
-¤Ê¤ª¡ÖÍ­¸ú²½¡×¥Ü¥¿¥ó¤Ï¡¤¤³¤Î¥È¥Ã¥×¥ì¥Ù¥ë¥¦¥£¥¸¥§¥Ã¥ÈÆâ¤Î\
-¾¤Î¤¹¤Ù¤Æ¤Î¥Æ¡¼¥Þ²½¥¦¥£¥¸¥§¥Ã¥È¤Î¾õÂÖ(state)¤¬"disabled"¤«¤É¤¦¤«¤ò\
-¥³¥ó¥È¥í¡¼¥ë¤¹¤ë¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡¥
-£³ÈÖÌܤΥ°¥ë¡¼¥×¤Ï´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥é¥¸¥ª¥Ü¥¿¥ó½¸¹ç¤È¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡¥
-EOL
-
-## Add buttons for setting the theme
-buttons = Ttk::Labelframe.new(base_frame, :text=>'¥Ü¥¿¥ó')
-# Ttk::Style.theme_names.each{|theme|
-# Ttk::Button.new(buttons, :text=>theme,
-# :command=>proc{Ttk::Style.theme_use theme}).pack(:pady=>2)
-# }
-Ttk.themes.each{|theme|
- Ttk::Button.new(buttons, :text=>theme,
- :command=>proc{Ttk.set_theme theme}).pack(:pady=>2)
-}
-
-## Helper procedure for the top checkbutton
-def setState(root, value, *excepts)
- return if excepts.member?(root)
-
- ## Non-Ttk widgets (e.g. the toplevel) will fail, so make it silent
- begin
- root.state = value
- rescue
- end
-
- ## Recursively invoke on all children of this root that are in the same
- ## toplevel widget
- root.winfo_children.each{|w|
- setState(w, value, *excepts) if w.winfo_toplevel == root.winfo_toplevel
- }
-end
-
-## Set up the checkbutton group
-checks = Ttk::Labelframe.new(base_frame, :text=>'¥Á¥§¥Ã¥¯¥Ü¥¿¥ó')
-enabled = TkVariable.new(true)
-e = Ttk::Checkbutton.new(checks, :text=>'Í­¸ú²½', :variable=>enabled,
- :command=>proc{
- setState($ttkbut_demo,
- ((enabled.bool)? "!disabled" : "disabled"),
- e)
- })
-
-## See ttk_widget(n) for other possible state flags
-sep1 = Ttk::Separator.new(checks)
-sep2 = Ttk::Separator.new(checks)
-
-cheese = TkVariable.new
-tomato = TkVariable.new
-basil = TkVariable.new
-oregano = TkVariable.new
-
-c1 = Ttk::Checkbutton.new(checks, :text=>'¥Á¡¼¥º', :variable=>cheese)
-c2 = Ttk::Checkbutton.new(checks, :text=>'¥È¥Þ¥È', :variable=>tomato)
-c3 = Ttk::Checkbutton.new(checks, :text=>'¥Ð¥¸¥ë', :variable=>basil)
-c4 = Ttk::Checkbutton.new(checks, :text=>'¥ª¥ì¥¬¥Î', :variable=>oregano)
-
-Tk.pack(e, sep1, c1, c2, sep2, c3, c4, :fill=>:x, :pady=>2)
-
-## Set up the radiobutton group
-radios = Ttk::Labelframe.new(base_frame, :text=>'¥é¥¸¥ª¥Ü¥¿¥ó')
-
-happyness = TkVariable.new
-
-r1 = Ttk::Radiobutton.new(radios, :variable=>happyness,
- :text=>'Great', :value=>'great')
-r2 = Ttk::Radiobutton.new(radios, :variable=>happyness,
- :text=>'Good', :value=>'good')
-r3 = Ttk::Radiobutton.new(radios, :variable=>happyness,
- :text=>'Ok', :value=>'ok')
-r4 = Ttk::Radiobutton.new(radios, :variable=>happyness,
- :text=>'Poor', :value=>'poor')
-r5 = Ttk::Radiobutton.new(radios, :variable=>happyness,
- :text=>'Awful', :value=>'awful')
-
-Tk.pack(r1, r2, r3, r4, r5, :fill=>:x, :padx=>3, :pady=>2)
-
-## See Code / Dismiss
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'ÊÑ¿ô»²¾È',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{
- showVars(base_frame, ['Í­¸ú²½', enabled],
- ['¥Á¡¼¥º', cheese], ['¥È¥Þ¥È', tomato],
- ['¥Ð¥¸¥ë', basil], ['¥ª¥ì¥¬¥Î', oregano],
- ['¹¬Ê¡ÅÙ', happyness])
- }),
- Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'ttkbut'}),
- Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- tmppath = $ttkbut_demo
- $ttkbut_demo = nil
- $showVarsWin[tmppath.path] = nil
- tmppath.destroy
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x, :expand=>true)
-}
-
-## Arrange things neatly
-f = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
-f.lower
-Tk.grid(buttons, checks, radios, :in=>f, :sticky=>'nwe', :pady=>2, :padx=>3)
-f.grid_columnconfigure([0, 1, 2], :weight=>1, :uniform=>:yes)
diff --git a/ext/tk/sample/demos-jp/ttkmenu.rb b/ext/tk/sample/demos-jp/ttkmenu.rb
deleted file mode 100644
index d349b42d11..0000000000
--- a/ext/tk/sample/demos-jp/ttkmenu.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-# -*- coding: euc-jp -*-
-#
-# ttkmenu.rb --
-#
-# This demonstration script creates a toplevel window containing several Ttk
-# menubutton widgets.
-#
-# based on "Id: ttkmenu.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($ttkmenu_demo) && $ttkmenu_demo
- $ttkmenu_demo.destroy
- $ttkmenu_demo = nil
-end
-
-$ttkmenu_demo = TkToplevel.new {|w|
- title("Ttk Menu Buttons")
- iconname("ttkmenu")
- positionWindow(w)
-}
-
-base_frame = Ttk::Frame.new($ttkmenu_demo).pack(:fill=>:both, :expand=>true)
-
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left,
- :text=><<EOL).pack(:side=>:top, :fill=>:x)
-Ttk¤È¤Ï¡¤¥Æ¡¼¥Þ»ØÄê²Äǽ¤Ê¿·¤·¤¤¥¦¥£¥¸¥§¥Ã¥È½¸¹ç¤Ç¤¹¡¥\
-¤³¤ì¤Ë¤è¤ê¥Æ¡¼¥Þ¤ËÂбþ¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¥¦¥£¥¸¥§¥Ã¥È¤Î¤Ò¤È¤Ä¤Ë\
-¥á¥Ë¥å¡¼¥Ü¥¿¥ó¤¬¤¢¤ê¤Þ¤¹¡¥\
-°Ê²¼¤Ç¤Ï¡¤¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿¥á¥Ë¥å¡¼¥Ü¥¿¥ó¤¬¤¤¤¯¤Ä¤«É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥\
-¤½¤ì¤é¤ò»È¤Ã¤Æ¡¤¸½ºß»ÈÍÑÃæ¤Î¥Æ¡¼¥Þ¤òÊѹ¹¤¹¤ë¤³¤È¤¬²Äǽ¤Ç¤¹¡¥\
-¥Æ¡¼¥Þ¤ÎÁªÂò¤¬¥á¥Ë¥å¡¼¥Ü¥¿¥ó¼«¿È¤Î¸«³Ý¤±¤òÊѲ½¤µ¤»¤ëÍͻҤ䡤\
-Ãæ±û¤Î¥á¥Ë¥å¡¼¥Ü¥¿¥ó¤À¤±¤¬°Û¤Ê¤ë¥¹¥¿¥¤¥ë\
-(¥Ä¡¼¥ë¥Ð¡¼¤Ç¤Î°ìÈÌŪ¤Êɽ¼¨¤ËŬ¤·¤¿¤â¤Î)¤Çɽ¼¨¤µ¤ì¤Æ¤¤¤ëÍͻҤË\
-ÃíÌܤ·¤Æ¤¯¤À¤µ¤¤¡¥\
-¤Ê¤ª¡¤¥á¥Ë¥å¡¼¥Ü¥¿¥ó¤Ë¤Ä¤¤¤Æ¤Ï¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿¥¦¥£¥¸¥§¥Ã¥È¤¬¤¢¤ê¤Þ¤¹¤¬¡¤\
-¥á¥Ë¥å¡¼¤Ë¤Ä¤¤¤Æ¤Ï¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿¥¦¥£¥¸¥§¥Ã¥È¤Ï´Þ¤Þ¤ì¤Æ¤¤¤Þ¤»¤ó¡¥\
-¤½¤ÎÍýͳ¤Ï¡¤É¸½à¤ÎTk¤Î¥á¥Ë¥å¡¼¥¦¥£¥¸¥§¥Ã¥È¤¬\
-¤¹¤Ù¤Æ¤Î¥×¥é¥Ã¥È¥Û¡¼¥à¤Ç½½Ê¬¤ËÎɹ¥¤Ê¸«³Ý¤±¤ÈÁàºîÀ­¤ò»ý¤Ã¤Æ¤¤¤ë¡¤\
-ÆÃ¤Ë¡¤Â¿¤¯¤Î´Ä¶­¤Ç¤½¤Î´Ä¶­ËÜÍè¤ÎÁàºîÂηϤȤʤë¤è¤¦¤Ë¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¤È\
-ȽÃǤµ¤ì¤¿¤³¤È¤Ë¤è¤ê¤Þ¤¹¡¥
-EOL
-
-Ttk::Separator.new(base_frame).pack(:side=>:top, :fill=>:x)
-
-## See Code / Dismiss
-Ttk::Frame.new($ttkmenu_demo) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'ttkmenu'}),
- Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $ttkmenu_demo.destroy
- $ttkmenu_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-b1 = Ttk::Menubutton.new(base_frame,:text=>'¥Æ¡¼¥Þ¤òÁªÂò',:direction=>:above)
-b2 = Ttk::Menubutton.new(base_frame,:text=>'¥Æ¡¼¥Þ¤òÁªÂò',:direction=>:left)
-b3 = Ttk::Menubutton.new(base_frame,:text=>'¥Æ¡¼¥Þ¤òÁªÂò',:direction=>:right)
-b4 = Ttk::Menubutton.new(base_frame,:text=>'¥Æ¡¼¥Þ¤òÁªÂò',:direction=>:flush,
- :style=>Ttk::Menubutton.style('Toolbutton'))
-b5 = Ttk::Menubutton.new(base_frame,:text=>'¥Æ¡¼¥Þ¤òÁªÂò',:direction=>:below)
-
-b1.menu(m1 = Tk::Menu.new(b1, :tearoff=>false))
-b2.menu(m2 = Tk::Menu.new(b2, :tearoff=>false))
-b3.menu(m3 = Tk::Menu.new(b3, :tearoff=>false))
-b4.menu(m4 = Tk::Menu.new(b4, :tearoff=>false))
-b5.menu(m5 = Tk::Menu.new(b5, :tearoff=>false))
-
-Ttk.themes.each{|theme|
- m1.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
- m2.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
- m3.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
- m4.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
- m5.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme})
-}
-
-f = Ttk::Frame.new(base_frame).pack(:fill=>:x)
-f1 = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
-f.lower
-
-f.grid_anchor(:center)
-TkGrid('x', b1, 'x', :in=>f, :padx=>3, :pady=>2)
-TkGrid(b2, b4, b3, :in=>f, :padx=>3, :pady=>2)
-TkGrid('x', b5, 'x', :in=>f, :padx=>3, :pady=>2)
diff --git a/ext/tk/sample/demos-jp/ttknote.rb b/ext/tk/sample/demos-jp/ttknote.rb
deleted file mode 100644
index 09cc7960a3..0000000000
--- a/ext/tk/sample/demos-jp/ttknote.rb
+++ /dev/null
@@ -1,97 +0,0 @@
-# -*- coding: euc-jp -*-
-#
-# ttknote.rb --
-#
-# This demonstration script creates a toplevel window containing a Ttk
-# notebook widget.
-#
-# based on "Id: ttknote.tcl,v 1.5 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($ttknote_demo) && $ttknote_demo
- $ttknote_demo.destroy
- $ttknote_demo = nil
-end
-
-$ttknote_demo = TkToplevel.new {|w|
- title("Ttk Notebook Widget")
- iconname("ttknote")
- positionWindow(w)
-}
-
-## See Code / Dismiss
-Ttk::Frame.new($ttknote_demo) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'ttknote'}),
- Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $ttknote_demo.destroy
- $ttknote_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-base_frame = Ttk::Frame.new($ttknote_demo).pack(:fill=>:both, :expand=>true)
-
-## Make the notebook and set up Ctrl+Tab traversal
-notebook = Ttk::Notebook.new(base_frame).pack(:fill=>:both, :expand=>true,
- :padx=>2, :pady=>3)
-notebook.enable_traversal
-
-## Popuplate the first pane
-f_msg = Ttk::Frame.new(notebook)
-msg_m = Ttk::Label.new(f_msg, :font=>$font, :wraplength=>'5i',
- :justify=>:left, :anchor=>'n', :text=><<EOL)
-Ttk¤È¤Ï¡¤¥Æ¡¼¥Þ»ØÄê²Äǽ¤Ê¿·¤·¤¤¥¦¥£¥¸¥§¥Ã¥È½¸¹ç¤Ç¤¹¡¥\
-¤½¤ÎÃæ¤Ë´Þ¤Þ¤ì¤ë¥¦¥£¥¸¥§¥Ã¥È¤Î¤Ò¤È¤Ä¤Ë¥Î¡¼¥È¥Ö¥Ã¥¯¥¦¥£¥¸¥§¥Ã¥È¤¬¤¢¤ê¤Þ¤¹¡¥\
-¥Î¡¼¥È¥Ö¥Ã¥¯¥¦¥£¥¸¥§¥Ã¥È¤Ï¡¤\
-¸ÄÊÌ¤ÎÆâÍÆ¤ò»ý¤Ã¤¿¥Ñ¥Í¥ë¤«¤é¤ÎÁªÂò¤ò²Äǽ¤Ë¤¹¤ë¤è¤¦¤Ê\
-¥¿¥Ö¤Î½¸¹ç¡Ê¥¿¥Ö¥»¥Ã¥È¡Ë¤òÄê¤á¤Þ¤¹¡¥\
-¥¿¥Ö¥»¥Ã¥È¤ÏºÇ¶á¤Î¿¤¯¤Î¥æ¡¼¥¶¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ç¸«¤é¤ì¤ëµ¡Ç½¤Ç¤¹¡¥\
-¥¿¥Ö¤ÎÁªÂò¤Ï¡¤¥Þ¥¦¥¹¤Ë¤è¤ë¤À¤±¤Ç¤Ê¤¯¡¤\
-¥Î¡¼¥È¥Ö¥Ã¥¯¥¦¥£¥¸¥§¥Ã¥È¤Î¥Ú¡¼¥¸¤Î¸«½Ð¤·¤¬ÁªÂò¤µ¤ì¤Æ¤¤¤ë»þ¤Ç¤¢¤ì¤Ð\
-Ctrl+Tab¥­¡¼¤ÎÆþÎϤˤè¤Ã¤Æ¤â¹Ô¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¥\
-¤³¤Î¥Ç¥â¤Ç¤Ï¡¤¸«½Ð¤·¤Ç²¼ÀþÉÕ¤­¤Îʸ»ú¤Î¥­¡¼¤ÈAlt¥­¡¼¤È¤òÁȤ߹ç¤ï¤»¤ë¤³¤È¤Ç\
-¥Ú¡¼¥¸¤òÁªÂò¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤âÀßÄꤷ¤Æ¤¤¤Þ¤¹¡¥\
-¤¿¤À¤·¡¤£²ÈÖÌܤΥ¿¥Ö¤Ï̵¸ú²½¤µ¤ì¤ÆÁªÂò¤Ç¤­¤Ê¤¤¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤³¤È¤Ë¤Ï\
-Ãí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡¥
-EOL
-neat = TkVariable.new
-after_id = nil
-msg_b = Ttk::Button.new(f_msg, :text=>'¤¹¤Æ¤­¤À¡ª(Neat!)', :underline=>6,
- :command=>proc{
- neat.value = '¤¢¤¡¡¤¤½¤Î¤È¤ª¤ê¤µ¡¥¡¥¡¥'
- Tk.after_cancel(after_id) if after_id
- after_id = Tk.after(500){neat.value = ''}
- })
-msg_b.winfo_toplevel.bind('Alt-n'){ msg_b.focus; msg_b.invoke }
-msg_l = Ttk::Label.new(f_msg, :textvariable=>neat)
-notebook.add(f_msg, :text=>'ÀâÌÀ(Description)', :underline=>3, :padding=>2)
-Tk.grid(msg_m, '-', :sticky=>'new', :pady=>2)
-Tk.grid(msg_b, msg_l, :pady=>[2, 4], :padx=>20)
-msg_b.grid_configure(:sticky=>'e')
-msg_l.grid_configure(:sticky=>'w')
-f_msg.grid_rowconfigure(1, :weight=>1)
-f_msg.grid_columnconfigure([0, 1], :weight=>1, :uniform=>1)
-
-## Populate the second pane. Note that the content doesn't really matter
-f_disabled = Ttk::Frame.new(notebook)
-notebook.add(f_disabled, :text=>'̵¸ú²½¤µ¤ì¤¿¥¿¥Ö', :state=>:disabled)
-
-## Popuplate the third pane
-f_editor = Ttk::Frame.new(notebook)
-notebook.add(f_editor, :text=>'¥Æ¥­¥¹¥È¥¨¥Ç¥£¥¿(Text Editor)', :underline=>9)
-editor_t = Tk::Text.new(f_editor, :width=>40, :height=>10, :wrap=>:char)
-if Tk.windowingsystem != 'aqua'
- editor_s = editor_t.yscrollbar(Ttk::Scrollbar.new(f_editor))
-else
- editor_s = editor_t.yscrollbar(Tk::Scrollbar.new(f_editor))
-end
-editor_s.pack(:side=>:right, :fill=>:y, :padx=>[0,2], :pady=>2)
-editor_t.pack(:fill=>:both, :expand=>true, :padx=>[2,0], :pady=>2)
diff --git a/ext/tk/sample/demos-jp/ttkpane.rb b/ext/tk/sample/demos-jp/ttkpane.rb
deleted file mode 100644
index 96670c0e5c..0000000000
--- a/ext/tk/sample/demos-jp/ttkpane.rb
+++ /dev/null
@@ -1,216 +0,0 @@
-# -*- coding: euc-jp -*-
-#
-# ttkpane.rb --
-#
-# This demonstration script creates a Ttk pane with some content.
-#
-# based on "Id: ttkpane.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($ttkpane_demo) && $ttkpane_demo
- $ttkpane_demo.destroy
- $ttkpane_demo = nil
-end
-
-$ttkpane_demo = TkToplevel.new {|w|
- title("Themed Nested Panes")
- iconname("ttkpane")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($ttkpane_demo).pack(:fill=>:both, :expand=>true)
-
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left,
- :text=><<EOL).pack(:side=>:top, :fill=>:x)
-¤³¤Î¥Ç¥â¤Ï¡¤Ëä¤á¹þ¤ß´Ø·¸¤Ë¤¢¤ë¥Æ¡¼¥ÞÉÕ¤­¥Ú¥¤¥ó¥É¥¦¥£¥ó¥É¥¦¤ò¼¨¤·¤Æ¤¤¤Þ¤¹¡¥\
-¤½¤ì¤¾¤ì¤ÎÂ礭¤µ¤Ï¡¤´Þ¤Þ¤ì¤Æ¤¤¤ë¥Ú¥¤¥ó¤Î´Ö¤Ë¤¢¤ë¥¨¥ê¥¢¤ò¤Ä¤«¤ó¤Ç\
-¶­³¦¤ò¥É¥é¥Ã¥°¤¹¤ë¤³¤È¤ÇÊѹ¹¤Ç¤­¤Þ¤¹¡¥
-EOL
-
-Ttk::Separator.new(base_frame).pack(:side=>:top, :fill=>:x)
-
-## See Code / Dismiss
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'ttkpane'}),
- Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $ttkpane_demo.destroy
- $ttkpane_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
-
-outer = Ttk::Panedwindow.new(frame, :orient=>:horizontal)
-outer.add(in_left = Ttk::Panedwindow.new(outer, :orient=>:vertical))
-outer.add(in_right = Ttk::Panedwindow.new(outer, :orient=>:vertical))
-in_left.add(left_top = Ttk::Labelframe.new(in_left, :text=>'¥Ü¥¿¥ó'))
-in_left.add(left_bot = Ttk::Labelframe.new(in_left, :text=>'»þ·×'))
-in_right.add(right_top = Ttk::Labelframe.new(in_right, :text=>'¥×¥í¥°¥ì¥¹'))
-in_right.add(right_bot = Ttk::Labelframe.new(in_right, :text=>'¥Æ¥­¥¹¥È'))
-if Tk.windowingsystem == 'aqua'
- [left_top, left_bot, right_top, right_bot].each{|w| w.padding(3) }
-end
-
-# Fill the button pane
-Ttk::Button.new(left_top, :text=>'²¡¤·¤Æ¤Í',
- :command=>proc{
- Tk.messageBox(:type=>'ok', :icon=>'info',
- :message=>'¤¤¤Æ¤Æ¡ª',
- :detail=>'That hurt...', :parent=>base_frame,
- :title=>'Button Pressed')
- }).pack(:padx=>2, :pady=>5)
-
-
-zones_list = [
- [':Europe/Berlin'],
- [':America/Argentina/Buenos_Aires', ':America/Buenos_Aires'],
- [':Africa/Johannesburg'],
- [':Europe/London'],
- [':America/Los_Angeles'],
- [':Europe/Moscow'],
- [':America/New_York'],
- [':Asia/Singapore'],
- [':Australia/Sydney'],
- [':Asia/Tokyo'],
-]
-
-zones = []
-
-# Check tzinfo support
-if $tk_major_ver > 8 || ($tk_major_ver == 8 && $tk_minor_ver >= 5)
- tzinfo = :tcl
-
- zones_list.each{|list|
- list.each{|zone|
- begin
- # Force a pre-load of all the timezones needed; otherwise can end up
- # poor-looking synch problems!
- Tk.tk_call('clock', 'format', '0', '-timezone', zone)
- rescue RuntimeError
- # ignore
- else
- zones << [zone, zone[%r<[^/:]+$>].tr('_', ' ')]
- break
- end
- }
- }
-
-else
- begin
- require 'tzinfo'
- tzinfo = :tzinfo
- rescue Exception
- begin
- require 'tzfile'
- tzinfo = :tzfile
- rescue Exception
- tzinfo = nil
- end
- end
-
- case tzinfo
- when :tzinfo
- zones_list.each{|list|
- list.each{|zone|
- begin
- tz = TZInfo::Timezone.get(zone[%r<[^:]+$>])
- rescue Exception
- # ignore
- else
- zones << [tz, zone[%r<[^/:]+$>].tr('_', ' ')]
- break
- end
- }
- }
-
- when :tzfile
- zones_list.each{|list|
- list.each{|zone|
- begin
- tz = TZFile.create(zone[%r<[^:]+$>])
- rescue Exception
- # ignore
- else
- zones << [tz, zone[%r<[^/:]+$>].tr('_', ' ')]
- break
- end
- }
- }
-
- else
- [ -7, -4, -2, -1, 0, +1, +3, +8, +9, +10 ].each{|zone|
- zones << [zone, 'UTC%+03d00' % zone]
- }
- end
-end
-
-time = TkVariable.new_hash
-
-case tzinfo
-when :tcl
- update_proc = proc{|now, tz, label|
- time[label] = Tk.tk_call('clock', 'format', now.tv_sec,
- '-timezone', tz, '-format', '%T')
- }
-when :tzinfo
- update_proc = proc{|now, tz, label|
- time[label] = tz.utc_to_local(now).strftime('%H:%M:%S')
- }
-when :tzfile
- update_proc = proc{|now, tz, label|
- time[label] = tz.at(now.tv_sec).strftime('%H:%M:%S')
- }
-else
- update_proc = proc{|now, tz, label|
- time[label] = (now + (tz * 3600)).strftime('%H:%M:%S')
- }
-end
-
-# Fill the clocks pane
-zones.each_with_index{|(zone, label), idx|
- Ttk::Separator.new(left_bot).pack(:fill=>:x) if idx > 0
- Ttk::Label.new(left_bot, :text=>label, :anchor=>'w').pack(:fill=>:x)
- Ttk::Label.new(left_bot, :textvariable=>time.ref(label),
- :anchor=>'w').pack(:fill=>:x)
-}
-
-# Timer start
-every = proc{
- now = Time.now.utc
- zones.each{|zone, label| update_proc.call(now, zone, label) }
-}
-TkRTTimer.new(1000, -1, every).start(0, every)
-
-# Fill the progress pane
-Ttk::Progressbar.new(right_top, :mode=>:indeterminate).pack(:fill=>:both, :expand=>true).start
-
-# Fill the text pane
-if Tk.windowingsystem != 'aqua'
- # The trick with the ttk::frame makes the text widget look like it fits with
- # the current Ttk theme despite not being a themed widget itself. It is done
- # by styling the frame like an entry, turning off the border in the text
- # widget, and putting the text widget in the frame with enough space to allow
- # the surrounding border to show through (2 pixels seems to be enough).
- f = Ttk::Frame.new(right_bot, :style=>Ttk::Entry)
- txt = TkText.new(frame, :wrap=>:word, :width=>30, :borderwidth=>0)
- txt.pack(:fill=>:both, :expand=>true, :in=>f, :pady=>2, :padx=>2)
- scr = txt.yscrollbar(Ttk::Scrollbar.new(frame))
- scr.pack(:side=>:right, :fill=>:y, :in=>right_bot)
- f.pack(:fill=>:both, :expand=>true)
- outer.pack(:fill=>:both, :expand=>true)
-else
- txt = TkText.new(frame, :wrap=>:word, :width=>30, :borderwidth=>0)
- scr = txt.yscrollbar(TkScrollbar.new(frame))
- scr.pack(:side=>:right, :fill=>:y, :in=>right_bot)
- txt.pack(:fill=>:both, :expand=>true, :in=>right_bot)
- outer.pack(:fill=>:both, :expand=>true, :padx=>10, :pady=>[6, 10])
-end
diff --git a/ext/tk/sample/demos-jp/ttkprogress.rb b/ext/tk/sample/demos-jp/ttkprogress.rb
deleted file mode 100644
index 43a9cbcd7e..0000000000
--- a/ext/tk/sample/demos-jp/ttkprogress.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-# -*- coding: euc-jp -*-
-#
-# ttkprogress.rb --
-#
-# This demonstration script creates several progress bar widgets.
-#
-# based on "Id: ttkprogress.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
-
-if defined?($ttkprogress_demo) && $ttkprogress_demo
- $ttkprogress_demo.destroy
- $ttkprogress_demo = nil
-end
-
-$ttkprogress_demo = TkToplevel.new {|w|
- title("Progress Bar Demonstration")
- iconname("ttkprogress")
- positionWindow(w)
-}
-
-base_frame = TkFrame.new($ttkprogress_demo).pack(:fill=>:both, :expand=>true)
-
-Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left,
- :text=><<EOL).pack(:side=>:top, :fill=>:x)
-²¼¤Ë¤¢¤ë¤Î¤ÏÆó¤Ä¤Î¥×¥í¥°¥ì¥¹¥Ð¡¼¤Ç¤¹¡¥\
-¾å¤Î¤â¤Î¤Ï"determinate"¥¿¥¤¥×¤Î¥×¥í¥°¥ì¥¹¥Ð¡¼¤Ç¡¤\
-Î㤨¤Ð¥×¥í¥°¥é¥à¤¬Í¿¤¨¤é¤ì¤¿¥¿¥¹¥¯¤ò½ªÎ»¤¹¤ë¤Þ¤Ç¤Ë¤É¤Î¤¯¤é¤¤¤«¤«¤ë¤«¤ò\
-¼¨¤¹¤È¤­¤Ê¤É¤ËÍѤ¤¤é¤ì¤Þ¤¹¡¥\
-²¼¤Î¤â¤Î¤Ï"indeterminate"¥¿¥¤¥×¤Î¥×¥í¥°¥ì¥¹¥Ð¡¼¤Ç¡¤\
-Î㤨¤Ð¥×¥í¥°¥é¥à¤¬¼Â¹ÔÃæ(busy)¤Ç¤¢¤ë¤â¤Î¤Î\
-½ªÎ»¤Þ¤Ç¤Ë¤É¤ì¤¯¤é¤¤¤«¤«¤ë¤«¤Ïʬ¤«¤é¤Ê¤¤¤È¤¤¤¦¾õÂÖ¤ò\
-¼¨¤¹¤È¤­¤Ê¤É¤ËÍѤ¤¤é¤ì¤Þ¤¹¡¥\
-¤¤¤º¤ì¤Î¥×¥í¥°¥ì¥¹¥Ð¡¼¤â¡¤¤¹¤°²¼¤Ë¤¢¤ë¥Ü¥¿¥ó¤ò»È¤¦¤³¤È¤Ç\
-¼«Æ°¥¢¥Ë¥á¡¼¥·¥ç¥ó¥â¡¼¥É¤ÎON/OFF¤òÀÚÂØ¤¨¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¥
-EOL
-
-## See Code / Dismiss buttons
-Ttk::Frame.new(base_frame) {|frame|
- sep = Ttk::Separator.new(frame)
- Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
- TkGrid('x',
- Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È',
- :image=>$image['view'], :compound=>:left,
- :command=>proc{showCode 'ttkprogress'}),
- Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë',
- :image=>$image['delete'], :compound=>:left,
- :command=>proc{
- $ttkprogress_demo.destroy
- $ttkprogress_demo = nil
- }),
- :padx=>4, :pady=>4)
- grid_columnconfigure(0, :weight=>1)
- pack(:side=>:bottom, :fill=>:x)
-}
-
-frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
-
-p1 = Ttk::Progressbar.new(frame, :mode=>:determinate)
-p2 = Ttk::Progressbar.new(frame, :mode=>:indeterminate)
-
-start = Ttk::Button.new(frame, :text=>'Start Progress',
- :command=>proc{ p1.start; p2.start })
-stop = Ttk::Button.new(frame, :text=>'Stop Progress',
- :command=>proc{ p1.stop; p2.stop })
-
-Tk.grid(p1, '-', :pady=>5, :padx=>10)
-Tk.grid(p2, '-', :pady=>5, :padx=>10)
-Tk.grid(start, stop, :padx=>10, :pady=>5)
-start.grid_configure(:sticky=>'e')
-stop.grid_configure(:sticky=>'w')
-frame.grid_columnconfigure(:all, :weight=>1)
-
diff --git a/ext/tk/sample/demos-jp/twind.rb b/ext/tk/sample/demos-jp/twind.rb
index faefaefd6e..2b228e4acd 100644
--- a/ext/tk/sample/demos-jp/twind.rb
+++ b/ext/tk/sample/demos-jp/twind.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# text (embedded windows) widget demo (called by 'widget')
#
@@ -16,10 +15,8 @@ $twind_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($twind_demo).pack(:fill=>:both, :expand=>true)
-
# frame À¸À®
-$twind_buttons = TkFrame.new(base_frame) {|frame|
+$twind_buttons = TkFrame.new($twind_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -39,7 +36,7 @@ $twind_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame À¸À®
$twind_text = nil
-TkFrame.new(base_frame, 'highlightthickness'=>2, 'borderwidth'=>2,
+TkFrame.new($twind_demo, 'highlightthickness'=>2, 'borderwidth'=>2,
'relief'=>'sunken') {|f|
$twind_text = TkText.new(f, 'setgrid'=>'true', 'font'=>$font,
'width'=>'70', 'height'=>35, 'wrap'=>'word',
@@ -209,11 +206,7 @@ def textWindPlot (t)
cursor 'top_left_arrow'
}
- if $tk_version =~ /^4.*/
- font = '-Adobe-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
- else
- font = 'Helvetica 18'
- end
+ font = '-Adobe-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
TkcLine.new($twind_plot, 100, 250, 400, 250, 'width'=>2)
TkcLine.new($twind_plot, 100, 250, 100, 50, 'width'=>2)
diff --git a/ext/tk/sample/demos-jp/twind2.rb b/ext/tk/sample/demos-jp/twind2.rb
index 2a26b28ef6..b634f07b4b 100644
--- a/ext/tk/sample/demos-jp/twind2.rb
+++ b/ext/tk/sample/demos-jp/twind2.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
#
# text (embedded windows) widget demo 2 (called by 'widget')
#
@@ -16,10 +15,8 @@ $twind2_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($twind2_demo).pack(:fill=>:both, :expand=>true)
-
# frame À¸À®
-$twind2_buttons = TkFrame.new(base_frame) {|frame|
+$twind2_buttons = TkFrame.new($twind2_demo) {|frame|
TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2),
:columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
TkGrid('x',
@@ -41,7 +38,7 @@ $twind2_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame À¸À®
$twind2_text = nil
-TkFrame.new(base_frame, 'highlightthickness'=>2, 'borderwidth'=>2,
+TkFrame.new($twind2_demo, 'highlightthickness'=>2, 'borderwidth'=>2,
'relief'=>'sunken') {|f|
$twind2_text = TkText.new(f, 'setgrid'=>true, 'font'=>$font,
# 'width'=>'70', 'height'=>35, 'wrap'=>'word',
diff --git a/ext/tk/sample/demos-jp/unicodeout.rb b/ext/tk/sample/demos-jp/unicodeout.rb
index 178077ec08..090cdf3059 100644
--- a/ext/tk/sample/demos-jp/unicodeout.rb
+++ b/ext/tk/sample/demos-jp/unicodeout.rb
@@ -1,5 +1,3 @@
-# -*- coding: euc-jp -*-
-#
# unicodeout.rb --
#
# This demonstration script shows how you can produce output (in label
@@ -18,9 +16,7 @@ $unicodeout_demo = TkToplevel.new {|w|
positionWindow(w)
}
-base_frame = TkFrame.new($unicodeout_demo).pack(:fill=>:both, :expand=>true)
-
-TkLabel.new(base_frame,
+TkLabel.new($unicodeout_demo,
:font=>$font, :wraplength=>'5.4i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
¤³¤ì¤Ï¡¤Tk¤Ë¤ª¤±¤ëÈó²¤ÊÆÊ¸»ú½¸¹ç¤òÍѤ¤¤ë¸À¸ì¤ËÂФ¹¤ë¥µ¥Ý¡¼¥È¤Ë¤Ä¤¤¤Æ¤Î\
@@ -42,7 +38,7 @@ Tcl¤Î¥¨¥¹¥±¡¼¥×ɽ¸½¤òÍѤ¤¤¿UNICODEʸ»úÎó¤Ç½ñ¤«¤ì¤Æ¤¤¤Þ¤¹¡¥\
EOL
#'
-TkFrame.new(base_frame){|f|
+TkFrame.new($unicodeout_demo){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{
@@ -55,7 +51,7 @@ TkFrame.new(base_frame){|f|
}).pack(:side=>:left, :expand=>true)
}
-wait_msg = TkLabel.new(base_frame,
+wait_msg = TkLabel.new($unicodeout_demo,
:text=>"¥Õ¥©¥ó¥ÈÆÉ¤ß¹þ¤ß¤Î´°Î»¤Þ¤Ç" +
"¤·¤Ð¤é¤¯¤ªÂÔ¤Á²¼¤µ¤¤¡¥¡¥¡¥",
:font=>"Helvetica 12 italic").pack
@@ -70,8 +66,8 @@ class Unicodeout_SampleFrame < TkFrame
# @@font = 'Newspaper 12'
# @@font = '{New century schoolbook} 12'
- def initialize(base)
- super(base)
+ def initialize()
+ super($unicodeout_demo)
grid_columnconfig(1, :weight=>1)
end
@@ -86,7 +82,7 @@ class Unicodeout_SampleFrame < TkFrame
l.grid_config(:padx, '1m')
end
end
-f = Unicodeout_SampleFrame.new(base_frame)
+f = Unicodeout_SampleFrame.new
f.pack(:expand=>true, :fill=>:both, :padx=>'2m', :pady=>'1m')
# Processing when some characters are missing might take a while, so make
diff --git a/ext/tk/sample/demos-jp/vscale.rb b/ext/tk/sample/demos-jp/vscale.rb
index a1097fd77f..86f6f7cdee 100644
--- a/ext/tk/sample/demos-jp/vscale.rb
+++ b/ext/tk/sample/demos-jp/vscale.rb
@@ -1,4 +1,3 @@
-# -*- coding: euc-jp -*-
require "tkcanvas"
if defined?($vscale_demo) && $vscale_demo
@@ -12,9 +11,7 @@ $vscale_demo = TkToplevel.new {|w|
}
positionWindow($vscale_demo)
-base_frame = TkFrame.new($vscale_demo).pack(:fill=>:both, :expand=>true)
-
-msg = TkLabel.new(base_frame) {
+msg = TkLabel.new($vscale_demo) {
font $font
wraplength '3.5i'
justify 'left'
@@ -25,7 +22,7 @@ msg = TkLabel.new(base_frame) {
}
msg.pack('side'=>'top', 'padx'=>'.5c')
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($vscale_demo) {|frame|
TkButton.new(frame) {
#text 'λ²ò'
text 'ÊĤ¸¤ë'
@@ -42,17 +39,7 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
-def setHeight(w, height)
- height = height + 21
- y2 = height - 30
- if y2 < 21
- y2 = 21
- end
- w.coords 'poly',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20
- w.coords 'line',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20
-end
-
-TkFrame.new(base_frame) {|frame|
+TkFrame.new($vscale_demo) {|frame|
borderwidth 10
canvas = TkCanvas.new(frame) {|c|
width 50
@@ -78,3 +65,14 @@ TkFrame.new(base_frame) {|frame|
}.pack('side'=>'left', 'anchor'=>'ne')
scale.set 75
}.pack
+
+
+def setHeight(w, height)
+ height = height + 21
+ y2 = height - 30
+ if y2 < 21
+ y2 = 21
+ end
+ w.coords 'poly',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20
+ w.coords 'line',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20
+end
diff --git a/ext/tk/sample/demos-jp/widget b/ext/tk/sample/demos-jp/widget
index 8eb699e513..11495dda54 100644
--- a/ext/tk/sample/demos-jp/widget
+++ b/ext/tk/sample/demos-jp/widget
@@ -1,22 +1,14 @@
#!/usr/bin/env ruby
-# -*- coding: euc-jp -*-
# ´Á»ú¥³¡¼¥ÉÀßÄê ( tk.rb ¤Î¥í¡¼¥É»þ¤Î encoding ¿äÄê/ÀßÄê¤Ë»È¤ï¤ì¤ë )
-if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!!!!
- $KCODE = 'euc'
-else
- DEFAULT_TK_ENCODING = 'EUC-JP'
-end
+$KCODE = 'euc'
# tk ´Ø·¸¥é¥¤¥Ö¥é¥ê¤ÎÆÉ¤ß¹þ¤ß
require 'tk'
# require 'tkafter'
-$RubyTk_WidgetDemo = true
-
# widget demo directory °ÌÃÖ¤Î³ÍÆÀ
-# $demo_dir = File.dirname($0)
-$demo_dir = File.dirname(__FILE__)
+$demo_dir = File.dirname($0)
# root ¤ÎÀ¸À®
$root = TkRoot.new{title "Ruby/Tk Widget Demonstration"}
@@ -51,14 +43,15 @@ when /^8.*/
$font = TkFont.new('Helvetica -12')
$kanji_font = TkFont.new('Helvetica -12', 'Mincho -12')
TkOption.add('*kanjiFont', knjfont, 'startupFile')
- $msg_kanji_font=TkFont.new('Helvetica 14 bold', 'Gothic 14 bold')
+ $msg_kanji_font=TkFont.new('Helvetica 16', 'Gothic 16 bold')
else
- $font = TkFont.new('Helvetica 14', nil)
+ $font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', nil)
knjfont = '-*--16-*-jisx0208.1983-0'
- $kanji_font = TkFont.new('Helvetic 14', knjfont)
+ $kanji_font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
+ knjfont)
TkOption.add('*kanjiFont', knjfont, 'startupFile')
- $msg_kanji_font=TkFont.new('Helvetica 14',
+ $msg_kanji_font=TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*',
'-*--24-*-jisx0208.1983-0')
end
#######
@@ -123,22 +116,14 @@ EOD
end
# ¥á¥Ë¥å¡¼ÀßÄê
-if $tk_major_ver >= 8
- $root.add_menubar([[['File', 0],
- ['About ... ', proc{aboutBox}, 0, '<F1>'],
- '---',
- ['Quit', proc{exit}, 0, 'Ctrl-Q']
- ]])
-else
- TkMenubar.new($root,
- [[['File', 0],
- ['About ... ', proc{aboutBox}, 0, '<F1>'],
- '---',
- ['Quit', proc{exit}, 0, 'Ctrl-Q']
- ]]).pack('side'=>'top', 'fill'=>'x')
-end
+TkMenubar.new($root,
+ [[['File', 0],
+ ['About ... ', proc{aboutBox}, 0, '<F1>'],
+ '---',
+ ['Quit', proc{exit}, 0, 'Meta-Q']
+ ]]).pack('side'=>'top', 'fill'=>'x')
$root.bind('F1', proc{aboutBox})
-$root.bind('Control-q', proc{exit})
+$root.bind('Meta-q', proc{exit})
=begin
TkFrame.new($root){|frame|
@@ -195,27 +180,18 @@ else
textFrame.pack('expand'=>'yes', 'fill'=>'both')
statusBar = TkFrame.new($root) {|f|
- if $tk_version =~ /^4.*/
- statusfont = '-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*'
- else
- statusfont = 'Helvetica 10'
- end
$statusBarLabel = \
TkLabel.new(f, 'text'=>" ", 'relief'=>'sunken', 'bd'=>1, 'anchor'=>'w',
- 'font'=>statusfont) \
+ 'font'=>'-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*') \
.pack('side'=>'left', 'padx'=>2, 'expand'=>'yes', 'fill'=>'both')
TkLabel.new(f, 'width'=>8, 'relief'=>'sunken', 'bd'=>1, 'anchor'=>'w',
- 'font'=>statusfont) \
+ 'font'=>'-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*') \
.pack('side'=>'left', 'padx'=>2)
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>2)
end
# ¥Æ¥­¥¹¥È¥¿¥°ÀßÄê
-if $tk_version =~ /^4.*/
- tag_title = TkTextTag.new(txt, 'font'=>'-*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-*')
-else
- tag_title = TkTextTag.new(txt, 'font'=>'Helvetica 18 bold')
-end
+tag_title = TkTextTag.new(txt, 'font'=>'-*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-*')
#tag_kanji_title = TkTextTag.new(txt, 'kanjifont'=>$msg_kanji_font)
#tag_middle = TkTextTag.new(txt, 'kanjifont'=>$kanji_font)
tag_kanji_title = TkTextTag.new(txt, 'font'=>$msg_kanji_font)
@@ -286,31 +262,14 @@ txt.insert('end', <<"EOT")
¤ë¤¿¤á¤Ë¡¢"¥³¡¼¥É»²¾È"¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤¢¤Ê¤¿¤¬\
˾¤à¤Ê¤é¡¢¤½¤Î¥³¡¼¥É¤ò½¤Àµ¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£½¤Àµ¤·¤¿¥³¡¼¥É¤Ç¥Ç¥â\
¥ó¥¹¥È¥ì¡¼¥·¥ç¥ó¤òºÆ¼Â¹Ô¤¹¤ë¤¿¤á¤Ë¤Ï¡¢¥³¡¼¥É¤¬½ñ¤«¤ì¤¿¥¦¥£¥ó¥É¥¦¤Ë\
-¤¢¤ë"¥Ç¥âºÆ¼Â¹Ô" ¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£\
-¥³¡¼¥É¤ò½¤Àµ¤·¤Æ¤â¥ª¥ê¥¸¥Ê¥ë¤Î¥Õ¥¡¥¤¥ë¤¬½ñ¤­´¹¤¨¤é¤ì¤ë¤³¤È¤Ï\
-¤¢¤ê¤Þ¤»¤ó¤«¤é¡¢¿´ÇÛ¤»¤º¤Ë¿§¡¹¤ÊÊѹ¹¤ò»î¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
-
-°ìÉô¤Î¥Ç¥â¤Ç¤Ï¡¢Èæ³ÓŪºÇ¶á¤Î¥Ð¡¼¥¸¥ç¥ó¤Î Tk ¤Ç¤Ê¤±¤ì¤Ð¥µ¥Ý¡¼¥È¤·¤Æ\
-¤¤¤Ê¤¤µ¡Ç½¤ò»È¤Ã¤Æ¼ÂÁõ¤·¤Æ¤¤¤Þ¤¹(Î㤨¤Ð Tk8.4 °Ê¾å¤Ê¤É)¡£¤½¤Î¤¿¤á¡¢\
-¤½¤¦¤·¤¿µ¡Ç½¤ò»ý¤¿¤Ê¤¤ Tk ¥é¥¤¥Ö¥é¥ê¤ò»È¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢¤½¤¦¤·¤¿\
-¥Ç¥â¤ÏÀµ¤·¤¯Æ°¤­¤Þ¤»¤ó¡£¤½¤Î¤è¤¦¤Êµ¡Ç½¤¬É¬ÍפǤ¢¤ì¤Ð¡¢¤½¤ì¤ò¥µ¥Ý¡¼¥È\
-¤·¤Æ¤¤¤ë Tk ¥é¥¤¥Ö¥é¥ê¤ò»È¤¦¤è¤¦¤Ë tcltklib ¤ò¥³¥ó¥Ñ¥¤¥ë¤·¤Ê¤ª¤·¤Æ\
-¤¯¤À¤µ¤¤¡£
-
-¤â¤·¤¢¤Ê¤¿¤Î Tk ¤¬ (ºÇ½é¤«¤é´Þ¤à¤«¥¤¥ó¥¹¥È¡¼¥ë¤·¤¿¤«¤Ë¤è¤ê) \
-Ttk (Tile) ³ÈÄ¥¤òÍøÍѤǤ­¤ë¾õÂ֤Ǥ¢¤ë¤Ê¤é¡¢\
-Ttk ³ÈÄ¥¤Î¥Ç¥â (sample/tkextlib/tile/demo.rb) ¤â¤¼¤Ò»î¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
-( ¿ʬ¡¤¸½ºß¤Î¤¢¤Ê¤¿¤Î´Ä¶­¤Ë¤Ï Ttk ³ÈÄ¥¤Ï\
-#{
-begin
- require 'tkextlib/tile'
- "¤¹¤Ç¤ËƳÆþ¤µ¤ì¤Æ¤¤¤Þ¤¹"
-rescue
- "¤Þ¤À¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Æ¤¤¤Þ¤»¤ó"
-end
-}\
-¡£)
-Ttk ³ÈÄ¥¤Ï¡¢Tk8.5 °Ê¾å¤Ç¤Ïɸ½à¤Îµ¡Ç½¤È¤·¤ÆÁȤ߹þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£
+¤¢¤ë"¥Ç¥âºÆ¼Â¹Ô" ¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£
+
+°ìÉô¤Î¥Ç¥â¤Ç¤Ï¡¤Èæ³ÓŪºÇ¶á¤Î¥Ð¡¼¥¸¥ç¥ó¤Î Tk ¤Ç¤Ê¤±¤ì¤Ð¥µ¥Ý¡¼¥È¤·¤Æ\
+¤¤¤Ê¤¤µ¡Ç½¤ò»È¤Ã¤Æ¼ÂÁõ¤·¤Æ¤¤¤Þ¤¹(Î㤨¤Ð Tk8.4 °Ê¾å¤Ê¤É)¡¥¤½¤Î¤¿¤á¡¤\
+¤½¤¦¤·¤¿µ¡Ç½¤ò»ý¤¿¤Ê¤¤ Tk ¥é¥¤¥Ö¥é¥ê¤ò»È¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¤¤½¤¦¤·¤¿\
+¥Ç¥â¤ÏÀµ¤·¤¯Æ°¤­¤Þ¤»¤ó¡¥¤½¤Î¤è¤¦¤Êµ¡Ç½¤¬É¬ÍפǤ¢¤ì¤Ð¡¤¤½¤ì¤ò¥µ¥Ý¡¼¥È\
+¤·¤Æ¤¤¤ë Tk ¥é¥¤¥Ö¥é¥ê¤ò»È¤¦¤è¤¦¤Ë¡¤tcltklib ¤ò¥³¥ó¥Ñ¥¤¥ë¤·¤Ê¤ª¤·¤Æ\
+¤¯¤À¤µ¤¤¡¥
EOT
@@ -359,9 +318,6 @@ txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "14. ¥é¥Ù¥ëÉÕ¤­¥Õ¥ì¡¼¥à (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n",
tag_demo, "demo-labelframe")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "15. ¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿¥¦¥£¥¸¥§¥Ã¥È¤Î´Êñ¤ÊÎã (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n",
- tag_demo, "demo-ttkbut")
-txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
#txt.insert('end', "¥ê¥¹¥È¥Ü¥Ã¥¯¥¹\n", tag_middle)
@@ -374,12 +330,6 @@ txt.insert('end', "2. ¿§: ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¤¿¤á¤ÎÇÛ¿§¤òÊѤ¨¤ë\n",
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. ³Ê¸À½¸\n", tag_demo, "demo-sayings")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "4. ¹ñ¤Ë¤Ä¤¤¤Æ¤Î¥Þ¥ë¥Á¥«¥é¥à¥ê¥¹¥È (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n",
- tag_demo, "demo-mclist")
-txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "5. ¥Ç¥£¥ì¥¯¥È¥ê¥Ö¥é¥¦¥¶ (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n",
- tag_demo, "demo-tree")
-txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
#txt.insert('end', "¥¨¥ó¥È¥ê¤È¥¹¥Ô¥ó¥Ü¥Ã¥¯¥¹\n", tag_middle)
@@ -395,10 +345,7 @@ txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. ¥¹¥Ô¥ó¥Ü¥Ã¥¯¥¹ (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n",
tag_demo, "demo-spin")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "5. ¥³¥ó¥Ü¥Ü¥Ã¥¯¥¹ (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n",
- tag_demo, "demo-combo")
-txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "6. ´Êñ¤Ê¥Õ¥©¡¼¥à\n", tag_demo, "demo-form")
+txt.insert('end', "5. ´Êñ¤Ê¥Õ¥©¡¼¥à\n", tag_demo, "demo-form")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
@@ -420,8 +367,6 @@ txt.insert('end', "5. ¥¦¥£¥ó¥É¥¦¤òËä¤á¹þ¤ó¤À¥Æ¥­¥¹¥È (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤Î
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "6. ¸¡º÷\n", tag_demo, "demo-search")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "7. ¥Æ¥­¥¹¥È¥¦¥£¥¸¥§¥Ã¥È¤ÎÂÐÅù²½(peering) (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", tag_demo, "demo-textpeer")
-txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
#txt.insert('end', "¥­¥ã¥ó¥Ð¥¹\n", tag_middle)
@@ -444,23 +389,18 @@ txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "8. ¥¹¥¯¥í¡¼¥ë²Äǽ¤Ê¥­¥ã¥ó¥Ð¥¹\n",
tag_demo, "demo-cscroll")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "9. ¥Á¥§¥¹¥Ü¡¼¥É¾å¤Îµ³»Î¤Î½ä²ó (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n",
- tag_demo, "demo-knightstour")
-txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
-#txt.insert('end', "¥¹¥±¡¼¥ë¤È¥×¥í¥°¥ì¥¹¥Ð¡¼\n", tag_middle)
-txt.insert('end', "¥¹¥±¡¼¥ë¤È¥×¥í¥°¥ì¥¹¥Ð¡¼\n", tag_kanji_title)
-txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "1. ¿âľ¥¹¥±¡¼¥ë\n", tag_demo.id, "demo-vscale")
+#txt.insert('end', "¥¹¥±¡¼¥ë\n", tag_middle)
+txt.insert('end', "¥¹¥±¡¼¥ë\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "2. ¿åÊ¿¥¹¥±¡¼¥ë\n", tag_demo.id, "demo-hscale")
+txt.insert('end', "1. ¿âľ\n", tag_demo.id, "demo-vscale")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "3. ¥×¥í¥°¥ì¥¹¥Ð¡¼ (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n", tag_demo.id, "demo-ttkprogress")
+txt.insert('end', "2. ¿åÊ¿\n", tag_demo.id, "demo-hscale")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
-txt.insert('end', "¥Ú¥¤¥ó¥É¥¦¥£¥ó¥É¥¦¤È¥Î¡¼¥È¥Ö¥Ã¥¯\n", tag_kanji_title)
+txt.insert('end', "¥Ú¥¤¥ó¥É¥¦¥£¥ó¥É¥¦\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. ¿åÊ¿Êý¸þ (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n",
tag_demo.id, "demo-paned1")
@@ -468,16 +408,10 @@ txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. ¿âľÊý¸þ (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n",
tag_demo.id, "demo-paned2")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "3. ¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿Ëä¤á¹þ¤ß¥Ú¥¤¥ó (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n",
- tag_demo.id, "demo-ttkpane")
-txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "4. ¥Î¡¼¥È¥Ö¥Ã¥¯¥¦¥£¥¸¥§¥Ã¥È (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n",
- tag_demo.id, "demo-ttknote")
-txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
-#txt.insert('end', "¥á¥Ë¥å¡¼¤È¥Ä¡¼¥ë¥Ð¡¼\n", tag_middle)
-txt.insert('end', "¥á¥Ë¥å¡¼¤È¥Ä¡¼¥ë¥Ð¡¼\n", tag_kanji_title)
+#txt.insert('end', "¥á¥Ë¥å¡¼\n", tag_middle)
+txt.insert('end', "¥á¥Ë¥å¡¼\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. ¥á¥Ë¥å¡¼¤È¥«¥¹¥±¡¼¥É¤ò´Þ¤ó¤À¥¦¥£¥ó¥É¥¦\n",
tag_demo, "demo-menu")
@@ -491,12 +425,6 @@ txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. ¥á¥Ë¥å¡¼¥Ü¥¿¥ó (Tk8.x ÀìÍÑ)\n",
tag_demo, "demo-menubu")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "5. ¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿¥á¥Ë¥å¡¼¥Ü¥¿¥ó (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n",
- tag_demo.id, "demo-ttkmenu")
-txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "6. ¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿¥Ä¡¼¥ë¥Ð¡¼ (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n",
- tag_demo.id, "demo-toolbar")
-txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
#txt.insert('end', "¥À¥¤¥¢¥í¥°¥¦¥£¥ó¥É¥¦\n", tag_middle)
@@ -504,11 +432,9 @@ txt.insert('end', "¥À¥¤¥¢¥í¥°¥¦¥£¥ó¥É¥¦\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. ¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹\n", tag_demo, "demo-msgbox")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "2. ¾ÜºÙ¥Æ¥­¥¹¥ÈÉÕ¤­¤Î¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹ (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", tag_demo, "demo-msgbox2")
+txt.insert('end', "2. ¥Õ¥¡¥¤¥ëÁªÂò¥À¥¤¥¢¥í¥°\n", tag_demo, "demo-filebox")
txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "3. ¥Õ¥¡¥¤¥ëÁªÂò¥À¥¤¥¢¥í¥°\n", tag_demo, "demo-filebox")
-txt.insert('end', " \n ", tag_demospace)
-txt.insert('end', "4. ¿§ÁªÂò¥À¥¤¥¢¥í¥°\n", tag_demo, "demo-clrpick")
+txt.insert('end', "3. ¿§ÁªÂò¥À¥¤¥¢¥í¥°\n", tag_demo, "demo-clrpick")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
@@ -557,30 +483,25 @@ def showVars1(parent, *args)
end
top = TkToplevel.new(parent) {|w|
title "Variable values"
- base = TkFrame.new(w).pack(:fill=>:both, :expand=>true)
- TkLabel.new(base) {
+ TkLabel.new(w) {
text "ÊÑ¿ôÃÍ:"
width 20
anchor 'center'
- if $tk_version =~ /^4.*/
- font '-Adobe-helvetica-medium-r-normal--*-180-*-*-*-*-*-*'
- else
- font 'Helvetica 14'
- end
+ font '-Adobe-helvetica-medium-r-normal--*-180-*-*-*-*-*-*'
}.pack('side'=>'top', 'fill'=>'x')
len = 1
args.each{|vnam,vbody|
len = vnam.to_s.length if vnam.to_s.length > len
}
args.each{|vnam,vbody|
- TkFrame.new(base){|f|
+ TkFrame.new(w){|f|
#TkLabel.new(f, 'text'=>"#{vnam}: ").pack('side'=>'left')
TkLabel.new(f, 'text'=>"#{vnam}: ",'width'=>len+2).pack('side'=>'left')
TkLabel.new(f, 'textvariable'=>vbody, 'anchor'=>'w')\
.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x')
}.pack('side'=>'top', 'anchor'=>'w', 'fill'=>'x')
}
- TkButton.new(base) {
+ TkButton.new(w) {
text "λ²ò"
command proc{w.destroy}
}.pack('side'=>'bottom', 'pady'=>2)
@@ -595,12 +516,10 @@ def showVars2(parent, *args)
rescue
end
end
- $showVarsWin[parent.path] = TkToplevel.new(parent) {|top|
+ $showVarsWin[parent.path] = TkToplevel.new(parent) {|w|
title "Variable values"
- base = TkFrame.new(top).pack(:fill=>:both, :expand=>true)
-
- TkLabelFrame.new(base, :text=>"ÊÑ¿ôÃÍ:",
+ TkLabelFrame.new(w, :text=>"ÊÑ¿ôÃÍ:",
:font=>{:family=>'Helvetica', :size=>14}){|f|
args.each{|vnam,vbody|
TkGrid(TkLabel.new(f, :text=>"#{vnam}: ", :anchor=>'w'),
@@ -612,15 +531,15 @@ def showVars2(parent, *args)
f.grid_columnconfig(1, :weight=>1)
f.grid_rowconfig(100, :weight=>1)
}
- TkButton.new(base, :text=>"λ²ò", :width=>8, :default=>:active,
- :command=>proc{top.destroy}){|b|
- top.bind('Return', proc{b.invoke})
- top.bind('Escape', proc{b.invoke})
+ TkButton.new(w, :text=>"λ²ò", :width=>8, :default=>:active,
+ :command=>proc{w.destroy}){|b|
+ w.bind('Return', proc{b.invoke})
+ w.bind('Escape', proc{b.invoke})
b.grid(:sticky=>'e', :padx=>4, :pady=>[6, 4])
}
- base.grid_columnconfig(0, :weight=>1)
- base.grid_rowconfig(0, :weight=>1)
+ w.grid_columnconfig(0, :weight=>1)
+ w.grid_rowconfig(0, :weight=>1)
}
end
@@ -714,27 +633,8 @@ def _null_binding
end
private :_null_binding
-def eval_samplecode(code, file=nil)
- #eval(code)
- #_null_binding.pseudo_toplevel_eval{ eval(code) }
- #Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } }
- Thread.new{
- _null_binding.pseudo_toplevel_eval{
- begin
- if file
- eval(code, binding, "(eval:#{file})")
- else
- eval(code)
- end
- rescue Exception=>e
- #p e
- TkBgError.show(e.message + "\n" +
- "\n---< backtrace of Ruby side >-----\n" +
- e.backtrace.join("\n") +
- "\n---< backtrace of Tk side >-------")
- end
- }
- }
+def eval_samplecode(code)
+ Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } }.run
Tk.update
end
@@ -748,7 +648,7 @@ def invoke(txt, idx)
Tk.update
# eval(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, _null_binding)
# Tk.update
- eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, tag[5..-1] + '.rb')
+ eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join)
txt.cursor(cursor)
$tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
@@ -794,7 +694,6 @@ def showCode1(demo)
if $code_window == nil || TkWinfo.exist?($code_window) == false
$code_window = TkToplevel.new(nil)
f = TkFrame.new($code_window)
-
TkButton.new(f) {
#text "λ²ò"
text "ÊĤ¸¤ë"
@@ -802,25 +701,14 @@ def showCode1(demo)
$code_window.destroy
$code_window = nil
}
- }.pack('side'=>'right', 'expand'=>'false', 'pady'=>2)
+ }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
TkButton.new(f) {
text "ºÆ¼Â¹Ô"
# command proc{eval($code_text.get('1.0','end'), _null_binding)}
- command proc{eval_samplecode($code_text.get('1.0','end'), '<viewer>')}
- }.pack('side'=>'right', 'expand'=>'false', 'pady'=>2)
-
- TkLabel.new(f,'text'=>'line:').pack('side'=>'left')
- linenum =TkLabel.new(f,'text'=>'').pack('side'=>'left')
- TkLabel.new(f,'text'=>' pos:').pack('side'=>'left')
- posnum =TkLabel.new(f,'text'=>'').pack('side'=>'left')
-
- $set_linenum = proc{|w|
- line, pos = w.index('insert').split('.')
- linenum.text = line
- posnum.text = pos
- }
-
- f.pack('side'=>'bottom', 'expand'=>'true', 'fill'=>'x')
+ command proc{eval_samplecode($code_text.get('1.0','end'))}
+ }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
+# f.pack('side'=>'bottom', 'expand'=>'yes', 'fill'=>'x')
+ f.pack('side'=>'bottom', 'fill'=>'x')
if $tk_version =~ /^4\.[01]/
s = TkScrollbar.new($code_window, 'orient'=>'vertical')
@@ -864,21 +752,10 @@ def showCode1(demo)
TkGrid.columnconfigure(f, 0, 'weight'=>1, 'minsize'=>0)
}
end
-
- btag = TkBindTag.new
-
- btag.bind('Key', $set_linenum, '%W')
- btag.bind('Button', $set_linenum, '%W')
-
- btags = $code_text.bindtags
- btags.insert(btags.index($code_text.class) + 1, btag)
- $code_text.bindtags = btags
-
else
$code_window.deiconify
$code_window.raise
end
-
$code_window.title("Demo code: #{file}")
$code_window.iconname(file)
# fid = open(file, 'r')
@@ -889,9 +766,6 @@ def showCode1(demo)
#$code_mark = TkTextMark.new($code_text, '1.0')
#$code_text.set_insert('1.0')
TkTextMarkInsert.new($code_text,'1.0')
-
- $set_linenum.call($code_text)
-
fid.close
end
@@ -912,19 +786,7 @@ def showCode2(demo)
tf.grid_columnconfigure(0, :weight=>1)
bf = TkFrame.new($code_window)
-
- lf = TkFrame.new(bf)
- TkLabel.new(lf, :text=>'line:').pack(:side=>:left)
- linenum =TkLabel.new(lf, :text=>'').pack(:side=>:left)
- TkLabel.new(lf, :text=>' pos:').pack(:side=>:left)
- posnum =TkLabel.new(lf, :text=>'').pack(:side=>:left)
-
- $set_linenum = proc{|w|
- line, pos = w.index('insert').split('.')
- linenum.text = line
- posnum.text = pos
- }
-
+
#b_dis = TkButton.new(bf, :text=>'λ²ò', :default=>:active,
b_dis = TkButton.new(bf, :text=>'ÊĤ¸¤ë', :default=>:active,
:command=>proc{
@@ -938,12 +800,12 @@ def showCode2(demo)
b_run = TkButton.new(bf, :text=>'ºÆ¼Â¹Ô',
:command=>proc{
# eval($code_text.get('1.0','end'), _null_binding)
- eval_samplecode($code_text.get('1.0','end'), '<viewer>')
+ eval_samplecode($code_text.get('1.0','end'))
},
:image=>$image['refresh'], :compound=>:left)
- TkGrid(lf, 'x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4])
- bf.grid_columnconfigure(1, :weight=>1)
+ TkGrid('x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4])
+ bf.grid_columnconfigure(0, :weight=>1)
TkGrid(tf, :sticky=>'news')
TkGrid(bf, :sticky=>'ew')
@@ -956,16 +818,6 @@ def showCode2(demo)
$code_window.bindinfo('Return').each{|cmd, arg|
$code_window.bind_append('Escape', cmd, arg)
}
-
- btag = TkBindTag.new
-
- btag.bind('Key', $set_linenum, '%W')
- btag.bind('Button', $set_linenum, '%W')
-
- btags = $code_text.bindtags
- btags.insert(btags.index($code_text.class) + 1, btag)
- $code_text.bindtags = btags
-
else
$code_window.deiconify
$code_window.raise
@@ -977,9 +829,6 @@ def showCode2(demo)
$code_text.delete('1.0', 'end')
$code_text.insert('1.0', fid.read)
TkTextMarkInsert.new($code_text,'1.0')
-
- $set_linenum.call($code_text)
-
fid.close
end
@@ -1077,13 +926,12 @@ end
#
def aboutBox
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo',
- 'message'=>"Ruby/Tk ¥¦¥£¥¸¥§¥Ã¥È¥Ç¥â Ver.1.7.0-jp\n\n" +
+ 'message'=>"Ruby/Tk ¥¦¥£¥¸¥§¥Ã¥È¥Ç¥â Ver.1.6.0-jp\n\n" +
"based on demos of Tk8.1 -- 8.5 " +
- "( Copyright of Tcl/Tk demos:: " +
+ "( Copyright:: " +
"(c) 1996-1997 Sun Microsystems, Inc. / " +
"(c) 1997-2000 Ajuba Solutions, Inc. / " +
- "(c) 2001-2007 Donal K. Fellows / " +
- "(c) 2002-2007 Daniel A. Steffen )\n\n" +
+ "(c) 2001-2003 Donal K. Fellows )\n\n" +
"Your Ruby & Tk Version ::\n" +
"Ruby#{RUBY_VERSION}(#{RUBY_RELEASE_DATE})[#{RUBY_PLATFORM}] / Tk#{$tk_patchlevel}#{(Tk::JAPANIZED_TK)? '-jp': ''}\n\n" +
"Ruby/Tk release date :: tcltklib #{TclTkLib::RELEASE_DATE}; tk #{Tk::RELEASE_DATE}")
@@ -1105,7 +953,7 @@ ARGV.each{|cmd|
end
#eval(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join,
# _null_binding)
- eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join, cmd + '.rb')
+ eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join)
}
if no_launcher
$root.withdraw # hide root window
diff --git a/ext/tk/sample/encstr_usage.rb b/ext/tk/sample/encstr_usage.rb
index b22c2504ac..4285ec861c 100644
--- a/ext/tk/sample/encstr_usage.rb
+++ b/ext/tk/sample/encstr_usage.rb
@@ -11,7 +11,7 @@ t1 = TkText.new(:height=>5).pack
t2 = TkText.new(:height=>5).pack
t3 = TkText.new(:height=>5).pack
-src_str = IO.readlines(File.join(File.dirname(__FILE__),'iso2022-kr.txt')).join
+src_str = IO.readlines('iso2022-kr.txt').join
t1.insert('end',
"use neither Tk::EncodedString class nor Tk.encoding= method\n\n")
@@ -23,8 +23,7 @@ t2.insert('end',
t2.insert('end', enc_str)
Tk.encoding = 'iso2022-kr'
-t3.insert('end', "use Tk.encoding = 'iso2022-kr' (Tk.force_default_encoding? == #{Tk.force_default_encoding?})\n\n")
-
+t3.insert('end', "use Tk.encoding = 'iso2022-kr'\n\n")
t3.insert('end', src_str)
Tk.mainloop
diff --git a/ext/tk/sample/figmemo_sample.rb b/ext/tk/sample/figmemo_sample.rb
deleted file mode 100644
index 1b6979d2dd..0000000000
--- a/ext/tk/sample/figmemo_sample.rb
+++ /dev/null
@@ -1,456 +0,0 @@
-#!/usr/bin/env ruby
-require 'tk'
-
-begin
- # try to use Img extension
- require 'tkextlib/tkimg'
-rescue Exception
- # cannot use Img extention --> ignore
-end
-
-
-############################
-# scrolled_canvas
-class TkScrolledCanvas < TkCanvas
- include TkComposite
-
- def initialize_composite(keys={})
- @h_scr = TkScrollbar.new(@frame)
- @v_scr = TkScrollbar.new(@frame)
-
- @canvas = TkCanvas.new(@frame)
- @path = @canvas.path
-
- @canvas.xscrollbar(@h_scr)
- @canvas.yscrollbar(@v_scr)
-
- TkGrid.rowconfigure(@frame, 0, :weight=>1, :minsize=>0)
- TkGrid.columnconfigure(@frame, 0, :weight=>1, :minsize=>0)
-
- @canvas.grid(:row=>0, :column=>0, :sticky=>'news')
- @h_scr.grid(:row=>1, :column=>0, :sticky=>'ew')
- @v_scr.grid(:row=>0, :column=>1, :sticky=>'ns')
-
- delegate('DEFAULT', @canvas)
- delegate('background', @canvas, @h_scr, @v_scr)
- delegate('activebackground', @h_scr, @v_scr)
- delegate('troughcolor', @h_scr, @v_scr)
- delegate('repeatdelay', @h_scr, @v_scr)
- delegate('repeatinterval', @h_scr, @v_scr)
- delegate('borderwidth', @frame)
- delegate('relief', @frame)
-
- delegate_alias('canvasborderwidth', 'borderwidth', @canvas)
- delegate_alias('canvasrelief', 'relief', @canvas)
-
- delegate_alias('scrollbarborderwidth', 'borderwidth', @h_scr, @v_scr)
- delegate_alias('scrollbarrelief', 'relief', @h_scr, @v_scr)
-
- configure(keys) unless keys.empty?
- end
-end
-
-############################
-class PhotoCanvas < TkScrolledCanvas
-
-USAGE = <<EOT
---- WHAT IS ---
-You can write comments on the loaded image, and save it as a Postscipt
-file (original image file is not modified). Each comment is drawn as a
-set of an indicator circle, an arrow, and a memo text. See the following
-how to write comments.
-This can save the list of memo texts to another file. It may useful to
-search the saved Postscript file by the comments on them.
-This may not support multibyte characters (multibyte texts are broken on
-a Postscript file). It depends on features of canvas widgets of Tcl/Tk
-libraries linked your Ruby/Tk. If you use Tcl/Tk8.0-jp (Japanized Tcl/Tk),
-you can (possibly) get a Japanese Postscript file.
-
---- BINDINGS ---
-* Button-1 : draw comments by following steps
- 1st - Set center of a indicator circle.
- 2nd - Set head position of an arrow.
- 3rd - Set tail position of an arrow, and show an entry box.
- Input a memo text and hit 'Enter' key to entry the comment.
-
-* Button-2-drag : scroll the canvas
-
-* Button-3 : when drawing, cancel current drawing
-
-* Double-Button-3 : delete the clicked comment (text, arrow, and circle)
-EOT
-
- def initialize(*args)
- super(*args)
-
- self.highlightthickness = 0
- self.selectborderwidth = 0
-
- @photo = TkPhotoImage.new
- @img = TkcImage.new(self, 0, 0, :image=>@photo)
-
- width = self.width
- height = self.height
- @scr_region = [-width, -height, width, height]
- self.scrollregion(@scr_region)
- self.xview_moveto(0.25)
- self.yview_moveto(0.25)
-
- @col = 'red'
- @font = 'Helvetica -12'
-
- @memo_id_num = -1
- @memo_id_head = 'memo_'
- @memo_id_tag = nil
- @overlap_d = 2
-
- @state = TkVariable.new
- @border = 2
- @selectborder = 1
- @delta = @border + @selectborder
- @entry = TkEntry.new(self, :relief=>:ridge, :borderwidth=>@border,
- :selectborderwidth=>@selectborder,
- :highlightthickness=>0)
- @entry.bind('Return'){@state.value = 0}
-
- @mode = old_mode = 0
-
- _state0()
-
- bind('2', :x, :y){|x,y| scan_mark(x,y)}
- bind('B2-Motion', :x, :y){|x,y| scan_dragto(x,y)}
-
- bind('3'){
- next if (old_mode = @mode) == 0
- @items.each{|item| item.delete }
- _state0()
- }
-
- bind('Double-3', :widget, :x, :y){|w, x, y|
- next if old_mode != 0
- x = w.canvasx(x)
- y = w.canvasy(y)
- tag = nil
- w.find_overlapping(x - @overlap_d, y - @overlap_d,
- x + @overlap_d, y + @overlap_d).find{|item|
- ! (item.tags.find{|name|
- if name =~ /^(#{@memo_id_head}\d+)$/
- tag = $1
- end
- }.empty?)
- }
- w.delete(tag) if tag
- }
- end
-
- #-----------------------------------
- private
- def _state0() # init
- @mode = 0
-
- @memo_id_num += 1
- @memo_id_tag = @memo_id_head + @memo_id_num.to_s
-
- @target = nil
- @items = []
- @mark = [0, 0]
- bind_remove('Motion')
- bind('ButtonRelease-1', proc{|x,y| _state1(x,y)}, '%x', '%y')
- end
-
- def _state1(x,y) # set center
- @mode = 1
-
- @target = TkcOval.new(self,
- [canvasx(x), canvasy(y)], [canvasx(x), canvasy(y)],
- :outline=>@col, :width=>3, :tags=>[@memo_id_tag])
- @items << @target
- @mark = [x,y]
-
- bind('Motion', proc{|x,y| _state2(x,y)}, '%x', '%y')
- bind('ButtonRelease-1', proc{|x,y| _state3(x,y)}, '%x', '%y')
- end
-
- def _state2(x,y) # create circle
- @mode = 2
-
- r = Integer(Math.sqrt((x-@mark[0])**2 + (y-@mark[1])**2))
- @target.coords([canvasx(@mark[0] - r), canvasy(@mark[1] - r)],
- [canvasx(@mark[0] + r), canvasy(@mark[1] + r)])
- end
-
- def _state3(x,y) # set line start
- @mode = 3
-
- @target = TkcLine.new(self,
- [canvasx(x), canvasy(y)], [canvasx(x), canvasy(y)],
- :arrow=>:first, :arrowshape=>[10, 14, 5],
- :fill=>@col, :tags=>[@memo_id_tag])
- @items << @target
- @mark = [x, y]
-
- bind('Motion', proc{|x,y| _state4(x,y)}, '%x', '%y')
- bind('ButtonRelease-1', proc{|x,y| _state5(x,y)}, '%x', '%y')
- end
-
- def _state4(x,y) # create line
- @mode = 4
-
- @target.coords([canvasx(@mark[0]), canvasy(@mark[1])],
- [canvasx(x), canvasy(y)])
- end
-
- def _state5(x,y) # set text
- @mode = 5
-
- if x - @mark[0] >= 0
- justify = 'left'
- dx = - @delta
-
- if y - @mark[1] >= 0
- anchor = 'nw'
- dy = - @delta
- else
- anchor = 'sw'
- dy = @delta
- end
- else
- justify = 'right'
- dx = @delta
-
- if y - @mark[1] >= 0
- anchor = 'ne'
- dy = - @delta
- else
- anchor = 'se'
- dy = @delta
- end
- end
-
- bind_remove('Motion')
-
- @entry.value = ''
- @entry.configure(:justify=>justify, :font=>@font, :foreground=>@col)
-
- ewin = TkcWindow.new(self, [canvasx(x)+dx, canvasy(y)+dy],
- :window=>@entry, :state=>:normal, :anchor=>anchor,
- :tags=>[@memo_id_tag])
-
- @entry.focus
- @entry.grab
- @state.wait
- @entry.grab_release
-
- ewin.delete
-
- @target = TkcText.new(self, [canvasx(x), canvasy(y)],
- :anchor=>anchor, :justify=>justify,
- :fill=>@col, :font=>@font, :text=>@entry.value,
- :tags=>[@memo_id_tag])
-
- _state0()
- end
-
- #-----------------------------------
- public
- def load_photo(filename)
- @photo.configure(:file=>filename)
- end
-
- def modified?
- ! ((find_withtag('all') - [@img]).empty?)
- end
-
- def fig_erase
- (find_withtag('all') - [@img]).each{|item| item.delete}
- end
-
- def reset_region
- width = @photo.width
- height = @photo.height
-
- if width > @scr_region[2]
- @scr_region[0] = -width
- @scr_region[2] = width
- end
-
- if height > @scr_region[3]
- @scr_region[1] = -height
- @scr_region[3] = height
- end
-
- self.scrollregion(@scr_region)
- self.xview_moveto(0.25)
- self.yview_moveto(0.25)
- end
-
- def get_texts
- ret = []
- find_withtag('all').each{|item|
- if item.kind_of?(TkcText)
- ret << item[:text]
- end
- }
- ret
- end
-end
-############################
-
-# define methods for menu
-def open_file(canvas, fname)
- if canvas.modified?
- ret = Tk.messageBox(:icon=>'warning',:type=>'okcancel',:default=>'cancel',
- :message=>'Canvas may be modified. Realy erase? ')
- return if ret == 'cancel'
- end
-
- filetypes = [
- ['GIF Files', '.gif'],
- ['GIF Files', [], 'GIFF'],
- ['PPM Files', '.ppm'],
- ['PGM Files', '.pgm']
- ]
-
- begin
- if Tk::Img::package_version != ''
- filetypes << ['JPEG Files', ['.jpg', '.jpeg']]
- filetypes << ['PNG Files', '.png']
- filetypes << ['PostScript Files', '.ps']
- filetypes << ['PDF Files', '.pdf']
- filetypes << ['Windows Bitmap Files', '.bmp']
- filetypes << ['Windows Icon Files', '.ico']
- filetypes << ['PCX Files', '.pcx']
- filetypes << ['Pixmap Files', '.pixmap']
- filetypes << ['SGI Files', '.sgi']
- filetypes << ['Sun Raster Files', '.sun']
- filetypes << ['TGA Files', '.tga']
- filetypes << ['TIFF Files', '.tiff']
- filetypes << ['XBM Files', '.xbm']
- filetypes << ['XPM Files', '.xpm']
- end
- rescue
- end
-
- filetypes << ['ALL Files', '*']
-
- fpath = Tk.getOpenFile(:filetypes=>filetypes)
- return if fpath.empty?
-
- begin
- canvas.load_photo(fpath)
- rescue => e
- Tk.messageBox(:icon=>'error', :type=>'ok',
- :message=>"Fail to read '#{fpath}'.\n#{e.message}")
- end
-
- canvas.fig_erase
- canvas.reset_region
-
- fname.value = fpath
-end
-
-# --------------------------------
-def save_memo(canvas, fname)
- initname = fname.value
- if initname != '-'
- initname = File.basename(initname, File.extname(initname))
- fpath = Tk.getSaveFile(:filetypes=>[ ['Text Files', '.txt'],
- ['ALL Files', '*'] ],
- :initialfile=>initname)
- else
- fpath = Tk.getSaveFile(:filetypes=>[ ['Text Files', '.txt'],
- ['ALL Files', '*'] ])
- end
- return if fpath.empty?
-
- begin
- fid = open(fpath, 'w')
- rescue => e
- Tk.messageBox(:icon=>'error', :type=>'ok',
- :message=>"Fail to open '#{fname.value}'.\n#{e.message}")
- end
-
- begin
- canvas.get_texts.each{|txt|
- fid.print(txt, "\n")
- }
- ensure
- fid.close
- end
-end
-
-# --------------------------------
-def ps_print(canvas, fname)
- initname = fname.value
- if initname != '-'
- initname = File.basename(initname, File.extname(initname))
- fpath = Tk.getSaveFile(:filetypes=>[ ['Postscript Files', '.ps'],
- ['ALL Files', '*'] ],
- :initialfile=>initname)
- else
- fpath = Tk.getSaveFile(:filetypes=>[ ['Postscript Files', '.ps'],
- ['ALL Files', '*'] ])
- end
- return if fpath.empty?
-
- bbox = canvas.bbox('all')
- canvas.postscript(:file=>fpath, :x=>bbox[0], :y=>bbox[1],
- :width=>bbox[2] - bbox[0], :height=>bbox[3] - bbox[1])
-end
-
-# --------------------------------
-def quit(canvas)
- ret = Tk.messageBox(:icon=>'warning', :type=>'okcancel',
- :default=>'cancel',
- :message=>'Realy quit? ')
- exit if ret == 'ok'
-end
-
-# --------------------------------
-# setup root
-root = TkRoot.new(:title=>'Fig Memo')
-
-# create canvas frame
-canvas = PhotoCanvas.new(root).pack(:fill=>:both, :expand=>true)
-usage_frame = TkFrame.new(root, :relief=>:ridge, :borderwidth=>2)
-hide_btn = TkButton.new(usage_frame, :text=>'hide usage',
- :font=>{:size=>8}, :pady=>1,
- :command=>proc{usage_frame.unpack})
-hide_btn.pack(:anchor=>'e', :padx=>5)
-usage = TkLabel.new(usage_frame, :text=>PhotoCanvas::USAGE,
- :font=>'Helvetica 8', :justify=>:left).pack
-
-show_usage = proc{
- usage_frame.pack(:before=>canvas, :fill=>:x, :expand=>true)
-}
-
-fname = TkVariable.new('-')
-f = TkFrame.new(root, :relief=>:sunken, :borderwidth=>1).pack(:fill=>:x)
-label = TkLabel.new(f, :textvariable=>fname,
- :font=>{:size=>-12, :weight=>:bold},
- :anchor=>'w').pack(:side=>:left, :fill=>:x, :padx=>10)
-
-# create menu
-mspec = [
- [ ['File', 0],
- ['Show Usage', proc{show_usage.call}, 5],
- '---',
- ['Open Image File', proc{open_file(canvas, fname)}, 0],
- ['Save Memo Texts', proc{save_memo(canvas, fname)}, 0],
- '---',
- ['Save Postscript', proc{ps_print(canvas, fname)}, 5],
- '---',
- ['Quit', proc{quit(canvas)}, 0]
- ]
-]
-root.add_menubar(mspec)
-
-# manage wm_protocol
-root.protocol(:WM_DELETE_WINDOW){quit(canvas)}
-
-# show usage
-show_usage.call
-
-# --------------------------------
-# start eventloop
-Tk.mainloop
diff --git a/ext/tk/sample/irbtkw.rbw b/ext/tk/sample/irbtkw.rbw
index 3fb6dde626..f6a35be6ed 100644
--- a/ext/tk/sample/irbtkw.rbw
+++ b/ext/tk/sample/irbtkw.rbw
@@ -4,7 +4,7 @@
#
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
-release = '2008/03/08'
+release = '2006/11/06'
require 'tk'
begin
@@ -15,32 +15,10 @@ end
require 'irb'
-if TkCore::WITH_ENCODING
-else
- # $KCODE setup
- case Tk.encoding
- when 'shiftjis', 'cp932'
- $KCODE='SJIS'
- when 'euc-jp'
- $KCODE='EUC'
- when 'utf-8', 'unicode'
- $KCODE='UTF8'
- else
- # unknown
- end
-end
-
# console setup
top = TkToplevel.new(:title=>'IRB console')
top.protocol(:WM_DELETE_WINDOW){ Tk.exit }
-case (Tk.windowingsystem)
-when 'win32'
- fnt = ['MS Gothic', '-12']
-else
- fnt = ['courier', '-12']
-end
-
console = TkTextIO.new(top, :mode=>:console,
:width=>80).pack(:side=>:left,
:expand=>true, :fill=>:both)
diff --git a/ext/tk/sample/tcltklib/sample2.rb b/ext/tk/sample/tcltklib/sample2.rb
index 110e81ebc4..444bb1eef7 100644
--- a/ext/tk/sample/tcltklib/sample2.rb
+++ b/ext/tk/sample/tcltklib/sample2.rb
@@ -41,7 +41,7 @@ class Othello
[ 1, -1], [ 1, 0], [ 1, 1]
]
- attr_accessor :com_disk
+ attr :com_disk, TRUE
def initialize(othello)
@othello = othello
diff --git a/ext/tk/sample/tkextlib/tile/demo.rb b/ext/tk/sample/tkextlib/tile/demo.rb
index 633a072460..b604410da4 100644
--- a/ext/tk/sample/tkextlib/tile/demo.rb
+++ b/ext/tk/sample/tkextlib/tile/demo.rb
@@ -20,14 +20,6 @@ def version?(ver)
TkPackage.vcompare(Tk::Tile.package_version, ver) >= 0
end
-# define Tcl/Tk procedures for compatibility
-Tk::Tile.__define_LoadImages_proc_for_compatibility__!
-Tk::Tile::Style.__define_wrapper_proc_for_compatibility__!
-
-unless Tk::Tile::Style.theme_names.include?('step')
- Tk::Tile::Style.theme_create('step')
-end
-
Tk.load_tclscript(File.join(demodir, 'toolbutton.tcl'))
Tk.load_tclscript(File.join(demodir, 'repeater.tcl'))
@@ -63,7 +55,7 @@ $V = TkVariable.new_hash(:THEME => 'default',
:CHOICE => 2)
# Add in any available loadable themes.
-TkPackage.names.find_all{|n| n =~ /^(tile|ttk)::theme::/}.each{|pkg|
+TkPackage.names.find_all{|n| n =~ /^tile::theme::/}.each{|pkg|
name = pkg.split('::')[-1]
unless $THEMELIST.assoc(name)
$THEMELIST << [name, Tk.tk_call('string', 'totitle', name)]
@@ -74,8 +66,7 @@ TkPackage.names.find_all{|n| n =~ /^(tile|ttk)::theme::/}.each{|pkg|
$RUBY_THEMELIST = []
begin
load(File.join(demodir, 'themes', 'kroc.rb'), true)
-rescue => e
-raise e
+rescue
$RUBY_THEMELIST << ['kroc-rb', 'Kroc (by Ruby)', false]
else
$RUBY_THEMELIST << ['kroc-rb', 'Kroc (by Ruby)', true]
@@ -88,8 +79,8 @@ def makeThemeControl(parent)
:variable=>$V.ref(:THEME),
:command=>proc{setTheme(theme)})
b.grid(:sticky=>:ew)
- unless (TkPackage.names.find{|n| n =~ /(tile|ttk)::theme::#{theme}/})
- b.ttk_state(:disabled)
+ unless (TkPackage.names.find{|n| n == "tile::theme::#{theme}"})
+ b.state(:disabled)
end
}
$RUBY_THEMELIST.each{|theme, name, available|
@@ -97,7 +88,7 @@ def makeThemeControl(parent)
:variable=>$V.ref(:THEME),
:command=>proc{setTheme(theme)})
b.grid(:sticky=>:ew)
- b.ttk_state(:disabled) unless available
+ b.state(:disabled) unless available
}
c
end
@@ -107,7 +98,7 @@ def makeThemeMenu(parent)
$THEMELIST.each{|theme, name|
m.add(:radiobutton, :label=>name, :variable=>$V.ref(:THEME),
:value=>theme, :command=>proc{setTheme(theme)})
- unless (TkPackage.names.find{|n| n =~ /(tile|ttk)::theme::#{theme}/})
+ unless (TkPackage.names.find{|n| n == "tile::theme::#{theme}"})
m.entryconfigure(:end, :state=>:disabled)
end
}
@@ -120,10 +111,8 @@ def makeThemeMenu(parent)
end
def setTheme(theme)
- if (pkg = TkPackage.names.find{|n| n =~ /(tile|ttk)::theme::#{theme}/})
- unless Tk::Tile::Style.theme_names.find{|n| n == theme}
- TkPackage.require(pkg)
- end
+ if (TkPackage.names.find{|n| n == "tile::theme::#{theme}"})
+ TkPackage.require("tile::theme::#{theme}")
end
Tk::Tile::Style.theme_use(theme)
end
@@ -686,7 +675,7 @@ values = %w(list abc def ghi jkl mno pqr stu vwx yz)
combo, :values=>values, :textvariable=>$V.ref(:COMBO))
cb.pack(:side=>:top, :padx=>2, :pady=>2, :expand=>false, :fill=>:x)
if i == 1
- cb.ttk_state :readonly
+ cb.state :readonly
begin
cb.current = 3 # ignore if unsupported (tile0.4)
rescue
@@ -933,11 +922,11 @@ end
def updateStates
$states_list.each{|st|
begin
- $State[st] = $Widget.window.ttk_instate(st)
+ $State[st] = $Widget.window.instate(st)
rescue
- $states_btns[st].ttk_state('disabled')
+ $states_btns[st].state('disabled')
else
- $states_btns[st].ttk_state('!disabled')
+ $states_btns[st].state('!disabled')
end
}
end
@@ -945,9 +934,9 @@ end
def changeState(st)
if $Widget.value != ''
if $State.bool_element(st)
- $Widget.window.ttk_state(st)
+ $Widget.window.state(st)
else
- $Widget.window.ttk_state("!#{st}")
+ $Widget.window.state("!#{st}")
end
end
end
diff --git a/ext/tk/sample/tkextlib/tile/themes/blue/pkgIndex.tcl b/ext/tk/sample/tkextlib/tile/themes/blue/pkgIndex.tcl
index 4facac70d8..19ddda7c73 100644
--- a/ext/tk/sample/tkextlib/tile/themes/blue/pkgIndex.tcl
+++ b/ext/tk/sample/tkextlib/tile/themes/blue/pkgIndex.tcl
@@ -1,6 +1,6 @@
# Package index for tile demo pixmap themes.
if {[file isdirectory [file join $dir blue]]} {
- package ifneeded tile::theme::blue 0.7 \
+ package ifneeded tile::theme::blue 0.0.1 \
[list source [file join $dir blue.tcl]]
}
diff --git a/ext/tk/sample/tkextlib/tile/themes/kroc.rb b/ext/tk/sample/tkextlib/tile/themes/kroc.rb
index 27006d847f..f67ce7a897 100644
--- a/ext/tk/sample/tkextlib/tile/themes/kroc.rb
+++ b/ext/tk/sample/tkextlib/tile/themes/kroc.rb
@@ -95,35 +95,8 @@ def kroc_rb_settings
#
# Elements:
#
- if Tk::Tile::TILE_SPEC_VERSION_ID >= 8
- Tk::Tile::Style.element_create('Button.button',
- :image,
- [ $images['button-n'],
- :pressed, $images['button-p'],
- :active, $images['button-h'],
- ], :border=>3, :sticky=>:ew)
-
- Tk::Tile::Style.element_create('Checkbutton.indicator',
- :image,
- [ $images['check-nu'],
- [:pressed, :selected],$images['check-nc'],
- :pressed, $images['check-nu'],
- [:active, :selected], $images['check-hc'],
- :active, $images['check-hu'],
- :selected, $images['check-nc'],
- ], :sticky=>:w)
+ if TkPackage.vcompare(Tk::Tile.package_version, '0.5') >= 0
- Tk::Tile::Style.element_create('Radiobutton.indicator',
- :image,
- [ $images['radio-nu'],
- [:pressed,:selected],$images['radio-nc'],
- :pressed, $images['radio-nu'],
- [:active,:selected], $images['radio-hc'],
- :active, $images['radio-hu'],
- :selected, $images['radio-nc'],
- ], :sticky=>:w)
-
- elsif TkPackage.vcompare(Tk::Tile.package_version, '0.5') >= 0
Tk::Tile::Style.element_create('Button.button',
:image, $images['button-n'],
:map=>[
@@ -152,6 +125,7 @@ def kroc_rb_settings
], :sticky=>:w)
else # tile 0.4 or earlier
+
Tk::Tile::Style.element_create('Button.button', :pixmap,
:images=>[
:pressed, $images['button-p'],
diff --git a/ext/tk/sample/tkextlib/treectrl/demo.rb b/ext/tk/sample/tkextlib/treectrl/demo.rb
index eed95d0e1c..50ecde91f0 100644
--- a/ext/tk/sample/tkextlib/treectrl/demo.rb
+++ b/ext/tk/sample/tkextlib/treectrl/demo.rb
@@ -9,12 +9,11 @@ $HasColumnCreate = Tk::TreeCtrl::HasColumnCreateCommand
$Version_1_1_OrLater = (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
-#if Hash.instance_methods.include?(:key)
-if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
- # ruby 1.9.x --> use Hash#key
+if Hash.instance_methods.include?('key')
+ # probably ruby 1.9.x --> use Hash#key
# Because Hash#index show warning "Hash#index is deprecated; use Hash#key".
else
- # ruby 1.8.x --> use Hash#index
+ # probably ruby 1.8.x --> use Hash#index
class Hash
alias key index
end
diff --git a/ext/tk/sample/tkextlib/vu/canvSticker2.rb b/ext/tk/sample/tkextlib/vu/canvSticker2.rb
index 548a72c2cb..f54e748660 100644
--- a/ext/tk/sample/tkextlib/vu/canvSticker2.rb
+++ b/ext/tk/sample/tkextlib/vu/canvSticker2.rb
@@ -20,16 +20,14 @@ c.destroy
#---
#--- set STRING {{x0 y0 x1 y1} {...text...} {resize point: center}
-#sti_conf = [ [10, 10, 180, 180], "Sticker äöüß@²³¼½¾", :center ]
-#txt_conf = [ [210, 210], "Text äöüß@²³¼½¾", :center ]
+#sti_conf = [ [10, 10, 180, 180], "Sticker äöüß@²³¼½¾", :center ]
+#txt_conf = [ [210, 210], "Text äöüß@²³¼½¾", :center ]
sti_conf = [ [10, 10, 350, 350],
- Tk::UTF8_String('Sticker \u00E4\u00F6\u00FC\u00DF\u0040\u00B2\u00B3\u00BC\u00BD\u00BE'),
- :center ]
+ Tk::UTF8_String("Sticker äöüß@²³¼½¾"), :center ]
txt_conf = [ [250, 250],
- Tk::UTF8_String('Text \u00E4\u00F6\u00FC\u00DF\u0040\u00B2\u00B3\u00BC\u00BD\u00BE'),
- :center ]
+ Tk::UTF8_String("Text äöüß@²³¼½¾"), :center ]
-#p sti_conf
+p sti_conf
fnt = TkFont.new('Helvetica 24 bold')
diff --git a/ext/tk/sample/tkrttimer.rb b/ext/tk/sample/tkrttimer.rb
index 0abd4ecbd2..531f4a8d5a 100644
--- a/ext/tk/sample/tkrttimer.rb
+++ b/ext/tk/sample/tkrttimer.rb
@@ -17,17 +17,8 @@ TkLabel.new(f2, :text=>'use TkRTTimer class').pack
label2 = TkLabel.new(:parent=>f2, :relief=>:raised,
:width=>10).pack(:fill=>:both)
-TkLabel.new(:padx=>10, :pady=>5, :justify=>'left', :text=><<EOT).pack
-Interval setting of each timer object is 10 ms.
-Each timer object counts up the value on each callback
-(the value is not the clock data).
-The count of the TkTimer object is delayed by execution
-time of callbacks and inaccuracy of interval.
-On the other hand, the count of the TkRTTimer object is
-not delayed. Its callback interval is not accurate too.
-But it can compute error correction about the time when
-a callback should start.
-EOT
+TkLabel.new(:text=>'Interval setting of each timer is 10 ms.',
+ :padx=>10, :pady=>5).pack
# define the procedure repeated by the TkTimer object
tick = proc{|aobj| #<== TkTimer object
diff --git a/ext/tk/sample/tksleep_sample.rb b/ext/tk/sample/tksleep_sample.rb
deleted file mode 100644
index 23f6eca54e..0000000000
--- a/ext/tk/sample/tksleep_sample.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require 'tk'
-
-v = TkVariable.new(0)
-l = TkLabel.new(:textvariable=>v).pack(:pady=>[1, 10])
-
-a = TkButton.new(:text=>"button A :: proc{p ['AAA', v.value]}").pack(:fill=>:x, :pady=>[1, 15], :padx=>15)
-a.command{p ['AAA', v.value]}
-
-TkLabel.new(:text=>'Callback of the button B returns LIFO order').pack
-b = TkButton.new(:text=>"button B :: proc{n = v.value; p ['B:start', n]; Tk.sleep(10000); p ['B:end', n]}").pack(:fill=>:x, :pady=>[1, 15], :padx=>15)
-b.command{n = v.value; p ['B:start', n]; Tk.sleep(10000); p ['B:end', n]}
-
-TkLabel.new(:text=>'Callback of the button C returns FIFO order').pack
-c = TkButton.new(:text=>"button C :: proc{n = v.value; Thread.new{p ['C:start', n]; Tk.sleep(10000); p ['C:end', n]}}").pack(:fill=>:x, :pady=>[1, 15], :padx=>15)
-c.command{n = v.value; Thread.new{p ['C:start', n]; Tk.sleep(10000); p ['C:end', n]}}
-
-TkLabel.new(:text=>'Callback of the button D blocks eventloop (no respond to event)').pack
-d = TkButton.new(:text=>"button D :: proc{n = v.value; p ['D:start', n]; sleep(10); p ['D:end', n]}").pack(:fill=>:x, :pady=>[1,15], :padx=>15)
-d.command{n = v.value; p ['D:start', n]; sleep(10); p ['D:end', n]}
-
-TkLabel.new(:text=>'Callback of the button E is another way to avoid eventloop blocking').pack
-e = TkButton.new(:text=>"button E :: proc{n = v.value; Thread.new{p ['D:start', n]; sleep(10); p ['D:end', n]}}").pack(:fill=>:x, :pady=>[1,15], :padx=>15)
-e.command{n = v.value; Thread.new{p ['D:start', n]; sleep(10); p ['D:end', n]}}
-
-TkButton.new(:text=>'QUIT', :command=>proc{exit}).pack
-
-TkTimer.new(500, -1){v.numeric += 1}.start
-
-Tk.mainloop
diff --git a/ext/tk/sample/tktextio.rb b/ext/tk/sample/tktextio.rb
index 9f012feada..4573bcebdf 100644
--- a/ext/tk/sample/tktextio.rb
+++ b/ext/tk/sample/tktextio.rb
@@ -254,15 +254,7 @@ class TkTextIO < TkText
Tk.callback_break
end
end
- def _cb_ctrl_u
- if @console_mode
- mark_set('insert', @ins_head)
- delete('insert', 'insert lineend')
- Tk.callback_break
- end
- end
- private :_cb_up, :_cb_down, :_cb_left, :_cb_backspace,
- :_cb_ctrl_a, :_cb_ctrl_u
+ private :_cb_up, :_cb_down, :_cb_left, :_cb_backspace, :_cb_ctrl_a
def _setup_console_bindings
@bindtag = TkBindTag.new
@@ -336,8 +328,6 @@ class TkTextIO < TkText
@bindtag.bind('Home'){ _cb_ctrl_a }
@bindtag.bind('Control-a'){ _cb_ctrl_a }
-
- @bindtag.bind('Control-u'){ _cb_ctrl_u }
end
private :_setup_console_bindings
diff --git a/ext/tk/sample/ttk_wrapper.rb b/ext/tk/sample/ttk_wrapper.rb
deleted file mode 100644
index 1580668994..0000000000
--- a/ext/tk/sample/ttk_wrapper.rb
+++ /dev/null
@@ -1,154 +0,0 @@
-#!/usr/bin/env ruby
-#
-# ttk_wrapper.rb -- use Ttk widgets as default on old Ruby/Tk scripts
-#
-# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
-#
-version = '0.1.3'
-#
-##########################################################################
-# parse commandline arguments
-##########################################################################
-require 'optparse'
-opt = OptionParser.new("Usage: #{$0} [options] rubytk_script" << "\n " <<
- "Ruby/Tk script wrapper. Use Ttk widgets as default.")
-opt.version = version
-
-OPTS = {}
-OPTS[:themedir] = []
-OPTS[:rb_theme] = []
-OPTS[:theme] = 'default'
-
-opt.on('-l', '--list', 'list available theme names'){|v| OPTS[:list] = true}
-opt.on('-t', '--theme theme', 'theme name'){|v| OPTS[:theme] = v}
-opt.on('-d', '--themedir themes_dir', 'directory of theme definitions'){|v|
- OPTS[:themedir] << v
-}
-opt.on('-r', '--rubytheme rb_theme', 'theme definition file (ruby script)'){|v|
- OPTS[:rb_theme] << v
-}
-opt.on('-v', '--verbose', 'print verbose messages'){|v| OPTS[:verbose] = true}
-
-opt.parse!(ARGV)
-
-
-##########################################################################
-# load Ttk (Tile) extension
-##########################################################################
-require 'tk'
-
-begin
- require 'tkextlib/tile'
- Tk.default_widget_set = :Ttk
-rescue LoadError
- if OPTS[:verbose]
- print "warning: fail to load 'Ttk' extension. use standard widgets.\n"
- end
-end
-
-if OPTS[:verbose]
- print "current default widget set is '#{Tk.default_widget_set}'\n"
-end
-
-
-##########################################################################
-# define Tcl/Tk procedures for compatibility.
-# those are required when want to use themes included
-# in "sample/tkextlib/tile/demo.rb".
-##########################################################################
-Tk::Tile.__define_LoadImages_proc_for_compatibility__!
-Tk::Tile::Style.__define_wrapper_proc_for_compatibility__!
-
-
-##########################################################################
-# use themes defined on the demo of Ttk (Tile) extension
-##########################################################################
-demodir = File.dirname(__FILE__)
-demo_themesdir = File.expand_path(File.join(demodir, 'tkextlib', 'tile', 'themes'))
-
-Tk::AUTO_PATH.lappend(*OPTS[:themedir]) unless OPTS[:themedir].empty?
-Tk::AUTO_PATH.lappend('.', demodir, demo_themesdir)
-
-OPTS[:themedir] << demo_themesdir
-print "theme-dirs: #{OPTS[:themedir].inspect}\n" if OPTS[:verbose]
-
-OPTS[:themedir].each{|themesdir|
- if File.directory?(themesdir)
- Dir.foreach(themesdir){|name|
- next if name == '.' || name == '..'
- path = File.join(themesdir, name)
- Tk::AUTO_PATH.lappend(path) if File.directory?(path)
- }
- end
-}
-
-# This forces an update of the available packages list. It's required
-# for package names to find the themes in demos/themes/*.tcl
-Tk.ip_eval("#{TkPackage.unknown_proc} Tcl #{TkPackage.provide('Tcl')}")
-
-# load themes written in Ruby.
-themes_by_ruby = [File.join(demo_themesdir, 'kroc.rb')]
-themes_by_ruby.concat OPTS[:rb_theme]
-print "ruby-themes: #{themes_by_ruby.inspect}\n" if OPTS[:verbose]
-
-themes_by_ruby.each{|f|
- begin
- load(f, true)
- rescue LoadError
- print "fail to load \"#{f}\"\n" if OPTS[:verbose]
- end
-}
-
-
-##########################################################################
-# ignore unsupported options of Ttk widgets
-##########################################################################
-TkConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__! true
-TkItemConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__! true
-
-
-##########################################################################
-# set theme of widget style
-##########################################################################
-if OPTS[:list] || OPTS[:verbose]
- print "supported theme names: #{Tk::Tile.themes.inspect}\n"
- exit if OPTS[:list] && ARGV.empty?
-end
-print "use theme: \"#{OPTS[:theme]}\"\n" if OPTS[:theme] && OPTS[:verbose]
-#setTheme(OPTS[:theme]) if OPTS[:theme]
-Tk::Tile.set_theme(OPTS[:theme]) if OPTS[:theme]
-
-
-##########################################################################
-# replace $0 and $RPAGRAM_NAME
-##########################################################################
-# When the expand_path of the target script is long, ruby sometimes
-# fails to set the path to $0 (the path string is trimmed).
-# The following replaces $0 and $PROGNAME to avoid such trouble.
-progname_obj = $0.dup
-$program_name = progname_obj
-
-alias $REAL_PROGRAM_NAME $0
-alias $PROGRAM_NAME $program_name
-alias $0 $program_name
-
-trace_var(:$program_name){|val|
- unless progname_obj.object_id == val.object_id
- progname_obj.replace(val.to_s)
- $program_name = progname_obj
- end
-}
-
-
-##########################################################################
-# load script
-##########################################################################
-if (path = ARGV.shift) && (script = File.expand_path(path))
- print "load script \"#{script}\"\n" if OPTS[:verbose]
- $0 = script
- load(script)
-else
- print "Error: no script is given.\n"
- print opt.help
- exit(1)
-end
diff --git a/ext/tk/stubs.c b/ext/tk/stubs.c
index 6d3b330f0e..23ff42a4f4 100644
--- a/ext/tk/stubs.c
+++ b/ext/tk/stubs.c
@@ -1,11 +1,5 @@
-/************************************************
-
- stubs.c - Tcl/Tk stubs support
-
-************************************************/
-
-#include "ruby.h"
#include "stubs.h"
+#include "ruby.h"
#include <tcl.h>
#include <tk.h>
@@ -92,12 +86,8 @@ static DL_HANDLE tcl_dll = (DL_HANDLE)0;
static DL_HANDLE tk_dll = (DL_HANDLE)0;
int
-#ifdef RUBY_VM
-ruby_open_tcl_dll(char *appname)
-#else
ruby_open_tcl_dll(appname)
char *appname;
-#endif
{
void (*p_Tcl_FindExecutable)(const char *);
int n;
@@ -151,8 +141,8 @@ ruby_open_tk_dll()
char tk_name[20];
if (!tcl_dll) {
- /* int ret = ruby_open_tcl_dll(RSTRING_PTR(rb_argv0)); */
- int ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ /* int ret = ruby_open_tcl_dll(RSTRING(rb_argv0)->ptr); */
+ int ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
if (ret != TCLTK_STUBS_OK) return ret;
}
@@ -179,12 +169,8 @@ ruby_open_tk_dll()
}
int
-#ifdef RUBY_VM
-ruby_open_tcltk_dll(char *appname)
-#else
ruby_open_tcltk_dll(appname)
char *appname;
-#endif
{
return( ruby_open_tcl_dll(appname) || ruby_open_tk_dll() );
}
@@ -203,12 +189,8 @@ tk_stubs_init_p()
Tcl_Interp *
-#ifdef RUBY_VM
-ruby_tcl_create_ip_and_stubs_init(int *st)
-#else
ruby_tcl_create_ip_and_stubs_init(st)
int *st;
-#endif
{
Tcl_Interp *tcl_ip;
@@ -231,8 +213,8 @@ ruby_tcl_create_ip_and_stubs_init(st)
Tcl_Interp *(*p_Tcl_DeleteInterp)();
if (!tcl_dll) {
- /* int ret = ruby_open_tcl_dll(RSTRING_PTR(rb_argv0)); */
- int ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ /* int ret = ruby_open_tcl_dll(RSTRING(rb_argv0)->ptr); */
+ int ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
if (ret != TCLTK_STUBS_OK) {
if (st) *st = ret;
@@ -290,12 +272,8 @@ ruby_tcl_stubs_init()
}
int
-#ifdef RUBY_VM
-ruby_tk_stubs_init(Tcl_Interp *tcl_ip)
-#else
ruby_tk_stubs_init(tcl_ip)
Tcl_Interp *tcl_ip;
-#endif
{
Tcl_ResetResult(tcl_ip);
@@ -330,12 +308,8 @@ ruby_tk_stubs_init(tcl_ip)
}
int
-#ifdef RUBY_VM
-ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip)
-#else
ruby_tk_stubs_safeinit(tcl_ip)
Tcl_Interp *tcl_ip;
-#endif
{
Tcl_ResetResult(tcl_ip);
@@ -374,8 +348,8 @@ ruby_tcltk_stubs()
int st;
Tcl_Interp *tcl_ip;
- /* st = ruby_open_tcltk_dll(RSTRING_PTR(rb_argv0)); */
- st = ruby_open_tcltk_dll(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ /* st = ruby_open_tcltk_dll(RSTRING(rb_argv0)->ptr); */
+ st = ruby_open_tcltk_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
switch(st) {
case NO_FindExecutable:
return -7;
@@ -421,12 +395,8 @@ static int open_tcl_dll = 0;
static int call_tk_stubs_init = 0;
int
-#ifdef RUBY_VM
-ruby_open_tcl_dll(char *appname)
-#else
ruby_open_tcl_dll(appname)
char *appname;
-#endif
{
if (appname) {
Tcl_FindExecutable(appname);
@@ -438,24 +408,18 @@ ruby_open_tcl_dll(appname)
return TCLTK_STUBS_OK;
}
-int
-ruby_open_tk_dll()
+int ruby_open_tk_dll()
{
if (!open_tcl_dll) {
- /* ruby_open_tcl_dll(RSTRING_PTR(rb_argv0)); */
- ruby_open_tcl_dll(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ /* ruby_open_tcl_dll(RSTRING(rb_argv0)->ptr); */
+ ruby_open_tcl_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
}
return TCLTK_STUBS_OK;
}
-int
-#ifdef RUBY_VM
-ruby_open_tcltk_dll(char *appname)
-#else
-ruby_open_tcltk_dll(appname)
+int ruby_open_tcltk_dll(appname)
char *appname;
-#endif
{
return( ruby_open_tcl_dll(appname) || ruby_open_tk_dll() );
}
@@ -473,18 +437,14 @@ tk_stubs_init_p()
}
Tcl_Interp *
-#ifdef RUBY_VM
-ruby_tcl_create_ip_and_stubs_init(int *st)
-#else
ruby_tcl_create_ip_and_stubs_init(st)
int *st;
-#endif
{
Tcl_Interp *tcl_ip;
if (!open_tcl_dll) {
- /* ruby_open_tcl_dll(RSTRING_PTR(rb_argv0)); */
- ruby_open_tcl_dll(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ /* ruby_open_tcl_dll(RSTRING(rb_argv0)->ptr); */
+ ruby_open_tcl_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
}
if (st) *st = 0;
@@ -506,12 +466,8 @@ ruby_tcl_stubs_init()
}
int
-#ifdef RUBY_VM
-ruby_tk_stubs_init(Tcl_Interp *tcl_ip)
-#else
ruby_tk_stubs_init(tcl_ip)
Tcl_Interp *tcl_ip;
-#endif
{
if (Tk_Init(tcl_ip) == TCL_ERROR)
return FAIL_Tk_Init;
@@ -527,12 +483,8 @@ ruby_tk_stubs_init(tcl_ip)
}
int
-#ifdef RUBY_VM
-ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip)
-#else
ruby_tk_stubs_safeinit(tcl_ip)
Tcl_Interp *tcl_ip;
-#endif
{
#if TCL_MAJOR_VERSION >= 8
if (Tk_SafeInit(tcl_ip) == TCL_ERROR)
@@ -556,8 +508,8 @@ ruby_tk_stubs_safeinit(tcl_ip)
int
ruby_tcltk_stubs()
{
- /* Tcl_FindExecutable(RSTRING_PTR(rb_argv0)); */
- Tcl_FindExecutable(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ /* Tcl_FindExecutable(RSTRING(rb_argv0)->ptr); */
+ Tcl_FindExecutable(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
return 0;
}
diff --git a/ext/tk/tcltklib.c b/ext/tk/tcltklib.c
index 8701cfef27..ff1f7640bd 100644
--- a/ext/tk/tcltklib.c
+++ b/ext/tk/tcltklib.c
@@ -4,20 +4,11 @@
* Oct. 24, 1997 Y. Matsumoto
*/
-#define TCLTKLIB_RELEASE_DATE "2008-05-23"
+#define TCLTKLIB_RELEASE_DATE "2006-12-01"
#include "ruby.h"
-
-#ifdef RUBY_VM
-/* #include "ruby/ruby.h" */
-#include "ruby/signal.h"
-#include "ruby/encoding.h"
-#else
-/* #include "ruby.h" */
#include "rubysig.h"
#include "version.h"
-#endif
-
#undef EXTERN /* avoid conflict with tcl.h of tcl8.2 or before */
#include <stdio.h>
#ifdef HAVE_STDARG_PROTOTYPES
@@ -39,24 +30,6 @@
#define TCL_FINAL_RELEASE 2
#endif
-static struct {
- int major;
- int minor;
- int patchlevel;
- int type;
-} tcltk_version = {0, 0, 0, 0};
-
-static void
-set_tcltk_version()
-{
- if (tcltk_version.major) return;
-
- Tcl_GetVersion(&(tcltk_version.major),
- &(tcltk_version.minor),
- &(tcltk_version.patchlevel),
- &(tcltk_version.type));
-}
-
#if TCL_MAJOR_VERSION >= 8
# ifndef CONST84
# if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION <= 4 /* Tcl8.0.x -- 8.4b1 */
@@ -110,26 +83,6 @@ static void ip_finalize _((Tcl_Interp*));
static int at_exit = 0;
-#ifdef RUBY_VM
-static VALUE cRubyEncoding;
-
-/* encoding */
-static int ENCODING_INDEX_UTF8;
-static int ENCODING_INDEX_BINARY;
-#endif
-static VALUE ENCODING_NAME_UTF8;
-static VALUE ENCODING_NAME_BINARY;
-
-static VALUE create_dummy_encoding_for_tk_core _((VALUE, VALUE, VALUE));
-static VALUE create_dummy_encoding_for_tk _((VALUE, VALUE));
-static int update_encoding_table _((VALUE, VALUE, VALUE));
-static VALUE encoding_table_get_name_core _((VALUE, VALUE, VALUE));
-static VALUE encoding_table_get_obj_core _((VALUE, VALUE, VALUE));
-static VALUE encoding_table_get_name _((VALUE, VALUE));
-static VALUE encoding_table_get_obj _((VALUE, VALUE));
-static VALUE create_encoding_table _((VALUE));
-static VALUE ip_get_encoding_table _((VALUE));
-
/* for callback break & continue */
static VALUE eTkCallbackReturn;
@@ -148,9 +101,6 @@ static VALUE tcltkip_class;
static ID ID_at_enc;
static ID ID_at_interp;
-static ID ID_encoding_name;
-static ID ID_encoding_table;
-
static ID ID_stop_p;
static ID ID_alive_p;
static ID ID_kill;
@@ -171,37 +121,14 @@ static ID ID_inspect;
static VALUE ip_invoke_real _((int, VALUE*, VALUE));
static VALUE ip_invoke _((int, VALUE*, VALUE));
-static VALUE ip_invoke_with_position _((int, VALUE*, VALUE, Tcl_QueuePosition));
-static VALUE tk_funcall _((VALUE(), int, VALUE*, VALUE));
-/* Tcl's object type */
-#if TCL_MAJOR_VERSION >= 8
-static char *Tcl_ObjTypeName_ByteArray = "bytearray";
-static Tcl_ObjType *Tcl_ObjType_ByteArray;
-
-static char *Tcl_ObjTypeName_String = "string";
-static Tcl_ObjType *Tcl_ObjType_String;
-
-#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1)
-#define IS_TCL_BYTEARRAY(obj) ((obj)->typePtr == Tcl_ObjType_ByteArray)
-#define IS_TCL_STRING(obj) ((obj)->typePtr == Tcl_ObjType_String)
-#define IS_TCL_VALID_STRING(obj) ((obj)->bytes != (char*)NULL)
-#endif
-#endif
-
-#ifndef HAVE_RB_HASH_LOOKUP
-#define rb_hash_lookup rb_hash_aref
-#endif
+static VALUE tk_funcall _((VALUE(), int, VALUE*, VALUE));
/* safe Tcl_Eval and Tcl_GlobalEval */
static int
-#ifdef RUBY_VM
-tcl_eval(Tcl_Interp *interp, const char *cmd)
-#else
tcl_eval(interp, cmd)
Tcl_Interp *interp;
const char *cmd; /* don't have to be writable */
-#endif
{
char *buf = strdup(cmd);
int ret;
@@ -216,13 +143,9 @@ tcl_eval(interp, cmd)
#define Tcl_Eval tcl_eval
static int
-#ifdef RUBY_VM
-tcl_global_eval(Tcl_Interp *interp, const char *cmd)
-#else
tcl_global_eval(interp, cmd)
Tcl_Interp *interp;
const char *cmd; /* don't have to be writable */
-#endif
{
char *buf = strdup(cmd);
int ret;
@@ -393,29 +316,12 @@ call_queue_mark(struct call_queue *q)
static VALUE eventloop_thread;
-#ifdef RUBY_VM
-Tcl_ThreadId tk_eventloop_thread_id; /* native thread ID of Tcl interpreter */
-#endif
static VALUE eventloop_stack;
-static int window_event_mode = ( ~ TCL_IDLE_EVENTS | TCL_WINDOW_EVENTS );
static VALUE watchdog_thread;
Tcl_Interp *current_interp;
-
-/* thread control strategy */
-/* multi-tk works with the following settings only ???
- : CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE 1
- : USE_TOGGLE_WINDOW_MODE_FOR_IDLE 0
- : DO_THREAD_SCHEDULE_AT_CALLBACK_DONE 0
-*/
-#define CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE 1
-#define USE_TOGGLE_WINDOW_MODE_FOR_IDLE 0
-#define DO_THREAD_SCHEDULE_AT_CALLBACK_DONE 0
-
-#if CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE
-static int have_rb_thread_waiting_for_value = 0;
-#endif
+
/*
* 'event_loop_max' is a maximum events which the eventloop processes in one
@@ -424,21 +330,12 @@ static int have_rb_thread_waiting_for_value = 0;
* 'timer_tick' is a limit of one term of thread scheduling.
* If 'timer_tick' == 0, then not use the timer for thread scheduling.
*/
-#ifdef RUBY_VM
-#define DEFAULT_EVENT_LOOP_MAX 800/*counts*/
-#define DEFAULT_NO_EVENT_TICK 10/*counts*/
-#define DEFAULT_NO_EVENT_WAIT 10/*milliseconds ( 1 -- 999 ) */
-#define WATCHDOG_INTERVAL 10/*milliseconds ( 1 -- 999 ) */
-#define DEFAULT_TIMER_TICK 0/*milliseconds ( 0 -- 999 ) */
-#define NO_THREAD_INTERRUPT_TIME 100/*milliseconds ( 1 -- 999 ) */
-#else /* ! RUBY_VM */
-#define DEFAULT_EVENT_LOOP_MAX 800/*counts*/
-#define DEFAULT_NO_EVENT_TICK 10/*counts*/
-#define DEFAULT_NO_EVENT_WAIT 20/*milliseconds ( 1 -- 999 ) */
-#define WATCHDOG_INTERVAL 10/*milliseconds ( 1 -- 999 ) */
-#define DEFAULT_TIMER_TICK 0/*milliseconds ( 0 -- 999 ) */
-#define NO_THREAD_INTERRUPT_TIME 100/*milliseconds ( 1 -- 999 ) */
-#endif
+#define DEFAULT_EVENT_LOOP_MAX 800/*counts*/
+#define DEFAULT_NO_EVENT_TICK 10/*counts*/
+#define DEFAULT_NO_EVENT_WAIT 20/*milliseconds ( 1 -- 999 ) */
+#define WATCHDOG_INTERVAL 10/*milliseconds ( 1 -- 999 ) */
+#define DEFAULT_TIMER_TICK 0/*milliseconds ( 0 -- 999 ) */
+#define NO_THREAD_INTERRUPT_TIME 100/*milliseconds ( 1 -- 999 ) */
static int event_loop_max = DEFAULT_EVENT_LOOP_MAX;
static int no_event_tick = DEFAULT_NO_EVENT_TICK;
@@ -673,9 +570,6 @@ struct tcltkip {
#if TCL_NAMESPACE_DEBUG
Tcl_Namespace *default_ns; /* default namespace */
#endif
-#ifdef RUBY_VM
- Tcl_ThreadId tk_thread_id; /* native thread ID of Tcl interpreter */
-#endif
int has_orig_exit; /* has original 'exit' command ? */
Tcl_CmdInfo orig_exit_info; /* command info of original 'exit' command */
int ref_count; /* reference count of rbtk_preserve_ip call */
@@ -711,9 +605,9 @@ deleted_ip(ptr)
#endif
) {
DUMP1("ip is deleted");
- return 1;
+ return Qtrue;
}
- return 0;
+ return Qfalse;
}
/* increment/decrement reference count of tcltkip */
@@ -866,10 +760,6 @@ tcltkip_init_tk(interp)
}
#endif
-#ifdef RUBY_VM
- ptr->tk_thread_id = Tcl_GetCurrentThread();
-#endif
-
return Qnil;
}
@@ -877,7 +767,6 @@ tcltkip_init_tk(interp)
/* treat excetiopn on Tcl side */
static VALUE rbtk_pending_exception;
static int rbtk_eventloop_depth = 0;
-static int rbtk_internal_eventloop_handler = 0;
static int
@@ -887,9 +776,7 @@ pending_exception_check0()
if (!NIL_P(exc) && rb_obj_is_kind_of(exc, rb_eException)) {
DUMP1("find a pending exception");
- if (rbtk_eventloop_depth > 0
- || rbtk_internal_eventloop_handler > 0
- ) {
+ if (rbtk_eventloop_depth > 0) {
return 1; /* pending */
} else {
rbtk_pending_exception = Qnil;
@@ -922,9 +809,7 @@ pending_exception_check1(thr_crit_bup, ptr)
if (!NIL_P(exc) && rb_obj_is_kind_of(exc, rb_eException)) {
DUMP1("find a pending exception");
- if (rbtk_eventloop_depth > 0
- || rbtk_internal_eventloop_handler > 0
- ) {
+ if (rbtk_eventloop_depth > 0) {
return 1; /* pending */
} else {
rbtk_pending_exception = Qnil;
@@ -963,10 +848,8 @@ call_original_exit(ptr, state)
int thr_crit_bup;
Tcl_CmdInfo *info;
#if TCL_MAJOR_VERSION >= 8
- Tcl_Obj *cmd_obj;
Tcl_Obj *state_obj;
#endif
- DUMP1("original_exit is called");
if (!(ptr->has_orig_exit)) return;
@@ -984,55 +867,20 @@ call_original_exit(ptr, state)
if (info->isNativeObjectProc) {
Tcl_Obj **argv;
-#define USE_RUBY_ALLOC 0
-#if USE_RUBY_ALLOC
argv = (Tcl_Obj **)ALLOC_N(Tcl_Obj *, 3);
-#else /* not USE_RUBY_ALLOC */
- argv = (Tcl_Obj **)ckalloc(sizeof(Tcl_Obj *) * 3);
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)argv); /* XXXXXXXX */
-#endif
-#endif
- cmd_obj = Tcl_NewStringObj("exit", 4);
- Tcl_IncrRefCount(cmd_obj);
-
- argv[0] = cmd_obj;
+ argv[0] = Tcl_NewStringObj("exit", 4);
argv[1] = state_obj;
argv[2] = (Tcl_Obj *)NULL;
ptr->return_value
= (*(info->objProc))(info->objClientData, ptr->ip, 2, argv);
- Tcl_DecrRefCount(cmd_obj);
-
-#if USE_RUBY_ALLOC
free(argv);
-#else /* not USE_RUBY_ALLOC */
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)argv, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)argv); /* XXXXXXXX */
-#else
- /* free(argv); */
- ckfree((char*)argv);
-#endif
-#endif
-#endif
-#undef USE_RUBY_ALLOC
} else {
/* string interface */
char **argv;
-#define USE_RUBY_ALLOC 0
-#if USE_RUBY_ALLOC
- argv = (char **)ALLOC_N(char *, 3); /* XXXXXXXXXX */
-#else /* not USE_RUBY_ALLOC */
- argv = (char **)ckalloc(sizeof(char *) * 3);
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)argv); /* XXXXXXXX */
-#endif
-#endif
+ argv = (char **)ALLOC_N(char *, 3);
argv[0] = "exit";
/* argv[1] = Tcl_GetString(state_obj); */
argv[1] = Tcl_GetStringFromObj(state_obj, (int*)NULL);
@@ -1041,21 +889,7 @@ call_original_exit(ptr, state)
ptr->return_value = (*(info->proc))(info->clientData, ptr->ip,
2, (CONST84 char **)argv);
-#if USE_RUBY_ALLOC
free(argv);
-#else /* not USE_RUBY_ALLOC */
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)argv, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)argv); /* XXXXXXXX */
-#else
- /* free(argv); */
- ckfree((char*)argv);
-#endif
-#endif
-#endif
-#undef USE_RUBY_ALLOC
}
Tcl_DecrRefCount(state_obj);
@@ -1064,40 +898,17 @@ call_original_exit(ptr, state)
{
/* string interface */
char **argv;
-#define USE_RUBY_ALLOC 0
-#if USE_RUBY_ALLOC
argv = (char **)ALLOC_N(char *, 3);
-#else /* not USE_RUBY_ALLOC */
- argv = (char **)ckalloc(sizeof(char *) * 3);
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)argv); /* XXXXXXXX */
-#endif
-#endif
argv[0] = "exit";
- argv[1] = RSTRING_PTR(rb_fix2str(INT2NUM(state), 10));
+ argv[1] = RSTRING(rb_fix2str(INT2NUM(state), 10))->ptr;
argv[2] = (char *)NULL;
ptr->return_value = (*(info->proc))(info->clientData, ptr->ip,
2, argv);
-#if USE_RUBY_ALLOC
free(argv);
-#else /* not USE_RUBY_ALLOC */
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)argv, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)argv); /* XXXXXXXX */
-#else
- /* free(argv); */
- ckfree(argv);
-#endif
-#endif
-#endif
-#undef USE_RUBY_ALLOC
}
#endif
- DUMP1("complete original_exit");
rb_thread_critical = thr_crit_bup;
}
@@ -1138,53 +949,6 @@ _timer_for_tcl(clientData)
/* tick_counter += event_loop_max; */
}
-#ifdef RUBY_VM
-#if USE_TOGGLE_WINDOW_MODE_FOR_IDLE
-static int
-toggle_eventloop_window_mode_for_idle()
-{
- if (window_event_mode & TCL_IDLE_EVENTS) {
- /* idle -> event */
- window_event_mode |= TCL_WINDOW_EVENTS;
- window_event_mode &= ~TCL_IDLE_EVENTS;
- return 1;
- } else {
- /* event -> idle */
- window_event_mode |= TCL_IDLE_EVENTS;
- window_event_mode &= ~TCL_WINDOW_EVENTS;
- return 0;
- }
-}
-#endif
-#endif
-
-static VALUE
-set_eventloop_window_mode(self, mode)
- VALUE self;
- VALUE mode;
-{
- rb_secure(4);
-
- if (RTEST(mode)) {
- window_event_mode = ~0;
- } else {
- window_event_mode = ~(TCL_WINDOW_EVENTS | TCL_IDLE_EVENTS);
- }
-
- return mode;
-}
-
-static VALUE
-get_eventloop_window_mode(self)
- VALUE self;
-{
- if ( ~window_event_mode ) {
- return Qfalse;
- } else {
- return Qtrue;
- }
-}
-
static VALUE
set_eventloop_tick(self, tick)
VALUE self;
@@ -1373,15 +1137,15 @@ set_max_block_time(self, time)
case T_BIGNUM:
/* time is micro-second value */
divmod = rb_funcall(time, rb_intern("divmod"), 1, LONG2NUM(1000000));
- tcl_time.sec = NUM2LONG(RARRAY_PTR(divmod)[0]);
- tcl_time.usec = NUM2LONG(RARRAY_PTR(divmod)[1]);
+ tcl_time.sec = NUM2LONG(RARRAY(divmod)->ptr[0]);
+ tcl_time.usec = NUM2LONG(RARRAY(divmod)->ptr[1]);
break;
case T_FLOAT:
/* time is second value */
divmod = rb_funcall(time, rb_intern("divmod"), 1, INT2FIX(1));
- tcl_time.sec = NUM2LONG(RARRAY_PTR(divmod)[0]);
- tcl_time.usec = (long)(NUM2DBL(RARRAY_PTR(divmod)[1]) * 1000000);
+ tcl_time.sec = NUM2LONG(RARRAY(divmod)->ptr[0]);
+ tcl_time.usec = (long)(NUM2DBL(RARRAY(divmod)->ptr[1]) * 1000000);
default:
{
@@ -1465,10 +1229,8 @@ ip_evloop_abort_on_exc_set(self, val)
}
static VALUE
-lib_num_of_mainwindows_core(self, argc, argv)
+lib_num_of_mainwindows(self)
VALUE self;
- int argc; /* dummy */
- VALUE *argv; /* dummy */
{
if (tk_stubs_init_p()) {
return INT2FIX(Tk_GetNumMainWindows());
@@ -1477,41 +1239,7 @@ lib_num_of_mainwindows_core(self, argc, argv)
}
}
-static VALUE
-lib_num_of_mainwindows(self)
- VALUE self;
-{
-#ifdef RUBY_VM /* Ruby 1.9+ !!! */
- return tk_funcall(lib_num_of_mainwindows_core, 0, (VALUE*)NULL, self);
-#else
- return lib_num_of_mainwindows_core(self, 0, (VALUE*)NULL);
-#endif
-}
-
-
-#ifdef RUBY_VM /* Ruby 1.9+ !!! */
-static VALUE
-call_DoOneEvent_core(flag_val)
- VALUE flag_val;
-{
- int flag;
-
- flag = FIX2INT(flag_val);
- if (Tcl_DoOneEvent(flag)) {
- return Qtrue;
- } else {
- return Qfalse;
- }
-}
-
-static VALUE
-call_DoOneEvent(flag_val)
- VALUE flag_val;
-{
- return tk_funcall(call_DoOneEvent_core, 0, (VALUE*)NULL, flag_val);
-}
-#else /* Ruby 1.8- */
static VALUE
call_DoOneEvent(flag_val)
VALUE flag_val;
@@ -1525,8 +1253,6 @@ call_DoOneEvent(flag_val)
return Qfalse;
}
}
-#endif
-
static VALUE
eventloop_sleep(dummy)
@@ -1538,77 +1264,22 @@ eventloop_sleep(dummy)
t.tv_usec = (time_t)(no_event_wait*1000.0);
#ifdef HAVE_NATIVETHREAD
-#ifdef RUBY_VM
-#if 0
- if (!ruby_native_thread_p()) {
- rb_bug("cross-thread violation on eventloop_sleep()");
- }
-#endif
-#else
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on eventloop_sleep()");
}
#endif
-#endif
- DUMP2("eventloop_sleep: rb_thread_wait_for() at thread : %lx", rb_thread_current());
rb_thread_wait_for(t);
- DUMP2("eventloop_sleep: finish at thread : %lx", rb_thread_current());
#ifdef HAVE_NATIVETHREAD
-#ifdef RUBY_VM
-#if 0
- if (!ruby_native_thread_p()) {
- rb_bug("cross-thread violation on eventloop_sleep()");
- }
-#endif
-#else
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on eventloop_sleep()");
}
#endif
-#endif
return Qnil;
}
-#define USE_EVLOOP_THREAD_ALONE_CHECK_FLAG 0
-
-#if USE_EVLOOP_THREAD_ALONE_CHECK_FLAG
-static int
-get_thread_alone_check_flag()
-{
-#ifdef RUBY_VM
- return 0;
-#else
- set_tcltk_version();
-
- if (tcltk_version.major < 8) {
- /* Tcl/Tk 7.x */
- return 1;
- } else if (tcltk_version.major == 8) {
- if (tcltk_version.minor < 5) {
- /* Tcl/Tk 8.0 - 8.4 */
- return 1;
- } else if (tcltk_version.minor == 5) {
- if (tcltk_version.type < TCL_FINAL_RELEASE) {
- /* Tcl/Tk 8.5a? - 8.5b? */
- return 1;
- } else {
- /* Tcl/Tk 8.5.x */
- return 0;
- }
- } else {
- /* Tcl/Tk 8.6 - 8.9 ?? */
- return 0;
- }
- } else {
- /* Tcl/Tk 9+ ?? */
- return 0;
- }
-#endif
-}
-#endif
static int
lib_eventloop_core(check_root, update_flag, check_var, interp)
@@ -1624,9 +1295,7 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
int thr_crit_bup;
int status;
int depth = rbtk_eventloop_depth;
-#if USE_EVLOOP_THREAD_ALONE_CHECK_FLAG
- int thread_alone_check_flag = 1;
-#endif
+
if (update_flag) DUMP1("update loop start!!");
@@ -1645,25 +1314,15 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
timer_token = (Tcl_TimerToken)NULL;
}
-#if USE_EVLOOP_THREAD_ALONE_CHECK_FLAG
- /* version check */
- thread_alone_check_flag = get_thread_alone_check_flag();
-#endif
-
for(;;) {
-#if USE_EVLOOP_THREAD_ALONE_CHECK_FLAG
- if (thread_alone_check_flag && rb_thread_alone()) {
-#else
if (rb_thread_alone()) {
-#endif
DUMP1("no other thread");
event_loop_wait_event = 0;
if (update_flag) {
event_flag = update_flag | TCL_DONT_WAIT; /* for safety */
} else {
- event_flag = TCL_ALL_EVENTS;
- /* event_flag = TCL_ALL_EVENTS | TCL_DONT_WAIT; */
+ event_flag = TCL_ALL_EVENTS;
}
if (timer_tick == 0 && update_flag == 0) {
@@ -1690,19 +1349,11 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
if (status) {
switch (status) {
case TAG_RAISE:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
rbtk_pending_exception
= rb_exc_new2(rb_eException, "unknown exception");
} else {
-#ifdef RUBY_VM
- rbtk_pending_exception = rb_errinfo();
-#else
rbtk_pending_exception = ruby_errinfo;
-#endif
if (!NIL_P(rbtk_pending_exception)) {
if (rbtk_eventloop_depth == 0) {
@@ -1717,18 +1368,10 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
break;
case TAG_FATAL:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
rb_exc_raise(rb_exc_new2(rb_eFatal, "FATAL"));
} else {
-#ifdef RUBY_VM
- rb_exc_raise(rb_errinfo());
-#else
rb_exc_raise(ruby_errinfo);
-#endif
}
}
}
@@ -1819,56 +1462,19 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
if (NIL_P(eventloop_thread) || current == eventloop_thread) {
int st;
int status;
-#ifdef RUBY_VM
- if (update_flag) {
- st = RTEST(rb_protect(call_DoOneEvent,
- INT2FIX(event_flag), &status));
- } else {
- st = RTEST(rb_protect(call_DoOneEvent,
- INT2FIX(event_flag & window_event_mode),
- &status));
-#if USE_TOGGLE_WINDOW_MODE_FOR_IDLE
- if (!st) {
- if (toggle_eventloop_window_mode_for_idle()) {
- /* idle-mode -> event-mode*/
- tick_counter = event_loop_max;
- } else {
- /* event-mode -> idle-mode */
- tick_counter = 0;
- }
- }
-#endif
- }
-#else
+
/* st = Tcl_DoOneEvent(event_flag); */
st = RTEST(rb_protect(call_DoOneEvent,
INT2FIX(event_flag), &status));
-#endif
-
-#if CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE
- if (have_rb_thread_waiting_for_value) {
- have_rb_thread_waiting_for_value = 0;
- rb_thread_schedule();
- }
-#endif
-
if (status) {
switch (status) {
case TAG_RAISE:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
rbtk_pending_exception
= rb_exc_new2(rb_eException,
"unknown exception");
} else {
-#ifdef RUBY_VM
- rbtk_pending_exception = rb_errinfo();
-#else
rbtk_pending_exception = ruby_errinfo;
-#endif
if (!NIL_P(rbtk_pending_exception)) {
if (rbtk_eventloop_depth == 0) {
@@ -1883,18 +1489,10 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
break;
case TAG_FATAL:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
rb_exc_raise(rb_exc_new2(rb_eFatal, "FATAL"));
} else {
-#ifdef RUBY_VM
- rb_exc_raise(rb_errinfo());
-#else
rb_exc_raise(ruby_errinfo);
-#endif
}
}
}
@@ -1938,26 +1536,17 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
tick_counter += no_event_tick;
/* rb_thread_wait_for(t); */
-
rb_protect(eventloop_sleep, Qnil, &status);
if (status) {
switch (status) {
case TAG_RAISE:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
rbtk_pending_exception
= rb_exc_new2(rb_eException,
"unknown exception");
} else {
-#ifdef RUBY_VM
- rbtk_pending_exception = rb_errinfo();
-#else
rbtk_pending_exception = ruby_errinfo;
-#endif
if (!NIL_P(rbtk_pending_exception)) {
if (rbtk_eventloop_depth == 0) {
@@ -1972,19 +1561,11 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
break;
case TAG_FATAL:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
rb_exc_raise(rb_exc_new2(rb_eFatal,
"FATAL"));
} else {
-#ifdef RUBY_VM
- rb_exc_raise(rb_errinfo());
-#else
rb_exc_raise(ruby_errinfo);
-#endif
}
}
}
@@ -1993,8 +1574,7 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
} else {
DUMP2("sleep eventloop %lx", current);
DUMP2("eventloop thread is %lx", eventloop_thread);
- /* rb_thread_stop(); */
- rb_thread_sleep_forever();
+ rb_thread_stop();
}
if (!NIL_P(watchdog_thread) && eventloop_thread != current) {
@@ -2039,17 +1619,10 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
break; /* switch to other thread */
}
}
-
- DUMP1("thread scheduling");
- rb_thread_schedule();
}
DUMP1("trap check & thread scheduling");
-#ifdef RUBY_VM
- /* if (update_flag == 0) CHECK_INTS; */ /*XXXXXXXXXXXXX TODO !!!! */
-#else
if (update_flag == 0) CHECK_INTS;
-#endif
}
return 1;
@@ -2096,35 +1669,19 @@ lib_eventloop_main(args)
switch (status) {
case TAG_RAISE:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
rbtk_pending_exception
= rb_exc_new2(rb_eException, "unknown exception");
} else {
-#ifdef RUBY_VM
- rbtk_pending_exception = rb_errinfo();
-#else
rbtk_pending_exception = ruby_errinfo;
-#endif
}
return Qnil;
case TAG_FATAL:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL");
} else {
-#ifdef RUBY_VM
- rbtk_pending_exception = rb_errinfo();
-#else
rbtk_pending_exception = ruby_errinfo;
-#endif
}
return Qnil;
}
@@ -2148,7 +1705,6 @@ lib_eventloop_ensure(args)
rb_thread_critical = ptr->thr_crit_bup;
free(ptr);
- /* ckfree((char*)ptr); */
return Qnil;
}
@@ -2170,8 +1726,7 @@ lib_eventloop_ensure(args)
break;
}
- /* if (RTEST(rb_funcall(eventloop_thread, ID_alive_p, 0, 0))) { */
- if (RTEST(rb_thread_alive_p(eventloop_thread))) {
+ if (RTEST(rb_funcall(eventloop_thread, ID_alive_p, 0, 0))) {
DUMP2("eventloop-enshure: wake up parent %lx", eventloop_thread);
rb_thread_wakeup(eventloop_thread);
@@ -2179,16 +1734,9 @@ lib_eventloop_ensure(args)
}
}
-#ifdef RUBY_VM
- if (NIL_P(eventloop_thread)) {
- tk_eventloop_thread_id = (Tcl_ThreadId) 0;
- }
-#endif
-
rb_thread_critical = ptr->thr_crit_bup;
free(ptr);
- /* ckfree((char*)ptr);*/
DUMP2("finish current eventloop %lx", current_evloop);
return Qnil;
@@ -2203,14 +1751,10 @@ lib_eventloop_launcher(check_root, update_flag, check_var, interp)
{
volatile VALUE parent_evloop = eventloop_thread;
struct evloop_params *args = ALLOC(struct evloop_params);
- /* struct evloop_params *args = (struct evloop_params *)ckalloc(sizeof(struct evloop_params)); */
tcl_stubs_check();
eventloop_thread = rb_thread_current();
-#ifdef RUBY_VM
- tk_eventloop_thread_id = Tcl_GetCurrentThread();
-#endif
if (parent_evloop == eventloop_thread) {
DUMP2("eventloop: recursive call on %lx", parent_evloop);
@@ -2361,9 +1905,6 @@ lib_watchdog_ensure(arg)
VALUE arg;
{
eventloop_thread = Qnil; /* stop eventloops */
-#ifdef RUBY_VM
- tk_eventloop_thread_id = (Tcl_ThreadId) 0;
-#endif
return Qnil;
}
@@ -2375,11 +1916,6 @@ lib_mainloop_watchdog(argc, argv, self)
{
VALUE check_rootwidget;
-#ifdef RUBY_VM
- rb_raise(rb_eNotImpError,
- "eventloop_watchdog is not implemented on Ruby VM.");
-#endif
-
if (rb_scan_args(argc, argv, "01", &check_rootwidget) == 0) {
check_rootwidget = Qtrue;
} else if (RTEST(check_rootwidget)) {
@@ -2474,10 +2010,8 @@ lib_thread_callback(argc, argv, self)
}
q = (struct thread_call_proc_arg *)ALLOC(struct thread_call_proc_arg);
- /* q = (struct thread_call_proc_arg *)ckalloc(sizeof(struct thread_call_proc_arg)); */
q->proc = proc;
q->done = (int*)ALLOC(int);
- /* q->done = (int*)ckalloc(sizeof(int)); */
*(q->done) = 0;
/* create call-proc thread */
@@ -2489,8 +2023,7 @@ lib_thread_callback(argc, argv, self)
foundEvent = RTEST(lib_eventloop_launcher(/* not check root-widget */0, 0,
q->done, (Tcl_Interp*)NULL));
- /* if (RTEST(rb_funcall(th, ID_alive_p, 0))) { */
- if (RTEST(rb_thread_alive_p(th))) {
+ if (RTEST(rb_funcall(th, ID_alive_p, 0))) {
rb_funcall(th, ID_kill, 0);
ret = Qnil;
} else {
@@ -2499,21 +2032,12 @@ lib_thread_callback(argc, argv, self)
free(q->done);
free(q);
- /* ckfree((char*)q->done); */
- /* ckfree((char*)q); */
if (NIL_P(rbtk_pending_exception)) {
-#ifdef RUBY_VM
- /* return rb_errinfo(); */
- if (status) {
- rb_exc_raise(rb_errinfo());
- }
-#else
/* return ruby_errinfo; */
if (status) {
rb_exc_raise(ruby_errinfo);
}
-#endif
} else {
VALUE exc = rbtk_pending_exception;
rbtk_pending_exception = Qnil;
@@ -2631,35 +2155,28 @@ ip_set_exc_message(interp, exc)
if (NIL_P(enc)) {
encoding = (Tcl_Encoding)NULL;
} else if (TYPE(enc) == T_STRING) {
- /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); */
- encoding = Tcl_GetEncoding((Tcl_Interp*)NULL, RSTRING_PTR(enc));
+ encoding = Tcl_GetEncoding(interp, RSTRING(enc)->ptr);
} else {
enc = rb_funcall(enc, ID_to_s, 0, 0);
- /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); */
- encoding = Tcl_GetEncoding((Tcl_Interp*)NULL, RSTRING_PTR(enc));
+ encoding = Tcl_GetEncoding(interp, RSTRING(enc)->ptr);
}
/* to avoid a garbled error message dialog */
- /* buf = ALLOC_N(char, (RSTRING(msg)->len)+1);*/
- /* memcpy(buf, RSTRING(msg)->ptr, RSTRING(msg)->len);*/
- /* buf[RSTRING(msg)->len] = 0; */
- buf = ALLOC_N(char, RSTRING_LEN(msg)+1);
- /* buf = ckalloc(sizeof(char)*((RSTRING_LEN(msg))+1)); */
- memcpy(buf, RSTRING_PTR(msg), RSTRING_LEN(msg));
- buf[RSTRING_LEN(msg)] = 0;
+ buf = ALLOC_N(char, (RSTRING(msg)->len)+1);
+ memcpy(buf, RSTRING(msg)->ptr, RSTRING(msg)->len);
+ buf[RSTRING(msg)->len] = 0;
Tcl_DStringInit(&dstr);
Tcl_DStringFree(&dstr);
- Tcl_ExternalToUtfDString(encoding, buf, RSTRING_LEN(msg), &dstr);
+ Tcl_ExternalToUtfDString(encoding, buf, RSTRING(msg)->len, &dstr);
Tcl_AppendResult(interp, Tcl_DStringValue(&dstr), (char*)NULL);
DUMP2("error message:%s", Tcl_DStringValue(&dstr));
Tcl_DStringFree(&dstr);
free(buf);
- /* ckfree(buf); */
#else /* TCL_VERSION <= 8.0 */
- Tcl_AppendResult(interp, RSTRING_PTR(msg), (char*)NULL);
+ Tcl_AppendResult(interp, RSTRING(msg)->ptr, (char*)NULL);
#endif
rb_thread_critical = thr_crit_bup;
@@ -2704,15 +2221,12 @@ tcl_protect_core(interp, proc, data) /* should not raise exception */
int status = 0;
int thr_crit_bup = rb_thread_critical;
- Tcl_ResetResult(interp);
-
rb_thread_critical = Qfalse;
ret = rb_protect(proc, data, &status);
rb_thread_critical = Qtrue;
if (status) {
char *buf;
- VALUE old_gc;
- volatile VALUE type, str;
+ VALUE old_gc, type, str;
old_gc = rb_gc_disable();
@@ -2728,104 +2242,58 @@ tcl_protect_core(interp, proc, data) /* should not raise exception */
goto error;
error:
str = rb_str_new2("LocalJumpError: ");
-#ifdef RUBY_VM
- rb_str_append(str, rb_obj_as_string(rb_errinfo()));
-#else
rb_str_append(str, rb_obj_as_string(ruby_errinfo));
-#endif
exc = rb_exc_new3(type, str);
break;
case TAG_RETRY:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
DUMP1("rb_protect: retry");
exc = rb_exc_new2(eTkCallbackRetry, "retry jump error");
} else {
-#ifdef RUBY_VM
- exc = rb_errinfo();
-#else
exc = ruby_errinfo;
-#endif
}
break;
case TAG_REDO:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
DUMP1("rb_protect: redo");
exc = rb_exc_new2(eTkCallbackRedo, "redo jump error");
} else {
-#ifdef RUBY_VM
- exc = rb_errinfo();
-#else
exc = ruby_errinfo;
-#endif
}
break;
case TAG_RAISE:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
exc = rb_exc_new2(rb_eException, "unknown exception");
} else {
-#ifdef RUBY_VM
- exc = rb_errinfo();
-#else
exc = ruby_errinfo;
-#endif
}
break;
case TAG_FATAL:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
exc = rb_exc_new2(rb_eFatal, "FATAL");
} else {
-#ifdef RUBY_VM
- exc = rb_errinfo();
-#else
exc = ruby_errinfo;
-#endif
}
break;
case TAG_THROW:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
DUMP1("rb_protect: throw");
exc = rb_exc_new2(eTkCallbackThrow, "throw jump error");
} else {
-#ifdef RUBY_VM
- exc = rb_errinfo();
-#else
exc = ruby_errinfo;
-#endif
}
break;
default:
buf = ALLOC_N(char, 256);
- /* buf = ckalloc(sizeof(char) * 256); */
sprintf(buf, "unknown loncaljmp status %d", status);
exc = rb_exc_new2(rb_eException, buf);
free(buf);
- /* ckfree(buf); */
break;
}
@@ -2903,12 +2371,12 @@ tcl_protect_core(interp, proc, data) /* should not raise exception */
ret = TkStringValue(ret);
DUMP1("Tcl_AppendResult");
- Tcl_AppendResult(interp, RSTRING_PTR(ret), (char *)NULL);
+ Tcl_AppendResult(interp, RSTRING(ret)->ptr, (char *)NULL);
rb_thread_critical = thr_crit_bup;
}
- DUMP2("(result) %s", NIL_P(ret) ? "nil" : RSTRING_PTR(ret));
+ DUMP2("(result) %s", NIL_P(ret) ? "nil" : RSTRING(ret)->ptr);
return TCL_OK;
}
@@ -2923,18 +2391,10 @@ tcl_protect(interp, proc, data)
int code;
#ifdef HAVE_NATIVETHREAD
-#ifdef RUBY_VM
-#if 0
- if (!ruby_native_thread_p()) {
- rb_bug("cross-thread violation on tcl_protect()");
- }
-#endif
-#else
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on tcl_protect()");
}
#endif
-#endif
rb_trap_immediate = 0;
code = tcl_protect_core(interp, proc, data);
@@ -2996,7 +2456,6 @@ ip_ruby_eval(clientData, interp, argc, argv)
str = Tcl_GetStringFromObj(argv[1], &len);
arg = ALLOC_N(char, len + 1);
- /* arg = ckalloc(sizeof(char) * (len + 1)); */
memcpy(arg, str, len);
arg[len] = 0;
@@ -3014,7 +2473,6 @@ ip_ruby_eval(clientData, interp, argc, argv)
#if TCL_MAJOR_VERSION >= 8
free(arg);
- /* ckfree(arg); */
#endif
return code;
@@ -3039,96 +2497,6 @@ ip_ruby_cmd_core(arg)
return ret;
}
-#define SUPPORT_NESTED_CONST_AS_IP_RUBY_CMD_RECEIVER 1
-
-static VALUE
-ip_ruby_cmd_receiver_const_get(name)
- char *name;
-{
- volatile VALUE klass = rb_cObject;
- char *head, *tail;
- int state;
-
-#if SUPPORT_NESTED_CONST_AS_IP_RUBY_CMD_RECEIVER
- klass = rb_eval_string_protect(name, &state);
- if (state) {
- return Qnil;
- } else {
- return klass;
- }
-#else
- return rb_const_get(klass, rb_intern(name));
-#endif
-
- /* TODO!!!!!! */
- /* support nest of classes/modules */
-
- /* return rb_eval_string(name); */
- /* return rb_eval_string_protect(name, &state); */
-
-#if 0 /* doesn't work!! (fail to autoload?) */
- /* duplicate */
- head = name = strdup(name);
-
- /* has '::' at head ? */
- if (*head == ':') head += 2;
- tail = head;
-
- /* search */
- while(*tail) {
- if (*tail == ':') {
- *tail = '\0';
- klass = rb_const_get(klass, rb_intern(head));
- tail += 2;
- head = tail;
- } else {
- tail++;
- }
- }
-
- free(name);
- return rb_const_get(klass, rb_intern(head));
-#endif
-}
-
-static VALUE
-ip_ruby_cmd_receiver_get(str)
- char *str;
-{
- volatile VALUE receiver;
- volatile VALUE klass = rb_cObject;
- int state;
-
- if (str[0] == ':' || ('A' <= str[0] && str[0] <= 'Z')) {
- /* class | module | constant */
-#if SUPPORT_NESTED_CONST_AS_IP_RUBY_CMD_RECEIVER
- receiver = ip_ruby_cmd_receiver_const_get(str);
-#else
- receiver = rb_protect(ip_ruby_cmd_receiver_const_get, (VALUE)str, &state);
- if (state) return Qnil;
-#endif
- } else if (str[0] == '$') {
- /* global variable */
- receiver = rb_gv_get(str);
- } else {
- /* global variable omitted '$' */
- char *buf;
- int len;
-
- len = strlen(str);
- buf = ALLOC_N(char, len + 2);
- /* buf = ckalloc(sizeof(char) * (len + 2)); */
- buf[0] = '$';
- memcpy(buf + 1, str, len);
- buf[len + 1] = 0;
- receiver = rb_gv_get(buf);
- free(buf);
- /* ckfree(buf); */
- }
-
- return receiver;
-}
-
/* ruby_cmd receiver method arg ... */
static int
#if TCL_MAJOR_VERSION >= 8
@@ -3174,6 +2542,9 @@ ip_ruby_cmd(clientData, interp, argc, argv)
#endif
}
+ /* allocate */
+ arg = ALLOC(struct cmd_body_arg);
+
/* get arguments from Tcl objects */
thr_crit_bup = rb_thread_critical;
rb_thread_critical = Qtrue;
@@ -3186,8 +2557,24 @@ ip_ruby_cmd(clientData, interp, argc, argv)
str = argv[1];
#endif
DUMP2("receiver:%s",str);
- /* receiver = rb_protect(ip_ruby_cmd_receiver_get, (VALUE)str, &code); */
- receiver = ip_ruby_cmd_receiver_get(str);
+ if (str[0] == ':' || ('A' <= str[0] && str[0] <= 'Z')) {
+ /* class | module | constant */
+ receiver = rb_const_get(rb_cObject, rb_intern(str));
+ } else if (str[0] == '$') {
+ /* global variable */
+ receiver = rb_gv_get(str);
+ } else {
+ /* global variable omitted '$' */
+ char *buf;
+
+ len = strlen(str);
+ buf = ALLOC_N(char, len + 2);
+ buf[0] = '$';
+ memcpy(buf + 1, str, len);
+ buf[len + 1] = 0;
+ receiver = rb_gv_get(buf);
+ free(buf);
+ }
if (NIL_P(receiver)) {
#if 0
rb_raise(rb_eArgError,
@@ -3198,7 +2585,6 @@ ip_ruby_cmd(clientData, interp, argc, argv)
str, "'", (char *)NULL);
rbtk_pending_exception = rb_exc_new2(rb_eArgError,
Tcl_GetStringResult(interp));
- if (old_gc == Qfalse) rb_gc_enable();
return TCL_ERROR;
#endif
}
@@ -3213,36 +2599,21 @@ ip_ruby_cmd(clientData, interp, argc, argv)
/* get args */
args = rb_ary_new2(argc - 2);
-#ifdef RUBY_VM
-#else
RARRAY(args)->len = 0;
-#endif
for(i = 3; i < argc; i++) {
#if TCL_MAJOR_VERSION >= 8
str = Tcl_GetStringFromObj(argv[i], &len);
DUMP2("arg:%s",str);
-#ifdef RUBY_VM
- rb_ary_push(args, rb_tainted_str_new(str, len));
-#else
RARRAY(args)->ptr[RARRAY(args)->len++] = rb_tainted_str_new(str, len);
-#endif
#else /* TCL_MAJOR_VERSION < 8 */
DUMP2("arg:%s",argv[i]);
-#ifdef RUBY_VM
- rb_ary_push(args, rb_tainted_str_new2(argv[i]));
-#else
RARRAY(args)->ptr[RARRAY(args)->len++] = rb_tainted_str_new2(argv[i]);
#endif
-#endif
}
if (old_gc == Qfalse) rb_gc_enable();
rb_thread_critical = thr_crit_bup;
- /* allocate */
- arg = ALLOC(struct cmd_body_arg);
- /* arg = (struct cmd_body_arg *)ckalloc(sizeof(struct cmd_body_arg)); */
-
arg->receiver = receiver;
arg->method = method;
arg->args = args;
@@ -3251,7 +2622,6 @@ ip_ruby_cmd(clientData, interp, argc, argv)
code = tcl_protect(interp, ip_ruby_cmd_core, (VALUE)arg);
free(arg);
- /* ckfree((char*)arg); */
return code;
}
@@ -3429,20 +2799,10 @@ ip_rbUpdateCommand(clientData, interp, objc, objv)
return TCL_ERROR;
}
#ifdef HAVE_NATIVETHREAD
-#ifdef RUBY_VM
-#if 0
- if (!ruby_native_thread_p()) {
- rb_bug("cross-thread violation on ip_ruby_eval()");
- }
-#endif
-#else
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on ip_ruby_eval()");
}
#endif
-#endif
-
- Tcl_ResetResult(interp);
if (objc == 1) {
flags = TCL_DONT_WAIT;
@@ -3586,18 +2946,10 @@ ip_rb_threadUpdateCommand(clientData, interp, objc, objv)
return TCL_ERROR;
}
#ifdef HAVE_NATIVETHREAD
-#ifdef RUBY_VM
-#if 0
- if (!ruby_native_thread_p()) {
- rb_bug("cross-thread violation on ip_rb_threadUpdateCommand()");
- }
-#endif
-#else
if (!is_ruby_native_thread()) {
- rb_bug("cross-thread violation on ip_rb_threadUpdateCommand()");
+ rb_bug("cross-thread violation on ip_ruby_eval()");
}
#endif
-#endif
if (rb_thread_alone()
|| NIL_P(eventloop_thread) || eventloop_thread == current_thread) {
@@ -3612,8 +2964,6 @@ ip_rb_threadUpdateCommand(clientData, interp, objc, objv)
DUMP1("start Ruby's 'thread_update' body");
- Tcl_ResetResult(interp);
-
if (objc == 1) {
flags = TCL_DONT_WAIT;
@@ -3660,11 +3010,8 @@ ip_rb_threadUpdateCommand(clientData, interp, objc, objv)
DUMP1("pass argument check");
- /* param = (struct th_update_param *)Tcl_Alloc(sizeof(struct th_update_param)); */
- param = (struct th_update_param *)ckalloc(sizeof(struct th_update_param));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)param);
-#endif
+ param = (struct th_update_param *)Tcl_Alloc(sizeof(struct th_update_param));
+ Tcl_Preserve(param);
param->thread = current_thread;
param->done = 0;
@@ -3673,20 +3020,11 @@ ip_rb_threadUpdateCommand(clientData, interp, objc, objv)
while(!param->done) {
DUMP1("wait for complete idle proc");
- /* rb_thread_stop(); */
- rb_thread_sleep_forever();
+ rb_thread_stop();
}
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)param);
-#else
- /* Tcl_Free((char *)param); */
- ckfree((char *)param);
-#endif
-#endif
+ Tcl_Release(param);
+ Tcl_Free((char *)param);
DUMP1("finish Ruby's 'thread_update'");
return TCL_OK;
@@ -3785,20 +3123,10 @@ ip_rbVwaitCommand(clientData, interp, objc, objv)
Tcl_Preserve(interp);
#ifdef HAVE_NATIVETHREAD
-#ifdef RUBY_VM
-#if 0
- if (!ruby_native_thread_p()) {
- rb_bug("cross-thread violation on ip_rbVwaitCommand()");
- }
-#endif
-#else
if (!is_ruby_native_thread()) {
- rb_bug("cross-thread violation on ip_rbVwaitCommand()");
+ rb_bug("cross-thread violation on ip_ruby_eval()");
}
#endif
-#endif
-
- Tcl_ResetResult(interp);
if (objc != 2) {
#ifdef Tcl_WrongNumArgs
@@ -4035,7 +3363,6 @@ ip_rbTkWaitCommand(clientData, interp, objc, objv)
#endif
Tcl_Preserve(interp);
- Tcl_ResetResult(interp);
if (objc != 3) {
#ifdef Tcl_WrongNumArgs
@@ -4189,7 +3516,6 @@ ip_rbTkWaitCommand(clientData, interp, objc, objv)
thr_crit_bup = rb_thread_critical;
rb_thread_critical = Qtrue;
- /* This function works on the Tk eventloop thread only. */
if (!tk_stubs_init_p() || Tk_MainWindow(interp) == (Tk_Window)NULL) {
window = NULL;
} else {
@@ -4197,7 +3523,7 @@ ip_rbTkWaitCommand(clientData, interp, objc, objv)
}
if (window == NULL) {
- Tcl_AppendResult(interp, ": tkwait: ",
+ Tcl_AppendResult(interp, "tkwait: ",
"no main-window (not Tk application?)",
(char*)NULL);
rb_thread_critical = thr_crit_bup;
@@ -4286,8 +3612,7 @@ ip_rbTkWaitCommand(clientData, interp, objc, objv)
case TKWAIT_WINDOW:
thr_crit_bup = rb_thread_critical;
rb_thread_critical = Qtrue;
-
- /* This function works on the Tk eventloop thread only. */
+
if (!tk_stubs_init_p() || Tk_MainWindow(interp) == (Tk_Window)NULL) {
window = NULL;
} else {
@@ -4299,7 +3624,7 @@ ip_rbTkWaitCommand(clientData, interp, objc, objv)
#endif
if (window == NULL) {
- Tcl_AppendResult(interp, ": tkwait: ",
+ Tcl_AppendResult(interp, "tkwait: ",
"no main-window (not Tk application?)",
(char*)NULL);
rb_thread_critical = thr_crit_bup;
@@ -4392,7 +3717,7 @@ rb_threadVwaitProc(clientData, interp, name1, name2, flags)
} else {
param->done = 1;
}
- if (param->done != 0) rb_thread_wakeup(param->thread);
+ rb_thread_wakeup(param->thread);
return (char *)NULL;
}
@@ -4414,7 +3739,7 @@ rb_threadWaitVisibilityProc(clientData, eventPtr)
if (eventPtr->type == DestroyNotify) {
param->done = TKWAIT_MODE_DESTROY;
}
- if (param->done != 0) rb_thread_wakeup(param->thread);
+ rb_thread_wakeup(param->thread);
}
static void rb_threadWaitWindowProc _((ClientData, XEvent *));
@@ -4428,7 +3753,7 @@ rb_threadWaitWindowProc(clientData, eventPtr)
if (eventPtr->type == DestroyNotify) {
param->done = TKWAIT_MODE_DESTROY;
}
- if (param->done != 0) rb_thread_wakeup(param->thread);
+ rb_thread_wakeup(param->thread);
}
#if TCL_MAJOR_VERSION >= 8
@@ -4471,7 +3796,6 @@ ip_rb_threadVwaitCommand(clientData, interp, objc, objv)
}
Tcl_Preserve(interp);
- Tcl_ResetResult(interp);
if (objc != 2) {
#ifdef Tcl_WrongNumArgs
@@ -4506,11 +3830,8 @@ ip_rb_threadVwaitCommand(clientData, interp, objc, objv)
thr_crit_bup = rb_thread_critical;
rb_thread_critical = Qtrue;
- /* param = (struct th_vwait_param *)Tcl_Alloc(sizeof(struct th_vwait_param)); */
- param = (struct th_vwait_param *)ckalloc(sizeof(struct th_vwait_param));
-#if 1 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)param);
-#endif
+ param = (struct th_vwait_param *)Tcl_Alloc(sizeof(struct th_vwait_param));
+ Tcl_Preserve(param);
param->thread = current_thread;
param->done = 0;
@@ -4528,16 +3849,8 @@ ip_rb_threadVwaitCommand(clientData, interp, objc, objv)
rb_thread_critical = thr_crit_bup;
if (ret != TCL_OK) {
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 1 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)param);
-#else
- /* Tcl_Free((char *)param); */
- ckfree((char *)param);
-#endif
-#endif
+ Tcl_Release(param);
+ Tcl_Free((char *)param);
#if TCL_MAJOR_VERSION >= 8
Tcl_DecrRefCount(objv[1]);
@@ -4546,9 +3859,9 @@ ip_rb_threadVwaitCommand(clientData, interp, objc, objv)
return TCL_ERROR;
}
+ /* if (!param->done) { */
while(!param->done) {
- /* rb_thread_stop(); */
- rb_thread_sleep_forever();
+ rb_thread_stop();
}
thr_crit_bup = rb_thread_critical;
@@ -4560,16 +3873,8 @@ ip_rb_threadVwaitCommand(clientData, interp, objc, objv)
rb_threadVwaitProc, (ClientData) param);
}
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 1 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)param);
-#else
- /* Tcl_Free((char *)param); */
- ckfree((char *)param);
-#endif
-#endif
+ Tcl_Release(param);
+ Tcl_Free((char *)param);
rb_thread_critical = thr_crit_bup;
@@ -4628,8 +3933,6 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv)
Tcl_Preserve(interp);
Tcl_Preserve(tkwin);
- Tcl_ResetResult(interp);
-
if (objc != 3) {
#ifdef Tcl_WrongNumArgs
Tcl_WrongNumArgs(interp, 1, objv, "variable|visibility|window name");
@@ -4712,11 +4015,8 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv)
nameString = objv[2];
#endif
- /* param = (struct th_vwait_param *)Tcl_Alloc(sizeof(struct th_vwait_param)); */
- param = (struct th_vwait_param *)ckalloc(sizeof(struct th_vwait_param));
-#if 1 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)param);
-#endif
+ param = (struct th_vwait_param *)Tcl_Alloc(sizeof(struct th_vwait_param));
+ Tcl_Preserve(param);
param->thread = current_thread;
param->done = 0;
@@ -4740,16 +4040,8 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv)
rb_thread_critical = thr_crit_bup;
if (ret != TCL_OK) {
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 1 /* use Tcl_Preserve/Release */
Tcl_Release(param);
-#else
- /* Tcl_Free((char *)param); */
- ckfree((char *)param);
-#endif
-#endif
+ Tcl_Free((char *)param);
#if TCL_MAJOR_VERSION >= 8
Tcl_DecrRefCount(objv[2]);
@@ -4760,9 +4052,9 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv)
return TCL_ERROR;
}
+ /* if (!param->done) { */
while(!param->done) {
- /* rb_thread_stop(); */
- rb_thread_sleep_forever();
+ rb_thread_stop();
}
thr_crit_bup = rb_thread_critical;
@@ -4786,43 +4078,21 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv)
thr_crit_bup = rb_thread_critical;
rb_thread_critical = Qtrue;
-#if 0 /* variable 'tkwin' must keep the token of MainWindow */
if (!tk_stubs_init_p() || Tk_MainWindow(interp) == (Tk_Window)NULL) {
window = NULL;
} else {
window = Tk_NameToWindow(interp, nameString, tkwin);
}
-#else
- if (!tk_stubs_init_p() || tkwin == (Tk_Window)NULL) {
- window = NULL;
- } else {
- /* Tk_NameToWindow() returns right token on non-eventloop thread */
- Tcl_CmdInfo info;
- if (Tcl_GetCommandInfo(interp, ".", &info)) { /* check root */
- window = Tk_NameToWindow(interp, nameString, tkwin);
- } else {
- window = NULL;
- }
- }
-#endif
if (window == NULL) {
- Tcl_AppendResult(interp, ": thread_tkwait: ",
+ Tcl_AppendResult(interp, "thread_tkwait: ",
"no main-window (not Tk application?)",
(char*)NULL);
rb_thread_critical = thr_crit_bup;
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 1 /* use Tcl_Preserve/Release */
Tcl_Release(param);
-#else
- /* Tcl_Free((char *)param); */
- ckfree((char *)param);
-#endif
-#endif
+ Tcl_Free((char *)param);
#if TCL_MAJOR_VERSION >= 8
Tcl_DecrRefCount(objv[2]);
@@ -4839,10 +4109,15 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv)
rb_thread_critical = thr_crit_bup;
+ /* if (!param->done) { */
+ /*
+ while(!param->done) {
+ rb_thread_stop();
+ }
+ */
while(param->done != TKWAIT_MODE_VISIBILITY) {
if (param->done == TKWAIT_MODE_DESTROY) break;
- /* rb_thread_stop(); */
- rb_thread_sleep_forever();
+ rb_thread_stop();
}
thr_crit_bup = rb_thread_critical;
@@ -4866,16 +4141,8 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv)
Tcl_Release(window);
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 1 /* use Tcl_Preserve/Release */
Tcl_Release(param);
-#else
- /* Tcl_Free((char *)param); */
- ckfree((char *)param);
-#endif
-#endif
+ Tcl_Free((char *)param);
#if TCL_MAJOR_VERSION >= 8
Tcl_DecrRefCount(objv[2]);
@@ -4900,47 +4167,25 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv)
thr_crit_bup = rb_thread_critical;
rb_thread_critical = Qtrue;
-#if 0 /* variable 'tkwin' must keep the token of MainWindow */
if (!tk_stubs_init_p() || Tk_MainWindow(interp) == (Tk_Window)NULL) {
window = NULL;
} else {
window = Tk_NameToWindow(interp, nameString, tkwin);
}
-#else
- if (!tk_stubs_init_p() || tkwin == (Tk_Window)NULL) {
- window = NULL;
- } else {
- /* Tk_NameToWindow() returns right token on non-eventloop thread */
- Tcl_CmdInfo info;
- if (Tcl_GetCommandInfo(interp, ".", &info)) { /* check root */
- window = Tk_NameToWindow(interp, nameString, tkwin);
- } else {
- window = NULL;
- }
- }
-#endif
#if TCL_MAJOR_VERSION >= 8
Tcl_DecrRefCount(objv[2]);
#endif
if (window == NULL) {
- Tcl_AppendResult(interp, ": thread_tkwait: ",
+ Tcl_AppendResult(interp, "thread_tkwait: ",
"no main-window (not Tk application?)",
(char*)NULL);
rb_thread_critical = thr_crit_bup;
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 1 /* use Tcl_Preserve/Release */
Tcl_Release(param);
-#else
- /* Tcl_Free((char *)param); */
- ckfree((char *)param);
-#endif
-#endif
+ Tcl_Free((char *)param);
Tcl_Release(tkwin);
Tcl_Release(interp);
@@ -4954,9 +4199,14 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv)
rb_thread_critical = thr_crit_bup;
+ /* if (!param->done) { */
+ /*
+ while(!param->done) {
+ rb_thread_stop();
+ }
+ */
while(param->done != TKWAIT_MODE_DESTROY) {
- /* rb_thread_stop(); */
- rb_thread_sleep_forever();
+ rb_thread_stop();
}
Tcl_Release(window);
@@ -4974,16 +4224,8 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv)
break;
} /* end of 'switch' statement */
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 1 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)param);
-#else
- /* Tcl_Free((char *)param); */
- ckfree((char *)param);
-#endif
-#endif
+ Tcl_Release(param);
+ Tcl_Free((char *)param);
/*
* Clear out the interpreter's result, since it may have been set
@@ -5008,7 +4250,7 @@ ip_thread_vwait(self, var)
argv[0] = cmd_str;
argv[1] = var;
- return ip_invoke_with_position(2, argv, self, TCL_QUEUE_TAIL);
+ return ip_invoke_real(2, argv, self);
}
static VALUE
@@ -5024,7 +4266,7 @@ ip_thread_tkwait(self, mode, target)
argv[1] = mode;
argv[2] = target;
- return ip_invoke_with_position(3, argv, self, TCL_QUEUE_TAIL);
+ return ip_invoke_real(3, argv, self);
}
@@ -5214,43 +4456,23 @@ ip_finalize(ip)
Tcl_CreateCommand(ip, "ruby_cmd", ip_null_proc,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
#endif
- /*
- rb_thread_critical = thr_crit_bup;
- return;
- */
}
/* delete root widget */
-#if 1
+#if 0
DUMP1("check `destroy'");
if (Tcl_GetCommandInfo(ip, "destroy", &info)) {
- DUMP1("call `destroy .'");
- Tcl_GlobalEval(ip, "catch {destroy .}");
+ DUMP1("call `destroy'");
+ Tcl_GlobalEval(ip, "destroy .");
}
#endif
#if 1
DUMP1("destroy root widget");
if (tk_stubs_init_p() && Tk_MainWindow(ip) != (Tk_Window)NULL) {
- /*
- * On Ruby VM, this code piece may be not called, because
- * Tk_MainWindow() returns NULL on a native thread except
- * the thread which initialize Tk environment.
- * Of course, that is a problem. But maybe not so serious.
- * All widgets are destroyed when the Tcl interp is deleted.
- * At then, Ruby may raise exceptions on the delete hook
- * callbacks which registered for the deleted widgets, and
- * may fail to clear objects which depends on the widgets.
- * Although it is the problem, it is possibly avoidable by
- * rescuing exceptions and the finalize hook of the interp.
- */
- Tk_Window win = Tk_MainWindow(ip);
-
DUMP1("call Tk_DestroyWindow");
ruby_debug = Qfalse;
ruby_verbose = Qnil;
- if (! (((Tk_FakeWin*)win)->flags & TK_ALREADY_DEAD)) {
- Tk_DestroyWindow(win);
- }
+ Tk_DestroyWindow(Tk_MainWindow(ip));
ruby_debug = rb_debug_bup;
ruby_verbose = rb_verbose_bup;
}
@@ -5273,7 +4495,7 @@ ip_finalize(ip)
DUMP1("cancel after callbacks");
ruby_debug = Qfalse;
ruby_verbose = Qnil;
- Tcl_GlobalEval(ip, "catch {foreach id [after info] {after cancel $id}}");
+ Tcl_GlobalEval(ip, "foreach id [after info] {after cancel $id}");
ruby_debug = rb_debug_bup;
ruby_verbose = rb_verbose_bup;
}
@@ -5308,7 +4530,6 @@ ip_free(ptr)
DUMP2("slave IP(%lx) should not be deleted",
(unsigned long)ptr->ip);
free(ptr);
- /* ckfree((char*)ptr); */
rb_thread_critical = thr_crit_bup;
return;
}
@@ -5316,7 +4537,6 @@ ip_free(ptr)
if (ptr->ip == (Tcl_Interp*)NULL) {
DUMP1("ip_free is called for deleted IP");
free(ptr);
- /* ckfree((char*)ptr); */
rb_thread_critical = thr_crit_bup;
return;
}
@@ -5327,7 +4547,6 @@ ip_free(ptr)
ptr->ip = (Tcl_Interp*)NULL;
free(ptr);
- /* ckfree((char*)ptr); */
rb_thread_critical = thr_crit_bup;
}
@@ -5449,11 +4668,7 @@ ip_rbNamespaceObjCmd(clientData, interp, objc, objv)
int i;
char **argv;
- /* argv = (char **)Tcl_Alloc(sizeof(char *) * (objc + 1)); */
- argv = (char **)ckalloc(sizeof(char *) * (objc + 1));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)argv); /* XXXXXXXX */
-#endif
+ argv = (char **)Tcl_Alloc(sizeof(char *) * (objc + 1));
for(i = 0; i < objc; i++) {
/* argv[i] = Tcl_GetString(objv[i]); */
@@ -5464,16 +4679,7 @@ ip_rbNamespaceObjCmd(clientData, interp, objc, objv)
ret = (*(info.proc))(info.clientData, interp,
objc, (CONST84 char **)argv);
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)argv, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)argv); /* XXXXXXXX */
-#else
- /* Tcl_Free((char*)argv); */
- ckfree((char*)argv);
-#endif
-#endif
+ Tcl_Free((char*)argv);
}
DUMP2("namespace wrapper exit depth == %d", rbtk_eventloop_depth);
@@ -5544,29 +4750,16 @@ ip_init(argc, argv, self)
Tk_Window mainWin = (Tk_Window)NULL;
/* security check */
-#ifdef RUBY_VM
- if (rb_safe_level() >= 4) {
-#else
if (ruby_safe_level >= 4) {
-#endif
rb_raise(rb_eSecurityError,
"Cannot create a TclTkIp object at level %d",
-#ifdef RUBY_VM
- rb_safe_level()
-#else
- ruby_safe_level
-#endif
- );
+ ruby_safe_level);
}
/* create object */
Data_Get_Struct(self, struct tcltkip, ptr);
ptr = ALLOC(struct tcltkip);
- /* ptr = (struct tcltkip *)ckalloc(sizeof(struct tcltkip)); */
DATA_PTR(self) = ptr;
-#ifdef RUBY_VM
- ptr->tk_thread_id = 0;
-#endif
ptr->ref_count = 0;
ptr->allow_ruby_exit = 1;
ptr->return_value = 0;
@@ -5674,10 +4867,6 @@ ip_init(argc, argv, self)
(Tcl_PackageInitProc *) NULL);
#endif
-#ifdef RUBY_VM
- /* set Tk thread ID */
- ptr->tk_thread_id = Tcl_GetCurrentThread();
-#endif
/* get main window */
mainWin = Tk_MainWindow(ptr->ip);
Tk_Preserve((ClientData)mainWin);
@@ -5753,7 +4942,6 @@ ip_create_slave_core(interp, argc, argv)
{
struct tcltkip *master = get_ip(interp);
struct tcltkip *slave = ALLOC(struct tcltkip);
- /* struct tcltkip *slave = (struct tcltkip *)ckalloc(sizeof(struct tcltkip)); */
VALUE safemode;
VALUE name;
int safe;
@@ -5796,10 +4984,6 @@ ip_create_slave_core(interp, argc, argv)
#endif
/* create slave-ip */
-#ifdef RUBY_VM
- /* slave->tk_thread_id = 0; */
- slave->tk_thread_id = master->tk_thread_id; /* == current thread */
-#endif
slave->ref_count = 0;
slave->allow_ruby_exit = 0;
slave->return_value = 0;
@@ -6088,12 +5272,6 @@ ip_allow_ruby_exit_set(self, val)
"insecure operation on a safe interpreter");
}
- /*
- * Because of cross-threading, the following line may fail to find
- * the MainWindow, even if the Tcl/Tk interpreter has one or more.
- * But it has no problem. Current implementation of both type of
- * the "exit" command don't need maiinWin token.
- */
mainWin = (tk_stubs_init_p())? Tk_MainWindow(ptr->ip): (Tk_Window)NULL;
if (RTEST(val)) {
@@ -6190,10 +5368,8 @@ ip_is_deleted_p(self)
}
static VALUE
-ip_has_mainwindow_p_core(self, argc, argv)
+ip_has_mainwindow_p(self)
VALUE self;
- int argc; /* dummy */
- VALUE *argv; /* dummy */
{
struct tcltkip *ptr = get_ip(self);
@@ -6206,14 +5382,6 @@ ip_has_mainwindow_p_core(self, argc, argv)
}
}
-static VALUE
-ip_has_mainwindow_p(self)
- VALUE self;
-{
- return tk_funcall(ip_has_mainwindow_p_core, 0, (VALUE*)NULL, self);
-}
-
-
/*** ruby string <=> tcl object ***/
#if TCL_MAJOR_VERSION >= 8
static VALUE
@@ -6223,16 +5391,10 @@ get_str_from_obj(obj)
int len, binary = 0;
const char *s;
volatile VALUE str;
-#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 4)
- int len2;
- const char *s2;
-#endif
#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0
s = Tcl_GetStringFromObj(obj, &len);
-#else
-#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION <= 3
- /* TCL_VERSION 8.1 -- 8.3 */
+#else /* TCL_VERSION >= 8.1 */
if (Tcl_GetCharLength(obj) != Tcl_UniCharLen(Tcl_GetUnicode(obj))) {
/* possibly binary string */
s = Tcl_GetByteArrayFromObj(obj, &len);
@@ -6241,30 +5403,9 @@ get_str_from_obj(obj)
/* possibly text string */
s = Tcl_GetStringFromObj(obj, &len);
}
-#else /* TCL_VERSION >= 8.4 */
- if (IS_TCL_BYTEARRAY(obj)) {
- s = Tcl_GetByteArrayFromObj(obj, &len);
- binary = 1;
- } else {
- s = Tcl_GetStringFromObj(obj, &len);
- }
-
-#endif
#endif
str = s ? rb_str_new(s, len) : rb_str_new2("");
- if (binary) {
-#ifdef RUBY_VM
- rb_enc_associate_index(str, ENCODING_INDEX_BINARY);
-#endif
- rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY);
-#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1)
- } else {
-#ifdef RUBY_VM
- rb_enc_associate_index(str, ENCODING_INDEX_UTF8);
-#endif
- rb_ivar_set(str, ID_at_enc, ENCODING_NAME_UTF8);
-#endif
- }
+ if (binary) rb_ivar_set(str, ID_at_enc, rb_str_new2("binary"));
return str;
}
@@ -6275,30 +5416,25 @@ get_obj_from_str(str)
const char *s = StringValuePtr(str);
#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0
- return Tcl_NewStringObj((char*)s, RSTRING_LEN(str));
+ return Tcl_NewStringObj((char*)s, RSTRING(str)->len);
#else /* TCL_VERSION >= 8.1 */
VALUE enc = rb_attr_get(str, ID_at_enc);
if (!NIL_P(enc)) {
StringValue(enc);
- if (strcmp(RSTRING_PTR(enc), "binary") == 0) {
+ if (strcmp(RSTRING(enc)->ptr, "binary") == 0) {
/* binary string */
- return Tcl_NewByteArrayObj(s, RSTRING_LEN(str));
+ return Tcl_NewByteArrayObj(s, RSTRING(str)->len);
} else {
/* text string */
- return Tcl_NewStringObj(s, RSTRING_LEN(str));
+ return Tcl_NewStringObj(s, RSTRING(str)->len);
}
-#ifdef RUBY_VM
- } else if (rb_enc_get_index(str) == ENCODING_INDEX_BINARY) {
- /* binary string */
- return Tcl_NewByteArrayObj(s, RSTRING_LEN(str));
-#endif
- } else if (strlen(s) != RSTRING_LEN(str)) {
+ } else if (strlen(s) != RSTRING(str)->len) {
/* probably binary string */
- return Tcl_NewByteArrayObj(s, RSTRING_LEN(str));
+ return Tcl_NewByteArrayObj(s, RSTRING(str)->len);
} else {
/* probably text string */
- return Tcl_NewStringObj(s, RSTRING_LEN(str));
+ return Tcl_NewStringObj(s, RSTRING(str)->len);
}
#endif
}
@@ -6316,7 +5452,6 @@ ip_get_result_string_obj(interp)
Tcl_IncrRefCount(retObj);
strval = get_str_from_obj(retObj);
OBJ_TAINT(strval);
- Tcl_ResetResult(interp);
Tcl_DecrRefCount(retObj);
return strval;
#else
@@ -6347,12 +5482,11 @@ call_queue_handler(evPtr, flags)
struct call_queue *q = (struct call_queue *)evPtr;
volatile VALUE ret;
volatile VALUE q_dat;
- volatile VALUE thread = q->thread;
struct tcltkip *ptr;
DUMP2("do_call_queue_handler : evPtr = %p", evPtr);
- DUMP2("call_queue_handler thread : %lx", rb_thread_current());
- DUMP2("added by thread : %lx", thread);
+ DUMP2("queue_handler thread : %lx", rb_thread_current());
+ DUMP2("added by thread : %lx", q->thread);
if (*(q->done)) {
DUMP1("processed by another event-loop");
@@ -6361,12 +5495,6 @@ call_queue_handler(evPtr, flags)
DUMP1("process it on current event-loop");
}
- if (RTEST(rb_thread_alive_p(thread))
- && ! RTEST(rb_funcall(thread, ID_stop_p, 0))) {
- DUMP1("caller is not yet ready to receive the result -> pending");
- return 0;
- }
-
/* process it */
*(q->done) = 1;
@@ -6377,56 +5505,33 @@ call_queue_handler(evPtr, flags)
return 1;
}
- /* incr internal handler mark */
- rbtk_internal_eventloop_handler++;
-
/* check safe-level */
if (rb_safe_level() != q->safe_level) {
- /* q_dat = Data_Wrap_Struct(rb_cData,0,-1,q); */
- q_dat = Data_Wrap_Struct(rb_cData,call_queue_mark,-1,q);
+ /* q_dat = Data_Wrap_Struct(rb_cData,0,0,q); */
+ q_dat = Data_Wrap_Struct(rb_cData,call_queue_mark,0,q);
ret = rb_funcall(rb_proc_new(callq_safelevel_handler, q_dat),
ID_call, 0);
rb_gc_force_recycle(q_dat);
- q_dat = (VALUE)NULL;
} else {
- DUMP2("call function (for caller thread:%lx)", thread);
+ DUMP2("call function (for caller thread:%lx)", q->thread);
DUMP2("call function (current thread:%lx)", rb_thread_current());
ret = (q->func)(q->interp, q->argc, q->argv);
}
/* set result */
- RARRAY_PTR(q->result)[0] = ret;
- ret = (VALUE)NULL;
-
- /* decr internal handler mark */
- rbtk_internal_eventloop_handler--;
+ RARRAY(q->result)->ptr[0] = ret;
/* complete */
*(q->done) = -1;
- /* unlink ruby objects */
- q->argv = (VALUE*)NULL;
- q->interp = (VALUE)NULL;
- q->result = (VALUE)NULL;
- q->thread = (VALUE)NULL;
-
/* back to caller */
- /* if (RTEST(rb_funcall(thread, ID_alive_p, 0, 0))) { */
- if (RTEST(rb_thread_alive_p(thread))) {
- DUMP2("back to caller (caller thread:%lx)", thread);
+ if (RTEST(rb_funcall(q->thread, ID_alive_p, 0, 0))) {
+ DUMP2("back to caller (caller thread:%lx)", q->thread);
DUMP2(" (current thread:%lx)", rb_thread_current());
-#if CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE
- have_rb_thread_waiting_for_value = 1;
- rb_thread_wakeup(thread);
-#else
- rb_thread_run(thread);
-#endif
+ rb_thread_run(q->thread);
DUMP1("finish back to caller");
-#if DO_THREAD_SCHEDULE_AT_CALLBACK_DONE
- rb_thread_schedule();
-#endif
} else {
- DUMP2("caller is dead (caller thread:%lx)", thread);
+ DUMP2("caller is dead (caller thread:%lx)", q->thread);
DUMP2(" (current thread:%lx)", rb_thread_current());
}
@@ -6442,39 +5547,19 @@ tk_funcall(func, argc, argv, obj)
VALUE obj;
{
struct call_queue *callq;
- struct tcltkip *ptr;
int *alloc_done;
int thr_crit_bup;
- int is_tk_evloop_thread;
volatile VALUE current = rb_thread_current();
volatile VALUE ip_obj = obj;
volatile VALUE result;
volatile VALUE ret;
- if (!NIL_P(ip_obj) && rb_obj_is_kind_of(ip_obj, tcltkip_class)) {
- ptr = get_ip(ip_obj);
- if (deleted_ip(ptr)) return Qnil;
- } else {
- ptr = (struct tcltkip *)NULL;
- }
-#ifdef RUBY_VM
- if (ptr) {
- /* on Tcl interpreter */
- is_tk_evloop_thread = (ptr->tk_thread_id == (Tcl_ThreadId) 0
- || ptr->tk_thread_id == Tcl_GetCurrentThread());
- } else {
- /* on Tcl/Tk library */
- is_tk_evloop_thread = (tk_eventloop_thread_id == (Tcl_ThreadId) 0
- || tk_eventloop_thread_id == Tcl_GetCurrentThread());
+ if (!NIL_P(ip_obj) && deleted_ip(get_ip(ip_obj))) {
+ return Qnil;
}
-#else
- is_tk_evloop_thread = 1;
-#endif
- if (is_tk_evloop_thread
- && (NIL_P(eventloop_thread) || current == eventloop_thread)
- ) {
+ if (NIL_P(eventloop_thread) || current == eventloop_thread) {
if (NIL_P(eventloop_thread)) {
DUMP2("tk_funcall from thread:%lx but no eventloop", current);
} else {
@@ -6494,32 +5579,23 @@ tk_funcall(func, argc, argv, obj)
/* allocate memory (argv cross over thread : must be in heap) */
if (argv) {
- /* VALUE *temp = ALLOC_N(VALUE, argc); */
- VALUE *temp = (VALUE*)ckalloc(sizeof(VALUE) * argc);
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)temp); /* XXXXXXXX */
-#endif
+ VALUE *temp = ALLOC_N(VALUE, argc);
MEMCPY(temp, argv, VALUE, argc);
argv = temp;
}
/* allocate memory (keep result) */
- /* alloc_done = (int*)ALLOC(int); */
- alloc_done = (int*)ckalloc(sizeof(int));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)alloc_done); /* XXXXXXXX */
-#endif
+ alloc_done = (int*)ALLOC(int);
*alloc_done = 0;
/* allocate memory (freed by Tcl_ServiceEvent) */
- /* callq = (struct call_queue *)Tcl_Alloc(sizeof(struct call_queue)); */
- callq = (struct call_queue *)ckalloc(sizeof(struct call_queue));
-#if 0 /* use Tcl_Preserve/Release */
+ callq = (struct call_queue *)Tcl_Alloc(sizeof(struct call_queue));
Tcl_Preserve(callq);
-#endif
/* allocate result obj */
- result = rb_ary_new3(1, Qnil);
+ result = rb_ary_new2(1);
+ RARRAY(result)->ptr[0] = Qnil;
+ RARRAY(result)->len = 1;
/* construct event data */
callq->done = alloc_done;
@@ -6534,83 +5610,28 @@ tk_funcall(func, argc, argv, obj)
/* add the handler to Tcl event queue */
DUMP1("add handler");
-#ifdef RUBY_VM
- if (ptr && ptr->tk_thread_id) {
- /* Tcl_ThreadQueueEvent(ptr->tk_thread_id,
- &(callq->ev), TCL_QUEUE_HEAD); */
- Tcl_ThreadQueueEvent(ptr->tk_thread_id,
- (Tcl_Event*)callq, TCL_QUEUE_HEAD);
- Tcl_ThreadAlert(ptr->tk_thread_id);
- } else if (tk_eventloop_thread_id) {
- /* Tcl_ThreadQueueEvent(tk_eventloop_thread_id,
- &(callq->ev), TCL_QUEUE_HEAD); */
- Tcl_ThreadQueueEvent(tk_eventloop_thread_id,
- (Tcl_Event*)callq, TCL_QUEUE_HEAD);
- Tcl_ThreadAlert(tk_eventloop_thread_id);
- } else {
- /* Tcl_QueueEvent(&(callq->ev), TCL_QUEUE_HEAD); */
- Tcl_QueueEvent((Tcl_Event*)callq, TCL_QUEUE_HEAD);
- }
-#else
- /* Tcl_QueueEvent(&(callq->ev), TCL_QUEUE_HEAD); */
- Tcl_QueueEvent((Tcl_Event*)callq, TCL_QUEUE_HEAD);
-#endif
+ Tcl_QueueEvent(&(callq->ev), TCL_QUEUE_HEAD);
rb_thread_critical = thr_crit_bup;
/* wait for the handler to be processed */
DUMP2("wait for handler (current thread:%lx)", current);
while(*alloc_done >= 0) {
- DUMP2("*** wait for handler (current thread:%lx)", current);
- /* rb_thread_stop(); */
- rb_thread_sleep_forever();
- DUMP2("*** wakeup (current thread:%lx)", current);
+ rb_thread_stop();
}
DUMP2("back from handler (current thread:%lx)", current);
/* get result & free allocated memory */
- ret = RARRAY_PTR(result)[0];
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)alloc_done, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)alloc_done); /* XXXXXXXX */
-#else
- /* free(alloc_done); */
- ckfree((char*)alloc_done);
-#endif
-#endif
- /* if (argv) free(argv); */
- if (argv) {
- /* if argv != NULL, alloc as 'temp' */
- int i;
- for(i = 0; i < argc; i++) { argv[i] = (VALUE)NULL; }
-
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)argv, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)argv); /* XXXXXXXX */
-#else
- ckfree((char*)argv);
-#endif
-#endif
- }
+ ret = RARRAY(result)->ptr[0];
+ free(alloc_done);
+ if (argv) free(argv);
-#if 0 /* callq is freed by Tcl_ServiceEvent */
-#if 0 /* use Tcl_Preserve/Release */
Tcl_Release(callq);
-#else
- ckfree((char*)callq);
-#endif
-#endif
/* exception? */
if (rb_obj_is_kind_of(ret, rb_eException)) {
DUMP1("raise exception");
- /* rb_exc_raise(ret); */
- rb_exc_raise(rb_exc_new3(rb_obj_class(ret),
- rb_funcall(ret, ID_to_s, 0, 0)));
+ rb_exc_raise(ret);
}
DUMP1("exit tk_funcall");
@@ -6681,35 +5702,19 @@ ip_eval_real(self, cmd_str, cmd_len)
ret = rb_protect(call_tcl_eval, (VALUE)&inf, &status);
switch(status) {
case TAG_RAISE:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
rbtk_pending_exception = rb_exc_new2(rb_eException,
"unknown exception");
} else {
-#ifdef RUBY_VM
- rbtk_pending_exception = rb_errinfo();
-#else
rbtk_pending_exception = ruby_errinfo;
-#endif
}
break;
case TAG_FATAL:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL");
} else {
-#ifdef RUBY_VM
- rbtk_pending_exception = rb_errinfo();
-#else
rbtk_pending_exception = ruby_errinfo;
-#endif
}
}
#endif
@@ -6809,12 +5814,6 @@ eval_queue_handler(evPtr, flags)
struct eval_queue *q = (struct eval_queue *)evPtr;
volatile VALUE ret;
volatile VALUE q_dat;
- volatile VALUE thread = q->thread;
- struct tcltkip *ptr;
-
- DUMP2("do_eval_queue_handler : evPtr = %p", evPtr);
- DUMP2("eval_queue_thread : %lx", rb_thread_current());
- DUMP2("added by thread : %lx", thread);
if (*(q->done)) {
DUMP1("processed by another event-loop");
@@ -6823,82 +5822,39 @@ eval_queue_handler(evPtr, flags)
DUMP1("process it on current event-loop");
}
- if (RTEST(rb_thread_alive_p(thread))
- && ! RTEST(rb_funcall(thread, ID_stop_p, 0))) {
- DUMP1("caller is not yet ready to receive the result -> pending");
- return 0;
- }
-
/* process it */
*(q->done) = 1;
- /* deleted ipterp ? */
- ptr = get_ip(q->interp);
- if (deleted_ip(ptr)) {
- /* deleted IP --> ignore */
- return 1;
- }
-
- /* incr internal handler mark */
- rbtk_internal_eventloop_handler++;
-
/* check safe-level */
if (rb_safe_level() != q->safe_level) {
#ifdef HAVE_NATIVETHREAD
-#ifdef RUBY_VM
-#if 0
- if (!ruby_native_thread_p()) {
- rb_bug("cross-thread violation on eval_queue_handler()");
- }
-#endif
-#else
- if (!is_ruby_native_thread()) {
- rb_bug("cross-thread violation on eval_queue_handler()");
- }
-#endif
+ if (!is_ruby_native_thread()) {
+ rb_bug("cross-thread violation on eval_queue_handler()");
+ }
#endif
- /* q_dat = Data_Wrap_Struct(rb_cData,0,-1,q); */
- q_dat = Data_Wrap_Struct(rb_cData,eval_queue_mark,-1,q);
+ /* q_dat = Data_Wrap_Struct(rb_cData,0,0,q); */
+ q_dat = Data_Wrap_Struct(rb_cData,eval_queue_mark,0,q);
ret = rb_funcall(rb_proc_new(evq_safelevel_handler, q_dat),
ID_call, 0);
rb_gc_force_recycle(q_dat);
- q_dat = (VALUE)NULL;
} else {
ret = ip_eval_real(q->interp, q->str, q->len);
}
/* set result */
- RARRAY_PTR(q->result)[0] = ret;
- ret = (VALUE)NULL;
-
- /* decr internal handler mark */
- rbtk_internal_eventloop_handler--;
+ RARRAY(q->result)->ptr[0] = ret;
/* complete */
*(q->done) = -1;
- /* unlink ruby objects */
- q->interp = (VALUE)NULL;
- q->result = (VALUE)NULL;
- q->thread = (VALUE)NULL;
-
/* back to caller */
- /* if (RTEST(rb_funcall(thread, ID_alive_p, 0, 0))) { */
- if (RTEST(rb_thread_alive_p(thread))) {
- DUMP2("back to caller (caller thread:%lx)", thread);
+ if (RTEST(rb_funcall(q->thread, ID_alive_p, 0, 0))) {
+ DUMP2("back to caller (caller thread:%lx)", q->thread);
DUMP2(" (current thread:%lx)", rb_thread_current());
-#if CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE
- have_rb_thread_waiting_for_value = 1;
- rb_thread_wakeup(thread);
-#else
- rb_thread_run(thread);
-#endif
+ rb_thread_run(q->thread);
DUMP1("finish back to caller");
-#if DO_THREAD_SCHEDULE_AT_CALLBACK_DONE
- rb_thread_schedule();
-#endif
} else {
- DUMP2("caller is dead (caller thread:%lx)", thread);
+ DUMP2("caller is dead (caller thread:%lx)", q->thread);
DUMP2(" (current thread:%lx)", rb_thread_current());
}
@@ -6912,9 +5868,6 @@ ip_eval(self, str)
VALUE str;
{
struct eval_queue *evq;
-#ifdef RUBY_VM
- struct tcltkip *ptr;
-#endif
char *eval_str;
int *alloc_done;
int thr_crit_bup;
@@ -6929,23 +5882,13 @@ ip_eval(self, str)
StringValue(str);
rb_thread_critical = thr_crit_bup;
-#ifdef RUBY_VM
- ptr = get_ip(ip_obj);
-#endif
-
- if (
-#ifdef RUBY_VM
- (ptr->tk_thread_id == 0 || ptr->tk_thread_id == Tcl_GetCurrentThread())
- &&
-#endif
- (NIL_P(eventloop_thread) || current == eventloop_thread)
- ) {
+ if (NIL_P(eventloop_thread) || current == eventloop_thread) {
if (NIL_P(eventloop_thread)) {
DUMP2("eval from thread:%lx but no eventloop", current);
} else {
DUMP2("eval from current eventloop %lx", current);
}
- result = ip_eval_real(self, RSTRING_PTR(str), RSTRING_LEN(str));
+ result = ip_eval_real(self, RSTRING(str)->ptr, RSTRING(str)->len);
if (rb_obj_is_kind_of(result, rb_eException)) {
rb_exc_raise(result);
}
@@ -6957,36 +5900,27 @@ ip_eval(self, str)
thr_crit_bup = rb_thread_critical;
rb_thread_critical = Qtrue;
- /* allocate memory (keep result) */
- /* alloc_done = (int*)ALLOC(int); */
- alloc_done = (int*)ckalloc(sizeof(int));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)alloc_done); /* XXXXXXXX */
-#endif
+ /* allocate memory (protected from Tcl_ServiceEvent) */
+ alloc_done = (int*)ALLOC(int);
*alloc_done = 0;
- /* eval_str = ALLOC_N(char, RSTRING_LEN(str) + 1); */
- eval_str = ckalloc(sizeof(char) * (RSTRING_LEN(str) + 1));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)eval_str); /* XXXXXXXX */
-#endif
- memcpy(eval_str, RSTRING_PTR(str), RSTRING_LEN(str));
- eval_str[RSTRING_LEN(str)] = 0;
+ eval_str = ALLOC_N(char, RSTRING(str)->len + 1);
+ memcpy(eval_str, RSTRING(str)->ptr, RSTRING(str)->len);
+ eval_str[RSTRING(str)->len] = 0;
/* allocate memory (freed by Tcl_ServiceEvent) */
- /* evq = (struct eval_queue *)Tcl_Alloc(sizeof(struct eval_queue)); */
- evq = (struct eval_queue *)ckalloc(sizeof(struct eval_queue));
-#if 0 /* use Tcl_Preserve/Release */
+ evq = (struct eval_queue *)Tcl_Alloc(sizeof(struct eval_queue));
Tcl_Preserve(evq);
-#endif
/* allocate result obj */
- result = rb_ary_new3(1, Qnil);
+ result = rb_ary_new2(1);
+ RARRAY(result)->ptr[0] = Qnil;
+ RARRAY(result)->len = 1;
/* construct event data */
evq->done = alloc_done;
evq->str = eval_str;
- evq->len = RSTRING_LEN(str);
+ evq->len = RSTRING(str)->len;
evq->interp = ip_obj;
evq->result = result;
evq->thread = current;
@@ -6997,73 +5931,26 @@ ip_eval(self, str)
/* add the handler to Tcl event queue */
DUMP1("add handler");
-#ifdef RUBY_VM
- if (ptr->tk_thread_id) {
- /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(evq->ev), position); */
- Tcl_ThreadQueueEvent(ptr->tk_thread_id, (Tcl_Event*)evq, position);
- Tcl_ThreadAlert(ptr->tk_thread_id);
- } else if (tk_eventloop_thread_id) {
- Tcl_ThreadQueueEvent(tk_eventloop_thread_id, (Tcl_Event*)evq, position);
- /* Tcl_ThreadQueueEvent(tk_eventloop_thread_id,
- &(evq->ev), position); */
- Tcl_ThreadAlert(tk_eventloop_thread_id);
- } else {
- /* Tcl_QueueEvent(&(evq->ev), position); */
- Tcl_QueueEvent((Tcl_Event*)evq, position);
- }
-#else
- /* Tcl_QueueEvent(&(evq->ev), position); */
- Tcl_QueueEvent((Tcl_Event*)evq, position);
-#endif
+ Tcl_QueueEvent(&(evq->ev), position);
rb_thread_critical = thr_crit_bup;
/* wait for the handler to be processed */
DUMP2("wait for handler (current thread:%lx)", current);
while(*alloc_done >= 0) {
- DUMP2("*** wait for handler (current thread:%lx)", current);
- /* rb_thread_stop(); */
- rb_thread_sleep_forever();
- DUMP2("*** wakeup (current thread:%lx)", current);
+ rb_thread_stop();
}
DUMP2("back from handler (current thread:%lx)", current);
/* get result & free allocated memory */
- ret = RARRAY_PTR(result)[0];
+ ret = RARRAY(result)->ptr[0];
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)alloc_done, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)alloc_done); /* XXXXXXXX */
-#else
- /* free(alloc_done); */
- ckfree((char*)alloc_done);
-#endif
-#endif
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)eval_str, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)eval_str); /* XXXXXXXX */
-#else
- /* free(eval_str); */
- ckfree(eval_str);
-#endif
-#endif
-#if 0 /* evq is freed by Tcl_ServiceEvent */
-#if 0 /* use Tcl_Preserve/Release */
+ free(alloc_done);
+ free(eval_str);
Tcl_Release(evq);
-#else
- ckfree((char*)evq);
-#endif
-#endif
if (rb_obj_is_kind_of(ret, rb_eException)) {
- DUMP1("raise exception");
- /* rb_exc_raise(ret); */
- rb_exc_raise(rb_exc_new3(rb_obj_class(ret),
- rb_funcall(ret, ID_to_s, 0, 0)));
+ rb_exc_raise(ret);
}
return ret;
@@ -7218,12 +6105,7 @@ lib_toUTF8_core(ip_obj, src, encodename)
if (NIL_P(encodename)) {
if (TYPE(str) == T_STRING) {
volatile VALUE enc;
-
-#ifdef RUBY_VM
- enc = rb_funcall(rb_obj_encoding(str), ID_to_s, 0, 0);
-#else
enc = rb_attr_get(str, ID_at_enc);
-#endif
if (NIL_P(enc)) {
if (NIL_P(ip_obj)) {
encoding = (Tcl_Encoding)NULL;
@@ -7232,35 +6114,22 @@ lib_toUTF8_core(ip_obj, src, encodename)
if (NIL_P(enc)) {
encoding = (Tcl_Encoding)NULL;
} else {
- /* StringValue(enc); */
- enc = rb_funcall(enc, ID_to_s, 0, 0);
- /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); */
- if (!RSTRING_LEN(enc)) {
- encoding = (Tcl_Encoding)NULL;
- } else {
- encoding = Tcl_GetEncoding((Tcl_Interp*)NULL,
- RSTRING_PTR(enc));
- if (encoding == (Tcl_Encoding)NULL) {
- rb_warning("Tk-interp has unknown encoding information (@encoding:'%s')", RSTRING_PTR(enc));
- }
- }
+ StringValue(enc);
+ encoding = Tcl_GetEncoding(interp, RSTRING(enc)->ptr);
+ if (encoding == (Tcl_Encoding)NULL) {
+ rb_warning("Tk-interp has unknown encoding information (@encoding:'%s')", RSTRING(enc)->ptr);
+ }
}
}
} else {
StringValue(enc);
- if (strcmp(RSTRING_PTR(enc), "binary") == 0) {
-#ifdef RUBY_VM
- rb_enc_associate_index(str, ENCODING_INDEX_BINARY);
-#endif
- rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY);
+ if (strcmp(RSTRING(enc)->ptr, "binary") == 0) {
rb_thread_critical = thr_crit_bup;
return str;
}
- /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); */
- encoding = Tcl_GetEncoding((Tcl_Interp*)NULL,
- RSTRING_PTR(enc));
+ encoding = Tcl_GetEncoding(interp, RSTRING(enc)->ptr);
if (encoding == (Tcl_Encoding)NULL) {
- rb_warning("string has unknown encoding information (@encoding:'%s')", RSTRING_PTR(enc));
+ rb_warning("string has unknown encoding information (@encoding:'%s')", RSTRING(enc)->ptr);
}
}
} else {
@@ -7268,59 +6137,43 @@ lib_toUTF8_core(ip_obj, src, encodename)
}
} else {
StringValue(encodename);
- if (strcmp(RSTRING_PTR(encodename), "binary") == 0) {
-#ifdef RUBY_VM
- rb_enc_associate_index(str, ENCODING_INDEX_BINARY);
-#endif
- rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY);
- rb_thread_critical = thr_crit_bup;
- return str;
- }
- /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(encodename)); */
- encoding = Tcl_GetEncoding((Tcl_Interp*)NULL, RSTRING_PTR(encodename));
+ encoding = Tcl_GetEncoding(interp, RSTRING(encodename)->ptr);
if (encoding == (Tcl_Encoding)NULL) {
/*
rb_warning("unknown encoding name '%s'",
- RSTRING_PTR(encodename));
+ RSTRING(encodename)->ptr);
*/
rb_raise(rb_eArgError, "unknown encoding name '%s'",
- RSTRING_PTR(encodename));
+ RSTRING(encodename)->ptr);
}
}
StringValue(str);
- if (!RSTRING_LEN(str)) {
+ if (!RSTRING(str)->len) {
rb_thread_critical = thr_crit_bup;
return str;
}
- buf = ALLOC_N(char, RSTRING_LEN(str)+1);
- /* buf = ckalloc(sizeof(char) * (RSTRING_LEN(str)+1)); */
- memcpy(buf, RSTRING_PTR(str), RSTRING_LEN(str));
- buf[RSTRING_LEN(str)] = 0;
+ buf = ALLOC_N(char,(RSTRING(str)->len)+1);
+ memcpy(buf, RSTRING(str)->ptr, RSTRING(str)->len);
+ buf[RSTRING(str)->len] = 0;
Tcl_DStringInit(&dstr);
Tcl_DStringFree(&dstr);
/* Tcl_ExternalToUtfDString(encoding,buf,strlen(buf),&dstr); */
- Tcl_ExternalToUtfDString(encoding, buf, RSTRING_LEN(str), &dstr);
+ Tcl_ExternalToUtfDString(encoding, buf, RSTRING(str)->len, &dstr);
/* str = rb_tainted_str_new2(Tcl_DStringValue(&dstr)); */
/* str = rb_str_new2(Tcl_DStringValue(&dstr)); */
str = rb_str_new(Tcl_DStringValue(&dstr), Tcl_DStringLength(&dstr));
-#ifdef RUBY_VM
- rb_enc_associate_index(str, ENCODING_INDEX_UTF8);
-#endif
- rb_ivar_set(str, ID_at_enc, ENCODING_NAME_UTF8);
+ rb_ivar_set(str, ID_at_enc, rb_tainted_str_new2("utf-8"));
if (taint_flag) OBJ_TAINT(str);
- /*
if (encoding != (Tcl_Encoding)NULL) {
Tcl_FreeEncoding(encoding);
}
- */
Tcl_DStringFree(&dstr);
free(buf);
- /* ckfree(buf); */
rb_thread_critical = thr_crit_bup;
#endif
@@ -7398,21 +6251,10 @@ lib_fromUTF8_core(ip_obj, src, encodename)
enc = rb_attr_get(str, ID_at_enc);
if (!NIL_P(enc)) {
StringValue(enc);
- if (strcmp(RSTRING_PTR(enc), "binary") == 0) {
-#ifdef RUBY_VM
- rb_enc_associate_index(str, ENCODING_INDEX_BINARY);
-#endif
- rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY);
+ if (strcmp(RSTRING(enc)->ptr, "binary") == 0) {
rb_thread_critical = thr_crit_bup;
return str;
}
-#ifdef RUBY_VM
- } else if (rb_enc_get_index(str) == ENCODING_INDEX_BINARY) {
- rb_enc_associate_index(str, ENCODING_INDEX_BINARY);
- rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY);
- rb_thread_critical = thr_crit_bup;
- return str;
-#endif
}
}
@@ -7423,106 +6265,75 @@ lib_fromUTF8_core(ip_obj, src, encodename)
if (NIL_P(enc)) {
encoding = (Tcl_Encoding)NULL;
} else {
- /* StringValue(enc); */
- enc = rb_funcall(enc, ID_to_s, 0, 0);
- /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); */
- if (!RSTRING_LEN(enc)) {
- encoding = (Tcl_Encoding)NULL;
- } else {
- encoding = Tcl_GetEncoding((Tcl_Interp*)NULL,
- RSTRING_PTR(enc));
- if (encoding == (Tcl_Encoding)NULL) {
- rb_warning("Tk-interp has unknown encoding information (@encoding:'%s')", RSTRING_PTR(enc));
- } else {
- encodename = rb_obj_dup(enc);
- }
- }
+ StringValue(enc);
+ encoding = Tcl_GetEncoding(interp, RSTRING(enc)->ptr);
+ if (encoding == (Tcl_Encoding)NULL) {
+ rb_warning("Tk-interp has unknown encoding information (@encoding:'%s')", RSTRING(enc)->ptr);
+ } else {
+ encodename = rb_obj_dup(enc);
+ }
}
}
} else {
StringValue(encodename);
- if (strcmp(RSTRING_PTR(encodename), "binary") == 0) {
- Tcl_Obj *tclstr;
+ if (strcmp(RSTRING(encodename)->ptr, "binary") == 0) {
char *s;
int len;
StringValue(str);
- tclstr = Tcl_NewStringObj(RSTRING_PTR(str), RSTRING_LEN(str));
- Tcl_IncrRefCount(tclstr);
- s = Tcl_GetByteArrayFromObj(tclstr, &len);
+ s = Tcl_GetByteArrayFromObj(Tcl_NewStringObj(RSTRING(str)->ptr,
+ RSTRING(str)->len),
+ &len);
str = rb_tainted_str_new(s, len);
- s = (char*)NULL;
- Tcl_DecrRefCount(tclstr);
-#ifdef RUBY_VM
- rb_enc_associate_index(str, ENCODING_INDEX_BINARY);
-#endif
- rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY);
+ rb_ivar_set(str, ID_at_enc, rb_tainted_str_new2("binary"));
rb_thread_critical = thr_crit_bup;
return str;
}
- /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(encodename)); */
- encoding = Tcl_GetEncoding((Tcl_Interp*)NULL, RSTRING_PTR(encodename));
+ encoding = Tcl_GetEncoding(interp, RSTRING(encodename)->ptr);
if (encoding == (Tcl_Encoding)NULL) {
/*
rb_warning("unknown encoding name '%s'",
- RSTRING_PTR(encodename));
+ RSTRING(encodename)->ptr);
encodename = Qnil;
*/
rb_raise(rb_eArgError, "unknown encoding name '%s'",
- RSTRING_PTR(encodename));
+ RSTRING(encodename)->ptr);
}
}
StringValue(str);
- if (RSTRING_LEN(str) == 0) {
+ if (RSTRING(str)->len == 0) {
rb_thread_critical = thr_crit_bup;
return rb_tainted_str_new2("");
}
- buf = ALLOC_N(char, RSTRING_LEN(str)+1);
- /* buf = ckalloc(sizeof(char) * (RSTRING_LEN(str)+1)); */
- memcpy(buf, RSTRING_PTR(str), RSTRING_LEN(str));
- buf[RSTRING_LEN(str)] = 0;
+ buf = ALLOC_N(char,strlen(RSTRING(str)->ptr)+1);
+ memcpy(buf, RSTRING(str)->ptr, RSTRING(str)->len);
+ buf[RSTRING(str)->len] = 0;
Tcl_DStringInit(&dstr);
Tcl_DStringFree(&dstr);
/* Tcl_UtfToExternalDString(encoding,buf,strlen(buf),&dstr); */
- Tcl_UtfToExternalDString(encoding,buf,RSTRING_LEN(str),&dstr);
+ Tcl_UtfToExternalDString(encoding,buf,RSTRING(str)->len,&dstr);
/* str = rb_tainted_str_new2(Tcl_DStringValue(&dstr)); */
/* str = rb_str_new2(Tcl_DStringValue(&dstr)); */
str = rb_str_new(Tcl_DStringValue(&dstr), Tcl_DStringLength(&dstr));
-#ifdef RUBY_VM
- if (interp) {
- /* can access encoding_table of TclTkIp */
- /* -> try to use encoding_table */
- VALUE tbl = ip_get_encoding_table(ip_obj);
- VALUE encobj = encoding_table_get_obj(tbl, encodename);
- rb_enc_associate_index(str, rb_to_encoding_index(encobj));
- } else {
- /* cannot access encoding_table of TclTkIp */
- /* -> try to find on Ruby Encoding */
- rb_enc_associate_index(str, rb_enc_find_index(RSTRING_PTR(encodename)));
- }
-#endif
rb_ivar_set(str, ID_at_enc, encodename);
if (taint_flag) OBJ_TAINT(str);
- /*
if (encoding != (Tcl_Encoding)NULL) {
Tcl_FreeEncoding(encoding);
}
- */
Tcl_DStringFree(&dstr);
free(buf);
- /* ckfree(buf); */
rb_thread_critical = thr_crit_bup;
#endif
@@ -7573,29 +6384,21 @@ lib_UTF_backslash_core(self, str, all_bs)
tcl_stubs_check();
StringValue(str);
- if (!RSTRING_LEN(str)) {
+ if (!RSTRING(str)->len) {
return str;
}
thr_crit_bup = rb_thread_critical;
rb_thread_critical = Qtrue;
- /* src_buf = ALLOC_N(char, RSTRING_LEN(str)+1); */
- src_buf = ckalloc(sizeof(char) * (RSTRING_LEN(str)+1));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)src_buf); /* XXXXXXXX */
-#endif
- memcpy(src_buf, RSTRING_PTR(str), RSTRING_LEN(str));
- src_buf[RSTRING_LEN(str)] = 0;
+ src_buf = ALLOC_N(char,(RSTRING(str)->len)+1);
+ memcpy(src_buf, RSTRING(str)->ptr, RSTRING(str)->len);
+ src_buf[RSTRING(str)->len] = 0;
- /* dst_buf = ALLOC_N(char, RSTRING_LEN(str)+1); */
- dst_buf = ckalloc(sizeof(char) * (RSTRING_LEN(str)+1));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)dst_buf); /* XXXXXXXX */
-#endif
+ dst_buf = ALLOC_N(char,(RSTRING(str)->len)+1);
ptr = src_buf;
- while(RSTRING_LEN(str) > ptr - src_buf) {
+ while(RSTRING(str)->len > ptr - src_buf) {
if (*ptr == '\\' && (all_bs || *(ptr + 1) == 'u')) {
dst_len += Tcl_UtfBackslash(ptr, &read_len, (dst_buf + dst_len));
ptr += read_len;
@@ -7606,31 +6409,9 @@ lib_UTF_backslash_core(self, str, all_bs)
str = rb_str_new(dst_buf, dst_len);
if (taint_flag) OBJ_TAINT(str);
-#ifdef RUBY_VM
- rb_enc_associate_index(str, ENCODING_INDEX_UTF8);
-#endif
- rb_ivar_set(str, ID_at_enc, ENCODING_NAME_UTF8);
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)src_buf, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)src_buf); /* XXXXXXXX */
-#else
- /* free(src_buf); */
- ckfree(src_buf);
-#endif
-#endif
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)dst_buf, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)dst_buf); /* XXXXXXXX */
-#else
- /* free(dst_buf); */
- ckfree(dst_buf);
-#endif
-#endif
+ free(src_buf);
+ free(dst_buf);
rb_thread_critical = thr_crit_bup;
#endif
@@ -7683,7 +6464,7 @@ lib_set_system_encoding(self, enc_name)
if (Tcl_SetSystemEncoding((Tcl_Interp *)NULL,
StringValuePtr(enc_name)) != TCL_OK) {
rb_raise(rb_eArgError, "unknown encoding name '%s'",
- RSTRING_PTR(enc_name));
+ RSTRING(enc_name)->ptr);
}
return enc_name;
@@ -7721,11 +6502,7 @@ invoke_tcl_proc(arg)
#if TCL_MAJOR_VERSION >= 8
if (!inf->cmdinfo.isNativeObjectProc) {
/* string interface */
- /* argv = (char **)ALLOC_N(char *, argc+1);*/ /* XXXXXXXXXX */
- argv = (char **)ckalloc(sizeof(char *)*(argc+1));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)argv); /* XXXXXXXX */
-#endif
+ argv = (char **)ALLOC_N(char *, argc+1);
for (i = 0; i < argc; ++i) {
argv[i] = Tcl_GetStringFromObj(inf->objv[i], &len);
}
@@ -7750,16 +6527,7 @@ invoke_tcl_proc(arg)
= (*(inf->cmdinfo.proc))(inf->cmdinfo.clientData, inf->ptr->ip,
argc, (CONST84 char **)argv);
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)argv, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)argv); /* XXXXXXXX */
-#else
- /* free(argv); */
- ckfree((char*)argv);
-#endif
-#endif
+ free(argv);
#else /* TCL_MAJOR_VERSION < 8 */
inf->ptr->return_value
@@ -7805,9 +6573,6 @@ ip_invoke_core(interp, argc, argv)
#endif
#endif
- /* get the data struct */
- ptr = get_ip(interp);
-
/* get the command name string */
#if TCL_MAJOR_VERSION >= 8
cmd = Tcl_GetStringFromObj(objv[0], &len);
@@ -7867,22 +6632,14 @@ ip_invoke_core(interp, argc, argv)
unknown_flag = 1;
#if TCL_MAJOR_VERSION >= 8
- /* unknown_objv = (Tcl_Obj **)ALLOC_N(Tcl_Obj *, objc+2); */
- unknown_objv = (Tcl_Obj **)ckalloc(sizeof(Tcl_Obj *) * (objc+2));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)unknown_objv); /* XXXXXXXX */
-#endif
+ unknown_objv = (Tcl_Obj **)ALLOC_N(Tcl_Obj *, objc+2);
unknown_objv[0] = Tcl_NewStringObj("::unknown", 9);
Tcl_IncrRefCount(unknown_objv[0]);
memcpy(unknown_objv + 1, objv, sizeof(Tcl_Obj *)*objc);
unknown_objv[++objc] = (Tcl_Obj*)NULL;
objv = unknown_objv;
#else
- /* unknown_argv = (char **)ALLOC_N(char *, argc+2); */
- unknown_argv = (char **)ckalloc(sizeof(char *) * (argc+2));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)unknown_argv); /* XXXXXXXX */
-#endif
+ unknown_argv = (char **)ALLOC_N(char *, argc+2);
unknown_argv[0] = strdup("unknown");
memcpy(unknown_argv + 1, argv, sizeof(char *)*argc);
unknown_argv[++argc] = (char *)NULL;
@@ -7895,6 +6652,7 @@ ip_invoke_core(interp, argc, argv)
thr_crit_bup = rb_thread_critical;
rb_thread_critical = Qtrue;
+
#if 1 /* wrap tcl-proc call */
/* setup params */
inf.ptr = ptr;
@@ -7911,35 +6669,19 @@ ip_invoke_core(interp, argc, argv)
ret = rb_protect(invoke_tcl_proc, (VALUE)&inf, &status);
switch(status) {
case TAG_RAISE:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
rbtk_pending_exception = rb_exc_new2(rb_eException,
"unknown exception");
} else {
-#ifdef RUBY_VM
- rbtk_pending_exception = rb_errinfo();
-#else
rbtk_pending_exception = ruby_errinfo;
-#endif
}
break;
case TAG_FATAL:
-#ifdef RUBY_VM
- if (NIL_P(rb_errinfo())) {
-#else
if (NIL_P(ruby_errinfo)) {
-#endif
rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL");
} else {
-#ifdef RUBY_VM
- rbtk_pending_exception = rb_errinfo();
-#else
rbtk_pending_exception = ruby_errinfo;
-#endif
}
}
@@ -7951,11 +6693,7 @@ ip_invoke_core(interp, argc, argv)
int i;
/* string interface */
- /* argv = (char **)ALLOC_N(char *, argc+1); */
- argv = (char **)ckalloc(sizeof(char *) * (argc+1));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)argv); /* XXXXXXXX */
-#endif
+ argv = (char **)ALLOC_N(char *, argc+1);
for (i = 0; i < argc; ++i) {
argv[i] = Tcl_GetStringFromObj(objv[i], &len);
}
@@ -7984,16 +6722,7 @@ ip_invoke_core(interp, argc, argv)
ptr->return_value = (*info.proc)(info.clientData, ptr->ip,
argc, (CONST84 char **)argv);
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)argv, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)argv); /* XXXXXXXX */
-#else
- /* free(argv); */
- ckfree((char*)argv);
-#endif
-#endif
+ free(argv);
#else /* TCL_MAJOR_VERSION < 8 */
ptr->return_value = (*info.proc)(info.clientData, ptr->ip,
@@ -8006,29 +6735,10 @@ ip_invoke_core(interp, argc, argv)
if (unknown_flag) {
#if TCL_MAJOR_VERSION >= 8
Tcl_DecrRefCount(objv[0]);
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)objv, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)objv); /* XXXXXXXX */
+ free(objv);
#else
- /* free(objv); */
- ckfree((char*)objv);
-#endif
-#endif
-#else /* TCL_MAJOR_VERSION < 8 */
free(argv[0]);
- /* ckfree(argv[0]); */
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)argv, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)argv); /* XXXXXXXX */
-#else
- /* free(argv); */
- ckfree((char*)argv);
-#endif
-#endif
+ free(argv);
#endif
}
@@ -8083,11 +6793,7 @@ alloc_invoke_arguments(argc, argv)
/* memory allocation */
#if TCL_MAJOR_VERSION >= 8
- /* av = ALLOC_N(Tcl_Obj *, argc+1);*/ /* XXXXXXXXXX */
- av = (Tcl_Obj**)ckalloc(sizeof(Tcl_Obj *)*(argc+1));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)av); /* XXXXXXXX */
-#endif
+ av = ALLOC_N(Tcl_Obj *, argc+1);
for (i = 0; i < argc; ++i) {
av[i] = get_obj_from_str(argv[i]);
Tcl_IncrRefCount(av[i]);
@@ -8096,11 +6802,7 @@ alloc_invoke_arguments(argc, argv)
#else /* TCL_MAJOR_VERSION < 8 */
/* string interface */
- /* av = ALLOC_N(char *, argc+1); */
- av = (char**)ckalloc(sizeof(char *) * (argc+1));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)av); /* XXXXXXXX */
-#endif
+ av = ALLOC_N(char *, argc+1);
for (i = 0; i < argc; ++i) {
av[i] = strdup(StringValuePtr(argv[i]));
}
@@ -8126,34 +6828,11 @@ free_invoke_arguments(argc, av)
for (i = 0; i < argc; ++i) {
#if TCL_MAJOR_VERSION >= 8
Tcl_DecrRefCount(av[i]);
- av[i] = (Tcl_Obj*)NULL;
#else /* TCL_MAJOR_VERSION < 8 */
free(av[i]);
- av[i] = (char*)NULL;
#endif
}
-#if TCL_MAJOR_VERSION >= 8
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)av, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)av); /* XXXXXXXX */
-#else
- ckfree((char*)av);
-#endif
-#endif
-#else /* TCL_MAJOR_VERSION < 8 */
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)av, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)av); /* XXXXXXXX */
-#else
- /* free(av); */
- ckfree((char*)av);
-#endif
-#endif
-#endif
+ free(av);
}
static VALUE
@@ -8216,12 +6895,10 @@ invoke_queue_handler(evPtr, flags)
struct invoke_queue *q = (struct invoke_queue *)evPtr;
volatile VALUE ret;
volatile VALUE q_dat;
- volatile VALUE thread = q->thread;
- struct tcltkip *ptr;
DUMP2("do_invoke_queue_handler : evPtr = %p", evPtr);
DUMP2("invoke queue_thread : %lx", rb_thread_current());
- DUMP2("added by thread : %lx", thread);
+ DUMP2("added by thread : %lx", q->thread);
if (*(q->done)) {
DUMP1("processed by another event-loop");
@@ -8230,71 +6907,36 @@ invoke_queue_handler(evPtr, flags)
DUMP1("process it on current event-loop");
}
- if (RTEST(rb_thread_alive_p(thread))
- && ! RTEST(rb_funcall(thread, ID_stop_p, 0))) {
- DUMP1("caller is not yet ready to receive the result -> pending");
- return 0;
- }
-
/* process it */
*(q->done) = 1;
- /* deleted ipterp ? */
- ptr = get_ip(q->interp);
- if (deleted_ip(ptr)) {
- /* deleted IP --> ignore */
- return 1;
- }
-
- /* incr internal handler mark */
- rbtk_internal_eventloop_handler++;
-
/* check safe-level */
if (rb_safe_level() != q->safe_level) {
/* q_dat = Data_Wrap_Struct(rb_cData,0,0,q); */
- q_dat = Data_Wrap_Struct(rb_cData,invoke_queue_mark,-1,q);
+ q_dat = Data_Wrap_Struct(rb_cData,invoke_queue_mark,0,q);
ret = rb_funcall(rb_proc_new(ivq_safelevel_handler, q_dat),
ID_call, 0);
rb_gc_force_recycle(q_dat);
- q_dat = (VALUE)NULL;
} else {
- DUMP2("call invoke_real (for caller thread:%lx)", thread);
+ DUMP2("call invoke_real (for caller thread:%lx)", q->thread);
DUMP2("call invoke_real (current thread:%lx)", rb_thread_current());
ret = ip_invoke_core(q->interp, q->argc, q->argv);
}
/* set result */
- RARRAY_PTR(q->result)[0] = ret;
- ret = (VALUE)NULL;
-
- /* decr internal handler mark */
- rbtk_internal_eventloop_handler--;
+ RARRAY(q->result)->ptr[0] = ret;
/* complete */
*(q->done) = -1;
- /* unlink ruby objects */
- q->interp = (VALUE)NULL;
- q->result = (VALUE)NULL;
- q->thread = (VALUE)NULL;
-
/* back to caller */
- /* if (RTEST(rb_funcall(thread, ID_alive_p, 0, 0))) { */
- if (RTEST(rb_thread_alive_p(thread))) {
- DUMP2("back to caller (caller thread:%lx)", thread);
+ if (RTEST(rb_funcall(q->thread, ID_alive_p, 0, 0))) {
+ DUMP2("back to caller (caller thread:%lx)", q->thread);
DUMP2(" (current thread:%lx)", rb_thread_current());
-#if CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE
- have_rb_thread_waiting_for_value = 1;
- rb_thread_wakeup(thread);
-#else
- rb_thread_run(thread);
-#endif
+ rb_thread_run(q->thread);
DUMP1("finish back to caller");
-#if DO_THREAD_SCHEDULE_AT_CALLBACK_DONE
- rb_thread_schedule();
-#endif
} else {
- DUMP2("caller is dead (caller thread:%lx)", thread);
+ DUMP2("caller is dead (caller thread:%lx)", q->thread);
DUMP2(" (current thread:%lx)", rb_thread_current());
}
@@ -8310,9 +6952,6 @@ ip_invoke_with_position(argc, argv, obj, position)
Tcl_QueuePosition position;
{
struct invoke_queue *ivq;
-#ifdef RUBY_VM
- struct tcltkip *ptr;
-#endif
int *alloc_done;
int thr_crit_bup;
volatile VALUE current = rb_thread_current();
@@ -8329,21 +6968,7 @@ ip_invoke_with_position(argc, argv, obj, position)
if (argc < 1) {
rb_raise(rb_eArgError, "command name missing");
}
-
-#ifdef RUBY_VM
- ptr = get_ip(ip_obj);
- DUMP2("status: ptr->tk_thread_id %d", ptr->tk_thread_id);
-#endif
- DUMP2("status: Tcl_GetCurrentThread %d", Tcl_GetCurrentThread());
- DUMP2("status: eventloopt_thread %lx", eventloop_thread);
-
- if (
-#ifdef RUBY_VM
- (ptr->tk_thread_id == 0 || ptr->tk_thread_id == Tcl_GetCurrentThread())
- &&
-#endif
- (NIL_P(eventloop_thread) || current == eventloop_thread)
- ) {
+ if (NIL_P(eventloop_thread) || current == eventloop_thread) {
if (NIL_P(eventloop_thread)) {
DUMP2("invoke from thread:%lx but no eventloop", current);
} else {
@@ -8365,22 +6990,17 @@ ip_invoke_with_position(argc, argv, obj, position)
av = alloc_invoke_arguments(argc, argv);
/* allocate memory (keep result) */
- /* alloc_done = (int*)ALLOC(int); */
- alloc_done = (int*)ckalloc(sizeof(int));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)alloc_done); /* XXXXXXXX */
-#endif
+ alloc_done = (int*)ALLOC(int);
*alloc_done = 0;
/* allocate memory (freed by Tcl_ServiceEvent) */
- /* ivq = (struct invoke_queue *)Tcl_Alloc(sizeof(struct invoke_queue)); */
- ivq = (struct invoke_queue *)ckalloc(sizeof(struct invoke_queue));
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)ivq); /* XXXXXXXX */
-#endif
+ ivq = (struct invoke_queue *)Tcl_Alloc(sizeof(struct invoke_queue));
+ Tcl_Preserve(ivq);
/* allocate result obj */
- result = rb_ary_new3(1, Qnil);
+ result = rb_ary_new2(1);
+ RARRAY(result)->ptr[0] = Qnil;
+ RARRAY(result)->len = 1;
/* construct event data */
ivq->done = alloc_done;
@@ -8394,60 +7014,22 @@ ip_invoke_with_position(argc, argv, obj, position)
/* add the handler to Tcl event queue */
DUMP1("add handler");
-#ifdef RUBY_VM
- if (ptr->tk_thread_id) {
- /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(ivq->ev), position); */
- Tcl_ThreadQueueEvent(ptr->tk_thread_id, (Tcl_Event*)ivq, position);
- Tcl_ThreadAlert(ptr->tk_thread_id);
- } else if (tk_eventloop_thread_id) {
- /* Tcl_ThreadQueueEvent(tk_eventloop_thread_id,
- &(ivq->ev), position); */
- Tcl_ThreadQueueEvent(tk_eventloop_thread_id,
- (Tcl_Event*)ivq, position);
- Tcl_ThreadAlert(tk_eventloop_thread_id);
- } else {
- /* Tcl_QueueEvent(&(ivq->ev), position); */
- Tcl_QueueEvent((Tcl_Event*)ivq, position);
- }
-#else
- /* Tcl_QueueEvent(&(ivq->ev), position); */
- Tcl_QueueEvent((Tcl_Event*)ivq, position);
-#endif
+ Tcl_QueueEvent(&(ivq->ev), position);
rb_thread_critical = thr_crit_bup;
/* wait for the handler to be processed */
DUMP2("wait for handler (current thread:%lx)", current);
while(*alloc_done >= 0) {
- /* rb_thread_stop(); */
- rb_thread_sleep_forever();
+ rb_thread_stop();
}
DUMP2("back from handler (current thread:%lx)", current);
/* get result & free allocated memory */
ret = RARRAY(result)->ptr[0];
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)alloc_done, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)alloc_done); /* XXXXXXXX */
-#else
- /* free(alloc_done); */
- ckfree((char*)alloc_done);
-#endif
-#endif
+ free(alloc_done);
-#if 0 /* ivq is freed by Tcl_ServiceEvent */
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)ivq, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
Tcl_Release(ivq);
-#else
- ckfree((char*)ivq);
-#endif
-#endif
-#endif
/* free allocated memory */
free_invoke_arguments(argc, av);
@@ -8455,9 +7037,7 @@ ip_invoke_with_position(argc, argv, obj, position)
/* exception? */
if (rb_obj_is_kind_of(ret, rb_eException)) {
DUMP1("raise exception");
- /* rb_exc_raise(ret); */
- rb_exc_raise(rb_exc_new3(rb_obj_class(ret),
- rb_funcall(ret, ID_to_s, 0, 0)));
+ rb_exc_raise(ret);
}
DUMP1("exit ip_invoke");
@@ -8539,8 +7119,8 @@ ip_get_variable2_core(interp, argc, argv)
} else {
/* Tcl_Preserve(ptr->ip); */
rbtk_preserve_ip(ptr);
- ret = Tcl_GetVar2Ex(ptr->ip, RSTRING_PTR(varname),
- NIL_P(index) ? NULL : RSTRING_PTR(index),
+ ret = Tcl_GetVar2Ex(ptr->ip, RSTRING(varname)->ptr,
+ NIL_P(index) ? NULL : RSTRING(index)->ptr,
FIX2INT(flag));
}
@@ -8577,8 +7157,8 @@ ip_get_variable2_core(interp, argc, argv)
} else {
/* Tcl_Preserve(ptr->ip); */
rbtk_preserve_ip(ptr);
- ret = Tcl_GetVar2(ptr->ip, RSTRING_PTR(varname),
- NIL_P(index) ? NULL : RSTRING_PTR(index),
+ ret = Tcl_GetVar2(ptr->ip, RSTRING(varname)->ptr,
+ NIL_P(index) ? NULL : RSTRING(index)->ptr,
FIX2INT(flag));
}
@@ -8676,8 +7256,8 @@ ip_set_variable2_core(interp, argc, argv)
} else {
/* Tcl_Preserve(ptr->ip); */
rbtk_preserve_ip(ptr);
- ret = Tcl_SetVar2Ex(ptr->ip, RSTRING_PTR(varname),
- NIL_P(index) ? NULL : RSTRING_PTR(index),
+ ret = Tcl_SetVar2Ex(ptr->ip, RSTRING(varname)->ptr,
+ NIL_P(index) ? NULL : RSTRING(index)->ptr,
valobj, FIX2INT(flag));
}
@@ -8717,9 +7297,9 @@ ip_set_variable2_core(interp, argc, argv)
} else {
/* Tcl_Preserve(ptr->ip); */
rbtk_preserve_ip(ptr);
- ret = Tcl_SetVar2(ptr->ip, RSTRING_PTR(varname),
- NIL_P(index) ? NULL : RSTRING_PTR(index),
- RSTRING_PTR(value), FIX2INT(flag));
+ ret = Tcl_SetVar2(ptr->ip, RSTRING(varname)->ptr,
+ NIL_P(index) ? NULL : RSTRING(index)->ptr,
+ RSTRING(value)->ptr, FIX2INT(flag));
}
if (ret == (char*)NULL) {
@@ -8799,8 +7379,8 @@ ip_unset_variable2_core(interp, argc, argv)
return Qtrue;
}
- ptr->return_value = Tcl_UnsetVar2(ptr->ip, RSTRING_PTR(varname),
- NIL_P(index) ? NULL : RSTRING_PTR(index),
+ ptr->return_value = Tcl_UnsetVar2(ptr->ip, RSTRING(varname)->ptr,
+ NIL_P(index) ? NULL : RSTRING(index)->ptr,
FIX2INT(flag));
if (ptr->return_value == TCL_ERROR) {
@@ -8920,10 +7500,6 @@ lib_split_tklist_core(ip_obj, list_str)
volatile VALUE ary, elem;
int idx;
int taint_flag = OBJ_TAINTED(list_str);
-#ifdef RUBY_VM
- int list_enc_idx;
- volatile VALUE list_ivar_enc;
-#endif
int result;
VALUE old_gc;
@@ -8938,10 +7514,6 @@ lib_split_tklist_core(ip_obj, list_str)
}
StringValue(list_str);
-#ifdef RUBY_VM
- list_enc_idx = rb_enc_get_index(list_str);
- list_ivar_enc = rb_ivar_get(list_str, ID_at_enc);
-#endif
{
#if TCL_MAJOR_VERSION >= 8
@@ -8980,21 +7552,11 @@ lib_split_tklist_core(ip_obj, list_str)
for(idx = 0; idx < objc; idx++) {
elem = get_str_from_obj(objv[idx]);
-#ifdef RUBY_VM
- if (rb_enc_get_index(elem) == ENCODING_INDEX_BINARY) {
- rb_enc_associate_index(elem, ENCODING_INDEX_BINARY);
- rb_ivar_set(elem, ID_at_enc, ENCODING_NAME_BINARY);
- } else {
- rb_enc_associate_index(elem, list_enc_idx);
- rb_ivar_set(elem, ID_at_enc, list_ivar_enc);
- }
-#endif
if (taint_flag) OBJ_TAINT(elem);
- /* RARRAY(ary)->ptr[idx] = elem; */
- rb_ary_push(ary, elem);
+ RARRAY(ary)->ptr[idx] = elem;
}
- /* RARRAY(ary)->len = objc; */
+ RARRAY(ary)->len = objc;
if (old_gc == Qfalse) rb_gc_enable();
@@ -9011,7 +7573,7 @@ lib_split_tklist_core(ip_obj, list_str)
int argc;
char **argv;
- if (Tcl_SplitList(interp, RSTRING_PTR(list_str),
+ if (Tcl_SplitList(interp, RSTRING(list_str)->ptr,
&argc, &argv) == TCL_ERROR) {
if (interp == (Tcl_Interp*)NULL) {
rb_raise(rb_eRuntimeError, "can't get elements from list");
@@ -9032,10 +7594,9 @@ lib_split_tklist_core(ip_obj, list_str)
elem = rb_str_new2(argv[idx]);
}
/* rb_ivar_set(elem, ID_at_enc, rb_str_new2("binary")); */
- /* RARRAY(ary)->ptr[idx] = elem; */
- rb_ary_push(ary, elem)
+ RARRAY(ary)->ptr[idx] = elem;
}
- /* RARRAY(ary)->len = argc; */
+ RARRAY(ary)->len = argc;
if (old_gc == Qfalse) rb_gc_enable();
#endif
@@ -9084,11 +7645,7 @@ lib_merge_tklist(argc, argv, obj)
old_gc = rb_gc_disable();
/* based on Tcl/Tk's Tcl_Merge() */
- /* flagPtr = ALLOC_N(int, argc); */
- flagPtr = (int *)ckalloc(sizeof(int) * argc);
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)flagPtr); /* XXXXXXXXXX */
-#endif
+ flagPtr = ALLOC_N(int, argc);
/* pass 1 */
len = 1;
@@ -9096,7 +7653,7 @@ lib_merge_tklist(argc, argv, obj)
if (OBJ_TAINTED(argv[num])) taint_flag = 1;
dst = StringValuePtr(argv[num]);
#if TCL_MAJOR_VERSION >= 8
- len += Tcl_ScanCountedElement(dst, RSTRING_LEN(argv[num]),
+ len += Tcl_ScanCountedElement(dst, RSTRING(argv[num])->len,
&flagPtr[num]) + 1;
#else /* TCL_MAJOR_VERSION < 8 */
len += Tcl_ScanElement(dst, &flagPtr[num]) + 1;
@@ -9104,19 +7661,15 @@ lib_merge_tklist(argc, argv, obj)
}
/* pass 2 */
- /* result = (char *)Tcl_Alloc(len); */
- result = (char *)ckalloc(len);
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Preserve((ClientData)result);
-#endif
+ result = (char *)Tcl_Alloc(len);
dst = result;
for(num = 0; num < argc; num++) {
#if TCL_MAJOR_VERSION >= 8
- len = Tcl_ConvertCountedElement(RSTRING_PTR(argv[num]),
- RSTRING_LEN(argv[num]),
+ len = Tcl_ConvertCountedElement(RSTRING(argv[num])->ptr,
+ RSTRING(argv[num])->len,
dst, flagPtr[num]);
#else /* TCL_MAJOR_VERSION < 8 */
- len = Tcl_ConvertElement(RSTRING_PTR(argv[num]), dst, flagPtr[num]);
+ len = Tcl_ConvertElement(RSTRING(argv[num])->ptr, dst, flagPtr[num]);
#endif
dst += len;
*dst = ' ';
@@ -9128,30 +7681,12 @@ lib_merge_tklist(argc, argv, obj)
dst[-1] = 0;
}
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)flagPtr, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)flagPtr);
-#else
- /* free(flagPtr); */
- ckfree((char*)flagPtr);
-#endif
-#endif
+ free(flagPtr);
/* create object */
str = rb_str_new(result, dst - result - 1);
if (taint_flag) OBJ_TAINT(str);
-#if 0 /* use Tcl_EventuallyFree */
- Tcl_EventuallyFree((ClientData)result, TCL_DYNAMIC); /* XXXXXXXX */
-#else
-#if 0 /* use Tcl_Preserve/Release */
- Tcl_Release((ClientData)result); /* XXXXXXXXXXX */
-#else
- /* Tcl_Free(result); */
- ckfree(result);
-#endif
-#endif
+ Tcl_Free(result);
if (old_gc == Qfalse) rb_gc_enable();
rb_thread_critical = thr_crit_bup;
@@ -9177,18 +7712,19 @@ lib_conv_listelement(self, src)
StringValue(src);
#if TCL_MAJOR_VERSION >= 8
- len = Tcl_ScanCountedElement(RSTRING_PTR(src), RSTRING_LEN(src),
+ len = Tcl_ScanCountedElement(RSTRING(src)->ptr, RSTRING(src)->len,
&scan_flag);
dst = rb_str_new(0, len + 1);
- len = Tcl_ConvertCountedElement(RSTRING_PTR(src), RSTRING_LEN(src),
- RSTRING_PTR(dst), scan_flag);
+ len = Tcl_ConvertCountedElement(RSTRING(src)->ptr, RSTRING(src)->len,
+ RSTRING(dst)->ptr, scan_flag);
#else /* TCL_MAJOR_VERSION < 8 */
- len = Tcl_ScanElement(RSTRING_PTR(src), &scan_flag);
+ len = Tcl_ScanElement(RSTRING(src)->ptr, &scan_flag);
dst = rb_str_new(0, len + 1);
- len = Tcl_ConvertElement(RSTRING_PTR(src), RSTRING_PTR(dst), scan_flag);
+ len = Tcl_ConvertElement(RSTRING(src)->ptr, RSTRING(dst)->ptr, scan_flag);
#endif
- rb_str_resize(dst, len);
+ RSTRING(dst)->len = len;
+ RSTRING(dst)->ptr[len] = '\0';
if (taint_flag) OBJ_TAINT(dst);
rb_thread_critical = thr_crit_bup;
@@ -9196,34 +7732,6 @@ lib_conv_listelement(self, src)
return dst;
}
-static VALUE
-lib_getversion(self)
- VALUE self;
-{
- volatile VALUE type_name;
-
- set_tcltk_version();
-
- switch(tcltk_version.type) {
- case TCL_ALPHA_RELEASE:
- type_name = rb_str_new2("alpha");
- break;
- case TCL_BETA_RELEASE:
- type_name = rb_str_new2("beta");
- break;
- case TCL_FINAL_RELEASE:
- type_name = rb_str_new2("final");
- break;
- default:
- type_name = rb_str_new2("unknown");
- }
-
- return rb_ary_new3(5, INT2NUM(tcltk_version.major),
- INT2NUM(tcltk_version.minor),
- INT2NUM(tcltk_version.type), type_name,
- INT2NUM(tcltk_version.patchlevel));
-}
-
static VALUE
tcltklib_compile_info()
@@ -9246,7 +7754,6 @@ tcltklib_compile_info()
+ strlen("unknown tcl_threads");
info = ALLOC_N(char, size);
- /* info = ckalloc(sizeof(char) * size); */ /* SEGV */
sprintf(info, form,
TCLTKLIB_RELEASE_DATE,
@@ -9282,532 +7789,15 @@ tcltklib_compile_info()
ret = rb_obj_freeze(rb_str_new2(info));
free(info);
- /* ckfree(info); */
return ret;
}
-
-/*###############################################*/
-
-static VALUE
-create_dummy_encoding_for_tk_core(interp, name, error_mode)
- VALUE interp;
- VALUE name;
- VALUE error_mode;
-{
- struct tcltkip *ptr = get_ip(interp);
-
- rb_secure(4);
-
- StringValue(name);
-
-#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1)
- if (Tcl_GetEncoding((Tcl_Interp*)NULL, RSTRING_PTR(name)) == (Tcl_Encoding)NULL) {
- if (RTEST(error_mode)) {
- rb_raise(rb_eArgError, "invalid Tk encoding name '%s'",
- RSTRING_PTR(name));
- } else {
- return Qnil;
- }
- }
-#endif
-
-#ifdef RUBY_VM
- if (RTEST(rb_define_dummy_encoding(RSTRING_PTR(name)))) {
- int idx = rb_enc_find_index(StringValueCStr(name));
- return rb_enc_from_encoding(rb_enc_from_index(idx));
- } else {
- if (RTEST(error_mode)) {
- rb_raise(rb_eRuntimeError, "fail to create dummy encoding for '%s'",
- RSTRING_PTR(name));
- } else {
- return Qnil;
- }
- }
-#else
- return name;
-#endif
-}
-static VALUE
-create_dummy_encoding_for_tk(interp, name)
- VALUE interp;
- VALUE name;
-{
- return create_dummy_encoding_for_tk_core(interp, name, Qtrue);
-}
-
-
-#ifdef RUBY_VM
-static int
-update_encoding_table(table, interp, error_mode)
- VALUE table;
- VALUE interp;
- VALUE error_mode;
-{
- struct tcltkip *ptr;
- int retry = 0;
- int i, idx, objc;
- Tcl_Obj **objv;
- Tcl_Obj *enc_list;
- volatile VALUE encname = Qnil;
- volatile VALUE encobj = Qnil;
-
- /* interpreter check */
- if (NIL_P(interp)) return 0;
- ptr = get_ip(interp);
- if (ptr == (struct tcltkip *) NULL) return 0;
- if (deleted_ip(ptr)) return 0;
-
- /* get Tcl's encoding list */
- Tcl_GetEncodingNames(ptr->ip);
- enc_list = Tcl_GetObjResult(ptr->ip);
- Tcl_IncrRefCount(enc_list);
-
- if (Tcl_ListObjGetElements(ptr->ip, enc_list,
- &objc, &objv) != TCL_OK) {
- Tcl_DecrRefCount(enc_list);
- /* rb_raise(rb_eRuntimeError, "failt to get Tcl's encoding names");*/
- return 0;
- }
-
- /* check each encoding name */
- for(i = 0; i < objc; i++) {
- encname = rb_str_new2(Tcl_GetString(objv[i]));
- if (NIL_P(rb_hash_lookup(table, encname))) {
- /* new Tk encoding -> add to table */
- idx = rb_enc_find_index(StringValueCStr(encname));
- if (idx < 0) {
- encobj = create_dummy_encoding_for_tk_core(interp,encname,error_mode);
- } else {
- encobj = rb_enc_from_encoding(rb_enc_from_index(idx));
- }
- encname = rb_obj_freeze(encname);
- rb_hash_aset(table, encname, encobj);
- if (!NIL_P(encobj) && NIL_P(rb_hash_lookup(table, encobj))) {
- rb_hash_aset(table, encobj, encname);
- }
- retry = 1;
- }
- }
-
- Tcl_DecrRefCount(enc_list);
-
- return retry;
-}
-
-static VALUE
-encoding_table_get_name_core(table, enc_arg, error_mode)
- VALUE table;
- VALUE enc_arg;
- VALUE error_mode;
-{
- volatile VALUE enc = enc_arg;
- volatile VALUE name = Qnil;
- volatile VALUE tmp = Qnil;
- volatile VALUE interp = rb_ivar_get(table, ID_at_interp);
- struct tcltkip *ptr = (struct tcltkip *) NULL;
- int idx;
-
- /* deleted interp ? */
- if (!NIL_P(interp)) {
- ptr = get_ip(interp);
- if (deleted_ip(ptr)) {
- ptr = (struct tcltkip *) NULL;
- }
- }
-
- /* encoding argument check */
- /* 1st: default encoding setting of interp */
- if (ptr && NIL_P(enc)) {
- if (rb_respond_to(interp, ID_encoding_name)) {
- enc = rb_funcall(interp, ID_encoding_name, 0, 0);
- }
- }
- /* 2nd: encoding system of Tcl/Tk */
- if (NIL_P(enc)) {
- enc = rb_str_new2(Tcl_GetEncodingName((Tcl_Encoding)NULL));
- }
- /* 3rd: Encoding.default_external */
- if (NIL_P(enc)) {
- enc = rb_enc_default_external();
- }
-
- if (RTEST(rb_obj_is_kind_of(enc, cRubyEncoding))) {
- /* Ruby's Encoding object */
- name = rb_hash_lookup(table, enc);
- if (!NIL_P(name)) {
- /* find */
- return name;
- }
-
- /* is it new ? */
- /* update check of Tk encoding names */
- if (update_encoding_table(table, interp, error_mode)) {
- /* add new relations to the table */
- /* RETRY: registered Ruby encoding? */
- name = rb_hash_lookup(table, enc);
- if (!NIL_P(name)) {
- /* find */
- return name;
- }
- }
- /* fail to find */
-
- } else {
- /* String or Symbol? */
- name = rb_funcall(enc, ID_to_s, 0, 0);
-
- if (!NIL_P(rb_hash_lookup(table, name))) {
- /* find */
- return name;
- }
-
- /* is it new ? */
- idx = rb_enc_find_index(StringValueCStr(name));
- if (idx >= 0) {
- enc = rb_enc_from_encoding(rb_enc_from_index(idx));
-
- /* registered Ruby encoding? */
- tmp = rb_hash_lookup(table, enc);
- if (!NIL_P(tmp)) {
- /* find */
- return tmp;
- }
-
- /* update check of Tk encoding names */
- if (update_encoding_table(table, interp, error_mode)) {
- /* add new relations to the table */
- /* RETRY: registered Ruby encoding? */
- tmp = rb_hash_lookup(table, enc);
- if (!NIL_P(tmp)) {
- /* find */
- return tmp;
- }
- }
- }
- /* fail to find */
- }
-
- if (RTEST(error_mode)) {
- enc = rb_funcall(enc_arg, ID_to_s, 0, 0);
- rb_raise(rb_eArgError, "unsupported Tk encoding '%s'", RSTRING_PTR(enc));
- }
- return Qnil;
-}
-static VALUE
-encoding_table_get_obj_core(table, enc, error_mode)
- VALUE table;
- VALUE enc;
- VALUE error_mode;
-{
- volatile VALUE obj = Qnil;
-
- obj = rb_hash_lookup(table,
- encoding_table_get_name_core(table, enc, error_mode));
- if (RTEST(rb_obj_is_kind_of(obj, cRubyEncoding))) {
- return obj;
- } else {
- return Qnil;
- }
-}
-
-#else /* ! RUBY_VM */
-#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1)
-static int
-update_encoding_table(table, interp, error_mode)
- VALUE table;
- VALUE interp;
- VALUE error_mode;
-{
- struct tcltkip *ptr;
- int retry = 0;
- int i, idx, objc;
- Tcl_Obj **objv;
- Tcl_Obj *enc_list;
- volatile VALUE encname = Qnil;
- volatile VALUE encobj = Qnil;
-
- /* interpreter check */
- if (NIL_P(interp)) return 0;
- ptr = get_ip(interp);
- if (ptr == (struct tcltkip *) NULL) return 0;
- if (deleted_ip(ptr)) return 0;
-
- /* get Tcl's encoding list */
- Tcl_GetEncodingNames(ptr->ip);
- enc_list = Tcl_GetObjResult(ptr->ip);
- Tcl_IncrRefCount(enc_list);
-
- if (Tcl_ListObjGetElements(ptr->ip, enc_list, &objc, &objv) != TCL_OK) {
- Tcl_DecrRefCount(enc_list);
- /* rb_raise(rb_eRuntimeError, "failt to get Tcl's encoding names"); */
- return 0;
- }
-
- /* get encoding name and set it to table */
- for(i = 0; i < objc; i++) {
- encname = rb_str_new2(Tcl_GetString(objv[i]));
- if (NIL_P(rb_hash_lookup(table, encname))) {
- /* new Tk encoding -> add to table */
- encname = rb_obj_freeze(encname);
- rb_hash_aset(table, encname, encname);
- retry = 1;
- }
- }
-
- Tcl_DecrRefCount(enc_list);
-
- return retry;
-}
-
-static VALUE
-encoding_table_get_name_core(table, enc, error_mode)
- VALUE table;
- VALUE enc;
- VALUE error_mode;
-{
- volatile VALUE name = Qnil;
- int retry = 0;
-
- enc = rb_funcall(enc, ID_to_s, 0, 0);
- name = rb_hash_lookup(table, enc);
-
- if (!NIL_P(name)) {
- /* find */
- return name;
- }
-
- /* update check */
- if (update_encoding_table(table, rb_ivar_get(table, ID_at_interp),
- error_mode)) {
- /* add new relations to the table */
- /* RETRY: registered Ruby encoding? */
- name = rb_hash_lookup(table, enc);
- if (!NIL_P(name)) {
- /* find */
- return name;
- }
- }
-
- if (RTEST(error_mode)) {
- rb_raise(rb_eArgError, "unsupported Tk encoding '%s'", RSTRING_PTR(enc));
- }
- return Qnil;
-}
-static VALUE
-encoding_table_get_obj_core(table, enc, error_mode)
- VALUE table;
- VALUE enc;
- VALUE error_mode;
-{
- return encoding_table_get_name_core(table, enc, error_mode);
-}
-
-#else /* Tcl/Tk 7.x or 8.0 */
-static VALUE
-encoding_table_get_name_core(table, enc, error_mode)
- VALUE table;
- VALUE enc;
- VALUE error_mode;
-{
- return Qnil;
-}
-static VALUE
-encoding_table_get_obj_core(table, enc, error_mode)
- VALUE table;
- VALUE enc;
- VALUE error_mode;
-{
- return Qnil;
-}
-#endif /* end of dependency for the version of Tcl/Tk */
-#endif
-
-static VALUE
-encoding_table_get_name(table, enc)
- VALUE table;
- VALUE enc;
-{
- return encoding_table_get_name_core(table, enc, Qtrue);
-}
-static VALUE
-encoding_table_get_obj(table, enc)
- VALUE table;
- VALUE enc;
-{
- return encoding_table_get_obj_core(table, enc, Qtrue);
-}
-
-#ifdef RUBY_VM
-static VALUE
-create_encoding_table(interp)
- VALUE interp;
-{
- struct tcltkip *ptr = get_ip(interp);
- volatile VALUE table = rb_hash_new();
- volatile VALUE encname = Qnil;
- volatile VALUE encobj = Qnil;
- int i, idx, objc;
- Tcl_Obj **objv;
- Tcl_Obj *enc_list;
-
- rb_secure(4);
-
- /* set 'binary' encoding */
- encobj = rb_enc_from_encoding(rb_enc_from_index(ENCODING_INDEX_BINARY));
- rb_hash_aset(table, ENCODING_NAME_BINARY, encobj);
- rb_hash_aset(table, encobj, ENCODING_NAME_BINARY);
-
-
- /* Tcl stub check */
- tcl_stubs_check();
-
- /* get Tcl's encoding list */
- Tcl_GetEncodingNames(ptr->ip);
- enc_list = Tcl_GetObjResult(ptr->ip);
- Tcl_IncrRefCount(enc_list);
-
- if (Tcl_ListObjGetElements(ptr->ip, enc_list, &objc, &objv) != TCL_OK) {
- Tcl_DecrRefCount(enc_list);
- rb_raise(rb_eRuntimeError, "failt to get Tcl's encoding names");
- }
-
- /* get encoding name and set it to table */
- for(i = 0; i < objc; i++) {
- int name2obj, obj2name;
-
- name2obj = 1; obj2name = 1;
- encname = rb_obj_freeze(rb_str_new2(Tcl_GetString(objv[i])));
- idx = rb_enc_find_index(StringValueCStr(encname));
- if (idx < 0) {
- /* fail to find ruby encoding -> check known encoding */
- if (strcmp(RSTRING_PTR(encname), "identity") == 0) {
- name2obj = 1; obj2name = 0;
- idx = ENCODING_INDEX_BINARY;
-
- } else if (strcmp(RSTRING_PTR(encname), "shiftjis") == 0) {
- name2obj = 1; obj2name = 0;
- idx = rb_enc_find_index("Shift_JIS");
-
- } else if (strcmp(RSTRING_PTR(encname), "unicode") == 0) {
- name2obj = 1; obj2name = 0;
- idx = ENCODING_INDEX_UTF8;
-
- } else if (strcmp(RSTRING_PTR(encname), "symbol") == 0) {
- name2obj = 1; obj2name = 0;
- idx = rb_enc_find_index("ASCII-8BIT");
-
- } else {
- /* regist dummy encoding */
- name2obj = 1; obj2name = 1;
- }
- }
-
- if (idx < 0) {
- /* unknown encoding -> create dummy */
- encobj = create_dummy_encoding_for_tk(interp, encname);
- } else {
- encobj = rb_enc_from_encoding(rb_enc_from_index(idx));
- }
-
- if (name2obj) {
- DUMP2("create_encoding_table: name2obj: %s", RSTRING_PTR(encname));
- rb_hash_aset(table, encname, encobj);
- }
- if (obj2name) {
- DUMP2("create_encoding_table: obj2name: %s", RSTRING_PTR(encname));
- rb_hash_aset(table, encobj, encname);
- }
- }
-
- Tcl_DecrRefCount(enc_list);
-
- rb_ivar_set(table, ID_at_interp, interp);
- rb_ivar_set(interp, ID_encoding_table, table);
-
- return table;
-}
-
-#else /* ! RUBY_VM */
-#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1)
-static VALUE
-create_encoding_table(interp)
- VALUE interp;
-{
- struct tcltkip *ptr = get_ip(interp);
- volatile VALUE table = rb_hash_new();
- volatile VALUE encname = Qnil;
- int i, objc;
- Tcl_Obj **objv;
- Tcl_Obj *enc_list;
-
- rb_secure(4);
-
- /* set 'binary' encoding */
- rb_hash_aset(table, ENCODING_NAME_BINARY, ENCODING_NAME_BINARY);
-
- /* get Tcl's encoding list */
- Tcl_GetEncodingNames(ptr->ip);
- enc_list = Tcl_GetObjResult(ptr->ip);
- Tcl_IncrRefCount(enc_list);
-
- if (Tcl_ListObjGetElements(ptr->ip, enc_list, &objc, &objv) != TCL_OK) {
- Tcl_DecrRefCount(enc_list);
- rb_raise(rb_eRuntimeError, "failt to get Tcl's encoding names");
- }
-
- /* get encoding name and set it to table */
- for(i = 0; i < objc; i++) {
- encname = rb_obj_freeze(rb_str_new2(Tcl_GetString(objv[i])));
- rb_hash_aset(table, encname, encname);
- }
-
- Tcl_DecrRefCount(enc_list);
-
- rb_ivar_set(table, ID_at_interp, interp);
- rb_ivar_set(interp, ID_encoding_table, table);
-
- return table;
-}
-
-#else /* Tcl/Tk 7.x or 8.0 */
-static VALUE
-create_encoding_table(interp)
- VALUE interp;
-{
- volatile VALUE table = rb_hash_new();
- rb_secure(4);
- rb_ivar_set(interp, ID_encoding_table, table);
- return table;
-}
-#endif
-#endif
-
-static VALUE
-ip_get_encoding_table(interp)
- VALUE interp;
-{
- volatile VALUE table = Qnil;
-
- table = rb_ivar_get(interp, ID_encoding_table);
-
- if (NIL_P(table)) {
- /* initialize encoding_table */
- table = create_encoding_table(interp);
- rb_define_singleton_method(table, "get_name", encoding_table_get_name, 1);
- rb_define_singleton_method(table, "get_obj", encoding_table_get_obj, 1);
- }
-
- return table;
-}
-
-
/*###############################################*/
/*
* The following is based on tkMenu.[ch]
- * of Tcl/Tk (Tk8.0 -- Tk8.5b1) source code.
+ * of Tcl/Tk (>=8.0) source code.
*/
#if TCL_MAJOR_VERSION >= 8
@@ -9841,45 +7831,22 @@ struct dummy_TkMenuRef {
char *dummy3;
};
-#if 0 /* was available on Tk8.0 -- Tk8.4 */
EXTERN struct dummy_TkMenuRef *TkFindMenuReferences(Tcl_Interp*, char*);
-#else /* based on Tk8.0 -- Tk8.5.0 */
-#define MENU_HASH_KEY "tkMenus"
-#endif
#endif
static VALUE
-ip_make_menu_embeddable_core(interp, argc, argv)
+ip_make_menu_embeddable(interp, menu_path)
VALUE interp;
- int argc;
- VALUE *argv;
+ VALUE menu_path;
{
#if TCL_MAJOR_VERSION >= 8
- volatile VALUE menu_path;
struct tcltkip *ptr = get_ip(interp);
- struct dummy_TkMenuRef *menuRefPtr = NULL;
- XEvent event;
- Tcl_HashTable *menuTablePtr;
- Tcl_HashEntry *hashEntryPtr;
+ struct dummy_TkMenuRef *menuRefPtr;
- menu_path = argv[0];
StringValue(menu_path);
-#if 0 /* was available on Tk8.0 -- Tk8.4 */
- menuRefPtr = TkFindMenuReferences(ptr->ip, RSTRING_PTR(menu_path));
-#else /* based on Tk8.0 -- Tk8.5b1 */
- if ((menuTablePtr
- = (Tcl_HashTable *) Tcl_GetAssocData(ptr->ip, MENU_HASH_KEY, NULL))
- != NULL) {
- if ((hashEntryPtr
- = Tcl_FindHashEntry(menuTablePtr, RSTRING_PTR(menu_path)))
- != NULL) {
- menuRefPtr = (struct dummy_TkMenuRef *) Tcl_GetHashValue(hashEntryPtr);
- }
- }
-#endif
-
+ menuRefPtr = TkFindMenuReferences(ptr->ip, RSTRING(menu_path)->ptr);
if (menuRefPtr == (struct dummy_TkMenuRef *) NULL) {
rb_raise(rb_eArgError, "not a menu widget, or invalid widget path");
}
@@ -9901,26 +7868,14 @@ ip_make_menu_embeddable_core(interp, argc, argv)
char *s = "normal";
/* Tcl_SetStringObj((menuRefPtr->menuPtr)->menuTypePtr, s, strlen(s));*/
(menuRefPtr->menuPtr)->menuTypePtr = Tcl_NewStringObj(s, strlen(s));
- /* Tcl_IncrRefCount((menuRefPtr->menuPtr)->menuTypePtr); */
/* (menuRefPtr->menuPtr)->menuType = TEAROFF_MENU; */
(menuRefPtr->menuPtr)->menuType = MASTER_MENU;
}
#endif
-#if 0 /* was available on Tk8.0 -- Tk8.4 */
TkEventuallyRecomputeMenu(menuRefPtr->menuPtr);
TkEventuallyRedrawMenu(menuRefPtr->menuPtr,
(struct dummy_TkMenuEntry *)NULL);
-#else /* based on Tk8.0 -- Tk8.5b1 */
- memset((void *) &event, 0, sizeof(event));
- event.xany.type = ConfigureNotify;
- event.xany.serial = NextRequest(Tk_Display((menuRefPtr->menuPtr)->tkwin));
- event.xany.send_event = 0; /* FALSE */
- event.xany.window = Tk_WindowId((menuRefPtr->menuPtr)->tkwin);
- event.xany.display = Tk_Display((menuRefPtr->menuPtr)->tkwin);
- event.xconfigure.window = event.xany.window;
- Tk_HandleEvent(&event);
-#endif
#else /* TCL_MAJOR_VERSION <= 7 */
rb_notimplement();
@@ -9929,18 +7884,6 @@ ip_make_menu_embeddable_core(interp, argc, argv)
return interp;
}
-static VALUE
-ip_make_menu_embeddable(interp, menu_path)
- VALUE interp;
- VALUE menu_path;
-{
- VALUE argv[1];
-
- argv[0] = menu_path;
- return tk_funcall(ip_make_menu_embeddable_core, 1, argv, interp);
-}
-
-
/*###############################################*/
/*---- initialization ----*/
@@ -9954,7 +7897,6 @@ Init_tcltklib()
VALUE ev_flag = rb_define_module_under(lib, "EventFlag");
VALUE var_flag = rb_define_module_under(lib, "VarAccessFlag");
- VALUE release_type = rb_define_module_under(lib, "RELEASE_TYPE");
/* --------------------------------------------------------------- */
@@ -9962,22 +7904,6 @@ Init_tcltklib()
/* --------------------------------------------------------------- */
-#ifdef RUBY_VM
- rb_global_variable(&cRubyEncoding);
- cRubyEncoding = rb_const_get(rb_cObject, rb_intern("Encoding"));
-
- ENCODING_INDEX_UTF8 = rb_enc_to_index(rb_utf8_encoding());
- ENCODING_INDEX_BINARY = rb_enc_find_index("binary");
-#endif
-
- rb_global_variable(&ENCODING_NAME_UTF8);
- rb_global_variable(&ENCODING_NAME_BINARY);
-
- ENCODING_NAME_UTF8 = rb_obj_freeze(rb_str_new2("utf-8"));
- ENCODING_NAME_BINARY = rb_obj_freeze(rb_str_new2("binary"));
-
- /* --------------------------------------------------------------- */
-
rb_global_variable(&eTkCallbackReturn);
rb_global_variable(&eTkCallbackBreak);
rb_global_variable(&eTkCallbackContinue);
@@ -10028,14 +7954,6 @@ Init_tcltklib()
/* --------------------------------------------------------------- */
- rb_define_module_function(lib, "get_version", lib_getversion, -1);
-
- rb_define_const(release_type, "ALPHA", INT2FIX(TCL_ALPHA_RELEASE));
- rb_define_const(release_type, "BETA", INT2FIX(TCL_BETA_RELEASE));
- rb_define_const(release_type, "FINAL", INT2FIX(TCL_FINAL_RELEASE));
-
- /* --------------------------------------------------------------- */
-
eTkCallbackReturn = rb_define_class("TkCallbackReturn", rb_eStandardError);
eTkCallbackBreak = rb_define_class("TkCallbackBreak", rb_eStandardError);
eTkCallbackContinue = rb_define_class("TkCallbackContinue",
@@ -10055,8 +7973,6 @@ Init_tcltklib()
ID_at_enc = rb_intern("@encoding");
ID_at_interp = rb_intern("@interp");
- ID_encoding_name = rb_intern("encoding_name");
- ID_encoding_table = rb_intern("encoding_table");
ID_stop_p = rb_intern("stop?");
ID_alive_p = rb_intern("alive?");
@@ -10090,10 +8006,6 @@ Init_tcltklib()
lib_evloop_abort_on_exc, 0);
rb_define_module_function(lib, "mainloop_abort_on_exception=",
lib_evloop_abort_on_exc_set, 1);
- rb_define_module_function(lib, "set_eventloop_window_mode",
- set_eventloop_window_mode, 1);
- rb_define_module_function(lib, "get_eventloop_window_mode",
- get_eventloop_window_mode, 0);
rb_define_module_function(lib, "set_eventloop_tick",set_eventloop_tick,1);
rb_define_module_function(lib, "get_eventloop_tick",get_eventloop_tick,0);
rb_define_module_function(lib, "set_no_event_wait", set_no_event_wait, 1);
@@ -10155,12 +8067,6 @@ Init_tcltklib()
/* --------------------------------------------------------------- */
- rb_define_method(ip, "create_dummy_encoding_for_tk",
- create_dummy_encoding_for_tk, 1);
- rb_define_method(ip, "encoding_table", ip_get_encoding_table, 0);
-
- /* --------------------------------------------------------------- */
-
rb_define_method(ip, "_get_variable", ip_get_variable, 2);
rb_define_method(ip, "_get_variable2", ip_get_variable2, 3);
rb_define_method(ip, "_set_variable", ip_set_variable, 3);
@@ -10220,11 +8126,7 @@ Init_tcltklib()
/* if ruby->nativethread-supprt and tcltklib->doen't,
the following will cause link-error. */
-#ifdef RUBY_VM
- ruby_native_thread_p();
-#else
is_ruby_native_thread();
-#endif
/* --------------------------------------------------------------- */
@@ -10232,7 +8134,7 @@ Init_tcltklib()
/* --------------------------------------------------------------- */
- ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
switch(ret) {
case TCLTK_STUBS_OK:
break;
@@ -10245,14 +8147,6 @@ Init_tcltklib()
}
/* --------------------------------------------------------------- */
-
- /* Tcl stub check */
- tcl_stubs_check();
-
- Tcl_ObjType_ByteArray = Tcl_GetObjType(Tcl_ObjTypeName_ByteArray);
- Tcl_ObjType_String = Tcl_GetObjType(Tcl_ObjTypeName_String);
-
- /* --------------------------------------------------------------- */
}
/* eof */
diff --git a/ext/tk/tkutil/extconf.rb b/ext/tk/tkutil/extconf.rb
index 015bc3a45e..dd00d5d535 100644
--- a/ext/tk/tkutil/extconf.rb
+++ b/ext/tk/tkutil/extconf.rb
@@ -7,7 +7,5 @@ end
if has_tk
require 'mkmf'
- have_func("rb_obj_instance_exec", "ruby.h")
- have_func("strndup", "string.h")
create_makefile('tkutil')
end
diff --git a/ext/tk/tkutil/tkutil.c b/ext/tk/tkutil/tkutil.c
index 00d719143b..f4271a724c 100644
--- a/ext/tk/tkutil/tkutil.c
+++ b/ext/tk/tkutil/tkutil.c
@@ -3,24 +3,17 @@
tkutil.c -
$Author$
+ $Date$
created at: Fri Nov 3 00:47:54 JST 1995
************************************************/
-#define TKUTIL_RELEASE_DATE "2008-05-23"
+#define TKUTIL_RELEASE_DATE "2006-04-06"
#include "ruby.h"
-
-#ifdef RUBY_VM /* Ruby 1.9 */
-/* #include "ruby/ruby.h" */
-#include "ruby/signal.h"
-#include "ruby/st.h"
-#else
-/* #include "ruby.h" */
#include "rubysig.h"
#include "version.h"
#include "st.h"
-#endif
static VALUE cMethod;
@@ -34,8 +27,6 @@ static VALUE TK_None;
static VALUE cCB_SUBST;
static VALUE cSUBST_INFO;
-static VALUE ENCODING_NAME_UTF8; /* for saving GC cost */
-
static ID ID_split_tklist;
static ID ID_toUTF8;
static ID ID_fromUTF8;
@@ -68,7 +59,7 @@ tk_s_new(argc, argv, klass)
VALUE obj = rb_class_new_instance(argc, argv, klass);
if (rb_block_given_p()) {
-#ifndef HAVE_RB_OBJ_INSTANCE_EXEC
+#if RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR <= 8 /* ruby 1.8.x */
rb_obj_instance_eval(0, 0, obj);
#else
rb_obj_instance_exec(1, &obj, obj);
@@ -164,16 +155,16 @@ tk_uninstall_cmd(self, cmd_id)
int prefix_len = strlen(cmd_id_prefix);
StringValue(cmd_id);
- if (strncmp(cmd_id_head, RSTRING_PTR(cmd_id), head_len) != 0) {
+ if (strncmp(cmd_id_head, RSTRING(cmd_id)->ptr, head_len) != 0) {
return Qnil;
}
if (strncmp(cmd_id_prefix,
- RSTRING_PTR(cmd_id) + head_len, prefix_len) != 0) {
+ RSTRING(cmd_id)->ptr + head_len, prefix_len) != 0) {
return Qnil;
}
return rb_hash_delete(CALLBACK_TABLE,
- rb_str_new2(RSTRING_PTR(cmd_id) + head_len));
+ rb_str_new2(RSTRING(cmd_id)->ptr + head_len));
}
static VALUE
@@ -236,7 +227,7 @@ tk_symbolkey2str(self, keys)
if NIL_P(keys) return new_keys;
keys = rb_convert_type(keys, T_HASH, "Hash", "to_hash");
- st_foreach(RHASH_TBL(keys), to_strkey, new_keys);
+ st_foreach(RHASH(keys)->tbl, to_strkey, new_keys);
return new_keys;
}
@@ -276,24 +267,25 @@ ary2list(ary, enc_flag, self)
req_chk_flag = 0;
}
- /* size = RARRAY_LEN(ary); */
+ /* size = RARRAY(ary)->len; */
size = 0;
- for(idx = 0; idx < RARRAY_LEN(ary); idx++) {
- if (TYPE(RARRAY_PTR(ary)[idx]) == T_HASH) {
- size += 2 * RHASH_SIZE(RARRAY_PTR(ary)[idx]);
+ for(idx = 0; idx < RARRAY(ary)->len; idx++) {
+ if (TYPE(RARRAY(ary)->ptr[idx]) == T_HASH) {
+ size += 2 * RHASH(RARRAY(ary)->ptr[idx])->tbl->num_entries;
} else {
size++;
}
}
dst = rb_ary_new2(size);
- for(idx = 0; idx < RARRAY_LEN(ary); idx++) {
- val = RARRAY_PTR(ary)[idx];
+ RARRAY(dst)->len = 0;
+ for(idx = 0; idx < RARRAY(ary)->len; idx++) {
+ val = RARRAY(ary)->ptr[idx];
str_val = Qnil;
switch(TYPE(val)) {
case T_ARRAY:
str_val = ary2list(val, enc_flag, self);
- rb_ary_push(dst, str_val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = str_val;
if (req_chk_flag) {
str_enc = rb_ivar_get(str_val, ID_at_enc);
@@ -311,19 +303,19 @@ ary2list(ary, enc_flag, self)
break;
case T_HASH:
- /* rb_ary_push(dst, hash2list(val, self)); */
+ /* RARRAY(dst)->ptr[RARRAY(dst)->len++] = hash2list(val, self); */
if (RTEST(enc_flag)) {
val = hash2kv_enc(val, Qnil, self);
} else {
val = hash2kv(val, Qnil, self);
}
- size2 = RARRAY_LEN(val);
+ size2 = RARRAY(val)->len;
for(idx2 = 0; idx2 < size2; idx2++) {
- val2 = RARRAY_PTR(val)[idx2];
+ val2 = RARRAY(val)->ptr[idx2];
switch(TYPE(val2)) {
case T_ARRAY:
str_val = ary2list(val2, enc_flag, self);
- rb_ary_push(dst, str_val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = str_val;
break;
case T_HASH:
@@ -332,13 +324,13 @@ ary2list(ary, enc_flag, self)
} else {
str_val = hash2list(val2, self);
}
- rb_ary_push(dst, str_val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = str_val;
break;
default:
if (val2 != TK_None) {
str_val = get_eval_string_core(val2, enc_flag, self);
- rb_ary_push(dst, str_val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = str_val;
}
}
@@ -360,7 +352,7 @@ ary2list(ary, enc_flag, self)
default:
if (val != TK_None) {
str_val = get_eval_string_core(val, enc_flag, self);
- rb_ary_push(dst, str_val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = str_val;
if (req_chk_flag) {
str_enc = rb_ivar_get(str_val, ID_at_enc);
@@ -379,21 +371,21 @@ ary2list(ary, enc_flag, self)
}
if (RTEST(dst_enc) && !NIL_P(sys_enc)) {
- for(idx = 0; idx < RARRAY_LEN(dst); idx++) {
- str_val = RARRAY_PTR(dst)[idx];
+ for(idx = 0; idx < RARRAY(dst)->len; idx++) {
+ str_val = RARRAY(dst)->ptr[idx];
if (rb_obj_respond_to(self, ID_toUTF8, Qtrue)) {
str_val = rb_funcall(self, ID_toUTF8, 1, str_val);
} else {
str_val = rb_funcall(cTclTkLib, ID_toUTF8, 1, str_val);
}
- RARRAY_PTR(dst)[idx] = str_val;
+ RARRAY(dst)->ptr[idx] = str_val;
}
val = rb_apply(cTclTkLib, ID_merge_tklist, dst);
if (TYPE(dst_enc) == T_STRING) {
val = rb_funcall(cTclTkLib, ID_fromUTF8, 2, val, dst_enc);
rb_ivar_set(val, ID_at_enc, dst_enc);
} else {
- rb_ivar_set(val, ID_at_enc, ENCODING_NAME_UTF8);
+ rb_ivar_set(val, ID_at_enc, rb_str_new2("utf-8"));
}
return val;
} else {
@@ -429,10 +421,11 @@ ary2list2(ary, enc_flag, self)
req_chk_flag = 0;
}
- size = RARRAY_LEN(ary);
+ size = RARRAY(ary)->len;
dst = rb_ary_new2(size);
- for(idx = 0; idx < RARRAY_LEN(ary); idx++) {
- val = RARRAY_PTR(ary)[idx];
+ RARRAY(dst)->len = 0;
+ for(idx = 0; idx < RARRAY(ary)->len; idx++) {
+ val = RARRAY(ary)->ptr[idx];
str_val = Qnil;
switch(TYPE(val)) {
case T_ARRAY:
@@ -454,7 +447,7 @@ ary2list2(ary, enc_flag, self)
}
if (!NIL_P(str_val)) {
- rb_ary_push(dst, str_val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = str_val;
if (req_chk_flag) {
str_enc = rb_ivar_get(str_val, ID_at_enc);
@@ -472,21 +465,21 @@ ary2list2(ary, enc_flag, self)
}
if (RTEST(dst_enc) && !NIL_P(sys_enc)) {
- for(idx = 0; idx < RARRAY_LEN(dst); idx++) {
- str_val = RARRAY_PTR(dst)[idx];
+ for(idx = 0; idx < RARRAY(dst)->len; idx++) {
+ str_val = RARRAY(dst)->ptr[idx];
if (rb_obj_respond_to(self, ID_toUTF8, Qtrue)) {
str_val = rb_funcall(self, ID_toUTF8, 1, str_val);
} else {
str_val = rb_funcall(cTclTkLib, ID_toUTF8, 1, str_val);
}
- RARRAY_PTR(dst)[idx] = str_val;
+ RARRAY(dst)->ptr[idx] = str_val;
}
val = rb_apply(cTclTkLib, ID_merge_tklist, dst);
if (TYPE(dst_enc) == T_STRING) {
val = rb_funcall(cTclTkLib, ID_fromUTF8, 2, val, dst_enc);
rb_ivar_set(val, ID_at_enc, dst_enc);
} else {
- rb_ivar_set(val, ID_at_enc, ENCODING_NAME_UTF8);
+ rb_ivar_set(val, ID_at_enc, rb_str_new2("utf-8"));
}
return val;
} else {
@@ -510,35 +503,38 @@ assoc2kv(assoc, ary, self)
int i, j, len;
volatile VALUE pair;
volatile VALUE val;
- volatile VALUE dst = rb_ary_new2(2 * RARRAY_LEN(assoc));
+ volatile VALUE dst = rb_ary_new2(2 * RARRAY(assoc)->len);
- len = RARRAY_LEN(assoc);
+ len = RARRAY(assoc)->len;
for(i = 0; i < len; i++) {
- pair = RARRAY_PTR(assoc)[i];
+ pair = RARRAY(assoc)->ptr[i];
if (TYPE(pair) != T_ARRAY) {
- rb_ary_push(dst, key2keyname(pair));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = key2keyname(pair);
continue;
}
- switch(RARRAY_LEN(assoc)) {
+ switch(RARRAY(assoc)->len) {
case 2:
- rb_ary_push(dst, RARRAY_PTR(pair)[2]);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = RARRAY(pair)->ptr[2];
case 1:
- rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0]));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = key2keyname(RARRAY(pair)->ptr[0]);
case 0:
continue;
default:
- rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0]));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = key2keyname(RARRAY(pair)->ptr[0]);
- val = rb_ary_new2(RARRAY_LEN(pair) - 1);
- for(j = 1; j < RARRAY_LEN(pair); j++) {
- rb_ary_push(val, RARRAY_PTR(pair)[j]);
+ val = rb_ary_new2(RARRAY(pair)->len - 1);
+ RARRAY(val)->len = 0;
+ for(j = 1; j < RARRAY(pair)->len; j++) {
+ RARRAY(val)->ptr[RARRAY(val)->len++] = RARRAY(pair)->ptr[j];
}
- rb_ary_push(dst, val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = val;
}
}
@@ -558,35 +554,40 @@ assoc2kv_enc(assoc, ary, self)
int i, j, len;
volatile VALUE pair;
volatile VALUE val;
- volatile VALUE dst = rb_ary_new2(2 * RARRAY_LEN(assoc));
+ volatile VALUE dst = rb_ary_new2(2 * RARRAY(assoc)->len);
- len = RARRAY_LEN(assoc);
+ len = RARRAY(assoc)->len;
for(i = 0; i < len; i++) {
- pair = RARRAY_PTR(assoc)[i];
+ pair = RARRAY(assoc)->ptr[i];
if (TYPE(pair) != T_ARRAY) {
- rb_ary_push(dst, key2keyname(pair));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = key2keyname(pair);
continue;
}
- switch(RARRAY_LEN(assoc)) {
+ switch(RARRAY(assoc)->len) {
case 2:
- rb_ary_push(dst, get_eval_string_core(RARRAY_PTR(pair)[2], Qtrue, self));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = get_eval_string_core(RARRAY(pair)->ptr[2], Qtrue, self);
case 1:
- rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0]));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = key2keyname(RARRAY(pair)->ptr[0]);
case 0:
continue;
default:
- rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0]));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = key2keyname(RARRAY(pair)->ptr[0]);
- val = rb_ary_new2(RARRAY_LEN(pair) - 1);
- for(j = 1; j < RARRAY_LEN(pair); j++) {
- rb_ary_push(val, RARRAY_PTR(pair)[j]);
+ val = rb_ary_new2(RARRAY(pair)->len - 1);
+ RARRAY(val)->len = 0;
+ for(j = 1; j < RARRAY(pair)->len; j++) {
+ RARRAY(val)->ptr[RARRAY(val)->len++] = RARRAY(pair)->ptr[j];
}
- rb_ary_push(dst, get_eval_string_core(val, Qtrue, self));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = get_eval_string_core(val, Qtrue, self);
}
}
@@ -605,18 +606,19 @@ push_kv(key, val, args)
{
volatile VALUE ary;
- ary = RARRAY_PTR(args)[0];
+ ary = RARRAY(args)->ptr[0];
if (key == Qundef) return ST_CONTINUE;
#if 0
rb_ary_push(ary, key2keyname(key));
if (val != TK_None) rb_ary_push(ary, val);
#endif
- rb_ary_push(ary, key2keyname(key));
+ RARRAY(ary)->ptr[RARRAY(ary)->len++] = key2keyname(key);
if (val == TK_None) return ST_CHECK;
- rb_ary_push(ary, get_eval_string_core(val, Qnil, RARRAY_PTR(args)[1]));
+ RARRAY(ary)->ptr[RARRAY(ary)->len++]
+ = get_eval_string_core(val, Qnil, RARRAY(args)->ptr[1]);
return ST_CHECK;
}
@@ -627,10 +629,15 @@ hash2kv(hash, ary, self)
VALUE ary;
VALUE self;
{
- volatile VALUE dst = rb_ary_new2(2 * RHASH_SIZE(hash));
- volatile VALUE args = rb_ary_new3(2, dst, self);
+ volatile VALUE args = rb_ary_new2(2);
+ volatile VALUE dst = rb_ary_new2(2 * RHASH(hash)->tbl->num_entries);
+
+ RARRAY(dst)->len = 0;
- st_foreach(RHASH_TBL(hash), push_kv, args);
+ RARRAY(args)->ptr[0] = dst;
+ RARRAY(args)->ptr[1] = self;
+ RARRAY(args)->len = 2;
+ st_foreach(RHASH(hash)->tbl, push_kv, args);
if (NIL_P(ary)) {
return dst;
@@ -647,21 +654,22 @@ push_kv_enc(key, val, args)
{
volatile VALUE ary;
- ary = RARRAY_PTR(args)[0];
+ ary = RARRAY(args)->ptr[0];
if (key == Qundef) return ST_CONTINUE;
#if 0
rb_ary_push(ary, key2keyname(key));
if (val != TK_None) {
rb_ary_push(ary, get_eval_string_core(val, Qtrue,
- RARRAY_PTR(args)[1]));
+ RARRAY(args)->ptr[1]));
}
#endif
- rb_ary_push(ary, key2keyname(key));
+ RARRAY(ary)->ptr[RARRAY(ary)->len++] = key2keyname(key);
if (val == TK_None) return ST_CHECK;
- rb_ary_push(ary, get_eval_string_core(val, Qtrue, RARRAY_PTR(args)[1]));
+ RARRAY(ary)->ptr[RARRAY(ary)->len++]
+ = get_eval_string_core(val, Qtrue, RARRAY(args)->ptr[1]);
return ST_CHECK;
}
@@ -672,10 +680,15 @@ hash2kv_enc(hash, ary, self)
VALUE ary;
VALUE self;
{
- volatile VALUE dst = rb_ary_new2(2 * RHASH_SIZE(hash));
- volatile VALUE args = rb_ary_new3(2, dst, self);
+ volatile VALUE args = rb_ary_new2(2);
+ volatile VALUE dst = rb_ary_new2(2 * RHASH(hash)->tbl->num_entries);
+
+ RARRAY(dst)->len = 0;
- st_foreach(RHASH_TBL(hash), push_kv_enc, args);
+ RARRAY(args)->ptr[0] = dst;
+ RARRAY(args)->ptr[1] = self;
+ RARRAY(args)->len = 2;
+ st_foreach(RHASH(hash)->tbl, push_kv_enc, args);
if (NIL_P(ary)) {
return dst;
@@ -791,11 +804,7 @@ get_eval_string_core(obj, enc_flag, self)
return fromDefaultEnc_toUTF8(rb_str_new2(rb_id2name(SYM2ID(obj))), self);
}
} else {
-#ifdef RUBY_VM
- return rb_sym_to_s(obj);
-#else
return rb_str_new2(rb_id2name(SYM2ID(obj)));
-#endif
}
case T_HASH:
@@ -853,7 +862,7 @@ get_eval_string_core(obj, enc_flag, self)
}
rb_warning("fail to convert '%s' to string for Tk",
- RSTRING_PTR(rb_funcall(obj, rb_intern("inspect"), 0, 0)));
+ RSTRING(rb_funcall(obj, rb_intern("inspect"), 0, 0))->ptr);
return obj;
}
@@ -906,13 +915,14 @@ tk_conv_args(argc, argv, self)
for(size = 0, idx = 2; idx < argc; idx++) {
if (TYPE(argv[idx]) == T_HASH) {
- size += 2 * RHASH_SIZE(argv[idx]);
+ size += 2 * RHASH(argv[idx])->tbl->num_entries;
} else {
size++;
}
}
/* dst = rb_ary_new2(argc - 2); */
dst = rb_ary_new2(size);
+ RARRAY(dst)->len = 0;
for(idx = 2; idx < argc; idx++) {
if (TYPE(argv[idx]) == T_HASH) {
if (RTEST(argv[1])) {
@@ -921,7 +931,8 @@ tk_conv_args(argc, argv, self)
hash2kv(argv[idx], dst, self);
}
} else if (argv[idx] != TK_None) {
- rb_ary_push(dst, get_eval_string_core(argv[idx], argv[1], self));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = get_eval_string_core(argv[idx], argv[1], self);
}
}
@@ -955,13 +966,13 @@ tcl2rb_bool(self, value)
value = rb_funcall(value, ID_downcase, 0);
- if (RSTRING_PTR(value) == (char*)NULL) return Qnil;
+ if (RSTRING(value)->ptr == (char*)NULL) return Qnil;
- if (RSTRING_PTR(value)[0] == '\0'
- || strcmp(RSTRING_PTR(value), "0") == 0
- || strcmp(RSTRING_PTR(value), "no") == 0
- || strcmp(RSTRING_PTR(value), "off") == 0
- || strcmp(RSTRING_PTR(value), "false") == 0) {
+ if (RSTRING(value)->ptr[0] == '\0'
+ || strcmp(RSTRING(value)->ptr, "0") == 0
+ || strcmp(RSTRING(value)->ptr, "no") == 0
+ || strcmp(RSTRING(value)->ptr, "off") == 0
+ || strcmp(RSTRING(value)->ptr, "false") == 0) {
return Qfalse;
} else {
return Qtrue;
@@ -972,21 +983,21 @@ static VALUE
tkstr_to_dec(value)
VALUE value;
{
- return rb_cstr_to_inum(RSTRING_PTR(value), 10, 1);
+ return rb_cstr_to_inum(RSTRING(value)->ptr, 10, 1);
}
static VALUE
tkstr_to_int(value)
VALUE value;
{
- return rb_cstr_to_inum(RSTRING_PTR(value), 0, 1);
+ return rb_cstr_to_inum(RSTRING(value)->ptr, 0, 1);
}
static VALUE
tkstr_to_float(value)
VALUE value;
{
- return rb_float_new(rb_cstr_to_dbl(RSTRING_PTR(value), 1));
+ return rb_float_new(rb_cstr_to_dbl(RSTRING(value)->ptr, 1));
}
static VALUE
@@ -994,7 +1005,7 @@ tkstr_invalid_numstr(value)
VALUE value;
{
rb_raise(rb_eArgError,
- "invalid value for Number: '%s'", RSTRING_PTR(value));
+ "invalid value for Number: '%s'", RSTRING(value)->ptr);
return Qnil; /*dummy*/
}
@@ -1013,7 +1024,7 @@ tkstr_to_number(value)
{
rb_check_type(value, T_STRING);
- if (RSTRING_PTR(value) == (char*)NULL) return INT2FIX(0);
+ if (RSTRING(value)->ptr == (char*)NULL) return INT2FIX(0);
return rb_rescue2(tkstr_to_int, value,
tkstr_rescue_float, value,
@@ -1035,8 +1046,8 @@ tkstr_to_str(value)
char * ptr;
int len;
- ptr = RSTRING_PTR(value);
- len = RSTRING_LEN(value);
+ ptr = RSTRING(value)->ptr;
+ len = RSTRING(value)->len;
if (len > 1 && *ptr == '{' && *(ptr + len - 1) == '}') {
return rb_str_new(ptr + 1, len - 2);
@@ -1051,7 +1062,7 @@ tcl2rb_string(self, value)
{
rb_check_type(value, T_STRING);
- if (RSTRING_PTR(value) == (char*)NULL) return rb_tainted_str_new2("");
+ if (RSTRING(value)->ptr == (char*)NULL) return rb_tainted_str_new2("");
return tkstr_to_str(value);
}
@@ -1063,7 +1074,7 @@ tcl2rb_num_or_str(self, value)
{
rb_check_type(value, T_STRING);
- if (RSTRING_PTR(value) == (char*)NULL) return rb_tainted_str_new2("");
+ if (RSTRING(value)->ptr == (char*)NULL) return rb_tainted_str_new2("");
return rb_rescue2(tkstr_to_number, value,
tkstr_to_str, value,
@@ -1073,13 +1084,11 @@ tcl2rb_num_or_str(self, value)
/*************************************/
-#define CBSUBST_TBL_MAX (256)
struct cbsubst_info {
- int full_subst_length;
- int keylen[CBSUBST_TBL_MAX];
- unsigned char *key[CBSUBST_TBL_MAX];
- unsigned char type[CBSUBST_TBL_MAX];
- ID ivar[CBSUBST_TBL_MAX];
+ int size;
+ char *key;
+ char *type;
+ ID *ivar;
VALUE proc;
VALUE aliases;
};
@@ -1096,52 +1105,42 @@ static void
subst_free(ptr)
struct cbsubst_info *ptr;
{
- int i;
-
if (ptr) {
- for(i = 0; i < CBSUBST_TBL_MAX; i++) {
- if (ptr->key[i] != (unsigned char *)NULL) {
- free(ptr->key[i]);
- ptr->key[i] = (unsigned char *)NULL;
- }
- }
- free(ptr);
+ if (ptr->key != (char*)NULL) free(ptr->key);
+ if (ptr->type != (char*)NULL) free(ptr->type);
+ if (ptr->ivar != (ID*)NULL) free(ptr->ivar);
+ free(ptr);
}
}
-static struct cbsubst_info *
-allocate_cbsubst_info()
+static void
+cbsubst_init()
{
- struct cbsubst_info *inf;
- volatile VALUE proc, aliases;
- int idx;
+ struct cbsubst_info *inf;
+ ID *ivar;
+ volatile VALUE proc, aliases;
- inf = ALLOC(struct cbsubst_info);
+ inf = ALLOC(struct cbsubst_info);
- inf->full_subst_length = 0;
+ inf->size = 0;
- for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
- inf->keylen[idx] = 0;
- inf->key[idx] = (unsigned char *) NULL;
- inf->type[idx] = '\0';
- inf->ivar[idx] = (ID) 0;
- }
+ inf->key = ALLOC_N(char, 1);
+ inf->key[0] = '\0';
- proc = rb_hash_new();
- inf->proc = proc;
+ inf->type = ALLOC_N(char, 1);
+ inf->type[0] = '\0';
- aliases = rb_hash_new();
- inf->aliases = aliases;
+ ivar = ALLOC_N(ID, 1);
+ inf->ivar = ivar;
- return inf;
-}
+ proc = rb_hash_new();
+ inf->proc = proc;
+
+ aliases = rb_hash_new();
+ inf->aliases = aliases;
-static void
-cbsubst_init()
-{
rb_const_set(cCB_SUBST, ID_SUBST_INFO,
- Data_Wrap_Struct(cSUBST_INFO, subst_mark, subst_free,
- allocate_cbsubst_info()));
+ Data_Wrap_Struct(cSUBST_INFO, subst_mark, subst_free, inf));
}
static VALUE
@@ -1151,29 +1150,24 @@ cbsubst_initialize(argc, argv, self)
VALUE self;
{
struct cbsubst_info *inf;
- int idx, iv_idx;
+ int idx;
Data_Get_Struct(rb_const_get(rb_obj_class(self), ID_SUBST_INFO),
struct cbsubst_info, inf);
- idx = 0;
- for(iv_idx = 0; iv_idx < CBSUBST_TBL_MAX; iv_idx++) {
- if ( inf->ivar[iv_idx] == (ID) 0 ) continue;
- rb_ivar_set(self, inf->ivar[iv_idx], argv[idx++]);
- if (idx >= argc) break;
+ for(idx = 0; idx < argc; idx++) {
+ rb_ivar_set(self, inf->ivar[idx], argv[idx]);
}
return self;
}
+
static VALUE
cbsubst_ret_val(self, val)
VALUE self;
VALUE val;
{
- /* This method may be overwritten on some sub-classes. */
- /* This method is used for converting from ruby's callback-return-value */
- /* to tcl's value (e.g. validation procedure of entry widget). */
return val;
}
@@ -1187,7 +1181,7 @@ each_attr_def(key, value, klass)
switch(TYPE(key)) {
case T_STRING:
- key_id = rb_intern(RSTRING_PTR(key));
+ key_id = rb_intern(RSTRING(key)->ptr);
break;
case T_SYMBOL:
key_id = SYM2ID(key);
@@ -1199,7 +1193,7 @@ each_attr_def(key, value, klass)
switch(TYPE(value)) {
case T_STRING:
- value_id = rb_intern(RSTRING_PTR(value));
+ value_id = rb_intern(RSTRING(value)->ptr);
break;
case T_SYMBOL:
value_id = SYM2ID(value);
@@ -1234,80 +1228,28 @@ cbsubst_def_attr_aliases(self, tbl)
}
static VALUE
-cbsubst_sym_to_subst(self, sym)
- VALUE self;
- VALUE sym;
-{
- struct cbsubst_info *inf;
- const char *str;
- unsigned char *buf, *ptr;
- int idx, len;
- ID id;
- volatile VALUE ret;
-
- if (TYPE(sym) != T_SYMBOL) return sym;
-
- Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
- struct cbsubst_info, inf);
-
- if (!NIL_P(ret = rb_hash_aref(inf->aliases, sym))) {
- str = rb_id2name(SYM2ID(ret));
- } else {
- str = rb_id2name(SYM2ID(sym));
- }
-
- id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str)));
-
- for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
- if (inf->ivar[idx] == id) break;
- }
- if (idx >= CBSUBST_TBL_MAX) return sym;
-
- ptr = buf = ALLOC_N(char, inf->full_subst_length + 1);
-
- *(ptr++) = '%';
-
- if (len = inf->keylen[idx]) {
- /* longname */
- strncpy(ptr, inf->key[idx], len);
- ptr += len;
- } else {
- /* single char */
- *(ptr++) = idx;
- }
-
- *(ptr++) = ' ';
- *(ptr++) = '\0';
-
- ret = rb_str_new2(buf);
-
- free(buf);
-
- return ret;
-}
-
-static VALUE
cbsubst_get_subst_arg(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
struct cbsubst_info *inf;
- const char *str;
- unsigned char *buf, *ptr;
- int i, idx, len;
+ char *str, *buf, *ptr;
+ int i, j, len;
ID id;
volatile VALUE arg_sym, ret;
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
struct cbsubst_info, inf);
- ptr = buf = ALLOC_N(char, inf->full_subst_length + 1);
+ buf = ALLOC_N(char, 3*argc + 1);
+ ptr = buf;
+ len = strlen(inf->key);
for(i = 0; i < argc; i++) {
switch(TYPE(argv[i])) {
case T_STRING:
- str = RSTRING_PTR(argv[i]);
+ str = RSTRING(argv[i])->ptr;
arg_sym = ID2SYM(rb_intern(str));
break;
case T_SYMBOL:
@@ -1322,27 +1264,19 @@ cbsubst_get_subst_arg(argc, argv, self)
str = rb_id2name(SYM2ID(ret));
}
- id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str)));
+ id = rb_intern(RSTRING(rb_str_cat2(rb_str_new2("@"), str))->ptr);
- for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
- if (inf->ivar[idx] == id) break;
- }
- if (idx >= CBSUBST_TBL_MAX) {
- rb_raise(rb_eArgError, "cannot find attribute :%s", str);
+ for(j = 0; j < len; j++) {
+ if (inf->ivar[j] == id) break;
}
- *(ptr++) = '%';
-
- if (len = inf->keylen[idx]) {
- /* longname */
- strncpy(ptr, inf->key[idx], len);
- ptr += len;
- } else {
- /* single char */
- *(ptr++) = idx;
- }
+ if (j >= len) {
+ rb_raise(rb_eArgError, "cannot find attribute :%s", str);
+ }
- *(ptr++) = ' ';
+ *(ptr++) = '%';
+ *(ptr++) = *(inf->key + j);
+ *(ptr++) = ' ';
}
*ptr = '\0';
@@ -1359,50 +1293,27 @@ cbsubst_get_subst_key(self, str)
VALUE self;
VALUE str;
{
- struct cbsubst_info *inf;
volatile VALUE list;
volatile VALUE ret;
- VALUE keyval;
- int i, len, keylen, idx;
- unsigned char *buf, *ptr, *key;
+ int i, len;
+ char *buf, *ptr;
list = rb_funcall(cTclTkLib, ID_split_tklist, 1, str);
- len = RARRAY_LEN(list);
-
- Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
- struct cbsubst_info, inf);
- ptr = buf = ALLOC_N(unsigned char, inf->full_subst_length + len + 1);
+ len = RARRAY(list)->len;
+ buf = ALLOC_N(char, len + 1);
for(i = 0; i < len; i++) {
- keyval = RARRAY_PTR(list)[i];
- key = (unsigned char*)RSTRING_PTR(keyval);
- if (*key == '%') {
- if (*(key + 2) == '\0') {
- /* single char */
- *(ptr++) = *(key + 1);
- } else {
- /* search longname-key */
- keylen = RSTRING_LEN(keyval) - 1;
- for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
- if (inf->keylen[idx] != keylen) continue;
- if (inf->key[idx][0] != *(key + 1)) continue;
- if (strncmp(inf->key[idx], key + 1, keylen)) continue;
- break;
- }
- if (idx < CBSUBST_TBL_MAX) {
- *(ptr++) = (unsigned char)idx;
- } else {
- *(ptr++) = ' ';
- }
- }
- } else {
- *(ptr++) = ' ';
- }
+ ptr = RSTRING(RARRAY(list)->ptr[i])->ptr;
+ if (*ptr == '%' && *(ptr + 2) == '\0') {
+ *(buf + i) = *(ptr + 1);
+ } else {
+ *(buf + i) = ' ';
+ }
}
- *ptr = '\0';
+ *(buf + len) = '\0';
- ret = rb_str_new2((const char*)buf);
+ ret = rb_str_new2(buf);
free(buf);
return ret;
}
@@ -1412,166 +1323,100 @@ cbsubst_get_all_subst_keys(self)
VALUE self;
{
struct cbsubst_info *inf;
- unsigned char *buf, *ptr;
- unsigned char *keys_buf, *keys_ptr;
- int idx, len;
+ char *buf, *ptr;
+ int i, len;
volatile VALUE ret;
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
struct cbsubst_info, inf);
- ptr = buf = ALLOC_N(unsigned char, inf->full_subst_length + 1);
- keys_ptr = keys_buf = ALLOC_N(unsigned char, CBSUBST_TBL_MAX + 1);
-
- for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
- if (inf->ivar[idx] == (ID) 0) continue;
-
- *(keys_ptr++) = (unsigned char)idx;
-
- *(ptr++) = '%';
-
- if (len = inf->keylen[idx]) {
- /* longname */
- strncpy(ptr, inf->key[idx], len);
- ptr += len;
- } else {
- /* single char */
- *(ptr++) = (unsigned char)idx;
- }
-
- *(ptr++) = ' ';
+ len = strlen(inf->key);
+ buf = ALLOC_N(char, 3*len + 1);
+ ptr = buf;
+ for(i = 0; i < len; i++) {
+ *(ptr++) = '%';
+ *(ptr++) = *(inf->key + i);
+ *(ptr++) = ' ';
}
+ *(buf + 3*len) = '\0';
- *ptr = '\0';
- *keys_ptr = '\0';
-
- ret = rb_ary_new3(2, rb_str_new2(keys_buf), rb_str_new2((const char*)buf));
+ ret = rb_ary_new3(2, rb_str_new2(inf->key), rb_str_new2(buf));
free(buf);
- free(keys_buf);
return ret;
}
static VALUE
-cbsubst_table_setup(argc, argv, self)
- int argc;
- VALUE *argv;
- VALUE self;
+cbsubst_table_setup(self, key_inf, proc_inf)
+ VALUE self;
+ VALUE key_inf;
+ VALUE proc_inf;
{
- volatile VALUE key_inf;
- volatile VALUE longkey_inf;
- volatile VALUE proc_inf;
- VALUE inf;
- ID id;
- struct cbsubst_info *subst_inf;
- int idx, len;
- unsigned char chr;
-
- /* accept (key_inf, proc_inf) or (key_inf, longkey_inf, procinf) */
- if (rb_scan_args(argc, argv, "21", &key_inf, &longkey_inf, &proc_inf) == 2) {
- proc_inf = longkey_inf;
- longkey_inf = rb_ary_new();
- }
-
- /* check the number of longkeys */
- if (RARRAY_LEN(longkey_inf) > 125 /* from 0x80 to 0xFD */) {
- rb_raise(rb_eArgError, "too many longname-key definitions");
- }
-
- /* init */
- subst_inf = allocate_cbsubst_info();
-
- /*
- * keys : array of [subst, type, ivar]
- * subst ==> char code or string
- * type ==> char code or string
- * ivar ==> symbol
- */
- len = RARRAY_LEN(key_inf);
- for(idx = 0; idx < len; idx++) {
- inf = RARRAY_PTR(key_inf)[idx];
- if (TYPE(inf) != T_ARRAY) continue;
-
- if (TYPE(RARRAY_PTR(inf)[0]) == T_STRING) {
- chr = *(RSTRING_PTR(RARRAY_PTR(inf)[0]));
- } else {
- chr = NUM2CHR(RARRAY_PTR(inf)[0]);
+ struct cbsubst_info *subst_inf;
+ int idx;
+ int len = RARRAY(key_inf)->len;
+ int real_len = 0;
+ char *key = ALLOC_N(char, len + 1);
+ char *type = ALLOC_N(char, len + 1);
+ ID *ivar = ALLOC_N(ID, len + 1);
+ volatile VALUE proc = rb_hash_new();
+ volatile VALUE aliases = rb_hash_new();
+ volatile VALUE inf;
+
+ /* init */
+ subst_inf = ALLOC(struct cbsubst_info);
+ /* subst_inf->size = len; */
+ subst_inf->key = key;
+ subst_inf->type = type;
+ subst_inf->ivar = ivar;
+ subst_inf->proc = proc;
+ subst_inf->aliases = aliases;
+
+ /*
+ * keys : array of [subst, type, ivar]
+ * subst ==> char code
+ * type ==> char code
+ * ivar ==> symbol
+ */
+ for(idx = 0; idx < len; idx++) {
+ inf = RARRAY(key_inf)->ptr[idx];
+ if (TYPE(inf) != T_ARRAY) continue;
+ *(key + real_len) = (char)NUM2INT(RARRAY(inf)->ptr[0]);
+ *(type + real_len) = (char)NUM2INT(RARRAY(inf)->ptr[1]);
+
+ *(ivar + real_len)
+ = rb_intern(
+ RSTRING(
+ rb_str_cat2(rb_str_new2("@"),
+ rb_id2name(SYM2ID(RARRAY(inf)->ptr[2])))
+ )->ptr
+ );
+
+ rb_attr(self, SYM2ID(RARRAY(inf)->ptr[2]), 1, 0, Qtrue);
+ real_len++;
}
- if (TYPE(RARRAY_PTR(inf)[1]) == T_STRING) {
- subst_inf->type[chr] = *(RSTRING_PTR(RARRAY_PTR(inf)[1]));
- } else {
- subst_inf->type[chr] = NUM2CHR(RARRAY_PTR(inf)[1]);
+ *(key + real_len) = '\0';
+ *(type + real_len) = '\0';
+ subst_inf->size = real_len;
+
+ /*
+ * procs : array of [type, proc]
+ * type ==> char code
+ * proc ==> proc/method/obj (must respond to 'call')
+ */
+ len = RARRAY(proc_inf)->len;
+ for(idx = 0; idx < len; idx++) {
+ inf = RARRAY(proc_inf)->ptr[idx];
+ if (TYPE(inf) != T_ARRAY) continue;
+ rb_hash_aset(proc, RARRAY(inf)->ptr[0], RARRAY(inf)->ptr[1]);
}
- subst_inf->full_subst_length += 3;
-
- id = SYM2ID(RARRAY_PTR(inf)[2]);
- subst_inf->ivar[chr] = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), rb_id2name(id))));
-
- rb_attr(self, id, 1, 0, Qtrue);
- }
+ rb_const_set(self, ID_SUBST_INFO,
+ Data_Wrap_Struct(cSUBST_INFO, subst_mark,
+ subst_free, subst_inf));
-
- /*
- * longkeys : array of [name, type, ivar]
- * name ==> longname key string
- * type ==> char code or string
- * ivar ==> symbol
- */
- len = RARRAY_LEN(longkey_inf);
- for(idx = 0; idx < len; idx++) {
- inf = RARRAY_PTR(longkey_inf)[idx];
- if (TYPE(inf) != T_ARRAY) continue;
-
- chr = (unsigned char)(0x80 + idx);
- subst_inf->keylen[chr] = RSTRING_LEN(RARRAY_PTR(inf)[0]);
-#if HAVE_STRNDUP
- subst_inf->key[chr] = strndup(RSTRING_PTR(RARRAY_PTR(inf)[0]),
- RSTRING_LEN(RARRAY_PTR(inf)[0]));
-#else
- subst_inf->key[chr] = malloc(RSTRING_LEN(RARRAY_PTR(inf)[0]) + 1);
- if (subst_inf->key[chr]) {
- strncpy(subst_inf->key[chr], RSTRING_PTR(RARRAY_PTR(inf)[0]),
- RSTRING_LEN(RARRAY_PTR(inf)[0]) + 1);
- subst_inf->key[chr][RSTRING_LEN(RARRAY_PTR(inf)[0])] = '\0';
- }
-#endif
- if (TYPE(RARRAY_PTR(inf)[1]) == T_STRING) {
- subst_inf->type[chr] = *(RSTRING_PTR(RARRAY_PTR(inf)[1]));
- } else {
- subst_inf->type[chr] = NUM2CHR(RARRAY_PTR(inf)[1]);
- }
-
- subst_inf->full_subst_length += (subst_inf->keylen[chr] + 2);
-
- id = SYM2ID(RARRAY_PTR(inf)[2]);
- subst_inf->ivar[chr] = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), rb_id2name(id))));
-
- rb_attr(self, id, 1, 0, Qtrue);
- }
-
- /*
- * procs : array of [type, proc]
- * type ==> char code or string
- * proc ==> proc/method/obj (must respond to 'call')
- */
- len = RARRAY_LEN(proc_inf);
- for(idx = 0; idx < len; idx++) {
- inf = RARRAY_PTR(proc_inf)[idx];
- if (TYPE(inf) != T_ARRAY) continue;
- rb_hash_aset(subst_inf->proc,
- ((TYPE(RARRAY_PTR(inf)[0]) == T_STRING)?
- INT2FIX(*(RSTRING_PTR(RARRAY_PTR(inf)[0]))) :
- RARRAY_PTR(inf)[0]),
- RARRAY_PTR(inf)[1]);
- }
-
- rb_const_set(self, ID_SUBST_INFO,
- Data_Wrap_Struct(cSUBST_INFO, subst_mark,
- subst_free, subst_inf));
-
- return self;
+ return self;
}
static VALUE
@@ -1589,11 +1434,10 @@ cbsubst_scan_args(self, arg_key, val_ary)
{
struct cbsubst_info *inf;
int idx;
- unsigned char *keyptr = (unsigned char*)RSTRING_PTR(arg_key);
- int keylen = RSTRING_LEN(arg_key);
- int vallen = RARRAY_LEN(val_ary);
- unsigned char type_chr;
- volatile VALUE dst = rb_ary_new2(vallen);
+ int len = RARRAY(val_ary)->len;
+ char c;
+ char *ptr;
+ volatile VALUE dst = rb_ary_new2(len);
volatile VALUE proc;
int thr_crit_bup;
VALUE old_gc;
@@ -1606,25 +1450,28 @@ cbsubst_scan_args(self, arg_key, val_ary)
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
struct cbsubst_info, inf);
- for(idx = 0; idx < vallen; idx++) {
- if (idx >= keylen) {
- proc = Qnil;
- } else if (*(keyptr + idx) == ' ') {
- proc = Qnil;
- } else {
- if (type_chr = inf->type[*(keyptr + idx)]) {
- proc = rb_hash_aref(inf->proc, INT2FIX((int)type_chr));
- } else {
- proc = Qnil;
- }
- }
-
- if (NIL_P(proc)) {
- rb_ary_push(dst, RARRAY_PTR(val_ary)[idx]);
- } else {
- rb_ary_push(dst, rb_funcall(proc, ID_call, 1,
- RARRAY_PTR(val_ary)[idx]));
- }
+ RARRAY(dst)->len = 0;
+ for(idx = 0; idx < len; idx++) {
+ if (idx >= RSTRING(arg_key)->len) {
+ proc = Qnil;
+ } else if (*(RSTRING(arg_key)->ptr + idx) == ' ') {
+ proc = Qnil;
+ } else {
+ ptr = strchr(inf->key, *(RSTRING(arg_key)->ptr + idx));
+ if (ptr == (char*)NULL) {
+ proc = Qnil;
+ } else {
+ c = *(inf->type + (ptr - inf->key));
+ proc = rb_hash_aref(inf->proc, INT2FIX(c));
+ }
+ }
+
+ if (NIL_P(proc)) {
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = RARRAY(val_ary)->ptr[idx];
+ } else {
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = rb_funcall(proc, ID_call, 1, RARRAY(val_ary)->ptr[idx]);
+ }
}
if (old_gc == Qfalse) rb_gc_enable();
@@ -1665,7 +1512,6 @@ tkobj_path(self)
return rb_ivar_get(self, ID_at_path);
}
-
/*************************************/
/* release date */
const char tkutil_release_date[] = TKUTIL_RELEASE_DATE;
@@ -1708,8 +1554,6 @@ Init_tkutil()
ID_SUBST_INFO = rb_intern("SUBST_INFO");
rb_define_singleton_method(cCB_SUBST, "ret_val", cbsubst_ret_val, 1);
rb_define_singleton_method(cCB_SUBST, "scan_args", cbsubst_scan_args, 2);
- rb_define_singleton_method(cCB_SUBST, "_sym2subst",
- cbsubst_sym_to_subst, 1);
rb_define_singleton_method(cCB_SUBST, "subst_arg",
cbsubst_get_subst_arg, -1);
rb_define_singleton_method(cCB_SUBST, "_get_subst_key",
@@ -1717,7 +1561,7 @@ Init_tkutil()
rb_define_singleton_method(cCB_SUBST, "_get_all_subst_keys",
cbsubst_get_all_subst_keys, 0);
rb_define_singleton_method(cCB_SUBST, "_setup_subst_table",
- cbsubst_table_setup, -1);
+ cbsubst_table_setup, 2);
rb_define_singleton_method(cCB_SUBST, "_get_extra_args_tbl",
cbsubst_get_extra_args_tbl, 0);
rb_define_singleton_method(cCB_SUBST, "_define_attribute_aliases",
@@ -1792,8 +1636,4 @@ Init_tkutil()
rb_define_method(mTK, "num_or_str", tcl2rb_num_or_str, 1);
/* --------------------- */
- rb_global_variable(&ENCODING_NAME_UTF8);
- ENCODING_NAME_UTF8 = rb_obj_freeze(rb_str_new2("utf-8"));
-
- /* --------------------- */
}
diff --git a/ext/win32ole/tests/testOLEEVENT.rb b/ext/win32ole/tests/testOLEEVENT.rb
new file mode 100644
index 0000000000..0901158642
--- /dev/null
+++ b/ext/win32ole/tests/testOLEEVENT.rb
@@ -0,0 +1,91 @@
+require 'rubyunit'
+require 'win32ole'
+
+class TestWIN32OLE_EVENT < RUNIT::TestCase
+ def setup
+ @excel = WIN32OLE.new("Excel.Application")
+ @excel.visible = true
+ @event = ""
+ @event2 = ""
+ end
+ def test_on_event
+ book = @excel.workbooks.Add
+ value = ""
+ begin
+ ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
+ ev.on_event('SheetChange'){|arg1, arg2|
+ begin
+ value = arg1.value
+ rescue
+ value = $!.message
+ end
+ }
+ book.Worksheets(1).Range("A1").value = "OK"
+ ensure
+ book.saved = true
+ end
+ assert_equal("OK", value)
+ end
+
+ def handler1
+ @event += "handler1"
+ end
+ def handler2
+ @event += "handler2"
+ end
+
+ def handler3
+ @event += "handler3"
+ end
+
+ def test_on_event2
+ book = @excel.workbooks.Add
+ begin
+ ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
+ ev.on_event('SheetChange'){|arg1, arg2|
+ handler1
+ }
+ ev.on_event('SheetChange'){|arg1, arg2|
+ handler2
+ }
+ book.Worksheets(1).Range("A1").value = "OK"
+ ensure
+ book.saved = true
+ end
+ assert_equal("handler2", @event)
+ end
+
+ def test_on_event3
+ book = @excel.workbooks.Add
+ begin
+ ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
+ ev.on_event{ handler1 }
+ ev.on_event{ handler2 }
+ book.Worksheets(1).Range("A1").value = "OK"
+ ensure
+ book.saved = true
+ end
+ assert_equal("handler2", @event)
+ end
+
+ def test_on_event4
+ book = @excel.workbooks.Add
+ begin
+ ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
+ ev.on_event{ handler1 }
+ ev.on_event{ handler2 }
+ ev.on_event('SheetChange'){|arg1, arg2| handler3 }
+ book.Worksheets(1).Range("A1").value = "OK"
+ ensure
+ book.saved = true
+ end
+ assert_equal("handler3", @event)
+ end
+
+ def teardown
+ @excel.quit
+ @excel = nil
+ GC.start
+ end
+end
+
diff --git a/ext/win32ole/tests/testWIN32OLE.rb b/ext/win32ole/tests/testWIN32OLE.rb
index d7f9dd2543..5c01507377 100644
--- a/ext/win32ole/tests/testWIN32OLE.rb
+++ b/ext/win32ole/tests/testWIN32OLE.rb
@@ -156,8 +156,7 @@ class TestWin32OLE < RUNIT::TestCase
sheet.range("A3").value = "=A1*10 + 9"
assert_equal(9999999999, sheet.range("A2").value)
assert_equal(9999999999, sheet.range("A3").value)
- sheet.range("A4").value = "2008/03/04"
- assert_equal("2008/03/04 00:00:00", sheet.range("A4").value)
+
ensure
book.saved = true
end
diff --git a/ext/win32ole/tests/test_win32ole_event.rb b/ext/win32ole/tests/test_win32ole_event.rb
deleted file mode 100644
index 744021dfd2..0000000000
--- a/ext/win32ole/tests/test_win32ole_event.rb
+++ /dev/null
@@ -1,133 +0,0 @@
-begin
- require 'win32ole'
-rescue LoadError
-end
-require 'test/unit'
-
-if defined?(WIN32OLE_EVENT)
- class TestWIN32OLE_EVENT < Test::Unit::TestCase
- def create_temp_html
- fso = WIN32OLE.new('Scripting.FileSystemObject')
- dummy_file = fso.GetTempName + ".html"
- cfolder = fso.getFolder(".")
- f = cfolder.CreateTextFile(dummy_file)
- f.writeLine("<html><body>This is test HTML file for Win32OLE.</body></html>")
- f.close
- dummy_path = cfolder.path + "\\" + dummy_file
- dummy_path
- end
-
- def setup
- @ie = WIN32OLE.new("InternetExplorer.Application")
- @ie.visible = true
- @event = ""
- @event2 = ""
- @event3 = ""
- @f = create_temp_html
- end
-
- def default_handler(event, *args)
- @event += event
- end
-
- def test_on_event
- ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- ev.on_event {|*args| default_handler(*args)}
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- GC.start
- sleep 0.1
- end
- assert_match(/BeforeNavigate/, @event)
- assert_match(/NavigateComplete/, @event)
- end
-
- def test_on_event2
- ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- ev.on_event('BeforeNavigate') {|*args| handler1}
- ev.on_event('BeforeNavigate') {|*args| handler2}
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- sleep 0.1
- end
- assert_equal("handler2", @event2)
- end
-
- def test_on_event3
- ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- ev.on_event {|*args| handler1}
- ev.on_event {|*args| handler2}
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- sleep 0.1
- end
- assert_equal("handler2", @event2)
- end
-
- def test_on_event4
- ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- ev.on_event{|*args| handler1}
- ev.on_event{|*args| handler2}
- ev.on_event('NavigateComplete'){|*args| handler3(*args)}
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- sleep 0.1
- end
- assert(@event3!="")
- assert("handler2", @event2)
- end
-
- def test_on_event5
- ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- ev.on_event {|*args| default_handler(*args)}
- ev.on_event('NavigateComplete'){|*args| handler3(*args)}
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- sleep 0.1
- end
- assert_match(/BeforeNavigate/, @event)
- assert(/NavigateComplete/ !~ @event)
- assert(@event!="")
- end
-
- def test_unadvise
- ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- ev.on_event {|*args| default_handler(*args)}
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- sleep 0.1
- end
- assert_match(/BeforeNavigate/, @event)
- ev.unadvise
- @event = ""
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- sleep 0.1
- end
- assert_equal("", @event);
- assert_raise(WIN32OLERuntimeError) {
- ev.on_event {|*args| default_handler(*args)}
- }
- end
-
- def handler1
- @event2 = "handler1"
- end
-
- def handler2
- @event2 = "handler2"
- end
-
- def handler3(url)
- @event3 += url
- end
-
- def teardown
- @ie.quit
- @ie = nil
- File.unlink(@f)
- GC.start
- end
- end
-end
diff --git a/ext/win32ole/tests/testall.rb b/ext/win32ole/tests/testall.rb
index 553ce88509..d45541f571 100644
--- a/ext/win32ole/tests/testall.rb
+++ b/ext/win32ole/tests/testall.rb
@@ -12,5 +12,4 @@ require "testNIL2VTEMPTY"
require "test_ole_methods.rb"
require "test_propertyputref.rb"
require "test_word.rb"
-require "test_win32ole_event.rb"
# require "testOLEEVENT"
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index ae0066ffc9..a2cac84cb7 100644
--- a/ext/win32ole/win32ole.c
+++ b/ext/win32ole/win32ole.c
@@ -29,7 +29,7 @@
#include <varargs.h>
#define va_init_list(a,b) va_start(a)
#endif
-#include <objidl.h>
+
#define DOUT fprintf(stderr,"[%d]\n",__LINE__)
#define DOUTS(x) fprintf(stderr,"[%d]:" #x "=%s\n",__LINE__,x)
@@ -79,7 +79,7 @@
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
-#define WIN32OLE_VERSION "0.7.6"
+#define WIN32OLE_VERSION "0.7.2"
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@@ -157,9 +157,6 @@ static VALUE com_hash;
static IDispatchVtbl com_vtbl;
static UINT cWIN32OLE_cp = CP_ACP;
static VARTYPE g_nil_to = VT_ERROR;
-static IMessageFilterVtbl message_filter;
-static IMessageFilter imessage_filter = { &message_filter };
-static IMessageFilter* previous_filter;
struct oledata {
IDispatch *pDispatch;
@@ -206,101 +203,6 @@ static char *ole_wc2mb(LPWSTR);
static VALUE ole_variant2val(VARIANT*);
static void ole_val2variant(VALUE, VARIANT*);
-static HRESULT (STDMETHODCALLTYPE mf_QueryInterface)(
- IMessageFilter __RPC_FAR * This,
- /* [in] */ REFIID riid,
- /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
-{
- if (MEMCMP(riid, &IID_IUnknown, GUID, 1) == 0
- || MEMCMP(riid, &IID_IMessageFilter, GUID, 1) == 0)
- {
- *ppvObject = &message_filter;
- return S_OK;
- }
- return E_NOINTERFACE;
-}
-
-static ULONG (STDMETHODCALLTYPE mf_AddRef)(
- IMessageFilter __RPC_FAR * This)
-{
- return 1;
-}
-
-static ULONG (STDMETHODCALLTYPE mf_Release)(
- IMessageFilter __RPC_FAR * This)
-{
- return 1;
-}
-
-static DWORD (STDMETHODCALLTYPE mf_HandleInComingCall)(
- IMessageFilter __RPC_FAR * pThis,
- DWORD dwCallType, //Type of incoming call
- HTASK threadIDCaller, //Task handle calling this task
- DWORD dwTickCount, //Elapsed tick count
- LPINTERFACEINFO lpInterfaceInfo //Pointer to INTERFACEINFO structure
- )
-{
-#ifdef DEBUG_MESSAGEFILTER
- printf("incoming %08X, %08X, %d\n", dwCallType, threadIDCaller, dwTickCount);
- fflush(stdout);
-#endif
- switch (dwCallType)
- {
- case CALLTYPE_ASYNC:
- case CALLTYPE_TOPLEVEL_CALLPENDING:
- case CALLTYPE_ASYNC_CALLPENDING:
- if (rb_during_gc()) {
- return SERVERCALL_RETRYLATER;
- }
- break;
- default:
- break;
- }
- if (previous_filter) {
- return previous_filter->lpVtbl->HandleInComingCall(previous_filter,
- dwCallType,
- threadIDCaller,
- dwTickCount,
- lpInterfaceInfo);
- }
- return SERVERCALL_ISHANDLED;
-}
-
-static DWORD (STDMETHODCALLTYPE mf_RetryRejectedCall)(
- IMessageFilter* pThis,
- HTASK threadIDCallee, //Server task handle
- DWORD dwTickCount, //Elapsed tick count
- DWORD dwRejectType //Returned rejection message
- )
-{
- if (previous_filter) {
- return previous_filter->lpVtbl->RetryRejectedCall(previous_filter,
- threadIDCallee,
- dwTickCount,
- dwRejectType);
- }
- return 1000;
-}
-
-static DWORD (STDMETHODCALLTYPE mf_MessagePending)(
- IMessageFilter* pThis,
- HTASK threadIDCallee, //Called applications task handle
- DWORD dwTickCount, //Elapsed tick count
- DWORD dwPendingType //Call type
- )
-{
- if (rb_during_gc()) {
- return PENDINGMSG_WAITNOPROCESS;
- }
- if (previous_filter) {
- return previous_filter->lpVtbl->MessagePending(previous_filter,
- threadIDCallee,
- dwTickCount,
- dwPendingType);
- }
- return PENDINGMSG_WAITNOPROCESS;
-}
-
typedef struct _Win32OLEIDispatch
{
IDispatch dispatch;
@@ -557,7 +459,7 @@ date2time_str(date)
double date;
{
int y, m, d, hh, mm, ss;
- char szTime[40];
+ char szTime[20];
double2time(date, &y, &m, &d, &hh, &mm, &ss);
sprintf(szTime,
"%4.4d/%02.2d/%02.2d %02.2d:%02.2d:%02.2d",
@@ -620,15 +522,6 @@ ole_hresult2msg(hr)
return msg;
}
-static void
-ole_freeexceptinfo(pExInfo)
- EXCEPINFO *pExInfo;
-{
- SysFreeString(pExInfo->bstrDescription);
- SysFreeString(pExInfo->bstrSource);
- SysFreeString(pExInfo->bstrHelpFile);
-}
-
static VALUE
ole_excepinfo2msg(pExInfo)
EXCEPINFO *pExInfo;
@@ -668,7 +561,9 @@ ole_excepinfo2msg(pExInfo)
}
if(pSource) free(pSource);
if(pDescription) free(pDescription);
- ole_freeexceptinfo(pExInfo);
+ SysFreeString(pExInfo->bstrDescription);
+ SysFreeString(pExInfo->bstrSource);
+ SysFreeString(pExInfo->bstrHelpFile);
return error_msg;
}
@@ -723,11 +618,6 @@ ole_initialize()
/*
atexit((void (*)(void))ole_uninitialize);
*/
- hr = CoRegisterMessageFilter(&imessage_filter, &previous_filter);
- if(FAILED(hr)) {
- previous_filter = NULL;
- ole_raise(hr, rb_eRuntimeError, "fail: install OLE MessageFilter");
- }
}
}
@@ -2213,15 +2103,12 @@ ole_invoke(argc, argv, self, wFlags)
&result, &excepinfo, &argErr);
if (FAILED(hr)) {
/* retry to call args by value */
- if(op.dp.cArgs >= cNamedArgs) {
+ if(op.dp.cArgs > cNamedArgs) {
for(i = cNamedArgs; i < op.dp.cArgs; i++) {
n = op.dp.cArgs - i + cNamedArgs - 1;
param = rb_ary_entry(paramS, i-cNamedArgs);
ole_val2variant(param, &op.dp.rgvarg[n]);
}
- if (hr == DISP_E_EXCEPTION) {
- ole_freeexceptinfo(&excepinfo);
- }
memset(&excepinfo, 0, sizeof(EXCEPINFO));
VariantInit(&result);
hr = pole->pDispatch->lpVtbl->Invoke(pole->pDispatch, DispID,
@@ -2234,9 +2121,6 @@ ole_invoke(argc, argv, self, wFlags)
* hResult == DISP_E_EXCEPTION. this only happens on
* functions whose DISPID > 0x8000 */
if ((hr == DISP_E_EXCEPTION || hr == DISP_E_MEMBERNOTFOUND) && DispID > 0x8000) {
- if (hr == DISP_E_EXCEPTION) {
- ole_freeexceptinfo(&excepinfo);
- }
memset(&excepinfo, 0, sizeof(EXCEPINFO));
hr = pole->pDispatch->lpVtbl->Invoke(pole->pDispatch, DispID,
&IID_NULL, lcid, wFlags,
@@ -2256,9 +2140,6 @@ ole_invoke(argc, argv, self, wFlags)
param = rb_ary_entry(paramS, i-cNamedArgs);
ole_val2variant2(param, &op.dp.rgvarg[n]);
}
- if (hr == DISP_E_EXCEPTION) {
- ole_freeexceptinfo(&excepinfo);
- }
memset(&excepinfo, 0, sizeof(EXCEPINFO));
VariantInit(&result);
hr = pole->pDispatch->lpVtbl->Invoke(pole->pDispatch, DispID,
@@ -3381,54 +3262,6 @@ fole_method_help( self, cmdname )
}
/*
- * call-seq:
- * WIN32OLE#ole_activex_initialize() -> Qnil
- *
- * Initialize WIN32OLE object(ActiveX Control) by calling
- * IPersistMemory::InitNew.
- *
- * Before calling OLE method, some kind of the ActiveX controls
- * created with MFC should be initialized by calling
- * IPersistXXX::InitNew.
- *
- * If and only if you recieved the exception "HRESULT error code:
- * 0x8000ffff catastrophic failure", try this method before
- * invoking any ole_method.
- *
- * obj = WIN32OLE.new("ProgID_or_GUID_of_ActiveX_Control")
- * obj.ole_activex_initialize
- * obj.method(...)
- *
- */
-static VALUE
-fole_activex_initialize(self)
- VALUE self;
-{
- struct oledata *pole;
- IPersistMemory *pPersistMemory;
-
- HRESULT hr = S_OK;
-
- OLEData_Get_Struct(self, pole);
-
- hr = pole->pDispatch->lpVtbl->QueryInterface(pole->pDispatch, &IID_IPersistMemory,
- (void **)&pPersistMemory);
- if (SUCCEEDED(hr)) {
- hr = pPersistMemory->lpVtbl->InitNew(pPersistMemory);
- OLE_RELEASE(pPersistMemory);
- if (SUCCEEDED(hr)) {
- return Qnil;
- }
- }
-
- if (FAILED(hr)) {
- ole_raise(hr, eWIN32OLE_RUNTIME_ERROR, "fail to initialize ActiveX control");
- }
-
- return Qnil;
-}
-
-/*
* call-seq:
* WIN32OLE_TYPE.ole_classes(typelib)
*
@@ -6286,14 +6119,6 @@ Init_win32ole()
com_vtbl.GetTypeInfo = GetTypeInfo;
com_vtbl.GetIDsOfNames = GetIDsOfNames;
com_vtbl.Invoke = Invoke;
-
- message_filter.QueryInterface = mf_QueryInterface;
- message_filter.AddRef = mf_AddRef;
- message_filter.Release = mf_Release;
- message_filter.HandleInComingCall = mf_HandleInComingCall;
- message_filter.RetryRejectedCall = mf_RetryRejectedCall;
- message_filter.MessagePending = mf_MessagePending;
-
com_hash = Data_Wrap_Struct(rb_cData, rb_mark_hash, st_free_table, st_init_numtable());
cWIN32OLE = rb_define_class("WIN32OLE", rb_cObject);
@@ -6337,7 +6162,6 @@ Init_win32ole()
rb_define_method(cWIN32OLE, "ole_method", fole_method_help, 1);
rb_define_alias(cWIN32OLE, "ole_method_help", "ole_method");
rb_define_method(cWIN32OLE, "ole_obj_help", fole_obj_help, 0);
- rb_define_method(cWIN32OLE, "ole_activex_initialize", fole_activex_initialize, 0);
rb_define_const(cWIN32OLE, "VERSION", rb_str_new2(WIN32OLE_VERSION));
rb_define_const(cWIN32OLE, "ARGV", rb_ary_new());
diff --git a/ext/zlib/extconf.rb b/ext/zlib/extconf.rb
index 53b971b189..b4e76af3c6 100644
--- a/ext/zlib/extconf.rb
+++ b/ext/zlib/extconf.rb
@@ -10,7 +10,7 @@ require 'rbconfig'
dir_config 'zlib'
-if %w'z libz zlib1 zlib zdll'.find {|z| have_library(z, 'deflateReset')} and
+if %w'z libz zlib zdll'.find {|z| have_library(z, 'deflateReset')} and
have_header('zlib.h') then
defines = []
@@ -22,7 +22,7 @@ if %w'z libz zlib1 zlib zdll'.find {|z| have_library(z, 'deflateReset')} and
os_code = 'AMIGA'
when /\Aos2[\-_]emx\z/ then
os_code = 'OS2'
- when /mswin|mingw|bccwin/ then
+ when 'mswin32', 'mingw32', 'bccwin32' then
# NOTE: cygwin should be regarded as Unix.
os_code = 'WIN32'
else
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index 306e267856..8caadaeddc 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -1182,19 +1182,14 @@ static VALUE
rb_deflate_init_copy(self, orig)
VALUE self, orig;
{
- struct zstream *z1, *z2;
+ struct zstream *z1 = get_zstream(self);
+ struct zstream *z2 = get_zstream(orig);
int err;
- Data_Get_Struct(self, struct zstream, z1);
- z2 = get_zstream(orig);
-
err = deflateCopy(&z1->stream, &z2->stream);
if (err != Z_OK) {
raise_zlib_error(err, 0);
}
- z1->input = NIL_P(z2->input) ? Qnil : rb_str_dup(z2->input);
- z1->buf = NIL_P(z2->buf) ? Qnil : rb_str_dup(z2->buf);
- z1->buf_filled = z2->buf_filled;
z1->flags = z2->flags;
return self;
@@ -2491,7 +2486,7 @@ rb_gzfile_set_mtime(obj, mtime)
rb_raise(cGzError, "header is already written");
}
- if (FIXNUM_P(mtime)) {
+ if (FIXNUM_P(time)) {
gz->mtime = FIX2INT(mtime);
}
else {
@@ -3116,8 +3111,6 @@ gzreader_gets(argc, argv, obj)
if (NIL_P(rs)) {
dst = gzfile_read_all(gz);
if (RSTRING(dst)->len != 0) gz->lineno++;
- else
- return Qnil;
return dst;
}
@@ -3376,7 +3369,7 @@ void Init_zlib()
rb_define_singleton_method(cDeflate, "deflate", rb_deflate_s_deflate, -1);
rb_define_alloc_func(cDeflate, rb_deflate_s_allocate);
rb_define_method(cDeflate, "initialize", rb_deflate_initialize, -1);
- rb_define_method(cDeflate, "initialize_copy", rb_deflate_init_copy, 1);
+ rb_define_method(cDeflate, "initialize_copy", rb_deflate_init_copy, 0);
rb_define_method(cDeflate, "deflate", rb_deflate_deflate, -1);
rb_define_method(cDeflate, "<<", rb_deflate_addstr, 1);
rb_define_method(cDeflate, "flush", rb_deflate_flush, -1);
diff --git a/file.c b/file.c
index ca80795817..52fe96c436 100644
--- a/file.c
+++ b/file.c
@@ -15,10 +15,6 @@
#ifdef _WIN32
#include "missing/file.h"
#endif
-#ifdef __CYGWIN__
-#include <windows.h>
-#include <sys/cygwin.h>
-#endif
#include "ruby.h"
#include "rubyio.h"
@@ -142,7 +138,7 @@ static VALUE
rb_file_path(obj)
VALUE obj;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
fptr = RFILE(rb_io_taint_check(obj))->fptr;
rb_io_check_initialized(fptr);
@@ -656,7 +652,7 @@ rb_stat(file, st)
tmp = rb_check_convert_type(file, T_FILE, "IO", "to_io");
if (!NIL_P(tmp)) {
- rb_io_t *fptr;
+ OpenFile *fptr;
rb_secure(2);
GetOpenFile(tmp, fptr);
@@ -677,7 +673,7 @@ w32_io_info(file, st)
tmp = rb_check_convert_type(*file, T_FILE, "IO", "to_io");
if (!NIL_P(tmp)) {
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(tmp, fptr);
f = (HANDLE)rb_w32_get_osfhandle(fileno(fptr->f));
@@ -743,7 +739,7 @@ static VALUE
rb_io_stat(obj)
VALUE obj;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct stat st;
GetOpenFile(obj, fptr);
@@ -804,7 +800,7 @@ rb_file_lstat(obj)
VALUE obj;
{
#ifdef HAVE_LSTAT
- rb_io_t *fptr;
+ OpenFile *fptr;
struct stat st;
rb_secure(2);
@@ -895,8 +891,8 @@ eaccess(path, mode)
return -1;
#else
-# if defined(_MSC_VER) || defined(__MINGW32__)
- mode &= ~1;
+# if _MSC_VER >= 1400
+ mode &= 6;
# endif
return access(path, mode);
#endif
@@ -1495,7 +1491,7 @@ static VALUE
rb_file_ftype(st)
struct stat *st;
{
- const char *t;
+ char *t;
if (S_ISREG(st->st_mode)) {
t = "file";
@@ -1598,7 +1594,7 @@ static VALUE
rb_file_atime(obj)
VALUE obj;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct stat st;
GetOpenFile(obj, fptr);
@@ -1643,7 +1639,7 @@ static VALUE
rb_file_mtime(obj)
VALUE obj;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct stat st;
GetOpenFile(obj, fptr);
@@ -1691,7 +1687,7 @@ static VALUE
rb_file_ctime(obj)
VALUE obj;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
struct stat st;
GetOpenFile(obj, fptr);
@@ -1759,7 +1755,7 @@ static VALUE
rb_file_chmod(obj, vmode)
VALUE obj, vmode;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
int mode;
rb_secure(2);
@@ -1785,7 +1781,7 @@ lchmod_internal(path, mode)
const char *path;
void *mode;
{
- if (lchmod(path, (int)(VALUE)mode) < 0)
+ if (lchmod(path, (int)mode) < 0)
rb_sys_fail(path);
}
@@ -1903,7 +1899,7 @@ static VALUE
rb_file_chown(obj, owner, group)
VALUE obj, owner, group;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
int o, g;
rb_secure(2);
@@ -2017,7 +2013,6 @@ rb_file_s_utime(argc, argv)
struct timeval tvs[2], *tvp = NULL;
long n;
- rb_secure(2);
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
if (!NIL_P(atime) || !NIL_P(mtime)) {
@@ -2303,33 +2298,12 @@ rb_file_s_umask(argc, argv)
return INT2FIX(omask);
}
-#ifdef __CYGWIN__
-#undef DOSISH
-#endif
-#if defined __CYGWIN__ || defined DOSISH
+#if defined DOSISH
#define DOSISH_UNC
-#define DOSISH_DRIVE_LETTER
#define isdirsep(x) ((x) == '/' || (x) == '\\')
#else
#define isdirsep(x) ((x) == '/')
#endif
-
-#if defined _WIN32 || defined __CYGWIN__
-#define USE_NTFS 1
-#else
-#define USE_NTFS 0
-#endif
-
-#ifdef DOSISH_DRIVE_LETTER
-#include <ctype.h>
-#endif
-
-#if USE_NTFS
-#define istrailinggabage(x) ((x) == '.' || (x) == ' ')
-#else
-#define istrailinggabage(x) 0
-#endif
-
#ifndef CharNext /* defined as CharNext[AW] on Windows. */
# if defined(DJGPP)
# define CharNext(p) ((p) + mblen(p, MB_CUR_MAX))
@@ -2338,6 +2312,12 @@ rb_file_s_umask(argc, argv)
# endif
#endif
+#ifdef __CYGWIN__
+#undef DOSISH
+#define DOSISH_UNC
+#define DOSISH_DRIVE_LETTER
+#endif
+
#ifdef DOSISH_DRIVE_LETTER
static inline int
has_drive_letter(buf)
@@ -2474,40 +2454,15 @@ rb_path_end(path)
return chompdirsep(path);
}
-#if USE_NTFS
-static char *
-ntfs_tail(const char *path)
-{
- while (*path == '.') path++;
- while (*path && *path != ':') {
- if (istrailinggabage(*path)) {
- const char *last = path++;
- while (istrailinggabage(*path)) path++;
- if (!*path || *path == ':') return (char *)last;
- }
- else if (isdirsep(*path)) {
- const char *last = path++;
- while (isdirsep(*path)) path++;
- if (!*path) return (char *)last;
- if (*path == ':') path++;
- }
- else {
- path = CharNext(path);
- }
- }
- return (char *)path;
-}
-#endif
-
#define BUFCHECK(cond) do {\
long bdiff = p - buf;\
- if (cond) {\
- do {buflen *= 2;} while (cond);\
- rb_str_resize(result, buflen);\
- buf = RSTRING_PTR(result);\
- p = buf + bdiff;\
- pend = buf + buflen;\
+ while (cond) {\
+ buflen *= 2;\
}\
+ rb_str_resize(result, buflen);\
+ buf = RSTRING(result)->ptr;\
+ p = buf + bdiff;\
+ pend = buf + buflen;\
} while (0)
#define BUFINIT() (\
@@ -2525,8 +2480,7 @@ static VALUE
file_expand_path(fname, dname, result)
VALUE fname, dname, result;
{
- const char *s, *b;
- char *buf, *p, *pend, *root;
+ char *s, *buf, *b, *p, *pend, *root;
long buflen, dirlen;
int tainted;
@@ -2536,7 +2490,7 @@ file_expand_path(fname, dname, result)
if (s[0] == '~') {
if (isdirsep(s[1]) || s[1] == '\0') {
- const char *dir = getenv("HOME");
+ char *dir = getenv("HOME");
if (!dir) {
rb_raise(rb_eArgError, "couldn't find HOME environment -- expanding `%s'", s);
@@ -2667,21 +2621,15 @@ file_expand_path(fname, dname, result)
case '.':
if (*(s+1) == '\0' || isdirsep(*(s+1))) {
/* We must go back to the parent */
- char *n;
*p = '\0';
- if (!(n = strrdirsep(root))) {
+ if (!(b = strrdirsep(root))) {
*p = '/';
}
else {
- p = n;
+ p = b;
}
b = ++s;
}
-#if USE_NTFS
- else {
- do *++s; while (istrailinggabage(*s));
- }
-#endif
break;
case '/':
#if defined DOSISH || defined __CYGWIN__
@@ -2694,19 +2642,6 @@ file_expand_path(fname, dname, result)
break;
}
}
-#if USE_NTFS
- else {
- --s;
- case ' ': {
- const char *e = s;
- while (istrailinggabage(*s)) s++;
- if (!*s) {
- s = e;
- goto endpath;
- }
- }
- }
-#endif
break;
case '/':
#if defined DOSISH || defined __CYGWIN__
@@ -2729,76 +2664,15 @@ file_expand_path(fname, dname, result)
}
if (s > b) {
-#if USE_NTFS
- endpath:
- if (s > b + 6 && strncasecmp(s - 6, ":$DATA", 6) == 0) {
- /* alias of stream */
- /* get rid of a bug of x64 VC++ */
- if (*(s-7) == ':') s -= 7; /* prime */
- else if (memchr(b, ':', s - 6 - b)) s -= 6; /* alternative */
- }
-#endif
BUFCHECK(bdiff + (s-b) >= buflen);
memcpy(++p, b, s-b);
p += s-b;
}
if (p == skiproot(buf) - 1) p++;
-#if USE_NTFS
- *p = '\0';
- if ((s = strrdirsep(b = buf)) != 0 && !strpbrk(s, "*?")) {
- size_t len;
- WIN32_FIND_DATA wfd;
-#ifdef __CYGWIN__
- int lnk_added = 0, is_symlink = 0;
- struct stat st;
- char w32buf[MAXPATHLEN];
- p = (char *)s;
- if (lstat(buf, &st) == 0 && S_ISLNK(st.st_mode)) {
- is_symlink = 1;
- *p = '\0';
- }
- if (cygwin_conv_to_win32_path((*buf ? buf : "/"), w32buf) == 0) {
- b = w32buf;
- }
- if (is_symlink && b == w32buf) {
- *p = '\\';
- strlcat(w32buf, p, sizeof(w32buf));
- len = strlen(p);
- if (len > 4 && strcasecmp(p + len - 4, ".lnk") != 0) {
- lnk_added = 1;
- strlcat(w32buf, ".lnk", sizeof(w32buf));
- }
- }
- *p = '/';
-#endif
- HANDLE h = FindFirstFile(b, &wfd);
- if (h != INVALID_HANDLE_VALUE) {
- FindClose(h);
- len = strlen(wfd.cFileName);
-#ifdef __CYGWIN__
- if (lnk_added && len > 4 &&
- strcasecmp(wfd.cFileName + len - 4, ".lnk") == 0) {
- wfd.cFileName[len -= 4] = '\0';
- }
-#else
- p = (char *)s;
-#endif
- ++p;
- BUFCHECK(bdiff + len >= buflen);
- memcpy(p, wfd.cFileName, len + 1);
- p += len;
- }
-#ifdef __CYGWIN__
- else {
- p += strlen(p);
- }
-#endif
- }
-#endif
-
if (tainted) OBJ_TAINT(result);
- rb_str_set_len(result, p - buf);
+ RSTRING(result)->len = p - buf;
+ *p = '\0';
return result;
}
@@ -2842,31 +2716,23 @@ rb_file_s_expand_path(argc, argv)
}
static int
-rmext(p, l1, e)
+rmext(p, e)
const char *p, *e;
- int l1;
{
- int l2;
+ int l1, l2;
if (!e) return 0;
+ l1 = chompdirsep(p) - p;
l2 = strlen(e);
if (l2 == 2 && e[1] == '*') {
- unsigned char c = *e;
- e = p + l1;
- do {
- if (e <= p) return 0;
- } while (*--e != c);
+ e = strrchr(p, *e);
+ if (!e) return 0;
return e - p;
}
if (l1 < l2) return l1;
-#if CASEFOLD_FILESYSTEM
-#define fncomp strncasecmp
-#else
-#define fncomp strncmp
-#endif
- if (fncomp(p+l1-l2, e, l2) == 0) {
+ if (strncmp(p+l1-l2, e, l2) == 0) {
return l1-l2;
}
return 0;
@@ -2892,11 +2758,11 @@ rb_file_s_basename(argc, argv)
VALUE *argv;
{
VALUE fname, fext, basename;
- const char *name, *p;
+ char *name, *p;
#if defined DOSISH_DRIVE_LETTER || defined DOSISH_UNC
- const char *root;
+ char *root;
#endif
- int f, n;
+ int f;
if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) {
StringValue(fext);
@@ -2930,22 +2796,18 @@ rb_file_s_basename(argc, argv)
#endif
#endif
}
- else {
- if (!(p = strrdirsep(name))) {
- p = name;
- }
- else {
- while (isdirsep(*p)) p++; /* skip last / */
+ else if (!(p = strrdirsep(name))) {
+ if (NIL_P(fext) || !(f = rmext(name, StringValueCStr(fext)))) {
+ f = chompdirsep(name) - name;
+ if (f == RSTRING(fname)->len) return fname;
}
-#if USE_NTFS
- n = ntfs_tail(p) - p;
-#else
- n = chompdirsep(p) - p;
-#endif
- if (NIL_P(fext) || !(f = rmext(p, n, StringValueCStr(fext)))) {
- f = n;
+ p = name;
+ }
+ else {
+ while (isdirsep(*p)) p++; /* skip last / */
+ if (NIL_P(fext) || !(f = rmext(p, StringValueCStr(fext)))) {
+ f = chompdirsep(p) - p;
}
- if (f == RSTRING_LEN(fname)) return fname;
}
basename = rb_str_new(p, f);
OBJ_INFECT(basename, fname);
@@ -3021,49 +2883,22 @@ static VALUE
rb_file_s_extname(klass, fname)
VALUE klass, fname;
{
- const char *name, *p, *e;
+ char *name, *p, *e;
VALUE extname;
name = StringValueCStr(fname);
p = strrdirsep(name); /* get the last path component */
if (!p)
- p = name;
+ p = name;
else
- name = ++p;
-
- e = 0;
- while (*p) {
- if (*p == '.' || istrailinggabage(*p)) {
-#if USE_NTFS
- const char *last = p++, *dot = last;
- while (istrailinggabage(*p)) {
- if (*p == '.') dot = p;
- p++;
- }
- if (!*p || *p == ':') {
- p = last;
- break;
- }
- if (*last == '.') e = dot;
- continue;
-#else
- e = p; /* get the last dot of the last component */
-#endif
- }
-#if USE_NTFS
- else if (*p == ':') {
- break;
- }
-#endif
- else if (isdirsep(*p))
- break;
- p = CharNext(p);
- }
- if (!e || e == name || e+1 == p) /* no dot, or the only dot is first or end? */
- return rb_str_new(0, 0);
- extname = rb_str_new(e, p - e); /* keep the dot, too! */
- OBJ_INFECT(extname, fname);
- return extname;
+ p++;
+
+ e = strrchr(p, '.'); /* get the last dot of the last component */
+ if (!e || e == p || !e[1]) /* no dot, or the only dot is first or end? */
+ return rb_str_new2("");
+ extname = rb_str_new(e, chompdirsep(e) - e); /* keep the dot, too! */
+ OBJ_INFECT(extname, fname);
+ return extname;
}
/*
@@ -3104,7 +2939,7 @@ rb_file_join(ary, sep)
long len, i;
int taint = 0;
VALUE result, tmp;
- const char *name, *tail;
+ char *name, *tail;
if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
if (OBJ_TAINTED(ary)) taint = 1;
@@ -3252,7 +3087,7 @@ static VALUE
rb_file_truncate(obj, len)
VALUE obj, len;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
FILE *f;
off_t pos;
@@ -3265,7 +3100,7 @@ rb_file_truncate(obj, len)
f = GetWriteFile(fptr);
fflush(f);
fseeko(f, (off_t)0, SEEK_CUR);
-#ifdef HAVE_FTRUNCATE
+#ifdef HAVE_TRUNCATE
if (ftruncate(fileno(f), pos) < 0)
rb_sys_fail(fptr->path);
#else
@@ -3313,7 +3148,7 @@ cygwin_flock(int fd, int op)
static int
rb_thread_flock(fd, op, fptr)
int fd, op;
- rb_io_t *fptr;
+ OpenFile *fptr;
{
if (rb_thread_alone() || (op & LOCK_NB)) {
int ret;
@@ -3379,7 +3214,7 @@ rb_file_flock(obj, operation)
VALUE operation;
{
#ifndef __CHECKER__
- rb_io_t *fptr;
+ OpenFile *fptr;
int op;
rb_secure(2);
@@ -4289,7 +4124,7 @@ path_check_0(fpath, execpath)
int execpath;
{
struct stat st;
- const char *p0 = StringValueCStr(fpath);
+ char *p0 = StringValueCStr(fpath);
char *p = 0, *s;
if (!is_absolute_path(p0)) {
@@ -4328,7 +4163,7 @@ path_check_0(fpath, execpath)
static int
fpath_check(path)
- const char *path;
+ char *path;
{
#if ENABLE_PATH_CHECK
return path_check_0(rb_str_new2(path), Qfalse);
@@ -4339,10 +4174,10 @@ fpath_check(path)
int
rb_path_check(path)
- const char *path;
+ char *path;
{
#if ENABLE_PATH_CHECK
- const char *p0, *p, *pend;
+ char *p0, *p, *pend;
const char sep = PATH_SEP_CHAR;
if (!path) return 1;
@@ -4377,7 +4212,7 @@ is_macos_native_path(path)
static int
file_load_ok(file)
- const char *file;
+ char *file;
{
FILE *f;
@@ -4395,8 +4230,8 @@ rb_find_file_ext(filep, ext)
VALUE *filep;
const char * const *ext;
{
- const char *path, *found;
- const char *f = RSTRING(*filep)->ptr;
+ char *path, *found;
+ char *f = RSTRING(*filep)->ptr;
VALUE fname;
long i, j;
@@ -4451,8 +4286,8 @@ rb_find_file(path)
VALUE path;
{
VALUE tmp;
- const char *f = StringValueCStr(path);
- const char *lpath;
+ char *f = StringValueCStr(path);
+ char *lpath;
if (f[0] == '~') {
path = rb_file_expand_path(path, Qnil);
diff --git a/gc.c b/gc.c
index 6edd5b433f..9ac3bfbf6f 100644
--- a/gc.c
+++ b/gc.c
@@ -35,12 +35,10 @@
#endif
void re_free_registers _((struct re_registers*));
-void rb_io_fptr_finalize _((struct rb_io_t*));
+void rb_io_fptr_finalize _((struct OpenFile*));
-#define rb_setjmp(env) RUBY_SETJMP(env)
-#define rb_jmp_buf rb_jmpbuf_t
-#ifdef __CYGWIN__
-int _setjmp(), _longjmp();
+#if !defined(setjmp) && defined(HAVE__SETJMP)
+#define setjmp(env) _setjmp(env)
#endif
/* Make alloca work the best possible way. */
@@ -76,62 +74,19 @@ static void run_final();
static VALUE nomem_error;
static void garbage_collect();
-int ruby_gc_stress = 0;
-
-NORETURN(void rb_exc_jump _((VALUE)));
-
void
rb_memerror()
{
- rb_thread_t th = rb_curr_thread;
+ static int recurse = 0;
- if (!nomem_error ||
- (rb_thread_raised_p(th, RAISED_NOMEMORY) && rb_safe_level() < 4)) {
+ if (!nomem_error || (recurse > 0 && rb_safe_level() < 4)) {
fprintf(stderr, "[FATAL] failed to allocate memory\n");
exit(1);
}
- if (rb_thread_raised_p(th, RAISED_NOMEMORY)) {
- rb_exc_jump(nomem_error);
- }
- rb_thread_raised_set(th, RAISED_NOMEMORY);
+ recurse++;
rb_exc_raise(nomem_error);
}
-/*
- * call-seq:
- * GC.stress => true or false
- *
- * returns current status of GC stress mode.
- */
-
-static VALUE
-gc_stress_get(self)
- VALUE self;
-{
- return ruby_gc_stress ? Qtrue : Qfalse;
-}
-
-/*
- * call-seq:
- * GC.stress = bool => bool
- *
- * updates GC stress mode.
- *
- * When GC.stress = true, GC is invoked for all GC opportunity:
- * all memory and object allocation.
- *
- * Since it makes Ruby very slow, it is only for debugging.
- */
-
-static VALUE
-gc_stress_set(self, bool)
- VALUE self, bool;
-{
- rb_secure(2);
- ruby_gc_stress = RTEST(bool);
- return bool;
-}
-
void *
ruby_xmalloc(size)
long size;
@@ -142,8 +97,9 @@ ruby_xmalloc(size)
rb_raise(rb_eNoMemError, "negative allocation size (or too big)");
}
if (size == 0) size = 1;
+ malloc_increase += size;
- if (ruby_gc_stress || (malloc_increase+size) > malloc_limit) {
+ if (malloc_increase > malloc_limit) {
garbage_collect();
}
RUBY_CRITICAL(mem = malloc(size));
@@ -154,7 +110,6 @@ ruby_xmalloc(size)
rb_memerror();
}
}
- malloc_increase += size;
return mem;
}
@@ -183,7 +138,7 @@ ruby_xrealloc(ptr, size)
}
if (!ptr) return xmalloc(size);
if (size == 0) size = 1;
- if (ruby_gc_stress) garbage_collect();
+ malloc_increase += size;
RUBY_CRITICAL(mem = realloc(ptr, size));
if (!mem) {
garbage_collect();
@@ -192,7 +147,6 @@ ruby_xrealloc(ptr, size)
rb_memerror();
}
}
- malloc_increase += size;
return mem;
}
@@ -419,21 +373,12 @@ add_heap()
}
#define RANY(o) ((RVALUE*)(o))
-int
-rb_during_gc()
-{
- return during_gc;
-}
-
VALUE
rb_newobj()
{
VALUE obj;
- if (during_gc)
- rb_bug("object allocation during garbage collection phase");
-
- if (ruby_gc_stress || !freelist) garbage_collect();
+ if (!freelist) garbage_collect();
obj = (VALUE)freelist;
freelist = freelist->as.free.next;
@@ -480,7 +425,7 @@ unsigned int _stacksize = 262144;
# define STACK_LEVEL_MAX (_stacksize - 4096)
# undef HAVE_GETRLIMIT
#elif defined(HAVE_GETRLIMIT) || defined(_WIN32)
-static size_t STACK_LEVEL_MAX = 655300;
+static unsigned int STACK_LEVEL_MAX = 655300;
#else
# define STACK_LEVEL_MAX 655300
#endif
@@ -493,19 +438,20 @@ static size_t STACK_LEVEL_MAX = 655300;
# if ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 ) || __GNUC__ > 3
__attribute__ ((noinline))
# endif
-static void
-stack_end_address(VALUE **stack_end_p)
+static VALUE *
+stack_end_address(void)
{
- VALUE stack_end;
- *stack_end_p = &stack_end;
+ return (VALUE *)__builtin_frame_address(0);
}
-# define SET_STACK_END VALUE *stack_end; stack_end_address(&stack_end)
+# define SET_STACK_END VALUE *stack_end = stack_end_address()
# else
# define SET_STACK_END VALUE *stack_end = alloca(1)
# endif
# define STACK_END (stack_end)
#endif
-#if STACK_GROW_DIRECTION < 0
+#if defined(sparc) || defined(__sparc__)
+# define STACK_LENGTH (rb_gc_stack_start - STACK_END + 0x80)
+#elif STACK_GROW_DIRECTION < 0
# define STACK_LENGTH (rb_gc_stack_start - STACK_END)
#elif STACK_GROW_DIRECTION > 0
# define STACK_LENGTH (STACK_END - rb_gc_stack_start + 1)
@@ -539,7 +485,7 @@ stack_grow_direction(addr)
(ret) = (STACK_LENGTH > STACK_LEVEL_MAX + GC_WATER_MARK);\
} while (0)
-size_t
+int
ruby_stack_length(p)
VALUE **p;
{
@@ -570,25 +516,24 @@ init_mark_stack()
}
#define MARK_STACK_EMPTY (mark_stack_ptr == mark_stack)
-
+
static st_table *source_filenames;
char *
rb_source_filename(f)
const char *f;
{
- st_data_t name;
+ char *name;
- if (!st_lookup(source_filenames, (st_data_t)f, &name)) {
+ if (!st_lookup(source_filenames, (st_data_t)f, (st_data_t *)&name)) {
long len = strlen(f) + 1;
- char *ptr = ALLOC_N(char, len + 1);
- name = (st_data_t)ptr;
+ char *ptr = name = ALLOC_N(char, len + 1);
*ptr++ = 0;
MEMCPY(ptr, f, char, len);
- st_add_direct(source_filenames, (st_data_t)ptr, name);
+ st_add_direct(source_filenames, (st_data_t)ptr, (st_data_t)name);
return ptr;
}
- return (char *)name + 1;
+ return name + 1;
}
static void
@@ -778,7 +723,7 @@ gc_mark(ptr, lev)
if (!mark_stack_overflow) {
if (mark_stack_ptr - mark_stack < MARK_STACK_MAX) {
*mark_stack_ptr = ptr;
- mark_stack_ptr++;
+ mark_stack_ptr++;
}
else {
mark_stack_overflow = 1;
@@ -1052,16 +997,7 @@ gc_mark_children(ptr, lev)
}
}
-static int obj_free _((VALUE));
-
-static inline void
-add_freelist(p)
- RVALUE *p;
-{
- p->as.free.flags = 0;
- p->as.free.next = freelist;
- freelist = p;
-}
+static void obj_free _((VALUE));
static void
finalize_list(p)
@@ -1071,7 +1007,9 @@ finalize_list(p)
RVALUE *tmp = p->as.free.next;
run_final((VALUE)p);
if (!FL_TEST(p, FL_SINGLETON)) { /* not freeing page */
- add_freelist(p);
+ p->as.free.flags = 0;
+ p->as.free.next = freelist;
+ freelist = p;
}
p = tmp;
}
@@ -1096,8 +1034,6 @@ free_unused_heaps()
}
}
-#define T_DEFERRED 0x3a
-
void rb_gc_abort_threads(void);
static void
@@ -1141,28 +1077,26 @@ gc_sweep()
int n = 0;
RVALUE *free = freelist;
RVALUE *final = final_list;
- int deferred;
p = heaps[i].slot; pend = p + heaps[i].limit;
while (p < pend) {
if (!(p->as.basic.flags & FL_MARK)) {
- if (p->as.basic.flags &&
- ((deferred = obj_free((VALUE)p)) ||
- ((FL_TEST(p, FL_FINALIZE)) && need_call_final))) {
- if (!deferred) {
- p->as.free.flags = T_DEFERRED;
- RDATA(p)->dfree = 0;
- }
- p->as.free.flags |= FL_MARK;
+ if (p->as.basic.flags) {
+ obj_free((VALUE)p);
+ }
+ if (need_call_final && FL_TEST(p, FL_FINALIZE)) {
+ p->as.free.flags = FL_MARK; /* remain marked */
p->as.free.next = final_list;
final_list = p;
}
else {
- add_freelist(p);
+ p->as.free.flags = 0;
+ p->as.free.next = freelist;
+ freelist = p;
}
n++;
}
- else if (BUILTIN_TYPE(p) == T_DEFERRED) {
+ else if (RBASIC(p)->flags == FL_MARK) {
/* objects to be finalized */
/* do nothing remain marked */
}
@@ -1198,7 +1132,6 @@ gc_sweep()
/* clear finalization list */
if (final_list) {
deferred_final_list = final_list;
- rb_thread_pending = 1;
return;
}
free_unused_heaps();
@@ -1208,21 +1141,16 @@ void
rb_gc_force_recycle(p)
VALUE p;
{
- add_freelist(p);
-}
-
-static inline void
-make_deferred(p)
- RVALUE *p;
-{
- p->as.basic.flags = (p->as.basic.flags & ~T_MASK) | T_DEFERRED;
+ RANY(p)->as.free.flags = 0;
+ RANY(p)->as.free.next = freelist;
+ freelist = RANY(p);
}
-static int
+static void
obj_free(obj)
VALUE obj;
{
- switch (BUILTIN_TYPE(obj)) {
+ switch (RANY(obj)->as.basic.flags & T_MASK) {
case T_NIL:
case T_FIXNUM:
case T_TRUE:
@@ -1235,7 +1163,7 @@ obj_free(obj)
rb_free_generic_ivar((VALUE)obj);
}
- switch (BUILTIN_TYPE(obj)) {
+ switch (RANY(obj)->as.basic.flags & T_MASK) {
case T_OBJECT:
if (RANY(obj)->as.object.iv_tbl) {
st_free_table(RANY(obj)->as.object.iv_tbl);
@@ -1278,8 +1206,7 @@ obj_free(obj)
RUBY_CRITICAL(free(DATA_PTR(obj)));
}
else if (RANY(obj)->as.data.dfree) {
- make_deferred(RANY(obj));
- return 1;
+ (*RANY(obj)->as.data.dfree)(DATA_PTR(obj));
}
}
break;
@@ -1291,11 +1218,8 @@ obj_free(obj)
break;
case T_FILE:
if (RANY(obj)->as.file.fptr) {
- struct rb_io_t *fptr = RANY(obj)->as.file.fptr;
- make_deferred(RANY(obj));
- RDATA(obj)->dfree = (void (*)(void*))rb_io_fptr_finalize;
- RDATA(obj)->data = fptr;
- return 1;
+ rb_io_fptr_finalize(RANY(obj)->as.file.fptr);
+ RUBY_CRITICAL(free(RANY(obj)->as.file.fptr));
}
break;
case T_ICLASS:
@@ -1323,13 +1247,13 @@ obj_free(obj)
RUBY_CRITICAL(free(RANY(obj)->as.node.u1.node));
break;
}
- break; /* no need to free iv_tbl */
+ return; /* no need to free iv_tbl */
case T_SCOPE:
if (RANY(obj)->as.scope.local_vars &&
RANY(obj)->as.scope.flags != SCOPE_ALLOCA) {
VALUE *vars = RANY(obj)->as.scope.local_vars-1;
- if (!(RANY(obj)->as.scope.flags & SCOPE_CLONE) && vars[0] == 0)
+ if (!(RANY(obj)->as.scope.flags & SCOPE_CLONE) && vars[0] == 0)
RUBY_CRITICAL(free(RANY(obj)->as.scope.local_tbl));
if (RANY(obj)->as.scope.flags & SCOPE_MALLOC)
RUBY_CRITICAL(free(vars));
@@ -1346,8 +1270,6 @@ obj_free(obj)
rb_bug("gc_sweep(): unknown data type 0x%lx(0x%lx)",
RANY(obj)->as.basic.flags & T_MASK, obj);
}
-
- return 0;
}
void
@@ -1359,8 +1281,6 @@ rb_gc_mark_frame(frame)
#ifdef __GNUC__
#if defined(__human68k__) || defined(DJGPP)
-#undef rb_setjmp
-#undef rb_jmp_buf
#if defined(__human68k__)
typedef unsigned long rb_jmp_buf[8];
__asm__ (".even\n\
@@ -1369,6 +1289,9 @@ _rb_setjmp:\n\
movem.l d3-d7/a3-a5,(a0)\n\
moveq.l #0,d0\n\
rts");
+#ifdef setjmp
+#undef setjmp
+#endif
#else
#if defined(DJGPP)
typedef unsigned long rb_jmp_buf[6];
@@ -1389,6 +1312,8 @@ _rb_setjmp:\n\
#endif
#endif
int rb_setjmp (rb_jmp_buf);
+#define jmp_buf rb_jmp_buf
+#define setjmp rb_setjmp
#endif /* __human68k__ or DJGPP */
#endif /* __GNUC__ */
@@ -1437,7 +1362,7 @@ garbage_collect()
FLUSH_REGISTER_WINDOWS;
/* This assumes that all registers are saved into the jmp_buf (and stack) */
- rb_setjmp(save_regs_gc_mark);
+ setjmp(save_regs_gc_mark);
mark_locations_array((VALUE*)save_regs_gc_mark, sizeof(save_regs_gc_mark) / sizeof(VALUE *));
#if STACK_GROW_DIRECTION < 0
rb_gc_mark_locations((VALUE*)STACK_END, rb_gc_stack_start);
@@ -1563,7 +1488,7 @@ Init_stack(addr)
rb_gc_stack_start = STACK_END_ADDRESS;
}
#else
- if (!addr) addr = (void *)&addr;
+ if (!addr) addr = (VALUE *)&addr;
STACK_UPPER(&addr, addr, ++addr);
if (rb_gc_stack_start) {
if (STACK_UPPER(&addr,
@@ -1674,12 +1599,43 @@ Init_heap()
}
static VALUE
+os_live_obj()
+{
+ int i;
+ int n = 0;
+
+ for (i = 0; i < heaps_used; i++) {
+ RVALUE *p, *pend;
+
+ p = heaps[i].slot; pend = p + heaps[i].limit;
+ for (;p < pend; p++) {
+ if (p->as.basic.flags) {
+ switch (TYPE(p)) {
+ case T_ICLASS:
+ case T_VARMAP:
+ case T_SCOPE:
+ case T_NODE:
+ continue;
+ case T_CLASS:
+ if (FL_TEST(p, FL_SINGLETON)) continue;
+ default:
+ if (!p->as.basic.klass) continue;
+ rb_yield((VALUE)p);
+ n++;
+ }
+ }
+ }
+ }
+
+ return INT2FIX(n);
+}
+
+static VALUE
os_obj_of(of)
VALUE of;
{
int i;
int n = 0;
- volatile VALUE v;
for (i = 0; i < heaps_used; i++) {
RVALUE *p, *pend;
@@ -1687,21 +1643,18 @@ os_obj_of(of)
p = heaps[i].slot; pend = p + heaps[i].limit;
for (;p < pend; p++) {
if (p->as.basic.flags) {
- switch (BUILTIN_TYPE(p)) {
- case T_NONE:
+ switch (TYPE(p)) {
case T_ICLASS:
case T_VARMAP:
case T_SCOPE:
case T_NODE:
- case T_DEFERRED:
continue;
case T_CLASS:
if (FL_TEST(p, FL_SINGLETON)) continue;
default:
if (!p->as.basic.klass) continue;
- v = (VALUE)p;
- if (!of || rb_obj_is_kind_of(v, of)) {
- rb_yield(v);
+ if (rb_obj_is_kind_of((VALUE)p, of)) {
+ rb_yield((VALUE)p);
n++;
}
}
@@ -1746,22 +1699,19 @@ os_obj_of(of)
*/
static VALUE
-os_each_obj(argc, argv, os)
+os_each_obj(argc, argv)
int argc;
VALUE *argv;
- VALUE os;
{
VALUE of;
rb_secure(4);
- if (argc == 0) {
- of = 0;
+ if (rb_scan_args(argc, argv, "01", &of) == 0) {
+ return os_live_obj();
}
else {
- rb_scan_args(argc, argv, "01", &of);
+ return os_obj_of(of);
}
- RETURN_ENUMERATOR(os, 1, &of);
- return os_obj_of(of);
}
static VALUE finalizers;
@@ -1941,21 +1891,6 @@ rb_gc_finalize_deferred()
}
}
-static int
-chain_finalized_object(st_data_t key, st_data_t val, st_data_t arg)
-{
- RVALUE *p = (RVALUE *)key, **final_list = (RVALUE **)arg;
- if ((p->as.basic.flags & (FL_FINALIZE|FL_MARK)) == FL_FINALIZE) {
- if (BUILTIN_TYPE(p) != T_DEFERRED) {
- p->as.free.flags = FL_MARK | T_DEFERRED; /* remain marked */
- RDATA(p)->dfree = 0;
- }
- p->as.free.next = *final_list;
- *final_list = p;
- }
- return ST_CONTINUE;
-}
-
void
rb_gc_call_finalizer_at_exit()
{
@@ -1964,14 +1899,20 @@ rb_gc_call_finalizer_at_exit()
/* run finalizers */
if (need_call_final) {
- do {
- p = deferred_final_list;
- deferred_final_list = 0;
- finalize_list(p);
- mark_tbl(finalizer_table, 0);
- st_foreach(finalizer_table, chain_finalized_object,
- (st_data_t)&deferred_final_list);
- } while (deferred_final_list);
+ p = deferred_final_list;
+ deferred_final_list = 0;
+ finalize_list(p);
+ for (i = 0; i < heaps_used; i++) {
+ p = heaps[i].slot; pend = p + heaps[i].limit;
+ while (p < pend) {
+ if (FL_TEST(p, FL_FINALIZE)) {
+ FL_UNSET(p, FL_FINALIZE);
+ p->as.basic.klass = 0;
+ run_final((VALUE)p);
+ }
+ p++;
+ }
+ }
}
/* run data object's finalizers */
for (i = 0; i < heaps_used; i++) {
@@ -2014,7 +1955,6 @@ id2ref(obj, objid)
VALUE obj, objid;
{
unsigned long ptr, p0;
- int type;
rb_secure(4);
p0 = ptr = NUM2ULONG(objid);
@@ -2031,8 +1971,7 @@ id2ref(obj, objid)
return ID2SYM(symid);
}
- if (!is_pointer_to_heap((void *)ptr)||
- (type = BUILTIN_TYPE(ptr)) > T_SYMBOL || type == T_ICLASS) {
+ if (!is_pointer_to_heap((void *)ptr)|| BUILTIN_TYPE(ptr) >= T_BLKTAG) {
rb_raise(rb_eRangeError, "0x%lx is not id value", p0);
}
if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0) {
@@ -2048,7 +1987,7 @@ id2ref(obj, objid)
* call-seq:
* obj.__id__ => fixnum
* obj.object_id => fixnum
- *
+ *
* Returns an integer identifier for <i>obj</i>. The same number will
* be returned on all calls to <code>id</code> for a given object, and
* no two active objects will share an id.
@@ -2060,7 +1999,7 @@ id2ref(obj, objid)
/*
* call-seq:
* obj.hash => fixnum
- *
+ *
* Generates a <code>Fixnum</code> hash value for this object. This
* function must have the property that <code>a.eql?(b)</code> implies
* <code>a.hash == b.hash</code>. The hash value is used by class
@@ -2123,8 +2062,6 @@ Init_GC()
rb_define_singleton_method(rb_mGC, "start", rb_gc_start, 0);
rb_define_singleton_method(rb_mGC, "enable", rb_gc_enable, 0);
rb_define_singleton_method(rb_mGC, "disable", rb_gc_disable, 0);
- rb_define_singleton_method(rb_mGC, "stress", gc_stress_get, 0);
- rb_define_singleton_method(rb_mGC, "stress=", gc_stress_set, 1);
rb_define_method(rb_mGC, "garbage_collect", rb_gc_start, 0);
rb_mObSpace = rb_define_module("ObjectSpace");
@@ -2148,10 +2085,7 @@ Init_GC()
source_filenames = st_init_strtable();
rb_global_variable(&nomem_error);
- nomem_error = rb_exc_new3(rb_eNoMemError,
- rb_obj_freeze(rb_str_new2("failed to allocate memory")));
- OBJ_TAINT(nomem_error);
- OBJ_FREEZE(nomem_error);
+ nomem_error = rb_exc_new2(rb_eNoMemError, "failed to allocate memory");
rb_define_method(rb_mKernel, "hash", rb_obj_id, 0);
rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0);
diff --git a/hash.c b/hash.c
index 3f269becb5..557e3c8b5a 100644
--- a/hash.c
+++ b/hash.c
@@ -89,16 +89,15 @@ rb_any_hash(a)
VALUE a;
{
VALUE hval;
- int hnum;
switch (TYPE(a)) {
case T_FIXNUM:
case T_SYMBOL:
- hnum = (int)a;
+ return (int)a;
break;
case T_STRING:
- hnum = rb_str_hash(a);
+ return rb_str_hash(a);
break;
default:
@@ -106,10 +105,8 @@ rb_any_hash(a)
if (!FIXNUM_P(hval)) {
hval = rb_funcall(hval, '%', 1, INT2FIX(536870923));
}
- hnum = (int)FIX2LONG(hval);
+ return (int)FIX2LONG(hval);
}
- hnum <<= 1;
- return RSHIFT(hnum, 1);
}
static struct st_hash_type objhash = {
@@ -117,11 +114,9 @@ static struct st_hash_type objhash = {
rb_any_hash,
};
-typedef int st_foreach_func(st_data_t, st_data_t, st_data_t);
-
struct foreach_safe_arg {
st_table *tbl;
- st_foreach_func *func;
+ int (*func)();
st_data_t arg;
};
@@ -149,18 +144,16 @@ st_foreach_safe(table, func, a)
struct foreach_safe_arg arg;
arg.tbl = table;
- arg.func = (st_foreach_func *)func;
+ arg.func = func;
arg.arg = a;
if (st_foreach(table, foreach_safe_i, (st_data_t)&arg)) {
rb_raise(rb_eRuntimeError, "hash modified during iteration");
}
}
-typedef int rb_foreach_func(VALUE, VALUE, VALUE);
-
struct hash_foreach_arg {
VALUE hash;
- rb_foreach_func *func;
+ int (*func)();
VALUE arg;
};
@@ -172,7 +165,7 @@ hash_foreach_iter(key, value, arg)
int status;
st_table *tbl;
- tbl = RHASH(arg->hash)->tbl;
+ tbl = RHASH(arg->hash)->tbl;
if (key == Qundef) return ST_CONTINUE;
status = (*arg->func)(key, value, arg->arg);
if (RHASH(arg->hash)->tbl != tbl) {
@@ -225,7 +218,7 @@ rb_hash_foreach(hash, func, farg)
RHASH(hash)->iter_lev++;
arg.hash = hash;
- arg.func = (rb_foreach_func *)func;
+ arg.func = func;
arg.arg = farg;
rb_ensure(hash_foreach_call, (VALUE)&arg, hash_foreach_ensure, hash);
}
@@ -266,7 +259,7 @@ rb_hash_new()
* Hash.new => hash
* Hash.new(obj) => aHash
* Hash.new {|hash, key| block } => aHash
- *
+ *
* Returns a new, empty hash. If this hash is subsequently accessed by
* a key that doesn't correspond to a hash entry, the value returned
* depends on the style of <code>new</code> used to create the hash. In
@@ -276,7 +269,7 @@ rb_hash_new()
* called with the hash object and the key, and should return the
* default value. It is the block's responsibility to store the value
* in the hash if required.
- *
+ *
* h = Hash.new("Go Fish")
* h["a"] = 100
* h["b"] = 200
@@ -286,14 +279,14 @@ rb_hash_new()
* h["c"].upcase! #=> "GO FISH"
* h["d"] #=> "GO FISH"
* h.keys #=> ["a", "b"]
- *
+ *
* # While this creates a new default object each time
* h = Hash.new { |hash, key| hash[key] = "Go Fish: #{key}" }
* h["c"] #=> "Go Fish: c"
* h["c"].upcase! #=> "GO FISH: C"
* h["d"] #=> "Go Fish: d"
* h.keys #=> ["c", "d"]
- *
+ *
*/
static VALUE
@@ -323,11 +316,11 @@ rb_hash_initialize(argc, argv, hash)
/*
* call-seq:
* Hash[ [key =>|, value]* ] => hash
- *
+ *
* Creates a new hash populated with the given objects. Equivalent to
* the literal <code>{ <i>key</i>, <i>value</i>, ... }</code>. Keys and
* values occur in pairs, so there must be an even number of arguments.
- *
+ *
* Hash["a", 100, "b", 200] #=> {"a"=>100, "b"=>200}
* Hash["a" => 100, "b" => 200] #=> {"a"=>100, "b"=>200}
* { "a" => 100, "b" => 200 } #=> {"a"=>100, "b"=>200}
@@ -339,32 +332,16 @@ rb_hash_s_create(argc, argv, klass)
VALUE *argv;
VALUE klass;
{
- VALUE hash, tmp;
+ VALUE hash;
int i;
- if (argc == 1) {
- tmp = rb_check_convert_type(argv[0], T_HASH, "Hash", "to_hash");
- if (!NIL_P(tmp)) {
- hash = hash_alloc0(klass);
- RHASH(hash)->tbl = st_copy(RHASH(tmp)->tbl);
- return hash;
- }
+ if (argc == 1 && TYPE(argv[0]) == T_HASH) {
+ hash = hash_alloc0(klass);
+ RHASH(hash)->tbl = st_copy(RHASH(argv[0])->tbl);
- tmp = rb_check_array_type(argv[0]);
- if (!NIL_P(tmp)) {
- long i;
-
- hash = hash_alloc(klass);
- for (i = 0; i < RARRAY_LEN(tmp); ++i) {
- VALUE v = rb_check_array_type(RARRAY_PTR(tmp)[i]);
-
- if (NIL_P(v)) continue;
- if (RARRAY_LEN(v) < 1 || 2 < RARRAY_LEN(v)) continue;
- rb_hash_aset(hash, RARRAY_PTR(v)[0], RARRAY_PTR(v)[1]);
- }
- return hash;
- }
+ return hash;
}
+
if (argc % 2 != 0) {
rb_raise(rb_eArgError, "odd number of arguments for Hash");
}
@@ -396,13 +373,13 @@ rb_hash_rehash_i(key, value, tbl)
/*
* call-seq:
* hsh.rehash -> hsh
- *
+ *
* Rebuilds the hash based on the current hash values for each key. If
* values of key objects have changed since they were inserted, this
* method will reindex <i>hsh</i>. If <code>Hash#rehash</code> is
* called while an iterator is traversing the hash, an
* <code>IndexError</code> will be raised in the iterator.
- *
+ *
* a = [ "a", "b" ]
* c = [ "c", "d" ]
* h = { a => 100, c => 300 }
@@ -431,15 +408,15 @@ rb_hash_rehash(hash)
/*
* call-seq:
* hsh[key] => value
- *
+ *
* Element Reference---Retrieves the <i>value</i> object corresponding
* to the <i>key</i> object. If not found, returns the a default value (see
* <code>Hash::new</code> for details).
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h["a"] #=> 100
* h["c"] #=> nil
- *
+ *
*/
VALUE
@@ -454,45 +431,33 @@ rb_hash_aref(hash, key)
return val;
}
-VALUE
-rb_hash_lookup(hash, key)
- VALUE hash, key;
-{
- VALUE val;
-
- if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
- return Qnil; /* without Hash#default */
- }
- return val;
-}
-
/*
* call-seq:
* hsh.fetch(key [, default] ) => obj
* hsh.fetch(key) {| key | block } => obj
- *
+ *
* Returns a value from the hash for the given key. If the key can't be
* found, there are several options: With no other arguments, it will
* raise an <code>IndexError</code> exception; if <i>default</i> is
* given, then that will be returned; if the optional code block is
* specified, then that will be run and its result returned.
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h.fetch("a") #=> 100
* h.fetch("z", "go fish") #=> "go fish"
* h.fetch("z") { |el| "go fish, #{el}"} #=> "go fish, z"
- *
+ *
* The following example shows that an exception is raised if the key
* is not found and a default value is not supplied.
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h.fetch("z")
- *
+ *
* <em>produces:</em>
- *
+ *
* prog.rb:2:in `fetch': key not found (IndexError)
* from prog.rb:2
- *
+ *
*/
static VALUE
@@ -524,21 +489,21 @@ rb_hash_fetch(argc, argv, hash)
/*
* call-seq:
* hsh.default(key=nil) => obj
- *
+ *
* Returns the default value, the value that would be returned by
* <i>hsh</i>[<i>key</i>] if <i>key</i> did not exist in <i>hsh</i>.
* See also <code>Hash::new</code> and <code>Hash#default=</code>.
- *
+ *
* h = Hash.new #=> {}
* h.default #=> nil
* h.default(2) #=> nil
- *
+ *
* h = Hash.new("cat") #=> {}
* h.default #=> "cat"
* h.default(2) #=> "cat"
- *
+ *
* h = Hash.new {|h,k| h[k] = k.to_i*10} #=> {}
- * h.default #=> nil
+ * h.default #=> 0
* h.default(2) #=> 20
*/
@@ -561,11 +526,11 @@ rb_hash_default(argc, argv, hash)
/*
* call-seq:
* hsh.default = obj => hsh
- *
+ *
* Sets the default value, the value returned for a key that does not
* exist in the hash. It is not possible to set the a default to a
* <code>Proc</code> that will be executed on each key lookup.
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h.default = "Go fish"
* h["a"] #=> 100
@@ -591,10 +556,10 @@ rb_hash_set_default(hash, ifnone)
/*
* call-seq:
* hsh.default_proc -> anObject
- *
+ *
* If <code>Hash::new</code> was invoked with a block, return that
* block, otherwise return <code>nil</code>.
- *
+ *
* h = Hash.new {|h,k| h[k] = k*k } #=> {}
* p = h.default_proc #=> #<Proc:0x401b3d08@-:1>
* a = [] #=> []
@@ -645,13 +610,13 @@ rb_hash_delete_key(hash, key)
/*
* call-seq:
* hsh.index(value) => key
- *
+ *
* Returns the key for a given value. If not found, returns <code>nil</code>.
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h.index(200) #=> "b"
* h.index(999) #=> nil
- *
+ *
*/
static VALUE
@@ -672,9 +637,9 @@ rb_hash_index(hash, value)
* call-seq:
* hsh.indexes(key, ...) => array
* hsh.indices(key, ...) => array
- *
+ *
* Deprecated in favor of <code>Hash#select</code>.
- *
+ *
*/
static VALUE
@@ -700,17 +665,18 @@ rb_hash_indexes(argc, argv, hash)
* call-seq:
* hsh.delete(key) => value
* hsh.delete(key) {| key | block } => value
- *
+ *
* Deletes and returns a key-value pair from <i>hsh</i> whose key is
- * equal to <i>key</i>. If the key is not found, returns <code>nil</code>.
- * If the optional code block is given and the key is not found,
- * pass in the key and return the result of <i>block</i>.
- *
+ * equal to <i>key</i>. If the key is not found, returns the
+ * <em>default value</em>. If the optional code block is given and the
+ * key is not found, pass in the key and return the result of
+ * <i>block</i>.
+ *
* h = { "a" => 100, "b" => 200 }
* h.delete("a") #=> 100
* h.delete("z") #=> nil
* h.delete("z") { |el| "#{el} not found" } #=> "z not found"
- *
+ *
*/
VALUE
@@ -759,11 +725,11 @@ shift_i_safe(key, value, var)
/*
* call-seq:
* hsh.shift -> anArray or obj
- *
+ *
* Removes a key-value pair from <i>hsh</i> and returns it as the
* two-item array <code>[</code> <i>key, value</i> <code>]</code>, or
* the hash's default value if the hash is empty.
- *
+ *
* h = { 1 => "a", 2 => "b", 3 => "c" }
* h.shift #=> [1, "a"]
* h #=> {2=>"b", 3=>"c"}
@@ -815,20 +781,19 @@ delete_if_i(key, value, hash)
/*
* call-seq:
* hsh.delete_if {| key, value | block } -> hsh
- *
+ *
* Deletes every key-value pair from <i>hsh</i> for which <i>block</i>
* evaluates to <code>true</code>.
- *
+ *
* h = { "a" => 100, "b" => 200, "c" => 300 }
* h.delete_if {|key, value| key >= "b" } #=> {"a"=>100}
- *
+ *
*/
VALUE
rb_hash_delete_if(hash)
VALUE hash;
{
- RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_modify(hash);
rb_hash_foreach(hash, delete_if_i, hash);
return hash;
@@ -837,7 +802,7 @@ rb_hash_delete_if(hash)
/*
* call-seq:
* hsh.reject! {| key, value | block } -> hsh or nil
- *
+ *
* Equivalent to <code>Hash#delete_if</code>, but returns
* <code>nil</code> if no changes were made.
*/
@@ -846,10 +811,7 @@ VALUE
rb_hash_reject_bang(hash)
VALUE hash;
{
- int n;
-
- RETURN_ENUMERATOR(hash, 0, 0);
- n = RHASH(hash)->tbl->num_entries;
+ int n = RHASH(hash)->tbl->num_entries;
rb_hash_delete_if(hash);
if (n == RHASH(hash)->tbl->num_entries) return Qnil;
return hash;
@@ -858,11 +820,11 @@ rb_hash_reject_bang(hash)
/*
* call-seq:
* hsh.reject {| key, value | block } -> a_hash
- *
+ *
* Same as <code>Hash#delete_if</code>, but works on (and returns) a
* copy of the <i>hsh</i>. Equivalent to
* <code><i>hsh</i>.dup.delete_if</code>.
- *
+ *
*/
static VALUE
@@ -891,7 +853,7 @@ select_i(key, value, result)
*
* h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
* h.values_at("cow", "cat") #=> ["bovine", "feline"]
- */
+*/
VALUE
rb_hash_values_at(argc, argv, hash)
@@ -911,23 +873,27 @@ rb_hash_values_at(argc, argv, hash)
/*
* call-seq:
* hsh.select {|key, value| block} => array
- *
+ *
* Returns a new array consisting of <code>[key,value]</code>
* pairs for which the block returns true.
* Also see <code>Hash.values_at</code>.
- *
+ *
* h = { "a" => 100, "b" => 200, "c" => 300 }
* h.select {|k,v| k > "a"} #=> [["b", 200], ["c", 300]]
* h.select {|k,v| v < 200} #=> [["a", 100]]
*/
VALUE
-rb_hash_select(hash)
+rb_hash_select(argc, argv, hash)
+ int argc;
+ VALUE *argv;
VALUE hash;
{
VALUE result;
- RETURN_ENUMERATOR(hash, 0, 0);
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
+ }
result = rb_ary_new();
rb_hash_foreach(hash, select_i, result);
return result;
@@ -943,12 +909,12 @@ clear_i(key, value, dummy)
/*
* call-seq:
* hsh.clear -> hsh
- *
+ *
* Removes all key-value pairs from <i>hsh</i>.
- *
+ *
* h = { "a" => 100, "b" => 200 } #=> {"a"=>100, "b"=>200}
* h.clear #=> {}
- *
+ *
*/
static VALUE
@@ -967,18 +933,18 @@ rb_hash_clear(hash)
* call-seq:
* hsh[key] = value => value
* hsh.store(key, value) => value
- *
+ *
* Element Assignment---Associates the value given by
* <i>value</i> with the key given by <i>key</i>.
* <i>key</i> should not have its value changed while it is in
* use as a key (a <code>String</code> passed as a key will be
* duplicated and frozen).
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h["a"] = 9
* h["c"] = 4
* h #=> {"a"=>9, "b"=>200, "c"=>4}
- *
+ *
*/
VALUE
@@ -1009,13 +975,13 @@ replace_i(key, val, hash)
/*
* call-seq:
* hsh.replace(other_hash) -> hsh
- *
+ *
* Replaces the contents of <i>hsh</i> with the contents of
* <i>other_hash</i>.
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h.replace({ "c" => 300, "d" => 400 }) #=> {"c"=>300, "d"=>400}
- *
+ *
*/
static VALUE
@@ -1041,9 +1007,9 @@ rb_hash_replace(hash, hash2)
* call-seq:
* hsh.length => fixnum
* hsh.size => fixnum
- *
+ *
* Returns the number of key-value pairs in the hash.
- *
+ *
* h = { "d" => 100, "a" => 200, "v" => 300, "e" => 400 }
* h.length #=> 4
* h.delete("a") #=> 200
@@ -1061,11 +1027,11 @@ rb_hash_size(hash)
/*
* call-seq:
* hsh.empty? => true or false
- *
+ *
* Returns <code>true</code> if <i>hsh</i> contains no key-value pairs.
- *
+ *
* {}.empty? #=> true
- *
+ *
*/
static VALUE
@@ -1089,15 +1055,15 @@ each_value_i(key, value)
/*
* call-seq:
* hsh.each_value {| value | block } -> hsh
- *
+ *
* Calls <i>block</i> once for each key in <i>hsh</i>, passing the
* value as a parameter.
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h.each_value {|value| puts value }
- *
+ *
* <em>produces:</em>
- *
+ *
* 100
* 200
*/
@@ -1106,7 +1072,6 @@ static VALUE
rb_hash_each_value(hash)
VALUE hash;
{
- RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_foreach(hash, each_value_i, 0);
return hash;
}
@@ -1123,15 +1088,15 @@ each_key_i(key, value)
/*
* call-seq:
* hsh.each_key {| key | block } -> hsh
- *
+ *
* Calls <i>block</i> once for each key in <i>hsh</i>, passing the key
* as a parameter.
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h.each_key {|key| puts key }
- *
+ *
* <em>produces:</em>
- *
+ *
* a
* b
*/
@@ -1139,7 +1104,6 @@ static VALUE
rb_hash_each_key(hash)
VALUE hash;
{
- RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_foreach(hash, each_key_i, 0);
return hash;
}
@@ -1156,25 +1120,24 @@ each_pair_i(key, value)
/*
* call-seq:
* hsh.each_pair {| key_value_array | block } -> hsh
- *
+ *
* Calls <i>block</i> once for each key in <i>hsh</i>, passing the key
* and value as parameters.
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h.each_pair {|key, value| puts "#{key} is #{value}" }
- *
+ *
* <em>produces:</em>
- *
+ *
* a is 100
* b is 200
- *
+ *
*/
static VALUE
rb_hash_each_pair(hash)
VALUE hash;
{
- RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_foreach(hash, each_pair_i, 0);
return hash;
}
@@ -1191,28 +1154,27 @@ each_i(key, value)
/*
* call-seq:
* hsh.each {| key, value | block } -> hsh
- *
+ *
* Calls <i>block</i> once for each key in <i>hsh</i>, passing the key
* and value to the block as a two-element array. Because of the assignment
* semantics of block parameters, these elements will be split out if the
* block has two formal parameters. Also see <code>Hash.each_pair</code>, which
* will be marginally more efficient for blocks with two parameters.
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h.each {|key, value| puts "#{key} is #{value}" }
- *
+ *
* <em>produces:</em>
- *
+ *
* a is 100
* b is 200
- *
+ *
*/
static VALUE
rb_hash_each(hash)
VALUE hash;
{
- RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_foreach(hash, each_i, 0);
return hash;
}
@@ -1229,10 +1191,10 @@ to_a_i(key, value, ary)
/*
* call-seq:
* hsh.to_a -> array
- *
+ *
* Converts <i>hsh</i> to a nested array of <code>[</code> <i>key,
* value</i> <code>]</code> arrays.
- *
+ *
* h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
* h.to_a #=> [["a", 100], ["c", 300], ["d", 400]]
*/
@@ -1252,17 +1214,17 @@ rb_hash_to_a(hash)
/*
* call-seq:
- * hsh.sort => array
- * hsh.sort {| a, b | block } => array
- *
+ * hsh.sort => array
+ * hsh.sort {| a, b | block } => array
+ *
* Converts <i>hsh</i> to a nested array of <code>[</code> <i>key,
* value</i> <code>]</code> arrays and sorts it, using
* <code>Array#sort</code>.
- *
+ *
* h = { "a" => 20, "b" => 30, "c" => 10 }
* h.sort #=> [["a", 20], ["b", 30], ["c", 10]]
* h.sort {|a,b| a[1]<=>b[1]} #=> [["c", 10], ["a", 20], ["b", 30]]
- *
+ *
*/
static VALUE
@@ -1336,12 +1298,12 @@ to_s_hash(hash)
/*
* call-seq:
* hsh.to_s => string
- *
+ *
* Converts <i>hsh</i> to a string by converting the hash to an array
* of <code>[</code> <i>key, value</i> <code>]</code> pairs and then
* converting that array to a string using <code>Array#join</code> with
* the default separator.
- *
+ *
* h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
* h.to_s #=> "a100c300d400"
*/
@@ -1380,13 +1342,13 @@ keys_i(key, value, ary)
/*
* call-seq:
* hsh.keys => array
- *
+ *
* Returns a new array populated with the keys from this hash. See also
* <code>Hash#values</code>.
- *
+ *
* h = { "a" => 100, "b" => 200, "c" => 300, "d" => 400 }
* h.keys #=> ["a", "b", "c", "d"]
- *
+ *
*/
static VALUE
@@ -1413,13 +1375,13 @@ values_i(key, value, ary)
/*
* call-seq:
* hsh.values => array
- *
+ *
* Returns a new array populated with the values from <i>hsh</i>. See
* also <code>Hash#keys</code>.
- *
+ *
* h = { "a" => 100, "b" => 200, "c" => 300 }
* h.values #=> [100, 200, 300]
- *
+ *
*/
static VALUE
@@ -1440,13 +1402,13 @@ rb_hash_values(hash)
* hsh.include?(key) => true or false
* hsh.key?(key) => true or false
* hsh.member?(key) => true or false
- *
+ *
* Returns <code>true</code> if the given key is present in <i>hsh</i>.
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h.has_key?("a") #=> true
* h.has_key?("z") #=> false
- *
+ *
*/
static VALUE
@@ -1476,10 +1438,10 @@ rb_hash_search_value(key, value, data)
* call-seq:
* hsh.has_value?(value) => true or false
* hsh.value?(value) => true or false
- *
+ *
* Returns <code>true</code> if the given value is present for some key
* in <i>hsh</i>.
- *
+ *
* h = { "a" => 100, "b" => 200 }
* h.has_value?(100) #=> true
* h.has_value?(999) #=> false
@@ -1501,13 +1463,11 @@ rb_hash_has_value(hash, val)
struct equal_data {
int result;
st_table *tbl;
- int eql;
};
static int
-eql_i(key, val1, data)
- VALUE key;
- VALUE val1;
+equal_i(key, val1, data)
+ VALUE key, val1;
struct equal_data *data;
{
VALUE val2;
@@ -1517,30 +1477,13 @@ eql_i(key, val1, data)
data->result = Qfalse;
return ST_STOP;
}
- if (!(data->eql ? rb_eql(val1, val2) : rb_equal(val1, val2))) {
+ if (!rb_equal(val1, val2)) {
data->result = Qfalse;
return ST_STOP;
}
return ST_CONTINUE;
}
-static VALUE recursive_eql _((VALUE, VALUE, int));
-static VALUE
-recursive_eql(hash, dt, recur)
- VALUE hash;
- VALUE dt;
- int recur;
-{
- struct equal_data *data;
-
- if (recur) return Qfalse;
- data = (struct equal_data*)dt;
- data->result = Qtrue;
- rb_hash_foreach(hash, eql_i, (st_data_t)data);
-
- return data->result;
-}
-
static VALUE
hash_equal(hash1, hash2, eql)
VALUE hash1, hash2;
@@ -1564,19 +1507,21 @@ hash_equal(hash1, hash2, eql)
}
data.tbl = RHASH(hash2)->tbl;
- data.eql = eql;
- return rb_exec_recursive(recursive_eql, hash1, (VALUE)&data);
+ data.result = Qtrue;
+ rb_hash_foreach(hash1, equal_i, (st_data_t)&data);
+
+ return data.result;
}
/*
* call-seq:
* hsh == other_hash => true or false
- *
+ *
* Equality---Two hashes are equal if they each contain the same number
* of keys and if each key-value pair is equal to (according to
* <code>Object#==</code>) the corresponding elements in the other
* hash.
- *
+ *
* h1 = { "a" => 1, "c" => 2 }
* h2 = { 7 => 35, "c" => 2, "a" => 1 }
* h3 = { "a" => 1, "c" => 2, 7 => 35 }
@@ -1584,7 +1529,7 @@ hash_equal(hash1, hash2, eql)
* h1 == h2 #=> false
* h2 == h3 #=> true
* h3 == h4 #=> false
- *
+ *
*/
static VALUE
@@ -1595,66 +1540,6 @@ rb_hash_equal(hash1, hash2)
}
static int
-hash_i(key, val, hval)
- VALUE key;
- VALUE val;
- int *hval;
-{
- if (key == Qundef) return ST_CONTINUE;
- *hval ^= rb_hash(key);
- *hval ^= rb_hash(val);
- return ST_CONTINUE;
-}
-
-static VALUE recursive_hash _((VALUE, VALUE, int));
-static VALUE
-recursive_hash(hash, dummy, recur)
- VALUE hash;
- VALUE dummy;
- int recur;
-{
- int hval;
-
- if (recur) {
- return LONG2FIX(0);
- }
- hval = RHASH(hash)->tbl->num_entries;
- rb_hash_foreach(hash, hash_i, (st_data_t)&hval);
- return INT2FIX(hval);
-}
-
-/*
- * call-seq:
- * array.hash -> fixnum
- *
- * Compute a hash-code for this array. Two arrays with the same content
- * will have the same hash code (and will compare using <code>eql?</code>).
- */
-
-static VALUE
-rb_hash_hash(hash)
- VALUE hash;
-{
- return rb_exec_recursive(recursive_hash, hash, 0);
-}
-
-
-/*
- * call-seq:
- * hash.eql?(other) -> true or false
- *
- * Returns <code>true</code> if <i>hash</i> and <i>other</i> are
- * both hashes with the same content.
- */
-
-static VALUE
-rb_hash_eql(hash1, hash2)
- VALUE hash1, hash2;
-{
- return hash_equal(hash1, hash2, Qtrue);
-}
-
-static int
rb_hash_invert_i(key, value, hash)
VALUE key, value;
VALUE hash;
@@ -1667,13 +1552,13 @@ rb_hash_invert_i(key, value, hash)
/*
* call-seq:
* hsh.invert -> aHash
- *
+ *
* Returns a new hash created by using <i>hsh</i>'s values as keys, and
* the keys as values.
- *
+ *
* h = { "n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0 }
* h.invert #=> {0=>"a", 100=>"n", 200=>"d", 300=>"y"}
- *
+ *
*/
static VALUE
@@ -1715,21 +1600,13 @@ rb_hash_update_block_i(key, value, hash)
* hsh.update(other_hash) => hsh
* hsh.merge!(other_hash){|key, oldval, newval| block} => hsh
* hsh.update(other_hash){|key, oldval, newval| block} => hsh
- *
- * Adds the contents of <i>other_hash</i> to <i>hsh</i>. If no
- * block is specified entries with duplicate keys are overwritten
- * with the values from <i>other_hash</i>, otherwise the value
- * of each duplicate key is determined by calling the block with
- * the key, its value in <i>hsh</i> and its value in <i>other_hash</i>.
- *
+ *
+ * Adds the contents of <i>other_hash</i> to <i>hsh</i>, overwriting
+ * entries with duplicate keys with those from <i>other_hash</i>.
+ *
* h1 = { "a" => 100, "b" => 200 }
* h2 = { "b" => 254, "c" => 300 }
* h1.merge!(h2) #=> {"a"=>100, "b"=>254, "c"=>300}
- *
- * h1 = { "a" => 100, "b" => 200 }
- * h2 = { "b" => 254, "c" => 300 }
- * h1.merge!(h2) { |key, v1, v2| v1 }
- * #=> {"a"=>100, "b"=>200, "c"=>300}
*/
static VALUE
@@ -1750,16 +1627,16 @@ rb_hash_update(hash1, hash2)
* call-seq:
* hsh.merge(other_hash) -> a_hash
* hsh.merge(other_hash){|key, oldval, newval| block} -> a_hash
- *
+ *
* Returns a new hash containing the contents of <i>other_hash</i> and
* the contents of <i>hsh</i>, overwriting entries in <i>hsh</i> with
* duplicate keys with those from <i>other_hash</i>.
- *
+ *
* h1 = { "a" => 100, "b" => 200 }
* h2 = { "b" => 254, "c" => 300 }
* h1.merge(h2) #=> {"a"=>100, "b"=>254, "c"=>300}
* h1 #=> {"a"=>100, "b"=>200}
- *
+ *
*/
static VALUE
@@ -1855,8 +1732,7 @@ rb_f_getenv(obj, name)
{
char *nam, *env;
- rb_secure(4);
- SafeStringValue(name);
+ StringValue(name);
nam = RSTRING(name)->ptr;
if (strlen(nam) != RSTRING(name)->len) {
rb_raise(rb_eArgError, "bad environment variable name");
@@ -1888,13 +1764,12 @@ env_fetch(argc, argv)
long block_given;
char *nam, *env;
- rb_secure(4);
rb_scan_args(argc, argv, "11", &key, &if_none);
block_given = rb_block_given_p();
if (block_given && argc == 2) {
rb_warn("block supersedes default value argument");
}
- SafeStringValue(key);
+ StringValue(key);
nam = RSTRING(key)->ptr;
if (strlen(nam) != RSTRING(key)->len) {
rb_raise(rb_eArgError, "bad environment variable name");
@@ -1932,7 +1807,6 @@ rb_env_path_tainted()
return path_tainted;
}
-#if !defined(_WIN32) && !(defined(HAVE_SETENV) && defined(HAVE_UNSETENV))
static int
envix(nam)
const char *nam;
@@ -1954,7 +1828,6 @@ envix(nam)
FREE_ENVIRON(environ);
return i;
}
-#endif
void
ruby_setenv(name, value)
@@ -2091,10 +1964,8 @@ static VALUE
env_keys()
{
char **env;
- VALUE ary;
+ VALUE ary = rb_ary_new();
- rb_secure(4);
- ary = rb_ary_new();
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -2111,11 +1982,9 @@ static VALUE
env_each_key(ehash)
VALUE ehash;
{
- VALUE keys;
+ VALUE keys = env_keys();
long i;
- RETURN_ENUMERATOR(ehash, 0, 0);
- keys = env_keys(); /* rb_secure(4); */
for (i=0; i<RARRAY(keys)->len; i++) {
rb_yield(RARRAY(keys)->ptr[i]);
}
@@ -2125,11 +1994,9 @@ env_each_key(ehash)
static VALUE
env_values()
{
- VALUE ary;
char **env;
+ VALUE ary = rb_ary_new();
- rb_secure(4);
- ary = rb_ary_new();
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -2146,11 +2013,9 @@ static VALUE
env_each_value(ehash)
VALUE ehash;
{
- VALUE values;
+ VALUE values = env_values();
long i;
- RETURN_ENUMERATOR(ehash, 0, 0);
- values = env_values(); /* rb_secure(4); */
for (i=0; i<RARRAY(values)->len; i++) {
rb_yield(RARRAY(values)->ptr[i]);
}
@@ -2163,11 +2028,9 @@ env_each_i(ehash, values)
int values;
{
char **env;
- VALUE ary;
+ VALUE ary = rb_ary_new();
long i;
- rb_secure(4);
- ary = rb_ary_new();
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -2194,7 +2057,6 @@ static VALUE
env_each(ehash)
VALUE ehash;
{
- RETURN_ENUMERATOR(ehash, 0, 0);
return env_each_i(ehash, Qfalse);
}
@@ -2202,20 +2064,19 @@ static VALUE
env_each_pair(ehash)
VALUE ehash;
{
- RETURN_ENUMERATOR(ehash, 0, 0);
return env_each_i(ehash, Qtrue);
}
static VALUE
-env_reject_bang(ehash)
- VALUE ehash;
+env_reject_bang()
{
volatile VALUE keys;
long i;
int del = 0;
- RETURN_ENUMERATOR(ehash, 0, 0);
- keys = env_keys(); /* rb_secure(4); */
+ rb_secure(4);
+ keys = env_keys();
+
for (i=0; i<RARRAY(keys)->len; i++) {
VALUE val = rb_f_getenv(Qnil, RARRAY(keys)->ptr[i]);
if (!NIL_P(val)) {
@@ -2231,11 +2092,9 @@ env_reject_bang(ehash)
}
static VALUE
-env_delete_if(ehash)
- VALUE ehash;
+env_delete_if()
{
- RETURN_ENUMERATOR(ehash, 0, 0);
- env_reject_bang(ehash);
+ env_reject_bang();
return envtbl;
}
@@ -2244,11 +2103,9 @@ env_values_at(argc, argv)
int argc;
VALUE *argv;
{
- VALUE result;
+ VALUE result = rb_ary_new();
long i;
- rb_secure(4);
- result = rb_ary_new();
for (i=0; i<argc; i++) {
rb_ary_push(result, rb_f_getenv(Qnil, argv[i]));
}
@@ -2256,14 +2113,16 @@ env_values_at(argc, argv)
}
static VALUE
-env_select(ehash)
- VALUE ehash;
+env_select(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE result;
char **env;
- RETURN_ENUMERATOR(ehash, 0, 0);
- rb_secure(4);
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
+ }
result = rb_ary_new();
env = GET_ENVIRON(environ);
while (*env) {
@@ -2287,8 +2146,10 @@ env_clear()
{
volatile VALUE keys;
long i;
+
+ rb_secure(4);
+ keys = env_keys();
- keys = env_keys(); /* rb_secure(4); */
for (i=0; i<RARRAY(keys)->len; i++) {
VALUE val = rb_f_getenv(Qnil, RARRAY(keys)->ptr[i]);
if (!NIL_P(val)) {
@@ -2308,10 +2169,9 @@ static VALUE
env_inspect()
{
char **env;
- VALUE str, i;
+ VALUE str = rb_str_buf_new2("{");
+ VALUE i;
- rb_secure(4);
- str = rb_str_buf_new2("{");
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -2339,10 +2199,8 @@ static VALUE
env_to_a()
{
char **env;
- VALUE ary;
+ VALUE ary = rb_ary_new();
- rb_secure(4);
- ary = rb_ary_new();
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -2368,7 +2226,6 @@ env_size()
int i;
char **env;
- rb_secure(4);
env = GET_ENVIRON(environ);
for(i=0; env[i]; i++)
;
@@ -2381,7 +2238,6 @@ env_empty_p()
{
char **env;
- rb_secure(4);
env = GET_ENVIRON(environ);
if (env[0] == 0) {
FREE_ENVIRON(environ);
@@ -2397,7 +2253,6 @@ env_has_key(env, key)
{
char *s;
- rb_secure(4);
s = StringValuePtr(key);
if (strlen(s) != RSTRING(key)->len)
rb_raise(rb_eArgError, "bad environment variable name");
@@ -2411,9 +2266,7 @@ env_has_value(dmy, value)
{
char **env;
- rb_secure(4);
- value = rb_check_string_type(value);
- if (NIL_P(value)) return Qfalse;
+ if (TYPE(value) != T_STRING) return Qfalse;
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -2437,7 +2290,6 @@ env_index(dmy, value)
char **env;
VALUE str;
- rb_secure(4);
StringValue(value);
env = GET_ENVIRON(environ);
while (*env) {
@@ -2466,7 +2318,6 @@ env_indexes(argc, argv)
rb_warn("ENV.%s is deprecated; use ENV.values_at",
rb_id2name(rb_frame_last_func()));
- rb_secure(4);
for (i=0;i<argc;i++) {
VALUE tmp = rb_check_string_type(argv[i]);
if (NIL_P(tmp)) {
@@ -2485,10 +2336,8 @@ static VALUE
env_to_hash()
{
char **env;
- VALUE hash;
+ VALUE hash = rb_hash_new();
- rb_secure(4);
- hash = rb_hash_new();
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -2513,7 +2362,6 @@ env_shift()
{
char **env;
- rb_secure(4);
env = GET_ENVIRON(environ);
if (*env) {
char *s = strchr(*env, '=');
@@ -2551,10 +2399,9 @@ static VALUE
env_replace(env, hash)
VALUE env, hash;
{
- volatile VALUE keys;
+ volatile VALUE keys = env_keys();
long i;
- keys = env_keys(); /* rb_secure(4); */
if (env == hash) return env;
hash = to_hash(hash);
rb_hash_foreach(hash, env_replace_i, keys);
@@ -2582,7 +2429,6 @@ static VALUE
env_update(env, hash)
VALUE env, hash;
{
- rb_secure(4);
if (env == hash) return env;
hash = to_hash(hash);
rb_hash_foreach(hash, env_update_i, 0);
@@ -2595,15 +2441,15 @@ env_update(env, hash)
* arbitrary keys of any object type, not an integer index. The order
* in which you traverse a hash by either key or value may seem
* arbitrary, and will generally not be in the insertion order.
- *
+ *
* Hashes have a <em>default value</em> that is returned when accessing
* keys that do not exist in the hash. By default, that value is
* <code>nil</code>.
- *
+ *
* <code>Hash</code> uses <code>key.eql?</code> to test keys for equality.
* If you need to use instances of your own classes as keys in a <code>Hash</code>,
* it is recommended that you define both the <code>eql?</code> and <code>hash</code>
- * methods. The <code>hash</code> method must have the property that
+ * methods. The <code>hash</code> method must have the property that
* <code>a.eql?(b)</code> implies <code>a.hash == b.hash</code>.
*
* class MyClass
@@ -2618,17 +2464,17 @@ env_update(env, hash)
* @str.hash
* end
* end
- *
+ *
* a = MyClass.new("some string")
* b = MyClass.new("some string")
* a.eql? b #=> true
- *
+ *
* h = {}
- *
+ *
* h[a] = 1
* h[a] #=> 1
* h[b] #=> 1
- *
+ *
* h[b] = 2
* h[a] #=> 2
* h[b] #=> 2
@@ -2658,8 +2504,6 @@ Init_Hash()
rb_define_method(rb_cHash,"==", rb_hash_equal, 1);
rb_define_method(rb_cHash,"[]", rb_hash_aref, 1);
- rb_define_method(rb_cHash,"hash", rb_hash_hash, 0);
- rb_define_method(rb_cHash,"eql?", rb_hash_eql, 1);
rb_define_method(rb_cHash,"fetch", rb_hash_fetch, -1);
rb_define_method(rb_cHash,"[]=", rb_hash_aset, 2);
rb_define_method(rb_cHash,"store", rb_hash_aset, 2);
@@ -2686,7 +2530,7 @@ Init_Hash()
rb_define_method(rb_cHash,"shift", rb_hash_shift, 0);
rb_define_method(rb_cHash,"delete", rb_hash_delete, 1);
rb_define_method(rb_cHash,"delete_if", rb_hash_delete_if, 0);
- rb_define_method(rb_cHash,"select", rb_hash_select, 0);
+ rb_define_method(rb_cHash,"select", rb_hash_select, -1);
rb_define_method(rb_cHash,"reject", rb_hash_reject, 0);
rb_define_method(rb_cHash,"reject!", rb_hash_reject_bang, 0);
rb_define_method(rb_cHash,"clear", rb_hash_clear, 0);
@@ -2721,7 +2565,7 @@ Init_Hash()
rb_define_singleton_method(envtbl,"clear", env_clear, 0);
rb_define_singleton_method(envtbl,"reject", env_reject, 0);
rb_define_singleton_method(envtbl,"reject!", env_reject_bang, 0);
- rb_define_singleton_method(envtbl,"select", env_select, 0);
+ rb_define_singleton_method(envtbl,"select", env_select, -1);
rb_define_singleton_method(envtbl,"shift", env_shift, 0);
rb_define_singleton_method(envtbl,"invert", env_invert, 0);
rb_define_singleton_method(envtbl,"replace", env_replace, 1);
diff --git a/inits.c b/inits.c
index 947bbbe242..052573a443 100644
--- a/inits.c
+++ b/inits.c
@@ -18,7 +18,6 @@ void Init_Binding _((void));
void Init_Comparable _((void));
void Init_Dir _((void));
void Init_Enumerable _((void));
-void Init_Enumerator _((void));
void Init_Exception _((void));
void Init_syserr _((void));
void Init_eval _((void));
@@ -80,7 +79,6 @@ rb_call_inits()
Init_Binding();
Init_Math();
Init_GC();
- Init_Enumerator();
Init_marshal();
Init_version();
}
diff --git a/instruby.rb b/instruby.rb
index 2903a7c739..a5606e8452 100755
--- a/instruby.rb
+++ b/instruby.rb
@@ -14,7 +14,7 @@ require 'tempfile'
STDOUT.sync = true
File.umask(0)
-def parse_args(argv = ARGV)
+def parse_args()
$mantype = 'doc'
$destdir = nil
$extout = nil
@@ -24,12 +24,6 @@ def parse_args(argv = ARGV)
$installed_list = nil
$dryrun = false
$rdocdir = nil
- $data_mode = 0644
- $prog_mode = 0755
- $dir_mode = nil
- $script_mode = nil
- $cmdtype = ('bat' if File::ALT_SEPARATOR == '\\')
- mflags = []
opt = OptionParser.new
opt.on('-n') {$dryrun = true}
opt.on('--dest-dir=DIR') {|dir| $destdir = dir}
@@ -43,48 +37,23 @@ def parse_args(argv = ARGV)
$mflags.concat(v)
end
opt.on('-i', '--install=TYPE',
- [:local, :bin, :"bin-arch", :"bin-comm", :lib, :man, :ext, :"ext-arch", :"ext-comm", :rdoc]) do |ins|
+ [:local, :bin, :lib, :man, :ext, :"ext-arch", :"ext-comm", :rdoc]) do |ins|
$install << ins
end
- opt.on('--data-mode=OCTAL-MODE', OptionParser::OctalInteger) do |mode|
- $data_mode = mode
- end
- opt.on('--prog-mode=OCTAL-MODE', OptionParser::OctalInteger) do |mode|
- $prog_mode = mode
- end
- opt.on('--dir-mode=OCTAL-MODE', OptionParser::OctalInteger) do |mode|
- $dir_mode = mode
- end
- opt.on('--script-mode=OCTAL-MODE', OptionParser::OctalInteger) do |mode|
- $script_mode = mode
- end
opt.on('--installed-list [FILENAME]') {|name| $installed_list = name}
opt.on('--rdoc-output [DIR]') {|dir| $rdocdir = dir}
- opt.on('--cmd-type=TYPE', %w[bat cmd plain]) {|cmd| $cmdtype = (cmd unless cmd == 'plain')}
-
- opt.order!(argv) do |v|
- case v
- when /\AINSTALL[-_]([-\w]+)=(.*)/
- argv.unshift("--#{$1.tr('_', '-')}=#{$2}")
- when /\A\w[-\w+]*=\z/
- mflags << v
- when /\A\w[-\w+]*\z/
- $install << v.intern
- else
- raise OptionParser::InvalidArgument, v
- end
- end rescue abort [$!.message, opt].join("\n")
+
+ opt.parse! rescue abort [$!.message, opt].join("\n")
$make, *rest = Shellwords.shellwords($make)
$mflags.unshift(*rest) unless rest.empty?
- $mflags.unshift(*mflags)
def $mflags.set?(flag)
- grep(/\A-(?!-).*#{flag.chr}/i) { return true }
+ grep(/\A-(?!-).*#{'%c' % flag}/i) { return true }
false
end
def $mflags.defined?(var)
- grep(/\A#{var}=(.*)/) {return block_given? ? yield($1) : $1}
+ grep(/\A#{var}=(.*)/) {return $1}
false
end
@@ -108,9 +77,6 @@ def parse_args(argv = ARGV)
end
$rdocdir ||= $mflags.defined?('RDOCOUT')
-
- $dir_mode ||= $prog_mode | 0700
- $script_mode ||= $prog_mode
end
parse_args()
@@ -153,46 +119,29 @@ def makedirs(dirs)
File.directory?(realdir)
end
end.compact!
- super(dirs, :mode => $dir_mode) unless dirs.empty?
+ super(dirs, :mode => 0755) unless dirs.empty?
end
-def install_recursive(srcdir, dest, options = {})
- opts = options.clone
- noinst = opts.delete(:no_install)
- glob = opts.delete(:glob) || "*"
- subpath = srcdir.size..-1
- Dir.glob("#{srcdir}/**/#{glob}") do |src|
- case base = File.basename(src)
- when /\A\#.*\#\z/, /~\z/
- next
- end
- if noinst
- if Array === noinst
- next if noinst.any? {|n| File.fnmatch?(n, base)}
- else
- next if File.fnmatch?(noinst, base)
- end
- end
+def install_recursive(src, dest, options = {})
+ noinst = options.delete(:no_install)
+ subpath = src.size..-1
+ Dir.glob("#{src}/**/*", File::FNM_DOTMATCH) do |src|
+ next if /\A\.{1,2}\z/ =~ (base = File.basename(src))
+ next if noinst and File.fnmatch?(noinst, File.basename(src))
d = dest + src[subpath]
if File.directory?(src)
makedirs(d)
else
- makedirs(File.dirname(d))
- install src, d, opts
+ install src, d
end
end
end
-def open_for_install(path, mode)
- data = open(realpath = with_destdir(path), "rb") {|f| f.read} rescue nil
- newdata = yield
+def open_for_install(path, mode, &block)
unless $dryrun
- unless newdata == data
- open(realpath, "wb", mode) {|f| f.write newdata}
- end
- File.chmod(mode, realpath)
+ open(with_destdir(path), mode, &block)
end
- $installed_list.puts path if $installed_list
+ $installed_list.puts path if /^w/ =~ mode and $installed_list
end
def with_destdir(dir)
@@ -213,8 +162,6 @@ rubylibdir = CONFIG["rubylibdir"]
archlibdir = CONFIG["archdir"]
sitelibdir = CONFIG["sitelibdir"]
sitearchlibdir = CONFIG["sitearchdir"]
-vendorlibdir = CONFIG["vendorlibdir"]
-vendorarchlibdir = CONFIG["vendorarchdir"]
mandir = File.join(CONFIG["mandir"], "man")
configure_args = Shellwords.shellwords(CONFIG["configure_args"])
enable_shared = CONFIG["ENABLE_SHARED"] == 'yes'
@@ -222,25 +169,25 @@ dll = CONFIG["LIBRUBY_SO"]
lib = CONFIG["LIBRUBY"]
arc = CONFIG["LIBRUBY_A"]
-install?(:local, :arch, :bin, :'bin-arch') do
+install?(:local, :arch, :bin) do
puts "installing binary commands"
makedirs [bindir, libdir, archlibdir]
- install ruby_install_name+exeext, bindir, :mode => $prog_mode
+ install ruby_install_name+exeext, bindir, :mode => 0755
if rubyw_install_name and !rubyw_install_name.empty?
- install rubyw_install_name+exeext, bindir, :mode => $prog_mode
+ install rubyw_install_name+exeext, bindir, :mode => 0755
end
if enable_shared and dll != lib
- install dll, bindir, :mode => $prog_mode
+ install dll, bindir, :mode => 0755
end
- install lib, libdir, :mode => $prog_mode unless lib == arc
- install arc, libdir, :mode => $data_mode
- install "config.h", archlibdir, :mode => $data_mode
- install "rbconfig.rb", archlibdir, :mode => $data_mode
+ install lib, libdir, :mode => 0755 unless lib == arc
+ install arc, libdir, :mode => 0644
+ install "config.h", archlibdir, :mode => 0644
+ install "rbconfig.rb", archlibdir, :mode => 0644
if CONFIG["ARCHFILE"]
for file in CONFIG["ARCHFILE"].split
- install file, archlibdir, :mode => $data_mode
+ install file, archlibdir, :mode => 0644
end
end
@@ -255,16 +202,16 @@ if $extout
extout = "#$extout"
install?(:ext, :arch, :'ext-arch') do
puts "installing extension objects"
- makedirs [archlibdir, sitearchlibdir, vendorarchlibdir]
+ makedirs [archlibdir, sitearchlibdir]
if noinst = CONFIG["no_install_files"] and noinst.empty?
noinst = nil
end
- install_recursive("#{extout}/#{CONFIG['arch']}", archlibdir, :no_install => noinst, :mode => $prog_mode)
+ install_recursive("#{extout}/#{CONFIG['arch']}", archlibdir, :no_install => noinst)
end
install?(:ext, :comm, :'ext-comm') do
puts "installing extension scripts"
- makedirs [rubylibdir, sitelibdir, vendorlibdir]
- install_recursive("#{extout}/common", rubylibdir, :mode => $data_mode)
+ makedirs [rubylibdir, sitelibdir]
+ install_recursive("#{extout}/common", rubylibdir)
end
end
@@ -275,11 +222,11 @@ install?(:rdoc) do
ridatadir = File.join(CONFIG['datadir'], 'ri/$(MAJOR).$(MINOR)/system')
Config.expand(ridatadir)
makedirs [ridatadir]
- install_recursive($rdocdir, ridatadir, :mode => $data_mode)
+ install_recursive($rdocdir, ridatadir)
end
end
-install?(:local, :comm, :bin, :'bin-comm') do
+install?(:local, :comm, :bin) do
puts "installing command scripts"
Dir.chdir srcdir
@@ -287,33 +234,39 @@ install?(:local, :comm, :bin, :'bin-comm') do
ruby_shebang = File.join(bindir, ruby_install_name)
if File::ALT_SEPARATOR
- ruby_bin = ruby_shebang.tr(File::SEPARATOR, File::ALT_SEPARATOR)
+ ruby_bin_dosish = ruby_shebang.tr(File::SEPARATOR, File::ALT_SEPARATOR)
end
for src in Dir["bin/*"]
next unless File.file?(src)
next if /\/[.#]|(\.(old|bak|orig|rej|diff|patch|core)|~|\/core)$/i =~ src
name = ruby_install_name.sub(/ruby/, File.basename(src))
+ dest = File.join(bindir, name)
+
+ install src, dest, :mode => 0755
+
+ next if $dryrun
shebang = ''
body = ''
- open(src, "rb") do |f|
+ open_for_install(dest, "r+") { |f|
shebang = f.gets
body = f.read
- end
- shebang.sub!(/^\#!.*?ruby\b/) {"#!" + ruby_shebang}
- shebang.sub!(/\r$/, '')
- body.gsub!(/\r$/, '')
-
- cmd = File.join(bindir, name)
- cmd << ".#{$cmdtype}" if $cmdtype
- open_for_install(cmd, $script_mode) do
- case $cmdtype
- when "bat"
- "#{<<EOH}#{shebang}#{body}#{<<EOF}".gsub(/$/, "\r")
+
+ if shebang.sub!(/^\#!.*?ruby\b/) {"#!" + ruby_shebang}
+ f.rewind
+ f.print shebang, body
+ f.truncate(f.pos)
+ end
+ }
+
+ if ruby_bin_dosish
+ batfile = File.join(bindir, name + ".bat")
+ open_for_install(batfile, "wb") {|b|
+ b.print((<<EOH+shebang+body+<<EOF).gsub(/\r?\n/, "\r\n"))
@echo off
@if not "%~d0" == "~d0" goto WinNT
-#{ruby_bin} -x "#{cmd}" %1 %2 %3 %4 %5 %6 %7 %8 %9
+#{ruby_bin_dosish} -x "#{batfile}" %1 %2 %3 %4 %5 %6 %7 %8 %9
@goto endofruby
:WinNT
"%~dp0#{ruby_install_name}" -x "%~f0" %*
@@ -322,14 +275,7 @@ EOH
__END__
:endofruby
EOF
- when "cmd"
- "#{<<EOH}#{shebang}#{body}"
-@"%~dp0#{ruby_install_name}" -x "%~f0" %*
-@exit /b %ERRORLEVEL%
-EOH
- else
- shebang + body
- end
+ }
end
end
end
@@ -343,7 +289,7 @@ install?(:local, :comm, :lib) do
for f in Dir["lib/**/*{.rb,help-message}"]
dir = File.dirname(f).sub!(/\Alib/, rubylibdir) || rubylibdir
makedirs dir
- install f, dir, :mode => $data_mode
+ install f, dir, :mode => 0644
end
end
@@ -353,13 +299,13 @@ install?(:local, :arch, :lib) do
Dir.chdir(srcdir)
makedirs [archlibdir]
for f in Dir["*.h"]
- install f, archlibdir, :mode => $data_mode
+ install f, archlibdir, :mode => 0644
end
if RUBY_PLATFORM =~ /mswin32|mingw|bccwin32/
win32libdir = File.join(archlibdir, "win32")
makedirs win32libdir
- install "win32/win32.h", win32libdir, :mode => $data_mode
+ install "win32/win32.h", win32libdir, :mode => 0644
end
end
@@ -376,7 +322,7 @@ install?(:local, :comm, :man) do
makedirs destdir
if $mantype == "doc"
- install mdoc, destfile, :mode => $data_mode
+ install mdoc, destfile, :mode => 0644
else
require 'mdoc2man.rb'
@@ -388,17 +334,15 @@ install?(:local, :comm, :man) do
w.close
- install w.path, destfile, :mode => $data_mode
+ install w.path, destfile, :mode => 0644
end
end
end
+$install.concat ARGV.collect {|n| n.intern}
$install << :local << :ext if $install.empty?
$install.each do |inst|
- if !(procs = $install_procs[inst]) || procs.empty?
- next warn("unknown install target - #{inst}")
- end
- procs.each do |block|
+ $install_procs[inst].each do |block|
dir = Dir.pwd
begin
block.call
diff --git a/intern.h b/intern.h
index 00bb8f16b5..47da14bb7a 100644
--- a/intern.h
+++ b/intern.h
@@ -128,14 +128,6 @@ VALUE rb_singleton_class _((VALUE));
int rb_cmpint _((VALUE, VALUE, VALUE));
NORETURN(void rb_cmperr _((VALUE, VALUE)));
/* enum.c */
-VALUE rb_block_call _((VALUE, ID, int, VALUE*, VALUE (*)(ANYARGS), VALUE));
-/* enumerator.c */
-VALUE rb_enumeratorize _((VALUE, VALUE, int, VALUE *));
-#define RETURN_ENUMERATOR(obj, argc, argv) do { \
- if (!rb_block_given_p()) \
- return rb_enumeratorize(obj, ID2SYM(rb_frame_this_func()), \
- argc, argv); \
- } while (0)
/* error.c */
RUBY_EXTERN int ruby_nerrs;
VALUE rb_exc_new _((VALUE, const char*, long));
@@ -180,7 +172,6 @@ void rb_interrupt _((void));
VALUE rb_apply _((VALUE, ID, VALUE));
void rb_backtrace _((void));
ID rb_frame_last_func _((void));
-ID rb_frame_this_func _((void));
VALUE rb_obj_instance_eval _((int, VALUE*, VALUE));
VALUE rb_mod_module_eval _((int, VALUE*, VALUE));
void rb_load _((VALUE, int));
@@ -193,11 +184,8 @@ VALUE rb_require_safe _((VALUE, int));
void rb_obj_call_init _((VALUE, int, VALUE*));
VALUE rb_class_new_instance _((int, VALUE*, VALUE));
VALUE rb_block_proc _((void));
-VALUE rb_block_dup _((VALUE, VALUE, VALUE));
-VALUE rb_method_dup _((VALUE, VALUE, VALUE));
VALUE rb_f_lambda _((void));
-VALUE rb_proc_call _((VALUE, VALUE));
-VALUE rb_obj_method _((VALUE, VALUE));
+VALUE rb_proc_new _((VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE));
VALUE rb_protect _((VALUE (*)(VALUE), VALUE, int*));
void rb_set_end_proc _((void (*)(VALUE), VALUE));
void rb_mark_end_proc _((void));
@@ -235,7 +223,6 @@ VALUE rb_thread_main _((void));
VALUE rb_thread_local_aref _((VALUE, ID));
VALUE rb_thread_local_aset _((VALUE, ID, VALUE));
void rb_thread_atfork _((void));
-VALUE rb_exec_recursive _((VALUE(*)(VALUE, VALUE, int),VALUE,VALUE));
VALUE rb_funcall_rescue __((VALUE, ID, int, ...));
/* file.c */
VALUE rb_file_s_expand_path _((int, VALUE *));
@@ -251,8 +238,7 @@ VALUE rb_file_directory_p _((VALUE,VALUE));
/* gc.c */
NORETURN(void rb_memerror __((void)));
int ruby_stack_check _((void));
-size_t ruby_stack_length _((VALUE**));
-int rb_during_gc _((void));
+int ruby_stack_length _((VALUE**));
char *rb_source_filename _((const char*));
void rb_gc_mark_locations _((VALUE*, VALUE*));
void rb_mark_tbl _((struct st_table*));
@@ -274,11 +260,10 @@ VALUE rb_hash _((VALUE));
VALUE rb_hash_new _((void));
VALUE rb_hash_freeze _((VALUE));
VALUE rb_hash_aref _((VALUE, VALUE));
-VALUE rb_hash_lookup _((VALUE, VALUE));
VALUE rb_hash_aset _((VALUE, VALUE, VALUE));
VALUE rb_hash_delete_if _((VALUE));
VALUE rb_hash_delete _((VALUE,VALUE));
-int rb_path_check _((const char*));
+int rb_path_check _((char*));
int rb_env_path_tainted _((void));
/* io.c */
#define rb_defout rb_stdout
@@ -334,7 +319,6 @@ VALUE rb_class_real _((VALUE));
VALUE rb_class_inherited_p _((VALUE, VALUE));
VALUE rb_convert_type _((VALUE,int,const char*,const char*));
VALUE rb_check_convert_type _((VALUE,int,const char*,const char*));
-VALUE rb_check_to_integer _((VALUE, const char *));
VALUE rb_to_int _((VALUE));
VALUE rb_Integer _((VALUE));
VALUE rb_Float _((VALUE));
@@ -374,9 +358,6 @@ VALUE rb_detach_process _((int));
VALUE rb_range_new _((VALUE, VALUE, int));
VALUE rb_range_beg_len _((VALUE, long*, long*, long, int));
VALUE rb_length_by_each _((VALUE));
-/* random.c */
-unsigned long rb_genrand_int32(void);
-double rb_genrand_real(void);
/* re.c */
int rb_memcmp _((const void*,const void*,long));
int rb_memcicmp _((const void*,const void*,long));
@@ -419,7 +400,6 @@ const char *ruby_signal_name _((int));
void ruby_default_signal _((int));
/* sprintf.c */
VALUE rb_f_sprintf _((int, VALUE*));
-VALUE rb_str_format _((int, VALUE*, VALUE));
/* string.c */
VALUE rb_str_new _((const char*, long));
VALUE rb_str_new2 _((const char*));
@@ -430,7 +410,6 @@ VALUE rb_tainted_str_new _((const char*, long));
VALUE rb_tainted_str_new2 _((const char*));
VALUE rb_str_buf_new _((long));
VALUE rb_str_buf_new2 _((const char*));
-VALUE rb_str_tmp_new _((long));
VALUE rb_str_buf_append _((VALUE, VALUE));
VALUE rb_str_buf_cat _((VALUE, const char*, long));
VALUE rb_str_buf_cat2 _((VALUE, const char*));
@@ -445,7 +424,6 @@ VALUE rb_str_times _((VALUE, VALUE));
VALUE rb_str_substr _((VALUE, long, long));
void rb_str_modify _((VALUE));
VALUE rb_str_freeze _((VALUE));
-void rb_str_set_len _((VALUE, long));
VALUE rb_str_resize _((VALUE, long));
VALUE rb_str_cat _((VALUE, const char*, long));
VALUE rb_str_cat2 _((VALUE, const char*));
@@ -469,7 +447,7 @@ VALUE rb_struct_alloc _((VALUE, VALUE));
VALUE rb_struct_aref _((VALUE, VALUE));
VALUE rb_struct_aset _((VALUE, VALUE, VALUE));
VALUE rb_struct_getmember _((VALUE, ID));
-VALUE rb_struct_iv_get _((VALUE, const char*));
+VALUE rb_struct_iv_get _((VALUE, char*));
VALUE rb_struct_s_members _((VALUE));
VALUE rb_struct_members _((VALUE));
/* time.c */
diff --git a/io.c b/io.c
index 7663733d1e..8f8dfcdf2e 100644
--- a/io.c
+++ b/io.c
@@ -21,7 +21,6 @@
#include "rubyio.h"
#include "rubysig.h"
#include "env.h"
-#include "re.h"
#include <ctype.h>
#include <errno.h>
@@ -50,9 +49,6 @@
#elif defined(HAVE_SYS_FCNTL_H)
#include <sys/fcntl.h>
#endif
-#ifdef __CYGWIN__
-#include <io.h>
-#endif
#if !HAVE_OFF_T && !defined(off_t)
# define off_t long
@@ -223,7 +219,7 @@ rb_io_taint_check(io)
void
rb_io_check_initialized(fptr)
- rb_io_t *fptr;
+ OpenFile *fptr;
{
if (!fptr) {
rb_raise(rb_eIOError, "uninitialized stream");
@@ -232,7 +228,7 @@ rb_io_check_initialized(fptr)
void
rb_io_check_closed(fptr)
- rb_io_t *fptr;
+ OpenFile *fptr;
{
rb_io_check_initialized(fptr);
if (!fptr->f && !fptr->f2) {
@@ -240,16 +236,15 @@ rb_io_check_closed(fptr)
}
}
-static void io_fflush _((FILE *, rb_io_t *));
+static void io_fflush _((FILE *, OpenFile *));
-static rb_io_t *
+static OpenFile *
flush_before_seek(fptr)
- rb_io_t *fptr;
+ OpenFile *fptr;
{
if (fptr->mode & FMODE_WBUF) {
io_fflush(GetWriteFile(fptr), fptr);
}
- errno = 0;
return fptr;
}
@@ -266,7 +261,7 @@ flush_before_seek(fptr)
void
rb_io_check_readable(fptr)
- rb_io_t *fptr;
+ OpenFile *fptr;
{
rb_io_check_closed(fptr);
if (!(fptr->mode & FMODE_READABLE)) {
@@ -285,7 +280,7 @@ rb_io_check_readable(fptr)
void
rb_io_check_writable(fptr)
- rb_io_t *fptr;
+ OpenFile *fptr;
{
rb_io_check_closed(fptr);
if (!(fptr->mode & FMODE_WRITABLE)) {
@@ -350,7 +345,7 @@ io_alloc(klass)
static void
io_fflush(f, fptr)
FILE *f;
- rb_io_t *fptr;
+ OpenFile *fptr;
{
int n;
@@ -429,13 +424,10 @@ rb_io_wait_writable(f)
#endif
static int
-wsplit_p(rb_io_t *fptr)
+wsplit_p(OpenFile *fptr)
{
FILE *f = GetWriteFile(fptr);
-#if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
int r;
-#endif
-
if (!(fptr->mode & FMODE_WSPLIT_INITIALIZED)) {
struct stat buf;
if (fstat(fileno(f), &buf) == 0 &&
@@ -456,7 +448,7 @@ wsplit_p(rb_io_t *fptr)
static long
io_fwrite(str, fptr)
VALUE str;
- rb_io_t *fptr;
+ OpenFile *fptr;
{
long len, n, r, l, offset = 0;
FILE *f = GetWriteFile(fptr);
@@ -536,7 +528,7 @@ rb_io_fwrite(ptr, len, f)
long len;
FILE *f;
{
- rb_io_t of;
+ OpenFile of;
of.f = f;
of.f2 = NULL;
@@ -567,7 +559,7 @@ static VALUE
io_write(io, str)
VALUE io, str;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
long n;
rb_secure(4);
@@ -642,7 +634,7 @@ static VALUE
rb_io_flush(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
FILE *f;
GetOpenFile(io, fptr);
@@ -671,12 +663,12 @@ static VALUE
rb_io_tell(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
off_t pos;
GetOpenFile(io, fptr);
pos = io_tell(fptr);
- if (pos < 0 && errno) rb_sys_fail(fptr->path);
+ if (pos < 0) rb_sys_fail(fptr->path);
return OFFT2NUM(pos);
}
@@ -685,13 +677,13 @@ rb_io_seek(io, offset, whence)
VALUE io, offset;
int whence;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
off_t pos;
pos = NUM2OFFT(offset);
GetOpenFile(io, fptr);
pos = io_seek(fptr, pos, whence);
- if (pos < 0 && errno) rb_sys_fail(fptr->path);
+ if (pos < 0) rb_sys_fail(fptr->path);
clearerr(fptr->f);
return INT2FIX(0);
@@ -749,7 +741,7 @@ static VALUE
rb_io_set_pos(io, offset)
VALUE io, offset;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
off_t pos;
pos = NUM2OFFT(offset);
@@ -779,7 +771,7 @@ static VALUE
rb_io_rewind(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(io, fptr);
if (io_seek(fptr, 0L, 0) != 0) rb_sys_fail(fptr->path);
@@ -828,7 +820,7 @@ VALUE
rb_io_eof(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
int ch;
GetOpenFile(io, fptr);
@@ -868,7 +860,7 @@ static VALUE
rb_io_sync(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(io, fptr);
return (fptr->mode & FMODE_SYNC) ? Qtrue : Qfalse;
@@ -893,7 +885,7 @@ static VALUE
rb_io_set_sync(io, mode)
VALUE io, mode;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(io, fptr);
if (RTEST(mode)) {
@@ -922,7 +914,7 @@ rb_io_fsync(io)
VALUE io;
{
#ifdef HAVE_FSYNC
- rb_io_t *fptr;
+ OpenFile *fptr;
FILE *f;
GetOpenFile(io, fptr);
@@ -954,7 +946,7 @@ static VALUE
rb_io_fileno(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
int fd;
GetOpenFile(io, fptr);
@@ -986,7 +978,7 @@ static VALUE
rb_io_pid(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(io, fptr);
if (!fptr->pid)
@@ -1005,9 +997,8 @@ static VALUE
rb_io_inspect(obj)
VALUE obj;
{
- rb_io_t *fptr;
- char *buf;
- const char *cname, *st = "";
+ OpenFile *fptr;
+ char *buf, *cname, *st = "";
long len;
fptr = RFILE(rb_io_taint_check(obj))->fptr;
@@ -1065,7 +1056,7 @@ static long
io_fread(ptr, len, fptr)
char *ptr;
long len;
- rb_io_t *fptr;
+ OpenFile *fptr;
{
long n = len;
int c;
@@ -1121,7 +1112,7 @@ rb_io_fread(ptr, len, f)
long len;
FILE *f;
{
- rb_io_t of;
+ OpenFile of;
of.f = f;
of.f2 = NULL;
@@ -1132,7 +1123,7 @@ rb_io_fread(ptr, len, f)
static long
remain_size(fptr)
- rb_io_t *fptr;
+ OpenFile *fptr;
{
struct stat st;
off_t siz = BUFSIZ;
@@ -1158,7 +1149,7 @@ remain_size(fptr)
static VALUE
read_all(fptr, siz, str)
- rb_io_t *fptr;
+ OpenFile *fptr;
long siz;
VALUE str;
{
@@ -1194,7 +1185,7 @@ read_all(fptr, siz, str)
return str;
}
-void rb_io_set_nonblock(rb_io_t *fptr)
+void rb_io_set_nonblock(OpenFile *fptr)
{
int flags;
#ifdef F_GETFL
@@ -1232,7 +1223,7 @@ void rb_io_set_nonblock(rb_io_t *fptr)
static VALUE
io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
{
- rb_io_t *fptr;
+ OpenFile *fptr;
VALUE length, str;
long n, len;
@@ -1415,7 +1406,7 @@ io_read_nonblock(int argc, VALUE *argv, VALUE io)
static VALUE
rb_io_write_nonblock(VALUE io, VALUE str)
{
- rb_io_t *fptr;
+ OpenFile *fptr;
FILE *f;
long n;
@@ -1462,7 +1453,7 @@ io_read(argc, argv, io)
VALUE *argv;
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
long n, len;
VALUE length, str;
@@ -1518,7 +1509,7 @@ io_read(argc, argv, io)
static int
appendline(fptr, delim, strp)
- rb_io_t *fptr;
+ OpenFile *fptr;
int delim;
VALUE *strp;
{
@@ -1623,7 +1614,7 @@ appendline(fptr, delim, strp)
static inline int
swallow(fptr, term)
- rb_io_t *fptr;
+ OpenFile *fptr;
int term;
{
FILE *f = fptr->f;
@@ -1662,7 +1653,7 @@ swallow(fptr, term)
static VALUE
rb_io_getline_fast(fptr, delim)
- rb_io_t *fptr;
+ OpenFile *fptr;
unsigned char delim;
{
VALUE str = Qnil;
@@ -1681,7 +1672,7 @@ rb_io_getline_fast(fptr, delim)
static int
rscheck(rsptr, rslen, rs)
- const char *rsptr;
+ char *rsptr;
long rslen;
VALUE rs;
{
@@ -1697,7 +1688,7 @@ rb_io_getline(rs, io)
VALUE rs, io;
{
VALUE str = Qnil;
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
@@ -1710,7 +1701,7 @@ rb_io_getline(rs, io)
}
else {
int c, newline;
- const char *rsptr;
+ char *rsptr;
long rslen;
int rspara = 0;
@@ -1731,7 +1722,7 @@ rb_io_getline(rs, io)
while ((c = appendline(fptr, newline, &str)) != EOF &&
(c != newline || RSTRING(str)->len < rslen ||
- ((rspara || rscheck(rsptr,rslen,rs)) && 0) ||
+ (rspara || rscheck(rsptr,rslen,rs), 0) ||
memcmp(RSTRING(str)->ptr+RSTRING(str)->len-rslen,rsptr,rslen)));
if (rspara) {
@@ -1754,7 +1745,7 @@ VALUE
rb_io_gets(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
@@ -1822,7 +1813,7 @@ static VALUE
rb_io_lineno(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
@@ -1850,7 +1841,7 @@ static VALUE
rb_io_set_lineno(io, lineno)
VALUE io, lineno;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
@@ -1972,7 +1963,6 @@ rb_io_each_line(argc, argv, io)
VALUE str;
VALUE rs;
- RETURN_ENUMERATOR(io, argc, argv);
if (argc == 0) {
rs = rb_rs;
}
@@ -1988,7 +1978,7 @@ rb_io_each_line(argc, argv, io)
/*
* call-seq:
- * ios.each_byte {|byte| block } => ios
+ * ios.each_byte {|byte| block } => nil
*
* Calls the given block once for each byte (0..255) in <em>ios</em>,
* passing the byte as an argument. The stream must be opened for
@@ -2004,11 +1994,10 @@ static VALUE
rb_io_each_byte(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
FILE *f;
int c;
- RETURN_ENUMERATOR(io, 0, 0);
GetOpenFile(io, fptr);
for (;;) {
@@ -2034,97 +2023,6 @@ rb_io_each_byte(io)
return io;
}
-VALUE rb_io_getc _((VALUE));
-
-/*
- * call-seq:
- * ios.each_char {|c| block } => ios
- *
- * Calls the given block once for each character in <em>ios</em>,
- * passing the character as an argument. The stream must be opened for
- * reading or an <code>IOError</code> will be raised. Multibyte
- * characters are dealt with according to $KCODE.
- *
- * f = File.new("testfile")
- * f.each_char {|c| print c, ' ' } #=> #<File:testfile>
- */
-
-static VALUE
-rb_io_each_char(io)
- VALUE io;
-{
- VALUE ch;
-
- RETURN_ENUMERATOR(io, 0, 0);
-
- while (!NIL_P(ch = rb_io_getc(io))) {
- unsigned char c;
- int n;
- VALUE str;
-
- c= FIX2INT(ch);
- n = mbclen(c);
- str = rb_tainted_str_new((const char *)&c, 1);
-
- while (--n > 0) {
- if (NIL_P(ch = rb_io_getc(io))) {
- rb_yield(str);
- return io;
- }
- c = FIX2INT(ch);
- rb_str_cat(str, (const char *)&c, 1);
- }
- rb_yield(str);
- }
- return io;
-}
-
-/*
- * call-seq:
- * ios.lines(sep=$/) => anEnumerator
- * ios.lines(limit) => anEnumerator
- * ios.lines(sep, limit) => anEnumerator
- *
- * Returns an enumerator that gives each line in <em>ios</em>.
- * The stream must be opened for reading or an <code>IOError</code>
- * will be raised.
- *
- * f = File.new("testfile")
- * f.lines.to_a #=> ["foo\n", "bar\n"]
- * f.rewind
- * f.lines.sort #=> ["bar\n", "foo\n"]
- */
-
-static VALUE
-rb_io_lines(argc, argv, io)
- int argc;
- VALUE *argv;
- VALUE io;
-{
- return rb_enumeratorize(io, ID2SYM(rb_intern("each_line")), argc, argv);
-}
-
-/*
- * call-seq:
- * ios.bytes => anEnumerator
- *
- * Returns an enumerator that gives each byte (0..255) in <em>ios</em>.
- * The stream must be opened for reading or an <code>IOError</code>
- * will be raised.
- *
- * f = File.new("testfile")
- * f.bytes.to_a #=> [104, 101, 108, 108, 111]
- * f.rewind
- * f.bytes.sort #=> [101, 104, 108, 108, 111]
- */
-
-static VALUE
-rb_io_bytes(io)
- VALUE io;
-{
- return rb_enumeratorize(io, ID2SYM(rb_intern("each_byte")), 0, 0);
-}
-
/*
* call-seq:
* ios.getc => fixnum or nil
@@ -2141,7 +2039,7 @@ VALUE
rb_io_getc(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
FILE *f;
int c;
@@ -2225,7 +2123,7 @@ VALUE
rb_io_ungetc(io, c)
VALUE io, c;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
int cc = NUM2INT(c);
GetOpenFile(io, fptr);
@@ -2255,7 +2153,7 @@ static VALUE
rb_io_isatty(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(io, fptr);
if (isatty(fileno(fptr->f)) == 0)
@@ -2265,12 +2163,11 @@ rb_io_isatty(io)
static void
fptr_finalize(fptr, noraise)
- rb_io_t *fptr;
+ OpenFile *fptr;
int noraise;
{
int n1 = 0, n2 = 0, f1, f2 = -1;
- errno = 0;
if (fptr->f2) {
f2 = fileno(fptr->f2);
while (n2 = 0, fflush(fptr->f2) < 0) {
@@ -2310,7 +2207,7 @@ fptr_finalize(fptr, noraise)
static void
rb_io_fptr_cleanup(fptr, noraise)
- rb_io_t *fptr;
+ OpenFile *fptr;
int noraise;
{
if (fptr->finalize) {
@@ -2323,7 +2220,7 @@ rb_io_fptr_cleanup(fptr, noraise)
void
rb_io_fptr_finalize(fptr)
- rb_io_t *fptr;
+ OpenFile *fptr;
{
if (!fptr) return;
if (fptr->path) {
@@ -2339,7 +2236,7 @@ VALUE
rb_io_close(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
int fd, fd2;
fptr = RFILE(io)->fptr;
@@ -2427,7 +2324,7 @@ static VALUE
rb_io_closed(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
fptr = RFILE(io)->fptr;
rb_io_check_initialized(fptr);
@@ -2456,7 +2353,7 @@ static VALUE
rb_io_close_read(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
int n;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(io)) {
@@ -2501,7 +2398,7 @@ static VALUE
rb_io_close_write(io)
VALUE io;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
int n;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(io)) {
@@ -2543,7 +2440,7 @@ rb_io_sysseek(argc, argv, io)
{
VALUE offset, ptrname;
int whence = SEEK_SET;
- rb_io_t *fptr;
+ OpenFile *fptr;
off_t pos;
if (rb_scan_args(argc, argv, "11", &offset, &ptrname) == 2) {
@@ -2581,7 +2478,7 @@ static VALUE
rb_io_syswrite(io, str)
VALUE io, str;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
FILE *f;
long n;
@@ -2629,7 +2526,7 @@ rb_io_sysread(argc, argv, io)
VALUE io;
{
VALUE len, str;
- rb_io_t *fptr;
+ OpenFile *fptr;
long n, ilen;
rb_scan_args(argc, argv, "11", &len, &str);
@@ -2692,7 +2589,7 @@ rb_io_binmode(io)
VALUE io;
{
#if defined(_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__EMX__)
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(io, fptr);
#ifdef __human68k__
@@ -2712,7 +2609,7 @@ rb_io_binmode(io)
return io;
}
-const char*
+char*
rb_io_flags_mode(flags)
int flags;
{
@@ -2772,16 +2669,11 @@ rb_io_mode_flags(mode)
case '+':
flags |= FMODE_READWRITE;
break;
- case ':':
- /* forward compatibility */
- rb_warning("encoding options not supported in 1.8: %s", mode);
- goto end;
default:
goto error;
}
}
- end:
return flags;
}
@@ -2850,22 +2742,17 @@ rb_io_mode_modenum(mode)
case '+':
flags = (flags & ~O_ACCMODE) | O_RDWR;
break;
- case ':':
- /* forward compatibility */
- rb_warning("encoding options not supported in 1.8: %s", mode);
- goto end;
default:
goto error;
}
}
- end:
return flags;
}
#define MODENUM_MAX 4
-static const char*
+static char*
rb_io_modenum_mode(flags)
int flags;
{
@@ -2986,7 +2873,7 @@ rb_file_open_internal(io, fname, mode)
VALUE io;
const char *fname, *mode;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
MakeOpenFile(io, fptr);
@@ -3010,9 +2897,9 @@ rb_file_sysopen_internal(io, fname, flags, mode)
char *fname;
int flags, mode;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
int fd;
- const char *m;
+ char *m;
MakeOpenFile(io, fptr);
@@ -3035,13 +2922,13 @@ rb_file_sysopen(fname, flags, mode)
#if defined (_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__VMS)
static struct pipe_list {
- rb_io_t *fptr;
+ OpenFile *fptr;
struct pipe_list *next;
} *pipe_list;
static void
pipe_add_fptr(fptr)
- rb_io_t *fptr;
+ OpenFile *fptr;
{
struct pipe_list *list;
@@ -3053,7 +2940,7 @@ pipe_add_fptr(fptr)
static void
pipe_del_fptr(fptr)
- rb_io_t *fptr;
+ OpenFile *fptr;
{
struct pipe_list *list = pipe_list;
struct pipe_list *tmp;
@@ -3088,11 +2975,11 @@ pipe_atexit _((void))
}
}
-static void pipe_finalize _((rb_io_t *fptr,int));
+static void pipe_finalize _((OpenFile *fptr,int));
static void
pipe_finalize(fptr, noraise)
- rb_io_t *fptr;
+ OpenFile *fptr;
int noraise;
{
#if !defined (__CYGWIN__) && !defined(_WIN32)
@@ -3118,27 +3005,27 @@ pipe_finalize(fptr, noraise)
void
rb_io_synchronized(fptr)
- rb_io_t *fptr;
+ OpenFile *fptr;
{
fptr->mode |= FMODE_SYNC;
}
void
rb_io_unbuffered(fptr)
- rb_io_t *fptr;
+ OpenFile *fptr;
{
rb_io_synchronized(fptr);
}
-static VALUE pipe_open(VALUE pstr, const char *pname, const char *mode);
+static VALUE pipe_open(VALUE pstr, char *pname, char *mode);
static VALUE
pipe_open(pstr, pname, mode)
VALUE pstr;
- const char *pname, *mode;
+ char *pname, *mode;
{
int modef = rb_io_mode_flags(mode);
- rb_io_t *fptr;
+ OpenFile *fptr;
#if defined(DJGPP) || defined(__human68k__) || defined(__VMS)
FILE *f;
#else
@@ -3357,7 +3244,7 @@ rb_io_s_popen(argc, argv, klass)
VALUE *argv;
VALUE klass;
{
- const char *mode;
+ char *mode;
VALUE pname, pmode, port;
if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
@@ -3367,7 +3254,7 @@ rb_io_s_popen(argc, argv, klass)
mode = rb_io_modenum_mode(FIX2INT(pmode));
}
else {
- mode = rb_io_flags_mode(rb_io_mode_flags(StringValueCStr(pmode)));
+ mode = rb_io_flags_mode(rb_io_mode_flags(StringValuePtr(pmode)));
}
SafeStringValue(pname);
port = pipe_open(pname, 0, mode);
@@ -3395,14 +3282,12 @@ rb_open_file(argc, argv, io)
VALUE io;
{
VALUE fname, vmode, perm;
- const char *path, *mode;
- int flags;
- unsigned int fmode;
+ char *mode;
+ int flags, fmode;
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
SafeStringValue(fname);
- path = StringValueCStr(fname);
if (FIXNUM_P(vmode) || !NIL_P(perm)) {
if (FIXNUM_P(vmode)) {
flags = FIX2INT(vmode);
@@ -3411,13 +3296,13 @@ rb_open_file(argc, argv, io)
SafeStringValue(vmode);
flags = rb_io_mode_modenum(RSTRING(vmode)->ptr);
}
- fmode = NIL_P(perm) ? 0666 : NUM2UINT(perm);
+ fmode = NIL_P(perm) ? 0666 : NUM2INT(perm);
- rb_file_sysopen_internal(io, path, flags, fmode);
+ rb_file_sysopen_internal(io, RSTRING(fname)->ptr, flags, fmode);
}
else {
- mode = NIL_P(vmode) ? "r" : StringValueCStr(vmode);
- rb_file_open_internal(io, path, mode);
+ mode = NIL_P(vmode) ? "r" : StringValuePtr(vmode);
+ rb_file_open_internal(io, RSTRING(fname)->ptr, mode);
}
return io;
}
@@ -3467,8 +3352,7 @@ rb_io_s_sysopen(argc, argv)
VALUE *argv;
{
VALUE fname, vmode, perm;
- int flags, fd;
- unsigned int fmode;
+ int flags, fmode, fd;
char *path;
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
@@ -3481,7 +3365,7 @@ rb_io_s_sysopen(argc, argv)
flags = rb_io_mode_modenum(RSTRING(vmode)->ptr);
}
if (NIL_P(perm)) fmode = 0666;
- else fmode = NUM2UINT(perm);
+ else fmode = NUM2INT(perm);
path = ALLOCA_N(char, strlen(RSTRING(fname)->ptr)+1);
strcpy(path, RSTRING(fname)->ptr);
@@ -3615,9 +3499,9 @@ rb_io_check_io(io)
return rb_check_convert_type(io, T_FILE, "IO", "to_io");
}
-static const char*
+static char*
rb_io_mode_string(fptr)
- rb_io_t *fptr;
+ OpenFile *fptr;
{
switch (fptr->mode & FMODE_READWRITE) {
case FMODE_READABLE:
@@ -3634,8 +3518,8 @@ static VALUE
io_reopen(io, nfile)
VALUE io, nfile;
{
- rb_io_t *fptr, *orig;
- const char *mode;
+ OpenFile *fptr, *orig;
+ char *mode;
int fd, fd2;
off_t pos = 0;
@@ -3660,7 +3544,7 @@ io_reopen(io, nfile)
io_fflush(GetWriteFile(fptr), fptr);
}
- /* copy rb_io_t structure */
+ /* copy OpenFile structure */
fptr->mode = orig->mode;
fptr->pid = orig->pid;
fptr->lineno = orig->lineno;
@@ -3751,8 +3635,8 @@ rb_io_reopen(argc, argv, file)
VALUE file;
{
VALUE fname, nmode;
- const char *mode;
- rb_io_t *fptr;
+ char *mode;
+ OpenFile *fptr;
rb_secure(4);
if (rb_scan_args(argc, argv, "11", &fname, &nmode) == 1) {
@@ -3766,12 +3650,12 @@ rb_io_reopen(argc, argv, file)
rb_io_taint_check(file);
fptr = RFILE(file)->fptr;
if (!fptr) {
- fptr = RFILE(file)->fptr = ALLOC(rb_io_t);
- MEMZERO(fptr, rb_io_t, 1);
+ fptr = RFILE(file)->fptr = ALLOC(OpenFile);
+ MEMZERO(fptr, OpenFile, 1);
}
if (!NIL_P(nmode)) {
- fptr->mode = rb_io_mode_flags(StringValueCStr(nmode));
+ fptr->mode = rb_io_mode_flags(StringValuePtr(nmode));
}
if (fptr->path) {
@@ -3779,7 +3663,7 @@ rb_io_reopen(argc, argv, file)
fptr->path = 0;
}
- fptr->path = strdup(StringValueCStr(fname));
+ fptr->path = strdup(RSTRING(fname)->ptr);
mode = rb_io_flags_mode(fptr->mode);
if (!fptr->f) {
fptr->f = rb_fopen(fptr->path, mode);
@@ -3790,16 +3674,16 @@ rb_io_reopen(argc, argv, file)
return file;
}
- if (freopen(fptr->path, mode, fptr->f) == 0) {
+ if (freopen(RSTRING(fname)->ptr, mode, fptr->f) == 0) {
rb_sys_fail(fptr->path);
}
#ifdef USE_SETVBUF
if (setvbuf(fptr->f, NULL, _IOFBF, 0) != 0)
- rb_warn("setvbuf() can't be honoured for %s", fptr->path);
+ rb_warn("setvbuf() can't be honoured for %s", RSTRING(fname)->ptr);
#endif
if (fptr->f2) {
- if (freopen(fptr->path, "w", fptr->f2) == 0) {
+ if (freopen(RSTRING(fname)->ptr, "w", fptr->f2) == 0) {
rb_sys_fail(fptr->path);
}
}
@@ -3812,9 +3696,9 @@ static VALUE
rb_io_init_copy(dest, io)
VALUE dest, io;
{
- rb_io_t *fptr, *orig;
+ OpenFile *fptr, *orig;
int fd;
- const char *mode;
+ char *mode;
io = rb_io_get_io(io);
if (dest == io) return dest;
@@ -3832,7 +3716,7 @@ rb_io_init_copy(dest, io)
fseeko(orig->f, 0L, SEEK_CUR);
}
- /* copy rb_io_t structure */
+ /* copy OpenFile structure */
fptr->mode = orig->mode;
fptr->pid = orig->pid;
fptr->lineno = orig->lineno;
@@ -4283,7 +4167,7 @@ prep_stdio(f, mode, klass)
int mode;
VALUE klass;
{
- rb_io_t *fp;
+ OpenFile *fp;
VALUE io = io_alloc(klass);
MakeOpenFile(io, fp);
@@ -4304,7 +4188,7 @@ prep_path(io, path)
VALUE io;
char *path;
{
- rb_io_t *fptr;
+ OpenFile *fptr;
GetOpenFile(io, fptr);
if (fptr->path) rb_bug("illegal prep_path() call");
@@ -4336,7 +4220,7 @@ rb_io_initialize(argc, argv, io)
VALUE io;
{
VALUE fnum, mode;
- rb_io_t *fp;
+ OpenFile *fp;
int fd, flags;
rb_secure(4);
@@ -4348,7 +4232,7 @@ rb_io_initialize(argc, argv, io)
}
else {
SafeStringValue(mode);
- flags = rb_io_mode_modenum(StringValueCStr(mode));
+ flags = rb_io_mode_modenum(RSTRING(mode)->ptr);
}
}
else {
@@ -4434,7 +4318,7 @@ rb_io_s_new(argc, argv, klass)
VALUE klass;
{
if (rb_block_given_p()) {
- const char *cname = rb_class2name(klass);
+ char *cname = rb_class2name(klass);
rb_warn("%s::new() does not take block; use %s::open() instead",
cname, cname);
@@ -4493,7 +4377,7 @@ next_argv()
{
extern VALUE rb_argv;
char *fn;
- rb_io_t *fptr;
+ OpenFile *fptr;
int stdout_binmode = 0;
if (TYPE(rb_stdout) == T_FILE) {
@@ -4518,7 +4402,7 @@ next_argv()
retry:
if (RARRAY(rb_argv)->len > 0) {
filename = rb_ary_shift(rb_argv);
- fn = StringValueCStr(filename);
+ fn = StringValuePtr(filename);
if (strlen(fn) == 1 && fn[0] == '-') {
current_file = rb_stdin;
if (ruby_inplace_mode) {
@@ -4530,10 +4414,7 @@ next_argv()
FILE *fr = rb_fopen(fn, "r");
if (ruby_inplace_mode) {
- struct stat st;
-#ifndef NO_SAFE_RENAME
- struct stat st2;
-#endif
+ struct stat st, st2;
VALUE str;
FILE *fw;
@@ -4803,7 +4684,7 @@ rb_f_backquote(obj, str)
{
volatile VALUE port;
VALUE result;
- rb_io_t *fptr;
+ OpenFile *fptr;
SafeStringValue(str);
port = pipe_open(str, 0, "r");
@@ -4840,7 +4721,7 @@ rb_f_select(argc, argv, obj)
fd_set rset, wset, eset, pset;
fd_set *rp, *wp, *ep;
struct timeval *tp, timerec;
- rb_io_t *fptr;
+ OpenFile *fptr;
long i;
int max = 0, n;
int interrupt_flag = 0;
@@ -5002,7 +4883,7 @@ rb_io_ctl(io, req, arg, io_p)
{
#if !defined(MSDOS) && !defined(__human68k__)
int cmd = NUM2ULONG(req);
- rb_io_t *fptr;
+ OpenFile *fptr;
long len = 0;
long narg = 0;
int retval;
@@ -5182,7 +5063,7 @@ rb_f_syscall(argc, argv)
if (!NIL_P(v)) {
StringValue(v);
rb_str_modify(v);
- arg[i] = (unsigned long)StringValueCStr(v);
+ arg[i] = (unsigned long)RSTRING(v)->ptr;
}
else {
arg[i] = (unsigned long)NUM2LONG(*argv);
@@ -5374,16 +5255,14 @@ io_s_foreach(arg)
*/
static VALUE
-rb_io_s_foreach(argc, argv, self)
+rb_io_s_foreach(argc, argv)
int argc;
VALUE *argv;
- VALUE self;
{
VALUE fname;
struct foreach_arg arg;
rb_scan_args(argc, argv, "11", &fname, &arg.sep);
- RETURN_ENUMERATOR(self, argc, argv);
SafeStringValue(fname);
if (argc == 1) {
@@ -5392,7 +5271,7 @@ rb_io_s_foreach(argc, argv, self)
else if (!NIL_P(arg.sep)) {
StringValue(arg.sep);
}
- arg.io = rb_io_open(StringValueCStr(fname), "r");
+ arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
if (NIL_P(arg.io)) return Qnil;
return rb_ensure(io_s_foreach, (VALUE)&arg, rb_io_close, arg.io);
@@ -5431,7 +5310,7 @@ rb_io_s_readlines(argc, argv, io)
SafeStringValue(fname);
arg.argc = argc - 1;
- arg.io = rb_io_open(StringValueCStr(fname), "r");
+ arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
if (NIL_P(arg.io)) return Qnil;
return rb_ensure(io_s_readlines, (VALUE)&arg, rb_io_close, arg.io);
}
@@ -5469,7 +5348,7 @@ rb_io_s_read(argc, argv, io)
SafeStringValue(fname);
arg.argc = argc ? 1 : 0;
- arg.io = rb_io_open(StringValueCStr(fname), "r");
+ arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
if (NIL_P(arg.io)) return Qnil;
if (!NIL_P(offset)) {
rb_io_seek(arg.io, offset, SEEK_SET);
@@ -5635,14 +5514,12 @@ argf_readchar()
}
static VALUE
-argf_each_line(argc, argv, argf)
+argf_each_line(argc, argv)
int argc;
VALUE *argv;
- VALUE argf;
{
VALUE str;
- RETURN_ENUMERATOR(argf, argc, argv);
if (!next_argv()) return Qnil;
if (TYPE(current_file) != T_FILE) {
for (;;) {
@@ -5658,12 +5535,10 @@ argf_each_line(argc, argv, argf)
}
static VALUE
-argf_each_byte(argf)
- VALUE argf;
+argf_each_byte()
{
VALUE byte;
- RETURN_ENUMERATOR(argf, 0, 0);
while (!NIL_P(byte = argf_getc())) {
rb_yield(byte);
}
@@ -5671,42 +5546,6 @@ argf_each_byte(argf)
}
static VALUE
-argf_each_char(argf)
- VALUE argf;
-{
- VALUE ch;
-
- RETURN_ENUMERATOR(argf, 0, 0);
-
- while (!NIL_P(ch = argf_getc())) {
- unsigned char c;
- int n;
- VALUE str, file;
-
- first_char:
- c = FIX2INT(ch);
- n = mbclen(c);
- str = rb_tainted_str_new((const char *)&c, 1);
- file = current_file;
-
- while (--n > 0) {
- if (NIL_P(ch = argf_getc())) {
- rb_yield(str);
- return argf;
- }
- if (current_file != file) {
- rb_yield(str);
- goto first_char;
- }
- c = FIX2INT(ch);
- rb_str_cat(str, (const char *)&c, 1);
- }
- rb_yield(str);
- }
- return argf;
-}
-
-static VALUE
argf_filename()
{
next_argv();
@@ -5785,7 +5624,7 @@ opt_i_set(val)
StringValue(val);
if (ruby_inplace_mode) free(ruby_inplace_mode);
ruby_inplace_mode = 0;
- ruby_inplace_mode = strdup(StringValueCStr(val));
+ ruby_inplace_mode = strdup(RSTRING(val)->ptr);
}
/*
@@ -5948,10 +5787,6 @@ Init_IO()
rb_define_method(rb_cIO, "each", rb_io_each_line, -1);
rb_define_method(rb_cIO, "each_line", rb_io_each_line, -1);
rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 0);
- rb_define_method(rb_cIO, "each_char", rb_io_each_char, 0);
- rb_define_method(rb_cIO, "lines", rb_io_lines, -1);
- rb_define_method(rb_cIO, "bytes", rb_io_bytes, 0);
- rb_define_method(rb_cIO, "chars", rb_io_each_char, 0);
rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
rb_define_method(rb_cIO, "sysread", rb_io_sysread, -1);
@@ -5977,9 +5812,7 @@ Init_IO()
rb_define_method(rb_cIO, "gets", rb_io_gets_m, -1);
rb_define_method(rb_cIO, "readline", rb_io_readline, -1);
rb_define_method(rb_cIO, "getc", rb_io_getc, 0);
- rb_define_method(rb_cIO, "getbyte", rb_io_getc, 0);
rb_define_method(rb_cIO, "readchar", rb_io_readchar, 0);
- rb_define_method(rb_cIO, "readbyte", rb_io_readchar, 0);
rb_define_method(rb_cIO, "ungetc",rb_io_ungetc, 1);
rb_define_method(rb_cIO, "<<", rb_io_addstr, 1);
rb_define_method(rb_cIO, "flush", rb_io_flush, 0);
@@ -6041,10 +5874,6 @@ Init_IO()
rb_define_singleton_method(argf, "each", argf_each_line, -1);
rb_define_singleton_method(argf, "each_line", argf_each_line, -1);
rb_define_singleton_method(argf, "each_byte", argf_each_byte, 0);
- rb_define_singleton_method(argf, "each_char", argf_each_char, 0);
- rb_define_singleton_method(argf, "lines", argf_each_line, -1);
- rb_define_singleton_method(argf, "bytes", argf_each_byte, 0);
- rb_define_singleton_method(argf, "chars", argf_each_char, 0);
rb_define_singleton_method(argf, "read", argf_read, -1);
rb_define_singleton_method(argf, "readlines", rb_f_readlines, -1);
@@ -6052,9 +5881,7 @@ Init_IO()
rb_define_singleton_method(argf, "gets", rb_f_gets, -1);
rb_define_singleton_method(argf, "readline", rb_f_readline, -1);
rb_define_singleton_method(argf, "getc", argf_getc, 0);
- rb_define_singleton_method(argf, "getbyte", argf_getc, 0);
rb_define_singleton_method(argf, "readchar", argf_readchar, 0);
- rb_define_singleton_method(argf, "readbyte", argf_readchar, 0);
rb_define_singleton_method(argf, "tell", argf_tell, 0);
rb_define_singleton_method(argf, "seek", argf_seek_m, -1);
rb_define_singleton_method(argf, "rewind", argf_rewind, 0);
diff --git a/keywords b/keywords
index 6eed5e1f4d..04be992857 100644
--- a/keywords
+++ b/keywords
@@ -1,4 +1,4 @@
-struct kwtable {const char *name; int id[2]; enum lex_state state;};
+struct kwtable {char *name; int id[2]; enum lex_state state;};
%%
__LINE__, {k__LINE__, k__LINE__}, EXPR_END
__FILE__, {k__FILE__, k__FILE__}, EXPR_END
diff --git a/lex.c b/lex.c
index a15309d502..79d9448dae 100644
--- a/lex.c
+++ b/lex.c
@@ -1,6 +1,6 @@
/* C code produced by gperf version 2.7.2 */
/* Command-line: gperf -p -j1 -i 1 -g -o -t -N rb_reserved_word -k'1,3,$' ./keywords */
-struct kwtable {const char *name; int id[2]; enum lex_state state;};
+struct kwtable {char *name; int id[2]; enum lex_state state;};
#define TOTAL_KEYWORDS 40
#define MIN_WORD_LENGTH 2
diff --git a/lib/README b/lib/README
index fa2bbd9635..d60c5cb1e9 100644
--- a/lib/README
+++ b/lib/README
@@ -49,7 +49,7 @@ open3.rb opens subprocess connection stdin/stdout/stderr
optparse.rb command line option analysis
ostruct.rb python style object
parsearg.rb argument parser using getopts
-parsedate.rb parses date string (obsolete)
+parsedate.rb parses date string
pathname.rb Object-Oriented Pathname Class
ping.rb checks whether host is up, using TCP echo.
pp.rb pretty print objects
@@ -59,7 +59,7 @@ profiler.rb ruby profiler module
pstore.rb persistent object strage using marshal
racc/parser.rb racc (Ruby yACC) runtime
rational.rb rational number support
-rdoc source-code documentation tool
+rdoc source-code documentation tool
readbytes.rb define IO#readbytes
resolv-replace.rb replace Socket DNS by resolve.rb
resolv.rb DNS resolver in Ruby
diff --git a/lib/benchmark.rb b/lib/benchmark.rb
index a54700a1c2..36e593518f 100644
--- a/lib/benchmark.rb
+++ b/lib/benchmark.rb
@@ -304,10 +304,7 @@ module Benchmark
# Returns the elapsed real time used to execute the given block.
#
def realtime(&blk) # :yield:
- r0 = Time.now
- yield
- r1 = Time.now
- r1.to_f - r0.to_f
+ Benchmark::measure(&blk).real
end
@@ -333,8 +330,8 @@ module Benchmark
# Registers the given label and block pair in the job list.
#
def item(label = "", &blk) # :yield:
- raise ArgumentError, "no block" unless block_given?
- label += ' '
+ raise ArgmentError, "no block" unless block_given?
+ label.concat ' '
w = label.length
@width = w if @width < w
@list.push [label, blk]
diff --git a/lib/cgi.rb b/lib/cgi.rb
index 5279439a08..a442d44930 100644
--- a/lib/cgi.rb
+++ b/lib/cgi.rb
@@ -792,16 +792,11 @@ class CGI
#
# These keywords correspond to attributes of the cookie object.
def initialize(name = "", *value)
- if name.kind_of?(String)
- @name = name
- @value = value
- %r|^(.*/)|.match(ENV["SCRIPT_NAME"])
- @path = ($1 or "")
- @secure = false
- return super(@value)
- end
-
- options = name
+ options = if name.kind_of?(String)
+ { "name" => name, "value" => value }
+ else
+ name
+ end
unless options.has_key?("name")
raise ArgumentError, "`name' required"
end
@@ -885,7 +880,7 @@ class CGI
if cookies.has_key?(name)
values = cookies[name].value + values
end
- cookies[name] = Cookie::new(name, *values)
+ cookies[name] = Cookie::new({ "name" => name, "value" => values })
end
cookies
@@ -1037,13 +1032,13 @@ class CGI
if "--" == $2
content_length = -1
end
- boundary_end = $2.dup
+ boundary_end = $2.dup
""
end
body.rewind
- /Content-Disposition:.* filename=(?:"((?:\\.|[^\"])*)"|([^;\s]*))/ni.match(head)
+ /Content-Disposition:.* filename=(?:"((?:\\.|[^\"])*)"|([^;]*))/ni.match(head)
filename = ($1 or $2 or "")
if /Mac/ni.match(env_table['HTTP_USER_AGENT']) and
/Mozilla/ni.match(env_table['HTTP_USER_AGENT']) and
@@ -1051,7 +1046,7 @@ class CGI
filename = CGI::unescape(filename)
end
- /Content-Type: ([^\s]*)/ni.match(head)
+ /Content-Type: (.*)/ni.match(head)
content_type = ($1 or "")
(class << body; self; end).class_eval do
@@ -1060,7 +1055,7 @@ class CGI
define_method(:content_type) {content_type.dup.taint}
end
- /Content-Disposition:.* name="?([^\";\s]*)"?/ni.match(head)
+ /Content-Disposition:.* name="?([^\";]*)"?/ni.match(head)
name = $1.dup
if params.has_key?(name)
diff --git a/lib/cgi/session.rb b/lib/cgi/session.rb
index a6e999bc34..82eb7534d8 100644
--- a/lib/cgi/session.rb
+++ b/lib/cgi/session.rb
@@ -174,22 +174,16 @@ class CGI
# is used internally for automatically generated
# session ids.
def create_new_id
- require 'securerandom'
- begin
- session_id = SecureRandom.hex(16)
- rescue NotImplementedError
- require 'digest/md5'
- md5 = Digest::MD5::new
- now = Time::now
- md5.update(now.to_s)
- md5.update(String(now.usec))
- md5.update(String(rand(0)))
- md5.update(String($$))
- md5.update('foobar')
- session_id = md5.hexdigest
- end
+ require 'digest/md5'
+ md5 = Digest::MD5::new
+ now = Time::now
+ md5.update(now.to_s)
+ md5.update(String(now.usec))
+ md5.update(String(rand(0)))
+ md5.update(String($$))
+ md5.update('foobar')
@new_session = true
- session_id
+ md5.hexdigest
end
private :create_new_id
@@ -230,7 +224,7 @@ class CGI
# session_path:: the path for which this session applies. Defaults
# to the directory of the CGI script.
#
- # +option+ is also passed on to the session storage class initializer; see
+ # +option+ is also passed on to the session storage class initialiser; see
# the documentation for each session storage class for the options
# they support.
#
@@ -357,7 +351,7 @@ class CGI
# characters; automatically generated session ids observe
# this requirement.
#
- # +option+ is a hash of options for the initializer. The
+ # +option+ is a hash of options for the initialiser. The
# following options are recognised:
#
# tmpdir:: the directory to use for storing the FileStore
@@ -397,9 +391,8 @@ class CGI
unless @hash
@hash = {}
begin
- lockf = File.open(@path+".lock", "r")
- lockf.flock File::LOCK_SH
f = File.open(@path, 'r')
+ f.flock File::LOCK_SH
for line in f
line.chomp!
k, v = line.split('=',2)
@@ -407,7 +400,6 @@ class CGI
end
ensure
f.close unless f.nil?
- lockf.close if lockf
end
end
@hash
@@ -417,17 +409,13 @@ class CGI
def update
return unless @hash
begin
- lockf = File.open(@path+".lock", File::CREAT|File::RDWR, 0600)
- lockf.flock File::LOCK_EX
- f = File.open(@path+".new", File::CREAT|File::TRUNC|File::WRONLY, 0600)
+ f = File.open(@path, File::CREAT|File::TRUNC|File::RDWR, 0600)
+ f.flock File::LOCK_EX
for k,v in @hash
f.printf "%s=%s\n", CGI::escape(k), CGI::escape(String(v))
end
- f.close
- File.rename @path+".new", @path
ensure
- f.close if f and !f.closed?
- lockf.close if lockf
+ f.close unless f.nil?
end
end
@@ -438,8 +426,6 @@ class CGI
# Close and delete the session's FileStore file.
def delete
- File::unlink @path+".lock" rescue nil
- File::unlink @path+".new" rescue nil
File::unlink @path
rescue Errno::ENOENT
end
diff --git a/lib/cgi/session/pstore.rb b/lib/cgi/session/pstore.rb
index 3d204d5dc0..bd93d0a6ff 100644
--- a/lib/cgi/session/pstore.rb
+++ b/lib/cgi/session/pstore.rb
@@ -30,7 +30,7 @@ class CGI
# characters; automatically generated session ids observe
# this requirement.
#
- # +option+ is a hash of options for the initializer. The
+ # +option+ is a hash of options for the initialiser. The
# following options are recognised:
#
# tmpdir:: the directory to use for storing the PStore
diff --git a/lib/complex.rb b/lib/complex.rb
index fbf50ffece..9300f391e8 100644
--- a/lib/complex.rb
+++ b/lib/complex.rb
@@ -102,8 +102,6 @@ class Complex < Numeric
@RCS_ID='-$Id: complex.rb,v 1.3 1998/07/08 10:05:28 keiju Exp keiju $-'
undef step
- undef div, divmod
- undef floor, truncate, ceil, round
def Complex.generic?(other) # :nodoc:
other.kind_of?(Integer) or
@@ -196,10 +194,6 @@ class Complex < Numeric
end
end
- def quo(other)
- Complex(@real.quo(1), @image.quo(1)) / other
- end
-
#
# Raise this complex number to the given (real or complex) power.
#
@@ -415,34 +409,8 @@ class Complex < Numeric
end
-class Integer
-
- unless defined?(1.numerator)
- def numerator() self end
- def denominator() 1 end
-
- def gcd(other)
- min = self.abs
- max = other.abs
- while min > 0
- tmp = min
- min = max % min
- max = tmp
- end
- max
- end
-
- def lcm(other)
- if self.zero? or other.zero?
- 0
- else
- (self.div(self.gcd(other)) * other).abs
- end
- end
- end
-end
module Math
alias sqrt! sqrt
diff --git a/lib/date.rb b/lib/date.rb
index 90a4a01ca3..6da4d6aa8e 100644
--- a/lib/date.rb
+++ b/lib/date.rb
@@ -1,12 +1,12 @@
#
# date.rb - date and time library
#
-# Author: Tadayoshi Funaba 1998-2008
+# Author: Tadayoshi Funaba 1998-2006
#
# Documentation: William Webber <william@williamwebber.com>
#
#--
-# $Id: date.rb,v 2.37 2008-01-17 20:16:31+09 tadf Exp $
+# $Id: date.rb,v 2.30 2006-12-30 21:43:41+09 tadf Exp $
#++
#
# == Overview
@@ -250,7 +250,7 @@ class Date
ABBR_DAYNAMES = %w(Sun Mon Tue Wed Thu Fri Sat)
[MONTHNAMES, DAYNAMES, ABBR_MONTHNAMES, ABBR_DAYNAMES].each do |xs|
- xs.each{|x| x.freeze unless x.nil?}.freeze
+ xs.each{|x| x.freeze}.freeze
end
class Infinity < Numeric # :nodoc:
@@ -275,8 +275,8 @@ class Date
def <=> (other)
case other
- when Infinity; return d <=> other.d
- when Numeric; return d
+ when Infinity; d <=> other.d
+ when Numeric; d
else
begin
l, r = other.coerce(self)
@@ -313,20 +313,7 @@ class Date
# Gregorian calendar.
GREGORIAN = -Infinity.new
- HALF_DAYS_IN_DAY = Rational(1, 2) # :nodoc:
- HOURS_IN_DAY = Rational(1, 24) # :nodoc:
- MINUTES_IN_DAY = Rational(1, 1440) # :nodoc:
- SECONDS_IN_DAY = Rational(1, 86400) # :nodoc:
- MILLISECONDS_IN_DAY = Rational(1, 86400*10**3) # :nodoc:
- NANOSECONDS_IN_DAY = Rational(1, 86400*10**9) # :nodoc:
- MILLISECONDS_IN_SECOND = Rational(1, 10**3) # :nodoc:
- NANOSECONDS_IN_SECOND = Rational(1, 10**9) # :nodoc:
-
- MJD_EPOCH_IN_AJD = Rational(4800001, 2) # 1858-11-17 # :nodoc:
- UNIX_EPOCH_IN_AJD = Rational(4881175, 2) # 1970-01-01 # :nodoc:
- MJD_EPOCH_IN_CJD = 2400001 # :nodoc:
- UNIX_EPOCH_IN_CJD = 2440588 # :nodoc:
- LD_EPOCH_IN_CJD = 2299160 # :nodoc:
+ UNIXEPOCH = 2440588 # 1970-01-01 :nodoc:
# Does a given Julian Day Number fall inside the old-style (Julian)
# calendar?
@@ -489,7 +476,7 @@ class Date
#
# Returns the (civil) Julian Day Number as [day_number,
# fraction] where +fraction+ is always 1/2.
- def self.ajd_to_jd(ajd, of=0) (ajd + of + HALF_DAYS_IN_DAY).divmod(1) end
+ def self.ajd_to_jd(ajd, of=0) (ajd + of + 1.to_r/2).divmod(1) end
# Convert a (civil) Julian Day Number to an Astronomical Julian
# Day Number.
@@ -500,58 +487,46 @@ class Date
#
# Returns the Astronomical Julian Day Number as a single
# numeric value.
- def self.jd_to_ajd(jd, fr, of=0) jd + fr - of - HALF_DAYS_IN_DAY end
+ def self.jd_to_ajd(jd, fr, of=0) jd + fr - of - 1.to_r/2 end
# Convert a fractional day +fr+ to [hours, minutes, seconds,
# fraction_of_a_second]
def self.day_fraction_to_time(fr)
- ss, fr = fr.divmod(SECONDS_IN_DAY) # 4p
- h, ss = ss.divmod(3600)
- min, s = ss.divmod(60)
+ h, fr = fr.divmod(1.to_r/24)
+ min, fr = fr.divmod(1.to_r/1440)
+ s, fr = fr.divmod(1.to_r/86400)
return h, min, s, fr
end
# Convert an +h+ hour, +min+ minutes, +s+ seconds period
# to a fractional day.
- begin
- Rational(Rational(1, 2), 2) # a challenge
-
- def self.time_to_day_fraction(h, min, s)
- Rational(h * 3600 + min * 60 + s, 86400) # 4p
- end
- rescue
- def self.time_to_day_fraction(h, min, s)
- if Integer === h && Integer === min && Integer === s
- Rational(h * 3600 + min * 60 + s, 86400) # 4p
- else
- (h * 3600 + min * 60 + s).to_r/86400 # 4p
- end
- end
+ def self.time_to_day_fraction(h, min, s)
+ h.to_r/24 + min.to_r/1440 + s.to_r/86400
end
# Convert an Astronomical Modified Julian Day Number to an
# Astronomical Julian Day Number.
- def self.amjd_to_ajd(amjd) amjd + MJD_EPOCH_IN_AJD end
+ def self.amjd_to_ajd(amjd) amjd + 4800001.to_r/2 end
# Convert an Astronomical Julian Day Number to an
# Astronomical Modified Julian Day Number.
- def self.ajd_to_amjd(ajd) ajd - MJD_EPOCH_IN_AJD end
+ def self.ajd_to_amjd(ajd) ajd - 4800001.to_r/2 end
# Convert a Modified Julian Day Number to a Julian
# Day Number.
- def self.mjd_to_jd(mjd) mjd + MJD_EPOCH_IN_CJD end
+ def self.mjd_to_jd(mjd) mjd + 2400001 end
# Convert a Julian Day Number to a Modified Julian Day
# Number.
- def self.jd_to_mjd(jd) jd - MJD_EPOCH_IN_CJD end
+ def self.jd_to_mjd(jd) jd - 2400001 end
# Convert a count of the number of days since the adoption
# of the Gregorian Calendar (in Italy) to a Julian Day Number.
- def self.ld_to_jd(ld) ld + LD_EPOCH_IN_CJD end
+ def self.ld_to_jd(ld) ld + 2299160 end
# Convert a Julian Day Number to the number of days since
# the adoption of the Gregorian Calendar (in Italy).
- def self.jd_to_ld(jd) jd - LD_EPOCH_IN_CJD end
+ def self.jd_to_ld(jd) jd - 2299160 end
# Convert a Julian Day Number to the day of the week.
#
@@ -698,9 +673,9 @@ class Date
h += 24 if h < 0
min += 60 if min < 0
s += 60 if s < 0
- return unless ((0...24) === h &&
- (0...60) === min &&
- (0...60) === s) ||
+ return unless ((0..23) === h &&
+ (0..59) === min &&
+ (0..59) === s) ||
(24 == h &&
0 == min &&
0 == s)
@@ -793,7 +768,7 @@ class Date
h, fr = fr.divmod(3600)
min, fr = fr.divmod(60)
s, fr = fr.divmod(1)
- elem[:jd] = UNIX_EPOCH_IN_CJD + d
+ elem[:jd] = UNIXEPOCH + d
elem[:hour] = h
elem[:min] = min
elem[:sec] = s
@@ -1121,14 +1096,7 @@ class Date
# I do NOT recommend you to use this method.
def sec_fraction() time[3] end
-=begin
- alias_method :minute, :min
- alias_method :second, :sec
- alias_method :second_fraction, :sec_fraction
-=end
-
private :hour, :min, :sec, :sec_fraction
-# :minute, :second, :second_fraction
def zone() strftime('%:z') end
@@ -1213,7 +1181,7 @@ class Date
def new_offset(of=0)
if String === of
- of = Rational(zone_to_diff(of) || 0, 86400)
+ of = (self.class.zone_to_diff(of) || 0).to_r/86400
end
self.class.new!(@ajd, of, @sg)
end
@@ -1333,11 +1301,6 @@ class Date
# date at each step.
def step(limit, step=1) # :yield: date
=begin
- if step.zero?
- raise ArgumentError, "step can't be 0"
- end
-=end
-=begin
unless block_given?
return to_enum(:step, limit, step)
end
@@ -1377,14 +1340,14 @@ class Date
# Return the date as a human-readable string.
#
# The format used is YYYY-MM-DD.
- def to_s() format('%.4d-%02d-%02d', year, mon, mday) end # 4p
+ def to_s() strftime end
# Dump to Marshal format.
def _dump(limit) Marshal.dump([@ajd, @of, @sg], -1) end
# def self._load(str) new!(*Marshal.load(str)) end
- # Load from Marshal format.
+ # Load from Marshall format.
def self._load(str)
a = Marshal.load(str)
if a.size == 2
@@ -1469,7 +1432,7 @@ class DateTime < Date
raise ArgumentError, 'invalid date'
end
if String === of
- of = Rational(zone_to_diff(of) || 0, 86400)
+ of = (zone_to_diff(of) || 0).to_r/86400
end
new!(jd_to_ajd(jd, fr, of), of, sg)
end
@@ -1494,7 +1457,7 @@ class DateTime < Date
raise ArgumentError, 'invalid date'
end
if String === of
- of = Rational(zone_to_diff(of) || 0, 86400)
+ of = (zone_to_diff(of) || 0).to_r/86400
end
new!(jd_to_ajd(jd, fr, of), of, sg)
end
@@ -1519,7 +1482,7 @@ class DateTime < Date
raise ArgumentError, 'invalid date'
end
if String === of
- of = Rational(zone_to_diff(of) || 0, 86400)
+ of = (zone_to_diff(of) || 0).to_r/86400
end
new!(jd_to_ajd(jd, fr, of), of, sg)
end
@@ -1547,7 +1510,7 @@ class DateTime < Date
raise ArgumentError, 'invalid date'
end
if String === of
- of = Rational(zone_to_diff(of) || 0, 86400)
+ of = (zone_to_diff(of) || 0).to_r/86400
end
new!(jd_to_ajd(jd, fr, of), of, sg)
end
@@ -1558,7 +1521,7 @@ class DateTime < Date
raise ArgumentError, 'invalid date'
end
if String === of
- of = Rational(zone_to_diff(of) || 0, 86400)
+ of = (zone_to_diff(of) || 0).to_r/86400
end
new!(jd_to_ajd(jd, fr, of), of, sg)
end
@@ -1572,8 +1535,10 @@ class DateTime < Date
(fr = valid_time_frags?(elem))
raise ArgumentError, 'invalid date'
end
- fr += (elem[:sec_fraction] || 0) / 86400
- of = Rational(elem[:offset] || 0, 86400)
+ sf = (elem[:sec_fraction] || 0)
+ fr += sf/86400
+ of = (elem[:offset] || 0)
+ of = of.to_r/86400
new!(jd_to_ajd(jd, fr, of), of, sg)
end
@@ -1619,12 +1584,6 @@ class DateTime < Date
end
public :hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset
-# :minute, :second, :second_fraction
-
- def to_s # 4p
- format('%.4d-%02d-%02dT%02d:%02d:%02d%s',
- year, mon, mday, hour, min, sec, zone)
- end
end
@@ -1640,8 +1599,8 @@ class Time
def to_datetime
jd = DateTime.civil_to_jd(year, mon, mday, DateTime::ITALY)
fr = DateTime.time_to_day_fraction(hour, min, [sec, 59].min) +
- Rational(usec, 86400_000_000)
- of = Rational(utc_offset, 86400)
+ usec.to_r/86400000000
+ of = utc_offset.to_r/86400
DateTime.new!(DateTime.jd_to_ajd(jd, fr, of), of, DateTime::ITALY)
end
@@ -1694,42 +1653,6 @@ end
class Date
- class << self
-
- def deprecated_class_method_alias(old, new) # :nodoc:
- module_eval <<-"end;"
- class << self
- def #{old}(*args, &block)
- if $VERBOSE
- warn("\#{caller.shift.sub(/:in .*/, '')}: " \
- "warning: \#{self}::#{old} is deprecated; " \
- "use \#{self}::#{new}")
- end
- #{new}(*args, &block)
- end
- end
- end;
- end
-
- private :deprecated_class_method_alias
-
- def deprecated_alias(old, new) # :nodoc:
- module_eval <<-"end;"
- def #{old}(*args, &block)
- if $VERBOSE
- warn("\#{caller.shift.sub(/:in .*/, '')}: " \
- "warning: \#{self.class}\##{old} is deprecated; " \
- "use \#{self.class}\##{new}")
- end
- #{new}(*args, &block)
- end
- end;
- end
-
- private :deprecated_alias
-
- end
-
[ %w(os? julian?),
%w(ns? gregorian?),
%w(exist1? valid_jd?),
@@ -1743,7 +1666,16 @@ class Date
%w(new3 new),
%w(neww commercial)
].each do |old, new|
- deprecated_class_method_alias(old, new)
+ module_eval <<-"end;"
+ def self.#{old}(*args, &block)
+ if $VERBOSE
+ warn("\#{caller.shift.sub(/:in .*/, '')}: " \
+ "warning: \#{self}::#{old} is deprecated; " \
+ "use \#{self}::#{new}")
+ end
+ #{new}(*args, &block)
+ end
+ end;
end
[ %w(os? julian?),
@@ -1753,7 +1685,16 @@ class Date
%w(of offset),
%w(newof new_offset)
].each do |old, new|
- deprecated_alias(old, new)
+ module_eval <<-"end;"
+ def #{old}(*args, &block)
+ if $VERBOSE
+ warn("\#{caller.shift.sub(/:in .*/, '')}: " \
+ "warning: \#{self.class}\##{old} is deprecated; " \
+ "use \#{self.class}\##{new}")
+ end
+ #{new}(*args, &block)
+ end
+ end;
end
private :of, :newof
diff --git a/lib/date/format.rb b/lib/date/format.rb
index f89c1344a9..8bd14c7fd0 100644
--- a/lib/date/format.rb
+++ b/lib/date/format.rb
@@ -1,5 +1,5 @@
-# format.rb: Written by Tadayoshi Funaba 1999-2008
-# $Id: format.rb,v 2.43 2008-01-17 20:16:31+09 tadf Exp $
+# format.rb: Written by Tadayoshi Funaba 1999-2007
+# $Id: format.rb,v 2.30 2007-01-07 09:16:24+09 tadf Exp $
require 'rational'
@@ -40,33 +40,16 @@ class Date
'r' => -5*3600, 's' => -6*3600, 't' => -7*3600, 'u' => -8*3600,
'v' => -9*3600, 'w' =>-10*3600, 'x' =>-11*3600, 'y' =>-12*3600,
'z' => 0*3600,
-
- 'utc' => 0*3600, 'wet' => 0*3600,
- 'at' => -2*3600, 'brst'=> -2*3600, 'ndt' => -(2*3600+1800),
- 'art' => -3*3600, 'adt' => -3*3600, 'brt' => -3*3600, 'clst'=> -3*3600,
- 'nst' => -(3*3600+1800),
- 'ast' => -4*3600, 'clt' => -4*3600,
- 'akdt'=> -8*3600, 'ydt' => -8*3600,
- 'akst'=> -9*3600, 'hadt'=> -9*3600, 'hdt' => -9*3600, 'yst' => -9*3600,
- 'ahst'=>-10*3600, 'cat' =>-10*3600, 'hast'=>-10*3600, 'hst' =>-10*3600,
- 'nt' =>-11*3600,
- 'idlw'=>-12*3600,
- 'bst' => 1*3600, 'cet' => 1*3600, 'fwt' => 1*3600, 'met' => 1*3600,
- 'mewt'=> 1*3600, 'mez' => 1*3600, 'swt' => 1*3600, 'wat' => 1*3600,
- 'west'=> 1*3600,
- 'cest'=> 2*3600, 'eet' => 2*3600, 'fst' => 2*3600, 'mest'=> 2*3600,
- 'mesz'=> 2*3600, 'sast'=> 2*3600, 'sst' => 2*3600,
- 'bt' => 3*3600, 'eat' => 3*3600, 'eest'=> 3*3600, 'msk' => 3*3600,
- 'msd' => 4*3600, 'zp4' => 4*3600,
- 'zp5' => 5*3600, 'ist' => (5*3600+1800),
- 'zp6' => 6*3600,
- 'wast'=> 7*3600,
- 'cct' => 8*3600, 'sgt' => 8*3600, 'wadt'=> 8*3600,
- 'jst' => 9*3600, 'kst' => 9*3600,
- 'east'=> 10*3600, 'gst' => 10*3600,
- 'eadt'=> 11*3600,
- 'idle'=> 12*3600, 'nzst'=> 12*3600, 'nzt' => 12*3600,
- 'nzdt'=> 13*3600,
+ 'utc' => 0*3600, 'wet' => 0*3600, 'bst' => 1*3600, 'wat' => -1*3600,
+ 'at' => -2*3600, 'ast' => -4*3600, 'adt' => -3*3600, 'yst' => -9*3600,
+ 'ydt' => -8*3600, 'hst' =>-10*3600, 'hdt' => -9*3600, 'cat' =>-10*3600,
+ 'ahst'=>-10*3600, 'nt' =>-11*3600, 'idlw'=>-12*3600, 'cet' => 1*3600,
+ 'met' => 1*3600, 'mewt'=> 1*3600, 'mest'=> 2*3600, 'mesz'=> 2*3600,
+ 'swt' => 1*3600, 'sst' => 2*3600, 'fwt' => 1*3600, 'fst' => 2*3600,
+ 'eet' => 2*3600, 'bt' => 3*3600, 'zp4' => 4*3600, 'zp5' => 5*3600,
+ 'zp6' => 6*3600, 'wast'=> 7*3600, 'wadt'=> 8*3600, 'cct' => 8*3600,
+ 'jst' => 9*3600, 'east'=> 10*3600, 'eadt'=> 11*3600, 'gst' => 10*3600,
+ 'nzt' => 12*3600, 'nzst'=> 12*3600, 'nzdt'=> 13*3600, 'idle'=> 12*3600,
'afghanistan' => 16200, 'alaskan' => -32400,
'arab' => 10800, 'arabian' => 14400,
@@ -215,9 +198,8 @@ class Date
:emit_a, :emit_ad, :emit_au
def strftime(fmt='%F')
- fmt.gsub(/%([-_0^#]+)?(\d+)?([EO]?(?::{1,3}z|.))/m) do |m|
+ fmt.gsub(/%([-_0^#]+)?(\d+)?[EO]?(:{1,3}z|.)/m) do |m|
f = {}
- a = $&
s, w, c = $1, $2, $3
if s
s.scan(/./) do |k|
@@ -238,11 +220,11 @@ class Date
when 'a'; emit_ad(ABBR_DAYNAMES[wday], 0, f)
when 'B'; emit_ad(MONTHNAMES[mon], 0, f)
when 'b'; emit_ad(ABBR_MONTHNAMES[mon], 0, f)
- when 'C', 'EC'; emit_sn((year / 100).floor, 2, f)
- when 'c', 'Ec'; emit_a(strftime('%a %b %e %H:%M:%S %Y'), 0, f)
+ when 'C'; emit_sn((year / 100).floor, 2, f)
+ when 'c'; emit_a(strftime('%a %b %e %H:%M:%S %Y'), 0, f)
when 'D'; emit_a(strftime('%m/%d/%y'), 0, f)
- when 'd', 'Od'; emit_n(mday, 2, f)
- when 'e', 'Oe'; emit_a(mday, 2, f)
+ when 'd'; emit_n(mday, 2, f)
+ when 'e'; emit_a(mday, 2, f)
when 'F'
if m == '%F'
format('%.4d-%02d-%02d', year, mon, mday) # 4p
@@ -251,29 +233,31 @@ class Date
end
when 'G'; emit_sn(cwyear, 4, f)
when 'g'; emit_n(cwyear % 100, 2, f)
- when 'H', 'OH'; emit_n(hour, 2, f)
+ when 'H'; emit_n(hour, 2, f)
when 'h'; emit_ad(strftime('%b'), 0, f)
- when 'I', 'OI'; emit_n((hour % 12).nonzero? || 12, 2, f)
+ when 'I'; emit_n((hour % 12).nonzero? || 12, 2, f)
when 'j'; emit_n(yday, 3, f)
when 'k'; emit_a(hour, 2, f)
when 'L'
- emit_n((sec_fraction / MILLISECONDS_IN_DAY).floor, 3, f)
+ emit_n((sec_fraction / (1.to_r/86400/(10**3))).round, 3, f)
when 'l'; emit_a((hour % 12).nonzero? || 12, 2, f)
- when 'M', 'OM'; emit_n(min, 2, f)
- when 'm', 'Om'; emit_n(mon, 2, f)
+ when 'M'; emit_n(min, 2, f)
+ when 'm'; emit_n(mon, 2, f)
when 'N'
- emit_n((sec_fraction / NANOSECONDS_IN_DAY).floor, 9, f)
+ emit_n((sec_fraction / (1.to_r/86400/(10**9))).round, 9, f)
when 'n'; "\n"
when 'P'; emit_ad(strftime('%p').downcase, 0, f)
when 'p'; emit_au(if hour < 12 then 'AM' else 'PM' end, 0, f)
when 'Q'
- s = ((ajd - UNIX_EPOCH_IN_AJD) / MILLISECONDS_IN_DAY).round
+ d = ajd - self.class.jd_to_ajd(self.class::UNIXEPOCH, 0)
+ s = (d * 86400*10**3).to_i
emit_sn(s, 1, f)
when 'R'; emit_a(strftime('%H:%M'), 0, f)
when 'r'; emit_a(strftime('%I:%M:%S %p'), 0, f)
- when 'S', 'OS'; emit_n(sec, 2, f)
+ when 'S'; emit_n(sec, 2, f)
when 's'
- s = ((ajd - UNIX_EPOCH_IN_AJD) / SECONDS_IN_DAY).round
+ d = ajd - self.class.jd_to_ajd(self.class::UNIXEPOCH, 0)
+ s = (d * 86400).to_i
emit_sn(s, 1, f)
when 'T'
if m == '%T'
@@ -282,24 +266,24 @@ class Date
emit_a(strftime('%H:%M:%S'), 0, f)
end
when 't'; "\t"
- when 'U', 'W', 'OU', 'OW'
- emit_n(if c[-1,1] == 'U' then wnum0 else wnum1 end, 2, f)
- when 'u', 'Ou'; emit_n(cwday, 1, f)
- when 'V', 'OV'; emit_n(cweek, 2, f)
+ when 'U', 'W'
+ emit_n(if c == 'U' then wnum0 else wnum1 end, 2, f)
+ when 'u'; emit_n(cwday, 1, f)
+ when 'V'; emit_n(cweek, 2, f)
when 'v'; emit_a(strftime('%e-%b-%Y'), 0, f)
- when 'w', 'Ow'; emit_n(wday, 1, f)
- when 'X', 'EX'; emit_a(strftime('%H:%M:%S'), 0, f)
- when 'x', 'Ex'; emit_a(strftime('%m/%d/%y'), 0, f)
- when 'Y', 'EY'; emit_sn(year, 4, f)
- when 'y', 'Ey', 'Oy'; emit_n(year % 100, 2, f)
+ when 'w'; emit_n(wday, 1, f)
+ when 'X'; emit_a(strftime('%H:%M:%S'), 0, f)
+ when 'x'; emit_a(strftime('%m/%d/%y'), 0, f)
+ when 'Y'; emit_sn(year, 4, f)
+ when 'y'; emit_n(year % 100, 2, f)
when 'Z'; emit_au(strftime('%:z'), 0, f)
when /\A(:{0,3})z/
t = $1.size
sign = if offset < 0 then -1 else +1 end
fr = offset.abs
- ss = fr.div(SECONDS_IN_DAY) # 4p
- hh, ss = ss.divmod(3600)
- mm, ss = ss.divmod(60)
+ hh, fr = fr.divmod(1.to_r/24)
+ mm, fr = fr.divmod(1.to_r/1440)
+ ss, fr = fr.divmod(1.to_r/86400)
if t == 3
if ss.nonzero? then t = 2
elsif mm.nonzero? then t = 1
@@ -342,7 +326,7 @@ class Date
end
emit_a(strftime('%F'), 0, f)
else
- a
+ c
end
end
end
@@ -381,12 +365,12 @@ class Date
end
def beat(n=0)
- i, f = (new_offset(HOURS_IN_DAY).day_fraction * 1000).divmod(1)
+ i, f = (new_offset(1.to_r/24).day_fraction * 1000).divmod(1)
('@%03d' % i) +
if n < 1
''
else
- '.%0*d' % [n, (f / Rational(1, 10**n)).round]
+ '.%0*d' % [n, (f / (1.to_r/(10**n))).round]
end
end
=end
@@ -398,8 +382,7 @@ class Date
private_class_method :num_pattern?
def self._strptime_i(str, fmt, e) # :nodoc:
- fmt.scan(/%([EO]?(?::{1,3}z|.))|(.)/m) do |s, c|
- a = $&
+ fmt.scan(/%[EO]?(:{1,3}z|.)|(.)/m) do |s, c|
if s
case s
when 'A', 'a'
@@ -414,18 +397,18 @@ class Date
val = Format::MONTHS[$1.downcase] || Format::ABBR_MONTHS[$1.downcase]
return unless val
e.mon = val
- when 'C', 'EC'
+ when 'C'
return unless str.sub!(if num_pattern?($')
then /\A([-+]?\d{1,2})/
else /\A([-+]?\d{1,})/
end, '')
val = $1.to_i
e._cent = val
- when 'c', 'Ec'
+ when 'c'
return unless _strptime_i(str, '%a %b %e %H:%M:%S %Y', e)
when 'D'
return unless _strptime_i(str, '%m/%d/%y', e)
- when 'd', 'e', 'Od', 'Oe'
+ when 'd', 'e'
return unless str.sub!(/\A( \d|\d{1,2})/, '')
val = $1.to_i
return unless (1..31) === val
@@ -445,12 +428,12 @@ class Date
return unless (0..99) === val
e.cwyear = val
e._cent ||= if val >= 69 then 19 else 20 end
- when 'H', 'k', 'OH'
+ when 'H', 'k'
return unless str.sub!(/\A( \d|\d{1,2})/, '')
val = $1.to_i
return unless (0..24) === val
e.hour = val
- when 'I', 'l', 'OI'
+ when 'I', 'l'
return unless str.sub!(/\A( \d|\d{1,2})/, '')
val = $1.to_i
return unless (1..12) === val
@@ -465,15 +448,15 @@ class Date
then /\A([-+]?\d{1,3})/
else /\A([-+]?\d{1,})/
end, '')
-# val = Rational($1.to_i, 10**3)
- val = Rational($1.to_i, 10**$1.size)
+# val = $1.to_i.to_r / (10**3)
+ val = $1.to_i.to_r / (10**$1.size)
e.sec_fraction = val
- when 'M', 'OM'
+ when 'M'
return unless str.sub!(/\A(\d{1,2})/, '')
val = $1.to_i
return unless (0..59) === val
e.min = val
- when 'm', 'Om'
+ when 'm'
return unless str.sub!(/\A(\d{1,2})/, '')
val = $1.to_i
return unless (1..12) === val
@@ -483,8 +466,8 @@ class Date
then /\A([-+]?\d{1,9})/
else /\A([-+]?\d{1,})/
end, '')
-# val = Rational($1.to_i, 10**9)
- val = Rational($1.to_i, 10**$1.size)
+# val = $1.to_i.to_r / (10**9)
+ val = $1.to_i.to_r / (10**$1.size)
e.sec_fraction = val
when 'n', 't'
return unless _strptime_i(str, "\s", e)
@@ -493,13 +476,13 @@ class Date
e._merid = if $1.downcase == 'a' then 0 else 12 end
when 'Q'
return unless str.sub!(/\A(-?\d{1,})/, '')
- val = Rational($1.to_i, 10**3)
+ val = $1.to_i.to_r / 10**3
e.seconds = val
when 'R'
return unless _strptime_i(str, '%H:%M', e)
when 'r'
return unless _strptime_i(str, '%I:%M:%S %p', e)
- when 'S', 'OS'
+ when 'S'
return unless str.sub!(/\A(\d{1,2})/, '')
val = $1.to_i
return unless (0..60) === val
@@ -510,17 +493,17 @@ class Date
e.seconds = val
when 'T'
return unless _strptime_i(str, '%H:%M:%S', e)
- when 'U', 'W', 'OU', 'OW'
+ when 'U', 'W'
return unless str.sub!(/\A(\d{1,2})/, '')
val = $1.to_i
return unless (0..53) === val
- e.__send__(if s[-1,1] == 'U' then :wnum0= else :wnum1= end, val)
- when 'u', 'Ou'
+ e.__send__(if s == 'U' then :wnum0= else :wnum1= end, val)
+ when 'u'
return unless str.sub!(/\A(\d{1})/, '')
val = $1.to_i
return unless (1..7) === val
e.cwday = val
- when 'V', 'OV'
+ when 'V'
return unless str.sub!(/\A(\d{1,2})/, '')
val = $1.to_i
return unless (1..53) === val
@@ -532,18 +515,18 @@ class Date
val = $1.to_i
return unless (0..6) === val
e.wday = val
- when 'X', 'EX'
+ when 'X'
return unless _strptime_i(str, '%H:%M:%S', e)
- when 'x', 'Ex'
+ when 'x'
return unless _strptime_i(str, '%m/%d/%y', e)
- when 'Y', 'EY'
+ when 'Y'
return unless str.sub!(if num_pattern?($')
then /\A([-+]?\d{1,4})/
else /\A([-+]?\d{1,})/
end, '')
val = $1.to_i
e.year = val
- when 'y', 'Ey', 'Oy'
+ when 'y'
return unless str.sub!(/\A(\d{1,2})/, '')
val = $1.to_i
return unless (0..99) === val
@@ -551,8 +534,8 @@ class Date
e._cent ||= if val >= 69 then 19 else 20 end
when 'Z', /\A:{0,3}z/
return unless str.sub!(/\A((?:gmt|utc?)?[-+]\d+(?:[,.:]\d+(?::\d+)?)?
- |[[:alpha:].\s]+(?:standard|daylight)\s+time\b
- |[[:alpha:]]+(?:\s+dst)?\b
+ |[a-z.\s]+(?:standard|daylight)\s+time\b
+ |[a-z]+(?:\s+dst)?\b
)/ix, '')
val = $1
e.zone = val
@@ -580,14 +563,14 @@ class Date
end
return unless _strptime_i(str, '%F', e)
else
- return unless str.sub!(Regexp.new('\\A' + Regexp.quote(a)), '')
+ return unless str.sub!(Regexp.new('\\A' + Regexp.quote(s)), '')
end
else
case c
when /\A[\s\v]/
str.sub!(/\A[\s\v]+/, '')
else
- return unless str.sub!(Regexp.new('\\A' + Regexp.quote(a)), '')
+ return unless str.sub!(Regexp.new('\\A' + Regexp.quote(c)), '')
end
end
end
@@ -596,9 +579,8 @@ class Date
private_class_method :_strptime_i
def self._strptime(str, fmt='%F')
- str = str.dup
e = Format::Bag.new
- return unless _strptime_i(str, fmt, e)
+ return unless _strptime_i(str.dup, fmt, e)
if e._cent
if e.cwyear
@@ -616,10 +598,6 @@ class Date
end
end
- unless str.empty?
- e.leftover = str
- end
-
e.to_hash
end
@@ -628,10 +606,6 @@ class Date
m = m.to_s
end
- if y && m && !d
- y, m, d = d, y, m
- end
-
if y == nil
if d && d.size > 2
y = d
@@ -727,9 +701,9 @@ class Date
(
(?:gmt|utc?)?[-+]\d+(?:[,.:]\d+(?::\d+)?)?
|
- [[:alpha:].\s]+(?:standard|daylight)\stime\b
+ [a-z.\s]+(?:standard|daylight)\stime\b
|
- [[:alpha:]]+(?:\sdst)?\b
+ [a-z]+(?:\sdst)?\b
)
)?
/inx,
@@ -749,7 +723,7 @@ class Date
e.hour = $1.to_i
e.min = $2.to_i if $2
e.sec = $3.to_i if $3
- e.sec_fraction = Rational($4.to_i, 10**$4.size) if $4
+ e.sec_fraction = $4.to_i.to_r / (10**$4.size) if $4
if $5
e.hour %= 12
@@ -761,12 +735,11 @@ class Date
end
end
-=begin
def self._parse_beat(str, e) # :nodoc:
if str.sub!(/@\s*(\d+)(?:[,.](\d*))?/, ' ')
- beat = Rational($1.to_i)
- beat += Rational($2.to_i, 10**$2.size) if $2
- secs = Rational(beat, 1000)
+ beat = $1.to_i.to_r
+ beat += $2.to_i.to_r / (10**$2.size) if $2
+ secs = beat.to_r / 1000
h, min, s, fr = self.day_fraction_to_time(secs)
e.hour = h
e.min = min
@@ -776,7 +749,6 @@ class Date
true
end
end
-=end
def self._parse_eu(str, e) # :nodoc:
if str.sub!(
@@ -824,36 +796,28 @@ class Date
end
def self._parse_iso2(str, e) # :nodoc:
- if str.sub!(/\b(\d{2}|\d{4})?-?w(\d{2})(?:-?(\d))?\b/in, ' ')
+ if str.sub!(/\b(\d{2}|\d{4})?-?w(\d{2})(?:-?(\d+))?/in, ' ')
e.cwyear = $1.to_i if $1
e.cweek = $2.to_i
e.cwday = $3.to_i if $3
true
- elsif str.sub!(/-w-(\d)\b/in, ' ')
- e.cwday = $1.to_i
- true
- elsif str.sub!(/--(\d{2})?-(\d{2})\b/n, ' ')
- e.mon = $1.to_i if $1
- e.mday = $2.to_i
- true
- elsif str.sub!(/--(\d{2})(\d{2})?\b/n, ' ')
+ elsif str.sub!(/--(\d{2})-(\d{2})\b/n, ' ')
e.mon = $1.to_i
- e.mday = $2.to_i if $2
+ e.mday = $2.to_i
true
- elsif /[,.](\d{2}|\d{4})-\d{3}\b/n !~ str &&
- str.sub!(/\b(\d{2}|\d{4})-(\d{3})\b/n, ' ')
+ elsif str.sub!(/\b(\d{2}|\d{4})-(\d{2,3})\b/n, ' ')
e.year = $1.to_i
- e.yday = $2.to_i
- true
- elsif /\d-\d{3}\b/n !~ str &&
- str.sub!(/\b-(\d{3})\b/n, ' ')
- e.yday = $1.to_i
+ if $2.size < 3
+ e.mon = $2.to_i
+ else
+ e.yday = $2.to_i
+ end
true
end
end
def self._parse_jis(str, e) # :nodoc:
- if str.sub!(/\b([mtsh])(\d+)\.(\d+)\.(\d+)/in, ' ')
+ if str.sub!(/\b([MTSH])(\d+)\.(\d+)\.(\d+)/in, ' ')
era = { 'm'=>1867,
't'=>1911,
's'=>1925,
@@ -878,22 +842,29 @@ class Date
end
end
- def self._parse_sla(str, e) # :nodoc:
- if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:\D\s*('?-?\d+))?|n, ' ') # '
- s3e(e, $3, $1, $2)
+ def self._parse_sla_ja(str, e) # :nodoc:
+ if str.sub!(%r|('?-?\d+)[/.]\s*('?\d+)(?:[^\d]\s*('?-?\d+))?|n, ' ') # '
+ s3e(e, $1, $2, $3)
true
end
end
- def self._parse_dot(str, e) # :nodoc:
- if str.sub!(%r|('?-?\d+)\.\s*('?\d+)\.\s*('?-?\d+)|n, ' ') # '
- s3e(e, $1, $2, $3)
+ def self._parse_sla_eu(str, e) # :nodoc:
+ if str.sub!(%r|('?-?\d+)[/.]\s*('?\d+)(?:[^\d]\s*('?-?\d+))?|n, ' ') # '
+ s3e(e, $3, $2, $1)
+ true
+ end
+ end
+
+ def self._parse_sla_us(str, e) # :nodoc:
+ if str.sub!(%r|('?-?\d+)[/.]\s*('?\d+)(?:[^\d]\s*('?-?\d+))?|n, ' ') # '
+ s3e(e, $3, $1, $2)
true
end
end
def self._parse_year(str, e) # :nodoc:
- if str.sub!(/'(\d+)\b/n, ' ')
+ if str.sub!(/'(\d+)\b/in, ' ')
e.year = $1.to_i
true
end
@@ -918,137 +889,70 @@ class Date
/([-+]?)(\d{2,14})
(?:
\s*
- t?
+ T?
\s*
- (\d{2,6})?(?:[,.](\d*))?
+ (\d{2,6})(?:[,.](\d*))?
)?
(?:
\s*
(
- z\b
+ Z
|
- [-+]\d{1,4}\b
- |
- \[[-+]?\d[^\]]*\]
+ [-+]\d{1,4}
)
+ \b
)?
/inx,
' ')
case $2.size
when 2
- if $3.nil? && $4
- e.sec = $2[-2, 2].to_i
- else
- e.mday = $2[ 0, 2].to_i
- end
+ e.mday = $2[ 0, 2].to_i
when 4
- if $3.nil? && $4
- e.sec = $2[-2, 2].to_i
- e.min = $2[-4, 2].to_i
- else
- e.mon = $2[ 0, 2].to_i
- e.mday = $2[ 2, 2].to_i
- end
+ e.mon = $2[ 0, 2].to_i
+ e.mday = $2[ 2, 2].to_i
when 6
- if $3.nil? && $4
- e.sec = $2[-2, 2].to_i
- e.min = $2[-4, 2].to_i
- e.hour = $2[-6, 2].to_i
- else
- e.year = ($1 + $2[ 0, 2]).to_i
- e.mon = $2[ 2, 2].to_i
- e.mday = $2[ 4, 2].to_i
- end
+ e.year = ($1 + $2[ 0, 2]).to_i
+ e.mon = $2[ 2, 2].to_i
+ e.mday = $2[ 4, 2].to_i
when 8, 10, 12, 14
- if $3.nil? && $4
- e.sec = $2[-2, 2].to_i
- e.min = $2[-4, 2].to_i
- e.hour = $2[-6, 2].to_i
- e.mday = $2[-8, 2].to_i
- if $2.size >= 10
- e.mon = $2[-10, 2].to_i
- end
- if $2.size == 12
- e.year = ($1 + $2[-12, 2]).to_i
- end
- if $2.size == 14
- e.year = ($1 + $2[-14, 4]).to_i
- e._comp = false
- end
- else
- e.year = ($1 + $2[ 0, 4]).to_i
- e.mon = $2[ 4, 2].to_i
- e.mday = $2[ 6, 2].to_i
- e.hour = $2[ 8, 2].to_i if $2.size >= 10
- e.min = $2[10, 2].to_i if $2.size >= 12
- e.sec = $2[12, 2].to_i if $2.size >= 14
- e._comp = false
- end
+ e.year = ($1 + $2[ 0, 4]).to_i
+ e.mon = $2[ 4, 2].to_i
+ e.mday = $2[ 6, 2].to_i
+ e.hour = $2[ 8, 2].to_i if $2.size >= 10
+ e.min = $2[10, 2].to_i if $2.size >= 12
+ e.sec = $2[12, 2].to_i if $2.size >= 14
+ e._comp = false
when 3
- if $3.nil? && $4
- e.sec = $2[-2, 2].to_i
- e.min = $2[-3, 1].to_i
- else
- e.yday = $2[ 0, 3].to_i
- end
+ e.yday = $2[ 0, 3].to_i
when 5
- if $3.nil? && $4
- e.sec = $2[-2, 2].to_i
- e.min = $2[-4, 2].to_i
- e.hour = $2[-5, 1].to_i
- else
- e.year = ($1 + $2[ 0, 2]).to_i
- e.yday = $2[ 2, 3].to_i
- end
+ e.year = ($1 + $2[ 0, 2]).to_i
+ e.yday = $2[ 2, 3].to_i
when 7
- if $3.nil? && $4
- e.sec = $2[-2, 2].to_i
- e.min = $2[-4, 2].to_i
- e.hour = $2[-6, 2].to_i
- e.mday = $2[-7, 1].to_i
- else
- e.year = ($1 + $2[ 0, 4]).to_i
- e.yday = $2[ 4, 3].to_i
- end
+ e.year = ($1 + $2[ 0, 4]).to_i
+ e.yday = $2[ 4, 3].to_i
end
if $3
- if $4
- case $3.size
- when 2, 4, 6
- e.sec = $3[-2, 2].to_i
- e.min = $3[-4, 2].to_i if $3.size >= 4
- e.hour = $3[-6, 2].to_i if $3.size >= 6
- end
- else
- case $3.size
- when 2, 4, 6
- e.hour = $3[ 0, 2].to_i
- e.min = $3[ 2, 2].to_i if $3.size >= 4
- e.sec = $3[ 4, 2].to_i if $3.size >= 6
- end
+ case $3.size
+ when 2, 4, 6
+ e.hour = $3[ 0, 2].to_i
+ e.min = $3[ 2, 2].to_i if $3.size >= 4
+ e.sec = $3[ 4, 2].to_i if $3.size >= 6
end
end
if $4
- e.sec_fraction = Rational($4.to_i, 10**$4.size)
+ e.sec_fraction = $4.to_i.to_r / (10**$4.size)
end
if $5
e.zone = $5
- if e.zone[0,1] == '['
- o, n, = e.zone[1..-2].split(':')
- e.zone = n || o
- if /\A\d/ =~ o
- o = format('+%s', o)
- end
- e.offset = zone_to_diff(o)
- end
end
true
end
end
- private_class_method :_parse_day, :_parse_time, # :_parse_beat,
+ private_class_method :_parse_day, :_parse_time, :_parse_beat,
:_parse_eu, :_parse_us, :_parse_iso, :_parse_iso2,
- :_parse_jis, :_parse_vms, :_parse_sla, :_parse_dot,
+ :_parse_jis, :_parse_vms,
+ :_parse_sla_ja, :_parse_sla_eu, :_parse_sla_us,
:_parse_year, :_parse_mon, :_parse_mday, :_parse_ddd
def self._parse(str, comp=false)
@@ -1058,7 +962,7 @@ class Date
e._comp = comp
- str.gsub!(/[^-+',.\/:@[:alnum:]\[\]\x80-\xff]+/n, ' ')
+ str.gsub!(/[^-+',.\/:0-9@a-z\x80-\xff]+/in, ' ')
_parse_time(str, e) # || _parse_beat(str, e)
_parse_day(str, e)
@@ -1068,8 +972,7 @@ class Date
_parse_iso(str, e) ||
_parse_jis(str, e) ||
_parse_vms(str, e) ||
- _parse_sla(str, e) ||
- _parse_dot(str, e) ||
+ _parse_sla_us(str, e) ||
_parse_iso2(str, e) ||
_parse_year(str, e) ||
_parse_mon(str, e) ||
@@ -1097,17 +1000,12 @@ class Date
end
end
- if e._comp
- if e.cwyear
- if e.cwyear >= 0 && e.cwyear <= 99
- e.cwyear += if e.cwyear >= 69
- then 1900 else 2000 end
- end
- end
- if e.year
- if e.year >= 0 && e.year <= 99
- e.year += if e.year >= 69
- then 1900 else 2000 end
+ if e._comp and e.year
+ if e.year >= 0 and e.year <= 99
+ if e.year >= 69
+ e.year += 1900
+ else
+ e.year += 2000
end
end
end
@@ -1133,7 +1031,7 @@ class Date
hour, min, sec, = zone.split(':')
elsif zone.include?(',') || zone.include?('.')
hour, fr, = zone.split(/[,.]/)
- min = Rational(fr.to_i, 10**fr.size) * 60
+ min = fr.to_i.to_r / (10**fr.size) * 60
else
case zone.size
when 3
@@ -1169,7 +1067,7 @@ class DateTime < Date
if n < 1
''
else
- '.%0*d' % [n, (sec_fraction / SECONDS_IN_DAY / (10**n)).round]
+ '.%0*d' % [n, (sec_fraction / (1.to_r/86400/(10**n))).round]
end +
'%:z')
end
diff --git a/lib/delegate.rb b/lib/delegate.rb
index bd2b5e4813..d810ccad42 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -115,7 +115,6 @@
# implementation, see SimpleDelegator.
#
class Delegator
- IgnoreBacktracePat = %r"\A#{Regexp.quote(__FILE__)}:\d+:in `"
#
# Pass in the _obj_ to delegate method calls to. All methods supported by
@@ -134,12 +133,14 @@ class Delegator
for method in obj.methods
next if preserved.include? method
begin
- eval <<-EOS, nil, __FILE__, __LINE__+1
+ eval <<-EOS
def self.#{method}(*args, &block)
begin
__getobj__.__send__(:#{method}, *args, &block)
- ensure
- $@.delete_if{|s|IgnoreBacktracePat=~s} if $@
+ rescue Exception
+ $@.delete_if{|s| /:in `__getobj__'$/ =~ s} #`
+ $@.delete_if{|s| /^\\(eval\\):/ =~ s}
+ Kernel::raise
end
end
EOS
@@ -163,9 +164,9 @@ class Delegator
# Checks for a method provided by this the delegate object by fowarding the
# call through \_\_getobj\_\_.
#
- def respond_to?(m, include_private = false)
+ def respond_to?(m)
return true if super
- return self.__getobj__.respond_to?(m, include_private)
+ return self.__getobj__.respond_to?(m)
end
#
@@ -227,15 +228,13 @@ class SimpleDelegator<Delegator
# Clone support for the object returned by \_\_getobj\_\_.
def clone
- new = super
- new.__setobj__(__getobj__.clone)
- new
+ super
+ __setobj__(__getobj__.clone)
end
# Duplication support for the object returned by \_\_getobj\_\_.
- def dup
- new = super
- new.__setobj__(__getobj__.clone)
- new
+ def dup(obj)
+ super
+ __setobj__(__getobj__.dup)
end
end
@@ -250,7 +249,7 @@ SimpleDelegater = SimpleDelegator
# your class.
#
# class MyClass < DelegateClass( ClassToDelegateTo ) # Step 1
-# def initialize
+# def initiaize
# super(obj_of_ClassToDelegateTo) # Step 2
# end
# end
@@ -270,9 +269,9 @@ def DelegateClass(superclass)
end
@_dc_obj.__send__(m, *args)
end
- def respond_to?(m, include_private = false) # :nodoc:
+ def respond_to?(m) # :nodoc:
return true if super
- return @_dc_obj.respond_to?(m, include_private)
+ return @_dc_obj.respond_to?(m)
end
def __getobj__ # :nodoc:
@_dc_obj
@@ -282,24 +281,23 @@ def DelegateClass(superclass)
@_dc_obj = obj
end
def clone # :nodoc:
- new = super
- new.__setobj__(__getobj__.clone)
- new
+ super
+ __setobj__(__getobj__.clone)
end
def dup # :nodoc:
- new = super
- new.__setobj__(__getobj__.clone)
- new
+ super
+ __setobj__(__getobj__.dup)
end
}
for method in methods
begin
- klass.module_eval <<-EOS, __FILE__, __LINE__+1
+ klass.module_eval <<-EOS
def #{method}(*args, &block)
begin
@_dc_obj.__send__(:#{method}, *args, &block)
- ensure
- $@.delete_if{|s| ::Delegator::IgnoreBacktracePat =~ s} if $@
+ rescue
+ $@[0,2] = nil
+ raise
end
end
EOS
diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb
index 20e658e611..25fbb3f788 100644
--- a/lib/drb/drb.rb
+++ b/lib/drb/drb.rb
@@ -578,7 +578,7 @@ module DRb
end
raise(DRbConnError, 'connection closed') if str.nil?
raise(DRbConnError, 'premature marshal format(can\'t read)') if str.size < sz
- DRb.mutex.synchronize do
+ Thread.exclusive do
begin
save = Thread.current[:drb_untaint]
Thread.current[:drb_untaint] = []
@@ -858,7 +858,6 @@ module DRb
def self.open_server(uri, config)
uri = 'druby://:0' unless uri
host, port, opt = parse_uri(uri)
- config = {:tcp_original_host => host}.update(config)
if host.size == 0
host = getservername
soc = open_server_inaddr_any(host, port)
@@ -866,7 +865,6 @@ module DRb
soc = TCPServer.open(host, port)
end
port = soc.addr[1] if port == 0
- config[:tcp_port] = port
uri = "druby://#{host}:#{port}"
self.new(uri, soc, config)
end
@@ -947,12 +945,7 @@ module DRb
break if (@acl ? @acl.allow_socket?(s) : true)
s.close
end
- if @config[:tcp_original_host].to_s.size == 0
- uri = "druby://#{s.addr[3]}:#{@config[:tcp_port]}"
- else
- uri = @uri
- end
- self.class.new(uri, s, @config)
+ self.class.new(nil, s, @config)
end
# Check to see if this connection is alive.
@@ -1673,12 +1666,6 @@ module DRb
#
# This is the URI of the current server. See #current_server.
def uri
- drb = Thread.current['DRb']
- client = (drb && drb['client'])
- if client
- uri = client.uri
- return uri if uri
- end
current_server.uri
end
module_function :uri
@@ -1751,16 +1738,10 @@ module DRb
end
module_function :install_acl
- @mutex = Mutex.new
- def mutex
- @mutex
- end
- module_function :mutex
-
@server = {}
def regist_server(server)
@server[server.uri] = server
- mutex.synchronize do
+ Thread.exclusive do
@primary_server = server unless @primary_server
end
end
diff --git a/lib/drb/extservm.rb b/lib/drb/extservm.rb
index be40aea9f5..7066f84c65 100644
--- a/lib/drb/extservm.rb
+++ b/lib/drb/extservm.rb
@@ -5,12 +5,10 @@
require 'drb/drb'
require 'thread'
-require 'monitor'
module DRb
class ExtServManager
include DRbUndumped
- include MonitorMixin
@@command = {}
@@ -23,8 +21,6 @@ module DRb
end
def initialize
- super()
- @cond = new_cond
@servers = {}
@waiting = []
@queue = Queue.new
@@ -34,26 +30,34 @@ module DRb
attr_accessor :uri
def service(name)
- synchronize do
- while true
- server = @servers[name]
- return server if server && server.alive?
- invoke_service(name)
- @cond.wait
- end
+ while true
+ server = nil
+ Thread.exclusive do
+ server = @servers[name] if @servers[name]
+ end
+ return server if server && server.alive?
+ invoke_service(name)
end
end
def regist(name, ro)
- synchronize do
- @servers[name] = ro
- @cond.signal
+ ary = nil
+ Thread.exclusive do
+ @servers[name] = ro
+ ary = @waiting
+ @waiting = []
+ end
+ ary.each do |th|
+ begin
+ th.run
+ rescue ThreadError
+ end
end
self
end
def unregist(name)
- synchronize do
+ Thread.exclusive do
@servers.delete(name)
end
end
@@ -69,12 +73,15 @@ module DRb
end
def invoke_service(name)
- @queue.push(name)
+ Thread.critical = true
+ @waiting.push Thread.current
+ @queue.push name
+ Thread.stop
end
def invoke_service_command(name, command)
raise "invalid command. name: #{name}" unless command
- synchronize do
+ Thread.exclusive do
return if @servers.include?(name)
@servers[name] = false
end
diff --git a/lib/erb.rb b/lib/erb.rb
index f1661f98cb..b714aa1ea6 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -240,7 +240,7 @@ class ERB
# Returns revision information for the erb.rb module.
def self.version
- "erb.rb [2.1.0 #{ERB::Revision.split[1]}]"
+ "erb.rb [2.0.4 #{ERB::Revision.split[1]}]"
end
end
@@ -254,13 +254,11 @@ class ERB
end
attr_reader :value
alias :to_s :value
-
- def empty?
- @value.empty?
- end
end
class Scanner # :nodoc:
+ SplitRegexp = /(<%%)|(%%>)|(<%=)|(<%#)|(<%)|(%>)|(\n)/
+
@scanner_map = {}
def self.regist_scanner(klass, trim_mode, percent)
@scanner_map[[trim_mode, percent]] = klass
@@ -285,6 +283,8 @@ class ERB
end
class TrimScanner < Scanner # :nodoc:
+ TrimSplitRegexp = /(<%%)|(%%>)|(<%=)|(<%#)|(<%)|(%>\n)|(%>)|(\n)/
+
def initialize(src, trim_mode, percent)
super
@trim_mode = trim_mode
@@ -308,7 +308,9 @@ class ERB
percent_line(line, &block)
end
else
- @scan_line.call(@src, &block)
+ @src.each do |line|
+ @scan_line.call(line, &block)
+ end
end
nil
end
@@ -327,66 +329,57 @@ class ERB
end
def scan_line(line)
- line.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>|\n|\z)/m) do |tokens|
- tokens.each do |token|
- next if token.empty?
- yield(token)
- end
+ line.split(SplitRegexp).each do |token|
+ next if token.empty?
+ yield(token)
end
end
def trim_line1(line)
- line.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>\n|%>|\n|\z)/m) do |tokens|
- tokens.each do |token|
- next if token.empty?
- if token == "%>\n"
- yield('%>')
- yield(:cr)
- else
- yield(token)
- end
- end
+ line.split(TrimSplitRegexp).each do |token|
+ next if token.empty?
+ if token == "%>\n"
+ yield('%>')
+ yield(:cr)
+ break
+ end
+ yield(token)
end
end
def trim_line2(line)
head = nil
- line.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>\n|%>|\n|\z)/m) do |tokens|
- tokens.each do |token|
- next if token.empty?
- head = token unless head
- if token == "%>\n"
- yield('%>')
- if is_erb_stag?(head)
- yield(:cr)
- else
- yield("\n")
- end
- head = nil
- else
- yield(token)
- head = nil if token == "\n"
- end
- end
+ line.split(TrimSplitRegexp).each do |token|
+ next if token.empty?
+ head = token unless head
+ if token == "%>\n"
+ yield('%>')
+ if is_erb_stag?(head)
+ yield(:cr)
+ else
+ yield("\n")
+ end
+ break
+ end
+ yield(token)
end
end
+ ExplicitTrimRegexp = /(^[ \t]*<%-)|(-%>\n?\z)|(<%-)|(-%>)|(<%%)|(%%>)|(<%=)|(<%#)|(<%)|(%>)|(\n)/
def explicit_trim_line(line)
- line.scan(/(.*?)(^[ \t]*<%\-|<%\-|<%%|%%>|<%=|<%#|<%|-%>\n|-%>|%>|\z)/m) do |tokens|
- tokens.each do |token|
- next if token.empty?
- if @stag.nil? && /[ \t]*<%-/ =~ token
- yield('<%')
- elsif @stag && token == "-%>\n"
- yield('%>')
- yield(:cr)
- elsif @stag && token == '-%>'
- yield('%>')
- else
- yield(token)
- end
- end
- end
+ line.split(ExplicitTrimRegexp).each do |token|
+ next if token.empty?
+ if @stag.nil? && /[ \t]*<%-/ =~ token
+ yield('<%')
+ elsif @stag && /-%>\n/ =~ token
+ yield('%>')
+ yield(:cr)
+ elsif @stag && token == '-%>'
+ yield('%>')
+ else
+ yield(token)
+ end
+ end
end
ERB_STAG = %w(<%= <%# <%)
@@ -399,11 +392,11 @@ class ERB
class SimpleScanner < Scanner # :nodoc:
def scan
- @src.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>|\n|\z)/m) do |tokens|
- tokens.each do |token|
- next if token.empty?
- yield(token)
- end
+ @src.each do |line|
+ line.split(SplitRegexp).each do |token|
+ next if token.empty?
+ yield(token)
+ end
end
end
end
@@ -414,47 +407,43 @@ class ERB
require 'strscan'
class SimpleScanner2 < Scanner # :nodoc:
def scan
- stag_reg = /(.*?)(<%%|<%=|<%#|<%|\z)/m
- etag_reg = /(.*?)(%%>|%>|\z)/m
+ stag_reg = /(.*?)(<%%|<%=|<%#|<%|\n|\z)/
+ etag_reg = /(.*?)(%%>|%>|\n|\z)/
scanner = StringScanner.new(@src)
while ! scanner.eos?
scanner.scan(@stag ? etag_reg : stag_reg)
- yield(scanner[1])
- yield(scanner[2])
+ text = scanner[1]
+ elem = scanner[2]
+ yield(text) unless text.empty?
+ yield(elem) unless elem.empty?
end
end
end
Scanner.regist_scanner(SimpleScanner2, nil, false)
class PercentScanner < Scanner # :nodoc:
- def scan(&blk)
- stag_reg = /(.*?)(^%%|^%|<%%|<%=|<%#|<%|\z)/m
- etag_reg = /(.*?)(%%>|%>|\z)/m
+ def scan
+ new_line = true
+ stag_reg = /(.*?)(<%%|<%=|<%#|<%|\n|\z)/
+ etag_reg = /(.*?)(%%>|%>|\n|\z)/
scanner = StringScanner.new(@src)
while ! scanner.eos?
+ if new_line && @stag.nil?
+ if scanner.scan(/%%/)
+ yield('%')
+ new_line = false
+ next
+ elsif scanner.scan(/%/)
+ yield(PercentLine.new(scanner.scan(/.*?(\n|\z)/).chomp))
+ next
+ end
+ end
scanner.scan(@stag ? etag_reg : stag_reg)
- yield(scanner[1])
-
+ text = scanner[1]
elem = scanner[2]
- if elem == '%%'
- yield('%')
- inline_scan(scanner.scan(/.*?(\n|\z)/), &blk)
- elsif elem == '%'
- yield(PercentLine.new(scanner.scan(/.*?(\n|\z)/).chomp))
- else
- yield(elem)
- end
- end
- end
-
- def inline_scan(line)
- stag_reg = /(.*?)(<%%|<%=|<%#|<%|\z)/m
- etag_reg = /(.*?)(%%>|%>|\z)/m
- scanner = StringScanner.new(line)
- while ! scanner.eos?
- scanner.scan(@stag ? etag_reg : stag_reg)
- yield(scanner[1])
- yield(scanner[2])
+ yield(text) unless text.empty?
+ yield(elem) unless elem.empty?
+ new_line = (elem == "\n")
end
end
end
@@ -462,21 +451,31 @@ class ERB
class ExplicitScanner < Scanner # :nodoc:
def scan
- stag_reg = /(.*?)(^[ \t]*<%-|<%%|<%=|<%#|<%-|<%|\z)/m
- etag_reg = /(.*?)(%%>|-%>|%>|\z)/m
+ new_line = true
+ stag_reg = /(.*?)(<%%|<%=|<%#|<%-|<%|\n|\z)/
+ etag_reg = /(.*?)(%%>|-%>|%>|\n|\z)/
scanner = StringScanner.new(@src)
while ! scanner.eos?
+ if new_line && @stag.nil? && scanner.scan(/[ \t]*<%-/)
+ yield('<%')
+ new_line = false
+ next
+ end
scanner.scan(@stag ? etag_reg : stag_reg)
- yield(scanner[1])
-
+ text = scanner[1]
elem = scanner[2]
- if /[ \t]*<%-/ =~ elem
- yield('<%')
- elsif elem == '-%>'
+ new_line = (elem == "\n")
+ yield(text) unless text.empty?
+ if elem == '-%>'
yield('%>')
- yield(:cr) if scanner.scan(/(\n|\z)/)
+ if scanner.scan(/(\n|\z)/)
+ yield(:cr)
+ new_line = true
+ end
+ elsif elem == '<%-'
+ yield('<%')
else
- yield(elem)
+ yield(elem) unless elem.empty?
end
end
end
@@ -517,27 +516,16 @@ class ERB
end
end
- def content_dump(s)
- n = s.count("\n")
- if n > 0
- s.dump + "\n" * n
- else
- s.dump
- end
- end
-
def compile(s)
out = Buffer.new(self)
content = ''
scanner = make_scanner(s)
scanner.scan do |token|
- next if token.nil?
- next if token == ''
if scanner.stag.nil?
case token
when PercentLine
- out.push("#{@put_cmd} #{content_dump(content)}") if content.size > 0
+ out.push("#{@put_cmd} #{content.dump}") if content.size > 0
content = ''
out.push(token.to_s)
out.cr
@@ -545,11 +533,12 @@ class ERB
out.cr
when '<%', '<%=', '<%#'
scanner.stag = token
- out.push("#{@put_cmd} #{content_dump(content)}") if content.size > 0
+ out.push("#{@put_cmd} #{content.dump}") if content.size > 0
content = ''
when "\n"
content << "\n"
- out.push("#{@put_cmd} #{content_dump(content)}")
+ out.push("#{@put_cmd} #{content.dump}")
+ out.cr
content = ''
when '<%%'
content << '<%'
@@ -571,7 +560,7 @@ class ERB
when '<%='
out.push("#{@insert_cmd}((#{content}).to_s)")
when '<%#'
- # out.push("# #{content_dump(content)}")
+ # out.push("# #{content.dump}")
end
scanner.stag = nil
content = ''
@@ -582,7 +571,7 @@ class ERB
end
end
end
- out.push("#{@put_cmd} #{content_dump(content)}") if content.size > 0
+ out.push("#{@put_cmd} #{content.dump}") if content.size > 0
out.close
out.script
end
@@ -669,7 +658,7 @@ class ERB
#
# def build
# b = binding
- # # create and run templates, filling member data variables
+ # # create and run templates, filling member data variebles
# ERB.new(<<-'END_PRODUCT'.gsub(/^\s+/, ""), 0, "", "@product").result b
# <%= PRODUCT[:name] %>
# <%= PRODUCT[:desc] %>
@@ -745,58 +734,29 @@ class ERB
#
def result(b=TOPLEVEL_BINDING)
if @safe_level
- proc {
+ th = Thread.start {
$SAFE = @safe_level
eval(@src, b, (@filename || '(erb)'), 1)
- }.call
+ }
+ return th.value
else
- eval(@src, b, (@filename || '(erb)'), 1)
+ return eval(@src, b, (@filename || '(erb)'), 1)
end
end
- # Define _methodname_ as instance method of _mod_ from compiled ruby source.
- #
- # example:
- # filename = 'example.rhtml' # 'arg1' and 'arg2' are used in example.rhtml
- # erb = ERB.new(File.read(filename))
- # erb.def_method(MyClass, 'render(arg1, arg2)', filename)
- # print MyClass.new.render('foo', 123)
- def def_method(mod, methodname, fname='(ERB)')
+ def def_method(mod, methodname, fname='(ERB)') # :nodoc:
mod.module_eval("def #{methodname}\n" + self.src + "\nend\n", fname, 0)
end
- # Create unnamed module, define _methodname_ as instance method of it, and return it.
- #
- # example:
- # filename = 'example.rhtml' # 'arg1' and 'arg2' are used in example.rhtml
- # erb = ERB.new(File.read(filename))
- # erb.filename = filename
- # MyModule = erb.def_module('render(arg1, arg2)')
- # class MyClass
- # include MyModule
- # end
- def def_module(methodname='erb')
+ def def_module(methodname='erb') # :nodoc:
mod = Module.new
- def_method(mod, methodname, @filename || '(ERB)')
+ def_method(mod, methodname)
mod
end
- # Define unnamed class which has _methodname_ as instance method, and return it.
- #
- # example:
- # class MyClass_
- # def initialize(arg1, arg2)
- # @arg1 = arg1; @arg2 = arg2
- # end
- # end
- # filename = 'example.rhtml' # @arg1 and @arg2 are used in example.rhtml
- # erb = ERB.new(File.read(filename))
- # erb.filename = filename
- # MyClass = erb.def_class(MyClass_, 'render()')
- # print MyClass.new('foo', 123).render()
- def def_class(superklass=Object, methodname='result')
+ def def_class(superklass=Object, methodname='result') # :nodoc:
cls = Class.new(superklass)
- def_method(cls, methodname, @filename || '(ERB)')
+ def_method(cls, methodname)
cls
end
end
@@ -850,45 +810,15 @@ end
#--
# ERB::DefMethod
class ERB
- # Utility module to define eRuby script as instance method.
- #
- # === Example
- #
- # example.rhtml:
- # <% for item in @items %>
- # <b><%= item %></b>
- # <% end %>
- #
- # example.rb:
- # require 'erb'
- # class MyClass
- # extend ERB::DefMethod
- # def_erb_method('render()', 'example.rhtml')
- # def initialize(items)
- # @items = items
- # end
- # end
- # print MyClass.new([10,20,30]).render()
- #
- # result:
- #
- # <b>10</b>
- #
- # <b>20</b>
- #
- # <b>30</b>
- #
- module DefMethod
+ module DefMethod # :nodoc:
public
- # define _methodname_ as instance method of current module, using ERB object or eRuby file
- def def_erb_method(methodname, erb_or_fname)
- if erb_or_fname.kind_of? String
- fname = erb_or_fname
- erb = ERB.new(File.read(fname))
- erb.def_method(self, methodname, fname)
+ def def_erb_method(methodname, erb)
+ if erb.kind_of? String
+ fname = erb
+ File.open(fname) {|f| erb = ERB.new(f.read) }
+ erb.def_method(self, methodname, fname)
else
- erb = erb_or_fname
- erb.def_method(self, methodname, erb.filename || '(ERB)')
+ erb.def_method(self, methodname)
end
end
module_function :def_erb_method
diff --git a/lib/forwardable.rb b/lib/forwardable.rb
index cc6e4ee418..b6344cd4f6 100644
--- a/lib/forwardable.rb
+++ b/lib/forwardable.rb
@@ -38,7 +38,7 @@
# @q = [ ] # prepare delegate object
# end
#
-# # setup preferred interface, enq() and deq()...
+# # setup prefered interface, enq() and deq()...
# def_delegator :@q, :push, :enq
# def_delegator :@q, :shift, :deq
#
diff --git a/lib/generator.rb b/lib/generator.rb
index dbdd0f40a9..a010559b60 100644
--- a/lib/generator.rb
+++ b/lib/generator.rb
@@ -165,44 +165,6 @@ class Generator
end
end
-class Enumerable::Enumerator
- def __generator
- @generator ||= Generator.new(self)
- end
- private :__generator
-
- # call-seq:
- # e.next => object
- #
- # Returns the next object in the enumerator, and move the internal
- # position forward. When the position reached at the end, internal
- # position is rewinded then StopIteration is raised.
- #
- # Note that enumeration sequence by next method does not affect other
- # non-external enumeration methods, unless underlying iteration
- # methods itself has side-effect, e.g. IO#each_line.
- #
- # Caution: This feature internally uses Generator, which uses callcc
- # to stop and resume enumeration to fetch each value. Use with care
- # and be aware of the performance loss.
- def next
- g = __generator
- return g.next unless g.end?
-
- g.rewind
- raise StopIteration, 'iteration reached at end'
- end
-
- # call-seq:
- # e.rewind => e
- #
- # Rewinds the enumeration sequence by the next method.
- def rewind
- __generator.rewind
- self
- end
-end
-
#
# SyncEnumerator creates an Enumerable object from multiple Enumerable
# objects and enumerates them synchronously.
diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb
index fe963e406c..17e47f016f 100644
--- a/lib/ipaddr.rb
+++ b/lib/ipaddr.rb
@@ -2,19 +2,14 @@
# ipaddr.rb - A class to manipulate an IP address
#
# Copyright (c) 2002 Hajimu UMEMOTO <ume@mahoroba.org>.
-# Copyright (c) 2007 Akinori MUSHA <knu@iDaemons.org>.
# All rights reserved.
#
# You can redistribute and/or modify it under the same terms as Ruby.
#
# $Id$
#
-# Contact:
-# - Akinori MUSHA <knu@iDaemons.org> (current maintainer)
-#
# TODO:
# - scope_id support
-#
require 'socket'
unless Socket.const_defined? "AF_INET6"
@@ -112,12 +107,12 @@ class IPAddr
# Returns a new ipaddr built by bitwise AND.
def &(other)
- return self.clone.set(@addr & coerce_other(other).to_i)
+ return self.clone.set(@addr & other.to_i)
end
# Returns a new ipaddr built by bitwise OR.
def |(other)
- return self.clone.set(@addr | coerce_other(other).to_i)
+ return self.clone.set(@addr | other.to_i)
end
# Returns a new ipaddr built by bitwise right-shift.
@@ -135,10 +130,12 @@ class IPAddr
return self.clone.set(addr_mask(~@addr))
end
- # Returns true if two ipaddrs are equal.
+ # Returns true if two ipaddr are equal.
def ==(other)
- other = coerce_other(other)
- return @family == other.family && @addr == other.to_i
+ if other.kind_of?(IPAddr) && @family != other.family
+ return false
+ end
+ return (@addr == other.to_i)
end
# Returns a new ipaddr built by masking IP address with the given
@@ -152,12 +149,10 @@ class IPAddr
# e.g.:
# require 'ipaddr'
# net1 = IPAddr.new("192.168.2.0/24")
- # net2 = IPAddr.new("192.168.2.100")
- # net3 = IPAddr.new("192.168.3.0")
- # p net1.include?(net2) #=> true
- # p net1.include?(net3) #=> false
+ # p net1.include?(IPAddr.new("192.168.2.0")) #=> true
+ # p net1.include?(IPAddr.new("192.168.2.255")) #=> true
+ # p net1.include?(IPAddr.new("192.168.3.0")) #=> false
def include?(other)
- other = coerce_other(other)
if ipv4_mapped?
if (@mask_addr >> 32) != 0xffffffffffffffffffffffff
return false
@@ -170,12 +165,17 @@ class IPAddr
addr = @addr
family = @family
end
- if other.ipv4_mapped?
- other_addr = (other.to_i & IN4MASK)
- other_family = Socket::AF_INET
- else
- other_addr = other.to_i
- other_family = other.family
+ if other.kind_of?(IPAddr)
+ if other.ipv4_mapped?
+ other_addr = (other.to_i & IN4MASK)
+ other_family = Socket::AF_INET
+ else
+ other_addr = other.to_i
+ other_family = other.family
+ end
+ else # Not IPAddr - assume integer in same family as us
+ other_addr = other.to_i
+ other_family = family
end
if family != other_family
@@ -316,37 +316,6 @@ class IPAddr
return _reverse + ".ip6.int"
end
- # Returns the successor to the ipaddr.
- def succ
- return self.clone.set(@addr + 1, @family)
- end
-
- # Compares the ipaddr with another.
- def <=>(other)
- other = coerce_other(other)
-
- return nil if other.family != @family
-
- return @addr <=> other.to_i
- end
- include Comparable
-
- # Creates a Range object for the network address.
- def to_range
- begin_addr = (@addr & @mask_addr)
-
- case @family
- when Socket::AF_INET
- end_addr = (@addr | (IN4MASK ^ @mask_addr))
- when Socket::AF_INET6
- end_addr = (@addr | (IN6MASK ^ @mask_addr))
- else
- raise "unsupported address family"
- end
-
- return clone.set(begin_addr, @family)..clone.set(end_addr, @family)
- end
-
# Returns a string containing a human-readable representation of the
# ipaddr. ("#<IPAddr: family:address/mask>")
def inspect
@@ -422,36 +391,22 @@ class IPAddr
private
- # Creates a new ipaddr object either from a human readable IP
- # address representation in string, or from a packed in_addr value
- # followed by an address family.
- #
- # In the former case, the following are the valid formats that will
- # be recognized: "address", "address/prefixlen" and "address/mask",
- # where IPv6 address may be enclosed in square brackets (`[' and
- # `]'). If a prefixlen or a mask is specified, it returns a masked
- # IP address. Although the address family is determined
- # automatically from a specified string, you can specify one
- # explicitly by the optional second argument.
- #
- # Otherwise an IP addess is generated from a packed in_addr value
- # and an address family.
+ # Creates a new ipaddr containing the given human readable form of
+ # an IP address. It also accepts `address/prefixlen' and
+ # `address/mask'. When prefixlen or mask is specified, it returns a
+ # masked ipaddr. IPv6 address may beenclosed with `[' and `]'.
#
- # The IPAddr class defines many methods and operators, and some of
- # those, such as &, |, include? and ==, accept a string, or a packed
- # in_addr value instead of an IPAddr object.
+ # Although an address family is determined automatically from a
+ # specified address, you can specify an address family explicitly by
+ # the optional second argument.
def initialize(addr = '::', family = Socket::AF_UNSPEC)
if !addr.kind_of?(String)
- case family
- when Socket::AF_INET, Socket::AF_INET6
- set(addr.to_i, family)
- @mask_addr = (family == Socket::AF_INET) ? IN4MASK : IN6MASK
- return
- when Socket::AF_UNSPEC
- raise ArgumentError, "address family must be specified"
- else
- raise ArgumentError, "unsupported address family: #{family}"
+ if family != Socket::AF_INET6 && family != Socket::AF_INET
+ raise ArgumentError, "unsupported address family"
end
+ set(addr, family)
+ @mask_addr = (family == Socket::AF_INET) ? IN4MASK : IN6MASK
+ return
end
prefix, prefixlen = addr.split('/')
if prefix =~ /^\[(.*)\]$/i
@@ -478,31 +433,23 @@ class IPAddr
@family = Socket::AF_INET6
end
if family != Socket::AF_UNSPEC && @family != family
- raise ArgumentError, "address family mismatch"
+ raise ArgumentError, "address family unmatch"
end
if prefixlen
mask!(prefixlen)
else
- @mask_addr = (@family == Socket::AF_INET) ? IN4MASK : IN6MASK
- end
- end
-
- def coerce_other(other)
- case other
- when IPAddr
- other
- when String
- self.class.new(other)
- else
- self.class.new(other, @family)
+ @mask_addr = (family == Socket::AF_INET) ? IN4MASK : IN6MASK
end
end
def in_addr(addr)
if addr =~ /^\d+\.\d+\.\d+\.\d+$/
- return addr.split('.').inject(0) { |i, s|
- i << 8 | s.to_i
+ n = 0
+ addr.split('.').each { |i|
+ n <<= 8
+ n += i.to_i
}
+ return n
end
return nil
end
@@ -526,20 +473,25 @@ class IPAddr
if rest < 0
return nil
end
- return (l + Array.new(rest, '0') + r).inject(0) { |i, s|
- i << 16 | s.hex
+ a = [l, Array.new(rest, '0'), r].flatten!
+ n = 0
+ a.each { |i|
+ n <<= 16
+ n += i.hex
}
+ return n
end
def addr_mask(addr)
case @family
when Socket::AF_INET
- return addr & IN4MASK
+ addr &= IN4MASK
when Socket::AF_INET6
- return addr & IN6MASK
+ addr &= IN6MASK
else
raise "unsupported address family"
end
+ return addr
end
def _reverse
diff --git a/lib/irb.rb b/lib/irb.rb
index 7580e39d43..1fb4397e68 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -149,15 +149,10 @@ module IRB
line.untaint
@context.evaluate(line, line_no)
output_value if @context.echo?
- exc = nil
- rescue Interrupt => exc
- rescue SystemExit, SignalException
- raise
- rescue Exception => exc
- end
- if exc
- print exc.class, ": ", exc, "\n"
- if exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/
+ rescue StandardError, ScriptError, Abort
+ $! = RuntimeError.new("unknown exception raised") unless $!
+ print $!.class, ": ", $!, "\n"
+ if $@[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && $!.class.to_s !~ /^IRB/
irb_bug = true
else
irb_bug = false
@@ -166,7 +161,7 @@ module IRB
messages = []
lasts = []
levels = 0
- for m in exc.backtrace
+ for m in $@
m = @context.workspace.filter_backtrace(m) unless irb_bug
if m
if messages.size < @context.back_trace_limit
@@ -188,7 +183,8 @@ module IRB
print "Maybe IRB bug!!\n" if irb_bug
end
if $SAFE > 2
- abort "Error: irb does not work for $SAFE level higher than 2"
+ warn "Error: irb does not work for $SAFE level higher than 2"
+ exit 1
end
end
end
diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb
index 508721c11d..8994f2f8d2 100644
--- a/lib/irb/extend-command.rb
+++ b/lib/irb/extend-command.rb
@@ -112,7 +112,7 @@ module IRB
end
end
- # aliases = [commands_alias, flag], ...
+ # aliases = [commans_alias, flag], ...
def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
case cmd_class
when Symbol
diff --git a/lib/irb/help.rb b/lib/irb/help.rb
index 4921de6ec9..f091999bd1 100644
--- a/lib/irb/help.rb
+++ b/lib/irb/help.rb
@@ -1,5 +1,5 @@
#
-# irb/help.rb - print usage module
+# irb/help.rb - print usase module
# $Release Version: 0.9.5$
# $Revision$
# $Date$
diff --git a/lib/irb/notifier.rb b/lib/irb/notifier.rb
index 0f79bc5a8d..c8e66fa859 100644
--- a/lib/irb/notifier.rb
+++ b/lib/irb/notifier.rb
@@ -1,5 +1,5 @@
#
-# notifier.rb - output methods used by irb
+# notifier.rb - optput methods used by irb
# $Release Version: 0.9.5$
# $Revision$
# $Date$
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index 313a809ccd..ab584d5253 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -1,5 +1,5 @@
#
-# irb/ruby-lex.rb - ruby lexcal analyzer
+# irb/ruby-lex.rb - ruby lexcal analizer
# $Release Version: 0.9.5$
# $Revision$
# $Date$
diff --git a/lib/irb/slex.rb b/lib/irb/slex.rb
index f7e3a3b2b2..a6ea6fb473 100644
--- a/lib/irb/slex.rb
+++ b/lib/irb/slex.rb
@@ -1,5 +1,5 @@
#
-# irb/slex.rb - simple lex analyzer
+# irb/slex.rb - symple lex analizer
# $Release Version: 0.9.5$
# $Revision$
# $Date$
diff --git a/lib/logger.rb b/lib/logger.rb
index 9030fa1d0d..60e72424ad 100644
--- a/lib/logger.rb
+++ b/lib/logger.rb
@@ -1,4 +1,4 @@
-# logger.rb - simple logging utility
+# logger.rb - saimple logging utility
# Copyright (C) 2000-2003, 2005 NAKAMURA, Hiroshi <nakahiro@sarion.co.jp>.
require 'monitor'
diff --git a/lib/matrix.rb b/lib/matrix.rb
index 470db19b05..c62acdf9aa 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -590,21 +590,15 @@ class Matrix
a = src.to_a
for k in 0..size
- i = k
- akk = a[k][k].abs
- for j in (k+1)..size
- v = a[j][k].abs
- if v > akk
- i = j
- akk = v
- end
- end
- Matrix.Raise ErrNotRegular if akk == 0
- if i != k
+ if (akk = a[k][k]) == 0
+ i = k
+ begin
+ Matrix.Raise ErrNotRegular if (i += 1) > size
+ end while a[i][k] == 0
a[i], a[k] = a[k], a[i]
@rows[i], @rows[k] = @rows[k], @rows[i]
+ akk = a[k][k]
end
- akk = a[k][k]
for i in 0 .. size
next if i == k
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index a532b5c0a8..f02003fb27 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -51,9 +51,6 @@ $archdir = CONFIG["archdir"]
$sitedir = CONFIG["sitedir"]
$sitelibdir = CONFIG["sitelibdir"]
$sitearchdir = CONFIG["sitearchdir"]
-$vendordir = CONFIG["vendordir"]
-$vendorlibdir = CONFIG["vendorlibdir"]
-$vendorarchdir = CONFIG["vendorarchdir"]
$mswin = /mswin/ =~ RUBY_PLATFORM
$bccwin = /bccwin/ =~ RUBY_PLATFORM
@@ -66,8 +63,6 @@ $beos = /beos/ =~ RUBY_PLATFORM
$solaris = /solaris/ =~ RUBY_PLATFORM
$dest_prefix_pattern = (File::PATH_SEPARATOR == ';' ? /\A([[:alpha:]]:)?/ : /\A/)
-# :stopdoc:
-
def config_string(key, config = CONFIG)
s = config[key] and !s.empty? and block_given? ? yield(s) : s
end
@@ -78,21 +73,16 @@ end
INSTALL_DIRS = [
[dir_re('commondir'), "$(RUBYCOMMONDIR)"],
- [dir_re('sitedir'), "$(RUBYCOMMONDIR)"],
- [dir_re('vendordir'), "$(RUBYCOMMONDIR)"],
+ [dir_re("sitedir"), "$(RUBYCOMMONDIR)"],
[dir_re('rubylibdir'), "$(RUBYLIBDIR)"],
[dir_re('archdir'), "$(RUBYARCHDIR)"],
[dir_re('sitelibdir'), "$(RUBYLIBDIR)"],
- [dir_re('vendorlibdir'), "$(RUBYLIBDIR)"],
- [dir_re('sitearchdir'), "$(RUBYARCHDIR)"],
- [dir_re('bindir'), "$(BINDIR)"],
- [dir_re('vendorarchdir'), "$(RUBYARCHDIR)"],
+ [dir_re('sitearchdir'), "$(RUBYARCHDIR)"]
]
def install_dirs(target_prefix = nil)
if $extout
dirs = [
- ['BINDIR', '$(extout)/bin'],
['RUBYCOMMONDIR', '$(extout)/common'],
['RUBYLIBDIR', '$(RUBYCOMMONDIR)$(target_prefix)'],
['RUBYARCHDIR', '$(extout)/$(arch)$(target_prefix)'],
@@ -101,21 +91,12 @@ def install_dirs(target_prefix = nil)
]
elsif $extmk
dirs = [
- ['BINDIR', '$(bindir)'],
['RUBYCOMMONDIR', '$(rubylibdir)'],
['RUBYLIBDIR', '$(rubylibdir)$(target_prefix)'],
['RUBYARCHDIR', '$(archdir)$(target_prefix)'],
]
- elsif $configure_args.has_key?('--vendor')
- dirs = [
- ['BINDIR', '$(bindir)'],
- ['RUBYCOMMONDIR', '$(vendordir)$(target_prefix)'],
- ['RUBYLIBDIR', '$(vendorlibdir)$(target_prefix)'],
- ['RUBYARCHDIR', '$(vendorarchdir)$(target_prefix)'],
- ]
else
dirs = [
- ['BINDIR', '$(bindir)'],
['RUBYCOMMONDIR', '$(sitedir)$(target_prefix)'],
['RUBYLIBDIR', '$(sitelibdir)$(target_prefix)'],
['RUBYARCHDIR', '$(sitearchdir)$(target_prefix)'],
@@ -133,12 +114,13 @@ end
topdir = File.dirname(libdir = File.dirname(__FILE__))
extdir = File.expand_path("ext", topdir)
$extmk = File.expand_path($0)[0, extdir.size+1] == extdir+"/"
-if not $extmk and File.exist?(($hdrdir = Config::CONFIG["archdir"]) + "/ruby.h")
- $topdir = $hdrdir
-elsif File.exist?(($hdrdir = ($top_srcdir ||= topdir)) + "/ruby.h") and
+if not $extmk and File.exist?(Config::CONFIG["archdir"] + "/ruby.h")
+ $hdrdir = $topdir = Config::CONFIG["archdir"]
+elsif File.exist?(($top_srcdir ||= topdir) + "/ruby.h") and
File.exist?(($topdir ||= Config::CONFIG["topdir"]) + "/config.h")
+ $hdrdir = $top_srcdir
else
- abort "mkmf.rb can't find header files for ruby at #{$hdrdir}/ruby.h"
+ abort "can't find header files for ruby."
end
OUTFLAG = CONFIG['OUTFLAG']
@@ -147,18 +129,11 @@ CPPOUTFILE = CONFIG['CPPOUTFILE']
CONFTEST_C = "conftest.c"
class String
- # Wraps a string in escaped quotes if it contains whitespace.
def quote
- /\s/ =~ self ? "\"#{self}\"" : "#{self}"
- end
-
- # Generates a string used as cpp macro name.
- def tr_cpp
- strip.upcase.tr_s("^A-Z0-9_", "_")
+ /\s/ =~ self ? "\"#{self}\"" : self
end
end
class Array
- # Wraps all strings in escaped quotes if they contain whitespace.
def quote
map {|s| s.quote}
end
@@ -168,8 +143,6 @@ def rm_f(*files)
FileUtils.rm_f(Dir[files.join("\0")])
end
-# Returns time stamp of the +target+ file if it exists and is newer
-# than or equal to all of +times+.
def modified?(target, times)
(t = File.mtime(target)) rescue return nil
Array === times or times = [times]
@@ -192,19 +165,12 @@ def merge_libs(*libs)
end
end
-# This is a custom logging module. It generates an mkmf.log file when you
-# run your extconf.rb script. This can be useful for debugging unexpected
-# failures.
-#
-# This module and its associated methods are meant for internal use only.
-#
module Logging
@log = nil
@logfile = 'mkmf.log'
@orgerr = $stderr.dup
@orgout = $stdout.dup
@postpone = 0
- @quiet = $extmk
def self::open
@log ||= File::open(@logfile, 'w')
@@ -248,19 +214,9 @@ module Logging
end
end
end
-
- class << self
- attr_accessor :quiet
- end
end
def xsystem command
- varpat = /\$\((\w+)\)|\$\{(\w+)\}/
- if varpat =~ command
- vars = Hash.new {|h, k| h[k] = ''; ENV[k]}
- command = command.dup
- nil while command.gsub!(varpat) {vars[$1||$2]}
- end
Logging::open do
puts command.quote
system(command)
@@ -482,7 +438,7 @@ def try_var(var, headers = nil, &b)
#{headers}
/*top*/
int main() { return 0; }
-int t() { const volatile void *volatile p; p = &(&#{var})[0]; return 0; }
+int t() { const volatile void *volatile p; p = (void *)&#{var}; return 0; }
SRC
end
@@ -512,7 +468,6 @@ ensure
log_src(src)
end
-# This is used internally by the have_macro? method.
def macro_defined?(macro, src, opt = "", &b)
src = src.sub(/[^\n]\z/, "\\&\n")
try_compile(src + <<"SRC", opt, &b)
@@ -536,14 +491,13 @@ end
def install_files(mfile, ifiles, map = nil, srcprefix = nil)
ifiles or return
- ifiles.empty? and return
srcprefix ||= '$(srcdir)'
Config::expand(srcdir = srcprefix.dup)
dirs = []
path = Hash.new {|h, i| h[i] = dirs.push([i])[-1]}
ifiles.each do |files, dir, prefix|
dir = map_dir(dir, map)
- prefix &&= %r|\A#{Regexp.quote(prefix)}/?|
+ prefix = %r|\A#{Regexp.quote(prefix)}/?| if prefix
if /\A\.\// =~ files
# install files which are in current working directory.
files = files[2..-1]
@@ -556,10 +510,6 @@ def install_files(mfile, ifiles, map = nil, srcprefix = nil)
f = nil
Dir.glob(files) do |f|
f[0..len] = "" if len
- case File.basename(f)
- when *$NONINSTALLFILES
- next
- end
d = File.dirname(f)
d.sub!(prefix, "") if prefix
d = (d.empty? || d == ".") ? dir : File.join(dir, d)
@@ -580,22 +530,17 @@ def install_rb(mfile, dest, srcdir = nil)
install_files(mfile, [["lib/**/*.rb", dest, "lib"]], nil, srcdir)
end
-def append_library(libs, lib) # :no-doc:
+def append_library(libs, lib)
format(LIBARG, lib) + " " + libs
end
def message(*s)
- unless Logging.quiet and not $VERBOSE
+ unless $extmk and not $VERBOSE
printf(*s)
$stdout.flush
end
end
-# This emits a string to stdout that allows users to see the results of the
-# various have* and find* methods as they are tested.
-#
-# Internal use only.
-#
def checking_for(m, fmt = nil)
f = caller[0][/in `(.*)'$/, 1] and f << ": " #` for vim
m = "checking #{/\Acheck/ =~ f ? '' : 'for '}#{m}... "
@@ -625,8 +570,6 @@ def checking_message(target, place = nil, opt = nil)
end
end
-# :startdoc:
-
# Returns whether or not +macro+ is defined either in the common header
# files or within any +headers+ you provide.
#
@@ -646,7 +589,7 @@ end
# If +headers+ are provided, it will include those header files as the
# header files it looks in when searching for +func+.
#
-# The real name of the library to be linked can be altered by
+# Real name of the library to be linked can be altered by
# '--with-FOOlib' configuration option.
#
def have_library(lib, func = nil, headers = nil, &b)
@@ -707,7 +650,7 @@ end
def have_func(func, headers = nil, &b)
checking_for checking_message("#{func}()", headers) do
if try_func(func, $libs, headers, &b)
- $defs.push(format("-DHAVE_%s", func.tr_cpp))
+ $defs.push(format("-DHAVE_%s", func.upcase))
true
else
false
@@ -726,7 +669,7 @@ end
def have_var(var, headers = nil, &b)
checking_for checking_message(var, headers) do
if try_var(var, headers, &b)
- $defs.push(format("-DHAVE_%s", var.tr_cpp))
+ $defs.push(format("-DHAVE_%s", var.upcase))
true
else
false
@@ -759,9 +702,8 @@ end
# of included directories that are sent to the compiler (via the -I switch).
#
def find_header(header, *paths)
- message = checking_message(header, paths)
header = cpp_include(header)
- checking_for message do
+ checking_for header do
if try_cpp(header)
true
else
@@ -787,7 +729,7 @@ end
# If found, a macro is passed as a preprocessor constant to the compiler using
# the member name, in uppercase, prepended with 'HAVE_ST_'.
#
-# For example, if have_struct_member('struct foo', 'bar') returned true, then the
+# For example, if have_struct_member('foo', 'bar') returned true, then the
# HAVE_ST_BAR preprocessor macro would be passed to the compiler.
#
def have_struct_member(type, member, headers = nil, &b)
@@ -799,7 +741,7 @@ def have_struct_member(type, member, headers = nil, &b)
int main() { return 0; }
int s = (char *)&((#{type}*)0)->#{member} - (char *)0;
SRC
- $defs.push(format("-DHAVE_ST_%s", member.tr_cpp))
+ $defs.push(format("-DHAVE_ST_%s", member.upcase))
true
else
false
@@ -807,21 +749,6 @@ SRC
end
end
-def try_type(type, headers = nil, opt = "", &b)
- if try_compile(<<"SRC", opt, &b)
-#{COMMON_HEADERS}
-#{cpp_include(headers)}
-/*top*/
-typedef #{type} conftest_type;
-int conftestval[sizeof(conftest_type)?1:-1];
-SRC
- $defs.push(format("-DHAVE_TYPE_%s", type.tr_cpp))
- true
- else
- false
- end
-end
-
# Returns whether or not the static type +type+ is defined. You may
# optionally pass additional +headers+ to check against in addition to the
# common header files.
@@ -837,65 +764,19 @@ end
#
def have_type(type, headers = nil, opt = "", &b)
checking_for checking_message(type, headers, opt) do
- try_type(type, headers, opt, &b)
- end
-end
-
-# Returns where the static type +type+ is defined.
-#
-# You may also pass additional flags to +opt+ which are then passed along to
-# the compiler.
-#
-# See also +have_type+.
-#
-def find_type(type, opt, *headers, &b)
- opt ||= ""
- fmt = "not found"
- def fmt.%(x)
- x ? x.respond_to?(:join) ? x.join(",") : x : self
- end
- checking_for checking_message(type, nil, opt), fmt do
- headers.find do |h|
- try_type(type, h, opt, &b)
- end
- end
-end
-
-def try_const(const, headers = nil, opt = "", &b)
- const, type = *const
- if try_compile(<<"SRC", opt, &b)
+ headers = cpp_include(headers)
+ if try_compile(<<"SRC", opt, &b)
#{COMMON_HEADERS}
-#{cpp_include(headers)}
+#{headers}
/*top*/
-typedef #{type || 'int'} conftest_type;
-conftest_type conftestval = #{type ? '' : '(int)'}#{const};
+typedef #{type} conftest_type;
+static conftest_type conftestval[sizeof(conftest_type)?1:-1];
SRC
- $defs.push(format("-DHAVE_CONST_%s", const.tr_cpp))
- true
- else
- false
- end
-end
-
-# Returns whether or not the constant +const+ is defined. You may
-# optionally pass the +type+ of +const+ as <code>[const, type]</code>,
-# like as:
-#
-# have_const(%w[PTHREAD_MUTEX_INITIALIZER pthread_mutex_t], "pthread.h")
-#
-# You may also pass additional +headers+ to check against in addition
-# to the common header files, and additional flags to +opt+ which are
-# then passed along to the compiler.
-#
-# If found, a macro is passed as a preprocessor constant to the compiler using
-# the type name, in uppercase, prepended with 'HAVE_CONST_'.
-#
-# For example, if have_const('foo') returned true, then the HAVE_CONST_FOO
-# preprocessor macro would be passed to the compiler.
-#
-def have_const(const, headers = nil, opt = "", &b)
- checking_for checking_message([*const].compact.join(' '), headers, opt) do
- try_const(const, headers, opt, &b)
+ $defs.push(format("-DHAVE_TYPE_%s", type.strip.upcase.tr_s("^A-Z0-9_", "_")))
+ true
+ else
+ false
+ end
end
end
@@ -917,16 +798,12 @@ def check_sizeof(type, headers = nil, &b)
end
checking_for checking_message("size of #{type}", headers), fmt do
if size = try_constant(expr, headers, &b)
- $defs.push(format("-DSIZEOF_%s=%d", type.tr_cpp, size))
+ $defs.push(format("-DSIZEOF_%s=%d", type.upcase.tr_s("^A-Z0-9_", "_"), size))
size
end
end
end
-# :stopdoc:
-
-# Used internally by the what_type? method to determine if +type+ is a scalar
-# pointer.
def scalar_ptr_type?(type, member = nil, headers = nil, &b)
try_compile(<<"SRC", &b) # pointer
#{COMMON_HEADERS}
@@ -938,8 +815,6 @@ int t() {return (int)(1-*(conftestval#{member ? ".#{member}" : ""}));}
SRC
end
-# Used internally by the what_type? method to determine if +type+ is a scalar
-# pointer.
def scalar_type?(type, member = nil, headers = nil, &b)
try_compile(<<"SRC", &b) # pointer
#{COMMON_HEADERS}
@@ -983,10 +858,6 @@ def what_type?(type, member = nil, headers = nil, &b)
end
end
-# This method is used internally by the find_executable method.
-#
-# Internal use only.
-#
def find_executable0(bin, path = nil)
ext = config_string('EXEEXT')
if File.expand_path(bin) == bin
@@ -1007,45 +878,18 @@ def find_executable0(bin, path = nil)
nil
end
-# :startdoc:
-
-# Searches for the executable +bin+ on +path+. The default path is your
-# PATH environment variable. If that isn't defined, it will resort to
-# searching /usr/local/bin, /usr/ucb, /usr/bin and /bin.
-#
-# If found, it will return the full path, including the executable name,
-# of where it was found.
-#
-# Note that this method does not actually affect the generated Makefile.
-#
def find_executable(bin, path = nil)
checking_for checking_message(bin, path) do
find_executable0(bin, path)
end
end
-# :stopdoc:
-
def arg_config(config, *defaults, &block)
$arg_config << [config, *defaults]
defaults << nil if !block and defaults.empty?
$configure_args.fetch(config.tr('_', '-'), *defaults, &block)
end
-# :startdoc:
-
-# Tests for the presence of a --with-<tt>config</tt> or --without-<tt>config</tt>
-# option. Returns true if the with option is given, false if the without
-# option is given, and the default value otherwise.
-#
-# This can be useful for adding custom definitions, such as debug information.
-#
-# Example:
-#
-# if with_config("debug")
-# $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
-# end
-#
def with_config(config, *defaults)
config = config.sub(/^--with[-_]/, '')
val = arg_config("--with-"+config) do
@@ -1067,18 +911,6 @@ def with_config(config, *defaults)
end
end
-# Tests for the presence of an --enable-<tt>config</tt> or
-# --disable-<tt>config</tt> option. Returns true if the enable option is given,
-# false if the disable option is given, and the default value otherwise.
-#
-# This can be useful for adding custom definitions, such as debug information.
-#
-# Example:
-#
-# if enable_config("debug")
-# $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
-# end
-#
def enable_config(config, *defaults)
if arg_config("--enable-"+config)
true
@@ -1091,32 +923,6 @@ def enable_config(config, *defaults)
end
end
-# Generates a header file consisting of the various macro definitions generated
-# by other methods such as have_func and have_header. These are then wrapped in
-# a custom #ifndef based on the +header+ file name, which defaults to
-# 'extconf.h'.
-#
-# For example:
-#
-# # extconf.rb
-# require 'mkmf'
-# have_func('realpath')
-# have_header('sys/utime.h')
-# create_header
-# create_makefile('foo')
-#
-# The above script would generate the following extconf.h file:
-#
-# #ifndef EXTCONF_H
-# #define EXTCONF_H
-# #define HAVE_REALPATH 1
-# #define HAVE_SYS_UTIME_H 1
-# #endif
-#
-# Given that the create_header method generates a file based on definitions
-# set earlier in your extconf.rb file, you will probably want to make this
-# one of the last methods you call in your script.
-#
def create_header(header = "extconf.h")
message "creating %s\n", header
sym = header.tr("a-z./\055", "A-Z___")
@@ -1184,10 +990,6 @@ def dir_config(target, idefault=nil, ldefault=nil)
[idir, ldir]
end
-# :stopdoc:
-
-# Handles meta information about installed libraries. Uses your platform's
-# pkg-config program if it has one.
def pkg_config(pkg)
if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
# iff package specific config command is given
@@ -1225,10 +1027,6 @@ def with_destdir(dir)
/\A\$[\(\{]/ =~ dir ? dir : "$(DESTDIR)"+dir
end
-# Converts forward slashes to backslashes. Aimed at MS Windows.
-#
-# Internal use only.
-#
def winsep(s)
s.tr('/', '\\')
end
@@ -1250,11 +1048,7 @@ def configuration(srcdir)
SHELL = /bin/sh
#### Start of system configuration section. ####
-#{
-if $extmk
- "top_srcdir = " + $top_srcdir.sub(%r"\A#{Regexp.quote($topdir)}/", "$(topdir)/")
-end
-}
+
srcdir = #{srcdir.gsub(/\$\((srcdir)\)|\$\{(srcdir)\}/) {CONFIG[$1||$2]}.quote}
topdir = #{($extmk ? CONFIG["topdir"] : $topdir).quote}
hdrdir = #{$extmk ? CONFIG["hdrdir"].quote : '$(topdir)'}
@@ -1292,13 +1086,9 @@ LIBRUBYARG_STATIC = #$LIBRUBYARG_STATIC
RUBY_EXTCONF_H = #{$extconf_h}
CFLAGS = #{$static ? '' : CONFIG['CCDLFLAGS']} #$CFLAGS #$ARCH_FLAG
INCFLAGS = -I. #$INCFLAGS
-DEFS = #{CONFIG['DEFS']}
CPPFLAGS = #{extconf_h}#{$CPPFLAGS}
CXXFLAGS = $(CFLAGS) #{CONFIG['CXXFLAGS']}
-ldflags = #{$LDFLAGS}
-dldflags = #{$DLDFLAGS}
-archflag = #{$ARCH_FLAG}
-DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
+DLDFLAGS = #$LDFLAGS #$DLDFLAGS #$ARCH_FLAG
LDSHARED = #{CONFIG['LDSHARED']}
AR = #{CONFIG['AR']}
EXEEXT = #{CONFIG['EXEEXT']}
@@ -1342,7 +1132,6 @@ all install static install-so install-rb: Makefile
RULES
end
-# :startdoc:
# Generates the Makefile for your extension, passing along any options and
# preprocessor constants that you may have generated through other methods.
@@ -1361,41 +1150,6 @@ end
# load the file within a Ruby program later, that directory structure will
# have to be followed, e.g. "require 'test/foo'".
#
-# The +srcprefix+ should be used when your source files are not in the same
-# directory as your build script. This will not only eliminate the need for
-# you to manually copy the source files into the same directory as your build
-# script, but it also sets the proper +target_prefix+ in the generated
-# Makefile.
-#
-# Setting the +target_prefix+ will, in turn, install the generated binary in
-# a directory under your Config::CONFIG['sitearchdir'] that mimics your local
-# filesystem when you run 'make install'.
-#
-# For example, given the following file tree:
-#
-# ext/
-# extconf.rb
-# test/
-# foo.c
-#
-# And given the following code:
-#
-# create_makefile('test/foo', 'test')
-#
-# That will set the +target_prefix+ in the generated Makefile to 'test'. That,
-# in turn, will create the following file tree when installed via the
-# 'make install' command:
-#
-# /path/to/ruby/sitearchdir/test/foo.so
-#
-# It is recommended that you use this approach to generate your makefiles,
-# instead of copying files around manually, because some third party
-# libraries may depend on the +target_prefix+ being set properly.
-#
-# The +srcprefix+ argument can be used to override the default source
-# directory, i.e. the current directory . It is included as part of the VPATH
-# and added to the list of INCFLAGS.
-#
def create_makefile(target, srcprefix = nil)
$target = target
libpath = $DEFLIBPATH|$LIBPATH
@@ -1494,11 +1248,11 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
dirs = []
mfile.print "install: install-so install-rb\n\n"
sodir = (dir = "$(RUBYARCHDIR)").dup
- mfile.print("install-so: ")
+ mfile.print("install-so: #{dir}\n")
if target
f = "$(DLLIB)"
dest = "#{dir}/#{f}"
- mfile.puts dir, "install-so: #{dest}"
+ mfile.print "install-so: #{dest}\n"
unless $extout
mfile.print "#{dest}: #{f}\n"
if (sep = config_string('BUILD_FILE_SEPARATOR'))
@@ -1515,8 +1269,6 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n"
end
end
- else
- mfile.puts "Makefile"
end
mfile.print("install-rb: pre-install-rb install-rb-default\n")
mfile.print("install-rb-default: pre-install-rb-default\n")
@@ -1532,7 +1284,7 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
files.each do |f|
dest = "#{dir}/#{File.basename(f)}"
mfile.print("install-rb#{sfx}: #{dest}\n")
- mfile.print("#{dest}: #{f} #{dir}\n\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) ")
+ mfile.print("#{dest}: #{f}\n\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) ")
sep = config_string('BUILD_FILE_SEPARATOR')
if sep
f = f.gsub("/", sep)
@@ -1629,7 +1381,7 @@ site-install-rb: install-rb
end
while line = dfile.gets()
line.gsub!(/\.o\b/, ".#{$OBJEXT}")
- line.gsub!(/\$\((?:hdr|top)dir\)\/config.h/, $config_h) if $config_h
+ line.gsub!(/\$\(hdrdir\)\/config.h/, $config_h) if $config_h
if /(?:^|[^\\])(?:\\\\)*\\$/ =~ line
(cont ||= []) << line
next
@@ -1665,8 +1417,6 @@ ensure
mfile.close if mfile
end
-# :stopdoc:
-
def init_mkmf(config = CONFIG)
$makefile_created = false
$arg_config = []
@@ -1688,8 +1438,7 @@ def init_mkmf(config = CONFIG)
$DEFLIBPATH = $extmk ? ["$(topdir)"] : CROSS_COMPILING ? [] : ["$(libdir)"]
$DEFLIBPATH.unshift(".")
$LIBPATH = []
- $INSTALLFILES = []
- $NONINSTALLFILES = [/~\z/, /\A#.*#\z/, /\A\.#/, /\.bak\z/i, /\.orig\z/, /\.rej\z/, /\.l[ao]\z/, /\.o\z/]
+ $INSTALLFILES = nil
$objs = nil
$srcs = nil
@@ -1719,11 +1468,6 @@ details. You may need configuration options.
Provided configuration options:
MESSAGE
-# Returns whether or not the Makefile was successfully generated. If not,
-# the script will abort with an error message.
-#
-# Internal use only.
-#
def mkmf_failed(path)
unless $makefile_created or File.exist?("Makefile")
opts = $arg_config.collect {|t, n| "\t#{t}#{n ? "=#{n}" : ""}\n"}
@@ -1731,8 +1475,6 @@ def mkmf_failed(path)
end
end
-# :startdoc:
-
init_mkmf
$make = with_config("make-prog", ENV["MAKE"] || "make")
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index d890130ce7..dfbcf1499f 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -278,9 +278,12 @@ module Net
def sendport(host, port)
af = (@sock.peeraddr)[0]
if af == "AF_INET"
- cmd = "PORT " + (host.split(".") + port.divmod(256)).join(",")
+ hbytes = host.split(".")
+ pbytes = [port / 256, port % 256]
+ bytes = hbytes + pbytes
+ cmd = "PORT " + bytes.join(",")
elsif af == "AF_INET6"
- cmd = sprintf("EPRT |2|%s|%d|", host, port)
+ cmd = "EPRT |2|" + host + "|" + sprintf("%d", port) + "|"
else
raise FTPProtoError, host
end
@@ -319,8 +322,6 @@ module Net
end
end
resp = sendcmd(cmd)
- # skip 2XX for some ftp servers
- resp = getresp if resp[0] == ?2
if resp[0] != ?1
raise FTPReplyError, resp
end
@@ -333,8 +334,6 @@ module Net
end
end
resp = sendcmd(cmd)
- # skip 2XX for some ftp servers
- resp = getresp if resp[0] == ?2
if resp[0] != ?1
raise FTPReplyError, resp
end
@@ -378,11 +377,9 @@ module Net
synchronize do
resp = sendcmd('USER ' + user)
if resp[0] == ?3
- raise FTPReplyError, resp if passwd.nil?
resp = sendcmd('PASS ' + passwd)
end
if resp[0] == ?3
- raise FTPReplyError, resp if acct.nil?
resp = sendcmd('ACCT ' + acct)
end
end
@@ -670,9 +667,9 @@ module Net
begin
voidcmd("CDUP")
return
- rescue FTPPermError => e
- if e.message[0, 3] != "500"
- raise e
+ rescue FTPPermError
+ if $![0, 3] != "500"
+ raise FTPPermError, $!
end
end
end
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 7dd1f24d4c..46d95b27b4 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -584,9 +584,6 @@ module Net #:nodoc:
HTTPResponse.read_new(@socket).value
end
s.connect
- if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
- s.post_connection_check(@address)
- end
end
on_connect
end
diff --git a/lib/net/https.rb b/lib/net/https.rb
index 7847c3ffea..e296dbbed4 100644
--- a/lib/net/https.rb
+++ b/lib/net/https.rb
@@ -65,11 +65,11 @@ It can be replaced by the following code:
: key, key=((|key|))
Sets an OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
- (This method is appeared in Michal Rokos's OpenSSL extension.)
+ (This method is appeared in Michal Rokos's OpenSSL extention.)
: cert, cert=((|cert|))
Sets an OpenSSL::X509::Certificate object as client certificate
- (This method is appeared in Michal Rokos's OpenSSL extension).
+ (This method is appeared in Michal Rokos's OpenSSL extention).
: ca_file, ca_file=((|path|))
Sets path of a CA certification file in PEM format.
diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index 6162ffa0d0..6436940df6 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -284,11 +284,9 @@ module Net
# Disconnects from the server.
def disconnect
- begin
- # try to call SSL::SSLSocket#io.
+ if SSL::SSLSocket === @sock
@sock.io.shutdown
- rescue NoMethodError
- # @sock is not an SSL::SSLSocket.
+ else
@sock.shutdown
end
@receiver_thread.join
@@ -902,7 +900,6 @@ module Net
end
@sock = SSLSocket.new(@sock, context)
@sock.connect # start ssl session.
- @sock.post_connection_check(@host) if verify
else
@usessl = false
end
diff --git a/lib/net/pop.rb b/lib/net/pop.rb
index 82cc9a747b..2ecbcbdf28 100644
--- a/lib/net/pop.rb
+++ b/lib/net/pop.rb
@@ -1,8 +1,8 @@
# = net/pop.rb
#
-# Copyright (c) 1999-2007 Yukihiro Matsumoto.
+# Copyright (c) 1999-2003 Yukihiro Matsumoto.
#
-# Copyright (c) 1999-2007 Minero Aoki.
+# Copyright (c) 1999-2003 Minero Aoki.
#
# Written & maintained by Minero Aoki <aamine@loveruby.net>.
#
@@ -10,24 +10,18 @@
#
# This program is free software. You can re-distribute and/or
# modify this program under the same terms as Ruby itself,
-# Ruby Distribute License.
+# Ruby Distribute License or GNU General Public License.
#
-# NOTE: You can find Japanese version of this document at:
-# http://www.ruby-lang.org/ja/man/html/net_pop.html
+# NOTE: You can find Japanese version of this document in
+# the doc/net directory of the standard ruby interpreter package.
#
# $Id$
-#
+#
# See Net::POP3 for documentation.
#
require 'net/protocol'
require 'digest/md5'
-require 'timeout'
-
-begin
- require "openssl/ssl"
-rescue LoadError
-end
module Net
@@ -202,19 +196,10 @@ module Net
# Class Parameters
#
- def POP3.default_port
- default_pop3_port()
- end
-
# The default port for POP3 connections, port 110
- def POP3.default_pop3_port
+ def POP3.default_port
110
end
-
- # The default port for POP3S connections, port 995
- def POP3.default_pop3s_port
- 995
- end
def POP3.socket_type #:nodoc: obsolete
Net::InternetMessageIO
@@ -235,7 +220,7 @@ module Net
# ....
# end
#
- def POP3.APOP(isapop)
+ def POP3.APOP( isapop )
isapop ? APOP : POP3
end
@@ -259,9 +244,9 @@ module Net
# m.delete if $DELETE
# end
#
- def POP3.foreach(address, port = nil,
- account = nil, password = nil,
- isapop = false, &block) # :yields: message
+ def POP3.foreach( address, port = nil,
+ account = nil, password = nil,
+ isapop = false, &block ) # :yields: message
start(address, port, account, password, isapop) {|pop|
pop.each_mail(&block)
}
@@ -280,9 +265,9 @@ module Net
# file.write m.pop
# end
#
- def POP3.delete_all(address, port = nil,
- account = nil, password = nil,
- isapop = false, &block)
+ def POP3.delete_all( address, port = nil,
+ account = nil, password = nil,
+ isapop = false, &block )
start(address, port, account, password, isapop) {|pop|
pop.delete_all(&block)
}
@@ -302,16 +287,16 @@ module Net
# Net::POP3.auth_only('pop.example.com', 110,
# 'YourAccount', 'YourPassword', true)
#
- def POP3.auth_only(address, port = nil,
- account = nil, password = nil,
- isapop = false)
+ def POP3.auth_only( address, port = nil,
+ account = nil, password = nil,
+ isapop = false )
new(address, port, isapop).auth_only account, password
end
# Starts a pop3 session, attempts authentication, and quits.
# This method must not be called while POP3 session is opened.
# This method raises POPAuthenticationError if authentication fails.
- def auth_only(account, password)
+ def auth_only( account, password )
raise IOError, 'opening previously opened POP session' if started?
start(account, password) {
;
@@ -319,59 +304,6 @@ module Net
end
#
- # SSL
- #
-
- @ssl_params = nil
-
- # call-seq:
- # Net::POP.enable_ssl(params = {})
- #
- # Enable SSL for all new instances.
- # +params+ is passed to OpenSSL::SSLContext#set_params.
- def POP3.enable_ssl(*args)
- @ssl_params = create_ssl_params(*args)
- end
-
- def POP3.create_ssl_params(verify_or_params = {}, certs = nil)
- begin
- params = verify_or_params.to_hash
- rescue NoMethodError
- params = {}
- params[:verify_mode] = verify_or_params
- if certs
- if File.file?(certs)
- params[:ca_file] = certs
- elsif File.directory?(certs)
- params[:ca_path] = certs
- end
- end
- end
- return params
- end
-
- # Disable SSL for all new instances.
- def POP3.disable_ssl
- @ssl_params = nil
- end
-
- def POP3.ssl_params
- return @ssl_params
- end
-
- def POP3.use_ssl?
- return !@ssl_params.nil?
- end
-
- def POP3.verify
- return @ssl_params[:verify_mode]
- end
-
- def POP3.certs
- return @ssl_params[:ca_file] || @ssl_params[:ca_path]
- end
-
- #
# Session management
#
@@ -391,28 +323,27 @@ module Net
# end
# end
#
- def POP3.start(address, port = nil,
- account = nil, password = nil,
- isapop = false, &block) # :yield: pop
+ def POP3.start( address, port = nil,
+ account = nil, password = nil,
+ isapop = false, &block ) # :yield: pop
new(address, port, isapop).start(account, password, &block)
end
-
+
# Creates a new POP3 object.
#
# +address+ is the hostname or ip address of your POP3 server.
#
- # The optional +port+ is the port to connect to.
+ # The optional +port+ is the port to connect to; it defaults to 110.
#
# The optional +isapop+ specifies whether this connection is going
# to use APOP authentication; it defaults to +false+.
#
# This method does *not* open the TCP connection.
- def initialize(addr, port = nil, isapop = false)
+ def initialize( addr, port = nil, isapop = false )
@address = addr
- @ssl_params = POP3.ssl_params
- @port = port
+ @port = port || self.class.default_port
@apop = isapop
-
+
@command = nil
@socket = nil
@started = false
@@ -430,32 +361,6 @@ module Net
@apop
end
- # does this instance use SSL?
- def use_ssl?
- return !@ssl_params.nil?
- end
-
- # call-seq:
- # Net::POP#enable_ssl(params = {})
- #
- # Enables SSL for this instance. Must be called before the connection is
- # established to have any effect.
- # +params[:port]+ is port to establish the SSL connection on; Defaults to 995.
- # +params+ (except :port) is passed to OpenSSL::SSLContext#set_params.
- def enable_ssl(verify_or_params = {}, certs = nil, port = nil)
- begin
- @ssl_params = verify_or_params.to_hash.dup
- @port = @ssl_params.delete(:port) || @port
- rescue NoMethodError
- @ssl_params = POP3.create_ssl_params(verify_or_params, certs)
- @port = port || @port
- end
- end
-
- def disable_ssl
- @ssl_params = nil
- end
-
# Provide human-readable stringification of class state.
def inspect
"#<#{self.class} #{@address}:#{@port} open=#{@started}>"
@@ -474,7 +379,7 @@ module Net
# ....
# end
#
- def set_debug_output(arg)
+ def set_debug_output( arg )
@debug_output = arg
end
@@ -482,9 +387,7 @@ module Net
attr_reader :address
# The port number to connect to.
- def port
- return @port || (use_ssl? ? POP3.default_pop3s_port : POP3.default_pop3_port)
- end
+ attr_reader :port
# Seconds to wait until a connection is opened.
# If the POP3 object cannot open a connection within this time,
@@ -497,7 +400,7 @@ module Net
attr_reader :read_timeout
# Set the read timeout.
- def read_timeout=(sec)
+ def read_timeout=( sec )
@command.socket.read_timeout = sec if @command
@read_timeout = sec
end
@@ -515,8 +418,9 @@ module Net
# closes the session after block call finishes.
#
# This method raises a POPAuthenticationError if authentication fails.
- def start(account, password) # :yield: pop
+ def start( account, password ) # :yield: pop
raise IOError, 'POP session already started' if @started
+
if block_given?
begin
do_start account, password
@@ -530,23 +434,9 @@ module Net
end
end
- def do_start(account, password)
- s = timeout(@open_timeout) { TCPSocket.open(@address, port) }
- if use_ssl?
- raise 'openssl library not installed' unless defined?(OpenSSL)
- context = OpenSSL::SSL::SSLContext.new
- context.set_params(@ssl_params)
- s = OpenSSL::SSL::SSLSocket.new(s, context)
- s.sync_close = true
- s.connect
- if context.verify_mode != OpenSSL::SSL::VERIFY_NONE
- s.post_connection_check(@address)
- end
- end
- @socket = InternetMessageIO.new(s)
- logging "POP session started: #{@address}:#{@port} (#{@apop ? 'APOP' : 'POP'})"
- @socket.read_timeout = @read_timeout
- @socket.debug_output = @debug_output
+ def do_start( account, password )
+ @socket = self.class.socket_type.old_open(@address, @port,
+ @open_timeout, @read_timeout, @debug_output)
on_connect
@command = POP3Command.new(@socket)
if apop?
@@ -556,12 +446,7 @@ module Net
end
@started = true
ensure
- # Authentication failed, clean up connection.
- unless @started
- s.close if s and not s.closed?
- @socket = nil
- @command = nil
- end
+ do_finish if not @started
end
private :do_start
@@ -577,8 +462,6 @@ module Net
def do_finish
@mails = nil
- @n_mails = nil
- @n_bytes = nil
@command.quit if @command
ensure
@started = false
@@ -641,7 +524,7 @@ module Net
# end
#
# This method raises a POPError if an error occurs.
- def each_mail(&block) # :yield: message
+ def each_mail( &block ) # :yield: message
mails().each(&block)
end
@@ -688,10 +571,6 @@ module Net
end
end
- def logging(msg)
- @debug_output << msg + "\n" if @debug_output
- end
-
end # class POP3
# class aliases
@@ -719,7 +598,7 @@ module Net
#
class POPMail
- def initialize(num, len, pop, cmd) #:nodoc:
+ def initialize( num, len, pop, cmd ) #:nodoc:
@number = num
@length = len
@pop = pop
@@ -798,7 +677,7 @@ module Net
# The optional +dest+ argument is obsolete.
#
# This method raises a POPError if an error occurs.
- def top(lines, dest = '')
+ def top( lines, dest = '' )
@command.top(@number, lines) do |chunk|
dest << chunk
end
@@ -810,7 +689,7 @@ module Net
# The optional +dest+ argument is obsolete.
#
# This method raises a POPError if an error occurs.
- def header(dest = '')
+ def header( dest = '' )
top(0, dest)
end
@@ -858,7 +737,7 @@ module Net
alias uidl unique_id
- def uid=(uid) #:nodoc: internal use only
+ def uid=( uid ) #:nodoc: internal use only (used from POP3#set_all_uids)
@uid = uid
end
@@ -867,7 +746,7 @@ module Net
class POP3Command #:nodoc: internal use only
- def initialize(sock)
+ def initialize( sock )
@socket = sock
@error_occured = false
res = check_response(critical { recv_response() })
@@ -878,14 +757,14 @@ module Net
"#<#{self.class} socket=#{@socket}>"
end
- def auth(account, password)
+ def auth( account, password )
check_response_auth(critical {
check_response_auth(get_response('USER %s', account))
get_response('PASS %s', password)
})
end
- def apop(account, password)
+ def apop( account, password )
raise POPAuthenticationError, 'not APOP server; cannot login' \
unless @apop_stamp
check_response_auth(critical {
@@ -916,28 +795,28 @@ module Net
end
def rset
- check_response(critical { get_response('RSET') })
+ check_response(critical { get_response 'RSET' })
end
- def top(num, lines = 0, &block)
+ def top( num, lines = 0, &block )
critical {
getok('TOP %d %d', num, lines)
@socket.each_message_chunk(&block)
}
end
- def retr(num, &block)
+ def retr( num, &block )
critical {
getok('RETR %d', num)
@socket.each_message_chunk(&block)
}
end
- def dele(num)
+ def dele( num )
check_response(critical { get_response('DELE %d', num) })
end
- def uidl(num = nil)
+ def uidl( num = nil )
if num
res = check_response(critical { get_response('UIDL %d', num) })
return res.split(/ /)[1]
@@ -960,12 +839,12 @@ module Net
private
- def getok(fmt, *fargs)
+ def getok( fmt, *fargs )
@socket.writeline sprintf(fmt, *fargs)
check_response(recv_response())
end
- def get_response(fmt, *fargs)
+ def get_response( fmt, *fargs )
@socket.writeline sprintf(fmt, *fargs)
recv_response()
end
@@ -974,13 +853,13 @@ module Net
@socket.readline
end
- def check_response(res)
- raise POPError, res unless /\A\+OK/i =~ res
+ def check_response( res )
+ raise POPError, res unless /\A\+OK/i === res
res
end
- def check_response_auth(res)
- raise POPAuthenticationError, res unless /\A\+OK/i =~ res
+ def check_response_auth( res )
+ raise POPAuthenticationError, res unless /\A\+OK/i === res
res
end
@@ -997,3 +876,4 @@ module Net
end # class POP3Command
end # module Net
+
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index dc23c14dfa..d722fdcbd4 100644
--- a/lib/net/protocol.rb
+++ b/lib/net/protocol.rb
@@ -128,11 +128,9 @@ module Net # :nodoc:
private
- BUFSIZE = 1024 * 16
-
def rbuf_fill
timeout(@read_timeout) {
- @rbuf << @io.sysread(BUFSIZE)
+ @rbuf << @io.sysread(1024)
}
end
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index 7c9d9388ef..dda9dab072 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -1,18 +1,19 @@
# = net/smtp.rb
#
-# Copyright (c) 1999-2007 Yukihiro Matsumoto.
+# Copyright (c) 1999-2003 Yukihiro Matsumoto.
#
-# Copyright (c) 1999-2007 Minero Aoki.
+# Copyright (c) 1999-2003 Minero Aoki.
#
# Written & maintained by Minero Aoki <aamine@loveruby.net>.
#
# Documented by William Webber and Minero Aoki.
#
# This program is free software. You can re-distribute and/or
-# modify this program under the same terms as Ruby itself.
+# modify this program under the same terms as Ruby itself,
+# Ruby Distribute License or GNU General Public License.
#
-# NOTE: You can find Japanese version of this document at:
-# http://www.ruby-lang.org/ja/man/html/net_smtp.html
+# NOTE: You can find Japanese version of this document in
+# the doc/net directory of the standard ruby interpreter package.
#
# $Id$
#
@@ -21,18 +22,13 @@
require 'net/protocol'
require 'digest/md5'
-require 'timeout'
-begin
- require 'openssl'
-rescue LoadError
-end
module Net
# Module mixed in to all SMTP error classes
module SMTPError
- # This *class* is a module for backward compatibility.
- # In later release, this module becomes a class.
+ # This *class* is module for some reason.
+ # In ruby 1.9.x, this module becomes a class.
end
# Represents an SMTP authentication error.
@@ -60,11 +56,6 @@ module Net
include SMTPError
end
- # Command is not supported on server.
- class SMTPUnsupportedCommand < ProtocolError
- include SMTPError
- end
-
#
# = Net::SMTP
#
@@ -174,29 +165,11 @@ module Net
Revision = %q$Revision$.split[1]
- # The default SMTP port number, 25.
+ # The default SMTP port, port 25.
def SMTP.default_port
25
end
- # The default mail submission port number, 587.
- def SMTP.default_submission_port
- 587
- end
-
- # The default SMTPS port number, 465.
- def SMTP.default_tls_port
- 465
- end
-
- class << self
- alias default_ssl_port default_tls_port
- end
-
- def SMTP.default_ssl_context
- OpenSSL::SSL::SSLContext.new
- end
-
#
# Creates a new Net::SMTP object.
#
@@ -208,22 +181,18 @@ module Net
# SMTP.start instead of SMTP.new if you want to do everything
# at once. Otherwise, follow SMTP.new with SMTP#start.
#
- def initialize(address, port = nil)
+ def initialize( address, port = nil )
@address = address
@port = (port || SMTP.default_port)
@esmtp = true
- @capabilities = nil
@socket = nil
@started = false
@open_timeout = 30
@read_timeout = 60
@error_occured = false
@debug_output = nil
- @tls = false
- @starttls = false
- @ssl_context = nil
end
-
+
# Provide human-readable stringification of class state.
def inspect
"#<#{self.class} #{@address}:#{@port} started=#{@started}>"
@@ -241,127 +210,12 @@ module Net
# object will automatically switch to plain SMTP mode and
# retry (but not vice versa).
#
- def esmtp=(bool)
+ def esmtp=( bool )
@esmtp = bool
end
alias esmtp esmtp?
- # true if server advertises STARTTLS.
- # You cannot get valid value before opening SMTP session.
- def capable_starttls?
- capable?('STARTTLS')
- end
-
- def capable?(key)
- return nil unless @capabilities
- @capabilities[key] ? true : false
- end
- private :capable?
-
- # true if server advertises AUTH PLAIN.
- # You cannot get valid value before opening SMTP session.
- def capable_plain_auth?
- auth_capable?('PLAIN')
- end
-
- # true if server advertises AUTH LOGIN.
- # You cannot get valid value before opening SMTP session.
- def capable_login_auth?
- auth_capable?('LOGIN')
- end
-
- # true if server advertises AUTH CRAM-MD5.
- # You cannot get valid value before opening SMTP session.
- def capable_cram_md5_auth?
- auth_capable?('CRAM-MD5')
- end
-
- def auth_capable?(type)
- return nil unless @capabilities
- return false unless @capabilities['AUTH']
- @capabilities['AUTH'].include?(type)
- end
- private :auth_capable?
-
- # Returns supported authentication methods on this server.
- # You cannot get valid value before opening SMTP session.
- def capable_auth_types
- return [] unless @capabilities
- return [] unless @capabilities['AUTH']
- @capabilities['AUTH']
- end
-
- # true if this object uses SMTP/TLS (SMTPS).
- def tls?
- @tls
- end
-
- alias ssl? tls?
-
- # Enables SMTP/TLS (SMTPS: SMTP over direct TLS connection) for
- # this object. Must be called before the connection is established
- # to have any effect. +context+ is a OpenSSL::SSL::SSLContext object.
- def enable_tls(context = SMTP.default_ssl_context)
- raise 'openssl library not installed' unless defined?(OpenSSL)
- raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @starttls
- @tls = true
- @ssl_context = context
- end
-
- alias enable_ssl enable_tls
-
- # Disables SMTP/TLS for this object. Must be called before the
- # connection is established to have any effect.
- def disable_tls
- @tls = false
- @ssl_context = nil
- end
-
- alias disable_ssl disable_tls
-
- # Returns truth value if this object uses STARTTLS.
- # If this object always uses STARTTLS, returns :always.
- # If this object uses STARTTLS when the server support TLS, returns :auto.
- def starttls?
- @starttls
- end
-
- # true if this object uses STARTTLS.
- def starttls_always?
- @starttls == :always
- end
-
- # true if this object uses STARTTLS when server advertises STARTTLS.
- def starttls_auto?
- @starttls == :auto
- end
-
- # Enables SMTP/TLS (STARTTLS) for this object.
- # +context+ is a OpenSSL::SSL::SSLContext object.
- def enable_starttls(context = SMTP.default_ssl_context)
- raise 'openssl library not installed' unless defined?(OpenSSL)
- raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @tls
- @starttls = :always
- @ssl_context = context
- end
-
- # Enables SMTP/TLS (STARTTLS) for this object if server accepts.
- # +context+ is a OpenSSL::SSL::SSLContext object.
- def enable_starttls_auto(context = SMTP.default_ssl_context)
- raise 'openssl library not installed' unless defined?(OpenSSL)
- raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @tls
- @starttls = :auto
- @ssl_context = context
- end
-
- # Disables SMTP/TLS (STARTTLS) for this object. Must be called
- # before the connection is established to have any effect.
- def disable_starttls
- @starttls = false
- @ssl_context = nil
- end
-
# The address of the SMTP server to connect to.
attr_reader :address
@@ -380,7 +234,7 @@ module Net
# Set the number of seconds to wait until timing-out a read(2)
# call.
- def read_timeout=(sec)
+ def read_timeout=( sec )
@socket.read_timeout = sec if @socket
@read_timeout = sec
end
@@ -399,12 +253,10 @@ module Net
# ....
# end
#
- def debug_output=(arg)
+ def set_debug_output( arg )
@debug_output = arg
end
- alias set_debug_output debug_output=
-
#
# SMTP session control
#
@@ -457,9 +309,10 @@ module Net
# * IOError
# * TimeoutError
#
- def SMTP.start(address, port = nil, helo = 'localhost.localdomain',
- user = nil, secret = nil, authtype = nil,
- &block) # :yield: smtp
+ def SMTP.start( address, port = nil,
+ helo = 'localhost.localdomain',
+ user = nil, secret = nil, authtype = nil,
+ &block) # :yield: smtp
new(address, port).start(helo, user, secret, authtype, &block)
end
@@ -518,89 +371,55 @@ module Net
# * IOError
# * TimeoutError
#
- def start(helo = 'localhost.localdomain',
- user = nil, secret = nil, authtype = nil) # :yield: smtp
+ def start( helo = 'localhost.localdomain',
+ user = nil, secret = nil, authtype = nil ) # :yield: smtp
if block_given?
begin
- do_start helo, user, secret, authtype
+ do_start(helo, user, secret, authtype)
return yield(self)
ensure
do_finish
end
else
- do_start helo, user, secret, authtype
+ do_start(helo, user, secret, authtype)
return self
end
end
- # Finishes the SMTP session and closes TCP connection.
- # Raises IOError if not started.
- def finish
- raise IOError, 'not yet started' unless started?
- do_finish
- end
-
- private
-
- def do_start(helo_domain, user, secret, authtype)
+ def do_start( helodomain, user, secret, authtype )
raise IOError, 'SMTP session already started' if @started
- if user or secret
- check_auth_method(authtype || DEFAULT_AUTH_TYPE)
- check_auth_args user, secret
- end
- s = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
- logging "Connection opened: #{@address}:#{@port}"
- @socket = new_internet_message_io(tls? ? tlsconnect(s) : s)
- check_response critical { recv_response() }
- do_helo helo_domain
- if starttls_always? or (capable_starttls? and starttls_auto?)
- unless capable_starttls?
- raise SMTPUnsupportedCommand,
- "STARTTLS is not supported on this server"
+ check_auth_args user, secret, authtype if user or secret
+
+ @socket = InternetMessageIO.old_open(@address, @port,
+ @open_timeout, @read_timeout,
+ @debug_output)
+ check_response(critical { recv_response() })
+ begin
+ if @esmtp
+ ehlo helodomain
+ else
+ helo helodomain
+ end
+ rescue ProtocolError
+ if @esmtp
+ @esmtp = false
+ @error_occured = false
+ retry
end
- starttls
- @socket = new_internet_message_io(tlsconnect(s))
- # helo response may be different after STARTTLS
- do_helo helo_domain
+ raise
end
- authenticate user, secret, (authtype || DEFAULT_AUTH_TYPE) if user
+ authenticate user, secret, authtype if user
@started = true
ensure
- unless @started
- # authentication failed, cancel connection.
- s.close if s and not s.closed?
- @socket = nil
- end
- end
-
- def tlsconnect(s)
- s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context)
- logging "TLS connection started"
- s.sync_close = true
- s.connect
- if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
- s.post_connection_check(@address)
- end
- s
- end
-
- def new_internet_message_io(s)
- io = InternetMessageIO.new(s)
- io.read_timeout = @read_timeout
- io.debug_output = @debug_output
- io
+ @socket.close if not @started and @socket and not @socket.closed?
end
+ private :do_start
- def do_helo(helo_domain)
- res = @esmtp ? ehlo(helo_domain) : helo(helo_domain)
- @capabilities = res.capabilities
- rescue SMTPError
- if @esmtp
- @esmtp = false
- @error_occured = false
- retry
- end
- raise
+ # Finishes the SMTP session and closes TCP connection.
+ # Raises IOError if not started.
+ def finish
+ raise IOError, 'not yet started' unless started?
+ do_finish
end
def do_finish
@@ -611,9 +430,10 @@ module Net
@socket.close if @socket and not @socket.closed?
@socket = nil
end
+ private :do_finish
#
- # Message Sending
+ # message send
#
public
@@ -648,11 +468,10 @@ module Net
# * IOError
# * TimeoutError
#
- def send_message(msgstr, from_addr, *to_addrs)
- raise IOError, 'closed session' unless @socket
- mailfrom from_addr
- rcptto_list to_addrs
- data msgstr
+ def send_message( msgstr, from_addr, *to_addrs )
+ send0(from_addr, to_addrs.flatten) {
+ @socket.write_message msgstr
+ }
end
alias send_mail send_message
@@ -702,220 +521,166 @@ module Net
# * IOError
# * TimeoutError
#
- def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
- raise IOError, 'closed session' unless @socket
- mailfrom from_addr
- rcptto_list to_addrs
- data(&block)
+ def open_message_stream( from_addr, *to_addrs, &block ) # :yield: stream
+ send0(from_addr, to_addrs.flatten) {
+ @socket.write_message_by_block(&block)
+ }
end
alias ready open_message_stream # obsolete
- #
- # Authentication
- #
-
- public
-
- DEFAULT_AUTH_TYPE = :plain
-
- def authenticate(user, secret, authtype = DEFAULT_AUTH_TYPE)
- check_auth_method authtype
- check_auth_args user, secret
- send auth_method(authtype), user, secret
- end
+ private
- def auth_plain(user, secret)
- check_auth_args user, secret
- res = critical {
- get_response('AUTH PLAIN ' + base64_encode("\0#{user}\0#{secret}"))
- }
- check_auth_response res
- res
- end
+ def send0( from_addr, to_addrs )
+ raise IOError, 'closed session' unless @socket
+ raise ArgumentError, 'mail destination not given' if to_addrs.empty?
+ if $SAFE > 0
+ raise SecurityError, 'tainted from_addr' if from_addr.tainted?
+ to_addrs.each do |to|
+ raise SecurityError, 'tainted to_addr' if to.tainted?
+ end
+ end
- def auth_login(user, secret)
- check_auth_args user, secret
+ mailfrom from_addr
+ to_addrs.each do |to|
+ rcptto to
+ end
res = critical {
- check_auth_continue get_response('AUTH LOGIN')
- check_auth_continue get_response(base64_encode(user))
- get_response(base64_encode(secret))
+ check_response(get_response('DATA'), true)
+ yield
+ recv_response()
}
- check_auth_response res
- res
+ check_response(res)
end
- def auth_cram_md5(user, secret)
- check_auth_args user, secret
- res = critical {
- res0 = get_response('AUTH CRAM-MD5')
- check_auth_continue res0
- crammed = cram_md5_response(secret, res0.cram_md5_challenge)
- get_response(base64_encode("#{user} #{crammed}"))
- }
- check_auth_response res
- res
- end
+ #
+ # auth
+ #
private
- def check_auth_method(type)
- unless respond_to?(auth_method(type), true)
- raise ArgumentError, "wrong authentication type #{type}"
- end
- end
-
- def auth_method(type)
- "auth_#{type.to_s.downcase}".intern
+ def check_auth_args( user, secret, authtype )
+ raise ArgumentError, 'both user and secret are required'\
+ unless user and secret
+ auth_method = "auth_#{authtype || 'cram_md5'}"
+ raise ArgumentError, "wrong auth type #{authtype}"\
+ unless respond_to?(auth_method, true)
end
- def check_auth_args(user, secret)
- unless user
- raise ArgumentError, 'SMTP-AUTH requested but missing user name'
- end
- unless secret
- raise ArgumentError, 'SMTP-AUTH requested but missing secret phrase'
- end
+ def authenticate( user, secret, authtype )
+ __send__("auth_#{authtype || 'cram_md5'}", user, secret)
end
- def base64_encode(str)
- # expects "str" may not become too long
- [str].pack('m').gsub(/\s+/, '')
+ def auth_plain( user, secret )
+ res = critical { get_response('AUTH PLAIN %s',
+ base64_encode("\0#{user}\0#{secret}")) }
+ raise SMTPAuthenticationError, res unless /\A2../ === res
end
- IMASK = 0x36
- OMASK = 0x5c
+ def auth_login( user, secret )
+ res = critical {
+ check_response(get_response('AUTH LOGIN'), true)
+ check_response(get_response(base64_encode(user)), true)
+ get_response(base64_encode(secret))
+ }
+ raise SMTPAuthenticationError, res unless /\A2../ === res
+ end
+
+ def auth_cram_md5( user, secret )
+ # CRAM-MD5: [RFC2195]
+ res = nil
+ critical {
+ res = check_response(get_response('AUTH CRAM-MD5'), true)
+ challenge = res.split(/ /)[1].unpack('m')[0]
+ secret = Digest::MD5.digest(secret) if secret.size > 64
+
+ isecret = secret + "\0" * (64 - secret.size)
+ osecret = isecret.dup
+ 0.upto(63) do |i|
+ isecret[i] ^= 0x36
+ osecret[i] ^= 0x5c
+ end
+ tmp = Digest::MD5.digest(isecret + challenge)
+ tmp = Digest::MD5.hexdigest(osecret + tmp)
- # CRAM-MD5: [RFC2195]
- def cram_md5_response(secret, challenge)
- tmp = Digest::MD5.digest(cram_secret(secret, IMASK) + challenge)
- Digest::MD5.hexdigest(cram_secret(secret, OMASK) + tmp)
+ res = get_response(base64_encode(user + ' ' + tmp))
+ }
+ raise SMTPAuthenticationError, res unless /\A2../ === res
end
- CRAM_BUFSIZE = 64
-
- def cram_secret(secret, mask)
- secret = Digest::MD5.digest(secret) if secret.size > CRAM_BUFSIZE
- buf = secret.ljust(CRAM_BUFSIZE, "\0")
- 0.upto(buf.size - 1) do |i|
- buf[i] = (buf[i].ord ^ mask).chr
- end
- buf
+ def base64_encode( str )
+ # expects "str" may not become too long
+ [str].pack('m').gsub(/\s+/, '')
end
#
# SMTP command dispatcher
#
- public
+ private
- def starttls
- getok('STARTTLS')
+ def helo( domain )
+ getok('HELO %s', domain)
end
- def helo(domain)
- getok("HELO #{domain}")
+ def ehlo( domain )
+ getok('EHLO %s', domain)
end
- def ehlo(domain)
- getok("EHLO #{domain}")
+ def mailfrom( fromaddr )
+ getok('MAIL FROM:<%s>', fromaddr)
end
- def mailfrom(from_addr)
- if $SAFE > 0
- raise SecurityError, 'tainted from_addr' if from_addr.tainted?
- end
- getok("MAIL FROM:<#{from_addr}>")
- end
-
- def rcptto_list(to_addrs)
- raise ArgumentError, 'mail destination not given' if to_addrs.empty?
- to_addrs.flatten.each do |addr|
- rcptto addr
- end
- end
-
- def rcptto(to_addr)
- if $SAFE > 0
- raise SecurityError, 'tainted to_addr' if to_addr.tainted?
- end
- getok("RCPT TO:<#{to_addr}>")
- end
-
- # This method sends a message.
- # If +msgstr+ is given, sends it as a message.
- # If block is given, yield a message writer stream.
- # You must write message before the block is closed.
- #
- # # Example 1 (by string)
- # smtp.data(<<EndMessage)
- # From: john@example.com
- # To: betty@example.com
- # Subject: I found a bug
- #
- # Check vm.c:58879.
- # EndMessage
- #
- # # Example 2 (by block)
- # smtp.data {|f|
- # f.puts "From: john@example.com"
- # f.puts "To: betty@example.com"
- # f.puts "Subject: I found a bug"
- # f.puts ""
- # f.puts "Check vm.c:58879."
- # }
- #
- def data(msgstr = nil, &block) #:yield: stream
- if msgstr and block
- raise ArgumentError, "message and block are exclusive"
- end
- unless msgstr or block
- raise ArgumentError, "message or block is required"
- end
- res = critical {
- check_continue get_response('DATA')
- if msgstr
- @socket.write_message msgstr
- else
- @socket.write_message_by_block(&block)
- end
- recv_response()
- }
- check_response res
- res
+ def rcptto( to )
+ getok('RCPT TO:<%s>', to)
end
def quit
getok('QUIT')
end
+ #
+ # row level library
+ #
+
private
- def getok(reqline)
+ def getok( fmt, *args )
res = critical {
- @socket.writeline reqline
+ @socket.writeline sprintf(fmt, *args)
recv_response()
}
- check_response res
- res
+ return check_response(res)
end
- def get_response(reqline)
- @socket.writeline reqline
+ def get_response( fmt, *args )
+ @socket.writeline sprintf(fmt, *args)
recv_response()
end
def recv_response
- buf = ''
+ res = ''
while true
line = @socket.readline
- buf << line << "\n"
- break unless line[3,1] == '-' # "210-PIPELINING"
+ res << line << "\n"
+ break unless line[3] == ?- # "210-PIPELINING"
end
- Response.parse(buf)
+ res
+ end
+
+ def check_response( res, allow_continue = false )
+ return res if /\A2/ === res
+ return res if allow_continue and /\A3/ === res
+ err = case res
+ when /\A4/ then SMTPServerBusy
+ when /\A50/ then SMTPSyntaxError
+ when /\A55/ then SMTPFatalError
+ else SMTPUnknownError
+ end
+ raise err, res
end
- def critical(&block)
+ def critical( &block )
return '200 dummy reply code' if @error_occured
begin
return yield()
@@ -925,90 +690,8 @@ module Net
end
end
- def check_response(res)
- unless res.success?
- raise res.exception_class, res.message
- end
- end
-
- def check_continue(res)
- unless res.continue?
- raise SMTPUnknownError, "could not get 3xx (#{res.status})"
- end
- end
-
- def check_auth_response(res)
- unless res.success?
- raise SMTPAuthenticationError, res.message
- end
- end
-
- def check_auth_continue(res)
- unless res.continue?
- raise res.exception_class, res.message
- end
- end
-
- class Response
- def Response.parse(str)
- new(str[0,3], str)
- end
-
- def initialize(status, string)
- @status = status
- @string = string
- end
-
- attr_reader :status
- attr_reader :string
-
- def status_type_char
- @status[0, 1]
- end
-
- def success?
- status_type_char() == '2'
- end
-
- def continue?
- status_type_char() == '3'
- end
-
- def message
- @string.lines.first
- end
-
- def cram_md5_challenge
- @string.split(/ /)[1].unpack('m')[0]
- end
-
- def capabilities
- return {} unless @string[3, 1] == '-'
- h = {}
- @string.lines.drop(1).each do |line|
- k, *v = line[4..-1].chomp.split(nil)
- h[k] = v
- end
- h
- end
-
- def exception_class
- case @status
- when /\A4/ then SMTPServerBusy
- when /\A50/ then SMTPSyntaxError
- when /\A53/ then SMTPAuthenticationError
- when /\A5/ then SMTPFatalError
- else SMTPUnknownError
- end
- end
- end
-
- def logging(msg)
- @debug_output << msg + "\n" if @debug_output
- end
-
end # class SMTP
SMTPSession = SMTP
-end
+end # module Net
diff --git a/lib/net/telnet.rb b/lib/net/telnet.rb
index 73471c3327..c5f8b0429a 100644
--- a/lib/net/telnet.rb
+++ b/lib/net/telnet.rb
@@ -520,15 +520,10 @@ module Net
# value specified when this instance was created will be
# used, or, failing that, the default value of 0 seconds,
# which means not to wait for more input.
- # FailEOF:: if true, when the remote end closes the connection then an
- # EOFError will be raised. Otherwise, defaults to the old
- # behaviour that the function will return whatever data
- # has been received already, or nil if nothing was received.
#
def waitfor(options) # :yield: recvdata
time_out = @options["Timeout"]
waittime = @options["Waittime"]
- fail_eof = @options["FailEOF"]
if options.kind_of?(Hash)
prompt = if options.has_key?("Match")
@@ -540,7 +535,6 @@ module Net
end
time_out = options["Timeout"] if options.has_key?("Timeout")
waittime = options["Waittime"] if options.has_key?("Waittime")
- fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
else
prompt = options
end
@@ -565,8 +559,7 @@ module Net
Integer(c.rindex(/#{IAC}#{SB}/no))
buf = preprocess(c[0 ... c.rindex(/#{IAC}#{SB}/no)])
rest = c[c.rindex(/#{IAC}#{SB}/no) .. -1]
- elsif pt = c.rindex(/#{IAC}[^#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]?\z/no) ||
- c.rindex(/\r\z/no)
+ elsif pt = c.rindex(/#{IAC}[^#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]?\z/no)
buf = preprocess(c[0 ... pt])
rest = c[pt .. -1]
else
@@ -578,21 +571,14 @@ module Net
#
# We cannot use preprocess() on this data, because that
# method makes some Telnetmode-specific assumptions.
- buf = rest + c
+ buf = c
+ buf.gsub!(/#{EOL}/no, "\n") unless @options["Binmode"]
rest = ''
- unless @options["Binmode"]
- if pt = buf.rindex(/\r\z/no)
- buf = buf[0 ... pt]
- rest = buf[pt .. -1]
- end
- buf.gsub!(/#{EOL}/no, "\n")
- end
end
@log.print(buf) if @options.has_key?("Output_log")
line += buf
yield buf if block_given?
rescue EOFError # End of file reached
- raise if fail_eof
if line == ''
line = nil
yield nil if block_given?
@@ -719,7 +705,7 @@ module Net
# data is also yielded to the block as it is received.
def login(options, password = nil) # :yield: recvdata
login_prompt = /[Ll]ogin[: ]*\z/n
- password_prompt = /[Pp]ass(?:word|phrase)[: ]*\z/n
+ password_prompt = /Password[: ]*\z/n
if options.kind_of?(Hash)
username = options["Name"]
password = options["Password"]
diff --git a/lib/open-uri.rb b/lib/open-uri.rb
index 54b42f336f..d69f7dbe41 100644
--- a/lib/open-uri.rb
+++ b/lib/open-uri.rb
@@ -240,6 +240,16 @@ module OpenURI
resp = nil
http.start {
+ if target.class == URI::HTTPS
+ # xxx: information hiding violation
+ sock = http.instance_variable_get(:@socket)
+ if sock.respond_to?(:io)
+ sock = sock.io # 1.9
+ else
+ sock = sock.instance_variable_get(:@socket) # 1.8
+ end
+ sock.post_connection_check(target_host)
+ end
req = Net::HTTP::Get.new(request_uri, header)
if options.include? :http_basic_authentication
user, pass = options[:http_basic_authentication]
@@ -567,7 +577,7 @@ module URI
proxy_uri = nil
end
else # http_proxy is safe to use because ENV is case sensitive.
- proxy_uri = ENV.to_hash[name]
+ proxy_uri = ENV[name]
end
if !proxy_uri
# Use CGI_HTTP_PROXY. cf. libwww-perl.
diff --git a/lib/optparse.rb b/lib/optparse.rb
index 389a815ffc..2c91cd004f 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -379,7 +379,7 @@ class OptionParser
while s = lopts.shift
l = left[-1].length + s.length
l += arg.length if left.size == 1 && arg
- l < max or sopts.empty? or left << ''
+ l < max or left << ''
left[-1] << if left[-1].empty? then ' ' * 4 else ', ' end << s
end
@@ -633,10 +633,8 @@ class OptionParser
list.each do |opt|
if opt.respond_to?(:summarize) # perhaps OptionParser::Switch
opt.summarize(*args, &block)
- elsif !opt
+ elsif !opt or opt.empty?
yield("")
- elsif opt.respond_to?(:each_line)
- opt.each_line(&block)
else
opt.each(&block)
end
@@ -826,7 +824,7 @@ class OptionParser
#
# Directs to reject specified class argument.
#
- # +t+:: Argument class specifier, any object including Class.
+ # +t+:: Argument class speficier, any object including Class.
#
# reject(t)
#
@@ -1037,13 +1035,13 @@ class OptionParser
# "-x[OPTIONAL]"
# "-x"
# There is also a special form which matches character range (not full
- # set of regular expression):
+ # set of regural expression):
# "-[a-z]MANDATORY"
# "-[a-z][OPTIONAL]"
# "-[a-z]"
#
# [Argument style and description:]
- # Instead of specifying mandatory or optional arguments directly in the
+ # Instead of specifying mandatory or optional orguments directly in the
# switch parameter, this separate parameter can be used.
# "=MANDATORY"
# "=[OPTIONAL]"
@@ -1079,7 +1077,7 @@ class OptionParser
# directly specified pattern(any object possible to match)
if !(String === o) and o.respond_to?(:match)
pattern = notwice(o, pattern, 'pattern')
- conv = pattern.method(:convert).to_proc if pattern.respond_to?(:convert)
+ conv = (pattern.method(:convert).to_proc if pattern.respond_to?(:convert))
next
end
@@ -1092,7 +1090,7 @@ class OptionParser
when CompletingHash
when nil
pattern = CompletingHash.new
- conv = pattern.method(:convert).to_proc if pattern.respond_to?(:convert)
+ conv = (pattern.method(:convert).to_proc if pattern.respond_to?(:convert))
else
raise ArgumentError, "argument pattern given twice"
end
@@ -1476,7 +1474,6 @@ class OptionParser
#
def environment(env = File.basename($0, '.*'))
env = ENV[env] || ENV[env.upcase] or return
- require 'shellwords'
parse(*Shellwords.shellwords(env))
end
diff --git a/lib/pp.rb b/lib/pp.rb
index 14fe62ee95..8080d879f9 100644
--- a/lib/pp.rb
+++ b/lib/pp.rb
@@ -255,9 +255,9 @@ class PP < PrettyPrint
# This module provides predefined #pretty_print methods for some of
# the most commonly used built-in classes for convenience.
def pretty_print(q)
- if /\(Kernel\)#/ !~ Object.instance_method(:method).bind(self).call(:inspect).inspect
+ if /\(Kernel\)#/ !~ method(:inspect).inspect
q.text self.inspect
- elsif /\(Kernel\)#/ !~ Object.instance_method(:method).bind(self).call(:to_s).inspect && instance_variables.empty?
+ elsif /\(Kernel\)#/ !~ method(:to_s).inspect && instance_variables.empty?
q.text self.to_s
else
q.pp_object(self)
@@ -289,7 +289,7 @@ class PP < PrettyPrint
# However, doing this requires that every class that #inspect is called on
# implement #pretty_print, or a RuntimeError will be raised.
def pretty_print_inspect
- if /\(PP::ObjectMixin\)#/ =~ Object.instance_method(:method).bind(self).call(:pretty_print).inspect
+ if /\(PP::ObjectMixin\)#/ =~ method(:pretty_print).inspect
raise "pretty_print is not overridden for #{self.class}"
end
PP.singleline_pp(self, '')
@@ -488,13 +488,6 @@ if __FILE__ == $0
a = OverriddenStruct.new(1,2)
assert_equal("#<struct Struct::OverriddenStruct members=1, class=2>\n", PP.pp(a, ''))
end
-
- def test_redefined_method
- o = ""
- def o.method
- end
- assert_equal(%(""\n), PP.pp(o, ""))
- end
end
class HasInspect
diff --git a/lib/pstore.rb b/lib/pstore.rb
index ab495d9ed7..6df64474ab 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -11,14 +11,14 @@ require "fileutils"
require "digest/md5"
#
-# PStore implements a file based persistence mechanism based on a Hash. User
+# PStore implements a file based persistance mechanism based on a Hash. User
# code can store hierarchies of Ruby objects (values) into the data store file
# by name (keys). An object hierarchy may be just a single object. User code
# may later read values back from the data store or even update data, as needed.
#
# The transactional behavior ensures that any changes succeed or fail together.
# This can be used to ensure that the data store is not left in a transitory
-# state, where some values were updated but others were not.
+# state, where some values were upated but others were not.
#
# Behind the scenes, Ruby objects are stored to the data store file with
# Marshal. That carries the usual limitations. Proc objects cannot be
diff --git a/lib/rational.rb b/lib/rational.rb
index 69a3b76bf1..ce754cfa3c 100644
--- a/lib/rational.rb
+++ b/lib/rational.rb
@@ -240,10 +240,6 @@ class Rational < Numeric
end
end
- def div(other)
- (self / other).floor
- end
-
#
# Returns the remainder when this value is divided by +other+.
#
@@ -255,7 +251,7 @@ class Rational < Numeric
# r % 0.26 # -> 0.19
#
def % (other)
- value = (self / other).floor
+ value = (self / other).to_i
return self - other * value
end
@@ -267,7 +263,7 @@ class Rational < Numeric
# r.divmod Rational(1,2) # -> [3, Rational(1,4)]
#
def divmod(other)
- value = (self / other).floor
+ value = (self / other).to_i
return value, self - other * value
end
@@ -276,7 +272,7 @@ class Rational < Numeric
#
def abs
if @numerator > 0
- self
+ Rational.new!(@numerator, @denominator)
else
Rational.new!(-@numerator, @denominator)
end
@@ -344,43 +340,15 @@ class Rational < Numeric
# Converts the rational to an Integer. Not the _nearest_ integer, the
# truncated integer. Study the following example carefully:
# Rational(+7,4).to_i # -> 1
- # Rational(-7,4).to_i # -> -1
+ # Rational(-7,4).to_i # -> -2
# (-1.75).to_i # -> -1
#
# In other words:
# Rational(-7,4) == -1.75 # -> true
- # Rational(-7,4).to_i == (-1.75).to_i # -> true
+ # Rational(-7,4).to_i == (-1.75).to_i # false
#
-
-
- def floor()
- @numerator.div(@denominator)
- end
-
- def ceil()
- -((-@numerator).div(@denominator))
- end
-
- def truncate()
- if @numerator < 0
- return -((-@numerator).div(@denominator))
- end
- @numerator.div(@denominator)
- end
-
- alias_method :to_i, :truncate
-
- def round()
- if @numerator < 0
- num = -@numerator
- num = num * 2 + @denominator
- den = @denominator * 2
- -(num.div(den))
- else
- num = @numerator * 2 + @denominator
- den = @denominator * 2
- num.div(den)
- end
+ def to_i
+ Integer(@numerator.div(@denominator))
end
#
@@ -513,11 +481,10 @@ class Integer
end
class Fixnum
- remove_method :quo
-
- # If Rational is defined, returns a Rational number instead of a Float.
+ undef quo
+ # If Rational is defined, returns a Rational number instead of a Fixnum.
def quo(other)
- Rational.new!(self, 1) / other
+ Rational.new!(self,1) / other
end
alias rdiv quo
@@ -526,18 +493,25 @@ class Fixnum
if other >= 0
self.power!(other)
else
- Rational.new!(self, 1)**other
+ Rational.new!(self,1)**other
end
end
+ unless defined? 1.power!
+ alias power! **
+ alias ** rpower
+ end
end
class Bignum
- remove_method :quo
+ unless defined? Complex
+ alias power! **
+ end
- # If Rational is defined, returns a Rational number instead of a Float.
+ undef quo
+ # If Rational is defined, returns a Rational number instead of a Bignum.
def quo(other)
- Rational.new!(self, 1) / other
+ Rational.new!(self,1) / other
end
alias rdiv quo
@@ -550,15 +524,7 @@ class Bignum
end
end
-end
-
-unless defined? 1.power!
- class Fixnum
- alias power! **
- alias ** rpower
- end
- class Bignum
- alias power! **
+ unless defined? Complex
alias ** rpower
end
end
diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb
index 7e35abdb0b..4dfe45169c 100644
--- a/lib/rdoc/options.rb
+++ b/lib/rdoc/options.rb
@@ -544,18 +544,18 @@ class Options
# so we'll bypass the test under Windows
def check_diagram
- return if RUBY_PLATFORM =~ /mswin|cygwin|mingw|bccwin/
+ return if RUBY_PLATFORM =~ /win/
ok = false
ver = nil
IO.popen("dot -V 2>&1") do |io|
ver = io.read
- if ver =~ /dot.+version(?:\s+gviz)?\s+(\d+)\.(\d+)/
+ if ver =~ /dot\s+version(?:\s+gviz)?\s+(\d+)\.(\d+)/
ok = ($1.to_i > 1) || ($1.to_i == 1 && $2.to_i >= 8)
end
end
unless ok
- if ver =~ /^dot.+version/
+ if ver =~ /^dot version/
$stderr.puts "Warning: You may need dot V1.8.6 or later to use\n",
"the --diagram option correctly. You have:\n\n ",
ver,
diff --git a/lib/rdoc/parsers/parse_c.rb b/lib/rdoc/parsers/parse_c.rb
index 7eefa29706..25fc66af3f 100644
--- a/lib/rdoc/parsers/parse_c.rb
+++ b/lib/rdoc/parsers/parse_c.rb
@@ -117,10 +117,10 @@ module RDoc
# method in the HTML output. This method must be in the same source file
# as the rb_define_method.
#
- # C classes can be diagrammed (see /tc/dl/ruby/ruby/error.c), and RDoc
+ # C classes can be diagramed (see /tc/dl/ruby/ruby/error.c), and RDoc
# integrates C and Ruby source into one tree
#
- # The comment blocks may include special directives:
+ # The comment blocks may include special direcives:
#
# [Document-class: <i>name</i>]
# This comment block is documentation for the given class. Use this
@@ -131,10 +131,10 @@ module RDoc
# automatically find the method from it's declaration
#
# [call-seq: <i>text up to an empty line</i>]
- # Because C source doesn't give descriptive names to Ruby-level parameters,
+ # Because C source doesn't give descripive names to Ruby-level parameters,
# you need to document the calling sequence explicitly
#
- # In addition, RDoc assumes by default that the C method implementing a
+ # In additon, RDoc assumes by default that the C method implementing a
# Ruby function is in the same source file as the rb_define_method call.
# If this isn't the case, add the comment
#
diff --git a/lib/rdoc/parsers/parse_f95.rb b/lib/rdoc/parsers/parse_f95.rb
index f1a1ae4d4b..f3f6d76103 100644
--- a/lib/rdoc/parsers/parse_f95.rb
+++ b/lib/rdoc/parsers/parse_f95.rb
@@ -201,7 +201,7 @@ module RDoc
@progress = $stderr unless options.quiet
end
- # define code constructs
+ # devine code constructs
def scan
# remove private comment
@@ -1065,7 +1065,7 @@ module RDoc
#
# If "all" argument is true, information of all arguments are returned.
# If "modified_params" is true, list of arguments are decorated,
- # for example, optional arguments are parenthetic as "[arg]".
+ # for exameple, optional arguments are parenthetic as "[arg]".
#
def find_arguments(args, text, all=nil, indent=nil, modified_params=nil)
return unless args || all
@@ -1143,8 +1143,8 @@ EOF
#
# Comments just after module or subprogram, or arguments are
- # returned. If "COMMENTS_ARE_UPPER" is true, comments just before
- # modules or subprograms are returned
+ # returnd. If "COMMENTS_ARE_UPPER" is true, comments just before
+ # modules or subprograms are returnd
#
def find_comments text
return "" unless text
diff --git a/lib/rdoc/parsers/parse_rb.rb b/lib/rdoc/parsers/parse_rb.rb
index 750c483c15..58ba06084e 100644
--- a/lib/rdoc/parsers/parse_rb.rb
+++ b/lib/rdoc/parsers/parse_rb.rb
@@ -1546,15 +1546,10 @@ module RDoc
tk = get_tk
while tk.kind_of?(TkCOMMENT)
- if first_line && /\A#!/ =~ tk.text
- skip_tkspace
- tk = get_tk
- elsif first_line && /\A#\s*-\*-/ =~ tk.text
- first_line = false
+ if first_line && tk.text[0,2] == "#!"
skip_tkspace
tk = get_tk
else
- first_line = false
res << tk.text << "\n"
tk = get_tk
if tk.kind_of? TkNL
@@ -1562,6 +1557,7 @@ module RDoc
tk = get_tk
end
end
+ first_line = false
end
unget_tk(tk)
res
diff --git a/lib/rdoc/ri/ri_options.rb b/lib/rdoc/ri/ri_options.rb
index 179ef96cea..db9f4afecf 100644
--- a/lib/rdoc/ri/ri_options.rb
+++ b/lib/rdoc/ri/ri_options.rb
@@ -62,11 +62,10 @@ module RI
(RI::Paths::HOMEDIR || "No ~/.rdoc found") ],
[ "--gems", nil, nil,
- "Include documentation from RubyGems:\n" +
- (RI::Paths::GEMDIRS ?
- Gem.path.map { |dir| " #{dir}/doc/*/ri" }.join("\n") :
- "No Rubygems ri found.") ],
-
+ "Include documentation from Rubygems:\n " +
+ (RI::Paths::GEMDIRS ? "#{Gem.path}/doc/*/ri" :
+ "No Rubygems ri found.") ],
+
[ "--format", "-f", "<name>",
"Format to use when displaying output:\n" +
" " + RI::TextFormatter.list + "\n" +
@@ -117,8 +116,7 @@ module RI
def OptionList.error(msg)
$stderr.puts
$stderr.puts msg
- name = File.basename $PROGRAM_NAME
- $stderr.puts "\nFor help on options, try '#{name} --help'\n\n"
+ $stderr.puts "\nFor help on options, try 'ri --help'\n\n"
exit 1
end
@@ -138,11 +136,7 @@ module RI
RI::Paths::HOMEDIR
]
- if RI::Paths::GEMDIRS then
- Gem.path.each do |dir|
- directories << "#{dir}/doc/*/ri"
- end
- end
+ directories << "#{Gem.path}/doc/*/ri" if RI::Paths::GEMDIRS
directories = directories.join("\n ")
@@ -163,16 +157,16 @@ module RI
For example:
- #{name} File
- #{name} File.new
- #{name} F.n
- #{name} zip
+ ri File
+ ri File.new
+ ri F.n
+ ri zip
Note that shell quoting may be required for method names
containing punctuation:
- #{name} 'Array.[]'
- #{name} compact\\!
+ ri 'Array.[]'
+ ri compact\\!
By default ri searches for documentation in the following
directories:
@@ -186,8 +180,8 @@ module RI
EOT
if short_form
- puts "For help on options, type '#{name} -h'"
- puts "For a list of classes I know about, type '#{name} -c'"
+ puts "For help on options, type 'ri -h'"
+ puts "For a list of classes I know about, type 'ri -c'"
else
puts "Options:\n\n"
OPTION_LIST.each do|long, short, arg, desc|
diff --git a/lib/rdoc/ri/ri_paths.rb b/lib/rdoc/ri/ri_paths.rb
index 9768f12b7d..32363bf70a 100644
--- a/lib/rdoc/ri/ri_paths.rb
+++ b/lib/rdoc/ri/ri_paths.rb
@@ -44,29 +44,8 @@ module RI
begin
require 'rubygems'
-
- # HACK dup'd from Gem.latest_partials and friends
- all_paths = []
-
- all_paths = Gem.path.map do |dir|
- Dir[File.join(dir, 'doc', '*', 'ri')]
- end.flatten
-
- ri_paths = {}
-
- all_paths.each do |dir|
- base = File.basename File.dirname(dir)
- if base =~ /(.*)-((\d+\.)*\d+)/ then
- name, version = $1, $2
- ver = Gem::Version.new version
- if ri_paths[name].nil? or ver > ri_paths[name][0] then
- ri_paths[name] = [ver, dir]
- end
- end
- end
-
- GEMDIRS = ri_paths.map { |k,v| v.last }.sort
- GEMDIRS.each { |dir| RI::Paths::PATH << dir }
+ GEMDIRS = Dir["#{Gem.path}/doc/*/ri"]
+ GEMDIRS.each { |path| RI::Paths::PATH << path }
rescue LoadError
GEMDIRS = nil
end
@@ -76,7 +55,7 @@ module RI
def self.path(use_system, use_site, use_home, use_gems, *extra_dirs)
path = raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
- return path.select { |directory| File.directory? directory }
+ return path.select { |path| File.directory? path }
end
# Returns the selected documentation directories including nonexistent
diff --git a/lib/resolv-replace.rb b/lib/resolv-replace.rb
index 63d58cea27..5d15b4577c 100644
--- a/lib/resolv-replace.rb
+++ b/lib/resolv-replace.rb
@@ -23,8 +23,7 @@ end
class UDPSocket
alias original_resolv_bind bind
def bind(host, port)
- host = IPSocket.getaddress(host) if host != ""
- original_resolv_bind(host, port)
+ original_resolv_bind(IPSocket.getaddress(host), port)
end
alias original_resolv_connect connect
diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1c03f0c003..49e40bdf07 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -1,110 +1,239 @@
+=begin
+= resolv library
+resolv.rb is a resolver library written in Ruby.
+Since it is written in Ruby, it is thread-aware.
+I.e. it can resolv many hostnames concurrently.
+
+It is possible to lookup various resources of DNS using DNS module directly.
+
+== example
+ p Resolv.getaddress("www.ruby-lang.org")
+ p Resolv.getname("210.251.121.214")
+
+ Resolv::DNS.open {|dns|
+ p dns.getresources("www.ruby-lang.org", Resolv::DNS::Resource::IN::A).collect {|r| r.address}
+ p dns.getresources("ruby-lang.org", Resolv::DNS::Resource::IN::MX).collect {|r| [r.exchange.to_s, r.preference]}
+ }
+
+== Resolv class
+
+=== class methods
+--- Resolv.getaddress(name)
+--- Resolv.getaddresses(name)
+--- Resolv.each_address(name) {|address| ...}
+ They lookups IP addresses of ((|name|)) which represents a hostname
+ as a string by default resolver.
+
+ getaddress returns first entry of lookupped addresses.
+ getaddresses returns lookupped addresses as an array.
+ each_address iterates over lookupped addresses.
+
+--- Resolv.getname(address)
+--- Resolv.getnames(address)
+--- Resolv.each_name(address) {|name| ...}
+ lookups hostnames of ((|address|)) which represents IP address as a string.
+
+ getname returns first entry of lookupped names.
+ getnames returns lookupped names as an array.
+ each_names iterates over lookupped names.
+
+== Resolv::Hosts class
+hostname resolver using /etc/hosts format.
+
+=== class methods
+--- Resolv::Hosts.new(hosts='/etc/hosts')
+
+=== methods
+--- Resolv::Hosts#getaddress(name)
+--- Resolv::Hosts#getaddresses(name)
+--- Resolv::Hosts#each_address(name) {|address| ...}
+ address lookup methods.
+
+--- Resolv::Hosts#getname(address)
+--- Resolv::Hosts#getnames(address)
+--- Resolv::Hosts#each_name(address) {|name| ...}
+ hostnames lookup methods.
+
+== Resolv::DNS class
+DNS stub resolver.
+
+=== class methods
+--- Resolv::DNS.new(config_info=nil)
+
+ ((|config_info|)) should be nil, a string or a hash.
+ If nil is given, /etc/resolv.conf and platform specific information is used.
+ If a string is given, it should be a filename which format is same as /etc/resolv.conf.
+ If a hash is given, it may contains information for nameserver, search and ndots as follows.
+
+ Resolv::DNS.new({:nameserver=>["210.251.121.21"], :search=>["ruby-lang.org"], :ndots=>1})
+
+--- Resolv::DNS.open(config_info=nil)
+--- Resolv::DNS.open(config_info=nil) {|dns| ...}
+
+=== methods
+--- Resolv::DNS#close
+
+--- Resolv::DNS#getaddress(name)
+--- Resolv::DNS#getaddresses(name)
+--- Resolv::DNS#each_address(name) {|address| ...}
+ address lookup methods.
+
+ ((|name|)) must be a instance of Resolv::DNS::Name or String. Lookupped
+ address is represented as an instance of Resolv::IPv4 or Resolv::IPv6.
+
+--- Resolv::DNS#getname(address)
+--- Resolv::DNS#getnames(address)
+--- Resolv::DNS#each_name(address) {|name| ...}
+ hostnames lookup methods.
+
+ ((|address|)) must be a instance of Resolv::IPv4, Resolv::IPv6 or String.
+ Lookupped name is represented as an instance of Resolv::DNS::Name.
+
+--- Resolv::DNS#getresource(name, typeclass)
+--- Resolv::DNS#getresources(name, typeclass)
+--- Resolv::DNS#each_resource(name, typeclass) {|resource| ...}
+ They lookup DNS resources of ((|name|)).
+ ((|name|)) must be a instance of Resolv::Name or String.
+
+ ((|typeclass|)) should be one of follows:
+ * Resolv::DNS::Resource::IN::ANY
+ * Resolv::DNS::Resource::IN::NS
+ * Resolv::DNS::Resource::IN::CNAME
+ * Resolv::DNS::Resource::IN::SOA
+ * Resolv::DNS::Resource::IN::HINFO
+ * Resolv::DNS::Resource::IN::MINFO
+ * Resolv::DNS::Resource::IN::MX
+ * Resolv::DNS::Resource::IN::TXT
+ * Resolv::DNS::Resource::IN::ANY
+ * Resolv::DNS::Resource::IN::A
+ * Resolv::DNS::Resource::IN::WKS
+ * Resolv::DNS::Resource::IN::PTR
+ * Resolv::DNS::Resource::IN::AAAA
+
+ Lookupped resource is represented as an instance of (a subclass of)
+ Resolv::DNS::Resource.
+ (Resolv::DNS::Resource::IN::A, etc.)
+
+== Resolv::DNS::Resource::IN::NS class
+--- name
+== Resolv::DNS::Resource::IN::CNAME class
+--- name
+== Resolv::DNS::Resource::IN::SOA class
+--- mname
+--- rname
+--- serial
+--- refresh
+--- retry
+--- expire
+--- minimum
+== Resolv::DNS::Resource::IN::HINFO class
+--- cpu
+--- os
+== Resolv::DNS::Resource::IN::MINFO class
+--- rmailbx
+--- emailbx
+== Resolv::DNS::Resource::IN::MX class
+--- preference
+--- exchange
+== Resolv::DNS::Resource::IN::TXT class
+--- data
+== Resolv::DNS::Resource::IN::A class
+--- address
+== Resolv::DNS::Resource::IN::WKS class
+--- address
+--- protocol
+--- bitmap
+== Resolv::DNS::Resource::IN::PTR class
+--- name
+== Resolv::DNS::Resource::IN::AAAA class
+--- address
+
+== Resolv::DNS::Name class
+
+=== class methods
+--- Resolv::DNS::Name.create(name)
+
+=== methods
+--- Resolv::DNS::Name#to_s
+
+== Resolv::DNS::Resource class
+
+== Resolv::IPv4 class
+=== class methods
+--- Resolv::IPv4.create(address)
+
+=== methods
+--- Resolv::IPv4#to_s
+--- Resolv::IPv4#to_name
+
+=== constants
+--- Resolv::IPv4::Regex
+ regular expression for IPv4 address.
+
+== Resolv::IPv6 class
+=== class methods
+--- Resolv::IPv6.create(address)
+
+=== methods
+--- Resolv::IPv6#to_s
+--- Resolv::IPv6#to_name
+
+=== constants
+--- Resolv::IPv6::Regex
+ regular expression for IPv6 address.
+
+== Bugs
+* NIS is not supported.
+* /etc/nsswitch.conf is not supported.
+* IPv6 is not supported.
+
+=end
+
require 'socket'
require 'fcntl'
require 'timeout'
require 'thread'
-begin
- require 'securerandom'
-rescue LoadError
-end
-
-# Resolv is a thread-aware DNS resolver library written in Ruby. Resolv can
-# handle multiple DNS requests concurrently without blocking. The ruby
-# interpreter.
-#
-# See also resolv-replace.rb to replace the libc resolver with # Resolv.
-#
-# Resolv can look up various DNS resources using the DNS module directly.
-#
-# Examples:
-#
-# p Resolv.getaddress "www.ruby-lang.org"
-# p Resolv.getname "210.251.121.214"
-#
-# Resolv::DNS.open do |dns|
-# ress = dns.getresources "www.ruby-lang.org", Resolv::DNS::Resource::IN::A
-# p ress.map { |r| r.address }
-# ress = dns.getresources "ruby-lang.org", Resolv::DNS::Resource::IN::MX
-# p ress.map { |r| [r.exchange.to_s, r.preference] }
-# end
-#
-#
-# == Bugs
-#
-# * NIS is not supported.
-# * /etc/nsswitch.conf is not supported.
-
class Resolv
-
- ##
- # Looks up the first IP address for +name+.
-
def self.getaddress(name)
DefaultResolver.getaddress(name)
end
- ##
- # Looks up all IP address for +name+.
-
def self.getaddresses(name)
DefaultResolver.getaddresses(name)
end
- ##
- # Iterates over all IP addresses for +name+.
-
def self.each_address(name, &block)
DefaultResolver.each_address(name, &block)
end
- ##
- # Looks up the hostname of +address+.
-
def self.getname(address)
DefaultResolver.getname(address)
end
- ##
- # Looks up all hostnames for +address+.
-
def self.getnames(address)
DefaultResolver.getnames(address)
end
- ##
- # Iterates over all hostnames for +address+.
-
def self.each_name(address, &proc)
DefaultResolver.each_name(address, &proc)
end
- ##
- # Creates a new Resolv using +resolvers+.
-
def initialize(resolvers=[Hosts.new, DNS.new])
@resolvers = resolvers
end
- ##
- # Looks up the first IP address for +name+.
-
def getaddress(name)
each_address(name) {|address| return address}
raise ResolvError.new("no address for #{name}")
end
- ##
- # Looks up all IP address for +name+.
-
def getaddresses(name)
ret = []
each_address(name) {|address| ret << address}
return ret
end
- ##
- # Iterates over all IP addresses for +name+.
-
def each_address(name)
if AddressRegex =~ name
yield name
@@ -120,26 +249,17 @@ class Resolv
}
end
- ##
- # Looks up the hostname of +address+.
-
def getname(address)
each_name(address) {|name| return name}
raise ResolvError.new("no name for #{address}")
end
- ##
- # Looks up all hostnames for +address+.
-
def getnames(address)
ret = []
each_name(address) {|name| ret << name}
return ret
end
- ##
- # Iterates over all hostnames for +address+.
-
def each_name(address)
yielded = false
@resolvers.each {|r|
@@ -151,37 +271,27 @@ class Resolv
}
end
- ##
- # Indicates a failure to resolve a name or address.
-
- class ResolvError < StandardError; end
-
- ##
- # Indicates a timeout resolving a name or address.
-
- class ResolvTimeout < TimeoutError; end
+ class ResolvError < StandardError
+ end
- ##
- # DNS::Hosts is a hostname resolver that uses the system hosts file.
+ class ResolvTimeout < TimeoutError
+ end
class Hosts
- if /mswin32|mingw|bccwin/ =~ RUBY_PLATFORM
+ if /mswin32|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
require 'win32/resolv'
DefaultFileName = Win32::Resolv.get_hosts_path
else
DefaultFileName = '/etc/hosts'
end
- ##
- # Creates a new DNS::Hosts, using +filename+ for its data source.
-
def initialize(filename = DefaultFileName)
@filename = filename
@mutex = Mutex.new
@initialized = nil
end
- def lazy_initialize # :nodoc:
+ def lazy_initialize
@mutex.synchronize {
unless @initialized
@name2addr = {}
@@ -212,26 +322,17 @@ class Resolv
self
end
- ##
- # Gets the IP address of +name+ from the hosts file.
-
def getaddress(name)
each_address(name) {|address| return address}
raise ResolvError.new("#{@filename} has no name: #{name}")
end
- ##
- # Gets all IP addresses for +name+ from the hosts file.
-
def getaddresses(name)
ret = []
each_address(name) {|address| ret << address}
return ret
end
- ##
- # Iterates over all IP addresses for +name+ retrieved from the hosts file.
-
def each_address(name, &proc)
lazy_initialize
if @name2addr.include?(name)
@@ -239,26 +340,17 @@ class Resolv
end
end
- ##
- # Gets the hostname of +address+ from the hosts file.
-
def getname(address)
each_name(address) {|name| return name}
raise ResolvError.new("#{@filename} has no address: #{address}")
end
- ##
- # Gets all hostnames for +address+ from the hosts file.
-
def getnames(address)
ret = []
each_name(address) {|name| ret << name}
return ret
end
- ##
- # Iterates over all hostnames for +address+ retrieved from the hosts file.
-
def each_name(address, &proc)
lazy_initialize
if @addr2name.include?(address)
@@ -267,39 +359,15 @@ class Resolv
end
end
- ##
- # Resolv::DNS is a DNS stub resolver.
- #
- # Information taken from the following places:
- #
- # * STD0013
- # * RFC 1035
- # * ftp://ftp.isi.edu/in-notes/iana/assignments/dns-parameters
- # * etc.
-
class DNS
-
- ##
- # Default DNS Port
+ # STD0013 (RFC 1035, etc.)
+ # ftp://ftp.isi.edu/in-notes/iana/assignments/dns-parameters
Port = 53
-
- ##
- # Default DNS UDP packet size
-
UDPSize = 512
- ##
- # Group of DNS resolver threads (obsolete)
-
DNSThreadGroup = ThreadGroup.new
- ##
- # Creates a new DNS resolver. See Resolv::DNS.new for argument details.
- #
- # Yields the created DNS resolver to the block, if given, otherwise
- # returns it.
-
def self.open(*args)
dns = new(*args)
return dns unless block_given?
@@ -310,113 +378,65 @@ class Resolv
end
end
- ##
- # Creates a new DNS resolver.
- #
- # +config_info+ can be:
- #
- # nil:: Uses /etc/resolv.conf.
- # String:: Path to a file using /etc/resolv.conf's format.
- # Hash:: Must contain :nameserver, :search and :ndots keys.
- #
- # Example:
- #
- # Resolv::DNS.new(:nameserver => ['210.251.121.21'],
- # :search => ['ruby-lang.org'],
- # :ndots => 1)
-
def initialize(config_info=nil)
@mutex = Mutex.new
@config = Config.new(config_info)
@initialized = nil
end
- def lazy_initialize # :nodoc:
+ def lazy_initialize
@mutex.synchronize {
unless @initialized
@config.lazy_initialize
+
+ if nameserver = @config.single?
+ @requester = Requester::ConnectedUDP.new(nameserver)
+ else
+ @requester = Requester::UnconnectedUDP.new
+ end
+
@initialized = true
end
}
self
end
- ##
- # Closes the DNS resolver.
-
def close
@mutex.synchronize {
if @initialized
+ @requester.close if @requester
+ @requester = nil
@initialized = false
end
}
end
- ##
- # Gets the IP address of +name+ from the DNS resolver.
- #
- # +name+ can be a Resolv::DNS::Name or a String. Retrieved address will
- # be a Resolv::IPv4 or Resolv::IPv6
-
def getaddress(name)
each_address(name) {|address| return address}
raise ResolvError.new("DNS result has no information for #{name}")
end
- ##
- # Gets all IP addresses for +name+ from the DNS resolver.
- #
- # +name+ can be a Resolv::DNS::Name or a String. Retrieved addresses will
- # be a Resolv::IPv4 or Resolv::IPv6
-
def getaddresses(name)
ret = []
each_address(name) {|address| ret << address}
return ret
end
- ##
- # Iterates over all IP addresses for +name+ retrieved from the DNS
- # resolver.
- #
- # +name+ can be a Resolv::DNS::Name or a String. Retrieved addresses will
- # be a Resolv::IPv4 or Resolv::IPv6
-
def each_address(name)
each_resource(name, Resource::IN::A) {|resource| yield resource.address}
- each_resource(name, Resource::IN::AAAA) {|resource| yield resource.address}
end
- ##
- # Gets the hostname for +address+ from the DNS resolver.
- #
- # +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
- # name will be a Resolv::DNS::Name.
-
def getname(address)
each_name(address) {|name| return name}
raise ResolvError.new("DNS result has no information for #{address}")
end
- ##
- # Gets all hostnames for +address+ from the DNS resolver.
- #
- # +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
- # names will be Resolv::DNS::Name instances.
-
def getnames(address)
ret = []
each_name(address) {|name| ret << name}
return ret
end
- ##
- # Iterates over all hostnames for +address+ retrieved from the DNS
- # resolver.
- #
- # +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
- # names will be Resolv::DNS::Name instances.
-
def each_name(address)
case address
when Name
@@ -431,51 +451,20 @@ class Resolv
each_resource(ptr, Resource::IN::PTR) {|resource| yield resource.name}
end
- ##
- # Look up the +typeclass+ DNS resource of +name+.
- #
- # +name+ must be a Resolv::DNS::Name or a String.
- #
- # +typeclass+ should be one of the following:
- #
- # * Resolv::DNS::Resource::IN::A
- # * Resolv::DNS::Resource::IN::AAAA
- # * Resolv::DNS::Resource::IN::ANY
- # * Resolv::DNS::Resource::IN::CNAME
- # * Resolv::DNS::Resource::IN::HINFO
- # * Resolv::DNS::Resource::IN::MINFO
- # * Resolv::DNS::Resource::IN::MX
- # * Resolv::DNS::Resource::IN::NS
- # * Resolv::DNS::Resource::IN::PTR
- # * Resolv::DNS::Resource::IN::SOA
- # * Resolv::DNS::Resource::IN::TXT
- # * Resolv::DNS::Resource::IN::WKS
- #
- # Returned resource is represented as a Resolv::DNS::Resource instance,
- # i.e. Resolv::DNS::Resource::IN::A.
-
def getresource(name, typeclass)
each_resource(name, typeclass) {|resource| return resource}
raise ResolvError.new("DNS result has no information for #{name}")
end
- ##
- # Looks up all +typeclass+ DNS resources for +name+. See #getresource for
- # argument details.
-
def getresources(name, typeclass)
ret = []
each_resource(name, typeclass) {|resource| ret << resource}
return ret
end
- ##
- # Iterates over all +typeclass+ DNS resources for +name+. See
- # #getresource for argument details.
-
def each_resource(name, typeclass, &proc)
lazy_initialize
- requester = make_requester
+ q = Queue.new
senders = {}
begin
@config.resolv(name) {|candidate, tout, nameserver|
@@ -484,9 +473,11 @@ class Resolv
msg.add_question(candidate, typeclass)
unless sender = senders[[candidate, nameserver]]
sender = senders[[candidate, nameserver]] =
- requester.sender(msg, candidate, nameserver)
+ @requester.sender(msg, candidate, q, nameserver)
end
- reply, reply_name = requester.request(sender, tout)
+ sender.send
+ reply = reply_name = nil
+ timeout(tout, ResolvTimeout) { reply, reply_name = q.pop }
case reply.rcode
when RCode::NoError
extract_resources(reply, reply_name, typeclass, &proc)
@@ -498,19 +489,11 @@ class Resolv
end
}
ensure
- requester.close
+ @requester.delete(q)
end
end
- def make_requester # :nodoc:
- if nameserver = @config.single?
- Requester::ConnectedUDP.new(nameserver)
- else
- Requester::UnconnectedUDP.new
- end
- end
-
- def extract_resources(msg, name, typeclass) # :nodoc:
+ def extract_resources(msg, name, typeclass)
if typeclass < Resource::ANY
n0 = Name.create(name)
msg.each_answer {|n, ttl, data|
@@ -541,145 +524,91 @@ class Resolv
}
end
- if defined? SecureRandom
- def self.random(arg) # :nodoc:
- begin
- SecureRandom.random_number(arg)
- rescue NotImplementedError
- rand(arg)
- end
- end
- else
- def self.random(arg) # :nodoc:
- rand(arg)
- end
- end
-
-
- def self.rangerand(range) # :nodoc:
- base = range.begin
- len = range.end - range.begin
- if !range.exclude_end?
- len += 1
- end
- base + random(len)
- end
-
- RequestID = {}
- RequestIDMutex = Mutex.new
-
- def self.allocate_request_id(host, port) # :nodoc:
- id = nil
- RequestIDMutex.synchronize {
- h = (RequestID[[host, port]] ||= {})
- begin
- id = rangerand(0x0000..0xffff)
- end while h[id]
- h[id] = true
- }
- id
- end
-
- def self.free_request_id(host, port, id) # :nodoc:
- RequestIDMutex.synchronize {
- key = [host, port]
- if h = RequestID[key]
- h.delete id
- if h.empty?
- RequestID.delete key
- end
- end
- }
- end
-
- def self.bind_random_port(udpsock) # :nodoc:
- begin
- port = rangerand(1024..65535)
- udpsock.bind("", port)
- rescue Errno::EADDRINUSE
- retry
- end
- end
-
- class Requester # :nodoc:
+ class Requester
def initialize
@senders = {}
- @sock = nil
end
- def request(sender, tout)
- timelimit = Time.now + tout
- sender.send
- while (now = Time.now) < timelimit
- timeout = timelimit - now
- if !IO.select([@sock], nil, nil, timeout)
- raise ResolvTimeout
- end
- reply, from = recv_reply
- begin
- msg = Message.decode(reply)
- rescue DecodeError
- next # broken DNS message ignored
- end
- if s = @senders[[from,msg.id]]
- break
- else
- # unexpected DNS message ignored
+ def close
+ thread, sock, @thread, @sock = @thread, @sock
+ begin
+ if thread
+ thread.kill
+ thread.join
end
+ ensure
+ sock.close if sock
end
- return msg, s.data
end
- def close
- sock = @sock
- @sock = nil
- sock.close if sock
+ def delete(arg)
+ case arg
+ when Sender
+ @senders.delete_if {|k, s| s == arg }
+ when Queue
+ @senders.delete_if {|k, s| s.queue == arg }
+ else
+ raise ArgumentError.new("neither Sender or Queue: #{arg}")
+ end
end
- class Sender # :nodoc:
- def initialize(msg, data, sock)
+ class Sender
+ def initialize(msg, data, sock, queue)
@msg = msg
@data = data
@sock = sock
+ @queue = queue
+ end
+ attr_reader :queue
+
+ def recv(msg)
+ @queue.push([msg, @data])
end
end
- class UnconnectedUDP < Requester # :nodoc:
+ class UnconnectedUDP < Requester
def initialize
super()
@sock = UDPSocket.new
- @sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
- DNS.bind_random_port(@sock)
- end
-
- def recv_reply
- reply, from = @sock.recvfrom(UDPSize)
- return reply, [from[3],from[1]]
+ @sock.fcntl(Fcntl::F_SETFD, 1) if defined? Fcntl::F_SETFD
+ @id = {}
+ @id.default = -1
+ @thread = Thread.new {
+ DNSThreadGroup.add Thread.current
+ loop {
+ reply, from = @sock.recvfrom(UDPSize)
+ msg = begin
+ Message.decode(reply)
+ rescue DecodeError
+ STDERR.print("DNS message decoding error: #{reply.inspect}\n")
+ next
+ end
+ if s = @senders[[[from[3],from[1]],msg.id]]
+ s.recv msg
+ else
+ #STDERR.print("non-handled DNS message: #{msg.inspect} from #{from.inspect}\n")
+ end
+ }
+ }
end
- def sender(msg, data, host, port=Port)
+ def sender(msg, data, queue, host, port=Port)
service = [host, port]
- id = DNS.allocate_request_id(host, port)
+ id = Thread.exclusive {
+ @id[service] = (@id[service] + 1) & 0xffff
+ }
request = msg.encode
request[0,2] = [id].pack('n')
return @senders[[service, id]] =
- Sender.new(request, data, @sock, host, port)
+ Sender.new(request, data, @sock, host, port, queue)
end
- def close
- super
- @senders.each_key {|service, id|
- DNS.free_request_id(service[0], service[1], id)
- }
- end
-
- class Sender < Requester::Sender # :nodoc:
- def initialize(msg, data, sock, host, port)
- super(msg, data, sock)
+ class Sender < Requester::Sender
+ def initialize(msg, data, sock, host, port, queue)
+ super(msg, data, sock, queue)
@host = host
@port = port
end
- attr_reader :data
def send
@sock.send(@msg, 0, @host, @port)
@@ -687,97 +616,104 @@ class Resolv
end
end
- class ConnectedUDP < Requester # :nodoc:
+ class ConnectedUDP < Requester
def initialize(host, port=Port)
super()
@host = host
@port = port
@sock = UDPSocket.new(host.index(':') ? Socket::AF_INET6 : Socket::AF_INET)
- DNS.bind_random_port(@sock)
@sock.connect(host, port)
- @sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
- end
-
- def recv_reply
- reply = @sock.recv(UDPSize)
- return reply, nil
+ @sock.fcntl(Fcntl::F_SETFD, 1) if defined? Fcntl::F_SETFD
+ @id = -1
+ @thread = Thread.new {
+ DNSThreadGroup.add Thread.current
+ loop {
+ reply = @sock.recv(UDPSize)
+ msg = begin
+ Message.decode(reply)
+ rescue DecodeError
+ STDERR.print("DNS message decoding error: #{reply.inspect}")
+ next
+ end
+ if s = @senders[msg.id]
+ s.recv msg
+ else
+ #STDERR.print("non-handled DNS message: #{msg.inspect}")
+ end
+ }
+ }
end
- def sender(msg, data, host=@host, port=@port)
+ def sender(msg, data, queue, host=@host, port=@port)
unless host == @host && port == @port
raise RequestError.new("host/port don't match: #{host}:#{port}")
end
- id = DNS.allocate_request_id(@host, @port)
+ id = Thread.exclusive { @id = (@id + 1) & 0xffff }
request = msg.encode
request[0,2] = [id].pack('n')
- return @senders[[nil,id]] = Sender.new(request, data, @sock)
- end
-
- def close
- super
- @senders.each_key {|from, id|
- DNS.free_request_id(@host, @port, id)
- }
+ return @senders[id] = Sender.new(request, data, @sock, queue)
end
- class Sender < Requester::Sender # :nodoc:
+ class Sender < Requester::Sender
def send
@sock.send(@msg, 0)
end
- attr_reader :data
end
end
- class TCP < Requester # :nodoc:
+ class TCP < Requester
def initialize(host, port=Port)
super()
@host = host
@port = port
- @sock = TCPSocket.new(@host, @port)
- @sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
+ @sock = TCPSocket.new
+ @sock.connect(host, port)
+ @sock.fcntl(Fcntl::F_SETFD, 1) if defined? Fcntl::F_SETFD
+ @id = -1
@senders = {}
+ @thread = Thread.new {
+ DNSThreadGroup.add Thread.current
+ loop {
+ len = @sock.read(2).unpack('n')
+ reply = @sock.read(len)
+ msg = begin
+ Message.decode(reply)
+ rescue DecodeError
+ STDERR.print("DNS message decoding error: #{reply.inspect}")
+ next
+ end
+ if s = @senders[msg.id]
+ s.push msg
+ else
+ #STDERR.print("non-handled DNS message: #{msg.inspect}")
+ end
+ }
+ }
end
- def recv_reply
- len = @sock.read(2).unpack('n')[0]
- reply = @sock.read(len)
- return reply, nil
- end
-
- def sender(msg, data, host=@host, port=@port)
+ def sender(msg, data, queue, host=@host, port=@port)
unless host == @host && port == @port
raise RequestError.new("host/port don't match: #{host}:#{port}")
end
- id = DNS.allocate_request_id(@host, @port)
+ id = Thread.exclusive { @id = (@id + 1) & 0xffff }
request = msg.encode
request[0,2] = [request.length, id].pack('nn')
- return @senders[[nil,id]] = Sender.new(request, data, @sock)
+ return @senders[id] = Sender.new(request, data, @sock, queue)
end
- class Sender < Requester::Sender # :nodoc:
+ class Sender < Requester::Sender
def send
@sock.print(@msg)
@sock.flush
end
- attr_reader :data
- end
-
- def close
- super
- @senders.each_key {|from,id|
- DNS.free_request_id(@host, @port, id)
- }
end
end
- ##
- # Indicates a problem with the DNS request.
-
class RequestError < StandardError
end
end
- class Config # :nodoc:
+ class Config
def initialize(config_info=nil)
@mutex = Mutex.new
@config_info = config_info
@@ -823,7 +759,6 @@ class Resolv
config_hash = Config.parse_resolv_conf(filename)
else
if /mswin32|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
- require 'win32/resolv'
search, nameserver = Win32::Resolv.get_resolv_info
config_hash = {}
config_hash[:nameserver] = nameserver if nameserver
@@ -948,20 +883,14 @@ class Resolv
end
end
- ##
- # Indicates no such domain was found.
-
class NXDomain < ResolvError
end
- ##
- # Indicates some other unhandled resolver error was encountered.
-
class OtherResolvError < ResolvError
end
end
- module OpCode # :nodoc:
+ module OpCode
Query = 0
IQuery = 1
Status = 2
@@ -969,7 +898,7 @@ class Resolv
Update = 5
end
- module RCode # :nodoc:
+ module RCode
NoError = 0
FormErr = 1
ServFail = 2
@@ -990,26 +919,20 @@ class Resolv
BADALG = 21
end
- ##
- # Indicates that the DNS response was unable to be decoded.
-
class DecodeError < StandardError
end
- ##
- # Indicates that the DNS request was unable to be encoded.
-
class EncodeError < StandardError
end
- module Label # :nodoc:
+ module Label
def self.split(arg)
labels = []
arg.scan(/[^\.]+/) {labels << Str.new($&)}
return labels
end
- class Str # :nodoc:
+ class Str
def initialize(string)
@string = string
@downcase = string.downcase
@@ -1038,17 +961,7 @@ class Resolv
end
end
- ##
- # A representation of a DNS name.
-
class Name
-
- ##
- # Creates a new DNS name from +arg+. +arg+ can be:
- #
- # Name:: returns +arg+.
- # String:: Creates a new Name.
-
def self.create(arg)
case arg
when Name
@@ -1060,33 +973,26 @@ class Resolv
end
end
- def initialize(labels, absolute=true) # :nodoc:
+ def initialize(labels, absolute=true)
@labels = labels
@absolute = absolute
end
- def inspect # :nodoc:
+ def inspect
"#<#{self.class}: #{self.to_s}#{@absolute ? '.' : ''}>"
end
- ##
- # True if this name is absolute.
-
def absolute?
return @absolute
end
- def ==(other) # :nodoc:
+ def ==(other)
return false unless Name === other
- return @labels.join == other.to_a.join && @absolute == other.absolute?
+ return @labels == other.to_a && @absolute == other.absolute?
end
+ alias eql? ==
- alias eql? == # :nodoc:
-
- ##
- # Returns true if +other+ is a subdomain.
- #
- # Example:
+ # tests subdomain-of relation.
#
# domain = Resolv::DNS::Name.create("y.z")
# p Resolv::DNS::Name.create("w.x.y.z").subdomain_of?(domain) #=> true
@@ -1096,7 +1002,6 @@ class Resolv
# p Resolv::DNS::Name.create("x.y.z.").subdomain_of?(domain) #=> false
# p Resolv::DNS::Name.create("w.z").subdomain_of?(domain) #=> false
#
-
def subdomain_of?(other)
raise ArgumentError, "not a domain name: #{other.inspect}" unless Name === other
return false if @absolute != other.absolute?
@@ -1105,39 +1010,36 @@ class Resolv
return @labels[-other_len, other_len] == other.to_a
end
- def hash # :nodoc:
+ def hash
return @labels.hash ^ @absolute.hash
end
- def to_a # :nodoc:
+ def to_a
return @labels
end
- def length # :nodoc:
+ def length
return @labels.length
end
- def [](i) # :nodoc:
+ def [](i)
return @labels[i]
end
- ##
# returns the domain name as a string.
#
# The domain name doesn't have a trailing dot even if the name object is
# absolute.
#
- # Example:
- #
# p Resolv::DNS::Name.create("x.y.z.").to_s #=> "x.y.z"
# p Resolv::DNS::Name.create("x.y.z").to_s #=> "x.y.z"
-
+ #
def to_s
return @labels.join('.')
end
end
- class Message # :nodoc:
+ class Message
@@identifier = -1
def initialize(id = (@@identifier += 1) & 0xffff)
@@ -1250,7 +1152,7 @@ class Resolv
}.to_s
end
- class MessageEncoder # :nodoc:
+ class MessageEncoder
def initialize
@data = ''
@names = {}
@@ -1308,7 +1210,7 @@ class Resolv
end
def put_label(d)
- self.put_string(d.to_s)
+ self.put_string(d.string)
end
end
@@ -1345,7 +1247,7 @@ class Resolv
return o
end
- class MessageDecoder # :nodoc:
+ class MessageDecoder
def initialize(data)
@data = data
@index = 0
@@ -1457,51 +1359,39 @@ class Resolv
end
end
- ##
- # A DNS query abstract class.
-
class Query
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
raise EncodeError.new("#{self.class} is query.")
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
raise DecodeError.new("#{self.class} is query.")
end
end
- ##
- # A DNS resource abstract class.
-
class Resource < Query
+ ClassHash = {}
- ##
- # Remaining Time To Live for this Resource.
-
- attr_reader :ttl
-
- ClassHash = {} # :nodoc:
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
raise NotImplementedError.new
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
raise NotImplementedError.new
end
- def ==(other) # :nodoc:
+ def ==(other)
return self.class == other.class &&
self.instance_variables == other.instance_variables &&
self.instance_variables.collect {|name| self.instance_eval name} ==
other.instance_variables.collect {|name| other.instance_eval name}
end
- def eql?(other) # :nodoc:
+ def eql?(other)
return self == other
end
- def hash # :nodoc:
+ def hash
h = 0
self.instance_variables.each {|name|
h ^= self.instance_eval("#{name}.hash")
@@ -1509,37 +1399,26 @@ class Resolv
return h
end
- def self.get_class(type_value, class_value) # :nodoc:
+ def self.get_class(type_value, class_value)
return ClassHash[[type_value, class_value]] ||
Generic.create(type_value, class_value)
end
- ##
- # A generic resource abstract class.
-
class Generic < Resource
-
- ##
- # Creates a new generic resource.
-
def initialize(data)
@data = data
end
-
- ##
- # Data for this generic resource.
-
attr_reader :data
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_bytes(data)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
return self.new(msg.get_bytes)
end
- def self.create(type_value, class_value) # :nodoc:
+ def self.create(type_value, class_value)
c = Class.new(Generic)
c.const_set(:TypeValue, type_value)
c.const_set(:ClassValue, class_value)
@@ -1549,60 +1428,34 @@ class Resolv
end
end
- ##
- # Domain Name resource abstract class.
-
class DomainName < Resource
-
- ##
- # Creates a new DomainName from +name+.
-
def initialize(name)
@name = name
end
-
- ##
- # The name of this DomainName.
-
attr_reader :name
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_name(@name)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
return self.new(msg.get_name)
end
end
# Standard (class generic) RRs
-
- ClassValue = nil # :nodoc:
-
- ##
- # An authoritative name server.
+ ClassValue = nil
class NS < DomainName
- TypeValue = 2 # :nodoc:
+ TypeValue = 2
end
- ##
- # The canonical name for an alias.
-
class CNAME < DomainName
- TypeValue = 5 # :nodoc:
+ TypeValue = 5
end
- ##
- # Start Of Authority resource.
-
class SOA < Resource
-
- TypeValue = 6 # :nodoc:
-
- ##
- # Creates a new SOA record. See the attr documentation for the
- # details of each argument.
+ TypeValue = 6
def initialize(mname, rname, serial, refresh, retry_, expire, minimum)
@mname = mname
@@ -1613,52 +1466,15 @@ class Resolv
@expire = expire
@minimum = minimum
end
+ attr_reader :mname, :rname, :serial, :refresh, :retry, :expire, :minimum
- ##
- # Name of the host where the master zone file for this zone resides.
-
- attr_reader :mname
-
- ##
- # The person responsible for this domain name.
-
- attr_reader :rname
-
- ##
- # The version number of the zone file.
-
- attr_reader :serial
-
- ##
- # How often, in seconds, a secondary name server is to check for
- # updates from the primary name server.
-
- attr_reader :refresh
-
- ##
- # How often, in seconds, a secondary name server is to retry after a
- # failure to check for a refresh.
-
- attr_reader :retry
-
- ##
- # Time in seconds that a secondary name server is to use the data
- # before refreshing from the primary name server.
-
- attr_reader :expire
-
- ##
- # The minimum number of seconds to be used for TTL values in RRs.
-
- attr_reader :minimum
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_name(@mname)
msg.put_name(@rname)
msg.put_pack('NNNNN', @serial, @refresh, @retry, @expire, @minimum)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
mname = msg.get_name
rname = msg.get_name
serial, refresh, retry_, expire, minimum = msg.get_unpack('NNNNN')
@@ -1667,172 +1483,106 @@ class Resolv
end
end
- ##
- # A Pointer to another DNS name.
-
class PTR < DomainName
- TypeValue = 12 # :nodoc:
+ TypeValue = 12
end
- ##
- # Host Information resource.
-
class HINFO < Resource
-
- TypeValue = 13 # :nodoc:
-
- ##
- # Creates a new HINFO running +os+ on +cpu+.
+ TypeValue = 13
def initialize(cpu, os)
@cpu = cpu
@os = os
end
+ attr_reader :cpu, :os
- ##
- # CPU architecture for this resource.
-
- attr_reader :cpu
-
- ##
- # Operating system for this resource.
-
- attr_reader :os
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_string(@cpu)
msg.put_string(@os)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
cpu = msg.get_string
os = msg.get_string
return self.new(cpu, os)
end
end
- ##
- # Mailing list or mailbox information.
-
class MINFO < Resource
-
- TypeValue = 14 # :nodoc:
+ TypeValue = 14
def initialize(rmailbx, emailbx)
@rmailbx = rmailbx
@emailbx = emailbx
end
+ attr_reader :rmailbx, :emailbx
- ##
- # Domain name responsible for this mail list or mailbox.
-
- attr_reader :rmailbx
-
- ##
- # Mailbox to use for error messages related to the mail list or mailbox.
-
- attr_reader :emailbx
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_name(@rmailbx)
msg.put_name(@emailbx)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
rmailbx = msg.get_string
emailbx = msg.get_string
return self.new(rmailbx, emailbx)
end
end
- ##
- # Mail Exchanger resource.
-
class MX < Resource
-
- TypeValue= 15 # :nodoc:
-
- ##
- # Creates a new MX record with +preference+, accepting mail at
- # +exchange+.
+ TypeValue= 15
def initialize(preference, exchange)
@preference = preference
@exchange = exchange
end
+ attr_reader :preference, :exchange
- ##
- # The preference for this MX.
-
- attr_reader :preference
-
- ##
- # The host of this MX.
-
- attr_reader :exchange
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_pack('n', @preference)
msg.put_name(@exchange)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
preference, = msg.get_unpack('n')
exchange = msg.get_name
return self.new(preference, exchange)
end
end
- ##
- # Unstructured text resource.
-
class TXT < Resource
-
- TypeValue = 16 # :nodoc:
+ TypeValue = 16
def initialize(first_string, *rest_strings)
@strings = [first_string, *rest_strings]
end
-
- ##
- # Returns an Array of Strings for this TXT record.
-
attr_reader :strings
- ##
- # Returns the first string from +strings+.
-
def data
@strings[0]
end
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_string_list(@strings)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
strings = msg.get_string_list
return self.new(*strings)
end
end
- ##
- # A Query type requesting any RR.
-
class ANY < Query
- TypeValue = 255 # :nodoc:
+ TypeValue = 255
end
- ClassInsensitiveTypes = [ # :nodoc:
+ ClassInsensitiveTypes = [
NS, CNAME, SOA, PTR, HINFO, MINFO, MX, TXT, ANY
]
- ##
- # module IN contains ARPA Internet specific RRs.
-
+ # ARPA Internet specific RRs
module IN
-
- ClassValue = 1 # :nodoc:
+ ClassValue = 1
ClassInsensitiveTypes.each {|s|
c = Class.new(s)
@@ -1842,76 +1592,40 @@ class Resolv
self.const_set(s.name.sub(/.*::/, ''), c)
}
- ##
- # IPv4 Address resource
-
class A < Resource
- TypeValue = 1
- ClassValue = IN::ClassValue
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
-
- ##
- # Creates a new A for +address+.
+ ClassHash[[TypeValue = 1, ClassValue = ClassValue]] = self
def initialize(address)
@address = IPv4.create(address)
end
-
- ##
- # The Resolv::IPv4 address for this A.
-
attr_reader :address
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_bytes(@address.address)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
return self.new(IPv4.new(msg.get_bytes(4)))
end
end
- ##
- # Well Known Service resource.
-
class WKS < Resource
- TypeValue = 11
- ClassValue = IN::ClassValue
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
+ ClassHash[[TypeValue = 11, ClassValue = ClassValue]] = self
def initialize(address, protocol, bitmap)
@address = IPv4.create(address)
@protocol = protocol
@bitmap = bitmap
end
+ attr_reader :address, :protocol, :bitmap
- ##
- # The host these services run on.
-
- attr_reader :address
-
- ##
- # IP protocol number for these services.
-
- attr_reader :protocol
-
- ##
- # A bit map of enabled services on this host.
- #
- # If protocol is 6 (TCP) then the 26th bit corresponds to the SMTP
- # service (port 25). If this bit is set, then an SMTP server should
- # be listening on TCP port 25; if zero, SMTP service is not
- # supported.
-
- attr_reader :bitmap
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_bytes(@address.address)
msg.put_pack("n", @protocol)
msg.put_bytes(@bitmap)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
address = IPv4.new(msg.get_bytes(4))
protocol, = msg.get_unpack("n")
bitmap = msg.get_bytes
@@ -1919,51 +1633,55 @@ class Resolv
end
end
- ##
- # An IPv6 address record.
-
class AAAA < Resource
- TypeValue = 28
- ClassValue = IN::ClassValue
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
-
- ##
- # Creates a new AAAA for +address+.
+ ClassHash[[TypeValue = 28, ClassValue = ClassValue]] = self
def initialize(address)
@address = IPv6.create(address)
end
-
- ##
- # The Resolv::IPv6 address for this AAAA.
-
attr_reader :address
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_bytes(@address.address)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
return self.new(IPv6.new(msg.get_bytes(16)))
end
end
- ##
# SRV resource record defined in RFC 2782
#
# These records identify the hostname and port that a service is
# available at.
-
+ #
+ # The format is:
+ # _Service._Proto.Name TTL Class SRV Priority Weight Port Target
+ #
+ # The fields specific to SRV are defined in RFC 2782 as meaning:
+ # - +priority+ The priority of this target host. A client MUST attempt
+ # to contact the target host with the lowest-numbered priority it can
+ # reach; target hosts with the same priority SHOULD be tried in an
+ # order defined by the weight field. The range is 0-65535. Note that
+ # it is not widely implemented and should be set to zero.
+ #
+ # - +weight+ A server selection mechanism. The weight field specifies
+ # a relative weight for entries with the same priority. Larger weights
+ # SHOULD be given a proportionately higher probability of being
+ # selected. The range of this number is 0-65535. Domain administrators
+ # SHOULD use Weight 0 when there isn't any server selection to do, to
+ # make the RR easier to read for humans (less noisy). Note that it is
+ # not widely implemented and should be set to zero.
+ #
+ # - +port+ The port on this target host of this service. The range is 0-
+ # 65535.
+ #
+ # - +target+ The domain name of the target host. A target of "." means
+ # that the service is decidedly not available at this domain.
class SRV < Resource
- TypeValue = 33
- ClassValue = IN::ClassValue
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
+ ClassHash[[TypeValue = 33, ClassValue = ClassValue]] = self
# Create a SRV resource record.
- #
- # See the documentation for #priority, #weight, #port and #target
- # for +priority+, +weight+, +port and +target+ respectively.
-
def initialize(priority, weight, port, target)
@priority = priority.to_int
@weight = weight.to_int
@@ -1971,49 +1689,16 @@ class Resolv
@target = Name.create(target)
end
- # The priority of this target host.
- #
- # A client MUST attempt to contact the target host with the
- # lowest-numbered priority it can reach; target hosts with the same
- # priority SHOULD be tried in an order defined by the weight field.
- # The range is 0-65535. Note that it is not widely implemented and
- # should be set to zero.
-
- attr_reader :priority
-
- # A server selection mechanism.
- #
- # The weight field specifies a relative weight for entries with the
- # same priority. Larger weights SHOULD be given a proportionately
- # higher probability of being selected. The range of this number is
- # 0-65535. Domain administrators SHOULD use Weight 0 when there
- # isn't any server selection to do, to make the RR easier to read
- # for humans (less noisy). Note that it is not widely implemented
- # and should be set to zero.
-
- attr_reader :weight
-
- # The port on this target host of this service.
- #
- # The range is 0-65535.
-
- attr_reader :port
-
- # The domain name of the target host.
- #
- # A target of "." means that the service is decidedly not available
- # at this domain.
-
- attr_reader :target
+ attr_reader :priority, :weight, :port, :target
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_pack("n", @priority)
msg.put_pack("n", @weight)
msg.put_pack("n", @port)
msg.put_name(@target)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
priority, = msg.get_unpack("n")
weight, = msg.get_unpack("n")
port, = msg.get_unpack("n")
@@ -2021,18 +1706,12 @@ class Resolv
return self.new(priority, weight, port, target)
end
end
+
end
end
end
- ##
- # A Resolv::DNS IPv4 address.
-
class IPv4
-
- ##
- # Regular expression IPv4 addresses must match.
-
Regex = /\A(\d+)\.(\d+)\.(\d+)\.(\d+)\z/
def self.create(arg)
@@ -2053,102 +1732,68 @@ class Resolv
end
end
- def initialize(address) # :nodoc:
+ def initialize(address)
unless address.kind_of?(String) && address.length == 4
raise ArgumentError.new('IPv4 address must be 4 bytes')
end
@address = address
end
-
- ##
- # A String representation of this IPv4 address.
-
- ##
- # The raw IPv4 address as a String.
-
attr_reader :address
- def to_s # :nodoc:
+ def to_s
return sprintf("%d.%d.%d.%d", *@address.unpack("CCCC"))
end
- def inspect # :nodoc:
+ def inspect
return "#<#{self.class} #{self.to_s}>"
end
- ##
- # Turns this IPv4 address into a Resolv::DNS::Name.
-
def to_name
return DNS::Name.create(
'%d.%d.%d.%d.in-addr.arpa.' % @address.unpack('CCCC').reverse)
end
- def ==(other) # :nodoc:
+ def ==(other)
return @address == other.address
end
- def eql?(other) # :nodoc:
+ def eql?(other)
return self == other
end
- def hash # :nodoc:
+ def hash
return @address.hash
end
end
- ##
- # A Resolv::DNS IPv6 address.
-
class IPv6
-
- ##
- # IPv6 address format a:b:c:d:e:f:g:h
Regex_8Hex = /\A
(?:[0-9A-Fa-f]{1,4}:){7}
[0-9A-Fa-f]{1,4}
\z/x
- ##
- # Compressed IPv6 address format a::b
-
Regex_CompressedHex = /\A
((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?) ::
((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)
\z/x
- ##
- # IPv4 mapped IPv6 address format a:b:c:d:e:f:w.x.y.z
-
Regex_6Hex4Dec = /\A
((?:[0-9A-Fa-f]{1,4}:){6,6})
(\d+)\.(\d+)\.(\d+)\.(\d+)
\z/x
- ##
- # Compressed IPv4 mapped IPv6 address format a::b:w.x.y.z
-
Regex_CompressedHex4Dec = /\A
((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?) ::
((?:[0-9A-Fa-f]{1,4}:)*)
(\d+)\.(\d+)\.(\d+)\.(\d+)
\z/x
- ##
- # A composite IPv6 address Regexp.
-
Regex = /
(?:#{Regex_8Hex}) |
(?:#{Regex_CompressedHex}) |
(?:#{Regex_6Hex4Dec}) |
(?:#{Regex_CompressedHex4Dec})/x
- ##
- # Creates a new IPv6 address from +arg+ which may be:
- #
- # IPv6:: returns +arg+.
- # String:: +arg+ must match one of the IPv6::Regex* constants
-
def self.create(arg)
case arg
when IPv6
@@ -2195,19 +1840,15 @@ class Resolv
end
end
- def initialize(address) # :nodoc:
+ def initialize(address)
unless address.kind_of?(String) && address.length == 16
raise ArgumentError.new('IPv6 address must be 16 bytes')
end
@address = address
end
-
- ##
- # The raw IPv6 address as a String.
-
attr_reader :address
- def to_s # :nodoc:
+ def to_s
address = sprintf("%X:%X:%X:%X:%X:%X:%X:%X", *@address.unpack("nnnnnnnn"))
unless address.sub!(/(^|:)0(:0)+(:|$)/, '::')
address.sub!(/(^|:)0(:|$)/, '::')
@@ -2215,42 +1856,29 @@ class Resolv
return address
end
- def inspect # :nodoc:
+ def inspect
return "#<#{self.class} #{self.to_s}>"
end
- ##
- # Turns this IPv6 address into a Resolv::DNS::Name.
- #--
- # ip6.arpa should be searched too. [RFC3152]
-
def to_name
+ # ip6.arpa should be searched too. [RFC3152]
return DNS::Name.new(
- @address.unpack("H32")[0].split(//).reverse + ['ip6', 'arpa'])
+ @address.unpack("H32")[0].split(//).reverse + ['ip6', 'int'])
end
- def ==(other) # :nodoc:
+ def ==(other)
return @address == other.address
end
- def eql?(other) # :nodoc:
+ def eql?(other)
return self == other
end
- def hash # :nodoc:
+ def hash
return @address.hash
end
end
- ##
- # Default resolver to use for Resolv class methods.
-
DefaultResolver = self.new
-
- ##
- # Address Regexp to use for matching IP addresses.
-
AddressRegex = /(?:#{IPv4::Regex})|(?:#{IPv6::Regex})/
-
end
-
diff --git a/lib/rexml/attlistdecl.rb b/lib/rexml/attlistdecl.rb
index ef4721b5ce..d4b5c38af6 100644
--- a/lib/rexml/attlistdecl.rb
+++ b/lib/rexml/attlistdecl.rb
@@ -44,7 +44,7 @@ module REXML
@pairs.keys.include? key
end
- # Iterate over the key/value pairs:
+ # Itterate over the key/value pairs:
# attlist_decl.each { |attribute_name, attribute_value| ... }
def each(&block)
@pairs.each(&block)
diff --git a/lib/rexml/attribute.rb b/lib/rexml/attribute.rb
index 89c1ada36c..029035d675 100644
--- a/lib/rexml/attribute.rb
+++ b/lib/rexml/attribute.rb
@@ -50,7 +50,7 @@ module REXML
@element = first.element
end
elsif first.kind_of? String
- @element = parent
+ @element = parent if parent.kind_of? Element
self.name = first
@normalized = second.to_s
else
diff --git a/lib/rexml/document.rb b/lib/rexml/document.rb
index 54aa691ad8..558b5d731a 100644
--- a/lib/rexml/document.rb
+++ b/lib/rexml/document.rb
@@ -66,7 +66,6 @@ module REXML
def add( child )
if child.kind_of? XMLDecl
@children.unshift child
- child.parent = self
elsif child.kind_of? DocType
# Find first Element or DocType node and insert the decl right
# before it. If there is no such node, just insert the child at the
@@ -147,7 +146,7 @@ module REXML
# A controversial point is whether Document should always write the XML
# declaration (<?xml version='1.0'?>) whether or not one is given by the
# user (or source document). REXML does not write one if one was not
- # specified, because it adds unnecessary bandwidth to applications such
+ # specified, because it adds unneccessary bandwidth to applications such
# as XML-RPC.
#
# See also the classes in the rexml/formatters package for the proper way
@@ -184,7 +183,7 @@ module REXML
output = Output.new( output, xml_decl.encoding )
end
formatter = if indent > -1
- if trans
+ if transitive
REXML::Formatters::Transitive.new( indent, ie_hack )
else
REXML::Formatters::Pretty.new( indent, ie_hack )
diff --git a/lib/rexml/element.rb b/lib/rexml/element.rb
index 3db87c6126..f757cfffa8 100644
--- a/lib/rexml/element.rb
+++ b/lib/rexml/element.rb
@@ -360,7 +360,7 @@ module REXML
# Iterates through the children, yielding for each Element that
# has a particular text set.
# text::
- # the text to search for. If nil, or not supplied, will iterate
+ # the text to search for. If nil, or not supplied, will itterate
# over all +Element+ children that contain at least one +Text+ node.
# max::
# (optional) causes this method to return after yielding
@@ -553,7 +553,6 @@ module REXML
def attribute( name, namespace=nil )
prefix = nil
prefix = namespaces.index(namespace) if namespace
- prefix = nil if prefix == 'xmlns'
attributes.get_attribute( "#{prefix ? prefix + ':' : ''}#{name}" )
end
@@ -855,15 +854,15 @@ module REXML
# Source (see Element.initialize). If not supplied or nil, a
# new, default Element will be constructed
# Returns:: the added Element
- # a = Element.new('a')
- # a.elements.add(Element.new('b')) #-> <a><b/></a>
- # a.elements.add('c') #-> <a><b/><c/></a>
+ # a = Element.new 'a'
+ # a.elements.add Element.new 'b' #-> <a><b/></a>
+ # a.elements.add 'c' #-> <a><b/><c/></a>
def add element=nil
rv = nil
if element.nil?
- Element.new("", self, @element.context)
+ Element.new "", self, @element.context
elsif not element.kind_of?(Element)
- Element.new(element, self, @element.context)
+ Element.new element, self, @element.context
else
@element << element
element.context = @element.context
@@ -989,7 +988,7 @@ module REXML
end
alias :size :length
- # Iterates over the attributes of an Element. Yields actual Attribute
+ # Itterates over the attributes of an Element. Yields actual Attribute
# nodes, not String values.
#
# doc = Document.new '<a x="1" y="2"/>'
@@ -1006,7 +1005,7 @@ module REXML
end
end
- # Iterates over each attribute of an Element, yielding the expanded name
+ # Itterates over each attribute of an Element, yielding the expanded name
# and value as a pair of Strings.
#
# doc = Document.new '<a x="1" y="2"/>'
diff --git a/lib/rexml/encoding.rb b/lib/rexml/encoding.rb
index a01763be99..6cae6b644d 100644
--- a/lib/rexml/encoding.rb
+++ b/lib/rexml/encoding.rb
@@ -56,13 +56,8 @@ module REXML
def check_encoding str
# We have to recognize UTF-16, LSB UTF-16, and UTF-8
- if str[0] == 0xfe && str[1] == 0xff
- str[0,2] = ""
- return UTF_16
- elsif str[0] == 0xff && str[1] == 0xfe
- str[0,2] = ""
- return UNILE
- end
+ return UTF_16 if /\A\xfe\xff/n =~ str
+ return UNILE if /\A\xff\xfe/n =~ str
str =~ /^\s*<\?xml\s+version\s*=\s*(['"]).*?\1\s+encoding\s*=\s*(["'])(.*?)\2/um
return $3.upcase if $3
return UTF_8
diff --git a/lib/rexml/encodings/SHIFT-JIS.rb b/lib/rexml/encodings/SHIFT-JIS.rb
index 9e0f4af20e..93c7877afd 100644
--- a/lib/rexml/encodings/SHIFT-JIS.rb
+++ b/lib/rexml/encodings/SHIFT-JIS.rb
@@ -13,8 +13,8 @@ module REXML
rescue LoadError
require 'nkf'
- SJISTOU8 = '-Swm0x'
- U8TOSJIS = '-Wsm0x'
+ SJISTOU8 = '-Swm0'
+ U8TOSJIS = '-Wsm0'
def decode_sjis(str)
NKF.nkf(SJISTOU8, str)
diff --git a/lib/rexml/formatters/pretty.rb b/lib/rexml/formatters/pretty.rb
index d21175d34a..22b6d857cd 100644
--- a/lib/rexml/formatters/pretty.rb
+++ b/lib/rexml/formatters/pretty.rb
@@ -125,7 +125,7 @@ module REXML
end
def wrap(string, width)
- # Recursively wrap string at width.
+ # Recursivly wrap string at width.
return string if string.length <= width
place = string.rindex(' ', width) # Position in string with last ' ' before cutoff
return string[0,place] + "\n" + wrap(string[place+1..-1], width)
diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb
index fefc9ef940..8293e9c5ac 100644
--- a/lib/rexml/functions.rb
+++ b/lib/rexml/functions.rb
@@ -235,7 +235,7 @@ module REXML
# from string then we ignore the second &
# subsequent mappings
#
- # if a character maps to nil then we delete it
+ # if a charactcer maps to nil then we delete it
# in the output. This happens if the from
# string is longer than the to string
#
diff --git a/lib/rexml/node.rb b/lib/rexml/node.rb
index d5e8456e53..9780376829 100644
--- a/lib/rexml/node.rb
+++ b/lib/rexml/node.rb
@@ -27,7 +27,7 @@ module REXML
unless indent.nil?
Kernel.warn( "#{self.class.name}.to_s(indent) parameter is deprecated" )
f = REXML::Formatters::Pretty.new( indent )
- f.write( self, rv = "" )
+ f.write( self, rv, indent )
else
f = REXML::Formatters::Default.new
f.write( self, rv = "" )
diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb
index fc2354a67f..3782d61b2c 100644
--- a/lib/rexml/parsers/baseparser.rb
+++ b/lib/rexml/parsers/baseparser.rb
@@ -1,7 +1,5 @@
require 'rexml/parseexception'
-require 'rexml/undefinednamespaceexception'
require 'rexml/source'
-require 'set'
module REXML
module Parsers
@@ -26,8 +24,7 @@ module REXML
# Nat Price gave me some good ideas for the API.
class BaseParser
NCNAME_STR= '[\w:][\-\w\d.]*'
- NAME_STR= "(?:(#{NCNAME_STR}):)?(#{NCNAME_STR})"
- UNAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"
+ NAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"
NAMECHAR = '[\-\w\d\.:]'
NAME = "([\\w:]#{NAMECHAR}*)"
@@ -38,7 +35,7 @@ module REXML
DOCTYPE_START = /\A\s*<!DOCTYPE\s/um
DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
- ATTRIBUTE_PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\4/um
+ ATTRIBUTE_PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\2/um
COMMENT_START = /\A<!--/u
COMMENT_PATTERN = /<!--(.*?)-->/um
CDATA_START = /\A<!\[CDATA\[/u
@@ -48,7 +45,7 @@ module REXML
XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>/um
INSTRUCTION_START = /\A<\?/u
INSTRUCTION_PATTERN = /<\?(.*?)(\s+.*?)?\?>/um
- TAG_MATCH = /^<((?>#{NAME_STR}))\s*((?>\s+#{UNAME_STR}\s*=\s*(["']).*?\5)*)\s*(\/)?>/um
+ TAG_MATCH = /^<((?>#{NAME_STR}))\s*((?>\s+#{NAME_STR}\s*=\s*(["']).*?\3)*)\s*(\/)?>/um
CLOSE_MATCH = /^\s*<\/(#{NAME_STR})\s*>/um
VERSION = /\bversion\s*=\s*["'](.*?)['"]/um
@@ -136,7 +133,6 @@ module REXML
@tags = []
@stack = []
@entities = []
- @nsstack = []
end
def position
@@ -192,7 +188,6 @@ module REXML
end
return [ :end_document ] if empty?
return @stack.shift if @stack.size > 0
- #STDERR.puts @source.encoding
@source.read if @source.buffer.size<2
#STDERR.puts "BUFFER = #{@source.buffer.inspect}"
if @document_status == nil
@@ -218,7 +213,6 @@ module REXML
return [ :processing_instruction, *@source.match(INSTRUCTION_PATTERN, true)[1,2] ]
when DOCTYPE_START
md = @source.match( DOCTYPE_PATTERN, true )
- @nsstack.unshift(curr_ns=Set.new)
identity = md[1]
close = md[2]
identity =~ IDENTITY
@@ -294,9 +288,6 @@ module REXML
val = attdef[3]
val = attdef[4] if val == "#FIXED "
pairs[attdef[0]] = val
- if attdef[0] =~ /^xmlns:(.*)/
- @nsstack[0] << $1
- end
end
end
return [ :attlistdecl, element, pairs, contents ]
@@ -321,7 +312,6 @@ module REXML
begin
if @source.buffer[0] == ?<
if @source.buffer[1] == ?/
- @nsstack.shift
last_tag = @tags.pop
#md = @source.match_to_consume( '>', CLOSE_MATCH)
md = @source.match( CLOSE_MATCH, true )
@@ -355,47 +345,19 @@ module REXML
raise REXML::ParseException.new("missing attribute quote", @source) if @source.match(MISSING_ATTRIBUTE_QUOTES )
raise REXML::ParseException.new("malformed XML: missing tag start", @source)
end
- attributes = {}
- prefixes = Set.new
- prefixes << md[2] if md[2]
- @nsstack.unshift(curr_ns=Set.new)
- if md[4].size > 0
- attrs = md[4].scan( ATTRIBUTE_PATTERN )
+ attrs = []
+ if md[2].size > 0
+ attrs = md[2].scan( ATTRIBUTE_PATTERN )
raise REXML::ParseException.new( "error parsing attributes: [#{attrs.join ', '}], excess = \"#$'\"", @source) if $' and $'.strip.size > 0
- attrs.each { |a,b,c,d,e|
- if b == "xmlns"
- if c == "xml"
- if d != "http://www.w3.org/XML/1998/namespace"
- msg = "The 'xml' prefix must not be bound to any other namespace "+
- "(http://www.w3.org/TR/REC-xml-names/#ns-decl)"
- raise REXML::ParseException.new( msg, @source, self )
- end
- elsif c == "xmlns"
- msg = "The 'xmlns' prefix must not be declared "+
- "(http://www.w3.org/TR/REC-xml-names/#ns-decl)"
- raise REXML::ParseException.new( msg, @source, self)
- end
- curr_ns << c
- elsif b
- prefixes << b unless b == "xml"
- end
- attributes[a] = e
- }
end
- # Verify that all of the prefixes have been defined
- for prefix in prefixes
- unless @nsstack.find{|k| k.member?(prefix)}
- raise UndefinedNamespaceException.new(prefix,@source,self)
- end
- end
-
- if md[6]
+ if md[4]
@closed = md[1]
- @nsstack.shift
else
@tags.push( md[1] )
end
+ attributes = {}
+ attrs.each { |a,b,c| attributes[a] = c }
return [ :start_element, md[1], attributes ]
end
else
@@ -409,8 +371,6 @@ module REXML
# return PullEvent.new( :text, md[1], unnormalized )
return [ :text, md[1] ]
end
- rescue REXML::UndefinedNamespaceException
- raise
rescue REXML::ParseException
raise
rescue Exception, NameError => error
diff --git a/lib/rexml/parsers/treeparser.rb b/lib/rexml/parsers/treeparser.rb
index 5c3e142ea7..a53fa41925 100644
--- a/lib/rexml/parsers/treeparser.rb
+++ b/lib/rexml/parsers/treeparser.rb
@@ -1,5 +1,4 @@
require 'rexml/validation/validationexception'
-require 'rexml/undefinednamespaceexception'
module REXML
module Parsers
@@ -30,7 +29,8 @@ module REXML
return
when :start_element
tag_stack.push(event[1])
- el = @build_context = @build_context.add_element( event[1], event[2] )
+ # find the observers for namespaces
+ @build_context = @build_context.add_element( event[1], event[2] )
when :end_element
tag_stack.pop
@build_context = @build_context.parent
@@ -86,8 +86,6 @@ module REXML
end
rescue REXML::Validation::ValidationException
raise
- rescue REXML::UndefinedNamespaceException
- raise
rescue
raise ParseException.new( $!.message, @parser.source, @parser, $! )
end
diff --git a/lib/rexml/rexml.rb b/lib/rexml/rexml.rb
index 8af1697e51..19805d61e1 100644
--- a/lib/rexml/rexml.rb
+++ b/lib/rexml/rexml.rb
@@ -1,4 +1,3 @@
-# -*- encoding: utf-8 -*-
# REXML is an XML toolkit for Ruby[http://www.ruby-lang.org], in Ruby.
#
# REXML is a _pure_ Ruby, XML 1.0 conforming,
@@ -11,9 +10,8 @@
#
# Main page:: http://www.germane-software.com/software/rexml
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
-# Version:: 3.1.7.2
-# Date:: 2007/275
-# Revision:: $Revision$
+# Version:: 3.1.7.1
+# Date:: 2007/209
#
# This API documentation can be downloaded from the REXML home page, or can
# be accessed online[http://www.germane-software.com/software/rexml_doc]
@@ -22,10 +20,10 @@
# or can be accessed
# online[http://www.germane-software.com/software/rexml/docs/tutorial.html]
module REXML
- COPYRIGHT = "Copyright \xC2\xA9 2001-2006 Sean Russell <ser@germane-software.com>"
- VERSION = "3.1.7.2"
- DATE = "2007/275"
- REVISION = "$Revision$".gsub(/\$Revision:|\$/,'').strip
+ COPYRIGHT = "Copyright © 2001-2007 Sean Russell <ser@germane-software.com>"
+ DATE = "2007/209"
+ VERSION = "3.1.7.1"
+ REVISION = "$Revision: 1270$".gsub(/\$Revision:|\$/,'').strip
Copyright = COPYRIGHT
Version = VERSION
diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb
index ce7a2c98b0..ada876cde5 100644
--- a/lib/rexml/source.rb
+++ b/lib/rexml/source.rb
@@ -17,8 +17,8 @@ module REXML
elsif arg.kind_of? Source
arg
else
- raise "#{arg.class} is not a valid input stream. It must walk \n"+
- "like either a String, an IO, or a Source."
+ raise "#{source.class} is not a valid input stream. It must walk \n"+
+ "like either a String, IO, or Source."
end
end
end
@@ -134,7 +134,6 @@ module REXML
def initialize(arg, block_size=500, encoding=nil)
@er_source = @source = arg
@to_utf = false
-
# Determining the encoding is a deceptively difficult issue to resolve.
# First, we check the first two bytes for UTF-16. Then we
# assume that the encoding is at least ASCII enough for the '>', and
@@ -146,16 +145,13 @@ module REXML
str = @source.read( 2 )
if encoding
self.encoding = encoding
- elsif 0xfe == str[0] && 0xff == str[1]
- @line_break = "\000>"
- elsif 0xff == str[0] && 0xfe == str[1]
- @line_break = ">\000"
- elsif 0xef == str[0] && 0xbb == str[1]
+ elsif /\A(?:\xfe\xff|\xff\xfe)/n =~ str
+ self.encoding = check_encoding( str )
+ elsif (0xef == str[0] && 0xbb == str[1])
str += @source.read(1)
str = '' if (0xbf == str[2])
- @line_break = ">"
else
- @line_break = ">"
+ @line_break = '>'
end
super str+@source.readline( @line_break )
end
diff --git a/lib/rexml/text.rb b/lib/rexml/text.rb
index 2bc00429b3..9804aa710b 100644
--- a/lib/rexml/text.rb
+++ b/lib/rexml/text.rb
@@ -189,7 +189,7 @@ module REXML
end
def wrap(string, width, addnewline=false)
- # Recursively wrap string at width.
+ # Recursivly wrap string at width.
return string if string.length <= width
place = string.rindex(' ', width) # Position in string with last ' ' before cutoff
if addnewline then
diff --git a/lib/rexml/undefinednamespaceexception.rb b/lib/rexml/undefinednamespaceexception.rb
deleted file mode 100644
index 8ebfdfd0a9..0000000000
--- a/lib/rexml/undefinednamespaceexception.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require 'rexml/parseexception'
-module REXML
- class UndefinedNamespaceException < ParseException
- def initialize( prefix, source, parser )
- super( "Undefined prefix #{prefix} found" )
- end
- end
-end
diff --git a/lib/rexml/xpath.rb b/lib/rexml/xpath.rb
index e8813efd3e..939399e283 100644
--- a/lib/rexml/xpath.rb
+++ b/lib/rexml/xpath.rb
@@ -30,7 +30,7 @@ module REXML
parser.parse(path, element).flatten[0]
end
- # Iterates over nodes that match the given path, calling the supplied
+ # Itterates over nodes that match the given path, calling the supplied
# block with the match.
# element::
# The context element
diff --git a/lib/rinda/ring.rb b/lib/rinda/ring.rb
index 1fad92dbc7..ac8a716216 100644
--- a/lib/rinda/ring.rb
+++ b/lib/rinda/ring.rb
@@ -19,7 +19,7 @@ module Rinda
# 1. A RingServer begins listening on the broadcast UDP address.
# 2. A RingFinger sends a UDP packet containing the DRb URI where it will
# listen for a reply.
- # 3. The RingServer receives the UDP packet and connects back to the
+ # 3. The RingServer recieves the UDP packet and connects back to the
# provided DRb URI with the DRb service.
class RingServer
@@ -119,7 +119,7 @@ module Rinda
end
##
- # Contains all discovered TupleSpaces except for the primary.
+ # Contains all discoverd TupleSpaces except for the primary.
def self.to_a
finger.to_a
diff --git a/lib/rinda/tuplespace.rb b/lib/rinda/tuplespace.rb
index b0409dde3b..6d58a0fd15 100644
--- a/lib/rinda/tuplespace.rb
+++ b/lib/rinda/tuplespace.rb
@@ -2,8 +2,6 @@ require 'monitor'
require 'thread'
require 'drb/drb'
require 'rinda/rinda'
-require 'enumerator'
-require 'forwardable'
module Rinda
@@ -288,70 +286,45 @@ module Rinda
# of Tuplespace.
class TupleBag
- class TupleBin
- extend Forwardable
- def_delegators '@bin', :find_all, :delete_if, :each, :empty?
-
- def initialize
- @bin = []
- end
-
- def add(tuple)
- @bin.push(tuple)
- end
-
- def delete(tuple)
- idx = @bin.rindex(tuple)
- @bin.delete_at(idx) if idx
- end
-
- def find(&blk)
- @bin.reverse_each do |x|
- return x if yield(x)
- end
- nil
- end
- end
def initialize # :nodoc:
@hash = {}
- @enum = Enumerable::Enumerator.new(self, :each_entry)
end
##
# +true+ if the TupleBag to see if it has any expired entries.
def has_expires?
- @enum.find do |tuple|
- tuple.expires
+ @hash.each do |k, v|
+ v.each do |tuple|
+ return true if tuple.expires
+ end
end
+ false
end
##
- # Add +tuple+ to the TupleBag.
+ # Add +ary+ to the TupleBag.
- def push(tuple)
- key = bin_key(tuple)
- @hash[key] ||= TupleBin.new
- @hash[key].add(tuple)
+ def push(ary)
+ size = ary.size
+ @hash[size] ||= []
+ @hash[size].push(ary)
end
##
- # Removes +tuple+ from the TupleBag.
+ # Removes +ary+ from the TupleBag.
- def delete(tuple)
- key = bin_key(tuple)
- bin = @hash[key]
- return nil unless bin
- bin.delete(tuple)
- @hash.delete(key) if bin.empty?
- tuple
+ def delete(ary)
+ size = ary.size
+ @hash.fetch(size, []).delete(ary)
end
##
# Finds all live tuples that match +template+.
+
def find_all(template)
- bin_for_find(template).find_all do |tuple|
+ @hash.fetch(template.size, []).find_all do |tuple|
tuple.alive? && template.match(tuple)
end
end
@@ -360,7 +333,7 @@ module Rinda
# Finds a live tuple that matches +template+.
def find(template)
- bin_for_find(template).find do |tuple|
+ @hash.fetch(template.size, []).find do |tuple|
tuple.alive? && template.match(tuple)
end
end
@@ -370,7 +343,7 @@ module Rinda
# +tuple+ and are alive.
def find_all_template(tuple)
- @enum.find_all do |template|
+ @hash.fetch(tuple.size, []).find_all do |template|
template.alive? && template.match(tuple)
end
end
@@ -381,39 +354,20 @@ module Rinda
def delete_unless_alive
deleted = []
- @hash.each do |key, bin|
- bin.delete_if do |tuple|
+ @hash.keys.each do |size|
+ ary = []
+ @hash[size].each do |tuple|
if tuple.alive?
- false
+ ary.push(tuple)
else
deleted.push(tuple)
- true
end
end
+ @hash[size] = ary
end
deleted
end
- private
- def each_entry(&blk)
- @hash.each do |k, v|
- v.each(&blk)
- end
- end
-
- def bin_key(tuple)
- head = tuple[0]
- if head.class == Symbol
- return head
- else
- false
- end
- end
-
- def bin_for_find(template)
- key = bin_key(template)
- key ? @hash.fetch(key, []) : @enum
- end
end
##
@@ -449,7 +403,7 @@ module Rinda
# Adds +tuple+
def write(tuple, sec=nil)
- entry = create_entry(tuple, sec)
+ entry = TupleEntry.new(tuple, sec)
synchronize do
if entry.expired?
@read_waiter.find_all_template(entry).each do |template|
@@ -575,10 +529,6 @@ module Rinda
private
- def create_entry(tuple, sec)
- TupleEntry.new(tuple, sec)
- end
-
##
# Removes dead tuples.
@@ -617,11 +567,11 @@ module Rinda
return if @keeper && @keeper.alive?
@keeper = Thread.new do
while true
- sleep(@period)
synchronize do
break unless need_keeper?
keep_clean
end
+ sleep(@period)
end
end
end
diff --git a/lib/rss.rb b/lib/rss.rb
index a1d0f76ba1..495edb1b98 100644
--- a/lib/rss.rb
+++ b/lib/rss.rb
@@ -1,4 +1,4 @@
-# Copyright (c) 2003-2007 Kouhei Sutou. You can redistribute it and/or
+# Copyright (c) 2003-2005 Kouhei Sutou. You can redistribute it and/or
# modify it under the same terms as Ruby.
#
# Author:: Kouhei Sutou <kou@cozmixng.org>
@@ -6,14 +6,11 @@
require 'rss/1.0'
require 'rss/2.0'
-require 'rss/atom'
require 'rss/content'
require 'rss/dublincore'
require 'rss/image'
-require 'rss/itunes'
-require 'rss/slash'
require 'rss/syndication'
-require 'rss/taxonomy'
+#require 'rss/taxonomy'
require 'rss/trackback'
require "rss/maker"
diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb
index 7b24e7596d..69e01ddd57 100644
--- a/lib/rss/0.9.rb
+++ b/lib/rss/0.9.rb
@@ -22,13 +22,10 @@ module RSS
install_have_child_element(name, "", nil)
end
- attr_writer :feed_version
- alias_method(:rss_version, :feed_version)
- alias_method(:rss_version=, :feed_version=)
-
- def initialize(feed_version, version=nil, encoding=nil, standalone=nil)
+ attr_accessor :rss_version, :version, :encoding, :standalone
+
+ def initialize(rss_version, version=nil, encoding=nil, standalone=nil)
super
- @feed_type = "rss"
end
def items
@@ -60,14 +57,12 @@ module RSS
items.each do |item|
item.setup_maker(maker.items)
end
- image.setup_maker(maker) if image
- textinput.setup_maker(maker) if textinput
end
private
def _attrs
[
- ["version", true, "feed_version"],
+ ["version", true, "rss_version"],
]
end
@@ -405,22 +400,21 @@ module RSS
end
RSS09::ELEMENTS.each do |name|
- BaseListener.install_get_text_element("", name, name)
+ BaseListener.install_get_text_element("", name, "#{name}=")
end
module ListenerMixin
private
- def initial_start_rss(tag_name, prefix, attrs, ns)
+ def start_rss(tag_name, prefix, attrs, ns)
check_ns(tag_name, prefix, ns, "")
@rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
@rss.do_validate = @do_validate
@rss.xml_stylesheets = @xml_stylesheets
@last_element = @rss
- pr = Proc.new do |text, tags|
+ @proc_stack.push Proc.new { |text, tags|
@rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate
- end
- @proc_stack.push(pr)
+ }
end
end
diff --git a/lib/rss/1.0.rb b/lib/rss/1.0.rb
index f04e61c5eb..a945434fbf 100644
--- a/lib/rss/1.0.rb
+++ b/lib/rss/1.0.rb
@@ -45,10 +45,10 @@ module RSS
__send__("install_have_#{type}_element", tag, ::RSS::URI, occurs)
end
- alias_method(:rss_version, :feed_version)
+ attr_accessor :rss_version, :version, :encoding, :standalone
+
def initialize(version=nil, encoding=nil, standalone=nil)
super('1.0', version, encoding, standalone)
- @feed_type = "rss"
end
def full_name
@@ -430,22 +430,21 @@ module RSS
end
RSS10::ELEMENTS.each do |name|
- BaseListener.install_get_text_element(URI, name, name)
+ BaseListener.install_get_text_element(URI, name, "#{name}=")
end
module ListenerMixin
private
- def initial_start_RDF(tag_name, prefix, attrs, ns)
+ def start_RDF(tag_name, prefix, attrs, ns)
check_ns(tag_name, prefix, ns, RDF::URI)
@rss = RDF.new(@version, @encoding, @standalone)
@rss.do_validate = @do_validate
@rss.xml_stylesheets = @xml_stylesheets
@last_element = @rss
- pr = Proc.new do |text, tags|
+ @proc_stack.push Proc.new { |text, tags|
@rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate
- end
- @proc_stack.push(pr)
+ }
end
end
diff --git a/lib/rss/2.0.rb b/lib/rss/2.0.rb
index 3798da4eb7..44bdb4f1ae 100644
--- a/lib/rss/2.0.rb
+++ b/lib/rss/2.0.rb
@@ -105,7 +105,7 @@ module RSS
end
RSS09::ELEMENTS.each do |name|
- BaseListener.install_get_text_element("", name, name)
+ BaseListener.install_get_text_element("", name, "#{name}=")
end
end
diff --git a/lib/rss/atom.rb b/lib/rss/atom.rb
deleted file mode 100644
index 7cba934feb..0000000000
--- a/lib/rss/atom.rb
+++ /dev/null
@@ -1,749 +0,0 @@
-require 'base64'
-require 'rss/parser'
-
-module RSS
- module Atom
- URI = "http://www.w3.org/2005/Atom"
- XHTML_URI = "http://www.w3.org/1999/xhtml"
-
- module CommonModel
- NSPOOL = {}
- ELEMENTS = []
-
- def self.append_features(klass)
- super
- klass.install_must_call_validator("atom", URI)
- [
- ["lang", :xml],
- ["base", :xml],
- ].each do |name, uri, required|
- klass.install_get_attribute(name, uri, required, [nil, :inherit])
- end
- klass.class_eval do
- class << self
- def required_uri
- URI
- end
-
- def need_parent?
- true
- end
- end
- end
- end
- end
-
- module ContentModel
- module ClassMethods
- def content_type
- @content_type ||= nil
- end
- end
-
- class << self
- def append_features(klass)
- super
- klass.extend(ClassMethods)
- klass.content_setup(klass.content_type, klass.tag_name)
- end
- end
-
- def maker_target(target)
- target
- end
-
- private
- def setup_maker_element_writer
- "#{self.class.name.split(/::/).last.downcase}="
- end
-
- def setup_maker_element(target)
- target.__send__(setup_maker_element_writer, content)
- super
- end
- end
-
- module URIContentModel
- class << self
- def append_features(klass)
- super
- klass.class_eval do
- @content_type = [nil, :uri]
- include(ContentModel)
- end
- end
- end
- end
-
- module TextConstruct
- def self.append_features(klass)
- super
- klass.class_eval do
- [
- ["type", ""],
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, :text_type)
- end
-
- content_setup
- add_need_initialize_variable("xhtml")
-
- class << self
- def xml_getter
- "xhtml"
- end
-
- def xml_setter
- "xhtml="
- end
- end
- end
- end
-
- attr_writer :xhtml
- def xhtml
- return @xhtml if @xhtml.nil?
- if @xhtml.is_a?(XML::Element) and
- [@xhtml.name, @xhtml.uri] == ["div", XHTML_URI]
- return @xhtml
- end
-
- children = @xhtml
- children = [children] unless children.is_a?(Array)
- XML::Element.new("div", nil, XHTML_URI,
- {"xmlns" => XHTML_URI}, children)
- end
-
- def have_xml_content?
- @type == "xhtml"
- end
-
- def atom_validate(ignore_unknown_element, tags, uri)
- if have_xml_content?
- if @xhtml.nil?
- raise MissingTagError.new("div", tag_name)
- end
- unless [@xhtml.name, @xhtml.uri] == ["div", XHTML_URI]
- raise NotExpectedTagError.new(@xhtml.name, @xhtml.uri, tag_name)
- end
- end
- end
-
- private
- def maker_target(target)
- target.__send__(self.class.name.split(/::/).last.downcase) {|x| x}
- end
-
- def setup_maker_attributes(target)
- target.type = type
- target.content = content
- target.xml_content = @xhtml
- end
- end
-
- module PersonConstruct
- def self.append_features(klass)
- super
- klass.class_eval do
- [
- ["name", nil],
- ["uri", "?"],
- ["email", "?"],
- ].each do |tag, occurs|
- install_have_attribute_element(tag, URI, occurs, nil, :content)
- end
- end
- end
-
- def maker_target(target)
- target.__send__("new_#{self.class.name.split(/::/).last.downcase}")
- end
-
- class Name < RSS::Element
- include CommonModel
- include ContentModel
- end
-
- class Uri < RSS::Element
- include CommonModel
- include URIContentModel
- end
-
- class Email < RSS::Element
- include CommonModel
- include ContentModel
- end
- end
-
- module DateConstruct
- def self.append_features(klass)
- super
- klass.class_eval do
- @content_type = :w3cdtf
- include(ContentModel)
- end
- end
-
- def atom_validate(ignore_unknown_element, tags, uri)
- raise NotAvailableValueError.new(tag_name, "") if content.nil?
- end
- end
-
- module DuplicateLinkChecker
- def validate_duplicate_links(links)
- link_infos = {}
- links.each do |link|
- rel = link.rel || "alternate"
- next unless rel == "alternate"
- key = [link.hreflang, link.type]
- if link_infos.has_key?(key)
- raise TooMuchTagError.new("link", tag_name)
- end
- link_infos[key] = true
- end
- end
- end
-
- class Feed < RSS::Element
- include RootElementMixin
- include CommonModel
- include DuplicateLinkChecker
-
- install_ns('', URI)
-
- [
- ["author", "*", :children],
- ["category", "*", :children, "categories"],
- ["contributor", "*", :children],
- ["generator", "?"],
- ["icon", "?", nil, :content],
- ["id", nil, nil, :content],
- ["link", "*", :children],
- ["logo", "?"],
- ["rights", "?"],
- ["subtitle", "?", nil, :content],
- ["title", nil, nil, :content],
- ["updated", nil, nil, :content],
- ["entry", "*", :children, "entries"],
- ].each do |tag, occurs, type, *args|
- type ||= :child
- __send__("install_have_#{type}_element",
- tag, URI, occurs, tag, *args)
- end
-
- def initialize(version=nil, encoding=nil, standalone=nil)
- super("1.0", version, encoding, standalone)
- @feed_type = "atom"
- @feed_subtype = "feed"
- end
-
- alias_method :items, :entries
-
- def have_author?
- authors.any? {|author| !author.to_s.empty?} or
- entries.any? {|entry| entry.have_author?(false)}
- end
-
- private
- def atom_validate(ignore_unknown_element, tags, uri)
- unless have_author?
- raise MissingTagError.new("author", tag_name)
- end
- validate_duplicate_links(links)
- end
-
- def have_required_elements?
- super and have_author?
- end
-
- def maker_target(maker)
- maker.channel
- end
-
- def setup_maker_element(channel)
- prev_dc_dates = channel.dc_dates.to_a.dup
- super
- channel.about = id.content if id
- channel.dc_dates.replace(prev_dc_dates)
- end
-
- def setup_maker_elements(channel)
- super
- items = channel.maker.items
- entries.each do |entry|
- entry.setup_maker(items)
- end
- end
-
- class Author < RSS::Element
- include CommonModel
- include PersonConstruct
- end
-
- class Category < RSS::Element
- include CommonModel
-
- [
- ["term", "", true],
- ["scheme", "", false, [nil, :uri]],
- ["label", ""],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- private
- def maker_target(target)
- target.new_category
- end
- end
-
- class Contributor < RSS::Element
- include CommonModel
- include PersonConstruct
- end
-
- class Generator < RSS::Element
- include CommonModel
- include ContentModel
-
- [
- ["uri", "", false, [nil, :uri]],
- ["version", ""],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- private
- def setup_maker_attributes(target)
- target.generator do |generator|
- generator.uri = uri if uri
- generator.version = version if version
- end
- end
- end
-
- class Icon < RSS::Element
- include CommonModel
- include URIContentModel
- end
-
- class Id < RSS::Element
- include CommonModel
- include URIContentModel
- end
-
- class Link < RSS::Element
- include CommonModel
-
- [
- ["href", "", true, [nil, :uri]],
- ["rel", ""],
- ["type", ""],
- ["hreflang", ""],
- ["title", ""],
- ["length", ""],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- private
- def maker_target(target)
- target.new_link
- end
- end
-
- class Logo < RSS::Element
- include CommonModel
- include URIContentModel
-
- def maker_target(target)
- target.maker.image
- end
-
- private
- def setup_maker_element_writer
- "url="
- end
- end
-
- class Rights < RSS::Element
- include CommonModel
- include TextConstruct
- end
-
- class Subtitle < RSS::Element
- include CommonModel
- include TextConstruct
- end
-
- class Title < RSS::Element
- include CommonModel
- include TextConstruct
- end
-
- class Updated < RSS::Element
- include CommonModel
- include DateConstruct
- end
-
- class Entry < RSS::Element
- include CommonModel
- include DuplicateLinkChecker
-
- [
- ["author", "*", :children],
- ["category", "*", :children, "categories"],
- ["content", "?", :child],
- ["contributor", "*", :children],
- ["id", nil, nil, :content],
- ["link", "*", :children],
- ["published", "?", :child, :content],
- ["rights", "?", :child],
- ["source", "?"],
- ["summary", "?", :child],
- ["title", nil],
- ["updated", nil, :child, :content],
- ].each do |tag, occurs, type, *args|
- type ||= :attribute
- __send__("install_have_#{type}_element",
- tag, URI, occurs, tag, *args)
- end
-
- def have_author?(check_parent=true)
- authors.any? {|author| !author.to_s.empty?} or
- (check_parent and @parent and @parent.have_author?) or
- (source and source.have_author?)
- end
-
- private
- def atom_validate(ignore_unknown_element, tags, uri)
- unless have_author?
- raise MissingTagError.new("author", tag_name)
- end
- validate_duplicate_links(links)
- end
-
- def have_required_elements?
- super and have_author?
- end
-
- def maker_target(items)
- if items.respond_to?("items")
- # For backward compatibility
- items = items.items
- end
- items.new_item
- end
-
- Author = Feed::Author
- Category = Feed::Category
-
- class Content < RSS::Element
- include CommonModel
-
- class << self
- def xml_setter
- "xml="
- end
-
- def xml_getter
- "xml"
- end
- end
-
- [
- ["type", ""],
- ["src", "", false, [nil, :uri]],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- content_setup
- add_need_initialize_variable("xml")
-
- attr_writer :xml
- def have_xml_content?
- inline_xhtml? or inline_other_xml?
- end
-
- def xml
- return @xml unless inline_xhtml?
- return @xml if @xml.nil?
- if @xml.is_a?(XML::Element) and
- [@xml.name, @xml.uri] == ["div", XHTML_URI]
- return @xml
- end
-
- children = @xml
- children = [children] unless children.is_a?(Array)
- XML::Element.new("div", nil, XHTML_URI,
- {"xmlns" => XHTML_URI}, children)
- end
-
- def xhtml
- if inline_xhtml?
- xml
- else
- nil
- end
- end
-
- def atom_validate(ignore_unknown_element, tags, uri)
- if out_of_line?
- raise MissingAttributeError.new(tag_name, "type") if @type.nil?
- unless (content.nil? or content.empty?)
- raise NotAvailableValueError.new(tag_name, content)
- end
- elsif inline_xhtml?
- if @xml.nil?
- raise MissingTagError.new("div", tag_name)
- end
- unless @xml.name == "div" and @xml.uri == XHTML_URI
- raise NotExpectedTagError.new(@xml.name, @xml.uri, tag_name)
- end
- end
- end
-
- def inline_text?
- !out_of_line? and [nil, "text", "html"].include?(@type)
- end
-
- def inline_html?
- return false if out_of_line?
- @type == "html" or mime_split == ["text", "html"]
- end
-
- def inline_xhtml?
- !out_of_line? and @type == "xhtml"
- end
-
- def inline_other?
- return false if out_of_line?
- media_type, subtype = mime_split
- return false if media_type.nil? or subtype.nil?
- true
- end
-
- def inline_other_text?
- return false unless inline_other?
- return false if inline_other_xml?
-
- media_type, subtype = mime_split
- return true if "text" == media_type.downcase
- false
- end
-
- def inline_other_xml?
- return false unless inline_other?
-
- media_type, subtype = mime_split
- normalized_mime_type = "#{media_type}/#{subtype}".downcase
- if /(?:\+xml|^xml)$/ =~ subtype or
- %w(text/xml-external-parsed-entity
- application/xml-external-parsed-entity
- application/xml-dtd).find {|x| x == normalized_mime_type}
- return true
- end
- false
- end
-
- def inline_other_base64?
- inline_other? and !inline_other_text? and !inline_other_xml?
- end
-
- def out_of_line?
- not @src.nil?
- end
-
- def mime_split
- media_type = subtype = nil
- if /\A\s*([a-z]+)\/([a-z\+]+)\s*(?:;.*)?\z/i =~ @type.to_s
- media_type = $1.downcase
- subtype = $2.downcase
- end
- [media_type, subtype]
- end
-
- def need_base64_encode?
- inline_other_base64?
- end
-
- private
- def empty_content?
- out_of_line? or super
- end
- end
-
- Contributor = Feed::Contributor
- Id = Feed::Id
- Link = Feed::Link
-
- class Published < RSS::Element
- include CommonModel
- include DateConstruct
- end
-
- Rights = Feed::Rights
-
- class Source < RSS::Element
- include CommonModel
-
- [
- ["author", "*", :children],
- ["category", "*", :children, "categories"],
- ["contributor", "*", :children],
- ["generator", "?"],
- ["icon", "?"],
- ["id", "?", nil, :content],
- ["link", "*", :children],
- ["logo", "?"],
- ["rights", "?"],
- ["subtitle", "?"],
- ["title", "?"],
- ["updated", "?", nil, :content],
- ].each do |tag, occurs, type, *args|
- type ||= :attribute
- __send__("install_have_#{type}_element",
- tag, URI, occurs, tag, *args)
- end
-
- def have_author?
- !author.to_s.empty?
- end
-
- Author = Feed::Author
- Category = Feed::Category
- Contributor = Feed::Contributor
- Generator = Feed::Generator
- Icon = Feed::Icon
- Id = Feed::Id
- Link = Feed::Link
- Logo = Feed::Logo
- Rights = Feed::Rights
- Subtitle = Feed::Subtitle
- Title = Feed::Title
- Updated = Feed::Updated
- end
-
- class Summary < RSS::Element
- include CommonModel
- include TextConstruct
- end
-
- Title = Feed::Title
- Updated = Feed::Updated
- end
- end
-
- class Entry < RSS::Element
- include RootElementMixin
- include CommonModel
- include DuplicateLinkChecker
-
- [
- ["author", "*", :children],
- ["category", "*", :children, "categories"],
- ["content", "?"],
- ["contributor", "*", :children],
- ["id", nil, nil, :content],
- ["link", "*", :children],
- ["published", "?", :child, :content],
- ["rights", "?"],
- ["source", "?"],
- ["summary", "?"],
- ["title", nil],
- ["updated", nil, nil, :content],
- ].each do |tag, occurs, type, *args|
- type ||= :attribute
- __send__("install_have_#{type}_element",
- tag, URI, occurs, tag, *args)
- end
-
- def initialize(version=nil, encoding=nil, standalone=nil)
- super("1.0", version, encoding, standalone)
- @feed_type = "atom"
- @feed_subtype = "entry"
- end
-
- def items
- [self]
- end
-
- def setup_maker(maker)
- maker = maker.maker if maker.respond_to?("maker")
- super(maker)
- end
-
- def have_author?
- authors.any? {|author| !author.to_s.empty?} or
- (source and source.have_author?)
- end
-
- private
- def atom_validate(ignore_unknown_element, tags, uri)
- unless have_author?
- raise MissingTagError.new("author", tag_name)
- end
- validate_duplicate_links(links)
- end
-
- def have_required_elements?
- super and have_author?
- end
-
- def maker_target(maker)
- maker.items.new_item
- end
-
- Author = Feed::Entry::Author
- Category = Feed::Entry::Category
- Content = Feed::Entry::Content
- Contributor = Feed::Entry::Contributor
- Id = Feed::Entry::Id
- Link = Feed::Entry::Link
- Published = Feed::Entry::Published
- Rights = Feed::Entry::Rights
- Source = Feed::Entry::Source
- Summary = Feed::Entry::Summary
- Title = Feed::Entry::Title
- Updated = Feed::Entry::Updated
- end
- end
-
- Atom::CommonModel::ELEMENTS.each do |name|
- BaseListener.install_get_text_element(Atom::URI, name, "#{name}=")
- end
-
- module ListenerMixin
- private
- def initial_start_feed(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, Atom::URI)
-
- @rss = Atom::Feed.new(@version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @rss.xml_stylesheets = @xml_stylesheets
- @rss.lang = attrs["xml:lang"]
- @rss.base = attrs["xml:base"]
- @last_element = @rss
- pr = Proc.new do |text, tags|
- @rss.validate_for_stream(tags) if @do_validate
- end
- @proc_stack.push(pr)
- end
-
- def initial_start_entry(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, Atom::URI)
-
- @rss = Atom::Entry.new(@version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @rss.xml_stylesheets = @xml_stylesheets
- @rss.lang = attrs["xml:lang"]
- @rss.base = attrs["xml:base"]
- @last_element = @rss
- pr = Proc.new do |text, tags|
- @rss.validate_for_stream(tags) if @do_validate
- end
- @proc_stack.push(pr)
- end
- end
-end
diff --git a/lib/rss/content.rb b/lib/rss/content.rb
index b12ee918aa..1b13f39fcf 100644
--- a/lib/rss/content.rb
+++ b/lib/rss/content.rb
@@ -1,31 +1,38 @@
-require "rss/rss"
+require "rss/1.0"
module RSS
+
CONTENT_PREFIX = 'content'
CONTENT_URI = "http://purl.org/rss/1.0/modules/content/"
+ RDF.install_ns(CONTENT_PREFIX, CONTENT_URI)
+
module ContentModel
+
extend BaseModel
- ELEMENTS = ["#{CONTENT_PREFIX}_encoded"]
+ ELEMENTS = []
def self.append_features(klass)
super
klass.install_must_call_validator(CONTENT_PREFIX, CONTENT_URI)
- ELEMENTS.each do |full_name|
- name = full_name[(CONTENT_PREFIX.size + 1)..-1]
- klass.install_text_element(name, CONTENT_URI, "?", full_name)
+ %w(encoded).each do |name|
+ klass.install_text_element(name, CONTENT_URI, "?",
+ "#{CONTENT_PREFIX}_#{name}")
end
end
end
+ class RDF
+ class Item; include ContentModel; end
+ end
+
prefix_size = CONTENT_PREFIX.size + 1
+ ContentModel::ELEMENTS.uniq!
ContentModel::ELEMENTS.each do |full_name|
name = full_name[prefix_size..-1]
- BaseListener.install_get_text_element(CONTENT_URI, name, full_name)
+ BaseListener.install_get_text_element(CONTENT_URI, name, "#{full_name}=")
end
-end
-require 'rss/content/1.0'
-require 'rss/content/2.0'
+end
diff --git a/lib/rss/content/1.0.rb b/lib/rss/content/1.0.rb
deleted file mode 100644
index e7c0c19685..0000000000
--- a/lib/rss/content/1.0.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require 'rss/1.0'
-require 'rss/content'
-
-module RSS
- RDF.install_ns(CONTENT_PREFIX, CONTENT_URI)
-
- class RDF
- class Item; include ContentModel; end
- end
-end
diff --git a/lib/rss/content/2.0.rb b/lib/rss/content/2.0.rb
deleted file mode 100644
index 8671b5b1a6..0000000000
--- a/lib/rss/content/2.0.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require "rss/2.0"
-require "rss/content"
-
-module RSS
- Rss.install_ns(CONTENT_PREFIX, CONTENT_URI)
-
- class Rss
- class Channel
- class Item; include ContentModel; end
- end
- end
-end
diff --git a/lib/rss/converter.rb b/lib/rss/converter.rb
index 415a319188..d928c48223 100644
--- a/lib/rss/converter.rb
+++ b/lib/rss/converter.rb
@@ -80,12 +80,8 @@ module RSS
end
rescue LoadError
require 'nkf'
- if NKF.const_defined?(:UTF8)
- def_convert(1) do |value|
- "NKF.nkf(#{nkf_arg.dump}, #{value})"
- end
- else
- def_iconv_convert(to_enc, from_enc, 1)
+ def_convert(1) do |value|
+ "NKF.nkf(#{nkf_arg.dump}, #{value})"
end
end
end
diff --git a/lib/rss/dublincore.rb b/lib/rss/dublincore.rb
index 7ba239f8f1..8a4afd4dd9 100644
--- a/lib/rss/dublincore.rb
+++ b/lib/rss/dublincore.rb
@@ -1,8 +1,11 @@
-require "rss/rss"
+require "rss/1.0"
module RSS
+
DC_PREFIX = 'dc'
DC_URI = "http://purl.org/dc/elements/1.1/"
+
+ RDF.install_ns(DC_PREFIX, DC_URI)
module BaseDublinCoreModel
def append_features(klass)
@@ -33,20 +36,8 @@ module RSS
EOC
end
klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0))
- if method_defined?(:date)
- alias date_without_#{DC_PREFIX}_date= date=
-
- def date=(value)
- self.date_without_#{DC_PREFIX}_date = value
- self.#{DC_PREFIX}_date = value
- end
- else
- alias date #{DC_PREFIX}_date
- alias date= #{DC_PREFIX}_date=
- end
-
- # For backward compatibility
- alias #{DC_PREFIX}_rightses #{DC_PREFIX}_rights_list
+ alias date #{DC_PREFIX}_date
+ alias date= #{DC_PREFIX}_date=
EOC
end
end
@@ -70,7 +61,7 @@ module RSS
"language" => nil,
"relation" => nil,
"coverage" => nil,
- "rights" => "rights_list"
+ "rights" => "rightses" # FIXME
}
DATE_ELEMENTS = {
@@ -131,14 +122,13 @@ module RSS
end
DATE_ELEMENTS.each do |name, type|
- tag_name = "#{DC_PREFIX}:#{name}"
module_eval(<<-EOC, *get_file_and_line_from_caller(0))
class DublinCore#{Utils.to_class_name(name)} < Element
remove_method(:content=)
remove_method(:value=)
- date_writer("content", #{type.dump}, #{tag_name.dump})
-
+ date_writer("content", #{type.dump}, #{name.dump})
+
alias_method(:value=, :content=)
end
EOC
@@ -148,6 +138,13 @@ module RSS
# For backward compatibility
DublincoreModel = DublinCoreModel
+ class RDF
+ class Channel; include DublinCoreModel; end
+ class Image; include DublinCoreModel; end
+ class Item; include DublinCoreModel; end
+ class Textinput; include DublinCoreModel; end
+ end
+
DublinCoreModel::ELEMENTS.each do |name|
class_name = Utils.to_class_name(name)
BaseListener.install_class_name(DC_URI, name, "DublinCore#{class_name}")
@@ -155,7 +152,3 @@ module RSS
DublinCoreModel::ELEMENTS.collect! {|name| "#{DC_PREFIX}_#{name}"}
end
-
-require 'rss/dublincore/1.0'
-require 'rss/dublincore/2.0'
-require 'rss/dublincore/atom'
diff --git a/lib/rss/dublincore/1.0.rb b/lib/rss/dublincore/1.0.rb
deleted file mode 100644
index e193c6d2c2..0000000000
--- a/lib/rss/dublincore/1.0.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require "rss/1.0"
-require "rss/dublincore"
-
-module RSS
- RDF.install_ns(DC_PREFIX, DC_URI)
-
- class RDF
- class Channel; include DublinCoreModel; end
- class Image; include DublinCoreModel; end
- class Item; include DublinCoreModel; end
- class Textinput; include DublinCoreModel; end
- end
-end
diff --git a/lib/rss/dublincore/2.0.rb b/lib/rss/dublincore/2.0.rb
deleted file mode 100644
index 82ed1888c5..0000000000
--- a/lib/rss/dublincore/2.0.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require "rss/2.0"
-require "rss/dublincore"
-
-module RSS
- Rss.install_ns(DC_PREFIX, DC_URI)
-
- class Rss
- class Channel
- include DublinCoreModel
- class Item; include DublinCoreModel; end
- end
- end
-end
diff --git a/lib/rss/dublincore/atom.rb b/lib/rss/dublincore/atom.rb
deleted file mode 100644
index e78df4821b..0000000000
--- a/lib/rss/dublincore/atom.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require "rss/atom"
-require "rss/dublincore"
-
-module RSS
- module Atom
- Feed.install_ns(DC_PREFIX, DC_URI)
-
- class Feed
- include DublinCoreModel
- class Entry; include DublinCoreModel; end
- end
-
- class Entry
- include DublinCoreModel
- end
- end
-end
diff --git a/lib/rss/image.rb b/lib/rss/image.rb
index c4714aea12..a9e9e9094e 100644
--- a/lib/rss/image.rb
+++ b/lib/rss/image.rb
@@ -4,7 +4,7 @@ require 'rss/dublincore'
module RSS
IMAGE_PREFIX = 'image'
- IMAGE_URI = 'http://purl.org/rss/1.0/modules/image/'
+ IMAGE_URI = 'http://web.resource.org/rss/1.0/modules/image/'
RDF.install_ns(IMAGE_PREFIX, IMAGE_URI)
@@ -69,7 +69,7 @@ module RSS
disp_name = "#{IMAGE_PREFIX}:#{tag}"
install_text_element(tag, IMAGE_URI, "?",
full_name, :integer, disp_name)
- BaseListener.install_get_text_element(IMAGE_URI, tag, full_name)
+ BaseListener.install_get_text_element(IMAGE_URI, tag, "#{full_name}=")
end
alias width= image_width=
@@ -142,8 +142,8 @@ module RSS
end
AVAILABLE_SIZES = %w(small medium large)
- alias_method :set_size, :size=
- private :set_size
+ alias_method :_size=, :size=
+ private :_size=
def size=(new_value)
if @do_validate and !new_value.nil?
new_value = new_value.strip
@@ -152,7 +152,7 @@ module RSS
raise NotAvailableValueError.new(full_name, new_value, attr_name)
end
end
- set_size(new_value)
+ __send__(:_size=, new_value)
end
alias image_size= size=
diff --git a/lib/rss/itunes.rb b/lib/rss/itunes.rb
deleted file mode 100644
index f95ca7aa2e..0000000000
--- a/lib/rss/itunes.rb
+++ /dev/null
@@ -1,410 +0,0 @@
-require 'rss/2.0'
-
-module RSS
- ITUNES_PREFIX = 'itunes'
- ITUNES_URI = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
-
- Rss.install_ns(ITUNES_PREFIX, ITUNES_URI)
-
- module ITunesModelUtils
- include Utils
-
- def def_class_accessor(klass, name, type, *args)
- normalized_name = name.gsub(/-/, "_")
- full_name = "#{ITUNES_PREFIX}_#{normalized_name}"
- klass_name = "ITunes#{Utils.to_class_name(normalized_name)}"
-
- case type
- when :element, :attribute
- klass::ELEMENTS << full_name
- def_element_class_accessor(klass, name, full_name, klass_name, *args)
- when :elements
- klass::ELEMENTS << full_name
- def_elements_class_accessor(klass, name, full_name, klass_name, *args)
- else
- klass.install_must_call_validator(ITUNES_PREFIX, ITUNES_URI)
- klass.install_text_element(normalized_name, ITUNES_URI, "?",
- full_name, type, name)
- end
- end
-
- def def_element_class_accessor(klass, name, full_name, klass_name,
- recommended_attribute_name=nil)
- klass.install_have_child_element(name, ITUNES_PREFIX, "?", full_name)
- end
-
- def def_elements_class_accessor(klass, name, full_name, klass_name,
- plural_name, recommended_attribute_name=nil)
- full_plural_name = "#{ITUNES_PREFIX}_#{plural_name}"
- klass.install_have_children_element(name, ITUNES_PREFIX, "*",
- full_name, full_plural_name)
- end
- end
-
- module ITunesBaseModel
- extend ITunesModelUtils
-
- ELEMENTS = []
-
- ELEMENT_INFOS = [["author"],
- ["block", :yes_other],
- ["explicit", :yes_clean_other],
- ["keywords", :csv],
- ["subtitle"],
- ["summary"]]
- end
-
- module ITunesChannelModel
- extend BaseModel
- extend ITunesModelUtils
- include ITunesBaseModel
-
- ELEMENTS = []
-
- class << self
- def append_features(klass)
- super
-
- return if klass.instance_of?(Module)
- ELEMENT_INFOS.each do |name, type, *additional_infos|
- def_class_accessor(klass, name, type, *additional_infos)
- end
- end
- end
-
- ELEMENT_INFOS = [
- ["category", :elements, "categories", "text"],
- ["image", :attribute, "href"],
- ["owner", :element],
- ["new-feed-url"],
- ] + ITunesBaseModel::ELEMENT_INFOS
-
- class ITunesCategory < Element
- include RSS09
-
- @tag_name = "category"
-
- class << self
- def required_prefix
- ITUNES_PREFIX
- end
-
- def required_uri
- ITUNES_URI
- end
- end
-
- [
- ["text", "", true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- ITunesCategory = self
- install_have_children_element("category", ITUNES_URI, "*",
- "#{ITUNES_PREFIX}_category",
- "#{ITUNES_PREFIX}_categories")
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.text = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(ITUNES_PREFIX)
- end
-
- private
- def maker_target(categories)
- if text or !itunes_categories.empty?
- categories.new_category
- else
- nil
- end
- end
-
- def setup_maker_attributes(category)
- category.text = text if text
- end
-
- def setup_maker_elements(category)
- super(category)
- itunes_categories.each do |sub_category|
- sub_category.setup_maker(category)
- end
- end
- end
-
- class ITunesImage < Element
- include RSS09
-
- @tag_name = "image"
-
- class << self
- def required_prefix
- ITUNES_PREFIX
- end
-
- def required_uri
- ITUNES_URI
- end
- end
-
- [
- ["href", "", true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.href = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(ITUNES_PREFIX)
- end
-
- private
- def maker_target(target)
- if href
- target.itunes_image {|image| image}
- else
- nil
- end
- end
-
- def setup_maker_attributes(image)
- image.href = href
- end
- end
-
- class ITunesOwner < Element
- include RSS09
-
- @tag_name = "owner"
-
- class << self
- def required_prefix
- ITUNES_PREFIX
- end
-
- def required_uri
- ITUNES_URI
- end
- end
-
- install_must_call_validator(ITUNES_PREFIX, ITUNES_URI)
- [
- ["name"],
- ["email"],
- ].each do |name,|
- ITunesBaseModel::ELEMENT_INFOS << name
- install_text_element(name, ITUNES_URI, nil, "#{ITUNES_PREFIX}_#{name}")
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.itunes_name = args[0]
- self.itunes_email = args[1]
- end
- end
-
- def full_name
- tag_name_with_prefix(ITUNES_PREFIX)
- end
-
- private
- def maker_target(target)
- target.itunes_owner
- end
-
- def setup_maker_element(owner)
- super(owner)
- owner.itunes_name = itunes_name
- owner.itunes_email = itunes_email
- end
- end
- end
-
- module ITunesItemModel
- extend BaseModel
- extend ITunesModelUtils
- include ITunesBaseModel
-
- class << self
- def append_features(klass)
- super
-
- return if klass.instance_of?(Module)
- ELEMENT_INFOS.each do |name, type|
- def_class_accessor(klass, name, type)
- end
- end
- end
-
- ELEMENT_INFOS = ITunesBaseModel::ELEMENT_INFOS +
- [["duration", :element, "content"]]
-
- class ITunesDuration < Element
- include RSS09
-
- @tag_name = "duration"
-
- class << self
- def required_prefix
- ITUNES_PREFIX
- end
-
- def required_uri
- ITUNES_URI
- end
-
- def parse(duration, do_validate=true)
- if do_validate and /\A(?:
- \d?\d:[0-5]\d:[0-5]\d|
- [0-5]?\d:[0-5]\d
- )\z/x !~ duration
- raise ArgumentError,
- "must be one of HH:MM:SS, H:MM:SS, MM::SS, M:SS: " +
- duration.inspect
- end
-
- components = duration.split(':')
- components[3..-1] = nil if components.size > 3
-
- components.unshift("00") until components.size == 3
-
- components.collect do |component|
- component.to_i
- end
- end
-
- def construct(hour, minute, second)
- components = [minute, second]
- if components.include?(nil)
- nil
- else
- components.unshift(hour) if hour and hour > 0
- components.collect do |component|
- "%02d" % component
- end.join(":")
- end
- end
- end
-
- content_setup
- alias_method(:value, :content)
- remove_method(:content=)
-
- attr_reader :hour, :minute, :second
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- args = args[0] if args.size == 1 and args[0].is_a?(Array)
- if args.size == 1
- self.content = args[0]
- elsif args.size > 3
- raise ArgumentError,
- "must be (do_validate, params), (content), " +
- "(minute, second), ([minute, second]), " +
- "(hour, minute, second) or ([hour, minute, second]): " +
- args.inspect
- else
- @second, @minute, @hour = args.reverse
- update_content
- end
- end
- end
-
- def content=(value)
- if value.nil?
- @content = nil
- elsif value.is_a?(self.class)
- self.content = value.content
- else
- begin
- @hour, @minute, @second = self.class.parse(value, @do_validate)
- rescue ArgumentError
- raise NotAvailableValueError.new(tag_name, value)
- end
- @content = value
- end
- end
- alias_method(:value=, :content=)
-
- def hour=(hour)
- @hour = @do_validate ? Integer(hour) : hour.to_i
- update_content
- hour
- end
-
- def minute=(minute)
- @minute = @do_validate ? Integer(minute) : minute.to_i
- update_content
- minute
- end
-
- def second=(second)
- @second = @do_validate ? Integer(second) : second.to_i
- update_content
- second
- end
-
- def full_name
- tag_name_with_prefix(ITUNES_PREFIX)
- end
-
- private
- def update_content
- @content = self.class.construct(hour, minute, second)
- end
-
- def maker_target(target)
- if @content
- target.itunes_duration {|duration| duration}
- else
- nil
- end
- end
-
- def setup_maker_element(duration)
- super(duration)
- duration.content = @content
- end
- end
- end
-
- class Rss
- class Channel
- include ITunesChannelModel
- class Item; include ITunesItemModel; end
- end
- end
-
- element_infos =
- ITunesChannelModel::ELEMENT_INFOS + ITunesItemModel::ELEMENT_INFOS
- element_infos.each do |name, type|
- case type
- when :element, :elements, :attribute
- class_name = Utils.to_class_name(name)
- BaseListener.install_class_name(ITUNES_URI, name, "ITunes#{class_name}")
- else
- accessor_base = "#{ITUNES_PREFIX}_#{name.gsub(/-/, '_')}"
- BaseListener.install_get_text_element(ITUNES_URI, name, accessor_base)
- end
- end
-end
diff --git a/lib/rss/maker.rb b/lib/rss/maker.rb
index bcba1aaff3..9ed799ac7f 100644
--- a/lib/rss/maker.rb
+++ b/lib/rss/maker.rb
@@ -1,44 +1,37 @@
require "rss/rss"
module RSS
+
module Maker
- MAKERS = {}
+ MAKERS = {}
+
class << self
def make(version, &block)
- m = maker(version)
- raise UnsupportedMakerVersionError.new(version) if m.nil?
- m[:maker].make(m[:version], &block)
+ maker(version).make(&block)
end
def maker(version)
MAKERS[version]
end
- def add_maker(version, normalized_version, maker)
- MAKERS[version] = {:maker => maker, :version => normalized_version}
- end
-
- def versions
- MAKERS.keys.uniq.sort
+ def add_maker(version, maker)
+ MAKERS[version] = maker
end
- def makers
- MAKERS.values.collect {|info| info[:maker]}.uniq
+ def filename_to_version(filename)
+ File.basename(filename, ".*")
end
end
end
+
end
require "rss/maker/1.0"
require "rss/maker/2.0"
-require "rss/maker/feed"
-require "rss/maker/entry"
require "rss/maker/content"
require "rss/maker/dublincore"
-require "rss/maker/slash"
require "rss/maker/syndication"
require "rss/maker/taxonomy"
require "rss/maker/trackback"
require "rss/maker/image"
-require "rss/maker/itunes"
diff --git a/lib/rss/maker/0.9.rb b/lib/rss/maker/0.9.rb
index 72b14dc977..b82585fb96 100644
--- a/lib/rss/maker/0.9.rb
+++ b/lib/rss/maker/0.9.rb
@@ -7,14 +7,13 @@ module RSS
class RSS09 < RSSBase
- def initialize(feed_version="0.92")
+ def initialize(rss_version="0.91")
super
- @feed_type = "rss"
end
private
- def make_feed
- Rss.new(@feed_version, @version, @encoding, @standalone)
+ def make_rss
+ Rss.new(@rss_version, @version, @encoding, @standalone)
end
def setup_elements(rss)
@@ -22,34 +21,41 @@ module RSS
end
class Channel < ChannelBase
- def to_feed(rss)
+
+ def to_rss(rss)
channel = Rss::Channel.new
set = setup_values(channel)
- _not_set_required_variables = not_set_required_variables
- if _not_set_required_variables.empty?
+ if set
rss.channel = channel
- set_parent(channel, rss)
setup_items(rss)
setup_image(rss)
setup_textinput(rss)
- setup_other_elements(rss, channel)
- rss
- else
- raise NotSetError.new("maker.channel", _not_set_required_variables)
+ setup_other_elements(rss)
+ if rss.channel.image
+ rss
+ else
+ nil
+ end
+ elsif variable_is_set?
+ raise NotSetError.new("maker.channel", not_set_required_variables)
end
end
+ def have_required_values?
+ @title and @link and @description and @language
+ end
+
private
def setup_items(rss)
- @maker.items.to_feed(rss)
+ @maker.items.to_rss(rss)
end
def setup_image(rss)
- @maker.image.to_feed(rss)
+ @maker.image.to_rss(rss)
end
def setup_textinput(rss)
- @maker.textinput.to_feed(rss)
+ @maker.textinput.to_rss(rss)
end
def variables
@@ -57,411 +63,162 @@ module RSS
end
def required_variable_names
- %w(link language)
+ %w(title link description language)
end
-
- def not_set_required_variables
- vars = super
- vars << "description" unless description {|d| d.have_required_values?}
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
-
+
class SkipDays < SkipDaysBase
- def to_feed(rss, channel)
+ def to_rss(rss, channel)
unless @days.empty?
skipDays = Rss::Channel::SkipDays.new
channel.skipDays = skipDays
- set_parent(skipDays, channel)
@days.each do |day|
- day.to_feed(rss, skipDays.days)
+ day.to_rss(rss, skipDays.days)
end
end
end
class Day < DayBase
- def to_feed(rss, days)
+ def to_rss(rss, days)
day = Rss::Channel::SkipDays::Day.new
set = setup_values(day)
if set
days << day
- set_parent(day, days)
- setup_other_elements(rss, day)
+ setup_other_elements(rss)
end
end
- private
- def required_variable_names
- %w(content)
+ def have_required_values?
+ @content
end
end
end
class SkipHours < SkipHoursBase
- def to_feed(rss, channel)
+ def to_rss(rss, channel)
unless @hours.empty?
skipHours = Rss::Channel::SkipHours.new
channel.skipHours = skipHours
- set_parent(skipHours, channel)
@hours.each do |hour|
- hour.to_feed(rss, skipHours.hours)
+ hour.to_rss(rss, skipHours.hours)
end
end
end
class Hour < HourBase
- def to_feed(rss, hours)
+ def to_rss(rss, hours)
hour = Rss::Channel::SkipHours::Hour.new
set = setup_values(hour)
if set
hours << hour
- set_parent(hour, hours)
- setup_other_elements(rss, hour)
+ setup_other_elements(rss)
end
end
- private
- def required_variable_names
- %w(content)
+ def have_required_values?
+ @content
end
end
end
class Cloud < CloudBase
- def to_feed(*args)
+ def to_rss(*args)
end
end
class Categories < CategoriesBase
- def to_feed(*args)
+ def to_rss(*args)
end
class Category < CategoryBase
end
end
-
- class Links < LinksBase
- def to_feed(rss, channel)
- return if @links.empty?
- @links.first.to_feed(rss, channel)
- end
-
- class Link < LinkBase
- def to_feed(rss, channel)
- if have_required_values?
- channel.link = href
- else
- raise NotSetError.new("maker.channel.link",
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(href)
- end
- end
- end
-
- class Authors < AuthorsBase
- def to_feed(rss, channel)
- end
-
- class Author < AuthorBase
- def to_feed(rss, channel)
- end
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(rss, channel)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(rss, channel)
- end
- end
-
- class Copyright < CopyrightBase
- def to_feed(rss, channel)
- channel.copyright = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Description < DescriptionBase
- def to_feed(rss, channel)
- channel.description = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Title < TitleBase
- def to_feed(rss, channel)
- channel.title = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
end
-
+
class Image < ImageBase
- def to_feed(rss)
+ def to_rss(rss)
image = Rss::Channel::Image.new
set = setup_values(image)
if set
image.link = link
rss.channel.image = image
- set_parent(image, rss.channel)
- setup_other_elements(rss, image)
- elsif required_element?
- raise NotSetError.new("maker.image", not_set_required_variables)
+ setup_other_elements(rss)
end
end
-
- private
- def required_variable_names
- %w(url title link)
- end
-
- def required_element?
- true
+
+ def have_required_values?
+ @url and @title and link
end
end
class Items < ItemsBase
- def to_feed(rss)
+ def to_rss(rss)
if rss.channel
normalize.each do |item|
- item.to_feed(rss)
+ item.to_rss(rss)
end
- setup_other_elements(rss, rss.items)
+ setup_other_elements(rss)
end
end
class Item < ItemBase
- def to_feed(rss)
+ def to_rss(rss)
item = Rss::Channel::Item.new
set = setup_values(item)
- _not_set_required_variables = not_set_required_variables
- if _not_set_required_variables.empty?
+ if set
rss.items << item
- set_parent(item, rss.channel)
- setup_other_elements(rss, item)
- elsif variable_is_set?
- raise NotSetError.new("maker.items", _not_set_required_variables)
+ setup_other_elements(rss)
end
end
-
+
private
- def required_variable_names
- []
- end
-
- def not_set_required_variables
- vars = super
- if @maker.feed_version == "0.91"
- vars << "title" unless title {|t| t.have_required_values?}
- vars << "link" unless link {|l| l.have_required_values?}
- end
- vars
+ def have_required_values?
+ @title and @link
end
class Guid < GuidBase
- def to_feed(*args)
+ def to_rss(*args)
end
end
-
+
class Enclosure < EnclosureBase
- def to_feed(*args)
+ def to_rss(*args)
end
end
-
+
class Source < SourceBase
- def to_feed(*args)
- end
-
- class Authors < AuthorsBase
- def to_feed(*args)
- end
-
- class Author < AuthorBase
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(*args)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(*args)
- end
- end
-
- class Icon < IconBase
- def to_feed(*args)
- end
- end
-
- class Links < LinksBase
- def to_feed(*args)
- end
-
- class Link < LinkBase
- end
- end
-
- class Logo < LogoBase
- def to_feed(*args)
- end
- end
-
- class Rights < RightsBase
- def to_feed(*args)
- end
- end
-
- class Subtitle < SubtitleBase
- def to_feed(*args)
- end
- end
-
- class Title < TitleBase
- def to_feed(*args)
- end
+ def to_rss(*args)
end
end
-
+
class Categories < CategoriesBase
- def to_feed(*args)
+ def to_rss(*args)
end
class Category < CategoryBase
end
end
-
- class Authors < AuthorsBase
- def to_feed(*args)
- end
-
- class Author < AuthorBase
- end
- end
-
- class Links < LinksBase
- def to_feed(rss, item)
- return if @links.empty?
- @links.first.to_feed(rss, item)
- end
-
- class Link < LinkBase
- def to_feed(rss, item)
- if have_required_values?
- item.link = href
- else
- raise NotSetError.new("maker.link",
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(href)
- end
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(rss, item)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Rights < RightsBase
- def to_feed(rss, item)
- end
- end
-
- class Description < DescriptionBase
- def to_feed(rss, item)
- item.description = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Content < ContentBase
- def to_feed(rss, item)
- end
- end
-
- class Title < TitleBase
- def to_feed(rss, item)
- item.title = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
+
end
end
class Textinput < TextinputBase
- def to_feed(rss)
+ def to_rss(rss)
textInput = Rss::Channel::TextInput.new
set = setup_values(textInput)
if set
rss.channel.textInput = textInput
- set_parent(textInput, rss.channel)
- setup_other_elements(rss, textInput)
+ setup_other_elements(rss)
end
end
private
- def required_variable_names
- %w(title description name link)
+ def have_required_values?
+ @title and @description and @name and @link
end
end
end
- add_maker("0.9", "0.92", RSS09)
- add_maker("0.91", "0.91", RSS09)
- add_maker("0.92", "0.92", RSS09)
- add_maker("rss0.91", "0.91", RSS09)
- add_maker("rss0.92", "0.92", RSS09)
+ add_maker(filename_to_version(__FILE__), RSS09)
+ add_maker(filename_to_version(__FILE__) + "1", RSS09)
end
end
diff --git a/lib/rss/maker/1.0.rb b/lib/rss/maker/1.0.rb
index a1e2594f70..3e6542a007 100644
--- a/lib/rss/maker/1.0.rb
+++ b/lib/rss/maker/1.0.rb
@@ -7,13 +7,12 @@ module RSS
class RSS10 < RSSBase
- def initialize(feed_version="1.0")
- super
- @feed_type = "rss"
+ def initialize
+ super("1.0")
end
private
- def make_feed
+ def make_rss
RDF.new(@version, @encoding, @standalone)
end
@@ -26,46 +25,43 @@ module RSS
class Channel < ChannelBase
- def to_feed(rss)
- set_default_values do
- _not_set_required_variables = not_set_required_variables
- if _not_set_required_variables.empty?
- channel = RDF::Channel.new(@about)
- set = setup_values(channel)
+ def to_rss(rss)
+ set = false
+ if @about
+ channel = RDF::Channel.new(@about)
+ set = setup_values(channel)
+ if set
channel.dc_dates.clear
rss.channel = channel
- set_parent(channel, rss)
setup_items(rss)
setup_image(rss)
setup_textinput(rss)
- setup_other_elements(rss, channel)
- else
- raise NotSetError.new("maker.channel", _not_set_required_variables)
+ setup_other_elements(rss)
end
end
+
+ if (!@about or !set) and variable_is_set?
+ raise NotSetError.new("maker.channel", not_set_required_variables)
+ end
+ end
+
+ def have_required_values?
+ @about and @title and @link and @description
end
private
def setup_items(rss)
items = RDF::Channel::Items.new
seq = items.Seq
- set_parent(items, seq)
- target_items = @maker.items.normalize
- raise NotSetError.new("maker", ["items"]) if target_items.empty?
- target_items.each do |item|
- li = RDF::Channel::Items::Seq::Li.new(item.link)
- seq.lis << li
- set_parent(li, seq)
+ @maker.items.normalize.each do |item|
+ seq.lis << RDF::Channel::Items::Seq::Li.new(item.link)
end
rss.channel.items = items
- set_parent(rss.channel, items)
end
def setup_image(rss)
if @maker.image.have_required_values?
- image = RDF::Channel::Image.new(@maker.image.url)
- rss.channel.image = image
- set_parent(image, rss.channel)
+ rss.channel.image = RDF::Channel::Image.new(@maker.image.url)
end
end
@@ -73,23 +69,15 @@ module RSS
if @maker.textinput.have_required_values?
textinput = RDF::Channel::Textinput.new(@maker.textinput.link)
rss.channel.textinput = textinput
- set_parent(textinput, rss.channel)
end
end
def required_variable_names
- %w(about link)
- end
-
- def not_set_required_variables
- vars = super
- vars << "description" unless description {|d| d.have_required_values?}
- vars << "title" unless title {|t| t.have_required_values?}
- vars
+ %w(about title link description)
end
-
+
class SkipDays < SkipDaysBase
- def to_feed(*args)
+ def to_rss(*args)
end
class Day < DayBase
@@ -97,7 +85,7 @@ module RSS
end
class SkipHours < SkipHoursBase
- def to_feed(*args)
+ def to_rss(*args)
end
class Hour < HourBase
@@ -105,330 +93,112 @@ module RSS
end
class Cloud < CloudBase
- def to_feed(*args)
+ def to_rss(*args)
end
end
class Categories < CategoriesBase
- def to_feed(*args)
+ def to_rss(*args)
end
class Category < CategoryBase
end
end
-
- class Links < LinksBase
- def to_feed(rss, channel)
- return if @links.empty?
- @links.first.to_feed(rss, channel)
- end
-
- class Link < LinkBase
- def to_feed(rss, channel)
- if have_required_values?
- channel.link = href
- else
- raise NotSetError.new("maker.channel.link",
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(href)
- end
- end
- end
-
- class Authors < AuthorsBase
- def to_feed(rss, channel)
- end
-
- class Author < AuthorBase
- def to_feed(rss, channel)
- end
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(rss, channel)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(rss, channel)
- end
- end
-
- class Copyright < CopyrightBase
- def to_feed(rss, channel)
- end
- end
-
- class Description < DescriptionBase
- def to_feed(rss, channel)
- channel.description = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Title < TitleBase
- def to_feed(rss, channel)
- channel.title = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
end
class Image < ImageBase
- def to_feed(rss)
+ def to_rss(rss)
if @url
image = RDF::Image.new(@url)
set = setup_values(image)
if set
rss.image = image
- set_parent(image, rss)
- setup_other_elements(rss, image)
+ setup_other_elements(rss)
end
end
end
def have_required_values?
- super and @maker.channel.have_required_values?
+ @url and @title and link and @maker.channel.have_required_values?
end
private
def variables
super + ["link"]
end
-
- def required_variable_names
- %w(url title link)
- end
end
class Items < ItemsBase
- def to_feed(rss)
+ def to_rss(rss)
if rss.channel
normalize.each do |item|
- item.to_feed(rss)
+ item.to_rss(rss)
end
- setup_other_elements(rss, rss.items)
+ setup_other_elements(rss)
end
end
class Item < ItemBase
- def to_feed(rss)
- set_default_values do
- item = RDF::Item.new(link)
+ def to_rss(rss)
+ if @link
+ item = RDF::Item.new(@link)
set = setup_values(item)
if set
item.dc_dates.clear
rss.items << item
- set_parent(item, rss)
- setup_other_elements(rss, item)
- elsif !have_required_values?
- raise NotSetError.new("maker.item", not_set_required_variables)
+ setup_other_elements(rss)
end
end
end
- private
- def required_variable_names
- %w(link)
- end
-
- def variables
- super + %w(link)
- end
-
- def not_set_required_variables
- set_default_values do
- vars = super
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
+ def have_required_values?
+ @title and @link
end
class Guid < GuidBase
- def to_feed(*args)
+ def to_rss(*args)
end
end
-
+
class Enclosure < EnclosureBase
- def to_feed(*args)
+ def to_rss(*args)
end
end
-
+
class Source < SourceBase
- def to_feed(*args)
- end
-
- class Authors < AuthorsBase
- def to_feed(*args)
- end
-
- class Author < AuthorBase
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(*args)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(*args)
- end
- end
-
- class Icon < IconBase
- def to_feed(*args)
- end
- end
-
- class Links < LinksBase
- def to_feed(*args)
- end
-
- class Link < LinkBase
- end
- end
-
- class Logo < LogoBase
- def to_feed(*args)
- end
- end
-
- class Rights < RightsBase
- def to_feed(*args)
- end
- end
-
- class Subtitle < SubtitleBase
- def to_feed(*args)
- end
- end
-
- class Title < TitleBase
- def to_feed(*args)
- end
+ def to_rss(*args)
end
end
-
+
class Categories < CategoriesBase
- def to_feed(*args)
+ def to_rss(*args)
end
class Category < CategoryBase
end
end
-
- class Authors < AuthorsBase
- def to_feed(*args)
- end
-
- class Author < AuthorBase
- end
- end
-
- class Links < LinksBase
- def to_feed(*args)
- end
-
- class Link < LinkBase
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(rss, item)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Rights < RightsBase
- def to_feed(rss, item)
- end
- end
-
- class Description < DescriptionBase
- def to_feed(rss, item)
- item.description = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Content < ContentBase
- def to_feed(rss, item)
- end
- end
-
- class Title < TitleBase
- def to_feed(rss, item)
- item.title = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
end
end
class Textinput < TextinputBase
- def to_feed(rss)
+ def to_rss(rss)
if @link
textinput = RDF::Textinput.new(@link)
set = setup_values(textinput)
if set
rss.textinput = textinput
- set_parent(textinput, rss)
- setup_other_elements(rss, textinput)
+ setup_other_elements(rss)
end
end
end
def have_required_values?
- super and @maker.channel.have_required_values?
- end
-
- private
- def required_variable_names
- %w(title description name link)
+ @title and @description and @name and @link and
+ @maker.channel.have_required_values?
end
end
end
- add_maker("1.0", "1.0", RSS10)
- add_maker("rss1.0", "1.0", RSS10)
+ add_maker(filename_to_version(__FILE__), RSS10)
end
end
diff --git a/lib/rss/maker/2.0.rb b/lib/rss/maker/2.0.rb
index 67d68126ac..a958661614 100644
--- a/lib/rss/maker/2.0.rb
+++ b/lib/rss/maker/2.0.rb
@@ -7,15 +7,18 @@ module RSS
class RSS20 < RSS09
- def initialize(feed_version="2.0")
+ def initialize(rss_version="2.0")
super
end
class Channel < RSS09::Channel
- private
+ def have_required_values?
+ @title and @link and @description
+ end
+
def required_variable_names
- %w(link)
+ %w(title link description)
end
class SkipDays < RSS09::Channel::SkipDays
@@ -29,195 +32,137 @@ module RSS
end
class Cloud < RSS09::Channel::Cloud
- def to_feed(rss, channel)
+ def to_rss(rss, channel)
cloud = Rss::Channel::Cloud.new
set = setup_values(cloud)
if set
channel.cloud = cloud
- set_parent(cloud, channel)
- setup_other_elements(rss, cloud)
+ setup_other_elements(rss)
end
end
- private
- def required_variable_names
- %w(domain port path registerProcedure protocol)
+ def have_required_values?
+ @domain and @port and @path and
+ @registerProcedure and @protocol
end
end
class Categories < RSS09::Channel::Categories
- def to_feed(rss, channel)
+ def to_rss(rss, channel)
@categories.each do |category|
- category.to_feed(rss, channel)
+ category.to_rss(rss, channel)
end
end
class Category < RSS09::Channel::Categories::Category
- def to_feed(rss, channel)
+ def to_rss(rss, channel)
category = Rss::Channel::Category.new
set = setup_values(category)
if set
channel.categories << category
- set_parent(category, channel)
- setup_other_elements(rss, category)
+ setup_other_elements(rss)
end
end
-
- private
- def required_variable_names
- %w(content)
+
+ def have_required_values?
+ @content
end
end
end
-
- class Generator < GeneratorBase
- def to_feed(rss, channel)
- channel.generator = content
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
+
end
class Image < RSS09::Image
- private
- def required_element?
- false
- end
end
class Items < RSS09::Items
+
class Item < RSS09::Items::Item
- private
- def required_variable_names
- []
- end
- def not_set_required_variables
- vars = super
- if !title {|t| t.have_required_values?} and
- !description {|d| d.have_required_values?}
- vars << "title or description"
- end
- vars
+ def have_required_values?
+ @title or @description
end
+ private
def variables
super + ["pubDate"]
end
class Guid < RSS09::Items::Item::Guid
- def to_feed(rss, item)
+ def to_rss(rss, item)
guid = Rss::Channel::Item::Guid.new
set = setup_values(guid)
if set
item.guid = guid
- set_parent(guid, item)
- setup_other_elements(rss, guid)
+ setup_other_elements(rss)
end
end
-
- private
- def required_variable_names
- %w(content)
+
+ def have_required_values?
+ @content
end
end
class Enclosure < RSS09::Items::Item::Enclosure
- def to_feed(rss, item)
+ def to_rss(rss, item)
enclosure = Rss::Channel::Item::Enclosure.new
set = setup_values(enclosure)
if set
item.enclosure = enclosure
- set_parent(enclosure, item)
- setup_other_elements(rss, enclosure)
+ setup_other_elements(rss)
end
end
-
- private
- def required_variable_names
- %w(url length type)
+
+ def have_required_values?
+ @url and @length and @type
end
end
class Source < RSS09::Items::Item::Source
- def to_feed(rss, item)
+ def to_rss(rss, item)
source = Rss::Channel::Item::Source.new
set = setup_values(source)
if set
item.source = source
- set_parent(source, item)
- setup_other_elements(rss, source)
+ setup_other_elements(rss)
end
end
-
- private
- def required_variable_names
- %w(url content)
- end
-
- class Links < RSS09::Items::Item::Source::Links
- def to_feed(rss, source)
- return if @links.empty?
- @links.first.to_feed(rss, source)
- end
-
- class Link < RSS09::Items::Item::Source::Links::Link
- def to_feed(rss, source)
- source.url = href
- end
- end
+
+ def have_required_values?
+ @url and @content
end
end
class Categories < RSS09::Items::Item::Categories
- def to_feed(rss, item)
+ def to_rss(rss, item)
@categories.each do |category|
- category.to_feed(rss, item)
+ category.to_rss(rss, item)
end
end
class Category < RSS09::Items::Item::Categories::Category
- def to_feed(rss, item)
+ def to_rss(rss, item)
category = Rss::Channel::Item::Category.new
set = setup_values(category)
if set
item.categories << category
- set_parent(category, item)
setup_other_elements(rss)
end
end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Authors < RSS09::Items::Item::Authors
- def to_feed(rss, item)
- return if @authors.empty?
- @authors.first.to_feed(rss, item)
- end
-
- class Author < RSS09::Items::Item::Authors::Author
- def to_feed(rss, item)
- item.author = name
+
+ def have_required_values?
+ @content
end
end
end
end
+
end
class Textinput < RSS09::Textinput
end
end
- add_maker("2.0", "2.0", RSS20)
- add_maker("rss2.0", "2.0", RSS20)
+ add_maker(filename_to_version(__FILE__), RSS20)
end
end
diff --git a/lib/rss/maker/atom.rb b/lib/rss/maker/atom.rb
deleted file mode 100644
index fd3198cd9e..0000000000
--- a/lib/rss/maker/atom.rb
+++ /dev/null
@@ -1,172 +0,0 @@
-require "rss/atom"
-
-require "rss/maker/base"
-
-module RSS
- module Maker
- module AtomPersons
- module_function
- def def_atom_persons(klass, name, maker_name, plural=nil)
- plural ||= "#{name}s"
- klass_name = Utils.to_class_name(name)
- plural_klass_name = Utils.to_class_name(plural)
-
- klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class #{plural_klass_name} < #{plural_klass_name}Base
- class #{klass_name} < #{klass_name}Base
- def to_feed(feed, current)
- #{name} = feed.class::#{klass_name}.new
- set = setup_values(#{name})
- unless set
- raise NotSetError.new(#{maker_name.dump},
- not_set_required_variables)
- end
- current.#{plural} << #{name}
- set_parent(#{name}, current)
- setup_other_elements(#{name})
- end
-
- private
- def required_variable_names
- %w(name)
- end
- end
- end
-EOC
- end
- end
-
- module AtomTextConstruct
- class << self
- def def_atom_text_construct(klass, name, maker_name, klass_name=nil,
- atom_klass_name=nil)
- klass_name ||= Utils.to_class_name(name)
- atom_klass_name ||= Utils.to_class_name(name)
-
- klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class #{klass_name} < #{klass_name}Base
- include #{self.name}
- def to_feed(feed, current)
- #{name} = current.class::#{atom_klass_name}.new
- if setup_values(#{name})
- current.#{name} = #{name}
- set_parent(#{name}, current)
- setup_other_elements(feed)
- elsif variable_is_set?
- raise NotSetError.new(#{maker_name.dump},
- not_set_required_variables)
- end
- end
- end
- EOC
- end
- end
-
- private
- def required_variable_names
- if type == "xhtml"
- %w(xml_content)
- else
- %w(content)
- end
- end
-
- def variables
- if type == "xhtml"
- super + %w(xhtml)
- else
- super
- end
- end
- end
-
- module AtomCategory
- def to_feed(feed, current)
- category = feed.class::Category.new
- set = setup_values(category)
- if set
- current.categories << category
- set_parent(category, current)
- setup_other_elements(feed)
- else
- raise NotSetError.new(self.class.not_set_name,
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(term)
- end
-
- def variables
- super + ["term", "scheme"]
- end
- end
-
- module AtomLink
- def to_feed(feed, current)
- link = feed.class::Link.new
- set = setup_values(link)
- if set
- current.links << link
- set_parent(link, current)
- setup_other_elements(feed)
- else
- raise NotSetError.new(self.class.not_set_name,
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(href)
- end
- end
-
- module AtomGenerator
- def to_feed(feed, current)
- generator = current.class::Generator.new
- if setup_values(generator)
- current.generator = generator
- set_parent(generator, current)
- setup_other_elements(feed)
- elsif variable_is_set?
- raise NotSetError.new(self.class.not_set_name,
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- module AtomLogo
- def to_feed(feed, current)
- logo = current.class::Logo.new
- class << logo
- alias_method(:uri=, :content=)
- end
- set = setup_values(logo)
- class << logo
- remove_method(:uri=)
- end
- if set
- current.logo = logo
- set_parent(logo, current)
- setup_other_elements(feed)
- elsif variable_is_set?
- raise NotSetError.new(self.class.not_set_name,
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(uri)
- end
- end
- end
-end
diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb
index 56bf04657e..2327dd98e4 100644
--- a/lib/rss/maker/base.rb
+++ b/lib/rss/maker/base.rb
@@ -4,184 +4,70 @@ require 'rss/rss'
module RSS
module Maker
- class Base
- extend Utils::InheritedReader
- OTHER_ELEMENTS = []
- NEED_INITIALIZE_VARIABLES = []
+ module Base
- class << self
- def other_elements
- inherited_array_reader("OTHER_ELEMENTS")
- end
- def need_initialize_variables
- inherited_array_reader("NEED_INITIALIZE_VARIABLES")
- end
+ def self.append_features(klass)
+ super
- def inherited_base
- ::RSS::Maker::Base
- end
+ klass.module_eval(<<-EOC, __FILE__, __LINE__)
+
+ OTHER_ELEMENTS = []
+ NEED_INITIALIZE_VARIABLES = []
- def inherited(subclass)
+ def self.inherited(subclass)
subclass.const_set("OTHER_ELEMENTS", [])
subclass.const_set("NEED_INITIALIZE_VARIABLES", [])
- end
-
- def add_other_element(variable_name)
- self::OTHER_ELEMENTS << variable_name
- end
-
- def add_need_initialize_variable(variable_name, init_value="nil")
- self::NEED_INITIALIZE_VARIABLES << [variable_name, init_value]
- end
-
- def def_array_element(name, plural=nil, klass_name=nil)
- include Enumerable
- extend Forwardable
-
- plural ||= "#{name}s"
- klass_name ||= Utils.to_class_name(name)
- def_delegators("@#{plural}", :<<, :[], :[]=, :first, :last)
- def_delegators("@#{plural}", :push, :pop, :shift, :unshift)
- def_delegators("@#{plural}", :each, :size, :empty?, :clear)
-
- add_need_initialize_variable(plural, "[]")
-
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def new_#{name}
- #{name} = self.class::#{klass_name}.new(@maker)
- @#{plural} << #{name}
- if block_given?
- yield #{name}
- else
- #{name}
- end
- end
- alias new_child new_#{name}
- def to_feed(*args)
- @#{plural}.each do |#{name}|
- #{name}.to_feed(*args)
- end
+ subclass.module_eval(<<-EOEOC, __FILE__, __LINE__)
+ def self.other_elements
+ OTHER_ELEMENTS + super
end
- def replace(elements)
- @#{plural}.replace(elements.to_a)
+ def self.need_initialize_variables
+ NEED_INITIALIZE_VARIABLES + super
end
- EOC
+ EOEOC
end
- def def_classed_element_without_accessor(name, class_name=nil)
- class_name ||= Utils.to_class_name(name)
- add_other_element(name)
- add_need_initialize_variable(name, "make_#{name}")
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- private
- def setup_#{name}(feed, current)
- @#{name}.to_feed(feed, current)
- end
-
- def make_#{name}
- self.class::#{class_name}.new(@maker)
- end
- EOC
- end
-
- def def_classed_element(name, class_name=nil, attribute_name=nil)
- def_classed_element_without_accessor(name, class_name)
- if attribute_name
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}
- if block_given?
- yield(@#{name})
- else
- @#{name}.#{attribute_name}
- end
- end
-
- def #{name}=(new_value)
- @#{name}.#{attribute_name} = new_value
- end
- EOC
- else
- attr_reader name
- end
+ def self.add_other_element(variable_name)
+ OTHER_ELEMENTS << variable_name
end
- def def_classed_elements(name, attribute, plural_class_name=nil,
- plural_name=nil, new_name=nil)
- plural_name ||= "#{name}s"
- new_name ||= name
- def_classed_element(plural_name, plural_class_name)
- local_variable_name = "_#{name}"
- new_value_variable_name = "new_value"
- additional_setup_code = nil
- if block_given?
- additional_setup_code = yield(local_variable_name,
- new_value_variable_name)
- end
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}
- #{local_variable_name} = #{plural_name}.first
- #{local_variable_name} ? #{local_variable_name}.#{attribute} : nil
- end
-
- def #{name}=(#{new_value_variable_name})
- #{local_variable_name} =
- #{plural_name}.first || #{plural_name}.new_#{new_name}
- #{additional_setup_code}
- #{local_variable_name}.#{attribute} = #{new_value_variable_name}
- end
- EOC
+ def self.other_elements
+ OTHER_ELEMENTS
end
- def def_other_element(name)
- attr_accessor name
- def_other_element_without_accessor(name)
+ def self.add_need_initialize_variable(variable_name, init_value="nil")
+ NEED_INITIALIZE_VARIABLES << [variable_name, init_value]
end
- def def_other_element_without_accessor(name)
- add_need_initialize_variable(name)
- add_other_element(name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def setup_#{name}(feed, current)
- if !@#{name}.nil? and current.respond_to?(:#{name}=)
- current.#{name} = @#{name}
- end
- end
- EOC
+ def self.need_initialize_variables
+ NEED_INITIALIZE_VARIABLES
end
- def def_csv_element(name, type=nil)
- def_other_element_without_accessor(name)
- attr_reader(name)
- converter = ""
- if type == :integer
- converter = "{|v| Integer(v)}"
- end
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(value)
- @#{name} = Utils::CSV.parse(value)#{converter}
- end
- EOC
+ def self.def_array_element(name)
+ include Enumerable
+ extend Forwardable
+
+ def_delegators("@\#{name}", :<<, :[], :[]=, :first, :last)
+ def_delegators("@\#{name}", :push, :pop, :shift, :unshift)
+ def_delegators("@\#{name}", :each, :size)
+
+ add_need_initialize_variable(name, "[]")
end
+ EOC
end
-
- attr_reader :maker
+
def initialize(maker)
@maker = maker
- @default_values_are_set = false
initialize_variables
end
def have_required_values?
- not_set_required_variables.empty?
- end
-
- def variable_is_set?
- variables.any? {|var| not __send__(var).nil?}
+ true
end
-
+
private
def initialize_variables
self.class.need_initialize_variables.each do |variable_name, init_value|
@@ -189,32 +75,16 @@ module RSS
end
end
- def setup_other_elements(feed, current=nil)
- current ||= current_element(feed)
+ def setup_other_elements(rss)
self.class.other_elements.each do |element|
- __send__("setup_#{element}", feed, current)
- end
- end
-
- def current_element(feed)
- feed
- end
-
- def set_default_values(&block)
- return yield if @default_values_are_set
-
- begin
- @default_values_are_set = true
- _set_default_values(&block)
- ensure
- @default_values_are_set = false
+ __send__("setup_#{element}", rss, current_element(rss))
end
end
- def _set_default_values(&block)
- yield
+ def current_element(rss)
+ rss
end
-
+
def setup_values(target)
set = false
if have_required_values?
@@ -232,10 +102,6 @@ module RSS
set
end
- def set_parent(target, parent)
- target.parent = parent if target.class.need_parent?
- end
-
def variables
self.class.need_initialize_variables.find_all do |name, init|
"nil" == init
@@ -244,6 +110,10 @@ module RSS
end
end
+ def variable_is_set?
+ variables.find {|var| !__send__(var).nil?}
+ end
+
def not_set_required_variables
required_variable_names.find_all do |var|
__send__(var).nil?
@@ -256,109 +126,15 @@ module RSS
end
true
end
+
end
- module AtomPersonConstructBase
- def self.append_features(klass)
- super
-
- klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
- %w(name uri email).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- EOC
- end
- end
-
- module AtomTextConstructBase
- module EnsureXMLContent
- class << self
- def included(base)
- super
- base.class_eval do
- %w(type content xml_content).each do |element|
- attr_reader element
- attr_writer element if element != "xml_content"
- add_need_initialize_variable(element)
- end
-
- alias_method(:xhtml, :xml_content)
- end
- end
- end
-
- def ensure_xml_content(content)
- xhtml_uri = ::RSS::Atom::XHTML_URI
- unless content.is_a?(RSS::XML::Element) and
- ["div", xhtml_uri] == [content.name, content.uri]
- children = content
- children = [children] unless content.is_a?(Array)
- children = set_xhtml_uri_as_default_uri(children)
- content = RSS::XML::Element.new("div", nil, xhtml_uri,
- {"xmlns" => xhtml_uri},
- children)
- end
- content
- end
-
- def xml_content=(content)
- @xml_content = ensure_xml_content(content)
- end
-
- def xhtml=(content)
- self.xml_content = content
- end
-
- private
- def set_xhtml_uri_as_default_uri(children)
- children.collect do |child|
- if child.is_a?(RSS::XML::Element) and
- child.prefix.nil? and child.uri.nil?
- RSS::XML::Element.new(child.name, nil, ::RSS::Atom::XHTML_URI,
- child.attributes.dup,
- set_xhtml_uri_as_default_uri(child.children))
- else
- child
- end
- end
- end
- end
-
- def self.append_features(klass)
- super
-
- klass.class_eval do
- include EnsureXMLContent
- end
- end
- end
-
- module SetupDefaultDate
- private
- def _set_default_values(&block)
- keep = {
- :date => date,
- :dc_dates => dc_dates.to_a.dup,
- }
- _date = date
- if _date and !dc_dates.any? {|dc_date| dc_date.value == _date}
- dc_date = self.class::DublinCoreDates::DublinCoreDate.new(self)
- dc_date.value = _date.dup
- dc_dates.unshift(dc_date)
- end
- self.date ||= self.dc_date
- super(&block)
- ensure
- date = keep[:date]
- dc_dates.replace(keep[:dc_dates])
- end
- end
+ class RSSBase
+ include Base
- class RSSBase < Base
class << self
- def make(version, &block)
- new(version).make(&block)
+ def make(&block)
+ new.make(&block)
end
end
@@ -367,25 +143,22 @@ module RSS
add_need_initialize_variable(element, "make_#{element}")
module_eval(<<-EOC, __FILE__, __LINE__)
private
- def setup_#{element}(feed)
- @#{element}.to_feed(feed)
+ def setup_#{element}(rss)
+ @#{element}.to_rss(rss)
end
def make_#{element}
self.class::#{Utils.to_class_name(element)}.new(self)
end
- EOC
+EOC
end
- attr_reader :feed_version
- alias_method(:rss_version, :feed_version)
+ attr_reader :rss_version
attr_accessor :version, :encoding, :standalone
-
- def initialize(feed_version)
+
+ def initialize(rss_version)
super(self)
- @feed_type = nil
- @feed_subtype = nil
- @feed_version = feed_version
+ @rss_version = rss_version
@version = "1.0"
@encoding = "UTF-8"
@standalone = nil
@@ -394,19 +167,19 @@ module RSS
def make
if block_given?
yield(self)
- to_feed
+ to_rss
else
nil
end
end
- def to_feed
- feed = make_feed
- setup_xml_stylesheets(feed)
- setup_elements(feed)
- setup_other_elements(feed)
- if feed.valid?
- feed
+ def to_rss
+ rss = make_rss
+ setup_xml_stylesheets(rss)
+ setup_elements(rss)
+ setup_other_elements(rss)
+ if rss.channel
+ rss
else
nil
end
@@ -417,27 +190,51 @@ module RSS
def make_xml_stylesheets
XMLStyleSheets.new(self)
end
+
end
- class XMLStyleSheets < Base
- def_array_element("xml_stylesheet", nil, "XMLStyleSheet")
+ class XMLStyleSheets
+ include Base
+
+ def_array_element("xml_stylesheets")
+
+ def to_rss(rss)
+ @xml_stylesheets.each do |xss|
+ xss.to_rss(rss)
+ end
+ end
+
+ def new_xml_stylesheet
+ xss = XMLStyleSheet.new(@maker)
+ @xml_stylesheets << xss
+ if block_given?
+ yield xss
+ else
+ xss
+ end
+ end
- class XMLStyleSheet < Base
+ class XMLStyleSheet
+ include Base
::RSS::XMLStyleSheet::ATTRIBUTES.each do |attribute|
attr_accessor attribute
add_need_initialize_variable(attribute)
end
- def to_feed(feed)
+ def to_rss(rss)
xss = ::RSS::XMLStyleSheet.new
guess_type_if_need(xss)
set = setup_values(xss)
if set
- feed.xml_stylesheets << xss
+ rss.xml_stylesheets << xss
end
end
+ def have_required_values?
+ @href and @type
+ end
+
private
def guess_type_if_need(xss)
if @type.nil?
@@ -445,183 +242,172 @@ module RSS
@type = xss.type
end
end
-
- def required_variable_names
- %w(href type)
- end
end
end
- class ChannelBase < Base
- include SetupDefaultDate
-
- %w(cloud categories skipDays skipHours).each do |name|
- def_classed_element(name)
- end
+ class ChannelBase
+ include Base
- %w(generator copyright description title).each do |name|
- def_classed_element(name, nil, "content")
- end
+ %w(cloud categories skipDays skipHours).each do |element|
+ attr_reader element
+ add_other_element(element)
+ add_need_initialize_variable(element, "make_#{element}")
+ module_eval(<<-EOC, __FILE__, __LINE__)
+ private
+ def setup_#{element}(rss, current)
+ @#{element}.to_rss(rss, current)
+ end
- [
- ["link", "href", Proc.new {|target,| "#{target}.href = 'self'"}],
- ["author", "name"],
- ["contributor", "name"],
- ].each do |name, attribute, additional_setup_maker|
- def_classed_elements(name, attribute, &additional_setup_maker)
+ def make_#{element}
+ self.class::#{Utils.to_class_name(element)}.new(@maker)
+ end
+EOC
end
- %w(id about language
+ %w(about title link description language copyright
managingEditor webMaster rating docs date
- lastBuildDate ttl).each do |element|
+ lastBuildDate generator ttl).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
- def pubDate
- date
- end
-
- def pubDate=(date)
- self.date = date
- end
-
- def updated
- date
- end
-
- def updated=(date)
- self.date = date
- end
-
- alias_method(:rights, :copyright)
- alias_method(:rights=, :copyright=)
-
- alias_method(:subtitle, :description)
- alias_method(:subtitle=, :description=)
+ alias_method(:pubDate, :date)
+ alias_method(:pubDate=, :date=)
- def icon
- image_favicon.about
+ def current_element(rss)
+ rss.channel
end
- def icon=(url)
- image_favicon.about = url
- end
+ class SkipDaysBase
+ include Base
- def logo
- maker.image.url
- end
+ def_array_element("days")
- def logo=(url)
- maker.image.url = url
- end
-
- class SkipDaysBase < Base
- def_array_element("day")
+ def new_day
+ day = self.class::Day.new(@maker)
+ @days << day
+ if block_given?
+ yield day
+ else
+ day
+ end
+ end
+
+ def current_element(rss)
+ rss.channel.skipDays
+ end
- class DayBase < Base
+ class DayBase
+ include Base
+
%w(content).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
+
+ def current_element(rss)
+ rss.channel.skipDays.last
+ end
+
end
end
- class SkipHoursBase < Base
- def_array_element("hour")
+ class SkipHoursBase
+ include Base
+
+ def_array_element("hours")
+
+ def new_hour
+ hour = self.class::Hour.new(@maker)
+ @hours << hour
+ if block_given?
+ yield hour
+ else
+ hour
+ end
+ end
+
+ def current_element(rss)
+ rss.channel.skipHours
+ end
- class HourBase < Base
+ class HourBase
+ include Base
+
%w(content).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
+
+ def current_element(rss)
+ rss.channel.skipHours.last
+ end
+
end
end
- class CloudBase < Base
+ class CloudBase
+ include Base
+
%w(domain port path registerProcedure protocol).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
+
+ def current_element(rss)
+ rss.channel.cloud
+ end
+
end
- class CategoriesBase < Base
- def_array_element("category", "categories")
+ class CategoriesBase
+ include Base
+
+ def_array_element("categories")
- class CategoryBase < Base
- %w(domain content label).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
+ def new_category
+ category = self.class::Category.new(@maker)
+ @categories << category
+ if block_given?
+ yield category
+ else
+ category
end
-
- alias_method(:term, :domain)
- alias_method(:term=, :domain=)
- alias_method(:scheme, :content)
- alias_method(:scheme=, :content=)
end
- end
- class LinksBase < Base
- def_array_element("link")
+ class CategoryBase
+ include Base
- class LinkBase < Base
- %w(href rel type hreflang title length).each do |element|
+ %w(domain content).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
end
end
-
- class AuthorsBase < Base
- def_array_element("author")
-
- class AuthorBase < Base
- include AtomPersonConstructBase
- end
- end
-
- class ContributorsBase < Base
- def_array_element("contributor")
-
- class ContributorBase < Base
- include AtomPersonConstructBase
- end
- end
-
- class GeneratorBase < Base
- %w(uri version content).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- class CopyrightBase < Base
- include AtomTextConstructBase
- end
-
- class DescriptionBase < Base
- include AtomTextConstructBase
- end
-
- class TitleBase < Base
- include AtomTextConstructBase
- end
end
- class ImageBase < Base
+ class ImageBase
+ include Base
+
%w(title url width height description).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
-
+
def link
@maker.channel.link
end
+
+ def current_element(rss)
+ rss.image
+ end
end
- class ItemsBase < Base
- def_array_element("item")
+ class ItemsBase
+ include Base
+ def_array_element("items")
+
attr_accessor :do_sort, :max_size
def initialize(maker)
@@ -637,7 +423,21 @@ module RSS
sort_if_need[0..@max_size]
end
end
+
+ def current_element(rss)
+ rss.items
+ end
+ def new_item
+ item = self.class::Item.new(@maker)
+ @items << item
+ if block_given?
+ yield item
+ else
+ item
+ end
+ end
+
private
def sort_if_need
if @do_sort.respond_to?(:call)
@@ -653,216 +453,94 @@ module RSS
end
end
- class ItemBase < Base
- include SetupDefaultDate
-
- %w(guid enclosure source categories content).each do |name|
- def_classed_element(name)
- end
+ class ItemBase
+ include Base
+
+ %w(guid enclosure source categories).each do |element|
+ attr_reader element
+ add_other_element(element)
+ add_need_initialize_variable(element, "make_#{element}")
+ module_eval(<<-EOC, __FILE__, __LINE__)
+ private
+ def setup_#{element}(rss, current)
+ @#{element}.to_rss(rss, current)
+ end
- %w(rights description title).each do |name|
- def_classed_element(name, nil, "content")
+ def make_#{element}
+ self.class::#{Utils.to_class_name(element)}.new(@maker)
+ end
+EOC
end
-
- [
- ["author", "name"],
- ["link", "href", Proc.new {|target,| "#{target}.href = 'alternate'"}],
- ["contributor", "name"],
- ].each do |name, attribute|
- def_classed_elements(name, attribute)
- end
-
- %w(date comments id published).each do |element|
+
+ %w(title link description date author comments).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
- def pubDate
- date
- end
-
- def pubDate=(date)
- self.date = date
- end
-
- def updated
- date
- end
-
- def updated=(date)
- self.date = date
- end
-
- alias_method(:summary, :description)
- alias_method(:summary=, :description=)
+ alias_method(:pubDate, :date)
+ alias_method(:pubDate=, :date=)
def <=>(other)
- _date = date || dc_date
- _other_date = other.date || other.dc_date
- if _date and _other_date
- _date <=> _other_date
- elsif _date
+ if date and other.date
+ date <=> other.date
+ elsif date
1
- elsif _other_date
+ elsif other.date
-1
else
0
end
end
+
+ def current_element(rss)
+ rss.items.last
+ end
+
+ class GuidBase
+ include Base
- class GuidBase < Base
%w(isPermaLink content).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
end
+
+ class EnclosureBase
+ include Base
- class EnclosureBase < Base
%w(url length type).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
end
+
+ class SourceBase
+ include Base
- class SourceBase < Base
- %w(authors categories contributors generator icon
- logo rights subtitle title).each do |name|
- def_classed_element(name)
- end
-
- [
- ["link", "href"],
- ].each do |name, attribute|
- def_classed_elements(name, attribute)
- end
-
- %w(id content date).each do |element|
+ %w(url content).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
-
- alias_method(:url, :link)
- alias_method(:url=, :link=)
-
- def updated
- date
- end
-
- def updated=(date)
- self.date = date
- end
-
- private
- AuthorsBase = ChannelBase::AuthorsBase
- CategoriesBase = ChannelBase::CategoriesBase
- ContributorsBase = ChannelBase::ContributorsBase
- GeneratorBase = ChannelBase::GeneratorBase
-
- class IconBase < Base
- %w(url).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- LinksBase = ChannelBase::LinksBase
-
- class LogoBase < Base
- %w(uri).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- class RightsBase < Base
- include AtomTextConstructBase
- end
-
- class SubtitleBase < Base
- include AtomTextConstructBase
- end
-
- class TitleBase < Base
- include AtomTextConstructBase
- end
end
-
+
CategoriesBase = ChannelBase::CategoriesBase
- AuthorsBase = ChannelBase::AuthorsBase
- LinksBase = ChannelBase::LinksBase
- ContributorsBase = ChannelBase::ContributorsBase
-
- class RightsBase < Base
- include AtomTextConstructBase
- end
-
- class DescriptionBase < Base
- include AtomTextConstructBase
- end
-
- class ContentBase < Base
- include AtomTextConstructBase::EnsureXMLContent
-
- %w(src).each do |element|
- attr_accessor(element)
- add_need_initialize_variable(element)
- end
-
- def xml_content=(content)
- content = ensure_xml_content(content) if inline_xhtml?
- @xml_content = content
- end
-
- alias_method(:xml, :xml_content)
- alias_method(:xml=, :xml_content=)
-
- def inline_text?
- [nil, "text", "html"].include?(@type)
- end
-
- def inline_html?
- @type == "html"
- end
-
- def inline_xhtml?
- @type == "xhtml"
- end
-
- def inline_other?
- !out_of_line? and ![nil, "text", "html", "xhtml"].include?(@type)
- end
-
- def inline_other_text?
- return false if @type.nil? or out_of_line?
- /\Atext\//i.match(@type) ? true : false
- end
-
- def inline_other_xml?
- return false if @type.nil? or out_of_line?
- /[\+\/]xml\z/i.match(@type) ? true : false
- end
-
- def inline_other_base64?
- return false if @type.nil? or out_of_line?
- @type.include?("/") and !inline_other_text? and !inline_other_xml?
- end
-
- def out_of_line?
- not @src.nil? and @content.nil?
- end
- end
-
- class TitleBase < Base
- include AtomTextConstructBase
- end
+
end
end
- class TextinputBase < Base
+ class TextinputBase
+ include Base
+
%w(title description name link).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
+
+ def current_element(rss)
+ rss.textinput
+ end
+
end
+
end
end
diff --git a/lib/rss/maker/content.rb b/lib/rss/maker/content.rb
index 46c4911f73..18590d0cf8 100644
--- a/lib/rss/maker/content.rb
+++ b/lib/rss/maker/content.rb
@@ -1,6 +1,5 @@
require 'rss/content'
require 'rss/maker/1.0'
-require 'rss/maker/2.0'
module RSS
module Maker
@@ -8,8 +7,17 @@ module RSS
def self.append_features(klass)
super
- ::RSS::ContentModel::ELEMENTS.each do |name|
- klass.def_other_element(name)
+ ::RSS::ContentModel::ELEMENTS.each do |element|
+ klass.add_need_initialize_variable(element)
+ klass.add_other_element(element)
+ klass.module_eval(<<-EOC, __FILE__, __LINE__+1)
+ attr_accessor :#{element}
+ def setup_#{element}(rss, current)
+ if #{element} and current.respond_to?(:#{element}=)
+ current.#{element} = @#{element} if @#{element}
+ end
+ end
+ EOC
end
end
end
diff --git a/lib/rss/maker/dublincore.rb b/lib/rss/maker/dublincore.rb
index ff4813fe19..0cf1255e82 100644
--- a/lib/rss/maker/dublincore.rb
+++ b/lib/rss/maker/dublincore.rb
@@ -15,40 +15,60 @@ module RSS
plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
full_plural_klass_name = "self.class::#{plural_klass_name}"
full_klass_name = "#{full_plural_klass_name}::#{klass_name}"
- klass.def_classed_elements(full_name, "value", plural_klass_name,
- full_plural_name, name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def new_#{full_name}(value=nil)
- _#{full_name} = #{full_plural_name}.new_#{name}
- _#{full_name}.value = value
- if block_given?
- yield _#{full_name}
- else
- _#{full_name}
- end
+ klass.add_need_initialize_variable(full_plural_name,
+ "make_#{full_plural_name}")
+ klass.add_other_element(full_plural_name)
+ klass.module_eval(<<-EOC, __FILE__, __LINE__+1)
+ attr_accessor :#{full_plural_name}
+ def make_#{full_plural_name}
+ #{full_plural_klass_name}.new(@maker)
+ end
+
+ def setup_#{full_plural_name}(rss, current)
+ @#{full_plural_name}.to_rss(rss, current)
end
- EOC
- end
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- # For backward compatibility
- alias #{DC_PREFIX}_rightses #{DC_PREFIX}_rights_list
- EOC
+ def #{full_name}
+ @#{full_plural_name}[0] and @#{full_plural_name}[0].value
+ end
+
+ def #{full_name}=(new_value)
+ @#{full_plural_name}[0] = #{full_klass_name}.new(self)
+ @#{full_plural_name}[0].value = new_value
+ end
+EOC
+ end
end
::RSS::DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
plural_name ||= "#{name}s"
- full_name ||= "#{DC_PREFIX}_#{name}"
- full_plural_name ||= "#{DC_PREFIX}_#{plural_name}"
klass_name = Utils.to_class_name(name)
- full_klass_name = "DublinCore#{klass_name}"
plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class #{plural_klass_name}Base < Base
- def_array_element(#{name.dump}, #{full_plural_name.dump},
- #{full_klass_name.dump})
+ module_eval(<<-EOC, __FILE__, __LINE__)
+ class #{plural_klass_name}Base
+ include Base
+
+ def_array_element(#{plural_name.dump})
+
+ def new_#{name}
+ #{name} = self.class::#{klass_name}.new(self)
+ @#{plural_name} << #{name}
+ if block_given?
+ yield #{name}
+ else
+ #{name}
+ end
+ end
+
+ def to_rss(rss, current)
+ @#{plural_name}.each do |#{name}|
+ #{name}.to_rss(rss, current)
+ end
+ end
+
+ class #{klass_name}Base
+ include Base
- class #{full_klass_name}Base < Base
attr_accessor :value
add_need_initialize_variable("value")
alias_method(:content, :value)
@@ -57,15 +77,7 @@ module RSS
def have_required_values?
@value
end
-
- def to_feed(feed, current)
- if value and current.respond_to?(:#{full_name})
- new_item = current.class::#{full_klass_name}.new(value)
- current.#{full_plural_name} << new_item
- end
- end
end
- #{klass_name}Base = #{full_klass_name}Base
end
EOC
end
@@ -74,13 +86,18 @@ module RSS
::RSS::DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
plural_name ||= "#{name}s"
klass_name = Utils.to_class_name(name)
- full_klass_name = "DublinCore#{klass_name}"
plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
+ full_klass_name = "DublinCore#{klass_name}"
+ klass.module_eval(<<-EOC, *Utils.get_file_and_line_from_caller(1))
class #{plural_klass_name} < #{plural_klass_name}Base
- class #{full_klass_name} < #{full_klass_name}Base
+ class #{klass_name} < #{klass_name}Base
+ def to_rss(rss, current)
+ if value and current.respond_to?(:dc_#{name})
+ new_item = current.class::#{full_klass_name}.new(value)
+ current.dc_#{plural_name} << new_item
+ end
+ end
end
- #{klass_name} = #{full_klass_name}
end
EOC
end
@@ -89,36 +106,64 @@ EOC
class ChannelBase
include DublinCoreModel
+
+ remove_method(:date)
+ remove_method(:date=)
+ alias_method(:date, :dc_date)
+ alias_method(:date=, :dc_date=)
end
class ImageBase; include DublinCoreModel; end
class ItemsBase
class ItemBase
include DublinCoreModel
+
+ remove_method(:date)
+ remove_method(:date=)
+ alias_method(:date, :dc_date)
+ alias_method(:date=, :dc_date=)
end
end
class TextinputBase; include DublinCoreModel; end
- makers.each do |maker|
- maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class Channel
- DublinCoreModel.install_dublin_core(self)
- end
+ class RSS10
+ class Channel
+ DublinCoreModel.install_dublin_core(self)
+ end
- class Image
+ class Image
+ DublinCoreModel.install_dublin_core(self)
+ end
+
+ class Items
+ class Item
DublinCoreModel.install_dublin_core(self)
end
+ end
- class Items
- class Item
- DublinCoreModel.install_dublin_core(self)
- end
- end
+ class Textinput
+ DublinCoreModel.install_dublin_core(self)
+ end
+ end
+
+ class RSS09
+ class Channel
+ DublinCoreModel.install_dublin_core(self)
+ end
- class Textinput
+ class Image
+ DublinCoreModel.install_dublin_core(self)
+ end
+
+ class Items
+ class Item
DublinCoreModel.install_dublin_core(self)
end
- EOC
+ end
+
+ class Textinput
+ DublinCoreModel.install_dublin_core(self)
+ end
end
end
end
diff --git a/lib/rss/maker/entry.rb b/lib/rss/maker/entry.rb
deleted file mode 100644
index edaa31ec06..0000000000
--- a/lib/rss/maker/entry.rb
+++ /dev/null
@@ -1,163 +0,0 @@
-require "rss/maker/atom"
-require "rss/maker/feed"
-
-module RSS
- module Maker
- module Atom
- class Entry < RSSBase
- def initialize(feed_version="1.0")
- super
- @feed_type = "atom"
- @feed_subtype = "entry"
- end
-
- private
- def make_feed
- ::RSS::Atom::Entry.new(@version, @encoding, @standalone)
- end
-
- def setup_elements(entry)
- setup_items(entry)
- end
-
- class Channel < ChannelBase
- class SkipDays < SkipDaysBase
- class Day < DayBase
- end
- end
-
- class SkipHours < SkipHoursBase
- class Hour < HourBase
- end
- end
-
- class Cloud < CloudBase
- end
-
- Categories = Feed::Channel::Categories
- Links = Feed::Channel::Links
- Authors = Feed::Channel::Authors
- Contributors = Feed::Channel::Contributors
-
- class Generator < GeneratorBase
- include AtomGenerator
-
- def self.not_set_name
- "maker.channel.generator"
- end
- end
-
- Copyright = Feed::Channel::Copyright
-
- class Description < DescriptionBase
- end
-
- Title = Feed::Channel::Title
- end
-
- class Image < ImageBase
- end
-
- class Items < ItemsBase
- def to_feed(entry)
- (normalize.first || Item.new(@maker)).to_feed(entry)
- end
-
- class Item < ItemBase
- def to_feed(entry)
- set_default_values do
- setup_values(entry)
- entry.dc_dates.clear
- setup_other_elements(entry)
- unless have_required_values?
- raise NotSetError.new("maker.item", not_set_required_variables)
- end
- end
- end
-
- private
- def required_variable_names
- %w(id updated)
- end
-
- def variables
- super + ["updated"]
- end
-
- def variable_is_set?
- super or !authors.empty?
- end
-
- def not_set_required_variables
- set_default_values do
- vars = super
- if authors.all? {|author| !author.have_required_values?}
- vars << "author"
- end
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
- end
-
- def _set_default_values(&block)
- keep = {
- :authors => authors.to_a.dup,
- :contributors => contributors.to_a.dup,
- :categories => categories.to_a.dup,
- :id => id,
- :links => links.to_a.dup,
- :rights => @rights,
- :title => @title,
- :updated => updated,
- }
- authors.replace(@maker.channel.authors) if keep[:authors].empty?
- if keep[:contributors].empty?
- contributors.replace(@maker.channel.contributors)
- end
- if keep[:categories].empty?
- categories.replace(@maker.channel.categories)
- end
- self.id ||= link || @maker.channel.id
- links.replace(@maker.channel.links) if keep[:links].empty?
- unless keep[:rights].variable_is_set?
- @maker.channel.rights {|r| @rights = r}
- end
- unless keep[:title].variable_is_set?
- @maker.channel.title {|t| @title = t}
- end
- self.updated ||= @maker.channel.updated
- super(&block)
- ensure
- authors.replace(keep[:authors])
- contributors.replace(keep[:contributors])
- categories.replace(keep[:categories])
- links.replace(keep[:links])
- self.id = keep[:id]
- @rights = keep[:rights]
- @title = keep[:title]
- self.updated = keep[:prev_updated]
- end
-
- Guid = Feed::Items::Item::Guid
- Enclosure = Feed::Items::Item::Enclosure
- Source = Feed::Items::Item::Source
- Categories = Feed::Items::Item::Categories
- Authors = Feed::Items::Item::Authors
- Contributors = Feed::Items::Item::Contributors
- Links = Feed::Items::Item::Links
- Rights = Feed::Items::Item::Rights
- Description = Feed::Items::Item::Description
- Title = Feed::Items::Item::Title
- Content = Feed::Items::Item::Content
- end
- end
-
- class Textinput < TextinputBase
- end
- end
- end
-
- add_maker("atom:entry", "1.0", Atom::Entry)
- add_maker("atom1.0:entry", "1.0", Atom::Entry)
- end
-end
diff --git a/lib/rss/maker/feed.rb b/lib/rss/maker/feed.rb
deleted file mode 100644
index 3a30ad4287..0000000000
--- a/lib/rss/maker/feed.rb
+++ /dev/null
@@ -1,429 +0,0 @@
-require "rss/maker/atom"
-
-module RSS
- module Maker
- module Atom
- class Feed < RSSBase
- def initialize(feed_version="1.0")
- super
- @feed_type = "atom"
- @feed_subtype = "feed"
- end
-
- private
- def make_feed
- ::RSS::Atom::Feed.new(@version, @encoding, @standalone)
- end
-
- def setup_elements(feed)
- setup_channel(feed)
- setup_image(feed)
- setup_items(feed)
- end
-
- class Channel < ChannelBase
- def to_feed(feed)
- set_default_values do
- setup_values(feed)
- feed.dc_dates.clear
- setup_other_elements(feed)
- if image_favicon.about
- icon = feed.class::Icon.new
- icon.content = image_favicon.about
- feed.icon = icon
- end
- unless have_required_values?
- raise NotSetError.new("maker.channel",
- not_set_required_variables)
- end
- end
- end
-
- def have_required_values?
- super and
- (!authors.empty? or
- @maker.items.any? {|item| !item.authors.empty?})
- end
-
- private
- def required_variable_names
- %w(id updated)
- end
-
- def variables
- super + %w(id updated)
- end
-
- def variable_is_set?
- super or !authors.empty?
- end
-
- def not_set_required_variables
- vars = super
- if authors.empty? and
- @maker.items.all? {|item| item.author.to_s.empty?}
- vars << "author"
- end
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
-
- def _set_default_values(&block)
- keep = {
- :id => id,
- :updated => updated,
- }
- self.id ||= about
- self.updated ||= dc_date
- super(&block)
- ensure
- self.id = keep[:id]
- self.updated = keep[:updated]
- end
-
- class SkipDays < SkipDaysBase
- def to_feed(*args)
- end
-
- class Day < DayBase
- end
- end
-
- class SkipHours < SkipHoursBase
- def to_feed(*args)
- end
-
- class Hour < HourBase
- end
- end
-
- class Cloud < CloudBase
- def to_feed(*args)
- end
- end
-
- class Categories < CategoriesBase
- class Category < CategoryBase
- include AtomCategory
-
- def self.not_set_name
- "maker.channel.category"
- end
- end
- end
-
- class Links < LinksBase
- class Link < LinkBase
- include AtomLink
-
- def self.not_set_name
- "maker.channel.link"
- end
- end
- end
-
- AtomPersons.def_atom_persons(self, "author", "maker.channel.author")
- AtomPersons.def_atom_persons(self, "contributor",
- "maker.channel.contributor")
-
- class Generator < GeneratorBase
- include AtomGenerator
-
- def self.not_set_name
- "maker.channel.generator"
- end
- end
-
- AtomTextConstruct.def_atom_text_construct(self, "rights",
- "maker.channel.copyright",
- "Copyright")
- AtomTextConstruct.def_atom_text_construct(self, "subtitle",
- "maker.channel.description",
- "Description")
- AtomTextConstruct.def_atom_text_construct(self, "title",
- "maker.channel.title")
- end
-
- class Image < ImageBase
- def to_feed(feed)
- logo = feed.class::Logo.new
- class << logo
- alias_method(:url=, :content=)
- end
- set = setup_values(logo)
- class << logo
- remove_method(:url=)
- end
- if set
- feed.logo = logo
- set_parent(logo, feed)
- setup_other_elements(feed, logo)
- elsif variable_is_set?
- raise NotSetError.new("maker.image", not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(url)
- end
- end
-
- class Items < ItemsBase
- def to_feed(feed)
- normalize.each do |item|
- item.to_feed(feed)
- end
- setup_other_elements(feed, feed.entries)
- end
-
- class Item < ItemBase
- def to_feed(feed)
- set_default_values do
- entry = feed.class::Entry.new
- set = setup_values(entry)
- setup_other_elements(feed, entry)
- if set
- feed.entries << entry
- set_parent(entry, feed)
- elsif variable_is_set?
- raise NotSetError.new("maker.item", not_set_required_variables)
- end
- end
- end
-
- def have_required_values?
- set_default_values do
- super and title {|t| t.have_required_values?}
- end
- end
-
- private
- def required_variable_names
- %w(id updated)
- end
-
- def variables
- super + ["updated"]
- end
-
- def not_set_required_variables
- vars = super
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
-
- def _set_default_values(&block)
- keep = {
- :id => id,
- :updated => updated,
- }
- self.id ||= link
- self.updated ||= dc_date
- super(&block)
- ensure
- self.id = keep[:id]
- self.updated = keep[:updated]
- end
-
- class Guid < GuidBase
- def to_feed(feed, current)
- end
- end
-
- class Enclosure < EnclosureBase
- def to_feed(feed, current)
- end
- end
-
- class Source < SourceBase
- def to_feed(feed, current)
- source = current.class::Source.new
- setup_values(source)
- current.source = source
- set_parent(source, current)
- setup_other_elements(feed, source)
- current.source = nil if source.to_s == "<source/>"
- end
-
- private
- def required_variable_names
- []
- end
-
- def variables
- super + ["updated"]
- end
-
- AtomPersons.def_atom_persons(self, "author",
- "maker.item.source.author")
- AtomPersons.def_atom_persons(self, "contributor",
- "maker.item.source.contributor")
-
- class Categories < CategoriesBase
- class Category < CategoryBase
- include AtomCategory
-
- def self.not_set_name
- "maker.item.source.category"
- end
- end
- end
-
- class Generator < GeneratorBase
- include AtomGenerator
-
- def self.not_set_name
- "maker.item.source.generator"
- end
- end
-
- class Icon < IconBase
- def to_feed(feed, current)
- icon = current.class::Icon.new
- class << icon
- alias_method(:url=, :content=)
- end
- set = setup_values(icon)
- class << icon
- remove_method(:url=)
- end
- if set
- current.icon = icon
- set_parent(icon, current)
- setup_other_elements(feed, icon)
- elsif variable_is_set?
- raise NotSetError.new("maker.item.source.icon",
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(url)
- end
- end
-
- class Links < LinksBase
- class Link < LinkBase
- include AtomLink
-
- def self.not_set_name
- "maker.item.source.link"
- end
- end
- end
-
- class Logo < LogoBase
- include AtomLogo
-
- def self.not_set_name
- "maker.item.source.logo"
- end
- end
-
- maker_name_base = "maker.item.source."
- maker_name = "#{maker_name_base}rights"
- AtomTextConstruct.def_atom_text_construct(self, "rights",
- maker_name)
- maker_name = "#{maker_name_base}subtitle"
- AtomTextConstruct.def_atom_text_construct(self, "subtitle",
- maker_name)
- maker_name = "#{maker_name_base}title"
- AtomTextConstruct.def_atom_text_construct(self, "title",
- maker_name)
- end
-
- class Categories < CategoriesBase
- class Category < CategoryBase
- include AtomCategory
-
- def self.not_set_name
- "maker.item.category"
- end
- end
- end
-
- AtomPersons.def_atom_persons(self, "author", "maker.item.author")
- AtomPersons.def_atom_persons(self, "contributor",
- "maker.item.contributor")
-
- class Links < LinksBase
- class Link < LinkBase
- include AtomLink
-
- def self.not_set_name
- "maker.item.link"
- end
- end
- end
-
- AtomTextConstruct.def_atom_text_construct(self, "rights",
- "maker.item.rights")
- AtomTextConstruct.def_atom_text_construct(self, "summary",
- "maker.item.description",
- "Description")
- AtomTextConstruct.def_atom_text_construct(self, "title",
- "maker.item.title")
-
- class Content < ContentBase
- def to_feed(feed, current)
- content = current.class::Content.new
- if setup_values(content)
- content.src = nil if content.src and content.content
- current.content = content
- set_parent(content, current)
- setup_other_elements(feed, content)
- elsif variable_is_set?
- raise NotSetError.new("maker.item.content",
- not_set_required_variables)
- end
- end
-
- alias_method(:xml, :xml_content)
-
- private
- def required_variable_names
- if out_of_line?
- %w(type)
- elsif xml_type?
- %w(xml_content)
- else
- %w(content)
- end
- end
-
- def variables
- if out_of_line?
- super
- elsif xml_type?
- super + %w(xml)
- else
- super
- end
- end
-
- def xml_type?
- _type = type
- return false if _type.nil?
- _type == "xhtml" or
- /(?:\+xml|\/xml)$/i =~ _type or
- %w(text/xml-external-parsed-entity
- application/xml-external-parsed-entity
- application/xml-dtd).include?(_type.downcase)
- end
- end
- end
- end
-
- class Textinput < TextinputBase
- end
- end
- end
-
- add_maker("atom", "1.0", Atom::Feed)
- add_maker("atom:feed", "1.0", Atom::Feed)
- add_maker("atom1.0", "1.0", Atom::Feed)
- add_maker("atom1.0:feed", "1.0", Atom::Feed)
- end
-end
diff --git a/lib/rss/maker/image.rb b/lib/rss/maker/image.rb
index b95cf4c714..ed51c8ecba 100644
--- a/lib/rss/maker/image.rb
+++ b/lib/rss/maker/image.rb
@@ -9,18 +9,24 @@ module RSS
super
name = "#{RSS::IMAGE_PREFIX}_item"
- klass.def_classed_element(name)
- end
+ klass.add_need_initialize_variable(name, "make_#{name}")
+ klass.add_other_element(name)
+ klass.module_eval(<<-EOC, __FILE__, __LINE__+1)
+ attr_reader :#{name}
+ def setup_#{name}(rss, current)
+ if @#{name}
+ @#{name}.to_rss(rss, current)
+ end
+ end
- def self.install_image_item(klass)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class ImageItem < ImageItemBase
- DublinCoreModel.install_dublin_core(self)
+ def make_#{name}
+ self.class::#{Utils.to_class_name(name)}.new(@maker)
end
EOC
end
- class ImageItemBase < Base
+ class ImageItemBase
+ include Base
include Maker::DublinCoreModel
attr_accessor :about, :resource, :image_width, :image_height
@@ -36,15 +42,6 @@ EOC
def have_required_values?
@about
end
-
- def to_feed(feed, current)
- if current.respond_to?(:image_item=) and have_required_values?
- item = current.class::ImageItem.new
- setup_values(item)
- setup_other_elements(item)
- current.image_item = item
- end
- end
end
end
@@ -53,18 +50,24 @@ EOC
super
name = "#{RSS::IMAGE_PREFIX}_favicon"
- klass.def_classed_element(name)
- end
+ klass.add_need_initialize_variable(name, "make_#{name}")
+ klass.add_other_element(name)
+ klass.module_eval(<<-EOC, __FILE__, __LINE__+1)
+ attr_reader :#{name}
+ def setup_#{name}(rss, current)
+ if @#{name}
+ @#{name}.to_rss(rss, current)
+ end
+ end
- def self.install_image_favicon(klass)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class ImageFavicon < ImageFaviconBase
- DublinCoreModel.install_dublin_core(self)
+ def make_#{name}
+ self.class::#{Utils.to_class_name(name)}.new(@maker)
end
- EOC
+EOC
end
- class ImageFaviconBase < Base
+ class ImageFaviconBase
+ include Base
include Maker::DublinCoreModel
attr_accessor :about, :image_size
@@ -76,15 +79,6 @@ EOC
def have_required_values?
@about and @image_size
end
-
- def to_feed(feed, current)
- if current.respond_to?(:image_favicon=) and have_required_values?
- favicon = current.class::ImageFavicon.new
- setup_values(favicon)
- setup_other_elements(favicon)
- current.image_favicon = favicon
- end
- end
end
end
@@ -94,18 +88,58 @@ EOC
class ItemBase; include Maker::ImageItemModel; end
end
- makers.each do |maker|
- maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class Channel
- ImageFaviconModel.install_image_favicon(self)
+ class RSS10
+ class Items
+ class Item
+ class ImageItem < ImageItemBase
+ DublinCoreModel.install_dublin_core(self)
+ def to_rss(rss, current)
+ if @about
+ item = ::RSS::ImageItemModel::ImageItem.new(@about, @resource)
+ setup_values(item)
+ setup_other_elements(item)
+ current.image_item = item
+ end
+ end
+ end
end
+ end
+
+ class Channel
+ class ImageFavicon < ImageFaviconBase
+ DublinCoreModel.install_dublin_core(self)
+ def to_rss(rss, current)
+ if @about and @image_size
+ args = [@about, @image_size]
+ favicon = ::RSS::ImageFaviconModel::ImageFavicon.new(*args)
+ setup_values(favicon)
+ setup_other_elements(favicon)
+ current.image_favicon = favicon
+ end
+ end
+ end
+ end
+ end
- class Items
- class Item
- ImageItemModel.install_image_item(self)
+ class RSS09
+ class Items
+ class Item
+ class ImageItem < ImageItemBase
+ DublinCoreModel.install_dublin_core(self)
+ def to_rss(*args)
+ end
end
end
- EOC
+ end
+
+ class Channel
+ class ImageFavicon < ImageFaviconBase
+ DublinCoreModel.install_dublin_core(self)
+ def to_rss(*args)
+ end
+ end
+ end
end
+
end
end
diff --git a/lib/rss/maker/itunes.rb b/lib/rss/maker/itunes.rb
deleted file mode 100644
index 7c5049129d..0000000000
--- a/lib/rss/maker/itunes.rb
+++ /dev/null
@@ -1,242 +0,0 @@
-require 'rss/itunes'
-require 'rss/maker/2.0'
-
-module RSS
- module Maker
- module ITunesBaseModel
- def def_class_accessor(klass, name, type, *args)
- name = name.gsub(/-/, "_").gsub(/^itunes_/, '')
- full_name = "#{RSS::ITUNES_PREFIX}_#{name}"
- case type
- when nil
- klass.def_other_element(full_name)
- when :yes_other
- def_yes_other_accessor(klass, full_name)
- when :yes_clean_other
- def_yes_clean_other_accessor(klass, full_name)
- when :csv
- def_csv_accessor(klass, full_name)
- when :element, :attribute
- recommended_attribute_name, = *args
- klass_name = "ITunes#{Utils.to_class_name(name)}"
- klass.def_classed_element(full_name, klass_name,
- recommended_attribute_name)
- when :elements
- plural_name, recommended_attribute_name = args
- plural_name ||= "#{name}s"
- full_plural_name = "#{RSS::ITUNES_PREFIX}_#{plural_name}"
- klass_name = "ITunes#{Utils.to_class_name(name)}"
- plural_klass_name = "ITunes#{Utils.to_class_name(plural_name)}"
- def_elements_class_accessor(klass, name, full_name, full_plural_name,
- klass_name, plural_klass_name,
- recommended_attribute_name)
- end
- end
-
- def def_yes_other_accessor(klass, full_name)
- klass.def_other_element(full_name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{full_name}?
- Utils::YesOther.parse(@#{full_name})
- end
- EOC
- end
-
- def def_yes_clean_other_accessor(klass, full_name)
- klass.def_other_element(full_name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{full_name}?
- Utils::YesCleanOther.parse(#{full_name})
- end
- EOC
- end
-
- def def_csv_accessor(klass, full_name)
- klass.def_csv_element(full_name)
- end
-
- def def_elements_class_accessor(klass, name, full_name, full_plural_name,
- klass_name, plural_klass_name,
- recommended_attribute_name=nil)
- if recommended_attribute_name
- klass.def_classed_elements(full_name, recommended_attribute_name,
- plural_klass_name, full_plural_name)
- else
- klass.def_classed_element(full_plural_name, plural_klass_name)
- end
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def new_#{full_name}(text=nil)
- #{full_name} = @#{full_plural_name}.new_#{name}
- #{full_name}.text = text
- if block_given?
- yield #{full_name}
- else
- #{full_name}
- end
- end
- EOC
- end
- end
-
- module ITunesChannelModel
- extend ITunesBaseModel
-
- class << self
- def append_features(klass)
- super
-
- ::RSS::ITunesChannelModel::ELEMENT_INFOS.each do |name, type, *args|
- def_class_accessor(klass, name, type, *args)
- end
- end
- end
-
- class ITunesCategoriesBase < Base
- def_array_element("category", "itunes_categories",
- "ITunesCategory")
- class ITunesCategoryBase < Base
- attr_accessor :text
- add_need_initialize_variable("text")
- def_array_element("category", "itunes_categories",
- "ITunesCategory")
-
- def have_required_values?
- text
- end
-
- alias_method :to_feed_for_categories, :to_feed
- def to_feed(feed, current)
- if text and current.respond_to?(:itunes_category)
- new_item = current.class::ITunesCategory.new(text)
- to_feed_for_categories(feed, new_item)
- current.itunes_categories << new_item
- end
- end
- end
- end
-
- class ITunesImageBase < Base
- add_need_initialize_variable("href")
- attr_accessor("href")
-
- def to_feed(feed, current)
- if @href and current.respond_to?(:itunes_image)
- current.itunes_image ||= current.class::ITunesImage.new
- current.itunes_image.href = @href
- end
- end
- end
-
- class ITunesOwnerBase < Base
- %w(itunes_name itunes_email).each do |name|
- add_need_initialize_variable(name)
- attr_accessor(name)
- end
-
- def to_feed(feed, current)
- if current.respond_to?(:itunes_owner=)
- _not_set_required_variables = not_set_required_variables
- if (required_variable_names - _not_set_required_variables).empty?
- return
- end
-
- unless have_required_values?
- raise NotSetError.new("maker.channel.itunes_owner",
- _not_set_required_variables)
- end
- current.itunes_owner ||= current.class::ITunesOwner.new
- current.itunes_owner.itunes_name = @itunes_name
- current.itunes_owner.itunes_email = @itunes_email
- end
- end
-
- private
- def required_variable_names
- %w(itunes_name itunes_email)
- end
- end
- end
-
- module ITunesItemModel
- extend ITunesBaseModel
-
- class << self
- def append_features(klass)
- super
-
- ::RSS::ITunesItemModel::ELEMENT_INFOS.each do |name, type, *args|
- def_class_accessor(klass, name, type, *args)
- end
- end
- end
-
- class ITunesDurationBase < Base
- attr_reader :content
- add_need_initialize_variable("content")
-
- %w(hour minute second).each do |name|
- attr_reader(name)
- add_need_initialize_variable(name, '0')
- end
-
- def content=(content)
- if content.nil?
- @hour, @minute, @second, @content = nil
- else
- @hour, @minute, @second =
- ::RSS::ITunesItemModel::ITunesDuration.parse(content)
- @content = content
- end
- end
-
- def hour=(hour)
- @hour = Integer(hour)
- update_content
- end
-
- def minute=(minute)
- @minute = Integer(minute)
- update_content
- end
-
- def second=(second)
- @second = Integer(second)
- update_content
- end
-
- def to_feed(feed, current)
- if @content and current.respond_to?(:itunes_duration=)
- current.itunes_duration ||= current.class::ITunesDuration.new
- current.itunes_duration.content = @content
- end
- end
-
- private
- def update_content
- components = [@hour, @minute, @second]
- @content =
- ::RSS::ITunesItemModel::ITunesDuration.construct(*components)
- end
- end
- end
-
- class ChannelBase
- include Maker::ITunesChannelModel
- class ITunesCategories < ITunesCategoriesBase
- class ITunesCategory < ITunesCategoryBase
- ITunesCategory = self
- end
- end
-
- class ITunesImage < ITunesImageBase; end
- class ITunesOwner < ITunesOwnerBase; end
- end
-
- class ItemsBase
- class ItemBase
- include Maker::ITunesItemModel
- class ITunesDuration < ITunesDurationBase; end
- end
- end
- end
-end
diff --git a/lib/rss/maker/slash.rb b/lib/rss/maker/slash.rb
deleted file mode 100644
index 27adef3832..0000000000
--- a/lib/rss/maker/slash.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-require 'rss/slash'
-require 'rss/maker/1.0'
-
-module RSS
- module Maker
- module SlashModel
- def self.append_features(klass)
- super
-
- ::RSS::SlashModel::ELEMENT_INFOS.each do |name, type|
- full_name = "#{RSS::SLASH_PREFIX}_#{name}"
- case type
- when :csv_integer
- klass.def_csv_element(full_name, :integer)
- else
- klass.def_other_element(full_name)
- end
- end
-
- klass.module_eval do
- alias_method(:slash_hit_parades, :slash_hit_parade)
- alias_method(:slash_hit_parades=, :slash_hit_parade=)
- end
- end
- end
-
- class ItemsBase
- class ItemBase
- include SlashModel
- end
- end
- end
-end
diff --git a/lib/rss/maker/syndication.rb b/lib/rss/maker/syndication.rb
index b81230457c..3717086257 100644
--- a/lib/rss/maker/syndication.rb
+++ b/lib/rss/maker/syndication.rb
@@ -7,8 +7,17 @@ module RSS
def self.append_features(klass)
super
- ::RSS::SyndicationModel::ELEMENTS.each do |name|
- klass.def_other_element(name)
+ ::RSS::SyndicationModel::ELEMENTS.each do |element|
+ klass.add_need_initialize_variable(element)
+ klass.add_other_element(element)
+ klass.module_eval(<<-EOC, __FILE__, __LINE__+1)
+ attr_accessor :#{element}
+ def setup_#{element}(rss, current)
+ if #{element} and current.respond_to?(:#{element}=)
+ current.#{element} = @#{element} if @#{element}
+ end
+ end
+ EOC
end
end
end
diff --git a/lib/rss/maker/taxonomy.rb b/lib/rss/maker/taxonomy.rb
index 211603840f..f272996581 100644
--- a/lib/rss/maker/taxonomy.rb
+++ b/lib/rss/maker/taxonomy.rb
@@ -8,14 +8,24 @@ module RSS
def self.append_features(klass)
super
- klass.def_classed_element("#{RSS::TAXO_PREFIX}_topics",
- "TaxonomyTopics")
+ klass.add_need_initialize_variable("taxo_topics", "make_taxo_topics")
+ klass.add_other_element("taxo_topics")
+ klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
+ attr_reader :taxo_topics
+ def make_taxo_topics
+ self.class::TaxonomyTopics.new(@maker)
+ end
+
+ def setup_taxo_topics(rss, current)
+ @taxo_topics.to_rss(rss, current)
+ end
+EOC
end
def self.install_taxo_topics(klass)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
+ klass.module_eval(<<-EOC, *Utils.get_file_and_line_from_caller(1))
class TaxonomyTopics < TaxonomyTopicsBase
- def to_feed(feed, current)
+ def to_rss(rss, current)
if current.respond_to?(:taxo_topics)
topics = current.class::TaxonomyTopics.new
bag = topics.Bag
@@ -29,10 +39,11 @@ module RSS
EOC
end
- class TaxonomyTopicsBase < Base
+ class TaxonomyTopicsBase
+ include Base
+
attr_reader :resources
- def_array_element("resource")
- remove_method :new_resource
+ def_array_element("resources")
end
end
@@ -40,36 +51,77 @@ EOC
def self.append_features(klass)
super
- class_name = "TaxonomyTopics"
- klass.def_classed_elements("#{TAXO_PREFIX}_topic", "value", class_name)
- end
+ klass.add_need_initialize_variable("taxo_topics", "make_taxo_topics")
+ klass.add_other_element("taxo_topics")
+ klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
+ attr_reader :taxo_topics
+ def make_taxo_topics
+ self.class::TaxonomyTopics.new(@maker)
+ end
+
+ def setup_taxo_topics(rss, current)
+ @taxo_topics.to_rss(rss, current)
+ end
+ def taxo_topic
+ @taxo_topics[0] and @taxo_topics[0].value
+ end
+
+ def taxo_topic=(new_value)
+ @taxo_topic[0] = self.class::TaxonomyTopic.new(self)
+ @taxo_topic[0].value = new_value
+ end
+EOC
+ end
+
def self.install_taxo_topic(klass)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
+ klass.module_eval(<<-EOC, *Utils.get_file_and_line_from_caller(1))
class TaxonomyTopics < TaxonomyTopicsBase
class TaxonomyTopic < TaxonomyTopicBase
DublinCoreModel.install_dublin_core(self)
TaxonomyTopicsModel.install_taxo_topics(self)
- def to_feed(feed, current)
+ def to_rss(rss, current)
if current.respond_to?(:taxo_topics)
topic = current.class::TaxonomyTopic.new(value)
topic.taxo_link = value
- taxo_topics.to_feed(feed, topic) if taxo_topics
+ taxo_topics.to_rss(rss, topic) if taxo_topics
current.taxo_topics << topic
- setup_other_elements(feed, topic)
+ setup_other_elements(rss)
end
end
+
+ def current_element(rss)
+ super.taxo_topics.last
+ end
end
end
EOC
end
- class TaxonomyTopicsBase < Base
- def_array_element("topic", nil, "TaxonomyTopic")
- alias_method(:new_taxo_topic, :new_topic) # For backward compatibility
+ class TaxonomyTopicsBase
+ include Base
+
+ def_array_element("taxo_topics")
+
+ def new_taxo_topic
+ taxo_topic = self.class::TaxonomyTopic.new(self)
+ @taxo_topics << taxo_topic
+ if block_given?
+ yield taxo_topic
+ else
+ taxo_topic
+ end
+ end
- class TaxonomyTopicBase < Base
+ def to_rss(rss, current)
+ @taxo_topics.each do |taxo_topic|
+ taxo_topic.to_rss(rss, current)
+ end
+ end
+
+ class TaxonomyTopicBase
+ include Base
include DublinCoreModel
include TaxonomyTopicsModel
@@ -99,20 +151,32 @@ EOC
end
end
- makers.each do |maker|
- maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- TaxonomyTopicModel.install_taxo_topic(self)
+ class RSS10
+ TaxonomyTopicModel.install_taxo_topic(self)
+
+ class Channel
+ TaxonomyTopicsModel.install_taxo_topics(self)
+ end
- class Channel
+ class Items
+ class Item
TaxonomyTopicsModel.install_taxo_topics(self)
end
+ end
+ end
+
+ class RSS09
+ TaxonomyTopicModel.install_taxo_topic(self)
+
+ class Channel
+ TaxonomyTopicsModel.install_taxo_topics(self)
+ end
- class Items
- class Item
- TaxonomyTopicsModel.install_taxo_topics(self)
- end
+ class Items
+ class Item
+ TaxonomyTopicsModel.install_taxo_topics(self)
end
- EOC
+ end
end
end
end
diff --git a/lib/rss/maker/trackback.rb b/lib/rss/maker/trackback.rb
index 278fe53ebe..4ae6164f68 100644
--- a/lib/rss/maker/trackback.rb
+++ b/lib/rss/maker/trackback.rb
@@ -8,15 +8,57 @@ module RSS
def self.append_features(klass)
super
- klass.def_other_element("#{RSS::TRACKBACK_PREFIX}_ping")
- klass.def_classed_elements("#{RSS::TRACKBACK_PREFIX}_about", "value",
- "TrackBackAbouts")
+ name = "#{RSS::TRACKBACK_PREFIX}_ping"
+ klass.add_need_initialize_variable(name)
+ klass.add_other_element(name)
+ klass.module_eval(<<-EOC, __FILE__, __LINE__+1)
+ attr_accessor :#{name}
+ def setup_#{name}(rss, current)
+ if #{name} and current.respond_to?(:#{name}=)
+ current.#{name} = #{name}
+ end
+ end
+ EOC
+
+ name = "#{RSS::TRACKBACK_PREFIX}_abouts"
+ klass.add_need_initialize_variable(name, "make_#{name}")
+ klass.add_other_element(name)
+ klass.module_eval(<<-EOC, __FILE__, __LINE__+1)
+ attr_accessor :#{name}
+ def make_#{name}
+ self.class::TrackBackAbouts.new(self)
+ end
+
+ def setup_#{name}(rss, current)
+ @#{name}.to_rss(rss, current)
+ end
+ EOC
end
- class TrackBackAboutsBase < Base
- def_array_element("about", nil, "TrackBackAbout")
+ class TrackBackAboutsBase
+ include Base
+
+ def_array_element("abouts")
+
+ def new_about
+ about = self.class::TrackBackAbout.new(@maker)
+ @abouts << about
+ if block_given?
+ yield about
+ else
+ about
+ end
+ end
+
+ def to_rss(rss, current)
+ @abouts.each do |about|
+ about.to_rss(rss, current)
+ end
+ end
+
+ class TrackBackAboutBase
+ include Base
- class TrackBackAboutBase < Base
attr_accessor :value
add_need_initialize_variable("value")
@@ -24,19 +66,11 @@ module RSS
alias_method(:resource=, :value=)
alias_method(:content, :value)
alias_method(:content=, :value=)
-
+
def have_required_values?
@value
end
-
- def to_feed(feed, current)
- if current.respond_to?(:trackback_abouts) and have_required_values?
- about = current.class::TrackBackAbout.new
- setup_values(about)
- setup_other_elements(about)
- current.trackback_abouts << about
- end
- end
+
end
end
end
@@ -45,17 +79,52 @@ module RSS
class ItemBase; include TrackBackModel; end
end
- makers.each do |maker|
- maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class Items
- class Item
- class TrackBackAbouts < TrackBackAboutsBase
- class TrackBackAbout < TrackBackAboutBase
+ class RSS10
+ class Items
+ class Item
+ class TrackBackAbouts < TrackBackAboutsBase
+ class TrackBackAbout < TrackBackAboutBase
+ def to_rss(rss, current)
+ if resource
+ about = ::RSS::TrackBackModel10::TrackBackAbout.new(resource)
+ current.trackback_abouts << about
+ end
end
end
end
end
- EOC
+ end
+ end
+
+ class RSS09
+ class Items
+ class Item
+ class TrackBackAbouts < TrackBackAboutsBase
+ def to_rss(*args)
+ end
+ class TrackBackAbout < TrackBackAboutBase
+ end
+ end
+ end
+ end
+ end
+
+ class RSS20
+ class Items
+ class Item
+ class TrackBackAbouts < TrackBackAboutsBase
+ class TrackBackAbout < TrackBackAboutBase
+ def to_rss(rss, current)
+ if content
+ about = ::RSS::TrackBackModel20::TrackBackAbout.new(content)
+ current.trackback_abouts << about
+ end
+ end
+ end
+ end
+ end
+ end
end
+
end
end
diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb
index 9e4919223c..033bc123aa 100644
--- a/lib/rss/parser.rb
+++ b/lib/rss/parser.rb
@@ -2,7 +2,6 @@ require "forwardable"
require "open-uri"
require "rss/rss"
-require "rss/xml"
module RSS
@@ -119,7 +118,7 @@ module RSS
return rss if rss.is_a?(::URI::Generic)
begin
- ::URI.parse(rss)
+ URI(rss)
rescue ::URI::Error
rss
end
@@ -174,27 +173,27 @@ module RSS
class << self
- @@accessor_bases = {}
+ @@setters = {}
@@registered_uris = {}
@@class_names = {}
# return the setter for the uri, tag_name pair, or nil.
def setter(uri, tag_name)
- _getter = getter(uri, tag_name)
- if _getter
- "#{_getter}="
- else
+ begin
+ @@setters[uri][tag_name]
+ rescue NameError
nil
end
end
- def getter(uri, tag_name)
- (@@accessor_bases[uri] || {})[tag_name]
- end
# return the tag_names for setters associated with uri
def available_tags(uri)
- (@@accessor_bases[uri] || {}).keys
+ begin
+ @@setters[uri].keys
+ rescue NameError
+ []
+ end
end
# register uri against this name.
@@ -217,17 +216,15 @@ module RSS
# retrieve class_name for the supplied uri and tag_name
# If it doesn't exist, capitalize the tag_name
def class_name(uri, tag_name)
- name = (@@class_names[uri] || {})[tag_name]
- return name if name
-
- tag_name = tag_name.gsub(/[_\-]([a-z]?)/) do
- $1.upcase
+ begin
+ @@class_names[uri][tag_name]
+ rescue NameError
+ tag_name[0,1].upcase + tag_name[1..-1]
end
- tag_name[0, 1].upcase + tag_name[1..-1]
end
- def install_get_text_element(uri, name, accessor_base)
- install_accessor_base(uri, name, accessor_base)
+ def install_get_text_element(uri, name, setter)
+ install_setter(uri, name, setter)
def_get_text_element(uri, name, *get_file_and_line_from_caller(1))
end
@@ -236,31 +233,35 @@ module RSS
end
private
- # set the accessor for the uri, tag_name pair
- def install_accessor_base(uri, tag_name, accessor_base)
- @@accessor_bases[uri] ||= {}
- @@accessor_bases[uri][tag_name] = accessor_base.chomp("=")
+ # set the setter for the uri, tag_name pair
+ def install_setter(uri, tag_name, setter)
+ @@setters[uri] ||= {}
+ @@setters[uri][tag_name] = setter
end
- def def_get_text_element(uri, element_name, file, line)
- register_uri(uri, element_name)
- method_name = "start_#{element_name}"
- unless private_method_defined?(method_name)
- define_method(method_name) do |name, prefix, attrs, ns|
+ def def_get_text_element(uri, name, file, line)
+ register_uri(uri, name)
+ unless private_instance_methods(false).include?("start_#{name}")
+ module_eval(<<-EOT, file, line)
+ def start_#{name}(name, prefix, attrs, ns)
uri = _ns(ns, prefix)
- if self.class.uri_registered?(uri, element_name)
+ if self.class.uri_registered?(uri, #{name.inspect})
start_get_text_element(name, prefix, ns, uri)
else
start_else_element(name, prefix, attrs, ns)
end
end
- private(method_name)
+ EOT
+ __send__("private", "start_#{name}")
end
end
+
end
+
end
module ListenerMixin
+
attr_reader :rss
attr_accessor :ignore_unknown_element
@@ -270,16 +271,13 @@ module RSS
@rss = nil
@ignore_unknown_element = true
@do_validate = true
- @ns_stack = [{"xml" => :xml}]
+ @ns_stack = [{}]
@tag_stack = [[]]
@text_stack = ['']
@proc_stack = []
@last_element = nil
@version = @encoding = @standalone = nil
@xml_stylesheets = []
- @xml_child_mode = false
- @xml_element = nil
- @last_xml_element = nil
end
# set instance vars for version, encoding, standalone
@@ -291,7 +289,7 @@ module RSS
if name == "xml-stylesheet"
params = parse_pi_content(content)
if params.has_key?("href")
- @xml_stylesheets << XMLStyleSheet.new(params)
+ @xml_stylesheets << XMLStyleSheet.new(*params)
end
end
end
@@ -313,39 +311,10 @@ module RSS
prefix, local = split_name(name)
@tag_stack.last.push([_ns(ns, prefix), local])
@tag_stack.push([])
- if @xml_child_mode
- previous = @last_xml_element
- element_attrs = attributes.dup
- unless previous
- ns.each do |ns_prefix, value|
- next if ns_prefix == "xml"
- key = ns_prefix.empty? ? "xmlns" : "xmlns:#{ns_prefix}"
- element_attrs[key] ||= value
- end
- end
- next_element = XML::Element.new(local,
- prefix.empty? ? nil : prefix,
- _ns(ns, prefix),
- element_attrs)
- previous << next_element if previous
- @last_xml_element = next_element
- pr = Proc.new do |text, tags|
- if previous
- @last_xml_element = previous
- else
- @xml_element = @last_xml_element
- @last_xml_element = nil
- end
- end
- @proc_stack.push(pr)
+ if respond_to?("start_#{local}", true)
+ __send__("start_#{local}", local, prefix, attrs, ns.dup)
else
- if @rss.nil? and respond_to?("initial_start_#{local}", true)
- __send__("initial_start_#{local}", local, prefix, attrs, ns.dup)
- elsif respond_to?("start_#{local}", true)
- __send__("start_#{local}", local, prefix, attrs, ns.dup)
- else
- start_else_element(local, prefix, attrs, ns.dup)
- end
+ start_else_element(local, prefix, attrs, ns.dup)
end
end
@@ -362,11 +331,7 @@ module RSS
end
def text(data)
- if @xml_child_mode
- @last_xml_element << data if @last_xml_element
- else
- @text_stack.last << data
- end
+ @text_stack.last << data
end
private
@@ -389,9 +354,7 @@ module RSS
def start_else_element(local, prefix, attrs, ns)
class_name = self.class.class_name(_ns(ns, prefix), local)
current_class = @last_element.class
- if class_name and
- (current_class.const_defined?(class_name) or
- current_class.constants.include?(class_name))
+ if current_class.constants.include?(class_name)
next_class = current_class.const_get(class_name)
start_have_something_element(local, prefix, attrs, ns, next_class)
else
@@ -414,26 +377,19 @@ module RSS
end
def check_ns(tag_name, prefix, ns, require_uri)
- unless _ns(ns, prefix) == require_uri
- if @do_validate
- raise NSError.new(tag_name, prefix, require_uri)
+ if @do_validate
+ if _ns(ns, prefix) == require_uri
+ #ns.delete(prefix)
else
- # Force bind required URI with prefix
- @ns_stack.last[prefix] = require_uri
+ raise NSError.new(tag_name, prefix, require_uri)
end
end
end
def start_get_text_element(tag_name, prefix, ns, required_uri)
- pr = Proc.new do |text, tags|
+ @proc_stack.push Proc.new {|text, tags|
setter = self.class.setter(required_uri, tag_name)
if @last_element.respond_to?(setter)
- if @do_validate
- getter = self.class.getter(required_uri, tag_name)
- if @last_element.__send__(getter)
- raise TooMuchTagError.new(tag_name, @last_element.tag_name)
- end
- end
@last_element.__send__(setter, text.to_s)
else
if @do_validate and !@ignore_unknown_element
@@ -441,19 +397,16 @@ module RSS
@last_element.tag_name)
end
end
- end
- @proc_stack.push(pr)
+ }
end
def start_have_something_element(tag_name, prefix, attrs, ns, klass)
+
check_ns(tag_name, prefix, ns, klass.required_uri)
- attributes = collect_attributes(tag_name, prefix, attrs, ns, klass)
- @proc_stack.push(setup_next_element(tag_name, klass, attributes))
- end
- def collect_attributes(tag_name, prefix, attrs, ns, klass)
attributes = {}
klass.get_attributes.each do |a_name, a_uri, required, element_name|
+
if a_uri.is_a?(String) or !a_uri.respond_to?(:include?)
a_uri = [a_uri]
end
@@ -482,39 +435,21 @@ module RSS
attributes[a_name] = val
end
- attributes
- end
- def setup_next_element(tag_name, klass, attributes)
previous = @last_element
next_element = klass.new(@do_validate, attributes)
- previous.set_next_element(tag_name, next_element)
+ previous.instance_eval {set_next_element(tag_name, next_element)}
@last_element = next_element
- @last_element.parent = previous if klass.need_parent?
- @xml_child_mode = @last_element.have_xml_content?
-
- Proc.new do |text, tags|
+ @proc_stack.push Proc.new { |text, tags|
p(@last_element.class) if DEBUG
- if @xml_child_mode
- @last_element.content = @xml_element.to_s
- xml_setter = @last_element.class.xml_setter
- @last_element.__send__(xml_setter, @xml_element)
- @xml_element = nil
- @xml_child_mode = false
- else
- if klass.have_content?
- if @last_element.need_base64_encode?
- text = Base64.decode64(text.lstrip)
- end
- @last_element.content = text
- end
- end
+ @last_element.content = text if klass.have_content?
if @do_validate
@last_element.validate_for_stream(tags, @ignore_unknown_element)
end
@last_element = previous
- end
+ }
end
+
end
unless const_defined? :AVAILABLE_PARSER_LIBRARIES
diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb
index 5aa4a2cedd..a06985af94 100644
--- a/lib/rss/rss.rb
+++ b/lib/rss/rss.rb
@@ -11,19 +11,11 @@ class Time
(\.\d+)?
(Z|[+-]\d\d:\d\d)?)?
\s*\z/ix =~ date and (($5 and $8) or (!$5 and !$8))
- datetime = [$1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i]
- usec = 0
- usec = $7.to_f * 1000000 if $7
- zone = $8
- if zone
- off = zone_offset(zone, datetime[0])
- datetime = apply_offset(*(datetime + [off]))
- datetime << usec
- time = Time.utc(*datetime)
- time.localtime unless zone_utc?(zone)
- time
+ datetime = [$1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i]
+ datetime << $7.to_f * 1000000 if $7
+ if $8
+ Time.utc(*datetime) - zone_offset($8)
else
- datetime << usec
Time.local(*datetime)
end
else
@@ -33,15 +25,8 @@ class Time
end
end
- unless method_defined?(:w3cdtf)
- def w3cdtf
- if usec.zero?
- fraction_digits = 0
- else
- fraction_digits = Math.log10(usec.to_s.sub(/0*$/, '').to_i).floor + 1
- end
- xmlschema(fraction_digits)
- end
+ unless instance_methods.include?("w3cdtf")
+ alias w3cdtf iso8601
end
end
@@ -52,7 +37,7 @@ require "rss/xml-stylesheet"
module RSS
- VERSION = "0.2.4"
+ VERSION = "0.1.6"
URI = "http://purl.org/rss/1.0/"
@@ -151,26 +136,17 @@ module RSS
super("required variables of #{@name} are not set: #{@variables.join(', ')}")
end
end
-
- class UnsupportedMakerVersionError < Error
- attr_reader :version
- def initialize(version)
- @version = version
- super("Maker doesn't support version: #{@version}")
- end
- end
-
+
module BaseModel
+
include Utils
- def install_have_child_element(tag_name, uri, occurs, name=nil, type=nil)
+ def install_have_child_element(tag_name, uri, occurs, name=nil)
name ||= tag_name
add_need_initialize_variable(name)
install_model(tag_name, uri, occurs, name)
- writer_type, reader_type = type
- def_corresponded_attr_writer name, writer_type
- def_corresponded_attr_reader name, reader_type
+ attr_accessor name
install_element(name) do |n, elem_name|
<<-EOC
if @#{n}
@@ -188,7 +164,7 @@ EOC
plural_name ||= "#{name}s"
add_have_children_element(name, plural_name)
add_plural_form(name, plural_name)
- install_model(tag_name, uri, occurs, plural_name, true)
+ install_model(tag_name, uri, occurs, plural_name)
def_children_accessor(name, plural_name)
install_element(name, "s") do |n, elem_name|
@@ -203,26 +179,20 @@ EOC
end
end
- def install_text_element(tag_name, uri, occurs, name=nil, type=nil,
- disp_name=nil)
+ def install_text_element(tag_name, uri, occurs, name=nil, type=nil, disp_name=nil)
name ||= tag_name
disp_name ||= name
- self::ELEMENTS << name unless self::ELEMENTS.include?(name)
+ self::ELEMENTS << name
add_need_initialize_variable(name)
install_model(tag_name, uri, occurs, name)
- def_corresponded_attr_writer(name, type, disp_name)
- def_corresponded_attr_reader(name, type || :convert)
+ def_corresponded_attr_writer name, type, disp_name
+ convert_attr_reader name
install_element(name) do |n, elem_name|
<<-EOC
- if respond_to?(:#{n}_content)
- content = #{n}_content
- else
- content = @#{n}
- end
- if content
+ if @#{n}
rv = "\#{indent}<#{elem_name}>"
- value = html_escape(content)
+ value = html_escape(@#{n})
if need_convert
rv << convert(value)
else
@@ -282,112 +252,26 @@ EOC
EOC
end
- def inherit_convert_attr_reader(*attrs)
- attrs.each do |attr|
- attr = attr.id2name if attr.kind_of?(Integer)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{attr}_without_inherit
- convert(@#{attr})
- end
-
- def #{attr}
- if @#{attr}
- #{attr}_without_inherit
- elsif @parent
- @parent.#{attr}
- else
- nil
- end
- end
-EOC
- end
- end
-
- def uri_convert_attr_reader(*attrs)
+ def convert_attr_reader(*attrs)
attrs.each do |attr|
attr = attr.id2name if attr.kind_of?(Integer)
module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{attr}_without_base
- convert(@#{attr})
- end
-
def #{attr}
- value = #{attr}_without_base
- return nil if value.nil?
- if /\\A[a-z][a-z0-9+.\\-]*:/i =~ value
- value
+ if @converter
+ @converter.convert(@#{attr})
else
- "\#{base}\#{value}"
+ @#{attr}
end
end
EOC
end
end
- def convert_attr_reader(*attrs)
- attrs.each do |attr|
- attr = attr.id2name if attr.kind_of?(Integer)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{attr}
- convert(@#{attr})
- end
-EOC
- end
- end
-
- def yes_clean_other_attr_reader(*attrs)
- attrs.each do |attr|
- attr = attr.id2name if attr.kind_of?(Integer)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- attr_reader(:#{attr})
- def #{attr}?
- YesCleanOther.parse(@#{attr})
- end
- EOC
- end
- end
-
- def yes_other_attr_reader(*attrs)
- attrs.each do |attr|
- attr = attr.id2name if attr.kind_of?(Integer)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- attr_reader(:#{attr})
- def #{attr}?
- Utils::YesOther.parse(@#{attr})
- end
- EOC
- end
- end
-
- def csv_attr_reader(*attrs)
- separator = nil
- if attrs.last.is_a?(Hash)
- options = attrs.pop
- separator = options[:separator]
- end
- separator ||= ", "
- attrs.each do |attr|
- attr = attr.id2name if attr.kind_of?(Integer)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- attr_reader(:#{attr})
- def #{attr}_content
- if @#{attr}.nil?
- @#{attr}
- else
- @#{attr}.join(#{separator.dump})
- end
- end
- EOC
- end
- end
-
def date_writer(name, type, disp_name=name)
module_eval(<<-EOC, *get_file_and_line_from_caller(2))
def #{name}=(new_value)
- if new_value.nil?
+ if new_value.nil? or new_value.kind_of?(Time)
@#{name} = new_value
- elsif new_value.kind_of?(Time)
- @#{name} = new_value.dup
else
if @do_validate
begin
@@ -399,9 +283,7 @@ EOC
@#{name} = nil
if /\\A\\s*\\z/ !~ new_value.to_s
begin
- unless Date._parse(new_value, false).empty?
- @#{name} = Time.parse(new_value)
- end
+ @#{name} = Time.parse(new_value)
rescue ArgumentError
end
end
@@ -482,68 +364,6 @@ EOC
EOC
end
- def text_type_writer(name, disp_name=name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if @do_validate and
- !["text", "html", "xhtml", nil].include?(new_value)
- raise NotAvailableValueError.new('#{disp_name}', new_value)
- end
- @#{name} = new_value
- end
-EOC
- end
-
- def content_writer(name, disp_name=name)
- klass_name = "self.class::#{Utils.to_class_name(name)}"
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if new_value.is_a?(#{klass_name})
- @#{name} = new_value
- else
- @#{name} = #{klass_name}.new
- @#{name}.content = new_value
- end
- end
-EOC
- end
-
- def yes_clean_other_writer(name, disp_name=name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(value)
- value = (value ? "yes" : "no") if [true, false].include?(value)
- @#{name} = value
- end
- EOC
- end
-
- def yes_other_writer(name, disp_name=name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(new_value)
- if [true, false].include?(new_value)
- new_value = new_value ? "yes" : "no"
- end
- @#{name} = new_value
- end
- EOC
- end
-
- def csv_writer(name, disp_name=name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(new_value)
- @#{name} = Utils::CSV.parse(new_value)
- end
- EOC
- end
-
- def csv_integer_writer(name, disp_name=name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(new_value)
- @#{name} = Utils::CSV.parse(new_value) {|v| Integer(v)}
- end
- EOC
- end
-
def def_children_accessor(accessor_name, plural_name)
module_eval(<<-EOC, *get_file_and_line_from_caller(2))
def #{plural_name}
@@ -559,12 +379,10 @@ EOC
end
def #{accessor_name}=(*args)
- receiver = self.class.name
warn("Warning:\#{caller.first.sub(/:in `.*'\z/, '')}: " \
- "Don't use `\#{receiver}\##{accessor_name} = XXX'/" \
- "`\#{receiver}\#set_#{accessor_name}(XXX)'. " \
+ "Don't use `#{accessor_name} = XXX'/`set_#{accessor_name}(XXX)'. " \
"Those APIs are not sense of Ruby. " \
- "Use `\#{receiver}\##{plural_name} << XXX' instead of them.")
+ "Use `#{plural_name} << XXX' instead of them.")
if args.size == 1
@#{accessor_name}.push(args[0])
else
@@ -576,61 +394,10 @@ EOC
end
end
- module SetupMaker
- def setup_maker(maker)
- target = maker_target(maker)
- unless target.nil?
- setup_maker_attributes(target)
- setup_maker_element(target)
- setup_maker_elements(target)
- end
- end
-
- private
- def maker_target(maker)
- nil
- end
-
- def setup_maker_attributes(target)
- end
-
- def setup_maker_element(target)
- self.class.need_initialize_variables.each do |var|
- value = __send__(var)
- next if value.nil?
- if value.respond_to?("setup_maker") and
- !not_need_to_call_setup_maker_variables.include?(var)
- value.setup_maker(target)
- else
- setter = "#{var}="
- if target.respond_to?(setter)
- target.__send__(setter, value)
- end
- end
- end
- end
-
- def not_need_to_call_setup_maker_variables
- []
- end
-
- def setup_maker_elements(parent)
- self.class.have_children_elements.each do |name, plural_name|
- if parent.respond_to?(plural_name)
- target = parent.__send__(plural_name)
- __send__(plural_name).each do |elem|
- elem.setup_maker(target)
- end
- end
- end
- end
- end
-
class Element
+
extend BaseModel
include Utils
- extend Utils::InheritedReader
- include SetupMaker
INDENT = " "
@@ -641,34 +408,32 @@ EOC
TO_ELEMENT_METHODS = []
NEED_INITIALIZE_VARIABLES = []
PLURAL_FORMS = {}
-
+
class << self
+
def must_call_validators
- inherited_hash_reader("MUST_CALL_VALIDATORS")
+ MUST_CALL_VALIDATORS
end
def models
- inherited_array_reader("MODELS")
+ MODELS
end
def get_attributes
- inherited_array_reader("GET_ATTRIBUTES")
+ GET_ATTRIBUTES
end
def have_children_elements
- inherited_array_reader("HAVE_CHILDREN_ELEMENTS")
+ HAVE_CHILDREN_ELEMENTS
end
def to_element_methods
- inherited_array_reader("TO_ELEMENT_METHODS")
+ TO_ELEMENT_METHODS
end
def need_initialize_variables
- inherited_array_reader("NEED_INITIALIZE_VARIABLES")
+ NEED_INITIALIZE_VARIABLES
end
def plural_forms
- inherited_hash_reader("PLURAL_FORMS")
- end
-
- def inherited_base
- ::RSS::Element
+ PLURAL_FORMS
end
+
def inherited(klass)
klass.const_set("MUST_CALL_VALIDATORS", {})
klass.const_set("MODELS", [])
@@ -678,112 +443,105 @@ EOC
klass.const_set("NEED_INITIALIZE_VARIABLES", [])
klass.const_set("PLURAL_FORMS", {})
- tag_name = klass.name.split(/::/).last
- tag_name[0, 1] = tag_name[0, 1].downcase
- klass.instance_variable_set("@tag_name", tag_name)
- klass.instance_variable_set("@have_content", false)
- end
-
- def install_must_call_validator(prefix, uri)
- self::MUST_CALL_VALIDATORS[uri] = prefix
- end
+ klass.module_eval(<<-EOC)
+ public
+
+ @tag_name = name.split(/::/).last
+ @tag_name[0,1] = @tag_name[0,1].downcase
+ @have_content = false
- def install_model(tag, uri, occurs=nil, getter=nil, plural=false)
- getter ||= tag
- if m = self::MODELS.find {|t, u, o, g, p| t == tag and u == uri}
- m[2] = occurs
- else
- self::MODELS << [tag, uri, occurs, getter, plural]
+ def self.must_call_validators
+ super.merge(MUST_CALL_VALIDATORS)
end
- end
-
- def install_get_attribute(name, uri, required=true,
- type=nil, disp_name=nil,
- element_name=nil)
- disp_name ||= name
- element_name ||= name
- writer_type, reader_type = type
- def_corresponded_attr_writer name, writer_type, disp_name
- def_corresponded_attr_reader name, reader_type
- if type == :boolean and /^is/ =~ name
- alias_method "#{$POSTMATCH}?", name
+ def self.models
+ MODELS + super
+ end
+ def self.get_attributes
+ GET_ATTRIBUTES + super
+ end
+ def self.have_children_elements
+ HAVE_CHILDREN_ELEMENTS + super
+ end
+ def self.to_element_methods
+ TO_ELEMENT_METHODS + super
+ end
+ def self.need_initialize_variables
+ NEED_INITIALIZE_VARIABLES + super
+ end
+ def self.plural_forms
+ super.merge(PLURAL_FORMS)
end
- self::GET_ATTRIBUTES << [name, uri, required, element_name]
- add_need_initialize_variable(disp_name)
- end
- def def_corresponded_attr_writer(name, type=nil, disp_name=nil)
- disp_name ||= name
- case type
- when :integer
- integer_writer name, disp_name
- when :positive_integer
- positive_integer_writer name, disp_name
- when :boolean
- boolean_writer name, disp_name
- when :w3cdtf, :rfc822, :rfc2822
- date_writer name, type, disp_name
- when :text_type
- text_type_writer name, disp_name
- when :content
- content_writer name, disp_name
- when :yes_clean_other
- yes_clean_other_writer name, disp_name
- when :yes_other
- yes_other_writer name, disp_name
- when :csv
- csv_writer name
- when :csv_integer
- csv_integer_writer name
- else
- attr_writer name
+
+ def self.install_must_call_validator(prefix, uri)
+ MUST_CALL_VALIDATORS[uri] = prefix
+ end
+
+ def self.install_model(tag, uri, occurs=nil, getter=nil)
+ getter ||= tag
+ if m = MODELS.find {|t, u, o, g| t == tag and u == uri}
+ m[2] = occurs
+ else
+ MODELS << [tag, uri, occurs, getter]
+ end
end
- end
- def def_corresponded_attr_reader(name, type=nil)
- case type
- when :inherit
- inherit_convert_attr_reader name
- when :uri
- uri_convert_attr_reader name
- when :yes_clean_other
- yes_clean_other_attr_reader name
- when :yes_other
- yes_other_attr_reader name
- when :csv
- csv_attr_reader name
- when :csv_integer
- csv_attr_reader name, :separator => ","
- else
+ def self.install_get_attribute(name, uri, required=true,
+ type=nil, disp_name=nil,
+ element_name=nil)
+ disp_name ||= name
+ element_name ||= name
+ def_corresponded_attr_writer name, type, disp_name
convert_attr_reader name
+ if type == :boolean and /^is/ =~ name
+ alias_method "\#{$POSTMATCH}?", name
+ end
+ GET_ATTRIBUTES << [name, uri, required, element_name]
+ add_need_initialize_variable(disp_name)
+ end
+
+ def self.def_corresponded_attr_writer(name, type=nil, disp_name=name)
+ case type
+ when :integer
+ integer_writer name, disp_name
+ when :positive_integer
+ positive_integer_writer name, disp_name
+ when :boolean
+ boolean_writer name, disp_name
+ when :w3cdtf, :rfc822, :rfc2822
+ date_writer name, type, disp_name
+ else
+ attr_writer name
+ end
end
- end
- def content_setup(type=nil, disp_name=nil)
- writer_type, reader_type = type
- def_corresponded_attr_writer :content, writer_type, disp_name
- def_corresponded_attr_reader :content, reader_type
- @have_content = true
- end
-
- def have_content?
- @have_content
- end
-
- def add_have_children_element(variable_name, plural_name)
- self::HAVE_CHILDREN_ELEMENTS << [variable_name, plural_name]
- end
+ def self.content_setup(type=nil)
+ def_corresponded_attr_writer "content", type
+ convert_attr_reader :content
+ @have_content = true
+ end
- def add_to_element_method(method_name)
- self::TO_ELEMENT_METHODS << method_name
- end
+ def self.have_content?
+ @have_content
+ end
- def add_need_initialize_variable(variable_name)
- self::NEED_INITIALIZE_VARIABLES << variable_name
- end
+ def self.add_have_children_element(variable_name, plural_name)
+ HAVE_CHILDREN_ELEMENTS << [variable_name, plural_name]
+ end
+
+ def self.add_to_element_method(method_name)
+ TO_ELEMENT_METHODS << method_name
+ end
- def add_plural_form(singular, plural)
- self::PLURAL_FORMS[singular] = plural
+ def self.add_need_initialize_variable(variable_name)
+ NEED_INITIALIZE_VARIABLES << variable_name
+ end
+
+ def self.add_plural_form(singular, plural)
+ PLURAL_FORMS[singular] = plural
+ end
+
+ EOC
end
def required_prefix
@@ -793,11 +551,7 @@ EOC
def required_uri
""
end
-
- def need_parent?
- false
- end
-
+
def install_ns(prefix, uri)
if self::NSPOOL.has_key?(prefix)
raise OverlappedPrefixError.new(prefix)
@@ -810,16 +564,12 @@ EOC
end
end
- attr_accessor :parent, :do_validate
+ attr_accessor :do_validate
- def initialize(do_validate=true, attrs=nil)
- @parent = nil
+ def initialize(do_validate=true, attrs={})
@converter = nil
- if attrs.nil? and (do_validate.is_a?(Hash) or do_validate.is_a?(Array))
- do_validate, attrs = true, do_validate
- end
@do_validate = do_validate
- initialize_variables(attrs || {})
+ initialize_variables(attrs)
end
def tag_name
@@ -848,21 +598,10 @@ EOC
value
end
end
-
- def valid?(ignore_unknown_element=true)
- validate(ignore_unknown_element)
- true
- rescue RSS::Error
- false
- end
-
+
def validate(ignore_unknown_element=true)
- do_validate = @do_validate
- @do_validate = true
validate_attribute
__validate(ignore_unknown_element)
- ensure
- @do_validate = do_validate
end
def validate_for_stream(tags, ignore_unknown_element=true)
@@ -870,15 +609,20 @@ EOC
__validate(ignore_unknown_element, tags, false)
end
+ def setup_maker(maker)
+ target = maker_target(maker)
+ unless target.nil?
+ setup_maker_attributes(target)
+ setup_maker_element(target)
+ setup_maker_elements(target)
+ end
+ end
+
def to_s(need_convert=true, indent='')
if self.class.have_content?
- return "" if !empty_content? and !content_is_set?
+ return "" unless @content
rv = tag(indent) do |next_indent|
- if empty_content?
- ""
- else
- xmled_content
- end
+ h(@content)
end
else
rv = tag(indent) do |next_indent|
@@ -891,44 +635,6 @@ EOC
rv
end
- def have_xml_content?
- false
- end
-
- def need_base64_encode?
- false
- end
-
- def set_next_element(tag_name, next_element)
- klass = next_element.class
- prefix = ""
- prefix << "#{klass.required_prefix}_" if klass.required_prefix
- key = "#{prefix}#{tag_name.gsub(/-/, '_')}"
- if self.class.plural_forms.has_key?(key)
- ary = __send__("#{self.class.plural_forms[key]}")
- ary << next_element
- else
- __send__("#{key}=", next_element)
- end
- end
-
- protected
- def have_required_elements?
- self.class::MODELS.all? do |tag, uri, occurs, getter|
- if occurs.nil? or occurs == "+"
- child = __send__(getter)
- if child.is_a?(Array)
- children = child
- children.any? {|c| c.have_required_elements?}
- else
- !child.to_s.empty?
- end
- else
- true
- end
- end
- end
-
private
def initialize_variables(attrs)
normalized_attrs = {}
@@ -940,16 +646,16 @@ EOC
if value
__send__("#{variable_name}=", value)
else
- instance_variable_set("@#{variable_name}", nil)
+ instance_eval("@#{variable_name} = nil")
end
end
initialize_have_children_elements
- @content = normalized_attrs["content"] if self.class.have_content?
+ @content = "" if self.class.have_content?
end
def initialize_have_children_elements
self.class.have_children_elements.each do |variable_name, plural_name|
- instance_variable_set("@#{variable_name}", [])
+ instance_eval("@#{variable_name} = []")
end
end
@@ -959,10 +665,8 @@ EOC
attrs = collect_attrs
return "" if attrs.nil?
- return "" unless have_required_elements?
-
attrs.update(additional_attrs)
- start_tag = make_start_tag(indent, next_indent, attrs.dup)
+ start_tag = make_start_tag(indent, next_indent, attrs)
if block
content = block.call(next_indent)
@@ -977,7 +681,6 @@ EOC
else
content = content.reject{|x| x.empty?}
if content.empty?
- return "" if attrs.empty?
end_tag = "/>"
else
start_tag << ">\n"
@@ -1019,6 +722,56 @@ EOC
''
end
+ def maker_target(maker)
+ nil
+ end
+
+ def setup_maker_attributes(target)
+ end
+
+ def setup_maker_element(target)
+ self.class.need_initialize_variables.each do |var|
+ value = __send__(var)
+ if value.respond_to?("setup_maker") and
+ !not_need_to_call_setup_maker_variables.include?(var)
+ value.setup_maker(target)
+ else
+ setter = "#{var}="
+ if target.respond_to?(setter)
+ target.__send__(setter, value)
+ end
+ end
+ end
+ end
+
+ def not_need_to_call_setup_maker_variables
+ []
+ end
+
+ def setup_maker_elements(parent)
+ self.class.have_children_elements.each do |name, plural_name|
+ if parent.respond_to?(plural_name)
+ target = parent.__send__(plural_name)
+ __send__(plural_name).each do |elem|
+ elem.setup_maker(target)
+ end
+ end
+ end
+ end
+
+ def set_next_element(tag_name, next_element)
+ klass = next_element.class
+ prefix = ""
+ prefix << "#{klass.required_prefix}_" if klass.required_prefix
+ key = "#{prefix}#{tag_name}"
+ if self.class.plural_forms.has_key?(key)
+ ary = __send__("#{self.class.plural_forms[key]}")
+ ary << next_element
+ else
+ __send__("#{prefix}#{tag_name}=", next_element)
+ end
+ end
+
def children
rv = []
self.class.models.each do |name, uri, occurs, getter|
@@ -1034,10 +787,10 @@ EOC
def _tags
rv = []
- self.class.models.each do |name, uri, occurs, getter, plural|
+ self.class.models.each do |name, uri, occurs, getter|
value = __send__(getter)
next if value.nil?
- if plural and value.is_a?(Array)
+ if value.is_a?(Array)
rv.concat([[uri, name]] * value.size)
else
rv << [uri, name]
@@ -1064,7 +817,7 @@ EOC
must_call_validators.each do |uri, prefix|
_validate(ignore_unknown_element, tags[uri], uri)
meth = "#{prefix}_validate"
- if !prefix.empty? and respond_to?(meth, true)
+ if respond_to?(meth, true)
__send__(meth, ignore_unknown_element, tags[uri], uri)
end
end
@@ -1072,11 +825,9 @@ EOC
def validate_attribute
_attrs.each do |a_name, required, alias_name|
- value = instance_variable_get("@#{alias_name || a_name}")
- if required and value.nil?
+ if required and __send__(alias_name || a_name).nil?
raise MissingAttributeError.new(tag_name, a_name)
end
- __send__("#{alias_name || a_name}=", value)
end
end
@@ -1092,12 +843,11 @@ EOC
tags = tags.sort_by {|x| element_names.index(x) || tags_size}
end
- _tags = tags.dup if tags
models.each_with_index do |model, i|
name, model_uri, occurs, getter = model
if DEBUG
- p "before"
+ p "before"
p tags
p model
end
@@ -1183,27 +933,6 @@ EOC
rv
end
- def empty_content?
- false
- end
-
- def content_is_set?
- if have_xml_content?
- __send__(self.class.xml_getter)
- else
- content
- end
- end
-
- def xmled_content
- if have_xml_content?
- __send__(self.class.xml_getter).to_s
- else
- _content = content
- _content = Base64.encode64(_content) if need_base64_encode?
- h(_content)
- end
- end
end
module RootElementMixin
@@ -1211,23 +940,16 @@ EOC
include XMLStyleSheetMixin
attr_reader :output_encoding
- attr_reader :feed_type, :feed_subtype, :feed_version
- attr_accessor :version, :encoding, :standalone
- def initialize(feed_version, version=nil, encoding=nil, standalone=nil)
+
+ def initialize(rss_version, version=nil, encoding=nil, standalone=nil)
super()
- @feed_type = nil
- @feed_subtype = nil
- @feed_version = feed_version
+ @rss_version = rss_version
@version = version || '1.0'
@encoding = encoding
@standalone = standalone
@output_encoding = nil
end
- def feed_info
- [@feed_type, @feed_version, @feed_subtype]
- end
-
def output_encoding=(enc)
@output_encoding = enc
self.converter = Converter.new(@output_encoding, @encoding)
@@ -1242,48 +964,25 @@ EOC
xss.setup_maker(maker)
end
- super
- end
-
- def to_feed(type, &block)
- Maker.make(type) do |maker|
- setup_maker(maker)
- block.call(maker) if block
- end
- end
-
- def to_rss(type, &block)
- to_feed("rss#{type}", &block)
+ setup_maker_elements(maker)
end
- def to_atom(type, &block)
- to_feed("atom:#{type}", &block)
- end
-
- def to_xml(type=nil, &block)
- if type.nil? or same_feed_type?(type)
+ def to_xml(version=nil, &block)
+ if version.nil? or version == @rss_version
to_s
else
- to_feed(type, &block).to_s
+ RSS::Maker.make(version) do |maker|
+ setup_maker(maker)
+ block.call(maker) if block
+ end.to_s
end
end
private
- def same_feed_type?(type)
- if /^(atom|rss)?(\d+\.\d+)?(?::(.+))?$/i =~ type
- feed_type = ($1 || @feed_type).downcase
- feed_version = $2 || @feed_version
- feed_subtype = $3 || @feed_subtype
- [feed_type, feed_version, feed_subtype] == feed_info
- else
- false
- end
- end
-
def tag(indent, attrs={}, &block)
- rv = super(indent, ns_declarations.merge(attrs), &block)
- return rv if rv.empty?
- "#{xmldecl}#{xml_stylesheet_pi}#{rv}"
+ rv = xmldecl + xml_stylesheet_pi
+ rv << super(indent, ns_declarations.merge(attrs), &block)
+ rv
end
def xmldecl
@@ -1304,9 +1003,13 @@ EOC
end
decls
end
-
- def maker_target(target)
- target
+
+ def setup_maker_elements(maker)
+ channel.setup_maker(maker) if channel
+ image.setup_maker(maker) if image
+ textinput.setup_maker(maker) if textinput
+ super(maker)
end
end
+
end
diff --git a/lib/rss/slash.rb b/lib/rss/slash.rb
deleted file mode 100644
index f102413b46..0000000000
--- a/lib/rss/slash.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-require 'rss/1.0'
-
-module RSS
- SLASH_PREFIX = 'slash'
- SLASH_URI = "http://purl.org/rss/1.0/modules/slash/"
-
- RDF.install_ns(SLASH_PREFIX, SLASH_URI)
-
- module SlashModel
- extend BaseModel
-
- ELEMENT_INFOS = \
- [
- ["section"],
- ["department"],
- ["comments", :positive_integer],
- ["hit_parade", :csv_integer],
- ]
-
- class << self
- def append_features(klass)
- super
-
- return if klass.instance_of?(Module)
- klass.install_must_call_validator(SLASH_PREFIX, SLASH_URI)
- ELEMENT_INFOS.each do |name, type, *additional_infos|
- full_name = "#{SLASH_PREFIX}_#{name}"
- klass.install_text_element(full_name, SLASH_URI, "?",
- full_name, type, name)
- end
-
- klass.module_eval do
- alias_method(:slash_hit_parades, :slash_hit_parade)
- undef_method(:slash_hit_parade)
- alias_method(:slash_hit_parade, :slash_hit_parade_content)
- end
- end
- end
- end
-
- class RDF
- class Item; include SlashModel; end
- end
-
- SlashModel::ELEMENT_INFOS.each do |name, type|
- accessor_base = "#{SLASH_PREFIX}_#{name}"
- BaseListener.install_get_text_element(SLASH_URI, name, accessor_base)
- end
-end
diff --git a/lib/rss/syndication.rb b/lib/rss/syndication.rb
index 3eb15429f6..93d35c89a7 100644
--- a/lib/rss/syndication.rb
+++ b/lib/rss/syndication.rb
@@ -29,19 +29,16 @@ module RSS
%w(updateBase).each do |name|
install_date_element(name, SY_URI, "?",
- "#{SY_PREFIX}_#{name}", 'w3cdtf',
- "#{SY_PREFIX}:#{name}")
+ "#{SY_PREFIX}_#{name}", 'w3cdtf', name)
end
- end
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
def sy_updatePeriod=(new_value)
new_value = new_value.strip
validate_sy_updatePeriod(new_value) if @do_validate
self._sy_updatePeriod = new_value
end
- EOC
+ end
end
private
@@ -61,7 +58,7 @@ module RSS
SyndicationModel::ELEMENTS.uniq!
SyndicationModel::ELEMENTS.each do |full_name|
name = full_name[prefix_size..-1]
- BaseListener.install_get_text_element(SY_URI, name, full_name)
+ BaseListener.install_get_text_element(SY_URI, name, "#{full_name}=")
end
end
diff --git a/lib/rss/taxonomy.rb b/lib/rss/taxonomy.rb
index 276f63b05d..8caa25e2a4 100644
--- a/lib/rss/taxonomy.rb
+++ b/lib/rss/taxonomy.rb
@@ -12,7 +12,7 @@ module RSS
%w(link).each do |name|
full_name = "#{TAXO_PREFIX}_#{name}"
- BaseListener.install_get_text_element(TAXO_URI, name, full_name)
+ BaseListener.install_get_text_element(TAXO_URI, name, "#{full_name}=")
TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
end
diff --git a/lib/rss/utils.rb b/lib/rss/utils.rb
index 0e4001e1f3..b242a72292 100644
--- a/lib/rss/utils.rb
+++ b/lib/rss/utils.rb
@@ -4,16 +4,14 @@ module RSS
# Convert a name_with_underscores to CamelCase.
def to_class_name(name)
- name.split(/[_\-]/).collect do |part|
+ name.split(/_/).collect do |part|
"#{part[0, 1].upcase}#{part[1..-1]}"
end.join("")
end
def get_file_and_line_from_caller(i=0)
file, line, = caller[i].split(':')
- line = line.to_i
- line += 1 if i.zero?
- [file, line]
+ [file, line.to_i]
end
# escape '&', '"', '<' and '>' for use in HTML.
@@ -35,77 +33,5 @@ module RSS
def element_initialize_arguments?(args)
[true, false].include?(args[0]) and args[1].is_a?(Hash)
end
-
- module YesCleanOther
- module_function
- def parse(value)
- if [true, false, nil].include?(value)
- value
- else
- case value.to_s
- when /\Ayes\z/i
- true
- when /\Aclean\z/i
- false
- else
- nil
- end
- end
- end
- end
-
- module YesOther
- module_function
- def parse(value)
- if [true, false].include?(value)
- value
- else
- /\Ayes\z/i.match(value.to_s) ? true : false
- end
- end
- end
-
- module CSV
- module_function
- def parse(value, &block)
- if value.is_a?(String)
- value = value.strip.split(/\s*,\s*/)
- value = value.collect(&block) if block_given?
- value
- else
- value
- end
- end
- end
-
- module InheritedReader
- def inherited_reader(constant_name)
- base_class = inherited_base
- result = base_class.const_get(constant_name)
- found_base_class = false
- ancestors.reverse_each do |klass|
- if found_base_class
- if klass.const_defined?(constant_name)
- result = yield(result, klass.const_get(constant_name))
- end
- else
- found_base_class = klass == base_class
- end
- end
- result
- end
-
- def inherited_array_reader(constant_name)
- inherited_reader(constant_name) do |result, current|
- current + result
- end
- end
-
- def inherited_hash_reader(constant_name)
- inherited_reader(constant_name) do |result, current|
- result.merge(current)
- end
- end
- end
end
end
diff --git a/lib/rss/xml-stylesheet.rb b/lib/rss/xml-stylesheet.rb
index 559d6bcd56..66e3161dd0 100644
--- a/lib/rss/xml-stylesheet.rb
+++ b/lib/rss/xml-stylesheet.rb
@@ -35,10 +35,6 @@ module RSS
attr_accessor(*ATTRIBUTES)
attr_accessor(:do_validate)
def initialize(*attrs)
- if attrs.size == 1 and
- (attrs.first.is_a?(Hash) or attrs.first.is_a?(Array))
- attrs = attrs.first
- end
@do_validate = true
ATTRIBUTES.each do |attr|
__send__("#{attr}=", nil)
diff --git a/lib/rss/xml.rb b/lib/rss/xml.rb
deleted file mode 100644
index 1ae878b772..0000000000
--- a/lib/rss/xml.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-require "rss/utils"
-
-module RSS
- module XML
- class Element
- include Enumerable
-
- attr_reader :name, :prefix, :uri, :attributes, :children
- def initialize(name, prefix=nil, uri=nil, attributes={}, children=[])
- @name = name
- @prefix = prefix
- @uri = uri
- @attributes = attributes
- if children.is_a?(String) or !children.respond_to?(:each)
- @children = [children]
- else
- @children = children
- end
- end
-
- def [](name)
- @attributes[name]
- end
-
- def []=(name, value)
- @attributes[name] = value
- end
-
- def <<(child)
- @children << child
- end
-
- def each(&block)
- @children.each(&block)
- end
-
- def ==(other)
- other.kind_of?(self.class) and
- @name == other.name and
- @uri == other.uri and
- @attributes == other.attributes and
- @children == other.children
- end
-
- def to_s
- rv = "<#{full_name}"
- attributes.each do |key, value|
- rv << " #{Utils.html_escape(key)}=\"#{Utils.html_escape(value)}\""
- end
- if children.empty?
- rv << "/>"
- else
- rv << ">"
- children.each do |child|
- rv << child.to_s
- end
- rv << "</#{full_name}>"
- end
- rv
- end
-
- def full_name
- if @prefix
- "#{@prefix}:#{@name}"
- else
- @name
- end
- end
- end
- end
-end
diff --git a/lib/securerandom.rb b/lib/securerandom.rb
deleted file mode 100644
index 3fd63e535f..0000000000
--- a/lib/securerandom.rb
+++ /dev/null
@@ -1,137 +0,0 @@
-# = Secure random number generator interface.
-#
-# This library is an interface for secure random number generator which is
-# suitable for generating session key in HTTP cookies, etc.
-#
-# It supports following secure random number generators.
-#
-# * openssl
-# * /dev/urandom
-#
-# == Example
-#
-# # random hexadecimal string.
-# p SecureRandom.hex(10) #=> "52750b30ffbc7de3b362"
-# p SecureRandom.hex(10) #=> "92b15d6c8dc4beb5f559"
-# p SecureRandom.hex(11) #=> "6aca1b5c58e4863e6b81b8"
-# p SecureRandom.hex(12) #=> "94b2fff3e7fd9b9c391a2306"
-# p SecureRandom.hex(13) #=> "39b290146bea6ce975c37cfc23"
-# ...
-#
-# # random base64 string.
-# p SecureRandom.base64(10) #=> "EcmTPZwWRAozdA=="
-# p SecureRandom.base64(10) #=> "9b0nsevdwNuM/w=="
-# p SecureRandom.base64(10) #=> "KO1nIU+p9DKxGg=="
-# p SecureRandom.base64(11) #=> "l7XEiFja+8EKEtY="
-# p SecureRandom.base64(12) #=> "7kJSM/MzBJI+75j8"
-# p SecureRandom.base64(13) #=> "vKLJ0tXBHqQOuIcSIg=="
-# ...
-#
-# # random binary string.
-# p SecureRandom.random_bytes(10) #=> "\016\t{\370g\310pbr\301"
-# p SecureRandom.random_bytes(10) #=> "\323U\030TO\234\357\020\a\337"
-# ...
-
-begin
- require 'openssl'
-rescue LoadError
-end
-
-module SecureRandom
- # SecureRandom.random_bytes generates a random binary string.
- #
- # The argument n specifies the length of the result string.
- #
- # If n is not specified, 16 is assumed.
- # It may be larger in future.
- #
- # If secure random number generator is not available,
- # NotImplementedError is raised.
- def self.random_bytes(n=nil)
- n ||= 16
- if defined? OpenSSL::Random
- return OpenSSL::Random.random_bytes(n)
- end
- if !defined?(@has_urandom) || @has_urandom
- @has_urandom = false
- flags = File::RDONLY
- flags |= File::NONBLOCK if defined? File::NONBLOCK
- flags |= File::NOCTTY if defined? File::NOCTTY
- flags |= File::NOFOLLOW if defined? File::NOFOLLOW
- begin
- File.open("/dev/urandom", flags) {|f|
- unless f.stat.chardev?
- raise Errno::ENOENT
- end
- @has_urandom = true
- ret = f.readpartial(n)
- if ret.length != n
- raise NotImplementedError, "Unexpected partial read from random device"
- end
- return ret
- }
- rescue Errno::ENOENT
- raise NotImplementedError, "No random device"
- end
- end
- raise NotImplementedError, "No random device"
- end
-
- # SecureRandom.hex generates a random hex string.
- #
- # The argument n specifies the length of the random length.
- # The length of the result string is twice of n.
- #
- # If n is not specified, 16 is assumed.
- # It may be larger in future.
- #
- # If secure random number generator is not available,
- # NotImplementedError is raised.
- def self.hex(n=nil)
- random_bytes(n).unpack("H*")[0]
- end
-
- # SecureRandom.base64 generates a random base64 string.
- #
- # The argument n specifies the length of the random length.
- # The length of the result string is about 4/3 of n.
- #
- # If n is not specified, 16 is assumed.
- # It may be larger in future.
- #
- # If secure random number generator is not available,
- # NotImplementedError is raised.
- def self.base64(n=nil)
- [random_bytes(n)].pack("m*").delete("\n")
- end
-
- # SecureRandom.random_number generates a random number.
- #
- # If an positive integer is given as n,
- # SecureRandom.random_number returns an integer:
- # 0 <= SecureRandom.random_number(n) < n.
- #
- # If 0 is given or an argument is not given,
- # SecureRandom.random_number returns an float:
- # 0.0 <= SecureRandom.random_number() < 1.0.
- def self.random_number(n=0)
- if 0 < n
- hex = n.to_s(16)
- hex = '0' + hex if (hex.length & 1) == 1
- bin = [hex].pack("H*")
- mask = bin[0]
- mask |= mask >> 1
- mask |= mask >> 2
- mask |= mask >> 4
- begin
- rnd = SecureRandom.random_bytes(bin.length)
- rnd[0] = (rnd[0] & mask).chr
- end until rnd < bin
- rnd.unpack("H*")[0].hex
- else
- # assumption: Float::MANT_DIG <= 64
- i64 = SecureRandom.random_bytes(8).unpack("Q")[0]
- Math.ldexp(i64 >> (64-Float::MANT_DIG), -Float::MANT_DIG)
- end
- end
-end
diff --git a/lib/set.rb b/lib/set.rb
index 164aa429d9..5a9287ba89 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -2,7 +2,7 @@
#--
# set.rb - defines the Set class
#++
-# Copyright (c) 2002-2008 Akinori MUSHA <knu@iDaemons.org>
+# Copyright (c) 2002 Akinori MUSHA <knu@iDaemons.org>
#
# Documentation by Akinori MUSHA and Gavin Sinclair.
#
@@ -48,10 +48,6 @@
# s1.subset? s2 # -> false
# s2.subset? s1 # -> true
#
-# == Contact
-#
-# - Akinori MUSHA <knu@iDaemons.org> (current maintainer)
-#
class Set
include Enumerable
@@ -188,10 +184,8 @@ class Set
end
# Calls the given block once for each element in the set, passing
- # the element as parameter. Returns an enumerator if no block is
- # given.
+ # the element as parameter.
def each
- block_given? or return enum_for(__method__)
@hash.each_key { |o| yield(o) }
self
end
@@ -234,7 +228,7 @@ class Set
# Deletes every element of the set for which block evaluates to
# true, and returns self.
def delete_if
- to_a.each { |o| @hash.delete(o) if yield(o) }
+ @hash.delete_if { |o,| yield(o) }
self
end
@@ -492,7 +486,7 @@ class SortedSet < Set
def delete_if
n = @hash.size
- super
+ @hash.delete_if { |o,| yield(o) }
@keys = nil if @hash.size != n
self
end
@@ -503,9 +497,7 @@ class SortedSet < Set
end
def each
- block_given? or return enum_for(__method__)
to_a.each { |o| yield(o) }
- self
end
def to_a
@@ -922,11 +914,9 @@ class TC_Set < Test::Unit::TestCase
ary = [1,3,5,7,10,20]
set = Set.new(ary)
- ret = set.each { |o| }
- assert_same(set, ret)
-
- e = set.each
- assert_instance_of(Enumerable::Enumerator, e)
+ assert_raises(LocalJumpError) {
+ set.each
+ }
assert_nothing_raised {
set.each { |o|
@@ -1171,33 +1161,11 @@ class TC_SortedSet < Test::Unit::TestCase
assert_equal([-10,-8,-6,-4,-2], s.to_a)
prev = nil
- ret = s.each { |o| assert(prev < o) if prev; prev = o }
+ s.each { |o| assert(prev < o) if prev; prev = o }
assert_not_nil(prev)
- assert_same(s, ret)
s = SortedSet.new([2,1,3]) { |o| o * -2 }
assert_equal([-6,-4,-2], s.to_a)
-
- s = SortedSet.new(['one', 'two', 'three', 'four'])
- a = []
- ret = s.delete_if { |o| a << o; o.start_with?('t') }
- assert_same(s, ret)
- assert_equal(['four', 'one'], s.to_a)
- assert_equal(['four', 'one', 'three', 'two'], a)
-
- s = SortedSet.new(['one', 'two', 'three', 'four'])
- a = []
- ret = s.reject! { |o| a << o; o.start_with?('t') }
- assert_same(s, ret)
- assert_equal(['four', 'one'], s.to_a)
- assert_equal(['four', 'one', 'three', 'two'], a)
-
- s = SortedSet.new(['one', 'two', 'three', 'four'])
- a = []
- ret = s.reject! { |o| a << o; false }
- assert_same(nil, ret)
- assert_equal(['four', 'one', 'three', 'two'], s.to_a)
- assert_equal(['four', 'one', 'three', 'two'], a)
end
end
diff --git a/lib/shellwords.rb b/lib/shellwords.rb
index a4ec552a7e..e87b9e656b 100644
--- a/lib/shellwords.rb
+++ b/lib/shellwords.rb
@@ -1,35 +1,31 @@
#
-# shellwords.rb: Manipulates strings a la UNIX Bourne shell
+# shellwords.rb: Split text into an array of tokens a la UNIX shell
#
#
-# This module manipulates strings according to the word parsing rules
-# of the UNIX Bourne shell.
+# This module is originally a port of shellwords.pl, but modified to
+# conform to POSIX / SUSv3 (IEEE Std 1003.1-2001).
#
-# The shellwords() function was originally a port of shellwords.pl,
-# but modified to conform to POSIX / SUSv3 (IEEE Std 1003.1-2001).
+# Examples:
#
-# Authors:
-# - Wakou Aoyama
-# - Akinori MUSHA <knu@iDaemons.org>
+# require 'shellwords'
+# words = Shellwords.shellwords(line)
#
-# Contact:
-# - Akinori MUSHA <knu@iDaemons.org> (current maintainer)
+# or
+#
+# require 'shellwords'
+# include Shellwords
+# words = shellwords(line)
#
module Shellwords
+
#
- # Splits a string into an array of tokens in the same way the UNIX
- # Bourne shell does.
- #
- # argv = Shellwords.split('here are "two words"')
- # argv #=> ["here", "are", "two words"]
- #
- # +String#shellsplit+ is a shorthand for this function.
+ # Split text into an array of tokens in the same way the UNIX Bourne
+ # shell does.
#
- # argv = 'here are "two words"'.shellsplit
- # argv #=> ["here", "are", "two words"]
+ # See the +Shellwords+ module documentation for an example.
#
- def shellsplit(line)
+ def shellwords(line)
line = String.new(line) rescue
raise(ArgumentError, "Argument must be a string")
line.lstrip!
@@ -60,113 +56,5 @@ module Shellwords
words
end
- alias shellwords shellsplit
-
- module_function :shellsplit, :shellwords
-
- class << self
- alias split shellsplit
- end
-
- #
- # Escapes a string so that it can be safely used in a Bourne shell
- # command line.
- #
- # Note that a resulted string should be used unquoted and is not
- # intended for use in double quotes nor in single quotes.
- #
- # open("| grep #{Shellwords.escape(pattern)} file") { |pipe|
- # # ...
- # }
- #
- # +String#shellescape+ is a shorthand for this function.
- #
- # open("| grep #{pattern.shellescape} file") { |pipe|
- # # ...
- # }
- #
- def shellescape(str)
- # An empty argument will be skipped, so return empty quotes.
- return "''" if str.empty?
-
- str = str.dup
-
- # Process as a single byte sequence because not all shell
- # implementations are multibyte aware.
- str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
-
- # A LF cannot be escaped with a backslash because a backslash + LF
- # combo is regarded as line continuation and simply ignored.
- str.gsub!(/\n/, "'\n'")
-
- return str
- end
-
- module_function :shellescape
-
- class << self
- alias escape shellescape
- end
-
- #
- # Builds a command line string from an argument list +array+ joining
- # all elements escaped for Bourne shell and separated by a space.
- #
- # open('|' + Shellwords.join(['grep', pattern, *files])) { |pipe|
- # # ...
- # }
- #
- # +Array#shelljoin+ is a shorthand for this function.
- #
- # open('|' + ['grep', pattern, *files].shelljoin) { |pipe|
- # # ...
- # }
- #
- def shelljoin(array)
- array.map { |arg| shellescape(arg) }.join(' ')
- end
-
- module_function :shelljoin
-
- class << self
- alias join shelljoin
- end
-end
-
-class String
- #
- # call-seq:
- # str.shellsplit => array
- #
- # Splits +str+ into an array of tokens in the same way the UNIX
- # Bourne shell does. See +Shellwords::shellsplit+ for details.
- #
- def shellsplit
- Shellwords.split(self)
- end
-
- #
- # call-seq:
- # str.shellescape => string
- #
- # Escapes +str+ so that it can be safely used in a Bourne shell
- # command line. See +Shellwords::shellescape+ for details.
- #
- def shellescape
- Shellwords.escape(self)
- end
-end
-
-class Array
- #
- # call-seq:
- # array.shelljoin => string
- #
- # Builds a command line string from an argument list +array+ joining
- # all elements escaped for Bourne shell and separated by a space.
- # See +Shellwords::shelljoin+ for details.
- #
- def shelljoin
- Shellwords.join(self)
- end
+ module_function :shellwords
end
diff --git a/lib/singleton.rb b/lib/singleton.rb
index 592d33c063..0ab8517275 100644
--- a/lib/singleton.rb
+++ b/lib/singleton.rb
@@ -30,7 +30,7 @@
# * Klass.new and Klass.allocate - as private
#
# Providing (or modifying) the class methods
-# * Klass.inherited(sub_klass) and Klass.clone() -
+# * Klass.inherited(sub_klass) and Klass.clone() -
# to ensure that the Singleton pattern is properly
# inherited and cloned.
#
@@ -70,9 +70,10 @@ module Singleton
def dup
raise TypeError, "can't dup instance of singleton #{self.class}"
end
-
+
+ private
# default marshalling strategy
- def _dump(depth=-1)
+ def _dump(depth=-1)
''
end
end
@@ -103,7 +104,7 @@ class << Singleton
end
end
elsif _instantiate?()
- Thread.critical = false
+ Thread.critical = false
else
@__instance__ = false
Thread.critical = false
@@ -122,26 +123,26 @@ class << Singleton
end
@__instance__
end
-
- module SingletonClassMethods
+
+ module SingletonClassMethods
# properly clone the Singleton pattern - did you know
- # that duping doesn't copy class methods?
+ # that duping doesn't copy class methods?
def clone
Singleton.__init__(super)
end
-
- def _load(str)
- instance
- end
-
+
private
-
- # ensure that the Singleton pattern is properly inherited
+
+ # ensure that the Singleton pattern is properly inherited
def inherited(sub_klass)
super
Singleton.__init__(sub_klass)
end
-
+
+ def _load(str)
+ instance
+ end
+
# waiting-loop hook
def _instantiate?()
while false.equal?(@__instance__)
@@ -152,7 +153,7 @@ class << Singleton
@__instance__
end
end
-
+
def __init__(klass)
klass.instance_eval { @__instance__ = nil }
class << klass
@@ -160,11 +161,11 @@ class << Singleton
end
klass
end
-
+
private
# extending an object with Singleton is a bad idea
undef_method :extend_object
-
+
def append_features(mod)
# help out people counting on transitive mixins
unless mod.instance_of?(Class)
@@ -172,7 +173,7 @@ class << Singleton
end
super
end
-
+
def included(klass)
super
klass.private_class_method :new, :allocate
@@ -180,21 +181,21 @@ class << Singleton
Singleton.__init__(klass)
end
end
-
+
if __FILE__ == $0
def num_of_instances(klass)
"#{ObjectSpace.each_object(klass){}} #{klass} instance(s)"
-end
+end
# The basic and most important example.
class SomeSingletonClass
include Singleton
end
-puts "There are #{num_of_instances(SomeSingletonClass)}"
+puts "There are #{num_of_instances(SomeSingletonClass)}"
a = SomeSingletonClass.instance
b = SomeSingletonClass.instance # a and b are same object
@@ -217,23 +218,23 @@ class Ups < SomeSingletonClass
puts "initialize called by thread ##{Thread.current[:i]}"
end
end
-
+
class << Ups
def _instantiate?
@enter.push Thread.current[:i]
while false.equal?(@__instance__)
Thread.critical = false
- sleep 0.08
+ sleep 0.08
Thread.critical = true
end
@leave.push Thread.current[:i]
@__instance__
end
-
+
def __sleep
sleep(rand(0.08))
end
-
+
def new
begin
__sleep
@@ -245,12 +246,12 @@ class << Ups
end
end
end
-
+
def instantiate_all
@enter = []
@leave = []
- 1.upto(9) {|i|
- Thread.new {
+ 1.upto(9) {|i|
+ Thread.new {
begin
Thread.current[:i] = i
__sleep
@@ -340,7 +341,7 @@ end
class Down < Middle; end
puts "and basic \"Down test\" is #{Down.instance == Down.instance}\n
-Various exceptions"
+Various exceptions"
begin
module AModule
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index c984cd3393..b885444b15 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -13,15 +13,9 @@ class Tempfile < DelegateClass(File)
MAX_TRY = 10
@@cleanlist = []
- # Creates a temporary file of mode 0600 in the temporary directory,
- # opens it with mode "w+", and returns a Tempfile object which
- # represents the created temporary file. A Tempfile object can be
- # treated just like a normal File object.
- #
- # The basename parameter is used to determine the name of a
- # temporary file. If an Array is given, the first element is used
- # as prefix string and the second as suffix string, respectively.
- # Otherwise it is treated as prefix string.
+ # Creates a temporary file of mode 0600 in the temporary directory
+ # whose name is basename.pid.n and opens with mode "w+". A Tempfile
+ # object works just like a File object.
#
# If tmpdir is omitted, the temporary directory is determined by
# Dir::tmpdir provided by 'tmpdir.rb'.
@@ -73,15 +67,7 @@ class Tempfile < DelegateClass(File)
end
def make_tmpname(basename, n)
- case basename
- when Array
- prefix, suffix = *basename
- else
- prefix, suffix = basename, ''
- end
-
- t = Time.now.strftime("%Y%m%d")
- path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-#{n}#{suffix}"
+ sprintf('%s.%d.%d', basename, $$, n)
end
private :make_tmpname
@@ -95,8 +81,7 @@ class Tempfile < DelegateClass(File)
def _close # :nodoc:
@tmpfile.close if @tmpfile
- @tmpfile = nil
- @data[1] = nil if @data
+ @data[1] = @tmpfile = nil
end
protected :_close
@@ -118,7 +103,6 @@ class Tempfile < DelegateClass(File)
_close
@clean_proc.call
ObjectSpace.undefine_finalizer(self)
- @data = @tmpname = nil
end
# Unlinks the file. On UNIX-like systems, it is often a good idea
diff --git a/lib/time.rb b/lib/time.rb
index a37a067390..dbc25f4193 100644
--- a/lib/time.rb
+++ b/lib/time.rb
@@ -66,7 +66,7 @@ class Time
'N' => -1, 'O' => -2, 'P' => -3, 'Q' => -4, 'R' => -5, 'S' => -6,
'T' => -7, 'U' => -8, 'V' => -9, 'W' => -10, 'X' => -11, 'Y' => -12,
}
- def zone_offset(zone, year=self.now.year)
+ def zone_offset(zone, year=Time.now.year)
off = nil
zone = zone.upcase
if /\A([+-])(\d\d):?(\d\d)\z/ =~ zone
@@ -75,9 +75,9 @@ class Time
off = zone.to_i * 3600
elsif ZoneOffset.include?(zone)
off = ZoneOffset[zone] * 3600
- elsif ((t = self.local(year, 1, 1)).zone.upcase == zone rescue false)
+ elsif ((t = Time.local(year, 1, 1)).zone.upcase == zone rescue false)
off = t.utc_offset
- elsif ((t = self.local(year, 7, 1)).zone.upcase == zone rescue false)
+ elsif ((t = Time.local(year, 7, 1)).zone.upcase == zone rescue false)
off = t.utc_offset
end
off
@@ -177,7 +177,7 @@ class Time
if off
year, mon, day, hour, min, sec =
apply_offset(year, mon, day, hour, min, sec, off)
- t = self.utc(year, mon, day, hour, min, sec, usec)
+ t = Time.utc(year, mon, day, hour, min, sec, usec)
t.localtime if !zone_utc?(zone)
t
else
@@ -236,7 +236,7 @@ class Time
#
# A failure for Time.parse should be checked, though.
#
- def parse(date, now=self.now)
+ def parse(date, now=Time.now)
d = Date._parse(date, false)
year = d[:year]
year = yield(year) if year && block_given?
@@ -363,14 +363,14 @@ class Time
min = $5.to_i
sec = $6.to_i
usec = 0
- usec = ($7[1..-1] + '000000')[0,6].to_i if $7
+ usec = $7.to_f * 1000000 if $7
if $8
zone = $8
year, mon, day, hour, min, sec =
apply_offset(year, mon, day, hour, min, sec, zone_offset(zone))
- self.utc(year, mon, day, hour, min, sec, usec)
+ Time.utc(year, mon, day, hour, min, sec, usec)
else
- self.local(year, mon, day, hour, min, sec, usec)
+ Time.local(year, mon, day, hour, min, sec, usec)
end
else
raise ArgumentError.new("invalid date: #{date.inspect}")
@@ -621,8 +621,6 @@ if __FILE__ == $0
t = Time.utc(1960, 12, 31, 23, 0, 0, 123456)
assert_equal("1960-12-31T23:00:00.123456Z", t.xmlschema(6))
end
-
- assert_equal(249, Time.xmlschema("2008-06-05T23:49:23.000249+09:00").usec)
end
def test_completion
diff --git a/lib/timeout.rb b/lib/timeout.rb
index 5a99c28092..dc92964c0b 100644
--- a/lib/timeout.rb
+++ b/lib/timeout.rb
@@ -32,13 +32,8 @@ module Timeout
##
# Raised by Timeout#timeout when the block times out.
- class Error < Interrupt
+ class Error<Interrupt
end
- class ExitException < ::Exception # :nodoc:
- end
-
- THIS_FILE = /\A#{Regexp.quote(__FILE__)}:/o
- CALLER_OFFSET = ((c = caller[0]) && THIS_FILE =~ c) ? 1 : 0
##
# Executes the method's block. If the block execution terminates before +sec+
@@ -49,10 +44,9 @@ module Timeout
# Timeout' into your classes so they have a #timeout method, as well as a
# module method, so you can call it directly as Timeout.timeout().
- def timeout(sec, klass = nil)
+ def timeout(sec, exception=Error)
return yield if sec == nil or sec.zero?
raise ThreadError, "timeout within critical session" if Thread.critical
- exception = klass || Class.new(ExitException)
begin
x = Thread.current
y = Thread.start {
@@ -61,17 +55,6 @@ module Timeout
}
yield sec
# return true
- rescue exception => e
- rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
- (bt = e.backtrace).reject! {|m| rej =~ m}
- level = -caller(CALLER_OFFSET).size
- while THIS_FILE =~ bt[level]
- bt.delete_at(level)
- level += 1
- end
- raise if klass # if exception class is specified, it
- # would be expected outside.
- raise Error, e.message, e.backtrace
ensure
y.kill if y and y.alive?
end
@@ -89,7 +72,7 @@ end
# Defined for backwards compatibility with earlier versions of timeout.rb, see
# Timeout#timeout.
-def timeout(n, e = nil, &block) # :nodoc:
+def timeout(n, e=Timeout::Error, &block) # :nodoc:
Timeout::timeout(n, e, &block)
end
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb
index 2e82aa528e..434d1bf053 100644
--- a/lib/tmpdir.rb
+++ b/lib/tmpdir.rb
@@ -4,31 +4,22 @@
# $Id$
#
-require 'fileutils'
-
class Dir
@@systmpdir = '/tmp'
begin
require 'Win32API'
- CSIDL_LOCAL_APPDATA = 0x001c
max_pathlen = 260
windir = ' '*(max_pathlen+1)
begin
- getdir = Win32API.new('shell32', 'SHGetFolderPath', 'LLLLP', 'L')
- raise RuntimeError if getdir.call(0, CSIDL_LOCAL_APPDATA, 0, 0, windir) != 0
- windir = File.expand_path(windir.rstrip)
+ getdir = Win32API.new('kernel32', 'GetSystemWindowsDirectory', 'PL', 'L')
rescue RuntimeError
- begin
- getdir = Win32API.new('kernel32', 'GetSystemWindowsDirectory', 'PL', 'L')
- rescue RuntimeError
- getdir = Win32API.new('kernel32', 'GetWindowsDirectory', 'PL', 'L')
- end
- len = getdir.call(windir, windir.size)
- windir = File.expand_path(windir[0, len])
+ getdir = Win32API.new('kernel32', 'GetWindowsDirectory', 'PL', 'L')
end
- temp = File.join(windir.untaint, 'temp')
+ len = getdir.call(windir, windir.size)
+ windir = File.expand_path(windir[0, len])
+ temp = File.join(windir, 'temp')
@@systmpdir = temp if File.directory?(temp) and File.writable?(temp)
rescue LoadError
end
@@ -48,90 +39,7 @@ class Dir
break
end
end
- File.expand_path(tmp)
- end
- end
-
- # Dir.mktmpdir creates a temporary directory.
- #
- # The directory is created with 0700 permission.
- #
- # The prefix and suffix of the name of the directory is specified by
- # the optional first argument, <i>prefix_suffix</i>.
- # - If it is not specified or nil, "d" is used as the prefix and no suffix is used.
- # - If it is a string, it is used as the prefix and no suffix is used.
- # - If it is an array, first element is used as the prefix and second element is used as a suffix.
- #
- # Dir.mktmpdir {|dir| dir is ".../d..." }
- # Dir.mktmpdir("foo") {|dir| dir is ".../foo..." }
- # Dir.mktmpdir(["foo", "bar"]) {|dir| dir is ".../foo...bar" }
- #
- # The directory is created under Dir.tmpdir or
- # the optional second argument <i>tmpdir</i> if non-nil value is given.
- #
- # Dir.mktmpdir {|dir| dir is "#{Dir.tmpdir}/d..." }
- # Dir.mktmpdir(nil, "/var/tmp") {|dir| dir is "/var/tmp/d..." }
- #
- # If a block is given,
- # it is yielded with the path of the directory.
- # The directory and its contents are removed
- # using FileUtils.remove_entry_secure before Dir.mktmpdir returns.
- # The value of the block is returned.
- #
- # Dir.mktmpdir {|dir|
- # # use the directory...
- # open("#{dir}/foo", "w") { ... }
- # }
- #
- # If a block is not given,
- # The path of the directory is returned.
- # In this case, Dir.mktmpdir doesn't remove the directory.
- #
- # dir = Dir.mktmpdir
- # begin
- # # use the directory...
- # open("#{dir}/foo", "w") { ... }
- # ensure
- # # remove the directory.
- # FileUtils.remove_entry_secure dir
- # end
- #
- def Dir.mktmpdir(prefix_suffix=nil, tmpdir=nil)
- case prefix_suffix
- when nil
- prefix = "d"
- suffix = ""
- when String
- prefix = prefix_suffix
- suffix = ""
- when Array
- prefix = prefix_suffix[0]
- suffix = prefix_suffix[1]
- else
- raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
- end
- tmpdir ||= Dir.tmpdir
- t = Time.now.strftime("%Y%m%d")
- n = nil
- begin
- path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
- path << "-#{n}" if n
- path << suffix
- Dir.mkdir(path, 0700)
- rescue Errno::EEXIST
- n ||= 0
- n += 1
- retry
- end
-
- if block_given?
- begin
- yield path
- ensure
- FileUtils.remove_entry_secure path
- end
- else
- path
end
+ File.expand_path(tmp)
end
end
diff --git a/lib/uri.rb b/lib/uri.rb
index f7110f18fd..09c4f5fbcf 100644
--- a/lib/uri.rb
+++ b/lib/uri.rb
@@ -25,5 +25,4 @@ require 'uri/ftp'
require 'uri/http'
require 'uri/https'
require 'uri/ldap'
-require 'uri/ldaps'
require 'uri/mailto'
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index af6aaf26fb..f74f0eb2e1 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -110,7 +110,7 @@ module URI
SERVER = "(?:#{USERINFO}@)?#{HOSTPORT}"
# reg_name = 1*( unreserved | escaped | "$" | "," |
# ";" | ":" | "@" | "&" | "=" | "+" )
- REG_NAME = "(?:[#{UNRESERVED}$,;:@&=+]|#{ESCAPED})+"
+ REG_NAME = "(?:[#{UNRESERVED}$,;+@&=+]|#{ESCAPED})+"
# authority = server | reg_name
AUTHORITY = "(?:#{SERVER}|#{REG_NAME})"
diff --git a/lib/uri/ftp.rb b/lib/uri/ftp.rb
index 1a18e9cae7..26109e4d27 100644
--- a/lib/uri/ftp.rb
+++ b/lib/uri/ftp.rb
@@ -11,7 +11,7 @@ require 'uri/generic'
module URI
#
- # FTP URI syntax is defined by RFC1738 section 3.2.
+ # RFC1738 section 3.2.
#
class FTP < Generic
DEFAULT_PORT = 21
@@ -22,11 +22,12 @@ module URI
:path, :typecode
].freeze
#
- # Typecode is "a", "i" or "d".
- #
- # * "a" indicates a text file (the FTP command was ASCII)
- # * "i" indicates a binary file (FTP command IMAGE)
- # * "d" indicates the contents of a directory should be displayed
+ # Typecode is, "a", "i" or "d".
+ # As for "a" the text, as for "i" binary,
+ # as for "d" the directory is displayed.
+ # "A" with the text, as for "i" being binary,
+ # is because the respective data type was called ASCII and
+ # IMAGE with the protocol of FTP.
#
TYPECODE = ['a', 'i', 'd'].freeze
TYPECODE_PREFIX = ';type='.freeze
@@ -51,43 +52,11 @@ module URI
#
# == Description
#
- # Creates a new URI::FTP object from components, with syntax checking.
- #
- # The components accepted are +userinfo+, +host+, +port+, +path+ and
- # +typecode+.
- #
- # The components should be provided either as an Array, or as a Hash
- # with keys formed by preceding the component names with a colon.
- #
- # If an Array is used, the components must be passed in the order
- # [userinfo, host, port, path, typecode]
- #
- # If the path supplied is absolute, it will be escaped in order to
- # make it absolute in the URI. Examples:
- #
- # require 'uri'
- #
- # uri = URI::FTP.build(['user:password', 'ftp.example.com', nil,
- # '/path/file.> zip', 'i'])
- # puts uri.to_s -> ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=a
- #
- # uri2 = URI::FTP.build({:host => 'ftp.example.com',
- # :path => 'ruby/src'})
- # puts uri2.to_s -> ftp://ftp.example.com/ruby/src
+ # Creates a new URI::FTP object from components of URI::FTP with
+ # check. It is scheme, userinfo, host, port, path and typecode. It
+ # provided by an Array or a Hash. typecode is "a", "i" or "d".
#
def self.build(args)
-
- # Fix the incoming path to be generic URL syntax
- # FTP path -> URL path
- # foo/bar /foo/bar
- # /foo/bar /%2Ffoo/bar
- #
- if args.kind_of?(Array)
- args[3] = '/' + args[3].sub(/^\//, '%2F')
- else
- args[:path] = '/' + args[:path].sub(/^\//, '%2F')
- end
-
tmp = Util::make_components_hash(self, args)
if tmp[:typecode]
@@ -103,14 +72,16 @@ module URI
#
# == Description
#
- # Creates a new URI::FTP object from generic URL components with no
- # syntax checking.
+ # Create a new URI::FTP object from ``generic'' components with no
+ # check.
#
- # Unlike build(), this method does not escape the path component as
- # required by RFC1738; instead it is treated as per RFC2396.
+ # == Usage
#
- # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
- # +opaque+, +query+ and +fragment+, in that order.
+ # require 'uri'
+ # p ftp = URI.parse("ftp://ftp.ruby-lang.org/pub/ruby/;type=d")
+ # # => #<URI::FTP:0x201fad08 URL:ftp://ftp.ruby-lang.org/pub/ruby/;type=d>
+ # p ftp.typecode
+ # # => "d"
#
def initialize(*arg)
super(*arg)
@@ -159,27 +130,6 @@ module URI
return tmp
end
- # Returns the path from an FTP URI.
- #
- # RFC 1738 specifically states that the path for an FTP URI does not
- # include the / which separates the URI path from the URI host. Example:
- #
- # ftp://ftp.example.com/pub/ruby
- #
- # The above URI indicates that the client should connect to
- # ftp.example.com then cd pub/ruby from the initial login directory.
- #
- # If you want to cd to an absolute directory, you must include an
- # escaped / (%2F) in the path. Example:
- #
- # ftp://ftp.example.com/%2Fpub/ruby
- #
- # This method will then return "/pub/ruby"
- #
- def path
- return @path.sub(/^\//,'').sub(/^%2F/i,'/')
- end
-
def to_s
save_path = nil
if @typecode
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index d907e0b4b2..2b66adeb93 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -616,65 +616,65 @@ module URI
private :split_path
def merge_path(base, rel)
-
# RFC2396, Section 5.2, 5)
- # RFC2396, Section 5.2, 6)
- base_path = split_path(base)
- rel_path = split_path(rel)
-
- # RFC2396, Section 5.2, 6), a)
- base_path << '' if base_path.last == '..'
- while i = base_path.index('..')
- base_path.slice!(i - 1, 2)
- end
-
- if (first = rel_path.first) and first.empty?
- base_path.clear
- rel_path.shift
- end
+ if rel[0] == ?/ #/
+ # RFC2396, Section 5.2, 5)
+ return rel
- # RFC2396, Section 5.2, 6), c)
- # RFC2396, Section 5.2, 6), d)
- rel_path.push('') if rel_path.last == '.' || rel_path.last == '..'
- rel_path.delete('.')
-
- # RFC2396, Section 5.2, 6), e)
- tmp = []
- rel_path.each do |x|
- if x == '..' &&
- !(tmp.empty? || tmp.last == '..')
- tmp.pop
+ else
+ # RFC2396, Section 5.2, 6)
+ base_path = split_path(base)
+ rel_path = split_path(rel)
+
+ # RFC2396, Section 5.2, 6), a)
+ base_path << '' if base_path.last == '..'
+ while i = base_path.index('..')
+ base_path.slice!(i - 1, 2)
+ end
+ if base_path.empty?
+ base_path = [''] # keep '/' for root directory
else
- tmp << x
+ base_path.pop
end
- end
- add_trailer_slash = !tmp.empty?
- if base_path.empty?
- base_path = [''] # keep '/' for root directory
- elsif add_trailer_slash
- base_path.pop
- end
- while x = tmp.shift
- if x == '..'
- # RFC2396, Section 4
- # a .. or . in an absolute path has no special meaning
- base_path.pop if base_path.size > 1
- else
- # if x == '..'
- # valid absolute (but abnormal) path "/../..."
- # else
- # valid absolute path
- # end
- base_path << x
- tmp.each {|t| base_path << t}
- add_trailer_slash = false
- break
+ # RFC2396, Section 5.2, 6), c)
+ # RFC2396, Section 5.2, 6), d)
+ rel_path.push('') if rel_path.last == '.' || rel_path.last == '..'
+ rel_path.delete('.')
+
+ # RFC2396, Section 5.2, 6), e)
+ tmp = []
+ rel_path.each do |x|
+ if x == '..' &&
+ !(tmp.empty? || tmp.last == '..')
+ tmp.pop
+ else
+ tmp << x
+ end
end
- end
- base_path.push('') if add_trailer_slash
- return base_path.join('/')
+ add_trailer_slash = true
+ while x = tmp.shift
+ if x == '..' && base_path.size > 1
+ # RFC2396, Section 4
+ # a .. or . in an absolute path has no special meaning
+ base_path.pop
+ else
+ # if x == '..'
+ # valid absolute (but abnormal) path "/../..."
+ # else
+ # valid absolute path
+ # end
+ base_path << x
+ tmp.each {|t| base_path << t}
+ add_trailer_slash = false
+ break
+ end
+ end
+ base_path.push('') if add_trailer_slash
+
+ return base_path.join('/')
+ end
end
private :merge_path
@@ -1103,9 +1103,8 @@ module URI
end
end
- @@to_s = Kernel.instance_method(:to_s)
def inspect
- @@to_s.bind(self).call.sub!(/>\z/) {" URL:#{self}>"}
+ sprintf("#<%s:%#0x URL:%s>", self.class.to_s, self.object_id, self.to_s)
end
def coerce(oth)
diff --git a/lib/uri/ldaps.rb b/lib/uri/ldaps.rb
deleted file mode 100644
index 6da333150f..0000000000
--- a/lib/uri/ldaps.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require 'uri/ldap'
-
-module URI
-
- # The default port for LDAPS URIs is 636, and the scheme is 'ldaps:' rather
- # than 'ldap:'. Other than that, LDAPS URIs are identical to LDAP URIs;
- # see URI::LDAP.
- class LDAPS < LDAP
- DEFAULT_PORT = 636
- end
- @@schemes['LDAPS'] = LDAPS
-end
diff --git a/lib/webrick/httpproxy.rb b/lib/webrick/httpproxy.rb
index 9295259085..14e3499775 100644
--- a/lib/webrick/httpproxy.rb
+++ b/lib/webrick/httpproxy.rb
@@ -47,7 +47,7 @@ module WEBrick
req.header.delete("proxy-authorization")
end
- # Some header fields should not be transferred.
+ # Some header fields shuold not be transfered.
HopByHop = %w( connection keep-alive proxy-authenticate upgrade
proxy-authorization te trailers transfer-encoding )
ShouldNotTransfer = %w( set-cookie proxy-connection )
diff --git a/lib/webrick/httpresponse.rb b/lib/webrick/httpresponse.rb
index 62156b1abd..d0f232d1e1 100644
--- a/lib/webrick/httpresponse.rb
+++ b/lib/webrick/httpresponse.rb
@@ -132,7 +132,7 @@ module WEBrick
end
end
- # Determine the message length (RFC2616 -- 4.4 Message Length)
+ # Determin the message length (RFC2616 -- 4.4 Message Length)
if @status == 304 || @status == 204 || HTTPStatus::info?(@status)
@header.delete('content-length')
@body = ""
diff --git a/lib/webrick/httpservlet/abstract.rb b/lib/webrick/httpservlet/abstract.rb
index 5375c4622d..03861e8fc7 100644
--- a/lib/webrick/httpservlet/abstract.rb
+++ b/lib/webrick/httpservlet/abstract.rb
@@ -58,7 +58,7 @@ module WEBrick
def redirect_to_directory_uri(req, res)
if req.path[-1] != ?/
- location = WEBrick::HTTPUtils.escape_path(req.path + "/")
+ location = req.path + "/"
if req.query_string && req.query_string.size > 0
location << "?" << req.query_string
end
diff --git a/lib/webrick/httpservlet/cgi_runner.rb b/lib/webrick/httpservlet/cgi_runner.rb
index 006abd458e..1069a68d58 100644
--- a/lib/webrick/httpservlet/cgi_runner.rb
+++ b/lib/webrick/httpservlet/cgi_runner.rb
@@ -39,9 +39,7 @@ dir = File::dirname(ENV["SCRIPT_FILENAME"])
Dir::chdir dir
if interpreter = ARGV[0]
- argv = ARGV.dup
- argv << ENV["SCRIPT_FILENAME"]
- exec(*argv)
+ exec(interpreter, ENV["SCRIPT_FILENAME"])
# NOTREACHED
end
exec ENV["SCRIPT_FILENAME"]
diff --git a/lib/webrick/httpservlet/cgihandler.rb b/lib/webrick/httpservlet/cgihandler.rb
index d5895e5285..a35b59edb8 100644
--- a/lib/webrick/httpservlet/cgihandler.rb
+++ b/lib/webrick/httpservlet/cgihandler.rb
@@ -85,10 +85,6 @@ module WEBrick
res.status = $1.to_i
header.delete('status')
end
- if header.has_key?('location')
- # RFC 3875 6.2.3, 6.2.4
- res.status = 302 unless (300...400) === res.status
- end
if header.has_key?('set-cookie')
header['set-cookie'].each{|k|
res.cookies << Cookie.parse_set_cookie(k)
diff --git a/lib/webrick/httpservlet/filehandler.rb b/lib/webrick/httpservlet/filehandler.rb
index 24f59d7142..410cc6f9a9 100644
--- a/lib/webrick/httpservlet/filehandler.rb
+++ b/lib/webrick/httpservlet/filehandler.rb
@@ -163,7 +163,6 @@ module WEBrick
end
end
end
- prevent_directory_traversal(req, res)
super(req, res)
end
@@ -199,38 +198,10 @@ module WEBrick
private
- def trailing_pathsep?(path)
- # check for trailing path separator:
- # File.dirname("/aaaa/bbbb/") #=> "/aaaa")
- # File.dirname("/aaaa/bbbb/x") #=> "/aaaa/bbbb")
- # File.dirname("/aaaa/bbbb") #=> "/aaaa")
- # File.dirname("/aaaa/bbbbx") #=> "/aaaa")
- return File.dirname(path) != File.dirname(path+"x")
- end
-
- def prevent_directory_traversal(req, res)
- # Preventing directory traversal on Windows platforms;
- # Backslashes (0x5c) in path_info are not interpreted as special
- # character in URI notation. So the value of path_info should be
- # normalize before accessing to the filesystem.
-
- if trailing_pathsep?(req.path_info)
- # File.expand_path removes the trailing path separator.
- # Adding a character is a workaround to save it.
- # File.expand_path("/aaa/") #=> "/aaa"
- # File.expand_path("/aaa/" + "x") #=> "/aaa/x"
- expanded = File.expand_path(req.path_info + "x")
- expanded.chop! # remove trailing "x"
- else
- expanded = File.expand_path(req.path_info)
- end
- req.path_info = expanded
- end
-
def exec_handler(req, res)
raise HTTPStatus::NotFound, "`#{req.path}' not found" unless @root
if set_filename(req, res)
- handler = get_handler(req, res)
+ handler = get_handler(req)
call_callback(:HandlerCallback, req, res)
h = handler.get_instance(@config, res.filename)
h.service(req, res)
@@ -240,13 +211,9 @@ module WEBrick
return false
end
- def get_handler(req, res)
- suffix1 = (/\.(\w+)\z/ =~ res.filename) && $1.downcase
- if /\.(\w+)\.([\w\-]+)\z/ =~ res.filename
- if @options[:AcceptableLanguages].include?($2.downcase)
- suffix2 = $1.downcase
- end
- end
+ def get_handler(req)
+ suffix1 = (/\.(\w+)$/ =~ req.script_name) && $1.downcase
+ suffix2 = (/\.(\w+)\.[\w\-]+$/ =~ req.script_name) && $1.downcase
handler_table = @options[:HandlerTable]
return handler_table[suffix1] || handler_table[suffix2] ||
HandlerTable[suffix1] || HandlerTable[suffix2] ||
@@ -259,13 +226,15 @@ module WEBrick
path_info.unshift("") # dummy for checking @root dir
while base = path_info.first
+ check_filename(req, res, base)
break if base == "/"
- break unless File.directory?(File.expand_path(res.filename + base))
+ break unless File.directory?(res.filename + base)
shift_path_info(req, res, path_info)
call_callback(:DirectoryCallback, req, res)
end
if base = path_info.first
+ check_filename(req, res, base)
if base == "/"
if file = search_index_file(req, res)
shift_path_info(req, res, path_info, file)
@@ -286,10 +255,12 @@ module WEBrick
end
def check_filename(req, res, name)
- if nondisclosure_name?(name) || windows_ambiguous_name?(name)
- @logger.warn("the request refers nondisclosure name `#{name}'.")
- raise HTTPStatus::NotFound, "`#{req.path}' not found."
- end
+ @options[:NondisclosureName].each{|pattern|
+ if File.fnmatch("/#{pattern}", name)
+ @logger.warn("the request refers nondisclosure name `#{name}'.")
+ raise HTTPStatus::NotFound, "`#{req.path}' not found."
+ end
+ }
end
def shift_path_info(req, res, path_info, base=nil)
@@ -297,8 +268,7 @@ module WEBrick
base = base || tmp
req.path_info = path_info.join
req.script_name << base
- res.filename = File.expand_path(res.filename + base)
- check_filename(req, res, File.basename(res.filename))
+ res.filename << base
end
def search_index_file(req, res)
@@ -338,15 +308,9 @@ module WEBrick
end
end
- def windows_ambiguous_name?(name)
- return true if /[. ]+\z/ =~ name
- return true if /::\$DATA\z/ =~ name
- return false
- end
-
def nondisclosure_name?(name)
@options[:NondisclosureName].each{|pattern|
- if File.fnmatch(pattern, name, File::FNM_CASEFOLD)
+ if File.fnmatch(pattern, name)
return true
end
}
@@ -362,8 +326,7 @@ module WEBrick
list = Dir::entries(local_path).collect{|name|
next if name == "." || name == ".."
next if nondisclosure_name?(name)
- next if windows_ambiguous_name?(name)
- st = (File::stat(File.join(local_path, name)) rescue nil)
+ st = (File::stat(local_path + name) rescue nil)
if st.nil?
[ name, nil, -1 ]
elsif st.directory?
@@ -403,7 +366,7 @@ module WEBrick
res.body << "<A HREF=\"?S=#{d1}\">Size</A>\n"
res.body << "<HR>\n"
- list.unshift [ "..", File::mtime(local_path+"/.."), -1 ]
+ list.unshift [ "..", File::mtime(local_path+".."), -1 ]
list.each{ |name, time, size|
if name == ".."
dname = "Parent Directory"
diff --git a/lib/webrick/httputils.rb b/lib/webrick/httputils.rb
index 976d3e915e..c57af2c860 100644
--- a/lib/webrick/httputils.rb
+++ b/lib/webrick/httputils.rb
@@ -23,8 +23,16 @@ module WEBrick
ret = path.dup
ret.gsub!(%r{/+}o, '/') # // => /
- while ret.sub!(%r'/\.(?:/|\Z)', '/'); end # /. => /
- while ret.sub!(%r'/(?!\.\./)[^/]+/\.\.(?:/|\Z)', '/'); end # /foo/.. => /foo
+ while ret.sub!(%r{/\.(/|\Z)}o, '/'); end # /. => /
+ begin # /foo/.. => /foo
+ match = ret.sub!(%r{/([^/]+)/\.\.(/|\Z)}o){
+ if $1 == ".."
+ raise "abnormal path `#{path}'"
+ else
+ "/"
+ end
+ }
+ end while match
raise "abnormal path `#{path}'" if %r{/\.\.(/|\Z)} =~ ret
ret
@@ -146,8 +154,8 @@ module WEBrick
module_function :parse_header
def split_header_value(str)
- str.scan(%r'\G((?:"(?:\\.|[^"])+?"|[^",]+)+)
- (?:,\s*|\Z)'xn).flatten
+ str.scan(/((?:"(?:\\.|[^"])+?"|[^",]+)+)
+ (?:,\s*|\Z)/xn).collect{|v| v[0] }
end
module_function :split_header_value
diff --git a/lib/xmlrpc/client.rb b/lib/xmlrpc/client.rb
index 278855e01d..10f547b632 100644
--- a/lib/xmlrpc/client.rb
+++ b/lib/xmlrpc/client.rb
@@ -530,9 +530,6 @@ module XMLRPC
}
else
# reuse the HTTP object for each call => connection alive is possible
- # we must start connection explicitely first time so that http.request
- # does not assume that we don't want keepalive
- @http.start if not @http.started?
# post request
resp = @http.post2(@path, request, header)
@@ -552,9 +549,9 @@ module XMLRPC
ct = parse_content_type(resp["Content-Type"]).first
if ct != "text/xml"
if ct == "text/html"
- raise "Wrong content-type (received '#{ct}' but expected 'text/xml'): \n#{data}"
+ raise "Wrong content-type: \n#{data}"
else
- raise "Wrong content-type (received '#{ct}' but expected 'text/xml')"
+ raise "Wrong content-type"
end
end
@@ -565,14 +562,8 @@ module XMLRPC
raise "Wrong size. Was #{data.size}, should be #{expected}"
end
- set_cookies = resp.get_fields("Set-Cookie")
- if set_cookies and !set_cookies.empty?
- require 'webrick/cookie'
- @cookie = set_cookies.collect do |set_cookie|
- cookie = WEBrick::Cookie.parse_set_cookie(set_cookie)
- WEBrick::Cookie.new(cookie.name, cookie.value).to_s
- end.join("; ")
- end
+ c = resp["Set-Cookie"]
+ @cookie = c if c
return data
end
diff --git a/lib/xmlrpc/parser.rb b/lib/xmlrpc/parser.rb
index 6d10fde9d9..d27d7c3827 100644
--- a/lib/xmlrpc/parser.rb
+++ b/lib/xmlrpc/parser.rb
@@ -92,7 +92,7 @@ module XMLRPC
if $7
ofs = $8.to_i*3600 + $9.to_i*60
ofs = -ofs if $7=='+'
- utc = Time.utc(*a) + ofs
+ utc = Time.utc(a.reverse) + ofs
a = [ utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec ]
end
XMLRPC::DateTime.new(*a)
@@ -106,7 +106,7 @@ module XMLRPC
if $7
ofs = $8.to_i*3600 + $9.to_i*60
ofs = -ofs if $7=='+'
- utc = Time.utc(*a) + ofs
+ utc = Time.utc(a.reverse) + ofs
a = [ utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec ]
end
XMLRPC::DateTime.new(*a)
diff --git a/lib/xmlrpc/server.rb b/lib/xmlrpc/server.rb
index ca8d3b0a5b..59a5869408 100644
--- a/lib/xmlrpc/server.rb
+++ b/lib/xmlrpc/server.rb
@@ -639,11 +639,11 @@ class Server < WEBrickServlet
def serve
if RUBY_PLATFORM =~ /mingw|mswin32/
- signals = [1]
+ signal = 1
else
- signals = %w[INT TERM HUP]
+ signal = "HUP"
end
- signals.each { |signal| trap(signal) { @server.shutdown } }
+ trap(signal) { @server.shutdown }
@server.start
end
diff --git a/lib/xmlrpc/utils.rb b/lib/xmlrpc/utils.rb
index f0966fee40..85c6bba372 100644
--- a/lib/xmlrpc/utils.rb
+++ b/lib/xmlrpc/utils.rb
@@ -157,7 +157,7 @@ module XMLRPC
module ParseContentType
def parse_content_type(str)
a, *b = str.split(";")
- return a.strip.downcase, *b
+ return a.strip, *b
end
end
diff --git a/lib/yaml.rb b/lib/yaml.rb
index a8da42a321..fe8335c8f0 100644
--- a/lib/yaml.rb
+++ b/lib/yaml.rb
@@ -384,10 +384,6 @@ module YAML
else
emitter.reset( opts )
end
- oid =
- case oid when Fixnum, NilClass; oid
- else oid = "#{oid.object_id}-#{oid.hash}"
- end
out.emit( oid, &e )
end
diff --git a/lib/yaml/baseemitter.rb b/lib/yaml/baseemitter.rb
index a1992f498b..1aef152749 100644
--- a/lib/yaml/baseemitter.rb
+++ b/lib/yaml/baseemitter.rb
@@ -132,7 +132,7 @@ module YAML
# Folding paragraphs within a column
#
def fold( value )
- value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do
+ value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do |s|
$1 || $2 + ( $3 || "\n" )
end
end
diff --git a/lib/yaml/basenode.rb b/lib/yaml/basenode.rb
index 5439903f42..d24f6172e9 100644
--- a/lib/yaml/basenode.rb
+++ b/lib/yaml/basenode.rb
@@ -184,7 +184,7 @@ module YAML
#
def []( *key )
if Hash === @value
- v = @value.detect { |k,| k.transform == key.first }
+ v = @value.detect { |k,v| k.transform == key.first }
v[1] if v
elsif Array === @value
@value.[]( *key )
diff --git a/lib/yaml/encoding.rb b/lib/yaml/encoding.rb
index 57dc553606..37f5cfda64 100644
--- a/lib/yaml/encoding.rb
+++ b/lib/yaml/encoding.rb
@@ -10,8 +10,8 @@ module YAML
def YAML.escape( value, skip = "" )
value.gsub( /\\/, "\\\\\\" ).
gsub( /"/, "\\\"" ).
- gsub( /([\x00-\x1f])/ ) do
- skip[$&] || ESCAPES[ $&.unpack("C")[0] ]
+ gsub( /([\x00-\x1f])/ ) do |x|
+ skip[x] || ESCAPES[ x.unpack("C")[0] ]
end
end
@@ -19,7 +19,7 @@ module YAML
# Unescape the condenses escapes
#
def YAML.unescape( value )
- value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) {
+ value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { |x|
if $3
["#$3".hex ].pack('U*')
elsif $2
diff --git a/lib/yaml/rubytypes.rb b/lib/yaml/rubytypes.rb
index 35b719196e..eebf027135 100644
--- a/lib/yaml/rubytypes.rb
+++ b/lib/yaml/rubytypes.rb
@@ -12,7 +12,7 @@ class Object
def to_yaml_style; end
def to_yaml_properties; instance_variables.sort; end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
to_yaml_properties.each do |m|
map.add( m[1..-1], instance_variable_get( m ) )
@@ -35,7 +35,7 @@ class Hash
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
each do |k, v|
map.add( k, v )
@@ -83,7 +83,7 @@ class Struct
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
#
# Basic struct is passed as a YAML map
#
@@ -104,7 +104,7 @@ class Array
yaml_as "tag:yaml.org,2002:seq"
def yaml_initialize( tag, val ); concat( val.to_a ); end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
out.seq( taguri, to_yaml_style ) do |seq|
each do |x|
seq.add( x )
@@ -124,7 +124,7 @@ class Exception
o
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
map.add( 'message', message )
to_yaml_properties.each do |m|
@@ -143,7 +143,7 @@ class String
to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
end
def is_binary_data?
- ( self.count( "^ -~", "^\r\n" ).fdiv(self.size) > 0.3 || self.index( "\x00" ) ) unless empty?
+ ( self.count( "^ -~", "^\r\n" ) / self.size > 0.3 || self.count( "\x00" ) > 0 ) unless empty?
end
def String.yaml_new( klass, tag, val )
val = val.unpack("m")[0] if tag == "tag:yaml.org,2002:binary"
@@ -161,7 +161,7 @@ class String
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( is_complex_yaml? ? self : nil, opts ) do |out|
+ YAML::quick_emit( is_complex_yaml? ? object_id : nil, opts ) do |out|
if is_binary_data?
out.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), :literal )
elsif to_yaml_properties.empty?
@@ -227,7 +227,7 @@ class Range
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
# if self.begin.is_complex_yaml? or self.begin.respond_to? :to_str or
# self.end.is_complex_yaml? or self.end.respond_to? :to_str or
# not to_yaml_properties.empty?
@@ -310,7 +310,7 @@ class Time
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
tz = "Z"
# from the tidy Tobias Peters <t-peters@gmx.de> Thanks!
unless self.utc?
@@ -347,7 +347,7 @@ end
class Date
yaml_as "tag:yaml.org,2002:timestamp#ymd"
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
out.scalar( "tag:yaml.org,2002:timestamp", self.to_s, :plain )
end
end
diff --git a/lib/yaml/store.rb b/lib/yaml/store.rb
index e3a8e9fcdd..2ffa9554b9 100644
--- a/lib/yaml/store.rb
+++ b/lib/yaml/store.rb
@@ -20,24 +20,10 @@ class YAML::Store < PStore
end
def load(content)
- table = YAML::load(content)
- if table == false
- {}
- else
- table
- end
- end
-
- def marshal_dump_supports_canonical_option?
- false
+ YAML::load(content)
end
- EMPTY_MARSHAL_DATA = {}.to_yaml
- EMPTY_MARSHAL_CHECKSUM = Digest::MD5.digest(EMPTY_MARSHAL_DATA)
- def empty_marshal_data
- EMPTY_MARSHAL_DATA
- end
- def empty_marshal_checksum
- EMPTY_MARSHAL_CHECKSUM
+ def load_file(file)
+ YAML::load(file)
end
end
diff --git a/lib/yaml/types.rb b/lib/yaml/types.rb
index 3871c628fe..05113f216d 100644
--- a/lib/yaml/types.rb
+++ b/lib/yaml/types.rb
@@ -10,6 +10,7 @@ module YAML
#
class PrivateType
def self.tag_subclasses?; false; end
+ attr_accessor :type_id, :value
verbose, $VERBOSE = $VERBOSE, nil
def initialize( type, val )
@type_id = type; @value = val
@@ -27,6 +28,7 @@ module YAML
#
class DomainType
def self.tag_subclasses?; false; end
+ attr_accessor :domain, :type_id, :value
verbose, $VERBOSE = $VERBOSE, nil
def initialize( domain, type, val )
@domain = domain; @type_id = type; @value = val
@@ -45,7 +47,7 @@ module YAML
class Object
def self.tag_subclasses?; false; end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
out.map( "tag:ruby.yaml.org,2002:object:#{ @class }", to_yaml_style ) do |map|
@ivars.each do |k,v|
map.add( k, v )
@@ -123,7 +125,7 @@ module YAML
true
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( self.object_id, opts ) do |out|
out.seq( taguri, to_yaml_style ) do |seq|
self.each do |v|
seq.add( Hash[ *v ] )
@@ -173,7 +175,7 @@ module YAML
true
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( self.object_id, opts ) do |out|
out.seq( taguri, to_yaml_style ) do |seq|
self.each do |v|
seq.add( Hash[ *v ] )
diff --git a/marshal.c b/marshal.c
index f643450abd..185ace6a72 100644
--- a/marshal.c
+++ b/marshal.c
@@ -81,19 +81,9 @@ shortlen(len, ds)
#define TYPE_LINK '@'
static ID s_dump, s_load, s_mdump, s_mload;
-static ID s_dump_data, s_load_data, s_alloc, s_call;
+static ID s_dump_data, s_load_data, s_alloc;
static ID s_getc, s_read, s_write, s_binmode;
-static void
-reentrant_check(obj, sym)
- VALUE obj;
- ID sym;
-{
- if (obj && RBASIC(obj)->klass) {
- rb_raise(rb_eRuntimeError, "%s reentered", rb_id2name(sym));
- }
-}
-
struct dump_arg {
VALUE obj;
VALUE str, dest;
@@ -130,7 +120,7 @@ static void w_long _((long, struct dump_arg*));
static void
w_nbyte(s, n, arg)
- const char *s;
+ char *s;
int n;
struct dump_arg *arg;
{
@@ -153,7 +143,7 @@ w_byte(c, arg)
static void
w_bytes(s, n, arg)
- const char *s;
+ char *s;
int n;
struct dump_arg *arg;
{
@@ -338,7 +328,7 @@ w_symbol(id, arg)
ID id;
struct dump_arg *arg;
{
- const char *sym = rb_id2name(id);
+ char *sym = rb_id2name(id);
st_data_t num;
if (st_lookup(arg->symbols, id, &num)) {
@@ -354,7 +344,7 @@ w_symbol(id, arg)
static void
w_unique(s, arg)
- const char *s;
+ char *s;
struct dump_arg *arg;
{
if (s[0] == '#') {
@@ -381,7 +371,7 @@ w_extended(klass, arg, check)
struct dump_arg *arg;
int check;
{
- const char *path;
+ char *path;
if (check && FL_TEST(klass, FL_SINGLETON)) {
if (RCLASS(klass)->m_tbl->num_entries ||
@@ -478,7 +468,7 @@ w_object(obj, arg, limit)
return;
}
- if ((ivtbl = rb_generic_ivar_table(obj)) != 0) {
+ if (ivtbl = rb_generic_ivar_table(obj)) {
w_byte(TYPE_IVAR, arg);
}
if (obj == Qnil) {
@@ -512,10 +502,9 @@ w_object(obj, arg, limit)
st_add_direct(arg->data, obj, arg->data->num_entries);
if (rb_respond_to(obj, s_mdump)) {
- volatile VALUE v;
+ VALUE v;
v = rb_funcall(obj, s_mdump, 0, 0);
- reentrant_check(arg->str, s_mdump);
w_class(TYPE_USRMARSHAL, obj, arg, Qfalse);
w_object(v, arg, limit);
if (ivtbl) w_ivar(0, &c_arg);
@@ -525,7 +514,6 @@ w_object(obj, arg, limit)
VALUE v;
v = rb_funcall(obj, s_dump, 1, INT2NUM(limit));
- reentrant_check(arg->str, s_dump);
if (TYPE(v) != T_STRING) {
rb_raise(rb_eTypeError, "_dump() must return string");
}
@@ -670,7 +658,6 @@ w_object(obj, arg, limit)
rb_obj_classname(obj));
}
v = rb_funcall(obj, s_dump_data, 0);
- reentrant_check(arg->str, s_dump_data);
w_class(TYPE_DATA, obj, arg, Qtrue);
w_object(v, arg, limit);
}
@@ -703,13 +690,11 @@ static VALUE
dump_ensure(arg)
struct dump_arg *arg;
{
- if (RBASIC(arg->str)->klass) return 0; /* ignore reentrant */
st_free_table(arg->symbols);
st_free_table(arg->data);
if (arg->taint) {
OBJ_TAINT(arg->str);
}
-
return 0;
}
@@ -762,21 +747,20 @@ marshal_dump(argc, argv)
else port = a1;
}
arg.dest = 0;
- arg.str = rb_str_buf_new(0);
- RBASIC(arg.str)->klass = 0;
if (!NIL_P(port)) {
if (!rb_respond_to(port, s_write)) {
type_error:
rb_raise(rb_eTypeError, "instance of IO needed");
}
+ arg.str = rb_str_buf_new(0);
arg.dest = port;
if (rb_respond_to(port, s_binmode)) {
rb_funcall2(port, s_binmode, 0, 0);
- reentrant_check(arg.str, s_dump_data);
}
}
else {
- port = arg.str;
+ port = rb_str_buf_new(0);
+ arg.str = port;
}
arg.symbols = st_init_numtable();
@@ -790,7 +774,6 @@ marshal_dump(argc, argv)
w_byte(MARSHAL_MINOR, &arg);
rb_ensure(dump, (VALUE)&c_arg, dump_ensure, (VALUE)&arg);
- RBASIC(arg.str)->klass = rb_cString;
return port;
}
@@ -823,7 +806,6 @@ r_byte(arg)
else {
VALUE src = arg->src;
VALUE v = rb_funcall2(src, s_getc, 0, 0);
- reentrant_check(arg->data, s_getc);
if (NIL_P(v)) rb_eof_error();
c = (unsigned char)FIX2INT(v);
}
@@ -891,7 +873,7 @@ r_bytes0(len, arg)
if (len == 0) return rb_str_new(0, 0);
if (TYPE(arg->src) == T_STRING) {
- if (RSTRING(arg->src)->len - arg->offset >= len) {
+ if (RSTRING(arg->src)->len > arg->offset) {
str = rb_str_new(RSTRING(arg->src)->ptr+arg->offset, len);
arg->offset += len;
}
@@ -904,7 +886,6 @@ r_bytes0(len, arg)
VALUE src = arg->src;
VALUE n = LONG2NUM(len);
str = rb_funcall2(src, s_read, 1, &n);
- reentrant_check(arg->data, s_read);
if (NIL_P(str)) goto too_short;
StringValue(str);
if (RSTRING(str)->len != len) goto too_short;
@@ -948,7 +929,7 @@ r_symbol(arg)
return r_symreal(arg);
}
-static const char*
+static char*
r_unique(arg)
struct load_arg *arg;
{
@@ -991,7 +972,7 @@ r_ivar(obj, arg)
static VALUE
path2class(path)
- const char *path;
+ char *path;
{
VALUE v = rb_path2class(path);
@@ -1003,7 +984,7 @@ path2class(path)
static VALUE
path2module(path)
- const char *path;
+ char *path;
{
VALUE v = rb_path2class(path);
@@ -1218,6 +1199,9 @@ r_object0(arg, proc, ivp, extmod)
klass = path2class(r_unique(arg));
mem = rb_struct_s_members(klass);
+ if (mem == Qnil) {
+ rb_raise(rb_eTypeError, "uninitialized struct");
+ }
len = r_long(arg);
values = rb_ary_new2(len);
@@ -1255,7 +1239,6 @@ r_object0(arg, proc, ivp, extmod)
*ivp = Qfalse;
}
v = rb_funcall(klass, s_load, 1, data);
- reentrant_check(arg->data, s_load);
r_entry(v, arg);
}
break;
@@ -1279,7 +1262,6 @@ r_object0(arg, proc, ivp, extmod)
r_entry(v, arg);
data = r_object(arg);
rb_funcall(v, s_mload, 1, data);
- reentrant_check(arg->data, s_mload);
}
break;
@@ -1306,7 +1288,6 @@ r_object0(arg, proc, ivp, extmod)
warn = Qfalse;
}
v = rb_funcall(klass, s_alloc, 0);
- reentrant_check(arg->data, s_alloc);
}
else {
v = rb_obj_alloc(klass);
@@ -1321,7 +1302,6 @@ r_object0(arg, proc, ivp, extmod)
rb_class2name(klass));
}
rb_funcall(v, s_load_data, 1, r_object0(arg, 0, 0, extmod));
- reentrant_check(arg->data, s_load_data);
}
break;
@@ -1364,8 +1344,7 @@ r_object0(arg, proc, ivp, extmod)
break;
}
if (proc) {
- rb_funcall(proc, s_call, 1, v);
- reentrant_check(arg->data, s_call);
+ rb_funcall(proc, rb_intern("call"), 1, v);
}
return v;
}
@@ -1388,7 +1367,6 @@ static VALUE
load_ensure(arg)
struct load_arg *arg;
{
- if (RBASIC(arg->data)->klass) return 0; /* ignore reentrant */
st_free_table(arg->symbols);
return 0;
}
@@ -1415,10 +1393,9 @@ marshal_load(argc, argv)
struct load_arg arg;
rb_scan_args(argc, argv, "11", &port, &proc);
- v = rb_check_string_type(port);
- if (!NIL_P(v)) {
+ if (rb_respond_to(port, rb_intern("to_str"))) {
arg.taint = OBJ_TAINTED(port); /* original taintedness */
- port = v;
+ StringValue(port); /* possible conversion */
}
else if (rb_respond_to(port, s_getc) && rb_respond_to(port, s_read)) {
if (rb_respond_to(port, s_binmode)) {
@@ -1431,7 +1408,6 @@ marshal_load(argc, argv)
}
arg.src = port;
arg.offset = 0;
- arg.data = 0;
major = r_byte(&arg);
minor = r_byte(&arg);
@@ -1448,11 +1424,9 @@ marshal_load(argc, argv)
arg.symbols = st_init_numtable();
arg.data = rb_hash_new();
- RBASIC(arg.data)->klass = 0;
if (NIL_P(proc)) arg.proc = 0;
else arg.proc = proc;
v = rb_ensure(load, (VALUE)&arg, load_ensure, (VALUE)&arg);
- RBASIC(arg.data)->klass = rb_cHash;
return v;
}
@@ -1502,7 +1476,6 @@ Init_marshal()
s_dump_data = rb_intern("_dump_data");
s_load_data = rb_intern("_load_data");
s_alloc = rb_intern("_alloc");
- s_call = rb_intern("call");
s_getc = rb_intern("getc");
s_read = rb_intern("read");
s_write = rb_intern("write");
diff --git a/math.c b/math.c
index bf9b598156..60dd0b7204 100644
--- a/math.c
+++ b/math.c