tk_as_gem 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +22 -0
- data/Rakefile +11 -0
- data/VERSION +1 -0
- data/ext/ChangeLog.tkextlib +935 -0
- data/ext/MANUAL_tcltklib.eng +469 -0
- data/ext/MANUAL_tcltklib.eucj +579 -0
- data/ext/README.1st +19 -0
- data/ext/README.ActiveTcl +49 -0
- data/ext/README.fork +34 -0
- data/ext/README.macosx-aqua +67 -0
- data/ext/README.tcltklib +85 -0
- data/ext/depend +2 -0
- data/ext/extconf.rb +451 -0
- data/ext/lib/README +30 -0
- data/ext/lib/multi-tk.rb +3491 -0
- data/ext/lib/remote-tk.rb +530 -0
- data/ext/lib/tcltk.rb +367 -0
- data/ext/lib/tk.rb +5584 -0
- data/ext/lib/tk/after.rb +6 -0
- data/ext/lib/tk/autoload.rb +414 -0
- data/ext/lib/tk/bgerror.rb +29 -0
- data/ext/lib/tk/bindtag.rb +138 -0
- data/ext/lib/tk/button.rb +30 -0
- data/ext/lib/tk/canvas.rb +789 -0
- data/ext/lib/tk/canvastag.rb +434 -0
- data/ext/lib/tk/checkbutton.rb +30 -0
- data/ext/lib/tk/clipboard.rb +75 -0
- data/ext/lib/tk/clock.rb +71 -0
- data/ext/lib/tk/composite.rb +458 -0
- data/ext/lib/tk/console.rb +52 -0
- data/ext/lib/tk/dialog.rb +326 -0
- data/ext/lib/tk/encodedstr.rb +187 -0
- data/ext/lib/tk/entry.rb +119 -0
- data/ext/lib/tk/event.rb +542 -0
- data/ext/lib/tk/font.rb +2344 -0
- data/ext/lib/tk/frame.rb +131 -0
- data/ext/lib/tk/grid.rb +279 -0
- data/ext/lib/tk/image.rb +275 -0
- data/ext/lib/tk/itemconfig.rb +1215 -0
- data/ext/lib/tk/itemfont.rb +327 -0
- data/ext/lib/tk/kinput.rb +71 -0
- data/ext/lib/tk/label.rb +21 -0
- data/ext/lib/tk/labelframe.rb +29 -0
- data/ext/lib/tk/listbox.rb +282 -0
- data/ext/lib/tk/macpkg.rb +78 -0
- data/ext/lib/tk/menu.rb +681 -0
- data/ext/lib/tk/menubar.rb +131 -0
- data/ext/lib/tk/menuspec.rb +275 -0
- data/ext/lib/tk/message.rb +22 -0
- data/ext/lib/tk/mngfocus.rb +33 -0
- data/ext/lib/tk/msgcat.rb +296 -0
- data/ext/lib/tk/namespace.rb +551 -0
- data/ext/lib/tk/optiondb.rb +377 -0
- data/ext/lib/tk/optionobj.rb +212 -0
- data/ext/lib/tk/pack.rb +107 -0
- data/ext/lib/tk/package.rb +143 -0
- data/ext/lib/tk/palette.rb +55 -0
- data/ext/lib/tk/panedwindow.rb +258 -0
- data/ext/lib/tk/place.rb +128 -0
- data/ext/lib/tk/radiobutton.rb +71 -0
- data/ext/lib/tk/root.rb +95 -0
- data/ext/lib/tk/scale.rb +111 -0
- data/ext/lib/tk/scrollable.rb +82 -0
- data/ext/lib/tk/scrollbar.rb +177 -0
- data/ext/lib/tk/scrollbox.rb +39 -0
- data/ext/lib/tk/selection.rb +86 -0
- data/ext/lib/tk/spinbox.rb +119 -0
- data/ext/lib/tk/tagfont.rb +43 -0
- data/ext/lib/tk/text.rb +1596 -0
- data/ext/lib/tk/textimage.rb +88 -0
- data/ext/lib/tk/textmark.rb +204 -0
- data/ext/lib/tk/texttag.rb +318 -0
- data/ext/lib/tk/textwindow.rb +154 -0
- data/ext/lib/tk/timer.rb +669 -0
- data/ext/lib/tk/toplevel.rb +262 -0
- data/ext/lib/tk/ttk_selector.rb +76 -0
- data/ext/lib/tk/txtwin_abst.rb +39 -0
- data/ext/lib/tk/validation.rb +397 -0
- data/ext/lib/tk/variable.rb +1765 -0
- data/ext/lib/tk/virtevent.rb +139 -0
- data/ext/lib/tk/winfo.rb +392 -0
- data/ext/lib/tk/winpkg.rb +153 -0
- data/ext/lib/tk/wm.rb +552 -0
- data/ext/lib/tk/xim.rb +122 -0
- data/ext/lib/tkafter.rb +4 -0
- data/ext/lib/tkbgerror.rb +4 -0
- data/ext/lib/tkcanvas.rb +4 -0
- data/ext/lib/tkclass.rb +47 -0
- data/ext/lib/tkconsole.rb +4 -0
- data/ext/lib/tkdialog.rb +4 -0
- data/ext/lib/tkentry.rb +4 -0
- data/ext/lib/tkextlib/ICONS.rb +13 -0
- data/ext/lib/tkextlib/ICONS/icons.rb +129 -0
- data/ext/lib/tkextlib/ICONS/setup.rb +8 -0
- data/ext/lib/tkextlib/SUPPORT_STATUS +196 -0
- data/ext/lib/tkextlib/blt.rb +187 -0
- data/ext/lib/tkextlib/blt/barchart.rb +79 -0
- data/ext/lib/tkextlib/blt/bitmap.rb +112 -0
- data/ext/lib/tkextlib/blt/busy.rb +82 -0
- data/ext/lib/tkextlib/blt/component.rb +2145 -0
- data/ext/lib/tkextlib/blt/container.rb +28 -0
- data/ext/lib/tkextlib/blt/cutbuffer.rb +23 -0
- data/ext/lib/tkextlib/blt/dragdrop.rb +268 -0
- data/ext/lib/tkextlib/blt/eps.rb +32 -0
- data/ext/lib/tkextlib/blt/graph.rb +67 -0
- data/ext/lib/tkextlib/blt/htext.rb +111 -0
- data/ext/lib/tkextlib/blt/setup.rb +8 -0
- data/ext/lib/tkextlib/blt/spline.rb +23 -0
- data/ext/lib/tkextlib/blt/stripchart.rb +74 -0
- data/ext/lib/tkextlib/blt/table.rb +399 -0
- data/ext/lib/tkextlib/blt/tabnotebook.rb +110 -0
- data/ext/lib/tkextlib/blt/tabset.rb +500 -0
- data/ext/lib/tkextlib/blt/ted.rb +65 -0
- data/ext/lib/tkextlib/blt/tile.rb +21 -0
- data/ext/lib/tkextlib/blt/tile/button.rb +16 -0
- data/ext/lib/tkextlib/blt/tile/checkbutton.rb +17 -0
- data/ext/lib/tkextlib/blt/tile/frame.rb +16 -0
- data/ext/lib/tkextlib/blt/tile/label.rb +16 -0
- data/ext/lib/tkextlib/blt/tile/radiobutton.rb +17 -0
- data/ext/lib/tkextlib/blt/tile/scrollbar.rb +16 -0
- data/ext/lib/tkextlib/blt/tile/toplevel.rb +16 -0
- data/ext/lib/tkextlib/blt/tree.rb +1058 -0
- data/ext/lib/tkextlib/blt/treeview.rb +1272 -0
- data/ext/lib/tkextlib/blt/unix_dnd.rb +135 -0
- data/ext/lib/tkextlib/blt/vector.rb +256 -0
- data/ext/lib/tkextlib/blt/watch.rb +175 -0
- data/ext/lib/tkextlib/blt/win_printer.rb +61 -0
- data/ext/lib/tkextlib/blt/winop.rb +107 -0
- data/ext/lib/tkextlib/bwidget.rb +151 -0
- data/ext/lib/tkextlib/bwidget/arrowbutton.rb +21 -0
- data/ext/lib/tkextlib/bwidget/bitmap.rb +21 -0
- data/ext/lib/tkextlib/bwidget/button.rb +31 -0
- data/ext/lib/tkextlib/bwidget/buttonbox.rb +90 -0
- data/ext/lib/tkextlib/bwidget/combobox.rb +51 -0
- data/ext/lib/tkextlib/bwidget/dialog.rb +182 -0
- data/ext/lib/tkextlib/bwidget/dragsite.rb +31 -0
- data/ext/lib/tkextlib/bwidget/dropsite.rb +39 -0
- data/ext/lib/tkextlib/bwidget/dynamichelp.rb +63 -0
- data/ext/lib/tkextlib/bwidget/entry.rb +43 -0
- data/ext/lib/tkextlib/bwidget/label.rb +41 -0
- data/ext/lib/tkextlib/bwidget/labelentry.rb +80 -0
- data/ext/lib/tkextlib/bwidget/labelframe.rb +52 -0
- data/ext/lib/tkextlib/bwidget/listbox.rb +358 -0
- data/ext/lib/tkextlib/bwidget/mainframe.rb +128 -0
- data/ext/lib/tkextlib/bwidget/messagedlg.rb +192 -0
- data/ext/lib/tkextlib/bwidget/notebook.rb +166 -0
- data/ext/lib/tkextlib/bwidget/pagesmanager.rb +73 -0
- data/ext/lib/tkextlib/bwidget/panedwindow.rb +37 -0
- data/ext/lib/tkextlib/bwidget/panelframe.rb +57 -0
- data/ext/lib/tkextlib/bwidget/passwddlg.rb +44 -0
- data/ext/lib/tkextlib/bwidget/progressbar.rb +20 -0
- data/ext/lib/tkextlib/bwidget/progressdlg.rb +58 -0
- data/ext/lib/tkextlib/bwidget/scrollableframe.rb +40 -0
- data/ext/lib/tkextlib/bwidget/scrolledwindow.rb +38 -0
- data/ext/lib/tkextlib/bwidget/scrollview.rb +25 -0
- data/ext/lib/tkextlib/bwidget/selectcolor.rb +73 -0
- data/ext/lib/tkextlib/bwidget/selectfont.rb +86 -0
- data/ext/lib/tkextlib/bwidget/separator.rb +20 -0
- data/ext/lib/tkextlib/bwidget/setup.rb +8 -0
- data/ext/lib/tkextlib/bwidget/spinbox.rb +98 -0
- data/ext/lib/tkextlib/bwidget/statusbar.rb +52 -0
- data/ext/lib/tkextlib/bwidget/titleframe.rb +33 -0
- data/ext/lib/tkextlib/bwidget/tree.rb +453 -0
- data/ext/lib/tkextlib/bwidget/widget.rb +129 -0
- data/ext/lib/tkextlib/itcl.rb +13 -0
- data/ext/lib/tkextlib/itcl/incr_tcl.rb +178 -0
- data/ext/lib/tkextlib/itcl/setup.rb +13 -0
- data/ext/lib/tkextlib/itk.rb +13 -0
- data/ext/lib/tkextlib/itk/incr_tk.rb +446 -0
- data/ext/lib/tkextlib/itk/setup.rb +13 -0
- data/ext/lib/tkextlib/iwidgets.rb +94 -0
- data/ext/lib/tkextlib/iwidgets/buttonbox.rb +120 -0
- data/ext/lib/tkextlib/iwidgets/calendar.rb +125 -0
- data/ext/lib/tkextlib/iwidgets/canvasprintbox.rb +53 -0
- data/ext/lib/tkextlib/iwidgets/canvasprintdialog.rb +38 -0
- data/ext/lib/tkextlib/iwidgets/checkbox.rb +129 -0
- data/ext/lib/tkextlib/iwidgets/combobox.rb +104 -0
- data/ext/lib/tkextlib/iwidgets/dateentry.rb +20 -0
- data/ext/lib/tkextlib/iwidgets/datefield.rb +58 -0
- data/ext/lib/tkextlib/iwidgets/dialog.rb +20 -0
- data/ext/lib/tkextlib/iwidgets/dialogshell.rb +120 -0
- data/ext/lib/tkextlib/iwidgets/disjointlistbox.rb +50 -0
- data/ext/lib/tkextlib/iwidgets/entryfield.rb +185 -0
- data/ext/lib/tkextlib/iwidgets/extbutton.rb +40 -0
- data/ext/lib/tkextlib/iwidgets/extfileselectionbox.rb +46 -0
- data/ext/lib/tkextlib/iwidgets/extfileselectiondialog.rb +33 -0
- data/ext/lib/tkextlib/iwidgets/feedback.rb +35 -0
- data/ext/lib/tkextlib/iwidgets/fileselectionbox.rb +46 -0
- data/ext/lib/tkextlib/iwidgets/fileselectiondialog.rb +33 -0
- data/ext/lib/tkextlib/iwidgets/finddialog.rb +42 -0
- data/ext/lib/tkextlib/iwidgets/hierarchy.rb +365 -0
- data/ext/lib/tkextlib/iwidgets/hyperhelp.rb +50 -0
- data/ext/lib/tkextlib/iwidgets/labeledframe.rb +39 -0
- data/ext/lib/tkextlib/iwidgets/labeledwidget.rb +45 -0
- data/ext/lib/tkextlib/iwidgets/mainwindow.rb +67 -0
- data/ext/lib/tkextlib/iwidgets/menubar.rb +211 -0
- data/ext/lib/tkextlib/iwidgets/messagebox.rb +92 -0
- data/ext/lib/tkextlib/iwidgets/messagedialog.rb +20 -0
- data/ext/lib/tkextlib/iwidgets/notebook.rb +174 -0
- data/ext/lib/tkextlib/iwidgets/optionmenu.rb +92 -0
- data/ext/lib/tkextlib/iwidgets/panedwindow.rb +133 -0
- data/ext/lib/tkextlib/iwidgets/promptdialog.rb +131 -0
- data/ext/lib/tkextlib/iwidgets/pushbutton.rb +35 -0
- data/ext/lib/tkextlib/iwidgets/radiobox.rb +120 -0
- data/ext/lib/tkextlib/iwidgets/scopedobject.rb +24 -0
- data/ext/lib/tkextlib/iwidgets/scrolledcanvas.rb +353 -0
- data/ext/lib/tkextlib/iwidgets/scrolledframe.rb +59 -0
- data/ext/lib/tkextlib/iwidgets/scrolledhtml.rb +58 -0
- data/ext/lib/tkextlib/iwidgets/scrolledlistbox.rb +207 -0
- data/ext/lib/tkextlib/iwidgets/scrolledtext.rb +564 -0
- data/ext/lib/tkextlib/iwidgets/scrolledwidget.rb +20 -0
- data/ext/lib/tkextlib/iwidgets/selectionbox.rb +102 -0
- data/ext/lib/tkextlib/iwidgets/selectiondialog.rb +92 -0
- data/ext/lib/tkextlib/iwidgets/setup.rb +8 -0
- data/ext/lib/tkextlib/iwidgets/shell.rb +38 -0
- data/ext/lib/tkextlib/iwidgets/spindate.rb +48 -0
- data/ext/lib/tkextlib/iwidgets/spinint.rb +30 -0
- data/ext/lib/tkextlib/iwidgets/spinner.rb +169 -0
- data/ext/lib/tkextlib/iwidgets/spintime.rb +48 -0
- data/ext/lib/tkextlib/iwidgets/tabnotebook.rb +180 -0
- data/ext/lib/tkextlib/iwidgets/tabset.rb +144 -0
- data/ext/lib/tkextlib/iwidgets/timeentry.rb +25 -0
- data/ext/lib/tkextlib/iwidgets/timefield.rb +58 -0
- data/ext/lib/tkextlib/iwidgets/toolbar.rb +112 -0
- data/ext/lib/tkextlib/iwidgets/watch.rb +56 -0
- data/ext/lib/tkextlib/pkg_checker.rb +184 -0
- data/ext/lib/tkextlib/setup.rb +8 -0
- data/ext/lib/tkextlib/tcllib.rb +90 -0
- data/ext/lib/tkextlib/tcllib/README +135 -0
- data/ext/lib/tkextlib/tcllib/autoscroll.rb +158 -0
- data/ext/lib/tkextlib/tcllib/ctext.rb +160 -0
- data/ext/lib/tkextlib/tcllib/cursor.rb +97 -0
- data/ext/lib/tkextlib/tcllib/datefield.rb +57 -0
- data/ext/lib/tkextlib/tcllib/dialog.rb +84 -0
- data/ext/lib/tkextlib/tcllib/getstring.rb +134 -0
- data/ext/lib/tkextlib/tcllib/history.rb +73 -0
- data/ext/lib/tkextlib/tcllib/ico.rb +116 -0
- data/ext/lib/tkextlib/tcllib/ip_entry.rb +66 -0
- data/ext/lib/tkextlib/tcllib/panelframe.rb +72 -0
- data/ext/lib/tkextlib/tcllib/plotchart.rb +886 -0
- data/ext/lib/tkextlib/tcllib/ruler.rb +65 -0
- data/ext/lib/tkextlib/tcllib/screenruler.rb +68 -0
- data/ext/lib/tkextlib/tcllib/scrollwin.rb +61 -0
- data/ext/lib/tkextlib/tcllib/setup.rb +8 -0
- data/ext/lib/tkextlib/tcllib/style.rb +61 -0
- data/ext/lib/tkextlib/tcllib/superframe.rb +51 -0
- data/ext/lib/tkextlib/tcllib/swaplist.rb +150 -0
- data/ext/lib/tkextlib/tcllib/tablelist.rb +27 -0
- data/ext/lib/tkextlib/tcllib/tablelist_core.rb +782 -0
- data/ext/lib/tkextlib/tcllib/tablelist_tile.rb +25 -0
- data/ext/lib/tkextlib/tcllib/tkpiechart.rb +314 -0
- data/ext/lib/tkextlib/tcllib/tooltip.rb +95 -0
- data/ext/lib/tkextlib/tcllib/widget.rb +48 -0
- data/ext/lib/tkextlib/tclx.rb +13 -0
- data/ext/lib/tkextlib/tclx/setup.rb +8 -0
- data/ext/lib/tkextlib/tclx/tclx.rb +74 -0
- data/ext/lib/tkextlib/tile.rb +419 -0
- data/ext/lib/tkextlib/tile/dialog.rb +96 -0
- data/ext/lib/tkextlib/tile/setup.rb +8 -0
- data/ext/lib/tkextlib/tile/sizegrip.rb +29 -0
- data/ext/lib/tkextlib/tile/style.rb +316 -0
- data/ext/lib/tkextlib/tile/tbutton.rb +33 -0
- data/ext/lib/tkextlib/tile/tcheckbutton.rb +36 -0
- data/ext/lib/tkextlib/tile/tcombobox.rb +54 -0
- data/ext/lib/tkextlib/tile/tentry.rb +48 -0
- data/ext/lib/tkextlib/tile/tframe.rb +33 -0
- data/ext/lib/tkextlib/tile/tlabel.rb +33 -0
- data/ext/lib/tkextlib/tile/tlabelframe.rb +36 -0
- data/ext/lib/tkextlib/tile/tmenubutton.rb +36 -0
- data/ext/lib/tkextlib/tile/tnotebook.rb +139 -0
- data/ext/lib/tkextlib/tile/tpaned.rb +231 -0
- data/ext/lib/tkextlib/tile/tprogressbar.rb +56 -0
- data/ext/lib/tkextlib/tile/tradiobutton.rb +36 -0
- data/ext/lib/tkextlib/tile/treeview.rb +1239 -0
- data/ext/lib/tkextlib/tile/tscale.rb +53 -0
- data/ext/lib/tkextlib/tile/tscrollbar.rb +54 -0
- data/ext/lib/tkextlib/tile/tseparator.rb +33 -0
- data/ext/lib/tkextlib/tile/tsquare.rb +30 -0
- data/ext/lib/tkextlib/tkDND.rb +18 -0
- data/ext/lib/tkextlib/tkDND/setup.rb +8 -0
- data/ext/lib/tkextlib/tkDND/shape.rb +125 -0
- data/ext/lib/tkextlib/tkDND/tkdnd.rb +182 -0
- data/ext/lib/tkextlib/tkHTML.rb +13 -0
- data/ext/lib/tkextlib/tkHTML/htmlwidget.rb +453 -0
- data/ext/lib/tkextlib/tkHTML/setup.rb +8 -0
- data/ext/lib/tkextlib/tkimg.rb +36 -0
- data/ext/lib/tkextlib/tkimg/README +26 -0
- data/ext/lib/tkextlib/tkimg/bmp.rb +33 -0
- data/ext/lib/tkextlib/tkimg/gif.rb +33 -0
- data/ext/lib/tkextlib/tkimg/ico.rb +33 -0
- data/ext/lib/tkextlib/tkimg/jpeg.rb +33 -0
- data/ext/lib/tkextlib/tkimg/pcx.rb +33 -0
- data/ext/lib/tkextlib/tkimg/pixmap.rb +44 -0
- data/ext/lib/tkextlib/tkimg/png.rb +33 -0
- data/ext/lib/tkextlib/tkimg/ppm.rb +33 -0
- data/ext/lib/tkextlib/tkimg/ps.rb +33 -0
- data/ext/lib/tkextlib/tkimg/setup.rb +8 -0
- data/ext/lib/tkextlib/tkimg/sgi.rb +33 -0
- data/ext/lib/tkextlib/tkimg/sun.rb +33 -0
- data/ext/lib/tkextlib/tkimg/tga.rb +33 -0
- data/ext/lib/tkextlib/tkimg/tiff.rb +33 -0
- data/ext/lib/tkextlib/tkimg/window.rb +33 -0
- data/ext/lib/tkextlib/tkimg/xbm.rb +33 -0
- data/ext/lib/tkextlib/tkimg/xpm.rb +33 -0
- data/ext/lib/tkextlib/tktable.rb +14 -0
- data/ext/lib/tkextlib/tktable/setup.rb +8 -0
- data/ext/lib/tkextlib/tktable/tktable.rb +957 -0
- data/ext/lib/tkextlib/tktrans.rb +14 -0
- data/ext/lib/tkextlib/tktrans/setup.rb +8 -0
- data/ext/lib/tkextlib/tktrans/tktrans.rb +64 -0
- data/ext/lib/tkextlib/treectrl.rb +13 -0
- data/ext/lib/tkextlib/treectrl/setup.rb +8 -0
- data/ext/lib/tkextlib/treectrl/tktreectrl.rb +2461 -0
- data/ext/lib/tkextlib/trofs.rb +13 -0
- data/ext/lib/tkextlib/trofs/setup.rb +8 -0
- data/ext/lib/tkextlib/trofs/trofs.rb +51 -0
- data/ext/lib/tkextlib/version.rb +6 -0
- data/ext/lib/tkextlib/vu.rb +48 -0
- data/ext/lib/tkextlib/vu/bargraph.rb +61 -0
- data/ext/lib/tkextlib/vu/charts.rb +53 -0
- data/ext/lib/tkextlib/vu/dial.rb +102 -0
- data/ext/lib/tkextlib/vu/pie.rb +282 -0
- data/ext/lib/tkextlib/vu/setup.rb +8 -0
- data/ext/lib/tkextlib/vu/spinbox.rb +22 -0
- data/ext/lib/tkextlib/winico.rb +14 -0
- data/ext/lib/tkextlib/winico/setup.rb +8 -0
- data/ext/lib/tkextlib/winico/winico.rb +224 -0
- data/ext/lib/tkfont.rb +4 -0
- data/ext/lib/tkmacpkg.rb +4 -0
- data/ext/lib/tkmenubar.rb +4 -0
- data/ext/lib/tkmngfocus.rb +4 -0
- data/ext/lib/tkpalette.rb +4 -0
- data/ext/lib/tkscrollbox.rb +4 -0
- data/ext/lib/tktext.rb +4 -0
- data/ext/lib/tkvirtevent.rb +4 -0
- data/ext/lib/tkwinpkg.rb +4 -0
- data/ext/old-README.tcltklib.eucj +159 -0
- data/ext/stubs.c +531 -0
- data/ext/stubs.h +33 -0
- data/ext/tcltklib.c +10155 -0
- data/ext/tkutil/.cvsignore +3 -0
- data/ext/tkutil/depend +1 -0
- data/ext/tkutil/extconf.rb +14 -0
- data/ext/tkutil/tkutil.c +1789 -0
- metadata +418 -0
data/ext/tkutil/depend
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
tkutil.o: tkutil.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h
|
@@ -0,0 +1,14 @@
|
|
1
|
+
begin
|
2
|
+
has_tk = compiled?('tk')
|
3
|
+
rescue NoMethodError
|
4
|
+
# Probably, called manually (NOT from 'extmk.rb'). Force to make Makefile.
|
5
|
+
has_tk = true
|
6
|
+
end
|
7
|
+
|
8
|
+
if has_tk
|
9
|
+
require 'mkmf'
|
10
|
+
have_func("rb_obj_instance_exec", "ruby.h")
|
11
|
+
have_func("rb_sym_to_s", "ruby.h")
|
12
|
+
have_func("strndup", "string.h")
|
13
|
+
create_makefile('tkutil')
|
14
|
+
end
|
data/ext/tkutil/tkutil.c
ADDED
@@ -0,0 +1,1789 @@
|
|
1
|
+
/************************************************
|
2
|
+
|
3
|
+
tkutil.c -
|
4
|
+
|
5
|
+
$Author: ko1 $
|
6
|
+
created at: Fri Nov 3 00:47:54 JST 1995
|
7
|
+
|
8
|
+
************************************************/
|
9
|
+
|
10
|
+
#define TKUTIL_RELEASE_DATE "2008-05-23"
|
11
|
+
|
12
|
+
#include "ruby.h"
|
13
|
+
|
14
|
+
#ifdef HAVE_RUBY_ST_H
|
15
|
+
#include "ruby/st.h"
|
16
|
+
#else
|
17
|
+
#include "st.h"
|
18
|
+
#endif
|
19
|
+
|
20
|
+
static VALUE cMethod;
|
21
|
+
|
22
|
+
static VALUE cTclTkLib;
|
23
|
+
|
24
|
+
static VALUE cTkObject;
|
25
|
+
static VALUE cTkCallbackEntry;
|
26
|
+
|
27
|
+
static VALUE TK_None;
|
28
|
+
|
29
|
+
static VALUE cCB_SUBST;
|
30
|
+
static VALUE cSUBST_INFO;
|
31
|
+
|
32
|
+
static VALUE ENCODING_NAME_UTF8; /* for saving GC cost */
|
33
|
+
|
34
|
+
static ID ID_split_tklist;
|
35
|
+
static ID ID_toUTF8;
|
36
|
+
static ID ID_fromUTF8;
|
37
|
+
static ID ID_path;
|
38
|
+
static ID ID_at_path;
|
39
|
+
static ID ID_at_enc;
|
40
|
+
static ID ID_to_eval;
|
41
|
+
static ID ID_to_s;
|
42
|
+
static ID ID_source;
|
43
|
+
static ID ID_downcase;
|
44
|
+
static ID ID_install_cmd;
|
45
|
+
static ID ID_merge_tklist;
|
46
|
+
static ID ID_encoding;
|
47
|
+
static ID ID_encoding_system;
|
48
|
+
static ID ID_call;
|
49
|
+
|
50
|
+
static ID ID_SUBST_INFO;
|
51
|
+
|
52
|
+
static VALUE CALLBACK_TABLE;
|
53
|
+
static unsigned long CALLBACK_ID_NUM = 0;
|
54
|
+
|
55
|
+
/*************************************/
|
56
|
+
|
57
|
+
static VALUE
|
58
|
+
tk_s_new(argc, argv, klass)
|
59
|
+
int argc;
|
60
|
+
VALUE *argv;
|
61
|
+
VALUE klass;
|
62
|
+
{
|
63
|
+
VALUE obj = rb_class_new_instance(argc, argv, klass);
|
64
|
+
|
65
|
+
if (rb_block_given_p()) {
|
66
|
+
#ifndef HAVE_RB_OBJ_INSTANCE_EXEC
|
67
|
+
rb_obj_instance_eval(0, 0, obj);
|
68
|
+
#else
|
69
|
+
rb_obj_instance_exec(1, &obj, obj);
|
70
|
+
#endif
|
71
|
+
}
|
72
|
+
return obj;
|
73
|
+
}
|
74
|
+
|
75
|
+
/*************************************/
|
76
|
+
|
77
|
+
static VALUE
|
78
|
+
tkNone_to_s(self)
|
79
|
+
VALUE self;
|
80
|
+
{
|
81
|
+
return rb_str_new2("None");
|
82
|
+
}
|
83
|
+
|
84
|
+
/*************************************/
|
85
|
+
|
86
|
+
static VALUE
|
87
|
+
tk_eval_cmd(argc, argv, self)
|
88
|
+
int argc;
|
89
|
+
VALUE argv[];
|
90
|
+
VALUE self;
|
91
|
+
{
|
92
|
+
volatile VALUE cmd, rest;
|
93
|
+
|
94
|
+
rb_scan_args(argc, argv, "1*", &cmd, &rest);
|
95
|
+
return rb_eval_cmd(cmd, rest, 0);
|
96
|
+
}
|
97
|
+
|
98
|
+
static VALUE
|
99
|
+
tk_do_callback(argc, argv, self)
|
100
|
+
int argc;
|
101
|
+
VALUE *argv;
|
102
|
+
VALUE self;
|
103
|
+
{
|
104
|
+
#if 0
|
105
|
+
volatile VALUE id;
|
106
|
+
volatile VALUE rest;
|
107
|
+
|
108
|
+
rb_scan_args(argc, argv, "1*", &id, &rest);
|
109
|
+
return rb_apply(rb_hash_aref(CALLBACK_TABLE, id), ID_call, rest);
|
110
|
+
#endif
|
111
|
+
return rb_funcall2(rb_hash_aref(CALLBACK_TABLE, argv[0]),
|
112
|
+
ID_call, argc - 1, argv + 1);
|
113
|
+
}
|
114
|
+
|
115
|
+
static const char cmd_id_head[] = "ruby_cmd TkUtil callback ";
|
116
|
+
static const char cmd_id_prefix[] = "cmd";
|
117
|
+
|
118
|
+
static VALUE
|
119
|
+
tk_install_cmd_core(cmd)
|
120
|
+
VALUE cmd;
|
121
|
+
{
|
122
|
+
volatile VALUE id_num;
|
123
|
+
|
124
|
+
id_num = ULONG2NUM(CALLBACK_ID_NUM++);
|
125
|
+
id_num = rb_funcall(id_num, ID_to_s, 0, 0);
|
126
|
+
id_num = rb_str_append(rb_str_new2(cmd_id_prefix), id_num);
|
127
|
+
rb_hash_aset(CALLBACK_TABLE, id_num, cmd);
|
128
|
+
return rb_str_append(rb_str_new2(cmd_id_head), id_num);
|
129
|
+
}
|
130
|
+
|
131
|
+
static VALUE
|
132
|
+
tk_install_cmd(argc, argv, self)
|
133
|
+
int argc;
|
134
|
+
VALUE *argv;
|
135
|
+
VALUE self;
|
136
|
+
{
|
137
|
+
volatile VALUE cmd;
|
138
|
+
|
139
|
+
#if 0
|
140
|
+
if (rb_scan_args(argc, argv, "01", &cmd) == 0) {
|
141
|
+
cmd = rb_block_proc();
|
142
|
+
}
|
143
|
+
return tk_install_cmd_core(cmd);
|
144
|
+
#endif
|
145
|
+
if (argc == 0) {
|
146
|
+
cmd = rb_block_proc();
|
147
|
+
} else {
|
148
|
+
cmd = argv[0];
|
149
|
+
}
|
150
|
+
return tk_install_cmd_core(cmd);
|
151
|
+
}
|
152
|
+
|
153
|
+
static VALUE
|
154
|
+
tk_uninstall_cmd(self, cmd_id)
|
155
|
+
VALUE self;
|
156
|
+
VALUE cmd_id;
|
157
|
+
{
|
158
|
+
int head_len = strlen(cmd_id_head);
|
159
|
+
int prefix_len = strlen(cmd_id_prefix);
|
160
|
+
|
161
|
+
StringValue(cmd_id);
|
162
|
+
if (strncmp(cmd_id_head, RSTRING_PTR(cmd_id), head_len) != 0) {
|
163
|
+
return Qnil;
|
164
|
+
}
|
165
|
+
if (strncmp(cmd_id_prefix,
|
166
|
+
RSTRING_PTR(cmd_id) + head_len, prefix_len) != 0) {
|
167
|
+
return Qnil;
|
168
|
+
}
|
169
|
+
|
170
|
+
return rb_hash_delete(CALLBACK_TABLE,
|
171
|
+
rb_str_new2(RSTRING_PTR(cmd_id) + head_len));
|
172
|
+
}
|
173
|
+
|
174
|
+
static VALUE
|
175
|
+
tk_toUTF8(argc, argv, self)
|
176
|
+
int argc;
|
177
|
+
VALUE *argv;
|
178
|
+
VALUE self;
|
179
|
+
{
|
180
|
+
return rb_funcall2(cTclTkLib, ID_toUTF8, argc, argv);
|
181
|
+
}
|
182
|
+
|
183
|
+
static VALUE
|
184
|
+
tk_fromUTF8(argc, argv, self)
|
185
|
+
int argc;
|
186
|
+
VALUE *argv;
|
187
|
+
VALUE self;
|
188
|
+
{
|
189
|
+
return rb_funcall2(cTclTkLib, ID_fromUTF8, argc, argv);
|
190
|
+
}
|
191
|
+
|
192
|
+
static VALUE
|
193
|
+
fromDefaultEnc_toUTF8(str, self)
|
194
|
+
VALUE str;
|
195
|
+
VALUE self;
|
196
|
+
{
|
197
|
+
VALUE argv[1];
|
198
|
+
|
199
|
+
argv[0] = str;
|
200
|
+
return tk_toUTF8(1, argv, self);
|
201
|
+
}
|
202
|
+
|
203
|
+
#if 0
|
204
|
+
static VALUE
|
205
|
+
fromUTF8_toDefaultEnc(str, self)
|
206
|
+
VALUE str;
|
207
|
+
VALUE self;
|
208
|
+
{
|
209
|
+
VALUE argv[1];
|
210
|
+
|
211
|
+
argv[0] = str;
|
212
|
+
return tk_fromUTF8(1, argv, self);
|
213
|
+
}
|
214
|
+
#endif
|
215
|
+
|
216
|
+
static int
|
217
|
+
to_strkey(key, value, hash)
|
218
|
+
VALUE key;
|
219
|
+
VALUE value;
|
220
|
+
VALUE hash;
|
221
|
+
{
|
222
|
+
if (key == Qundef) return ST_CONTINUE;
|
223
|
+
rb_hash_aset(hash, rb_funcall(key, ID_to_s, 0, 0), value);
|
224
|
+
return ST_CHECK;
|
225
|
+
}
|
226
|
+
|
227
|
+
static VALUE
|
228
|
+
tk_symbolkey2str(self, keys)
|
229
|
+
VALUE self;
|
230
|
+
VALUE keys;
|
231
|
+
{
|
232
|
+
volatile VALUE new_keys = rb_hash_new();
|
233
|
+
|
234
|
+
if NIL_P(keys) return new_keys;
|
235
|
+
keys = rb_convert_type(keys, T_HASH, "Hash", "to_hash");
|
236
|
+
st_foreach(RHASH_TBL(keys), to_strkey, new_keys);
|
237
|
+
return new_keys;
|
238
|
+
}
|
239
|
+
|
240
|
+
static VALUE get_eval_string_core _((VALUE, VALUE, VALUE));
|
241
|
+
static VALUE ary2list _((VALUE, VALUE, VALUE));
|
242
|
+
static VALUE ary2list2 _((VALUE, VALUE, VALUE));
|
243
|
+
static VALUE hash2list _((VALUE, VALUE));
|
244
|
+
static VALUE hash2list_enc _((VALUE, VALUE));
|
245
|
+
static VALUE hash2kv _((VALUE, VALUE, VALUE));
|
246
|
+
static VALUE hash2kv_enc _((VALUE, VALUE, VALUE));
|
247
|
+
|
248
|
+
static VALUE
|
249
|
+
ary2list(ary, enc_flag, self)
|
250
|
+
VALUE ary;
|
251
|
+
VALUE enc_flag;
|
252
|
+
VALUE self;
|
253
|
+
{
|
254
|
+
int idx, idx2, size, size2, req_chk_flag;
|
255
|
+
volatile VALUE val, val2, str_val;
|
256
|
+
volatile VALUE dst;
|
257
|
+
volatile VALUE sys_enc, dst_enc, str_enc;
|
258
|
+
|
259
|
+
sys_enc = rb_funcall(cTclTkLib, ID_encoding, 0, 0);
|
260
|
+
if (NIL_P(sys_enc)) {
|
261
|
+
sys_enc = rb_funcall(cTclTkLib, ID_encoding_system, 0, 0);
|
262
|
+
sys_enc = rb_funcall(sys_enc, ID_to_s, 0, 0);
|
263
|
+
}
|
264
|
+
|
265
|
+
if NIL_P(enc_flag) {
|
266
|
+
dst_enc = sys_enc;
|
267
|
+
req_chk_flag = 1;
|
268
|
+
} else if (TYPE(enc_flag) == T_TRUE || TYPE(enc_flag) == T_FALSE) {
|
269
|
+
dst_enc = enc_flag;
|
270
|
+
req_chk_flag = 0;
|
271
|
+
} else {
|
272
|
+
dst_enc = rb_funcall(enc_flag, ID_to_s, 0, 0);
|
273
|
+
req_chk_flag = 0;
|
274
|
+
}
|
275
|
+
|
276
|
+
/* size = RARRAY_LEN(ary); */
|
277
|
+
size = 0;
|
278
|
+
for(idx = 0; idx < RARRAY_LEN(ary); idx++) {
|
279
|
+
if (TYPE(RARRAY_PTR(ary)[idx]) == T_HASH) {
|
280
|
+
size += 2 * RHASH_SIZE(RARRAY_PTR(ary)[idx]);
|
281
|
+
} else {
|
282
|
+
size++;
|
283
|
+
}
|
284
|
+
}
|
285
|
+
|
286
|
+
dst = rb_ary_new2(size);
|
287
|
+
for(idx = 0; idx < RARRAY_LEN(ary); idx++) {
|
288
|
+
val = RARRAY_PTR(ary)[idx];
|
289
|
+
str_val = Qnil;
|
290
|
+
switch(TYPE(val)) {
|
291
|
+
case T_ARRAY:
|
292
|
+
str_val = ary2list(val, enc_flag, self);
|
293
|
+
rb_ary_push(dst, str_val);
|
294
|
+
|
295
|
+
if (req_chk_flag) {
|
296
|
+
str_enc = rb_ivar_get(str_val, ID_at_enc);
|
297
|
+
if (!NIL_P(str_enc)) {
|
298
|
+
str_enc = rb_funcall(str_enc, ID_to_s, 0, 0);
|
299
|
+
} else {
|
300
|
+
str_enc = sys_enc;
|
301
|
+
}
|
302
|
+
if (!rb_str_cmp(str_enc, dst_enc)) {
|
303
|
+
dst_enc = Qtrue;
|
304
|
+
req_chk_flag = 0;
|
305
|
+
}
|
306
|
+
}
|
307
|
+
|
308
|
+
break;
|
309
|
+
|
310
|
+
case T_HASH:
|
311
|
+
/* rb_ary_push(dst, hash2list(val, self)); */
|
312
|
+
if (RTEST(enc_flag)) {
|
313
|
+
val = hash2kv_enc(val, Qnil, self);
|
314
|
+
} else {
|
315
|
+
val = hash2kv(val, Qnil, self);
|
316
|
+
}
|
317
|
+
size2 = RARRAY_LEN(val);
|
318
|
+
for(idx2 = 0; idx2 < size2; idx2++) {
|
319
|
+
val2 = RARRAY_PTR(val)[idx2];
|
320
|
+
switch(TYPE(val2)) {
|
321
|
+
case T_ARRAY:
|
322
|
+
str_val = ary2list(val2, enc_flag, self);
|
323
|
+
rb_ary_push(dst, str_val);
|
324
|
+
break;
|
325
|
+
|
326
|
+
case T_HASH:
|
327
|
+
if (RTEST(enc_flag)) {
|
328
|
+
str_val = hash2list_enc(val2, self);
|
329
|
+
} else {
|
330
|
+
str_val = hash2list(val2, self);
|
331
|
+
}
|
332
|
+
rb_ary_push(dst, str_val);
|
333
|
+
break;
|
334
|
+
|
335
|
+
default:
|
336
|
+
if (val2 != TK_None) {
|
337
|
+
str_val = get_eval_string_core(val2, enc_flag, self);
|
338
|
+
rb_ary_push(dst, str_val);
|
339
|
+
}
|
340
|
+
}
|
341
|
+
|
342
|
+
if (req_chk_flag) {
|
343
|
+
str_enc = rb_ivar_get(str_val, ID_at_enc);
|
344
|
+
if (!NIL_P(str_enc)) {
|
345
|
+
str_enc = rb_funcall(str_enc, ID_to_s, 0, 0);
|
346
|
+
} else {
|
347
|
+
str_enc = sys_enc;
|
348
|
+
}
|
349
|
+
if (!rb_str_cmp(str_enc, dst_enc)) {
|
350
|
+
dst_enc = Qtrue;
|
351
|
+
req_chk_flag = 0;
|
352
|
+
}
|
353
|
+
}
|
354
|
+
}
|
355
|
+
break;
|
356
|
+
|
357
|
+
default:
|
358
|
+
if (val != TK_None) {
|
359
|
+
str_val = get_eval_string_core(val, enc_flag, self);
|
360
|
+
rb_ary_push(dst, str_val);
|
361
|
+
|
362
|
+
if (req_chk_flag) {
|
363
|
+
str_enc = rb_ivar_get(str_val, ID_at_enc);
|
364
|
+
if (!NIL_P(str_enc)) {
|
365
|
+
str_enc = rb_funcall(str_enc, ID_to_s, 0, 0);
|
366
|
+
} else {
|
367
|
+
str_enc = sys_enc;
|
368
|
+
}
|
369
|
+
if (!rb_str_cmp(str_enc, dst_enc)) {
|
370
|
+
dst_enc = Qtrue;
|
371
|
+
req_chk_flag = 0;
|
372
|
+
}
|
373
|
+
}
|
374
|
+
}
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
if (RTEST(dst_enc) && !NIL_P(sys_enc)) {
|
379
|
+
for(idx = 0; idx < RARRAY_LEN(dst); idx++) {
|
380
|
+
str_val = RARRAY_PTR(dst)[idx];
|
381
|
+
if (rb_obj_respond_to(self, ID_toUTF8, Qtrue)) {
|
382
|
+
str_val = rb_funcall(self, ID_toUTF8, 1, str_val);
|
383
|
+
} else {
|
384
|
+
str_val = rb_funcall(cTclTkLib, ID_toUTF8, 1, str_val);
|
385
|
+
}
|
386
|
+
RARRAY_PTR(dst)[idx] = str_val;
|
387
|
+
}
|
388
|
+
val = rb_apply(cTclTkLib, ID_merge_tklist, dst);
|
389
|
+
if (TYPE(dst_enc) == T_STRING) {
|
390
|
+
val = rb_funcall(cTclTkLib, ID_fromUTF8, 2, val, dst_enc);
|
391
|
+
rb_ivar_set(val, ID_at_enc, dst_enc);
|
392
|
+
} else {
|
393
|
+
rb_ivar_set(val, ID_at_enc, ENCODING_NAME_UTF8);
|
394
|
+
}
|
395
|
+
return val;
|
396
|
+
} else {
|
397
|
+
return rb_apply(cTclTkLib, ID_merge_tklist, dst);
|
398
|
+
}
|
399
|
+
}
|
400
|
+
|
401
|
+
static VALUE
|
402
|
+
ary2list2(ary, enc_flag, self)
|
403
|
+
VALUE ary;
|
404
|
+
VALUE enc_flag;
|
405
|
+
VALUE self;
|
406
|
+
{
|
407
|
+
int idx, size, req_chk_flag;
|
408
|
+
volatile VALUE val, str_val;
|
409
|
+
volatile VALUE dst;
|
410
|
+
volatile VALUE sys_enc, dst_enc, str_enc;
|
411
|
+
|
412
|
+
sys_enc = rb_funcall(cTclTkLib, ID_encoding, 0, 0);
|
413
|
+
if NIL_P(sys_enc) {
|
414
|
+
sys_enc = rb_funcall(cTclTkLib, ID_encoding_system, 0, 0);
|
415
|
+
sys_enc = rb_funcall(sys_enc, ID_to_s, 0, 0);
|
416
|
+
}
|
417
|
+
|
418
|
+
if NIL_P(enc_flag) {
|
419
|
+
dst_enc = sys_enc;
|
420
|
+
req_chk_flag = 1;
|
421
|
+
} else if (TYPE(enc_flag) == T_TRUE || TYPE(enc_flag) == T_FALSE) {
|
422
|
+
dst_enc = enc_flag;
|
423
|
+
req_chk_flag = 0;
|
424
|
+
} else {
|
425
|
+
dst_enc = rb_funcall(enc_flag, ID_to_s, 0, 0);
|
426
|
+
req_chk_flag = 0;
|
427
|
+
}
|
428
|
+
|
429
|
+
size = RARRAY_LEN(ary);
|
430
|
+
dst = rb_ary_new2(size);
|
431
|
+
for(idx = 0; idx < RARRAY_LEN(ary); idx++) {
|
432
|
+
val = RARRAY_PTR(ary)[idx];
|
433
|
+
str_val = Qnil;
|
434
|
+
switch(TYPE(val)) {
|
435
|
+
case T_ARRAY:
|
436
|
+
str_val = ary2list(val, enc_flag, self);
|
437
|
+
break;
|
438
|
+
|
439
|
+
case T_HASH:
|
440
|
+
if (RTEST(enc_flag)) {
|
441
|
+
str_val = hash2list(val, self);
|
442
|
+
} else {
|
443
|
+
str_val = hash2list_enc(val, self);
|
444
|
+
}
|
445
|
+
break;
|
446
|
+
|
447
|
+
default:
|
448
|
+
if (val != TK_None) {
|
449
|
+
str_val = get_eval_string_core(val, enc_flag, self);
|
450
|
+
}
|
451
|
+
}
|
452
|
+
|
453
|
+
if (!NIL_P(str_val)) {
|
454
|
+
rb_ary_push(dst, str_val);
|
455
|
+
|
456
|
+
if (req_chk_flag) {
|
457
|
+
str_enc = rb_ivar_get(str_val, ID_at_enc);
|
458
|
+
if (!NIL_P(str_enc)) {
|
459
|
+
str_enc = rb_funcall(str_enc, ID_to_s, 0, 0);
|
460
|
+
} else {
|
461
|
+
str_enc = sys_enc;
|
462
|
+
}
|
463
|
+
if (!rb_str_cmp(str_enc, dst_enc)) {
|
464
|
+
dst_enc = Qtrue;
|
465
|
+
req_chk_flag = 0;
|
466
|
+
}
|
467
|
+
}
|
468
|
+
}
|
469
|
+
}
|
470
|
+
|
471
|
+
if (RTEST(dst_enc) && !NIL_P(sys_enc)) {
|
472
|
+
for(idx = 0; idx < RARRAY_LEN(dst); idx++) {
|
473
|
+
str_val = RARRAY_PTR(dst)[idx];
|
474
|
+
if (rb_obj_respond_to(self, ID_toUTF8, Qtrue)) {
|
475
|
+
str_val = rb_funcall(self, ID_toUTF8, 1, str_val);
|
476
|
+
} else {
|
477
|
+
str_val = rb_funcall(cTclTkLib, ID_toUTF8, 1, str_val);
|
478
|
+
}
|
479
|
+
RARRAY_PTR(dst)[idx] = str_val;
|
480
|
+
}
|
481
|
+
val = rb_apply(cTclTkLib, ID_merge_tklist, dst);
|
482
|
+
if (TYPE(dst_enc) == T_STRING) {
|
483
|
+
val = rb_funcall(cTclTkLib, ID_fromUTF8, 2, val, dst_enc);
|
484
|
+
rb_ivar_set(val, ID_at_enc, dst_enc);
|
485
|
+
} else {
|
486
|
+
rb_ivar_set(val, ID_at_enc, ENCODING_NAME_UTF8);
|
487
|
+
}
|
488
|
+
return val;
|
489
|
+
} else {
|
490
|
+
return rb_apply(cTclTkLib, ID_merge_tklist, dst);
|
491
|
+
}
|
492
|
+
}
|
493
|
+
|
494
|
+
static VALUE
|
495
|
+
key2keyname(key)
|
496
|
+
VALUE key;
|
497
|
+
{
|
498
|
+
return rb_str_append(rb_str_new2("-"), rb_funcall(key, ID_to_s, 0, 0));
|
499
|
+
}
|
500
|
+
|
501
|
+
static VALUE
|
502
|
+
assoc2kv(assoc, ary, self)
|
503
|
+
VALUE assoc;
|
504
|
+
VALUE ary;
|
505
|
+
VALUE self;
|
506
|
+
{
|
507
|
+
int i, j, len;
|
508
|
+
volatile VALUE pair;
|
509
|
+
volatile VALUE val;
|
510
|
+
volatile VALUE dst = rb_ary_new2(2 * RARRAY_LEN(assoc));
|
511
|
+
|
512
|
+
len = RARRAY_LEN(assoc);
|
513
|
+
|
514
|
+
for(i = 0; i < len; i++) {
|
515
|
+
pair = RARRAY_PTR(assoc)[i];
|
516
|
+
if (TYPE(pair) != T_ARRAY) {
|
517
|
+
rb_ary_push(dst, key2keyname(pair));
|
518
|
+
continue;
|
519
|
+
}
|
520
|
+
switch(RARRAY_LEN(assoc)) {
|
521
|
+
case 2:
|
522
|
+
rb_ary_push(dst, RARRAY_PTR(pair)[2]);
|
523
|
+
|
524
|
+
case 1:
|
525
|
+
rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0]));
|
526
|
+
|
527
|
+
case 0:
|
528
|
+
continue;
|
529
|
+
|
530
|
+
default:
|
531
|
+
rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0]));
|
532
|
+
|
533
|
+
val = rb_ary_new2(RARRAY_LEN(pair) - 1);
|
534
|
+
for(j = 1; j < RARRAY_LEN(pair); j++) {
|
535
|
+
rb_ary_push(val, RARRAY_PTR(pair)[j]);
|
536
|
+
}
|
537
|
+
|
538
|
+
rb_ary_push(dst, val);
|
539
|
+
}
|
540
|
+
}
|
541
|
+
|
542
|
+
if (NIL_P(ary)) {
|
543
|
+
return dst;
|
544
|
+
} else {
|
545
|
+
return rb_ary_plus(ary, dst);
|
546
|
+
}
|
547
|
+
}
|
548
|
+
|
549
|
+
static VALUE
|
550
|
+
assoc2kv_enc(assoc, ary, self)
|
551
|
+
VALUE assoc;
|
552
|
+
VALUE ary;
|
553
|
+
VALUE self;
|
554
|
+
{
|
555
|
+
int i, j, len;
|
556
|
+
volatile VALUE pair;
|
557
|
+
volatile VALUE val;
|
558
|
+
volatile VALUE dst = rb_ary_new2(2 * RARRAY_LEN(assoc));
|
559
|
+
|
560
|
+
len = RARRAY_LEN(assoc);
|
561
|
+
|
562
|
+
for(i = 0; i < len; i++) {
|
563
|
+
pair = RARRAY_PTR(assoc)[i];
|
564
|
+
if (TYPE(pair) != T_ARRAY) {
|
565
|
+
rb_ary_push(dst, key2keyname(pair));
|
566
|
+
continue;
|
567
|
+
}
|
568
|
+
switch(RARRAY_LEN(assoc)) {
|
569
|
+
case 2:
|
570
|
+
rb_ary_push(dst, get_eval_string_core(RARRAY_PTR(pair)[2], Qtrue, self));
|
571
|
+
|
572
|
+
case 1:
|
573
|
+
rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0]));
|
574
|
+
|
575
|
+
case 0:
|
576
|
+
continue;
|
577
|
+
|
578
|
+
default:
|
579
|
+
rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0]));
|
580
|
+
|
581
|
+
val = rb_ary_new2(RARRAY_LEN(pair) - 1);
|
582
|
+
for(j = 1; j < RARRAY_LEN(pair); j++) {
|
583
|
+
rb_ary_push(val, RARRAY_PTR(pair)[j]);
|
584
|
+
}
|
585
|
+
|
586
|
+
rb_ary_push(dst, get_eval_string_core(val, Qtrue, self));
|
587
|
+
}
|
588
|
+
}
|
589
|
+
|
590
|
+
if (NIL_P(ary)) {
|
591
|
+
return dst;
|
592
|
+
} else {
|
593
|
+
return rb_ary_plus(ary, dst);
|
594
|
+
}
|
595
|
+
}
|
596
|
+
|
597
|
+
static int
|
598
|
+
push_kv(key, val, args)
|
599
|
+
VALUE key;
|
600
|
+
VALUE val;
|
601
|
+
VALUE args;
|
602
|
+
{
|
603
|
+
volatile VALUE ary;
|
604
|
+
|
605
|
+
ary = RARRAY_PTR(args)[0];
|
606
|
+
|
607
|
+
if (key == Qundef) return ST_CONTINUE;
|
608
|
+
#if 0
|
609
|
+
rb_ary_push(ary, key2keyname(key));
|
610
|
+
if (val != TK_None) rb_ary_push(ary, val);
|
611
|
+
#endif
|
612
|
+
rb_ary_push(ary, key2keyname(key));
|
613
|
+
|
614
|
+
if (val == TK_None) return ST_CHECK;
|
615
|
+
|
616
|
+
rb_ary_push(ary, get_eval_string_core(val, Qnil, RARRAY_PTR(args)[1]));
|
617
|
+
|
618
|
+
return ST_CHECK;
|
619
|
+
}
|
620
|
+
|
621
|
+
static VALUE
|
622
|
+
hash2kv(hash, ary, self)
|
623
|
+
VALUE hash;
|
624
|
+
VALUE ary;
|
625
|
+
VALUE self;
|
626
|
+
{
|
627
|
+
volatile VALUE dst = rb_ary_new2(2 * RHASH_SIZE(hash));
|
628
|
+
volatile VALUE args = rb_ary_new3(2, dst, self);
|
629
|
+
|
630
|
+
st_foreach(RHASH_TBL(hash), push_kv, args);
|
631
|
+
|
632
|
+
if (NIL_P(ary)) {
|
633
|
+
return dst;
|
634
|
+
} else {
|
635
|
+
return rb_ary_concat(ary, dst);
|
636
|
+
}
|
637
|
+
}
|
638
|
+
|
639
|
+
static int
|
640
|
+
push_kv_enc(key, val, args)
|
641
|
+
VALUE key;
|
642
|
+
VALUE val;
|
643
|
+
VALUE args;
|
644
|
+
{
|
645
|
+
volatile VALUE ary;
|
646
|
+
|
647
|
+
ary = RARRAY_PTR(args)[0];
|
648
|
+
|
649
|
+
if (key == Qundef) return ST_CONTINUE;
|
650
|
+
#if 0
|
651
|
+
rb_ary_push(ary, key2keyname(key));
|
652
|
+
if (val != TK_None) {
|
653
|
+
rb_ary_push(ary, get_eval_string_core(val, Qtrue,
|
654
|
+
RARRAY_PTR(args)[1]));
|
655
|
+
}
|
656
|
+
#endif
|
657
|
+
rb_ary_push(ary, key2keyname(key));
|
658
|
+
|
659
|
+
if (val == TK_None) return ST_CHECK;
|
660
|
+
|
661
|
+
rb_ary_push(ary, get_eval_string_core(val, Qtrue, RARRAY_PTR(args)[1]));
|
662
|
+
|
663
|
+
return ST_CHECK;
|
664
|
+
}
|
665
|
+
|
666
|
+
static VALUE
|
667
|
+
hash2kv_enc(hash, ary, self)
|
668
|
+
VALUE hash;
|
669
|
+
VALUE ary;
|
670
|
+
VALUE self;
|
671
|
+
{
|
672
|
+
volatile VALUE dst = rb_ary_new2(2 * RHASH_SIZE(hash));
|
673
|
+
volatile VALUE args = rb_ary_new3(2, dst, self);
|
674
|
+
|
675
|
+
st_foreach(RHASH_TBL(hash), push_kv_enc, args);
|
676
|
+
|
677
|
+
if (NIL_P(ary)) {
|
678
|
+
return dst;
|
679
|
+
} else {
|
680
|
+
return rb_ary_concat(ary, dst);
|
681
|
+
}
|
682
|
+
}
|
683
|
+
|
684
|
+
static VALUE
|
685
|
+
hash2list(hash, self)
|
686
|
+
VALUE hash;
|
687
|
+
VALUE self;
|
688
|
+
{
|
689
|
+
return ary2list2(hash2kv(hash, Qnil, self), Qfalse, self);
|
690
|
+
}
|
691
|
+
|
692
|
+
|
693
|
+
static VALUE
|
694
|
+
hash2list_enc(hash, self)
|
695
|
+
VALUE hash;
|
696
|
+
VALUE self;
|
697
|
+
{
|
698
|
+
return ary2list2(hash2kv_enc(hash, Qnil, self), Qfalse, self);
|
699
|
+
}
|
700
|
+
|
701
|
+
static VALUE
|
702
|
+
tk_hash_kv(argc, argv, self)
|
703
|
+
int argc;
|
704
|
+
VALUE *argv;
|
705
|
+
VALUE self;
|
706
|
+
{
|
707
|
+
volatile VALUE hash, enc_flag, ary;
|
708
|
+
|
709
|
+
ary = Qnil;
|
710
|
+
enc_flag = Qnil;
|
711
|
+
switch(argc) {
|
712
|
+
case 3:
|
713
|
+
ary = argv[2];
|
714
|
+
case 2:
|
715
|
+
enc_flag = argv[1];
|
716
|
+
case 1:
|
717
|
+
hash = argv[0];
|
718
|
+
break;
|
719
|
+
case 0:
|
720
|
+
rb_raise(rb_eArgError, "too few arguments");
|
721
|
+
default: /* >= 3 */
|
722
|
+
rb_raise(rb_eArgError, "too many arguments");
|
723
|
+
}
|
724
|
+
|
725
|
+
switch(TYPE(hash)) {
|
726
|
+
case T_ARRAY:
|
727
|
+
if (RTEST(enc_flag)) {
|
728
|
+
return assoc2kv_enc(hash, ary, self);
|
729
|
+
} else {
|
730
|
+
return assoc2kv(hash, ary, self);
|
731
|
+
}
|
732
|
+
|
733
|
+
case T_HASH:
|
734
|
+
if (RTEST(enc_flag)) {
|
735
|
+
return hash2kv_enc(hash, ary, self);
|
736
|
+
} else {
|
737
|
+
return hash2kv(hash, ary, self);
|
738
|
+
}
|
739
|
+
|
740
|
+
case T_NIL:
|
741
|
+
if (NIL_P(ary)) {
|
742
|
+
return rb_ary_new();
|
743
|
+
} else {
|
744
|
+
return ary;
|
745
|
+
}
|
746
|
+
|
747
|
+
default:
|
748
|
+
if (hash == TK_None) {
|
749
|
+
if (NIL_P(ary)) {
|
750
|
+
return rb_ary_new();
|
751
|
+
} else {
|
752
|
+
return ary;
|
753
|
+
}
|
754
|
+
}
|
755
|
+
rb_raise(rb_eArgError, "Hash is expected for 1st argument");
|
756
|
+
}
|
757
|
+
}
|
758
|
+
|
759
|
+
static VALUE
|
760
|
+
get_eval_string_core(obj, enc_flag, self)
|
761
|
+
VALUE obj;
|
762
|
+
VALUE enc_flag;
|
763
|
+
VALUE self;
|
764
|
+
{
|
765
|
+
switch(TYPE(obj)) {
|
766
|
+
case T_FLOAT:
|
767
|
+
case T_FIXNUM:
|
768
|
+
case T_BIGNUM:
|
769
|
+
return rb_funcall(obj, ID_to_s, 0, 0);
|
770
|
+
|
771
|
+
case T_STRING:
|
772
|
+
if (RTEST(enc_flag)) {
|
773
|
+
if (rb_obj_respond_to(self, ID_toUTF8, Qtrue)) {
|
774
|
+
return rb_funcall(self, ID_toUTF8, 1, obj);
|
775
|
+
} else {
|
776
|
+
return fromDefaultEnc_toUTF8(obj, self);
|
777
|
+
}
|
778
|
+
} else {
|
779
|
+
return obj;
|
780
|
+
}
|
781
|
+
|
782
|
+
case T_SYMBOL:
|
783
|
+
if (RTEST(enc_flag)) {
|
784
|
+
if (rb_obj_respond_to(self, ID_toUTF8, Qtrue)) {
|
785
|
+
return rb_funcall(self, ID_toUTF8, 1,
|
786
|
+
rb_str_new2(rb_id2name(SYM2ID(obj))));
|
787
|
+
} else {
|
788
|
+
return fromDefaultEnc_toUTF8(rb_str_new2(rb_id2name(SYM2ID(obj))), self);
|
789
|
+
}
|
790
|
+
} else {
|
791
|
+
#ifdef HAVE_RB_SYM_TO_S
|
792
|
+
return rb_sym_to_s(obj);
|
793
|
+
#else
|
794
|
+
return rb_str_new2(rb_id2name(SYM2ID(obj)));
|
795
|
+
#endif
|
796
|
+
}
|
797
|
+
|
798
|
+
case T_HASH:
|
799
|
+
if (RTEST(enc_flag)) {
|
800
|
+
return hash2list_enc(obj, self);
|
801
|
+
} else {
|
802
|
+
return hash2list(obj, self);
|
803
|
+
}
|
804
|
+
|
805
|
+
case T_ARRAY:
|
806
|
+
return ary2list(obj, enc_flag, self);
|
807
|
+
|
808
|
+
case T_FALSE:
|
809
|
+
return rb_str_new2("0");
|
810
|
+
|
811
|
+
case T_TRUE:
|
812
|
+
return rb_str_new2("1");
|
813
|
+
|
814
|
+
case T_NIL:
|
815
|
+
return rb_str_new2("");
|
816
|
+
|
817
|
+
case T_REGEXP:
|
818
|
+
return rb_funcall(obj, ID_source, 0, 0);
|
819
|
+
|
820
|
+
default:
|
821
|
+
if (rb_obj_is_kind_of(obj, cTkObject)) {
|
822
|
+
/* return rb_str_new3(rb_funcall(obj, ID_path, 0, 0)); */
|
823
|
+
return get_eval_string_core(rb_funcall(obj, ID_path, 0, 0),
|
824
|
+
enc_flag, self);
|
825
|
+
}
|
826
|
+
|
827
|
+
if (rb_obj_is_kind_of(obj, rb_cProc)
|
828
|
+
|| rb_obj_is_kind_of(obj, cMethod)
|
829
|
+
|| rb_obj_is_kind_of(obj, cTkCallbackEntry)) {
|
830
|
+
if (rb_obj_respond_to(self, ID_install_cmd, Qtrue)) {
|
831
|
+
return rb_funcall(self, ID_install_cmd, 1, obj);
|
832
|
+
} else {
|
833
|
+
return tk_install_cmd_core(obj);
|
834
|
+
}
|
835
|
+
}
|
836
|
+
|
837
|
+
if (obj == TK_None) return Qnil;
|
838
|
+
|
839
|
+
if (rb_obj_respond_to(obj, ID_to_eval, Qtrue)) {
|
840
|
+
/* return rb_funcall(obj, ID_to_eval, 0, 0); */
|
841
|
+
return get_eval_string_core(rb_funcall(obj, ID_to_eval, 0, 0),
|
842
|
+
enc_flag, self);
|
843
|
+
} else if (rb_obj_respond_to(obj, ID_path, Qtrue)) {
|
844
|
+
/* return rb_funcall(obj, ID_path, 0, 0); */
|
845
|
+
return get_eval_string_core(rb_funcall(obj, ID_path, 0, 0),
|
846
|
+
enc_flag, self);
|
847
|
+
} else if (rb_obj_respond_to(obj, ID_to_s, Qtrue)) {
|
848
|
+
return rb_funcall(obj, ID_to_s, 0, 0);
|
849
|
+
}
|
850
|
+
}
|
851
|
+
|
852
|
+
rb_warning("fail to convert '%s' to string for Tk",
|
853
|
+
RSTRING_PTR(rb_funcall(obj, rb_intern("inspect"), 0, 0)));
|
854
|
+
|
855
|
+
return obj;
|
856
|
+
}
|
857
|
+
|
858
|
+
static VALUE
|
859
|
+
tk_get_eval_string(argc, argv, self)
|
860
|
+
int argc;
|
861
|
+
VALUE *argv;
|
862
|
+
VALUE self;
|
863
|
+
{
|
864
|
+
volatile VALUE obj, enc_flag;
|
865
|
+
|
866
|
+
if (rb_scan_args(argc, argv, "11", &obj, &enc_flag) == 1) {
|
867
|
+
enc_flag = Qnil;
|
868
|
+
}
|
869
|
+
|
870
|
+
return get_eval_string_core(obj, enc_flag, self);
|
871
|
+
}
|
872
|
+
|
873
|
+
static VALUE
|
874
|
+
tk_get_eval_enc_str(self, obj)
|
875
|
+
VALUE self;
|
876
|
+
VALUE obj;
|
877
|
+
{
|
878
|
+
if (obj == TK_None) {
|
879
|
+
return obj;
|
880
|
+
} else {
|
881
|
+
return get_eval_string_core(obj, Qtrue, self);
|
882
|
+
}
|
883
|
+
}
|
884
|
+
|
885
|
+
static VALUE
|
886
|
+
tk_conv_args(argc, argv, self)
|
887
|
+
int argc;
|
888
|
+
VALUE *argv; /* [0]:base_array, [1]:enc_mode, [2]..[n]:args */
|
889
|
+
VALUE self;
|
890
|
+
{
|
891
|
+
int idx, size;
|
892
|
+
volatile VALUE dst;
|
893
|
+
VALUE old_gc;
|
894
|
+
|
895
|
+
if (argc < 2) {
|
896
|
+
rb_raise(rb_eArgError, "too few arguments");
|
897
|
+
}
|
898
|
+
|
899
|
+
old_gc = rb_gc_disable();
|
900
|
+
|
901
|
+
for(size = 0, idx = 2; idx < argc; idx++) {
|
902
|
+
if (TYPE(argv[idx]) == T_HASH) {
|
903
|
+
size += 2 * RHASH_SIZE(argv[idx]);
|
904
|
+
} else {
|
905
|
+
size++;
|
906
|
+
}
|
907
|
+
}
|
908
|
+
/* dst = rb_ary_new2(argc - 2); */
|
909
|
+
dst = rb_ary_new2(size);
|
910
|
+
for(idx = 2; idx < argc; idx++) {
|
911
|
+
if (TYPE(argv[idx]) == T_HASH) {
|
912
|
+
if (RTEST(argv[1])) {
|
913
|
+
hash2kv_enc(argv[idx], dst, self);
|
914
|
+
} else {
|
915
|
+
hash2kv(argv[idx], dst, self);
|
916
|
+
}
|
917
|
+
} else if (argv[idx] != TK_None) {
|
918
|
+
rb_ary_push(dst, get_eval_string_core(argv[idx], argv[1], self));
|
919
|
+
}
|
920
|
+
}
|
921
|
+
|
922
|
+
if (old_gc == Qfalse) rb_gc_enable();
|
923
|
+
|
924
|
+
return rb_ary_plus(argv[0], dst);
|
925
|
+
}
|
926
|
+
|
927
|
+
|
928
|
+
/*************************************/
|
929
|
+
|
930
|
+
static VALUE
|
931
|
+
tcl2rb_bool(self, value)
|
932
|
+
VALUE self;
|
933
|
+
VALUE value;
|
934
|
+
{
|
935
|
+
if (TYPE(value) == T_FIXNUM) {
|
936
|
+
if (NUM2INT(value) == 0) {
|
937
|
+
return Qfalse;
|
938
|
+
} else {
|
939
|
+
return Qtrue;
|
940
|
+
}
|
941
|
+
}
|
942
|
+
|
943
|
+
if (TYPE(value) == T_TRUE || TYPE(value) == T_FALSE) {
|
944
|
+
return value;
|
945
|
+
}
|
946
|
+
|
947
|
+
rb_check_type(value, T_STRING);
|
948
|
+
|
949
|
+
value = rb_funcall(value, ID_downcase, 0);
|
950
|
+
|
951
|
+
if (RSTRING_PTR(value) == (char*)NULL) return Qnil;
|
952
|
+
|
953
|
+
if (RSTRING_PTR(value)[0] == '\0'
|
954
|
+
|| strcmp(RSTRING_PTR(value), "0") == 0
|
955
|
+
|| strcmp(RSTRING_PTR(value), "no") == 0
|
956
|
+
|| strcmp(RSTRING_PTR(value), "off") == 0
|
957
|
+
|| strcmp(RSTRING_PTR(value), "false") == 0) {
|
958
|
+
return Qfalse;
|
959
|
+
} else {
|
960
|
+
return Qtrue;
|
961
|
+
}
|
962
|
+
}
|
963
|
+
|
964
|
+
#if 0
|
965
|
+
static VALUE
|
966
|
+
tkstr_to_dec(value)
|
967
|
+
VALUE value;
|
968
|
+
{
|
969
|
+
return rb_cstr_to_inum(RSTRING_PTR(value), 10, 1);
|
970
|
+
}
|
971
|
+
#endif
|
972
|
+
|
973
|
+
static VALUE
|
974
|
+
tkstr_to_int(value)
|
975
|
+
VALUE value;
|
976
|
+
{
|
977
|
+
return rb_cstr_to_inum(RSTRING_PTR(value), 0, 1);
|
978
|
+
}
|
979
|
+
|
980
|
+
static VALUE
|
981
|
+
tkstr_to_float(value)
|
982
|
+
VALUE value;
|
983
|
+
{
|
984
|
+
return rb_float_new(rb_cstr_to_dbl(RSTRING_PTR(value), 1));
|
985
|
+
}
|
986
|
+
|
987
|
+
static VALUE
|
988
|
+
tkstr_invalid_numstr(value)
|
989
|
+
VALUE value;
|
990
|
+
{
|
991
|
+
rb_raise(rb_eArgError,
|
992
|
+
"invalid value for Number: '%s'", RSTRING_PTR(value));
|
993
|
+
return Qnil; /*dummy*/
|
994
|
+
}
|
995
|
+
|
996
|
+
static VALUE
|
997
|
+
tkstr_rescue_float(value)
|
998
|
+
VALUE value;
|
999
|
+
{
|
1000
|
+
return rb_rescue2(tkstr_to_float, value,
|
1001
|
+
tkstr_invalid_numstr, value,
|
1002
|
+
rb_eArgError, 0);
|
1003
|
+
}
|
1004
|
+
|
1005
|
+
static VALUE
|
1006
|
+
tkstr_to_number(value)
|
1007
|
+
VALUE value;
|
1008
|
+
{
|
1009
|
+
rb_check_type(value, T_STRING);
|
1010
|
+
|
1011
|
+
if (RSTRING_PTR(value) == (char*)NULL) return INT2FIX(0);
|
1012
|
+
|
1013
|
+
return rb_rescue2(tkstr_to_int, value,
|
1014
|
+
tkstr_rescue_float, value,
|
1015
|
+
rb_eArgError, 0);
|
1016
|
+
}
|
1017
|
+
|
1018
|
+
static VALUE
|
1019
|
+
tcl2rb_number(self, value)
|
1020
|
+
VALUE self;
|
1021
|
+
VALUE value;
|
1022
|
+
{
|
1023
|
+
return tkstr_to_number(value);
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
static VALUE
|
1027
|
+
tkstr_to_str(value)
|
1028
|
+
VALUE value;
|
1029
|
+
{
|
1030
|
+
char * ptr;
|
1031
|
+
int len;
|
1032
|
+
|
1033
|
+
ptr = RSTRING_PTR(value);
|
1034
|
+
len = RSTRING_LEN(value);
|
1035
|
+
|
1036
|
+
if (len > 1 && *ptr == '{' && *(ptr + len - 1) == '}') {
|
1037
|
+
return rb_str_new(ptr + 1, len - 2);
|
1038
|
+
}
|
1039
|
+
return value;
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
static VALUE
|
1043
|
+
tcl2rb_string(self, value)
|
1044
|
+
VALUE self;
|
1045
|
+
VALUE value;
|
1046
|
+
{
|
1047
|
+
rb_check_type(value, T_STRING);
|
1048
|
+
|
1049
|
+
if (RSTRING_PTR(value) == (char*)NULL) return rb_tainted_str_new2("");
|
1050
|
+
|
1051
|
+
return tkstr_to_str(value);
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
static VALUE
|
1055
|
+
tcl2rb_num_or_str(self, value)
|
1056
|
+
VALUE self;
|
1057
|
+
VALUE value;
|
1058
|
+
{
|
1059
|
+
rb_check_type(value, T_STRING);
|
1060
|
+
|
1061
|
+
if (RSTRING_PTR(value) == (char*)NULL) return rb_tainted_str_new2("");
|
1062
|
+
|
1063
|
+
return rb_rescue2(tkstr_to_number, value,
|
1064
|
+
tkstr_to_str, value,
|
1065
|
+
rb_eArgError, 0);
|
1066
|
+
}
|
1067
|
+
|
1068
|
+
|
1069
|
+
/*************************************/
|
1070
|
+
|
1071
|
+
#define CBSUBST_TBL_MAX (256)
|
1072
|
+
struct cbsubst_info {
|
1073
|
+
int full_subst_length;
|
1074
|
+
int keylen[CBSUBST_TBL_MAX];
|
1075
|
+
char *key[CBSUBST_TBL_MAX];
|
1076
|
+
char type[CBSUBST_TBL_MAX];
|
1077
|
+
ID ivar[CBSUBST_TBL_MAX];
|
1078
|
+
VALUE proc;
|
1079
|
+
VALUE aliases;
|
1080
|
+
};
|
1081
|
+
|
1082
|
+
static void
|
1083
|
+
subst_mark(ptr)
|
1084
|
+
struct cbsubst_info *ptr;
|
1085
|
+
{
|
1086
|
+
rb_gc_mark(ptr->proc);
|
1087
|
+
rb_gc_mark(ptr->aliases);
|
1088
|
+
}
|
1089
|
+
|
1090
|
+
static void
|
1091
|
+
subst_free(ptr)
|
1092
|
+
struct cbsubst_info *ptr;
|
1093
|
+
{
|
1094
|
+
int i;
|
1095
|
+
|
1096
|
+
if (ptr) {
|
1097
|
+
for(i = 0; i < CBSUBST_TBL_MAX; i++) {
|
1098
|
+
if (ptr->key[i] != NULL) {
|
1099
|
+
free(ptr->key[i]);
|
1100
|
+
ptr->key[i] = NULL;
|
1101
|
+
}
|
1102
|
+
}
|
1103
|
+
free(ptr);
|
1104
|
+
}
|
1105
|
+
}
|
1106
|
+
|
1107
|
+
static struct cbsubst_info *
|
1108
|
+
allocate_cbsubst_info()
|
1109
|
+
{
|
1110
|
+
struct cbsubst_info *inf;
|
1111
|
+
volatile VALUE proc, aliases;
|
1112
|
+
int idx;
|
1113
|
+
|
1114
|
+
inf = ALLOC(struct cbsubst_info);
|
1115
|
+
|
1116
|
+
inf->full_subst_length = 0;
|
1117
|
+
|
1118
|
+
for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
|
1119
|
+
inf->keylen[idx] = 0;
|
1120
|
+
inf->key[idx] = NULL;
|
1121
|
+
inf->type[idx] = '\0';
|
1122
|
+
inf->ivar[idx] = (ID) 0;
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
proc = rb_hash_new();
|
1126
|
+
inf->proc = proc;
|
1127
|
+
|
1128
|
+
aliases = rb_hash_new();
|
1129
|
+
inf->aliases = aliases;
|
1130
|
+
|
1131
|
+
return inf;
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
static void
|
1135
|
+
cbsubst_init()
|
1136
|
+
{
|
1137
|
+
rb_const_set(cCB_SUBST, ID_SUBST_INFO,
|
1138
|
+
Data_Wrap_Struct(cSUBST_INFO, subst_mark, subst_free,
|
1139
|
+
allocate_cbsubst_info()));
|
1140
|
+
}
|
1141
|
+
|
1142
|
+
static VALUE
|
1143
|
+
cbsubst_initialize(argc, argv, self)
|
1144
|
+
int argc;
|
1145
|
+
VALUE *argv;
|
1146
|
+
VALUE self;
|
1147
|
+
{
|
1148
|
+
struct cbsubst_info *inf;
|
1149
|
+
int idx, iv_idx;
|
1150
|
+
|
1151
|
+
Data_Get_Struct(rb_const_get(rb_obj_class(self), ID_SUBST_INFO),
|
1152
|
+
struct cbsubst_info, inf);
|
1153
|
+
|
1154
|
+
idx = 0;
|
1155
|
+
for(iv_idx = 0; iv_idx < CBSUBST_TBL_MAX; iv_idx++) {
|
1156
|
+
if ( inf->ivar[iv_idx] == (ID) 0 ) continue;
|
1157
|
+
rb_ivar_set(self, inf->ivar[iv_idx], argv[idx++]);
|
1158
|
+
if (idx >= argc) break;
|
1159
|
+
}
|
1160
|
+
|
1161
|
+
return self;
|
1162
|
+
}
|
1163
|
+
|
1164
|
+
static VALUE
|
1165
|
+
cbsubst_ret_val(self, val)
|
1166
|
+
VALUE self;
|
1167
|
+
VALUE val;
|
1168
|
+
{
|
1169
|
+
/* This method may be overwritten on some sub-classes. */
|
1170
|
+
/* This method is used for converting from ruby's callback-return-value */
|
1171
|
+
/* to tcl's value (e.g. validation procedure of entry widget). */
|
1172
|
+
return val;
|
1173
|
+
}
|
1174
|
+
|
1175
|
+
static int
|
1176
|
+
each_attr_def(key, value, klass)
|
1177
|
+
VALUE key, value, klass;
|
1178
|
+
{
|
1179
|
+
ID key_id, value_id;
|
1180
|
+
|
1181
|
+
if (key == Qundef) return ST_CONTINUE;
|
1182
|
+
|
1183
|
+
switch(TYPE(key)) {
|
1184
|
+
case T_STRING:
|
1185
|
+
key_id = rb_intern(RSTRING_PTR(key));
|
1186
|
+
break;
|
1187
|
+
case T_SYMBOL:
|
1188
|
+
key_id = SYM2ID(key);
|
1189
|
+
break;
|
1190
|
+
default:
|
1191
|
+
rb_raise(rb_eArgError,
|
1192
|
+
"includes invalid key(s). expected a String or a Symbol");
|
1193
|
+
}
|
1194
|
+
|
1195
|
+
switch(TYPE(value)) {
|
1196
|
+
case T_STRING:
|
1197
|
+
value_id = rb_intern(RSTRING_PTR(value));
|
1198
|
+
break;
|
1199
|
+
case T_SYMBOL:
|
1200
|
+
value_id = SYM2ID(value);
|
1201
|
+
break;
|
1202
|
+
default:
|
1203
|
+
rb_raise(rb_eArgError,
|
1204
|
+
"includes invalid value(s). expected a String or a Symbol");
|
1205
|
+
}
|
1206
|
+
|
1207
|
+
rb_alias(klass, key_id, value_id);
|
1208
|
+
|
1209
|
+
return ST_CONTINUE;
|
1210
|
+
}
|
1211
|
+
|
1212
|
+
static VALUE
|
1213
|
+
cbsubst_def_attr_aliases(self, tbl)
|
1214
|
+
VALUE self;
|
1215
|
+
VALUE tbl;
|
1216
|
+
{
|
1217
|
+
struct cbsubst_info *inf;
|
1218
|
+
|
1219
|
+
if (TYPE(tbl) != T_HASH) {
|
1220
|
+
rb_raise(rb_eArgError, "expected a Hash");
|
1221
|
+
}
|
1222
|
+
|
1223
|
+
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
|
1224
|
+
struct cbsubst_info, inf);
|
1225
|
+
|
1226
|
+
rb_hash_foreach(tbl, each_attr_def, self);
|
1227
|
+
|
1228
|
+
return rb_funcall(inf->aliases, rb_intern("update"), 1, tbl);
|
1229
|
+
}
|
1230
|
+
|
1231
|
+
static VALUE
|
1232
|
+
cbsubst_sym_to_subst(self, sym)
|
1233
|
+
VALUE self;
|
1234
|
+
VALUE sym;
|
1235
|
+
{
|
1236
|
+
struct cbsubst_info *inf;
|
1237
|
+
const char *str;
|
1238
|
+
char *buf, *ptr;
|
1239
|
+
int idx, len;
|
1240
|
+
ID id;
|
1241
|
+
volatile VALUE ret;
|
1242
|
+
|
1243
|
+
if (TYPE(sym) != T_SYMBOL) return sym;
|
1244
|
+
|
1245
|
+
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
|
1246
|
+
struct cbsubst_info, inf);
|
1247
|
+
|
1248
|
+
if (!NIL_P(ret = rb_hash_aref(inf->aliases, sym))) {
|
1249
|
+
str = rb_id2name(SYM2ID(ret));
|
1250
|
+
} else {
|
1251
|
+
str = rb_id2name(SYM2ID(sym));
|
1252
|
+
}
|
1253
|
+
|
1254
|
+
id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str)));
|
1255
|
+
|
1256
|
+
for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
|
1257
|
+
if (inf->ivar[idx] == id) break;
|
1258
|
+
}
|
1259
|
+
if (idx >= CBSUBST_TBL_MAX) return sym;
|
1260
|
+
|
1261
|
+
ptr = buf = ALLOC_N(char, inf->full_subst_length + 1);
|
1262
|
+
|
1263
|
+
*(ptr++) = '%';
|
1264
|
+
|
1265
|
+
if (len = inf->keylen[idx]) {
|
1266
|
+
/* longname */
|
1267
|
+
strncpy(ptr, inf->key[idx], len);
|
1268
|
+
ptr += len;
|
1269
|
+
} else {
|
1270
|
+
/* single char */
|
1271
|
+
*(ptr++) = (unsigned char)idx;
|
1272
|
+
}
|
1273
|
+
|
1274
|
+
*(ptr++) = ' ';
|
1275
|
+
*(ptr++) = '\0';
|
1276
|
+
|
1277
|
+
ret = rb_str_new2(buf);
|
1278
|
+
|
1279
|
+
free(buf);
|
1280
|
+
|
1281
|
+
return ret;
|
1282
|
+
}
|
1283
|
+
|
1284
|
+
static VALUE
|
1285
|
+
cbsubst_get_subst_arg(argc, argv, self)
|
1286
|
+
int argc;
|
1287
|
+
VALUE *argv;
|
1288
|
+
VALUE self;
|
1289
|
+
{
|
1290
|
+
struct cbsubst_info *inf;
|
1291
|
+
const char *str;
|
1292
|
+
char *buf, *ptr;
|
1293
|
+
int i, idx, len;
|
1294
|
+
ID id;
|
1295
|
+
volatile VALUE arg_sym, ret;
|
1296
|
+
|
1297
|
+
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
|
1298
|
+
struct cbsubst_info, inf);
|
1299
|
+
|
1300
|
+
ptr = buf = ALLOC_N(char, inf->full_subst_length + 1);
|
1301
|
+
|
1302
|
+
for(i = 0; i < argc; i++) {
|
1303
|
+
switch(TYPE(argv[i])) {
|
1304
|
+
case T_STRING:
|
1305
|
+
str = RSTRING_PTR(argv[i]);
|
1306
|
+
arg_sym = ID2SYM(rb_intern(str));
|
1307
|
+
break;
|
1308
|
+
case T_SYMBOL:
|
1309
|
+
arg_sym = argv[i];
|
1310
|
+
str = rb_id2name(SYM2ID(arg_sym));
|
1311
|
+
break;
|
1312
|
+
default:
|
1313
|
+
rb_raise(rb_eArgError, "arg #%d is not a String or a Symbol", i);
|
1314
|
+
}
|
1315
|
+
|
1316
|
+
if (!NIL_P(ret = rb_hash_aref(inf->aliases, arg_sym))) {
|
1317
|
+
str = rb_id2name(SYM2ID(ret));
|
1318
|
+
}
|
1319
|
+
|
1320
|
+
id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str)));
|
1321
|
+
|
1322
|
+
for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
|
1323
|
+
if (inf->ivar[idx] == id) break;
|
1324
|
+
}
|
1325
|
+
if (idx >= CBSUBST_TBL_MAX) {
|
1326
|
+
rb_raise(rb_eArgError, "cannot find attribute :%s", str);
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
*(ptr++) = '%';
|
1330
|
+
|
1331
|
+
if (len = inf->keylen[idx]) {
|
1332
|
+
/* longname */
|
1333
|
+
strncpy(ptr, inf->key[idx], len);
|
1334
|
+
ptr += len;
|
1335
|
+
} else {
|
1336
|
+
/* single char */
|
1337
|
+
*(ptr++) = (unsigned char)idx;
|
1338
|
+
}
|
1339
|
+
|
1340
|
+
*(ptr++) = ' ';
|
1341
|
+
}
|
1342
|
+
|
1343
|
+
*ptr = '\0';
|
1344
|
+
|
1345
|
+
ret = rb_str_new2(buf);
|
1346
|
+
|
1347
|
+
free(buf);
|
1348
|
+
|
1349
|
+
return ret;
|
1350
|
+
}
|
1351
|
+
|
1352
|
+
static VALUE
|
1353
|
+
cbsubst_get_subst_key(self, str)
|
1354
|
+
VALUE self;
|
1355
|
+
VALUE str;
|
1356
|
+
{
|
1357
|
+
struct cbsubst_info *inf;
|
1358
|
+
volatile VALUE list;
|
1359
|
+
volatile VALUE ret;
|
1360
|
+
VALUE keyval;
|
1361
|
+
int i, len, keylen, idx;
|
1362
|
+
char *buf, *ptr, *key;
|
1363
|
+
|
1364
|
+
list = rb_funcall(cTclTkLib, ID_split_tklist, 1, str);
|
1365
|
+
len = RARRAY_LEN(list);
|
1366
|
+
|
1367
|
+
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
|
1368
|
+
struct cbsubst_info, inf);
|
1369
|
+
|
1370
|
+
ptr = buf = ALLOC_N(char, inf->full_subst_length + len + 1);
|
1371
|
+
|
1372
|
+
for(i = 0; i < len; i++) {
|
1373
|
+
keyval = RARRAY_PTR(list)[i];
|
1374
|
+
key = RSTRING_PTR(keyval);
|
1375
|
+
if (*key == '%') {
|
1376
|
+
if (*(key + 2) == '\0') {
|
1377
|
+
/* single char */
|
1378
|
+
*(ptr++) = *(key + 1);
|
1379
|
+
} else {
|
1380
|
+
/* search longname-key */
|
1381
|
+
keylen = RSTRING_LEN(keyval) - 1;
|
1382
|
+
for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
|
1383
|
+
if (inf->keylen[idx] != keylen) continue;
|
1384
|
+
if ((unsigned char)inf->key[idx][0] != (unsigned char)*(key + 1)) continue;
|
1385
|
+
if (strncmp(inf->key[idx], key + 1, keylen)) continue;
|
1386
|
+
break;
|
1387
|
+
}
|
1388
|
+
if (idx < CBSUBST_TBL_MAX) {
|
1389
|
+
*(ptr++) = (unsigned char)idx;
|
1390
|
+
} else {
|
1391
|
+
*(ptr++) = ' ';
|
1392
|
+
}
|
1393
|
+
}
|
1394
|
+
} else {
|
1395
|
+
*(ptr++) = ' ';
|
1396
|
+
}
|
1397
|
+
}
|
1398
|
+
*ptr = '\0';
|
1399
|
+
|
1400
|
+
ret = rb_str_new2(buf);
|
1401
|
+
free(buf);
|
1402
|
+
return ret;
|
1403
|
+
}
|
1404
|
+
|
1405
|
+
static VALUE
|
1406
|
+
cbsubst_get_all_subst_keys(self)
|
1407
|
+
VALUE self;
|
1408
|
+
{
|
1409
|
+
struct cbsubst_info *inf;
|
1410
|
+
char *buf, *ptr;
|
1411
|
+
char *keys_buf, *keys_ptr;
|
1412
|
+
int idx, len;
|
1413
|
+
volatile VALUE ret;
|
1414
|
+
|
1415
|
+
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
|
1416
|
+
struct cbsubst_info, inf);
|
1417
|
+
|
1418
|
+
ptr = buf = ALLOC_N(char, inf->full_subst_length + 1);
|
1419
|
+
keys_ptr = keys_buf = ALLOC_N(char, CBSUBST_TBL_MAX + 1);
|
1420
|
+
|
1421
|
+
for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
|
1422
|
+
if (inf->ivar[idx] == (ID) 0) continue;
|
1423
|
+
|
1424
|
+
*(keys_ptr++) = (unsigned char)idx;
|
1425
|
+
|
1426
|
+
*(ptr++) = '%';
|
1427
|
+
|
1428
|
+
if (len = inf->keylen[idx]) {
|
1429
|
+
/* longname */
|
1430
|
+
strncpy(ptr, inf->key[idx], len);
|
1431
|
+
ptr += len;
|
1432
|
+
} else {
|
1433
|
+
/* single char */
|
1434
|
+
*(ptr++) = (unsigned char)idx;
|
1435
|
+
}
|
1436
|
+
|
1437
|
+
*(ptr++) = ' ';
|
1438
|
+
}
|
1439
|
+
|
1440
|
+
*ptr = '\0';
|
1441
|
+
*keys_ptr = '\0';
|
1442
|
+
|
1443
|
+
ret = rb_ary_new3(2, rb_str_new2(keys_buf), rb_str_new2(buf));
|
1444
|
+
|
1445
|
+
free(buf);
|
1446
|
+
free(keys_buf);
|
1447
|
+
|
1448
|
+
return ret;
|
1449
|
+
}
|
1450
|
+
|
1451
|
+
static VALUE
|
1452
|
+
cbsubst_table_setup(argc, argv, self)
|
1453
|
+
int argc;
|
1454
|
+
VALUE *argv;
|
1455
|
+
VALUE self;
|
1456
|
+
{
|
1457
|
+
volatile VALUE key_inf;
|
1458
|
+
volatile VALUE longkey_inf;
|
1459
|
+
volatile VALUE proc_inf;
|
1460
|
+
VALUE inf;
|
1461
|
+
ID id;
|
1462
|
+
struct cbsubst_info *subst_inf;
|
1463
|
+
int idx, len;
|
1464
|
+
unsigned char chr;
|
1465
|
+
|
1466
|
+
/* accept (key_inf, proc_inf) or (key_inf, longkey_inf, procinf) */
|
1467
|
+
if (rb_scan_args(argc, argv, "21", &key_inf, &longkey_inf, &proc_inf) == 2) {
|
1468
|
+
proc_inf = longkey_inf;
|
1469
|
+
longkey_inf = rb_ary_new();
|
1470
|
+
}
|
1471
|
+
|
1472
|
+
/* check the number of longkeys */
|
1473
|
+
if (RARRAY_LEN(longkey_inf) > 125 /* from 0x80 to 0xFD */) {
|
1474
|
+
rb_raise(rb_eArgError, "too many longname-key definitions");
|
1475
|
+
}
|
1476
|
+
|
1477
|
+
/* init */
|
1478
|
+
subst_inf = allocate_cbsubst_info();
|
1479
|
+
|
1480
|
+
/*
|
1481
|
+
* keys : array of [subst, type, ivar]
|
1482
|
+
* subst ==> char code or string
|
1483
|
+
* type ==> char code or string
|
1484
|
+
* ivar ==> symbol
|
1485
|
+
*/
|
1486
|
+
len = RARRAY_LEN(key_inf);
|
1487
|
+
for(idx = 0; idx < len; idx++) {
|
1488
|
+
inf = RARRAY_PTR(key_inf)[idx];
|
1489
|
+
if (TYPE(inf) != T_ARRAY) continue;
|
1490
|
+
|
1491
|
+
if (TYPE(RARRAY_PTR(inf)[0]) == T_STRING) {
|
1492
|
+
chr = *(RSTRING_PTR(RARRAY_PTR(inf)[0]));
|
1493
|
+
} else {
|
1494
|
+
chr = NUM2CHR(RARRAY_PTR(inf)[0]);
|
1495
|
+
}
|
1496
|
+
if (TYPE(RARRAY_PTR(inf)[1]) == T_STRING) {
|
1497
|
+
subst_inf->type[chr] = *(RSTRING_PTR(RARRAY_PTR(inf)[1]));
|
1498
|
+
} else {
|
1499
|
+
subst_inf->type[chr] = NUM2CHR(RARRAY_PTR(inf)[1]);
|
1500
|
+
}
|
1501
|
+
|
1502
|
+
subst_inf->full_subst_length += 3;
|
1503
|
+
|
1504
|
+
id = SYM2ID(RARRAY_PTR(inf)[2]);
|
1505
|
+
subst_inf->ivar[chr] = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), rb_id2name(id))));
|
1506
|
+
|
1507
|
+
rb_attr(self, id, 1, 0, Qtrue);
|
1508
|
+
}
|
1509
|
+
|
1510
|
+
|
1511
|
+
/*
|
1512
|
+
* longkeys : array of [name, type, ivar]
|
1513
|
+
* name ==> longname key string
|
1514
|
+
* type ==> char code or string
|
1515
|
+
* ivar ==> symbol
|
1516
|
+
*/
|
1517
|
+
len = RARRAY_LEN(longkey_inf);
|
1518
|
+
for(idx = 0; idx < len; idx++) {
|
1519
|
+
inf = RARRAY_PTR(longkey_inf)[idx];
|
1520
|
+
if (TYPE(inf) != T_ARRAY) continue;
|
1521
|
+
|
1522
|
+
chr = (unsigned char)(0x80 + idx);
|
1523
|
+
subst_inf->keylen[chr] = RSTRING_LEN(RARRAY_PTR(inf)[0]);
|
1524
|
+
#if HAVE_STRNDUP
|
1525
|
+
subst_inf->key[chr] = strndup(RSTRING_PTR(RARRAY_PTR(inf)[0]),
|
1526
|
+
RSTRING_LEN(RARRAY_PTR(inf)[0]));
|
1527
|
+
#else
|
1528
|
+
subst_inf->key[chr] = malloc(RSTRING_LEN(RARRAY_PTR(inf)[0]) + 1);
|
1529
|
+
if (subst_inf->key[chr]) {
|
1530
|
+
strncpy(subst_inf->key[chr], RSTRING_PTR(RARRAY_PTR(inf)[0]),
|
1531
|
+
RSTRING_LEN(RARRAY_PTR(inf)[0]) + 1);
|
1532
|
+
subst_inf->key[chr][RSTRING_LEN(RARRAY_PTR(inf)[0])] = '\0';
|
1533
|
+
}
|
1534
|
+
#endif
|
1535
|
+
if (TYPE(RARRAY_PTR(inf)[1]) == T_STRING) {
|
1536
|
+
subst_inf->type[chr] = *(RSTRING_PTR(RARRAY_PTR(inf)[1]));
|
1537
|
+
} else {
|
1538
|
+
subst_inf->type[chr] = NUM2CHR(RARRAY_PTR(inf)[1]);
|
1539
|
+
}
|
1540
|
+
|
1541
|
+
subst_inf->full_subst_length += (subst_inf->keylen[chr] + 2);
|
1542
|
+
|
1543
|
+
id = SYM2ID(RARRAY_PTR(inf)[2]);
|
1544
|
+
subst_inf->ivar[chr] = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), rb_id2name(id))));
|
1545
|
+
|
1546
|
+
rb_attr(self, id, 1, 0, Qtrue);
|
1547
|
+
}
|
1548
|
+
|
1549
|
+
/*
|
1550
|
+
* procs : array of [type, proc]
|
1551
|
+
* type ==> char code or string
|
1552
|
+
* proc ==> proc/method/obj (must respond to 'call')
|
1553
|
+
*/
|
1554
|
+
len = RARRAY_LEN(proc_inf);
|
1555
|
+
for(idx = 0; idx < len; idx++) {
|
1556
|
+
inf = RARRAY_PTR(proc_inf)[idx];
|
1557
|
+
if (TYPE(inf) != T_ARRAY) continue;
|
1558
|
+
rb_hash_aset(subst_inf->proc,
|
1559
|
+
((TYPE(RARRAY_PTR(inf)[0]) == T_STRING)?
|
1560
|
+
INT2FIX(*(RSTRING_PTR(RARRAY_PTR(inf)[0]))) :
|
1561
|
+
RARRAY_PTR(inf)[0]),
|
1562
|
+
RARRAY_PTR(inf)[1]);
|
1563
|
+
}
|
1564
|
+
|
1565
|
+
rb_const_set(self, ID_SUBST_INFO,
|
1566
|
+
Data_Wrap_Struct(cSUBST_INFO, subst_mark,
|
1567
|
+
subst_free, subst_inf));
|
1568
|
+
|
1569
|
+
return self;
|
1570
|
+
}
|
1571
|
+
|
1572
|
+
static VALUE
|
1573
|
+
cbsubst_get_extra_args_tbl(self)
|
1574
|
+
VALUE self;
|
1575
|
+
{
|
1576
|
+
return rb_ary_new();
|
1577
|
+
}
|
1578
|
+
|
1579
|
+
static VALUE
|
1580
|
+
cbsubst_scan_args(self, arg_key, val_ary)
|
1581
|
+
VALUE self;
|
1582
|
+
VALUE arg_key;
|
1583
|
+
VALUE val_ary;
|
1584
|
+
{
|
1585
|
+
struct cbsubst_info *inf;
|
1586
|
+
int idx;
|
1587
|
+
unsigned char *keyptr = (unsigned char*)RSTRING_PTR(arg_key);
|
1588
|
+
int keylen = RSTRING_LEN(arg_key);
|
1589
|
+
int vallen = RARRAY_LEN(val_ary);
|
1590
|
+
unsigned char type_chr;
|
1591
|
+
volatile VALUE dst = rb_ary_new2(vallen);
|
1592
|
+
volatile VALUE proc;
|
1593
|
+
VALUE old_gc;
|
1594
|
+
|
1595
|
+
old_gc = rb_gc_disable();
|
1596
|
+
|
1597
|
+
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
|
1598
|
+
struct cbsubst_info, inf);
|
1599
|
+
|
1600
|
+
for(idx = 0; idx < vallen; idx++) {
|
1601
|
+
if (idx >= keylen) {
|
1602
|
+
proc = Qnil;
|
1603
|
+
} else if (*(keyptr + idx) == ' ') {
|
1604
|
+
proc = Qnil;
|
1605
|
+
} else {
|
1606
|
+
if (type_chr = inf->type[*(keyptr + idx)]) {
|
1607
|
+
proc = rb_hash_aref(inf->proc, INT2FIX((int)type_chr));
|
1608
|
+
} else {
|
1609
|
+
proc = Qnil;
|
1610
|
+
}
|
1611
|
+
}
|
1612
|
+
|
1613
|
+
if (NIL_P(proc)) {
|
1614
|
+
rb_ary_push(dst, RARRAY_PTR(val_ary)[idx]);
|
1615
|
+
} else {
|
1616
|
+
rb_ary_push(dst, rb_funcall(proc, ID_call, 1,
|
1617
|
+
RARRAY_PTR(val_ary)[idx]));
|
1618
|
+
}
|
1619
|
+
}
|
1620
|
+
|
1621
|
+
if (old_gc == Qfalse) rb_gc_enable();
|
1622
|
+
|
1623
|
+
return dst;
|
1624
|
+
}
|
1625
|
+
|
1626
|
+
static VALUE
|
1627
|
+
cbsubst_inspect(self)
|
1628
|
+
VALUE self;
|
1629
|
+
{
|
1630
|
+
return rb_str_new2("CallbackSubst");
|
1631
|
+
}
|
1632
|
+
|
1633
|
+
static VALUE
|
1634
|
+
substinfo_inspect(self)
|
1635
|
+
VALUE self;
|
1636
|
+
{
|
1637
|
+
return rb_str_new2("SubstInfo");
|
1638
|
+
}
|
1639
|
+
|
1640
|
+
/*************************************/
|
1641
|
+
|
1642
|
+
static VALUE
|
1643
|
+
tk_cbe_inspect(self)
|
1644
|
+
VALUE self;
|
1645
|
+
{
|
1646
|
+
return rb_str_new2("TkCallbackEntry");
|
1647
|
+
}
|
1648
|
+
|
1649
|
+
/*************************************/
|
1650
|
+
|
1651
|
+
static VALUE
|
1652
|
+
tkobj_path(self)
|
1653
|
+
VALUE self;
|
1654
|
+
{
|
1655
|
+
return rb_ivar_get(self, ID_at_path);
|
1656
|
+
}
|
1657
|
+
|
1658
|
+
|
1659
|
+
/*************************************/
|
1660
|
+
/* release date */
|
1661
|
+
const char tkutil_release_date[] = TKUTIL_RELEASE_DATE;
|
1662
|
+
|
1663
|
+
void
|
1664
|
+
Init_tkutil()
|
1665
|
+
{
|
1666
|
+
VALUE cTK = rb_define_class("TkKernel", rb_cObject);
|
1667
|
+
VALUE mTK = rb_define_module("TkUtil");
|
1668
|
+
|
1669
|
+
/* --------------------- */
|
1670
|
+
|
1671
|
+
rb_define_const(mTK, "RELEASE_DATE",
|
1672
|
+
rb_obj_freeze(rb_str_new2(tkutil_release_date)));
|
1673
|
+
|
1674
|
+
/* --------------------- */
|
1675
|
+
rb_global_variable(&cMethod);
|
1676
|
+
cMethod = rb_const_get(rb_cObject, rb_intern("Method"));
|
1677
|
+
|
1678
|
+
ID_path = rb_intern("path");
|
1679
|
+
ID_at_path = rb_intern("@path");
|
1680
|
+
ID_at_enc = rb_intern("@encoding");
|
1681
|
+
ID_to_eval = rb_intern("to_eval");
|
1682
|
+
ID_to_s = rb_intern("to_s");
|
1683
|
+
ID_source = rb_intern("source");
|
1684
|
+
ID_downcase = rb_intern("downcase");
|
1685
|
+
ID_install_cmd = rb_intern("install_cmd");
|
1686
|
+
ID_merge_tklist = rb_intern("_merge_tklist");
|
1687
|
+
ID_encoding = rb_intern("encoding");
|
1688
|
+
ID_encoding_system = rb_intern("encoding_system");
|
1689
|
+
ID_call = rb_intern("call");
|
1690
|
+
|
1691
|
+
/* --------------------- */
|
1692
|
+
cCB_SUBST = rb_define_class_under(mTK, "CallbackSubst", rb_cObject);
|
1693
|
+
rb_define_singleton_method(cCB_SUBST, "inspect", cbsubst_inspect, 0);
|
1694
|
+
|
1695
|
+
cSUBST_INFO = rb_define_class_under(cCB_SUBST, "Info", rb_cObject);
|
1696
|
+
rb_define_singleton_method(cSUBST_INFO, "inspect", substinfo_inspect, 0);
|
1697
|
+
|
1698
|
+
ID_SUBST_INFO = rb_intern("SUBST_INFO");
|
1699
|
+
rb_define_singleton_method(cCB_SUBST, "ret_val", cbsubst_ret_val, 1);
|
1700
|
+
rb_define_singleton_method(cCB_SUBST, "scan_args", cbsubst_scan_args, 2);
|
1701
|
+
rb_define_singleton_method(cCB_SUBST, "_sym2subst",
|
1702
|
+
cbsubst_sym_to_subst, 1);
|
1703
|
+
rb_define_singleton_method(cCB_SUBST, "subst_arg",
|
1704
|
+
cbsubst_get_subst_arg, -1);
|
1705
|
+
rb_define_singleton_method(cCB_SUBST, "_get_subst_key",
|
1706
|
+
cbsubst_get_subst_key, 1);
|
1707
|
+
rb_define_singleton_method(cCB_SUBST, "_get_all_subst_keys",
|
1708
|
+
cbsubst_get_all_subst_keys, 0);
|
1709
|
+
rb_define_singleton_method(cCB_SUBST, "_setup_subst_table",
|
1710
|
+
cbsubst_table_setup, -1);
|
1711
|
+
rb_define_singleton_method(cCB_SUBST, "_get_extra_args_tbl",
|
1712
|
+
cbsubst_get_extra_args_tbl, 0);
|
1713
|
+
rb_define_singleton_method(cCB_SUBST, "_define_attribute_aliases",
|
1714
|
+
cbsubst_def_attr_aliases, 1);
|
1715
|
+
|
1716
|
+
rb_define_method(cCB_SUBST, "initialize", cbsubst_initialize, -1);
|
1717
|
+
|
1718
|
+
cbsubst_init();
|
1719
|
+
|
1720
|
+
/* --------------------- */
|
1721
|
+
rb_global_variable(&cTkCallbackEntry);
|
1722
|
+
cTkCallbackEntry = rb_define_class("TkCallbackEntry", cTK);
|
1723
|
+
rb_define_singleton_method(cTkCallbackEntry, "inspect", tk_cbe_inspect, 0);
|
1724
|
+
|
1725
|
+
/* --------------------- */
|
1726
|
+
rb_global_variable(&cTkObject);
|
1727
|
+
cTkObject = rb_define_class("TkObject", cTK);
|
1728
|
+
rb_define_method(cTkObject, "path", tkobj_path, 0);
|
1729
|
+
|
1730
|
+
/* --------------------- */
|
1731
|
+
rb_require("tcltklib");
|
1732
|
+
rb_global_variable(&cTclTkLib);
|
1733
|
+
cTclTkLib = rb_const_get(rb_cObject, rb_intern("TclTkLib"));
|
1734
|
+
ID_split_tklist = rb_intern("_split_tklist");
|
1735
|
+
ID_toUTF8 = rb_intern("_toUTF8");
|
1736
|
+
ID_fromUTF8 = rb_intern("_fromUTF8");
|
1737
|
+
|
1738
|
+
/* --------------------- */
|
1739
|
+
rb_define_singleton_method(cTK, "new", tk_s_new, -1);
|
1740
|
+
|
1741
|
+
/* --------------------- */
|
1742
|
+
rb_global_variable(&TK_None);
|
1743
|
+
TK_None = rb_obj_alloc(rb_cObject);
|
1744
|
+
rb_define_const(mTK, "None", TK_None);
|
1745
|
+
rb_define_singleton_method(TK_None, "to_s", tkNone_to_s, 0);
|
1746
|
+
rb_define_singleton_method(TK_None, "inspect", tkNone_to_s, 0);
|
1747
|
+
OBJ_FREEZE(TK_None);
|
1748
|
+
|
1749
|
+
/* --------------------- */
|
1750
|
+
rb_global_variable(&CALLBACK_TABLE);
|
1751
|
+
CALLBACK_TABLE = rb_hash_new();
|
1752
|
+
|
1753
|
+
/* --------------------- */
|
1754
|
+
rb_define_singleton_method(mTK, "eval_cmd", tk_eval_cmd, -1);
|
1755
|
+
rb_define_singleton_method(mTK, "callback", tk_do_callback, -1);
|
1756
|
+
rb_define_singleton_method(mTK, "install_cmd", tk_install_cmd, -1);
|
1757
|
+
rb_define_singleton_method(mTK, "uninstall_cmd", tk_uninstall_cmd, 1);
|
1758
|
+
rb_define_singleton_method(mTK, "_symbolkey2str", tk_symbolkey2str, 1);
|
1759
|
+
rb_define_singleton_method(mTK, "hash_kv", tk_hash_kv, -1);
|
1760
|
+
rb_define_singleton_method(mTK, "_get_eval_string",
|
1761
|
+
tk_get_eval_string, -1);
|
1762
|
+
rb_define_singleton_method(mTK, "_get_eval_enc_str",
|
1763
|
+
tk_get_eval_enc_str, 1);
|
1764
|
+
rb_define_singleton_method(mTK, "_conv_args", tk_conv_args, -1);
|
1765
|
+
|
1766
|
+
rb_define_singleton_method(mTK, "bool", tcl2rb_bool, 1);
|
1767
|
+
rb_define_singleton_method(mTK, "number", tcl2rb_number, 1);
|
1768
|
+
rb_define_singleton_method(mTK, "string", tcl2rb_string, 1);
|
1769
|
+
rb_define_singleton_method(mTK, "num_or_str", tcl2rb_num_or_str, 1);
|
1770
|
+
|
1771
|
+
rb_define_method(mTK, "_toUTF8", tk_toUTF8, -1);
|
1772
|
+
rb_define_method(mTK, "_fromUTF8", tk_fromUTF8, -1);
|
1773
|
+
rb_define_method(mTK, "_symbolkey2str", tk_symbolkey2str, 1);
|
1774
|
+
rb_define_method(mTK, "hash_kv", tk_hash_kv, -1);
|
1775
|
+
rb_define_method(mTK, "_get_eval_string", tk_get_eval_string, -1);
|
1776
|
+
rb_define_method(mTK, "_get_eval_enc_str", tk_get_eval_enc_str, 1);
|
1777
|
+
rb_define_method(mTK, "_conv_args", tk_conv_args, -1);
|
1778
|
+
|
1779
|
+
rb_define_method(mTK, "bool", tcl2rb_bool, 1);
|
1780
|
+
rb_define_method(mTK, "number", tcl2rb_number, 1);
|
1781
|
+
rb_define_method(mTK, "string", tcl2rb_string, 1);
|
1782
|
+
rb_define_method(mTK, "num_or_str", tcl2rb_num_or_str, 1);
|
1783
|
+
|
1784
|
+
/* --------------------- */
|
1785
|
+
rb_global_variable(&ENCODING_NAME_UTF8);
|
1786
|
+
ENCODING_NAME_UTF8 = rb_obj_freeze(rb_str_new2("utf-8"));
|
1787
|
+
|
1788
|
+
/* --------------------- */
|
1789
|
+
}
|