mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
remove obsolete files
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
65a5162550
commit
942b2ba4b6
26 changed files with 0 additions and 7308 deletions
36
config.dj
36
config.dj
|
@ -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"
|
58
io.h
58
io.h
|
@ -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
|
|
@ -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
|
||||
|
326
lib/tkcanvas.rb
326
lib/tkcanvas.rb
|
@ -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
|
|
@ -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
|
528
lib/tkcore.rb
528
lib/tkcore.rb
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
164
lib/tktext.rb
164
lib/tktext.rb
|
@ -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
|
550
lib/tkthcore.rb
550
lib/tkthcore.rb
|
@ -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
|
2194
missing/nt.c
2194
missing/nt.c
File diff suppressed because it is too large
Load diff
362
missing/nt.h
362
missing/nt.h
|
@ -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
|
149
missing/setenv.c
149
missing/setenv.c
|
@ -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 */
|
|
@ -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))))))
|
|
@ -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)
|
||||
)
|
|
@ -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)
|
||||
)
|
149
sample/tkbiff.rb
149
sample/tkbiff.rb
|
@ -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
|
|
@ -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
|
|
@ -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
|
126
sample/tkfrom.rb
126
sample/tkfrom.rb
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
53
sig.h
53
sig.h
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue