• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

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

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


Commit MetaInfo

Revisionc39594cfb191fae67487b1c794bb3ea124d97935 (tree)
Time2014-04-03 22:55:22
AuthorShyouzou Sugitani <shy@user...>
CommiterShyouzou Sugitani

Log Message

add alias.rb

Change Summary

Incremental Difference

--- /dev/null
+++ b/lib/ninix/alias.rb
@@ -0,0 +1,136 @@
1+# -*- coding: utf-8 -*-
2+#
3+# Copyright (C) 2001, 2002 by Tamito KAJIYAMA
4+# Copyright (C) 2004-2014 by Shyouzou Sugitani <shy@users.sourceforge.jp>
5+#
6+# This program is free software; you can redistribute it and/or modify it
7+# under the terms of the GNU General Public License (version 2) as
8+# published by the Free Software Foundation. It is distributed in the
9+# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11+# PURPOSE. See the GNU General Public License for more details.
12+#
13+
14+require "ninix/config"
15+
16+module Alias
17+
18+ def self.fatal(error)
19+ #logging.error('alias.py: {0}'.format(str(error)))
20+ return NConfig.null_config()
21+ end
22+
23+ def self.create_from_file(path)
24+ f = File.open(path, 'rb')
25+ buf = []
26+ while line = f.gets
27+ if line.strip
28+ buf << line.strip
29+ end
30+ end
31+ return create_from_buffer(buf)
32+ end
33+
34+ def self.create_from_buffer(buf)
35+ re_alias = Regexp.new("^(sakura|kero|char[0-9]+)\.surface\.alias$")
36+ dic = NConfig::Config.new
37+ i, j = 0, buf.length
38+ while i < j
39+ line = buf[i]
40+ i += 1
41+ if line.length == 0
42+ next
43+ end
44+ match = re_alias.match(line)
45+ if match
46+ name = line
47+ table = {}
48+ begin
49+ while 1
50+ if i < j
51+ line = buf[i]
52+ i += 1
53+ else
54+ raise ValueError('unexpedted end of file')
55+ end
56+ line = line.sub('\x81\x40', '').strip()
57+ if line.length == 0
58+ next
59+ elsif line == '{'
60+ break
61+ end
62+ raise ValueError('open brace not found')
63+ end
64+ while 1
65+ if i < j
66+ line = buf[i]
67+ i += 1
68+ else
69+ raise ValueError('unexpected end of file')
70+ end
71+ line = line.sub('\x81\x40', '').strip()
72+ if line.length == 0
73+ next
74+ elsif line == '}'
75+ break
76+ end
77+ line = line.split(',', 2)
78+ if line.length == 2
79+ key = line[0].strip
80+ values = line[1].strip
81+ else
82+ #raise ValueError('malformed line found')
83+ end
84+ if values and \
85+ values.start_with?('[') and values.end_with?(']')
86+ table[key] = []
87+ for value in values[1, values.length - 2].split(',')
88+ begin
89+ value = str(int(value))
90+ rescue
91+ #except ValueError:
92+ #pass
93+ end
94+ table[key] << value
95+ # else
96+ # raise ValueError('malformed line found')
97+ end
98+ end
99+ end
100+ rescue# except ValueError as error
101+ return fatal(error)
102+ end
103+ dic[name] = table
104+ else
105+ line = line.split(',', 2)
106+ if line.length == 2
107+ key = line[0].strip
108+ value = line[1].strip
109+ else
110+ #return fatal('malformed line found')
111+ end
112+ if key == 'makoto'
113+ if value and \
114+ value.start_with('[') and value.end_with(']')
115+ value = value[1, value.length - 2].split(',')
116+ else
117+ value = [value]
118+ end
119+ end
120+ dic[key] = value
121+ end
122+ end
123+ return dic
124+ end
125+
126+ class TEST
127+ def initialize(path)
128+ conf = Alias::create_from_file(path)
129+ print("ALIAS: ", conf, "\n")
130+ end
131+ end
132+end
133+
134+$:.unshift(File.dirname(__FILE__))
135+
136+Alias::TEST.new(ARGV.shift)
--- a/lib/ninix/config.rb
+++ b/lib/ninix/config.rb
@@ -92,7 +92,7 @@ module NConfig
9292 end
9393
9494 def self.null_config()
95- return Config()
95+ return NConfig::Config.new()
9696 end
9797
9898 class TEST