• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Ruby GTK3移行後のメインリポジトリ


Commit MetaInfo

修訂eef9739562994265a5048384b2229731395e5465 (tree)
時間2017-03-25 19:55:45
作者Shyouzou Sugitani <shy@user...>
CommiterShyouzou Sugitani

Log Message

coding style cleanup and misc fixes

Change Summary

差異

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
1+Sat March 25 2017 Shyouzou Sugitani <shy@users.osdn.me>
2+ * Copyrightを2017年に更新した.
3+ * Rubyらしいコーディングスタイルへの修正.
4+ * HolonとMemeクラスを拡張.
5+
16 Sun December 11 2016 Shyouzou Sugitani <shy@users.osdn.me>
27 * Rubyらしいコーディングスタイルへの修正.
38 * Makotoクラスのテストをtest-makoto.rbに移動.
--- a/lib/ninix/alias.rb
+++ b/lib/ninix/alias.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
4-# Copyright (C) 2004-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2004-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/balloon.rb
+++ b/lib/ninix/balloon.rb
@@ -2,7 +2,7 @@
22 #
33 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
44 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
5-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
5+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
66 # Copyright (C) 2003 by Shun-ichi TAHARA <jado@flowernet.gr.jp>
77 #
88 # This program is free software; you can redistribute it and/or modify it
@@ -16,15 +16,18 @@
1616 require "gtk3"
1717
1818 require_relative "pix"
19-
19+require_relative "metamagic"
2020
2121 module Balloon
2222
23- class Balloon
23+ class Balloon < MetaMagic::Holon
2424 attr_accessor :window, :user_interaction
2525
2626 def initialize
27- @parent = nil
27+ super("") # FIXME
28+ @handlers = {
29+ 'reset_user_interaction' => 'reset_user_interaction',
30+ }
2831 @synchronized = []
2932 @user_interaction = false
3033 @window = []
@@ -42,24 +45,6 @@ module Balloon
4245 @passwordinputbox.set_responsible(self)
4346 end
4447
45- def set_responsible(parent)
46- @parent = parent
47- end
48-
49- def handle_request(event_type, event, *arglist)
50- fail "assert" unless ['GET', 'NOTIFY'].include?(event_type)
51- handlers = {
52- 'reset_user_interaction' => 'reset_user_interaction',
53- }
54- unless handlers.include?(event)
55- result = @parent.handle_request(
56- event_type, event, *arglist)
57- else
58- result = method(handlers[event]).call(*arglist)
59- end
60- return result if event_type == 'GET'
61- end
62-
6348 def reset_user_interaction
6449 @user_interaction = false
6550 end
--- a/lib/ninix/communicate.rb
+++ b/lib/ninix/communicate.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # communicate.rb - ghost-to-ghost communication mechanism
4-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
66 #
77 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/config.rb
+++ b/lib/ninix/config.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
4-# Copyright (C) 2003-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2003-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/dll.rb
+++ b/lib/ninix/dll.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # dll.rb - a pseudo DLL (SHIORI/SAORI API support) module for ninix
4-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
66 #
77 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/dll/aya.rb
+++ b/lib/ninix/dll/aya.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # aya.rb - an aya.dll compatible Shiori module for ninix
4-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
66 #
77 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/dll/aya5.rb
+++ b/lib/ninix/dll/aya5.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # aya5.rb - an aya.dll(Ver.5) compatible Shiori module for ninix
4-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
66 #
77 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/dll/bln.rb
+++ b/lib/ninix/dll/bln.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # bln.rb - a easyballoon compatible Saori module for ninix
4-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/dll/gomi.rb
+++ b/lib/ninix/dll/gomi.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # gomi.rb - a gomi.dll compatible Saori module for ninix
4-# Copyright (C) 2012-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2012-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/dll/hanayu.rb
+++ b/lib/ninix/dll/hanayu.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # hanayu.rb - a "花柚" compatible Saori module for ninix
4-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
66 #
77 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/dll/httpc.rb
+++ b/lib/ninix/dll/httpc.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # httpc.rb - a HTTPC compatible Saori module for ninix
4-# Copyright (C) 2011-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2011-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/dll/kawari.rb
+++ b/lib/ninix/dll/kawari.rb
@@ -3,7 +3,7 @@
33 # kawari.rb - a "華和梨" compatible Shiori module for ninix
44 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
6-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
6+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
77 # Copyright (C) 2003 by Shun-ichi TAHARA <jado@flowernet.gr.jp>
88 #
99 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/dll/kawari8.rb
+++ b/lib/ninix/dll/kawari8.rb
@@ -2,7 +2,7 @@
22 #
33 # kawari8.rb - a (Real) 華和梨 loader for ninix
44 # Copyright (C) 2002, 2003 by ABE Hideaki <abe-xx@eos.dricas.com>
5-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.sourceforge.jp>
5+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.sourceforge.jp>
66 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
77 #
88 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/dll/mciaudio.rb
+++ b/lib/ninix/dll/mciaudio.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # mciaudio.rb - a MCIAUDIO compatible Saori module for ninix
4-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
66 #
77 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/dll/mciaudior.rb
+++ b/lib/ninix/dll/mciaudior.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # mciaudior.rb - a MCIAUDIOR compatible Saori module for ninix
4-# Copyright (C) 2003-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2003-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 # Copyright (C) 2003 by MATSUMURA Namihiko <nie@counterghost.net>
66 #
77 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/dll/misaka.rb
+++ b/lib/ninix/dll/misaka.rb
@@ -3,7 +3,7 @@
33 # misaka.rb - a "美坂" compatible Shiori module for ninix
44 # Copyright (C) 2002 by Tamito KAJIYAMA
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
6-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
6+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
77 #
88 # This program is free software; you can redistribute it and/or modify it
99 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/dll/niseshiori.rb
+++ b/lib/ninix/dll/niseshiori.rb
@@ -3,7 +3,7 @@
33 # niseshiori.rb - a "偽栞" compatible Shiori module for ninix
44 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
6-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
6+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
77 # Copyright (C) 2003 by Shun-ichi TAHARA <jado@flowernet.gr.jp>
88 #
99 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/dll/osuwari.rb
+++ b/lib/ninix/dll/osuwari.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # osuwari.rb - a Osuwari compatible Saori module for ninix
4-# Copyright (C) 2006-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2006-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/dll/saori_cpuid.rb
+++ b/lib/ninix/dll/saori_cpuid.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # saori_cpuid.rb - a saori_cpuid compatible Saori module for ninix
4-# Copyright (C) 2003-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2003-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/dll/satori.rb
+++ b/lib/ninix/dll/satori.rb
@@ -3,7 +3,7 @@
33 # satori.rb - a "里々" compatible Shiori module for ninix
44 # Copyright (C) 2002 by Tamito KAJIYAMA
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
6-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
6+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
77 # Copyright (C) 2003, 2004 by Shun-ichi TAHARA <jado@flowernet.gr.jp>
88 #
99 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/dll/ssu.rb
+++ b/lib/ninix/dll/ssu.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # ssu.rb - a ssu compatible Saori module for ninix
4-# Copyright (C) 2003-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2003-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/dll/textcopy.rb
+++ b/lib/ninix/dll/textcopy.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # textcopy.rb - a TEXTCOPY compatible Saori module for ninix
4-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
66 #
77 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/dll/wmove.rb
+++ b/lib/ninix/dll/wmove.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # wmove.rb - a wmove.dll compatible Saori module for ninix
4-# Copyright (C) 2003-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2003-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/dll/yaya.rb
+++ b/lib/ninix/dll/yaya.rb
@@ -2,7 +2,7 @@
22 #
33 # yaya.rb - a (Real) YAYA loader for ninix
44 # Copyright (C) 2004 by linjian
5-# Copyright (C) 2004-2016 by Shyouzou Sugitani <shy@users.sourceforge.jp>
5+# Copyright (C) 2004-2017 by Shyouzou Sugitani <shy@users.sourceforge.jp>
66 # Copyright (C) 2011 by henryhu
77 #
88 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/entry_db.rb
+++ b/lib/ninix/entry_db.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
4-# Copyright (C) 2004-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2004-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/home.rb
+++ b/lib/ninix/home.rb
@@ -2,7 +2,7 @@
22 #
33 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
44 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
5-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
5+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
66 #
77 # This program is free software; you can redistribute it and/or modify it
88 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/install.rb
+++ b/lib/ninix/install.rb
@@ -3,7 +3,7 @@
33 # install.rb - an installer module for ninix
44 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
6-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
6+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
77 # Copyright (C) 2003 by Shun-ichi TAHARA <jado@flowernet.gr.jp>
88 #
99 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/keymap.rb
+++ b/lib/ninix/keymap.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # Copyright (C) 2002 by Tamito KAJIYAMA
4-# Copyright (C) 2003-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2003-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/kinoko.rb
+++ b/lib/ninix/kinoko.rb
@@ -1,6 +1,6 @@
11 # -*- coding: utf-8 -*-
22 #
3-# Copyright (C) 2004-2016 by Shyouzou Sugitani <shy@users.osdn.me>
3+# Copyright (C) 2004-2017 by Shyouzou Sugitani <shy@users.osdn.me>
44 #
55 # This program is free software; you can redistribute it and/or modify it
66 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/lock.rb
+++ b/lib/ninix/lock.rb
@@ -1,6 +1,6 @@
11 # -*- coding: utf-8 -*-
22 #
3-# Copyright (C) 2011-2016 by Shyouzou Sugitani <shy@users.osdn.me>
3+# Copyright (C) 2011-2017 by Shyouzou Sugitani <shy@users.osdn.me>
44 #
55 # This program is free software; you can redistribute it and/or modify it
66 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/logging.rb
+++ b/lib/ninix/logging.rb
@@ -1,6 +1,6 @@
11 # -*- coding: utf-8 -*-
22 #
3-# Copyright (C) 2015, 2016 by Shyouzou Sugitani <shy@users.osdn.me>
3+# Copyright (C) 2015-2017 by Shyouzou Sugitani <shy@users.osdn.me>
44 #
55 # This program is free software; you can redistribute it and/or modify it
66 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/makoto.rb
+++ b/lib/ninix/makoto.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
4-# Copyright (C) 2004-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2004-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/menu.rb
+++ b/lib/ninix/menu.rb
@@ -1,6 +1,6 @@
11 # -*- coding: utf-8 -*-
22 #
3-# Copyright (C) 2003-2016 by Shyouzou Sugitani <shy@users.osdn.me>
3+# Copyright (C) 2003-2017 by Shyouzou Sugitani <shy@users.osdn.me>
44 # Copyright (C) 2003 by Shun-ichi TAHARA <jado@flowernet.gr.jp>
55 #
66 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/metamagic.rb
+++ b/lib/ninix/metamagic.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # metamagic.rb - unknown unknowns
4-# Copyright (C) 2011-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2011-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
@@ -19,6 +19,27 @@ module MetaMagic
1919 @key = key
2020 @baseinfo = nil
2121 @menuitem = nil
22+ @parent = nil
23+ @handlers = {}
24+ end
25+
26+ def set_responsible(parent)
27+ @parent = parent
28+ end
29+
30+ def handle_request(event_type, event, *arglist)
31+ fail "assert" unless ['GET', 'NOTIFY'].include?(event_type)
32+ unless @handlers.include?(event)
33+ if self.class.method_defined?(event)
34+ result = method(event).call(*arglist)
35+ else
36+ result = @parent.handle_request(
37+ event_type, event, *arglist)
38+ end
39+ else
40+ result = method(@handlers[event]).call(*arglist)
41+ end
42+ return result if event_type == 'GET'
2243 end
2344
2445 def create_menuitem(data)
@@ -62,8 +83,28 @@ module MetaMagic
6283 @baseinfo = nil
6384 @menuitem = nil
6485 @instance = nil
86+ @parent = nil
87+ end
88+
89+ def set_responsible(parent)
90+ @parent = parent
6591 end
6692
93+ def handle_request(event_type, event, *arglist)
94+ fail "assert" unless ['GET', 'NOTIFY'].include?(event_type)
95+ unless @handlers.include?(event)
96+ if self.class.method_defined?(event)
97+ result = method(event).call(*arglist)
98+ else
99+ result = @parent.handle_request(
100+ event_type, event, *arglist)
101+ end
102+ else
103+ result = method(@handlers[event]).call(*arglist)
104+ end
105+ return result if event_type == 'GET'
106+ end
107+
67108 def create_menuitem(data)
68109 nil
69110 end
--- a/lib/ninix/nekodorif.rb
+++ b/lib/ninix/nekodorif.rb
@@ -1,6 +1,6 @@
11 # -*- coding: utf-8 -*-
22 #
3-# Copyright (C) 2004-2016 by Shyouzou Sugitani <shy@users.osdn.me>
3+# Copyright (C) 2004-2017 by Shyouzou Sugitani <shy@users.osdn.me>
44 #
55 # This program is free software; you can redistribute it and/or modify it
66 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/ngm.rb
+++ b/lib/ninix/ngm.rb
@@ -1,7 +1,7 @@
11 # -*- coding: utf-8 -*-
22 #
33 # Copyright (C) 2001-2004 by MATSUMURA Namihiko <nie@counterghost.net>
4-# Copyright (C) 2004-2016 by Shyouzou Sugitani <shy@users.osdn.me>
4+# Copyright (C) 2004-2017 by Shyouzou Sugitani <shy@users.osdn.me>
55 #
66 # This program is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/pix.rb
+++ b/lib/ninix/pix.rb
@@ -1,6 +1,6 @@
11 # -*- coding: utf-8 -*-
22 #
3-# Copyright (C) 2003-2016 by Shyouzou Sugitani <shy@users.osdn.me>
3+# Copyright (C) 2003-2017 by Shyouzou Sugitani <shy@users.osdn.me>
44 #
55 # This program is free software; you can redistribute it and/or modify it
66 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/prefs.rb
+++ b/lib/ninix/prefs.rb
@@ -2,7 +2,7 @@
22 #
33 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
44 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
5-# Copyright (C) 2004-2016 by Shyouzou Sugitani <shy@users.osdn.me>
5+# Copyright (C) 2004-2017 by Shyouzou Sugitani <shy@users.osdn.me>
66 # Copyright (C) 2003-2005 by Shun-ichi TAHARA <jado@flowernet.gr.jp>
77 #
88 # This program is free software; you can redistribute it and/or modify it
--- a/lib/ninix/sakura.rb
+++ b/lib/ninix/sakura.rb
@@ -2,7 +2,7 @@
22 #
33 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
44 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
5-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
5+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
66 # Copyright (C) 2003 by Shun-ichi TAHARA <jado@flowernet.gr.jp>
77 #
88 # This program is free software; you can redistribute it and/or modify it
@@ -40,11 +40,6 @@ module Sakura
4040
4141 def initialize(key)
4242 super(key)
43- @parent = nil
44- end
45-
46- def set_responsible(parent)
47- @parent = parent
4843 end
4944
5045 def create_menuitem(data)
@@ -66,7 +61,7 @@ module Sakura
6661 end
6762 end
6863
69- class Sakura
64+ class Sakura < MetaMagic::Holon
7065 attr_reader :key, :cantalk, :last_script
7166
7267 include GetText
@@ -88,7 +83,10 @@ module Sakura
8883 FROM_GHOST = 2
8984
9085 def initialize
91- @parent = nil
86+ super("") # FIXME
87+ @handlers = {
88+ 'lock_repaint' => "get_lock_repaint"
89+ }
9290 @sstp_handle = nil
9391 @sstp_entry_db = nil
9492 @sstp_request_handler = nil
@@ -160,28 +158,6 @@ module Sakura
160158 @reload_event = nil
161159 end
162160
163- def set_responsible(parent)
164- @parent = parent
165- end
166-
167- def handle_request(event_type, event, *arglist)
168- fail "assert" unless ['GET', 'NOTIFY'].include?(event_type)
169- handlers = {
170- 'lock_repaint' => "get_lock_repaint"
171- }
172- unless handlers.include?(event)
173- if Sakura.method_defined?(event)
174- result = method(event).call(*arglist)
175- else
176- result = @parent.handle_request(
177- event_type, event, *arglist)
178- end
179- else
180- result = method(handlers[event]).call(*arglist)
181- end
182- return result if event_type == 'GET'
183- end
184-
185161 def get_lock_repaint(*args)
186162 @lock_repaint
187163 end
@@ -2076,7 +2052,7 @@ module Sakura
20762052 def __yen__b(args)
20772053 begin
20782054 filename, x, y = expand_meta(args[0]).split(',', 3)
2079- rescue ArgumentError
2055+ rescue ArgumentError ## FIXME: no exception in Ruby
20802056 filename, param = expand_meta(args[0]).split(',', 2)
20812057 raise "assert" unless param == 'inline'
20822058 x, y = 0, 0 ## FIXME
@@ -2380,6 +2356,7 @@ module Sakura
23802356 'NOTIFY', 'select_ghost_by_name', self, args[2], :event => 0)
23812357 end
23822358 elsif args[0, 2] == ['call', 'ghost'] and argc > 2
2359+ ## FIXME: 'random', 'lastinstalled'対応
23832360 key = @parent.handle_request('GET', 'find_ghost_by_name', args[2])
23842361 unless key.nil?
23852362 @parent.handle_request('NOTIFY', 'start_sakura_cb', key, :caller => self)
@@ -2470,7 +2447,7 @@ module Sakura
24702447 when '!stayontop'
24712448 @surface.window_stayontop(false)
24722449 end
2473- elsif args[0, 2] == ['set', 'trayicon'] and argc > 2
2450+ elsif args[0, 2] == ['set', 'trayicon'] and argc > 2 ## FIXME: tasktrayicon
24742451 path = File.join(get_prefix(), args[2])
24752452 if File.exist?(path)
24762453 @status_icon.set_from_file(path) # XXX
@@ -2604,9 +2581,9 @@ module Sakura
26042581 elsif args[0] == '*'
26052582 @balloon.append_sstp_marker(@script_side)
26062583 elsif args[0] == 'quicksession' and argc > 1
2607- if args[1] == 'true'
2584+ if args[1] == 'true' ## FIXME: '1'でも可
26082585 @quick_session = true
2609- elsif args[1] == 'false'
2586+ elsif args[1] == 'false' ## FIXME: '0'でも可
26102587 @quick_session = false
26112588 else
26122589 #pass ## FIXME
--- a/lib/ninix/script.rb
+++ b/lib/ninix/script.rb
@@ -2,7 +2,7 @@
22 #
33 # script.rb - a Sakura Script parser
44 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
5-# Copyright (C) 2004-2016 by Shyouzou Sugitani <shy@users.osdn.me>
5+# Copyright (C) 2004-2017 by Shyouzou Sugitani <shy@users.osdn.me>
66 #
77 # This program is free software; you can redistribute it and/or modify it
88 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/seriko.rb
+++ b/lib/ninix/seriko.rb
@@ -2,7 +2,7 @@
22 #
33 # Copyright (C) 2002 by Tamito KAJIYAMA
44 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
5-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
5+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
66 #
77 # This program is free software; you can redistribute it and/or modify it
88 # under the terms of the GNU General Public License (version 2) as
@@ -14,17 +14,18 @@
1414
1515 require "gtk3"
1616
17+require_relative "metamagic"
1718 require_relative "logging"
1819
1920 module Seriko
2021
21- class Controller
22+ class Controller < MetaMagic::Holon
2223
2324 DEFAULT_FPS = 30.0 # current default
2425
2526 def initialize(seriko)
27+ super("") # FIXME
2628 @seriko = seriko
27- @parent = nil
2829 @exclusive_actor = nil
2930 @base_id = nil
3031 @timeout_id = nil
@@ -38,10 +39,6 @@ module Seriko
3839 @dirty = true
3940 end
4041
41- def set_responsible(parent)
42- @parent = parent
43- end
44-
4542 def set_base_id(window, surface_id)
4643 case surface_id
4744 when '-2'
@@ -131,12 +128,16 @@ module Seriko
131128 end
132129
133130 def remove_overlay(actor)
134- @dirty = true if @overlays.delete(actor)
131+ @dirty = true unless @overlays.delete(actor).nil?
135132 end
136133
137134 def add_overlay(window, actor, surface_id, x, y, method)
138- terminate(window) if surface_id == '-2'
139- if ['-1', '-2'].include?(surface_id)
135+ case surface_id
136+ when '-2'
137+ terminate(window)
138+ remove_overlay(actor)
139+ return
140+ when '-1'
140141 remove_overlay(actor)
141142 return
142143 end
--- a/lib/ninix/sstp.rb
+++ b/lib/ninix/sstp.rb
@@ -2,7 +2,7 @@
22 #
33 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
44 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
5-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
5+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
66 #
77 # This program is free software; you can redistribute it and/or modify it
88 # under the terms of the GNU General Public License (version 2) as
@@ -52,7 +52,7 @@ module SSTP
5252 def send_response(code, data: nil)
5353 begin
5454 @request_handler.send_response(code)
55- @request_handler.write(data) if not data.nil? # FIXME
55+ @request_handler.write(data) unless data.nil? # FIXME
5656 @request_handler.shutdown(Socket::SHUT_WR) # XXX
5757 rescue
5858 #pass
@@ -62,7 +62,7 @@ module SSTP
6262
6363 def send_answer(value)
6464 charset = @request_handler.get_charset
65- answer = [value.encode(charset, :invalid => :replace, :undef => :replace), "\r\n\r\n"].join("")
65+ answer = "#{value.encode(charset, :invalid => :replace, :undef => :replace)}\r\n\r\n"
6666 send_response(200, :data => answer) # OK
6767 end
6868
@@ -87,11 +87,10 @@ module SSTP
8787 class SSTPRequestHandler < SSTPLib::BaseSSTPRequestHandler
8888
8989 def handle(line)
90- if not @server.handle_request('GET', 'get_sakura_cantalk')
91- @error = @version = nil
92- if not parse_request(line)
93- return
94- end
90+ unless @server.handle_request('GET', 'get_sakura_cantalk')
91+ @error = nil
92+ @version = nil
93+ return unless parse_request(line)
9594 send_error(512)
9695 else
9796 super(line)
@@ -120,32 +119,24 @@ module SSTP
120119 end
121120
122121 def handle_send(version)
123- if not check_decoder()
124- return
125- end
122+ return unless check_decoder()
126123 sender = get_sender()
127- if sender.nil?
128- return
129- end
130- if version == 1.3
124+ return if sender.nil?
125+ case version
126+ when 1.3
131127 handle = get_handle()
132- if handle.nil?
133- return
134- end
128+ return if handle.nil?
135129 else
136130 handle = nil
137131 end
138132 script_odict = get_script_odict()
139- if script_odict.nil?
140- return
141- end
142- if [1.0, 1.1].include?(version)
133+ return if script_odict.nil?
134+ case version
135+ when 1.0, 1.1
143136 entry_db = nil
144- elsif [1.2, 1.3, 1.4].include?(version)
137+ when 1.2, 1.3, 1.4
145138 entry_db = get_entry_db()
146- if entry_db.nil?
147- return
148- end
139+ return if entry_db.nil?
149140 end
150141 enqueue_request(sender, nil, handle, script_odict, entry_db)
151142 end
@@ -161,28 +152,19 @@ module SSTP
161152
162153 def handle_notify(version)
163154 script_odict = {}
164- if not check_decoder()
165- return
166- end
155+ return unless check_decoder()
167156 sender = get_sender()
168- if sender.nil?
169- return
170- end
157+ return if sender.nil?
171158 event = get_event()
172- if event.nil?
173- return
174- end
175- if version == 1.0
159+ return if event.nil?
160+ case version
161+ when 1.0
176162 entry_db = nil
177- elsif version == 1.1
163+ when 1.1
178164 script_odict = get_script_odict()
179- if script_odict.nil?
180- return
181- end
165+ return if script_odict.nil?
182166 entry_db = get_entry_db()
183- if entry_db.nil?
184- return
185- end
167+ return if entry_db.nil?
186168 end
187169 enqueue_request(sender, event, nil, script_odict, entry_db)
188170 end
@@ -214,7 +196,7 @@ module SSTP
214196 PROHIBITED_TAGS = ['\j', '\-', '\+', '\_+', '\!', '\8', '\_v', '\C']
215197
216198 def check_script(script)
217- if not local_request()
199+ unless local_request()
218200 parser = Script::Parser.new
219201 nodes = []
220202 while true
@@ -227,11 +209,11 @@ module SSTP
227209 break
228210 end
229211 end
230- for node in nodes
231- if node[0] == Script::SCRIPT_TAG and \
232- PROHIBITED_TAGS.include?(node[1])
212+ nodes.each do |node|
213+ next unless node[0] == Script::SCRIPT_TAG
214+ if PROHIBITED_TAGS.include?(node[1])
233215 send_response(400) # Bad Request
234- log_error('Script: tag ' + node[1].to_s + ' not allowed')
216+ log_error("Script: tag #{node[1]} not allowed")
235217 return true
236218 end
237219 end
@@ -242,25 +224,19 @@ module SSTP
242224 def get_script_odict
243225 script_odict = {} # Ordered Hash
244226 if_ghost = nil
245- for item in @headers
246- name, value = item
247- if name != 'Script'
248- if name == ('IfGhost')
249- if_ghost = value
250- else
251- if_ghost = nil
252- end
227+ @headers.each do |name, value|
228+ case name
229+ when 'IfGhost'
230+ if_ghost = value
231+ when 'Script'
232+ # nop
233+ else
234+ if_ghost = nil
253235 next
254236 end
255237 script = value.to_s
256- if check_script(script)
257- return
258- end
259- if if_ghost.nil?
260- script_odict[''] = script
261- else
262- script_odict[if_ghost] = script
263- end
238+ return if check_script(script)
239+ script_odict[if_ghost || ''] = script
264240 if_ghost = nil
265241 end
266242 return script_odict
@@ -268,50 +244,36 @@ module SSTP
268244
269245 def get_entry_db
270246 entry_db = EntryDB::EntryDatabase.new
271- for item in @headers
272- key, value = item
273- if key == "Entry"
274- entry = value.split(',', 2)
275- if entry.length != 2
276- send_response(400) # Bad Request
277- return nil
278- end
279- entry_db.add(entry[0].strip(), entry[1].strip())
247+ @headers.each do |key, value|
248+ next unless key == "Entry"
249+ entry = value.split(',', 2)
250+ if entry.length != 2
251+ send_response(400) # Bad Request
252+ return nil
280253 end
254+ entry_db.add(entry[0].strip(), entry[1].strip())
281255 end
282256 return entry_db
283257 end
284258
285259 def get_event
286- if not @headers.assoc("Event").nil?
287- event = @headers.reverse.assoc("Event")[1]
288- else
289- event = nil
290- end
260+ event = @headers.reverse.assoc("Event")&.at(1)
291261 if event.nil?
292262 send_response(400) # Bad Request
293263 log_error('Event: header field not found')
294264 return nil
295265 end
296266 buf = [event]
297- for i in 0..7
298- key = ['Reference', i.to_s].join("")
299- if not @headers.assoc(key).nil?
300- value = @headers.reverse.assoc(key)[1]
301- else
302- value = nil
303- end
267+ (0..7).each do |i|
268+ key = "Reference#{i}"
269+ value = @headers.reverse.assoc(key)&.at(1)
304270 buf << value
305271 end
306272 return buf
307273 end
308274
309275 def get_sender
310- if not @headers.assoc('Sender').nil?
311- sender = @headers.reverse.assoc('Sender')[1]
312- else
313- sender = nil
314- end
276+ sender = @headers.reverse.assoc('Sender')&.at(1)
315277 if sender.nil?
316278 send_response(400) # Bad Request
317279 log_error('Sender: header field not found')
@@ -321,11 +283,7 @@ module SSTP
321283 end
322284
323285 def get_handle
324- if not @headers.assoc("HWnd").nil?
325- path = @headers.assoc("HWnd")[1]
326- else
327- path = nil
328- end
286+ path = @headers.assoc("HWnd")&.at(1)
329287 if path.nil?
330288 send_response(400) # Bad Request
331289 log_error('HWnd: header field not found')
@@ -347,40 +305,27 @@ module SSTP
347305 end
348306
349307 def get_charset
350- if not @headers.assoc('Charset').nil?
351- charset = @headers.reverse.assoc('Charset')[1] # XXX
352- else
353- charset = 'Shift_JIS'
354- end
355- return charset
308+ @headers.reverse.assoc('Charset')&.at(1) || 'Shift_JIS' # XXX
356309 end
357310
358311 def check_decoder
359- if not @headers.assoc('Charset').nil?
360- charset = @headers.reverse.assoc('Charset')[1] # XXX
361- else
362- charset = 'Shift_JIS'
363- end
364- if not Encoding.name_list.include?(charset)
365- send_response(420, :data => 'Refuse (unsupported charset)')
366- log_error('Unsupported charset ' + charset.to_s)
367- else
368- return true
369- end
312+ charset = get_charset
313+ return true if Encoding.name_list.include?(charset)
314+ send_response(420, :data => 'Refuse (unsupported charset)')
315+ log_error("Unsupported charset #{charset}")
370316 return false
371317 end
372318
373319 def get_options
374320 show_sstp_marker = use_translator = true
375- if not @headers.assoc("Option").nil?
376- options = @headers.reverse.assoc("Option")[1].split(",", 0)
377- for option in options
378- option = option.strip()
379- if option == 'nodescript' and local_request()
380- show_sstp_marker = false
381- elsif option == 'notranslate'
382- use_translator = false
383- end
321+ options = (@headers.reverse.assoc("Option")&.at(1) || "").split(",", 0)
322+ options.each do |option|
323+ option = option.strip()
324+ case option
325+ when 'nodescript'
326+ show_sstp_marker = false if local_request()
327+ when 'notranslate'
328+ use_translator = false
384329 end
385330 end
386331 return show_sstp_marker, use_translator
@@ -401,11 +346,10 @@ module SSTP
401346 end
402347
403348 def do_EXECUTE_1_3
404- if not local_request()
349+ unless local_request()
405350 sock_domain, remote_port, remote_hostname, remote_ip = @fp.peeraddr
406351 send_response(420)
407- log_error(
408- 'Unauthorized EXECUTE/1.3 request from ' + remote_hostname)
352+ log_error("Unauthorized EXECUTE/1.3 request from #{remote_hostname}")
409353 return
410354 end
411355 handle_command()
@@ -420,66 +364,62 @@ module SSTP
420364 end
421365
422366 def handle_command
423- if not check_decoder()
424- return
425- end
367+ return unless check_decoder()
426368 sender = get_sender()
427- if sender.nil?
428- return
429- end
369+ return if sender.nil?
430370 command = get_command()
431- if not @headers.assoc('Charset').nil?
432- charset = @headers.reverse.assoc('Charset')[1] # XXX
433- else
434- charset = 'Shift_JIS'
435- end
371+ charset = get_charset
436372 charset = charset.to_s
437- if command.nil?
373+ case command
374+ when nil
438375 return
439- elsif command == 'getname'
376+ when 'getname'
440377 send_response(200)
441378 name = @server.handle_request('GET', 'get_ghost_name')
442- @fp.write([name.encode(charset, :invalid => :replace, :undef => :replace),
443- "\r\n"].join(""))
379+ @fp.write(name.encode(
380+ charset, :invalid => :replace, :undef => :replace))
444381 @fp.write("\r\n")
445- elsif command == 'getversion'
382+ @fp.write("\r\n")
383+ when 'getversion'
446384 send_response(200)
447- @fp.write(["ninix-aya ",
448- Version.VERSION.encode(charset, :invalid => :replace, :undef => :replace),
449- "\r\n"].join(""))
385+ @fp.write("ninix-aya ")
386+ @fp.write(Version.VERSION.encode(
387+ charset, :invalid => :replace, :undef => :replace))
388+ @fp.write("\r\n")
450389 @fp.write("\r\n")
451- elsif command == 'quiet'
390+ when 'quiet'
452391 send_response(200)
453392 @server.handle_request('NOTIFY', 'keep_silence', true)
454- elsif command == 'restore'
393+ when 'restore'
455394 send_response(200)
456395 @server.handle_request('NOTIFY', 'keep_silence', false)
457- elsif command == 'getnames'
396+ when 'getnames'
458397 send_response(200)
459398 for name in @server.handle_request('GET', 'get_ghost_names')
460- @fp.write(
461- [name.encode(charset, :invalid => :replace, :undef => :replace), "\r\n"].join(""))
399+ @fp.write(name.encode(
400+ charset, :invalid => :replace, :undef => :replace))
401+ @fp.write("\r\n")
462402 end
463403 @fp.write("\r\n")
464- elsif command == 'checkqueue'
404+ when 'checkqueue'
465405 send_response(200)
466406 count, total = @server.handle_request(
467407 'GET', 'check_request_queue', sender)
468- @fp.write([count.to_s.encode(charset, :invalid => :replace, :undef => :replace), "\r\n"].join(""))
469- @fp.write([total.to_s.encode(charset, :invalid => :replace, :undef => :replace), "\r\n"].join(""))
408+ @fp.write(count.to_s.encode(
409+ charset, :invalid => :replace, :undef => :replace))
410+ @fp.write("\r\n")
411+ @fp.write(total.to_s.encode(
412+ charset, :invalid => :replace, :undef => :replace))
413+ @fp.write("\r\n")
470414 @fp.write("\r\n")
471415 else
472416 send_response(501) # Not Implemented
473- log_error('Not Implemented (' + command + ')')
417+ log_error("Not Implemented (#{command})")
474418 end
475419 end
476420
477421 def get_command
478- if @headers.assoc('Command')
479- command = @headers.reverse.assoc('Command')[1]
480- else
481- command = nil
482- end
422+ command = @headers.reverse.assoc('Command')&.at(1)
483423 if command.nil?
484424 send_response(400) # Bad Request
485425 log_error('Command: header field not found')
@@ -489,17 +429,11 @@ module SSTP
489429 end
490430
491431 def do_COMMUNICATE_1_1
492- if not check_decoder()
493- return
494- end
432+ return unless check_decoder()
495433 sender = get_sender()
496- if sender.nil?
497- return
498- end
434+ return if sender.nil?
499435 sentence = get_sentence()
500- if sentence.nil?
501- return
502- end
436+ return if sentence.nil?
503437 send_response(200) # OK
504438 @server.handle_request(
505439 'NOTIFY', 'enqueue_event', 'OnCommunicate', sender, sentence)
@@ -507,11 +441,7 @@ module SSTP
507441 end
508442
509443 def get_sentence
510- if @headers.assoc("Sentence")
511- sentence = @headers.reverse.assoc("Sentence")[1]
512- else
513- sentence = nil
514- end
444+ sentence = @headers.reverse.assoc("Sentence")&.at(1)
515445 if sentence.nil?
516446 send_response(400) # Bad Request
517447 log_error('Sentence: header field not found')
--- a/lib/ninix/sstplib.rb
+++ b/lib/ninix/sstplib.rb
@@ -3,7 +3,7 @@
33 # sstplib.rb - an SSTP library module in Ruby
44 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
55 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
6-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
6+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
77 #
88 # This program is free software; you can redistribute it and/or modify it
99 # under the terms of the GNU General Public License (version 2) as
@@ -40,71 +40,41 @@ module SSTPLib
4040 end
4141
4242 def parse_headers()
43- if @fp.nil?
44- return
45- end
46- headers = []
47- while true
48- line = @fp.readline()
49- if line.strip.empty?
50- break
51- end
52- if line.end_with?("\r\n")
53- line = line[0..-3]
54- elsif line.end_with?("\n")
55- line = line[0..-2]
56- end
57- headers << line
58- end
43+ return if @fp.nil?
5944 message = []
60- for h in headers
61- if h.include?(":")
62- key, value = h.split(":", 2)
63- message << [key, value.strip]
64- end
65- end
66- if not message.assoc("Charset").nil?
67- charset = message.reverse.assoc("Charset")[1] # XXX
68- else
69- charset = "Shift_JIS"
45+ while line = @fp.gets
46+ break if line.strip.empty?
47+ line = line.chomp
48+ next unless line.include?(":")
49+ key, value = line.split(":", 2)
50+ message << [key, value.strip]
7051 end
71- new_list = []
72- for item in message
73- key, value = item
74- new_list << [key, value.force_encoding(charset).encode("UTF-8", :invalid => :replace, :undef => :replace)]
75- end
76- message = new_list
77- return message
52+ charset = message.reverse.assoc("Charset")&.at(1) || "Shift_JIS" # XXX
53+ message.each {|k, v| v.force_encoding(charset).encode!("UTF-8", :invalid => :replace, :undef => :replace) }
7854 end
7955
8056 def parse_request(requestline)
8157 requestline = requestline.encode('Shift_JIS', :invalid => :replace, :undef => :replace)
82- if requestline.end_with?("\r\n")
83- requestline = requestline[0..-3]
84- elsif requestline.end_with?("\n")
85- requestline = requestline[0..-2]
86- end
58+ requestline = requestline.chomp
8759 @requestline = requestline
8860 re_requestsyntax = Regexp.new('\A([A-Z]+) SSTP/([0-9]\\.[0-9])\z')
8961 match = re_requestsyntax.match(requestline)
9062 if match.nil?
9163 @equestline = '-'
92- send_error(400, :message => 'Bad Request ' + requestline.to_s)
64+ send_error(400, :message => "Bad Request #{requestline}")
9365 return false
9466 end
9567 @command, @version = match[1, 2]
96- @headers = parse_headers()
68+ @headers = parse_headers
9769 return true
9870 end
9971
10072 def handle(line)
10173 @error = @version = nil
102- if not parse_request(line)
103- return
104- end
74+ return unless parse_request(line)
10575 name = ("do_#{@command}_#{@version[0]}_#{@version[2]}")
10676 begin
107- method(name).call()
77+ method(name).call
10878 rescue
10979 send_error(
11080 501,
@@ -121,20 +91,20 @@ module SSTPLib
12191
12292 def send_response(code, message: nil)
12393 log_request(code, :message => message)
124- @fp.write("SSTP/" + (@version or "1.0") + " " + code.to_i.to_s + " " + RESPONSES[code] + "\r\n\r\n")
94+ @fp.write("SSTP/#{(@version or "1.0")} #{code} #{RESPONSES[code]}\r\n\r\n")
12595 end
12696
12797 def log_error(message)
128- Logging::Logging.error('[' + timestamp + '] ' + message + '\n')
98+ Logging::Logging.error("[#{timestamp}] #{message}\n")
12999 end
130100
131101 def log_request(code, message: nil)
132102 if @requestline == '-'
133103 request = @requestline
134104 else
135- request = ['"', @requestline, '"'].join("")
105+ request = "\"#{@requestline}\""
136106 end
137- Logging::Logging.info(client_hostname + ' [' + timestamp + '] ' + request + ' ' + code.to_s + ' ' + (message or RESPONSES[code]) + "\n")
107+ Logging::Logging.info("#{client_hostname} [#{timestamp}] #{request} #{code} #{(message or RESPONSES[code])}\n")
138108 end
139109
140110 def client_hostname
@@ -147,12 +117,7 @@ module SSTPLib
147117 end
148118
149119 def timestamp
150- month_names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
151- 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
152- t = Time.now.localtime
153- m = month_names[t.month - 1]
154- return sprintf('%02d/%s/%d:%02d:%02d:%02d %+05d',
155- t.day, m, t.year, t.hour, t.min, t.sec, t.utc_offset / 36)
120+ Time.now.localtime.strftime("%d/%b/%Y:%H:%M:%S %z")
156121 end
157122 end
158123 end
--- a/lib/ninix/surface.rb
+++ b/lib/ninix/surface.rb
@@ -2,7 +2,7 @@
22 #
33 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
44 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
5-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
5+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
66 # Copyright (C) 2003 by Shun-ichi TAHARA <jado@flowernet.gr.jp>
77 #
88 # This program is free software; you can redistribute it and/or modify it
@@ -18,40 +18,24 @@ require "gtk3"
1818 require_relative "keymap"
1919 require_relative "pix"
2020 require_relative "seriko"
21+require_relative "metamagic"
2122 require_relative "logging"
2223
2324 module Surface
2425
25- class Surface
26+ class Surface < MetaMagic::Holon
2627 attr_reader :name, :prefix, :window
2728
2829 def initialize
30+ super("") # FIXME
2931 @window = []
3032 @desc = nil
3133 @mikire = 0
3234 @kasanari = 0
3335 @key_press_count = 0
34- end
35-
36- def set_responsible(parent)
37- @parent = parent
38- end
39-
40- def handle_request(event_type, event, *arglist)
41- fail "assert" unless ['GET', 'NOTIFY'].include?(event_type)
42- handlers = {
36+ @handlers = {
4337 'stick_window' => 'window_stick',
4438 }
45- if handlers.include?(event)
46- result = handlers[event].call # no argument
47- else
48- if Surface.method_defined?(event)
49- result = method(event).call(*arglist)
50- else
51- result = @parent.handle_request(event_type, event, *arglist)
52- end
53- end
54- return result if event_type == 'GET'
5539 end
5640
5741 def finalize
@@ -516,9 +500,7 @@ module Surface
516500 end
517501
518502 def reset_surface
519- for window in @window
520- window.reset_surface()
521- end
503+ @window.map {|window| window.reset_surface }
522504 end
523505
524506 def set_surface_default(side)
@@ -892,15 +874,16 @@ module Surface
892874 end
893875 end
894876
895- class SurfaceWindow
877+ class SurfaceWindow < MetaMagic::Holon
896878 attr_reader :bind
897879
898880 def initialize(window, side, desc, surface_alias, surface_info, tooltips,
899881 surfaces, seriko, region, mayuna, bind, default_id, maxsize)
882+ super("") # FIXME
883+ @handlers = {}
900884 @window = window
901885 @maxsize = maxsize
902886 @side = side
903- @parent = nil
904887 @desc = desc
905888 @alias = surface_alias
906889 @tooltips = tooltips
@@ -997,27 +980,6 @@ module Surface
997980 Gdk.Visual.get_best_depth(), scrn_w, scrn_h)
998981 end
999982
1000- def set_responsible(parent)
1001- @parent = parent
1002- end
1003-
1004- def handle_request(event_type, event, *arglist)
1005- fail "assert" unless ['GET', 'NOTIFY'].include?(event_type)
1006- handlers = {
1007- }
1008- if handlers.include?(event)
1009- result = handlers[event].call # no argument
1010- else
1011- if SurfaceWindow.method_defined?(event)
1012- result = method(event).call(*arglist)
1013- else
1014- result = @parent.handle_request(event_type, event, *arglist)
1015- end
1016- end
1017- return result if event_type == 'GET'
1018- end
1019-
1020- @property
1021983 def direction
1022984 @__direction
1023985 end
--- a/lib/ninix/update.rb
+++ b/lib/ninix/update.rb
@@ -2,7 +2,7 @@
22 #
33 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
44 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
5-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
5+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
66 #
77 # This program is free software; you can redistribute it and/or modify it
88 # under the terms of the GNU General Public License (version 2) as
--- a/lib/ninix/version.rb
+++ b/lib/ninix/version.rb
@@ -1,6 +1,6 @@
11 # -*- coding: utf-8 -*-
22 #
3-# Copyright (C) 2005-2016 by Shyouzou Sugitani <shy@users.osdn.me>
3+# Copyright (C) 2005-2017 by Shyouzou Sugitani <shy@users.osdn.me>
44 #
55 # This program is free software; you can redistribute it and/or modify it
66 # under the terms of the GNU General Public License (version 2) as
@@ -38,7 +38,7 @@ module Version
3838 .concat('\_q')
3939 .concat('Copyright (c) 2001, 2002 Tamito KAJIYAMA\n')
4040 .concat('Copyright (c) 2002-2006 MATSUMURA Namihiko\n')
41- .concat('Copyright (c) 2002-2016 Shyouzou Sugitani\n')
41+ .concat('Copyright (c) 2002-2017 Shyouzou Sugitani\n')
4242 .concat('Copyright (c) 2002, 2003 ABE Hideaki\n')
4343 .concat('Copyright (c) 2003-2005 Shun-ichi TAHARA\e')
4444 end
--- a/lib/ninix_main.rb
+++ b/lib/ninix_main.rb
@@ -2,7 +2,7 @@
22 #
33 # Copyright (C) 2001, 2002 by Tamito KAJIYAMA
44 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net>
5-# Copyright (C) 2002-2016 by Shyouzou Sugitani <shy@users.osdn.me>
5+# Copyright (C) 2002-2017 by Shyouzou Sugitani <shy@users.osdn.me>
66 # Copyright (C) 2003-2005 by Shun-ichi TAHARA <jado@flowernet.gr.jp>
77 #
88 # This program is free software; you can redistribute it and/or modify it
@@ -39,7 +39,7 @@ module Ninix_Main
3939 bindtextdomain("ninix-aya")
4040
4141 def self.handleException(exception)
42- message = ("Uncaught exception (" + exception.class.to_s + ")\n" + exception.backtrace.join("\n"))
42+ message = ("Uncaught exception (#{exception.class})\n" + exception.backtrace.join("\n"))
4343 Logging::Logging.error(message)
4444 response_id = 1
4545 dialog = Gtk::MessageDialog.new(
@@ -260,11 +260,9 @@ module Ninix_Main
260260 buffer = socket.gets
261261 handler.handle(buffer)
262262 rescue SocketError => e
263- Logging::Logging.error(
264- 'socket.error: ' + e.message)
263+ Logging::Logging.error("socket.error: #{e.message}")
265264 rescue SystemCallError => e
266- Logging::Logging.error(
267- 'socket.error: ' + e.message + ' (' + e.errno.to_s + ')')
265+ Logging::Logging.error("socket.error: #{e.message} (#{e.errno})")
268266 rescue # may happen when ninix is terminated
269267 return
270268 end
@@ -287,13 +285,12 @@ module Ninix_Main
287285 begin
288286 server = SSTP::SSTPServer.new(port)
289287 rescue SystemCallError => e
290- Logging::Logging.warning(
291- 'Port ' + port.to_s + ': ' + e.message + ' (ignored)')
288+ Logging::Logging.warning("Port #{port}: #{e.message} (ignored)")
292289 next
293290 end
294291 server.set_responsible(self)
295292 @sstp_servers << server
296- Logging::Logging.info('Serving SSTP on port ' + port.to_s)
293+ Logging::Logging.info("Serving SSTP on port #{port}")
297294 end
298295 end
299296 end
@@ -844,9 +841,9 @@ module Ninix_Main
844841 end
845842 # load ghost
846843 @current_sakura = default_sakura
847- ##for i, name in enumerate(self.get_ghost_names()):
848- ## Logging::Logging.info(
849- ## 'GHOST(' + i.to_s +'): ' + name)
844+ ##for i, name in enumerate(get_ghost_names())
845+ ## Logging::Logging.info("GHOST(#{i}): #{name}")
846+ ##end
850847 start_sakura(@current_sakura, :init => true, :abend => @abend)
851848 end
852849