summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-08-13 06:09:54 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-08-13 06:09:54 +0000
commit942b2ba4b66a1026972e27ea7990dc08f01ec9cc (patch)
treebf2d0e2f5e93c927aa7a8d1fd809a26c955fb1ba
parent65a5162550f58047974793cdc8067a970b2435c0 (diff)
remove obsolete files
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--config.dj36
-rw-r--r--io.h58
-rw-r--r--lib/e2mmap1_0.rb71
-rw-r--r--lib/tk.rb1254
-rw-r--r--lib/tkcanvas.rb326
-rw-r--r--lib/tkclass.rb38
-rw-r--r--lib/tkcore.rb528
-rw-r--r--lib/tkdialog.rb62
-rw-r--r--lib/tkentry.rb67
-rw-r--r--lib/tkscrollbox.rb27
-rw-r--r--lib/tktext.rb164
-rw-r--r--lib/tkthcore.rb550
-rw-r--r--missing/nt.c2194
-rw-r--r--missing/nt.h362
-rw-r--r--missing/setenv.c149
-rw-r--r--sample/ruby-mode.el649
-rw-r--r--sample/rubydb2x.el104
-rw-r--r--sample/rubydb3x.el104
-rw-r--r--sample/tkbiff.rb149
-rw-r--r--sample/tkbrowse.rb69
-rw-r--r--sample/tkdialog.rb62
-rw-r--r--sample/tkfrom.rb126
-rw-r--r--sample/tkhello.rb10
-rw-r--r--sample/tkline.rb46
-rw-r--r--sample/tktimer.rb50
-rw-r--r--sig.h53
26 files changed, 0 insertions, 7308 deletions
diff --git a/config.dj b/config.dj
deleted file mode 100644
index 8ad3883380..0000000000
--- a/config.dj
+++ /dev/null
@@ -1,36 +0,0 @@
-#define THREAD 1
-#define HAVE_DIRENT_H 1
-#define HAVE_UNISTD_H 1
-#define HAVE_LIMITS_H 1
-#define HAVE_SYS_FILE_H 1
-#define HAVE_PWD_H 1
-#define HAVE_SYS_TIME_H 1
-#define HAVE_SYS_TIMES_H 1
-#define HAVE_SYS_PARAM_H 1
-#define HAVE_SYS_WAIT_H 1
-#define HAVE_STRING_H 1
-#define HAVE_UTIME_H 1
-#define HAVE_MEMORY_H 1
-#define HAVE_ST_BLKSIZE 1
-#define HAVE_ST_RDEV 1
-#define GETGROUPS_T gid_t
-#define RETSIGTYPE void
-#define HAVE_ALLOCA 1
-#define vfork fork
-#define HAVE_FMOD 1
-#define HAVE_RANDOM 1
-#define HAVE_WAITPID 1
-#define HAVE_GETCWD 1
-#define HAVE_TRUNCATE 1
-#define HAVE_CHSIZE 1
-#define HAVE_TIMES 1
-#define HAVE_UTIMES 1
-/* #define HAVE_FCNTL 1 */
-/* #define HAVE_SETITIMER 1 */
-#define HAVE_GETGROUPS 1
-#define HAVE_SIGPROCMASK 1
-#define FILE_COUNT _cnt
-#define DLEXT ".so"
-#define RUBY_LIB ";/usr/local/lib/ruby;."
-#define RUBY_ARCHLIB "/usr/local/lib/ruby/i386-djgpp"
-#define RUBY_PLATFORM "i386-djgpp"
diff --git a/io.h b/io.h
deleted file mode 100644
index c671fca8ed..0000000000
--- a/io.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/************************************************
-
- io.h -
-
- $Author$
- $Revision$
- $Date$
- created at: Fri Nov 12 16:47:09 JST 1993
-
- Copyright (C) 1993-1996 Yukihiro Matsumoto
-
-************************************************/
-
-#ifndef IO_H
-#define IO_H
-
-#include "sig.h"
-#include <stdio.h>
-#include <errno.h>
-
-typedef struct OpenFile {
- FILE *f; /* stdio ptr for read/write */
- FILE *f2; /* additional ptr for rw pipes */
- int mode; /* mode flags */
- int pid; /* child's pid (for pipes) */
- int lineno; /* number of lines read */
- char *path; /* pathname for file */
- void (*finalize)(); /* finalize proc */
-} OpenFile;
-
-#define FMODE_READABLE 1
-#define FMODE_WRITABLE 2
-#define FMODE_READWRITE 3
-#define FMODE_BINMODE 4
-#define FMODE_SYNC 8
-
-#define GetOpenFile(obj,fp) ((fp) = RFILE(obj)->fptr)
-
-#define MakeOpenFile(obj, fp) do {\
- fp = RFILE(obj)->fptr = ALLOC(OpenFile);\
- fp->f = fp->f2 = NULL;\
- fp->mode = 0;\
- fp->pid = 0;\
- fp->lineno = 0;\
- fp->path = NULL;\
- fp->finalize = 0;\
-} while (0)
-
-#define GetWriteFile(fptr) (((fptr)->f2) ? (fptr)->f2 : (fptr)->f)
-
-FILE *rb_fopen _((char *, char *));
-FILE *rb_fdopen _((int, char *));
-void io_writable _((OpenFile *));
-void io_readable _((OpenFile *));
-void io_fptr_finalize _((OpenFile *));
-void io_unbuffered _((OpenFile *));
-
-#endif
diff --git a/lib/e2mmap1_0.rb b/lib/e2mmap1_0.rb
deleted file mode 100644
index d245dec975..0000000000
--- a/lib/e2mmap1_0.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-#
-# e2mmap.rb -
-# $Release Version: 1.0$
-# $Revision$
-# $Date$
-# by Keiju ISHITSUKA
-#
-# --
-#
-#
-
-module Exception2MessageMapper
- RCS_ID='-$Header$-'
- E2MM = Exception2MessageMapper
-
- def E2MM.extend_to(b)
- c = eval("self", b)
- c.extend(self)
- c.bind(b)
- end
-
- def bind(b)
- eval "
- @binding = binding
- E2MM_ErrorMSG = Hash.new
-
- # fail(err, *rest)
- # err: 例外
- # rest: メッセージに渡すパラメータ
- #
- def fail!(*rest)
- super
- end
-
- def fail(err, *rest)
- $! = err.new(sprintf(E2MM_ErrorMSG[err], *rest))
- super()
- end
-
- public :fail
- # def_exception(c, m)
- # c: exception
- # m: message_form
- # 例外cのメッセージをmとする.
- #
- def def_e2message(c, m)
- E2MM_ErrorMSG[c] = m
- end
-
- # def_exception(c, m)
- # c: exception_name
- # m: message_form
- # s: 例外スーパークラス(デフォルト: Exception)
- # 例外名``c''をもつ例外を定義し, そのメッセージをmとする.
- #
- def def_exception(c, m)
-
- c = c.id2name if c.kind_of?(Fixnum)
- eval \"class \#{c} < Exception
- end
- E2MM_ErrorMSG[\#{c}] = '\#{m}'
- \", @binding
- end
-", b
-
- end
-
- E2MM.extend_to(binding)
- def_exception("ErrNotClassOrModule", "Not Class or Module")
-end
-
diff --git a/lib/tk.rb b/lib/tk.rb
deleted file mode 100644
index 2cbbec02a8..0000000000
--- a/lib/tk.rb
+++ /dev/null
@@ -1,1254 +0,0 @@
-#
-# tk.rb - Tk interface modue using tcltklib
-# $Date$
-# by Yukihiro Matsumoto <matz@netlab.co.jp>
-
-# use Shigehiro's tcltklib
-require "tcltklib"
-require "tkutil"
-
-module TkComm
- None = Object.new
- def None.to_s
- 'None'
- end
-
- Tk_CMDTBL = {}
- Tk_WINDOWS = {}
-
- def error_at
- frames = caller(1)
- frames.delete_if do |c|
- c =~ %r!/tk(|core|thcore|canvas|text|entry|scrollbox)\.rb:\d+!
- end
- frames
- end
- private :error_at
-
- def tk_tcl2ruby(val)
- case val
- when /^-?\d+$/
- val.to_i
- when /^\./
- Tk_WINDOWS[val]
- when /^rb_out (c\d+)/
- Tk_CMDTBL[$1]
- when / /
- val.split.collect{|elt|
- tk_tcl2ruby(elt)
- }
- when /^-?\d+\.\d*$/
- val.to_f
- else
- val
- end
- end
-
- def tk_split_list(str)
- idx = str.index('{')
- return tk_tcl2ruby(str) if not idx
-
- list = tk_tcl2ruby(str[0,idx])
- str = str[idx+1..-1]
- i = -1
- brace = 1
- str.each_byte {|c|
- i += 1
- brace += 1 if c == ?{
- brace -= 1 if c == ?}
- break if brace == 0
- }
- 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
- private :tk_tcl2ruby, :tk_split_list
-
- def hash_kv(keys)
- conf = []
- if keys and keys != None
- for k, v in keys
- conf.push("-#{k}")
- v = install_cmd(v) if v.kind_of? Proc
- conf.push(v)
- end
- end
- conf
- end
- private :hash_kv
-
- def bool(val)
- case val
- when "1", 1, 'yes', 'true'
- TRUE
- else
- FALSE
- end
- end
- def number(val)
- case val
- when /^-?\d+$/
- val.to_i
- when /^-?\d+\.\d*$/
- val.to_f
- else
- val
- end
- end
- def string(val)
- if val == "{}"
- ''
- elsif val[0] == ?{
- val[1..-2]
- else
- val
- end
- end
- def list(val)
- tk_split_list(val)
- end
- def window(val)
- Tk_WINDOWS[val]
- end
- def procedure(val)
- if val =~ /^rb_out (c\d+)/
- Tk_CMDTBL[$1]
- else
- nil
- end
- end
- private :bool, :number, :string, :list, :window, :procedure
-
- Tk_IDs = [0] # [0]-cmdid, [1]-winid
- def _curr_cmd_id
- id = format("c%.4d", Tk_IDs[0])
- end
- def _next_cmd_id
- id = _curr_cmd_id
- Tk_IDs[0] += 1
- end
- def install_cmd(cmd)
- return '' if cmd == ''
- id = _next_cmd_id
- Tk_CMDTBL[id] = cmd
- @cmdtbl = [] if not @cmdtbl
- @cmdtbl.push id
- return format("rb_out %s", id);
- end
- def uninstall_cmd(id)
- Tk_CMDTBL[id] = nil
- end
- private :install_cmd, :uninstall_cmd
-
- def install_win(ppath)
- id = format("w%.4d", Tk_IDs[0])
- Tk_IDs[0] += 1
- if !ppath or ppath == "."
- @path = format(".%s", id);
- else
- @path = format("%s.%s", ppath, id)
- end
- Tk_WINDOWS[@path] = self
- end
-
- def uninstall_win()
- Tk_WINDOWS[@path] = nil
- end
-
- class Event
- def initialize(seq,b,f,h,k,s,t,w,x,y,aa,ee,kk,nn,ww,tt,xx,yy)
- @serial = seq
- @num = b
- @focus = (f == 1)
- @height = h
- @keycode = k
- @state = s
- @time = t
- @width = w
- @x = x
- @y = y
- @char = aa
- @send_event = (ee == 1)
- @keysym = kk
- @keysym_num = nn
- @type = tt
- @widget = ww
- @x_root = xx
- @y_root = yy
- end
- attr :serial
- attr :num
- attr :focus
- attr :height
- attr :keycode
- attr :state
- attr :time
- attr :width
- attr :x
- attr :y
- attr :char
- attr :send_event
- attr :keysym
- attr :keysym_num
- attr :type
- attr :widget
- attr :x_root
- attr :y_root
- end
-
- def install_bind(cmd, args=nil)
- if args
- id = install_cmd(proc{|arg|
- TkUtil.eval_cmd cmd, *arg
- })
- id + " " + args
- else
- id = install_cmd(proc{|arg|
- TkUtil.eval_cmd cmd, Event.new(*arg)
- })
- id + ' %# %b %f %h %k %s %t %w %x %y %A %E %K %N %W %T %X %Y'
- end
- end
-
- def _bind(path, context, cmd, args=nil)
- begin
- id = install_bind(cmd, args)
- tk_call 'bind', path, "<#{context}>", id
- rescue
- uninstall_cmd(id)
- fail
- end
- end
- private :install_bind, :_bind
-
- def bind_all(context, cmd=Proc.new, args=nil)
- _bind 'all', context, cmd, args
- end
-
- def pack(*args)
- TkPack.configure *args
- end
-
- def after(ms, cmd=Proc.new)
- myid = _curr_cmd_id
- tk_call 'after', ms,
- install_cmd(proc{
- TkUtil.eval_cmd cmd
- uninstall_cmd myid
- })
- end
-end
-
-module TkCore
- include TkComm
- extend TkComm
-
- INTERP = TclTkIp.new
- INTERP._eval("proc rb_out {args} { ruby [format \"TkCore.callback %%Q!%s!\" $args] }")
-
- def TkCore.callback(arg)
- arg = Array(tk_split_list(arg))
- TkUtil.eval_cmd Tk_CMDTBL[arg.shift], *arg
- end
-
- def mainloop
- TclTkLib.mainloop
- end
-
- def _get_eval_string(*args)
- argstr = ""
- args.each{|arg|
- next if arg == None
- if arg.kind_of?(Hash)
- str = hash_kv(arg).join(" ")
- elsif arg == nil
- str = ""
- elsif arg == false
- str = "0"
- elsif arg == true
- str = "1"
- elsif (arg.respond_to?(:to_eval))
- str = arg.to_eval()
- else
- str = arg.to_s()
- end
- argstr += " " if argstr != ""
- argstr += '"' + str.gsub(/[][$"]/, '\\\\\&') + '"'
- }
- return argstr
- end
-
- def tk_call(*args)
- argstr = _get_eval_string(*args)
-
- res = INTERP._eval(argstr)
- if INTERP._return_value() != 0
- fail RuntimeError, res, error_at
- end
- return res
- end
-end
-
-module Tk
- include TkCore
- extend Tk
-
- def root
- TkRoot.new
- end
-
- def bell
- tk_call 'bell'
- end
-
- def mainloop
- TclTkLib.mainloop
- end
-
- module Scrollable
- def xscrollcommand(cmd=Proc.new)
- configure_cmd 'xscrollcommand', cmd
- end
- def yscrollcommand(cmd=Proc.new)
- configure_cmd 'yscrollcommand', cmd
- end
- end
-
- module Wm
- def aspect(*args)
- w = window(tk_call('wm', 'grid', path, *args))
- w.split.collect{|s|s.to_i} if args.length == 0
- end
- def client(name=None)
- tk_call 'wm', 'client', path, name
- end
- def colormapwindows(*args)
- list(tk_call('wm', 'colormapwindows', path, *args))
- end
- def wm_command(value=None)
- string(tk_call('wm', 'command', path, value))
- end
- def deiconify
- tk_call 'wm', 'deiconify', path
- end
- def focusmodel(*args)
- tk_call 'wm', 'focusmodel', path, *args
- end
- def frame
- tk_call 'wm', 'frame', path
- end
- def geometry(*args)
- list(tk_call('wm', 'geometry', path, *args))
- end
- def grid(*args)
- w = tk_call('wm', 'grid', path, *args)
- list(w) if args.size == 0
- end
- def group(*args)
- tk_call 'wm', 'path', path, *args
- end
- def iconbitmap(*args)
- tk_call 'wm', 'bitmap', path, *args
- end
- def iconify
- tk_call 'wm', 'iconify'
- end
- def iconmask(*args)
- tk_call 'wm', 'iconmask', path, *args
- end
- def iconname(*args)
- tk_call 'wm', 'iconname', path, *args
- end
- def iconposition(*args)
- w = tk_call('wm', 'iconposition', path, *args)
- list(w) if args.size == 0
- end
- def iconwindow(*args)
- tk_call 'wm', 'iconwindow', path, *args
- end
- def maxsize(*args)
- w = tk_call('wm', 'maxsize', path, *args)
- list(w) if not args.size == 0
- end
- def minsize(*args)
- w = tk_call('wm', 'minsize', path, *args)
- list(w) if args.size == 0
- end
- def overrideredirect(bool=None)
- if bool == None
- bool(tk_call('wm', 'overrideredirect', path))
- else
- tk_call 'wm', 'overrideredirect', path, bool
- end
- end
- def positionfrom(*args)
- tk_call 'wm', 'positionfrom', path, *args
- end
- def protocol(name, func=None)
- func = install_cmd(func) if not func == None
- tk_call 'wm', 'command', path, name, func
- end
- def resizable(*args)
- w = tk_call('wm', 'resizable', path, *args)
- if args.length == 0
- list(w).collect{|e| bool(e)}
- end
- end
- def sizefrom(*args)
- list(tk_call('wm', 'sizefrom', path, *args))
- end
- def state
- tk_call 'wm', 'state', path
- end
- def title(*args)
- tk_call 'wm', 'title', path, *args
- end
- def transient(*args)
- tk_call 'wm', 'transient', path, *args
- end
- def withdraw
- tk_call 'wm', 'withdraw', path
- end
- end
-end
-
-class TkVariable
- include Tk
-
- Tk_VARIABLE_ID = ["v00000"]
- def initialize(val="")
- @id = Tk_VARIABLE_ID[0]
- Tk_VARIABLE_ID[0] = Tk_VARIABLE_ID[0].succ
- INTERP._eval(format('global %s; set %s %s', @id, @id, _get_eval_string(val)))
- end
-
- def id
- @id
- end
-
- def value
- INTERP._eval(format('global %s; set %s', @id, @id))
- end
-
- def value=(val)
- INTERP._eval(format('global %s; set %s %s', @id, @id, _get_eval_string(val)))
- end
-
- def to_i
- Integer(number(value))
- end
-
- def to_f
- Float(number(value))
- end
-
- def to_s
- String(string(value))
- end
-
- def inspect
- format "<TkVariable: %s>", @id
- end
-
- def ==(other)
- case other
- when TkVariable
- self.equal(self)
- when String
- self.to_s == other
- when Integer
- self.to_i == other
- when Float
- self.to_f == other
- when Array
- self.to_a == other
- else
- false
- end
- end
-
- def to_a
- list(value)
- end
-
- def to_eval
- @id
- end
-end
-
-module TkSelection
- include Tk
- extend Tk
- def clear(win=Tk.root)
- tk_call 'selection', 'clear', win.path
- end
- def get(type=None)
- tk_call 'selection', 'get', type
- end
- def TkSelection.handle(win, func, type=None, format=None)
- id = install_cmd(func)
- tk_call 'selection', 'handle', win.path, id, type, format
- end
- def handle(func, type=None, format=None)
- TkSelection.handle self, func, type, format
- end
- def TkSelection.own(win, func=None)
- id = install_cmd(func)
- tk_call 'selection', 'own', win.path, id
- end
- def own(func=None)
- TkSelection.own self, func
- end
-
- module_function :clear, :get
-end
-
-module TkWinfo
- include Tk
- extend Tk
- def TkWinfo.atom(name)
- tk_call 'winfo', name
- end
- def winfo_atom(name)
- TkWinfo.atom name
- end
- def TkWinfo.atomname(id)
- tk_call 'winfo', id
- end
- def winfo_atomname(id)
- TkWinfo.atomname id
- end
- def TkWinfo.cells(window)
- number(tk_call('winfo', window.path))
- end
- def winfo_cells
- TkWinfo.cells self
- end
- def TkWinfo.children(window)
- c = tk_call('winfo', 'children', window.path)
- list(c)
- end
- def winfo_children
- TkWinfo.children self
- end
- def TkWinfo.classname(window)
- tk_call 'winfo', 'class', window.path
- end
- def winfo_classname
- TkWinfo.classname self
- end
- def TkWinfo.containing(rootX, rootY)
- path = tk_call('winfo', 'class', window.path)
- window(path)
- end
- def winfo_containing(x, y)
- TkWinfo.containing x, y
- end
- def TkWinfo.depth(window)
- number(tk_call('winfo', 'depth', window.path))
- end
- def winfo_depth(window)
- TkWinfo.depth self
- end
- def TkWinfo.exist?(window)
- bool(tk_call('winfo', 'exists', window.path))
- end
- def winfo_exist?(window)
- TkWinfo.exist? self
- end
- def TkWinfo.fpixels(window, number)
- number(tk_call('winfo', 'fpixels', window.path, number))
- end
- def winfo_fpixels(window, number)
- TkWinfo.fpixels self
- end
- def TkWinfo.geometry(window)
- list(tk_call('winfo', 'geometry', window.path))
- end
- def winfo_geometry(window)
- TkWinfo.geometry self
- end
- def TkWinfo.height(window)
- number(tk_call('winfo', 'height', window.path))
- end
- def winfo_height(window)
- TkWinfo.height self
- end
- def TkWinfo.id(window)
- number(tk_call('winfo', 'id', window.path))
- end
- def winfo_id(window)
- TkWinfo.id self
- end
- def TkWinfo.mapped?(window)
- bool(tk_call('winfo', 'ismapped', window.path))
- end
- def winfo_mapped?(window)
- TkWinfo.mapped? self
- end
- def TkWinfo.parent(window)
- window(tk_call('winfo', 'parent', window.path))
- end
- def winfo_parent(window)
- TkWinfo.parent self
- end
- def TkWinfo.widget(id)
- window(tk_call('winfo', 'pathname', id))
- end
- def winfo_widget(id)
- TkWinfo.widget id
- end
- def TkWinfo.pixels(window, number)
- number(tk_call('winfo', 'pixels', window.path, number))
- end
- def winfo_pixels(window, number)
- TkWinfo.pixels self, number
- end
- def TkWinfo.reqheight(window)
- number(tk_call('winfo', 'reqheight', window.path))
- end
- def winfo_reqheight(window)
- TkWinfo.reqheight self
- end
- def TkWinfo.reqwidth(window)
- number(tk_call('winfo', 'reqwidth', window.path))
- end
- def winfo_reqwidth(window)
- TkWinfo.reqwidth self
- end
- def TkWinfo.rgb(window, color)
- list(tk_call('winfo', 'rgb', window.path, color))
- end
- def winfo_rgb(window, color)
- TkWinfo.rgb self, color
- end
- def TkWinfo.rootx(window)
- number(tk_call('winfo', 'rootx', window.path))
- end
- def winfo_rootx(window)
- TkWinfo.rootx self
- end
- def TkWinfo.rooty(window)
- number(tk_call('winfo', 'rooty', window.path))
- end
- def winfo_rooty(window)
- TkWinfo.rooty self
- end
- def TkWinfo.screen(window)
- tk_call 'winfo', 'screen', window.path
- end
- def winfo_screen(window)
- TkWinfo.screen self
- end
- def TkWinfo.screencells(window)
- number(tk_call('winfo', 'screencells', window.path))
- end
- def winfo_screencells(window)
- TkWinfo.screencells self
- end
- def TkWinfo.screendepth(window)
- number(tk_call('winfo', 'screendepth', window.path))
- end
- def winfo_screendepth(window)
- TkWinfo.screendepth self
- end
- def TkWinfo.screenheight (window)
- number(tk_call('winfo', 'screenheight', window.path))
- end
- def winfo_screenheight(window)
- TkWinfo.screenheight self
- end
- def TkWinfo.screenmmheight(window)
- number(tk_call('winfo', 'screenmmheight', window.path))
- end
- def winfo_screenmmheight(window)
- TkWinfo.screenmmheight self
- end
- def TkWinfo.screenmmwidth(window)
- number(tk_call('winfo', 'screenmmwidth', window.path))
- end
- def winfo_screenmmwidth(window)
- TkWinfo.screenmmwidth self
- end
- def TkWinfo.screenvisual(window)
- tk_call 'winfo', 'screenvisual', window.path
- end
- def winfo_screenvisual(window)
- TkWinfo.screenvisual self
- end
- def TkWinfo.screenwidth(window)
- number(tk_call('winfo', 'screenwidth', window.path))
- end
- def winfo_screenwidth(window)
- TkWinfo.screenwidth self
- end
- def TkWinfo.toplevel(window)
- window(tk_call('winfo', 'toplevel', window.path))
- end
- def winfo_toplevel(window)
- TkWinfo.toplevel self
- end
- def TkWinfo.visual(window)
- tk_call 'winfo', 'visual', window.path
- end
- def winfo_visual(window)
- TkWinfo.visual self
- end
- def TkWinfo.vrootheigh(window)
- number(tk_call('winfo', 'vrootheight', window.path))
- end
- def winfo_vrootheight(window)
- TkWinfo.vrootheight self
- end
- def TkWinfo.vrootwidth(window)
- number(tk_call('winfo', 'vrootwidth', window.path))
- end
- def winfo_vrootwidth(window)
- TkWinfo.vrootwidth self
- end
- def TkWinfo.vrootx(window)
- number(tk_call('winfo', 'vrootx', window.path))
- end
- def winfo_vrootx(window)
- TkWinfo.vrootx self
- end
- def TkWinfo.vrooty(window)
- number(tk_call('winfo', 'vrooty', window.path))
- end
- def winfo_vrooty(window)
- TkWinfo.vrooty self
- end
- def TkWinfo.width(window)
- number(tk_call('winfo', 'width', window.path))
- end
- def winfo_width(window)
- TkWinfo.width self
- end
- def TkWinfo.x(window)
- number(tk_call('winfo', 'x', window.path))
- end
- def winfo_x(window)
- TkWinfo.x self
- end
- def TkWinfo.y(window)
- number(tk_call('winfo', 'y', window.path))
- end
- def winfo_y(window)
- TkWinfo.y self
- end
-end
-
-module TkPack
- include Tk
- extend Tk
- def configure(win, *args)
- if args[-1].kind_of?(Hash)
- keys = args.pop
- end
- wins = [win.epath]
- for i in args
- wins.push i.epath
- end
- tk_call "pack", 'configure', *(wins+hash_kv(keys))
- end
-
- def forget(*args)
- tk_call 'pack', 'forget' *args
- end
-
- def propagate(master, bool=None)
- bool(tk_call('pack', 'propagate', master.epath, bool))
- end
- module_function :configure, :forget, :propagate
-end
-
-module TkOption
- include Tk
- extend Tk
- def add pat, value, pri=None
- tk_call 'option', 'add', pat, value, pri
- end
- def clear
- tk_call 'option', 'clear'
- end
- def get win, classname, name
- tk_call 'option', 'get', classname, name
- end
- def readfile file, pri=None
- tk_call 'option', 'readfile', file, pri
- end
- module_function :add, :clear, :get, :readfile
-end
-
-class TkObject<TkKernel
- include Tk
-
- def path
- return @path
- end
-
- def epath
- return @path
- end
-
- def to_eval
- @path
- end
-
- def tk_send(cmd, *rest)
- tk_call path, cmd, *rest
- end
- private :tk_send
-
- def method_missing(id, *args)
- if (args.length == 1)
- configure id.id2name, args[0]
- else
- $@ = error_at
- super
- end
- end
-
- def []=(id, val)
- configure id, val
- end
-
- def configure(slot, value)
- if value == FALSE
- value = "0"
- elsif value.kind_of? Proc
- value = install_cmd(value)
- end
- tk_call path, 'configure', "-#{slot}", value
- end
-
- def configure_cmd(slot, value)
- configure slot, install_cmd(value)
- end
-
- def bind(context, cmd=Proc.new, args=nil)
- _bind path, context, cmd, args
- end
-
- def tk_trace_variable(v)
- unless v.kind_of?(TkVariable)
- fail ArgumentError, format("requires TkVariable given %s", v.type)
- end
- v
- end
- private :tk_trace_variable
-
- def destroy
- tk_call 'trace', 'vdelete', @tk_vn, 'w', @var_id if @var_id
- end
-end
-
-class TkWindow<TkObject
-
- def initialize(parent=nil, keys=nil)
- install_win(if parent then parent.path end)
- create_self
- if keys
- tk_call @path, 'configure', *hash_kv(keys)
- end
- end
-
- def create_self
- end
- private :create_self
-
- def pack(keys = nil)
- tk_call 'pack', epath, *hash_kv(keys)
- self
- end
-
- def unpack(keys = nil)
- tk_call 'pack', 'forget', epath
- self
- end
-
- def place(keys = nil)
- tk_call 'place', epath, *hash_kv(keys)
- self
- end
-
- def unplace(keys = nil)
- tk_call 'place', 'forget', epath, *hash_kv(keys)
- self
- end
- alias place_forget unplace
-
- def place_config(keys)
- tk_call "place", 'configure', epath, *hash_kv(keys)
- end
-
- def place_info()
- ilist = list(tk_call('place', 'info', epath))
- info = {}
- while key = ilist.shift
- info[key[1,-1]] = ilist.shift
- end
- return info
- end
-
- def place_slaves()
- list(tk_call('place', 'slaves', epath)).collect { |w|
- window(w)
- }
- end
-
- def focus
- tk_call 'focus', path
- self
- end
-
- def grab(*args)
- if !args or args.length == 0
- tk_call 'grab', 'set', path
- elsif args.length == 1
- case args[0]
- when 'global'
- tk_call 'grab', 'set', '-global', path
- else
- val = tk_call('grab', arg[0], path)
- end
- case args[0]
- when 'current'
- return window(val)
- when 'status'
- return val
- end
- else
- fail ArgumentError, 'wrong # of args'
- end
- end
-
- def lower(below=None)
- tk_call 'lower', path, below
- self
- end
- def raise(above=None)
- tk_call 'raise', path, above
- self
- end
-
- def command(cmd=Proc.new)
- configure_cmd 'command', cmd
- end
-
- def colormodel model=None
- tk_call 'tk', 'colormodel', path, model
- self
- end
-
- def destroy
- tk_call 'destroy', path
- if @cmdtbl
- for id in @cmdtbl
- uninstall_cmd id
- end
- end
- uninstall_win
- end
-end
-
-class TkRoot<TkWindow
- include Wm
- ROOT = []
- def TkRoot.new
- return ROOT[0] if ROOT[0]
- new = super
- ROOT[0] = new
- end
- def create_self
- @path = '.'
- end
- def path
- "."
- end
-end
-
-class TkToplevel<TkWindow
- include Wm
- def initialize(parent=nil, screen=nil, classname=nil, keys=nil)
- @screen = screen if screen
- @classname = classname if classname
- super(parent, keys)
- end
-
- def create_self
- s = []
- s.push "-screen #@screen" if @screen
- s.push "-class #@classname" if @classname
- tk_call 'toplevel', path, *s
- end
-end
-
-class TkFrame<TkWindow
- def create_self
- tk_call 'frame', @path
- end
-end
-
-class TkLabel<TkWindow
- def create_self
- tk_call 'label', @path
- end
- def textvariable(v)
- configure 'textvariable', tk_trace_variable(v)
- end
-end
-
-class TkButton<TkLabel
- def create_self
- tk_call 'button', @path
- end
- def invoke
- tk_send 'invoke'
- end
- def flash
- tk_send 'flash'
- end
-end
-
-class TkRadioButton<TkButton
- def create_self
- tk_call 'radiobutton', @path
- end
- def deselect
- tk_send 'deselect'
- end
- def select
- tk_send 'select'
- end
- def variable(v)
- configure 'variable', tk_trace_variable(v)
- end
-end
-
-class TkCheckButton<TkRadioButton
- def create_self
- tk_call 'checkbutton', @path
- end
- def toggle
- tk_send 'toggle'
- end
-end
-
-class TkMessage<TkLabel
- def create_self
- tk_call 'message', @path
- end
-end
-
-class TkScale<TkWindow
- def create_self
- tk_call 'scale', path
- end
-
- def get
- number(tk_send('get'))
- end
-
- def set(val)
- tk_send "set", val
- end
-
- def value
- get
- end
-
- def value= (val)
- set val
- end
-end
-
-class TkScrollbar<TkWindow
- def create_self
- tk_call 'scrollbar', path
- end
-
- def delta(deltax=None, deltay=None)
- number(tk_send('delta', deltax, deltay))
- end
-
- def fraction(x=None, y=None)
- number(tk_send('fraction', x, y))
- end
-
- def identify(x=None, y=None)
- tk_send('fraction', x, y)
- end
-
- def get
- ary1 = tk_send('get', path).split
- ary2 = []
- for i in ary1
- ary2.push number(i)
- end
- ary2
- end
-
- def set(first, last)
- tk_send "set", first, last
- end
-end
-
-class TkTextWin<TkWindow
- def bbox(index)
- tk_send 'bbox', index
- end
- def delete(first, last=None)
- tk_send 'delete', first, last
- end
- def get(*index)
- tk_send 'get', *index
- end
- def index(index)
- tk_send 'index', index
- end
- def insert(index, chars, *args)
- tk_send 'insert', index, chars, *args
- end
- def scan_mark(x, y)
- tk_send 'scan', 'mark', x, y
- end
- def scan_dragto(x, y)
- tk_send 'scan', 'dragto', x, y
- end
- def see(index)
- tk_send 'see', index
- end
-end
-
-class TkListbox<TkTextWin
- def create_self
- tk_call 'listbox', path
- end
-
- def curselection
- tk_send 'curselection'
- end
- def nearest(y)
- tk_send 'nearest', y
- end
- def selection_anchor(index)
- tk_send 'selection', 'anchor', index
- end
- def selection_clear(first, last=None)
- tk_send 'selection', 'clear', first, last
- end
- def selection_includes
- bool(tk_send('selection', 'includes'))
- end
- def selection_set(first, last=None)
- tk_send 'selection', 'set', first, last
- end
- def xview(cmd, index, *more)
- tk_send 'xview', cmd, index, *more
- end
- def yview(cmd, index, *more)
- tk_send 'yview', cmd, index, *more
- end
-end
-
-class TkMenu<TkWindow
- def create_self
- tk_call 'menu', path
- end
- def activate(index)
- tk_send 'activate', index
- end
- def add(type, keys=nil)
- tk_send 'add', type, *hash_kv(keys)
- end
- def index(index)
- tk_send 'index', index
- end
- def invoke
- tk_send 'invoke'
- end
- def insert(index, type, *keys)
- tk_send 'add', index, type, *hash_kv(keys)
- end
- def post(x, y)
- tk_send 'post', x, y
- end
- def postcascade(index)
- tk_send 'postcascade', index
- end
- def postcommand(cmd=Proc.new)
- configure_cmd 'postcommand', cmd
- end
- def menutype(index)
- tk_send 'type', index
- end
- def unpost
- tk_send 'unpost'
- end
- def yposition(index)
- number(tk_send('yposition', index))
- end
-end
-
-class TkMenubutton<TkLabel
- def create_self
- tk_call 'menubutton', path
- end
-end
-
-module TkComposite
- def initialize(parent=nil, *args)
- @frame = TkFrame.new(parent)
- @path = @epath = @frame.path
- initialize_composite(*args)
- end
-
- def epath
- @epath
- end
-
- def initialize_composite(*args) end
- private :initialize_composite
-
- def delegate(option, *wins)
- unless @delegates
- @delegates = {}
- @delegates['DEFAULT'] = @frame
- end
- if option.kind_of?(String)
- @delegates[option] = wins
- else
- for i in option
- @delegates[i] = wins
- end
- end
- end
-
- def configure(slot, value)
- if @delegates and @delegates[slot]
- for i in @delegates[slot]
- if not i
- i = @delegates['DEFALUT']
- redo
- else
- last = i.configure(slot, value)
- end
- end
- last
- else
- super
- end
- end
-end
-
-autoload :TkCanvas, 'tkcanvas'
-autoload :TkImage, 'tkcanvas'
-autoload :TkBitmapImage, 'tkcanvas'
-autoload :TkPhotoImage, 'tkcanvas'
-autoload :TkEntry, 'tkentry'
-autoload :TkText, 'tktext'
diff --git a/lib/tkcanvas.rb b/lib/tkcanvas.rb
deleted file mode 100644
index a02db097fd..0000000000
--- a/lib/tkcanvas.rb
+++ /dev/null
@@ -1,326 +0,0 @@
-#
-# tkcanvas.rb - Tk canvas classes
-# $Date$
-# by Yukihiro Matsumoto <matz@caelum.co.jp>
-
-require "tk"
-
-class TkCanvas<TkWindow
- def create_self
- tk_call 'canvas', path
- end
- def tagid(tag)
- if tag.kind_of?(TkcItem)
- tag.id
- else
- tag
- end
- end
- private :tagid
- def addtag(tag, *args)
- tk_send 'addtag', tagid(tag), *args
- end
- def addtag_above(tagOrId)
- addtag('above', tagOrId)
- end
- def addtag_all
- addtag('all')
- end
- def addtag_below(tagOrId)
- addtag('below', tagOrId)
- end
- def addtag_closest(x, y, halo=None, start=None)
- addtag('closest', x, y, halo, start)
- end
- def addtag_enclosed(x1, y1, x2, y2)
- addtag('enclosed', x1, y1, x2, y2)
- end
- def addtag_overlapping(x1, y1, x2, y2)
- addtag('overlapping', x1, y1, x2, y2)
- end
- def addtag_withtag(tagOrId)
- addtag('withtag', tagOrId)
- end
- def bbox(tag)
- list(tk_send('bbox', tagid(tag)))
- end
- def itembind(tag, seq, cmd=Proc.new)
- id = install_cmd(cmd)
- tk_send 'bind', tagid(tag), "<#{seq}>", id
- @cmdtbl.push id
- end
- def canvasx(x, *args)
- tk_send 'canvasx', x, *args
- end
- def canvasy(y, *args)
- tk_send 'canvasy', y, *args
- end
- def coords(tag, *args)
- tk_send 'coords', tagid(tag), *args
- end
- def dchars(tag, first, last=None)
- tk_send 'dchars', tagid(tag), first, last
- end
- def delete(*args)
- tk_send 'delete', *args
- end
- alias remove delete
- def dtag(tag, tag_to_del=None)
- tk_send 'dtag', tagid(tag), tag_to_del
- end
- def find(*args)
- tk_send 'find', *args
- end
- def itemfocus(tag)
- tk_send 'find', tagid(tag)
- end
- def gettags(tag)
- tk_send 'gettags', tagid(tag)
- end
- def icursor(tag, index)
- tk_send 'icursor', tagid(tag), index
- end
- def index(tag)
- tk_send 'index', tagid(tag), index
- end
- def lower(tag, below=None)
- tk_send 'lower', tagid(tag), below
- end
- def move(tag, x, y)
- tk_send 'move', tagid(tag), x, y
- end
- def itemtype(tag)
- tk_send 'type', tagid(tag)
- end
- def postscript(keys)
- tk_send "postscript", *hash_kv(keys)
- end
- def raise(tag, above=None)
- tk_send 'raise', tagid(tag), above
- end
- def scale(tag, x, y, xs, ys)
- tk_send 'scale', tagid(tag), x, y, xs, ys
- end
- def scan_mark(x, y)
- tk_send 'scan', 'mark', x, y
- end
- def scan_dragto(x, y)
- tk_send 'scan', 'dragto', x, y
- end
- def select(*args)
- tk_send 'select', *args
- end
- def xview(*index)
- tk_send 'xview', *index
- end
- def yview(*index)
- tk_send 'yview', *index
- end
-end
-
-class TkcItem<TkObject
- def initialize(parent, *args)
- if not parent.kind_of?(TkCanvas)
- fail format("%s need to be TkCanvas", parent.inspect)
- end
- @c = parent
- @path = parent.path
- if args[-1].kind_of? Hash
- keys = args.pop
- end
- @id = create_self(*args)
- if keys
- tk_call @path, 'itemconfigure', @id, *hash_kv(keys)
- end
- end
- def create_self(*args) end
- private :create_self
- def id
- return @id
- end
-
- def configure(slot, value)
- tk_call path, 'itemconfigure', @id, "-#{slot}", value
- end
-
- def addtag(tag)
- @c.addtag(tag, 'withtag', @id)
- end
- def bbox
- @c.bbox(@id)
- end
- def bind(seq, cmd=Proc.new)
- @c.itembind @id, seq, cmd
- end
- def coords(*args)
- @c.coords @id, *args
- end
- def dchars(first, last=None)
- @c.dchars @id, first, last
- end
- def dtag(ttd)
- @c.dtag @id, ttd
- end
- def focus
- @c.focus @id
- end
- def gettags
- @c.gettags @id
- end
- def icursor
- @c.icursor @id
- end
- def index
- @c.index @id
- end
- def insert(beforethis, string)
- @c.insert @id, beforethis, string
- end
- def lower(belowthis=None)
- @c.lower @id, belowthis
- end
- def move(xamount, yamount)
- @c.move @id, xamount, yamount
- end
- def raise(abovethis=None)
- @c.raise @id, abovethis
- end
- def scale(xorigin, yorigin, xscale, yscale)
- @c.scale @id, xorigin, yorigin, xscale, yscale
- end
- def itemtype
- @c.itemtype @id
- end
- def destroy
- tk_call path, 'delete', @id
- end
-end
-
-class TkcArc<TkcItem
- def create_self(*args)
- tk_call(@path, 'create', 'arc', *args)
- end
-end
-class TkcBitmap<TkcItem
- def create_self(*args)
- tk_call(@path, 'create', 'bitmap', *args)
- end
-end
-class TkcImage<TkcItem
- def create_self(*args)
- tk_call(@path, 'create', 'image', *args)
- end
-end
-class TkcLine<TkcItem
- def create_self(*args)
- tk_call(@path, 'create', 'line', *args)
- end
-end
-class TkcOval<TkcItem
- def create_self(*args)
- tk_call(@path, 'create', 'oval', *args)
- end
-end
-class TkcPolygon<TkcItem
- def create_self(*args)
- tk_call(@path, 'create', 'polygon', *args)
- end
-end
-class TkcRectangle<TkcItem
- def create_self(*args)
- tk_call(@path, 'create', 'rectangle', *args)
- end
-end
-class TkcText<TkcItem
- def create_self(*args)
- tk_call(@path, 'create', 'text', *args)
- end
-end
-class TkcWindow<TkcItem
- def create_self(*args)
- tk_call(@path, 'create', 'window', *args)
- end
-end
-class TkcGroup<TkcItem
- $tk_group_id = 'tkg00000'
- def create_self(*args)
- @id = $tk_group_id
- $tk_group_id = $tk_group_id.succ
- end
-
- def add(*tags)
- for i in tags
- i.addtag @id
- end
- end
- def add(*tags)
- for i in tags
- i.addtag @id
- end
- end
- def delete(*tags)
- for i in tags
- i.delete @id
- end
- end
- def list
- @c.find 'withtag', @id
- end
- alias remove delete
-end
-
-
-class TkImage<TkObject
- include Tk
-
- $tk_image_id = 'i00000'
- def initialize(keys=nil)
- @path = $tk_image_id
- $tk_image_id = $tk_image_id.succ
- tk_call 'image', 'create', @type, @path, *hash_kv(keys)
- end
-
- def height
- number(tk_call('image', 'height', @path))
- end
- def itemtype
- tk_call('image', 'type', @path)
- end
- def width
- number(tk_call('image', 'height', @path))
- end
-
- def TkImage.names
- tk_call('image', 'names', @path).split
- end
- def TkImage.types
- tk_call('image', 'types', @path).split
- end
-end
-
-class TkBitmapImage<TkImage
- def initialize(*args)
- @type = 'bitmap'
- super
- end
-end
-
-class TkPhotoImage<TkImage
- def initialize(*args)
- @type = 'photo'
- super
- end
-
- def blank
- tk_send 'blank'
- end
- def cget
- tk_send 'cget'
- end
- def get(x, y)
- tk_send 'get', x, y
- end
- def put(data, to=None)
- tk_send 'put', data, to
- end
-end
diff --git a/lib/tkclass.rb b/lib/tkclass.rb
deleted file mode 100644
index 0b33d4ec8b..0000000000
--- a/lib/tkclass.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-#
-# tkclass.rb - Tk classes
-# $Date$
-# by Yukihiro Matsumoto <matz@caelum.co.jp>
-
-require "tk"
-
-TopLevel = TkToplevel
-Frame = TkFrame
-Label = TkLabel
-Button = TkButton
-Radiobutton = TkRadioButton
-Checkbutton = TkCheckButton
-Message = TkMessage
-Entry = TkEntry
-Text = TkText
-Scale = TkScale
-Scrollbar = TkScrollbar
-Listbox = TkListbox
-Menu = TkMenu
-Menubutton = TkMenubutton
-Canvas = TkCanvas
-Arc = TkcArc
-Bitmap = TkcBitmap
-Line = TkcLine
-Oval = TkcOval
-Polygon = TkcPolygon
-Rectangle = TkcRectangle
-TextItem = TkcText
-WindowItem = TkcWindow
-Selection = TkSelection
-Winfo = TkWinfo
-Pack = TkPack
-Variable = TkVariable
-
-def Mainloop
- Tk.mainloop
-end
diff --git a/lib/tkcore.rb b/lib/tkcore.rb
deleted file mode 100644
index c151b0af9e..0000000000
--- a/lib/tkcore.rb
+++ /dev/null
@@ -1,528 +0,0 @@
-#
-# tkcore.rb - Tk interface modue without thread
-# $Date$
-# by Yukihiro Matsumoto <matz@caelum.co.jp>
-
-require "tkutil"
-if defined? Thread
- require "thread"
-end
-
-module Tk
- include TkUtil
- extend Tk
-
- wish_path = nil
- ENV['PATH'].split(":").each {|path|
- for wish in ['wish4.2', 'wish4.1', 'wish4.0', 'wish']
- if File.exist? path+'/'+wish
- wish_path = path+'/'+wish
- break
- end
- break if wish_path
- end
- }
- fail 'can\'t find wish' if not wish_path #'
-
- def Tk.tk_exit
- if not PORT.closed?
- PORT.print "exit\n"
- PORT.close
- end
- end
-
-# PORT = open(format("|%s -n %s", wish_path, File.basename($0)), "w+");
- PORT = open(format("|%s", wish_path), "w+");
- trap "EXIT", proc{Tk.tk_exit}
- trap "PIPE", ""
-
- def tk_write(*args)
- printf PORT, *args;
- PORT.print "\n"
- PORT.flush
- end
- tk_write '\
-wm withdraw .
-proc rb_out args {
- puts [format %%s $args]
- flush stdout
-}
-proc rb_ans arg {
- if [catch $arg var] {puts "!$var"} {puts "=$var@@"}
- flush stdout
-}
-proc tkerror args { exit }
-proc keepalive {} { rb_out alive; after 120000 keepalive}
-after 120000 keepalive'
-
- READABLE = []
- READ_CMD = {}
-
- def file_readable(port, cmd)
- if cmd == nil
- READABLE.delete port
- else
- READABLE.push port
- end
- READ_CMD[port] = cmd
- end
-
- WRITABLE = []
- WRITE_CMD = {}
- def file_writable(port, cmd)
- if cmd == nil
- WRITABLE.delete port
- else
- WRITABLE.push port
- end
- WRITE_CMD[port] = cmd
- end
- module_function :file_readable, :file_writable
-
- file_readable PORT, proc {
- line = PORT.gets
- exit if not line
- Tk.dispatch(line.chop!)
- }
-
- def error_at
- frames = caller(1)
- frames.delete_if do |c|
- c =~ %r!/tk(|core|thcore|canvas|text|entry|scrollbox)\.rb:\d+!
- end
- frames
- end
-
- def tk_tcl2ruby(val)
- case val
- when /^-?\d+$/
- val.to_i
- when /^\./
- $tk_window_list[val]
- when /^rb_out (c\d+)/
- $tk_cmdtbl[$1]
- when / /
- val.split.collect{|elt|
- tk_tcl2ruby(elt)
- }
- when /^-?\d+\.\d*$/
- val.to_f
- else
- val
- end
- end
-
- def tk_split_list(str)
- idx = str.index('{')
- return tk_tcl2ruby(str) if not idx
-
- list = tk_tcl2ruby(str[0,idx])
- str = str[idx+1..-1]
- i = -1
- brace = 1
- str.each_byte {|c|
- i += 1
- brace += 1 if c == ?{
- brace -= 1 if c == ?}
- break if brace == 0
- }
- 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
- private :tk_tcl2ruby, :tk_split_list
-
- def bool(val)
- case bool
- when "1", 1, 'yes', 'true'
- TRUE
- else
- FALSE
- end
- end
- def number(val)
- case val
- when /^-?\d+$/
- val.to_i
- when /^-?\d+\.\d*$/
- val.to_f
- else
- val
- end
- end
- def string(val)
- if val == "{}"
- ''
- elsif val[0] == ?{
- val[1..-2]
- else
- val
- end
- end
- def list(val)
- tk_split_list(val)
- end
- def window(val)
- $tk_window_list[val]
- end
- def procedure(val)
- if val =~ /^rb_out (c\d+)/
- $tk_cmdtbl[$1]
- else
- nil
- end
- end
- private :bool, :number, :string, :list, :window, :procedure
-
- # mark for non-given arguments
- None = Object.new
- def None.to_s
- 'None'
- end
-
- $tk_event_queue = []
- def tk_call(str, *args)
- args = args.collect{|s|
- next if s == None
- if s.kind_of?(Hash)
- s = hash_kv(s).join(" ")
- else
- if not s
- s = "0"
- elsif s == TRUE
- s = "1"
- elsif s.kind_of?(TkObject)
- s = s.path
- elsif s.kind_of?(TkVariable)
- s = s.id
- else
- s = s.to_s
- s.gsub!(/["\\\$\[\]]/, '\\\\\0') #"
- s.gsub!(/\{/, '\\\\173')
- s.gsub!(/\}/, '\\\\175')
- end
- "\"#{s}\""
- end
- }
- str += " "
- str += args.join(" ")
- print str, "\n" if $DEBUG
- tk_write 'rb_ans {%s}', str
- while PORT.gets
- print $_ if $DEBUG
- $_.chop!
- if /^=(.*)@@$/
- val = $1
- break
- elsif /^=/
- val = $' + "\n"
- while TRUE
- PORT.readline
- if ~/@@$/
- val += $'
- return val
- else
- val += $_
- end
- end
- elsif /^!/
- $@ = error_at
- msg = $'
- if msg =~ /unknown option "-(.*)"/
- $! = NameError.new(format("undefined method `%s' for %s(%s)",
- $1, self, self.type)) #`'
- else
- $! = RuntimeError.new(format("%s - %s", self.type, msg))
- end
- fail
- end
- $tk_event_queue.push $_
- end
-
- while ev = $tk_event_queue.shift
- Tk.dispatch ev
- end
- fail 'wish closed' if PORT.closed?
-# tk_split_list(val)
- val
- end
-
- def hash_kv(keys)
- conf = []
- if keys
- for k, v in keys
- conf.push("-#{k}")
- v = install_cmd(v) if v.kind_of? Proc
- conf.push(v)
- end
- end
- conf
- end
- private :tk_call, :error_at, :hash_kv
-
- $tk_cmdid = 0
- def install_cmd(cmd)
- return '' if cmd == '' # uninstall cmd
- id = format("c%.4d", $tk_cmdid)
- $tk_cmdid += 1
- $tk_cmdtbl[id] = cmd
- @cmdtbl = [] if not @cmdtbl
- @cmdtbl.push id
- return format('rb_out %s', id)
- end
- def uninstall_cmd(id)
- $tk_cmdtbl[id] = nil
- end
- private :install_cmd, :uninstall_cmd
-
- $tk_window_list = {}
- class Event
- def initialize(seq,b,f,h,k,s,t,w,x,y,aa,ee,kk,nn,ww,tt,xx,yy)
- @serial = seq
- @num = b
- @focus = (f == 1)
- @height = h
- @keycode = k
- @state = s
- @time = t
- @width = w
- @x = x
- @y = y
- @char = aa
- @send_event = (ee == 1)
- @keysym = kk
- @keysym_num = nn
- @type = tt
- @widget = ww
- @x_root = xx
- @y_root = yy
- end
- attr :serial
- attr :num
- attr :focus
- attr :height
- attr :keycode
- attr :state
- attr :time
- attr :width
- attr :x
- attr :y
- attr :char
- attr :send_event
- attr :keysym
- attr :keysym_num
- attr :type
- attr :widget
- attr :x_root
- attr :y_root
- end
-
- def install_bind(cmd, args=nil)
- if args
- id = install_cmd(proc{|arg|
- TkUtil.eval_cmd cmd, *arg
- })
- id + " " + args
- else
- id = install_cmd(proc{|arg|
- TkUtil.eval_cmd cmd, Event.new(*arg)
- })
- id + " %# %b %f %h %k %s %t %w %x %y %A %E %K %N %W %T %X %Y"
- end
- end
-
- def _bind(path, context, cmd, args=nil)
- begin
- id = install_bind(cmd, args)
- tk_call 'bind', path, "<#{context}>", id
- rescue
- $tk_cmdtbl[id] = nil
- fail
- end
- end
- private :install_bind, :_bind
-
- def bind_all(context, cmd=Proc.new, args=nil)
- _bind 'all', context, cmd, args
- end
-
- def pack(*args)
- TkPack.configure *args
- end
-
- $tk_cmdtbl = {}
-
- def after(ms, cmd=Proc.new)
- myid = format("c%.4d", $tk_cmdid)
- tk_call 'after', ms,
- install_cmd(proc{
- TkUtil.eval_cmd cmd
- uninstall_cmd myid
- })
- end
-
- def update(idle=nil)
- if idle
- tk_call 'update', 'idletasks'
- else
- tk_call 'update'
- end
- end
-
- def dispatch(line)
- if line =~ /^c\d+/
- cmd = $&
- fail "no command `#{cmd}'" if not $tk_cmdtbl[cmd]
- args = tk_split_list($')
- TkUtil.eval_cmd $tk_cmdtbl[cmd], *args
- elsif line =~ /^alive$/
- # keep alive, do nothing
- else
- fail "malformed line <#{line}>"
- end
- end
-
- def mainloop
- begin
- tk_write 'after idle {wm deiconify .}'
- while TRUE
- rf, wf = select(READABLE, WRITABLE)
- for f in rf
- READ_CMD[f].call(f) if READ_CMD[f]
- if f.closed?
- READABLE.delete f
- READ_CMD[f] = nil
- end
- end
- for f in wf
- WRITE_CMD[f].call(f) if WRITE_CMD[f]
- if f.closed?
- WRITABLE.delete f
- WRITE_CMD[f] = nil
- end
- end
- end
- ensure
- Tk.tk_exit
- end
- end
-
- def root
- $tk_root
- end
-
- def bell
- tk_call 'bell'
- end
- module_function :after, :update, :dispatch, :mainloop, :root, :bell
-
- module Scrollable
- def xscrollcommand(cmd=Proc.new)
- configure_cmd 'xscrollcommand', cmd
- end
- def yscrollcommand(cmd=Proc.new)
- configure_cmd 'yscrollcommand', cmd
- end
- end
-
- module Wm
- def aspect(*args)
- w = window(tk_call('wm', 'grid', path, *args))
- w.split.collect{|s|s.to_i} if args.length == 0
- end
- def client(name=None)
- tk_call 'wm', 'client', path, name
- end
- def colormapwindows(*args)
- list(tk_call('wm', 'colormapwindows', path, *args))
- end
- def wm_command(value=None)
- string(tk_call('wm', 'command', path, value))
- end
- def deiconify
- tk_call 'wm', 'deiconify', path
- end
- def focusmodel(*args)
- tk_call 'wm', 'focusmodel', path, *args
- end
- def frame
- tk_call 'wm', 'frame', path
- end
- def geometry(*args)
- list(tk_call('wm', 'geometry', path, *args))
- end
- def grid(*args)
- w = tk_call('wm', 'grid', path, *args)
- list(w) if args.size == 0
- end
- def group(*args)
- tk_call 'wm', 'path', path, *args
- end
- def iconbitmap(*args)
- tk_call 'wm', 'bitmap', path, *args
- end
- def iconify
- tk_call 'wm', 'iconify'
- end
- def iconmask(*args)
- tk_call 'wm', 'iconmask', path, *args
- end
- def iconname(*args)
- tk_call 'wm', 'iconname', path, *args
- end
- def iconposition(*args)
- w = tk_call('wm', 'iconposition', path, *args)
- list(w) if args.size == 0
- end
- def iconwindow(*args)
- tk_call 'wm', 'iconwindow', path, *args
- end
- def maxsize(*args)
- w = tk_call('wm', 'maxsize', path, *args)
- list(w) if not args.size == 0
- end
- def minsize(*args)
- w = tk_call('wm', 'minsize', path, *args)
- list(w) if args.size == 0
- end
- def overrideredirect(bool=None)
- if bool == None
- bool(tk_call('wm', 'overrideredirect', path))
- else
- tk_call 'wm', 'overrideredirect', path, bool
- end
- end
- def positionfrom(*args)
- tk_call 'wm', 'positionfrom', path, *args
- end
- def protocol(name, func=None)
- func = install_cmd(func) if not func == None
- tk_call 'wm', 'command', path, name, func
- end
- def resizable(*args)
- w = tk_call('wm', 'resizable', path, *args)
- if args.length == 0
- list(w).collect{|e| bool(e)}
- end
- end
- def sizefrom(*args)
- list(tk_call('wm', 'sizefrom', path, *args))
- end
- def state
- tk_call 'wm', 'state', path
- end
- def title(*args)
- tk_call 'wm', 'title', path, *args
- end
- def transient(*args)
- tk_call 'wm', 'transient', path, *args
- end
- def withdraw
- tk_call 'wm', 'withdraw', path
- end
- end
-end
diff --git a/lib/tkdialog.rb b/lib/tkdialog.rb
deleted file mode 100644
index e8f2142e07..0000000000
--- a/lib/tkdialog.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-require "tk"
-
-class TkDialog < TkWindow
- # initialize tk_dialog
- def initialize
- super
- @var = TkVariable.new
- id = @var.id
- INTERP._eval('eval {global '+id+';'+
- 'set '+id+' [tk_dialog '+
- @path+" "+title+" \"#{message}\" "+bitmap+" "+
- default_button+" "+buttons+']}')
- end
- def value
- return @var.value.to_i
- end
- ######################################################
- # #
- # these methods must be overridden for each dialog #
- # #
- ######################################################
- def title
- return "DIALOG"
- end
- def message
- return "MESSAGE"
- end
- def bitmap
- return "info"
- end
- def default_button
- return 0
- end
- def buttons
- return "BUTTON1 BUTTON2"
- end
-end
-
-#
-# dialog for warning
-#
-class TkWarning < TkDialog
- def initialize(mes)
- @mes = mes
- super()
- end
- def message
- return @mes
- end
- def title
- return "WARNING";
- end
- def bitmap
- return "warning";
- end
- def default_button
- return 0;
- end
- def buttons
- return "OK";
- end
-end
diff --git a/lib/tkentry.rb b/lib/tkentry.rb
deleted file mode 100644
index bcf092a15c..0000000000
--- a/lib/tkentry.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-#
-# tkentry.rb - Tk entry classes
-# $Date$
-# by Yukihiro Matsumoto <matz@caelum.co.jp>
-
-require 'tk.rb'
-
-class TkEntry<TkLabel
- def create_self
- tk_call 'entry', @path
- end
- def scrollcommand(cmd)
- configure 'scrollcommand', cmd
- end
-
- def delete(s, e=None)
- tk_send 'delete', s, e
- end
-
- def cursor
- tk_send 'index', 'insert'
- end
- def cursor=(index)
- tk_send 'icursor', index
- end
- def index(index)
- number(tk_send('index', index))
- end
- def insert(pos,text)
- tk_send 'insert', pos, text
- end
- def mark(pos)
- tk_send 'scan', 'mark', pos
- end
- def dragto(pos)
- tk_send 'scan', 'dragto', pos
- end
- def select_adjust(index)
- tk_send 'select', 'adjust', index
- end
- def select_clear
- tk_send 'select', 'clear', 'end'
- end
- def select_from(index)
- tk_send 'select', 'from', index
- end
- def select_present()
- tk_send('select', 'present') == 1
- end
- def select_range(s, e)
- tk_send 'select', 'range', s, e
- end
- def select_to(index)
- tk_send 'select', 'to', index
- end
- def xview(*index)
- tk_send 'xview', *index
- end
-
- def value
- tk_send 'get'
- end
- def value= (val)
- tk_send 'delete', 0, 'end'
- tk_send 'insert', 0, val
- end
-end
diff --git a/lib/tkscrollbox.rb b/lib/tkscrollbox.rb
deleted file mode 100644
index 8d129b2f4b..0000000000
--- a/lib/tkscrollbox.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# tkscrollbox.rb - Tk Listbox with Scrollbar
-# as an example of Composite Widget
-# $Date$
-# by Yukihiro Matsumoto <matz@caelum.co.jp>
-
-require 'tk.rb'
-
-class TkScrollbox<TkListbox
- include TkComposite
- def initialize_composite
- list = TkListbox.new(@frame)
- scroll = TkScrollbar.new(@frame)
- @path = list.path
-
- list.configure 'yscroll', scroll.path+" set"
- list.pack 'side'=>'left','fill'=>'both','expand'=>'yes'
- scroll.configure 'command', list.path+" yview"
- scroll.pack 'side'=>'right','fill'=>'y'
-
- delegate('DEFAULT', list)
- delegate('foreground', list)
- delegate('background', list, scroll)
- delegate('borderwidth', @frame)
- delegate('relief', @frame)
- end
-end
diff --git a/lib/tktext.rb b/lib/tktext.rb
deleted file mode 100644
index 47e11f2c85..0000000000
--- a/lib/tktext.rb
+++ /dev/null
@@ -1,164 +0,0 @@
-#
-# tktext.rb - Tk text classes
-# $Date$
-# by Yukihiro Matsumoto <matz@caelum.co.jp>
-
-require 'tk.rb'
-
-class TkText<TkTextWin
- include Scrollable
- def create_self
- tk_call 'text', @path
- @tags = {}
- end
- def index(index)
- tk_send 'index', index
- end
- def value
- tk_send 'get', "1.0", "end"
- end
- def value= (val)
- tk_send 'delete', "1.0", 'end'
- tk_send 'insert', "1.0", val
- end
- def _addcmd(cmd)
- @cmdtbl.push id
- end
- def _addtag(name, obj)
- @tags[name] = obj
- end
- def tag_names
- tk_send('tag', 'names').collect{|elt|
- if not @tags[elt]
- elt
- else
- @tags[elt]
- end
- }
- end
- def window_names
- tk_send('window', 'names').collect{|elt|
- if not @tags[elt]
- elt
- else
- @tags[elt]
- end
- }
- end
-
- def destroy
- for t in @tags
- t.destroy
- end
- super
- end
-
- def backspace
- self.delete 'insert'
- end
-
- def compare(idx1, op, idx2)
- bool(tk_send('compare', idx1, op, idx2))
- end
-
- def debug
- bool(tk_send('debug'))
- end
- def debug=(boolean)
- tk_send 'debug', boolean
- end
-
- def yview(*what)
- tk_send 'yview', *what
- end
- def yview_pickplace(*what)
- tk_send 'yview', '-pickplace', *what
- end
-
- def xview(*what)
- tk_send 'xview', *what
- end
- def xview_pickplace(*what)
- tk_send 'xview', '-pickplace', *what
- end
-end
-
-class TkTextTag<TkObject
- $tk_text_tag = 'tag0000'
- def initialize(parent, keys=nil)
- if not parent.kind_of?(TkText)
- fail format("%s need to be TkText", parent.inspect)
- end
- @t = parent
- @path = @id = $tk_text_tag
- $tk_text_tag = $tk_text_tag.succ
- tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
- @t._addtag id, self
- end
- def id
- return @id
- end
-
- def add(*index)
- tk_call @t.path, 'tag', 'add', @id, *index
- end
-
- def configure(keys)
- tk_call @t.path, 'tag', 'configure', @id, *hash_kv(keys)
- end
-
- def bind(seq, cmd=Proc.new)
- id = install_cmd(cmd)
- tk_call @t, 'tag', 'bind', tag, "<#{seq}>", id
- @t._addcmd cmd
- end
-
- def lower(below=None)
- tk_call @t.path, 'tag', 'lower', below
- end
-
- def destroy
- tk_call @t.path, 'tag', 'delete', @id
- end
-end
-
-class TkTextMark<TkObject
- $tk_text_mark = 'mark0000'
- def initialize(parent, index)
- if not parent.kind_of?(TkText)
- fail format("%s need to be TkText", parent.inspect)
- end
- @t = parent
- @path = @id = $tk_text_mark
- $tk_text_mark = $tk_text_mark.succ
- tk_call @t.path, 'mark', 'set', @id, index
- @t._addtag id, self
- end
- def id
- return @id
- end
-
- def set(where)
- tk_call @t.path, 'mark', 'set', @id, where
- end
-
- def unset
- tk_call @t.path, 'mark', 'unset', @id
- end
- alias destroy unset
-end
-
-class TkTextWindow<TkObject
- def initialize(parent, index, *args)
- if not parent.kind_of?(TkText)
- fail format("%s need to be TkText", parent.inspect)
- end
- @t = parent
- @path = @index = index
- tk_call @t.path, 'window', 'create', index, *args
- end
-
- def configure(slot, value)
- tk_call @t.path, 'window', 'configure', @index, "-#{slot}", value
- end
-end
diff --git a/lib/tkthcore.rb b/lib/tkthcore.rb
deleted file mode 100644
index a6648502bd..0000000000
--- a/lib/tkthcore.rb
+++ /dev/null
@@ -1,550 +0,0 @@
-#
-# tkthcore.rb - Tk interface modue using thread
-# $Date$
-# by Yukihiro Matsumoto <matz@caelum.co.jp>
-
-require "tkutil"
-require "thread"
-
-module Tk
- include TkUtil
- extend Tk
-
- def Tk.tk_exit
- if not PORT.closed?
- tk_write "exit"
- PORT.close
- end
- end
-
- trap "EXIT", proc{Tk.tk_exit}
- trap "PIPE", ''
-
- wish_path = nil
- ENV['PATH'].split(":").each {|path|
- for wish in ['wish4.2', 'wish4.1', 'wish4.0', 'wish']
- if File.exist? path+'/'+wish
- wish_path = path+'/'+wish
- break
- end
- break if wish_path
- end
- }
- fail 'can\'t find wish' if not wish_path #'
-
- # mark for non-given arguments
- None = Object.new
- def None.to_s
- 'None'
- end
-
- Qin = Queue.new
- Qout = Queue.new
- Qwish = Queue.new
- Qcmd = Queue.new
- PORT = open(format("|%s -n %s", wish_path, File.basename($0)), "w+");
-
- $tk_not_init = TRUE
-
- def Tk.init
- $tk_not_init = FALSE
- Thread.start do
- loop do
- while line = PORT.gets
- line.chop!
- if line =~ /^[=!]/
- Qwish.push line
- else
- Qcmd.push line
- end
- end
- exit
- end
- end
-
- Thread.start do
- ary = [PORT]
- loop do
- str = Qin.pop
- print "Qin: ", str, "\n" if $DEBUG
- tk_write 'if [catch {%s} var] {puts "!$var"} {puts "=$var@@"};flush stdout', str
- line = tk_recv
- Qout.push(line)
- end
- end
- end
-
- $tk_event_queue = []
- def tk_recv()
- val = nil
- $_ = Qwish.pop
- loop do
- if /^=(.*)@@$/
- val = $1
- break
- elsif /^=/
- val = $' + "\n"
- while TRUE
- PORT.readline
- if ~/@@$/
- val += $'
- return val
- else
- val += $_
- end
- end
- elsif /^!/
- $@ = error_at
- msg = $'
- if msg =~ /unknown option "-(.*)"/
- fail NameError, format("undefined method `%s' for %s(%s)", $1, self, self.type) #`'
- else
- fail format("%s - %s", self.type, msg)
- end
- end
- end
-
- fail 'wish closed' if PORT.closed?
-# tk_split_list(val)
- val
- end
-
- def tk_call(str, *args)
- Tk.init if $tk_not_init
- args = args.collect{|s|
- next if s == None
- if s.kind_of?(Hash)
- s = hash_kv(s).join(" ")
- else
- if not s
- s = "0"
- elsif s == TRUE
- s = "1"
- elsif s.kind_of?(TkObject)
- s = s.path
- elsif s.kind_of?(TkVariable)
- s = s.id
- else
- s = s.to_s
- s.gsub!(/["\\\$\[\]]/, '\\\\\0') #"
- s.gsub!(/\{/, '\\\\173')
- s.gsub!(/\}/, '\\\\175')
- end
- "\"#{s}\""
- end
- }
- str += " "
- str += args.join(" ")
- Qin.push str
- return Qout.pop
- end
-
- def tk_write(*args)
- PORT.printf *args; PORT.print "\n"
- PORT.flush
- end
- module_function :tk_write, :tk_recv
- tk_write '\
-wm withdraw .
-proc rb_out args {
- puts [format %%s $args]
- flush stdout
-}
-proc tkerror args { exit }
-proc keepalive {} { rb_out alive; after 120000 keepalive}
-after 120000 keepalive'
-
- READ_TH = {}
- def file_readable(port, cmd)
- if cmd == nil
- if READ_TH[port].has_key?
- READ_TH[port].exit
- READ_TH[port] = nil
- end
- else
- READ_TH[port] = Thread.start{
- loop do
- TkUtil.eval_cmd cmd
- end
- }
- end
- end
-
- WRITE_TH = {}
- def file_writable(port, cmd)
- if cmd == nil
- if WRITE_TH[port].has_key?
- WRITE_TH[port].exit
- end
- else
- WRITE_TH[port] = Thread.start{
- loop do
- TkUtil.eval_cmd cmd
- end
- }
- end
- end
- module_function :file_readable, :file_writable
-
- def tk_tcl2ruby(val)
- case val
- when /^-?\d+$/
- val.to_i
- when /^\./
- $tk_window_list[val]
- when /^rb_out (c\d+)/
- $tk_cmdtbl[$1]
- when / /
- val.split.collect{|elt|
- tk_tcl2ruby(elt)
- }
- when /^-?\d+\.\d*$/
- val.to_f
- else
- val
- end
- end
-
- def tk_split_list(str)
- idx = str.index('{')
- return tk_tcl2ruby(str) if not idx
-
- list = tk_tcl2ruby(str[0,idx])
- str = str[idx+1..-1]
- i = -1
- brace = 1
- str.each_byte {|c|
- i += 1
- brace += 1 if c == ?{
- brace -= 1 if c == ?}
- break if brace == 0
- }
- 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
- private :tk_tcl2ruby, :tk_split_list
-
- def dispatch(line)
- if line =~ /^c\d+/
- cmd = $&
- fail "no command `#{cmd}'" if not $tk_cmdtbl[cmd]
- args = tk_split_list($')
- TkUtil.eval_cmd $tk_cmdtbl[cmd], *args
- elsif line =~ /^alive$/
- # keep alive, do nothing
- else
- fail "malformed line <#{line}>"
- end
- end
- module_function :dispatch
-
- def error_at
- frames = caller(1)
- frames.delete_if do |c|
- c =~ %r!/tk(|core|thcore|canvas|text|entry|scrollbox)\.rb:\d+!
- end
- frames
- end
-
- def bool(val)
- case bool
- when "1", 1, 'yes', 'true'
- TRUE
- else
- FALSE
- end
- end
- def number(val)
- case val
- when /^-?\d+$/
- val.to_i
- when /^-?\d+\.\d*$/
- val.to_f
- else
- val
- end
- end
- def string(val)
- if val == "{}"
- ''
- elsif val[0] == ?{
- val[1..-2]
- else
- val
- end
- end
- def list(val)
- tk_split_list(val)
- end
- def window(val)
- $tk_window_list[val]
- end
- def procedure(val)
- if val =~ /^rb_out (c\d+)/
- $tk_cmdtbl[$1]
- else
- nil
- end
- end
- private :bool, :number, :string, :list, :window, :procedure
-
- def hash_kv(keys)
- conf = []
- if keys
- for k, v in keys
- conf.push("-#{k}")
- v = install_cmd(v) if v.kind_of? Proc
- conf.push(v)
- end
- end
- conf
- end
- private :tk_call, :error_at, :hash_kv
-
- $tk_cmdid = 0
- def install_cmd(cmd)
- return '' if cmd == '' # uninstall cmd
- id = format("c%.4d", $tk_cmdid)
- $tk_cmdid += 1
- $tk_cmdtbl[id] = cmd
- @cmdtbl = [] if not @cmdtbl
- @cmdtbl.push id
- return format('rb_out %s', id)
- end
- def uninstall_cmd(id)
- $tk_cmdtbl[id] = nil
- end
- private :install_cmd, :uninstall_cmd
-
- $tk_window_list = {}
- class Event
- def initialize(seq,b,f,h,k,s,t,w,x,y,aa,ee,kk,nn,ww,tt,xx,yy)
- @serial = seq
- @num = b
- @focus = (f == 1)
- @height = h
- @keycode = k
- @state = s
- @time = t
- @width = w
- @x = x
- @y = y
- @char = aa
- @send_event = (ee == 1)
- @keysym = kk
- @keysym_num = nn
- @type = tt
- @widget = ww
- @x_root = xx
- @y_root = yy
- end
- attr :serial
- attr :num
- attr :focus
- attr :height
- attr :keycode
- attr :state
- attr :time
- attr :width
- attr :x
- attr :y
- attr :char
- attr :send_event
- attr :keysym
- attr :keysym_num
- attr :type
- attr :widget
- attr :x_root
- attr :y_root
- end
-
- def install_bind(cmd, args=nil)
- if args
- id = install_cmd(proc{|arg|
- TkUtil.eval_cmd cmd, *arg
- })
- id + " " + args
- else
- id = install_cmd(proc{|arg|
- TkUtil.eval_cmd cmd, Event.new(*arg)
- })
- id + " %# %b %f %h %k %s %t %w %x %y %A %E %K %N %W %T %X %Y"
- end
- end
-
- def _bind(path, context, cmd, args=nil)
- begin
- id = install_bind(cmd, args)
- tk_call 'bind', path, "<#{context}>", id
- rescue
- $tk_cmdtbl[id] = nil
- fail
- end
- end
- private :install_bind, :_bind
-
- def bind_all(context, cmd=Proc.new, args=nil)
- _bind 'all', context, cmd, args
- end
-
- def pack(*args)
- TkPack.configure *args
- end
-
- $tk_cmdtbl = {}
-
- Qafter = Queue.new
- def after(ms, cmd=Proc.new)
- unless $tk_after_thread
- $tk_after_thread = Thread.start{
- loop do
- cmd = Qafter.pop
- TkUtil.eval_cmd cmd
- end
- }
- end
- Thread.start do
- sleep Float(ms)/1000
- Qafter.push cmd
- end
- end
-
- def update(idle=nil)
- if idle
- tk_call 'update', 'idletasks'
- else
- tk_call 'update'
- end
- end
-
- def root
- $tk_root
- end
-
- def bell
- tk_call 'bell'
- end
-
- def mainloop
- begin
- tk_call 'after', 'idle', 'wm deiconify .'
- loop do
- dispatch Qcmd.pop
- end
- ensure
- Tk.tk_exit
- end
- end
- module_function :after, :update, :dispatch, :mainloop, :root, :bell
-
- module Scrollable
- def xscrollcommand(cmd=Proc.new)
- configure_cmd 'xscrollcommand', cmd
- end
- def yscrollcommand(cmd=Proc.new)
- configure_cmd 'yscrollcommand', cmd
- end
- end
-
- module Wm
- def aspect(*args)
- w = window(tk_call('wm', 'grid', path, *args))
- w.split.collect{|s|s.to_i} if args.length == 0
- end
- def client(name=None)
- tk_call 'wm', 'client', path, name
- end
- def colormapwindows(*args)
- list(tk_call('wm', 'colormapwindows', path, *args))
- end
- def wm_command(value=None)
- string(tk_call('wm', 'command', path, value))
- end
- def deiconify
- tk_call 'wm', 'deiconify', path
- end
- def focusmodel(*args)
- tk_call 'wm', 'focusmodel', path, *args
- end
- def frame
- tk_call 'wm', 'frame', path
- end
- def geometry(*args)
- list(tk_call('wm', 'geometry', path, *args))
- end
- def grid(*args)
- w = tk_call('wm', 'grid', path, *args)
- list(w) if args.size == 0
- end
- def group(*args)
- tk_call 'wm', 'path', path, *args
- end
- def iconbitmap(*args)
- tk_call 'wm', 'bitmap', path, *args
- end
- def iconify
- tk_call 'wm', 'iconify'
- end
- def iconmask(*args)
- tk_call 'wm', 'iconmask', path, *args
- end
- def iconname(*args)
- tk_call 'wm', 'iconname', path, *args
- end
- def iconposition(*args)
- w = tk_call('wm', 'iconposition', path, *args)
- list(w) if args.size == 0
- end
- def iconwindow(*args)
- tk_call 'wm', 'iconwindow', path, *args
- end
- def maxsize(*args)
- w = tk_call('wm', 'maxsize', path, *args)
- list(w) if not args.size == 0
- end
- def minsize(*args)
- w = tk_call('wm', 'minsize', path, *args)
- list(w) if args.size == 0
- end
- def overrideredirect(bool=None)
- if bool == None
- bool(tk_call('wm', 'overrideredirect', path))
- else
- tk_call 'wm', 'overrideredirect', path, bool
- end
- end
- def positionfrom(*args)
- tk_call 'wm', 'positionfrom', path, *args
- end
- def protocol(name, func=None)
- func = install_cmd(func) if not func == None
- tk_call 'wm', 'command', path, name, func
- end
- def resizable(*args)
- w = tk_call('wm', 'resizable', path, *args)
- if args.length == 0
- list(w).collect{|e| bool(e)}
- end
- end
- def sizefrom(*args)
- list(tk_call('wm', 'sizefrom', path, *args))
- end
- def state
- tk_call 'wm', 'state', path
- end
- def title(*args)
- tk_call 'wm', 'title', path, *args
- end
- def transient(*args)
- tk_call 'wm', 'transient', path, *args
- end
- def withdraw
- tk_call 'wm', 'withdraw', path
- end
- end
-end
diff --git a/missing/nt.c b/missing/nt.c
deleted file mode 100644
index 703556cad7..0000000000
--- a/missing/nt.c
+++ /dev/null
@@ -1,2194 +0,0 @@
-/*
- * Copyright (c) 1993, Intergraph Corporation
- *
- * You may distribute under the terms of either the GNU General Public
- * License or the Artistic License, as specified in the perl README file.
- *
- * Various Unix compatibility functions and NT specific functions.
- *
- * Some of this code was derived from the MSDOS port(s) and the OS/2 port.
- *
- */
-
-#include "ruby.h"
-#include <fcntl.h>
-#include <process.h>
-#include <sys/stat.h>
-/* #include <sys/wait.h> */
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <assert.h>
-
-#include <windows.h>
-#include <winbase.h>
-#include <wincon.h>
-#include "nt.h"
-#include "dir.h"
-#ifndef index
-#define index(x, y) strchr((x), (y))
-#endif
-
-#ifndef bool
-#define bool int
-#endif
-
-bool NtSyncProcess = TRUE;
-#if 0 // declared in header file
-extern char **environ;
-#define environ _environ
-#endif
-
-static bool NtHasRedirection (char *);
-static int valid_filename(char *s);
-static void StartSockets ();
-static char *str_grow(struct RString *str, size_t new_size);
-
-char *NTLoginName;
-
-DWORD Win32System = (DWORD)-1;
-
-static DWORD
-IdOS(void)
-{
- static OSVERSIONINFO osver;
-
- if (osver.dwPlatformId != Win32System) {
- memset(&osver, 0, sizeof(OSVERSIONINFO));
- osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx(&osver);
- Win32System = osver.dwPlatformId;
- }
- return (Win32System);
-}
-
-static int
-IsWin95(void) {
- return (IdOS() == VER_PLATFORM_WIN32_WINDOWS);
-}
-
-static int
-IsWinNT(void) {
- return (IdOS() == VER_PLATFORM_WIN32_NT);
-}
-
-
-/* simulate flock by locking a range on the file */
-
-
-#define LK_ERR(f,i) ((f) ? (i = 0) : (errno = GetLastError()))
-#define LK_LEN 0xffff0000
-
-int
-flock(int fd, int oper)
-{
- OVERLAPPED o;
- int i = -1;
- HANDLE fh;
-
- fh = (HANDLE)_get_osfhandle(fd);
- memset(&o, 0, sizeof(o));
-
- if(IsWinNT()) {
- switch(oper) {
- case LOCK_SH: /* shared lock */
- LK_ERR(LockFileEx(fh, 0, 0, LK_LEN, 0, &o),i);
- break;
- case LOCK_EX: /* exclusive lock */
- LK_ERR(LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, LK_LEN, 0, &o),i);
- break;
- case LOCK_SH|LOCK_NB: /* non-blocking shared lock */
- LK_ERR(LockFileEx(fh, LOCKFILE_FAIL_IMMEDIATELY, 0, LK_LEN, 0, &o),i);
- break;
- case LOCK_EX|LOCK_NB: /* non-blocking exclusive lock */
- LK_ERR(LockFileEx(fh,
- LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
- 0, LK_LEN, 0, &o),i);
- if(errno == EDOM) errno = EWOULDBLOCK;
- break;
- case LOCK_UN: /* unlock lock */
- if (UnlockFileEx(fh, 0, LK_LEN, 0, &o)) {
- i = 0;
- }
- else {
- /* GetLastError() must returns `ERROR_NOT_LOCKED' */
- errno = EWOULDBLOCK;
- }
- if(errno == EDOM) errno = EWOULDBLOCK;
- break;
- default: /* unknown */
- errno = EINVAL;
- break;
- }
- }
- else if(IsWin95()) {
- switch(oper) {
- case LOCK_EX:
- while(i == -1) {
- LK_ERR(LockFile(fh, 0, 0, LK_LEN, 0), i);
- if(errno != EDOM && i == -1) break;
- }
- break;
- case LOCK_EX | LOCK_NB:
- LK_ERR(LockFile(fh, 0, 0, LK_LEN, 0), i);
- if(errno == EDOM) errno = EWOULDBLOCK;
- break;
- case LOCK_UN:
- LK_ERR(UnlockFile(fh, 0, 0, LK_LEN, 0), i);
- if(errno == EDOM) errno = EWOULDBLOCK;
- break;
- default:
- errno = EINVAL;
- break;
- }
- }
- return i;
-}
-
-#undef LK_ERR
-#undef LK_LEN
-
-
-//#undef const
-//FILE *fdopen(int, const char *);
-
-#if 0
-void
-sleep(unsigned int len)
-{
- time_t end;
-
- end = time((time_t *)0) + len;
- while (time((time_t *)0) < end)
- ;
-}
-#endif
-
-//
-// Initialization stuff
-//
-void
-NtInitialize(int *argc, char ***argv) {
-
- WORD version;
- int ret;
-
- //
- // subvert cmd.exe\'s feeble attempt at command line parsing
- //
- *argc = NtMakeCmdVector((char *)GetCommandLine(), argv, TRUE);
-
- //
- // Now set up the correct time stuff
- //
-
- tzset();
-
- // Initialize Winsock
- StartSockets();
-}
-
-
-char *getlogin()
-{
- char buffer[200];
- int len = 200;
- extern char *NTLoginName;
-
- if (NTLoginName == NULL) {
- if (GetUserName(buffer, &len)) {
- NTLoginName = ALLOC_N(char, len+1);
- strncpy(NTLoginName, buffer, len);
- NTLoginName[len] = '\0';
- }
- else {
- NTLoginName = "<Unknown>";
- }
- }
- return NTLoginName;
-}
-
-
-
-#if 1
-// popen stuff
-
-//
-// use these so I can remember which index is which
-//
-
-#define NtPipeRead 0 // index of pipe read descriptor
-#define NtPipeWrite 1 // index of pipe write descriptor
-
-#define NtPipeSize 1024 // size of pipe buffer
-
-#define MYPOPENSIZE 256 // size of book keeping structure
-
-struct {
- int inuse;
- int pid;
- HANDLE oshandle;
- FILE *pipe;
-} MyPopenRecord[MYPOPENSIZE];
-
-int SafeFree(char **vec, int vecc)
-{
- // vec
- // |
- // V ^---------------------V
- // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
- // | | | .... | NULL | | ..... |\0 | | ..... |\0 |...
- // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
- // |- elements+1 -| ^ 1st element ^ 2nd element
-
- char *p;
-
- p = (char *)(vec - (vecc * sizeof (char *) + 1));
- free(p);
-
- return 0;
-}
-
-
-static char *szInternalCmds[] = {
- "cd",
- "chdir",
- "cls",
- "copy",
- "date",
- "del",
- "dir",
- "echo",
- "erase",
- "label",
- "md",
- "mkdir",
- "path",
- "rd",
- "rem",
- "ren",
- "rename",
- "rmdir",
- "set",
- "start",
- "time",
- "type",
- "ver",
- "vol",
-};
-
-int
-isInternalCmd(char *cmd)
-{
- int fRet;
- char **vec;
- int vecc = NtMakeCmdVector(cmd, &vec, FALSE);
-
- SafeFree (vec, vecc);
-
- return 0;
-}
-
-
-FILE *
-mypopen (char *cmd, char *mode)
-{
- FILE *fp;
- int saved, reading;
- int pipemode;
- int pipes[2];
- int pid;
- int slot;
- static initialized = 0;
-
- //
- // if first time through, intialize our book keeping structure
- //
-
- if (!initialized++) {
- for (slot = 0; slot < MYPOPENSIZE; slot++)
- MyPopenRecord[slot].inuse = FALSE;
- }
-
- //printf("mypopen %s\n", cmd);
-
- //
- // find a free popen slot
- //
-
- for (slot = 0; slot < MYPOPENSIZE && MyPopenRecord[slot].inuse; slot++)
- ;
-
- if (slot > MYPOPENSIZE) {
- return NULL;
- }
-
- //
- // Figure out what we\'re doing...
- //
-
- reading = (*mode == 'r') ? TRUE : FALSE;
- pipemode = (*(mode+1) == 'b') ? O_BINARY : O_TEXT;
-
- //
- // Now get a pipe
- //
-
-#if 0
- if (_pipe(pipes, NtPipeSize, pipemode) == -1) {
- return NULL;
- }
-
- if (reading) {
-
- //
- // we\'re reading from the pipe, so we must hook up the
- // write end of the pipe to the new processes stdout.
- // To do this we must save our file handle from stdout
- // by _dup\'ing it, then setting our stdout to be the pipe\'s
- // write descriptor. We must also make the write handle
- // inheritable so the new process can use it.
-
- if ((saved = _dup(fileno(stdout))) == -1) {
- _close(pipes[NtPipeRead]);
- _close(pipes[NtPipeWrite]);
- return NULL;
- }
- if (_dup2 (pipes[NtPipeWrite], fileno(stdout)) == -1) {
- _close(pipes[NtPipeRead]);
- _close(pipes[NtPipeWrite]);
- return NULL;
- }
- }
- else {
- //
- // must be writing to the new process. Do the opposite of
- // the above, i.e. hook up the processes stdin to the read
- // end of the pipe.
- //
-
- if ((saved = _dup(fileno(stdin))) == -1) {
- _close(pipes[NtPipeRead]);
- _close(pipes[NtPipeWrite]);
- return NULL;
- }
- if (_dup2(pipes[NtPipeRead], fileno(stdin)) == -1) {
- _close(pipes[NtPipeRead]);
- _close(pipes[NtPipeWrite]);
- return NULL;
- }
- }
-
- //
- // Start the new process. Must set _fileinfo to non-zero value
- // for file descriptors to be inherited. Reset after the process
- // is started.
- //
-
- if (NtHasRedirection(cmd)) {
- docmd:
- pid = spawnlpe(_P_NOWAIT, "cmd.exe", "/c", cmd, 0, environ);
- if (pid == -1) {
- _close(pipes[NtPipeRead]);
- _close(pipes[NtPipeWrite]);
- return NULL;
- }
- }
- else {
- char **vec;
- int vecc = NtMakeCmdVector(cmd, &vec, FALSE);
-
- //pid = spawnvpe (_P_NOWAIT, vec[0], vec, environ);
- pid = spawnvpe (_P_WAIT, vec[0], vec, environ);
- if (pid == -1) {
- goto docmd;
- }
- Safefree (vec, vecc);
- }
-
- if (reading) {
-
- //
- // We need to close our instance of the inherited pipe write
- // handle now that it's been inherited so that it will actually close
- // when the child process ends.
- //
-
- if (_close(pipes[NtPipeWrite]) == -1) {
- _close(pipes[NtPipeRead]);
- return NULL;
- }
- if (_dup2 (saved, fileno(stdout)) == -1) {
- _close(pipes[NtPipeRead]);
- return NULL;
- }
- _close(saved);
-
- //
- // Now get a stream pointer to return to the calling program.
- //
-
- if ((fp = (FILE *) fdopen(pipes[NtPipeRead], mode)) == NULL) {
- return NULL;
- }
- }
- else {
-
- //
- // need to close our read end of the pipe so that it will go
- // away when the write end is closed.
- //
-
- if (_close(pipes[NtPipeRead]) == -1) {
- _close(pipes[NtPipeWrite]);
- return NULL;
- }
- if (_dup2 (saved, fileno(stdin)) == -1) {
- _close(pipes[NtPipeWrite]);
- return NULL;
- }
- _close(saved);
-
- //
- // Now get a stream pointer to return to the calling program.
- //
-
- if ((fp = (FILE *) fdopen(pipes[NtPipeWrite], mode)) == NULL) {
- _close(pipes[NtPipeWrite]);
- return NULL;
- }
- }
-
- //
- // do the book keeping
- //
-
- MyPopenRecord[slot].inuse = TRUE;
- MyPopenRecord[slot].pipe = fp;
- MyPopenRecord[slot].pid = pid;
-
- return fp;
-#else
- {
- int p[2];
-
- BOOL fRet;
- HANDLE hInFile, hOutFile, hStdin, hStdout;
- LPCSTR lpApplicationName = NULL;
- LPTSTR lpCommandLine;
- LPTSTR lpCmd2 = NULL;
- DWORD dwCreationFlags;
- STARTUPINFO aStartupInfo;
- PROCESS_INFORMATION aProcessInformation;
- SECURITY_ATTRIBUTES sa;
- int fd;
-
- sa.nLength = sizeof (SECURITY_ATTRIBUTES);
- sa.lpSecurityDescriptor = NULL;
- sa.bInheritHandle = TRUE;
-
- if (!reading) {
- FILE *fp;
-
- fp = (_popen)(cmd, mode);
-
- MyPopenRecord[slot].inuse = TRUE;
- MyPopenRecord[slot].pipe = fp;
- MyPopenRecord[slot].pid = -1;
-
- if (!fp)
- Fatal("cannot open pipe \"%s\" (%s)", cmd, strerror(errno));
- return fp;
- }
-
- fRet = CreatePipe(&hInFile, &hOutFile, &sa, 2048L);
- if (!fRet)
- Fatal("cannot open pipe \"%s\" (%s)", cmd, strerror(errno));
-
- memset(&aStartupInfo, 0, sizeof (STARTUPINFO));
- memset(&aProcessInformation, 0, sizeof (PROCESS_INFORMATION));
- aStartupInfo.cb = sizeof (STARTUPINFO);
- aStartupInfo.dwFlags = STARTF_USESTDHANDLES;
-
- if (reading) {
- aStartupInfo.hStdInput = GetStdHandle(STD_OUTPUT_HANDLE);//hStdin;
- aStartupInfo.hStdError = INVALID_HANDLE_VALUE;
- //for save
- DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE),
- GetCurrentProcess(), &hStdout,
- 0, FALSE, DUPLICATE_SAME_ACCESS
- );
- //for redirect
- DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_INPUT_HANDLE),
- GetCurrentProcess(), &hStdin,
- 0, TRUE, DUPLICATE_SAME_ACCESS
- );
- aStartupInfo.hStdOutput = hOutFile;
- }
- else {
- aStartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); //hStdout;
- aStartupInfo.hStdError = INVALID_HANDLE_VALUE;
- // for save
- DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_INPUT_HANDLE),
- GetCurrentProcess(), &hStdin,
- 0, FALSE, DUPLICATE_SAME_ACCESS
- );
- //for redirect
- DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE),
- GetCurrentProcess(), &hStdout,
- 0, TRUE, DUPLICATE_SAME_ACCESS
- );
- aStartupInfo.hStdInput = hInFile;
- }
-
- dwCreationFlags = (NORMAL_PRIORITY_CLASS);
-
- lpCommandLine = cmd;
- if (NtHasRedirection(cmd) || isInternalCmd(cmd)) {
- lpApplicationName = getenv("COMSPEC");
- lpCmd2 = malloc(strlen(lpApplicationName) + 1 + strlen(cmd) + sizeof (" /c "));
- if (lpCmd2 == NULL)
- Fatal("Mypopen: malloc failed");
- sprintf(lpCmd2, "%s %s%s", lpApplicationName, " /c ", cmd);
- lpCommandLine = lpCmd2;
- }
-
- fRet = CreateProcess(lpApplicationName, lpCommandLine, &sa, &sa,
- sa.bInheritHandle, dwCreationFlags, NULL, NULL, &aStartupInfo, &aProcessInformation);
-
- if (!fRet) {
- CloseHandle(hInFile);
- CloseHandle(hOutFile);
- Fatal("cannot fork for \"%s\" (%s)", cmd, strerror(errno));
- }
-
- CloseHandle(aProcessInformation.hThread);
-
- if (reading) {
- HANDLE hDummy;
-
- fd = _open_osfhandle((long)hInFile, (_O_RDONLY | pipemode));
- CloseHandle(hOutFile);
- DuplicateHandle(GetCurrentProcess(), hStdout,
- GetCurrentProcess(), &hDummy,
- 0, TRUE, (DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)
- );
- }
- else {
- HANDLE hDummy;
-
- fd = _open_osfhandle((long)hOutFile, (_O_WRONLY | pipemode));
- CloseHandle(hInFile);
- DuplicateHandle(GetCurrentProcess(), hStdin,
- GetCurrentProcess(), &hDummy,
- 0, TRUE, (DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)
- );
- }
-
- if (fd == -1)
- Fatal("cannot open pipe \"%s\" (%s)", cmd, strerror(errno));
-
-
- if ((fp = (FILE *) fdopen(fd, mode)) == NULL)
- return NULL;
-
- if (lpCmd2)
- free(lpCmd2);
-
- MyPopenRecord[slot].inuse = TRUE;
- MyPopenRecord[slot].pipe = fp;
- MyPopenRecord[slot].oshandle = (reading ? hInFile : hOutFile);
- MyPopenRecord[slot].pid = (int)aProcessInformation.hProcess;
- return fp;
- }
-#endif
-}
-
-int
-mypclose(FILE *fp)
-{
- int i;
- int exitcode;
-
- Sleep(100);
- for (i = 0; i < MYPOPENSIZE; i++) {
- if (MyPopenRecord[i].inuse && MyPopenRecord[i].pipe == fp)
- break;
- }
- if (i >= MYPOPENSIZE) {
- Fatal("Invalid file pointer passed to mypclose!\n");
- }
-
- //
- // get the return status of the process
- //
-
-#if 0
- if (_cwait(&exitcode, MyPopenRecord[i].pid, WAIT_CHILD) == -1) {
- if (errno == ECHILD) {
- fprintf(stderr, "mypclose: nosuch child as pid %x\n",
- MyPopenRecord[i].pid);
- }
- }
-#else
- for (;;) {
- if (GetExitCodeProcess((HANDLE)MyPopenRecord[i].pid, &exitcode)) {
- if (exitcode == STILL_ACTIVE) {
- //printf("Process is Active.\n");
- Sleep(100);
- TerminateProcess((HANDLE)MyPopenRecord[i].pid, 0); // ugly...
- continue;
- }
- else if (exitcode == 0) {
- //printf("done.\n");
- break;
- }
- else {
- //printf("never.\n");
- break;
- }
- }
- }
-#endif
-
-
- //
- // close the pipe
- //
- CloseHandle(MyPopenRecord[i].oshandle);
- fflush(fp);
- fclose(fp);
-
- //
- // free this slot
- //
-
- MyPopenRecord[i].inuse = FALSE;
- MyPopenRecord[i].pipe = NULL;
- MyPopenRecord[i].pid = 0;
-
- return exitcode;
-}
-#endif
-
-#if 1
-
-
-typedef char* CHARP;
-/*
- * The following code is based on the do_exec and do_aexec functions
- * in file doio.c
- */
-
-int
-do_spawn(cmd)
-char *cmd;
-{
- register char **a;
- register char *s;
- char **argv;
- int status;
- char *shell, *cmd2;
- int mode = NtSyncProcess ? P_WAIT : P_NOWAIT;
-
- /* save an extra exec if possible */
- if ((shell = getenv("RUBYSHELL")) != 0) {
- if (NtHasRedirection(cmd)) {
- int i;
- char *p;
- char *argv[4];
- char *cmdline = ALLOC_N(char, (strlen(cmd) * 2 + 1));
-
- p=cmdline;
- *p++ = '"';
- for (s=cmd; *s;) {
- if (*s == '"')
- *p++ = '\\'; /* Escape d-quote */
- *p++ = *s++;
- }
- *p++ = '"';
- *p = '\0';
-
- /* fprintf(stderr, "do_spawn: %s %s\n", shell, cmdline); */
- argv[0] = shell;
- argv[1] = "-c";
- argv[2] = cmdline;
- argv[4] = NULL;
- status = spawnvpe(mode, argv[0], argv, environ);
- /* return spawnle(mode, shell, shell, "-c", cmd, (char*)0, environ); */
- free(cmdline);
- return status;
- }
- }
- else if ((shell = getenv("COMSPEC")) != 0) {
- if (NtHasRedirection(cmd) /* || isInternalCmd(cmd) */) {
- do_comspec_shell:
- return spawnle(mode, shell, shell, "/c", cmd, (char*)0, environ);
- }
- }
-
- argv = ALLOC_N(CHARP, (strlen(cmd) / 2 + 2));
- cmd2 = ALLOC_N(char, (strlen(cmd) + 1));
- strcpy(cmd2, cmd);
- a = argv;
- for (s = cmd2; *s;) {
- while (*s && isspace(*s)) s++;
- if (*s)
- *(a++) = s;
- while (*s && !isspace(*s)) s++;
- if (*s)
- *s++ = '\0';
- }
- *a = NULL;
- if (argv[0]) {
- if ((status = spawnvpe(mode, argv[0], argv, environ)) == -1) {
- free(argv);
- free(cmd2);
- return -1;
- }
- }
- free(cmd2);
- free(argv);
- return status;
-}
-
-#endif
-
-typedef struct _NtCmdLineElement {
- struct _NtCmdLineElement *next, *prev;
- char *str;
- int len;
- int flags;
-} NtCmdLineElement;
-
-//
-// Possible values for flags
-//
-
-#define NTGLOB 0x1 // element contains a wildcard
-#define NTMALLOC 0x2 // string in element was malloc'ed
-#define NTSTRING 0x4 // element contains a quoted string
-
-NtCmdLineElement *NtCmdHead = NULL, *NtCmdTail = NULL;
-
-void
-NtFreeCmdLine(void)
-{
- NtCmdLineElement *ptr;
-
- while(NtCmdHead) {
- ptr = NtCmdHead;
- NtCmdHead = NtCmdHead->next;
- free(ptr);
- }
- NtCmdHead = NtCmdTail = NULL;
-}
-
-//
-// This function expands wild card characters that were spotted
-// during the parse phase. The idea here is to call FindFirstFile and
-// FindNextFile with the wildcard pattern specified, and splice in the
-// resulting list of new names. If the wildcard pattern doesn\'t match
-// any existing files, just leave it in the list.
-//
-
-void
-NtCmdGlob (NtCmdLineElement *patt)
-{
- WIN32_FIND_DATA fd;
- HANDLE fh;
- char buffer[512];
- NtCmdLineElement *tmphead, *tmptail, *tmpcurr;
-
- strncpy(buffer, patt->str, patt->len);
- buffer[patt->len] = '\0';
- if ((fh = FindFirstFile (buffer, &fd)) == INVALID_HANDLE_VALUE) {
- return;
- }
- tmphead = tmptail = NULL;
- do {
- tmpcurr = ALLOC(NtCmdLineElement);
- if (tmpcurr == NULL) {
- fprintf(stderr, "Out of Memory in globbing!\n");
- while (tmphead) {
- tmpcurr = tmphead;
- tmphead = tmphead->next;
- free(tmpcurr->str);
- free(tmpcurr);
- }
- return;
- }
- memset (tmpcurr, 0, sizeof(*tmpcurr));
- tmpcurr->len = strlen(fd.cFileName);
- tmpcurr->str = ALLOC_N(char, tmpcurr->len+1);
- if (tmpcurr->str == NULL) {
- fprintf(stderr, "Out of Memory in globbing!\n");
- while (tmphead) {
- tmpcurr = tmphead;
- tmphead = tmphead->next;
- free(tmpcurr->str);
- free(tmpcurr);
- }
- return;
- }
- strcpy(tmpcurr->str, fd.cFileName);
- tmpcurr->flags |= NTMALLOC;
- if (tmptail) {
- tmptail->next = tmpcurr;
- tmpcurr->prev = tmptail;
- tmptail = tmpcurr;
- }
- else {
- tmptail = tmphead = tmpcurr;
- }
- } while(FindNextFile(fh, &fd));
-
- //
- // ok, now we\'ve got a list of files that matched the wildcard
- // specification. Put it in place of the pattern structure.
- //
-
- tmphead->prev = patt->prev;
- tmptail->next = patt->next;
-
- if (tmphead->prev)
- tmphead->prev->next = tmphead;
-
- if (tmptail->next)
- tmptail->next->prev = tmptail;
-
- //
- // Now get rid of the pattern structure
- //
-
- if (patt->flags & NTMALLOC)
- free(patt->str);
- // free(patt); //TODO: memory leak occures here. we have to fix it.
-}
-
-//
-// Check a command string to determine if it has I/O redirection
-// characters that require it to be executed by a command interpreter
-//
-
-static bool
-NtHasRedirection (char *cmd)
-{
- int inquote = 0;
- char quote = '\0';
- char *ptr ;
-
- //
- // Scan the string, looking for redirection (< or >) or pipe
- // characters (|) that are not in a quoted string
- //
-
- for (ptr = cmd; *ptr; ptr++) {
-
- switch (*ptr) {
-
- case '\'':
- case '\"':
- if (inquote) {
- if (quote == *ptr) {
- inquote = 0;
- quote = '\0';
- }
- }
- else {
- quote = *ptr;
- inquote++;
- }
- break;
-
- case '>':
- case '<':
-
- if (!inquote)
- return TRUE;
- }
- }
- return FALSE;
-}
-
-
-int
-NtMakeCmdVector (char *cmdline, char ***vec, int InputCmd)
-{
- int cmdlen = strlen(cmdline);
- int done, instring, globbing, quoted, len;
- int newline, need_free = 0, i;
- int elements, strsz;
- int slashes = 0;
- char *ptr, *base, *buffer;
- char **vptr;
- char quote;
- NtCmdLineElement *curr;
-
- //
- // just return if we don\'t have a command line
- //
-
- if (cmdlen == 0) {
- *vec = NULL;
- return 0;
- }
-
- //
- // strip trailing white space
- //
-
- ptr = cmdline+(cmdlen - 1);
- while(ptr >= cmdline && isspace(*ptr))
- --ptr;
- *++ptr = '\0';
-
- //
- // check for newlines and formfeeds. If we find any, make a new
- // command string that replaces them with escaped sequences (\n or \f)
- //
-
- for (ptr = cmdline, newline = 0; *ptr; ptr++) {
- if (*ptr == '\n' || *ptr == '\f')
- newline++;
- }
-
- if (newline) {
- base = ALLOC_N(char, strlen(cmdline) + 1 + newline + slashes);
- if (base == NULL) {
- fprintf(stderr, "malloc failed!\n");
- return 0;
- }
- for (i = 0, ptr = base; (unsigned) i < strlen(cmdline); i++) {
- switch (cmdline[i]) {
- case '\n':
- *ptr++ = '\\';
- *ptr++ = 'n';
- break;
- default:
- *ptr++ = cmdline[i];
- }
- }
- *ptr = '\0';
- cmdline = base;
- need_free++;
- }
-
- //
- // Ok, parse the command line, building a list of CmdLineElements.
- // When we\'ve finished, and it\'s an input command (meaning that it\'s
- // the processes argv), we\'ll do globing and then build the argument
- // vector.
- // The outer loop does one interation for each element seen.
- // The inner loop does one interation for each character in the element.
- //
-
- for (done = 0, ptr = cmdline; *ptr;) {
-
- //
- // zap any leading whitespace
- //
-
- while(isspace(*ptr))
- ptr++;
- base = ptr;
-
- for (done = newline = globbing = instring = quoted = 0;
- *ptr && !done; ptr++) {
-
- //
- // Switch on the current character. We only care about the
- // white-space characters, the wild-card characters, and the
- // quote characters.
- //
-
- switch (*ptr) {
- case ' ':
- case '\t':
-#if 0
- case '/': // have to do this for NT/DOS option strings
-
- //
- // check to see if we\'re parsing an option switch
- //
-
- if (*ptr == '/' && base == ptr)
- continue;
-#endif
- //
- // if we\'re not in a string, then we\'re finished with this
- // element
- //
-
- if (!instring)
- done++;
- break;
-
- case '*':
- case '?':
-
- //
- // record the fact that this element has a wildcard character
- // N.B. Don\'t glob if inside a single quoted string
- //
-
- if (!(instring && quote == '\''))
- globbing++;
- break;
-
- case '\n':
-
- //
- // If this string contains a newline, mark it as such so
- // we can replace it with the two character sequence "\n"
- // (cmd.exe doesn\'t like raw newlines in strings...sigh).
- //
-
- newline++;
- break;
-
- case '\'':
- case '\"':
-
- //
- // if we\'re already in a string, see if this is the
- // terminating close-quote. If it is, we\'re finished with
- // the string, but not neccessarily with the element.
- // If we\'re not already in a string, start one.
- //
-
- if (instring) {
- if (quote == *ptr) {
- instring = 0;
- quote = '\0';
- }
- }
- else {
- instring++;
- quote = *ptr;
- quoted++;
- }
- break;
- }
- }
-
- //
- // need to back up ptr by one due to last increment of for loop
- // (if we got out by seeing white space)
- //
-
- if (*ptr)
- ptr--;
-
- //
- // when we get here, we\'ve got a pair of pointers to the element,
- // base and ptr. Base points to the start of the element while ptr
- // points to the character following the element.
- //
-
- curr = ALLOC(NtCmdLineElement);
- if (curr == NULL) {
- NtFreeCmdLine();
- fprintf(stderr, "Out of memory!!\n");
- *vec = NULL;
- return 0;
- }
- memset (curr, 0, sizeof(*curr));
-
- len = ptr - base;
-
- //
- // if it\'s an input vector element and it\'s enclosed by quotes,
- // we can remove them.
- //
-
- if (InputCmd &&
- ((base[0] == '\"' && base[len-1] == '\"') ||
- (base[0] == '\'' && base[len-1] == '\''))) {
- base++;
- len -= 2;
- }
-
- curr->str = base;
- curr->len = len;
- curr->flags |= (globbing ? NTGLOB : 0);
-
- //
- // Now put it in the list of elements
- //
- if (NtCmdTail) {
- NtCmdTail->next = curr;
- curr->prev = NtCmdTail;
- NtCmdTail = curr;
- }
- else {
- NtCmdHead = NtCmdTail = curr;
- }
- }
-
- if (InputCmd) {
-
- //
- // When we get here we\'ve finished parsing the command line. Now
- // we need to run the list, expanding any globbing patterns.
- //
-
- for(curr = NtCmdHead; curr; curr = curr->next) {
- if (curr->flags & NTGLOB) {
- NtCmdGlob(curr);
- }
- }
- }
-
- //
- // Almost done!
- // Count up the elements, then allocate space for a vector of pointers
- // (argv) and a string table for the elements.
- //
-
- for (elements = 0, strsz = 0, curr = NtCmdHead; curr; curr = curr->next) {
- elements++;
- strsz += (curr->len + 1);
- }
-
- len = (elements+1)*sizeof(char *) + strsz;
- buffer = ALLOC_N(char, len);
- if (buffer == NULL) {
- fprintf(stderr, "Out of memory!!\n");
- NtFreeCmdLine();
- *vec = NULL;
- return 0;
- }
-
- memset (buffer, 0, len);
-
- //
- // make vptr point to the start of the buffer
- // and ptr point to the area we\'ll consider the string table.
- //
- // buffer (*vec)
- // |
- // V ^---------------------V
- // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
- // | | | .... | NULL | | ..... |\0 | | ..... |\0 |...
- // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
- // |- elements+1 -| ^ 1st element ^ 2nd element
-
- vptr = (char **) buffer;
-
- ptr = buffer + (elements+1) * sizeof(char *);
-
- for (curr = NtCmdHead; curr; curr = curr->next) {
- strncpy (ptr, curr->str, curr->len);
- ptr[curr->len] = '\0';
- *vptr++ = ptr;
- ptr += curr->len + 1;
- }
- NtFreeCmdLine();
- *vec = (char **) buffer;
- return elements;
-}
-
-
-#if 1
-//
-// UNIX compatible directory access functions for NT
-//
-
-//
-// File names are converted to lowercase if the
-// CONVERT_TO_LOWER_CASE variable is defined.
-//
-
-#define CONVERT_TO_LOWER_CASE
-#define PATHLEN 1024
-
-//
-// The idea here is to read all the directory names into a string table
-// (separated by nulls) and when one of the other dir functions is called
-// return the pointer to the current file name.
-//
-
-DIR *
-opendir(char *filename)
-{
- DIR *p;
- long len;
- long idx;
- char scannamespc[PATHLEN];
- char *scanname = scannamespc;
- struct stat sbuf;
- WIN32_FIND_DATA FindData;
- HANDLE fh;
- char root[PATHLEN];
- char volname[PATHLEN];
- DWORD serial, maxname, flags;
- BOOL downcase;
- char *dummy;
-
- //
- // check to see if we\'ve got a directory
- //
-
- if (stat (filename, &sbuf) < 0 ||
- sbuf.st_mode & _S_IFDIR == 0) {
- return NULL;
- }
-
- //
- // check out the file system characteristics
- //
- if (GetFullPathName(filename, PATHLEN, root, &dummy)) {
- if (dummy = strchr(root, '\\'))
- *++dummy = '\0';
- if (GetVolumeInformation(root, volname, PATHLEN,
- &serial, &maxname, &flags, 0, 0)) {
- downcase = !(flags & FS_CASE_SENSITIVE);
- }
- }
- else {
- downcase = TRUE;
- }
-
- //
- // Get us a DIR structure
- //
-
- p = xcalloc(sizeof(DIR), 1);
- if (p == NULL)
- return NULL;
-
- //
- // Create the search pattern
- //
-
- strcpy(scanname, filename);
-
- if (index("/\\", *(scanname + strlen(scanname) - 1)) == NULL)
- strcat(scanname, "/*");
- else
- strcat(scanname, "*");
-
- //
- // do the FindFirstFile call
- //
-
- fh = FindFirstFile (scanname, &FindData);
- if (fh == INVALID_HANDLE_VALUE) {
- return NULL;
- }
-
- //
- // now allocate the first part of the string table for the
- // filenames that we find.
- //
-
- idx = strlen(FindData.cFileName)+1;
- p->start = ALLOC_N(char, idx);
- strcpy (p->start, FindData.cFileName);
- if (downcase)
- strlwr(p->start);
- p->nfiles++;
-
- //
- // loop finding all the files that match the wildcard
- // (which should be all of them in this directory!).
- // the variable idx should point one past the null terminator
- // of the previous string found.
- //
- while (FindNextFile(fh, &FindData)) {
- len = strlen (FindData.cFileName);
-
- //
- // bump the string table size by enough for the
- // new name and it's null terminator
- //
-
- #define Renew(x, y, z) (x = (z *)realloc(x, y))
-
- Renew (p->start, idx+len+1, char);
- if (p->start == NULL) {
- Fatal ("opendir: malloc failed!\n");
- }
- strcpy(&p->start[idx], FindData.cFileName);
- if (downcase)
- strlwr(&p->start[idx]);
- p->nfiles++;
- idx += len+1;
- }
- FindClose(fh);
- p->size = idx;
- p->curr = p->start;
- return p;
-}
-
-
-//
-// Readdir just returns the current string pointer and bumps the
-// string pointer to the next entry.
-//
-
-struct direct *
-readdir(DIR *dirp)
-{
- int len;
- static int dummy = 0;
-
- if (dirp->curr) {
-
- //
- // first set up the structure to return
- //
-
- len = strlen(dirp->curr);
- strcpy(dirp->dirstr.d_name, dirp->curr);
- dirp->dirstr.d_namlen = len;
-
- //
- // Fake inode
- //
- dirp->dirstr.d_ino = dummy++;
-
- //
- // Now set up for the next call to readdir
- //
-
- dirp->curr += len + 1;
- if (dirp->curr >= (dirp->start + dirp->size)) {
- dirp->curr = NULL;
- }
-
- return &(dirp->dirstr);
-
- } else
- return NULL;
-}
-
-//
-// Telldir returns the current string pointer position
-//
-
-long
-telldir(DIR *dirp)
-{
- return (long) dirp->curr; /* ouch! pointer to long cast */
-}
-
-//
-// Seekdir moves the string pointer to a previously saved position
-// (Saved by telldir).
-
-void
-seekdir(DIR *dirp, long loc)
-{
- dirp->curr = (char *) loc; /* ouch! long to pointer cast */
-}
-
-//
-// Rewinddir resets the string pointer to the start
-//
-
-void
-rewinddir(DIR *dirp)
-{
- dirp->curr = dirp->start;
-}
-
-//
-// This just free\'s the memory allocated by opendir
-//
-
-void
-closedir(DIR *dirp)
-{
- free(dirp->start);
- free(dirp);
-}
-#endif
-
-
-//
-// 98.2% of this code was lifted from the OS2 port. (JCW)
-//
-
-#if 0
-// add_suffix is in util.c too.
-/*
- * Suffix appending for in-place editing under MS-DOS and OS/2 (and now NT!).
- *
- * Here are the rules:
- *
- * Style 0: Append the suffix exactly as standard perl would do it.
- * If the filesystem groks it, use it. (HPFS will always
- * grok it. So will NTFS. FAT will rarely accept it.)
- *
- * Style 1: The suffix begins with a '.'. The extension is replaced.
- * If the name matches the original name, use the fallback method.
- *
- * Style 2: The suffix is a single character, not a '.'. Try to add the
- * suffix to the following places, using the first one that works.
- * [1] Append to extension.
- * [2] Append to filename,
- * [3] Replace end of extension,
- * [4] Replace end of filename.
- * If the name matches the original name, use the fallback method.
- *
- * Style 3: Any other case: Ignore the suffix completely and use the
- * fallback method.
- *
- * Fallback method: Change the extension to ".$$$". If that matches the
- * original name, then change the extension to ".~~~".
- *
- * If filename is more than 1000 characters long, we die a horrible
- * death. Sorry.
- *
- * The filename restriction is a cheat so that we can use buf[] to store
- * assorted temporary goo.
- *
- * Examples, assuming style 0 failed.
- *
- * suffix = ".bak" (style 1)
- * foo.bar => foo.bak
- * foo.bak => foo.$$$ (fallback)
- * foo.$$$ => foo.~~~ (fallback)
- * makefile => makefile.bak
- *
- * suffix = "~" (style 2)
- * foo.c => foo.c~
- * foo.c~ => foo.c~~
- * foo.c~~ => foo~.c~~
- * foo~.c~~ => foo~~.c~~
- * foo~~~~~.c~~ => foo~~~~~.$$$ (fallback)
- *
- * foo.pas => foo~.pas
- * makefile => makefile.~
- * longname.fil => longname.fi~
- * longname.fi~ => longnam~.fi~
- * longnam~.fi~ => longnam~.$$$
- *
- */
-
-
-static char suffix1[] = ".$$$";
-static char suffix2[] = ".~~~";
-
-#define ext (&buf[1000])
-
-#define strEQ(s1,s2) (strcmp(s1,s2) == 0)
-
-void
-add_suffix(struct RString *str, char *suffix)
-{
- int baselen;
- int extlen = strlen(suffix);
- char *s, *t, *p;
- int slen;
- char buf[1024];
-
- if (str->len > 1000)
- Fatal("Cannot do inplace edit on long filename (%d characters)", str->len);
-
- /* Style 0 */
- slen = str->len;
- str_cat(str, suffix, extlen);
- if (valid_filename(str->ptr)) return;
-
- /* Fooey, style 0 failed. Fix str before continuing. */
- str->ptr[str->len = slen] = '\0';
-
- slen = extlen;
- t = buf; baselen = 0; s = str->ptr;
- while ( (*t = *s) && *s != '.') {
- baselen++;
- if (*s == '\\' || *s == '/') baselen = 0;
- s++; t++;
- }
- p = t;
-
- t = ext; extlen = 0;
- while (*t++ = *s++) extlen++;
- if (extlen == 0) { ext[0] = '.'; ext[1] = 0; extlen++; }
-
- if (*suffix == '.') { /* Style 1 */
- if (strEQ(ext, suffix)) goto fallback;
- strcpy(p, suffix);
- } else if (suffix[1] == '\0') { /* Style 2 */
- if (extlen < 4) {
- ext[extlen] = *suffix;
- ext[++extlen] = '\0';
- } else if (baselen < 8) {
- *p++ = *suffix;
- } else if (ext[3] != *suffix) {
- ext[3] = *suffix;
- } else if (buf[7] != *suffix) {
- buf[7] = *suffix;
- } else goto fallback;
- strcpy(p, ext);
- } else { /* Style 3: Panic */
-fallback:
- (void)memcpy(p, strEQ(ext, suffix1) ? suffix2 : suffix1, 5);
- }
- str_grow(str, strlen(buf));
- memcpy(str->ptr, buf, str->len);
-}
-#endif
-
-static int
-valid_filename(char *s)
-{
- int fd;
-
- //
- // if the file exists, then it\'s a valid filename!
- //
-
- if (_access(s, 0) == 0) {
- return 1;
- }
-
- //
- // It doesn\'t exist, so see if we can open it.
- //
-
- if ((fd = _open(s, _O_CREAT, 0666)) >= 0) {
- close(fd);
- _unlink (s); // don\'t leave it laying around
- return 1;
- }
- return 0;
-}
-
-
-//
-// This is a clone of fdopen so that we can handle the
-// brain damaged version of sockets that NT gets to use.
-//
-// The problem is that sockets are not real file handles and
-// cannot be fdopen\'ed. This causes problems in the do_socket
-// routine in doio.c, since it tries to create two file pointers
-// for the socket just created. We\'ll fake out an fdopen and see
-// if we can prevent perl from trying to do stdio on sockets.
-//
-
-FILE *
-myfdopen (int fd, const char *mode)
-{
- FILE *fp;
- char sockbuf[80];
- int optlen;
- int retval;
- extern int errno;
-
- //fprintf(stderr, "myfdopen()\n");
-
- retval = getsockopt((SOCKET)fd, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
- if (retval == SOCKET_ERROR) {
- int iRet;
-
- iRet = WSAGetLastError();
- if (iRet == WSAENOTSOCK || iRet == WSANOTINITIALISED)
- return (_fdopen(fd, mode));
- }
-
- //
- // If we get here, then fd is actually a socket.
- //
- fp = xcalloc(sizeof(FILE), 1);
-#if _MSC_VER < 800
- fileno(fp) = fd;
-#else
- fp->_file = fd;
-#endif
- if (*mode == 'r')
- fp->_flag = _IOREAD;
- else
- fp->_flag = _IOWRT;
- return fp;
-}
-
-
-//
-// Since the errors returned by the socket error function
-// WSAGetLastError() are not known by the library routine strerror
-// we have to roll our own.
-//
-
-#undef strerror
-
-char *
-mystrerror(int e)
-{
- static char buffer[512];
- extern int sys_nerr;
- DWORD source = 0;
-
- if (e < 0 || e > sys_nerr) {
- if (e < 0)
- e = GetLastError();
- if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, &source, e, 0,
- buffer, 512, NULL) == 0) {
- strcpy (buffer, "Unknown Error");
- }
- return buffer;
- }
- return strerror(e);
-
-}
-
-//
-// various stubs
-//
-
-
-// Ownership
-//
-// Just pretend that everyone is a superuser. NT will let us know if
-// we don\'t really have permission to do something.
-//
-
-#define ROOT_UID 0
-#define ROOT_GID 0
-
-UIDTYPE
-getuid(void)
-{
- return ROOT_UID;
-}
-
-UIDTYPE
-geteuid(void)
-{
- return ROOT_UID;
-}
-
-GIDTYPE
-getgid(void)
-{
- return ROOT_GID;
-}
-
-GIDTYPE
-getegid(void)
-{
- return ROOT_GID;
-}
-
-int
-setuid(int uid)
-{
- return (uid == ROOT_UID ? 0 : -1);
-}
-
-int
-setgid(int gid)
-{
- return (gid == ROOT_GID ? 0 : -1);
-}
-
-//
-// File system stuff
-//
-
-int
-/* ioctl(int i, unsigned int u, char *data) */
-ioctl(int i, unsigned int u, long data)
-{
- return -1;
-}
-
-
-//
-// Networking trampolines
-// These are used to avoid socket startup/shutdown overhead in case
-// the socket routines aren\'t used.
-//
-
-#undef select
-
-static int NtSocketsInitialized = 0;
-
-long
-myselect (int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
- struct timeval *timeout)
-{
- long r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = select (nfds, rd, wr, ex, timeout)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-static void
-StartSockets () {
- WORD version;
- WSADATA retdata;
- int ret;
-
- //
- // initalize the winsock interface and insure that it\'s
- // cleaned up at exit.
- //
- version = MAKEWORD(1, 1);
- if (ret = WSAStartup(version, &retdata))
- Fatal ("Unable to locate winsock library!\n");
- if (LOBYTE(retdata.wVersion) != 1)
- Fatal("could not find version 1 of winsock dll\n");
-
- if (HIBYTE(retdata.wVersion) != 1)
- Fatal("could not find version 1 of winsock dll\n");
-
- atexit((void (*)(void)) WSACleanup);
-}
-
-#undef accept
-
-SOCKET
-myaccept (SOCKET s, struct sockaddr *addr, int *addrlen)
-{
- SOCKET r;
-
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = accept (s, addr, addrlen)) == INVALID_SOCKET)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef bind
-
-int
-mybind (SOCKET s, struct sockaddr *addr, int addrlen)
-{
- int r;
-
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = bind (s, addr, addrlen)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef connect
-
-int
-myconnect (SOCKET s, struct sockaddr *addr, int addrlen)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = connect (s, addr, addrlen)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-
-#undef getpeername
-
-int
-mygetpeername (SOCKET s, struct sockaddr *addr, int *addrlen)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = getpeername (s, addr, addrlen)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef getsockname
-
-int
-mygetsockname (SOCKET s, struct sockaddr *addr, int *addrlen)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = getsockname (s, addr, addrlen)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef getsockopt
-
-int
-mygetsockopt (SOCKET s, int level, int optname, char *optval, int *optlen)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = getsockopt (s, level, optname, optval, optlen)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef ioctlsocket
-
-int
-myioctlsocket (SOCKET s, long cmd, u_long *argp)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = ioctlsocket (s, cmd, argp)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef listen
-
-int
-mylisten (SOCKET s, int backlog)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = listen (s, backlog)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef recv
-
-int
-myrecv (SOCKET s, char *buf, int len, int flags)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = recv (s, buf, len, flags)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef recvfrom
-
-int
-myrecvfrom (SOCKET s, char *buf, int len, int flags,
- struct sockaddr *from, int *fromlen)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = recvfrom (s, buf, len, flags, from, fromlen)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef send
-
-int
-mysend (SOCKET s, char *buf, int len, int flags)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = send (s, buf, len, flags)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef sendto
-
-int
-mysendto (SOCKET s, char *buf, int len, int flags,
- struct sockaddr *to, int tolen)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = sendto (s, buf, len, flags, to, tolen)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef setsockopt
-
-int
-mysetsockopt (SOCKET s, int level, int optname, char *optval, int optlen)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = setsockopt (s, level, optname, optval, optlen)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef shutdown
-
-int
-myshutdown (SOCKET s, int how)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = shutdown (s, how)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef socket
-
-SOCKET
-mysocket (int af, int type, int protocol)
-{
- SOCKET s;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((s = socket (af, type, protocol)) == INVALID_SOCKET) {
- errno = WSAGetLastError();
- //fprintf(stderr, "socket fail (%d)", WSAGetLastError());
- }
- return s;
-}
-
-#undef gethostbyaddr
-
-struct hostent *
-mygethostbyaddr (char *addr, int len, int type)
-{
- struct hostent *r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = gethostbyaddr (addr, len, type)) == NULL)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef gethostbyname
-
-struct hostent *
-mygethostbyname (char *name)
-{
- struct hostent *r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = gethostbyname (name)) == NULL)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef gethostname
-
-int
-mygethostname (char *name, int len)
-{
- int r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = gethostname (name, len)) == SOCKET_ERROR)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef getprotobyname
-
-struct protoent *
-mygetprotobyname (char *name)
-{
- struct protoent *r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = getprotobyname (name)) == NULL)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef getprotobynumber
-
-struct protoent *
-mygetprotobynumber (int num)
-{
- struct protoent *r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = getprotobynumber (num)) == NULL)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef getservbyname
-
-struct servent *
-mygetservbyname (char *name, char *proto)
-{
- struct servent *r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = getservbyname (name, proto)) == NULL)
- errno = WSAGetLastError();
- return r;
-}
-
-#undef getservbyport
-
-struct servent *
-mygetservbyport (int port, char *proto)
-{
- struct servent *r;
- if (!NtSocketsInitialized++) {
- StartSockets();
- }
- if ((r = getservbyport (port, proto)) == NULL)
- errno = WSAGetLastError();
- return r;
-}
-
-//
-// Networking stubs
-//
-
-void endhostent() {}
-void endnetent() {}
-void endprotoent() {}
-void endservent() {}
-
-struct netent *getnetent (void) {return (struct netent *) NULL;}
-
-struct netent *getnetbyaddr(char *name) {return (struct netent *)NULL;}
-
-struct netent *getnetbyname(long net, int type) {return (struct netent *)NULL;}
-
-struct protoent *getprotoent (void) {return (struct protoent *) NULL;}
-
-struct servent *getservent (void) {return (struct servent *) NULL;}
-
-void sethostent (int stayopen) {}
-
-void setnetent (int stayopen) {}
-
-void setprotoent (int stayopen) {}
-
-void setservent (int stayopen) {}
-
-
-#ifndef WNOHANG
-#define WNOHANG -1
-#endif
-
-pid_t
-waitpid (pid_t pid, int *stat_loc, int options)
-{
- DWORD timeout;
-
- if (options == WNOHANG) {
- timeout = 0;
- } else {
- timeout = INFINITE;
- }
- if (WaitForSingleObject((HANDLE) pid, timeout) == WAIT_OBJECT_0) {
- pid = _cwait(stat_loc, pid, 0);
- return pid;
- }
- return 0;
-}
-
-#include <sys/timeb.h>
-
-void _cdecl
-gettimeofday(struct timeval *tv, struct timezone *tz)
-{
- struct timeb tb;
-
- ftime(&tb);
- tv->tv_sec = tb.time;
- tv->tv_usec = tb.millitm * 1000;
-}
-
-char *
-getcwd(buffer, size)
- char *buffer;
- int size;
-{
- int length;
- char *bp;
-
- if (_getcwd(buffer, size) == NULL) {
- return NULL;
- }
- length = strlen(buffer);
- if (length >= size) {
- return NULL;
- }
-
- for (bp = buffer; *bp != '\0'; bp++) {
- if (*bp == '\\') {
- *bp = '/';
- }
- }
- return buffer;
-}
-
-static char *
-str_grow(struct RString *str, size_t new_size)
-{
- char *p;
-
- p = realloc(str->ptr, new_size);
- if (p == NULL)
- Fatal("cannot grow string\n");
-
- str->len = new_size;
- str->ptr = p;
-
- return p;
-}
-
-int
-chown(char *path, int owner, int group)
-{
- return 0;
-}
-
-int
-kill(int pid, int sig)
-{
-#if 1
- if (pid == GetCurrentProcessId())
- return raise(sig);
-
- if (sig == 2 && pid > 0)
- if (GenerateConsoleCtrlEvent(CTRL_C_EVENT, (DWORD)pid))
- return 0;
-
- return -1;
-#else
- return 0;
-#endif
-}
-
-int
-link(char *from, char *to)
-{
- return -1;
-}
-
-int
-wait()
-{
- return 0;
-}
-
diff --git a/missing/nt.h b/missing/nt.h
deleted file mode 100644
index 830b9edf13..0000000000
--- a/missing/nt.h
+++ /dev/null
@@ -1,362 +0,0 @@
-#ifndef EXT_NT_H
-#define EXT_NT_H
-
-/*
- * Copyright (c) 1993, Intergraph Corporation
- *
- * You may distribute under the terms of either the GNU General Public
- * License or the Artistic License, as specified in the perl README file.
- *
- */
-
-//
-// Definitions for NT port of Perl
-//
-
-//
-// GRRRR!!!! Windows Nonsense.
-// Define the following so we don't get tons of extra stuff
-// when we include windows.h
-//
-#if 0
-#define NOGDICAPMASKS
-#define NOVIRTUALKEYCODES
-#define NOWINMESSAGES
-#define NOWINSTYLES
-#define NOSYSMETRICS
-#define NOMENUS
-#define NOICONS
-#define NOKEYSTATES
-#define NOSYSCOMMANDS
-#define NORASTEROPS
-#define NOSHOWWINDOW
-#define OEMRESOURCE
-#define NOATOM
-#define NOCLIPBOARD
-#define NOCOLOR
-#define NOCTLMGR
-#define NODRAWTEXT
-#define NOGDI
-//#define NOKERNEL
-//#define NOUSER
-#define NONLS
-#define NOMB
-#define NOMEMMGR
-#define NOMETAFILE
-#define NOMINMAX
-#define NOMSG
-#define NOOPENFILE
-#define NOSCROLL
-#define NOSERVICE
-#define NOSOUND
-#define NOTEXTMETRIC
-#define NOWH
-#define NOWINOFFSETS
-#define NOCOMM
-#define NOKANJI
-#define NOHELP
-#define NOPROFILER
-#define NODEFERWINDOWPOS
-#endif
-
-//
-// Ok now we can include the normal include files.
-//
-
-// #include <stdarg.h> conflict with varargs.h?
-// There is function-name conflitct, so we rename it
-#if !defined(IN) && !defined(FLOAT)
-#define OpenFile WINAPI_OpenFile
-#include <windows.h>
-#include <winsock.h>
-#undef OpenFile
-#endif
-//
-// We\'re not using Microsoft\'s "extensions" to C for
-// Structured Exception Handling (SEH) so we can nuke these
-//
-#undef try
-#undef except
-#undef finally
-#undef leave
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <direct.h>
-#include <process.h>
-#include <time.h>
-#include <math.h>
-#include <sys/types.h>
-#include <sys/utime.h>
-
-//
-// Grrr...
-//
-
-#define access _access
-#define chmod _chmod
-#define chsize _chsize
-#define close _close
-#define creat _creat
-#define dup _dup
-#define dup2 _dup2
-#define eof _eof
-#define filelength _filelength
-#define isatty _isatty
-#define locking _locking
-#define lseek _lseek
-#define mktemp _mktemp
-#define open _open
-#define read _read
-#define setmode _setmode
-#define sopen _sopen
-#define tell _tell
-#define umask _umask
-#define unlink _unlink
-#define write _write
-#define execl _execl
-#define execle _execle
-#define execlp _execlp
-#define execlpe _execlpe
-#define execv _execv
-#define execve _execve
-#define execvp _execvp
-#define execvpe _execvpe
-#define getpid _getpid
-#define spawnl _spawnl
-#define spawnle _spawnle
-#define spawnlp _spawnlp
-#define spawnlpe _spawnlpe
-#define spawnv _spawnv
-#define spawnve _spawnve
-#define spawnvp _spawnvp
-#define spawnvpe _spawnvpe
-#if _MSC_VER < 800
-#define fileno _fileno
-#endif
-#define utime _utime
-//#define pipe _pipe
-#define perror _perror
-
-
-/* these are defined in nt.c */
-
-extern int NtMakeCmdVector(char *, char ***, int);
-/* extern void NtInitialize(int *, char ***); */
-extern char *NtGetLib(void);
-extern char *NtGetBin(void);
-extern FILE *mypopen(char *, char *);
-extern int flock(int fd, int oper);
-extern FILE * myfdopen(int, char*);
-extern SOCKET myaccept(SOCKET, struct sockaddr *, int *);
-extern int mybind(SOCKET, struct sockaddr *, int);
-extern int myconnect(SOCKET, struct sockaddr *, int);
-extern int mygetpeername(SOCKET, struct sockaddr *, int *);
-extern int mygetsockname(SOCKET, struct sockaddr *, int *);
-extern int mygetsockopt(SOCKET, int, int, char *, int *);
-extern int myioctlsocket(SOCKET, long, u_long *);
-extern int mylisten(SOCKET, int);
-extern int myrecv(SOCKET, char *, int, int);
-extern int myrecvfrom(SOCKET, char *, int, int, struct sockaddr *, int *);
-extern int mysend(SOCKET, char *, int, int);
-extern int mysendto(SOCKET, char *, int, int, struct sockaddr *, int);
-extern int mysetsockopt(SOCKET, int, int, char *, int);
-extern int myshutdown(SOCKET, int);
-extern SOCKET mysocket(int, int, int);
-extern struct hostent * mygethostbyaddr(char *, int, int);
-extern struct hostent * mygethostbyname(char *);
-extern int mygethostname(char *, int);
-extern struct protoent * mygetprotobyname(char *);
-extern struct protoent * mygetprotobynumber(int);
-extern struct servent * mygetservbyname(char *, char *);
-extern struct servent * mygetservbyport(int, char *);
-
-//
-// define this so we can do inplace editing
-//
-
-#define SUFFIX
-
-//
-// stubs
-//
-// extern int ioctl (int, unsigned int, char *);
-extern int ioctl (int, unsigned int, long);
-#if 0
-extern void sleep (unsigned int);
-#else
-#define sleep(x) Sleep(x*1000)
-#endif
-
-extern UIDTYPE getuid (void);
-extern UIDTYPE geteuid (void);
-extern GIDTYPE getgid (void);
-extern GIDTYPE getegid (void);
-extern int setuid (int);
-extern int setgid (int);
-
-
-#undef IN /* confict in parse.c */
-
-#if 0
-extern int sys_nerr;
-extern char *sys_errlist[];
-#endif
-extern char *mystrerror(int);
-
-#define strerror(e) mystrerror(e)
-
-#define PIPE_BUF 1024
-
-#define HAVE_STDLIB_H 1
-#define HAVE_GETLOGIN 1
-#define HAVE_WAITPID 1
-#define HAVE_GETCWD 1
-
-#define LOCK_SH 1
-#define LOCK_EX 2
-#define LOCK_NB 4
-#define LOCK_UN 8
-#ifndef EWOULDBLOCK
-#define EWOULDBLOCK 10035 /* EBASEERR + 35 (winsock.h) */
-#endif
-
-#ifdef popen
-#undef popen
-#define popen mypopen
-#endif
-#ifdef pclose
-#undef pclose
-#define pclose mypclose
-#endif
-
-#undef va_start
-#undef va_end
-
-#ifdef popen
-#undef popen
-#define popen mypopen
-#endif
-#ifdef pclose
-#undef pclose
-#define pclose mypclose
-#endif
-
-#undef va_start
-#undef va_end
-
-#ifdef fdopen
-#undef fdopen
-#endif
-#define fdopen myfdopen
-
-#ifdef accept
-#undef accept
-#endif
-#define accept myaccept
-
-#ifdef bind
-#undef bind
-#endif
-#define bind mybind
-
-#ifdef connect
-#undef connect
-#endif
-#define connect myconnect
-
-#ifdef getpeername
-#undef getpeername
-#endif
-#define getpeername mygetpeername
-
-#ifdef getsockname
-#undef getsockname
-#endif
-#define getsockname mygetsockname
-
-#ifdef getsockopt
-#undef getsockopt
-#endif
-#define getsockopt mygetsockopt
-
-#ifdef ioctlsocket
-#undef ioctlsocket
-#endif
-#define ioctlsocket myioctlsocket
-
-#ifdef listen
-#undef listen
-#endif
-#define listen mylisten
-
-#ifdef recv
-#undef recv
-#endif
-#define recv myrecv
-
-#ifdef recvfrom
-#undef recvfrom
-#endif
-#define recvfrom myrecvfrom
-
-#ifdef send
-#undef send
-#endif
-#define send mysend
-
-#ifdef sendto
-#undef sendto
-#endif
-#define sendto mysendto
-
-#ifdef setsockopt
-#undef setsockopt
-#endif
-#define setsockopt mysetsockopt
-
-#ifdef shutdown
-#undef shutdown
-#endif
-#define shutdown myshutdown
-
-#ifdef socket
-#undef socket
-#endif
-#define socket mysocket
-
-#ifdef gethostbyaddr
-#undef gethostbyaddr
-#endif
-#define gethostbyaddr mygethostbyaddr
-
-#ifdef gethostbyname
-#undef gethostbyname
-#endif
-#define gethostbyname mygethostbyname
-
-#ifdef gethostname
-#undef gethostname
-#endif
-#define gethostname mygethostname
-
-#ifdef getprotobyname
-#undef getprotobyname
-#endif
-#define getprotobyname mygetprotobyname
-
-#ifdef getprotobynumber
-#undef getprotobynumber
-#endif
-#define getprotobynumber mygetprotobynumber
-
-#ifdef getservbyname
-#undef getservbyname
-#endif
-#define getservbyname mygetservbyname
-
-#ifdef getservbyport
-#undef getservbyport
-#endif
-#define getservbyport mygetservbyport
-#endif
diff --git a/missing/setenv.c b/missing/setenv.c
deleted file mode 100644
index c9cb4b20e0..0000000000
--- a/missing/setenv.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (c) 1991, Larry Wall
- *
- * You may distribute under the terms of either the GNU General Public
- * License or the Artistic License, as specified in the README file.
- */
-
-#include "ruby.h"
-
-#ifndef NT
-extern char **environ;
-#endif
-extern char **origenviron;
-
-#ifndef NT
-char *strdup();
-#endif
-
-#ifdef USE_WIN32_RTL_ENV
-#include <stdlib.h>
-#endif
-
-static int
-envix(nam)
-char *nam;
-{
- register int i, len = strlen(nam);
-
- for (i = 0; environ[i]; i++) {
- if (memcmp(environ[i],nam,len) == 0 && environ[i][len] == '=')
- break; /* memcmp must come first to avoid */
- } /* potential SEGV's */
- return i;
-}
-
-#ifndef WIN32
-void
-setenv(nam,val, n)
-char *nam, *val;
-int n;
-{
- register int i=envix(nam); /* where does it go? */
-
- if (environ == origenviron) { /* need we copy environment? */
- int j;
- int max;
- char **tmpenv;
-
- /*SUPPRESS 530*/
- for (max = i; environ[max]; max++) ;
- tmpenv = ALLOC_N(char*, max+2);
- for (j=0; j<max; j++) /* copy environment */
- tmpenv[j] = strdup(environ[j]);
- tmpenv[max] = 0;
- environ = tmpenv; /* tell exec where it is now */
- }
- if (!val) {
- while (environ[i]) {
- environ[i] = environ[i+1];
- i++;
- }
- return;
- }
- if (!environ[i]) { /* does not exist yet */
- REALLOC_N(environ, char*, i+2); /* just expand it a bit */
- environ[i+1] = 0; /* make sure it's null terminated */
- }
- else {
- free(environ[i]);
- }
- environ[i] = ALLOC_N(char, strlen(nam) + strlen(val) + 2);
-#ifndef MSDOS
- (void)sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
-#else
- /* MS-DOS requires environment variable names to be in uppercase */
- /* [Tom Dinger, 27 August 1990: Well, it doesn't _require_ it, but
- * some utilities and applications may break because they only look
- * for upper case strings. (Fixed strupr() bug here.)]
- */
- strcpy(environ[i],nam); strupr(environ[i]);
- (void)sprintf(environ[i] + strlen(nam),"=%s",val);
-#endif /* MSDOS */
-}
-#else /* if WIN32 */
-void
-setenv(nam,val, n)
-char *nam, *val;
-int n;
-{
-#ifdef USE_WIN32_RTL_ENV
-
- register char *envstr;
- STRLEN namlen = strlen(nam);
- STRLEN vallen;
- char *oldstr = environ[envix(nam)];
-
- /* putenv() has totally broken semantics in both the Borland
- * and Microsoft CRTLs. They either store the passed pointer in
- * the environment without making a copy, or make a copy and don't
- * free it. And on top of that, they dont free() old entries that
- * are being replaced/deleted. This means the caller must
- * free any old entries somehow, or we end up with a memory
- * leak every time setenv() is called. One might think
- * one could directly manipulate environ[], like the UNIX code
- * above, but direct changes to environ are not allowed when
- * calling putenv(), since the RTLs maintain an internal
- * *copy* of environ[]. Bad, bad, *bad* stink.
- * GSAR 97-06-07
- */
-
- if (!val) {
- if (!oldstr)
- return;
- val = "";
- vallen = 0;
- }
- else
- vallen = strlen(val);
- envstr = ALLOC_N(char, namelen + vallen + 3);
- (void)sprintf(envstr,"%s=%s",nam,val);
- (void)putenv(envstr);
- if (oldstr)
- free(oldstr);
-#ifdef _MSC_VER
- free(envstr); /* MSVCRT leaks without this */
-#endif
-
-#else /* !USE_WIN32_RTL_ENV */
-
- /* The sane way to deal with the environment.
- * Has these advantages over putenv() & co.:
- * * enables us to store a truly empty value in the
- * environment (like in UNIX).
- * * we don't have to deal with RTL globals, bugs and leaks.
- * * Much faster.
- * Why you may want to enable USE_WIN32_RTL_ENV:
- * * environ[] and RTL functions will not reflect changes,
- * which might be an issue if extensions want to access
- * the env. via RTL. This cuts both ways, since RTL will
- * not see changes made by extensions that call the Win32
- * functions directly, either.
- * GSAR 97-06-07
- */
- SetEnvironmentVariable(nam,val);
-
-#endif
-}
-
-#endif /* WIN32 */
diff --git a/sample/ruby-mode.el b/sample/ruby-mode.el
deleted file mode 100644
index 0f56477ea0..0000000000
--- a/sample/ruby-mode.el
+++ /dev/null
@@ -1,649 +0,0 @@
-;;;
-;;; ruby-mode.el -
-;;;
-;;; $Author$
-;;; Time-stamp: <97/03/21 01:16:05 matz>
-;;; created at: Fri Feb 4 14:49:13 JST 1994
-;;;
-
-(defconst ruby-mode-version "1.0.7")
-
-(defconst ruby-block-beg-re
- "class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin\\|do"
- )
-
-(defconst ruby-indent-beg-re
- "\\(\\s *\\(class\\|module\\|def\\)\\)\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin"
- )
-
-(defconst ruby-modifier-re
- "if\\|unless\\|while\\|until"
- )
-
-(defconst ruby-block-mid-re
- "then\\|else\\|elsif\\|when\\|rescue\\|ensure"
- )
-
-(defconst ruby-block-op-re
- "and\\|or\\|not"
- )
-
-(defconst ruby-block-end-re "end")
-
-(defconst ruby-delimiter
- (concat "[?$/%(){}#\"'`]\\|\\[\\|\\]\\|\\<\\("
- ruby-block-beg-re
- "\\|" ruby-block-end-re
- "\\)\\>\\|^=begin")
- )
-
-(defconst ruby-negative
- (concat "^[ \t]*\\(\\(" ruby-block-mid-re "\\)\\>\\|\\("
- ruby-block-end-re "\\)\\>\\|\\}\\|\\]\\)")
- )
-
-(defconst ruby-operator-chars "[,.+*/%-&|^~=<>:]")
-(defconst ruby-symbol-chars "[a-zA-Z0-9_]")
-
-(defvar ruby-mode-abbrev-table nil
- "Abbrev table in use in ruby-mode buffers.")
-
-(define-abbrev-table 'ruby-mode-abbrev-table ())
-
-(defvar ruby-mode-map nil "Keymap used in ruby mode.")
-
-(if ruby-mode-map
- nil
- (setq ruby-mode-map (make-sparse-keymap))
- (define-key ruby-mode-map "{" 'ruby-electric-brace)
- (define-key ruby-mode-map "}" 'ruby-electric-brace)
- (define-key ruby-mode-map "\e\C-a" 'ruby-beginning-of-defun)
- (define-key ruby-mode-map "\e\C-e" 'ruby-end-of-defun)
- (define-key ruby-mode-map "\e\C-b" 'ruby-beginning-of-block)
- (define-key ruby-mode-map "\e\C-f" 'ruby-end-of-block)
- (define-key ruby-mode-map "\e\C-p" 'ruby-beginning-of-block)
- (define-key ruby-mode-map "\e\C-n" 'ruby-end-of-block)
- (define-key ruby-mode-map "\t" 'ruby-indent-command)
- (define-key ruby-mode-map "\C-c\C-e" 'ruby-insert-end)
- (define-key ruby-mode-map "\C-j" 'ruby-reindent-then-newline-and-indent)
- (define-key ruby-mode-map "\C-m" 'newline))
-
-(defvar ruby-mode-syntax-table nil
- "Syntax table in use in ruby-mode buffers.")
-
-(if ruby-mode-syntax-table
- ()
- (setq ruby-mode-syntax-table (make-syntax-table))
- (modify-syntax-entry ?\' "\"" ruby-mode-syntax-table)
- (modify-syntax-entry ?\" "\"" ruby-mode-syntax-table)
- (modify-syntax-entry ?\` "\"" ruby-mode-syntax-table)
- (modify-syntax-entry ?# "<" ruby-mode-syntax-table)
- (modify-syntax-entry ?\n ">" ruby-mode-syntax-table)
- (modify-syntax-entry ?\\ "'" ruby-mode-syntax-table)
- (modify-syntax-entry ?$ "/" ruby-mode-syntax-table)
- (modify-syntax-entry ?? "_" ruby-mode-syntax-table)
- (modify-syntax-entry ?_ "_" ruby-mode-syntax-table)
- (modify-syntax-entry ?< "." ruby-mode-syntax-table)
- (modify-syntax-entry ?> "." ruby-mode-syntax-table)
- (modify-syntax-entry ?& "." ruby-mode-syntax-table)
- (modify-syntax-entry ?| "." ruby-mode-syntax-table)
- (modify-syntax-entry ?% "." ruby-mode-syntax-table)
- (modify-syntax-entry ?= "." ruby-mode-syntax-table)
- (modify-syntax-entry ?/ "." ruby-mode-syntax-table)
- (modify-syntax-entry ?+ "." ruby-mode-syntax-table)
- (modify-syntax-entry ?* "." ruby-mode-syntax-table)
- (modify-syntax-entry ?- "." ruby-mode-syntax-table)
- (modify-syntax-entry ?\; "." ruby-mode-syntax-table)
- (modify-syntax-entry ?\( "()" ruby-mode-syntax-table)
- (modify-syntax-entry ?\) ")(" ruby-mode-syntax-table)
- (modify-syntax-entry ?\{ "(}" ruby-mode-syntax-table)
- (modify-syntax-entry ?\} "){" ruby-mode-syntax-table)
- (modify-syntax-entry ?\[ "(]" ruby-mode-syntax-table)
- (modify-syntax-entry ?\] ")[" ruby-mode-syntax-table)
- )
-
-(defvar ruby-indent-level 2
- "*Indentation of ruby statements.")
-
-(defun ruby-mode ()
- "Major mode for editing ruby scripts.
-\\[ruby-indent-command] properly indents subexpressions of multi-line
-class, module, def, if, while, for, do, and case statements, taking
-nesting into account.
-
-The variable ruby-indent-level controls the amount of indentation.
-\\{ruby-mode-map}"
- (interactive)
- (kill-all-local-variables)
- (use-local-map ruby-mode-map)
- (setq mode-name "ruby")
- (setq major-mode 'ruby-mode)
- (set-syntax-table ruby-mode-syntax-table)
- (setq local-abbrev-table ruby-mode-abbrev-table)
- (make-local-variable 'indent-line-function)
- (setq indent-line-function 'ruby-indent-line)
- (make-local-variable 'require-final-newline)
- (setq require-final-newline t)
- (make-variable-buffer-local 'comment-start)
- (setq comment-start "# ")
- (make-variable-buffer-local 'comment-end)
- (setq comment-end "")
- (make-variable-buffer-local 'comment-column)
- (setq comment-column 32)
- (make-variable-buffer-local 'comment-start-skip)
- (setq comment-start-skip "\\(^\\|\\s-\\);?#+ *")
- (make-local-variable 'parse-sexp-ignore-comments)
- (setq parse-sexp-ignore-comments t)
- (run-hooks 'ruby-mode-hook))
-
-(defun ruby-current-indentation ()
- (save-excursion
- (beginning-of-line)
- (back-to-indentation)
- (current-column)))
-
-(defun ruby-indent-line (&optional flag)
- "Correct indentation of the current ruby line."
- (ruby-indent-to (ruby-calculate-indent)))
-
-(defun ruby-indent-command ()
- (interactive)
- (ruby-indent-line t))
-
-(defun ruby-indent-to (x)
- (if x
- (let (shift top beg)
- (and (< x 0)
- (error "invalid nest"))
- (setq shift (current-column))
- (beginning-of-line)
- (setq beg (point))
- (back-to-indentation)
- (setq top (current-column))
- (skip-chars-backward " \t")
- (cond
- ((>= x shift)
- (setq shift 0))
- ((>= shift top)
- (setq shift (- shift top)))
- (t (setq shift 0)))
- (if (and (bolp)
- (= x top))
- (move-to-column (+ x shift))
- (move-to-column top)
- (delete-region beg (point))
- (beginning-of-line)
- (indent-to x)
- (move-to-column (+ x shift))))))
-
-(defun ruby-expr-beg (&optional modifier)
- (save-excursion
- (if (looking-at "\\?")
- (progn
- (or (bolp) (forward-char -1))
- (not (looking-at "\\sw")))
- (skip-chars-backward " \t")
- (or (bolp) (forward-char -1))
- (or (looking-at ruby-operator-chars)
- (looking-at "[\\[({!?]")
- (bolp)
- (and (looking-at ruby-symbol-chars)
- (forward-word -1)
- (or
- (and modifier (bolp))
- (looking-at ruby-block-beg-re)
- (looking-at ruby-block-op-re)
- (looking-at ruby-block-mid-re)
- (and modifier
- (save-excursion
- (forward-char -1)
- (let ((c (char-after (point))))
- (or (eq c ?.)
- (eq c ? )
- (eq c ?\t))))))
- (goto-char (match-end 0))
- (looking-at "[^_]"))))))
-
-(defun ruby-parse-region (start end)
- (let ((indent-point end)
- (indent 0)
- (in-string nil)
- (in-paren nil)
- (depth 0)
- (nest nil)
- (pcol nil))
- (save-excursion
- (if start
- (goto-char start)
- (ruby-beginning-of-indent))
- (save-restriction
- (narrow-to-region (point) end)
- (while (and (> indent-point (point))
- (re-search-forward ruby-delimiter indent-point t))
- (let ((pnt (point)) w)
- (goto-char (match-beginning 0))
- (cond
- ((or (looking-at "\"") ;skip string
- (looking-at "'")
- (looking-at "`"))
- (setq w (char-after (point)))
- (cond
- ((and (not (eobp))
- (re-search-forward (format "[^\\]%c" w) indent-point t))
- nil)
- (t
- (setq in-string (point))
- (goto-char indent-point))))
- ((looking-at "/")
- (cond
- ((and (not (eobp)) (ruby-expr-beg))
- (if (re-search-forward "[^\\]/" indent-point t)
- nil
- (setq in-string (point))
- (goto-char indent-point)))
- (t
- (goto-char pnt))))
- ((looking-at "%")
- (cond
- ((and (not (eobp)) (ruby-expr-beg)
- (looking-at "%[Qqrx]?\\(.\\)"))
- (setq w (buffer-substring (match-beginning 1)
- (match-end 1)))
- (cond
- ((string= w "[") (setq w "]"))
- ((string= w "{") (setq w "}"))
- ((string= w "(") (setq w ")"))
- ((string= w "<") (setq w ">")))
- (goto-char (match-end 0))
- (if (search-forward w indent-point t)
- nil
- (setq in-string (point))
- (goto-char indent-point)))
- (t
- (goto-char pnt))))
- ((looking-at "\\?") ;skip ?char
- (cond
- ((ruby-expr-beg)
- (looking-at "?\\(\\\\C-\\|\\\\M-\\)*.")
- (goto-char (match-end 0)))
- (t
- (goto-char pnt))))
- ((looking-at "\\$") ;skip $char
- (goto-char pnt)
- (forward-char 1))
- ((looking-at "#") ;skip comment
- (forward-line 1)
- (goto-char (point))
- )
- ((looking-at "(")
- (setq nest (cons (cons (char-after (point)) pnt) nest))
- (setq pcol (cons (cons pnt depth) pcol))
- (setq depth 0)
- (goto-char pnt)
- )
- ((looking-at "[\\[{]")
- (setq nest (cons (cons (char-after (point)) pnt) nest))
- (setq depth (1+ depth))
- (goto-char pnt)
- )
- ((looking-at ")")
- (setq nest (cdr nest))
- (setq depth (cdr (car pcol)))
- (setq pcol (cdr pcol))
- (goto-char pnt))
- ((looking-at "[])}]")
- (setq nest (cdr nest))
- (setq depth (1- depth))
- (goto-char pnt))
- ((looking-at ruby-block-end-re)
- (if (or (and (not (bolp))
- (progn
- (forward-char -1)
- (eq ?_ (char-after (point)))))
- (progn
- (goto-char pnt)
- (setq w (char-after (point)))
- (or (eq ?_ w)
- (eq ?! w)
- (eq ?? w))))
- nil
- (setq nest (cdr nest))
- (setq depth (1- depth)))
- (goto-char pnt))
- ((looking-at ruby-block-beg-re)
- (and
- (or (bolp)
- (progn
- (forward-char -1)
- (not (eq ?_ (char-after (point))))))
- (progn
- (goto-char pnt)
- (setq w (char-after (point)))
- (and (not (eq ?_ w))
- (not (eq ?! w))
- (not (eq ?? w))))
- (progn
- (goto-char (match-beginning 0))
- (if (looking-at ruby-modifier-re)
- (ruby-expr-beg)
- t))
- (progn
- (setq nest (cons (cons nil pnt) nest))
- (setq depth (1+ depth))))
- (if (looking-at "def\\s *[/`]")
- (goto-char (match-end 0))
- (goto-char pnt)))
- ((looking-at "^=begin")
- (if (re-search-forward "^=end" indent-point t)
- (forward-line 1)
- (setq in-string (match-end 0))
- (goto-char indent-point)))
- (t
- (error (format "bad string %s"
- (buffer-substring (point) pnt)
- )))))))
- (list in-string (car nest) depth (car (car pcol))))))
-
-(defun ruby-calculate-indent (&optional parse-start)
- (save-excursion
- (beginning-of-line)
- (let ((indent-point (point))
- (case-fold-search nil)
- state bol eol
- (indent 0))
- (if parse-start
- (goto-char parse-start)
- (ruby-beginning-of-indent)
- (setq parse-start (point)))
- (back-to-indentation)
- (setq indent (current-column))
- (setq state (ruby-parse-region parse-start indent-point))
- (cond
- ((nth 0 state) ; within string
- (setq indent nil)) ; do nothing
-
- ((car (nth 1 state)) ; in paren
- (goto-char (cdr (nth 1 state)))
- (if (eq (car (nth 1 state)) ?\( )
- (let ((column (current-column))
- (s (ruby-parse-region (point) indent-point)))
- (cond
- ((and (nth 2 s) (> (nth 2 s) 0))
- (goto-char (cdr (nth 1 s)))
- (forward-word -1)
- (setq indent (+ (current-column) ruby-indent-level)))
- (t
- (setq indent (current-column)))))
- (cond
- ((nth 3 state)
- (goto-char (nth 3 state))
- (setq indent (+ (current-column) ruby-indent-level)))
- (t
- (goto-char parse-start)
- (back-to-indentation)
- (setq indent (+ (current-column) (* (nth 2 state) ruby-indent-level)))))
- ))
-
- ((and (nth 2 state)(> (nth 2 state) 0)) ; in nest
- (if (null (cdr (nth 1 state)))
- (error "invalid nest"))
- (goto-char (cdr (nth 1 state)))
- (forward-word -1) ; skip back a keyword
- (cond
- ((looking-at "do") ; iter block is a special case
- (cond
- ((nth 3 state)
- (goto-char (nth 3 state))
- (setq indent (+ (current-column) ruby-indent-level)))
- (t
- (goto-char parse-start)
- (back-to-indentation)
- (setq indent (+ (current-column) (* (nth 2 state) ruby-indent-level))))))
- (t
- (setq indent (+ (current-column) ruby-indent-level)))))
-
- ((and (nth 2 state) (< (nth 2 state) 0)) ; in negative nest
- (setq indent (+ (current-column) (* (nth 2 state) ruby-indent-level)))))
-
- (cond
- (indent
- (goto-char indent-point)
- (end-of-line)
- (setq eol (point))
- (beginning-of-line)
- (cond
- ((re-search-forward ruby-negative eol t)
- (and (not (eq ?_ (char-after (match-end 0))))
- (setq indent (- indent ruby-indent-level))))
- ;;operator terminated lines
- ((and
- (save-excursion
- (beginning-of-line)
- (not (bobp)))
- (or (null (car (nth 1 state))) ;not in parens
- (and (eq (car (nth 1 state)) ?\{)
- (save-excursion ;except non-block braces
- (goto-char (cdr (nth 1 state)))
- (or (bobp) (forward-char -1))
- (not (ruby-expr-beg))))))
- ;; goto beginning of non-empty no-comment line
- (let (end done)
- (while (not done)
- (skip-chars-backward " \t\n")
- (setq end (point))
- (beginning-of-line)
- (if (re-search-forward "^\\s *#" end t)
- (beginning-of-line)
- (setq done t))))
- (setq bol (point))
- (end-of-line)
- (skip-chars-backward " \t")
- (or (bobp) (forward-char -1))
- (and
- (or (and (looking-at ruby-symbol-chars)
- (skip-chars-backward ruby-symbol-chars)
- (looking-at ruby-block-op-re)
- (save-excursion
- (goto-char (match-end 0))
- (not (looking-at "[a-z_]"))))
- (and (looking-at ruby-operator-chars)
- (or (not (or (eq ?/ (char-after (point)))))
- (null (nth 0 (ruby-parse-region parse-start (point)))))
- (not (eq (char-after (1- (point))) ?$))
- (or (not (eq ?| (char-after (point))))
- (save-excursion
- (or (eolp) (forward-char -1))
- (and (search-backward "|")
- (skip-chars-backward " \t\n")
- (and (not (eolp))
- (progn
- (forward-char -1)
- (not (looking-at "\\{")))
- (progn
- (forward-word -1)
- (not (looking-at "do\\>[^_]")))))))))
- (setq indent (+ indent ruby-indent-level)))))))
- indent)))
-
-(defun ruby-electric-brace (arg)
- (interactive "P")
- (self-insert-command (prefix-numeric-value arg))
- (ruby-indent-line t))
-
-(defun ruby-beginning-of-defun (&optional arg)
- "Move backward to next beginning-of-defun.
-With argument, do this that many times.
-Returns t unless search stops due to end of buffer."
- (interactive "p")
- (and (re-search-backward (concat "^\\(" ruby-block-beg-re "\\)\\b")
- nil 'move (or arg 1))
- (progn (beginning-of-line) t)))
-
-(defun ruby-beginning-of-indent ()
- (and (re-search-backward (concat "^\\(" ruby-indent-beg-re "\\)\\b")
- nil 'move)
- (progn
- (beginning-of-line)
- t)))
-
-(defun ruby-end-of-defun (&optional arg)
- "Move forward to next end of defun.
-An end of a defun is found by moving forward from the beginning of one."
- (interactive "p")
- (and (re-search-forward (concat "^\\(" ruby-block-end-re "\\)\\b[^_]")
- nil 'move (or arg 1))
- (progn (beginning-of-line) t))
- (forward-line 1))
-
-(defun ruby-move-to-block (n)
- (let (start pos done down)
- (setq start (ruby-calculate-indent))
- (if (eobp)
- nil
- (while (and (not (bobp)) (not done))
- (forward-line n)
- (cond
- ((looking-at "^$"))
- ((looking-at "^\\s *#"))
- (t
- (setq pos (current-indentation))
- (cond
- ((< start pos)
- (setq down t))
- ((and down (= pos start))
- (setq done t))
- ((> start pos)
- (setq done t)))))
- (if done
- (progn
- (back-to-indentation)
- (if (looking-at ruby-block-mid-re)
- (setq done nil)))))))
- (back-to-indentation))
-
-(defun ruby-beginning-of-block ()
- "Move backward to next beginning-of-block"
- (interactive)
- (ruby-move-to-block -1))
-
-(defun ruby-end-of-block ()
- "Move forward to next beginning-of-block"
- (interactive)
- (ruby-move-to-block 1))
-
-(defun ruby-reindent-then-newline-and-indent ()
- (interactive "*")
- (save-excursion
- (delete-region (point) (progn (skip-chars-backward " \t") (point))))
- (newline)
- (save-excursion
- (forward-line -1)
- (indent-according-to-mode))
- (indent-according-to-mode))
-
-(fset 'ruby-encomment-region (symbol-function 'comment-region))
-
-(defun ruby-decomment-region (beg end)
- (interactive "r")
- (save-excursion
- (goto-char beg)
- (while (re-search-forward "^\\([ \t]*\\)#" end t)
- (replace-match "\\1" nil nil)
- (save-excursion
- (ruby-indent-line)))))
-
-(defun ruby-insert-end ()
- (interactive)
- (insert "end")
- (ruby-indent-line t)
- (end-of-line))
-
-(cond
- ((featurep 'hilit19)
- (hilit-set-mode-patterns
- 'ruby-mode
- '(("[^$\\?]\\(\"[^\\\"]*\\(\\\\\\(.\\|\n\\)[^\\\"]*\\)*\"\\)" 1 string)
- ("[^$\\?]\\('[^\\']*\\(\\\\\\(.\\|\n\\)[^\\']*\\)*'\\)" 1 string)
- ("[^$\\?]\\(`[^\\`]*\\(\\\\\\(.\\|\n\\)[^\\`]*\\)*`\\)" 1 string)
- ("^\\s *#.*$" nil comment)
- ("[^$@?\\]\\(#[^$@{].*$\\)" 1 comment)
- ("[^a-zA-Z_]\\(\\?\\(\\\\[CM]-\\)*.\\)" 1 string)
- ("^\\s *\\(require\\|load\\).*$" nil include)
- ("^\\s *\\(include\\|alias\\|undef\\).*$" nil decl)
- ("^\\s *\\<\\(class\\|def\\|module\\)\\>" "[)\n;]" defun)
- ("[^_]\\<\\(begin\\|case\\|else\\|elsif\\|end\\|ensure\\|for\\|if\\|unless\\|rescue\\|then\\|when\\|while\\|until\\|do\\)\\>[^_]" 1 defun)
- ("[^_]\\<\\(and\\|break\\|next\\|raise\\|fail\\|in\\|not\\|or\\|redo\\|retry\\|return\\|super\\|yield\\|self\\|nil\\)\\>[^_]" 1 keyword)
- ("\\$\\(.\\|\\sw+\\)" nil type)
- ("[$@].[a-zA-Z_0-9]*" nil struct)
- ("^__END__" nil label))))
-
- ((featurep 'font-lock)
- (or (boundp 'font-lock-variable-name-face)
- (setq font-lock-variable-name-face font-lock-type-face))
- (defvar ruby-font-lock-keywords
- (list
- (cons (concat
- "\\(^\\|[^_]\\)\\b\\("
- (mapconcat
- 'identity
- '("alias"
- "and"
- "begin"
- "break"
- "case"
- "class"
- "do"
- "elsif"
- "else"
- "fail"
- "ensure"
- "for"
- "end"
- "if"
- "in"
- "module"
- "next"
- "not"
- "or"
- "raise"
- "redo"
- "rescue"
- "retry"
- "return"
- "then"
- "self"
- "super"
- "unless"
- "undef"
- "until"
- "when"
- "while"
- )
- "\\|")
- "\\)[ \n\t()]")
- 2)
- ;; variables
- '("\\(^\\|[^_]\\)\\b\\(nil\\|self\\|true\\|false\\)\\b[^_]"
- 2 font-lock-variable-name-face)
- ;; variables
- '("\\[$@].\\([a-zA-Z0-9_]\\)"
- 0 font-lock-variable-name-face)
- ;; constants
- '("\\(^\\|[^_]\\)\\b\\([A-Z]+[a-zA-Z0-9_]*\\)"
- 2 font-lock-type-face)
- ;; functions
- '("^\\s *def[ \t]+.*$"
- 0 font-lock-function-name-face))
- "*Additional expressions to highlight in ruby mode.")
- (if (and (>= (string-to-int emacs-version) 20)
- (not (featurep 'xemacs)))
- (add-hook
- 'ruby-mode-hook
- (lambda ()
- (make-local-variable 'font-lock-defaults)
- (setq font-lock-defaults
- '((ruby-font-lock-keywords) nil nil ((?\_ . "w"))))))
- (add-hook 'ruby-mode-hook
- (lambda ()
- (setq font-lock-keywords ruby-font-lock-keywords)
- (font-lock-mode 1))))))
diff --git a/sample/rubydb2x.el b/sample/rubydb2x.el
deleted file mode 100644
index a74265fb0e..0000000000
--- a/sample/rubydb2x.el
+++ /dev/null
@@ -1,104 +0,0 @@
-(require 'gud)
-(provide 'rubydb)
-
-;; ======================================================================
-;; rubydb functions
-
-;;; History of argument lists passed to rubydb.
-(defvar gud-rubydb-history nil)
-
-(defun gud-rubydb-massage-args (file args)
- (cons "-I" (cons "." (cons "-r" (cons "debug" (cons file args))))))
-
-;; There's no guarantee that Emacs will hand the filter the entire
-;; marker at once; it could be broken up across several strings. We
-;; might even receive a big chunk with several markers in it. If we
-;; receive a chunk of text which looks like it might contain the
-;; beginning of a marker, we save it here between calls to the
-;; filter.
-(defvar gud-rubydb-marker-acc "")
-
-(defun gud-rubydb-marker-filter (string)
- (save-match-data
- (setq gud-marker-acc (concat gud-marker-acc string))
- (let ((output ""))
-
- ;; Process all the complete markers in this chunk.
- (while (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
- gud-marker-acc)
- (setq
-
- ;; Extract the frame position from the marker.
- gud-last-frame
- (cons (substring gud-marker-acc (match-beginning 1) (match-end 1))
- (string-to-int (substring gud-marker-acc
- (match-beginning 2)
- (match-end 2))))
-
- ;; Append any text before the marker to the output we're going
- ;; to return - we don't include the marker in this text.
- output (concat output
- (substring gud-marker-acc 0 (match-beginning 0)))
-
- ;; Set the accumulator to the remaining text.
- gud-marker-acc (substring gud-marker-acc (match-end 0))))
-
- ;; Does the remaining text look like it might end with the
- ;; beginning of another marker? If it does, then keep it in
- ;; gud-marker-acc until we receive the rest of it. Since we
- ;; know the full marker regexp above failed, it's pretty simple to
- ;; test for marker starts.
- (if (string-match "\032.*\\'" gud-marker-acc)
- (progn
- ;; Everything before the potential marker start can be output.
- (setq output (concat output (substring gud-marker-acc
- 0 (match-beginning 0))))
-
- ;; Everything after, we save, to combine with later input.
- (setq gud-marker-acc
- (substring gud-marker-acc (match-beginning 0))))
-
- (setq output (concat output gud-marker-acc)
- gud-marker-acc ""))
-
- output)))
-
-(defun gud-rubydb-find-file (f)
- (find-file-noselect f))
-
-(defvar rubydb-command-name "ruby"
- "File name for executing ruby.")
-
-;;;###autoload
-(defun rubydb (command-line)
- "Run rubydb on program FILE in buffer *gud-FILE*.
-The directory containing FILE becomes the initial working directory
-and source-file directory for your debugger."
- (interactive
- (list (read-from-minibuffer "Run rubydb (like this): "
- (if (consp gud-rubydb-history)
- (car gud-rubydb-history)
- (concat rubydb-command-name " "))
- nil nil
- '(gud-rubydb-history . 1))))
-
- (gud-overload-functions '((gud-massage-args . gud-rubydb-massage-args)
- (gud-marker-filter . gud-rubydb-marker-filter)
- (gud-find-file . gud-rubydb-find-file)
- ))
- (gud-common-init command-line)
-
- (gud-def gud-break "b %l" "\C-b" "Set breakpoint at current line.")
-; (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
- (gud-def gud-step "s" "\C-s" "Step one source line with display.")
- (gud-def gud-next "n" "\C-n" "Step one line (skip functions).")
- (gud-def gud-cont "c" "\C-r" "Continue with display.")
- (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
- (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
- (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
- (gud-def gud-print "p %e" "\C-p" "Evaluate ruby expression at point.")
-
- (setq comint-prompt-regexp "^(rdb:-) ")
- (setq paragraph-start comint-prompt-regexp)
- (run-hooks 'rubydb-mode-hook)
- )
diff --git a/sample/rubydb3x.el b/sample/rubydb3x.el
deleted file mode 100644
index 9d4e31f90e..0000000000
--- a/sample/rubydb3x.el
+++ /dev/null
@@ -1,104 +0,0 @@
-(require 'gud)
-(provide 'rubydb)
-
-;; ======================================================================
-;; rubydb functions
-
-;;; History of argument lists passed to rubydb.
-(defvar gud-rubydb-history nil)
-
-(defun gud-rubydb-massage-args (file args)
- (cons "-r" (cons "debug" args)))
-
-;; There's no guarantee that Emacs will hand the filter the entire
-;; marker at once; it could be broken up across several strings. We
-;; might even receive a big chunk with several markers in it. If we
-;; receive a chunk of text which looks like it might contain the
-;; beginning of a marker, we save it here between calls to the
-;; filter.
-(defvar gud-rubydb-marker-acc "")
-
-(defun gud-rubydb-marker-filter (string)
- (setq gud-marker-acc (concat gud-marker-acc string))
- (let ((output ""))
-
- ;; Process all the complete markers in this chunk.
- (while (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
- gud-marker-acc)
- (setq
-
- ;; Extract the frame position from the marker.
- gud-last-frame
- (cons (substring gud-marker-acc (match-beginning 1) (match-end 1))
- (string-to-int (substring gud-marker-acc
- (match-beginning 2)
- (match-end 2))))
-
- ;; Append any text before the marker to the output we're going
- ;; to return - we don't include the marker in this text.
- output (concat output
- (substring gud-marker-acc 0 (match-beginning 0)))
-
- ;; Set the accumulator to the remaining text.
- gud-marker-acc (substring gud-marker-acc (match-end 0))))
-
- ;; Does the remaining text look like it might end with the
- ;; beginning of another marker? If it does, then keep it in
- ;; gud-marker-acc until we receive the rest of it. Since we
- ;; know the full marker regexp above failed, it's pretty simple to
- ;; test for marker starts.
- (if (string-match "\032.*\\'" gud-marker-acc)
- (progn
- ;; Everything before the potential marker start can be output.
- (setq output (concat output (substring gud-marker-acc
- 0 (match-beginning 0))))
-
- ;; Everything after, we save, to combine with later input.
- (setq gud-marker-acc
- (substring gud-marker-acc (match-beginning 0))))
-
- (setq output (concat output gud-marker-acc)
- gud-marker-acc ""))
-
- output))
-
-(defun gud-rubydb-find-file (f)
- (save-excursion
- (let ((buf (find-file-noselect f)))
- (set-buffer buf)
- (gud-make-debug-menu)
- buf)))
-
-(defvar rubydb-command-name "ruby"
- "File name for executing ruby.")
-
-;;;###autoload
-(defun rubydb (command-line)
- "Run rubydb on program FILE in buffer *gud-FILE*.
-The directory containing FILE becomes the initial working directory
-and source-file directory for your debugger."
- (interactive
- (list (read-from-minibuffer "Run rubydb (like this): "
- (if (consp gud-rubydb-history)
- (car gud-rubydb-history)
- (concat rubydb-command-name " "))
- nil nil
- '(gud-rubydb-history . 1))))
-
- (gud-common-init command-line 'gud-rubydb-massage-args
- 'gud-rubydb-marker-filter 'gud-rubydb-find-file)
-
- (gud-def gud-break "b %l" "\C-b" "Set breakpoint at current line.")
-; (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
- (gud-def gud-step "s" "\C-s" "Step one source line with display.")
- (gud-def gud-next "n" "\C-n" "Step one line (skip functions).")
- (gud-def gud-cont "c" "\C-r" "Continue with display.")
- (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
- (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
- (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
- (gud-def gud-print "p %e" "\C-p" "Evaluate ruby expression at point.")
-
- (setq comint-prompt-regexp "^(rdb:-) ")
- (setq paragraph-start comint-prompt-regexp)
- (run-hooks 'rubydb-mode-hook)
- )
diff --git a/sample/tkbiff.rb b/sample/tkbiff.rb
deleted file mode 100644
index d2d7bf7beb..0000000000
--- a/sample/tkbiff.rb
+++ /dev/null
@@ -1,149 +0,0 @@
-#! /usr/local/bin/ruby
-
-if ARGV[0] != '-d'
- unless $DEBUG
- exit if fork
- end
-else
- ARGV.shift
-end
-
-if ARGV.length == 0
- if ENV['MAIL']
- $spool = ENV['MAIL']
- else
- $spool = '/usr/spool/mail/' + ENV['USER']
- end
-else
- $spool = ARGV[0]
-end
-
-require "parsedate"
-require "base64"
-
-include ParseDate
-
-class Mail
- def Mail.new(f)
- if !f.kind_of?(IO)
- f = open(f, "r")
- me = super
- f.close
- else
- me = super
- end
- return me
- end
-
- def initialize(f)
- @header = {}
- @body = []
- while f.gets()
- $_.chop!
- next if /^From / # skip From-line
- break if /^$/ # end of header
- if /^(\S+):\s*(.*)/
- @header[attr = $1.capitalize] = $2
- elsif attr
- sub(/^\s*/, '')
- @header[attr] += "\n" + $_
- end
- end
-
- return if ! $_
-
- while f.gets()
- break if /^From /
- @body.push($_)
- end
- end
-
- def header
- return @header
- end
-
- def body
- return @body
- end
-
-end
-
-require "tkscrollbox"
-
-$top = TkRoot.new
-$top.withdraw
-$list = TkScrollbox.new($top) {
- relief 'raised'
- width 80
- height 8
- setgrid 'yes'
- pack
-}
-TkButton.new($top) {
- text 'Dismiss'
- command proc {$top.withdraw}
- pack('fill'=>'both','expand'=>'yes')
-}
-$top.bind "Control-c", proc{exit}
-$top.bind "Control-q", proc{exit}
-$top.bind "space", proc{exit}
-
-$spool_size = 0
-$check_time = Time.now
-
-def check
- $check_time = Time.now
- size = File.size($spool)
- if size and size != $spool_size
- $spool_size = size
- pop_up if size > 0
- end
- Tk.after 5000, proc{check}
-end
-
-if defined? Thread
- Thread.start do
- loop do
- sleep 600
- if Time.now - $check_time > 200
- Tk.after 5000, proc{check}
- end
- end
- end
-end
-
-def pop_up
- outcount = 0;
- $list.delete 0, 'end'
- f = open($spool, "r")
- while !f.eof?
- mail = Mail.new(f)
- date, from, subj = mail.header['Date'], mail.header['From'], mail.header['Subject']
- next if !date
- y = m = d = 0
- y, m, d = parsedate(date) if date
- from = "sombody@somewhere" if ! from
- subj = "(nil)" if ! subj
- from = decode_b(from)
- subj = decode_b(subj)
- $list.insert 'end', format('%-02d/%02d/%02d [%-28.28s] %s',y,m,d,from,subj)
- outcount += 1
- end
- f.close
- if outcount == 0
- $list.insert 'end', "You have no mail."
- else
- $list.see 'end'
- end
- $top.deiconify
- Tk.after 2000, proc{$top.withdraw}
-end
-
-$list.insert 'end', "You have no mail."
-check
-Tk.after 2000, proc{$top.withdraw}
-begin
- Tk.mainloop
-rescue
- `echo #$! > /tmp/tkbiff`
-end
diff --git a/sample/tkbrowse.rb b/sample/tkbrowse.rb
deleted file mode 100644
index d127996173..0000000000
--- a/sample/tkbrowse.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/local/bin/ruby
-#
-# This script generates a directory browser, which lists the working
-# directory and allows you to open files or subdirectories by
-# double-clicking.
-
-# Create a scrollbar on the right side of the main window and a listbox
-# on the left side.
-
-require "tkscrollbox"
-
-list = TkScrollbox.new {
- relief 'raised'
- width 20
- height 20
- setgrid 'yes'
- pack
-}
-
-# The procedure below is invoked to open a browser on a given file; if the
-# file is a directory then another instance of this program is invoked; if
-# the file is a regular file then the Mx editor is invoked to display
-# the file.
-
-def browse (dir, file)
- if dir != "."
- file="#{dir}/#{file}"
- if File.directory? file
- system "browse #{file} &"
- else
- if File.file? file
- if ENV['EDITOR']
- system format("%s %s&", ENV['EDITOR'], file)
- else
- sysmte "xedit #{file}&"
- end
- else
- STDERR.print "\"#{file}\" isn't a directory or regular file"
- end
- end
- end
-end
-
-# Fill the listbox with a list of all the files in the directory (run
-# the "ls" command to get that information).
-
-if ARGV.length>0
- dir = ARGV[0]
-else
- dir="."
-end
-list.insert 'end', *`ls #{dir}`.split
-
-# Set up bindings for the browser.
-
-list.focus
-list.bind "Control-q", proc{exit}
-list.bind "Control-c", proc{exit}
-list.bind "Control-p", proc{
- print "selection <", TkSelection.get, ">\n"
-}
-
-list.bind "Double-Button-1", proc{
- for i in TkSelection.get.split
- print "clicked ", i, "\n"
- browse dir, i
- end
-}
-Tk.mainloop
diff --git a/sample/tkdialog.rb b/sample/tkdialog.rb
deleted file mode 100644
index e83e16d0a8..0000000000
--- a/sample/tkdialog.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-#! /usr/local/bin/ruby
-require "tk"
-
-root = TkFrame.new
-top = TkFrame.new(root) {
- relief 'raised'
- border 1
-}
-msg = TkMessage.new(top) {
- text "File main.c hasn't been saved to disk since \
-it was last modified. What should I do?"
- justify 'center'
- aspect 200
- font '-Adobe-helvetica-medium-r-normal--*-240*'
- pack('padx'=>5, 'pady'=>5, 'expand'=>'yes')
-}
-top.pack('fill'=>'both')
-root.pack
-
-bot = TkFrame.new(root) {
- relief 'raised'
- border 1
-}
-
-TkFrame.new(bot) { |left|
- relief 'sunken'
- border 1
- pack('side'=>'left', 'expand'=>'yes', 'padx'=>10, 'pady'=> 10)
- TkButton.new(left) {
- text "Save File"
- command "quit 'save'"
- pack('expand'=>'yes','padx'=>6,'pady'=> 6)
- top.bind "Enter", proc{state 'active'}
- msg.bind "Enter", proc{state 'active'}
- bot.bind "Enter", proc{state 'active'}
- top.bind "Leave", proc{state 'normal'}
- msg.bind "Leave", proc{state 'normal'}
- bot.bind "Leave", proc{state 'normal'}
- Tk.root.bind "ButtonRelease-1", proc{quit 'save'}
- Tk.root.bind "Return", proc{quit 'save'}
- }
-}
-TkButton.new(bot) {
- text "Quit Anyway"
- command "quit 'quit'"
- pack('side'=>'left', 'expand'=>'yes', 'padx'=>10)
-}
-TkButton.new(bot) {
- text "Return To Editor"
- command "quit 'return'"
- pack('side'=>'left', 'expand'=>'yes', 'padx'=>10)
-}
-bot.pack
-root.pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes')
-
-def quit(button)
- print "aaa\n"
- print "You pressed the \"#{button}\" button; bye-bye!\n"
- exit
-end
-
-Tk.mainloop
diff --git a/sample/tkfrom.rb b/sample/tkfrom.rb
deleted file mode 100644
index b0ef8995ca..0000000000
--- a/sample/tkfrom.rb
+++ /dev/null
@@ -1,126 +0,0 @@
-#! /usr/local/bin/ruby
-
-require "parsedate"
-require "base64"
-
-include ParseDate
-
-class Mail
- def Mail.new(f)
- if !f.kind_of?(IO)
- f = open(f, "r")
- me = super(f)
- f.close
- else
- me = super
- end
- return me
- end
-
- def initialize(f)
- @header = {}
- @body = []
- while f.gets()
- $_.chop!
- next if /^From / # skip From-line
- break if /^$/ # end of header
- if /^(\S+):\s*(.*)/
- @header[attr = $1.capitalize] = $2
- elsif attr
- sub(/^\s*/, '')
- @header[attr] += "\n" + $_
- end
- end
-
- return if ! $_
-
- while f.gets()
- break if /^From /
- @body.push($_)
- end
- end
-
- def header
- return @header
- end
-
- def body
- return @body
- end
-
-end
-
-if ARGV.length == 0
- if ENV['MAIL']
- ARGV[0] = ENV['MAIL']
- elsif ENV['USER']
- ARGV[0] = '/usr/spool/mail/' + ENV['USER']
- elsif ENV['LOGNAME']
- ARGV[0] = '/usr/spool/mail/' + ENV['LOGNAME']
- end
-end
-
-require "tk"
-list = scroll = nil
-TkFrame.new{|f|
- list = TkListbox.new(f) {
- yscroll proc{|idx|
- scroll.set *idx
- }
- relief 'raised'
-# geometry "80x5"
- width 80
- height 5
- setgrid 'yes'
- pack('side'=>'left','fill'=>'both','expand'=>'yes')
- }
- scroll = TkScrollbar.new(f) {
- command proc{|idx|
- list.yview *idx
- }
- pack('side'=>'right','fill'=>'y')
- }
- pack
-}
-root = Tk.root
-TkButton.new(root) {
- text 'Dismiss'
- command proc {exit}
- pack('fill'=>'both','expand'=>'yes')
-}
-root.bind "Control-c", proc{exit}
-root.bind "Control-q", proc{exit}
-root.bind "space", proc{exit}
-
-$outcount = 0;
-for file in ARGV
- next if !File.exist?(file)
- f = open(file, "r")
- while !f.eof
- mail = Mail.new(f)
- date = mail.header['Date']
- next if !date
- from = mail.header['From']
- subj = mail.header['Subject']
- y = m = d = 0
- y, m, d = parsedate(date) if date
- from = "sombody@somewhere" if ! from
- subj = "(nil)" if ! subj
- from = decode_b(from)
- subj = decode_b(subj)
- list.insert 'end', format('%-02d/%02d/%02d [%-28.28s] %s',y,m,d,from,subj)
- $outcount += 1
- end
- f.close
- list.see 'end'
-end
-
-limit = 10000
-if $outcount == 0
- list.insert 'end', "You have no mail."
- limit = 2000
-end
-Tk.after limit, proc{
- exit
-}
-Tk.mainloop
diff --git a/sample/tkhello.rb b/sample/tkhello.rb
deleted file mode 100644
index 5188fe1c8c..0000000000
--- a/sample/tkhello.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require "tk"
-
-TkButton.new(nil,
- 'text' => 'hello',
- 'command' => proc{print "hello\n"}).pack('fill'=>'x')
-TkButton.new(nil,
- 'text' => 'quit',
- 'command' => 'exit').pack('fill'=>'x')
-
-Tk.mainloop
diff --git a/sample/tkline.rb b/sample/tkline.rb
deleted file mode 100644
index 63d763a680..0000000000
--- a/sample/tkline.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-
-$tk_thread_safe = TRUE
-require "tkclass"
-
-$tkline_init = FALSE
-def start_random
- return if $tkline_init
- $tkline_init = TRUE
- if defined? Thread
- Thread.start do
- loop do
- sleep 2
- Line.new($c, rand(400), rand(200), rand(400), rand(200))
- end
- end
- end
-end
-
-$c = Canvas.new
-$c.pack
-$start_x = start_y = 0
-
-def do_press(x, y)
- $start_x = x
- $start_y = y
- $current_line = Line.new($c, x, y, x, y)
- start_random
-end
-def do_motion(x, y)
- if $current_line
- $current_line.coords $start_x, $start_y, x, y
- end
-end
-
-def do_release(x, y)
- if $current_line
- $current_line.coords $start_x, $start_y, x, y
- $current_line.fill 'black'
- $current_line = nil
- end
-end
-
-$c.bind("1", proc{|e| do_press e.x, e.y})
-$c.bind("B1-Motion", proc{|x, y| do_motion x, y}, "%x %y")
-$c.bind("ButtonRelease-1", proc{|x, y| do_release x, y}, "%x %y")
-Tk.mainloop
diff --git a/sample/tktimer.rb b/sample/tktimer.rb
deleted file mode 100644
index 34377e2f39..0000000000
--- a/sample/tktimer.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/local/bin/ruby
-# This script generates a counter with start and stop buttons.
-
-require "tk"
-$label = TkLabel.new {
- text '0.00'
- relief 'raised'
- width 10
- pack('side'=>'bottom', 'fill'=>'both')
-}
-
-TkButton.new {
- text 'Start'
- command proc {
- if $stopped
- $stopped = FALSE
- tick
- end
- }
- pack('side'=>'left','fill'=>'both','expand'=>'yes')
-}
-TkButton.new {
- text 'Stop'
- command proc{
- exit if $stopped
- $stopped = TRUE
- }
- pack('side'=>'right','fill'=>'both','expand'=>'yes')
-}
-
-$seconds=0
-$hundredths=0
-$stopped=TRUE
-
-def tick
- if $stopped then return end
- Tk.after 50, proc{tick}
- $hundredths+=5
- if $hundredths >= 100
- $hundredths=0
- $seconds+=1
- end
- $label.text format("%d.%02d", $seconds, $hundredths)
-end
-
-root = Tk.root
-root.bind "Control-c", proc{root.destroy}
-root.bind "Control-q", proc{root.destroy}
-Tk.root.focus
-Tk.mainloop
diff --git a/sig.h b/sig.h
deleted file mode 100644
index ac4a4787f4..0000000000
--- a/sig.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/************************************************
-
- sig.h -
-
- $Author$
- $Date$
- created at: Wed Aug 16 01:15:38 JST 1995
-
-************************************************/
-#ifndef SIG_H
-#define SIG_H
-
-extern int trap_immediate;
-#define TRAP_BEG (trap_immediate=1)
-#define TRAP_END (trap_immediate=0)
-
-extern int prohibit_interrupt;
-#define DEFER_INTS {prohibit_interrupt++;}
-#define ALLOW_INTS {prohibit_interrupt--; CHECK_INTS;}
-#define ENABLE_INTS {prohibit_interrupt--;}
-
-extern int trap_pending;
-#ifdef THREAD
-extern int thread_critical;
-#if defined(HAVE_SETITIMER) && !defined(__BOW__)
-extern int thread_pending;
-void thread_schedule();
-# define CHECK_INTS if (!prohibit_interrupt) {\
- if (trap_pending) rb_trap_exec();\
- if (thread_pending && !thread_critical) thread_schedule();\
-}
-# else
-/* pseudo preemptive thread switching */
-extern int thread_tick;
-#define THREAD_TICK 500
-void thread_schedule();
-# define CHECK_INTS if (!prohibit_interrupt) {\
- if (trap_pending) rb_trap_exec();\
- if (!thread_critical) {\
- if (thread_tick-- <= 0) {\
- thread_tick = THREAD_TICK;\
- thread_schedule();\
- }\
- }\
-}
-# endif
-#else
-# define CHECK_INTS if (!prohibit_interrupt) {\
- if (trap_pending) rb_trap_exec();\
-}
-#endif
-
-#endif